| 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_MenuFileSave, _("Save\tCtrl+S"), wxT(""), wxITEM_NORMAL); |
| 32 |
tmp_menu_1->Append(ID_MenuFileRemove, _("Remove\tCtrl+R"), wxT(""), wxITEM_NORMAL); |
| 33 |
tmp_menu_1->AppendSeparator(); |
| 34 |
tmp_menu_1->Append(ID_MenuFileConfig, _("Configure..."), wxT(""), wxITEM_NORMAL); |
| 35 |
tmp_menu_1->AppendSeparator(); |
| 36 |
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 |
newItemRoot = searchTree->AppendItem(searchItemRoot, wxT(LABEL_NEW_ITEM), -1, -1, NULL); |
| 57 |
} |
| 58 |
|
| 59 |
void mnFrame::showPlainTextCtrl() |
| 60 |
{ |
| 61 |
mnWikiDataEntryDialog* dlg = new mnWikiDataEntryDialog(this, -1, wxT("Malon Note")); |
| 62 |
dlg->ShowModal(); |
| 63 |
} |
| 64 |
|
| 65 |
void mnFrame::hidePlainTextCtrl() |
| 66 |
{ |
| 67 |
} |
| 68 |
|
| 69 |
|
| 70 |
void mnFrame::set_properties() |
| 71 |
{ |
| 72 |
// begin wxGlade: mnFrame::set_properties |
| 73 |
SetTitle(wxT("Malon Note")); |
| 74 |
SetSize(wxSize(900, 572)); |
| 75 |
searchTextCtrl->SetFocus(); |
| 76 |
// end wxGlade |
| 77 |
} |
| 78 |
|
| 79 |
|
| 80 |
void mnFrame::do_layout() |
| 81 |
{ |
| 82 |
wxBoxSizer* mainSizer = new wxBoxSizer(wxVERTICAL); |
| 83 |
rightPanelSizer = new wxGridSizer(1, 1, 0, 0); |
| 84 |
wxBoxSizer* leftPanelSizer = new wxBoxSizer(wxHORIZONTAL); |
| 85 |
wxBoxSizer* topSizer = new wxBoxSizer(wxHORIZONTAL); |
| 86 |
wxBoxSizer* labelSizer = new wxBoxSizer(wxHORIZONTAL); |
| 87 |
labelSizer->Add(searchLaebl, 0, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5); |
| 88 |
panel->SetAutoLayout(true); |
| 89 |
panel->SetSizer(labelSizer); |
| 90 |
labelSizer->Fit(panel); |
| 91 |
labelSizer->SetSizeHints(panel); |
| 92 |
topSizer->Add(panel, 0, wxEXPAND, 0); |
| 93 |
topSizer->Add(searchTextCtrl, 1, wxTOP|wxBOTTOM|wxEXPAND|wxFIXED_MINSIZE, 1); |
| 94 |
mainSizer->Add(topSizer, 0, wxEXPAND, 0); |
| 95 |
leftPanelSizer->Add(searchTree, 1, wxEXPAND, 0); |
| 96 |
leftPanel->SetAutoLayout(true); |
| 97 |
leftPanel->SetSizer(leftPanelSizer); |
| 98 |
leftPanelSizer->Fit(leftPanel); |
| 99 |
leftPanelSizer->SetSizeHints(leftPanel); |
| 100 |
rightPanelSizer->Add(wikiHtmlTextCtrl, 0, wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 0); |
| 101 |
rightPanel->SetAutoLayout(true); |
| 102 |
rightPanel->SetSizer(rightPanelSizer); |
| 103 |
rightPanelSizer->Fit(rightPanel); |
| 104 |
rightPanelSizer->SetSizeHints(rightPanel); |
| 105 |
splitWindow->SplitVertically(leftPanel, rightPanel, 250); |
| 106 |
mainSizer->Add(splitWindow, 1, wxEXPAND, 0); |
| 107 |
SetAutoLayout(true); |
| 108 |
SetSizer(mainSizer); |
| 109 |
Layout(); |
| 110 |
|
| 111 |
searchTree->Expand(searchItemRoot); |
| 112 |
searchTree->Expand(newItemRoot); |
| 113 |
} |
| 114 |
|
| 115 |
void mnFrame::showSearchResult(mnModel* wiki) |
| 116 |
{ |
| 117 |
const wxArrayString* searchStrList; |
| 118 |
WikiList* wikiList; |
| 119 |
WikiList::Node* node; |
| 120 |
int i; |
| 121 |
|
| 122 |
searchTree->DeleteChildren(searchItemRoot); |
| 123 |
newItemRoot = searchTree->AppendItem(searchItemRoot, wxT(LABEL_NEW_ITEM), -1, -1, NULL); |
| 124 |
|
| 125 |
searchStrList = wiki->getSearchStrList(); |
| 126 |
for(i = 0; i < searchStrList->Count(); i++) { |
| 127 |
wxString& searchStr = searchStrList->Item(i); |
| 128 |
|
| 129 |
wikiList = wiki->search(searchStr.mb_str()); |
| 130 |
addSearchResult(&searchStr, wikiList); |
| 131 |
} |
| 132 |
|
| 133 |
searchTree->ScrollTo(searchItemRoot); |
| 134 |
} |
| 135 |
|
| 136 |
void mnFrame::addSearchResult(wxString* searchStr, WikiList* wikiList) |
| 137 |
{ |
| 138 |
wxTreeItemId searchItem; |
| 139 |
WikiList::Node* node; |
| 140 |
WikiData* data; |
| 141 |
const wxString* subject; |
| 142 |
|
| 143 |
searchItem = searchTree->AppendItem(searchItemRoot, *searchStr, -1, -1, NULL); |
| 144 |
node = wikiList->GetFirst(); |
| 145 |
while(node) { |
| 146 |
data = node->GetData(); |
| 147 |
subject = data->getSubject(); |
| 148 |
searchTree->AppendItem(searchItem, *subject, -1, -1, (wxTreeItemData*)data); |
| 149 |
node = node->GetNext(); |
| 150 |
} |
| 151 |
searchTree->Expand(searchItemRoot); |
| 152 |
searchTree->Expand(searchItem); |
| 153 |
} |
| 154 |
|
| 155 |
void mnFrame::showSelectedItemText(wxTreeEvent& event) |
| 156 |
{ |
| 157 |
wxTreeItemData* item = searchTree->GetItemData(event.GetItem()); |
| 158 |
if(item == NULL) { |
| 159 |
wikiHtmlTextCtrl->SetPage(wxT("")); |
| 160 |
return; |
| 161 |
} |
| 162 |
|
| 163 |
const wxString* fileName = ((WikiData*)(item))->getFileName(); |
| 164 |
const wxString* wikiText = ((WikiData*)(item))->getText(); |
| 165 |
wxString wikiHtml = wxT("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=EUC-JP\"><pre>") + |
| 166 |
*wikiText + |
| 167 |
wxT("</pre>"); |
| 168 |
|
| 169 |
wikiHtmlTextCtrl->SetPage(wikiHtml); |
| 170 |
} |
| 171 |
|
| 172 |
void mnFrame::showNewItem(WikiData* data) |
| 173 |
{ |
| 174 |
wxTreeItemId itemId; |
| 175 |
|
| 176 |
itemId = searchTree->AppendItem(newItemRoot, *(data->getSubject()), -1, -1, (wxTreeItemData*)data); |
| 177 |
searchTree->Expand(searchItemRoot); |
| 178 |
searchTree->Expand(newItemRoot); |
| 179 |
searchTree->SelectItem(itemId); |
| 180 |
} |
| 181 |
|
| 182 |
wxTreeItemData* mnFrame::getSelectedItem() |
| 183 |
{ |
| 184 |
return searchTree->GetItemData(searchTree->GetSelection()); |
| 185 |
} |
| 186 |
|
| 187 |
wxString mnFrame::getSelectedLabel() |
| 188 |
{ |
| 189 |
return searchTree->GetItemText(searchTree->GetSelection()); |
| 190 |
} |
| 191 |
|
| 192 |
bool mnFrame::isEditableTreeLabel(wxTreeItemId id) |
| 193 |
{ |
| 194 |
return !(searchTree->GetItemParent(id) == searchItemRoot || id == searchItemRoot); |
| 195 |
} |
| 196 |
|
| 197 |
bool mnFrame::isNewItem(wxTreeItemId id) |
| 198 |
{ |
| 199 |
return (searchTree->GetItemParent(id) == newItemRoot); |
| 200 |
} |
| 201 |
|