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