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"
35 # include "wx/cshelp.h"
38 # include "wx/tooltip.h"
41 // define this to 1 to use HTML help even under Windows (by default, Windows
42 // version will use WinHelp).
43 // Please also see samples/html/helpview.
45 #define USE_HTML_HELP 1
47 // Use old-style HTML help if 1
48 #define USE_OLD_HTML_HELP 0
52 #define USE_HTML_HELP 0
56 #include <wx/filesys.h>
57 #include <wx/fs_zip.h>
60 #include "wx/generic/helpwxht.h"
63 #include "wx/html/helpctrl.h"
66 #if wxUSE_MS_HTML_HELP
67 #include "wx/msw/helpchm.h"
70 // ----------------------------------------------------------------------------
72 // ----------------------------------------------------------------------------
73 // the application icon
74 #if defined(__WXGTK__) || defined(__WXMOTIF__)
75 #include "mondrian.xpm"
78 // ----------------------------------------------------------------------------
80 // ----------------------------------------------------------------------------
82 // Define a new application type, each program should derive a class from wxApp
83 class MyApp
: public wxApp
86 // override base class virtuals
87 // ----------------------------
89 // this one is called on application startup and is a good place for the app
90 // initialization (doing it here and not in the ctor allows to have an error
91 // return: if OnInit() returns false, the application terminates)
92 virtual bool OnInit();
95 // Define a new frame type: this is going to be our main frame
96 class MyFrame
: public wxFrame
100 MyFrame(const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
);
102 wxHelpController
& GetHelpController() { return m_help
; }
105 #if USE_OLD_HTML_HELP
106 wxHelpControllerHtml
& GetHtmlHelpController() { return m_htmlHelp
; }
108 wxHtmlHelpController
& GetAdvancedHtmlHelpController() { return m_advancedHtmlHelp
; }
110 #if wxUSE_MS_HTML_HELP
111 wxCHMHelpController
& GetMSHtmlHelpController() { return m_msHtmlHelp
; }
114 // event handlers (these functions should _not_ be virtual)
115 void OnQuit(wxCommandEvent
& event
);
116 void OnHelp(wxCommandEvent
& event
);
117 void OnHtmlHelp(wxCommandEvent
& event
);
118 void OnAdvancedHtmlHelp(wxCommandEvent
& event
);
119 void OnMSHtmlHelp(wxCommandEvent
& event
);
121 void OnContextHelp(wxHelpEvent
& event
);
122 void OnShowContextHelp(wxCommandEvent
& event
);
124 void ShowHelp(int commandId
, wxHelpControllerBase
& helpController
);
127 wxHelpController m_help
;
130 #if USE_OLD_HTML_HELP
131 wxHelpControllerHtml m_htmlHelp
;
133 wxHtmlHelpController m_advancedHtmlHelp
;
136 #if wxUSE_MS_HTML_HELP
137 wxCHMHelpController m_msHtmlHelp
;
140 // any class wishing to process wxWindows events must use this macro
141 DECLARE_EVENT_TABLE()
144 // ----------------------------------------------------------------------------
146 // ----------------------------------------------------------------------------
148 // IDs for the controls and the menu commands
154 HelpDemo_Help_Classes
,
155 HelpDemo_Help_Functions
,
157 HelpDemo_Help_Search
,
158 HelpDemo_Help_ContextHelp
,
160 HelpDemo_Html_Help_Index
,
161 HelpDemo_Html_Help_Classes
,
162 HelpDemo_Html_Help_Functions
,
163 HelpDemo_Html_Help_Help
,
164 HelpDemo_Html_Help_Search
,
166 HelpDemo_Advanced_Html_Help_Index
,
167 HelpDemo_Advanced_Html_Help_Classes
,
168 HelpDemo_Advanced_Html_Help_Functions
,
169 HelpDemo_Advanced_Html_Help_Help
,
170 HelpDemo_Advanced_Html_Help_Search
,
172 HelpDemo_MS_Html_Help_Index
,
173 HelpDemo_MS_Html_Help_Classes
,
174 HelpDemo_MS_Html_Help_Functions
,
175 HelpDemo_MS_Html_Help_Help
,
176 HelpDemo_MS_Html_Help_Search
,
180 HelpDemo_Help_Netscape
,
181 // controls start here (the numbers are, of course, arbitrary)
182 HelpDemo_Text
= 1000,
185 // ----------------------------------------------------------------------------
186 // event tables and other macros for wxWindows
187 // ----------------------------------------------------------------------------
189 // the event tables connect the wxWindows events with the functions (event
190 // handlers) which process them. It can be also done at run-time, but for the
191 // simple menu events like this the static method is much simpler.
192 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
193 EVT_MENU(HelpDemo_Quit
, MyFrame::OnQuit
)
194 EVT_MENU(HelpDemo_Help_Index
, MyFrame::OnHelp
)
195 EVT_MENU(HelpDemo_Help_Classes
, MyFrame::OnHelp
)
196 EVT_MENU(HelpDemo_Help_Functions
, MyFrame::OnHelp
)
197 EVT_MENU(HelpDemo_Help_Help
, MyFrame::OnHelp
)
198 EVT_MENU(HelpDemo_Help_Search
, MyFrame::OnHelp
)
199 EVT_MENU(HelpDemo_Help_ContextHelp
, MyFrame::OnShowContextHelp
)
201 EVT_HELP(-1, MyFrame::OnContextHelp
)
203 EVT_MENU(HelpDemo_Html_Help_Index
, MyFrame::OnHtmlHelp
)
204 EVT_MENU(HelpDemo_Html_Help_Classes
, MyFrame::OnHtmlHelp
)
205 EVT_MENU(HelpDemo_Html_Help_Functions
, MyFrame::OnHtmlHelp
)
206 EVT_MENU(HelpDemo_Html_Help_Help
, MyFrame::OnHtmlHelp
)
207 EVT_MENU(HelpDemo_Html_Help_Search
, MyFrame::OnHtmlHelp
)
209 EVT_MENU(HelpDemo_Advanced_Html_Help_Index
, MyFrame::OnAdvancedHtmlHelp
)
210 EVT_MENU(HelpDemo_Advanced_Html_Help_Classes
, MyFrame::OnAdvancedHtmlHelp
)
211 EVT_MENU(HelpDemo_Advanced_Html_Help_Functions
, MyFrame::OnAdvancedHtmlHelp
)
212 EVT_MENU(HelpDemo_Advanced_Html_Help_Help
, MyFrame::OnAdvancedHtmlHelp
)
213 EVT_MENU(HelpDemo_Advanced_Html_Help_Search
, MyFrame::OnAdvancedHtmlHelp
)
215 EVT_MENU(HelpDemo_MS_Html_Help_Index
, MyFrame::OnMSHtmlHelp
)
216 EVT_MENU(HelpDemo_MS_Html_Help_Classes
, MyFrame::OnMSHtmlHelp
)
217 EVT_MENU(HelpDemo_MS_Html_Help_Functions
, MyFrame::OnMSHtmlHelp
)
218 EVT_MENU(HelpDemo_MS_Html_Help_Help
, MyFrame::OnMSHtmlHelp
)
219 EVT_MENU(HelpDemo_MS_Html_Help_Search
, MyFrame::OnMSHtmlHelp
)
221 EVT_MENU(HelpDemo_Help_KDE
, MyFrame::OnHelp
)
222 EVT_MENU(HelpDemo_Help_GNOME
, MyFrame::OnHelp
)
223 EVT_MENU(HelpDemo_Help_Netscape
, MyFrame::OnHelp
)
226 // Create a new application object: this macro will allow wxWindows to create
227 // the application object during program execution (it's better than using a
228 // static object for many reasons) and also declares the accessor function
229 // wxGetApp() which will return the reference of the right type (i.e. MyApp and
233 // ============================================================================
235 // ============================================================================
237 // ----------------------------------------------------------------------------
238 // the application class
239 // ----------------------------------------------------------------------------
241 // `Main program' equivalent: the program execution "starts" here
246 // Required for images in the online documentation
247 wxImage::AddHandler(new wxGIFHandler
);
249 // Required for advanced HTML help
250 #if wxUSE_STREAMS && wxUSE_ZIPSTREAM && wxUSE_ZLIB
251 wxFileSystem::AddHandler(new wxZipFSHandler
);
257 // Create the main application window
258 MyFrame
*frame
= new MyFrame("HelpDemo wxWindows App",
259 wxPoint(50, 50), wxSize(450, 340));
264 // initialise the help system: this means that we'll use doc.hlp file under
265 // Windows and that the HTML docs are in the subdirectory doc for platforms
267 if ( !frame
->GetHelpController().Initialize("doc") )
269 wxLogError("Cannot initialize the help system, aborting.");
275 // initialise the standard HTML help system: this means that the HTML docs are in the
276 // subdirectory doc for platforms using HTML help
277 #if USE_OLD_HTML_HELP
278 if ( !frame
->GetHtmlHelpController().Initialize("doc") )
280 wxLogError("Cannot initialize the HTML help system, aborting.");
286 // initialise the advanced HTML help system: this means that the HTML docs are in .htb
288 if ( !frame
->GetAdvancedHtmlHelpController().Initialize("doc") )
290 wxLogError("Cannot initialize the advanced HTML help system, aborting.");
296 #if wxUSE_MS_HTML_HELP
297 if ( !frame
->GetMSHtmlHelpController().Initialize("doc") )
299 wxLogError("Cannot initialize the MS HTML help system, aborting.");
308 // ----------------------------------------------------------------------------
310 // ----------------------------------------------------------------------------
313 MyFrame::MyFrame(const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
)
314 : wxFrame((wxFrame
*)NULL
, -1, title
, pos
, size
)
316 // set the frame icon
317 SetIcon(wxICON(mondrian
));
320 wxMenu
*menuFile
= new wxMenu
;
322 menuFile
->Append(HelpDemo_Help_Index
, "&Help Index...");
323 menuFile
->Append(HelpDemo_Help_Classes
, "&Help on Classes...");
324 menuFile
->Append(HelpDemo_Help_Functions
, "&Help on Functions...");
325 menuFile
->Append(HelpDemo_Help_ContextHelp
, "&Context Help...");
326 menuFile
->Append(HelpDemo_Help_Help
, "&About Help Demo...");
327 menuFile
->Append(HelpDemo_Help_Search
, "&Search help...");
329 #if USE_OLD_HTML_HELP
330 menuFile
->AppendSeparator();
331 menuFile
->Append(HelpDemo_Html_Help_Index
, "HTML &Help Index...");
332 menuFile
->Append(HelpDemo_Html_Help_Classes
, "HTML &Help on Classes...");
333 menuFile
->Append(HelpDemo_Html_Help_Functions
, "HTML &Help on Functions...");
334 menuFile
->Append(HelpDemo_Html_Help_Help
, "HTML &About Help Demo...");
335 menuFile
->Append(HelpDemo_Html_Help_Search
, "HTML &Search help...");
337 menuFile
->AppendSeparator();
338 menuFile
->Append(HelpDemo_Advanced_Html_Help_Index
, "Advanced HTML &Help Index...");
339 menuFile
->Append(HelpDemo_Advanced_Html_Help_Classes
, "Advanced HTML &Help on Classes...");
340 menuFile
->Append(HelpDemo_Advanced_Html_Help_Functions
, "Advanced HTML &Help on Functions...");
341 menuFile
->Append(HelpDemo_Advanced_Html_Help_Help
, "Advanced HTML &About Help Demo...");
342 menuFile
->Append(HelpDemo_Advanced_Html_Help_Search
, "Advanced HTML &Search help...");
345 #if wxUSE_MS_HTML_HELP
346 menuFile
->AppendSeparator();
347 menuFile
->Append(HelpDemo_MS_Html_Help_Index
, "MS HTML &Help Index...");
348 menuFile
->Append(HelpDemo_MS_Html_Help_Classes
, "MS HTML &Help on Classes...");
349 menuFile
->Append(HelpDemo_MS_Html_Help_Functions
, "MS HTML &Help on Functions...");
350 menuFile
->Append(HelpDemo_MS_Html_Help_Help
, "MS HTML &About Help Demo...");
351 menuFile
->Append(HelpDemo_MS_Html_Help_Search
, "MS HTML &Search help...");
356 menuFile
->AppendSeparator();
357 menuFile
->Append(HelpDemo_Help_KDE
, "Use &KDE");
358 menuFile
->Append(HelpDemo_Help_GNOME
, "Use &GNOME");
359 menuFile
->Append(HelpDemo_Help_Netscape
, "Use &Netscape");
362 menuFile
->AppendSeparator();
363 menuFile
->Append(HelpDemo_Quit
, "E&xit");
365 // now append the freshly created menu to the menu bar...
366 wxMenuBar
*menuBar
= new wxMenuBar
;
367 menuBar
->Append(menuFile
, "&File");
369 // ... and attach this menu bar to the frame
372 // create a status bar just for fun (by default with 1 pane only)
374 SetStatusText("Welcome to wxWindows!");
376 // now create some controls
378 // a panel first - if there were several controls, it would allow us to
379 // navigate between them from the keyboard
380 wxPanel
*panel
= new wxPanel(this, -1, wxPoint(0, 0), wxSize(400, 200));
382 // and a static control whose parent is the panel
383 (void)new wxStaticText(panel
, -1, "Hello, world!", wxPoint(10, 10));
389 void MyFrame::OnQuit(wxCommandEvent
& WXUNUSED(event
))
391 // TRUE is to force the frame to close
395 void MyFrame::OnHelp(wxCommandEvent
& event
)
397 ShowHelp(event
.GetId(), m_help
);
400 void MyFrame::OnShowContextHelp(wxCommandEvent
& event
)
402 // This starts context help mode, then the user
403 // clicks on a window to send a help message
404 wxContextHelp
contextHelp(this);
407 void MyFrame::OnContextHelp(wxHelpEvent
& event
)
409 // In a real app, if we didn't recognise this ID, we should call event.Skip()
411 msg
.Printf(wxT("We should now display help for window %d"), event
.GetId());
413 //wxToolTip::Enable(TRUE);
417 void MyFrame::OnHtmlHelp(wxCommandEvent
& event
)
419 #if USE_HTML_HELP && USE_OLD_HTML_HELP
420 ShowHelp(event
.GetId(), m_htmlHelp
);
424 void MyFrame::OnAdvancedHtmlHelp(wxCommandEvent
& event
)
427 ShowHelp(event
.GetId(), m_advancedHtmlHelp
);
431 void MyFrame::OnMSHtmlHelp(wxCommandEvent
& event
)
433 #if wxUSE_MS_HTML_HELP
434 ShowHelp(event
.GetId(), m_msHtmlHelp
);
439 Notes: ShowHelp uses section ids for displaying particular topics,
440 but you might want to use a unique keyword to display a topic, instead.
442 Section ids are specified as follows for the different formats.
446 The [MAP] section specifies the topic to integer id mapping, e.g.
454 The identifier name corresponds to the label used for that topic.
455 You could also put these in a .h file and #include it in both the MAP
456 section and your C++ source.
458 Note that Tex2RTF doesn't currently generate the MAP section automatically.
462 The [MAP] section specifies the HTML filename root to integer id mapping, e.g.
470 The identifier name corresponds to the HTML filename used for that topic.
471 You could also put these in a .h file and #include it in both the MAP
472 section and your C++ source.
474 Note that Tex2RTF doesn't currently generate the MAP section automatically.
476 Simple wxHTML Help and External HTML Help
478 A wxhelp.map file is used, for example:
480 0 wx.htm ; wxWindows: Help index; additional keywords like overview
481 1 wx204.htm ; wxWindows Function Reference
482 2 wx34.htm ; wxWindows Class Reference
484 Note that Tex2RTF doesn't currently generate the MAP section automatically.
488 An extension to the .hhc file format is used, specifying a new parameter
491 <OBJECT type="text/sitemap">
492 <param name="Local" value="doc2.htm#classes">
493 <param name="Name" value="Classes">
494 <param name="ID" value=2>
497 Again, this is not generated automatically by Tex2RTF, though it could
498 be added quite easily.
500 Unfortunately adding the ID parameters appears to interfere with MS HTML Help,
501 so you should not try to compile a .chm file from a .hhc file with
502 this extension, or the contents will be messed up.
505 void MyFrame::ShowHelp(int commandId
, wxHelpControllerBase
& helpController
)
509 case HelpDemo_Help_Classes
:
510 case HelpDemo_Html_Help_Classes
:
511 case HelpDemo_Advanced_Html_Help_Classes
:
512 case HelpDemo_MS_Html_Help_Classes
:
513 helpController
.DisplaySection(2);
514 //helpController.DisplaySection("Classes"); // An alternative form for most controllers
517 case HelpDemo_Help_Functions
:
518 case HelpDemo_Html_Help_Functions
:
519 case HelpDemo_Advanced_Html_Help_Functions
:
520 case HelpDemo_MS_Html_Help_Functions
:
521 helpController
.DisplaySection(1);
522 //helpController.DisplaySection("Functions"); // An alternative form for most controllers
524 case HelpDemo_Help_Help
:
525 case HelpDemo_Html_Help_Help
:
526 case HelpDemo_Advanced_Html_Help_Help
:
527 case HelpDemo_MS_Html_Help_Help
:
528 helpController
.DisplaySection(3);
529 //helpController.DisplaySection("About"); // An alternative form for most controllers
532 case HelpDemo_Help_Search
:
533 case HelpDemo_Html_Help_Search
:
534 case HelpDemo_Advanced_Html_Help_Search
:
535 case HelpDemo_MS_Html_Help_Search
:
537 wxString key
= wxGetTextFromUser("Search for?",
538 "Search help for keyword",
542 helpController
.KeywordSearch(key
);
546 case HelpDemo_Help_Index
:
547 case HelpDemo_Html_Help_Index
:
548 case HelpDemo_Advanced_Html_Help_Index
:
549 case HelpDemo_MS_Html_Help_Index
:
550 helpController
.DisplayContents();
553 // These three calls are only used by wxExtHelpController
555 case HelpDemo_Help_KDE
:
556 helpController
.SetViewer("kdehelp");
558 case HelpDemo_Help_GNOME
:
559 helpController
.SetViewer("gnome-help-browser");
561 case HelpDemo_Help_Netscape
:
562 helpController
.SetViewer("netscape", wxHELP_NETSCAPE
);