Develop and Download Open Source Software

Browse CVS Repository

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

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


Revision 1.18 - (show annotations) (download) (as text)
Sat Sep 30 12:48:08 2006 UTC (17 years, 6 months ago) by hirami
Branch: MAIN
CVS Tags: HEAD
Changes since 1.17: +8 -0 lines
File MIME type: text/x-c++src
* FIX: view mode is not work(#9105)

1 #include <windows.h>
2 #include <tchar.h>
3 #include <commctrl.h>
4 #include "YAEditor.h"
5
6 #include "resource.h"
7
8 #include "Tombo.h"
9 #include "UniConv.h"
10 #include "Property.h"
11 #include "Region.h"
12 #include "YAEdit.h"
13 #include "YAEditDoc.h"
14 #include "YAEditView.h"
15 #include "MemoManager.h"
16 #include "MainFrame.h"
17
18 /////////////////////////////////////////////////////////////////////////////
19 // TomboDoc callback
20 /////////////////////////////////////////////////////////////////////////////
21
22 class YAEDetailsViewCallback : public YAEditCallback {
23 YAEditor *pEditor;
24 MemoManager *pManager;
25 public:
26 YAEDetailsViewCallback(YAEditor *pSelf, MemoManager *pmm) : pEditor(pSelf), pManager(pmm) {}
27
28 void OnGetFocus();
29 void ChangeModifyStatusNotify(BOOL bStatus);
30 void ChangeReadOnlyStatusNotify(BOOL bStatus);
31
32 void OnContextMenu(HWND hWnd, WORD x, WORD y);
33 };
34
35 void YAEDetailsViewCallback::OnGetFocus()
36 {
37 pEditor->OnGetFocus();
38 }
39
40 void YAEDetailsViewCallback::ChangeModifyStatusNotify(BOOL bStatus)
41 {
42 pEditor->ChangeModifyStatusNotify(bStatus);
43 }
44
45 void YAEDetailsViewCallback::ChangeReadOnlyStatusNotify(BOOL bStatus)
46 {
47 pManager->GetMainFrame()->SetReadOnlyStatus(bStatus);
48 }
49
50
51 typedef void (YAEditor::*YAEditCommandFunc)();
52
53 struct YAEContextMenu {
54 LPCTSTR pItemName;
55 YAEditCommandFunc pFunc;
56 };
57
58 void YAEDetailsViewCallback::OnContextMenu(HWND hWnd, WORD x, WORD y)
59 {
60 // MSG_xx needs initializ after initialized message resources.
61 static YAEContextMenu contextMenu[] = {
62 { MSG_MENUITEM_UNDO, &YAEditor::CmdUndo },
63 { TEXT(""), NULL },
64 { MSG_MENUITEM_MAIN_CUT, &YAEditor::CmdCut },
65 { MSG_MENUITEM_MAIN_COPY, &YAEditor::CmdCopy },
66 { MSG_MENUITEM_MAIN_PASTE, &YAEditor::CmdPaste },
67 { MSG_MENUITEM_MAIN_DELETE, &YAEditor::CmdBackSpace },
68 { TEXT(""), NULL },
69 { MSG_MENUITEM_DETAILS_SELALL, &YAEditor::CmdSelAll },
70 { TEXT(""), NULL },
71 { MSG_TOOLTIPS_INSDATE1, &YAEditor::InsertDate1 },
72 { MSG_TOOLTIPS_INSDATE2, &YAEditor::InsertDate2 },
73 { NULL, NULL },
74 };
75
76 // create context menu
77 HMENU hMenu = CreatePopupMenu();
78 DWORD nItems = 1;
79
80 const YAEContextMenu *p = contextMenu;
81 while (p->pItemName != NULL) {
82 if (*(p->pItemName) == TEXT('\0')) {
83 InsertMenu(hMenu, nItems - 1, MF_BYPOSITION | MF_SEPARATOR, 0, NULL);
84 } else {
85 InsertMenu(hMenu, nItems - 1, MF_BYPOSITION | MF_STRING, nItems, p->pItemName);
86 }
87 p++;
88 nItems++;
89 }
90
91 DWORD id = TrackPopupMenuEx(hMenu, TPM_RETURNCMD | TPM_TOPALIGN | TPM_LEFTALIGN, x, y, hWnd, NULL);
92 if (id > 0 && id < nItems) {
93 YAEditCommandFunc f = contextMenu[id - 1].pFunc;
94 (pEditor->*f)();
95 }
96 DestroyMenu(hMenu);
97 }
98
99 /////////////////////////////////////////////////////////////////////////////
100 // YAEditor implimentation
101 /////////////////////////////////////////////////////////////////////////////
102
103
104 YAEditor::YAEditor(MemoManager *pMgr) : MemoDetailsView(pMgr), pEdit(NULL), pYAECallback(NULL)
105 {
106 }
107
108 YAEditor::~YAEditor()
109 {
110 delete pEdit;
111 delete pYAECallback;
112 }
113
114 BOOL YAEditor::Create(LPCTSTR pName, RECT &r, HWND hParent, HINSTANCE hInst, HFONT hFont)
115 {
116 pYAECallback = new YAEDetailsViewCallback(this, pManager);
117 pEdit = YAEdit::GetInstance(pYAECallback);
118 pEdit->Create(hInst, hParent, nID, r, g_Property.GetWrapText());
119 pEdit->SetFont(hFont);
120 return TRUE;
121 }
122
123 BOOL YAEditor::Init(DWORD n)
124 {
125 nID = n;
126 return TRUE;
127 }
128
129 void YAEditor::SetFocus()
130 {
131 if (pEdit) pEdit->SetFocus();
132 }
133
134 void YAEditor::OnGetFocus()
135 {
136 pManager->GetMainFrame()->NotifyDetailsViewFocused();
137 }
138
139
140 LPTSTR YAEditor::GetMemo()
141 {
142 DWORD nLen;
143 char *pData = pEdit->GetDoc()->GetDocumentData(&nLen);
144 #if defined(PLATFORM_WIN32)
145 return pData;
146 #else
147 LPTSTR pDataW = ConvSJIS2Unicode(pData);
148 delete [] pData;
149 return pDataW;
150 #endif
151 }
152
153 void YAEditor::MoveWindow(DWORD x, DWORD y, DWORD nWidth, DWORD nHeight)
154 {
155 if (pEdit) pEdit->ResizeWindow(x, y, nWidth, nHeight);
156 }
157
158 BOOL YAEditor::SetMemo(LPCTSTR pMemoW, DWORD nPos, BOOL bReadOnly)
159 {
160 #if defined(PLATFORM_WIN32)
161 const char *pMemo = pMemoW;
162 #else
163 char *pMemo = ConvUnicode2SJIS(pMemoW);
164 #endif
165 YAEditDoc *pDoc = pEdit->CreateDocument(pMemo, pYAECallback);
166 if (pDoc == NULL) return FALSE;
167
168 pDoc->SetReadOnly(bReadOnly);
169 pYAECallback->ChangeReadOnlyStatusNotify(bReadOnly);
170
171 #if !defined(PLATFORM_WIN32)
172 delete [] pMemo;
173 #endif
174
175 YAEditDoc *pOldDoc = pEdit->SetDoc(pDoc);
176 delete pOldDoc;
177
178 if (g_Property.GetKeepCaret()) {
179 pEdit->SetCaretPos(nPos);
180 }
181
182 return TRUE;
183 }
184
185 BOOL YAEditor::IsModify()
186 {
187 return pEdit->GetDoc()->IsModify();
188 }
189
190 void YAEditor::ResetModify()
191 {
192 pEdit->GetDoc()->SetModify(FALSE);
193 }
194
195 BOOL YAEditor::OnCommand(HWND hWnd, WPARAM wParam, LPARAM lParam)
196 {
197 switch(LOWORD(wParam)) {
198 case IDM_CUT:
199 pEdit->CmdCut();
200 return TRUE;
201 case IDM_COPY:
202 pEdit->CmdCopy();
203 return TRUE;
204 case IDM_PASTE:
205 pEdit->CmdPaste();
206 return TRUE;
207 case IDM_INSDATE1:
208 InsertDate1();
209 return TRUE;
210 case IDM_INSDATE2:
211 InsertDate2();
212 return TRUE;
213 case IDM_UNDO:
214 pEdit->CmdUndo();
215 return TRUE;
216 }
217 return FALSE;
218 }
219
220 void YAEditor::SetMDSearchFlg(BOOL bFlg)
221 {
222 pManager->SetMDSearchFlg(bFlg);
223 }
224
225 void YAEditor::SetFont(HFONT hFont)
226 {
227 pEdit->SetFont(hFont);
228 }
229
230 DWORD YAEditor::GetCursorPos()
231 {
232 return pEdit->GetCaretPos();
233 }
234
235 void YAEditor::ChangeModifyStatusNotify(BOOL bStatus)
236 {
237 pManager->GetMainFrame()->SetModifyStatus(bStatus);
238 }
239
240 BOOL YAEditor::ReplaceText(LPCTSTR p)
241 {
242 pEdit->CmdReplaceString(p);
243 return TRUE;
244 }
245
246 void YAEditor::SetSelectRegion(DWORD nStart, DWORD nEnd)
247 {
248 pEdit->SetSelectRegion(nStart, nEnd);
249 }
250
251 void YAEditor::SetReadOnly(BOOL bReadOnly)
252 {
253 pEdit->GetDoc()->SetReadOnly(bReadOnly);
254 }
255
256 BOOL YAEditor::IsReadOnly()
257 {
258 return pEdit->GetDoc()->IsReadOnly();
259 }
260
261 BOOL YAEditor::SetFolding(BOOL bFold)
262 {
263 pEdit->CmdToggleWrapMode(bFold);
264 return TRUE;
265 }
266
267 void YAEditor::CmdUndo()
268 {
269 pEdit->CmdUndo();
270 }
271
272 void YAEditor::CmdCut()
273 {
274 pEdit->CmdCut();
275 }
276
277 void YAEditor::CmdCopy()
278 {
279 pEdit->CmdCopy();
280 }
281
282 void YAEditor::CmdPaste()
283 {
284 pEdit->CmdPaste();
285 }
286
287 void YAEditor::CmdBackSpace()
288 {
289 pEdit->CmdBackSpace();
290 }
291
292 void YAEditor::CmdSelAll()
293 {
294 pEdit->CmdSelAll();
295 }
296
297 BOOL YAEditor::Show(int nCmdShow)
298 {
299 return pEdit->Show(nCmdShow);
300 }

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