1 /////////////////////////////////////////////////////////////////////////////
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
8 // Copyright: (c) Harm van der Heijden and Vaclav Slavik
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_HELPWIN_H_
13 #define _WX_HELPWIN_H_
19 #include "wx/helpbase.h"
20 #include "wx/html/helpdata.h"
21 #include "wx/window.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"
34 class WXDLLIMPEXP_CORE wxButton
;
35 class WXDLLIMPEXP_CORE wxTextCtrl
;
36 class WXDLLIMPEXP_CORE wxTreeEvent
;
37 class WXDLLIMPEXP_CORE wxTreeCtrl
;
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)
56 #define wxHF_OPENFILES wxHF_OPEN_FILES
57 #define wxHF_FLATTOOLBAR wxHF_FLAT_TOOLBAR
58 #define wxHF_DEFAULTSTYLE wxHF_DEFAULT_STYLE
60 struct wxHtmlHelpFrameCfg
67 struct wxHtmlHelpMergedIndexItem
;
68 class wxHtmlHelpMergedIndex
;
70 class WXDLLIMPEXP_CORE wxHelpControllerBase
;
71 class WXDLLIMPEXP_HTML wxHtmlHelpController
;
73 class WXDLLIMPEXP_HTML wxHtmlHelpWindow
: public wxWindow
75 DECLARE_DYNAMIC_CLASS(wxHtmlHelpWindow
)
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
);
92 wxHtmlHelpData
* GetData() { return m_Data
; }
93 wxHtmlHelpController
* GetController() const { return m_helpController
; }
94 void SetController(wxHtmlHelpController
* controller
);
96 // Displays page x. If not found it will offect the user a choice of
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
);
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
);
109 // Displays help window and focuses contents.
110 bool DisplayContents();
112 // Displays help window and focuses index.
115 // Searches for keyword. Returns true and display page if found, return
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
);
126 void UseConfig(wxConfigBase
*config
, const wxString
& rootpath
= wxEmptyString
)
129 m_ConfigRoot
= rootpath
;
130 ReadCustomization(config
, rootpath
);
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
);
139 // call this to let wxHtmlHelpWindow know page changed
140 void NotifyPageChanged();
142 // Refreshes Contents and Index tabs
145 // Gets the HTML window
146 wxHtmlWindow
* GetHtmlWindow() const { return m_HtmlWin
; }
148 // Gets the splitter window
149 wxSplitterWindow
* GetSplitterWindow() const { return m_Splitter
; }
152 wxToolBar
* GetToolBar() const { return m_toolBar
; }
154 // Gets the configuration data
155 wxHtmlHelpFrameCfg
& GetCfgData() { return m_Cfg
; }
157 // Gets the tree control
158 wxTreeCtrl
*GetTreeCtrl() const { return m_ContentsBox
; }
161 void Init(wxHtmlHelpData
* data
= NULL
);
163 // Adds items to m_Contents tree control
164 void CreateContents();
166 // Adds items to m_IndexList
169 // Add books to search choice panel
172 // Updates "merged index" structure that combines indexes of all books
173 // into better searchable structure
174 void UpdateMergedIndex();
176 // Add custom buttons to toolbar
177 virtual void AddToolbarButtons(wxToolBar
*toolBar
, int style
);
179 // Displays options dialog (fonts etc.)
180 virtual void OptionsDialog();
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
);
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
;
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
;
222 wxComboBox
*m_Bookmarks
;
223 wxArrayString m_BookmarksNames
, m_BookmarksPages
;
225 wxHtmlHelpFrameCfg m_Cfg
;
227 wxConfigBase
*m_Config
;
228 wxString m_ConfigRoot
;
230 // pagenumbers of controls in notebook (usually 0,1,2)
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
;
240 bool m_UpdateContents
;
242 #if wxUSE_PRINTING_ARCHITECTURE
243 wxHtmlEasyPrinting
*m_Printer
;
245 wxHashTable
*m_PagesHash
;
246 wxHtmlHelpController
* m_helpController
;
251 void DisplayIndexItem(const wxHtmlHelpMergedIndexItem
*it
);
252 wxHtmlHelpMergedIndex
*m_mergedIndex
;
254 DECLARE_EVENT_TABLE()
255 DECLARE_NO_COPY_CLASS(wxHtmlHelpWindow
)
258 class WXDLLIMPEXP_HTML wxHtmlWindowEvent
: public wxNotifyEvent
261 wxHtmlWindowEvent(wxEventType commandType
= wxEVT_NULL
, int id
= 0):
262 wxNotifyEvent(commandType
, id
)
267 void SetURL(const wxString
& url
) { m_url
= url
; }
268 const wxString
& GetURL() const { return m_url
; }
273 DECLARE_DYNAMIC_CLASS(wxHtmlWindowEvent
);
276 typedef void (wxEvtHandler::*wxHtmlWindowEventFunction
)(wxHtmlWindowEvent
&);
278 BEGIN_DECLARE_EVENT_TYPES()
279 DECLARE_EVENT_TYPE(wxEVT_COMMAND_HTMLWINDOW_URL_CLICKED
, 1000)
280 END_DECLARE_EVENT_TYPES()
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 ),
284 #endif // wxUSE_WXHTML_HELP