Develop and Download Open Source Software

Browse CVS Repository

Annotation of /malonnote/mnNotePanel.cpp

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


Revision 1.9 - (hide annotations) (download) (as text)
Fri Dec 30 04:06:33 2005 UTC (18 years, 2 months ago) by maloninc
Branch: MAIN
CVS Tags: dev_1_6-0005
Changes since 1.8: +8 -2 lines
File MIME type: text/x-c++src
modify "*" and "**" tags for Mac.

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

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