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.21 - (hide annotations) (download) (as text)
Sat Oct 1 05:43:58 2005 UTC (18 years, 6 months ago) by maloninc
Branch: MAIN
Changes since 1.20: +14 -0 lines
File MIME type: text/x-c++src
implement table

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 exp13(wxT("\n\n<tr>"));
163     exp13.Replace(&htmlText, wxT("\n<table border>\n<tr>"));
164     wxRegEx exp14(wxT("</tr>\n\n"));
165     exp14.Replace(&htmlText, wxT("</tr>\n</table>\n"));
166     wxRegEx exp15(wxT("</tr>\n"));
167     exp15.Replace(&htmlText, wxT("</tr>"));
168    
169 maloninc 1.13 /* Highlight search text */
170     highlight = isHighlight;
171     if(isHighlight) {
172     wxTreeItemId parentId = searchTree->GetItemParent(searchTree->GetSelection());
173     wxString searchWords = searchTree->GetItemText(parentId);
174     wxStringTokenizer tkz(searchWords, wxT(" "));
175     while ( tkz.HasMoreTokens() )
176     {
177     wxString token = tkz.GetNextToken();
178     wxRegEx exp9(wxT("(?!<[^>]+)(") + token + wxT(")(?![^<]+>)"), wxRE_ADVANCED|wxRE_ICASE|wxRE_NEWLINE);
179     exp9.Replace(&htmlText, wxT("<b><font color=\"red\">\\1</font></b>"));
180     }
181     }
182    
183    
184 maloninc 1.7 /* make HTML document */
185 maloninc 1.8 wxString wikiHtml;
186 maloninc 1.9 wikiHtml.Append(wxT("<meta http-equiv=\"Content-Type\"content=\"text/html; charset="));
187     wikiHtml.Append(wxT(CODE_SET_SYSTEM));
188 maloninc 1.10 wikiHtml.Append(wxT("\">"));
189     wikiHtml.Append(wxT("<pre>"));
190 maloninc 1.8 wikiHtml.Append(htmlText);
191     wikiHtml.Append(wxT("</pre>"));
192    
193 maloninc 1.2 wikiHtmlTextCtrl->SetPage(wikiHtml);
194 maloninc 1.1 }
195    
196 maloninc 1.13 void mnFrame::showSelectedItemText(wxTreeEvent& event)
197     {
198 maloninc 1.18 wxTreeItemId id;
199     wxTreeItemData* item;
200    
201     id = searchTree->GetSelection();
202     item = searchTree->GetItemData(id);
203    
204 maloninc 1.19 if(!id.IsOk() || !isEditableTreeLabel(id) || item == NULL) { /* selection is not memo data */
205 maloninc 1.13 wikiHtmlTextCtrl->SetPage(wxT(""));
206     return;
207     }
208 maloninc 1.18 makeHtml((WikiData*)item, false);
209     }
210 maloninc 1.13
211 maloninc 1.18 wxTreeItemId mnFrame::getSelection()
212     {
213     return searchTree->GetSelection();
214 maloninc 1.13 }
215    
216     void mnFrame::highlightSelectedItem()
217     {
218     wxTreeItemData* item = getSelectedItem();
219 maloninc 1.18
220     if(!isEditableTreeLabel(searchTree->GetSelection())) { /* selection is not memo data */
221 maloninc 1.13 wikiHtmlTextCtrl->SetPage(wxT(""));
222     return;
223     }
224    
225     if(highlight){
226     makeHtml((WikiData*)item, false);
227     }
228     else {
229     makeHtml((WikiData*)item, true);
230     }
231     }
232 maloninc 1.1
233 maloninc 1.17 void mnFrame::expandAllTree()
234     {
235     wxTreeItemIdValue cookie;
236     wxTreeItemId itemId;
237    
238     memset(&cookie, 1, sizeof(cookie));
239     itemId = searchTree->GetFirstChild(searchItemRoot, cookie);
240     while(itemId.IsOk()) {
241     searchTree->Expand(itemId);
242     itemId = searchTree->GetNextChild(searchItemRoot, cookie);
243     }
244     }
245    
246     void mnFrame::collapseAllTree()
247     {
248     wxTreeItemIdValue cookie;
249     wxTreeItemId itemId;
250    
251     memset(&cookie, 1, sizeof(cookie));
252     itemId = searchTree->GetFirstChild(searchItemRoot, cookie);
253     while(itemId.IsOk()) {
254     searchTree->Collapse(itemId);
255     itemId = searchTree->GetNextChild(searchItemRoot, cookie);
256     }
257     }
258    
259     void mnFrame::clearAllTree()
260     {
261 maloninc 1.19 wxTreeItemIdValue cookie1, cookie2;
262     wxTreeItemId searchStrId;
263     wxTreeItemId wikiDataId;
264    
265     memset(&cookie1, 1, sizeof(cookie1));
266     memset(&cookie2, 2, sizeof(cookie2));
267     searchStrId = searchTree->GetFirstChild(searchItemRoot, cookie1);
268     while(searchStrId.IsOk()) {
269     wikiDataId = searchTree->GetFirstChild(searchStrId, cookie2);
270     while(wikiDataId.IsOk()) {
271     searchTree->SetItemData(wikiDataId, NULL);
272     wikiDataId = searchTree->GetNextChild(searchStrId, cookie2);
273     }
274     searchStrId = searchTree->GetNextChild(searchItemRoot, cookie1);
275     }
276    
277 maloninc 1.17 searchTree->DeleteChildren(searchItemRoot);
278     }
279    
280     void mnFrame::removeSelectedItem()
281     {
282 maloninc 1.19 searchTree->Delete(searchTree->GetSelection());
283 maloninc 1.17 }
284    
285 maloninc 1.1 wxTreeItemData* mnFrame::getSelectedItem()
286     {
287     return searchTree->GetItemData(searchTree->GetSelection());
288     }
289    
290     wxString mnFrame::getSelectedLabel()
291     {
292     return searchTree->GetItemText(searchTree->GetSelection());
293     }
294    
295     bool mnFrame::isEditableTreeLabel(wxTreeItemId id)
296     {
297 maloninc 1.18 if(id.IsOk()){
298     return !(searchTree->GetItemParent(id) == searchItemRoot || id == searchItemRoot);
299     }
300     else {
301     return false;
302     }
303 maloninc 1.1 }
304    

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