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.18 - (hide annotations) (download) (as text)
Thu Sep 15 09:20:48 2005 UTC (18 years, 7 months ago) by maloninc
Branch: MAIN
CVS Tags: dev_1_3-0005
Changes since 1.17: +70 -7 lines
File MIME type: text/x-c++src
implement effective update, but it's incomplete. (9/15)

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.18 /*
119 maloninc 1.1 const wxArrayString* searchStrList;
120     int i;
121    
122     searchTree->DeleteChildren(searchItemRoot);
123    
124     searchStrList = wiki->getSearchStrList();
125     for(i = 0; i < searchStrList->Count(); i++) {
126     wxString& searchStr = searchStrList->Item(i);
127 maloninc 1.17 addSearchResult(wiki, &searchStr, isExpand);
128 maloninc 1.1 }
129    
130     searchTree->ScrollTo(searchItemRoot);
131 maloninc 1.18 */
132     wxLogMessage(wxT("showSearchResult was invalid"));
133     }
134    
135     void mnFrame::updateSearchResult(mnModel* wiki, wxString* searchStr, bool isExpand)
136     {
137     wxTreeItemIdValue cookie1, cookie2;
138     wxTreeItemId searchStrId;
139     wxTreeItemId wikiDataId;
140     const WikiList* wikiList;
141     WikiList::Node* node;
142     WikiData* data;
143     const wxString* subject;
144    
145     memset(&cookie1, 1, sizeof(cookie1));
146     memset(&cookie2, 2, sizeof(cookie2));
147     searchStrId = searchTree->GetFirstChild(searchItemRoot, cookie1);
148     while(searchStrId.IsOk()) {
149     if(searchTree->GetItemText(searchStrId) == *searchStr) {
150     wikiDataId = searchTree->GetFirstChild(searchStrId, cookie2);
151     while(wikiDataId.IsOk()) {
152     searchTree->SetItemData(wikiDataId, NULL);
153     wikiDataId = searchTree->GetNextChild(searchStrId, cookie2);
154     }
155     searchTree->DeleteChildren(searchStrId);
156     break;
157     }
158     searchStrId = searchTree->GetNextChild(searchItemRoot, cookie1);
159     }
160    
161     wikiList = wiki->getSearchResultList(searchStr);
162     node = wikiList->GetFirst();
163     while(node) {
164     data = node->GetData();
165     subject = data->getSubject();
166     searchTree->AppendItem(searchStrId, *subject, -1, -1, (wxTreeItemData*)data);
167     node = node->GetNext();
168     }
169     if(isExpand){
170     searchTree->Expand(searchStrId);
171     }
172     else {
173     searchTree->Collapse(searchStrId);
174     }
175 maloninc 1.1 }
176    
177 maloninc 1.17 void mnFrame::addSearchResult(mnModel* wiki, wxString* searchStr, bool isExpand)
178 maloninc 1.1 {
179     wxTreeItemId searchItem;
180 maloninc 1.18 const WikiList* wikiList;
181 maloninc 1.1 WikiList::Node* node;
182     WikiData* data;
183     const wxString* subject;
184    
185 maloninc 1.18 wikiList = wiki->getSearchResultList(searchStr);
186 maloninc 1.17 //searchItem = searchTree->AppendItem(searchItemRoot, *searchStr, -1, -1, NULL);
187     searchItem = searchTree->InsertItem(searchItemRoot, 0, *searchStr, -1, -1, NULL);
188 maloninc 1.1 node = wikiList->GetFirst();
189     while(node) {
190     data = node->GetData();
191     subject = data->getSubject();
192     searchTree->AppendItem(searchItem, *subject, -1, -1, (wxTreeItemData*)data);
193     node = node->GetNext();
194     }
195 maloninc 1.15
196 maloninc 1.1 searchTree->Expand(searchItemRoot);
197 maloninc 1.15 if(isExpand){
198     searchTree->Expand(searchItem);
199     }
200     else {
201     searchTree->Collapse(searchItem);
202     }
203 maloninc 1.1 }
204    
205 maloninc 1.13 void mnFrame::makeHtml(WikiData* wikiData, bool isHighlight)
206 maloninc 1.1 {
207 maloninc 1.13 const wxString* fileName = wikiData->getFileName();
208     const wxString* wikiText = wikiData->getText();
209 maloninc 1.7 wxString htmlText(*wikiText);
210    
211 maloninc 1.12 /* escape < */
212     wxRegEx exp01(wxT("<"), wxRE_NEWLINE|wxRE_DEFAULT);
213     exp01.Replace(&htmlText, wxT("\\&lt "));
214    
215     /* escape > */
216     wxRegEx exp02(wxT(">"), wxRE_NEWLINE|wxRE_DEFAULT);
217     exp02.Replace(&htmlText, wxT("\\&gt "));
218 maloninc 1.13
219 maloninc 1.7 /* [[ ]] */
220 maloninc 1.10 wxRegEx exp1(wxT("\\[\\[([^\\}]+)\\]\\]"));
221 maloninc 1.7 exp1.Replace(&htmlText, wxT("<a href=mnlink:\\1>\\1</a>"));
222    
223     /* http:// */
224 maloninc 1.14 wxRegEx exp2(wxT("(http://[-_.!~*'a-zA-Z0-9;/?:@&=+$,%#]+)"), wxRE_NEWLINE|wxRE_DEFAULT);
225 maloninc 1.7 exp2.Replace(&htmlText, wxT("<a href=\\1>\\1</a>"));
226    
227 maloninc 1.8 /* file:// */
228 maloninc 1.11 wxRegEx exp3(wxT("(file://[^ ]+)"), wxRE_NEWLINE|wxRE_DEFAULT);
229 maloninc 1.8 exp3.Replace(&htmlText, wxT("<a href=\\1>\\1</a>"));
230    
231     /* *XXXX */
232     wxRegEx exp4(wxT("^\\*([^\\*]+)"), wxRE_NEWLINE|wxRE_DEFAULT);
233     exp4.Replace(&htmlText, wxT("<h3>\\1</h3>"));
234    
235     /* **XXXX */
236     wxRegEx exp5(wxT("^\\*\\*([^\\*]+)"), wxRE_NEWLINE|wxRE_DEFAULT);
237     exp5.Replace(&htmlText, wxT("<h4>\\1</h4>"));
238    
239     /* :''XXXX'': */
240     wxRegEx exp6(wxT("^:''(.+)'':(.+)"), wxRE_NEWLINE|wxRE_DEFAULT);
241     exp6.Replace(&htmlText, wxT("<u><b>\\1:\\2</b></u>"));
242    
243     /* ---- */
244 maloninc 1.10 wxRegEx exp7(wxT("^----.*"), wxRE_NEWLINE|wxRE_DEFAULT);
245 maloninc 1.8 exp7.Replace(&htmlText, wxT("<hr>"));
246    
247 maloninc 1.10 /* {{ }} */
248     wxRegEx exp8(wxT("\\{\\{([^\\}]+)\\}\\}"));
249     exp8.Replace(&htmlText, wxT("<a href=mndoc:\\1>\\1</a>"));
250    
251 maloninc 1.13 /* Highlight search text */
252     highlight = isHighlight;
253     if(isHighlight) {
254     wxTreeItemId parentId = searchTree->GetItemParent(searchTree->GetSelection());
255     wxString searchWords = searchTree->GetItemText(parentId);
256     wxStringTokenizer tkz(searchWords, wxT(" "));
257     while ( tkz.HasMoreTokens() )
258     {
259     wxString token = tkz.GetNextToken();
260     wxRegEx exp9(wxT("(?!<[^>]+)(") + token + wxT(")(?![^<]+>)"), wxRE_ADVANCED|wxRE_ICASE|wxRE_NEWLINE);
261     exp9.Replace(&htmlText, wxT("<b><font color=\"red\">\\1</font></b>"));
262     }
263     }
264    
265    
266 maloninc 1.7 /* make HTML document */
267 maloninc 1.8 wxString wikiHtml;
268 maloninc 1.9 wikiHtml.Append(wxT("<meta http-equiv=\"Content-Type\"content=\"text/html; charset="));
269     wikiHtml.Append(wxT(CODE_SET_SYSTEM));
270 maloninc 1.10 wikiHtml.Append(wxT("\">"));
271     wikiHtml.Append(wxT("<pre>"));
272 maloninc 1.8 wikiHtml.Append(htmlText);
273     wikiHtml.Append(wxT("</pre>"));
274    
275 maloninc 1.2 wikiHtmlTextCtrl->SetPage(wikiHtml);
276 maloninc 1.1 }
277    
278 maloninc 1.13 void mnFrame::showSelectedItemText(wxTreeEvent& event)
279     {
280 maloninc 1.18 wxTreeItemId id;
281     wxTreeItemData* item;
282    
283     id = searchTree->GetSelection();
284     if(!id.IsOk()) return ;
285     item = searchTree->GetItemData(id);
286    
287     if(item == NULL) return ;
288    
289     if(!isEditableTreeLabel(id)) { /* selection is not memo data */
290 maloninc 1.13 wikiHtmlTextCtrl->SetPage(wxT(""));
291     return;
292     }
293 maloninc 1.18 makeHtml((WikiData*)item, false);
294     }
295 maloninc 1.13
296 maloninc 1.18 wxTreeItemId mnFrame::getSelection()
297     {
298     return searchTree->GetSelection();
299 maloninc 1.13 }
300    
301     void mnFrame::highlightSelectedItem()
302     {
303     wxTreeItemData* item = getSelectedItem();
304 maloninc 1.18
305     if(!isEditableTreeLabel(searchTree->GetSelection())) { /* selection is not memo data */
306 maloninc 1.13 wikiHtmlTextCtrl->SetPage(wxT(""));
307     return;
308     }
309    
310     if(highlight){
311     makeHtml((WikiData*)item, false);
312     }
313     else {
314     makeHtml((WikiData*)item, true);
315     }
316     }
317 maloninc 1.1
318 maloninc 1.17 void mnFrame::expandAllTree()
319     {
320     wxTreeItemIdValue cookie;
321     wxTreeItemId itemId;
322    
323     memset(&cookie, 1, sizeof(cookie));
324     itemId = searchTree->GetFirstChild(searchItemRoot, cookie);
325     while(itemId.IsOk()) {
326     searchTree->Expand(itemId);
327     itemId = searchTree->GetNextChild(searchItemRoot, cookie);
328     }
329     }
330    
331     void mnFrame::collapseAllTree()
332     {
333     wxTreeItemIdValue cookie;
334     wxTreeItemId itemId;
335    
336     memset(&cookie, 1, sizeof(cookie));
337     itemId = searchTree->GetFirstChild(searchItemRoot, cookie);
338     while(itemId.IsOk()) {
339     searchTree->Collapse(itemId);
340     itemId = searchTree->GetNextChild(searchItemRoot, cookie);
341     }
342     }
343    
344     void mnFrame::clearAllTree()
345     {
346     searchTree->DeleteChildren(searchItemRoot);
347     }
348    
349     void mnFrame::removeSelectedItem()
350     {
351     searchTree->DeleteChildren(searchTree->GetSelection());
352     }
353    
354 maloninc 1.1 wxTreeItemData* mnFrame::getSelectedItem()
355     {
356     return searchTree->GetItemData(searchTree->GetSelection());
357     }
358    
359     wxString mnFrame::getSelectedLabel()
360     {
361     return searchTree->GetItemText(searchTree->GetSelection());
362     }
363    
364     bool mnFrame::isEditableTreeLabel(wxTreeItemId id)
365     {
366 maloninc 1.18 if(id.IsOk()){
367     return !(searchTree->GetItemParent(id) == searchItemRoot || id == searchItemRoot);
368     }
369     else {
370     return false;
371     }
372 maloninc 1.1 }
373    

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