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.20 - (hide annotations) (download) (as text)
Thu Sep 29 04:15:30 2005 UTC (18 years, 6 months ago) by maloninc
Branch: MAIN
CVS Tags: dev_1_4-0003, dev_1_4-0002, dev_1_4-0005
Changes since 1.19: +7 -99 lines
File MIME type: text/x-c++src
use XRC file for mnFrame

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

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