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.8 - (hide annotations) (download) (as text)
Fri Dec 30 03:50:38 2005 UTC (18 years, 2 months ago) by maloninc
Branch: MAIN
Changes since 1.7: +4 -2 lines
File MIME type: text/x-c++src
modify "*"tag and "**" tag.

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.8 //exp5.Replace(&htmlText, wxT("<h4>\\1</h4>"));
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><BR>"));
149 maloninc 1.1
150     /* *XXXX */
151 maloninc 1.4 wxRegEx exp4(wxT("^\\*([^*]+)"), wxRE_NEWLINE|wxRE_DEFAULT);
152 maloninc 1.8 //exp4.Replace(&htmlText, wxT("<h3>\\1</h3>"));
153     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>"));
154 maloninc 1.1
155     /* :''XXXX'': */
156     wxRegEx exp6(wxT("^:''(.+)'':(.+)"), wxRE_NEWLINE|wxRE_DEFAULT);
157 maloninc 1.5 exp6.Replace(&htmlText, wxT("<u><b>\\1:\\2</b></u>"));
158 maloninc 1.1
159     /* ---- */
160     wxRegEx exp7(wxT("^----.*"), wxRE_NEWLINE|wxRE_DEFAULT);
161     exp7.Replace(&htmlText, wxT("<hr>"));
162    
163     /* {{ }} */
164     wxRegEx exp8(wxT("\\{\\{([^\\}]+)\\}\\}"));
165 maloninc 1.5 exp8.Replace(&htmlText, wxT("<a href=" MNDOC "\\1>\\1</a>"));
166 maloninc 1.1
167     /* table */
168 maloninc 1.3 wxRegEx exp10(wxT("^,([^,]+)"), wxRE_NEWLINE|wxRE_DEFAULT);
169 maloninc 1.4 exp10.Replace(&htmlText, wxT("<td> \\1 </td>"));
170 maloninc 1.3 for(int i = 0; i < 10; i++){ // It's not good. :P
171     wxRegEx exp16(wxT("</td>,([^,\n]+)"), wxRE_DEFAULT);
172 maloninc 1.5 exp16.Replace(&htmlText, wxT("</td><td>\\1</td>"));
173 maloninc 1.3 }
174 maloninc 1.1 wxRegEx exp11(wxT("^<td>"), wxRE_NEWLINE|wxRE_DEFAULT);
175     exp11.Replace(&htmlText, wxT("<tr><td>"));
176     wxRegEx exp12(wxT("</td>$"), wxRE_NEWLINE|wxRE_DEFAULT);
177     exp12.Replace(&htmlText, wxT("</td></tr>"));
178     wxRegEx exp15(wxT("</tr>\n"));
179     exp15.Replace(&htmlText, wxT("</tr>"));
180    
181     wxRegEx exp13(wxT("^<tr>"), wxRE_NEWLINE|wxRE_DEFAULT);
182     exp13.Replace(&htmlText, wxT("<table border><tr>"));
183     wxRegEx exp14(wxT("</tr>$"), wxRE_NEWLINE|wxRE_DEFAULT);
184     exp14.Replace(&htmlText, wxT("</tr></table>"));
185    
186    
187     /* Highlight search text */
188     highlight = isHighlight;
189     if(isHighlight) {
190     wxTreeItemId parentId = searchTree->GetItemParent(searchTree->GetSelection());
191     wxString searchWords = searchTree->GetItemText(parentId);
192     wxStringTokenizer tkz(searchWords, wxT(" "));
193     while ( tkz.HasMoreTokens() )
194     {
195     wxString token = tkz.GetNextToken();
196     wxRegEx exp9(wxT("(?!<[^>]+)(") + token + wxT(")(?![^<]+>)"), wxRE_ADVANCED|wxRE_ICASE|wxRE_NEWLINE);
197 maloninc 1.5 exp9.Replace(&htmlText, wxT("<b><font color=\"red\">\\1</font></b>"));
198 maloninc 1.1 }
199     }
200    
201     /* make HTML document */
202     wxString wikiHtml;
203 maloninc 1.5 wikiHtml.Append(wxT("<meta http-equiv=\"Content-Type\" content=\"text/html; charset="));
204 maloninc 1.1 wikiHtml.Append(wxT(CODE_SET_SYSTEM));
205     wikiHtml.Append(wxT("\">"));
206     wikiHtml.Append(wxT("<pre>"));
207 maloninc 1.4 wikiHtml.Append(wxT("<html>"));
208     wikiHtml.Append(htmlText.c_str());
209 maloninc 1.1 wikiHtml.Append(wxT("</pre>"));
210 maloninc 1.4 wikiHtml.Append(wxT("</html>"));
211 maloninc 1.1
212     wikiHtmlTextCtrl->SetPage(wikiHtml);
213     }
214    
215     void mnNotePanel::showSelectedItemText(wxTreeEvent& event)
216     {
217     wxTreeItemId id;
218     wxTreeItemData* item;
219    
220     id = searchTree->GetSelection();
221     item = searchTree->GetItemData(id);
222    
223     if(!id.IsOk() || !isEditableTreeLabel(id) || item == NULL) { /* selection is not memo data */
224 maloninc 1.5 wikiHtmlTextCtrl->SetPage(wxT("<html></html>"));
225 maloninc 1.1 return;
226     }
227     makeHtml((WikiData*)item, false);
228     }
229    
230     wxTreeItemId mnNotePanel::getSelection()
231     {
232     return searchTree->GetSelection();
233     }
234    
235     void mnNotePanel::highlightSelectedItem()
236     {
237     wxTreeItemData* item = getSelectedItem();
238    
239     if(!isEditableTreeLabel(searchTree->GetSelection())) { /* selection is not memo data */
240     wikiHtmlTextCtrl->SetPage(wxT(""));
241     return;
242     }
243    
244     if(highlight){
245     makeHtml((WikiData*)item, false);
246     }
247     else {
248     makeHtml((WikiData*)item, true);
249     }
250     }
251    
252 maloninc 1.2
253 maloninc 1.1 void mnNotePanel::expandAllTree()
254     {
255     wxTreeItemIdValue cookie;
256     wxTreeItemId itemId;
257    
258     memset(&cookie, 1, sizeof(cookie));
259     itemId = searchTree->GetFirstChild(searchItemRoot, cookie);
260     while(itemId.IsOk()) {
261     searchTree->Expand(itemId);
262     itemId = searchTree->GetNextChild(searchItemRoot, cookie);
263     }
264     }
265    
266     void mnNotePanel::collapseAllTree()
267     {
268     wxTreeItemIdValue cookie;
269     wxTreeItemId itemId;
270    
271     memset(&cookie, 1, sizeof(cookie));
272     itemId = searchTree->GetFirstChild(searchItemRoot, cookie);
273     while(itemId.IsOk()) {
274     searchTree->Collapse(itemId);
275     itemId = searchTree->GetNextChild(searchItemRoot, cookie);
276     }
277     }
278    
279     void mnNotePanel::clearAllTree()
280     {
281     wxTreeItemIdValue cookie1, cookie2;
282     wxTreeItemId searchStrId;
283     wxTreeItemId wikiDataId;
284    
285     memset(&cookie1, 1, sizeof(cookie1));
286     memset(&cookie2, 2, sizeof(cookie2));
287     searchStrId = searchTree->GetFirstChild(searchItemRoot, cookie1);
288     while(searchStrId.IsOk()) {
289     wikiDataId = searchTree->GetFirstChild(searchStrId, cookie2);
290     while(wikiDataId.IsOk()) {
291     searchTree->SetItemData(wikiDataId, NULL);
292     wikiDataId = searchTree->GetNextChild(searchStrId, cookie2);
293     }
294     searchStrId = searchTree->GetNextChild(searchItemRoot, cookie1);
295     }
296    
297     searchTree->DeleteChildren(searchItemRoot);
298     }
299    
300     void mnNotePanel::removeSelectedItem()
301     {
302     searchTree->Delete(searchTree->GetSelection());
303     }
304    
305     wxTreeItemData* mnNotePanel::getSelectedItem()
306     {
307     return searchTree->GetItemData(searchTree->GetSelection());
308     }
309    
310     wxString mnNotePanel::getSelectedLabel()
311     {
312     return searchTree->GetItemText(searchTree->GetSelection());
313     }
314    
315     bool mnNotePanel::isEditableTreeLabel(wxTreeItemId id)
316     {
317     if(id.IsOk()){
318     return !(searchTree->GetItemParent(id) == searchItemRoot || id == searchItemRoot);
319     }
320     else {
321     return false;
322     }
323     }
324    

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