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.19 - (hide annotations) (download) (as text)
Fri Sep 16 04:12:58 2005 UTC (18 years, 7 months ago) by maloninc
Branch: MAIN
CVS Tags: rel_1_3, dev_1_3-0008, dev_1_3-0006, dev_1_3-0007, dev_1_4-0001
Changes since 1.18: +29 -20 lines
File MIME type: text/x-c++src
implement group by TYPE, but it may be bugy? (9/16)

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.1 #include "mnID.h"
5     #include "mnDef.h"
6     #include "mnFrame.h"
7 maloninc 1.3 #include "mnDialog.h"
8 maloninc 1.1
9    
10     mnFrame::mnFrame(wxWindow* parent, int id, const wxString& title, const wxPoint& pos, const wxSize& size, long style):
11     wxFrame(parent, id, title, pos, size, wxDEFAULT_FRAME_STYLE)
12     {
13     // begin wxGlade: mnFrame::mnFrame
14     splitWindow = new wxSplitterWindow(this, -1, wxDefaultPosition, wxDefaultSize, wxSP_3D|wxSP_BORDER);
15     rightPanel = new wxPanel(splitWindow, -1);
16     leftPanel = new wxPanel(splitWindow, -1);
17     panel = new wxPanel(this, -1);
18     searchLaebl = new wxStaticText(panel, -1, wxT("Search"), wxDefaultPosition, wxDefaultSize, wxALIGN_CENTRE);
19     searchTextCtrl = new wxTextCtrl(this, ID_SearchTextCtrl, wxT(""), wxDefaultPosition, wxDefaultSize, wxTE_PROCESS_ENTER);
20     searchTree = new wxTreeCtrl(leftPanel, ID_SearchTree, wxDefaultPosition, wxDefaultSize, wxTR_HAS_BUTTONS|wxTR_LINES_AT_ROOT|wxTR_DEFAULT_STYLE|wxSUNKEN_BORDER|wxTR_EDIT_LABELS);
21 maloninc 1.7 wikiHtmlTextCtrl = new mnHtmlWindow(rightPanel, ID_HtmlTextCtrl);
22 maloninc 1.1
23     // begin add by hand
24     menuBar = new wxMenuBar();
25     SetMenuBar(menuBar);
26    
27     // File menu
28     wxMenu* tmp_menu_1 = new wxMenu();
29     tmp_menu_1->Append(ID_MenuFileNew, _("New\tCtrl+N"), wxT(""), wxITEM_NORMAL);
30 maloninc 1.2 tmp_menu_1->Append(ID_MenuFileEdit, _("Edit\tCtrl+E"), wxT(""), wxITEM_NORMAL);
31 maloninc 1.1 tmp_menu_1->Append(ID_MenuFileRemove, _("Remove\tCtrl+R"), wxT(""), wxITEM_NORMAL);
32 maloninc 1.13 tmp_menu_1->Append(ID_MenuFileHighlight, _("Highlight\tCtrl+L"), wxT(""), wxITEM_NORMAL);
33 maloninc 1.2 tmp_menu_1->AppendSeparator();
34 maloninc 1.16 tmp_menu_1->Append(ID_MenuFileGroup, _("Group by TYPE\tCtrl+G"), wxT(""), wxITEM_NORMAL);
35     tmp_menu_1->AppendSeparator();
36 maloninc 1.1 tmp_menu_1->Append(ID_MenuFileConfig, _("Configure..."), wxT(""), wxITEM_NORMAL);
37 maloninc 1.2 tmp_menu_1->AppendSeparator();
38 maloninc 1.1 tmp_menu_1->Append(ID_MenuFileExit, _("Quit\tCtrl+Q"), wxT(""), wxITEM_NORMAL);
39     menuBar->Append(tmp_menu_1, _("&File"));
40 maloninc 1.17
41     // Tree menu
42     wxMenu* tmp_menu_3 = new wxMenu();
43     tmp_menu_3->Append(ID_MenuTreeExpand, _("Expand All\tCtrl+D"), wxT(""), wxITEM_NORMAL);
44     tmp_menu_3->Append(ID_MenuTreeCollapse, _("Collapse All\tCtrl+U"), wxT(""), wxITEM_NORMAL);
45     tmp_menu_3->Append(ID_MenuTreeClear, _("Clear All\tCtrl+K"), wxT(""), wxITEM_NORMAL);
46     //tmp_menu_3->AppendSeparator();
47     //tmp_menu_3->AppendCheckItem(ID_MenuTreeDisableUpdate, _("Disable AutoUpdate"));
48     menuBar->Append(tmp_menu_3, _("&Tree"));
49 maloninc 1.1
50     // Help menu
51     wxMenu* tmp_menu_2 = new wxMenu();
52     tmp_menu_2->Append(wxID_ABOUT, _("&About"), wxT(""), wxITEM_NORMAL);
53     menuBar->Append(tmp_menu_2, _("&Help"));
54    
55     #ifdef __WXMSW__
56     wxIcon icon(wxT(APP_ICON_NAME), wxBITMAP_TYPE_ICO_RESOURCE);
57     SetIcon(icon);
58     #endif
59     // end add by hand
60    
61     set_properties();
62     do_layout();
63     // end wxGlade
64    
65     /* create search tree */
66     searchItemRoot = searchTree->AddRoot(wxT(LABEL_ITEM_TREE), -1, -1, NULL);
67     }
68    
69     void mnFrame::set_properties()
70     {
71     // begin wxGlade: mnFrame::set_properties
72     SetTitle(wxT("Malon Note"));
73     SetSize(wxSize(900, 572));
74     searchTextCtrl->SetFocus();
75     // end wxGlade
76 maloninc 1.10
77     wxFont font(12, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL);
78     wikiHtmlTextCtrl->SetFonts(font.GetFaceName(), font.GetFaceName());
79 maloninc 1.1 }
80    
81    
82     void mnFrame::do_layout()
83     {
84     wxBoxSizer* mainSizer = new wxBoxSizer(wxVERTICAL);
85 maloninc 1.3 rightPanelSizer = new wxGridSizer(1, 1, 0, 0);
86 maloninc 1.1 wxBoxSizer* leftPanelSizer = new wxBoxSizer(wxHORIZONTAL);
87     wxBoxSizer* topSizer = new wxBoxSizer(wxHORIZONTAL);
88     wxBoxSizer* labelSizer = new wxBoxSizer(wxHORIZONTAL);
89     labelSizer->Add(searchLaebl, 0, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
90     panel->SetAutoLayout(true);
91     panel->SetSizer(labelSizer);
92     labelSizer->Fit(panel);
93     labelSizer->SetSizeHints(panel);
94     topSizer->Add(panel, 0, wxEXPAND, 0);
95     topSizer->Add(searchTextCtrl, 1, wxTOP|wxBOTTOM|wxEXPAND|wxFIXED_MINSIZE, 1);
96     mainSizer->Add(topSizer, 0, wxEXPAND, 0);
97     leftPanelSizer->Add(searchTree, 1, wxEXPAND, 0);
98     leftPanel->SetAutoLayout(true);
99     leftPanel->SetSizer(leftPanelSizer);
100     leftPanelSizer->Fit(leftPanel);
101     leftPanelSizer->SetSizeHints(leftPanel);
102 maloninc 1.2 rightPanelSizer->Add(wikiHtmlTextCtrl, 0, wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 0);
103 maloninc 1.1 rightPanel->SetAutoLayout(true);
104     rightPanel->SetSizer(rightPanelSizer);
105     rightPanelSizer->Fit(rightPanel);
106     rightPanelSizer->SetSizeHints(rightPanel);
107     splitWindow->SplitVertically(leftPanel, rightPanel, 250);
108     mainSizer->Add(splitWindow, 1, wxEXPAND, 0);
109     SetAutoLayout(true);
110     SetSizer(mainSizer);
111     Layout();
112    
113     searchTree->Expand(searchItemRoot);
114     }
115    
116 maloninc 1.15 void mnFrame::showSearchResult(mnModel* wiki, bool isExpand)
117 maloninc 1.1 {
118 maloninc 1.19 wxLogMessage(wxT("showSearchResult is not available"));
119 maloninc 1.18 }
120    
121     void mnFrame::updateSearchResult(mnModel* wiki, wxString* searchStr, bool isExpand)
122     {
123     wxTreeItemIdValue cookie1, cookie2;
124     wxTreeItemId searchStrId;
125     wxTreeItemId wikiDataId;
126     const WikiList* wikiList;
127     WikiList::Node* node;
128     WikiData* data;
129     const wxString* subject;
130    
131     memset(&cookie1, 1, sizeof(cookie1));
132     memset(&cookie2, 2, sizeof(cookie2));
133     searchStrId = searchTree->GetFirstChild(searchItemRoot, cookie1);
134     while(searchStrId.IsOk()) {
135     if(searchTree->GetItemText(searchStrId) == *searchStr) {
136     wikiDataId = searchTree->GetFirstChild(searchStrId, cookie2);
137     while(wikiDataId.IsOk()) {
138     searchTree->SetItemData(wikiDataId, NULL);
139     wikiDataId = searchTree->GetNextChild(searchStrId, cookie2);
140     }
141     searchTree->DeleteChildren(searchStrId);
142     break;
143     }
144     searchStrId = searchTree->GetNextChild(searchItemRoot, cookie1);
145     }
146    
147     wikiList = wiki->getSearchResultList(searchStr);
148 maloninc 1.19 if(wikiList == NULL) {
149     MN_FATAL_ERROR(wxT("wikiList is null"));
150     return;
151     }
152    
153 maloninc 1.18 node = wikiList->GetFirst();
154     while(node) {
155     data = node->GetData();
156     subject = data->getSubject();
157     searchTree->AppendItem(searchStrId, *subject, -1, -1, (wxTreeItemData*)data);
158     node = node->GetNext();
159     }
160     if(isExpand){
161     searchTree->Expand(searchStrId);
162     }
163     else {
164     searchTree->Collapse(searchStrId);
165     }
166 maloninc 1.1 }
167    
168 maloninc 1.17 void mnFrame::addSearchResult(mnModel* wiki, wxString* searchStr, bool isExpand)
169 maloninc 1.1 {
170     wxTreeItemId searchItem;
171 maloninc 1.18 const WikiList* wikiList;
172 maloninc 1.1 WikiList::Node* node;
173     WikiData* data;
174     const wxString* subject;
175    
176 maloninc 1.18 wikiList = wiki->getSearchResultList(searchStr);
177 maloninc 1.19 if(wikiList == NULL) {
178     MN_FATAL_ERROR(wxT("wikiList is null"));
179     return;
180     }
181    
182 maloninc 1.17 //searchItem = searchTree->AppendItem(searchItemRoot, *searchStr, -1, -1, NULL);
183     searchItem = searchTree->InsertItem(searchItemRoot, 0, *searchStr, -1, -1, NULL);
184 maloninc 1.1 node = wikiList->GetFirst();
185     while(node) {
186     data = node->GetData();
187     subject = data->getSubject();
188     searchTree->AppendItem(searchItem, *subject, -1, -1, (wxTreeItemData*)data);
189     node = node->GetNext();
190     }
191 maloninc 1.15
192 maloninc 1.1 searchTree->Expand(searchItemRoot);
193 maloninc 1.15 if(isExpand){
194     searchTree->Expand(searchItem);
195     }
196     else {
197     searchTree->Collapse(searchItem);
198     }
199 maloninc 1.1 }
200    
201 maloninc 1.13 void mnFrame::makeHtml(WikiData* wikiData, bool isHighlight)
202 maloninc 1.1 {
203 maloninc 1.13 const wxString* fileName = wikiData->getFileName();
204     const wxString* wikiText = wikiData->getText();
205 maloninc 1.7 wxString htmlText(*wikiText);
206    
207 maloninc 1.12 /* escape < */
208     wxRegEx exp01(wxT("<"), wxRE_NEWLINE|wxRE_DEFAULT);
209     exp01.Replace(&htmlText, wxT("\\&lt "));
210    
211     /* escape > */
212     wxRegEx exp02(wxT(">"), wxRE_NEWLINE|wxRE_DEFAULT);
213     exp02.Replace(&htmlText, wxT("\\&gt "));
214 maloninc 1.13
215 maloninc 1.7 /* [[ ]] */
216 maloninc 1.10 wxRegEx exp1(wxT("\\[\\[([^\\}]+)\\]\\]"));
217 maloninc 1.7 exp1.Replace(&htmlText, wxT("<a href=mnlink:\\1>\\1</a>"));
218    
219     /* http:// */
220 maloninc 1.14 wxRegEx exp2(wxT("(http://[-_.!~*'a-zA-Z0-9;/?:@&=+$,%#]+)"), wxRE_NEWLINE|wxRE_DEFAULT);
221 maloninc 1.7 exp2.Replace(&htmlText, wxT("<a href=\\1>\\1</a>"));
222    
223 maloninc 1.8 /* file:// */
224 maloninc 1.11 wxRegEx exp3(wxT("(file://[^ ]+)"), wxRE_NEWLINE|wxRE_DEFAULT);
225 maloninc 1.8 exp3.Replace(&htmlText, wxT("<a href=\\1>\\1</a>"));
226    
227     /* *XXXX */
228     wxRegEx exp4(wxT("^\\*([^\\*]+)"), wxRE_NEWLINE|wxRE_DEFAULT);
229     exp4.Replace(&htmlText, wxT("<h3>\\1</h3>"));
230    
231     /* **XXXX */
232     wxRegEx exp5(wxT("^\\*\\*([^\\*]+)"), wxRE_NEWLINE|wxRE_DEFAULT);
233     exp5.Replace(&htmlText, wxT("<h4>\\1</h4>"));
234    
235     /* :''XXXX'': */
236     wxRegEx exp6(wxT("^:''(.+)'':(.+)"), wxRE_NEWLINE|wxRE_DEFAULT);
237     exp6.Replace(&htmlText, wxT("<u><b>\\1:\\2</b></u>"));
238    
239     /* ---- */
240 maloninc 1.10 wxRegEx exp7(wxT("^----.*"), wxRE_NEWLINE|wxRE_DEFAULT);
241 maloninc 1.8 exp7.Replace(&htmlText, wxT("<hr>"));
242    
243 maloninc 1.10 /* {{ }} */
244     wxRegEx exp8(wxT("\\{\\{([^\\}]+)\\}\\}"));
245     exp8.Replace(&htmlText, wxT("<a href=mndoc:\\1>\\1</a>"));
246    
247 maloninc 1.13 /* Highlight search text */
248     highlight = isHighlight;
249     if(isHighlight) {
250     wxTreeItemId parentId = searchTree->GetItemParent(searchTree->GetSelection());
251     wxString searchWords = searchTree->GetItemText(parentId);
252     wxStringTokenizer tkz(searchWords, wxT(" "));
253     while ( tkz.HasMoreTokens() )
254     {
255     wxString token = tkz.GetNextToken();
256     wxRegEx exp9(wxT("(?!<[^>]+)(") + token + wxT(")(?![^<]+>)"), wxRE_ADVANCED|wxRE_ICASE|wxRE_NEWLINE);
257     exp9.Replace(&htmlText, wxT("<b><font color=\"red\">\\1</font></b>"));
258     }
259     }
260    
261    
262 maloninc 1.7 /* make HTML document */
263 maloninc 1.8 wxString wikiHtml;
264 maloninc 1.9 wikiHtml.Append(wxT("<meta http-equiv=\"Content-Type\"content=\"text/html; charset="));
265     wikiHtml.Append(wxT(CODE_SET_SYSTEM));
266 maloninc 1.10 wikiHtml.Append(wxT("\">"));
267     wikiHtml.Append(wxT("<pre>"));
268 maloninc 1.8 wikiHtml.Append(htmlText);
269     wikiHtml.Append(wxT("</pre>"));
270    
271 maloninc 1.2 wikiHtmlTextCtrl->SetPage(wikiHtml);
272 maloninc 1.1 }
273    
274 maloninc 1.13 void mnFrame::showSelectedItemText(wxTreeEvent& event)
275     {
276 maloninc 1.18 wxTreeItemId id;
277     wxTreeItemData* item;
278    
279     id = searchTree->GetSelection();
280     item = searchTree->GetItemData(id);
281    
282 maloninc 1.19 if(!id.IsOk() || !isEditableTreeLabel(id) || item == NULL) { /* selection is not memo data */
283 maloninc 1.13 wikiHtmlTextCtrl->SetPage(wxT(""));
284     return;
285     }
286 maloninc 1.18 makeHtml((WikiData*)item, false);
287     }
288 maloninc 1.13
289 maloninc 1.18 wxTreeItemId mnFrame::getSelection()
290     {
291     return searchTree->GetSelection();
292 maloninc 1.13 }
293    
294     void mnFrame::highlightSelectedItem()
295     {
296     wxTreeItemData* item = getSelectedItem();
297 maloninc 1.18
298     if(!isEditableTreeLabel(searchTree->GetSelection())) { /* selection is not memo data */
299 maloninc 1.13 wikiHtmlTextCtrl->SetPage(wxT(""));
300     return;
301     }
302    
303     if(highlight){
304     makeHtml((WikiData*)item, false);
305     }
306     else {
307     makeHtml((WikiData*)item, true);
308     }
309     }
310 maloninc 1.1
311 maloninc 1.17 void mnFrame::expandAllTree()
312     {
313     wxTreeItemIdValue cookie;
314     wxTreeItemId itemId;
315    
316     memset(&cookie, 1, sizeof(cookie));
317     itemId = searchTree->GetFirstChild(searchItemRoot, cookie);
318     while(itemId.IsOk()) {
319     searchTree->Expand(itemId);
320     itemId = searchTree->GetNextChild(searchItemRoot, cookie);
321     }
322     }
323    
324     void mnFrame::collapseAllTree()
325     {
326     wxTreeItemIdValue cookie;
327     wxTreeItemId itemId;
328    
329     memset(&cookie, 1, sizeof(cookie));
330     itemId = searchTree->GetFirstChild(searchItemRoot, cookie);
331     while(itemId.IsOk()) {
332     searchTree->Collapse(itemId);
333     itemId = searchTree->GetNextChild(searchItemRoot, cookie);
334     }
335     }
336    
337     void mnFrame::clearAllTree()
338     {
339 maloninc 1.19 wxTreeItemIdValue cookie1, cookie2;
340     wxTreeItemId searchStrId;
341     wxTreeItemId wikiDataId;
342    
343     memset(&cookie1, 1, sizeof(cookie1));
344     memset(&cookie2, 2, sizeof(cookie2));
345     searchStrId = searchTree->GetFirstChild(searchItemRoot, cookie1);
346     while(searchStrId.IsOk()) {
347     wikiDataId = searchTree->GetFirstChild(searchStrId, cookie2);
348     while(wikiDataId.IsOk()) {
349     searchTree->SetItemData(wikiDataId, NULL);
350     wikiDataId = searchTree->GetNextChild(searchStrId, cookie2);
351     }
352     searchStrId = searchTree->GetNextChild(searchItemRoot, cookie1);
353     }
354    
355 maloninc 1.17 searchTree->DeleteChildren(searchItemRoot);
356     }
357    
358     void mnFrame::removeSelectedItem()
359     {
360 maloninc 1.19 searchTree->Delete(searchTree->GetSelection());
361 maloninc 1.17 }
362    
363 maloninc 1.1 wxTreeItemData* mnFrame::getSelectedItem()
364     {
365     return searchTree->GetItemData(searchTree->GetSelection());
366     }
367    
368     wxString mnFrame::getSelectedLabel()
369     {
370     return searchTree->GetItemText(searchTree->GetSelection());
371     }
372    
373     bool mnFrame::isEditableTreeLabel(wxTreeItemId id)
374     {
375 maloninc 1.18 if(id.IsOk()){
376     return !(searchTree->GetItemParent(id) == searchItemRoot || id == searchItemRoot);
377     }
378     else {
379     return false;
380     }
381 maloninc 1.1 }
382    

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