Develop and Download Open Source Software

Browse CVS Repository

Contents of /malonnote/mnFrame.cpp

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


Revision 1.22 - (show 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 // -*- 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 "mnFrame.h"
8 #include "mnDialog.h"
9
10
11 mnFrame::mnFrame(wxWindow* parent)
12 {
13 wxXmlResource::Get()->LoadFrame(this, parent, wxT("mnFrame"));
14
15 #ifdef __WXMSW__
16 wxIcon icon(wxT(APP_ICON_NAME), wxBITMAP_TYPE_ICO_RESOURCE);
17 SetIcon(icon);
18 #endif
19
20 /* init members */
21 searchTree = XRCCTRL(*this, "searchTree", wxTreeCtrl);
22 searchTextCtrl = XRCCTRL(*this, "searchTextCtrl", wxTextCtrl);
23 wikiHtmlTextCtrl = XRCCTRL(*this, "wikiHtmlTextCtrl", mnHtmlWindow);
24
25 /* create search tree */
26 searchItemRoot = searchTree->AddRoot(wxT(LABEL_ITEM_TREE), -1, -1, NULL);
27 }
28
29 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 if(wikiList == NULL) {
57 MN_FATAL_ERROR(wxT("wikiList is null"));
58 return;
59 }
60
61 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 }
75
76 void mnFrame::addSearchResult(mnModel* wiki, wxString* searchStr, bool isExpand)
77 {
78 wxTreeItemId searchItem;
79 const WikiList* wikiList;
80 WikiList::Node* node;
81 WikiData* data;
82 const wxString* subject;
83
84 wikiList = wiki->getSearchResultList(searchStr);
85 if(wikiList == NULL) {
86 MN_FATAL_ERROR(wxT("wikiList is null"));
87 return;
88 }
89
90 //searchItem = searchTree->AppendItem(searchItemRoot, *searchStr, -1, -1, NULL);
91 searchItem = searchTree->InsertItem(searchItemRoot, 0, *searchStr, -1, -1, NULL);
92 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
100 searchTree->Expand(searchItemRoot);
101 if(isExpand){
102 searchTree->Expand(searchItem);
103 }
104 else {
105 searchTree->Collapse(searchItem);
106 }
107 }
108
109 void mnFrame::makeHtml(WikiData* wikiData, bool isHighlight)
110 {
111 const wxString* fileName = wikiData->getFileName();
112 const wxString* wikiText = wikiData->getText();
113 wxString htmlText(*wikiText);
114
115 /* 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
123 /* [[ ]] */
124 wxRegEx exp1(wxT("\\[\\[([^\\}]+)\\]\\]"));
125 exp1.Replace(&htmlText, wxT("<a href=mnlink:\\1>\\1</a>"));
126
127 /* http:// */
128 wxRegEx exp2(wxT("(http://[-_.!~*'a-zA-Z0-9;/?:@&=+$,%#]+)"), wxRE_NEWLINE|wxRE_DEFAULT);
129 exp2.Replace(&htmlText, wxT("<a href=\\1>\\1</a>"));
130
131 /* file:// */
132 wxRegEx exp3(wxT("(file://[^ ]+)"), wxRE_NEWLINE|wxRE_DEFAULT);
133 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 wxRegEx exp7(wxT("^----.*"), wxRE_NEWLINE|wxRE_DEFAULT);
149 exp7.Replace(&htmlText, wxT("<hr>"));
150
151 /* {{ }} */
152 wxRegEx exp8(wxT("\\{\\{([^\\}]+)\\}\\}"));
153 exp8.Replace(&htmlText, wxT("<a href=mndoc:\\1>\\1</a>"));
154
155 /* 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
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
171 /* 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 /* make HTML document */
187 wxString wikiHtml;
188 wikiHtml.Append(wxT("<meta http-equiv=\"Content-Type\"content=\"text/html; charset="));
189 wikiHtml.Append(wxT(CODE_SET_SYSTEM));
190 wikiHtml.Append(wxT("\">"));
191 wikiHtml.Append(wxT("<pre>"));
192 wikiHtml.Append(htmlText);
193 wikiHtml.Append(wxT("</pre>"));
194
195 wikiHtmlTextCtrl->SetPage(wikiHtml);
196 }
197
198 void mnFrame::showSelectedItemText(wxTreeEvent& event)
199 {
200 wxTreeItemId id;
201 wxTreeItemData* item;
202
203 id = searchTree->GetSelection();
204 item = searchTree->GetItemData(id);
205
206 if(!id.IsOk() || !isEditableTreeLabel(id) || item == NULL) { /* selection is not memo data */
207 wikiHtmlTextCtrl->SetPage(wxT(""));
208 return;
209 }
210 makeHtml((WikiData*)item, false);
211 }
212
213 wxTreeItemId mnFrame::getSelection()
214 {
215 return searchTree->GetSelection();
216 }
217
218 void mnFrame::highlightSelectedItem()
219 {
220 wxTreeItemData* item = getSelectedItem();
221
222 if(!isEditableTreeLabel(searchTree->GetSelection())) { /* selection is not memo data */
223 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
235 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 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 searchTree->DeleteChildren(searchItemRoot);
280 }
281
282 void mnFrame::removeSelectedItem()
283 {
284 searchTree->Delete(searchTree->GetSelection());
285 }
286
287 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 if(id.IsOk()){
300 return !(searchTree->GetItemParent(id) == searchItemRoot || id == searchItemRoot);
301 }
302 else {
303 return false;
304 }
305 }
306

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