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.14 - (show annotations) (download) (as text)
Thu Oct 19 08:55:19 2006 UTC (17 years, 5 months ago) by maloninc
Branch: MAIN
Changes since 1.13: +6 -1 lines
File MIME type: text/x-c++src
hyphen(-) -> <li></li>

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

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