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_HELPWND_H_
13 #define _WX_HELPWND_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
;
77 class WXDLLIMPEXP_HTML wxHtmlHelpWindow
: public wxWindow
79 DECLARE_DYNAMIC_CLASS(wxHtmlHelpWindow
)
82 wxHtmlHelpWindow(wxHtmlHelpData
* data
= NULL
) { Init(data
); }
83 wxHtmlHelpWindow(wxWindow
* parent
, wxWindowID wxWindowID
,
84 const wxPoint
& pos
= wxDefaultPosition
,
85 const wxSize
& size
= wxDefaultSize
,
86 int style
= wxTAB_TRAVERSAL
|wxNO_BORDER
,
87 int helpStyle
= wxHF_DEFAULT_STYLE
,
88 wxHtmlHelpData
* data
= NULL
);
89 bool Create(wxWindow
* parent
, wxWindowID id
,
90 const wxPoint
& pos
= wxDefaultPosition
,
91 const wxSize
& size
= wxDefaultSize
,
92 int style
= wxTAB_TRAVERSAL
|wxNO_BORDER
,
93 int helpStyle
= wxHF_DEFAULT_STYLE
);
96 wxHtmlHelpData
* GetData() { return m_Data
; }
97 wxHtmlHelpController
* GetController() const { return m_helpController
; }
98 void SetController(wxHtmlHelpController
* controller
);
100 // Displays page x. If not found it will offect the user a choice of
102 // Looking for the page runs in these steps:
103 // 1. try to locate file named x (if x is for example "doc/howto.htm")
104 // 2. try to open starting page of book x
105 // 3. try to find x in contents (if x is for example "How To ...")
106 // 4. try to find x in index (if x is for example "How To ...")
107 bool Display(const wxString
& x
);
109 // Alternative version that works with numeric ID.
110 // (uses extension to MS format, <param name="ID" value=id>, see docs)
111 bool Display(const int id
);
113 // Displays help window and focuses contents.
114 bool DisplayContents();
116 // Displays help window and focuses index.
119 // Searches for keyword. Returns true and display page if found, return
121 // Syntax of keyword is Altavista-like:
122 // * words are separated by spaces
123 // (but "\"hello world\"" is only one world "hello world")
124 // * word may be pretended by + or -
125 // (+ : page must contain the word ; - : page can't contain the word)
126 // * if there is no + or - before the word, + is default
127 bool KeywordSearch(const wxString
& keyword
,
128 wxHelpSearchMode mode
= wxHELP_SEARCH_ALL
);
130 void UseConfig(wxConfigBase
*config
, const wxString
& rootpath
= wxEmptyString
)
133 m_ConfigRoot
= rootpath
;
134 ReadCustomization(config
, rootpath
);
137 // Saves custom settings into cfg config. it will use the path 'path'
138 // if given, otherwise it will save info into currently selected path.
139 // saved values : things set by SetFonts, SetBorders.
140 void ReadCustomization(wxConfigBase
*cfg
, const wxString
& path
= wxEmptyString
);
141 void WriteCustomization(wxConfigBase
*cfg
, const wxString
& path
= wxEmptyString
);
143 // call this to let wxHtmlHelpWindow know page changed
144 void NotifyPageChanged();
146 // Refreshes Contents and Index tabs
149 // Gets the HTML window
150 wxHtmlWindow
* GetHtmlWindow() const { return m_HtmlWin
; }
152 // Gets the splitter window
153 wxSplitterWindow
* GetSplitterWindow() const { return m_Splitter
; }
156 wxToolBar
* GetToolBar() const { return m_toolBar
; }
158 // Gets the configuration data
159 wxHtmlHelpFrameCfg
& GetCfgData() { return m_Cfg
; }
161 // Gets the tree control
162 wxTreeCtrl
*GetTreeCtrl() const { return m_ContentsBox
; }
165 void Init(wxHtmlHelpData
* data
= NULL
);
167 // Adds items to m_Contents tree control
168 void CreateContents();
170 // Adds items to m_IndexList
173 // Add books to search choice panel
176 // Updates "merged index" structure that combines indexes of all books
177 // into better searchable structure
178 void UpdateMergedIndex();
180 // Add custom buttons to toolbar
181 virtual void AddToolbarButtons(wxToolBar
*toolBar
, int style
);
183 // Displays options dialog (fonts etc.)
184 virtual void OptionsDialog();
186 void OnToolbar(wxCommandEvent
& event
);
187 void OnContentsSel(wxTreeEvent
& event
);
188 void OnIndexSel(wxCommandEvent
& event
);
189 void OnIndexFind(wxCommandEvent
& event
);
190 void OnIndexAll(wxCommandEvent
& event
);
191 void OnSearchSel(wxCommandEvent
& event
);
192 void OnSearch(wxCommandEvent
& event
);
193 void OnBookmarksSel(wxCommandEvent
& event
);
194 void OnSize(wxSizeEvent
& event
);
204 wxHtmlHelpData
* m_Data
;
205 bool m_DataCreated
; // m_Data created by frame, or supplied?
206 wxString m_TitleFormat
; // title of the help frame
207 // below are various pointers to GUI components
208 wxHtmlWindow
*m_HtmlWin
;
209 wxSplitterWindow
*m_Splitter
;
211 wxNotebook
*m_NavigNotebook
;
212 wxTreeCtrl
*m_ContentsBox
;
213 wxTextCtrl
*m_IndexText
;
214 wxButton
*m_IndexButton
;
215 wxButton
*m_IndexButtonAll
;
216 wxListBox
*m_IndexList
;
217 wxTextCtrl
*m_SearchText
;
218 wxButton
*m_SearchButton
;
219 wxListBox
*m_SearchList
;
220 wxChoice
*m_SearchChoice
;
221 wxStaticText
*m_IndexCountInfo
;
222 wxCheckBox
*m_SearchCaseSensitive
;
223 wxCheckBox
*m_SearchWholeWords
;
224 wxToolBar
* m_toolBar
;
226 wxComboBox
*m_Bookmarks
;
227 wxArrayString m_BookmarksNames
, m_BookmarksPages
;
229 wxHtmlHelpFrameCfg m_Cfg
;
231 wxConfigBase
*m_Config
;
232 wxString m_ConfigRoot
;
234 // pagenumbers of controls in notebook (usually 0,1,2)
239 // lists of available fonts (used in options dialog)
240 wxArrayString
*m_NormalFonts
, *m_FixedFonts
;
241 int m_FontSize
; // 0,1,2 = small,medium,big
242 wxString m_NormalFace
, m_FixedFace
;
244 bool m_UpdateContents
;
246 #if wxUSE_PRINTING_ARCHITECTURE
247 wxHtmlEasyPrinting
*m_Printer
;
249 wxHashTable
*m_PagesHash
;
250 wxHtmlHelpController
* m_helpController
;
255 void DisplayIndexItem(const wxHtmlHelpMergedIndexItem
*it
);
256 wxHtmlHelpMergedIndex
*m_mergedIndex
;
258 DECLARE_EVENT_TABLE()
259 DECLARE_NO_COPY_CLASS(wxHtmlHelpWindow
)
268 //wxID_HTML_HELPFRAME = wxID_HIGHEST + 1,
269 wxID_HTML_PANEL
= wxID_HIGHEST
+ 2,
278 wxID_HTML_BOOKMARKSLIST
,
279 wxID_HTML_BOOKMARKSADD
,
280 wxID_HTML_BOOKMARKSREMOVE
,
285 wxID_HTML_INDEXBUTTON
,
286 wxID_HTML_INDEXBUTTONALL
,
288 wxID_HTML_SEARCHPAGE
,
289 wxID_HTML_SEARCHTEXT
,
290 wxID_HTML_SEARCHLIST
,
291 wxID_HTML_SEARCHBUTTON
,
292 wxID_HTML_SEARCHCHOICE
,
300 class WXDLLIMPEXP_HTML wxHtmlWindowEvent
: public wxNotifyEvent
303 wxHtmlWindowEvent(wxEventType commandType
= wxEVT_NULL
, int id
= 0):
304 wxNotifyEvent(commandType
, id
)
309 void SetURL(const wxString
& url
) { m_url
= url
; }
310 const wxString
& GetURL() const { return m_url
; }
315 DECLARE_DYNAMIC_CLASS(wxHtmlWindowEvent
)
318 typedef void (wxEvtHandler::*wxHtmlWindowEventFunction
)(wxHtmlWindowEvent
&);
320 BEGIN_DECLARE_EVENT_TYPES()
321 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_HTML
,
322 wxEVT_COMMAND_HTMLWINDOW_URL_CLICKED
, 1000)
323 END_DECLARE_EVENT_TYPES()
325 #define EVT_HTMLWINDOW_URL_CLICKED(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_HTMLWINDOW_URL_CLICKED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxHtmlWindowEventFunction) & fn, (wxObject *) NULL ),
327 #endif // wxUSE_WXHTML_HELP