Develop and Download Open Source Software

Browse CVS Repository

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

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


Revision 1.36 - (show annotations) (download) (as text)
Sun Aug 27 11:11:36 2006 UTC (17 years, 7 months ago) by hirami
Branch: MAIN
CVS Tags: Tombo_2_0b2, Tombo_2_0b3, Tombo_2_0b1, Tombo_2_0b4, B228, B229, B226, B227, B224, B225, B231, B230, HEAD
Changes since 1.35: +2 -2 lines
File MIME type: text/x-c++src
- Create new project for WM5 platform.
	In current version, feature is same as PocketPC.

1 #include <windows.h>
2 #include <commctrl.h>
3 #include <tchar.h>
4 #if defined(PLATFORM_PKTPC) || defined(PLATFORM_WM5)
5 #include <aygshell.h>
6 #endif
7 #include "Tombo.h"
8 #include "AutoPtr.h"
9 #include "VarBuffer.h"
10 #include "MainFrame.h"
11 #include "MemoDetailsView.h"
12 #include "resource.h"
13 #include "TString.h"
14 #include "UniConv.h"
15 #include "Property.h"
16 #include "SearchEngine.h"
17 #include "Message.h"
18 #include "TomboURI.h"
19 #include "Repository.h"
20 #include "MemoManager.h"
21
22 #define KEY_COLON 0xBB
23 #define KEY_SEMICOLON 0xBA
24
25 static BOOL GetDateText(TString *pInsStr, LPCTSTR pFormat, TString *pPath);
26
27 void SetWndProc(SUPER_WND_PROC wp);
28 LRESULT CALLBACK NewDetailsViewProc( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam );
29
30 LPCTSTR pMonth[12] = {
31 TEXT("Jan"), TEXT("Feb"), TEXT("Mar"), TEXT("Apr"),
32 TEXT("May"), TEXT("Jun"), TEXT("Jul"), TEXT("Aug"),
33 TEXT("Sep"), TEXT("Oct"), TEXT("Nov"), TEXT("Dec")
34 };
35
36 LPCTSTR pWeekJ[7] = {
37 TEXT("“ú"), TEXT("ŒŽ"), TEXT("‰Î"), TEXT("…"), TEXT("–Ř"), TEXT("‹ŕ"), TEXT("“y")
38 };
39
40 LPCTSTR pWeekE[7] = {
41 TEXT("Sun"), TEXT("Mon"), TEXT("Tue"), TEXT("Wed"), TEXT("Thr"), TEXT("Fri"), TEXT("Sat")
42 };
43
44 ///////////////////////////////////////////
45 //
46 ///////////////////////////////////////////
47
48 MemoDetailsView::MemoDetailsView(MemoManager *pMgr) : pCurrentURI(NULL), pManager(pMgr)
49 {
50 }
51
52 MemoDetailsView::~MemoDetailsView()
53 {
54 delete pCurrentURI;
55 }
56
57 const TomboURI* MemoDetailsView::GetCurrentURI()
58 {
59 return pCurrentURI;
60 }
61
62 void MemoDetailsView::SetCurrentNote(const TomboURI *pURI)
63 {
64 if (pCurrentURI == pURI) return;
65 delete pCurrentURI;
66 pCurrentURI = NULL;
67
68 if (pURI) {
69 pCurrentURI = new TomboURI(*pURI);
70 }
71 }
72
73 ///////////////////////////////////////////
74 // Discard current note
75 ///////////////////////////////////////////
76 //
77 // note is discarded even if it is modifying.
78
79 BOOL MemoDetailsView::DiscardMemo()
80 {
81 SetMemo(TEXT(""), 0, FALSE);
82 SetCurrentNote(NULL);
83 SetReadOnly(FALSE);
84 pManager->GetMainFrame()->SetNewMemoStatus(TRUE);
85 pManager->GetMainFrame()->SetWindowTitle(NULL);
86 return TRUE;
87 }
88
89
90 BOOL MemoDetailsView::StoreCursorPos()
91 {
92 if (g_Property.GetKeepCaret()) {
93
94 DWORD nPos = GetCursorPos();
95 DWORD nInitPos = GetInitialPos();
96
97 if (pCurrentURI && nPos != nInitPos) {
98 NoteAttribute attr;
99 attr.nCursorPos = nPos;
100 if (!g_Repository.SetAttribute(pCurrentURI, &attr)) return FALSE;
101 }
102 }
103 return TRUE;
104 }
105
106 BOOL MemoDetailsView::Save(const TomboURI *pCurrentURI, TomboURI *pNewURI, TString *pNewHeadLine, LPCTSTR pText)
107 {
108 if (!g_Repository.Update(pCurrentURI, pText, pNewURI, pNewHeadLine)) return FALSE;
109 ResetModify();
110 pManager->GetMainFrame()->SetModifyStatus(FALSE);
111 SetCurrentNote(pNewURI);
112 return TRUE;
113 }
114
115 BOOL MemoDetailsView::LoadNote(const TomboURI *pURI)
116 {
117 // load note data and attribute
118 LPTSTR p = g_Repository.GetNoteData(pURI);
119 if (p == NULL) {
120 SetMemo(MSG_CANT_OPEN_MEMO, 0, TRUE);
121 return TRUE;
122 }
123 SecureBufferAutoPointerT sp(p);
124
125 NoteAttribute attr;
126 if (!g_Repository.GetAttribute(pURI, &attr)) return FALSE;
127
128 // set memo to view
129 SetMemo(p, attr.nCursorPos, attr.bReadOnly);
130 SetCurrentNote(pURI);
131
132 return TRUE;
133 }
134
135 ////////////////////////////////////////////////////////
136 // Is this note are displayed in detailsview?
137 ////////////////////////////////////////////////////////
138
139 BOOL MemoDetailsView::IsNoteDisplayed(const TomboURI *pURI)
140 {
141 if (GetCurrentURI() == NULL) return FALSE;
142 return _tcsicmp(pURI->GetFullURI(), GetCurrentURI()->GetFullURI()) == 0;
143 }
144
145 ////////////////////////////////////////////////////////
146 // insert date
147 ////////////////////////////////////////////////////////
148
149 void MemoDetailsView::InsertDate1()
150 {
151 TString sDate;
152
153 TString sPathStr;
154 pManager->GetCurrentSelectedPath(&sPathStr);
155
156 if (!GetDateText(&sDate, g_Property.GetDateFormat1(), &sPathStr)) {
157 TomboMessageBox(NULL, MSG_GET_DATE_FAILED, TEXT("ERROR"), MB_ICONERROR | MB_OK);
158 return;
159 }
160 ReplaceText(sDate.Get());
161 }
162
163 void MemoDetailsView::InsertDate2()
164 {
165 TString sDate;
166
167 TString sPathStr;
168 pManager->GetCurrentSelectedPath(&sPathStr);
169
170 if (!GetDateText(&sDate, g_Property.GetDateFormat2(), &sPathStr)) {
171 TomboMessageBox(NULL, MSG_GET_DATE_FAILED, TEXT("ERROR"), MB_ICONERROR | MB_OK);
172 return;
173 }
174 ReplaceText(sDate.Get());
175 }
176
177 /////////////////////////////////////////
178 // ŒŸő
179 /////////////////////////////////////////
180 //
181 // RESULT: return TRUE if matched.
182 //
183 // bFirstSearch : ŒŸőŠJŽnˆĘ’u: TRUE = ƒƒ‚ć“Ş FALSE = ŒťÝ‚ĚƒJ[ƒ\ƒ‹ˆĘ’u + 1
184 // bForward : ŒŸő‚ĚŒü‚Ť: TRUE = ‡•űŒü FALSE = ‹t•űŒü
185 // bNFMsg: ŒŠ‚Â‚Š‚ç‚ȂЂÁ‚˝ę‡‚ɃƒbƒZ[ƒW‚đo‚ˇ‚Š
186 // pFound: if string is found, set TRUE otherwise set FALSE.
187
188
189 BOOL MemoDetailsView::Search(BOOL bFirstSearch, BOOL bForward, BOOL bNFMsg, BOOL bSearchFromTop)
190 {
191 SearchEngineA *pSE;
192 pSE = pManager->GetSearchEngine();
193 if (pSE == NULL) return FALSE;
194
195 LPTSTR pT = GetMemo();
196 SecureBufferAutoPointerT sb(pT);
197
198 DWORD nSearchStart;
199 BOOL bShift = FALSE;
200
201 if (bFirstSearch) {
202 nSearchStart = 0;
203 } else {
204 nSearchStart = GetCursorPos();
205 bShift = TRUE;
206 }
207
208 BOOL bMatch;
209 bMatch = pSE->SearchTextT(pT, nSearchStart, bForward, bShift);
210
211 if (bMatch) {
212 DWORD nStart = pSE->MatchStart();
213 DWORD nEnd = pSE->MatchEnd();
214
215 SetSelectRegion(nStart, nEnd);
216 } else {
217 if (bNFMsg) MessageBox(NULL, MSG_STRING_NOT_FOUND, TOMBO_APP_NAME, MB_OK | MB_ICONINFORMATION);
218 }
219
220 return bMatch;
221 }
222
223 ///////////////////////////////////////////
224 // initializer
225 ///////////////////////////////////////////
226
227 SimpleEditor::SimpleEditor(MemoManager *pMgr) : MemoDetailsView(pMgr), hViewWnd(NULL)
228 {
229 }
230
231
232 BOOL SimpleEditor::Init(DWORD id, DWORD id_nf)
233 {
234 nID = id;
235 nID_nf = id_nf;
236 return TRUE;
237 }
238
239 extern SUPER_WND_PROC gDefaultProc;
240 extern DWORD gDelta;
241 LRESULT CALLBACK DetailsViewSuperProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam );
242
243 BOOL SimpleEditor::RegisterClass(HINSTANCE hInst)
244 {
245 // superclassing
246 WNDCLASS wc;
247 GetClassInfo(hInst, TEXT("EDIT"), &wc);
248
249 wc.hInstance = hInst;
250 wc.lpszClassName = TEXT("TomboSimpleEditor");
251 gDelta = wc.cbWndExtra;
252 wc.cbWndExtra = ((wc.cbWndExtra + sizeof(MemoDetailsView*)) / 4 + 1)* 4;
253
254 gDefaultProc = (SUPER_WND_PROC)wc.lpfnWndProc;
255
256 wc.lpfnWndProc = DetailsViewSuperProc;
257
258 return ::RegisterClass(&wc) != 0;
259 }
260 ///////////////////////////////////////////
261 // Create window
262 ///////////////////////////////////////////
263 extern HINSTANCE g_hInstance;
264
265 BOOL SimpleEditor::Create(LPCTSTR pName, RECT &r, HWND hParent, HINSTANCE hInst, HFONT hFont)
266 {
267 DWORD nWndStyle;
268
269 nWndStyle = WS_CHILD | WS_VSCROLL | ES_MULTILINE | ES_WANTRETURN;
270
271 #if defined(PLATFORM_PSPC) || defined(PLATFORM_BE500)
272 // nLeftOffset = 3;
273 // for draw border, left offset has disabled.
274 nLeftOffset = 0;
275 #else
276 nLeftOffset = 0;
277 #endif
278
279 #if defined(PLATFORM_WIN32) || defined(PLATFORM_HPC)
280 hViewWnd_fd = CreateWindowEx(WS_EX_CLIENTEDGE, TEXT("TomboSimpleEditor"), pName, nWndStyle,
281 r.left + nLeftOffset, r.top, r.right - nLeftOffset, r.bottom,
282 hParent, (HMENU)nID, hInst, this);
283 hViewWnd_nf = CreateWindowEx(WS_EX_CLIENTEDGE, TEXT("TomboSimpleEditor"), pName, nWndStyle | ES_AUTOHSCROLL | WS_HSCROLL,
284 r.left + nLeftOffset, r.top, r.right - nLeftOffset, r.bottom,
285 hParent, (HMENU)nID_nf, hInst, this);
286 #else
287 hViewWnd_fd = CreateWindow(TEXT("TomboSimpleEditor"), pName, nWndStyle | WS_BORDER,
288 r.left + nLeftOffset, r.top, r.right - nLeftOffset, r.bottom,
289 hParent, (HMENU)nID, hInst, this);
290 hViewWnd_nf = CreateWindow(TEXT("TomboSimpleEditor"), pName, nWndStyle | ES_AUTOHSCROLL | WS_HSCROLL | WS_BORDER,
291 r.left + nLeftOffset, r.top, r.right - nLeftOffset, r.bottom,
292 hParent, (HMENU)nID_nf, hInst, this);
293 #endif
294 if (hViewWnd_fd == NULL || hViewWnd_nf == NULL) return FALSE;
295 hViewWnd = hViewWnd_fd;
296
297 // sub classing of edit control
298 SUPER_WND_PROC wp = (SUPER_WND_PROC)GetWindowLong(hViewWnd, GWL_WNDPROC);
299 SetWndProc(wp);
300 SetWindowLong(hViewWnd_nf, GWL_WNDPROC, (LONG)NewDetailsViewProc);
301 SetWindowLong(hViewWnd_fd, GWL_WNDPROC, (LONG)NewDetailsViewProc);
302
303 if (hFont != NULL) {
304 SetFont(hFont);
305 }
306 SetTabstop();
307 return TRUE;
308 }
309
310 ///////////////////////////////////////////
311 // hide/show window
312 ///////////////////////////////////////////
313
314 BOOL SimpleEditor::Show(int nCmdShow)
315 {
316 ShowWindow(hViewWnd, nCmdShow);
317 if (nCmdShow == SW_SHOW) {
318 bShowStatus = TRUE;
319 } else if (nCmdShow == SW_HIDE) {
320 bShowStatus = FALSE;
321 }
322
323 #if defined(PLATFORM_PKTPC) || defined(PLATFORM_WM5)
324 // ƒ^ƒbƒv&ƒz[ƒ‹ƒhƒƒjƒ…[‚ޏo‚˝‚܂܉ć–Ę‚ŞŘ‚č‘Ö‚í‚Á‚˝Ű‚Ƀƒjƒ…[‚đ•‚ś‚ł‚š‚é
325 if (nCmdShow == SW_HIDE) {
326 ReleaseCapture();
327 }
328 #endif
329 return UpdateWindow(hViewWnd);
330 }
331
332 ///////////////////////////////////////////
333 // ƒEƒBƒ“ƒhƒEƒTƒCƒY‚ĚˆÚ“Ž
334 ///////////////////////////////////////////
335
336 void SimpleEditor::MoveWindow(DWORD x, DWORD y, DWORD nWidth, DWORD nHeight)
337 {
338 ::MoveWindow(hViewWnd_nf, x + nLeftOffset, y, nWidth - nLeftOffset, nHeight, TRUE);
339 ::MoveWindow(hViewWnd_fd, x + nLeftOffset, y, nWidth - nLeftOffset, nHeight, TRUE);
340 }
341
342 ///////////////////////////////////////////
343 // OnCommand‚̏ˆ—
344 ///////////////////////////////////////////
345
346 BOOL SimpleEditor::OnCommand(HWND hWnd, WPARAM wParam, LPARAM lParam)
347 {
348 switch(LOWORD(wParam)) {
349 case IDM_CUT:
350 SendMessage(hViewWnd, WM_CUT, 0, 0);
351 return TRUE;
352 case IDM_COPY:
353 SendMessage(hViewWnd, WM_COPY, 0, 0);
354 return TRUE;
355 case IDM_PASTE:
356 SendMessage(hViewWnd, WM_PASTE, 0, 0);
357 return TRUE;
358 case IDM_UNDO:
359 SendMessage(hViewWnd, WM_UNDO, 0, 0);
360 return TRUE;
361 case IDM_ACTIONBUTTON:
362 PostMessage(hWnd, WM_COMMAND, MAKEWPARAM(IDM_RETURNLIST, 0), 0);
363 return TRUE;
364 case IDM_INSDATE1:
365 {
366 InsertDate1();
367 return TRUE;
368 }
369 case IDM_INSDATE2:
370 {
371 InsertDate2();
372 return TRUE;
373 }
374 case IDM_TOGGLEREADONLY:
375 {
376 SetReadOnly(!IsReadOnly());
377 return FALSE;
378 }
379 }
380
381 return FALSE;
382 }
383
384 ///////////////////////////////////////////
385 // ƒzƒbƒgƒL[‚̏ˆ—
386 ///////////////////////////////////////////
387
388 BOOL SimpleEditor::OnHotKey(HWND hWnd, WPARAM wParam)
389 {
390 switch(wParam) {
391 case APP_BUTTON1:
392 /* fall through */
393 case APP_BUTTON2:
394 /* fall through */
395 case APP_BUTTON3:
396 /* fall through */
397 case APP_BUTTON4:
398 /* fall through */
399 case APP_BUTTON5:
400 PostMessage(hWnd, WM_COMMAND, MAKEWPARAM(IDM_RETURNLIST, 0), 0);
401 return TRUE;
402 default:
403 return FALSE;
404 }
405 }
406
407 ///////////////////////////////////////////
408 // Key handler
409 ///////////////////////////////////////////
410 UINT SimpleEditor::OnKeyDown(HWND hWnd, WPARAM wParam, LPARAM lParam)
411 {
412 BOOL bShiftDown = (GetKeyState(VK_SHIFT) & 0x8000) != 0;
413 BOOL bCtrlKeyDown = (GetKeyState(VK_CONTROL) & 0x8000) != 0;
414
415 #if defined(PLATFORM_SIG3)
416 if (bShiftDown && wParam == VK_UP) {
417 INT nPrevStart, nPrevEnd;
418 INT nAftStart, nAftEnd;
419 SendMessage(hWnd, EM_GETSEL, (WPARAM)&nPrevStart, (LPARAM)&nPrevEnd);
420 LRESULT lResult = CallWindowProc(gSuperProc, hWnd, msg, wParam, lParam);
421 SendMessage(hWnd, EM_GETSEL, (WPARAM)&nAftStart, (LPARAM)&nAftEnd);
422
423 if (nAftStart < nSelBase) {
424 SendMessage(hwnd, EM_SETSEL, (WPARAM)nSelBase, (LPARAM)nAftStart);
425 return lResult;
426 } else {
427 return lResult;
428 }
429 }
430 if (bShiftDown && wParam == VK_DOWN) {
431 INT nPrevStart, nPrevEnd;
432 INT nAftStart, nAftEnd;
433 SendMessage(hwnd, EM_GETSEL, (WPARAM)&nPrevStart, (LPARAM)&nPrevEnd);
434 LRESULT lResult = CallWindowProc(gSuperProc, hwnd, msg, wParam, lParam);
435 SendMessage(hwnd, EM_GETSEL, (WPARAM)&nAftStart, (LPARAM)&nAftEnd);
436
437 if (nAftStart < nSelBase) {
438 SendMessage(hwnd, EM_SETSEL, (WPARAM)nSelBase, (LPARAM)nAftEnd);
439 return lResult;
440 } else {
441 return lResult;
442 }
443 }
444
445 if (!(bShiftDown && wParam == VK_LEFT) &&
446 !(bShiftDown && wParam == VK_RIGHT)) {
447 POINT pt;
448 GetCaretPos(&pt);
449 LPARAM l = MAKELPARAM(pt.x, pt.y);
450 nSelBase = SendMessage(hwnd, EM_CHARFROMPOS, 0, l) & 0xFFFF;
451 }
452 #endif
453
454 if (bCtrlKeyDown && wParam == TEXT('A')) {
455 SelectAll();
456 return 0;
457 } else if (bCtrlKeyDown && wParam == TEXT('B')) {
458 SetReadOnly(!IsReadOnly());
459 return 0;
460 }
461
462 if (IsReadOnly()) {
463 if (wParam == VK_DELETE) return 0;
464 if (wParam == VK_BACK || wParam == VK_CONVERT || wParam == VK_LEFT) {
465 SendMessage(hWnd, WM_KEYDOWN, VK_PRIOR, lParam);
466 return 0;
467 }
468 if (wParam == VK_SPACE || wParam == VK_RIGHT) {
469 SendMessage(hWnd, WM_KEYDOWN, VK_NEXT, lParam);
470 return 0;
471 }
472 } else {
473 if (wParam == KEY_COLON && bCtrlKeyDown) { // :
474 InsertDate1();
475 }
476 if (wParam == KEY_SEMICOLON && bCtrlKeyDown) { // ;
477 InsertDate2();
478 }
479 }
480 return 1;
481 }
482
483 ///////////////////////////////////////////
484 // ƒtƒH[ƒJƒX‚̎擞
485 ///////////////////////////////////////////
486
487 void SimpleEditor::OnGetFocus()
488 {
489 pManager->GetMainFrame()->NotifyDetailsViewFocused();
490 }
491
492 ///////////////////////////////////////////
493 // ƒƒ‚‚̐ݒč
494 ///////////////////////////////////////////
495
496 BOOL SimpleEditor::SetMemo(LPCTSTR pMemo, DWORD nPos, BOOL bReadOnly)
497 {
498 SetReadOnly(bReadOnly);
499
500 nInitialPos = nPos;
501
502 SetWindowText(hViewWnd, pMemo);
503 if (g_Property.GetKeepCaret()) {
504 SendMessage(hViewWnd, EM_SETSEL, nPos, nPos);
505 PostMessage(hViewWnd, EM_SCROLLCARET, 0, 0);
506 }
507 SetModifyStatus();
508 return TRUE;
509 }
510
511 ///////////////////////////////////////////
512 // ƒƒ‚‚̎擞
513 ///////////////////////////////////////////
514
515 LPTSTR SimpleEditor::GetMemo()
516 {
517 DWORD n = GetWindowTextLength(hViewWnd);
518
519 LPTSTR p = new TCHAR[n + 1];
520 if (p == NULL) {
521 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
522 return NULL;
523 }
524 GetWindowText(hViewWnd, p,n+1);
525 return p;
526 }
527
528 /////////////////////////////////////////
529 // ƒtƒHƒ“ƒg‚̐ݒč
530 /////////////////////////////////////////
531
532 void SimpleEditor::SetFont(HFONT hFont)
533 {
534 SendMessage(hViewWnd_fd, WM_SETFONT, (WPARAM)hFont, MAKELPARAM(TRUE, 0));
535 SendMessage(hViewWnd_nf, WM_SETFONT, (WPARAM)hFont, MAKELPARAM(TRUE, 0));
536 }
537
538 /////////////////////////////////////////
539 // get cursor position
540 /////////////////////////////////////////
541
542 DWORD SimpleEditor::GetCursorPos()
543 {
544 DWORD nPos;
545 SendMessage(hViewWnd, EM_GETSEL, (WPARAM)&nPos, (LPARAM)NULL);
546 return nPos;
547 }
548
549 /////////////////////////////////////////
550 // get partial path
551 /////////////////////////////////////////
552
553 static BOOL GetPartialPathFW(TString *pChoped, TString *pOrig, DWORD nLevel)
554 {
555 if (!pChoped->Join(TEXT("\\"), pOrig->Get())) return FALSE;
556 if (nLevel == 0) return TRUE;
557
558 LPTSTR p = pChoped->Get() + 1;
559 DWORD i = 0;
560 while (*p) {
561 if (*p == TEXT('\\')) {
562 i++;
563 if (i >= nLevel) {
564 *p = TEXT('\0');
565 return TRUE;
566 }
567 }
568
569 p = CharNext(p);
570 }
571 return TRUE;
572 }
573
574 static LPCTSTR GetPartialPathBW(TString *pChoped, TString *pOrig, DWORD nLevel)
575 {
576 if (!pChoped->Join(TEXT("\\"), pOrig->Get())) return NULL;
577 if (nLevel == 0) return pChoped->Get();
578
579 LPTSTR p = pChoped->Get() + 1;
580 DWORD n = 0;
581 while(*p) {
582 if (*p == TEXT('\\')) {
583 n++;
584 }
585 p = CharNext(p);
586 }
587
588 if (nLevel > n) {
589 nLevel = n;
590 }
591 DWORD k = n - nLevel;
592
593 p = pChoped->Get() + 1;
594 DWORD i = 0;
595 while(*p) {
596 if (*p == TEXT('\\')) {
597 i++;
598 if (i > k) break;
599 }
600 p = CharNext(p);
601 }
602 return p;
603 }
604 /////////////////////////////////////////
605 // format date string
606 /////////////////////////////////////////
607
608 static BOOL GetDateText(TString *pInsStr, LPCTSTR pFormat, TString *pPath)
609 {
610 SYSTEMTIME st;
611 GetLocalTime(&st);
612
613 TString sPartPath;
614 LPCTSTR pTop;
615 DWORD nLv;
616
617 // •śŽšƒoƒbƒtƒ@ƒTƒCƒY‚ĚƒJƒEƒ“ƒg
618 DWORD nLen = 0;
619 LPCTSTR p = pFormat;
620 while(*p) {
621 #if defined(PLATFORM_WIN32)
622 if (IsDBCSLeadByte(*p)) {
623 p += 2;
624 nLen += 2;
625 continue;
626 }
627 #endif
628 if (*p == TEXT('%')) {
629 p++;
630 switch(*p) {
631 case TEXT('y'):
632 nLen += 4;
633 break;
634 case TEXT('b'):
635 nLen += 3;
636 break;
637 case TEXT('w'):
638 case TEXT('W'):
639 nLen += 3;
640 break;
641 case TEXT('f'):
642 if (_istdigit(*(p+1))) {
643 nLv = *(p+1) - TEXT('0');
644 p++;
645 } else {
646 nLv = 0;
647 }
648 if (!GetPartialPathFW(&sPartPath, pPath, nLv)) return FALSE;
649 nLen += _tcslen(sPartPath.Get());
650 break;
651 case TEXT('F'):
652 if (_istdigit(*(p+1))) {
653 nLv = *(p+1) - TEXT('0');
654 p++;
655 } else {
656 nLv = 0;
657 }
658 pTop = GetPartialPathBW(&sPartPath, pPath, nLv);
659 if (!pTop) return FALSE;
660 nLen += _tcslen(pTop);
661 break;
662 default:
663 nLen += 2;
664 break;
665 }
666 if (*p) p++;
667 } else {
668 p++;
669 nLen++;
670 }
671 }
672 nLen++;
673 if (!pInsStr->Alloc(nLen)) return FALSE;
674
675 LPTSTR q = pInsStr->Get();
676 p = pFormat;
677 while(*p) {
678 #if defined(PLATFORM_WIN32)
679 if (IsDBCSLeadByte(*p)) {
680 *q++ = *p++;
681 *q++ = *p++;
682 continue;
683 }
684 #endif
685 if (*p == TEXT('%')) {
686 p++;
687 switch(*p) {
688 case TEXT('y'):
689 wsprintf(q, TEXT("%4d"), st.wYear);
690 q += 4;
691 break;
692 case TEXT('Y'):
693 wsprintf(q, TEXT("%02d"), st.wYear % 100);
694 q += 2;
695 break;
696 case TEXT('M'):
697 wsprintf(q, TEXT("%02d"), st.wMonth);
698 q += 2;
699 break;
700 case TEXT('b'):
701 _tcscpy(q, pMonth[st.wMonth - 1]);
702 q += 3;
703 break;
704 case TEXT('d'):
705 wsprintf(q, TEXT("%02d"), st.wDay);
706 q += 2;
707 break;
708 case TEXT('D'):
709 wsprintf(q, TEXT("%d"), st.wDay);
710 q++;
711 if (st.wDay >= 10) q++;
712 break;
713 case TEXT('w'):
714 _tcscpy(q, pWeekJ[st.wDayOfWeek]);
715 q += _tcslen(pWeekJ[st.wDayOfWeek]);
716 break;
717 case TEXT('W'):
718 _tcscpy(q, pWeekE[st.wDayOfWeek]);
719 q += _tcslen(pWeekE[st.wDayOfWeek]);
720 break;
721 case TEXT('h'):
722 wsprintf(q, TEXT("%02d"), st.wHour);
723 q += 2;
724 break;
725 case TEXT('H'):
726 wsprintf(q, TEXT("%02d"), st.wHour % 12);
727 q += 2;
728 break;
729 case TEXT('I'):
730 {
731 int n = st.wHour % 12;
732 if (n == 0) n = 12;
733 wsprintf(q, TEXT("%02d"), n);
734 q+= 2;
735 }
736 break;
737 case TEXT('a'):
738 if (st.wHour >= 12) {
739 _tcscpy(q, TEXT("PM"));
740 } else {
741 _tcscpy(q, TEXT("AM"));
742 }
743 q += 2;
744 break;
745 case TEXT('m'):
746 wsprintf(q, TEXT("%02d"), st.wMinute);
747 q += 2;
748 break;
749 case TEXT('s'):
750 wsprintf(q, TEXT("%02d"), st.wSecond);
751 q += 2;
752 break;
753 case TEXT('n'):
754 wsprintf(q, TEXT("\r\n"));
755 q += 2;
756 break;
757 case TEXT('f'):
758 if (_istdigit(*(p+1))) {
759 nLv = *(p+1) - TEXT('0');
760 p++;
761 } else {
762 nLv = 0;
763 }
764 if (!GetPartialPathFW(&sPartPath, pPath, nLv)) return FALSE;
765 _tcscpy(q, sPartPath.Get());
766 q += _tcslen(sPartPath.Get());
767 break;
768 case TEXT('F'):
769 if (_istdigit(*(p+1))) {
770 nLv = *(p+1) - TEXT('0');
771 p++;
772 } else {
773 nLv = 0;
774 }
775 pTop = GetPartialPathBW(&sPartPath, pPath, nLv);
776 if (!pTop) return FALSE;
777 _tcscpy(q, pTop);
778 q += _tcslen(pTop);
779 break;
780 default:
781 *q++ = TEXT('%');
782 if (*p) *q++ = *p++;
783 }
784 p++;
785 } else {
786 *q++ = *p++;
787 }
788 }
789 *q = TEXT('\0');
790 return TRUE;
791 }
792
793 /////////////////////////////////////////
794 // ƒXƒe[ƒ^ƒX•\ŽŚ
795 /////////////////////////////////////////
796
797 void SimpleEditor::SetModifyStatus()
798 {
799 pManager->GetMainFrame()->SetModifyStatus(IsModify());
800 }
801
802 /////////////////////////////////////////
803 // ƒXƒe[ƒ^ƒX•\ŽŚ
804 /////////////////////////////////////////
805
806 void SimpleEditor::SelectAll()
807 {
808 SetFocus();
809 SendMessage(hViewWnd, EM_SETSEL, 0, -1);
810 }
811
812 /////////////////////////////////////////
813 // Ü‚č•Ô‚ľ•\ŽŚ‚̐؂č‘Ö‚Ś
814 /////////////////////////////////////////
815
816 BOOL SimpleEditor::SetFolding(BOOL bFold)
817 {
818 HWND hPrev;
819 HWND hAfter;
820
821 // ŒťÝŽg—p‚ł‚ę‚Ä‚˘‚éƒEƒBƒ“ƒhƒE‚̐؂č‘Ö‚Ś
822 if (hViewWnd == hViewWnd_fd) {
823 hPrev = hViewWnd_fd;
824 hAfter = hViewWnd_nf;
825 } else {
826 hPrev = hViewWnd_nf;
827 hAfter = hViewWnd_fd;
828 }
829 hViewWnd = hAfter;
830
831 // ƒeƒLƒXƒg–{•ś‚ĚˆřŒp‚Ź
832 DWORD nLen = GetWindowTextLength(hPrev) + 1;
833 LPTSTR p = new TCHAR[nLen];
834 if (p == NULL) {
835 hViewWnd = hPrev;
836 return FALSE;
837 }
838 p[0] = TEXT('\0');
839 GetWindowText(hPrev, p, nLen);
840 SetWindowText(hAfter, p);
841 delete [] p; p = NULL;
842
843 // XVó‘Ô‚ĚˆřŒp‚Ź
844 SendMessage(hAfter, EM_SETMODIFY, (WPARAM)SendMessage(hPrev, EM_GETMODIFY, 0, 0), 0);
845
846 // ƒJ[ƒ\ƒ‹ˆĘ’u‚ĚˆřŒp‚Ź
847
848 // ŒťÝ•\ŽŚ‚ł‚ę‚Ä‚˘‚éę‡A•\ŽŚó‘Ô‚đŘ‚č‘Ö‚Ś
849 if (!bShowStatus) return TRUE;
850 ::ShowWindow(hPrev, SW_HIDE);
851 ::ShowWindow(hAfter, SW_SHOW);
852
853 return TRUE;
854 }
855
856 /////////////////////////////////////////
857 // ƒ^ƒuƒXƒgƒbƒv‚̐ݒč
858 /////////////////////////////////////////
859
860 void SimpleEditor::SetTabstop() {
861 DWORD n = g_Property.GetTabstop() * 4;
862 SendMessage(hViewWnd_fd, EM_SETTABSTOPS, 1, (LPARAM)&n);
863 SendMessage(hViewWnd_nf, EM_SETTABSTOPS, 1, (LPARAM)&n);
864 }
865
866 /////////////////////////////////////////
867 // change read only mode
868 /////////////////////////////////////////
869
870 void SimpleEditor::SetReadOnly(BOOL bro)
871 {
872 bReadOnly = bro;
873 pManager->GetMainFrame()->SetReadOnlyStatus(IsReadOnly());
874 }
875
876 /////////////////////////////////////////
877 //
878 /////////////////////////////////////////
879
880 void SimpleEditor::SetMDSearchFlg(BOOL bFlg)
881 {
882 pManager->SetMDSearchFlg(bFlg);
883 }
884
885 /////////////////////////////////////////
886 // Insert date
887 /////////////////////////////////////////
888
889 BOOL SimpleEditor::ReplaceText(LPCTSTR p)
890 {
891 SendMessage(hViewWnd, EM_REPLACESEL, 0, (LPARAM)p);
892 return TRUE;
893 }
894
895 void SimpleEditor::SetSelectRegion(DWORD nStart, DWORD nEnd)
896 {
897 SendMessage(hViewWnd, EM_SETSEL, (WPARAM)nStart, (LPARAM)nEnd);
898 SendMessage(hViewWnd, EM_SCROLLCARET, 0, 0);
899 }

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