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
42 // Use old-style HTML help if 1
43 #define USE_OLD_HTML_HELP 0
47 #define USE_HTML_HELP 0
51 #include <wx/filesys.h>
52 #include <wx/fs_zip.h>
55 #include "wx/generic/helpwxht.h"
58 #include "wx/html/helpctrl.h"
61 #if wxUSE_MS_HTML_HELP
62 #include "wx/msw/helpchm.h"
65 // ----------------------------------------------------------------------------
67 // ----------------------------------------------------------------------------
68 // the application icon
69 #if defined(__WXGTK__) || defined(__WXMOTIF__)
70 #include "mondrian.xpm"
73 // ----------------------------------------------------------------------------
75 // ----------------------------------------------------------------------------
77 // Define a new application type, each program should derive a class from wxApp
78 class MyApp
: public wxApp
81 // override base class virtuals
82 // ----------------------------
84 // this one is called on application startup and is a good place for the app
85 // initialization (doing it here and not in the ctor allows to have an error
86 // return: if OnInit() returns false, the application terminates)
87 virtual bool OnInit();
90 // Define a new frame type: this is going to be our main frame
91 class MyFrame
: public wxFrame
95 MyFrame(const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
);
97 wxHelpController
& GetHelpController() { return m_help
; }
100 #if USE_OLD_HTML_HELP
101 wxHelpControllerHtml
& GetHtmlHelpController() { return m_htmlHelp
; }
103 wxHtmlHelpController
& GetAdvancedHtmlHelpController() { return m_advancedHtmlHelp
; }
105 #if wxUSE_MS_HTML_HELP
106 wxCHMHelpController
& GetMSHtmlHelpController() { return m_msHtmlHelp
; }
109 // event handlers (these functions should _not_ be virtual)
110 void OnQuit(wxCommandEvent
& event
);
111 void OnHelp(wxCommandEvent
& event
);
112 void OnHtmlHelp(wxCommandEvent
& event
);
113 void OnAdvancedHtmlHelp(wxCommandEvent
& event
);
114 void OnMSHtmlHelp(wxCommandEvent
& event
);
116 void OnContextHelp(wxHelpEvent
& event
);
117 void OnShowContextHelp(wxCommandEvent
& event
);
119 void ShowHelp(int commandId
, wxHelpControllerBase
& helpController
);
122 wxHelpController m_help
;
125 #if USE_OLD_HTML_HELP
126 wxHelpControllerHtml m_htmlHelp
;
128 wxHtmlHelpController m_advancedHtmlHelp
;
131 #if wxUSE_MS_HTML_HELP
132 wxCHMHelpController m_msHtmlHelp
;
135 // any class wishing to process wxWindows events must use this macro
136 DECLARE_EVENT_TABLE()
139 // ----------------------------------------------------------------------------
141 // ----------------------------------------------------------------------------
143 // IDs for the controls and the menu commands
149 HelpDemo_Help_Classes
,
150 HelpDemo_Help_Functions
,
152 HelpDemo_Help_Search
,
153 HelpDemo_Help_ContextHelp
,
155 HelpDemo_Html_Help_Index
,
156 HelpDemo_Html_Help_Classes
,
157 HelpDemo_Html_Help_Functions
,
158 HelpDemo_Html_Help_Help
,
159 HelpDemo_Html_Help_Search
,
161 HelpDemo_Advanced_Html_Help_Index
,
162 HelpDemo_Advanced_Html_Help_Classes
,
163 HelpDemo_Advanced_Html_Help_Functions
,
164 HelpDemo_Advanced_Html_Help_Help
,
165 HelpDemo_Advanced_Html_Help_Search
,
167 HelpDemo_MS_Html_Help_Index
,
168 HelpDemo_MS_Html_Help_Classes
,
169 HelpDemo_MS_Html_Help_Functions
,
170 HelpDemo_MS_Html_Help_Help
,
171 HelpDemo_MS_Html_Help_Search
,
175 HelpDemo_Help_Netscape
,
176 // controls start here (the numbers are, of course, arbitrary)
177 HelpDemo_Text
= 1000,
180 // ----------------------------------------------------------------------------
181 // event tables and other macros for wxWindows
182 // ----------------------------------------------------------------------------
184 // the event tables connect the wxWindows events with the functions (event
185 // handlers) which process them. It can be also done at run-time, but for the
186 // simple menu events like this the static method is much simpler.
187 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
188 EVT_MENU(HelpDemo_Quit
, MyFrame::OnQuit
)
189 EVT_MENU(HelpDemo_Help_Index
, MyFrame::OnHelp
)
190 EVT_MENU(HelpDemo_Help_Classes
, MyFrame::OnHelp
)
191 EVT_MENU(HelpDemo_Help_Functions
, MyFrame::OnHelp
)
192 EVT_MENU(HelpDemo_Help_Help
, MyFrame::OnHelp
)
193 EVT_MENU(HelpDemo_Help_Search
, MyFrame::OnHelp
)
194 EVT_MENU(HelpDemo_Help_ContextHelp
, MyFrame::OnShowContextHelp
)
196 EVT_HELP(-1, MyFrame::OnContextHelp
)
198 EVT_MENU(HelpDemo_Html_Help_Index
, MyFrame::OnHtmlHelp
)
199 EVT_MENU(HelpDemo_Html_Help_Classes
, MyFrame::OnHtmlHelp
)
200 EVT_MENU(HelpDemo_Html_Help_Functions
, MyFrame::OnHtmlHelp
)
201 EVT_MENU(HelpDemo_Html_Help_Help
, MyFrame::OnHtmlHelp
)
202 EVT_MENU(HelpDemo_Html_Help_Search
, MyFrame::OnHtmlHelp
)
204 EVT_MENU(HelpDemo_Advanced_Html_Help_Index
, MyFrame::OnAdvancedHtmlHelp
)
205 EVT_MENU(HelpDemo_Advanced_Html_Help_Classes
, MyFrame::OnAdvancedHtmlHelp
)
206 EVT_MENU(HelpDemo_Advanced_Html_Help_Functions
, MyFrame::OnAdvancedHtmlHelp
)
207 EVT_MENU(HelpDemo_Advanced_Html_Help_Help
, MyFrame::OnAdvancedHtmlHelp
)
208 EVT_MENU(HelpDemo_Advanced_Html_Help_Search
, MyFrame::OnAdvancedHtmlHelp
)
210 EVT_MENU(HelpDemo_MS_Html_Help_Index
, MyFrame::OnMSHtmlHelp
)
211 EVT_MENU(HelpDemo_MS_Html_Help_Classes
, MyFrame::OnMSHtmlHelp
)
212 EVT_MENU(HelpDemo_MS_Html_Help_Functions
, MyFrame::OnMSHtmlHelp
)
213 EVT_MENU(HelpDemo_MS_Html_Help_Help
, MyFrame::OnMSHtmlHelp
)
214 EVT_MENU(HelpDemo_MS_Html_Help_Search
, MyFrame::OnMSHtmlHelp
)
216 EVT_MENU(HelpDemo_Help_KDE
, MyFrame::OnHelp
)
217 EVT_MENU(HelpDemo_Help_GNOME
, MyFrame::OnHelp
)
218 EVT_MENU(HelpDemo_Help_Netscape
, MyFrame::OnHelp
)
221 // Create a new application object: this macro will allow wxWindows to create
222 // the application object during program execution (it's better than using a
223 // static object for many reasons) and also declares the accessor function
224 // wxGetApp() which will return the reference of the right type (i.e. MyApp and
228 // ============================================================================
230 // ============================================================================
232 // ----------------------------------------------------------------------------
233 // the application class
234 // ----------------------------------------------------------------------------
236 // `Main program' equivalent: the program execution "starts" here
241 // Required for images in the online documentation
242 wxImage::AddHandler(new wxGIFHandler
);
244 // Required for advanced HTML help
245 #if wxUSE_STREAMS && wxUSE_ZIPSTREAM && wxUSE_ZLIB
246 wxFileSystem::AddHandler(new wxZipFSHandler
);
252 // Create the main application window
253 MyFrame
*frame
= new MyFrame("HelpDemo wxWindows App",
254 wxPoint(50, 50), wxSize(450, 340));
259 // initialise the help system: this means that we'll use doc.hlp file under
260 // Windows and that the HTML docs are in the subdirectory doc for platforms
262 if ( !frame
->GetHelpController().Initialize("doc") )
264 wxLogError("Cannot initialize the help system, aborting.");
270 // initialise the standard HTML help system: this means that the HTML docs are in the
271 // subdirectory doc for platforms using HTML help
272 #if USE_OLD_HTML_HELP
273 if ( !frame
->GetHtmlHelpController().Initialize("doc") )
275 wxLogError("Cannot initialize the HTML help system, aborting.");
281 // initialise the advanced HTML help system: this means that the HTML docs are in .htb
283 if ( !frame
->GetAdvancedHtmlHelpController().Initialize("doc") )
285 wxLogError("Cannot initialize the advanced HTML help system, aborting.");
291 #if wxUSE_MS_HTML_HELP
292 if ( !frame
->GetMSHtmlHelpController().Initialize("doc") )
294 wxLogError("Cannot initialize the MS HTML help system, aborting.");
303 // ----------------------------------------------------------------------------
305 // ----------------------------------------------------------------------------
308 MyFrame::MyFrame(const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
)
309 : wxFrame((wxFrame
*)NULL
, -1, title
, pos
, size
)
311 // set the frame icon
312 SetIcon(wxICON(mondrian
));
315 wxMenu
*menuFile
= new wxMenu
;
317 menuFile
->Append(HelpDemo_Help_Index
, "&Help Index...");
318 menuFile
->Append(HelpDemo_Help_Classes
, "&Help on Classes...");
319 menuFile
->Append(HelpDemo_Help_Functions
, "&Help on Functions...");
320 menuFile
->Append(HelpDemo_Help_ContextHelp
, "&Context Help...");
321 menuFile
->Append(HelpDemo_Help_Help
, "&About Help Demo...");
322 menuFile
->Append(HelpDemo_Help_Search
, "&Search help...");
324 #if USE_OLD_HTML_HELP
325 menuFile
->AppendSeparator();
326 menuFile
->Append(HelpDemo_Html_Help_Index
, "HTML &Help Index...");
327 menuFile
->Append(HelpDemo_Html_Help_Classes
, "HTML &Help on Classes...");
328 menuFile
->Append(HelpDemo_Html_Help_Functions
, "HTML &Help on Functions...");
329 menuFile
->Append(HelpDemo_Html_Help_Help
, "HTML &About Help Demo...");
330 menuFile
->Append(HelpDemo_Html_Help_Search
, "HTML &Search help...");
332 menuFile
->AppendSeparator();
333 menuFile
->Append(HelpDemo_Advanced_Html_Help_Index
, "Advanced HTML &Help Index...");
334 menuFile
->Append(HelpDemo_Advanced_Html_Help_Classes
, "Advanced HTML &Help on Classes...");
335 menuFile
->Append(HelpDemo_Advanced_Html_Help_Functions
, "Advanced HTML &Help on Functions...");
336 menuFile
->Append(HelpDemo_Advanced_Html_Help_Help
, "Advanced HTML &About Help Demo...");
337 menuFile
->Append(HelpDemo_Advanced_Html_Help_Search
, "Advanced HTML &Search help...");
340 #if wxUSE_MS_HTML_HELP
341 menuFile
->AppendSeparator();
342 menuFile
->Append(HelpDemo_MS_Html_Help_Index
, "MS HTML &Help Index...");
343 menuFile
->Append(HelpDemo_MS_Html_Help_Classes
, "MS HTML &Help on Classes...");
344 menuFile
->Append(HelpDemo_MS_Html_Help_Functions
, "MS HTML &Help on Functions...");
345 menuFile
->Append(HelpDemo_MS_Html_Help_Help
, "MS HTML &About Help Demo...");
346 menuFile
->Append(HelpDemo_MS_Html_Help_Search
, "MS HTML &Search help...");
351 menuFile
->AppendSeparator();
352 menuFile
->Append(HelpDemo_Help_KDE
, "Use &KDE");
353 menuFile
->Append(HelpDemo_Help_GNOME
, "Use &GNOME");
354 menuFile
->Append(HelpDemo_Help_Netscape
, "Use &Netscape");
357 menuFile
->AppendSeparator();
358 menuFile
->Append(HelpDemo_Quit
, "E&xit");
360 // now append the freshly created menu to the menu bar...
361 wxMenuBar
*menuBar
= new wxMenuBar
;
362 menuBar
->Append(menuFile
, "&File");
364 // ... and attach this menu bar to the frame
367 // create a status bar just for fun (by default with 1 pane only)
369 SetStatusText("Welcome to wxWindows!");
371 // now create some controls
373 // a panel first - if there were several controls, it would allow us to
374 // navigate between them from the keyboard
375 wxPanel
*panel
= new wxPanel(this, -1, wxPoint(0, 0), wxSize(400, 200));
377 // and a static control whose parent is the panel
378 (void)new wxStaticText(panel
, -1, "Hello, world!", wxPoint(10, 10));
384 void MyFrame::OnQuit(wxCommandEvent
& WXUNUSED(event
))
386 // TRUE is to force the frame to close
390 void MyFrame::OnHelp(wxCommandEvent
& event
)
392 ShowHelp(event
.GetId(), m_help
);
395 void MyFrame::OnShowContextHelp(wxCommandEvent
& event
)
397 // This starts context help mode, then the user
398 // clicks on a window to send a help message
399 wxContextHelp
contextHelp(this);
402 void MyFrame::OnContextHelp(wxHelpEvent
& event
)
404 // In a real app, if we didn't recognise this ID, we should call event.Skip()
406 msg
.Printf(wxT("We should now display help for window %d"), event
.GetId());
410 void MyFrame::OnHtmlHelp(wxCommandEvent
& event
)
412 #if USE_HTML_HELP && USE_OLD_HTML_HELP
413 ShowHelp(event
.GetId(), m_htmlHelp
);
417 void MyFrame::OnAdvancedHtmlHelp(wxCommandEvent
& event
)
420 ShowHelp(event
.GetId(), m_advancedHtmlHelp
);
424 void MyFrame::OnMSHtmlHelp(wxCommandEvent
& event
)
426 #if wxUSE_MS_HTML_HELP
427 ShowHelp(event
.GetId(), m_msHtmlHelp
);
432 Notes: ShowHelp uses section ids for displaying particular topics,
433 but you might want to use a unique keyword to display a topic, instead.
435 Section ids are specified as follows for the different formats.
439 The [MAP] section specifies the topic to integer id mapping, e.g.
447 The identifier name corresponds to the label used for that topic.
448 You could also put these in a .h file and #include it in both the MAP
449 section and your C++ source.
451 Note that Tex2RTF doesn't currently generate the MAP section automatically.
455 The [MAP] section specifies the HTML filename root to integer id mapping, e.g.
463 The identifier name corresponds to the HTML filename used for that topic.
464 You could also put these in a .h file and #include it in both the MAP
465 section and your C++ source.
467 Note that Tex2RTF doesn't currently generate the MAP section automatically.
469 Simple wxHTML Help and External HTML Help
471 A wxhelp.map file is used, for example:
473 0 wx.htm ; wxWindows: Help index; additional keywords like overview
474 1 wx204.htm ; wxWindows Function Reference
475 2 wx34.htm ; wxWindows Class Reference
477 Note that Tex2RTF doesn't currently generate the MAP section automatically.
481 An extension to the .hhc file format is used, specifying a new parameter
484 <OBJECT type="text/sitemap">
485 <param name="Local" value="doc2.htm#classes">
486 <param name="Name" value="Classes">
487 <param name="ID" value=2>
490 Again, this is not generated automatically by Tex2RTF, though it could
491 be added quite easily.
493 Unfortunately adding the ID parameters appears to interfere with MS HTML Help,
494 so you should not try to compile a .chm file from a .hhc file with
495 this extension, or the contents will be messed up.
498 void MyFrame::ShowHelp(int commandId
, wxHelpControllerBase
& helpController
)
502 case HelpDemo_Help_Classes
:
503 case HelpDemo_Html_Help_Classes
:
504 case HelpDemo_Advanced_Html_Help_Classes
:
505 case HelpDemo_MS_Html_Help_Classes
:
506 helpController
.DisplaySection(2);
507 //helpController.DisplaySection("Classes"); // An alternative form for most controllers
510 case HelpDemo_Help_Functions
:
511 case HelpDemo_Html_Help_Functions
:
512 case HelpDemo_Advanced_Html_Help_Functions
:
513 case HelpDemo_MS_Html_Help_Functions
:
514 helpController
.DisplaySection(1);
515 //helpController.DisplaySection("Functions"); // An alternative form for most controllers
517 case HelpDemo_Help_Help
:
518 case HelpDemo_Html_Help_Help
:
519 case HelpDemo_Advanced_Html_Help_Help
:
520 case HelpDemo_MS_Html_Help_Help
:
521 helpController
.DisplaySection(3);
522 //helpController.DisplaySection("About"); // An alternative form for most controllers
525 case HelpDemo_Help_Search
:
526 case HelpDemo_Html_Help_Search
:
527 case HelpDemo_Advanced_Html_Help_Search
:
528 case HelpDemo_MS_Html_Help_Search
:
530 wxString key
= wxGetTextFromUser("Search for?",
531 "Search help for keyword",
535 helpController
.KeywordSearch(key
);
539 case HelpDemo_Help_Index
:
540 case HelpDemo_Html_Help_Index
:
541 case HelpDemo_Advanced_Html_Help_Index
:
542 case HelpDemo_MS_Html_Help_Index
:
543 helpController
.DisplayContents();
546 // These three calls are only used by wxExtHelpController
548 case HelpDemo_Help_KDE
:
549 helpController
.SetViewer("kdehelp");
551 case HelpDemo_Help_GNOME
:
552 helpController
.SetViewer("gnome-help-browser");
554 case HelpDemo_Help_Netscape
:
555 helpController
.SetViewer("netscape", wxHELP_NETSCAPE
);