]> git.saurik.com Git - wxWidgets.git/blame - samples/help/demo.cpp
set WXWIN_COMPATIBILITY_2_2 to 1 by default
[wxWidgets.git] / samples / help / demo.cpp
CommitLineData
de5c0ba7 1/////////////////////////////////////////////////////////////////////////////
33b64e6f
JS
2// Name: demo.cpp
3// Purpose: wxHelpController demo
4// Author: Karsten Ballueder
de5c0ba7
KB
5// Modified by:
6// Created: 04/01/98
7// RCS-ID: $Id$
33b64e6f
JS
8// Copyright: (c) Karsten Ballueder, Julian Smart
9// Licence: wxWindows licence
de5c0ba7
KB
10/////////////////////////////////////////////////////////////////////////////
11
12// ============================================================================
13// declarations
14// ============================================================================
15
16// ----------------------------------------------------------------------------
17// headers
18// ----------------------------------------------------------------------------
f96b60aa 19
de5c0ba7
KB
20// For compilers that support precompilation, includes "wx/wx.h".
21#include "wx/wxprec.h"
22
23#ifdef __BORLANDC__
29ea4a29 24# pragma hdrstop
de5c0ba7
KB
25#endif
26
27// for all others, include the necessary headers (this file is usually all you
28// need because it includes almost all "standard" wxWindows headers
29#ifndef WX_PRECOMP
29ea4a29 30# include "wx/wx.h"
de5c0ba7
KB
31#endif
32
7c4a59a8
JS
33# include "wx/image.h"
34# include "wx/help.h"
fb6261e9 35# include "wx/cshelp.h"
7c4a59a8 36
c43e86bd
JS
37#if wxUSE_TOOLTIPS
38# include "wx/tooltip.h"
39#endif
40
29ea4a29 41// define this to 1 to use HTML help even under Windows (by default, Windows
7c4a59a8 42// version will use WinHelp).
5da69e38 43// Please also see samples/html/helpview.
7c4a59a8 44
d22699b5 45#define USE_HTML_HELP 1
7c4a59a8 46
f6bcfd97
BP
47// Use old-style HTML help if 1
48#define USE_OLD_HTML_HELP 0
49
7c4a59a8
JS
50#if !wxUSE_HTML
51#undef USE_HTML_HELP
52#define USE_HTML_HELP 0
53#endif
54
f96b60aa 55#if USE_HTML_HELP
012f2cb2
GD
56#include "wx/filesys.h"
57#include "wx/fs_zip.h"
7b28757f 58
f6bcfd97 59#if USE_OLD_HTML_HELP
7b28757f 60#include "wx/generic/helpwxht.h"
f6bcfd97
BP
61#endif
62
7b28757f 63#include "wx/html/helpctrl.h"
f96b60aa 64#endif
de5c0ba7 65
f6bcfd97
BP
66#if wxUSE_MS_HTML_HELP
67#include "wx/msw/helpchm.h"
68#endif
69
3d285623
VS
70#if wxUSE_MS_HTML_HELP && wxUSE_WXHTML_HELP
71#include "wx/msw/helpbest.h"
72#endif
73
de5c0ba7
KB
74// ----------------------------------------------------------------------------
75// ressources
76// ----------------------------------------------------------------------------
77// the application icon
b87c90c1 78#if defined(__WXGTK__) || defined(__WXMOTIF__) || defined(__WXMAC__) || defined(__WXMGL__)
de5c0ba7
KB
79 #include "mondrian.xpm"
80#endif
81
82// ----------------------------------------------------------------------------
83// private classes
84// ----------------------------------------------------------------------------
85
86// Define a new application type, each program should derive a class from wxApp
87class MyApp : public wxApp
88{
89public:
90 // override base class virtuals
91 // ----------------------------
92
93 // this one is called on application startup and is a good place for the app
94 // initialization (doing it here and not in the ctor allows to have an error
95 // return: if OnInit() returns false, the application terminates)
96 virtual bool OnInit();
bd83cb56
VZ
97
98 // do some clean up here
99 virtual int OnExit();
de5c0ba7
KB
100};
101
102// Define a new frame type: this is going to be our main frame
103class MyFrame : public wxFrame
104{
105public:
106 // ctor(s)
107 MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size);
108
e66ad5c6
VZ
109 wxHelpController& GetHelpController() { return m_help; }
110
7c4a59a8 111#if USE_HTML_HELP
f6bcfd97 112#if USE_OLD_HTML_HELP
7c4a59a8 113 wxHelpControllerHtml& GetHtmlHelpController() { return m_htmlHelp; }
f6bcfd97 114#endif
7b28757f 115 wxHtmlHelpController& GetAdvancedHtmlHelpController() { return m_advancedHtmlHelp; }
7c4a59a8 116#endif
f6bcfd97
BP
117#if wxUSE_MS_HTML_HELP
118 wxCHMHelpController& GetMSHtmlHelpController() { return m_msHtmlHelp; }
119#endif
3d285623
VS
120#if wxUSE_MS_HTML_HELP && wxUSE_WXHTML_HELP
121 wxBestHelpController& GetBestHelpController() { return m_bestHelp; }
122#endif
7c4a59a8 123
de5c0ba7
KB
124 // event handlers (these functions should _not_ be virtual)
125 void OnQuit(wxCommandEvent& event);
126 void OnHelp(wxCommandEvent& event);
7c4a59a8 127 void OnHtmlHelp(wxCommandEvent& event);
7b28757f 128 void OnAdvancedHtmlHelp(wxCommandEvent& event);
f6bcfd97 129 void OnMSHtmlHelp(wxCommandEvent& event);
3d285623 130 void OnBestHelp(wxCommandEvent& event);
de5c0ba7 131
b96340e6 132 void OnShowContextHelp(wxCommandEvent& event);
542acbee 133 void OnShowDialogContextHelp(wxCommandEvent& event);
b96340e6 134
5da69e38
JS
135 void ShowHelp(int commandId, wxHelpControllerBase& helpController);
136
de5c0ba7 137private:
7c4a59a8
JS
138 wxHelpController m_help;
139
140#if USE_HTML_HELP
f6bcfd97 141#if USE_OLD_HTML_HELP
7c4a59a8 142 wxHelpControllerHtml m_htmlHelp;
f6bcfd97 143#endif
7b28757f 144 wxHtmlHelpController m_advancedHtmlHelp;
7c4a59a8 145#endif
f96b60aa 146
f6bcfd97
BP
147#if wxUSE_MS_HTML_HELP
148 wxCHMHelpController m_msHtmlHelp;
149#endif
150
3d285623
VS
151#if wxUSE_MS_HTML_HELP && wxUSE_WXHTML_HELP
152 wxBestHelpController m_bestHelp;
153#endif
154
de5c0ba7
KB
155 // any class wishing to process wxWindows events must use this macro
156 DECLARE_EVENT_TABLE()
157};
158
542acbee
JS
159// A custom modal dialog
160class MyModalDialog : public wxDialog
161{
162public:
163 MyModalDialog(wxWindow *parent);
164
542acbee
JS
165private:
166
167 DECLARE_EVENT_TABLE()
168};
169
de5c0ba7
KB
170// ----------------------------------------------------------------------------
171// constants
172// ----------------------------------------------------------------------------
173
174// IDs for the controls and the menu commands
175enum
176{
177 // menu items
5100cabf 178 HelpDemo_Quit = 100,
33b64e6f
JS
179 HelpDemo_Help_Index,
180 HelpDemo_Help_Classes,
181 HelpDemo_Help_Functions,
182 HelpDemo_Help_Help,
7c4a59a8 183 HelpDemo_Help_Search,
b96340e6 184 HelpDemo_Help_ContextHelp,
542acbee 185 HelpDemo_Help_DialogContextHelp,
7c4a59a8
JS
186
187 HelpDemo_Html_Help_Index,
188 HelpDemo_Html_Help_Classes,
189 HelpDemo_Html_Help_Functions,
190 HelpDemo_Html_Help_Help,
191 HelpDemo_Html_Help_Search,
192
7b28757f
JS
193 HelpDemo_Advanced_Html_Help_Index,
194 HelpDemo_Advanced_Html_Help_Classes,
195 HelpDemo_Advanced_Html_Help_Functions,
196 HelpDemo_Advanced_Html_Help_Help,
197 HelpDemo_Advanced_Html_Help_Search,
198
f6bcfd97
BP
199 HelpDemo_MS_Html_Help_Index,
200 HelpDemo_MS_Html_Help_Classes,
201 HelpDemo_MS_Html_Help_Functions,
202 HelpDemo_MS_Html_Help_Help,
203 HelpDemo_MS_Html_Help_Search,
204
3d285623
VS
205 HelpDemo_Best_Help_Index,
206 HelpDemo_Best_Help_Classes,
207 HelpDemo_Best_Help_Functions,
208 HelpDemo_Best_Help_Help,
209 HelpDemo_Best_Help_Search,
210
33b64e6f
JS
211 HelpDemo_Help_KDE,
212 HelpDemo_Help_GNOME,
213 HelpDemo_Help_Netscape,
de5c0ba7 214 // controls start here (the numbers are, of course, arbitrary)
7b28757f 215 HelpDemo_Text = 1000,
de5c0ba7
KB
216};
217
218// ----------------------------------------------------------------------------
219// event tables and other macros for wxWindows
220// ----------------------------------------------------------------------------
221
222// the event tables connect the wxWindows events with the functions (event
223// handlers) which process them. It can be also done at run-time, but for the
224// simple menu events like this the static method is much simpler.
225BEGIN_EVENT_TABLE(MyFrame, wxFrame)
33b64e6f
JS
226 EVT_MENU(HelpDemo_Quit, MyFrame::OnQuit)
227 EVT_MENU(HelpDemo_Help_Index, MyFrame::OnHelp)
228 EVT_MENU(HelpDemo_Help_Classes, MyFrame::OnHelp)
229 EVT_MENU(HelpDemo_Help_Functions, MyFrame::OnHelp)
230 EVT_MENU(HelpDemo_Help_Help, MyFrame::OnHelp)
7c4a59a8 231 EVT_MENU(HelpDemo_Help_Search, MyFrame::OnHelp)
b96340e6 232 EVT_MENU(HelpDemo_Help_ContextHelp, MyFrame::OnShowContextHelp)
542acbee 233 EVT_MENU(HelpDemo_Help_DialogContextHelp, MyFrame::OnShowDialogContextHelp)
b96340e6 234
7c4a59a8
JS
235 EVT_MENU(HelpDemo_Html_Help_Index, MyFrame::OnHtmlHelp)
236 EVT_MENU(HelpDemo_Html_Help_Classes, MyFrame::OnHtmlHelp)
237 EVT_MENU(HelpDemo_Html_Help_Functions, MyFrame::OnHtmlHelp)
238 EVT_MENU(HelpDemo_Html_Help_Help, MyFrame::OnHtmlHelp)
239 EVT_MENU(HelpDemo_Html_Help_Search, MyFrame::OnHtmlHelp)
240
7b28757f
JS
241 EVT_MENU(HelpDemo_Advanced_Html_Help_Index, MyFrame::OnAdvancedHtmlHelp)
242 EVT_MENU(HelpDemo_Advanced_Html_Help_Classes, MyFrame::OnAdvancedHtmlHelp)
243 EVT_MENU(HelpDemo_Advanced_Html_Help_Functions, MyFrame::OnAdvancedHtmlHelp)
244 EVT_MENU(HelpDemo_Advanced_Html_Help_Help, MyFrame::OnAdvancedHtmlHelp)
245 EVT_MENU(HelpDemo_Advanced_Html_Help_Search, MyFrame::OnAdvancedHtmlHelp)
246
f6bcfd97
BP
247 EVT_MENU(HelpDemo_MS_Html_Help_Index, MyFrame::OnMSHtmlHelp)
248 EVT_MENU(HelpDemo_MS_Html_Help_Classes, MyFrame::OnMSHtmlHelp)
249 EVT_MENU(HelpDemo_MS_Html_Help_Functions, MyFrame::OnMSHtmlHelp)
250 EVT_MENU(HelpDemo_MS_Html_Help_Help, MyFrame::OnMSHtmlHelp)
251 EVT_MENU(HelpDemo_MS_Html_Help_Search, MyFrame::OnMSHtmlHelp)
252
3d285623
VS
253 EVT_MENU(HelpDemo_Best_Help_Index, MyFrame::OnBestHelp)
254
33b64e6f
JS
255 EVT_MENU(HelpDemo_Help_KDE, MyFrame::OnHelp)
256 EVT_MENU(HelpDemo_Help_GNOME, MyFrame::OnHelp)
257 EVT_MENU(HelpDemo_Help_Netscape, MyFrame::OnHelp)
de5c0ba7
KB
258END_EVENT_TABLE()
259
260// Create a new application object: this macro will allow wxWindows to create
261// the application object during program execution (it's better than using a
262// static object for many reasons) and also declares the accessor function
263// wxGetApp() which will return the reference of the right type (i.e. MyApp and
264// not wxApp)
265IMPLEMENT_APP(MyApp)
266
267// ============================================================================
268// implementation
269// ============================================================================
270
271// ----------------------------------------------------------------------------
272// the application class
273// ----------------------------------------------------------------------------
274
275// `Main program' equivalent: the program execution "starts" here
276bool MyApp::OnInit()
277{
5100cabf
JS
278 // Create a simple help provider to make SetHelpText() do something.
279 // Note that this must be set before any SetHelpText() calls are made.
280 //wxHelpProvider::Set(new wxSimpleHelpProvider);
281 wxHelpControllerHelpProvider* provider = new wxHelpControllerHelpProvider;
282 wxHelpProvider::Set(provider);
283
7c4a59a8
JS
284#if wxUSE_HTML
285#if wxUSE_GIF
286 // Required for images in the online documentation
287 wxImage::AddHandler(new wxGIFHandler);
7b28757f
JS
288
289 // Required for advanced HTML help
290#if wxUSE_STREAMS && wxUSE_ZIPSTREAM && wxUSE_ZLIB
291 wxFileSystem::AddHandler(new wxZipFSHandler);
292#endif
293
7c4a59a8
JS
294#endif
295#endif
296
de5c0ba7 297 // Create the main application window
33b64e6f 298 MyFrame *frame = new MyFrame("HelpDemo wxWindows App",
de5c0ba7
KB
299 wxPoint(50, 50), wxSize(450, 340));
300
5100cabf
JS
301#if wxUSE_MS_HTML_HELP
302 provider->SetHelpController(& frame->GetMSHtmlHelpController());
303#else
304 provider->SetHelpController(& frame->GetHelpController());
305#endif
306
de5c0ba7
KB
307 frame->Show(TRUE);
308 SetTopWindow(frame);
309
e66ad5c6
VZ
310 // initialise the help system: this means that we'll use doc.hlp file under
311 // Windows and that the HTML docs are in the subdirectory doc for platforms
312 // using HTML help
313 if ( !frame->GetHelpController().Initialize("doc") )
314 {
4693b20c 315 wxLogError(wxT("Cannot initialize the help system, aborting."));
e66ad5c6
VZ
316
317 return FALSE;
318 }
319
3d285623
VS
320#if wxUSE_MS_HTML_HELP
321 if( !frame->GetMSHtmlHelpController().Initialize("doc") )
322 {
4693b20c 323 wxLogError(wxT("Cannot initialize the MS HTML Help system."));
3d285623
VS
324 }
325#endif
326
327#if wxUSE_MS_HTML_HELP && wxUSE_WXHTML_HELP
328 // you need to call Initialize in order to use wxBestHelpController
329 if( !frame->GetBestHelpController().Initialize("doc") )
330 {
4693b20c 331 wxLogError(wxT("Cannot initialize the best help system, aborting."));
3d285623
VS
332 }
333#endif
334
7c4a59a8 335#if USE_HTML_HELP
7b28757f 336 // initialise the standard HTML help system: this means that the HTML docs are in the
7c4a59a8 337 // subdirectory doc for platforms using HTML help
f6bcfd97 338#if USE_OLD_HTML_HELP
7c4a59a8
JS
339 if ( !frame->GetHtmlHelpController().Initialize("doc") )
340 {
4693b20c 341 wxLogError(wxT("Cannot initialize the HTML help system, aborting."));
7c4a59a8
JS
342
343 return FALSE;
344 }
f6bcfd97 345#endif
7b28757f
JS
346
347 // initialise the advanced HTML help system: this means that the HTML docs are in .htb
348 // (zipped) form
349 if ( !frame->GetAdvancedHtmlHelpController().Initialize("doc") )
350 {
4693b20c 351 wxLogError(wxT("Cannot initialize the advanced HTML help system, aborting."));
7b28757f
JS
352
353 return FALSE;
354 }
7c4a59a8
JS
355#endif
356
3d285623
VS
357#if 0
358 // defined(__WXMSW__) && wxUSE_MS_HTML_HELP
a1b8f548
JS
359 wxString path(wxGetCwd());
360 if ( !frame->GetMSHtmlHelpController().Initialize(path + "\\doc.chm") )
f6bcfd97
BP
361 {
362 wxLogError("Cannot initialize the MS HTML help system, aborting.");
363
364 return FALSE;
365 }
366#endif
367
de5c0ba7
KB
368 return TRUE;
369}
370
bd83cb56
VZ
371int MyApp::OnExit()
372{
373 // clean up
374 delete wxHelpProvider::Set(NULL);
375
376 return 0;
377}
378
de5c0ba7
KB
379// ----------------------------------------------------------------------------
380// main frame
381// ----------------------------------------------------------------------------
382
383// frame constructor
384MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size)
5100cabf 385 : wxFrame((wxFrame *)NULL, 300, title, pos, size)
de5c0ba7
KB
386{
387 // set the frame icon
388 SetIcon(wxICON(mondrian));
389
390 // create a menu bar
391 wxMenu *menuFile = new wxMenu;
392
33b64e6f
JS
393 menuFile->Append(HelpDemo_Help_Index, "&Help Index...");
394 menuFile->Append(HelpDemo_Help_Classes, "&Help on Classes...");
395 menuFile->Append(HelpDemo_Help_Functions, "&Help on Functions...");
b96340e6 396 menuFile->Append(HelpDemo_Help_ContextHelp, "&Context Help...");
bd83cb56 397 menuFile->Append(HelpDemo_Help_DialogContextHelp, "&Dialog Context Help...\tCtrl-H");
33b64e6f 398 menuFile->Append(HelpDemo_Help_Help, "&About Help Demo...");
33b64e6f 399 menuFile->Append(HelpDemo_Help_Search, "&Search help...");
7c4a59a8 400#if USE_HTML_HELP
f6bcfd97 401#if USE_OLD_HTML_HELP
7c4a59a8
JS
402 menuFile->AppendSeparator();
403 menuFile->Append(HelpDemo_Html_Help_Index, "HTML &Help Index...");
404 menuFile->Append(HelpDemo_Html_Help_Classes, "HTML &Help on Classes...");
405 menuFile->Append(HelpDemo_Html_Help_Functions, "HTML &Help on Functions...");
406 menuFile->Append(HelpDemo_Html_Help_Help, "HTML &About Help Demo...");
7c4a59a8 407 menuFile->Append(HelpDemo_Html_Help_Search, "HTML &Search help...");
f6bcfd97 408#endif
7b28757f
JS
409 menuFile->AppendSeparator();
410 menuFile->Append(HelpDemo_Advanced_Html_Help_Index, "Advanced HTML &Help Index...");
411 menuFile->Append(HelpDemo_Advanced_Html_Help_Classes, "Advanced HTML &Help on Classes...");
412 menuFile->Append(HelpDemo_Advanced_Html_Help_Functions, "Advanced HTML &Help on Functions...");
413 menuFile->Append(HelpDemo_Advanced_Html_Help_Help, "Advanced HTML &About Help Demo...");
414 menuFile->Append(HelpDemo_Advanced_Html_Help_Search, "Advanced HTML &Search help...");
7c4a59a8
JS
415#endif
416
f6bcfd97
BP
417#if wxUSE_MS_HTML_HELP
418 menuFile->AppendSeparator();
419 menuFile->Append(HelpDemo_MS_Html_Help_Index, "MS HTML &Help Index...");
420 menuFile->Append(HelpDemo_MS_Html_Help_Classes, "MS HTML &Help on Classes...");
421 menuFile->Append(HelpDemo_MS_Html_Help_Functions, "MS HTML &Help on Functions...");
422 menuFile->Append(HelpDemo_MS_Html_Help_Help, "MS HTML &About Help Demo...");
423 menuFile->Append(HelpDemo_MS_Html_Help_Search, "MS HTML &Search help...");
424#endif
425
3d285623
VS
426#if wxUSE_MS_HTML_HELP && wxUSE_WXHTML_HELP
427 menuFile->AppendSeparator();
428 menuFile->Append(HelpDemo_Best_Help_Index, "Best &Help Index...");
429#endif
430
29ea4a29 431#ifndef __WXMSW__
e66ad5c6 432#if !wxUSE_HTML
de5c0ba7 433 menuFile->AppendSeparator();
33b64e6f
JS
434 menuFile->Append(HelpDemo_Help_KDE, "Use &KDE");
435 menuFile->Append(HelpDemo_Help_GNOME, "Use &GNOME");
436 menuFile->Append(HelpDemo_Help_Netscape, "Use &Netscape");
29ea4a29 437#endif
33b64e6f
JS
438#endif
439 menuFile->AppendSeparator();
440 menuFile->Append(HelpDemo_Quit, "E&xit");
de5c0ba7
KB
441
442 // now append the freshly created menu to the menu bar...
443 wxMenuBar *menuBar = new wxMenuBar;
444 menuBar->Append(menuFile, "&File");
445
446 // ... and attach this menu bar to the frame
447 SetMenuBar(menuBar);
448
449 // create a status bar just for fun (by default with 1 pane only)
450 CreateStatusBar();
451 SetStatusText("Welcome to wxWindows!");
452
453 // now create some controls
454
455 // a panel first - if there were several controls, it would allow us to
456 // navigate between them from the keyboard
5100cabf
JS
457 wxPanel *panel = new wxPanel(this, 301, wxPoint(0, 0), wxSize(400, 200));
458 //panel->SetHelpText(_("This panel just holds a static text control."));
459 panel->SetHelpText(wxContextId(300));
de5c0ba7
KB
460
461 // and a static control whose parent is the panel
5100cabf
JS
462 wxStaticText* staticText = new wxStaticText(panel, 302, "Hello, world!", wxPoint(10, 10));
463 staticText->SetHelpText(_("This static text control isn't doing a lot right now."));
de5c0ba7
KB
464}
465
466
467// event handlers
468
469void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
470{
471 // TRUE is to force the frame to close
472 Close(TRUE);
473}
474
475void MyFrame::OnHelp(wxCommandEvent& event)
476{
5da69e38
JS
477 ShowHelp(event.GetId(), m_help);
478}
479
b96340e6
JS
480void MyFrame::OnShowContextHelp(wxCommandEvent& event)
481{
482 // This starts context help mode, then the user
483 // clicks on a window to send a help message
484 wxContextHelp contextHelp(this);
485}
486
542acbee
JS
487void MyFrame::OnShowDialogContextHelp(wxCommandEvent& event)
488{
489 MyModalDialog dialog(this);
490 dialog.ShowModal();
491}
492
5da69e38
JS
493void MyFrame::OnHtmlHelp(wxCommandEvent& event)
494{
f6bcfd97 495#if USE_HTML_HELP && USE_OLD_HTML_HELP
5da69e38
JS
496 ShowHelp(event.GetId(), m_htmlHelp);
497#endif
498}
499
500void MyFrame::OnAdvancedHtmlHelp(wxCommandEvent& event)
501{
502#if USE_HTML_HELP
503 ShowHelp(event.GetId(), m_advancedHtmlHelp);
504#endif
505}
506
f6bcfd97
BP
507void MyFrame::OnMSHtmlHelp(wxCommandEvent& event)
508{
509#if wxUSE_MS_HTML_HELP
510 ShowHelp(event.GetId(), m_msHtmlHelp);
511#endif
512}
513
3d285623
VS
514void MyFrame::OnBestHelp(wxCommandEvent& event)
515{
4693b20c 516#if wxUSE_MS_HTML_HELP && wxUSE_WXHTML_HELP
3d285623
VS
517 ShowHelp(event.GetId(), m_bestHelp);
518#endif
519}
520
f6bcfd97
BP
521/*
522 Notes: ShowHelp uses section ids for displaying particular topics,
523 but you might want to use a unique keyword to display a topic, instead.
524
525 Section ids are specified as follows for the different formats.
526
527 WinHelp
528
529 The [MAP] section specifies the topic to integer id mapping, e.g.
530
531 [MAP]
532 #define intro 100
533 #define functions 1
534 #define classes 2
535 #define about 3
536
537 The identifier name corresponds to the label used for that topic.
538 You could also put these in a .h file and #include it in both the MAP
539 section and your C++ source.
540
541 Note that Tex2RTF doesn't currently generate the MAP section automatically.
542
543 MS HTML Help
544
545 The [MAP] section specifies the HTML filename root to integer id mapping, e.g.
546
547 [MAP]
548 #define doc1 100
549 #define doc3 1
550 #define doc2 2
551 #define doc4 3
552
553 The identifier name corresponds to the HTML filename used for that topic.
554 You could also put these in a .h file and #include it in both the MAP
555 section and your C++ source.
556
557 Note that Tex2RTF doesn't currently generate the MAP section automatically.
558
559 Simple wxHTML Help and External HTML Help
560
561 A wxhelp.map file is used, for example:
562
563 0 wx.htm ; wxWindows: Help index; additional keywords like overview
564 1 wx204.htm ; wxWindows Function Reference
565 2 wx34.htm ; wxWindows Class Reference
566
567 Note that Tex2RTF doesn't currently generate the MAP section automatically.
568
569 Advanced HTML Help
570
571 An extension to the .hhc file format is used, specifying a new parameter
572 with name="ID":
573
574 <OBJECT type="text/sitemap">
575 <param name="Local" value="doc2.htm#classes">
576 <param name="Name" value="Classes">
577 <param name="ID" value=2>
578 </OBJECT>
579
580 Again, this is not generated automatically by Tex2RTF, though it could
581 be added quite easily.
582
583 Unfortunately adding the ID parameters appears to interfere with MS HTML Help,
584 so you should not try to compile a .chm file from a .hhc file with
585 this extension, or the contents will be messed up.
586 */
587
5da69e38
JS
588void MyFrame::ShowHelp(int commandId, wxHelpControllerBase& helpController)
589{
590 switch(commandId)
de5c0ba7 591 {
33b64e6f 592 case HelpDemo_Help_Classes:
5da69e38
JS
593 case HelpDemo_Html_Help_Classes:
594 case HelpDemo_Advanced_Html_Help_Classes:
f6bcfd97 595 case HelpDemo_MS_Html_Help_Classes:
3d285623 596 case HelpDemo_Best_Help_Classes:
5da69e38 597 helpController.DisplaySection(2);
f6bcfd97 598 //helpController.DisplaySection("Classes"); // An alternative form for most controllers
7c4a59a8 599
7c4a59a8 600 break;
5da69e38 601 case HelpDemo_Help_Functions:
7c4a59a8 602 case HelpDemo_Html_Help_Functions:
5da69e38 603 case HelpDemo_Advanced_Html_Help_Functions:
f6bcfd97 604 case HelpDemo_MS_Html_Help_Functions:
5da69e38 605 helpController.DisplaySection(1);
f6bcfd97 606 //helpController.DisplaySection("Functions"); // An alternative form for most controllers
7c4a59a8 607 break;
5da69e38 608 case HelpDemo_Help_Help:
7c4a59a8 609 case HelpDemo_Html_Help_Help:
5da69e38 610 case HelpDemo_Advanced_Html_Help_Help:
f6bcfd97 611 case HelpDemo_MS_Html_Help_Help:
3d285623 612 case HelpDemo_Best_Help_Help:
5da69e38 613 helpController.DisplaySection(3);
f6bcfd97 614 //helpController.DisplaySection("About"); // An alternative form for most controllers
7c4a59a8
JS
615 break;
616
5da69e38 617 case HelpDemo_Help_Search:
7c4a59a8 618 case HelpDemo_Html_Help_Search:
5da69e38 619 case HelpDemo_Advanced_Html_Help_Search:
f6bcfd97 620 case HelpDemo_MS_Html_Help_Search:
3d285623 621 case HelpDemo_Best_Help_Search:
7c4a59a8
JS
622 {
623 wxString key = wxGetTextFromUser("Search for?",
624 "Search help for keyword",
625 "",
626 this);
627 if(! key.IsEmpty())
5da69e38 628 helpController.KeywordSearch(key);
7c4a59a8
JS
629 }
630 break;
5da69e38
JS
631
632 case HelpDemo_Help_Index:
7c4a59a8 633 case HelpDemo_Html_Help_Index:
5da69e38 634 case HelpDemo_Advanced_Html_Help_Index:
f6bcfd97 635 case HelpDemo_MS_Html_Help_Index:
3d285623 636 case HelpDemo_Best_Help_Index:
5da69e38 637 helpController.DisplayContents();
7c4a59a8 638 break;
7c4a59a8 639
5da69e38 640 // These three calls are only used by wxExtHelpController
7b28757f 641
5da69e38
JS
642 case HelpDemo_Help_KDE:
643 helpController.SetViewer("kdehelp");
7b28757f 644 break;
5da69e38
JS
645 case HelpDemo_Help_GNOME:
646 helpController.SetViewer("gnome-help-browser");
7b28757f 647 break;
5da69e38
JS
648 case HelpDemo_Help_Netscape:
649 helpController.SetViewer("netscape", wxHELP_NETSCAPE);
7b28757f 650 break;
7b28757f 651 default:
7b28757f
JS
652 break;
653 }
7b28757f
JS
654}
655
542acbee
JS
656// ----------------------------------------------------------------------------
657// MyModalDialog
658// Demonstrates context-sensitive help
659// ----------------------------------------------------------------------------
660
661BEGIN_EVENT_TABLE(MyModalDialog, wxDialog)
542acbee
JS
662END_EVENT_TABLE()
663
664MyModalDialog::MyModalDialog(wxWindow *parent)
665 : wxDialog()
666{
5100cabf
JS
667 // Add the context-sensitive help button on the caption for MSW
668#ifdef __WXMSW__
669 SetExtraStyle(wxDIALOG_EX_CONTEXTHELP);
670#endif
671
542acbee
JS
672 wxDialog::Create(parent, -1, wxString("Modal dialog"));
673
674 wxBoxSizer *sizerTop = new wxBoxSizer(wxVERTICAL);
675 wxBoxSizer *sizerRow = new wxBoxSizer(wxHORIZONTAL);
676
677 wxButton* btnOK = new wxButton(this, wxID_OK, "&OK");
5100cabf
JS
678 btnOK->SetHelpText(_("The OK button confirms the dialog choices."));
679
542acbee 680 wxButton* btnCancel = new wxButton(this, wxID_CANCEL, "&Cancel");
5100cabf
JS
681 btnCancel->SetHelpText(_("The Cancel button cancels the dialog."));
682
542acbee
JS
683 sizerRow->Add(btnOK, 0, wxALIGN_CENTER | wxALL, 5);
684 sizerRow->Add(btnCancel, 0, wxALIGN_CENTER | wxALL, 5);
685
5100cabf
JS
686 // Add explicit context-sensitive help button for non-MSW
687#ifndef __WXMSW__
542acbee
JS
688 sizerRow->Add(new wxContextHelpButton(this), 0, wxALIGN_CENTER | wxALL, 5);
689#endif
690
bd83cb56
VZ
691 wxTextCtrl *text = new wxTextCtrl(this, -1, wxT("A demo text control"),
692 wxDefaultPosition, wxSize(300, 100),
693 wxTE_MULTILINE);
4693b20c 694 text->SetHelpText(_("Type text here if you have got nothing more interesting to do"));
bd83cb56 695 sizerTop->Add(text, 0, wxEXPAND|wxALIGN_CENTER_VERTICAL|wxALL, 5 );
542acbee
JS
696 sizerTop->Add(sizerRow, 0, wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL|wxALL, 5 );
697
698 SetAutoLayout(TRUE);
699 SetSizer(sizerTop);
700
701 sizerTop->SetSizeHints(this);
702 sizerTop->Fit(this);
703
704 btnOK->SetFocus();
705 btnOK->SetDefault();
706}
707