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