📄 chmframe.cpp
字号:
bool CHMFrame::LoadCHM(const wxString& archive){ wxBusyCursor bc; bool rtn; SaveBookmarks(); _nb->SetSelection(0); rtn = _html->LoadPage(wxString(wxT("file:")) + archive + wxT("#xchm:/")); UpdateCHMInfo(); LoadBookmarks(); return rtn;}bool CHMFrame::LoadContextID( const int contextID ){ wxBusyCursor bc; CHMFile *chmf = CHMInputStream::GetCache(); if(!chmf) return FALSE; if( !chmf->IsValidCID( contextID ) ) return FALSE; return _html->LoadPage(wxString(wxT("file:")) + chmf->ArchiveName() + wxT("#xchm:") + chmf->GetPageByCID( contextID ) );}void CHMFrame::UpdateCHMInfo(){#if !wxUSE_UNICODE static bool noSpecialFont = true; static wxFontEncoding enc = wxFont::GetDefaultEncoding();#endif CHMFile *chmf = CHMInputStream::GetCache(); if(!chmf) return; wxString filename = chmf->ArchiveName(); if(!filename.IsEmpty()) { _fh.AddFileToHistory(filename); if(!_menuFile->IsEnabled(ID_Recent)) _menuFile->Enable(ID_Recent, TRUE); } _html->HistoryClear(); _csp->Reset(); _cip->Reset(); wxString title = chmf->Title(); if(_tcl->GetCount()) _tcl->DeleteAllItems(); chmf->GetTopicsTree(_tcl); chmf->GetIndex(_cip->GetResultsList()); if(!title.IsEmpty()) { wxString titleBarText = wxString(wxT("xCHM v. " VERSION ": ")) + title; SetTitle(titleBarText); _html->SetRelatedFrame(this, titleBarText); } else { SetTitle(wxT("xCHM v. " VERSION)); _html->SetRelatedFrame(this, wxT("xCHM v. " VERSION)); }#if !wxUSE_UNICODE wxString fontFace = chmf->DefaultFont(); if(!fontFace.IsEmpty()) { long fs = -1; fontFace.BeforeLast(wxT(',')).AfterLast(wxT(',')).ToLong(&fs); wxFont font((int)fs, wxDEFAULT, wxNORMAL, wxNORMAL, FALSE, fontFace.BeforeFirst(wxT(',')), chmf->DesiredEncoding()); if(font.Ok()) { int sizes[7]; for(int i = -3; i <= 3; ++i) sizes[i+3] = _fontSize + i * 2; _tcl->SetFont(font); _csp->SetNewFont(font); _cip->SetNewFont(font); _cb->SetFont(font); _html->SetFonts(font.GetFaceName(), font.GetFaceName(), sizes); noSpecialFont = false; } } else if(noSpecialFont == false) { int sizes[7]; for(int i = -3; i <= 3; ++i) sizes[i+3] = _fontSize + i * 2; _tcl->SetFont(_font); wxFont tmp(_font.GetPointSize(), _font.GetFamily(), _font.GetStyle(), _font.GetWeight(), _font.GetUnderlined(), _font.GetFaceName(), enc); if(tmp.Ok()) { _cb->SetFont(tmp); _csp->SetNewFont(tmp); _cip->SetNewFont(tmp); } _html->SetFonts(_normalFont, _fixedFont, sizes); noSpecialFont = true; }#endif // if we have contents.. if(_tcl->GetCount() >= 1) { if(!_sw->IsSplit()) { _nb->Show(TRUE); _sw->SplitVertically(_nb, _html, _sashPos); _menuFile->Check(ID_Contents, TRUE); _tb->ToggleTool(ID_Contents, TRUE); } } else { if(_sw->IsSplit()) { _sw->Unsplit(_nb); _nb->Show(FALSE); } _menuFile->Check(ID_Contents, FALSE); _tb->ToggleTool(ID_Contents, FALSE); } // select Contents _nb->SetSelection(0); }wxMenuBar* CHMFrame::CreateMenu(){ _menuFile = new wxMenu; _menuFile->Append(ID_Open, _("&Open..\tCtrl-O"), OPEN_HELP); _menuFile->Append(ID_Print, _("&Print page..\tCtrl-P"), PRINT_HELP); _menuFile->Append(ID_Fonts, _("Fon&ts..\tCtrl-T"), FONTS_HELP); _menuFile->AppendSeparator(); _menuFile->AppendCheckItem(ID_Contents, _("&Show contents tree\tCtrl-S"), CONTENTS_HELP); _menuFile->AppendSeparator(); wxMenu *recent = new wxMenu; _menuFile->Append(ID_Recent, _("&Recent files"), recent); _fh.UseMenu(recent); // Fill the file history menu. wxConfig config(wxT("xchm")); config.SetPath(wxT("/Recent")); _fh.Load(config); if(_fh.GetCount() == 0) _menuFile->Enable(ID_Recent, FALSE); _menuFile->AppendSeparator(); _menuFile->Append(ID_Quit, _("E&xit\tCtrl-X"), _("Quit the application.")); wxMenu *menuHistory = new wxMenu; menuHistory->Append(ID_Home, _("&Home\tCtrl-H"), HOME_HELP); menuHistory->Append(ID_Forward, _("For&ward\tCtrl-W"), FORWARD_HELP); menuHistory->Append(ID_Back, _("&Back\tCtrl-B"), BACK_HELP); wxMenu *menuHelp = new wxMenu; menuHelp->Append(ID_About, _("&About ..\tF1"), ABOUT_HELP); wxMenuBar *menuBar = new wxMenuBar; menuBar->Append(_menuFile, _("&File")); menuBar->Append(menuHistory, _("Hi&story")); menuBar->Append(menuHelp, _("&Help")); return menuBar;}namespace {#include <hbook_open.xpm>#include <hbook_closed.xpm>#include <hpage.xpm>} // namespacewxPanel* CHMFrame::CreateContentsPanel(){ wxPanel *temp = new wxPanel(_nb); wxSizer *sizer = new wxBoxSizer(wxVERTICAL); wxSizer *bmarks = new wxStaticBoxSizer( new wxStaticBox(temp, -1, _("Bookmarks")), wxVERTICAL); wxSizer *inner = new wxBoxSizer(wxHORIZONTAL); temp->SetAutoLayout(TRUE); temp->SetSizer(sizer); wxImageList *tclBL = new wxImageList(16, 16); tclBL->Add(wxIcon(hbook_closed_xpm)); tclBL->Add(wxIcon(hbook_closed_xpm)); tclBL->Add(wxIcon(hbook_open_xpm)); tclBL->Add(wxIcon(hbook_open_xpm)); wxImageList *tclIL = new wxImageList(16, 16); tclIL->Add(wxIcon(hpage_xpm)); _tcl = new wxTreeCtrl(temp, ID_TreeCtrl, wxDefaultPosition, wxDefaultSize, wxTR_HAS_BUTTONS | wxSUNKEN_BORDER | wxTR_HIDE_ROOT | wxTR_LINES_AT_ROOT); _tcl->AssignButtonsImageList(tclBL); _tcl->AssignImageList(tclIL); _cb = new wxComboBox(temp, ID_Bookmarks, wxT(""), wxDefaultPosition, wxDefaultSize, 0, NULL, wxCB_DROPDOWN | wxCB_READONLY); sizer->Add(_tcl, 1, wxEXPAND, 0); sizer->Add(bmarks, 0, wxEXPAND | wxALL, 0); bmarks->Add(_cb, 0, wxEXPAND | wxBOTTOM, 5); bmarks->Add(inner, 1, wxEXPAND, 0); wxButton *badd = new wxButton(temp, ID_Add, _("Add")); wxButton *bremove = new wxButton(temp, ID_Remove, _("Remove"));#if wxUSE_TOOLTIPS badd->SetToolTip(_("Add displayed page to bookmarks.")); bremove->SetToolTip(_("Remove selected bookmark."));#endif inner->Add(badd, 1, wxEXPAND | wxRIGHT, 2); inner->Add(bremove, 1, wxEXPAND | wxLEFT, 2); return temp;}void CHMFrame::LoadBookmarks(){ _cb->Clear(); _cb->SetValue(wxEmptyString); CHMFile *chmf = CHMInputStream::GetCache(); if(!chmf) return; wxConfig config(wxT("xchm")); wxString bookname = chmf->ArchiveName(); bookname.Replace(wxT("/"), wxT("."), TRUE); bookname = wxString(wxT("/Bookmarks/")) + bookname; long noEntries; config.SetPath(bookname); wxString title, url; if(config.Read(wxT("noEntries"), &noEntries)) { const wxChar* format1 = wxT("bookmark_%ld_title"); const wxChar* format2 = wxT("bookmark_%ld_url"); for(long i = 0; i < noEntries; ++i) { config.Read(wxString::Format(format1, i), &title); config.Read(wxString::Format(format2, i), &url); _cb->Append(title, new wxString(url)); } }}void CHMFrame::SaveBookmarks(){ long noEntries = _cb->GetCount(); if(!_bookmarksDeleted && noEntries == 0) return; CHMFile *chmf = CHMInputStream::GetCache(); if(!chmf) return; wxConfig config(wxT("xchm")); wxString bookname = chmf->ArchiveName(); bookname.Replace(wxT("/"), wxT("."), TRUE); bookname = wxString(wxT("/Bookmarks/")) + bookname; if(_bookmarksDeleted) config.DeleteGroup(bookname); if(noEntries == 0) return; config.SetPath(bookname); config.Write(wxT("noEntries"), noEntries); const wxChar* format1 = wxT("bookmark_%ld_title"); const wxChar* format2 = wxT("bookmark_%ld_url"); for(int i = 0; i < noEntries; ++i) { wxString *url = reinterpret_cast<wxString *>(#ifdef __WXGTK__ _cb->GetClientData(i));#else _cb->wxItemContainer::GetClientData(i));#endif config.Write(wxString::Format(format1, i), _cb->GetString(i)); if(url) config.Write(wxString::Format(format2, i), *url); }}void CHMFrame::SaveExitInfo(){ int xorig, yorig, width, height; int sashPos = _sw->IsSplit() ? _sw->GetSashPosition() : _sashPos; GetPosition(&xorig, &yorig); GetSize(&width, &height); wxConfig config(wxT("xchm")); config.Write(wxT("/Position/xOrig"), xorig); config.Write(wxT("/Position/yOrig"), yorig); config.Write(wxT("/Position/width"), width); config.Write(wxT("/Position/height"), height); config.Write(wxT("/Paths/lastOpenedDir"), _openPath); config.Write(wxT("/Fonts/normalFontFace"), _normalFont); config.Write(wxT("/Fonts/fixedFontFace"), _fixedFont); config.Write(wxT("/Fonts/size"), _fontSize); config.Write(wxT("/Sash/leftMargin"), sashPos); config.SetPath(wxT("/Recent")); _fh.Save(config);}namespace {#include <fileopen.xpm>#include <print.xpm>#include <back.xpm>#include <forward.xpm>#include <home.xpm>#include <helpicon.xpm>#include <htmsidep.xpm>#include <htmoptns.xpm>} // namespacebool CHMFrame::InitToolBar(wxToolBar *toolbar){ toolbar->AddTool(ID_Open, _("Open .."), wxBitmap(fileopen_xpm), OPEN_HELP); toolbar->AddTool(ID_Print, _("Print .."), wxBitmap(print_xpm), PRINT_HELP); toolbar->AddTool(ID_Fonts, _("Fonts .."), wxBitmap(htmoptns_xpm), FONTS_HELP); toolbar->AddCheckTool(ID_Contents, _("Contents"), wxBitmap(htmsidep_xpm), wxBitmap(htmsidep_xpm), CONTENTS_HELP); toolbar->AddSeparator(); toolbar->AddTool(ID_Back, _("Back"), wxBitmap(back_xpm), BACK_HELP); toolbar->AddTool(ID_Forward, _("Forward"), wxBitmap(forward_xpm), FORWARD_HELP); toolbar->AddTool(ID_Home, _("Home"), wxBitmap(home_xpm), HOME_HELP); toolbar->AddSeparator(); toolbar->AddTool(ID_About, _("About"), wxBitmap(helpicon_xpm), ABOUT_HELP); toolbar->Realize(); return TRUE;}// They say this needs to be in the implementation file.BEGIN_EVENT_TABLE(CHMFrame, wxFrame) EVT_MENU(ID_Quit, CHMFrame::OnQuit) EVT_MENU(ID_About, CHMFrame::OnAbout) EVT_MENU(ID_Open, CHMFrame::OnOpen) EVT_MENU(ID_Fonts, CHMFrame::OnChangeFonts) EVT_MENU(ID_Home, CHMFrame::OnHome) EVT_MENU(ID_Forward, CHMFrame::OnHistoryForward) EVT_MENU(ID_Back, CHMFrame::OnHistoryBack) EVT_MENU(ID_Contents, CHMFrame::OnShowContents) EVT_MENU(ID_Print, CHMFrame::OnPrint) EVT_MENU_RANGE(wxID_FILE1, wxID_FILE9, CHMFrame::OnHistFile) EVT_MENU(ID_FindInPage, CHMFrame::OnFind) EVT_BUTTON(ID_Add, CHMFrame::OnAddBookmark) EVT_BUTTON(ID_Remove, CHMFrame::OnRemoveBookmark) EVT_TREE_SEL_CHANGED(ID_TreeCtrl, CHMFrame::OnSelectionChanged) EVT_COMBOBOX(ID_Bookmarks, CHMFrame::OnBookmarkSel) EVT_CLOSE(CHMFrame::OnCloseWindow)END_EVENT_TABLE()
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -