Develop and Download Open Source Software

Browse CVS Repository

Contents of /tombo/Tombo/Src/Property.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.59 - (show annotations) (download) (as text)
Mon Sep 18 17:45:03 2006 UTC (17 years, 6 months ago) by hirami
Branch: MAIN
CVS Tags: Tombo_2_0b4, B231, B230, HEAD
Changes since 1.58: +49 -4 lines
File MIME type: text/x-c++src
* FIX: password timeout occures in serveral minutes even though timeout value is 60 min (#8952)
* FIX: "Use random filename" option is always ON even though check is off (#8960)
* FIX: PocketPC's menu is corrupt(#8961)

1 #include <windows.h>
2 #include <commctrl.h>
3 #include <tchar.h>
4 #if defined(PLATFORM_WIN32)
5 #include <stdio.h>
6 #endif
7 #if defined(PLATFORM_BE500)
8 #include <GetDisk.h>
9 #endif
10 #include <expat.h>
11
12 #include "Tombo.h"
13 #include "Property.h"
14 #include "resource.h"
15 #include "FileSelector.h"
16 #include "UniConv.h"
17 #include "PasswordManager.h"
18 #include "Message.h"
19 #include "DialogTemplate.h"
20 #include "TString.h"
21 #include "PropertyPage.h"
22 #include "TomboPropertyTab.h"
23 #include "File.h"
24 #include "AutoPtr.h"
25 #include "List.h"
26 #include "TomboURI.h"
27 #include "Repository.h"
28 #include "VarBuffer.h"
29 #include "RepositoryImpl.h"
30
31 //////////////////////////////////////////
32 // Attribute definitions
33
34 #define TOMBO_PROP_VERSION "1.16"
35 #define PROP_FILE_NAME TEXT("tomboprops.xml")
36 #define PROP_TMP_FILE_NAME TEXT("tomboprops.xml~")
37
38 #define TOMBO_MAIN_KEY TEXT("Software\\flatfish\\Tombo")
39 #define TOPDIR_ATTR_NAME TEXT("TopDir")
40 #define USEYAE_ATTR_NAME TEXT("UseYAEdit")
41 #define BOOKMARK_ATTR_NAME TEXT("BookMark")
42 #define SEARCHHIST_ATTR_NAME TEXT("SearchHistory")
43 #define TOPDIRHIST_ATTR_NAME TEXT("TopDirHistory")
44 #define REBARHIST_ATTR_NAME TEXT("RebarPos")
45
46 //////////////////////////////////////////
47 // property pages
48
49 #if defined(PLATFORM_PKTPC) || defined(PLATFORM_WM5)
50 #define PROPTAB_PAGES 10
51 #else
52 #define PROPTAB_PAGES 8
53 #endif
54
55 //////////////////////////////////////////
56 // default values
57
58 #if defined(PLATFORM_WIN32)
59 #define MEMO_TOP_DIR TEXT("c:\\My Documents\\Pocket_PC My Documents\\TomboRoot")
60 #else
61 #define MEMO_TOP_DIR TEXT("\\My Documents\\TomboRoot")
62 #endif
63
64 #if defined(PLATFORM_BE500)
65 #define TOMBO_ROOT_SUFFIX TEXT("\\TomboRoot")
66 #endif
67
68 #define DEFAULTDATEFORMAT1 TEXT("%y/%M/%d")
69 #define DEFAULTDATEFORMAT2 TEXT("%h:%m:%s")
70
71 //////////////////////////////////////////
72 class RepositoryImpl;
73
74 static HKEY GetTomboRootKey();
75
76 static BOOL SetSZToReg(HKEY hKey, LPCTSTR pAttr, LPCTSTR pValue);
77 static BOOL SetDWORDToReg(HKEY hKey, LPCTSTR pAttr, DWORD nValue);
78 static BOOL SetMultiSZToReg(HKEY hKey, LPCTSTR pAttr, LPCTSTR pValue, DWORD nSize);
79
80 static DWORD GetDWORDFromReg(HKEY hKey, LPCTSTR pAttr, DWORD nDefault);
81 static LPTSTR GetMultiSZFromReg(HKEY hKey, LPCTSTR pAttr);
82 static BOOL GetSZFromReg(HKEY hKey, LPCTSTR pAttr, LPTSTR pBuf, DWORD nBuf, LPCTSTR pDefault);
83 static LPTSTR GetAllocSZFromReg(HKEY hKey, LPCTSTR pAttr);
84
85 static DWORD CountMultiSZLen(LPCTSTR pData);
86
87 static BOOL MakeFont(HFONT *phFont, LPCTSTR pName, DWORD nSize, BYTE bQuality);
88
89 //////////////////////////////////////////
90 // property definitions
91 //////////////////////////////////////////
92
93 struct PropListNum {
94 DWORD nPropId;
95 LPCTSTR pAttrName;
96 DWORD nDefault;
97 } propListNum[] = {
98 { PROP_N_PASSTIMEOUT, TEXT("PassTimeOut"), 5 },
99 { PROP_N_DETAILSVIEW_KEEPCARET, TEXT("KeepCaret"), FALSE },
100 { PROP_NDETAILSVIEW_TABSTOP, TEXT("Tabstop"), 8 },
101 { PROP_N_SELECTVIEW_FONTSIZE, TEXT("SelectViewFontSize"), 0xFFFFFFFF },
102 { PROP_N_SELECTVIEW_FONTQUALITY, TEXT("SelectViewFontQuality"), DEFAULT_QUALITY },
103 { PROP_N_DETAILSVIEW_FONTSIZE, TEXT("DetailsViewFontSize"), 0xFFFFFFFF },
104 { PROP_N_DETAILSVIEW_FONTQUALITY, TEXT("DetailsViewFontQuality"), DEFAULT_QUALITY },
105 { PROP_N_AUTOSELECT_MODE, TEXT("AutoSelectMode"), TRUE },
106 { PROP_N_SINGLECLICK_MODE, TEXT("SingleClickMode"), TRUE },
107 { PROP_N_USE_TWO_PANE, TEXT("UseTwoPane"), TRUE },
108 { PROP_N_KEEP_TITLE, TEXT("KeepTitle"), FALSE },
109 #if defined(PLATFORM_PKTPC) || defined(PLATFORM_WIN32) || defined(PLATFORM_WM5)
110 { PROP_N_SWITCH_WINDOW_TITLE, TEXT("SwitchWindowTitle"), TRUE },
111 #endif
112 #if defined(PLATFORM_PKTPC) || defined(PLATFORM_WM5)
113 { PROP_N_APP_BUTTON1, TEXT("AppButton1"), APPBUTTON_ACTION_DISABLE },
114 { PROP_N_APP_BUTTON2, TEXT("AppButton2"), APPBUTTON_ACTION_DISABLE },
115 { PROP_N_APP_BUTTON3, TEXT("AppButton3"), APPBUTTON_ACTION_DISABLE },
116 { PROP_N_APP_BUTTON4, TEXT("AppButton4"), APPBUTTON_ACTION_DISABLE },
117 { PROP_N_APP_BUTTON5, TEXT("AppButton5"), APPBUTTON_ACTION_DISABLE },
118 { PROP_N_SIPSIZE_DELTA, TEXT("SipSizeDelta"), 0},
119 #endif
120 { PROP_N_CODEPAGE, TEXT("CodePage"), 0 },
121 #if defined(PLATFORM_PKTPC) || defined(PLATFORM_WM5)
122 { PROP_N_DISABLEEXTRAACTIONBUTTON, TEXT("DisableExtraActionButton"), 0},
123 #endif
124 #if defined(PLATFORM_HPC) || defined(PLATFORM_WIN32)
125 { PROP_N_HIDESTATUSBAR, TEXT("HideStatusBar"), 0 },
126 #endif
127 #if defined(PLATFORM_WIN32)
128 { PROP_N_STAYTOPMOST, TEXT("StayTopMost"), 0 },
129 { PROP_N_HIDEREBAR, TEXT("HideRebar"), 0 },
130 #endif
131 { PROP_N_WRAPTEXT, TEXT("WrapText"), 1 },
132 { PROP_N_OPENREADONLY, TEXT("OpenReadOnly"), FALSE },
133 { PROP_N_DISABLESAVEDLG, TEXT("DisableSaveDlg"), FALSE },
134 { PROP_N_USEASSOC, TEXT("UseSoftwareAssoc"), FALSE },
135 { PROP_N_SAFEFILENAME, TEXT("UseSafeFileName"), FALSE },
136 #if (defined(PLATFORM_PKTPC) || defined(PLATFORM_WM5)) && defined(FOR_VGA)
137 { PROP_N_TOMBO_WINSIZE3, TEXT("WinSize3"), 0xFFFF },
138 #endif
139 { PROP_N_KEEP_LAST_OPEN, TEXT("UseLastOpenNote"), FALSE },
140 { PROP_N_USE_YAE, TEXT("UseYAE"), FALSE },
141 { PROP_N_DISABLE_YAE, TEXT("DisableYAE"), FALSE },
142 { 0xFFFFFFFF, NULL, NULL},
143 };
144
145 struct PropListStr {
146 DWORD nPropId;
147 LPCTSTR pAttrName;
148 LPCTSTR pDefault;
149 } propListStr[] = {
150 { PROP_S_TOPDIR, TOPDIR_ATTR_NAME, NULL },
151 { PROP_S_SELECTVIEW_FONTNAME, TEXT("SelectViewFontName"), TEXT("") },
152 { PROP_S_DETAILSVIEW_FONTNAME, TEXT("DetailsViewFontName"), TEXT("") },
153 { PROP_S_DETAILSVIEW_DATEFORMAT1, TEXT("DateFormat1"), DEFAULTDATEFORMAT1 },
154 { PROP_S_DETAILSVIEW_DATEFORMAT2, TEXT("DateFormat2"), DEFAULTDATEFORMAT2 },
155 { PROP_S_DEFAULTNOTE, TEXT("DefaultNote"), TEXT("") },
156 { PROP_S_EXTAPP1, TEXT("ExtApp1"), TEXT("") },
157 { PROP_S_EXTAPP2, TEXT("ExtApp2"), TEXT("") },
158 { PROP_S_WINSIZE, TEXT("WinSize2"), NULL },
159 { PROP_S_LAST_OPEN_URI, TEXT("LastOpenURI"), TEXT("") },
160 { 0xFFFFFFFF, NULL, NULL },
161 };
162
163 //////////////////////////////////////////
164 // get message string
165 //////////////////////////////////////////
166
167 LPCTSTR GetString(UINT nID)
168 {
169 static TCHAR buf[MESSAGE_MAX_SIZE];
170 LoadString(g_hInstance, nID, buf, MESSAGE_MAX_SIZE);
171 return buf;
172 }
173
174 //////////////////////////////////////////
175 // ctor
176 //////////////////////////////////////////
177
178 Property::Property() : pCmdlineAssignedTopDir(NULL), pBookMark(NULL), pSearchHistory(NULL), pTopDirHistory(NULL),
179 pDefaultRep(NULL), pRepos(NULL), nNumRepos(0)
180 #if defined(PLATFORM_HPC)
181 ,pCmdBarInfo(NULL)
182 #endif
183 {
184 bLoad = FALSE;
185 bNeedAsk = TRUE;
186
187 for (DWORD i = 0; i < NUM_PROPS_STR; i++) {
188 pPropsStr[i] = NULL;
189 }
190
191 SetTopDir(TEXT(""));
192 SetDefaultNote(TEXT(""));
193 }
194
195 Property::~Property()
196 {
197 DWORD i;
198 for (i = 0; i < NUM_PROPS_STR; i++) {
199 delete [] pPropsStr[i];
200 }
201
202 for (i = 0; i < nNumRepos; i++) {
203 delete pRepos[i];
204 }
205 delete [] pRepos;
206
207 delete [] pCmdlineAssignedTopDir;
208 delete [] pBookMark;
209 delete [] pSearchHistory;
210 delete [] pTopDirHistory;
211 #if defined(PLATFORM_HPC)
212 delete [] pCmdBarInfo;
213 #endif
214 }
215
216 //////////////////////////////////////////
217 //
218 //////////////////////////////////////////
219
220 BOOL Property::SetStringProperty(DWORD nPropId, LPCTSTR pValue)
221 {
222 delete[] pPropsStr[nPropId];
223 if (pValue == NULL) {
224 pPropsStr[nPropId] = NULL;
225 return TRUE;
226 }
227 if ((pPropsStr[nPropId] = StringDup(pValue)) == NULL) return FALSE;
228 return TRUE;
229 }
230
231 //////////////////////////////////////////
232 // topdir
233 //////////////////////////////////////////
234
235 LPCTSTR Property::GetTomboRoot()
236 {
237 if (pCmdlineAssignedTopDir != NULL && _tcslen(pCmdlineAssignedTopDir) > 0) {
238 return pCmdlineAssignedTopDir;
239 }
240 return GetTopDir();
241 }
242
243 //////////////////////////////////////////
244 // font
245 //////////////////////////////////////////
246
247 HFONT Property::SelectViewFont()
248 {
249 HFONT hFont = NULL;
250 MakeFont(&hFont, GetSelectViewFontName(), GetSelectViewFontSize(), (BYTE)GetSelectViewFontQuality());
251 return hFont;
252 }
253
254 HFONT Property::DetailsViewFont()
255 {
256 HFONT hFont = NULL;
257 MakeFont(&hFont, GetDetailsViewFontName(), GetDetailsViewFontSize(), (BYTE)GetDetailsViewFontQuality());
258 return hFont;
259 }
260
261 //////////////////////////////////////////
262 // Popup property dialog
263 //////////////////////////////////////////
264
265 DWORD Property::Popup(HINSTANCE hInst, HWND hWnd, const TomboURI *pCurrentSelectedURI)
266 {
267 TString sSelPath;
268 if (pCurrentSelectedURI == NULL) {
269 sSelPath.Set(TEXT(""));
270 } else {
271 sSelPath.Set(pCurrentSelectedURI->GetFullURI());
272 }
273
274 PropertyTab *pages[PROPTAB_PAGES];
275 FolderTab pgFolder(this);
276 DefaultNoteTab pgDefNote(this, sSelPath.Get());
277 PassTimeoutTab pgTimeout(this);
278 FontTab pgFont(this);
279 DateFormatTab pgDate(this);
280 KeepCaretTab pgKeepCaret(this);
281 #if defined(PLATFORM_PKTPC) || defined(PLATFORM_WM5)
282 AppButtonTab pgAppButton(this);
283 SipTab pgSip(this);
284 #endif
285 CodepageTab pgCodepage(this);
286 #if !defined(PLATFORM_PSPC)
287 ExtAppTab pgExtApp(this);
288 #endif
289
290 DWORD n = 0;
291
292 pages[n++] = &pgFolder;
293 pages[n++] = &pgDefNote;
294 pages[n++] = &pgTimeout;
295 pages[n++] = &pgFont;
296 pages[n++] = &pgDate;
297 pages[n++] = &pgKeepCaret;
298 #if !defined(PLATFORM_PSPC)
299 pages[n++] = &pgExtApp;
300 #endif
301 #if defined(PLATFORM_PKTPC) || defined(PLATFORM_WM5)
302 pages[n++] = &pgAppButton;
303 pages[n++] = &pgSip;
304 #endif
305 pages[n++] = &pgCodepage;
306
307 PropertyPage pp;
308 if (pp.Popup(hInst, hWnd, pages, n, MSG_PROPTAB_TITLE, MAKEINTRESOURCE(IDI_TOMBO)) == IDOK) {
309 ////////////////////////////////////
310 // sync Topdir <-> rep array settings
311 // XXXX: this code are temporary till changing property dialog
312 LPCTSTR pTopDir = GetTopDir();
313 for (DWORD i = 0; i < GetNumSubRepository(); i++) {
314 RepositoryImpl *pImpl = pRepos[i];
315 if (pImpl->GetRepositoryType() == TOMBO_REPO_SUBREPO_TYPE_LOCALFILE && _tcscmp(pImpl->GetRepositoryName(), TEXT("default")) == 0) {
316 LocalFileRepository *pDefaultRep = (LocalFileRepository*)pImpl;
317 pDefaultRep->SetTopDir(pTopDir);
318 }
319 }
320 ////////////////////////////////////
321
322 if (!Save()) {
323 MessageBox(NULL, MSG_SAVE_DATA_FAILED, TEXT("ERROR"), MB_ICONSTOP | MB_OK);
324 }
325 return IDOK;
326 }
327 return IDCANCEL;
328 }
329
330 //////////////////////////////////////////
331 // load properties
332 //////////////////////////////////////////
333
334 void GetNameAndValue(const XML_Char **atts, LPTSTR *ppKey, LPTSTR *ppValue)
335 {
336 *ppKey = NULL;
337 *ppValue = NULL;
338
339 int i = 0;
340 while (atts[i]) {
341 if (wcscmp((LPCWSTR)atts[i], L"name") == 0) {
342 *ppKey = ConvWCharToTChar((LPCWSTR)atts[i + 1]);
343 } else if (wcscmp((LPCWSTR)atts[i], L"value") == 0) {
344 *ppValue = ConvWCharToTChar((LPCWSTR)atts[i + 1]);
345 }
346 i+= 2;
347 }
348 }
349
350 PropListNum *SerachNumAttrName(LPTSTR pAttr)
351 {
352 PropListNum *p = propListNum;
353 while (p->nPropId != 0xFFFFFFFF) {
354 if (_tcscmp(pAttr, p->pAttrName) == 0) {
355 return p;
356 }
357 p++;
358 }
359 return NULL;
360 }
361
362 PropListStr *SerachStrAttrName(LPTSTR pAttr)
363 {
364 PropListStr *p = propListStr;
365 while (p->nPropId != 0xFFFFFFFF) {
366 if (_tcscmp(pAttr, p->pAttrName) == 0) {
367 return p;
368 }
369 p++;
370 }
371 return NULL;
372 }
373
374 struct PropFileParseInfo {
375 Property *pProperty;
376
377 LPTSTR pMultiName;
378 List lMultiItem;
379
380 BOOL bInTomboRoot;
381
382 TVector<RepositoryImpl*> vSubRepos;
383 LocalFileRepository *pDefaultRep;
384
385 PropFileParseInfo() : pMultiName(NULL), bInTomboRoot(FALSE), pDefaultRep(NULL) {}
386 ~PropFileParseInfo() { delete[] pMultiName; }
387
388 void SetMultiName(LPTSTR p) { delete[] pMultiName; pMultiName = p; }
389 };
390
391 static void StartElement(void *userData, const XML_Char *name, const XML_Char **atts)
392 {
393 PropFileParseInfo *pParseInfo = (PropFileParseInfo*)userData;
394 Property *pProperty = pParseInfo->pProperty;
395
396 LPCWSTR pName = (LPCWSTR)name;
397
398 LPTSTR pKey;
399 LPTSTR pValue;
400
401 if (wcscmp(pName, L"tomboroot") == 0) {
402 pParseInfo->bInTomboRoot = TRUE;
403 } else if (pParseInfo->bInTomboRoot) {
404 RepositoryImpl *pImpl = Repository::CreateSubRepo((LPCWSTR)name, (const WCHAR **)atts);
405 if (pImpl != NULL) {
406 pParseInfo->vSubRepos.Add(&pImpl);
407 }
408 // XXX: in current version, default repository assumed as LocalFileRepository.
409 if (_tcscmp(TEXT("default"), pImpl->GetRepositoryName()) == 0) {
410 pParseInfo->pDefaultRep = (LocalFileRepository*)pImpl;
411 }
412 } else if (wcscmp(pName, L"tomboprop") == 0) {
413 // XXXX: NOP in current version
414 // for future version, version check will be added.
415 } else if (wcscmp(pName, L"num") == 0) {
416 GetNameAndValue(atts, &pKey, &pValue);
417 PropListNum *p = SerachNumAttrName(pKey);
418 if (p != NULL) {
419 DWORD nValue = _ttol(pValue);
420 pProperty->SetNumberPropertyById(p->nPropId, nValue);
421 }
422 delete [] pKey;
423 delete [] pValue;
424 } else if (wcscmp(pName, L"str") == 0) {
425 GetNameAndValue(atts, &pKey, &pValue);
426 PropListStr *p = SerachStrAttrName(pKey);
427 if (p != NULL) {
428 pProperty->SetStringPropertyWithBuffer(p->nPropId, pValue);
429 // buffer is managed under Property, so do not delete[] pValue;
430 } else {
431 delete [] pValue;
432 }
433 delete [] pKey;
434 } else if (wcscmp(pName, L"multistr") == 0) {
435 if (wcscmp((LPCWSTR)atts[0], L"name") == 0) {
436 pParseInfo->SetMultiName(ConvWCharToTChar((LPCWSTR)atts[1]));
437 }
438 } else if (wcscmp(pName, L"item") == 0) {
439 if (wcscmp((LPCWSTR)atts[0], L"value") == 0) {
440 pParseInfo->lMultiItem.Add(ConvWCharToTChar((LPCWSTR)atts[1]));
441 }
442 }
443 #if defined(PLATFORM_HPC)
444 else if (wcscmp(pName, L"rebar") == 0) {
445 GetNameAndValue(atts, &pKey, &pValue);
446 LPCOMMANDBANDSRESTOREINFO pCmdBarInfo = new COMMANDBANDSRESTOREINFO[NUM_COMMANDBAR];
447 memset(pCmdBarInfo, 0, sizeof(COMMANDBANDSRESTOREINFO) * NUM_COMMANDBAR);
448 DWORD wID1, fStyle1, cxRestored1, fMaximized1;
449 DWORD wID2, fStyle2, cxRestored2, fMaximized2;
450
451 if (swscanf(pValue, TEXT("%d,%d,%d,%d,%d,%d,%d,%d"),
452 &wID1, &fStyle1, &cxRestored1, &fMaximized1,
453 &wID2, &fStyle2, &cxRestored2, &fMaximized2) != 8) {
454 // TODO: set default
455 MessageBox(NULL, TEXT("NOT YET"), TEXT("DEBUG"), MB_OK);
456 } else {
457 pCmdBarInfo[0].cbSize = pCmdBarInfo[1].cbSize = sizeof(COMMANDBANDSRESTOREINFO);
458 pCmdBarInfo[0].wID = (UINT)wID1;
459 pCmdBarInfo[1].wID = (UINT)wID2;
460 pCmdBarInfo[0].fStyle = (UINT)fStyle1;
461 pCmdBarInfo[1].fStyle = (UINT)fStyle2;
462 pCmdBarInfo[0].cxRestored = (UINT)cxRestored1;
463 pCmdBarInfo[1].cxRestored = (UINT)cxRestored2;
464 pCmdBarInfo[0].fMaximized = (BOOL)fMaximized1;
465 pCmdBarInfo[1].fMaximized = (BOOL)fMaximized2;
466 pProperty->SetCommandbarInfoWithBuffer(pCmdBarInfo);
467 }
468 }
469 #endif
470 }
471
472 static void EndElement(void *userData, const XML_Char *name)
473 {
474 PropFileParseInfo *pParseInfo = (PropFileParseInfo*)userData;
475
476 if (wcscmp((LPCWSTR)name, L"tomboroot") == 0) {
477 pParseInfo->bInTomboRoot = FALSE;
478 } else if (wcscmp((LPCWSTR)name, L"multistr") == 0) {
479 List *pList = &(pParseInfo->lMultiItem);
480
481 DWORD n = 0;
482 DWORD i = 0;
483 HANDLE h = pList->First();
484 while (h) {
485 LPTSTR p = (LPTSTR)pList->Value(h);
486 n += _tcslen(p) + 1;
487 i++;
488 h = pList->Next(h);
489 }
490 if (i == 0) return;
491
492 LPTSTR pValue = new TCHAR[n + 1];
493 LPTSTR p = pValue;
494 h = pList->First();
495 while (h) {
496 LPTSTR item = (LPTSTR)pList->Value(h);
497 _tcscpy(p, item);
498 p += _tcslen(item) + 1;
499
500 delete[] item;
501 h = pList->Next(h);
502 }
503 *p = TEXT('\0');
504
505 pList->Clear();
506
507 if (_tcscmp(pParseInfo->pMultiName, BOOKMARK_ATTR_NAME) == 0) {
508 pParseInfo->pProperty->SetBookMark(pValue);
509 delete[] pValue;
510 } else if (_tcscmp(pParseInfo->pMultiName, TOPDIRHIST_ATTR_NAME) == 0) {
511 pParseInfo->pProperty->SetTopDirHist(pValue);
512 } else if (_tcscmp(pParseInfo->pMultiName, SEARCHHIST_ATTR_NAME) == 0) {
513 pParseInfo->pProperty->SetSearchHist(pValue);
514 } else {
515 delete [] pValue;
516 }
517 }
518 }
519
520 BOOL Property::LoadDefaultProperties()
521 {
522 PropListNum *pNum = propListNum;
523 while (pNum->nPropId != 0xFFFFFFFF) {
524 nPropsNum[pNum->nPropId] = pNum->nDefault;
525 pNum++;
526 }
527
528 PropListStr *pPLS = propListStr;
529 while (pPLS->nPropId != 0xFFFFFFFF) {
530 if (pPLS->pDefault != NULL) {
531 pPropsStr[pPLS->nPropId] = StringDup(pPLS->pDefault);
532 if (pPropsStr[pPLS->nPropId] == NULL) return FALSE;
533 } else {
534 pPropsStr[pPLS->nPropId] = NULL;
535 }
536 pPLS++;
537 }
538 return TRUE;
539 }
540
541 BOOL Property::Load()
542 {
543 BOOL bResult = LoadProperties();
544
545 // Convert topdir value to repository value
546 LPCTSTR pTopDir = GetTopDir();
547 if (pTopDir != NULL && GetNumSubRepository() == 0) {
548 pRepos = new RepositoryImpl*[2];
549 nNumRepos = 2;
550
551 LocalFileRepository *pLocalImpl = new LocalFileRepository();
552 // if (!pLocalImpl->Init(TEXT("default"), , pTopDir, bKeepTitle, bKeepCaret, bSafeFileName)) {
553 // XXXX :
554 if (!pLocalImpl->Init(TEXT("default"), MSG_MEMO, pTopDir, FALSE, FALSE, FALSE)) {
555 return FALSE;
556 }
557 pRepos[0] = pLocalImpl;
558 pDefaultRep = pLocalImpl;
559
560 VFolderRepository *pVImpl = new VFolderRepository();
561 if (!pVImpl->Init(TEXT("@vfolder"), MSG_VIRTUAL_FOLDER)) {
562 return FALSE;
563 }
564 pRepos[1] = pVImpl;
565 }
566
567 if (!bResult) {
568 // set default value
569 bNeedAsk = TRUE;
570 return LoadDefaultProperties();
571 }
572 return TRUE;
573 }
574
575 BOOL Property::LoadProperties()
576 {
577 TCHAR pathbuf[MAX_PATH + 1];
578 TCHAR pathbuf2[MAX_PATH + 1];
579 GetModuleFileName(NULL, pathbuf, MAX_PATH);
580 GetFilePath(pathbuf2, pathbuf);
581 TString sPropFile;
582 if (!sPropFile.Join(pathbuf2, PROP_FILE_NAME)) return FALSE;
583
584 File fFile;
585 DWORD i;
586 if (!fFile.Open(sPropFile.Get(), GENERIC_READ, FILE_SHARE_READ, OPEN_EXISTING)) {
587 BOOL bStrict;
588 BOOL bResult = LoadFromReg(&bStrict);
589 if (bResult) {
590 if (bStrict) {
591 bNeedAsk = FALSE;
592 } else {
593 bNeedAsk = TRUE;
594 }
595 return TRUE;
596 } else {
597 return FALSE;
598 }
599 }
600 DWORD nFileSize = fFile.FileSize();
601 XML_Parser pParser = XML_ParserCreate(NULL);
602 if (pParser == NULL) return FALSE;
603
604 PropFileParseInfo ppi;
605 ppi.pProperty = this;
606 if (!ppi.vSubRepos.Init(5, 5)) return FALSE;
607
608 XML_SetElementHandler(pParser, StartElement, EndElement);
609 XML_SetUserData(pParser, &ppi);
610
611 void *pBuf = XML_GetBuffer(pParser, nFileSize);
612 if (pBuf == NULL) return FALSE;
613
614 if (!fFile.Read((LPBYTE)pBuf, &nFileSize)) return FALSE;
615
616 for (i = 0; i < NUM_PROPS_STR; i++) {
617 delete [] pPropsStr[i];
618 pPropsStr[i] = NULL;
619 }
620
621 if (!XML_ParseBuffer(pParser, nFileSize, TRUE)) {
622 return FALSE;
623 }
624 XML_ParserFree(pParser);
625
626 for (i = 0; i < nNumRepos; i++) {
627 delete pRepos[i];
628 }
629 delete [] pRepos;
630
631 nNumRepos = ppi.vSubRepos.NumItems();
632 pRepos = new RepositoryImpl*[nNumRepos];
633 for (i = 0; i < ppi.vSubRepos.NumItems(); i++) {
634 RepositoryImpl *pImpl = *ppi.vSubRepos.GetUnit(i);
635 pRepos[i] = pImpl;
636 }
637 pDefaultRep = ppi.pDefaultRep;
638
639 bNeedAsk = FALSE;
640 bLoad = TRUE;
641
642 return TRUE;
643 }
644
645 BOOL Property::LoadFromReg(BOOL *pStrict)
646 {
647 DWORD res, typ, siz;
648 HKEY hTomboRoot;
649
650 hTomboRoot = GetTomboRootKey();
651 if (hTomboRoot == NULL) return FALSE;
652
653 *pStrict = TRUE;
654
655 if (pCmdlineAssignedTopDir) {
656 SetTopDir(pCmdlineAssignedTopDir);
657 } else {
658 TCHAR buf[MAX_PATH];
659 siz = sizeof(buf);
660 res = RegQueryValueEx(hTomboRoot, TOPDIR_ATTR_NAME, NULL, &typ, (LPBYTE)buf, &siz);
661 if (res == ERROR_SUCCESS) {
662 if (!SetTopDir(buf)) return FALSE;
663 } else {
664 #if defined(PLATFORM_BE500)
665 GetUserDiskName(g_hInstance, buf, MAX_PATH);
666 if (_tcslen(buf) + _tcslen(TOMBO_ROOT_SUFFIX) < MAX_PATH - 1) {
667 _tcscat(buf, TOMBO_ROOT_SUFFIX);
668 }
669 if (!SetTopDir(buf)) return FALSE;
670 #else
671 if (!SetTopDir(MEMO_TOP_DIR)) return FALSE;
672 #endif
673 *pStrict = FALSE;
674 }
675 }
676
677 // load number props.
678 PropListNum *pNum = propListNum;
679 while (pNum->nPropId != 0xFFFFFFFF) {
680 DWORD nVal = GetDWORDFromReg(hTomboRoot, pNum->pAttrName, pNum->nDefault);
681 nPropsNum[pNum->nPropId] = nVal;
682 pNum++;
683 }
684
685 #if !(defined(PLATFORM_WIN32) || defined(PLATFORM_PKTPC) || defined(PLATFORM_WM5))
686 SetSwitchWindowTitle(FALSE);
687 #endif
688
689 LPTSTR pStr;
690
691 PropListStr *pPLS = propListStr;
692 while (pPLS->nPropId != 0xFFFFFFFF) {
693 if (pPLS->nPropId == PROP_S_TOPDIR) { pPLS++; continue; }
694
695 pStr = GetAllocSZFromReg(hTomboRoot, pPLS->pAttrName);
696 if (pStr == NULL) {
697 if (pPLS->pDefault) {
698 pStr = StringDup(pPLS->pDefault);
699 } else {
700 pStr = NULL;
701 }
702 }
703 delete [] pPropsStr[pPLS->nPropId];
704 pPropsStr[pPLS->nPropId] = pStr;
705
706 pPLS++;
707 }
708
709 delete[] pBookMark;
710 pBookMark = GetMultiSZFromReg(hTomboRoot, BOOKMARK_ATTR_NAME);
711
712 delete [] pSearchHistory;
713 pSearchHistory = GetMultiSZFromReg(hTomboRoot, SEARCHHIST_ATTR_NAME);
714
715 delete [] pTopDirHistory;
716 pTopDirHistory = GetMultiSZFromReg(hTomboRoot, TOPDIRHIST_ATTR_NAME);
717
718
719 #if defined(PLATFORM_HPC)
720 LPCOMMANDBANDSRESTOREINFO pcbi = new COMMANDBANDSRESTOREINFO[NUM_COMMANDBAR];
721 siz = sizeof(COMMANDBANDSRESTOREINFO) * NUM_COMMANDBAR;
722 res = RegQueryValueEx(hTomboRoot, REBARHIST_ATTR_NAME, 0,
723 &typ, (LPBYTE)pcbi, &siz);
724
725 if (siz == NUM_COMMANDBAR * sizeof(COMMANDBANDSRESTOREINFO)) {
726 delete []pCmdBarInfo;
727 pCmdBarInfo = pcbi;
728 }
729 #endif
730 RegCloseKey(hTomboRoot);
731 return TRUE;
732 }
733
734 //////////////////////////////////////////
735 // save properties
736 //////////////////////////////////////////
737
738 BOOL SaveMultiSZToFile(File *pFile, LPCTSTR pAttr, LPCTSTR pMValue)
739 {
740 if (pMValue == NULL) return TRUE;
741
742 const char *pMultiPropHdr = " <multistr name=\"";
743 const char *pMultiPropClose = "\">\n";
744 const char *pMultiPropCloseTag = " </multistr>\n";
745 const char *pItemHdr = " <item value=\"";
746 const char *pItemClose = "\"/>\n";
747
748 DWORD nMultiPropHdr = strlen(pMultiPropHdr);
749 DWORD nMultiPropClose = strlen(pMultiPropClose);
750 DWORD nMultiPropCloseTag = strlen(pMultiPropCloseTag);
751 DWORD nItemHdr = strlen(pItemHdr);
752 DWORD nItemClose = strlen(pItemClose);
753
754 if (!pFile->Write((LPBYTE)pMultiPropHdr, nMultiPropHdr)) return FALSE;
755
756 char *pName = ConvUnicode2SJIS(pAttr);
757 if (pName == NULL) return FALSE;
758 if (!pFile->Write((LPBYTE)pName, strlen(pName))) { delete[] pName; return FALSE; }
759 delete[] pName;
760
761 if (!pFile->Write((LPBYTE)pMultiPropClose, nMultiPropClose)) return FALSE;
762
763 LPCTSTR p = pMValue;
764 while(*p) {
765 LPCTSTR pTVal = p;
766 if (!pFile->Write((LPBYTE)pItemHdr, nItemHdr)) return FALSE;
767
768 char *pUTFVal = EscapeXMLStr(pTVal);
769 if (!pFile->Write((LPBYTE)pUTFVal, strlen(pUTFVal))) { delete[] pUTFVal; return FALSE;}
770 delete[] pUTFVal;
771
772 if (!pFile->Write((LPBYTE)pItemClose, nItemClose)) return FALSE;
773 p+= _tcslen(p) + 1;
774 }
775
776 if (!pFile->Write((LPBYTE)pMultiPropCloseTag, nMultiPropCloseTag)) return FALSE;
777 return TRUE;
778 }
779
780 BOOL Property::SaveToFile(File *pFile)
781 {
782 const char *pHeader =
783 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
784 // TODO: DTD
785 "<tomboprop version=\"" TOMBO_PROP_VERSION "\">\n";
786
787 const char *pFooter = "</tomboprop>\n";
788
789 if (!pFile->Write((LPBYTE)pHeader, strlen(pHeader))) return FALSE;
790
791 const char *pNumPropHdr = " <num name=\"";
792 const char *pStrPropHdr = " <str name=\"";
793 const char *pProp2nd = "\" value=\"";
794 const char *pPropLst = "\"/>\n";
795
796 DWORD nNumPropHdr = strlen(pNumPropHdr);
797 DWORD nStrPropHdr = strlen(pStrPropHdr);
798 DWORD nProp2nd = strlen(pProp2nd);
799 DWORD nPropLst = strlen(pPropLst);
800
801 char buf[128];
802
803 const char *pTomboRootStart = " <tomboroot>\n";
804 const char *pTomboRootEnd = " </tomboroot>\n";
805
806 if (!pFile->Write((LPBYTE)pTomboRootStart, strlen(pTomboRootStart))) return FALSE;
807 for (DWORD i = 0; i < g_Repository.GetNumOfSubRepository(); i++) {
808 LPTSTR pSaveStr = g_Repository.GetSubRepoXMLSaveString(i);
809 AutoPointer<TCHAR> ap(pSaveStr);
810 if (pSaveStr == NULL) return FALSE;
811 char *pSaveStrA = ConvTCharToUTF8(pSaveStr);
812 AutoPointer<char> ap2(pSaveStrA);
813
814 if (!pFile->Write((LPBYTE)pSaveStrA, strlen(pSaveStrA))) return FALSE;
815 }
816 if (!pFile->Write((LPBYTE)pTomboRootEnd, strlen(pTomboRootEnd))) return FALSE;
817
818
819 // save number props.
820 PropListNum *pNum = propListNum;
821 while (pNum->nPropId != 0xFFFFFFFF) {
822
823 if (!pFile->Write((LPBYTE)pNumPropHdr, nNumPropHdr)) return FALSE;
824
825 char *pName = ConvUnicode2SJIS(pNum->pAttrName);
826 if (pName == NULL) return FALSE;
827 if (!pFile->Write((LPBYTE)pName, strlen(pName))) { delete[] pName; return FALSE; }
828 delete[] pName;
829
830 if (!pFile->Write((LPBYTE)pProp2nd, nProp2nd)) return FALSE;
831
832 DWORD nValue = nPropsNum[pNum->nPropId];
833 sprintf(buf, "%d", nValue);
834 if (!pFile->Write((LPBYTE)buf, strlen(buf))) return FALSE;
835
836 if (!pFile->Write((LPBYTE)pPropLst, nPropLst)) return FALSE;
837
838 pNum++;
839 }
840
841 // save string props.
842 PropListStr *pStr = propListStr;
843 while (pStr->nPropId != 0xFFFFFFFF) {
844 if (pPropsStr[pStr->nPropId] == NULL) {
845 pStr++;
846 continue;
847 }
848
849 if (!pFile->Write((LPBYTE)pStrPropHdr, nStrPropHdr)) return FALSE;
850
851 char *pName = ConvUnicode2SJIS(pStr->pAttrName);
852 if (pName == NULL) return FALSE;
853 if (!pFile->Write((LPBYTE)pName, strlen(pName))) { delete[] pName; return FALSE; }
854 delete[] pName;
855
856 if (!pFile->Write((LPBYTE)pProp2nd, nProp2nd)) return FALSE;
857
858 char *pVal = EscapeXMLStr(pPropsStr[pStr->nPropId]);
859 if (pVal == NULL) return FALSE;
860 if (!pFile->Write((LPBYTE)pVal, strlen(pVal))) { delete[] pVal; return FALSE; }
861 delete[] pVal;
862
863 if (!pFile->Write((LPBYTE)pPropLst, nPropLst)) return FALSE;
864 pStr++;
865 }
866
867 // save multi value
868 if (!SaveMultiSZToFile(pFile, BOOKMARK_ATTR_NAME, pBookMark)) return FALSE;
869 if (!SaveMultiSZToFile(pFile, SEARCHHIST_ATTR_NAME, pSearchHistory)) return FALSE;
870 if (!SaveMultiSZToFile(pFile, TOPDIRHIST_ATTR_NAME, pTopDirHistory)) return FALSE;
871
872 #if defined(PLATFORM_HPC)
873 if (pCmdBarInfo != NULL) {
874 LPCOMMANDBANDSRESTOREINFO p1 = pCmdBarInfo;
875 LPCOMMANDBANDSRESTOREINFO p2 = pCmdBarInfo + 1;
876
877 char aCmdBarBuf[1024];
878 sprintf(aCmdBarBuf, "%d,%d,%d,%d,%d,%d,%d,%d",
879 p1->wID, p1->fStyle, p1->cxRestored, p1->fMaximized,
880 p2->wID, p2->fStyle, p2->cxRestored, p2->fMaximized);
881
882 const char *pRebarPropHdr = " <rebar value=\"";
883 if (!pFile->Write((LPBYTE)pRebarPropHdr, strlen(pRebarPropHdr))) return FALSE;
884 if (!pFile->Write((LPBYTE)aCmdBarBuf, strlen(aCmdBarBuf))) return FALSE;
885 if (!pFile->Write((LPBYTE)pPropLst, nPropLst)) return FALSE;
886 }
887 #endif
888
889 // footer
890 if (!pFile->Write((LPBYTE)pFooter, strlen(pFooter))) return FALSE;
891 return TRUE;
892 }
893
894 BOOL Property::Save()
895 {
896
897 TCHAR pathbuf[MAX_PATH + 1];
898 TCHAR pathbuf2[MAX_PATH + 1];
899 GetModuleFileName(NULL, pathbuf, MAX_PATH);
900 GetFilePath(pathbuf2, pathbuf);
901 TString sPropFile, sPropFileTmp;
902 if (!sPropFile.Join(pathbuf2, PROP_FILE_NAME)) return FALSE;
903 if (!sPropFileTmp.Join(pathbuf2, PROP_TMP_FILE_NAME)) return FALSE;
904
905 File propFile;
906 if (!propFile.Open(sPropFileTmp.Get(), GENERIC_WRITE, FILE_SHARE_WRITE, CREATE_ALWAYS)) return FALSE;
907
908 if (!SaveToFile(&propFile)) {
909 return FALSE;
910 } else {
911 propFile.Close();
912 DeleteFile(sPropFile.Get());
913 MoveFile(sPropFileTmp.Get(), sPropFile.Get());
914 }
915 return TRUE;
916 }
917
918 //////////////////////////////////////////
919 // Registry operations
920 //////////////////////////////////////////
921
922 static DWORD GetDWORDFromReg(HKEY hKey, LPCTSTR pAttr, DWORD nDefault)
923 {
924 DWORD siz = sizeof(DWORD);
925 DWORD typ;
926 DWORD nValue;
927 DWORD res = RegQueryValueEx(hKey, pAttr, NULL, &typ, (LPBYTE)&nValue, &siz);
928 if (res != ERROR_SUCCESS) {
929 return nDefault;
930 }
931 return nValue;
932 }
933
934 static BOOL GetSZFromReg(HKEY hKey, LPCTSTR pAttr, LPTSTR pBuf, DWORD nBuf, LPCTSTR pDefault)
935 {
936 DWORD res, siz, typ;
937 siz = nBuf;
938 res = RegQueryValueEx(hKey, pAttr, NULL, &typ, (LPBYTE)pBuf, &siz);
939 if (res != ERROR_SUCCESS) {
940 if (res == ERROR_FILE_NOT_FOUND) {
941 _tcscpy(pBuf, pDefault);
942 return TRUE;
943 } else {
944 SetLastError(res);
945 return FALSE;
946 }
947 }
948 return TRUE;
949 }
950
951 static LPTSTR GetAllocSZFromReg(HKEY hKey, LPCTSTR pAttr)
952 {
953 DWORD res, siz, typ;
954 siz = 0;
955 res = RegQueryValueEx(hKey, pAttr, NULL, &typ, NULL, &siz);
956 if (res != ERROR_SUCCESS) {
957 SetLastError(res);
958 return FALSE;
959 }
960 LPTSTR p = new TCHAR[siz / sizeof(TCHAR) + 1];
961 res = RegQueryValueEx(hKey, pAttr, NULL, &typ, (LPBYTE)p, &siz);
962 if (res != ERROR_SUCCESS) {
963 SetLastError(res);
964 return FALSE;
965 }
966 return p;
967 }
968
969 static LPTSTR GetMultiSZFromReg(HKEY hKey, LPCTSTR pAttr)
970 {
971 DWORD res, siz, typ;
972 res = RegQueryValueEx(hKey, pAttr, NULL, &typ, NULL, &siz);
973 if (res != ERROR_SUCCESS) {
974 SetLastError(res);
975 return NULL;
976 }
977
978 LPTSTR pBuf;
979 DWORD n = siz / sizeof(TCHAR) + 1;
980 pBuf = new TCHAR[n];
981 if (pBuf == NULL) {
982 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
983 return NULL;
984 }
985 memset(pBuf, 0, n * sizeof(TCHAR));
986 res = RegQueryValueEx(hKey, pAttr, NULL, &typ, (LPBYTE)pBuf, &siz);
987 if (res != ERROR_SUCCESS) {
988 delete[] pBuf;
989 SetLastError(res);
990 return NULL;
991 }
992 return pBuf;
993 }
994
995 ///////////////////////////////////////////////////
996 // get font
997 ///////////////////////////////////////////////////
998
999 static BOOL MakeFont(HFONT *phFont, LPCTSTR pName, DWORD nSize, BYTE bQuality)
1000 {
1001 if (nSize == 0xFFFFFFFF) {
1002 *phFont = NULL;
1003 return TRUE;
1004 }
1005 LOGFONT lf;
1006 lf.lfHeight = nSize;
1007 lf.lfWidth = 0;
1008 lf.lfEscapement = 0;
1009 lf.lfOrientation = 0;
1010 lf.lfWeight = FW_NORMAL;
1011 lf.lfItalic = FALSE;
1012 lf.lfUnderline = FALSE;
1013 lf.lfStrikeOut = FALSE;
1014 lf.lfCharSet = DEFAULT_CHARSET;
1015 lf.lfOutPrecision = OUT_DEFAULT_PRECIS;
1016 lf.lfClipPrecision = CLIP_DEFAULT_PRECIS;
1017 lf.lfQuality = bQuality;
1018 lf.lfPitchAndFamily = DEFAULT_PITCH;
1019 _tcscpy(lf.lfFaceName, pName);
1020 *phFont = CreateFontIndirect(&lf);
1021 return *phFont != NULL;
1022 }
1023
1024 ///////////////////////////////////////////////////
1025 // save window size
1026 ///////////////////////////////////////////////////
1027
1028 BOOL Property::SaveWinSize(UINT flags, UINT showCmd, LPRECT pWinRect, WORD nSelectViewWidth)
1029 {
1030 TCHAR buf[1024];
1031
1032 wsprintf(buf, TEXT("%d,%d,%d,%d,%d,%d,%d"),
1033 flags, showCmd,
1034 pWinRect->left, pWinRect->top,
1035 pWinRect->right, pWinRect->bottom,
1036 nSelectViewWidth);
1037
1038 delete [] pPropsStr[PROP_S_WINSIZE];
1039 pPropsStr[PROP_S_WINSIZE] = StringDup(buf);
1040 return TRUE;
1041 }
1042
1043 ///////////////////////////////////////////////////
1044 // get window size
1045 ///////////////////////////////////////////////////
1046
1047 BOOL Property::GetWinSize(UINT *pFlags, UINT *pShowCmd, LPRECT pWinRect, LPWORD pSelectViewWidth)
1048 {
1049 if (pPropsStr[PROP_S_WINSIZE] == NULL) {
1050 SetLastError(ERROR_INVALID_DATA);
1051 return FALSE;
1052 }
1053
1054 DWORD n;
1055 if (_stscanf(pPropsStr[PROP_S_WINSIZE], TEXT("%d,%d,%d,%d,%d,%d,%d"),
1056 pFlags, pShowCmd,
1057 &(pWinRect->left), &(pWinRect->top),
1058 &(pWinRect->right), &(pWinRect->bottom),
1059 &n) != 7) {
1060 SetLastError(ERROR_INVALID_DATA);
1061 return FALSE;
1062 }
1063 *pSelectViewWidth = (WORD)n;
1064 // check and modify window position
1065 if (pWinRect->left < 0) pWinRect->left = 0;
1066 if (pWinRect->top < 0) pWinRect->top = 0;
1067
1068 return TRUE;
1069 }
1070
1071 ///////////////////////////////////////////////////
1072 // helper funcs
1073 ///////////////////////////////////////////////////
1074
1075 static HKEY GetTomboRootKey()
1076 {
1077 DWORD res;
1078 HKEY hTomboRoot;
1079
1080 res = RegOpenKeyEx(HKEY_CURRENT_USER, TOMBO_MAIN_KEY, 0, KEY_READ, &hTomboRoot);
1081 if (res != ERROR_SUCCESS) {
1082 SetLastError(res);
1083 return NULL;
1084 }
1085 return hTomboRoot;
1086 }
1087
1088 ////////////////////////////////////////////////////////////////
1089 // Get/Set History from/to ComboBox
1090 ////////////////////////////////////////////////////////////////
1091
1092 BOOL SetHistoryToComboBox(HWND hCombo, LPCTSTR pHistoryStr)
1093 {
1094 if (pHistoryStr == NULL) return TRUE;
1095
1096 LPCTSTR p = pHistoryStr;
1097 LPCTSTR q = p;
1098 while(*q) {
1099 SendMessage(hCombo, CB_ADDSTRING, 0, (LPARAM)q);
1100 q += _tcslen(q) + 1;
1101 }
1102 SendMessage(hCombo, CB_SETCURSEL, 0, 0);
1103 return TRUE;
1104 }
1105
1106 LPTSTR GetHistoryFromComboBox(HWND hCombo, LPCTSTR pSelValue, DWORD nSave)
1107 {
1108 DWORD nItems = SendMessage(hCombo, CB_GETCOUNT, 0, 0);
1109 if (nItems > nSave) nItems = nSave;
1110
1111 DWORD i;
1112 DWORD nMatch = SendMessage(hCombo, CB_FINDSTRINGEXACT, (WPARAM)-1, (LPARAM)pSelValue);
1113
1114 DWORD nBufLen = _tcslen(pSelValue) + 1;
1115 DWORD nLen;
1116 for (i = 0; i < nItems; i++) {
1117 if (i == nMatch) continue;
1118
1119 nLen = SendMessage(hCombo, CB_GETLBTEXTLEN, i, 0);
1120 if (nLen == CB_ERR) return FALSE;
1121 nBufLen += nLen + 1;
1122 }
1123 nBufLen++;
1124
1125 LPTSTR p = new TCHAR[nBufLen];
1126 if (!p) {
1127 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
1128 return FALSE;
1129 }
1130
1131 LPTSTR q = p;
1132 _tcscpy(q, pSelValue);
1133 q += _tcslen(pSelValue) + 1;
1134 for (i = 0; i < nItems; i++) {
1135 if (i == nMatch) continue;
1136 SendMessage(hCombo, CB_GETLBTEXT, i, (LPARAM)q);
1137 q += _tcslen(q) + 1;
1138 }
1139 *q = TEXT('\0');
1140 return p;
1141 }
1142
1143 #if defined(PLATFORM_HPC)
1144 BOOL Property::SetCommandbarInfo(LPCOMMANDBANDSRESTOREINFO p)
1145 {
1146 delete[] pCmdBarInfo;
1147 pCmdBarInfo = new COMMANDBANDSRESTOREINFO[NUM_COMMANDBAR];
1148 memcpy(pCmdBarInfo, p, sizeof(COMMANDBANDSRESTOREINFO) * NUM_COMMANDBAR);
1149 return TRUE;
1150 }
1151
1152 BOOL Property::GetCommandbarInfo(LPCOMMANDBANDSRESTOREINFO p, DWORD n)
1153 {
1154 if (pCmdBarInfo == NULL) return FALSE;
1155 memcpy(p, pCmdBarInfo, sizeof(COMMANDBANDSRESTOREINFO) * NUM_COMMANDBAR);
1156 return TRUE;
1157 }
1158
1159 #endif
1160
1161 BOOL Property::SetCmdLineAssignedTomboRoot(LPCTSTR p, DWORD nLen)
1162 {
1163 pCmdlineAssignedTopDir = new TCHAR[nLen + 1];
1164 if (!pCmdlineAssignedTopDir) return FALSE;
1165 _tcsncpy(pCmdlineAssignedTopDir, p, nLen);
1166 pCmdlineAssignedTopDir[nLen] = TEXT('\0');
1167 ChopFileSeparator(pCmdlineAssignedTopDir);
1168 return TRUE;
1169 }
1170
1171 static DWORD CountMultiSZLen(LPCTSTR pData)
1172 {
1173 if (pData == NULL) return 0;
1174 LPCTSTR p = pData;
1175 DWORD n = 0;
1176 while(*p) {
1177 DWORD i = _tcslen(p) + 1;
1178 p += i;
1179 n += i;
1180 }
1181 n++;
1182 return n;
1183 }
1184
1185 ///////////////////////////////////////////////////
1186 // BookMark
1187 ///////////////////////////////////////////////////
1188
1189 BOOL Property::SetBookMark(LPCTSTR pBM)
1190 {
1191 DWORD nSize = CountMultiSZLen(pBM);
1192
1193 LPTSTR pBuf = new TCHAR[nSize];
1194 if (pBuf == NULL) return FALSE;
1195 for (DWORD i = 0; i < nSize; i++) {
1196 pBuf[i] = pBM[i];
1197 }
1198 delete[] pBookMark;
1199
1200 pBookMark = pBuf;
1201 return TRUE;
1202 }
1203
1204 ///////////////////////////////////////////////////
1205 // Code conversion related
1206 ///////////////////////////////////////////////////
1207
1208 LPBYTE ConvTCharToFileEncoding(LPCTSTR p, LPDWORD pSize)
1209 {
1210 LPBYTE pData;
1211
1212 switch (g_Property.GetCodePage()) {
1213 case TOMBO_CP_UTF16LE:
1214 pData = (LPBYTE)ConvTCharToWChar(p);
1215 if (pData == NULL) return FALSE;
1216 *pSize = wcslen((LPCWSTR)pData) * sizeof(WCHAR);
1217 break;
1218 case TOMBO_CP_UTF8:
1219 pData = (LPBYTE)ConvTCharToUTF8(p);
1220 if (pData == NULL) return FALSE;
1221 *pSize = strlen((const char*)pData);
1222 break;
1223 default:
1224 pData = (LPBYTE)ConvUnicode2SJIS(p);
1225 if (pData == NULL) return FALSE;
1226 *pSize = strlen((const char*)pData);
1227 }
1228 return pData;
1229 }
1230
1231 LPTSTR ConvFileEncodingToTChar(LPBYTE p)
1232 {
1233 switch (g_Property.GetCodePage()) {
1234 case TOMBO_CP_UTF16LE:
1235 return ConvWCharToTChar((LPCWSTR)p);
1236 case TOMBO_CP_UTF8:
1237 return ConvUTF8ToTChar((const char*)p);
1238 default:
1239 return ConvSJIS2Unicode((const char*)p);
1240 }
1241 }
1242
1243 RepositoryImpl *Property::GetSubRepository(DWORD nIndex)
1244 {
1245 RepositoryImpl *pImpl = pRepos[nIndex];
1246 if (pImpl == NULL) return NULL;
1247 return pImpl->Clone();
1248 }
1249
1250 DWORD Property::GetKeepCaret()
1251 {
1252 if (pDefaultRep) return pDefaultRep->GetKeepCaret();
1253 else return nPropsNum[PROP_N_DETAILSVIEW_KEEPCARET];
1254 }
1255
1256 void Property::SetKeepCaret(DWORD n)
1257 {
1258 if (pDefaultRep) pDefaultRep->SetKeepCaret(n);
1259 nPropsNum[PROP_N_DETAILSVIEW_KEEPCARET] = n;
1260 }
1261
1262 DWORD Property::GetUseSafeFileName()
1263 {
1264 if (pDefaultRep) return pDefaultRep->GetSafeFileName();
1265 else return nPropsNum[PROP_N_SAFEFILENAME];
1266 }
1267
1268 void Property::SetUseSafeFileName(DWORD n)
1269 {
1270 if (pDefaultRep) pDefaultRep->SetSafeFileName(n);
1271 nPropsNum[PROP_N_SAFEFILENAME] = n;
1272 }
1273
1274 DWORD Property::GetKeepTitle()
1275 {
1276 if (pDefaultRep) return pDefaultRep->GetKeepTitle();
1277 else return nPropsNum[PROP_N_KEEP_TITLE];
1278 }
1279
1280 void Property::SetKeepTitle(DWORD n)
1281 {
1282 if (pDefaultRep) pDefaultRep->SetKeepTitle(n);
1283 nPropsNum[PROP_N_KEEP_TITLE] = n;
1284 }
1285

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26