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.17 - (hide annotations) (download) (as text)
Thu Sep 15 03:02:37 2005 UTC (18 years, 7 months ago) by maloninc
Branch: MAIN
Changes since 1.16: +51 -7 lines
File MIME type: text/x-c++src
implemet "Expand/Collpase/Clear All"

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

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