New HTML help system. The old controller class has been split in
[wxWidgets.git] / include / wx / html / helpfrm.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: helpfrm.h
3 // Purpose: wxHtmlHelpFrame
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 // Created:
8 // RCS-ID:
9 // Copyright: (c) Harm van der Heijden and Vaclav Slavik
10 // Licence: wxWindows licence
11 /////////////////////////////////////////////////////////////////////////////
12
13 #ifndef _WX_HELPFRM_H_
14 #define _WX_HELPFRM_H_
15
16 #ifdef __GNUG__
17 #pragma interface "helpfrm.h"
18 #endif
19
20 #include "wx/defs.h"
21
22 #if wxUSE_HTML
23
24 #include "helpdata.h"
25 #include "wx/window.h"
26 #include "wx/frame.h"
27 #include "wx/config.h"
28 #include "wx/splitter.h"
29 #include "wx/notebook.h"
30 #include "wx/listbox.h"
31 #include "wx/choice.h"
32 #include "wx/html/htmlwin.h"
33
34 // style flags for the Help Frame
35 const int wxHF_TOOLBAR = 1;
36 const int wxHF_CONTENTS = 2;
37 const int wxHF_INDEX = 4;
38 const int wxHF_SEARCH = 8;
39 const int wxHF_DEFAULTSTYLE = -1;
40
41 // Command IDs :
42 enum {
43 wxID_HTML_PANEL = wxID_HIGHEST + 1,
44 wxID_HTML_BACK,
45 wxID_HTML_FORWARD,
46 wxID_HTML_TREECTRL,
47 wxID_HTML_INDEXPAGE,
48 wxID_HTML_INDEXLIST,
49 wxID_HTML_NOTEBOOK,
50 wxID_HTML_SEARCHPAGE,
51 wxID_HTML_SEARCHTEXT,
52 wxID_HTML_SEARCHLIST,
53 wxID_HTML_SEARCHBUTTON,
54 wxID_HTML_SEARCHCHOICE,
55 wxID_HTML_HELPFRAME // the id of wxHtmlHelpController's helpframe
56 };
57
58 class WXDLLEXPORT wxHtmlHelpFrame : public wxFrame
59 {
60 DECLARE_DYNAMIC_CLASS(wxHtmlHelpFrame)
61
62 public:
63 wxHtmlHelpFrame(wxHtmlHelpData* data = NULL) { Init(data); }
64 wxHtmlHelpFrame(wxWindow* parent, int wxWindowID,
65 const wxString& title = wxEmptyString,
66 int style = wxHF_DEFAULTSTYLE, wxHtmlHelpData* data = NULL);
67 bool Create(wxWindow* parent, wxWindowID id, const wxString& title = wxEmptyString,
68 int style = wxHF_DEFAULTSTYLE);
69 ~wxHtmlHelpFrame();
70
71 wxHtmlHelpData* GetData() { return m_Data; }
72
73 void SetTitleFormat(const wxString& format) {
74 if (m_HtmlWin)
75 m_HtmlWin->SetRelatedFrame(this, format);
76 m_TitleFormat = format;
77 }
78 // Sets format of title of the frame. Must contain exactly one "%s"
79 // (for title of displayed HTML page)
80
81 bool Display(const wxString& x);
82 // Displays page x. If not found it will offect the user a choice of
83 // searching books.
84 // Looking for the page runs in these steps:
85 // 1. try to locate file named x (if x is for example "doc/howto.htm")
86 // 2. try to open starting page of book x
87 // 3. try to find x in contents (if x is for example "How To ...")
88 // 4. try to find x in index (if x is for example "How To ...")
89 bool Display(const int id);
90 // Alternative version that works with numeric ID.
91 // (uses extension to MS format, <param name="ID" value=id>, see docs)
92
93 bool DisplayContents();
94 // Displays help window and focuses contents.
95
96 bool DisplayIndex();
97 // Displays help window and focuses index.
98
99 bool KeywordSearch(const wxString& keyword);
100 // Searches for keyword. Returns TRUE and display page if found, return
101 // FALSE otherwise
102 // Syntax of keyword is Altavista-like:
103 // * words are separated by spaces
104 // (but "\"hello world\"" is only one world "hello world")
105 // * word may be pretended by + or -
106 // (+ : page must contain the word ; - : page can't contain the word)
107 // * if there is no + or - before the word, + is default
108 void RefreshLists(bool show_progress = FALSE);
109 // Refreshes Contents and Index tabs
110 void CreateContents(bool show_progress = FALSE);
111 // Adds items to m_Contents tree control
112 void CreateIndex(bool show_progress = FALSE);
113 // Adds items to m_IndexList
114 void CreateSearch();
115 // Add books to search choice panel
116 void UseConfig(wxConfigBase *config, const wxString& rootpath = wxEmptyString) {
117 m_Config = config; m_ConfigRoot = rootpath;
118 ReadCustomization(config, rootpath);
119 }
120 void ReadCustomization(wxConfigBase *cfg, const wxString& path = wxEmptyString);
121 // saves custom settings into cfg config. it will use the path 'path'
122 // if given, otherwise it will save info into currently selected path.
123 // saved values : things set by SetFonts, SetBorders.
124 void WriteCustomization(wxConfigBase *cfg, const wxString& path = wxEmptyString);
125 // ...
126 void OnToolbar(wxCommandEvent& event);
127 void OnContentsSel(wxTreeEvent& event);
128 void OnIndexSel(wxCommandEvent& event);
129 void OnSearchSel(wxCommandEvent& event);
130 void OnSearch(wxCommandEvent& event);
131 void OnCloseWindow(wxCloseEvent& event);
132
133 // Images:
134 enum {
135 IMG_Book = 0,
136 IMG_Folder,
137 IMG_Page
138 };
139
140 protected:
141 wxHtmlHelpData* m_Data;
142 bool m_DataCreated; // m_Data created by frame, or supplied?
143 wxString m_TitleFormat; // title of the help frame
144 // below are various pointers to GUI components
145 wxHtmlWindow *m_HtmlWin;
146 wxSplitterWindow *m_Splitter;
147 wxNotebook *m_NavigPan;
148 wxTreeCtrl *m_ContentsBox;
149 wxImageList *m_ContentsImageList;
150 wxListBox *m_IndexBox;
151 wxTextCtrl *m_SearchText;
152 wxButton *m_SearchButton;
153 wxListBox *m_SearchList;
154 wxChoice *m_SearchChoice;
155
156 struct {
157 long x, y, w, h;
158 long sashpos;
159 bool navig_on;
160 int style; // flags given to wxHtmlHelpFrame ctor
161 wxString titleformat;
162 } m_Cfg;
163 // settings (window size, position, sash pos etc..)
164 wxConfigBase *m_Config;
165 wxString m_ConfigRoot;
166
167 // pagenumbers of controls in notebook (usually 0,1,2)
168 int m_ContentsPage;
169 int m_IndexPage;
170 int m_SearchPage;
171
172 protected:
173 void Init(wxHtmlHelpData* data = NULL);
174
175 DECLARE_EVENT_TABLE()
176 };
177
178 #endif
179
180 #endif