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.11 - (hide annotations) (download) (as text)
Mon Aug 8 01:03:19 2005 UTC (18 years, 8 months ago) by maloninc
Branch: MAIN
Changes since 1.10: +2 -2 lines
File MIME type: text/x-c++src
fixed - problems in http://, ftp:// clickable strings.

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.1 #include "mnID.h"
4     #include "mnDef.h"
5     #include "mnFrame.h"
6 maloninc 1.3 #include "mnDialog.h"
7 maloninc 1.1
8    
9     mnFrame::mnFrame(wxWindow* parent, int id, const wxString& title, const wxPoint& pos, const wxSize& size, long style):
10     wxFrame(parent, id, title, pos, size, wxDEFAULT_FRAME_STYLE)
11     {
12     // begin wxGlade: mnFrame::mnFrame
13     splitWindow = new wxSplitterWindow(this, -1, wxDefaultPosition, wxDefaultSize, wxSP_3D|wxSP_BORDER);
14     rightPanel = new wxPanel(splitWindow, -1);
15     leftPanel = new wxPanel(splitWindow, -1);
16     panel = new wxPanel(this, -1);
17     searchLaebl = new wxStaticText(panel, -1, wxT("Search"), wxDefaultPosition, wxDefaultSize, wxALIGN_CENTRE);
18     searchTextCtrl = new wxTextCtrl(this, ID_SearchTextCtrl, wxT(""), wxDefaultPosition, wxDefaultSize, wxTE_PROCESS_ENTER);
19     searchTree = new wxTreeCtrl(leftPanel, ID_SearchTree, wxDefaultPosition, wxDefaultSize, wxTR_HAS_BUTTONS|wxTR_LINES_AT_ROOT|wxTR_DEFAULT_STYLE|wxSUNKEN_BORDER|wxTR_EDIT_LABELS);
20 maloninc 1.7 wikiHtmlTextCtrl = new mnHtmlWindow(rightPanel, ID_HtmlTextCtrl);
21 maloninc 1.1
22     // begin add by hand
23     menuBar = new wxMenuBar();
24     SetMenuBar(menuBar);
25    
26     // File menu
27     wxMenu* tmp_menu_1 = new wxMenu();
28     tmp_menu_1->Append(ID_MenuFileNew, _("New\tCtrl+N"), wxT(""), wxITEM_NORMAL);
29 maloninc 1.2 tmp_menu_1->Append(ID_MenuFileEdit, _("Edit\tCtrl+E"), wxT(""), wxITEM_NORMAL);
30 maloninc 1.1 tmp_menu_1->Append(ID_MenuFileRemove, _("Remove\tCtrl+R"), wxT(""), wxITEM_NORMAL);
31 maloninc 1.2 tmp_menu_1->AppendSeparator();
32 maloninc 1.1 tmp_menu_1->Append(ID_MenuFileConfig, _("Configure..."), wxT(""), wxITEM_NORMAL);
33 maloninc 1.2 tmp_menu_1->AppendSeparator();
34 maloninc 1.1 tmp_menu_1->Append(ID_MenuFileExit, _("Quit\tCtrl+Q"), wxT(""), wxITEM_NORMAL);
35     menuBar->Append(tmp_menu_1, _("&File"));
36    
37     // Help menu
38     wxMenu* tmp_menu_2 = new wxMenu();
39     tmp_menu_2->Append(wxID_ABOUT, _("&About"), wxT(""), wxITEM_NORMAL);
40     menuBar->Append(tmp_menu_2, _("&Help"));
41    
42     #ifdef __WXMSW__
43     wxIcon icon(wxT(APP_ICON_NAME), wxBITMAP_TYPE_ICO_RESOURCE);
44     SetIcon(icon);
45     #endif
46     // end add by hand
47    
48     set_properties();
49     do_layout();
50     // end wxGlade
51    
52     /* create search tree */
53     searchItemRoot = searchTree->AddRoot(wxT(LABEL_ITEM_TREE), -1, -1, NULL);
54     }
55    
56     void mnFrame::set_properties()
57     {
58     // begin wxGlade: mnFrame::set_properties
59     SetTitle(wxT("Malon Note"));
60     SetSize(wxSize(900, 572));
61     searchTextCtrl->SetFocus();
62     // end wxGlade
63 maloninc 1.10
64     wxFont font(12, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL);
65     wikiHtmlTextCtrl->SetFonts(font.GetFaceName(), font.GetFaceName());
66 maloninc 1.1 }
67    
68    
69     void mnFrame::do_layout()
70     {
71     wxBoxSizer* mainSizer = new wxBoxSizer(wxVERTICAL);
72 maloninc 1.3 rightPanelSizer = new wxGridSizer(1, 1, 0, 0);
73 maloninc 1.1 wxBoxSizer* leftPanelSizer = new wxBoxSizer(wxHORIZONTAL);
74     wxBoxSizer* topSizer = new wxBoxSizer(wxHORIZONTAL);
75     wxBoxSizer* labelSizer = new wxBoxSizer(wxHORIZONTAL);
76     labelSizer->Add(searchLaebl, 0, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
77     panel->SetAutoLayout(true);
78     panel->SetSizer(labelSizer);
79     labelSizer->Fit(panel);
80     labelSizer->SetSizeHints(panel);
81     topSizer->Add(panel, 0, wxEXPAND, 0);
82     topSizer->Add(searchTextCtrl, 1, wxTOP|wxBOTTOM|wxEXPAND|wxFIXED_MINSIZE, 1);
83     mainSizer->Add(topSizer, 0, wxEXPAND, 0);
84     leftPanelSizer->Add(searchTree, 1, wxEXPAND, 0);
85     leftPanel->SetAutoLayout(true);
86     leftPanel->SetSizer(leftPanelSizer);
87     leftPanelSizer->Fit(leftPanel);
88     leftPanelSizer->SetSizeHints(leftPanel);
89 maloninc 1.2 rightPanelSizer->Add(wikiHtmlTextCtrl, 0, wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 0);
90 maloninc 1.1 rightPanel->SetAutoLayout(true);
91     rightPanel->SetSizer(rightPanelSizer);
92     rightPanelSizer->Fit(rightPanel);
93     rightPanelSizer->SetSizeHints(rightPanel);
94     splitWindow->SplitVertically(leftPanel, rightPanel, 250);
95     mainSizer->Add(splitWindow, 1, wxEXPAND, 0);
96     SetAutoLayout(true);
97     SetSizer(mainSizer);
98     Layout();
99    
100     searchTree->Expand(searchItemRoot);
101     }
102    
103     void mnFrame::showSearchResult(mnModel* wiki)
104     {
105     const wxArrayString* searchStrList;
106     WikiList* wikiList;
107     WikiList::Node* node;
108     int i;
109    
110     searchTree->DeleteChildren(searchItemRoot);
111    
112     searchStrList = wiki->getSearchStrList();
113     for(i = 0; i < searchStrList->Count(); i++) {
114     wxString& searchStr = searchStrList->Item(i);
115    
116     wikiList = wiki->search(searchStr.mb_str());
117     addSearchResult(&searchStr, wikiList);
118     }
119    
120     searchTree->ScrollTo(searchItemRoot);
121     }
122    
123     void mnFrame::addSearchResult(wxString* searchStr, WikiList* wikiList)
124     {
125     wxTreeItemId searchItem;
126     WikiList::Node* node;
127     WikiData* data;
128     const wxString* subject;
129    
130     searchItem = searchTree->AppendItem(searchItemRoot, *searchStr, -1, -1, NULL);
131     node = wikiList->GetFirst();
132     while(node) {
133     data = node->GetData();
134     subject = data->getSubject();
135     searchTree->AppendItem(searchItem, *subject, -1, -1, (wxTreeItemData*)data);
136     node = node->GetNext();
137     }
138     searchTree->Expand(searchItemRoot);
139     searchTree->Expand(searchItem);
140     }
141    
142     void mnFrame::showSelectedItemText(wxTreeEvent& event)
143     {
144     wxTreeItemData* item = searchTree->GetItemData(event.GetItem());
145     if(item == NULL) {
146 maloninc 1.2 wikiHtmlTextCtrl->SetPage(wxT(""));
147 maloninc 1.1 return;
148     }
149    
150     const wxString* fileName = ((WikiData*)(item))->getFileName();
151 maloninc 1.2 const wxString* wikiText = ((WikiData*)(item))->getText();
152 maloninc 1.7 wxString htmlText(*wikiText);
153    
154     /* [[ ]] */
155 maloninc 1.10 wxRegEx exp1(wxT("\\[\\[([^\\}]+)\\]\\]"));
156 maloninc 1.7 exp1.Replace(&htmlText, wxT("<a href=mnlink:\\1>\\1</a>"));
157    
158     /* http:// */
159 maloninc 1.11 wxRegEx exp2(wxT("(http://[^ ]+)"), wxRE_NEWLINE|wxRE_DEFAULT);
160 maloninc 1.7 exp2.Replace(&htmlText, wxT("<a href=\\1>\\1</a>"));
161    
162 maloninc 1.8 /* file:// */
163 maloninc 1.11 wxRegEx exp3(wxT("(file://[^ ]+)"), wxRE_NEWLINE|wxRE_DEFAULT);
164 maloninc 1.8 exp3.Replace(&htmlText, wxT("<a href=\\1>\\1</a>"));
165    
166     /* *XXXX */
167     wxRegEx exp4(wxT("^\\*([^\\*]+)"), wxRE_NEWLINE|wxRE_DEFAULT);
168     exp4.Replace(&htmlText, wxT("<h3>\\1</h3>"));
169    
170     /* **XXXX */
171     wxRegEx exp5(wxT("^\\*\\*([^\\*]+)"), wxRE_NEWLINE|wxRE_DEFAULT);
172     exp5.Replace(&htmlText, wxT("<h4>\\1</h4>"));
173    
174     /* :''XXXX'': */
175     wxRegEx exp6(wxT("^:''(.+)'':(.+)"), wxRE_NEWLINE|wxRE_DEFAULT);
176     exp6.Replace(&htmlText, wxT("<u><b>\\1:\\2</b></u>"));
177    
178     /* ---- */
179 maloninc 1.10 wxRegEx exp7(wxT("^----.*"), wxRE_NEWLINE|wxRE_DEFAULT);
180 maloninc 1.8 exp7.Replace(&htmlText, wxT("<hr>"));
181    
182 maloninc 1.10 /* {{ }} */
183     wxRegEx exp8(wxT("\\{\\{([^\\}]+)\\}\\}"));
184     exp8.Replace(&htmlText, wxT("<a href=mndoc:\\1>\\1</a>"));
185    
186 maloninc 1.7 /* make HTML document */
187 maloninc 1.8 wxString wikiHtml;
188 maloninc 1.9 wikiHtml.Append(wxT("<meta http-equiv=\"Content-Type\"content=\"text/html; charset="));
189     wikiHtml.Append(wxT(CODE_SET_SYSTEM));
190 maloninc 1.10 wikiHtml.Append(wxT("\">"));
191     wikiHtml.Append(wxT("<pre>"));
192 maloninc 1.8 wikiHtml.Append(htmlText);
193     wikiHtml.Append(wxT("</pre>"));
194    
195 maloninc 1.2 wikiHtmlTextCtrl->SetPage(wikiHtml);
196 maloninc 1.1 }
197    
198    
199     wxTreeItemData* mnFrame::getSelectedItem()
200     {
201     return searchTree->GetItemData(searchTree->GetSelection());
202     }
203    
204     wxString mnFrame::getSelectedLabel()
205     {
206     return searchTree->GetItemText(searchTree->GetSelection());
207     }
208    
209     bool mnFrame::isEditableTreeLabel(wxTreeItemId id)
210     {
211     return !(searchTree->GetItemParent(id) == searchItemRoot || id == searchItemRoot);
212     }
213    

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