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