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.7 - (hide annotations) (download) (as text)
Wed Dec 28 12:38:18 2005 UTC (18 years, 2 months ago) by maloninc
Branch: MAIN
CVS Tags: dev_1_6-0004
Changes since 1.6: +1 -1 lines
File MIME type: text/x-c++src
Fixed bugs.
1. Call SetPosition.
2. For https:// and ftp://

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

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