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"
37 # include "wx/tooltip.h"
40 // define this to 1 to use HTML help even under Windows (by default, Windows
41 // version will use WinHelp).
42 // Please also see samples/html/helpview.
44 #define USE_HTML_HELP 1
46 // Use old-style HTML help if 1
47 #define USE_OLD_HTML_HELP 0
51 #define USE_HTML_HELP 0
55 #include <wx/filesys.h>
56 #include <wx/fs_zip.h>
59 #include "wx/generic/helpwxht.h"
62 #include "wx/html/helpctrl.h"
65 #if wxUSE_MS_HTML_HELP
66 #include "wx/msw/helpchm.h"
69 // ----------------------------------------------------------------------------
71 // ----------------------------------------------------------------------------
72 // the application icon
73 #if defined(__WXGTK__) || defined(__WXMOTIF__)
74 #include "mondrian.xpm"
77 // ----------------------------------------------------------------------------
79 // ----------------------------------------------------------------------------
81 // Define a new application type, each program should derive a class from wxApp
82 class MyApp
: public wxApp
85 // override base class virtuals
86 // ----------------------------
88 // this one is called on application startup and is a good place for the app
89 // initialization (doing it here and not in the ctor allows to have an error
90 // return: if OnInit() returns false, the application terminates)
91 virtual bool OnInit();
94 // Define a new frame type: this is going to be our main frame
95 class MyFrame
: public wxFrame
99 MyFrame(const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
);
101 wxHelpController
& GetHelpController() { return m_help
; }
104 #if USE_OLD_HTML_HELP
105 wxHelpControllerHtml
& GetHtmlHelpController() { return m_htmlHelp
; }
107 wxHtmlHelpController
& GetAdvancedHtmlHelpController() { return m_advancedHtmlHelp
; }
109 #if wxUSE_MS_HTML_HELP
110 wxCHMHelpController
& GetMSHtmlHelpController() { return m_msHtmlHelp
; }
113 // event handlers (these functions should _not_ be virtual)
114 void OnQuit(wxCommandEvent
& event
);
115 void OnHelp(wxCommandEvent
& event
);
116 void OnHtmlHelp(wxCommandEvent
& event
);
117 void OnAdvancedHtmlHelp(wxCommandEvent
& event
);
118 void OnMSHtmlHelp(wxCommandEvent
& event
);
120 void OnContextHelp(wxHelpEvent
& event
);
121 void OnShowContextHelp(wxCommandEvent
& event
);
123 void ShowHelp(int commandId
, wxHelpControllerBase
& helpController
);
126 wxHelpController m_help
;
129 #if USE_OLD_HTML_HELP
130 wxHelpControllerHtml m_htmlHelp
;
132 wxHtmlHelpController m_advancedHtmlHelp
;
135 #if wxUSE_MS_HTML_HELP
136 wxCHMHelpController m_msHtmlHelp
;
139 // any class wishing to process wxWindows events must use this macro
140 DECLARE_EVENT_TABLE()
143 // ----------------------------------------------------------------------------
145 // ----------------------------------------------------------------------------
147 // IDs for the controls and the menu commands
153 HelpDemo_Help_Classes
,
154 HelpDemo_Help_Functions
,
156 HelpDemo_Help_Search
,
157 HelpDemo_Help_ContextHelp
,
159 HelpDemo_Html_Help_Index
,
160 HelpDemo_Html_Help_Classes
,
161 HelpDemo_Html_Help_Functions
,
162 HelpDemo_Html_Help_Help
,
163 HelpDemo_Html_Help_Search
,
165 HelpDemo_Advanced_Html_Help_Index
,
166 HelpDemo_Advanced_Html_Help_Classes
,
167 HelpDemo_Advanced_Html_Help_Functions
,
168 HelpDemo_Advanced_Html_Help_Help
,
169 HelpDemo_Advanced_Html_Help_Search
,
171 HelpDemo_MS_Html_Help_Index
,
172 HelpDemo_MS_Html_Help_Classes
,
173 HelpDemo_MS_Html_Help_Functions
,
174 HelpDemo_MS_Html_Help_Help
,
175 HelpDemo_MS_Html_Help_Search
,
179 HelpDemo_Help_Netscape
,
180 // controls start here (the numbers are, of course, arbitrary)
181 HelpDemo_Text
= 1000,
184 // ----------------------------------------------------------------------------
185 // event tables and other macros for wxWindows
186 // ----------------------------------------------------------------------------
188 // the event tables connect the wxWindows events with the functions (event
189 // handlers) which process them. It can be also done at run-time, but for the
190 // simple menu events like this the static method is much simpler.
191 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
192 EVT_MENU(HelpDemo_Quit
, MyFrame::OnQuit
)
193 EVT_MENU(HelpDemo_Help_Index
, MyFrame::OnHelp
)
194 EVT_MENU(HelpDemo_Help_Classes
, MyFrame::OnHelp
)
195 EVT_MENU(HelpDemo_Help_Functions
, MyFrame::OnHelp
)
196 EVT_MENU(HelpDemo_Help_Help
, MyFrame::OnHelp
)
197 EVT_MENU(HelpDemo_Help_Search
, MyFrame::OnHelp
)
198 EVT_MENU(HelpDemo_Help_ContextHelp
, MyFrame::OnShowContextHelp
)
200 EVT_HELP(-1, MyFrame::OnContextHelp
)
202 EVT_MENU(HelpDemo_Html_Help_Index
, MyFrame::OnHtmlHelp
)
203 EVT_MENU(HelpDemo_Html_Help_Classes
, MyFrame::OnHtmlHelp
)
204 EVT_MENU(HelpDemo_Html_Help_Functions
, MyFrame::OnHtmlHelp
)
205 EVT_MENU(HelpDemo_Html_Help_Help
, MyFrame::OnHtmlHelp
)
206 EVT_MENU(HelpDemo_Html_Help_Search
, MyFrame::OnHtmlHelp
)
208 EVT_MENU(HelpDemo_Advanced_Html_Help_Index
, MyFrame::OnAdvancedHtmlHelp
)
209 EVT_MENU(HelpDemo_Advanced_Html_Help_Classes
, MyFrame::OnAdvancedHtmlHelp
)
210 EVT_MENU(HelpDemo_Advanced_Html_Help_Functions
, MyFrame::OnAdvancedHtmlHelp
)
211 EVT_MENU(HelpDemo_Advanced_Html_Help_Help
, MyFrame::OnAdvancedHtmlHelp
)
212 EVT_MENU(HelpDemo_Advanced_Html_Help_Search
, MyFrame::OnAdvancedHtmlHelp
)
214 EVT_MENU(HelpDemo_MS_Html_Help_Index
, MyFrame::OnMSHtmlHelp
)
215 EVT_MENU(HelpDemo_MS_Html_Help_Classes
, MyFrame::OnMSHtmlHelp
)
216 EVT_MENU(HelpDemo_MS_Html_Help_Functions
, MyFrame::OnMSHtmlHelp
)
217 EVT_MENU(HelpDemo_MS_Html_Help_Help
, MyFrame::OnMSHtmlHelp
)
218 EVT_MENU(HelpDemo_MS_Html_Help_Search
, MyFrame::OnMSHtmlHelp
)
220 EVT_MENU(HelpDemo_Help_KDE
, MyFrame::OnHelp
)
221 EVT_MENU(HelpDemo_Help_GNOME
, MyFrame::OnHelp
)
222 EVT_MENU(HelpDemo_Help_Netscape
, MyFrame::OnHelp
)
225 // Create a new application object: this macro will allow wxWindows to create
226 // the application object during program execution (it's better than using a
227 // static object for many reasons) and also declares the accessor function
228 // wxGetApp() which will return the reference of the right type (i.e. MyApp and
232 // ============================================================================
234 // ============================================================================
236 // ----------------------------------------------------------------------------
237 // the application class
238 // ----------------------------------------------------------------------------
240 // `Main program' equivalent: the program execution "starts" here
245 // Required for images in the online documentation
246 wxImage::AddHandler(new wxGIFHandler
);
248 // Required for advanced HTML help
249 #if wxUSE_STREAMS && wxUSE_ZIPSTREAM && wxUSE_ZLIB
250 wxFileSystem::AddHandler(new wxZipFSHandler
);
256 // Create the main application window
257 MyFrame
*frame
= new MyFrame("HelpDemo wxWindows App",
258 wxPoint(50, 50), wxSize(450, 340));
263 // initialise the help system: this means that we'll use doc.hlp file under
264 // Windows and that the HTML docs are in the subdirectory doc for platforms
266 if ( !frame
->GetHelpController().Initialize("doc") )
268 wxLogError("Cannot initialize the help system, aborting.");
274 // initialise the standard HTML help system: this means that the HTML docs are in the
275 // subdirectory doc for platforms using HTML help
276 #if USE_OLD_HTML_HELP
277 if ( !frame
->GetHtmlHelpController().Initialize("doc") )
279 wxLogError("Cannot initialize the HTML help system, aborting.");
285 // initialise the advanced HTML help system: this means that the HTML docs are in .htb
287 if ( !frame
->GetAdvancedHtmlHelpController().Initialize("doc") )
289 wxLogError("Cannot initialize the advanced HTML help system, aborting.");
295 #if wxUSE_MS_HTML_HELP
296 if ( !frame
->GetMSHtmlHelpController().Initialize("doc") )
298 wxLogError("Cannot initialize the MS HTML help system, aborting.");
307 // ----------------------------------------------------------------------------
309 // ----------------------------------------------------------------------------
312 MyFrame::MyFrame(const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
)
313 : wxFrame((wxFrame
*)NULL
, -1, title
, pos
, size
)
315 // set the frame icon
316 SetIcon(wxICON(mondrian
));
319 wxMenu
*menuFile
= new wxMenu
;
321 menuFile
->Append(HelpDemo_Help_Index
, "&Help Index...");
322 menuFile
->Append(HelpDemo_Help_Classes
, "&Help on Classes...");
323 menuFile
->Append(HelpDemo_Help_Functions
, "&Help on Functions...");
324 menuFile
->Append(HelpDemo_Help_ContextHelp
, "&Context Help...");
325 menuFile
->Append(HelpDemo_Help_Help
, "&About Help Demo...");
326 menuFile
->Append(HelpDemo_Help_Search
, "&Search help...");
328 #if USE_OLD_HTML_HELP
329 menuFile
->AppendSeparator();
330 menuFile
->Append(HelpDemo_Html_Help_Index
, "HTML &Help Index...");
331 menuFile
->Append(HelpDemo_Html_Help_Classes
, "HTML &Help on Classes...");
332 menuFile
->Append(HelpDemo_Html_Help_Functions
, "HTML &Help on Functions...");
333 menuFile
->Append(HelpDemo_Html_Help_Help
, "HTML &About Help Demo...");
334 menuFile
->Append(HelpDemo_Html_Help_Search
, "HTML &Search help...");
336 menuFile
->AppendSeparator();
337 menuFile
->Append(HelpDemo_Advanced_Html_Help_Index
, "Advanced HTML &Help Index...");
338 menuFile
->Append(HelpDemo_Advanced_Html_Help_Classes
, "Advanced HTML &Help on Classes...");
339 menuFile
->Append(HelpDemo_Advanced_Html_Help_Functions
, "Advanced HTML &Help on Functions...");
340 menuFile
->Append(HelpDemo_Advanced_Html_Help_Help
, "Advanced HTML &About Help Demo...");
341 menuFile
->Append(HelpDemo_Advanced_Html_Help_Search
, "Advanced HTML &Search help...");
344 #if wxUSE_MS_HTML_HELP
345 menuFile
->AppendSeparator();
346 menuFile
->Append(HelpDemo_MS_Html_Help_Index
, "MS HTML &Help Index...");
347 menuFile
->Append(HelpDemo_MS_Html_Help_Classes
, "MS HTML &Help on Classes...");
348 menuFile
->Append(HelpDemo_MS_Html_Help_Functions
, "MS HTML &Help on Functions...");
349 menuFile
->Append(HelpDemo_MS_Html_Help_Help
, "MS HTML &About Help Demo...");
350 menuFile
->Append(HelpDemo_MS_Html_Help_Search
, "MS HTML &Search help...");
355 menuFile
->AppendSeparator();
356 menuFile
->Append(HelpDemo_Help_KDE
, "Use &KDE");
357 menuFile
->Append(HelpDemo_Help_GNOME
, "Use &GNOME");
358 menuFile
->Append(HelpDemo_Help_Netscape
, "Use &Netscape");
361 menuFile
->AppendSeparator();
362 menuFile
->Append(HelpDemo_Quit
, "E&xit");
364 // now append the freshly created menu to the menu bar...
365 wxMenuBar
*menuBar
= new wxMenuBar
;
366 menuBar
->Append(menuFile
, "&File");
368 // ... and attach this menu bar to the frame
371 // create a status bar just for fun (by default with 1 pane only)
373 SetStatusText("Welcome to wxWindows!");
375 // now create some controls
377 // a panel first - if there were several controls, it would allow us to
378 // navigate between them from the keyboard
379 wxPanel
*panel
= new wxPanel(this, -1, wxPoint(0, 0), wxSize(400, 200));
381 // and a static control whose parent is the panel
382 (void)new wxStaticText(panel
, -1, "Hello, world!", wxPoint(10, 10));
388 void MyFrame::OnQuit(wxCommandEvent
& WXUNUSED(event
))
390 // TRUE is to force the frame to close
394 void MyFrame::OnHelp(wxCommandEvent
& event
)
396 ShowHelp(event
.GetId(), m_help
);
399 void MyFrame::OnShowContextHelp(wxCommandEvent
& event
)
401 // This starts context help mode, then the user
402 // clicks on a window to send a help message
403 wxContextHelp
contextHelp(this);
406 void MyFrame::OnContextHelp(wxHelpEvent
& event
)
408 // In a real app, if we didn't recognise this ID, we should call event.Skip()
410 msg
.Printf(wxT("We should now display help for window %d"), event
.GetId());
412 //wxToolTip::Enable(TRUE);
416 void MyFrame::OnHtmlHelp(wxCommandEvent
& event
)
418 #if USE_HTML_HELP && USE_OLD_HTML_HELP
419 ShowHelp(event
.GetId(), m_htmlHelp
);
423 void MyFrame::OnAdvancedHtmlHelp(wxCommandEvent
& event
)
426 ShowHelp(event
.GetId(), m_advancedHtmlHelp
);
430 void MyFrame::OnMSHtmlHelp(wxCommandEvent
& event
)
432 #if wxUSE_MS_HTML_HELP
433 ShowHelp(event
.GetId(), m_msHtmlHelp
);
438 Notes: ShowHelp uses section ids for displaying particular topics,
439 but you might want to use a unique keyword to display a topic, instead.
441 Section ids are specified as follows for the different formats.
445 The [MAP] section specifies the topic to integer id mapping, e.g.
453 The identifier name corresponds to the label used for that topic.
454 You could also put these in a .h file and #include it in both the MAP
455 section and your C++ source.
457 Note that Tex2RTF doesn't currently generate the MAP section automatically.
461 The [MAP] section specifies the HTML filename root to integer id mapping, e.g.
469 The identifier name corresponds to the HTML filename used for that topic.
470 You could also put these in a .h file and #include it in both the MAP
471 section and your C++ source.
473 Note that Tex2RTF doesn't currently generate the MAP section automatically.
475 Simple wxHTML Help and External HTML Help
477 A wxhelp.map file is used, for example:
479 0 wx.htm ; wxWindows: Help index; additional keywords like overview
480 1 wx204.htm ; wxWindows Function Reference
481 2 wx34.htm ; wxWindows Class Reference
483 Note that Tex2RTF doesn't currently generate the MAP section automatically.
487 An extension to the .hhc file format is used, specifying a new parameter
490 <OBJECT type="text/sitemap">
491 <param name="Local" value="doc2.htm#classes">
492 <param name="Name" value="Classes">
493 <param name="ID" value=2>
496 Again, this is not generated automatically by Tex2RTF, though it could
497 be added quite easily.
499 Unfortunately adding the ID parameters appears to interfere with MS HTML Help,
500 so you should not try to compile a .chm file from a .hhc file with
501 this extension, or the contents will be messed up.
504 void MyFrame::ShowHelp(int commandId
, wxHelpControllerBase
& helpController
)
508 case HelpDemo_Help_Classes
:
509 case HelpDemo_Html_Help_Classes
:
510 case HelpDemo_Advanced_Html_Help_Classes
:
511 case HelpDemo_MS_Html_Help_Classes
:
512 helpController
.DisplaySection(2);
513 //helpController.DisplaySection("Classes"); // An alternative form for most controllers
516 case HelpDemo_Help_Functions
:
517 case HelpDemo_Html_Help_Functions
:
518 case HelpDemo_Advanced_Html_Help_Functions
:
519 case HelpDemo_MS_Html_Help_Functions
:
520 helpController
.DisplaySection(1);
521 //helpController.DisplaySection("Functions"); // An alternative form for most controllers
523 case HelpDemo_Help_Help
:
524 case HelpDemo_Html_Help_Help
:
525 case HelpDemo_Advanced_Html_Help_Help
:
526 case HelpDemo_MS_Html_Help_Help
:
527 helpController
.DisplaySection(3);
528 //helpController.DisplaySection("About"); // An alternative form for most controllers
531 case HelpDemo_Help_Search
:
532 case HelpDemo_Html_Help_Search
:
533 case HelpDemo_Advanced_Html_Help_Search
:
534 case HelpDemo_MS_Html_Help_Search
:
536 wxString key
= wxGetTextFromUser("Search for?",
537 "Search help for keyword",
541 helpController
.KeywordSearch(key
);
545 case HelpDemo_Help_Index
:
546 case HelpDemo_Html_Help_Index
:
547 case HelpDemo_Advanced_Html_Help_Index
:
548 case HelpDemo_MS_Html_Help_Index
:
549 helpController
.DisplayContents();
552 // These three calls are only used by wxExtHelpController
554 case HelpDemo_Help_KDE
:
555 helpController
.SetViewer("kdehelp");
557 case HelpDemo_Help_GNOME
:
558 helpController
.SetViewer("gnome-help-browser");
560 case HelpDemo_Help_Netscape
:
561 helpController
.SetViewer("netscape", wxHELP_NETSCAPE
);