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