Develop and Download Open Source Software

Browse CVS Repository

Annotation of /malonnote/mnFrame.cpp

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


Revision 1.22 - (hide annotations) (download) (as text)
Sun Oct 2 00:13:47 2005 UTC (18 years, 6 months ago) by maloninc
Branch: MAIN
CVS Tags: rel_1_4, dev_1_4-0006
Changes since 1.21: +6 -4 lines
File MIME type: text/x-c++src
implement Table perfectly

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

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