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 
45 //! Default font size for the wxHtmlWindow.
46 #define CHM_DEFAULT_FONT_SIZE 12
47 
48 //! Default sash position.
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 
60 //! IDs for various widget events.
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 
87 /*!
88   \class wxFrame
89   \brief wxWidgets frame widget class.
90 */
91 
92 
93 /*!
94   \brief The frame, owner of the wxHtmlWindow, contents tree control and
95   all the other nifty stuff.
96 */
97 class CHMFrame : public wxFrame {
98 
99 public:
100 	/*!
101 	  \brief Brings the frame into existence.
102 	  \param title The text that shows up on the titlebar.
103 	  \param booksDir Where to go when you click Open.. on the
104 	  toolbar. This is used to remember the last directory where
105 	  a book was sucessfully opened. For the current working
106 	  directory just pass the empty string.
107 	  \param pos The upper left corner of the frame.
108 	  \param size The size of the frame.
109 	  \param normalFont Name of the font face to use for normal text.
110 	  \param fixedFont Name of the font face to use for fixed text.
111 	  \param fontSize The font size.
112 	  \param sashPosition Distance from the left of the frame to
113 	  \param fullAppPath The absolute path to the executable of the process
114 	  the end of the contents / search panel.
115 	  \param loadTopics If set to false, don't try to load the topics tree.
116 	  \param loadIndex If set to false, don't try to load the index list.
117 	*/
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 
127 	//! Cleans up.
128 	~CHMFrame();
129 
130 	/*!
131 	  \brief Attempts to load a .chm file and display it's home page.
132 	  \param archive The .chm file name on disk.
133 	  \return TRUE if the operation was successful.
134 	 */
135 	bool LoadCHM(const wxString& archive);
136 
137 	/*!
138 	  \brief Attempts to load a context-ID from within the current chm file
139 	  \param contextID the context-ID to load.
140 	  \return TRUE if the operation was successful.
141 	 */
142 	bool LoadContextID( const int contextID );
143 
144 	//! Fills the index and the contents tree.
145 	void UpdateCHMInfo();
146 
147 	//! Add html view
148 	void AddHtmlView(const wxString& path, const wxString& link);
149 
150 	//! Toggles fullscreen mode
151 	void ToggleFullScreen(bool onlyIfFullScreenOn = false);
152 
153 protected:
154 	//! Called when the user closes the window.
155 	void OnQuit(wxCommandEvent& event);
156 
157 	//! Called when the user clicks on About.
158 	void OnAbout(wxCommandEvent& event);
159 
160 	//! Called when the user wants to open a file.
161 	void OnOpen(wxCommandEvent& event);
162 
163 	//! Called when the user wants to change the fonts.
164 	void OnChangeFonts(wxCommandEvent& event);
165 
166 	//! Called when the user wants to see the default page.
167 	void OnHome(wxCommandEvent& event);
168 
169 	//! Called when the user wants to go forward in the history.
170 	void OnHistoryForward(wxCommandEvent& event);
171 
172 	//! Called when the user wants to go back in the history.
173 	void OnHistoryBack(wxCommandEvent& event);
174 
175 	/*!
176 	  \brief Called when the user wants to either disable or enable
177 	  the contents tree panel on the left.
178 	*/
179 	void OnShowContents(wxCommandEvent& event);
180 
181 	//! Called when the user wants to print the displayed page.
182 	void OnPrint(wxCommandEvent& event);
183 
184 	//! Called when the user selects a file from the file history.
185 	void OnHistFile(wxCommandEvent& event);
186 
187 	//! Called when the user types Ctrl-F.
188 	void OnFind(wxCommandEvent& event);
189 
190 	//! Called when the user types Ctrl-F.
191 	void OnCopySelection(wxCommandEvent& event);
192 
193 	//! Called when fullscreen mode is being toggled
194 	void OnFullScreen(wxCommandEvent& event);
195 
196 	//! Called when the user clicks on the Add button.
197 	void OnAddBookmark(wxCommandEvent& event);
198 
199 #if defined(__WXMSW__) || defined(__WXMAC__)
200 	//! Called when the user selects Register extension
201 	void OnRegisterExtension(wxCommandEvent& event);
202 #endif// __WXMSW__
203 
204 	//! Called when the user clicks on the Remove button.
205 	void OnRemoveBookmark(wxCommandEvent& event);
206 
207 	//! Called when the user chooses a bookmark from the wxChoice control.
208 	void OnBookmarkSel(wxCommandEvent &event);
209 
210 	//! Called when an item in the contents tree is clicked.
211 	void OnSelectionChanged(wxTreeEvent& event);
212 
213 	//! Cleanup code. This saves the window position and last open dir.
214 	void OnCloseWindow(wxCloseEvent& event);
215 
216 	//! Called when the user presses a key
217 	void OnChar(wxKeyEvent &event);
218 
219 	//! Called when the user types Ctrl-F4.
220 	void OnCloseTab(wxCommandEvent& event);
221 
222 	//! Called when the user types Ctrl-N.
223 	void OnNewTab(wxCommandEvent& event);
224 private:
225 	//! Helper. Creates the menu.
226 	wxMenuBar *CreateMenu();
227 
228 	//! Helper. Initializes the frame toolbar.
229 	bool InitToolBar(wxToolBar *toolbar);
230 
231 	//! Helper. Creates the contents panel.
232 	wxPanel* CreateContentsPanel();
233 
234 	//! Helper. Loads the bookmarks for the currently opened CHM file.
235 	void LoadBookmarks();
236 
237 	//! Helper. Saves the bookmarks for the currently opened CHM file.
238 	void SaveBookmarks();
239 
240 	//! Helper. Saves exit information (size, history, etc.)
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
291