| 1 |
// -*- C++ -*- generated by wxGlade 0.3.5.1 on Wed Jun 29 12:57:38 2005 |
| 2 |
|
| 3 |
#include "mnID.h" |
| 4 |
#include "mnDef.h" |
| 5 |
#include "mnFrame.h" |
| 6 |
#include "mnDialog.h" |
| 7 |
|
| 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 |
wikiPlainTextCtrl = new wxTextCtrl(rightPanel, ID_PlainTextCtrl, wxT(""), wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE|wxHSCROLL|wxTE_AUTO_URL); |
| 21 |
wikiHtmlTextCtrl = new wxHtmlWindow(rightPanel, ID_HtmlTextCtrl, wxDefaultPosition, wxDefaultSize, wxHW_DEFAULT_STYLE, wxT("")); |
| 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->AppendSeparator(); |
| 33 |
tmp_menu_1->Append(ID_MenuFileConfig, _("Configure..."), wxT(""), wxITEM_NORMAL); |
| 34 |
tmp_menu_1->AppendSeparator(); |
| 35 |
tmp_menu_1->Append(ID_MenuFileExit, _("Quit\tCtrl+Q"), wxT(""), wxITEM_NORMAL); |
| 36 |
menuBar->Append(tmp_menu_1, _("&File")); |
| 37 |
|
| 38 |
// Help menu |
| 39 |
wxMenu* tmp_menu_2 = new wxMenu(); |
| 40 |
tmp_menu_2->Append(wxID_ABOUT, _("&About"), wxT(""), wxITEM_NORMAL); |
| 41 |
menuBar->Append(tmp_menu_2, _("&Help")); |
| 42 |
|
| 43 |
#ifdef __WXMSW__ |
| 44 |
wxIcon icon(wxT(APP_ICON_NAME), wxBITMAP_TYPE_ICO_RESOURCE); |
| 45 |
SetIcon(icon); |
| 46 |
#endif |
| 47 |
// end add by hand |
| 48 |
|
| 49 |
set_properties(); |
| 50 |
do_layout(); |
| 51 |
// end wxGlade |
| 52 |
|
| 53 |
/* create search tree */ |
| 54 |
searchItemRoot = searchTree->AddRoot(wxT(LABEL_ITEM_TREE), -1, -1, NULL); |
| 55 |
newItemRoot = searchTree->AppendItem(searchItemRoot, wxT(LABEL_NEW_ITEM), -1, -1, NULL); |
| 56 |
} |
| 57 |
|
| 58 |
int mnFrame::showDataEntryDialog(mnWikiDataEntryDialog* dlg) |
| 59 |
{ |
| 60 |
return wxID_CANCEL; |
| 61 |
} |
| 62 |
|
| 63 |
int mnFrame::showDataEditDialog(mnWikiDataEntryDialog* dlg) |
| 64 |
{ |
| 65 |
wxTreeItemData* itemData = getSelectedItem(); |
| 66 |
wxString subject = getSelectedLabel(); |
| 67 |
|
| 68 |
if(itemData == NULL) return wxID_CANCEL; |
| 69 |
const wxString* wikiText = ((WikiData*)(itemData))->getText(); |
| 70 |
|
| 71 |
dlg->setSubject(subject); |
| 72 |
dlg->setPlainText(*wikiText); |
| 73 |
return dlg->ShowModal(); |
| 74 |
} |
| 75 |
|
| 76 |
|
| 77 |
void mnFrame::set_properties() |
| 78 |
{ |
| 79 |
// begin wxGlade: mnFrame::set_properties |
| 80 |
SetTitle(wxT("Malon Note")); |
| 81 |
SetSize(wxSize(900, 572)); |
| 82 |
searchTextCtrl->SetFocus(); |
| 83 |
// end wxGlade |
| 84 |
} |
| 85 |
|
| 86 |
|
| 87 |
void mnFrame::do_layout() |
| 88 |
{ |
| 89 |
wxBoxSizer* mainSizer = new wxBoxSizer(wxVERTICAL); |
| 90 |
rightPanelSizer = new wxGridSizer(1, 1, 0, 0); |
| 91 |
wxBoxSizer* leftPanelSizer = new wxBoxSizer(wxHORIZONTAL); |
| 92 |
wxBoxSizer* topSizer = new wxBoxSizer(wxHORIZONTAL); |
| 93 |
wxBoxSizer* labelSizer = new wxBoxSizer(wxHORIZONTAL); |
| 94 |
labelSizer->Add(searchLaebl, 0, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5); |
| 95 |
panel->SetAutoLayout(true); |
| 96 |
panel->SetSizer(labelSizer); |
| 97 |
labelSizer->Fit(panel); |
| 98 |
labelSizer->SetSizeHints(panel); |
| 99 |
topSizer->Add(panel, 0, wxEXPAND, 0); |
| 100 |
topSizer->Add(searchTextCtrl, 1, wxTOP|wxBOTTOM|wxEXPAND|wxFIXED_MINSIZE, 1); |
| 101 |
mainSizer->Add(topSizer, 0, wxEXPAND, 0); |
| 102 |
leftPanelSizer->Add(searchTree, 1, wxEXPAND, 0); |
| 103 |
leftPanel->SetAutoLayout(true); |
| 104 |
leftPanel->SetSizer(leftPanelSizer); |
| 105 |
leftPanelSizer->Fit(leftPanel); |
| 106 |
leftPanelSizer->SetSizeHints(leftPanel); |
| 107 |
rightPanelSizer->Add(wikiHtmlTextCtrl, 0, wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 0); |
| 108 |
rightPanel->SetAutoLayout(true); |
| 109 |
rightPanel->SetSizer(rightPanelSizer); |
| 110 |
rightPanelSizer->Fit(rightPanel); |
| 111 |
rightPanelSizer->SetSizeHints(rightPanel); |
| 112 |
splitWindow->SplitVertically(leftPanel, rightPanel, 250); |
| 113 |
mainSizer->Add(splitWindow, 1, wxEXPAND, 0); |
| 114 |
SetAutoLayout(true); |
| 115 |
SetSizer(mainSizer); |
| 116 |
Layout(); |
| 117 |
|
| 118 |
searchTree->Expand(searchItemRoot); |
| 119 |
searchTree->Expand(newItemRoot); |
| 120 |
} |
| 121 |
|
| 122 |
void mnFrame::showSearchResult(mnModel* wiki) |
| 123 |
{ |
| 124 |
const wxArrayString* searchStrList; |
| 125 |
WikiList* wikiList; |
| 126 |
WikiList::Node* node; |
| 127 |
int i; |
| 128 |
|
| 129 |
searchTree->DeleteChildren(searchItemRoot); |
| 130 |
newItemRoot = searchTree->AppendItem(searchItemRoot, wxT(LABEL_NEW_ITEM), -1, -1, NULL); |
| 131 |
|
| 132 |
searchStrList = wiki->getSearchStrList(); |
| 133 |
for(i = 0; i < searchStrList->Count(); i++) { |
| 134 |
wxString& searchStr = searchStrList->Item(i); |
| 135 |
|
| 136 |
wikiList = wiki->search(searchStr.mb_str()); |
| 137 |
addSearchResult(&searchStr, wikiList); |
| 138 |
} |
| 139 |
|
| 140 |
searchTree->ScrollTo(searchItemRoot); |
| 141 |
} |
| 142 |
|
| 143 |
void mnFrame::addSearchResult(wxString* searchStr, WikiList* wikiList) |
| 144 |
{ |
| 145 |
wxTreeItemId searchItem; |
| 146 |
WikiList::Node* node; |
| 147 |
WikiData* data; |
| 148 |
const wxString* subject; |
| 149 |
|
| 150 |
searchItem = searchTree->AppendItem(searchItemRoot, *searchStr, -1, -1, NULL); |
| 151 |
node = wikiList->GetFirst(); |
| 152 |
while(node) { |
| 153 |
data = node->GetData(); |
| 154 |
subject = data->getSubject(); |
| 155 |
searchTree->AppendItem(searchItem, *subject, -1, -1, (wxTreeItemData*)data); |
| 156 |
node = node->GetNext(); |
| 157 |
} |
| 158 |
searchTree->Expand(searchItemRoot); |
| 159 |
searchTree->Expand(searchItem); |
| 160 |
} |
| 161 |
|
| 162 |
void mnFrame::showSelectedItemText(wxTreeEvent& event) |
| 163 |
{ |
| 164 |
wxTreeItemData* item = searchTree->GetItemData(event.GetItem()); |
| 165 |
if(item == NULL) { |
| 166 |
wikiHtmlTextCtrl->SetPage(wxT("")); |
| 167 |
return; |
| 168 |
} |
| 169 |
|
| 170 |
const wxString* fileName = ((WikiData*)(item))->getFileName(); |
| 171 |
const wxString* wikiText = ((WikiData*)(item))->getText(); |
| 172 |
wxString wikiHtml = wxT("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=EUC-JP\"><pre>") + |
| 173 |
*wikiText + |
| 174 |
wxT("</pre>"); |
| 175 |
|
| 176 |
wikiHtmlTextCtrl->SetPage(wikiHtml); |
| 177 |
} |
| 178 |
|
| 179 |
void mnFrame::showNewItem(WikiData* data) |
| 180 |
{ |
| 181 |
wxTreeItemId itemId; |
| 182 |
|
| 183 |
itemId = searchTree->AppendItem(newItemRoot, *(data->getSubject()), -1, -1, (wxTreeItemData*)data); |
| 184 |
searchTree->Expand(searchItemRoot); |
| 185 |
searchTree->Expand(newItemRoot); |
| 186 |
searchTree->SelectItem(itemId); |
| 187 |
} |
| 188 |
|
| 189 |
wxTreeItemData* mnFrame::getSelectedItem() |
| 190 |
{ |
| 191 |
return searchTree->GetItemData(searchTree->GetSelection()); |
| 192 |
} |
| 193 |
|
| 194 |
wxString mnFrame::getSelectedLabel() |
| 195 |
{ |
| 196 |
return searchTree->GetItemText(searchTree->GetSelection()); |
| 197 |
} |
| 198 |
|
| 199 |
bool mnFrame::isEditableTreeLabel(wxTreeItemId id) |
| 200 |
{ |
| 201 |
return !(searchTree->GetItemParent(id) == searchItemRoot || id == searchItemRoot); |
| 202 |
} |
| 203 |
|
| 204 |
bool mnFrame::isNewItem(wxTreeItemId id) |
| 205 |
{ |
| 206 |
return (searchTree->GetItemParent(id) == newItemRoot); |
| 207 |
} |
| 208 |
|