xCHM  1.23
chmframe.h
1 /*
2 
3  Copyright (C) 2003 - 2013 Razvan Cojocaru <rzvncj@gmail.com>
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program; if not, write to the Free Software
17  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
18  MA 02110-1301, USA.
19 
20 */
21 
22 
23 #ifndef __CHMFRAME_H_
24 #define __CHMFRAME_H_
25 
26 #include <wx/wx.h>
27 #include <wx/html/htmprint.h>
28 #include <wx/splitter.h>
29 #include <wx/notebook.h>
30 #include <wx/treectrl.h>
31 #include <wx/panel.h>
32 #include <wx/combobox.h>
33 #include <wx/font.h>
34 #include <wx/docview.h>
35 #include <wx/thread.h>
36 
37 
38 // Forward declarations.
39 class CHMHtmlWindow;
40 class CHMSearchPanel;
41 class CHMIndexPanel;
42 class wxFileType;
43 class CHMHtmlNotebook;
44 
46 #define CHM_DEFAULT_FONT_SIZE 12
47 
49 #define CONTENTS_MARGIN 170
50 
51 
52 #ifdef HAVE_CONFIG_H
53 # include <config.h>
54 #else
55  // this should never happen
56 # define VERSION "unknown"
57 #endif
58 
59 
61 enum
62 {
63  ID_Quit = 1,
64  ID_About,
65  ID_Open,
66  ID_Fonts,
67  ID_Print,
68  ID_Home,
69  ID_Forward,
70  ID_Back,
71  ID_Contents,
72  ID_Bookmarks,
73  ID_Add,
74  ID_Remove,
75  ID_FindInPage,
76  ID_CopySelection,
77  ID_Recent,
78  ID_Notebook,
79  ID_RegisterExtension,
80  ID_CloseTab,
81  ID_NewTab,
82  ID_FullScreen,
83  ID_TreeCtrl = 1000,
84 };
85 
86 
97 class CHMFrame : public wxFrame {
98 
99 public:
118  CHMFrame(const wxString& title, const wxString& booksDir,
119  const wxPoint& pos, const wxSize& size,
120  const wxString& normalFont = wxEmptyString,
121  const wxString& fixedFont = wxEmptyString,
122  const int fontSize = CHM_DEFAULT_FONT_SIZE,
123  const int sashPosition = CONTENTS_MARGIN,
124  const wxString& fullAppPath = wxEmptyString,
125  bool loadTopics = true, bool loadIndex = true);
126 
128  ~CHMFrame();
129 
135  bool LoadCHM(const wxString& archive);
136 
142  bool LoadContextID( const int contextID );
143 
145  void UpdateCHMInfo();
146 
148  void AddHtmlView(const wxString& path, const wxString& link);
149 
151  void ToggleFullScreen(bool onlyIfFullScreenOn = false);
152 
153 protected:
155  void OnQuit(wxCommandEvent& event);
156 
158  void OnAbout(wxCommandEvent& event);
159 
161  void OnOpen(wxCommandEvent& event);
162 
164  void OnChangeFonts(wxCommandEvent& event);
165 
167  void OnHome(wxCommandEvent& event);
168 
170  void OnHistoryForward(wxCommandEvent& event);
171 
173  void OnHistoryBack(wxCommandEvent& event);
174 
179  void OnShowContents(wxCommandEvent& event);
180 
182  void OnPrint(wxCommandEvent& event);
183 
185  void OnHistFile(wxCommandEvent& event);
186 
188  void OnFind(wxCommandEvent& event);
189 
191  void OnCopySelection(wxCommandEvent& event);
192 
194  void OnFullScreen(wxCommandEvent& event);
195 
197  void OnAddBookmark(wxCommandEvent& event);
198 
199 #if defined(__WXMSW__) || defined(__WXMAC__)
200  void OnRegisterExtension(wxCommandEvent& event);
202 #endif// __WXMSW__
203 
205  void OnRemoveBookmark(wxCommandEvent& event);
206 
208  void OnBookmarkSel(wxCommandEvent &event);
209 
211  void OnSelectionChanged(wxTreeEvent& event);
212 
214  void OnCloseWindow(wxCloseEvent& event);
215 
217  void OnChar(wxKeyEvent &event);
218 
220  void OnCloseTab(wxCommandEvent& event);
221 
223  void OnNewTab(wxCommandEvent& event);
224 private:
226  wxMenuBar *CreateMenu();
227 
229  bool InitToolBar(wxToolBar *toolbar);
230 
233 
235  void LoadBookmarks();
236 
238  void SaveBookmarks();
239 
241  void SaveExitInfo();
242 
243 private:
244  CHMHtmlNotebook * _nbhtml;
245  wxTreeCtrl* _tcl;
246  wxSplitterWindow* _sw;
247  wxMenu* _menuFile;
248  wxToolBar* _tb;
249  wxHtmlEasyPrinting* _ep;
250  wxNotebook* _nb;
251  wxComboBox* _cb;
252  CHMSearchPanel* _csp;
253  CHMIndexPanel* _cip;
254 
255  wxString _openPath;
256  wxArrayString* _normalFonts;
257  wxArrayString* _fixedFonts;
258  wxString _normalFont;
259  wxString _fixedFont;
260  int _fontSize;
261  bool _bookmarkSel;
262  bool _bookmarksDeleted;
263  int _sashPos;
264  wxFont _font;
265  wxFileHistory _fh;
266  wxString _fullAppPath;
267  bool _loadTopics;
268  bool _loadIndex;
269  bool _fullScreen;
270 
271 private:
272  DECLARE_EVENT_TABLE()
273 };
274 
275 
276 #endif // __CHMFRAME_H_
277 
278 
279 /*
280  Local Variables:
281  mode: c++
282  c-basic-offset: 8
283  tab-width: 8
284  c-indent-comments-syntactically-p: t
285  c-tab-always-indent: t
286  indent-tabs-mode: t
287  End:
288 */
289 
290 // vim:shiftwidth=8:autoindent:tabstop=8:noexpandtab:softtabstop=8
void OnFullScreen(wxCommandEvent &event)
Called when fullscreen mode is being toggled.
Definition: chmframe.cpp:450
void OnHistoryForward(wxCommandEvent &event)
Called when the user wants to go forward in the history.
Definition: chmframe.cpp:328
void OnHistoryBack(wxCommandEvent &event)
Called when the user wants to go back in the history.
Definition: chmframe.cpp:334
void OnHistFile(wxCommandEvent &event)
Called when the user selects a file from the file history.
Definition: chmframe.cpp:418
void SaveBookmarks()
Helper. Saves the bookmarks for the currently opened CHM file.
Definition: chmframe.cpp:931
void OnBookmarkSel(wxCommandEvent &event)
Called when the user chooses a bookmark from the wxChoice control.
Definition: chmframe.cpp:501
void OnChangeFonts(wxCommandEvent &event)
Called when the user wants to change the fonts.
Definition: chmframe.cpp:258
void OnFind(wxCommandEvent &event)
Called when the user types Ctrl-F.
Definition: chmframe.cpp:426
Custom HTML widget class. Needed for sychnronization between the topics tree control and the currentl...
Definition: chmhtmlwindow.h:62
wxWidgets application class.
Definition: chmhtmlnotebook.h:38
void OnOpen(wxCommandEvent &event)
Called when the user wants to open a file.
Definition: chmframe.cpp:236
Custom built search panel.
Definition: chmsearchpanel.h:59
wxWidgets frame widget class.
Custom panel for displaying the .chm index (if available).
Definition: chmindexpanel.h:50
bool InitToolBar(wxToolBar *toolbar)
Helper. Initializes the frame toolbar.
Definition: chmframe.cpp:1019
void OnChar(wxKeyEvent &event)
Called when the user presses a key.
Definition: chmframe.cpp:562
Custom HTML notebook widget class. For tabbed viewing of a CHM file.
Definition: chmhtmlnotebook.h:49
CHMFrame(const wxString &title, const wxString &booksDir, const wxPoint &pos, const wxSize &size, const wxString &normalFont=wxEmptyString, const wxString &fixedFont=wxEmptyString, const int fontSize=CHM_DEFAULT_FONT_SIZE, const int sashPosition=CONTENTS_MARGIN, const wxString &fullAppPath=wxEmptyString, bool loadTopics=true, bool loadIndex=true)
Brings the frame into existence.
Definition: chmframe.cpp:127
void OnShowContents(wxCommandEvent &event)
Called when the user wants to either disable or enable the contents tree panel on the left...
Definition: chmframe.cpp:345
generic wxWidgets panel widget class.
Definition: chmindexpanel.h:33
wxPanel * CreateContentsPanel()
Helper. Creates the contents panel.
Definition: chmframe.cpp:848
void UpdateCHMInfo()
Fills the index and the contents tree.
Definition: chmframe.cpp:643
void OnCloseWindow(wxCloseEvent &event)
Cleanup code. This saves the window position and last open dir.
Definition: chmframe.cpp:554
void OnCopySelection(wxCommandEvent &event)
Called when the user types Ctrl-F.
Definition: chmframe.cpp:444
void LoadBookmarks()
Helper. Loads the bookmarks for the currently opened CHM file.
Definition: chmframe.cpp:896
void AddHtmlView(const wxString &path, const wxString &link)
Add html view.
Definition: chmframe.cpp:1059
bool LoadContextID(const int contextID)
Attempts to load a context-ID from within the current chm file.
Definition: chmframe.cpp:625
void OnAbout(wxCommandEvent &event)
Called when the user clicks on About.
Definition: chmframe.cpp:229
void OnRemoveBookmark(wxCommandEvent &event)
Called when the user clicks on the Remove button.
Definition: chmframe.cpp:483
The frame, owner of the wxHtmlWindow, contents tree control and all the other nifty stuff...
Definition: chmframe.h:97
void OnQuit(wxCommandEvent &event)
Called when the user closes the window.
Definition: chmframe.cpp:223
void SaveExitInfo()
Helper. Saves exit information (size, history, etc.)
Definition: chmframe.cpp:977
void ToggleFullScreen(bool onlyIfFullScreenOn=false)
Toggles fullscreen mode.
Definition: chmframe.cpp:1065
void OnNewTab(wxCommandEvent &event)
Called when the user types Ctrl-N.
Definition: chmframe.cpp:438
void OnAddBookmark(wxCommandEvent &event)
Called when the user clicks on the Add button.
Definition: chmframe.cpp:457
~CHMFrame()
Cleans up.
Definition: chmframe.cpp:212
wxMenuBar * CreateMenu()
Helper. Creates the menu.
Definition: chmframe.cpp:770
bool LoadCHM(const wxString &archive)
Attempts to load a .chm file and display it&#39;s home page.
Definition: chmframe.cpp:573
void OnSelectionChanged(wxTreeEvent &event)
Called when an item in the contents tree is clicked.
Definition: chmframe.cpp:527
void OnCloseTab(wxCommandEvent &event)
Called when the user types Ctrl-F4.
Definition: chmframe.cpp:432
void OnHome(wxCommandEvent &event)
Called when the user wants to see the default page.
Definition: chmframe.cpp:315
void OnPrint(wxCommandEvent &event)
Called when the user wants to print the displayed page.
Definition: chmframe.cpp:405