Develop and Download Open Source Software

Browse CVS Repository

Contents of /malonnote/mnNotePanel.cpp

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


Revision 1.3 - (show annotations) (download) (as text)
Fri Oct 7 10:19:46 2005 UTC (18 years, 5 months ago) by maloninc
Branch: MAIN
CVS Tags: dev_1_5-0004
Changes since 1.2: +5 -1 lines
File MIME type: text/x-c++src
fixed some bugs.

1 // -*- C++ -*- generated by wxGlade 0.3.5.1 on Wed Jun 29 12:57:38 2005
2 #include <wx/regex.h>
3 #include <wx/tokenzr.h>
4 #include <wx/xrc/xmlres.h>
5 #include "mnID.h"
6 #include "mnDef.h"
7 #include "mnNotePanel.h"
8 #include "mnDialog.h"
9 #include "mnNotePanelController.h"
10
11 mnNotePanel::mnNotePanel(wxWindow* parent, wxString* dirName)
12 {
13 wxXmlResource::Get()->LoadPanel(this, parent, wxT("notePanel"));
14
15 /* init members */
16 searchTree = XRCCTRL(*this, "searchTree", wxTreeCtrl);
17 wikiHtmlTextCtrl = XRCCTRL(*this, "wikiHtmlTextCtrl", mnHtmlWindow);
18
19 /* create search tree */
20 searchItemRoot = searchTree->AddRoot(wxT(LABEL_ITEM_TREE), -1, -1, NULL);
21
22 /* create controller, and push as event handler */
23 panelController = new mnNotePanelController(this, dirName);
24 PushEventHandler(panelController);
25 }
26
27 mnNotePanelController* mnNotePanel::getController()
28 {
29 return panelController;
30 }
31
32 void mnNotePanel::updateSearchResult(mnModel* wiki, wxString* searchStr, bool isExpand)
33 {
34 wxTreeItemIdValue cookie1, cookie2;
35 wxTreeItemId searchStrId;
36 wxTreeItemId wikiDataId;
37 const WikiList* wikiList;
38 WikiList::Node* node;
39 WikiData* data;
40 const wxString* subject;
41
42 memset(&cookie1, 1, sizeof(cookie1));
43 memset(&cookie2, 2, sizeof(cookie2));
44 searchStrId = searchTree->GetFirstChild(searchItemRoot, cookie1);
45 while(searchStrId.IsOk()) {
46 if(searchTree->GetItemText(searchStrId) == *searchStr) {
47 wikiDataId = searchTree->GetFirstChild(searchStrId, cookie2);
48 while(wikiDataId.IsOk()) {
49 searchTree->SetItemData(wikiDataId, NULL);
50 wikiDataId = searchTree->GetNextChild(searchStrId, cookie2);
51 }
52 searchTree->DeleteChildren(searchStrId);
53 break;
54 }
55 searchStrId = searchTree->GetNextChild(searchItemRoot, cookie1);
56 }
57
58 wikiList = wiki->getSearchResultList(searchStr);
59 if(wikiList == NULL) {
60 MN_FATAL_ERROR(wxT("wikiList is null"));
61 return;
62 }
63
64 node = wikiList->GetFirst();
65 while(node) {
66 data = node->GetData();
67 subject = data->getSubject();
68 searchTree->AppendItem(searchStrId, *subject, -1, -1, (wxTreeItemData*)data);
69 node = node->GetNext();
70 }
71 if(isExpand){
72 searchTree->Expand(searchStrId);
73 }
74 else {
75 searchTree->Collapse(searchStrId);
76 }
77 }
78
79
80 void mnNotePanel::addSearchResult(mnModel* wiki, wxString* searchStr, bool isExpand)
81 {
82 wxTreeItemId searchItem;
83 const WikiList* wikiList;
84 WikiList::Node* node;
85 WikiData* data;
86 const wxString* subject;
87
88 wikiList = wiki->getSearchResultList(searchStr);
89 if(wikiList == NULL) {
90 MN_FATAL_ERROR(wxT("wikiList is null"));
91 return;
92 }
93
94 //searchItem = searchTree->AppendItem(searchItemRoot, *searchStr, -1, -1, NULL);
95 searchItem = searchTree->InsertItem(searchItemRoot, 0, *searchStr, -1, -1, NULL);
96 node = wikiList->GetFirst();
97 while(node) {
98 data = node->GetData();
99 subject = data->getSubject();
100 searchTree->AppendItem(searchItem, *subject, -1, -1, (wxTreeItemData*)data);
101 node = node->GetNext();
102 }
103
104 searchTree->Expand(searchItemRoot);
105 if(isExpand){
106 searchTree->Expand(searchItem);
107 }
108 else {
109 searchTree->Collapse(searchItem);
110 }
111 }
112
113 void mnNotePanel::makeHtml(WikiData* wikiData, bool isHighlight)
114 {
115 const wxString* fileName = wikiData->getFileName();
116 const wxString* wikiText = wikiData->getText();
117 wxString htmlText(*wikiText);
118
119 /* escape < */
120 wxRegEx exp01(wxT("<"), wxRE_NEWLINE|wxRE_DEFAULT);
121 exp01.Replace(&htmlText, wxT("\\&lt "));
122
123 /* escape > */
124 wxRegEx exp02(wxT(">"), wxRE_NEWLINE|wxRE_DEFAULT);
125 exp02.Replace(&htmlText, wxT("\\&gt "));
126
127 /* [[ ]] */
128 wxRegEx exp1(wxT("\\[\\[([^\\}]+)\\]\\]"));
129 exp1.Replace(&htmlText, wxT("<a href=mnlink:\\1>\\1</a>"));
130
131 /* http:// */
132 wxRegEx exp2(wxT("(http://[-_.!~*'a-zA-Z0-9;/?:@&=+$,%#]+)"), wxRE_NEWLINE|wxRE_DEFAULT);
133 exp2.Replace(&htmlText, wxT("<a href=\\1>\\1</a>"));
134
135 /* file:// */
136 wxRegEx exp3(wxT("(file://[^ ]+)"), wxRE_NEWLINE|wxRE_DEFAULT);
137 exp3.Replace(&htmlText, wxT("<a href=\\1>\\1</a>"));
138
139 /* *XXXX */
140 wxRegEx exp4(wxT("^\\*([^\\*]+)"), wxRE_NEWLINE|wxRE_DEFAULT);
141 exp4.Replace(&htmlText, wxT("<h3>\\1</h3>"));
142
143 /* **XXXX */
144 wxRegEx exp5(wxT("^\\*\\*([^\\*]+)"), wxRE_NEWLINE|wxRE_DEFAULT);
145 exp5.Replace(&htmlText, wxT("<h4>\\1</h4>"));
146
147 /* :''XXXX'': */
148 wxRegEx exp6(wxT("^:''(.+)'':(.+)"), wxRE_NEWLINE|wxRE_DEFAULT);
149 exp6.Replace(&htmlText, wxT("<u><b>\\1:\\2</b></u>"));
150
151 /* ---- */
152 wxRegEx exp7(wxT("^----.*"), wxRE_NEWLINE|wxRE_DEFAULT);
153 exp7.Replace(&htmlText, wxT("<hr>"));
154
155 /* {{ }} */
156 wxRegEx exp8(wxT("\\{\\{([^\\}]+)\\}\\}"));
157 exp8.Replace(&htmlText, wxT("<a href=mndoc:\\1>\\1</a>"));
158
159 /* table */
160 wxRegEx exp10(wxT("^,([^,]+)"), wxRE_NEWLINE|wxRE_DEFAULT);
161 exp10.Replace(&htmlText, wxT("<td>\\1</td>"));
162 for(int i = 0; i < 10; i++){ // It's not good. :P
163 wxRegEx exp16(wxT("</td>,([^,\n]+)"), wxRE_DEFAULT);
164 exp16.Replace(&htmlText, wxT("</td><td>\\1</td>"));
165 }
166 wxRegEx exp11(wxT("^<td>"), wxRE_NEWLINE|wxRE_DEFAULT);
167 exp11.Replace(&htmlText, wxT("<tr><td>"));
168 wxRegEx exp12(wxT("</td>$"), wxRE_NEWLINE|wxRE_DEFAULT);
169 exp12.Replace(&htmlText, wxT("</td></tr>"));
170 wxRegEx exp15(wxT("</tr>\n"));
171 exp15.Replace(&htmlText, wxT("</tr>"));
172
173 wxRegEx exp13(wxT("^<tr>"), wxRE_NEWLINE|wxRE_DEFAULT);
174 exp13.Replace(&htmlText, wxT("<table border><tr>"));
175 wxRegEx exp14(wxT("</tr>$"), wxRE_NEWLINE|wxRE_DEFAULT);
176 exp14.Replace(&htmlText, wxT("</tr></table>"));
177
178
179 /* Highlight search text */
180 highlight = isHighlight;
181 if(isHighlight) {
182 wxTreeItemId parentId = searchTree->GetItemParent(searchTree->GetSelection());
183 wxString searchWords = searchTree->GetItemText(parentId);
184 wxStringTokenizer tkz(searchWords, wxT(" "));
185 while ( tkz.HasMoreTokens() )
186 {
187 wxString token = tkz.GetNextToken();
188 wxRegEx exp9(wxT("(?!<[^>]+)(") + token + wxT(")(?![^<]+>)"), wxRE_ADVANCED|wxRE_ICASE|wxRE_NEWLINE);
189 exp9.Replace(&htmlText, wxT("<b><font color=\"red\">\\1</font></b>"));
190 }
191 }
192
193
194 /* make HTML document */
195 wxString wikiHtml;
196 wikiHtml.Append(wxT("<meta http-equiv=\"Content-Type\"content=\"text/html; charset="));
197 wikiHtml.Append(wxT(CODE_SET_SYSTEM));
198 wikiHtml.Append(wxT("\">"));
199 wikiHtml.Append(wxT("<pre>"));
200 wikiHtml.Append(htmlText);
201 wikiHtml.Append(wxT("</pre>"));
202
203 wikiHtmlTextCtrl->SetPage(wikiHtml);
204 }
205
206 void mnNotePanel::showSelectedItemText(wxTreeEvent& event)
207 {
208 wxTreeItemId id;
209 wxTreeItemData* item;
210
211 id = searchTree->GetSelection();
212 item = searchTree->GetItemData(id);
213
214 if(!id.IsOk() || !isEditableTreeLabel(id) || item == NULL) { /* selection is not memo data */
215 wikiHtmlTextCtrl->SetPage(wxT(""));
216 return;
217 }
218 makeHtml((WikiData*)item, false);
219 }
220
221 wxTreeItemId mnNotePanel::getSelection()
222 {
223 return searchTree->GetSelection();
224 }
225
226 void mnNotePanel::highlightSelectedItem()
227 {
228 wxTreeItemData* item = getSelectedItem();
229
230 if(!isEditableTreeLabel(searchTree->GetSelection())) { /* selection is not memo data */
231 wikiHtmlTextCtrl->SetPage(wxT(""));
232 return;
233 }
234
235 if(highlight){
236 makeHtml((WikiData*)item, false);
237 }
238 else {
239 makeHtml((WikiData*)item, true);
240 }
241 }
242
243
244 void mnNotePanel::expandAllTree()
245 {
246 wxTreeItemIdValue cookie;
247 wxTreeItemId itemId;
248
249 memset(&cookie, 1, sizeof(cookie));
250 itemId = searchTree->GetFirstChild(searchItemRoot, cookie);
251 while(itemId.IsOk()) {
252 searchTree->Expand(itemId);
253 itemId = searchTree->GetNextChild(searchItemRoot, cookie);
254 }
255 }
256
257 void mnNotePanel::collapseAllTree()
258 {
259 wxTreeItemIdValue cookie;
260 wxTreeItemId itemId;
261
262 memset(&cookie, 1, sizeof(cookie));
263 itemId = searchTree->GetFirstChild(searchItemRoot, cookie);
264 while(itemId.IsOk()) {
265 searchTree->Collapse(itemId);
266 itemId = searchTree->GetNextChild(searchItemRoot, cookie);
267 }
268 }
269
270 void mnNotePanel::clearAllTree()
271 {
272 wxTreeItemIdValue cookie1, cookie2;
273 wxTreeItemId searchStrId;
274 wxTreeItemId wikiDataId;
275
276 memset(&cookie1, 1, sizeof(cookie1));
277 memset(&cookie2, 2, sizeof(cookie2));
278 searchStrId = searchTree->GetFirstChild(searchItemRoot, cookie1);
279 while(searchStrId.IsOk()) {
280 wikiDataId = searchTree->GetFirstChild(searchStrId, cookie2);
281 while(wikiDataId.IsOk()) {
282 searchTree->SetItemData(wikiDataId, NULL);
283 wikiDataId = searchTree->GetNextChild(searchStrId, cookie2);
284 }
285 searchStrId = searchTree->GetNextChild(searchItemRoot, cookie1);
286 }
287
288 searchTree->DeleteChildren(searchItemRoot);
289 }
290
291 void mnNotePanel::removeSelectedItem()
292 {
293 searchTree->Delete(searchTree->GetSelection());
294 }
295
296 wxTreeItemData* mnNotePanel::getSelectedItem()
297 {
298 return searchTree->GetItemData(searchTree->GetSelection());
299 }
300
301 wxString mnNotePanel::getSelectedLabel()
302 {
303 return searchTree->GetItemText(searchTree->GetSelection());
304 }
305
306 bool mnNotePanel::isEditableTreeLabel(wxTreeItemId id)
307 {
308 if(id.IsOk()){
309 return !(searchTree->GetItemParent(id) == searchItemRoot || id == searchItemRoot);
310 }
311 else {
312 return false;
313 }
314 }
315

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