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__
20 #include <wx/window.h>
21 #include <wx/config.h>
22 #include <wx/splitter.h>
23 #include <wx/notebook.h>
24 #include <wx/listctrl.h>
25 #include <wx/html/htmlwin.h>
29 //--------------------------------------------------------------------------------
30 // helper classes & structs - please ignore 'em
31 //--------------------------------------------------------------------------------
35 class WXDLLEXPORT HtmlBookRecord
: public wxObject
42 HtmlBookRecord(const wxString
& basepath
, const wxString
& title
, const wxString
& start
) {m_BasePath
= basepath
; m_Title
= title
; m_Start
= start
;}
43 wxString
GetTitle() const {return m_Title
;}
44 wxString
GetStart() const {return m_Start
;}
45 wxString
GetBasePath() const {return m_BasePath
;}
49 #undef WXDLLEXPORTLOCAL
50 #define WXDLLEXPORTLOCAL WXDLLEXPORT
51 // ?? Don't know why - but Allen Van Sickel reported it to fix problems with DLL
52 WX_DECLARE_OBJARRAY(HtmlBookRecord
, HtmlBookRecArray
);
54 #undef WXDLLEXPORTLOCAL
55 #define WXDLLEXPORTLOCAL
64 HtmlBookRecord
*m_Book
;
70 //--------------------------------------------------------------------------------
71 // wxHtmlHelpController
72 // This class ensures dislaying help.
73 // See documentation for details on its philosophy.
76 // This class is not derived from wxHelpController and is not
77 // compatible with it!
78 //--------------------------------------------------------------------------------
81 class WXDLLEXPORT wxHtmlHelpController
: public wxEvtHandler
83 DECLARE_DYNAMIC_CLASS(wxHtmlHelpController
)
86 wxConfigBase
*m_Config
;
87 wxString m_ConfigRoot
;
88 // configuration file/registry used to store custom settings
89 wxString m_TitleFormat
;
90 // title of the help frame
94 wxHtmlWindow
*m_HtmlWin
;
95 wxSplitterWindow
*m_Splitter
;
96 wxNotebook
*m_NavigPan
;
97 wxTreeCtrl
*m_ContentsBox
;
98 wxImageList
*m_ContentsImageList
;
99 wxListBox
*m_IndexBox
;
100 wxTextCtrl
*m_SearchText
;
101 wxButton
*m_SearchButton
;
102 wxListBox
*m_SearchList
;
103 // ...pointers to parts of help window
110 // settings (window size, position, sash pos etc..)
112 HtmlBookRecArray m_BookRecords
;
113 // each book has one record in this array
114 HtmlContentsItem
* m_Contents
;
116 // list of all available books and pages.
117 HtmlContentsItem
* m_Index
;
119 // list of index items
122 wxHtmlHelpController();
123 ~wxHtmlHelpController();
125 void SetTitleFormat(const wxString
& format
) {m_TitleFormat
= format
;}
126 // Sets format of title of the frame. Must contain exactly one "%s"
127 // (for title of displayed HTML page)
129 void SetTempDir(const wxString
& path
);
130 // Sets directory where temporary files are stored.
131 // These temp files are index & contents file in binary (much faster to read)
132 // form. These files are NOT deleted on program's exit.
134 bool AddBook(const wxString
& book
, bool show_wait_msg
= FALSE
);
135 // Adds new book. 'book' is location of .htb file (stands for "html book").
136 // See documentation for details on its format.
138 // If show_wait_msg == true then message window with "loading book..." is displayed
140 void Display(const wxString
& x
);
141 // Displays page x. If not found it will offect the user a choice of searching
143 // Looking for the page runs in these steps:
144 // 1. try to locate file named x (if x is for example "doc/howto.htm")
145 // 2. try to open starting page of book x
146 // 3. try to find x in contents (if x is for example "How To ...")
147 // 4. try to find x in index (if x is for example "How To ...")
148 // 5. offer searching and if the user agree, run KeywordSearch
149 void Display(const int id
);
150 // Alternative version that works with numeric ID.
151 // (uses extension to MS format, <param name="ID" value=id>, see docs)
153 void DisplayContents();
154 // Displays help window and focuses contents.
157 // Displays help window and focuses index.
159 bool KeywordSearch(const wxString
& keyword
);
160 // Searches for keyword. Returns TRUE and display page if found, return
162 // Syntax of keyword is Altavista-like:
163 // * words are separated by spaces
164 // (but "\"hello world\"" is only one world "hello world")
165 // * word may be pretended by + or -
166 // (+ : page must contain the word ; - : page can't contain the word)
167 // * if there is no + or - before the word, + is default
169 void UseConfig(wxConfigBase
*config
, const wxString
& rootpath
= wxEmptyString
) {m_Config
= config
; m_ConfigRoot
= rootpath
;}
170 // Assigns config object to the controller. This config is then
171 // used in subsequent calls to Read/WriteCustomization of both help
172 // controller and it's wxHtmlWindow
174 void ReadCustomization(wxConfigBase
*cfg
, wxString path
= wxEmptyString
);
175 // saves custom settings into cfg config. it will use the path 'path'
176 // if given, otherwise it will save info into currently selected path.
177 // saved values : things set by SetFonts, SetBorders.
178 void WriteCustomization(wxConfigBase
*cfg
, wxString path
= wxEmptyString
);
182 virtual void CreateHelpWindow();
183 // Creates frame & html window and sets m_Frame and other variables;
184 // Do nothing if the window already exists
186 // Refreshes Contents and Index tabs
187 void CreateContents();
188 // Adds items to m_Contents tree control
190 // Adds items to m_IndexList
192 void LoadMSProject(HtmlBookRecord
*book
, wxFileSystem
& fsys
, const wxString
& indexfile
, const wxString
& contentsfile
, bool show_wait_msg
);
193 // Imports .hhp files (MS HTML Help Workshop)
194 void LoadCachedBook(HtmlBookRecord
*book
, wxInputStream
*f
);
196 void SaveCachedBook(HtmlBookRecord
*book
, wxOutputStream
*f
);
197 // Writes binary book
199 void OnToolbar(wxCommandEvent
& event
);
200 void OnContentsSel(wxTreeEvent
& event
);
201 void OnIndexSel(wxCommandEvent
& event
);
202 void OnSearchSel(wxCommandEvent
& event
);
203 void OnSearch(wxCommandEvent
& event
);
204 void OnCloseWindow(wxCloseEvent
& event
);
206 DECLARE_EVENT_TABLE()
211 #endif // __HTMLHELP_H__