| 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 |
// Tree menu |
| 42 |
wxMenu* tmp_menu_3 = new wxMenu(); |
| 43 |
tmp_menu_3->Append(ID_MenuTreeExpand, _("Expand All\tCtrl+D"), wxT(""), wxITEM_NORMAL); |
| 44 |
tmp_menu_3->Append(ID_MenuTreeCollapse, _("Collapse All\tCtrl+U"), wxT(""), wxITEM_NORMAL); |
| 45 |
tmp_menu_3->Append(ID_MenuTreeClear, _("Clear All\tCtrl+K"), wxT(""), wxITEM_NORMAL); |
| 46 |
//tmp_menu_3->AppendSeparator(); |
| 47 |
//tmp_menu_3->AppendCheckItem(ID_MenuTreeDisableUpdate, _("Disable AutoUpdate")); |
| 48 |
menuBar->Append(tmp_menu_3, _("&Tree")); |
| 49 |
|
| 50 |
// Help menu |
| 51 |
wxMenu* tmp_menu_2 = new wxMenu(); |
| 52 |
tmp_menu_2->Append(wxID_ABOUT, _("&About"), wxT(""), wxITEM_NORMAL); |
| 53 |
menuBar->Append(tmp_menu_2, _("&Help")); |
| 54 |
|
| 55 |
#ifdef __WXMSW__ |
| 56 |
wxIcon icon(wxT(APP_ICON_NAME), wxBITMAP_TYPE_ICO_RESOURCE); |
| 57 |
SetIcon(icon); |
| 58 |
#endif |
| 59 |
// end add by hand |
| 60 |
|
| 61 |
set_properties(); |
| 62 |
do_layout(); |
| 63 |
// end wxGlade |
| 64 |
|
| 65 |
/* create search tree */ |
| 66 |
searchItemRoot = searchTree->AddRoot(wxT(LABEL_ITEM_TREE), -1, -1, NULL); |
| 67 |
} |
| 68 |
|
| 69 |
void mnFrame::set_properties() |
| 70 |
{ |
| 71 |
// begin wxGlade: mnFrame::set_properties |
| 72 |
SetTitle(wxT("Malon Note")); |
| 73 |
SetSize(wxSize(900, 572)); |
| 74 |
searchTextCtrl->SetFocus(); |
| 75 |
// end wxGlade |
| 76 |
|
| 77 |
wxFont font(12, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL); |
| 78 |
wikiHtmlTextCtrl->SetFonts(font.GetFaceName(), font.GetFaceName()); |
| 79 |
} |
| 80 |
|
| 81 |
|
| 82 |
void mnFrame::do_layout() |
| 83 |
{ |
| 84 |
wxBoxSizer* mainSizer = new wxBoxSizer(wxVERTICAL); |
| 85 |
rightPanelSizer = new wxGridSizer(1, 1, 0, 0); |
| 86 |
wxBoxSizer* leftPanelSizer = new wxBoxSizer(wxHORIZONTAL); |
| 87 |
wxBoxSizer* topSizer = new wxBoxSizer(wxHORIZONTAL); |
| 88 |
wxBoxSizer* labelSizer = new wxBoxSizer(wxHORIZONTAL); |
| 89 |
labelSizer->Add(searchLaebl, 0, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5); |
| 90 |
panel->SetAutoLayout(true); |
| 91 |
panel->SetSizer(labelSizer); |
| 92 |
labelSizer->Fit(panel); |
| 93 |
labelSizer->SetSizeHints(panel); |
| 94 |
topSizer->Add(panel, 0, wxEXPAND, 0); |
| 95 |
topSizer->Add(searchTextCtrl, 1, wxTOP|wxBOTTOM|wxEXPAND|wxFIXED_MINSIZE, 1); |
| 96 |
mainSizer->Add(topSizer, 0, wxEXPAND, 0); |
| 97 |
leftPanelSizer->Add(searchTree, 1, wxEXPAND, 0); |
| 98 |
leftPanel->SetAutoLayout(true); |
| 99 |
leftPanel->SetSizer(leftPanelSizer); |
| 100 |
leftPanelSizer->Fit(leftPanel); |
| 101 |
leftPanelSizer->SetSizeHints(leftPanel); |
| 102 |
rightPanelSizer->Add(wikiHtmlTextCtrl, 0, wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 0); |
| 103 |
rightPanel->SetAutoLayout(true); |
| 104 |
rightPanel->SetSizer(rightPanelSizer); |
| 105 |
rightPanelSizer->Fit(rightPanel); |
| 106 |
rightPanelSizer->SetSizeHints(rightPanel); |
| 107 |
splitWindow->SplitVertically(leftPanel, rightPanel, 250); |
| 108 |
mainSizer->Add(splitWindow, 1, wxEXPAND, 0); |
| 109 |
SetAutoLayout(true); |
| 110 |
SetSizer(mainSizer); |
| 111 |
Layout(); |
| 112 |
|
| 113 |
searchTree->Expand(searchItemRoot); |
| 114 |
} |
| 115 |
|
| 116 |
void mnFrame::showSearchResult(mnModel* wiki, bool isExpand) |
| 117 |
{ |
| 118 |
wxLogMessage(wxT("showSearchResult is not available")); |
| 119 |
} |
| 120 |
|
| 121 |
void mnFrame::updateSearchResult(mnModel* wiki, wxString* searchStr, bool isExpand) |
| 122 |
{ |
| 123 |
wxTreeItemIdValue cookie1, cookie2; |
| 124 |
wxTreeItemId searchStrId; |
| 125 |
wxTreeItemId wikiDataId; |
| 126 |
const WikiList* wikiList; |
| 127 |
WikiList::Node* node; |
| 128 |
WikiData* data; |
| 129 |
const wxString* subject; |
| 130 |
|
| 131 |
memset(&cookie1, 1, sizeof(cookie1)); |
| 132 |
memset(&cookie2, 2, sizeof(cookie2)); |
| 133 |
searchStrId = searchTree->GetFirstChild(searchItemRoot, cookie1); |
| 134 |
while(searchStrId.IsOk()) { |
| 135 |
if(searchTree->GetItemText(searchStrId) == *searchStr) { |
| 136 |
wikiDataId = searchTree->GetFirstChild(searchStrId, cookie2); |
| 137 |
while(wikiDataId.IsOk()) { |
| 138 |
searchTree->SetItemData(wikiDataId, NULL); |
| 139 |
wikiDataId = searchTree->GetNextChild(searchStrId, cookie2); |
| 140 |
} |
| 141 |
searchTree->DeleteChildren(searchStrId); |
| 142 |
break; |
| 143 |
} |
| 144 |
searchStrId = searchTree->GetNextChild(searchItemRoot, cookie1); |
| 145 |
} |
| 146 |
|
| 147 |
wikiList = wiki->getSearchResultList(searchStr); |
| 148 |
if(wikiList == NULL) { |
| 149 |
MN_FATAL_ERROR(wxT("wikiList is null")); |
| 150 |
return; |
| 151 |
} |
| 152 |
|
| 153 |
node = wikiList->GetFirst(); |
| 154 |
while(node) { |
| 155 |
data = node->GetData(); |
| 156 |
subject = data->getSubject(); |
| 157 |
searchTree->AppendItem(searchStrId, *subject, -1, -1, (wxTreeItemData*)data); |
| 158 |
node = node->GetNext(); |
| 159 |
} |
| 160 |
if(isExpand){ |
| 161 |
searchTree->Expand(searchStrId); |
| 162 |
} |
| 163 |
else { |
| 164 |
searchTree->Collapse(searchStrId); |
| 165 |
} |
| 166 |
} |
| 167 |
|
| 168 |
void mnFrame::addSearchResult(mnModel* wiki, wxString* searchStr, bool isExpand) |
| 169 |
{ |
| 170 |
wxTreeItemId searchItem; |
| 171 |
const WikiList* wikiList; |
| 172 |
WikiList::Node* node; |
| 173 |
WikiData* data; |
| 174 |
const wxString* subject; |
| 175 |
|
| 176 |
wikiList = wiki->getSearchResultList(searchStr); |
| 177 |
if(wikiList == NULL) { |
| 178 |
MN_FATAL_ERROR(wxT("wikiList is null")); |
| 179 |
return; |
| 180 |
} |
| 181 |
|
| 182 |
//searchItem = searchTree->AppendItem(searchItemRoot, *searchStr, -1, -1, NULL); |
| 183 |
searchItem = searchTree->InsertItem(searchItemRoot, 0, *searchStr, -1, -1, NULL); |
| 184 |
node = wikiList->GetFirst(); |
| 185 |
while(node) { |
| 186 |
data = node->GetData(); |
| 187 |
subject = data->getSubject(); |
| 188 |
searchTree->AppendItem(searchItem, *subject, -1, -1, (wxTreeItemData*)data); |
| 189 |
node = node->GetNext(); |
| 190 |
} |
| 191 |
|
| 192 |
searchTree->Expand(searchItemRoot); |
| 193 |
if(isExpand){ |
| 194 |
searchTree->Expand(searchItem); |
| 195 |
} |
| 196 |
else { |
| 197 |
searchTree->Collapse(searchItem); |
| 198 |
} |
| 199 |
} |
| 200 |
|
| 201 |
void mnFrame::makeHtml(WikiData* wikiData, bool isHighlight) |
| 202 |
{ |
| 203 |
const wxString* fileName = wikiData->getFileName(); |
| 204 |
const wxString* wikiText = wikiData->getText(); |
| 205 |
wxString htmlText(*wikiText); |
| 206 |
|
| 207 |
/* escape < */ |
| 208 |
wxRegEx exp01(wxT("<"), wxRE_NEWLINE|wxRE_DEFAULT); |
| 209 |
exp01.Replace(&htmlText, wxT("\\< ")); |
| 210 |
|
| 211 |
/* escape > */ |
| 212 |
wxRegEx exp02(wxT(">"), wxRE_NEWLINE|wxRE_DEFAULT); |
| 213 |
exp02.Replace(&htmlText, wxT("\\> ")); |
| 214 |
|
| 215 |
/* [[ ]] */ |
| 216 |
wxRegEx exp1(wxT("\\[\\[([^\\}]+)\\]\\]")); |
| 217 |
exp1.Replace(&htmlText, wxT("<a href=mnlink:\\1>\\1</a>")); |
| 218 |
|
| 219 |
/* http:// */ |
| 220 |
wxRegEx exp2(wxT("(http://[-_.!~*'a-zA-Z0-9;/?:@&=+$,%#]+)"), wxRE_NEWLINE|wxRE_DEFAULT); |
| 221 |
exp2.Replace(&htmlText, wxT("<a href=\\1>\\1</a>")); |
| 222 |
|
| 223 |
/* file:// */ |
| 224 |
wxRegEx exp3(wxT("(file://[^ ]+)"), wxRE_NEWLINE|wxRE_DEFAULT); |
| 225 |
exp3.Replace(&htmlText, wxT("<a href=\\1>\\1</a>")); |
| 226 |
|
| 227 |
/* *XXXX */ |
| 228 |
wxRegEx exp4(wxT("^\\*([^\\*]+)"), wxRE_NEWLINE|wxRE_DEFAULT); |
| 229 |
exp4.Replace(&htmlText, wxT("<h3>\\1</h3>")); |
| 230 |
|
| 231 |
/* **XXXX */ |
| 232 |
wxRegEx exp5(wxT("^\\*\\*([^\\*]+)"), wxRE_NEWLINE|wxRE_DEFAULT); |
| 233 |
exp5.Replace(&htmlText, wxT("<h4>\\1</h4>")); |
| 234 |
|
| 235 |
/* :''XXXX'': */ |
| 236 |
wxRegEx exp6(wxT("^:''(.+)'':(.+)"), wxRE_NEWLINE|wxRE_DEFAULT); |
| 237 |
exp6.Replace(&htmlText, wxT("<u><b>\\1:\\2</b></u>")); |
| 238 |
|
| 239 |
/* ---- */ |
| 240 |
wxRegEx exp7(wxT("^----.*"), wxRE_NEWLINE|wxRE_DEFAULT); |
| 241 |
exp7.Replace(&htmlText, wxT("<hr>")); |
| 242 |
|
| 243 |
/* {{ }} */ |
| 244 |
wxRegEx exp8(wxT("\\{\\{([^\\}]+)\\}\\}")); |
| 245 |
exp8.Replace(&htmlText, wxT("<a href=mndoc:\\1>\\1</a>")); |
| 246 |
|
| 247 |
/* Highlight search text */ |
| 248 |
highlight = isHighlight; |
| 249 |
if(isHighlight) { |
| 250 |
wxTreeItemId parentId = searchTree->GetItemParent(searchTree->GetSelection()); |
| 251 |
wxString searchWords = searchTree->GetItemText(parentId); |
| 252 |
wxStringTokenizer tkz(searchWords, wxT(" ")); |
| 253 |
while ( tkz.HasMoreTokens() ) |
| 254 |
{ |
| 255 |
wxString token = tkz.GetNextToken(); |
| 256 |
wxRegEx exp9(wxT("(?!<[^>]+)(") + token + wxT(")(?![^<]+>)"), wxRE_ADVANCED|wxRE_ICASE|wxRE_NEWLINE); |
| 257 |
exp9.Replace(&htmlText, wxT("<b><font color=\"red\">\\1</font></b>")); |
| 258 |
} |
| 259 |
} |
| 260 |
|
| 261 |
|
| 262 |
/* make HTML document */ |
| 263 |
wxString wikiHtml; |
| 264 |
wikiHtml.Append(wxT("<meta http-equiv=\"Content-Type\"content=\"text/html; charset=")); |
| 265 |
wikiHtml.Append(wxT(CODE_SET_SYSTEM)); |
| 266 |
wikiHtml.Append(wxT("\">")); |
| 267 |
wikiHtml.Append(wxT("<pre>")); |
| 268 |
wikiHtml.Append(htmlText); |
| 269 |
wikiHtml.Append(wxT("</pre>")); |
| 270 |
|
| 271 |
wikiHtmlTextCtrl->SetPage(wikiHtml); |
| 272 |
} |
| 273 |
|
| 274 |
void mnFrame::showSelectedItemText(wxTreeEvent& event) |
| 275 |
{ |
| 276 |
wxTreeItemId id; |
| 277 |
wxTreeItemData* item; |
| 278 |
|
| 279 |
id = searchTree->GetSelection(); |
| 280 |
item = searchTree->GetItemData(id); |
| 281 |
|
| 282 |
if(!id.IsOk() || !isEditableTreeLabel(id) || item == NULL) { /* selection is not memo data */ |
| 283 |
wikiHtmlTextCtrl->SetPage(wxT("")); |
| 284 |
return; |
| 285 |
} |
| 286 |
makeHtml((WikiData*)item, false); |
| 287 |
} |
| 288 |
|
| 289 |
wxTreeItemId mnFrame::getSelection() |
| 290 |
{ |
| 291 |
return searchTree->GetSelection(); |
| 292 |
} |
| 293 |
|
| 294 |
void mnFrame::highlightSelectedItem() |
| 295 |
{ |
| 296 |
wxTreeItemData* item = getSelectedItem(); |
| 297 |
|
| 298 |
if(!isEditableTreeLabel(searchTree->GetSelection())) { /* selection is not memo data */ |
| 299 |
wikiHtmlTextCtrl->SetPage(wxT("")); |
| 300 |
return; |
| 301 |
} |
| 302 |
|
| 303 |
if(highlight){ |
| 304 |
makeHtml((WikiData*)item, false); |
| 305 |
} |
| 306 |
else { |
| 307 |
makeHtml((WikiData*)item, true); |
| 308 |
} |
| 309 |
} |
| 310 |
|
| 311 |
void mnFrame::expandAllTree() |
| 312 |
{ |
| 313 |
wxTreeItemIdValue cookie; |
| 314 |
wxTreeItemId itemId; |
| 315 |
|
| 316 |
memset(&cookie, 1, sizeof(cookie)); |
| 317 |
itemId = searchTree->GetFirstChild(searchItemRoot, cookie); |
| 318 |
while(itemId.IsOk()) { |
| 319 |
searchTree->Expand(itemId); |
| 320 |
itemId = searchTree->GetNextChild(searchItemRoot, cookie); |
| 321 |
} |
| 322 |
} |
| 323 |
|
| 324 |
void mnFrame::collapseAllTree() |
| 325 |
{ |
| 326 |
wxTreeItemIdValue cookie; |
| 327 |
wxTreeItemId itemId; |
| 328 |
|
| 329 |
memset(&cookie, 1, sizeof(cookie)); |
| 330 |
itemId = searchTree->GetFirstChild(searchItemRoot, cookie); |
| 331 |
while(itemId.IsOk()) { |
| 332 |
searchTree->Collapse(itemId); |
| 333 |
itemId = searchTree->GetNextChild(searchItemRoot, cookie); |
| 334 |
} |
| 335 |
} |
| 336 |
|
| 337 |
void mnFrame::clearAllTree() |
| 338 |
{ |
| 339 |
wxTreeItemIdValue cookie1, cookie2; |
| 340 |
wxTreeItemId searchStrId; |
| 341 |
wxTreeItemId wikiDataId; |
| 342 |
|
| 343 |
memset(&cookie1, 1, sizeof(cookie1)); |
| 344 |
memset(&cookie2, 2, sizeof(cookie2)); |
| 345 |
searchStrId = searchTree->GetFirstChild(searchItemRoot, cookie1); |
| 346 |
while(searchStrId.IsOk()) { |
| 347 |
wikiDataId = searchTree->GetFirstChild(searchStrId, cookie2); |
| 348 |
while(wikiDataId.IsOk()) { |
| 349 |
searchTree->SetItemData(wikiDataId, NULL); |
| 350 |
wikiDataId = searchTree->GetNextChild(searchStrId, cookie2); |
| 351 |
} |
| 352 |
searchStrId = searchTree->GetNextChild(searchItemRoot, cookie1); |
| 353 |
} |
| 354 |
|
| 355 |
searchTree->DeleteChildren(searchItemRoot); |
| 356 |
} |
| 357 |
|
| 358 |
void mnFrame::removeSelectedItem() |
| 359 |
{ |
| 360 |
searchTree->Delete(searchTree->GetSelection()); |
| 361 |
} |
| 362 |
|
| 363 |
wxTreeItemData* mnFrame::getSelectedItem() |
| 364 |
{ |
| 365 |
return searchTree->GetItemData(searchTree->GetSelection()); |
| 366 |
} |
| 367 |
|
| 368 |
wxString mnFrame::getSelectedLabel() |
| 369 |
{ |
| 370 |
return searchTree->GetItemText(searchTree->GetSelection()); |
| 371 |
} |
| 372 |
|
| 373 |
bool mnFrame::isEditableTreeLabel(wxTreeItemId id) |
| 374 |
{ |
| 375 |
if(id.IsOk()){ |
| 376 |
return !(searchTree->GetItemParent(id) == searchItemRoot || id == searchItemRoot); |
| 377 |
} |
| 378 |
else { |
| 379 |
return false; |
| 380 |
} |
| 381 |
} |
| 382 |
|