1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Help controller
4 // Author: Vaclav Slavik
5 // Copyright: (c) 1999 Vaclav Slavik
6 // Licence: wxWindows Licence
7 /////////////////////////////////////////////////////////////////////////////
10 #ifndef __HTMLHELP_H__
11 #define __HTMLHELP_H__
14 #pragma interface "htmlhelp.h"
21 #include "wx/window.h"
22 #include "wx/config.h"
23 #include "wx/splitter.h"
24 #include "wx/notebook.h"
25 #include "wx/listctrl.h"
26 #include "wx/html/htmlwin.h"
30 //--------------------------------------------------------------------------------
31 // helper classes & structs - please ignore 'em
32 //--------------------------------------------------------------------------------
36 class WXDLLEXPORT HtmlBookRecord
: public wxObject
43 HtmlBookRecord(const wxString
& basepath
, const wxString
& title
, const wxString
& start
) {m_BasePath
= basepath
; m_Title
= title
; m_Start
= start
;}
44 wxString
GetTitle() const {return m_Title
;}
45 wxString
GetStart() const {return m_Start
;}
46 wxString
GetBasePath() const {return m_BasePath
;}
50 #undef WXDLLEXPORTLOCAL
51 #define WXDLLEXPORTLOCAL WXDLLEXPORT
52 // ?? Don't know why - but Allen Van Sickel reported it to fix problems with DLL
53 WX_DECLARE_OBJARRAY(HtmlBookRecord
, HtmlBookRecArray
);
55 #undef WXDLLEXPORTLOCAL
56 #define WXDLLEXPORTLOCAL
65 HtmlBookRecord
*m_Book
;
69 //-----------------------------------------------------------------------------
71 //-----------------------------------------------------------------------------
77 wxID_HTML_PANEL
= wxID_HIGHEST
+ 1,
87 wxID_HTML_SEARCHBUTTON
91 //--------------------------------------------------------------------------------
92 // HtmlHelpTreeItemData
93 // Stores the location of a contents item in a tree item
94 //--------------------------------------------------------------------------------
96 class wxHtmlHelpTreeItemData
: public wxTreeItemData
102 wxHtmlHelpTreeItemData(HtmlContentsItem
*it
) : wxTreeItemData() {m_Page
= it
-> m_Book
-> GetBasePath() + it
-> m_Page
;}
103 const wxString
& GetPage() {return m_Page
;}
107 //--------------------------------------------------------------------------------
108 // wxHtmlHelpController
109 // This class ensures dislaying help.
110 // See documentation for details on its philosophy.
113 // This class is not derived from wxHelpController and is not
114 // compatible with it!
115 //--------------------------------------------------------------------------------
118 class WXDLLEXPORT wxHtmlHelpController
: public wxEvtHandler
120 DECLARE_DYNAMIC_CLASS(wxHtmlHelpController
)
123 wxConfigBase
*m_Config
;
124 wxString m_ConfigRoot
;
125 // configuration file/registry used to store custom settings
126 wxString m_TitleFormat
;
127 // title of the help frame
131 wxHtmlWindow
*m_HtmlWin
;
132 wxSplitterWindow
*m_Splitter
;
133 wxNotebook
*m_NavigPan
;
134 wxTreeCtrl
*m_ContentsBox
;
135 wxImageList
*m_ContentsImageList
;
136 wxListBox
*m_IndexBox
;
137 wxTextCtrl
*m_SearchText
;
138 wxButton
*m_SearchButton
;
139 wxListBox
*m_SearchList
;
140 // ...pointers to parts of help window
147 // settings (window size, position, sash pos etc..)
149 HtmlBookRecArray m_BookRecords
;
150 // each book has one record in this array
151 HtmlContentsItem
* m_Contents
;
153 // list of all available books and pages.
154 HtmlContentsItem
* m_Index
;
156 // list of index items
159 wxHtmlHelpController();
160 ~wxHtmlHelpController();
169 void SetTitleFormat(const wxString
& format
) {m_TitleFormat
= format
;}
170 // Sets format of title of the frame. Must contain exactly one "%s"
171 // (for title of displayed HTML page)
173 void SetTempDir(const wxString
& path
);
174 // Sets directory where temporary files are stored.
175 // These temp files are index & contents file in binary (much faster to read)
176 // form. These files are NOT deleted on program's exit.
178 bool AddBook(const wxString
& book
, bool show_wait_msg
= FALSE
);
179 // Adds new book. 'book' is location of .htb file (stands for "html book").
180 // See documentation for details on its format.
182 // If show_wait_msg == true then message window with "loading book..." is displayed
184 void Display(const wxString
& x
);
185 // Displays page x. If not found it will offect the user a choice of searching
187 // Looking for the page runs in these steps:
188 // 1. try to locate file named x (if x is for example "doc/howto.htm")
189 // 2. try to open starting page of book x
190 // 3. try to find x in contents (if x is for example "How To ...")
191 // 4. try to find x in index (if x is for example "How To ...")
192 // 5. offer searching and if the user agree, run KeywordSearch
193 void Display(const int id
);
194 // Alternative version that works with numeric ID.
195 // (uses extension to MS format, <param name="ID" value=id>, see docs)
197 void DisplayContents();
198 // Displays help window and focuses contents.
201 // Displays help window and focuses index.
203 bool KeywordSearch(const wxString
& keyword
);
204 // Searches for keyword. Returns TRUE and display page if found, return
206 // Syntax of keyword is Altavista-like:
207 // * words are separated by spaces
208 // (but "\"hello world\"" is only one world "hello world")
209 // * word may be pretended by + or -
210 // (+ : page must contain the word ; - : page can't contain the word)
211 // * if there is no + or - before the word, + is default
213 void UseConfig(wxConfigBase
*config
, const wxString
& rootpath
= wxEmptyString
) {m_Config
= config
; m_ConfigRoot
= rootpath
;}
214 // Assigns config object to the controller. This config is then
215 // used in subsequent calls to Read/WriteCustomization of both help
216 // controller and it's wxHtmlWindow
218 void ReadCustomization(wxConfigBase
*cfg
, wxString path
= wxEmptyString
);
219 // saves custom settings into cfg config. it will use the path 'path'
220 // if given, otherwise it will save info into currently selected path.
221 // saved values : things set by SetFonts, SetBorders.
222 void WriteCustomization(wxConfigBase
*cfg
, wxString path
= wxEmptyString
);
226 virtual void CreateHelpWindow();
227 // Creates frame & html window and sets m_Frame and other variables;
228 // Do nothing if the window already exists
230 // Refreshes Contents and Index tabs
231 void CreateContents();
232 // Adds items to m_Contents tree control
234 // Adds items to m_IndexList
236 void LoadMSProject(HtmlBookRecord
*book
, wxFileSystem
& fsys
, const wxString
& indexfile
, const wxString
& contentsfile
, bool show_wait_msg
);
237 // Imports .hhp files (MS HTML Help Workshop)
238 void LoadCachedBook(HtmlBookRecord
*book
, wxInputStream
*f
);
240 void SaveCachedBook(HtmlBookRecord
*book
, wxOutputStream
*f
);
241 // Writes binary book
243 void OnToolbar(wxCommandEvent
& event
);
244 void OnContentsSel(wxTreeEvent
& event
);
245 void OnIndexSel(wxCommandEvent
& event
);
246 void OnSearchSel(wxCommandEvent
& event
);
247 void OnSearch(wxCommandEvent
& event
);
248 void OnCloseWindow(wxCloseEvent
& event
);
250 DECLARE_EVENT_TABLE()
255 #endif // __HTMLHELP_H__