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.15 - (hide annotations) (download) (as text)
Fri Oct 20 02:00:03 2006 UTC (17 years, 5 months ago) by maloninc
Branch: MAIN
CVS Tags: HEAD
Changes since 1.14: +5 -1 lines
File MIME type: text/x-c++src
fixed table bug, and implement <li> for Windows

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.11 wxFont font(12, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL);
23 maloninc 1.6 wikiHtmlTextCtrl = XRCCTRL(*this, "wikiHtmlTextCtrl", mnHtmlWindow);
24 maloninc 1.11 wikiHtmlTextCtrl->SetFonts(font.GetFaceName(), font.GetFaceName());
25 maloninc 1.4 #endif
26 maloninc 1.1
27 maloninc 1.10
28 maloninc 1.1 /* 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 maloninc 1.5
136     /* http:// */
137 maloninc 1.7 wxRegEx exp2(wxT("((http|https|ftp)://[-_.!~*'a-zA-Z0-9;/?:@&=+$,%#]+)"), wxRE_NEWLINE|wxRE_DEFAULT);
138 maloninc 1.5 exp2.Replace(&htmlText, wxT("<a href=\\1>\\1</a>"));
139 maloninc 1.1
140     /* [[ ]] */
141 maloninc 1.13 wxRegEx exp1(wxT("\\[\\[([^]]+)\\]\\]"));
142 maloninc 1.12 exp1.Replace(&htmlText, wxT("<a href=\"" MNLINK "\\1\">\\1</a>"));
143 maloninc 1.1
144     /* file:// */
145     wxRegEx exp3(wxT("(file://[^ ]+)"), wxRE_NEWLINE|wxRE_DEFAULT);
146 maloninc 1.5 exp3.Replace(&htmlText, wxT("<a href=\\1>\\1</a>"));
147 maloninc 1.4
148     /* **XXXX */
149     wxRegEx exp5(wxT("^\\*\\*([^*]+)"), wxRE_NEWLINE|wxRE_DEFAULT);
150 maloninc 1.9 #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 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>"));
154 maloninc 1.9 #endif
155 maloninc 1.1
156     /* *XXXX */
157 maloninc 1.4 wxRegEx exp4(wxT("^\\*([^*]+)"), wxRE_NEWLINE|wxRE_DEFAULT);
158 maloninc 1.9 #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 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>"));
162 maloninc 1.9 #endif
163 maloninc 1.14
164 maloninc 1.1 /* :''XXXX'': */
165     wxRegEx exp6(wxT("^:''(.+)'':(.+)"), wxRE_NEWLINE|wxRE_DEFAULT);
166 maloninc 1.5 exp6.Replace(&htmlText, wxT("<u><b>\\1:\\2</b></u>"));
167 maloninc 1.1
168     /* ---- */
169     wxRegEx exp7(wxT("^----.*"), wxRE_NEWLINE|wxRE_DEFAULT);
170     exp7.Replace(&htmlText, wxT("<hr>"));
171 maloninc 1.14
172     /* -XXXX */
173     wxRegEx exp16(wxT("^-(.*)"), wxRE_NEWLINE|wxRE_DEFAULT);
174 maloninc 1.15 #ifdef __WXMAC__
175 maloninc 1.14 exp16.Replace(&htmlText, wxT("<li>\\1</li>"));
176 maloninc 1.15 #else
177     exp16.Replace(&htmlText, wxT("<ul><li>\\1</li></ul>"));
178     #endif
179 maloninc 1.14
180 maloninc 1.1
181     /* {{ }} */
182     wxRegEx exp8(wxT("\\{\\{([^\\}]+)\\}\\}"));
183 maloninc 1.12 exp8.Replace(&htmlText, wxT("<a href=\"" MNDOC "\\1\">\\1</a>"));
184 maloninc 1.1
185     /* table */
186 maloninc 1.3 wxRegEx exp10(wxT("^,([^,]+)"), wxRE_NEWLINE|wxRE_DEFAULT);
187 maloninc 1.4 exp10.Replace(&htmlText, wxT("<td> \\1 </td>"));
188 maloninc 1.15 for(int i = 0; i < 64; i++){ // It's not good. :P
189 maloninc 1.3 wxRegEx exp16(wxT("</td>,([^,\n]+)"), wxRE_DEFAULT);
190 maloninc 1.5 exp16.Replace(&htmlText, wxT("</td><td>\\1</td>"));
191 maloninc 1.3 }
192 maloninc 1.1 wxRegEx exp11(wxT("^<td>"), wxRE_NEWLINE|wxRE_DEFAULT);
193     exp11.Replace(&htmlText, wxT("<tr><td>"));
194     wxRegEx exp12(wxT("</td>$"), wxRE_NEWLINE|wxRE_DEFAULT);
195     exp12.Replace(&htmlText, wxT("</td></tr>"));
196     wxRegEx exp15(wxT("</tr>\n"));
197     exp15.Replace(&htmlText, wxT("</tr>"));
198    
199     wxRegEx exp13(wxT("^<tr>"), wxRE_NEWLINE|wxRE_DEFAULT);
200     exp13.Replace(&htmlText, wxT("<table border><tr>"));
201     wxRegEx exp14(wxT("</tr>$"), wxRE_NEWLINE|wxRE_DEFAULT);
202     exp14.Replace(&htmlText, wxT("</tr></table>"));
203    
204    
205     /* Highlight search text */
206     highlight = isHighlight;
207     if(isHighlight) {
208     wxTreeItemId parentId = searchTree->GetItemParent(searchTree->GetSelection());
209     wxString searchWords = searchTree->GetItemText(parentId);
210     wxStringTokenizer tkz(searchWords, wxT(" "));
211     while ( tkz.HasMoreTokens() )
212     {
213     wxString token = tkz.GetNextToken();
214     wxRegEx exp9(wxT("(?!<[^>]+)(") + token + wxT(")(?![^<]+>)"), wxRE_ADVANCED|wxRE_ICASE|wxRE_NEWLINE);
215 maloninc 1.5 exp9.Replace(&htmlText, wxT("<b><font color=\"red\">\\1</font></b>"));
216 maloninc 1.1 }
217     }
218    
219     /* make HTML document */
220     wxString wikiHtml;
221 maloninc 1.5 wikiHtml.Append(wxT("<meta http-equiv=\"Content-Type\" content=\"text/html; charset="));
222 maloninc 1.1 wikiHtml.Append(wxT(CODE_SET_SYSTEM));
223     wikiHtml.Append(wxT("\">"));
224     wikiHtml.Append(wxT("<pre>"));
225 maloninc 1.4 wikiHtml.Append(wxT("<html>"));
226     wikiHtml.Append(htmlText.c_str());
227 maloninc 1.1 wikiHtml.Append(wxT("</pre>"));
228 maloninc 1.4 wikiHtml.Append(wxT("</html>"));
229 maloninc 1.1
230     wikiHtmlTextCtrl->SetPage(wikiHtml);
231     }
232    
233     void mnNotePanel::showSelectedItemText(wxTreeEvent& event)
234     {
235     wxTreeItemId id;
236     wxTreeItemData* item;
237    
238     id = searchTree->GetSelection();
239     item = searchTree->GetItemData(id);
240    
241     if(!id.IsOk() || !isEditableTreeLabel(id) || item == NULL) { /* selection is not memo data */
242 maloninc 1.5 wikiHtmlTextCtrl->SetPage(wxT("<html></html>"));
243 maloninc 1.1 return;
244     }
245     makeHtml((WikiData*)item, false);
246     }
247    
248     wxTreeItemId mnNotePanel::getSelection()
249     {
250     return searchTree->GetSelection();
251     }
252    
253     void mnNotePanel::highlightSelectedItem()
254     {
255     wxTreeItemData* item = getSelectedItem();
256    
257     if(!isEditableTreeLabel(searchTree->GetSelection())) { /* selection is not memo data */
258     wikiHtmlTextCtrl->SetPage(wxT(""));
259     return;
260     }
261    
262     if(highlight){
263     makeHtml((WikiData*)item, false);
264     }
265     else {
266     makeHtml((WikiData*)item, true);
267     }
268     }
269    
270 maloninc 1.2
271 maloninc 1.1 void mnNotePanel::expandAllTree()
272     {
273     wxTreeItemIdValue cookie;
274     wxTreeItemId itemId;
275    
276     memset(&cookie, 1, sizeof(cookie));
277     itemId = searchTree->GetFirstChild(searchItemRoot, cookie);
278     while(itemId.IsOk()) {
279     searchTree->Expand(itemId);
280     itemId = searchTree->GetNextChild(searchItemRoot, cookie);
281     }
282     }
283    
284     void mnNotePanel::collapseAllTree()
285     {
286     wxTreeItemIdValue cookie;
287     wxTreeItemId itemId;
288    
289     memset(&cookie, 1, sizeof(cookie));
290     itemId = searchTree->GetFirstChild(searchItemRoot, cookie);
291     while(itemId.IsOk()) {
292     searchTree->Collapse(itemId);
293     itemId = searchTree->GetNextChild(searchItemRoot, cookie);
294     }
295     }
296    
297     void mnNotePanel::clearAllTree()
298     {
299     wxTreeItemIdValue cookie1, cookie2;
300     wxTreeItemId searchStrId;
301     wxTreeItemId wikiDataId;
302    
303     memset(&cookie1, 1, sizeof(cookie1));
304     memset(&cookie2, 2, sizeof(cookie2));
305     searchStrId = searchTree->GetFirstChild(searchItemRoot, cookie1);
306     while(searchStrId.IsOk()) {
307     wikiDataId = searchTree->GetFirstChild(searchStrId, cookie2);
308     while(wikiDataId.IsOk()) {
309     searchTree->SetItemData(wikiDataId, NULL);
310     wikiDataId = searchTree->GetNextChild(searchStrId, cookie2);
311     }
312     searchStrId = searchTree->GetNextChild(searchItemRoot, cookie1);
313     }
314    
315     searchTree->DeleteChildren(searchItemRoot);
316     }
317    
318     void mnNotePanel::removeSelectedItem()
319     {
320     searchTree->Delete(searchTree->GetSelection());
321     }
322    
323     wxTreeItemData* mnNotePanel::getSelectedItem()
324     {
325     return searchTree->GetItemData(searchTree->GetSelection());
326     }
327    
328     wxString mnNotePanel::getSelectedLabel()
329     {
330     return searchTree->GetItemText(searchTree->GetSelection());
331     }
332    
333     bool mnNotePanel::isEditableTreeLabel(wxTreeItemId id)
334     {
335     if(id.IsOk()){
336     return !(searchTree->GetItemParent(id) == searchItemRoot || id == searchItemRoot);
337     }
338     else {
339     return false;
340     }
341     }
342    

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