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.10 - (hide annotations) (download) (as text)
Tue Jan 3 23:20:39 2006 UTC (18 years, 2 months ago) by maloninc
Branch: MAIN
Changes since 1.9: +4 -0 lines
File MIME type: text/x-c++src
modify "open directory" command for windows, and add SetFont method to
mnHtml

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

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