⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 chmframe.cpp

📁 一个CHM在LINUX下的使用工具
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/*  Copyright (C) 2003  Razvan Cojocaru <razvanco@gmx.net>   XML-RPC/Context ID code contributed by Eamon Millman / PCI Geomatics  <millman@pcigeomatics.com>  Tree control icons code (and the icons) contributed by Fritz Elfert  <felfert@users.sourceforge.net>.   This program is free software; you can redistribute it and/or modify  it under the terms of the GNU General Public License as published by  the Free Software Foundation; either version 2 of the License, or  (at your option) any later version.    This program is distributed in the hope that it will be useful,  but WITHOUT ANY WARRANTY; without even the implied warranty of  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the  GNU General Public License for more details.    You should have received a copy of the GNU General Public License  along with this program; if not, write to the Free Software  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.*/#include <chmframe.h>#include <chminputstream.h>#include <contenttaghandler.h>#include <chmhtmlwindow.h>#include <chmfontdialog.h>#include <chmsearchpanel.h>#include <chmindexpanel.h>#include <chmlistctrl.h>#include <wx/fontenum.h>#include <wx/statbox.h>#include <wx/accel.h>#define OPEN_HELP _("Open a CHM book.")#define FONTS_HELP _("Change fonts.")#define PRINT_HELP _("Print the page currently displayed.")#define CONTENTS_HELP _("On or off?")#define HOME_HELP _("Go to the book's start page.")#define FORWARD_HELP _("Go forward in history. Per book.")#define BACK_HELP _("Back to the last visited page. Per book.")#define ABOUT_HELP _("About the program.")namespace {const wxChar *greeting = wxT(	"<html><body>Hello, and welcome to <B>xCHM</B>, the UNIX CHM viewer."	"<br><br><B>xCHM</B> has been written by Razvan Cojocaru "	"(razvanco@gmx.net). It is licensed under the <TT>GPL</TT>.<br>"	"<B>xCHM</B> is based on Jed Wing's <a href=\"http://66.93.236.84/"	"~jedwin/projects/chmlib/\">CHMLIB</a> and <a href=\"http://www."	"wxwidgets.org\">wxWidgets</a>.<br><br>If you'd like to know more"	" about CHM, you could check out <a href=\"http://www.speakeasy."	"org/~russotto/chm/\">Matthew Russoto's CHM page</a> or <a"	" href=\"http://bonedaddy.net/pabs3/hhm/\">Pabs' CHM Specification"	" page</a>.<br>Pabs has contributed time and knowledge to the"	" development of <B>xCHM</B>, and features such as the fast index"	" search would not have been implemented without his help."	" Portions of the fast index search are modified versions of"	" Pabs' <TT>GPL</TT>d <TT>chmdeco</TT> code.<br><br>If"	" you'd like to use the code in your own stuff please figure"	" <TT>GPL</TT> out first. Far too many people think <TT>GPL</TT> is"	" bad out of utter ignorance.<br><br>Tips:<br><ul><li>"	"The global search is an \'AND\' search, i.e. searching for"	" \'word1 word2\' (quotes not included) will find all the pages"	" that contain both word1 and word2, in whatever order.</li>"	"<li>Allowing partial matches will find pages that contain"	" words that only start with the typed strings, i.e. searching"	" for \'ans 4\' (quotes not included) will find pages that"	" contain the sentence \'The answer is 42.\'.</li><li>Right"	" clicking on the displayed page brings out a popup menu with"	" common options.</li></ul><br><br>Enjoy.</body></html>");const wxChar *about_txt = wxT(	"xCHM v. " VERSION "\nby Razvan Cojocaru <razvanco@gmx.net>\n\n"	"With thanks to Pabs (http://bonedaddy.net/pabs3/hhm/).\n"	"Based on Jed Wing's CHMLIB (http://66.93.236.84/~jedwin/projects/).\n"	"XMLRPC code for context sensitive help contributed by\n"	"Eamon Millman <millman@pcigeomatics.com>.\n"	"<SPAN> tag support and contents tree icons contributed by\n"	"Fritz Elfert <felfert@users.sourceforge.net>.\n"	"Written with wxWidgets (http://www.wxwidgets.org).\n\n"	"This program is (proudly) under the GPL.");#include <xchm-32.xpm>} // namespaceCHMFrame::CHMFrame(const wxString& title, const wxString& booksDir, 		   const wxPoint& pos, const wxSize& size,		   const wxString& normalFont, const wxString& fixedFont,		   const int fontSize, const int sashPosition)	: wxFrame(NULL, -1, title, pos, size), _html(NULL),	  _tcl(NULL), _sw(NULL), _menuFile(NULL), _tb(NULL), _ep(NULL),	  _nb(NULL), _cb(NULL), _csp(NULL), _cip(NULL), _openPath(booksDir), 	  _normalFonts(NULL), _fixedFonts(NULL), _normalFont(normalFont), 	  _fixedFont(fixedFont), _fontSize(fontSize), _bookmarkSel(true),	  _bookmarksDeleted(false), _sashPos(sashPosition){#	if wxUSE_ACCEL	wxAcceleratorEntry entries[1];	entries[0].Set(wxACCEL_CTRL, (int) 'F', ID_FindInPage);	wxAcceleratorTable accel(1, entries);	SetAcceleratorTable(accel);#	endif	int sizes[7];	for(int i = -3; i <= 3; ++i)		sizes[i+3] = _fontSize + i * 2;	SetIcon(wxIcon(xchm_32_xpm));	SetMenuBar(CreateMenu());	_tb = CreateToolBar(wxTB_FLAT | wxTB_DOCKABLE			    | wxTB_HORIZONTAL | wxTB_TEXT);	InitToolBar(_tb);	CreateStatusBar();	SetStatusText(_("Ready."));	_ep = new wxHtmlEasyPrinting(wxT("Printing"), this);	_sw = new wxSplitterWindow(this);	_sw->SetMinimumPaneSize(CONTENTS_MARGIN);	_nb = new wxNotebook(_sw, ID_Notebook);	_nb->Show(FALSE);	wxPanel* temp = CreateContentsPanel();	_html = new CHMHtmlWindow(_sw, _tcl, this);	_html->SetRelatedFrame(this, wxT("xCHM v. " VERSION));	_html->SetRelatedStatusBar(0);	_html->SetFonts(_normalFont, _fixedFont, sizes);		_html->SetPage(greeting);	_csp = new CHMSearchPanel(_nb, _tcl, _html);	_font = _tcl->GetFont();	_cip = new CHMIndexPanel(_nb, _html);	_nb->AddPage(temp, _("Contents"));	_nb->AddPage(_cip, _("Index"));	_nb->AddPage(_csp, _("Search"));	_sw->Initialize(_html);	_html->SetFocusFromKbd();}CHMFrame::~CHMFrame(){	delete _ep;	delete _fixedFonts;	delete _normalFonts;}void CHMFrame::OnQuit(wxCommandEvent& WXUNUSED(event)){	Close(TRUE);}void CHMFrame::OnAbout(wxCommandEvent& WXUNUSED(event)){	::wxMessageBox(about_txt, _("About xCHM"),		       wxOK | wxICON_INFORMATION, this );}void CHMFrame::OnOpen(wxCommandEvent& WXUNUSED(event)){	wxString selection =		::wxFileSelector(_("Choose a file.."), _openPath, 				 wxEmptyString, wxT("chm"),#ifndef __WXMOTIF__				 // they say Motif can't handle the following.				 wxT("CHM files (*.chm)|*.chm;*.CHM|"				 "All files (*.*)|*.*"), #else				 wxT("All files (*.*)|*.*"),#endif				 wxOPEN | wxFILE_MUST_EXIST, this);	if(selection.IsEmpty() || !_tcl)		return;	_openPath = selection.BeforeLast(wxT('/'));	LoadCHM(selection);}void CHMFrame::OnChangeFonts(wxCommandEvent& WXUNUSED(event)){	// First time initialization only.	if(_normalFonts == NULL) {		wxFontEnumerator enu;		enu.EnumerateFacenames();		_normalFonts = new wxArrayString;		*_normalFonts = *enu.GetFacenames();		_normalFonts->Sort();	}	if(_fixedFonts == NULL) {		wxFontEnumerator enu;		enu.EnumerateFacenames(wxFONTENCODING_SYSTEM, TRUE);		_fixedFonts = new wxArrayString;		*_fixedFonts = *enu.GetFacenames();		_fixedFonts->Sort();	}	assert(_normalFonts != NULL);	assert(_fixedFonts != NULL);	CHMFontDialog cfd(this, _normalFonts, _fixedFonts, _normalFont,			  _fixedFont, _fontSize);	if(cfd.ShowModal() == wxID_OK) {				wxBusyCursor bc;		_html->SetFonts(_normalFont = cfd.NormalFont(), 				_fixedFont = cfd.FixedFont(),				cfd.Sizes());		_fontSize = *(cfd.Sizes() + 3);		wxString page = _html->GetOpenedPage();		if(page.IsEmpty())			_html->SetPage(greeting); 	}}void CHMFrame::OnHome(wxCommandEvent& WXUNUSED(event)){	CHMFile *chmf = CHMInputStream::GetCache();	if(!chmf)		return;	_html->LoadPage(wxString(wxT("file:")) + chmf->ArchiveName()		+ wxT("#xchm:") + chmf->HomePage());}void CHMFrame::OnHistoryForward(wxCommandEvent& WXUNUSED(event)){	_html->HistoryForward();}void CHMFrame::OnHistoryBack(wxCommandEvent& WXUNUSED(event)){	_html->HistoryBack();}void CHMFrame::OnShowContents(wxCommandEvent& WXUNUSED(event)){	if(_sw->IsSplit()) {		_tb->ToggleTool(ID_Contents, FALSE);		_menuFile->Check(ID_Contents, FALSE);		_sashPos = _sw->GetSashPosition();				_sw->Unsplit(_nb);		_nb->Show(FALSE);	} else {							if(_tcl->GetCount() >= 1) {						_tb->ToggleTool(ID_Contents, TRUE);			_menuFile->Check(ID_Contents, TRUE);			_nb->Show(TRUE);			_sw->SplitVertically(_nb, _html, _sashPos);		} else {			_tb->ToggleTool(ID_Contents, FALSE);			_menuFile->Check(ID_Contents, FALSE);						::wxMessageBox(_("Couldn't extract the book"				       " contents tree."), 				       _("No contents.."), 				       wxOK | wxICON_WARNING, this );		}	}}void CHMFrame::OnPrint(wxCommandEvent& WXUNUSED(event)){	wxString page = _html->GetOpenedPage();	if(page.IsEmpty())		_ep->PrintText(greeting);	else		_ep->PrintFile(page);}void CHMFrame::OnHistFile(wxCommandEvent& event){      wxString f(_fh.GetHistoryFile(event.GetId() - wxID_FILE1));      if (!f.IsEmpty())	      LoadCHM(f);}void CHMFrame::OnFind(wxCommandEvent& event){	_html->OnFind(event);}void CHMFrame::OnAddBookmark(wxCommandEvent& WXUNUSED(event)){	wxTreeItemId id = _tcl->GetSelection();	if(!id.IsOk())		return;	wxString title = _tcl->GetItemText(id); 	if(title.IsEmpty())		return;       	URLTreeItem *data = reinterpret_cast<URLTreeItem *>(		_tcl->GetItemData(id));	if(!data || (data->_url).IsEmpty())		return;	_cb->Append(title, new wxString(data->_url));	_bookmarkSel = false;	_cb->SetSelection(_cb->GetCount() - 1);	_bookmarkSel = true;		}void CHMFrame::OnRemoveBookmark(wxCommandEvent& WXUNUSED(event)){	if(!_cb->GetCount())		return;	_cb->Delete(_cb->GetSelection());	_bookmarksDeleted = true;	if(_cb->GetCount()) {		_bookmarkSel = false;		_cb->SetSelection(0);		_bookmarkSel = true;	} else {		_cb->SetValue(wxEmptyString);	}}void CHMFrame::OnBookmarkSel(wxCommandEvent& WXUNUSED(event)){	if(!_bookmarkSel)		return;	wxString *url = reinterpret_cast<wxString *>(#ifdef __WXGTK__		_cb->GetClientData(_cb->GetSelection()));#else		_cb->wxItemContainer::GetClientData(_cb->GetSelection()));#endif	if(!url || url->IsEmpty())		return;	CHMFile *chmf = CHMInputStream::GetCache();	if(!chmf)		return;	_html->LoadPage(wxString(wxT("file:")) + chmf->ArchiveName() +			wxT("#xchm:/") + *url);}void CHMFrame::OnSelectionChanged(wxTreeEvent& event){	wxTreeItemId id = event.GetItem();	CHMFile *chmf = CHMInputStream::GetCache();	if(id == _tcl->GetRootItem() || !chmf)		return;	URLTreeItem *data = reinterpret_cast<URLTreeItem *>(		_tcl->GetItemData(id));	if(!data || data->_url.IsEmpty())		return;	if(!_html->IsCaller()) {		_html->SetSync(false);		_html->LoadPage(wxString(wxT("file:")) + chmf->ArchiveName() +				wxT("#xchm:/") + data->_url);		_html->SetSync(true);	}}void CHMFrame::OnCloseWindow(wxCloseEvent& WXUNUSED(event)){	SaveExitInfo();	SaveBookmarks();	Destroy();}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -