Develop and Download Open Source Software

Browse CVS Repository

Annotation of /malonnote/mnNotePanel.cpp

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


Revision 1.4 - (hide annotations) (download) (as text)
Thu Dec 22 10:48:29 2005 UTC (18 years, 3 months ago) by maloninc
Branch: MAIN
CVS Tags: dev_1_6-0001
Changes since 1.3: +26 -18 lines
File MIME type: text/x-c++src
for webkit, only for mac

1 maloninc 1.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 "mnNotePanel.h"
8     #include "mnDialog.h"
9     #include "mnNotePanelController.h"
10    
11     mnNotePanel::mnNotePanel(wxWindow* parent, wxString* dirName)
12     {
13     wxXmlResource::Get()->LoadPanel(this, parent, wxT("notePanel"));
14 maloninc 1.4 wxSplitterWindow* spWindow = XRCCTRL(*this, "splitWindow", wxSplitterWindow);
15     searchTree = XRCCTRL(*spWindow, "searchTree", wxTreeCtrl);
16 maloninc 1.1
17 maloninc 1.4 #ifdef __WXMAC__
18     wikiHtmlTextCtrl = new mnHtmlWindow(spWindow, -1, wxT(""), wxPoint(0,-100), wxSize(200, 200));
19     spWindow->SplitVertically(searchTree, wikiHtmlTextCtrl, 250);
20     #else
21 maloninc 1.1 /* init members */
22 maloninc 1.4 wikiHtmlTextCtrl = XRCCTRL(*spWindow, "wikiHtmlTextCtrl", mnHtmlWindow);
23     #endif
24 maloninc 1.1
25     /* create search tree */
26     searchItemRoot = searchTree->AddRoot(wxT(LABEL_ITEM_TREE), -1, -1, NULL);
27    
28     /* create controller, and push as event handler */
29     panelController = new mnNotePanelController(this, dirName);
30     PushEventHandler(panelController);
31     }
32    
33     mnNotePanelController* mnNotePanel::getController()
34     {
35     return panelController;
36     }
37    
38     void mnNotePanel::updateSearchResult(mnModel* wiki, wxString* searchStr, bool isExpand)
39     {
40     wxTreeItemIdValue cookie1, cookie2;
41     wxTreeItemId searchStrId;
42     wxTreeItemId wikiDataId;
43     const WikiList* wikiList;
44     WikiList::Node* node;
45     WikiData* data;
46     const wxString* subject;
47    
48     memset(&cookie1, 1, sizeof(cookie1));
49     memset(&cookie2, 2, sizeof(cookie2));
50     searchStrId = searchTree->GetFirstChild(searchItemRoot, cookie1);
51     while(searchStrId.IsOk()) {
52     if(searchTree->GetItemText(searchStrId) == *searchStr) {
53     wikiDataId = searchTree->GetFirstChild(searchStrId, cookie2);
54     while(wikiDataId.IsOk()) {
55     searchTree->SetItemData(wikiDataId, NULL);
56     wikiDataId = searchTree->GetNextChild(searchStrId, cookie2);
57     }
58     searchTree->DeleteChildren(searchStrId);
59     break;
60     }
61     searchStrId = searchTree->GetNextChild(searchItemRoot, cookie1);
62     }
63    
64     wikiList = wiki->getSearchResultList(searchStr);
65     if(wikiList == NULL) {
66     MN_FATAL_ERROR(wxT("wikiList is null"));
67     return;
68     }
69    
70     node = wikiList->GetFirst();
71     while(node) {
72     data = node->GetData();
73     subject = data->getSubject();
74     searchTree->AppendItem(searchStrId, *subject, -1, -1, (wxTreeItemData*)data);
75     node = node->GetNext();
76     }
77     if(isExpand){
78     searchTree->Expand(searchStrId);
79     }
80     else {
81     searchTree->Collapse(searchStrId);
82     }
83     }
84    
85    
86     void mnNotePanel::addSearchResult(mnModel* wiki, wxString* searchStr, bool isExpand)
87     {
88     wxTreeItemId searchItem;
89     const WikiList* wikiList;
90     WikiList::Node* node;
91     WikiData* data;
92     const wxString* subject;
93    
94     wikiList = wiki->getSearchResultList(searchStr);
95     if(wikiList == NULL) {
96     MN_FATAL_ERROR(wxT("wikiList is null"));
97     return;
98     }
99    
100     //searchItem = searchTree->AppendItem(searchItemRoot, *searchStr, -1, -1, NULL);
101     searchItem = searchTree->InsertItem(searchItemRoot, 0, *searchStr, -1, -1, NULL);
102     node = wikiList->GetFirst();
103     while(node) {
104     data = node->GetData();
105     subject = data->getSubject();
106     searchTree->AppendItem(searchItem, *subject, -1, -1, (wxTreeItemData*)data);
107     node = node->GetNext();
108     }
109    
110     searchTree->Expand(searchItemRoot);
111     if(isExpand){
112     searchTree->Expand(searchItem);
113     }
114     else {
115     searchTree->Collapse(searchItem);
116     }
117     }
118    
119     void mnNotePanel::makeHtml(WikiData* wikiData, bool isHighlight)
120     {
121     const wxString* fileName = wikiData->getFileName();
122     const wxString* wikiText = wikiData->getText();
123     wxString htmlText(*wikiText);
124    
125     /* escape < */
126     wxRegEx exp01(wxT("<"), wxRE_NEWLINE|wxRE_DEFAULT);
127     exp01.Replace(&htmlText, wxT("\\&lt "));
128    
129     /* escape > */
130     wxRegEx exp02(wxT(">"), wxRE_NEWLINE|wxRE_DEFAULT);
131     exp02.Replace(&htmlText, wxT("\\&gt "));
132    
133     /* [[ ]] */
134     wxRegEx exp1(wxT("\\[\\[([^\\}]+)\\]\\]"));
135 maloninc 1.4 exp1.Replace(&htmlText, wxT("<a href=mnlink:\\1> \\1 </a>"));
136 maloninc 1.1
137     /* http:// */
138     wxRegEx exp2(wxT("(http://[-_.!~*'a-zA-Z0-9;/?:@&=+$,%#]+)"), wxRE_NEWLINE|wxRE_DEFAULT);
139 maloninc 1.4 exp2.Replace(&htmlText, wxT("<a href=\\1> \\1 </a>"));
140 maloninc 1.1
141     /* file:// */
142     wxRegEx exp3(wxT("(file://[^ ]+)"), wxRE_NEWLINE|wxRE_DEFAULT);
143 maloninc 1.4 exp3.Replace(&htmlText, wxT("<a href=\\1> \\1 </a>"));
144    
145     /* **XXXX */
146     wxRegEx exp5(wxT("^\\*\\*([^*]+)"), wxRE_NEWLINE|wxRE_DEFAULT);
147     exp5.Replace(&htmlText, wxT("<h4> \\1 </h4>"));
148 maloninc 1.1
149     /* *XXXX */
150 maloninc 1.4 wxRegEx exp4(wxT("^\\*([^*]+)"), wxRE_NEWLINE|wxRE_DEFAULT);
151     //wxRegEx exp4(wxT("^\\*(..*)"), wxRE_NEWLINE|wxRE_DEFAULT);
152     exp4.Replace(&htmlText, wxT("<h3> \\1 </h3>"));
153 maloninc 1.1
154     /* :''XXXX'': */
155     wxRegEx exp6(wxT("^:''(.+)'':(.+)"), wxRE_NEWLINE|wxRE_DEFAULT);
156 maloninc 1.4 exp6.Replace(&htmlText, wxT("<u><b> \\1:\\2 </b></u>"));
157 maloninc 1.1
158     /* ---- */
159     wxRegEx exp7(wxT("^----.*"), wxRE_NEWLINE|wxRE_DEFAULT);
160     exp7.Replace(&htmlText, wxT("<hr>"));
161    
162     /* {{ }} */
163     wxRegEx exp8(wxT("\\{\\{([^\\}]+)\\}\\}"));
164 maloninc 1.4 exp8.Replace(&htmlText, wxT("<a href=mndoc:\\1> \\1 </a>"));
165 maloninc 1.1
166     /* table */
167 maloninc 1.3 wxRegEx exp10(wxT("^,([^,]+)"), wxRE_NEWLINE|wxRE_DEFAULT);
168 maloninc 1.4 exp10.Replace(&htmlText, wxT("<td> \\1 </td>"));
169 maloninc 1.3 for(int i = 0; i < 10; i++){ // It's not good. :P
170     wxRegEx exp16(wxT("</td>,([^,\n]+)"), wxRE_DEFAULT);
171 maloninc 1.4 exp16.Replace(&htmlText, wxT("</td><td> \\1 </td>"));
172 maloninc 1.3 }
173 maloninc 1.1 wxRegEx exp11(wxT("^<td>"), wxRE_NEWLINE|wxRE_DEFAULT);
174     exp11.Replace(&htmlText, wxT("<tr><td>"));
175     wxRegEx exp12(wxT("</td>$"), wxRE_NEWLINE|wxRE_DEFAULT);
176     exp12.Replace(&htmlText, wxT("</td></tr>"));
177     wxRegEx exp15(wxT("</tr>\n"));
178     exp15.Replace(&htmlText, wxT("</tr>"));
179    
180     wxRegEx exp13(wxT("^<tr>"), wxRE_NEWLINE|wxRE_DEFAULT);
181     exp13.Replace(&htmlText, wxT("<table border><tr>"));
182     wxRegEx exp14(wxT("</tr>$"), wxRE_NEWLINE|wxRE_DEFAULT);
183     exp14.Replace(&htmlText, wxT("</tr></table>"));
184    
185    
186     /* Highlight search text */
187     highlight = isHighlight;
188     if(isHighlight) {
189     wxTreeItemId parentId = searchTree->GetItemParent(searchTree->GetSelection());
190     wxString searchWords = searchTree->GetItemText(parentId);
191     wxStringTokenizer tkz(searchWords, wxT(" "));
192     while ( tkz.HasMoreTokens() )
193     {
194     wxString token = tkz.GetNextToken();
195     wxRegEx exp9(wxT("(?!<[^>]+)(") + token + wxT(")(?![^<]+>)"), wxRE_ADVANCED|wxRE_ICASE|wxRE_NEWLINE);
196 maloninc 1.4 exp9.Replace(&htmlText, wxT("<b><font color=\"red\"> \\1 </font></b>"));
197 maloninc 1.1 }
198     }
199    
200     /* make HTML document */
201     wxString wikiHtml;
202     wikiHtml.Append(wxT("<meta http-equiv=\"Content-Type\"content=\"text/html; charset="));
203     wikiHtml.Append(wxT(CODE_SET_SYSTEM));
204     wikiHtml.Append(wxT("\">"));
205     wikiHtml.Append(wxT("<pre>"));
206 maloninc 1.4 wikiHtml.Append(wxT("<html>"));
207     wikiHtml.Append(htmlText.c_str());
208 maloninc 1.1 wikiHtml.Append(wxT("</pre>"));
209 maloninc 1.4 wikiHtml.Append(wxT("</html>"));
210 maloninc 1.1
211     wikiHtmlTextCtrl->SetPage(wikiHtml);
212     }
213    
214     void mnNotePanel::showSelectedItemText(wxTreeEvent& event)
215     {
216     wxTreeItemId id;
217     wxTreeItemData* item;
218    
219     id = searchTree->GetSelection();
220     item = searchTree->GetItemData(id);
221    
222     if(!id.IsOk() || !isEditableTreeLabel(id) || item == NULL) { /* selection is not memo data */
223     wikiHtmlTextCtrl->SetPage(wxT(""));
224     return;
225     }
226     makeHtml((WikiData*)item, false);
227     }
228    
229     wxTreeItemId mnNotePanel::getSelection()
230     {
231     return searchTree->GetSelection();
232     }
233    
234     void mnNotePanel::highlightSelectedItem()
235     {
236     wxTreeItemData* item = getSelectedItem();
237    
238     if(!isEditableTreeLabel(searchTree->GetSelection())) { /* selection is not memo data */
239     wikiHtmlTextCtrl->SetPage(wxT(""));
240     return;
241     }
242    
243     if(highlight){
244     makeHtml((WikiData*)item, false);
245     }
246     else {
247     makeHtml((WikiData*)item, true);
248     }
249     }
250    
251 maloninc 1.2
252 maloninc 1.1 void mnNotePanel::expandAllTree()
253     {
254     wxTreeItemIdValue cookie;
255     wxTreeItemId itemId;
256    
257     memset(&cookie, 1, sizeof(cookie));
258     itemId = searchTree->GetFirstChild(searchItemRoot, cookie);
259     while(itemId.IsOk()) {
260     searchTree->Expand(itemId);
261     itemId = searchTree->GetNextChild(searchItemRoot, cookie);
262     }
263     }
264    
265     void mnNotePanel::collapseAllTree()
266     {
267     wxTreeItemIdValue cookie;
268     wxTreeItemId itemId;
269    
270     memset(&cookie, 1, sizeof(cookie));
271     itemId = searchTree->GetFirstChild(searchItemRoot, cookie);
272     while(itemId.IsOk()) {
273     searchTree->Collapse(itemId);
274     itemId = searchTree->GetNextChild(searchItemRoot, cookie);
275     }
276     }
277    
278     void mnNotePanel::clearAllTree()
279     {
280     wxTreeItemIdValue cookie1, cookie2;
281     wxTreeItemId searchStrId;
282     wxTreeItemId wikiDataId;
283    
284     memset(&cookie1, 1, sizeof(cookie1));
285     memset(&cookie2, 2, sizeof(cookie2));
286     searchStrId = searchTree->GetFirstChild(searchItemRoot, cookie1);
287     while(searchStrId.IsOk()) {
288     wikiDataId = searchTree->GetFirstChild(searchStrId, cookie2);
289     while(wikiDataId.IsOk()) {
290     searchTree->SetItemData(wikiDataId, NULL);
291     wikiDataId = searchTree->GetNextChild(searchStrId, cookie2);
292     }
293     searchStrId = searchTree->GetNextChild(searchItemRoot, cookie1);
294     }
295    
296     searchTree->DeleteChildren(searchItemRoot);
297     }
298    
299     void mnNotePanel::removeSelectedItem()
300     {
301     searchTree->Delete(searchTree->GetSelection());
302     }
303    
304     wxTreeItemData* mnNotePanel::getSelectedItem()
305     {
306     return searchTree->GetItemData(searchTree->GetSelection());
307     }
308    
309     wxString mnNotePanel::getSelectedLabel()
310     {
311     return searchTree->GetItemText(searchTree->GetSelection());
312     }
313    
314     bool mnNotePanel::isEditableTreeLabel(wxTreeItemId id)
315     {
316     if(id.IsOk()){
317     return !(searchTree->GetItemParent(id) == searchItemRoot || id == searchItemRoot);
318     }
319     else {
320     return false;
321     }
322     }
323    

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