1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxHelpController demo
4 // Author: Karsten Ballueder
8 // Copyright: (c) Karsten Ballueder, Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 // For compilers that support precompilation, includes "wx/wx.h".
21 #include "wx/wxprec.h"
27 // for all others, include the necessary headers (this file is usually all you
28 // need because it includes almost all "standard" wxWindows headers
33 # include "wx/image.h"
36 // define this to 1 to use HTML help even under Windows (by default, Windows
37 // version will use WinHelp).
38 // Please also see samples/html/helpview.
40 #define USE_HTML_HELP 1
44 #define USE_HTML_HELP 0
49 #include <wx/filesys.h>
50 #include <wx/fs_zip.h>
52 #include "wx/generic/helpwxht.h"
53 #include "wx/html/helpctrl.h"
56 // ----------------------------------------------------------------------------
58 // ----------------------------------------------------------------------------
59 // the application icon
60 #if defined(__WXGTK__) || defined(__WXMOTIF__)
61 #include "mondrian.xpm"
64 // ----------------------------------------------------------------------------
66 // ----------------------------------------------------------------------------
68 // Define a new application type, each program should derive a class from wxApp
69 class MyApp
: public wxApp
72 // override base class virtuals
73 // ----------------------------
75 // this one is called on application startup and is a good place for the app
76 // initialization (doing it here and not in the ctor allows to have an error
77 // return: if OnInit() returns false, the application terminates)
78 virtual bool OnInit();
81 // Define a new frame type: this is going to be our main frame
82 class MyFrame
: public wxFrame
86 MyFrame(const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
);
88 wxHelpController
& GetHelpController() { return m_help
; }
91 wxHelpControllerHtml
& GetHtmlHelpController() { return m_htmlHelp
; }
92 wxHtmlHelpController
& GetAdvancedHtmlHelpController() { return m_advancedHtmlHelp
; }
95 // event handlers (these functions should _not_ be virtual)
96 void OnQuit(wxCommandEvent
& event
);
97 void OnHelp(wxCommandEvent
& event
);
98 void OnHtmlHelp(wxCommandEvent
& event
);
99 void OnAdvancedHtmlHelp(wxCommandEvent
& event
);
101 void ShowHelp(int commandId
, wxHelpControllerBase
& helpController
);
104 wxHelpController m_help
;
107 wxHelpControllerHtml m_htmlHelp
;
108 wxHtmlHelpController m_advancedHtmlHelp
;
111 // any class wishing to process wxWindows events must use this macro
112 DECLARE_EVENT_TABLE()
115 // ----------------------------------------------------------------------------
117 // ----------------------------------------------------------------------------
119 // IDs for the controls and the menu commands
125 HelpDemo_Help_Classes
,
126 HelpDemo_Help_Functions
,
128 HelpDemo_Help_Search
,
130 HelpDemo_Html_Help_Index
,
131 HelpDemo_Html_Help_Classes
,
132 HelpDemo_Html_Help_Functions
,
133 HelpDemo_Html_Help_Help
,
134 HelpDemo_Html_Help_Search
,
136 HelpDemo_Advanced_Html_Help_Index
,
137 HelpDemo_Advanced_Html_Help_Classes
,
138 HelpDemo_Advanced_Html_Help_Functions
,
139 HelpDemo_Advanced_Html_Help_Help
,
140 HelpDemo_Advanced_Html_Help_Search
,
144 HelpDemo_Help_Netscape
,
145 // controls start here (the numbers are, of course, arbitrary)
146 HelpDemo_Text
= 1000,
149 // ----------------------------------------------------------------------------
150 // event tables and other macros for wxWindows
151 // ----------------------------------------------------------------------------
153 // the event tables connect the wxWindows events with the functions (event
154 // handlers) which process them. It can be also done at run-time, but for the
155 // simple menu events like this the static method is much simpler.
156 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
157 EVT_MENU(HelpDemo_Quit
, MyFrame::OnQuit
)
158 EVT_MENU(HelpDemo_Help_Index
, MyFrame::OnHelp
)
159 EVT_MENU(HelpDemo_Help_Classes
, MyFrame::OnHelp
)
160 EVT_MENU(HelpDemo_Help_Functions
, MyFrame::OnHelp
)
161 EVT_MENU(HelpDemo_Help_Help
, MyFrame::OnHelp
)
162 EVT_MENU(HelpDemo_Help_Search
, MyFrame::OnHelp
)
164 EVT_MENU(HelpDemo_Html_Help_Index
, MyFrame::OnHtmlHelp
)
165 EVT_MENU(HelpDemo_Html_Help_Classes
, MyFrame::OnHtmlHelp
)
166 EVT_MENU(HelpDemo_Html_Help_Functions
, MyFrame::OnHtmlHelp
)
167 EVT_MENU(HelpDemo_Html_Help_Help
, MyFrame::OnHtmlHelp
)
168 EVT_MENU(HelpDemo_Html_Help_Search
, MyFrame::OnHtmlHelp
)
170 EVT_MENU(HelpDemo_Advanced_Html_Help_Index
, MyFrame::OnAdvancedHtmlHelp
)
171 EVT_MENU(HelpDemo_Advanced_Html_Help_Classes
, MyFrame::OnAdvancedHtmlHelp
)
172 EVT_MENU(HelpDemo_Advanced_Html_Help_Functions
, MyFrame::OnAdvancedHtmlHelp
)
173 EVT_MENU(HelpDemo_Advanced_Html_Help_Help
, MyFrame::OnAdvancedHtmlHelp
)
174 EVT_MENU(HelpDemo_Advanced_Html_Help_Search
, MyFrame::OnAdvancedHtmlHelp
)
176 EVT_MENU(HelpDemo_Help_KDE
, MyFrame::OnHelp
)
177 EVT_MENU(HelpDemo_Help_GNOME
, MyFrame::OnHelp
)
178 EVT_MENU(HelpDemo_Help_Netscape
, MyFrame::OnHelp
)
181 // Create a new application object: this macro will allow wxWindows to create
182 // the application object during program execution (it's better than using a
183 // static object for many reasons) and also declares the accessor function
184 // wxGetApp() which will return the reference of the right type (i.e. MyApp and
188 // ============================================================================
190 // ============================================================================
192 // ----------------------------------------------------------------------------
193 // the application class
194 // ----------------------------------------------------------------------------
196 // `Main program' equivalent: the program execution "starts" here
201 // Required for images in the online documentation
202 wxImage::AddHandler(new wxGIFHandler
);
204 // Required for advanced HTML help
205 #if wxUSE_STREAMS && wxUSE_ZIPSTREAM && wxUSE_ZLIB
206 wxFileSystem::AddHandler(new wxZipFSHandler
);
212 // Create the main application window
213 MyFrame
*frame
= new MyFrame("HelpDemo wxWindows App",
214 wxPoint(50, 50), wxSize(450, 340));
219 // initialise the help system: this means that we'll use doc.hlp file under
220 // Windows and that the HTML docs are in the subdirectory doc for platforms
222 if ( !frame
->GetHelpController().Initialize("doc") )
224 wxLogError("Cannot initialize the help system, aborting.");
230 // initialise the standard HTML help system: this means that the HTML docs are in the
231 // subdirectory doc for platforms using HTML help
232 if ( !frame
->GetHtmlHelpController().Initialize("doc") )
234 wxLogError("Cannot initialize the HTML help system, aborting.");
239 // initialise the advanced HTML help system: this means that the HTML docs are in .htb
241 if ( !frame
->GetAdvancedHtmlHelpController().Initialize("doc") )
243 wxLogError("Cannot initialize the advanced HTML help system, aborting.");
252 // ----------------------------------------------------------------------------
254 // ----------------------------------------------------------------------------
257 MyFrame::MyFrame(const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
)
258 : wxFrame((wxFrame
*)NULL
, -1, title
, pos
, size
)
260 // set the frame icon
261 SetIcon(wxICON(mondrian
));
264 wxMenu
*menuFile
= new wxMenu
;
266 menuFile
->Append(HelpDemo_Help_Index
, "&Help Index...");
267 menuFile
->Append(HelpDemo_Help_Classes
, "&Help on Classes...");
268 menuFile
->Append(HelpDemo_Help_Functions
, "&Help on Functions...");
269 menuFile
->Append(HelpDemo_Help_Help
, "&About Help Demo...");
270 menuFile
->Append(HelpDemo_Help_Search
, "&Search help...");
272 menuFile
->AppendSeparator();
273 menuFile
->Append(HelpDemo_Html_Help_Index
, "HTML &Help Index...");
274 menuFile
->Append(HelpDemo_Html_Help_Classes
, "HTML &Help on Classes...");
275 menuFile
->Append(HelpDemo_Html_Help_Functions
, "HTML &Help on Functions...");
276 menuFile
->Append(HelpDemo_Html_Help_Help
, "HTML &About Help Demo...");
277 menuFile
->Append(HelpDemo_Html_Help_Search
, "HTML &Search help...");
278 menuFile
->AppendSeparator();
279 menuFile
->Append(HelpDemo_Advanced_Html_Help_Index
, "Advanced HTML &Help Index...");
280 menuFile
->Append(HelpDemo_Advanced_Html_Help_Classes
, "Advanced HTML &Help on Classes...");
281 menuFile
->Append(HelpDemo_Advanced_Html_Help_Functions
, "Advanced HTML &Help on Functions...");
282 menuFile
->Append(HelpDemo_Advanced_Html_Help_Help
, "Advanced HTML &About Help Demo...");
283 menuFile
->Append(HelpDemo_Advanced_Html_Help_Search
, "Advanced HTML &Search help...");
288 menuFile
->AppendSeparator();
289 menuFile
->Append(HelpDemo_Help_KDE
, "Use &KDE");
290 menuFile
->Append(HelpDemo_Help_GNOME
, "Use &GNOME");
291 menuFile
->Append(HelpDemo_Help_Netscape
, "Use &Netscape");
294 menuFile
->AppendSeparator();
295 menuFile
->Append(HelpDemo_Quit
, "E&xit");
297 // now append the freshly created menu to the menu bar...
298 wxMenuBar
*menuBar
= new wxMenuBar
;
299 menuBar
->Append(menuFile
, "&File");
301 // ... and attach this menu bar to the frame
304 // create a status bar just for fun (by default with 1 pane only)
306 SetStatusText("Welcome to wxWindows!");
308 // now create some controls
310 // a panel first - if there were several controls, it would allow us to
311 // navigate between them from the keyboard
312 wxPanel
*panel
= new wxPanel(this, -1, wxPoint(0, 0), wxSize(400, 200));
314 // and a static control whose parent is the panel
315 (void)new wxStaticText(panel
, -1, "Hello, world!", wxPoint(10, 10));
321 void MyFrame::OnQuit(wxCommandEvent
& WXUNUSED(event
))
323 // TRUE is to force the frame to close
327 void MyFrame::OnHelp(wxCommandEvent
& event
)
329 ShowHelp(event
.GetId(), m_help
);
332 void MyFrame::OnHtmlHelp(wxCommandEvent
& event
)
335 ShowHelp(event
.GetId(), m_htmlHelp
);
339 void MyFrame::OnAdvancedHtmlHelp(wxCommandEvent
& event
)
342 ShowHelp(event
.GetId(), m_advancedHtmlHelp
);
346 void MyFrame::ShowHelp(int commandId
, wxHelpControllerBase
& helpController
)
351 // Note: For WinHelp, these ids are specified in the map session, mapping
352 // topic names to numbers.
353 // For HTML and external help, a wxhelp.map file is used.
355 case HelpDemo_Help_Classes
:
356 case HelpDemo_Html_Help_Classes
:
357 case HelpDemo_Advanced_Html_Help_Classes
:
358 helpController
.DisplaySection(2);
360 // if (helpController.IsKindOf(CLASSINFO(wxHtmlHelpController)))
361 // ((wxHtmlHelpController&)helpController).Display("Classes"); // An alternative form for this controller
364 case HelpDemo_Help_Functions
:
365 case HelpDemo_Html_Help_Functions
:
366 case HelpDemo_Advanced_Html_Help_Functions
:
367 helpController
.DisplaySection(1);
369 case HelpDemo_Help_Help
:
370 case HelpDemo_Html_Help_Help
:
371 case HelpDemo_Advanced_Html_Help_Help
:
372 helpController
.DisplaySection(3);
375 case HelpDemo_Help_Search
:
376 case HelpDemo_Html_Help_Search
:
377 case HelpDemo_Advanced_Html_Help_Search
:
379 wxString key
= wxGetTextFromUser("Search for?",
380 "Search help for keyword",
384 helpController
.KeywordSearch(key
);
388 case HelpDemo_Help_Index
:
389 case HelpDemo_Html_Help_Index
:
390 case HelpDemo_Advanced_Html_Help_Index
:
391 helpController
.DisplayContents();
394 // These three calls are only used by wxExtHelpController
396 case HelpDemo_Help_KDE
:
397 helpController
.SetViewer("kdehelp");
399 case HelpDemo_Help_GNOME
:
400 helpController
.SetViewer("gnome-help-browser");
402 case HelpDemo_Help_Netscape
:
403 helpController
.SetViewer("netscape", wxHELP_NETSCAPE
);