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.15 - (hide annotations) (download) (as text)
Tue Sep 13 04:22:15 2005 UTC (18 years, 7 months ago) by maloninc
Branch: MAIN
CVS Tags: dev_1_3-0003
Changes since 1.14: +10 -4 lines
File MIME type: text/x-c++src
implement searching all memo

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.1 tmp_menu_1->Append(ID_MenuFileConfig, _("Configure..."), wxT(""), wxITEM_NORMAL);
35 maloninc 1.2 tmp_menu_1->AppendSeparator();
36 maloninc 1.1 tmp_menu_1->Append(ID_MenuFileExit, _("Quit\tCtrl+Q"), wxT(""), wxITEM_NORMAL);
37     menuBar->Append(tmp_menu_1, _("&File"));
38    
39     // Help menu
40     wxMenu* tmp_menu_2 = new wxMenu();
41     tmp_menu_2->Append(wxID_ABOUT, _("&About"), wxT(""), wxITEM_NORMAL);
42     menuBar->Append(tmp_menu_2, _("&Help"));
43    
44     #ifdef __WXMSW__
45     wxIcon icon(wxT(APP_ICON_NAME), wxBITMAP_TYPE_ICO_RESOURCE);
46     SetIcon(icon);
47     #endif
48     // end add by hand
49    
50     set_properties();
51     do_layout();
52     // end wxGlade
53    
54     /* create search tree */
55     searchItemRoot = searchTree->AddRoot(wxT(LABEL_ITEM_TREE), -1, -1, NULL);
56     }
57    
58     void mnFrame::set_properties()
59     {
60     // begin wxGlade: mnFrame::set_properties
61     SetTitle(wxT("Malon Note"));
62     SetSize(wxSize(900, 572));
63     searchTextCtrl->SetFocus();
64     // end wxGlade
65 maloninc 1.10
66     wxFont font(12, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL);
67     wikiHtmlTextCtrl->SetFonts(font.GetFaceName(), font.GetFaceName());
68 maloninc 1.1 }
69    
70    
71     void mnFrame::do_layout()
72     {
73     wxBoxSizer* mainSizer = new wxBoxSizer(wxVERTICAL);
74 maloninc 1.3 rightPanelSizer = new wxGridSizer(1, 1, 0, 0);
75 maloninc 1.1 wxBoxSizer* leftPanelSizer = new wxBoxSizer(wxHORIZONTAL);
76     wxBoxSizer* topSizer = new wxBoxSizer(wxHORIZONTAL);
77     wxBoxSizer* labelSizer = new wxBoxSizer(wxHORIZONTAL);
78     labelSizer->Add(searchLaebl, 0, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
79     panel->SetAutoLayout(true);
80     panel->SetSizer(labelSizer);
81     labelSizer->Fit(panel);
82     labelSizer->SetSizeHints(panel);
83     topSizer->Add(panel, 0, wxEXPAND, 0);
84     topSizer->Add(searchTextCtrl, 1, wxTOP|wxBOTTOM|wxEXPAND|wxFIXED_MINSIZE, 1);
85     mainSizer->Add(topSizer, 0, wxEXPAND, 0);
86     leftPanelSizer->Add(searchTree, 1, wxEXPAND, 0);
87     leftPanel->SetAutoLayout(true);
88     leftPanel->SetSizer(leftPanelSizer);
89     leftPanelSizer->Fit(leftPanel);
90     leftPanelSizer->SetSizeHints(leftPanel);
91 maloninc 1.2 rightPanelSizer->Add(wikiHtmlTextCtrl, 0, wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 0);
92 maloninc 1.1 rightPanel->SetAutoLayout(true);
93     rightPanel->SetSizer(rightPanelSizer);
94     rightPanelSizer->Fit(rightPanel);
95     rightPanelSizer->SetSizeHints(rightPanel);
96     splitWindow->SplitVertically(leftPanel, rightPanel, 250);
97     mainSizer->Add(splitWindow, 1, wxEXPAND, 0);
98     SetAutoLayout(true);
99     SetSizer(mainSizer);
100     Layout();
101    
102     searchTree->Expand(searchItemRoot);
103     }
104    
105 maloninc 1.15 void mnFrame::showSearchResult(mnModel* wiki, bool isExpand)
106 maloninc 1.1 {
107     const wxArrayString* searchStrList;
108     WikiList* wikiList;
109     WikiList::Node* node;
110     int i;
111    
112     searchTree->DeleteChildren(searchItemRoot);
113    
114     searchStrList = wiki->getSearchStrList();
115     for(i = 0; i < searchStrList->Count(); i++) {
116     wxString& searchStr = searchStrList->Item(i);
117    
118     wikiList = wiki->search(searchStr.mb_str());
119 maloninc 1.15 addSearchResult(&searchStr, wikiList, isExpand);
120 maloninc 1.1 }
121    
122     searchTree->ScrollTo(searchItemRoot);
123     }
124    
125 maloninc 1.15 void mnFrame::addSearchResult(wxString* searchStr, WikiList* wikiList, bool isExpand)
126 maloninc 1.1 {
127     wxTreeItemId searchItem;
128     WikiList::Node* node;
129     WikiData* data;
130     const wxString* subject;
131    
132     searchItem = searchTree->AppendItem(searchItemRoot, *searchStr, -1, -1, NULL);
133     node = wikiList->GetFirst();
134     while(node) {
135     data = node->GetData();
136     subject = data->getSubject();
137     searchTree->AppendItem(searchItem, *subject, -1, -1, (wxTreeItemData*)data);
138     node = node->GetNext();
139     }
140 maloninc 1.15
141 maloninc 1.1 searchTree->Expand(searchItemRoot);
142 maloninc 1.15 if(isExpand){
143     searchTree->Expand(searchItem);
144     }
145     else {
146     searchTree->Collapse(searchItem);
147     }
148 maloninc 1.1 }
149    
150 maloninc 1.13 void mnFrame::makeHtml(WikiData* wikiData, bool isHighlight)
151 maloninc 1.1 {
152 maloninc 1.13 const wxString* fileName = wikiData->getFileName();
153     const wxString* wikiText = wikiData->getText();
154 maloninc 1.7 wxString htmlText(*wikiText);
155    
156 maloninc 1.12 /* escape < */
157     wxRegEx exp01(wxT("<"), wxRE_NEWLINE|wxRE_DEFAULT);
158     exp01.Replace(&htmlText, wxT("\\&lt "));
159    
160     /* escape > */
161     wxRegEx exp02(wxT(">"), wxRE_NEWLINE|wxRE_DEFAULT);
162     exp02.Replace(&htmlText, wxT("\\&gt "));
163 maloninc 1.13
164 maloninc 1.7 /* [[ ]] */
165 maloninc 1.10 wxRegEx exp1(wxT("\\[\\[([^\\}]+)\\]\\]"));
166 maloninc 1.7 exp1.Replace(&htmlText, wxT("<a href=mnlink:\\1>\\1</a>"));
167    
168     /* http:// */
169 maloninc 1.14 wxRegEx exp2(wxT("(http://[-_.!~*'a-zA-Z0-9;/?:@&=+$,%#]+)"), wxRE_NEWLINE|wxRE_DEFAULT);
170 maloninc 1.7 exp2.Replace(&htmlText, wxT("<a href=\\1>\\1</a>"));
171    
172 maloninc 1.8 /* file:// */
173 maloninc 1.11 wxRegEx exp3(wxT("(file://[^ ]+)"), wxRE_NEWLINE|wxRE_DEFAULT);
174 maloninc 1.8 exp3.Replace(&htmlText, wxT("<a href=\\1>\\1</a>"));
175    
176     /* *XXXX */
177     wxRegEx exp4(wxT("^\\*([^\\*]+)"), wxRE_NEWLINE|wxRE_DEFAULT);
178     exp4.Replace(&htmlText, wxT("<h3>\\1</h3>"));
179    
180     /* **XXXX */
181     wxRegEx exp5(wxT("^\\*\\*([^\\*]+)"), wxRE_NEWLINE|wxRE_DEFAULT);
182     exp5.Replace(&htmlText, wxT("<h4>\\1</h4>"));
183    
184     /* :''XXXX'': */
185     wxRegEx exp6(wxT("^:''(.+)'':(.+)"), wxRE_NEWLINE|wxRE_DEFAULT);
186     exp6.Replace(&htmlText, wxT("<u><b>\\1:\\2</b></u>"));
187    
188     /* ---- */
189 maloninc 1.10 wxRegEx exp7(wxT("^----.*"), wxRE_NEWLINE|wxRE_DEFAULT);
190 maloninc 1.8 exp7.Replace(&htmlText, wxT("<hr>"));
191    
192 maloninc 1.10 /* {{ }} */
193     wxRegEx exp8(wxT("\\{\\{([^\\}]+)\\}\\}"));
194     exp8.Replace(&htmlText, wxT("<a href=mndoc:\\1>\\1</a>"));
195    
196 maloninc 1.13 /* Highlight search text */
197     highlight = isHighlight;
198     if(isHighlight) {
199     wxTreeItemId parentId = searchTree->GetItemParent(searchTree->GetSelection());
200     wxString searchWords = searchTree->GetItemText(parentId);
201     wxStringTokenizer tkz(searchWords, wxT(" "));
202     while ( tkz.HasMoreTokens() )
203     {
204     wxString token = tkz.GetNextToken();
205     wxRegEx exp9(wxT("(?!<[^>]+)(") + token + wxT(")(?![^<]+>)"), wxRE_ADVANCED|wxRE_ICASE|wxRE_NEWLINE);
206     exp9.Replace(&htmlText, wxT("<b><font color=\"red\">\\1</font></b>"));
207     }
208     }
209    
210    
211 maloninc 1.7 /* make HTML document */
212 maloninc 1.8 wxString wikiHtml;
213 maloninc 1.9 wikiHtml.Append(wxT("<meta http-equiv=\"Content-Type\"content=\"text/html; charset="));
214     wikiHtml.Append(wxT(CODE_SET_SYSTEM));
215 maloninc 1.10 wikiHtml.Append(wxT("\">"));
216     wikiHtml.Append(wxT("<pre>"));
217 maloninc 1.8 wikiHtml.Append(htmlText);
218     wikiHtml.Append(wxT("</pre>"));
219    
220 maloninc 1.2 wikiHtmlTextCtrl->SetPage(wikiHtml);
221 maloninc 1.1 }
222    
223 maloninc 1.13 void mnFrame::showSelectedItemText(wxTreeEvent& event)
224     {
225     wxTreeItemData* item = searchTree->GetItemData(event.GetItem());
226     if(item == NULL) {
227     wikiHtmlTextCtrl->SetPage(wxT(""));
228     return;
229     }
230    
231     makeHtml((WikiData*)item, false);
232     }
233    
234     void mnFrame::highlightSelectedItem()
235     {
236     wxTreeItemData* item = getSelectedItem();
237     if(item == NULL) {
238     wikiHtmlTextCtrl->SetPage(wxT(""));
239     return;
240     }
241    
242     if(highlight){
243     makeHtml((WikiData*)item, false);
244     }
245     else {
246     makeHtml((WikiData*)item, true);
247     }
248     }
249 maloninc 1.1
250     wxTreeItemData* mnFrame::getSelectedItem()
251     {
252     return searchTree->GetItemData(searchTree->GetSelection());
253     }
254    
255     wxString mnFrame::getSelectedLabel()
256     {
257     return searchTree->GetItemText(searchTree->GetSelection());
258     }
259    
260     bool mnFrame::isEditableTreeLabel(wxTreeItemId id)
261     {
262     return !(searchTree->GetItemParent(id) == searchItemRoot || id == searchItemRoot);
263     }
264    

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