]> git.saurik.com Git - wxWidgets.git/blob - include/wx/html/helpwnd.h
minor cleanup; add wxDocument::OnChangeFilename for coherence with wxView::OnChangefi...
[wxWidgets.git] / include / wx / html / helpwnd.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/html/helpwnd.h
3 // Purpose: wxHtmlHelpWindow
4 // Notes: Based on htmlhelp.cpp, implementing a monolithic
5 // HTML Help controller class, by Vaclav Slavik
6 // Author: Harm van der Heijden and Vaclav Slavik
7 // RCS-ID: $Id$
8 // Copyright: (c) Harm van der Heijden and Vaclav Slavik
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_HELPWND_H_
13 #define _WX_HELPWND_H_
14
15 #include "wx/defs.h"
16
17 #if wxUSE_WXHTML_HELP
18
19 #include "wx/helpbase.h"
20 #include "wx/html/helpdata.h"
21 #include "wx/window.h"
22 #include "wx/frame.h"
23 #include "wx/config.h"
24 #include "wx/splitter.h"
25 #include "wx/notebook.h"
26 #include "wx/listbox.h"
27 #include "wx/choice.h"
28 #include "wx/combobox.h"
29 #include "wx/checkbox.h"
30 #include "wx/stattext.h"
31 #include "wx/hash.h"
32 #include "wx/html/htmlwin.h"
33 #include "wx/html/htmprint.h"
34
35 class WXDLLIMPEXP_FWD_CORE wxButton;
36 class WXDLLIMPEXP_FWD_CORE wxTextCtrl;
37 class WXDLLIMPEXP_FWD_CORE wxTreeEvent;
38 class WXDLLIMPEXP_FWD_CORE wxTreeCtrl;
39
40 // style flags for the Help Frame
41 #define wxHF_TOOLBAR 0x0001
42 #define wxHF_CONTENTS 0x0002
43 #define wxHF_INDEX 0x0004
44 #define wxHF_SEARCH 0x0008
45 #define wxHF_BOOKMARKS 0x0010
46 #define wxHF_OPEN_FILES 0x0020
47 #define wxHF_PRINT 0x0040
48 #define wxHF_FLAT_TOOLBAR 0x0080
49 #define wxHF_MERGE_BOOKS 0x0100
50 #define wxHF_ICONS_BOOK 0x0200
51 #define wxHF_ICONS_BOOK_CHAPTER 0x0400
52 #define wxHF_ICONS_FOLDER 0x0000 // this is 0 since it is default
53 #define wxHF_DEFAULT_STYLE (wxHF_TOOLBAR | wxHF_CONTENTS | \
54 wxHF_INDEX | wxHF_SEARCH | \
55 wxHF_BOOKMARKS | wxHF_PRINT)
56 //compatibility:
57 #define wxHF_OPENFILES wxHF_OPEN_FILES
58 #define wxHF_FLATTOOLBAR wxHF_FLAT_TOOLBAR
59 #define wxHF_DEFAULTSTYLE wxHF_DEFAULT_STYLE
60
61 struct wxHtmlHelpFrameCfg
62 {
63 int x, y, w, h;
64 long sashpos;
65 bool navig_on;
66 };
67
68 struct wxHtmlHelpMergedIndexItem;
69 class wxHtmlHelpMergedIndex;
70
71 class WXDLLIMPEXP_FWD_CORE wxHelpControllerBase;
72 class WXDLLIMPEXP_FWD_HTML wxHtmlHelpController;
73
74 /*!
75 * Help window
76 */
77
78 class WXDLLIMPEXP_HTML wxHtmlHelpWindow : public wxWindow
79 {
80 DECLARE_DYNAMIC_CLASS(wxHtmlHelpWindow)
81
82 public:
83 wxHtmlHelpWindow(wxHtmlHelpData* data = NULL) { Init(data); }
84 wxHtmlHelpWindow(wxWindow* parent, wxWindowID wxWindowID,
85 const wxPoint& pos = wxDefaultPosition,
86 const wxSize& size = wxDefaultSize,
87 int style = wxTAB_TRAVERSAL|wxNO_BORDER,
88 int helpStyle = wxHF_DEFAULT_STYLE,
89 wxHtmlHelpData* data = NULL);
90 bool Create(wxWindow* parent, wxWindowID id,
91 const wxPoint& pos = wxDefaultPosition,
92 const wxSize& size = wxDefaultSize,
93 int style = wxTAB_TRAVERSAL|wxNO_BORDER,
94 int helpStyle = wxHF_DEFAULT_STYLE);
95 virtual ~wxHtmlHelpWindow();
96
97 wxHtmlHelpData* GetData() { return m_Data; }
98 wxHtmlHelpController* GetController() const { return m_helpController; }
99 void SetController(wxHtmlHelpController* controller);
100
101 // Displays page x. If not found it will offect the user a choice of
102 // searching books.
103 // Looking for the page runs in these steps:
104 // 1. try to locate file named x (if x is for example "doc/howto.htm")
105 // 2. try to open starting page of book x
106 // 3. try to find x in contents (if x is for example "How To ...")
107 // 4. try to find x in index (if x is for example "How To ...")
108 bool Display(const wxString& x);
109
110 // Alternative version that works with numeric ID.
111 // (uses extension to MS format, <param name="ID" value=id>, see docs)
112 bool Display(const int id);
113
114 // Displays help window and focuses contents.
115 bool DisplayContents();
116
117 // Displays help window and focuses index.
118 bool DisplayIndex();
119
120 // Searches for keyword. Returns true and display page if found, return
121 // false otherwise
122 // Syntax of keyword is Altavista-like:
123 // * words are separated by spaces
124 // (but "\"hello world\"" is only one world "hello world")
125 // * word may be pretended by + or -
126 // (+ : page must contain the word ; - : page can't contain the word)
127 // * if there is no + or - before the word, + is default
128 bool KeywordSearch(const wxString& keyword,
129 wxHelpSearchMode mode = wxHELP_SEARCH_ALL);
130
131 void UseConfig(wxConfigBase *config, const wxString& rootpath = wxEmptyString)
132 {
133 m_Config = config;
134 m_ConfigRoot = rootpath;
135 ReadCustomization(config, rootpath);
136 }
137
138 // Saves custom settings into cfg config. it will use the path 'path'
139 // if given, otherwise it will save info into currently selected path.
140 // saved values : things set by SetFonts, SetBorders.
141 void ReadCustomization(wxConfigBase *cfg, const wxString& path = wxEmptyString);
142 void WriteCustomization(wxConfigBase *cfg, const wxString& path = wxEmptyString);
143
144 // call this to let wxHtmlHelpWindow know page changed
145 void NotifyPageChanged();
146
147 // Refreshes Contents and Index tabs
148 void RefreshLists();
149
150 // Gets the HTML window
151 wxHtmlWindow* GetHtmlWindow() const { return m_HtmlWin; }
152
153 // Gets the splitter window
154 wxSplitterWindow* GetSplitterWindow() const { return m_Splitter; }
155
156 // Gets the toolbar
157 wxToolBar* GetToolBar() const { return m_toolBar; }
158
159 // Gets the configuration data
160 wxHtmlHelpFrameCfg& GetCfgData() { return m_Cfg; }
161
162 // Gets the tree control
163 wxTreeCtrl *GetTreeCtrl() const { return m_ContentsBox; }
164
165 protected:
166 void Init(wxHtmlHelpData* data = NULL);
167
168 // Adds items to m_Contents tree control
169 void CreateContents();
170
171 // Adds items to m_IndexList
172 void CreateIndex();
173
174 // Add books to search choice panel
175 void CreateSearch();
176
177 // Updates "merged index" structure that combines indexes of all books
178 // into better searchable structure
179 void UpdateMergedIndex();
180
181 // Add custom buttons to toolbar
182 virtual void AddToolbarButtons(wxToolBar *toolBar, int style);
183
184 // Displays options dialog (fonts etc.)
185 virtual void OptionsDialog();
186
187 void OnToolbar(wxCommandEvent& event);
188 void OnContentsSel(wxTreeEvent& event);
189 void OnIndexSel(wxCommandEvent& event);
190 void OnIndexFind(wxCommandEvent& event);
191 void OnIndexAll(wxCommandEvent& event);
192 void OnSearchSel(wxCommandEvent& event);
193 void OnSearch(wxCommandEvent& event);
194 void OnBookmarksSel(wxCommandEvent& event);
195 void OnSize(wxSizeEvent& event);
196
197 // Images:
198 enum {
199 IMG_Book = 0,
200 IMG_Folder,
201 IMG_Page
202 };
203
204 protected:
205 wxHtmlHelpData* m_Data;
206 bool m_DataCreated; // m_Data created by frame, or supplied?
207 wxString m_TitleFormat; // title of the help frame
208 // below are various pointers to GUI components
209 wxHtmlWindow *m_HtmlWin;
210 wxSplitterWindow *m_Splitter;
211 wxPanel *m_NavigPan;
212 wxNotebook *m_NavigNotebook;
213 wxTreeCtrl *m_ContentsBox;
214 wxTextCtrl *m_IndexText;
215 wxButton *m_IndexButton;
216 wxButton *m_IndexButtonAll;
217 wxListBox *m_IndexList;
218 wxTextCtrl *m_SearchText;
219 wxButton *m_SearchButton;
220 wxListBox *m_SearchList;
221 wxChoice *m_SearchChoice;
222 wxStaticText *m_IndexCountInfo;
223 wxCheckBox *m_SearchCaseSensitive;
224 wxCheckBox *m_SearchWholeWords;
225 wxToolBar* m_toolBar;
226
227 wxComboBox *m_Bookmarks;
228 wxArrayString m_BookmarksNames, m_BookmarksPages;
229
230 wxHtmlHelpFrameCfg m_Cfg;
231
232 wxConfigBase *m_Config;
233 wxString m_ConfigRoot;
234
235 // pagenumbers of controls in notebook (usually 0,1,2)
236 int m_ContentsPage;
237 int m_IndexPage;
238 int m_SearchPage;
239
240 // lists of available fonts (used in options dialog)
241 wxArrayString *m_NormalFonts, *m_FixedFonts;
242 int m_FontSize; // 0,1,2 = small,medium,big
243 wxString m_NormalFace, m_FixedFace;
244
245 bool m_UpdateContents;
246
247 #if wxUSE_PRINTING_ARCHITECTURE
248 wxHtmlEasyPrinting *m_Printer;
249 #endif
250 wxHashTable *m_PagesHash;
251 wxHtmlHelpController* m_helpController;
252
253 int m_hfStyle;
254
255 private:
256 void DoIndexFind();
257 void DoIndexAll();
258 void DisplayIndexItem(const wxHtmlHelpMergedIndexItem *it);
259 wxHtmlHelpMergedIndex *m_mergedIndex;
260
261 DECLARE_EVENT_TABLE()
262 DECLARE_NO_COPY_CLASS(wxHtmlHelpWindow)
263 };
264
265 /*!
266 * Command IDs
267 */
268
269 enum
270 {
271 //wxID_HTML_HELPFRAME = wxID_HIGHEST + 1,
272 wxID_HTML_PANEL = wxID_HIGHEST + 2,
273 wxID_HTML_BACK,
274 wxID_HTML_FORWARD,
275 wxID_HTML_UPNODE,
276 wxID_HTML_UP,
277 wxID_HTML_DOWN,
278 wxID_HTML_PRINT,
279 wxID_HTML_OPENFILE,
280 wxID_HTML_OPTIONS,
281 wxID_HTML_BOOKMARKSLIST,
282 wxID_HTML_BOOKMARKSADD,
283 wxID_HTML_BOOKMARKSREMOVE,
284 wxID_HTML_TREECTRL,
285 wxID_HTML_INDEXPAGE,
286 wxID_HTML_INDEXLIST,
287 wxID_HTML_INDEXTEXT,
288 wxID_HTML_INDEXBUTTON,
289 wxID_HTML_INDEXBUTTONALL,
290 wxID_HTML_NOTEBOOK,
291 wxID_HTML_SEARCHPAGE,
292 wxID_HTML_SEARCHTEXT,
293 wxID_HTML_SEARCHLIST,
294 wxID_HTML_SEARCHBUTTON,
295 wxID_HTML_SEARCHCHOICE,
296 wxID_HTML_COUNTINFO
297 };
298
299 #endif // wxUSE_WXHTML_HELP
300
301 #endif