no changes
[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" wxWindows 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 // Use old-style HTML help if 1
48 #define USE_OLD_HTML_HELP 0
49
50 #if !wxUSE_HTML
51 #undef USE_HTML_HELP
52 #define USE_HTML_HELP 0
53 #endif
54
55 #if USE_HTML_HELP
56 #include "wx/filesys.h"
57 #include "wx/fs_zip.h"
58
59 #if USE_OLD_HTML_HELP
60 #include "wx/generic/helpwxht.h"
61 #endif
62
63 #include "wx/html/helpctrl.h"
64 #endif
65
66 #if wxUSE_MS_HTML_HELP
67 #include "wx/msw/helpchm.h"
68 #endif
69
70 #if wxUSE_MS_HTML_HELP && wxUSE_WXHTML_HELP
71 #include "wx/msw/helpbest.h"
72 #endif
73
74 // ----------------------------------------------------------------------------
75 // ressources
76 // ----------------------------------------------------------------------------
77 // the application icon
78 #if defined(__WXGTK__) || defined(__WXMOTIF__) || defined(__WXMAC__) || defined(__WXMGL__)
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
87 class MyApp : public wxApp
88 {
89 public:
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();
97
98 // do some clean up here
99 virtual int OnExit();
100 };
101
102 // Define a new frame type: this is going to be our main frame
103 class MyFrame : public wxFrame
104 {
105 public:
106 // ctor(s)
107 MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size);
108
109 wxHelpController& GetHelpController() { return m_help; }
110
111 #if USE_HTML_HELP
112 #if USE_OLD_HTML_HELP
113 wxHelpControllerHtml& GetHtmlHelpController() { return m_htmlHelp; }
114 #endif
115 wxHtmlHelpController& GetAdvancedHtmlHelpController() { return m_advancedHtmlHelp; }
116 #endif
117 #if wxUSE_MS_HTML_HELP
118 wxCHMHelpController& GetMSHtmlHelpController() { return m_msHtmlHelp; }
119 #endif
120 #if wxUSE_MS_HTML_HELP && wxUSE_WXHTML_HELP
121 wxBestHelpController& GetBestHelpController() { return m_bestHelp; }
122 #endif
123
124 // event handlers (these functions should _not_ be virtual)
125 void OnQuit(wxCommandEvent& event);
126 void OnHelp(wxCommandEvent& event);
127 void OnHtmlHelp(wxCommandEvent& event);
128 void OnAdvancedHtmlHelp(wxCommandEvent& event);
129 void OnMSHtmlHelp(wxCommandEvent& event);
130 void OnBestHelp(wxCommandEvent& event);
131
132 void OnShowContextHelp(wxCommandEvent& event);
133 void OnShowDialogContextHelp(wxCommandEvent& event);
134
135 void ShowHelp(int commandId, wxHelpControllerBase& helpController);
136
137 private:
138 wxHelpController m_help;
139
140 #if USE_HTML_HELP
141 #if USE_OLD_HTML_HELP
142 wxHelpControllerHtml m_htmlHelp;
143 #endif
144 wxHtmlHelpController m_advancedHtmlHelp;
145 #endif
146
147 #if wxUSE_MS_HTML_HELP
148 wxCHMHelpController m_msHtmlHelp;
149 #endif
150
151 #if wxUSE_MS_HTML_HELP && wxUSE_WXHTML_HELP
152 wxBestHelpController m_bestHelp;
153 #endif
154
155 // any class wishing to process wxWindows 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
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
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
211 HelpDemo_Help_KDE,
212 HelpDemo_Help_GNOME,
213 HelpDemo_Help_Netscape,
214 // controls start here (the numbers are, of course, arbitrary)
215 HelpDemo_Text = 1000,
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.
225 BEGIN_EVENT_TABLE(MyFrame, wxFrame)
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)
231 EVT_MENU(HelpDemo_Help_Search, MyFrame::OnHelp)
232 EVT_MENU(HelpDemo_Help_ContextHelp, MyFrame::OnShowContextHelp)
233 EVT_MENU(HelpDemo_Help_DialogContextHelp, MyFrame::OnShowDialogContextHelp)
234
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
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
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
253 EVT_MENU(HelpDemo_Best_Help_Index, MyFrame::OnBestHelp)
254
255 EVT_MENU(HelpDemo_Help_KDE, MyFrame::OnHelp)
256 EVT_MENU(HelpDemo_Help_GNOME, MyFrame::OnHelp)
257 EVT_MENU(HelpDemo_Help_Netscape, MyFrame::OnHelp)
258 END_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)
265 IMPLEMENT_APP(MyApp)
266
267 // ============================================================================
268 // implementation
269 // ============================================================================
270
271 // ----------------------------------------------------------------------------
272 // the application class
273 // ----------------------------------------------------------------------------
274
275 // `Main program' equivalent: the program execution "starts" here
276 bool MyApp::OnInit()
277 {
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
284 #if wxUSE_HTML
285 #if wxUSE_GIF
286 // Required for images in the online documentation
287 wxImage::AddHandler(new wxGIFHandler);
288
289 // Required for advanced HTML help
290 #if wxUSE_STREAMS && wxUSE_ZIPSTREAM && wxUSE_ZLIB
291 wxFileSystem::AddHandler(new wxZipFSHandler);
292 #endif
293
294 #endif
295 #endif
296
297 // Create the main application window
298 MyFrame *frame = new MyFrame("HelpDemo wxWindows App",
299 wxPoint(50, 50), wxSize(450, 340));
300
301 #if wxUSE_MS_HTML_HELP
302 provider->SetHelpController(& frame->GetMSHtmlHelpController());
303 #else
304 provider->SetHelpController(& frame->GetHelpController());
305 #endif
306
307 frame->Show(TRUE);
308 SetTopWindow(frame);
309
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 {
315 wxLogError(wxT("Cannot initialize the help system, aborting."));
316
317 return FALSE;
318 }
319
320 #if wxUSE_MS_HTML_HELP
321 if( !frame->GetMSHtmlHelpController().Initialize("doc") )
322 {
323 wxLogError(wxT("Cannot initialize the MS HTML Help system."));
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 {
331 wxLogError(wxT("Cannot initialize the best help system, aborting."));
332 }
333 #endif
334
335 #if USE_HTML_HELP
336 // initialise the standard HTML help system: this means that the HTML docs are in the
337 // subdirectory doc for platforms using HTML help
338 #if USE_OLD_HTML_HELP
339 if ( !frame->GetHtmlHelpController().Initialize("doc") )
340 {
341 wxLogError(wxT("Cannot initialize the HTML help system, aborting."));
342
343 return FALSE;
344 }
345 #endif
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 {
351 wxLogError(wxT("Cannot initialize the advanced HTML help system, aborting."));
352
353 return FALSE;
354 }
355 #endif
356
357 #if 0
358 // defined(__WXMSW__) && wxUSE_MS_HTML_HELP
359 wxString path(wxGetCwd());
360 if ( !frame->GetMSHtmlHelpController().Initialize(path + "\\doc.chm") )
361 {
362 wxLogError("Cannot initialize the MS HTML help system, aborting.");
363
364 return FALSE;
365 }
366 #endif
367
368 return TRUE;
369 }
370
371 int MyApp::OnExit()
372 {
373 // clean up
374 delete wxHelpProvider::Set(NULL);
375
376 return 0;
377 }
378
379 // ----------------------------------------------------------------------------
380 // main frame
381 // ----------------------------------------------------------------------------
382
383 // frame constructor
384 MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size)
385 : wxFrame((wxFrame *)NULL, 300, title, pos, size)
386 {
387 // set the frame icon
388 SetIcon(wxICON(mondrian));
389
390 // create a menu bar
391 wxMenu *menuFile = new wxMenu;
392
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...");
396 menuFile->Append(HelpDemo_Help_ContextHelp, "&Context Help...");
397 menuFile->Append(HelpDemo_Help_DialogContextHelp, "&Dialog Context Help...\tCtrl-H");
398 menuFile->Append(HelpDemo_Help_Help, "&About Help Demo...");
399 menuFile->Append(HelpDemo_Help_Search, "&Search help...");
400 #if USE_HTML_HELP
401 #if USE_OLD_HTML_HELP
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...");
407 menuFile->Append(HelpDemo_Html_Help_Search, "HTML &Search help...");
408 #endif
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...");
415 #endif
416
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
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
431 #ifndef __WXMSW__
432 #if !wxUSE_HTML
433 menuFile->AppendSeparator();
434 menuFile->Append(HelpDemo_Help_KDE, "Use &KDE");
435 menuFile->Append(HelpDemo_Help_GNOME, "Use &GNOME");
436 menuFile->Append(HelpDemo_Help_Netscape, "Use &Netscape");
437 #endif
438 #endif
439 menuFile->AppendSeparator();
440 menuFile->Append(HelpDemo_Quit, "E&xit");
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
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));
460
461 // and a static control whose parent is the panel
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."));
464 }
465
466
467 // event handlers
468
469 void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
470 {
471 // TRUE is to force the frame to close
472 Close(TRUE);
473 }
474
475 void MyFrame::OnHelp(wxCommandEvent& event)
476 {
477 ShowHelp(event.GetId(), m_help);
478 }
479
480 void 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
487 void MyFrame::OnShowDialogContextHelp(wxCommandEvent& event)
488 {
489 MyModalDialog dialog(this);
490 dialog.ShowModal();
491 }
492
493 void MyFrame::OnHtmlHelp(wxCommandEvent& event)
494 {
495 #if USE_HTML_HELP && USE_OLD_HTML_HELP
496 ShowHelp(event.GetId(), m_htmlHelp);
497 #endif
498 }
499
500 void MyFrame::OnAdvancedHtmlHelp(wxCommandEvent& event)
501 {
502 #if USE_HTML_HELP
503 ShowHelp(event.GetId(), m_advancedHtmlHelp);
504 #endif
505 }
506
507 void MyFrame::OnMSHtmlHelp(wxCommandEvent& event)
508 {
509 #if wxUSE_MS_HTML_HELP
510 ShowHelp(event.GetId(), m_msHtmlHelp);
511 #endif
512 }
513
514 void MyFrame::OnBestHelp(wxCommandEvent& event)
515 {
516 #if wxUSE_MS_HTML_HELP && wxUSE_WXHTML_HELP
517 ShowHelp(event.GetId(), m_bestHelp);
518 #endif
519 }
520
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
588 void MyFrame::ShowHelp(int commandId, wxHelpControllerBase& helpController)
589 {
590 switch(commandId)
591 {
592 case HelpDemo_Help_Classes:
593 case HelpDemo_Html_Help_Classes:
594 case HelpDemo_Advanced_Html_Help_Classes:
595 case HelpDemo_MS_Html_Help_Classes:
596 case HelpDemo_Best_Help_Classes:
597 helpController.DisplaySection(2);
598 //helpController.DisplaySection("Classes"); // An alternative form for most controllers
599 break;
600
601 case HelpDemo_Help_Functions:
602 case HelpDemo_Html_Help_Functions:
603 case HelpDemo_Advanced_Html_Help_Functions:
604 case HelpDemo_MS_Html_Help_Functions:
605 helpController.DisplaySection(1);
606 //helpController.DisplaySection("Functions"); // An alternative form for most controllers
607 break;
608
609 case HelpDemo_Help_Help:
610 case HelpDemo_Html_Help_Help:
611 case HelpDemo_Advanced_Html_Help_Help:
612 case HelpDemo_MS_Html_Help_Help:
613 case HelpDemo_Best_Help_Help:
614 helpController.DisplaySection(3);
615 //helpController.DisplaySection("About"); // An alternative form for most controllers
616 break;
617
618 case HelpDemo_Help_Search:
619 case HelpDemo_Html_Help_Search:
620 case HelpDemo_Advanced_Html_Help_Search:
621 case HelpDemo_MS_Html_Help_Search:
622 case HelpDemo_Best_Help_Search:
623 {
624 wxString key = wxGetTextFromUser("Search for?",
625 "Search help for keyword",
626 "",
627 this);
628 if(! key.IsEmpty())
629 helpController.KeywordSearch(key);
630 }
631 break;
632
633 case HelpDemo_Help_Index:
634 case HelpDemo_Html_Help_Index:
635 case HelpDemo_Advanced_Html_Help_Index:
636 case HelpDemo_MS_Html_Help_Index:
637 case HelpDemo_Best_Help_Index:
638 helpController.DisplayContents();
639 break;
640
641 // These three calls are only used by wxExtHelpController
642
643 case HelpDemo_Help_KDE:
644 helpController.SetViewer("kdehelp");
645 break;
646 case HelpDemo_Help_GNOME:
647 helpController.SetViewer("gnome-help-browser");
648 break;
649 case HelpDemo_Help_Netscape:
650 helpController.SetViewer("netscape", wxHELP_NETSCAPE);
651 break;
652 }
653 }
654
655 // ----------------------------------------------------------------------------
656 // MyModalDialog
657 // Demonstrates context-sensitive help
658 // ----------------------------------------------------------------------------
659
660 BEGIN_EVENT_TABLE(MyModalDialog, wxDialog)
661 END_EVENT_TABLE()
662
663 MyModalDialog::MyModalDialog(wxWindow *parent)
664 : wxDialog()
665 {
666 // Add the context-sensitive help button on the caption for MSW
667 #ifdef __WXMSW__
668 SetExtraStyle(wxDIALOG_EX_CONTEXTHELP);
669 #endif
670
671 wxDialog::Create(parent, -1, wxString("Modal dialog"));
672
673 wxBoxSizer *sizerTop = new wxBoxSizer(wxVERTICAL);
674 wxBoxSizer *sizerRow = new wxBoxSizer(wxHORIZONTAL);
675
676 wxButton* btnOK = new wxButton(this, wxID_OK, "&OK");
677 btnOK->SetHelpText(_("The OK button confirms the dialog choices."));
678
679 wxButton* btnCancel = new wxButton(this, wxID_CANCEL, "&Cancel");
680 btnCancel->SetHelpText(_("The Cancel button cancels the dialog."));
681
682 sizerRow->Add(btnOK, 0, wxALIGN_CENTER | wxALL, 5);
683 sizerRow->Add(btnCancel, 0, wxALIGN_CENTER | wxALL, 5);
684
685 // Add explicit context-sensitive help button for non-MSW
686 #ifndef __WXMSW__
687 sizerRow->Add(new wxContextHelpButton(this), 0, wxALIGN_CENTER | wxALL, 5);
688 #endif
689
690 wxTextCtrl *text = new wxTextCtrl(this, -1, wxT("A demo text control"),
691 wxDefaultPosition, wxSize(300, 100),
692 wxTE_MULTILINE);
693 text->SetHelpText(_("Type text here if you have got nothing more interesting to do"));
694 sizerTop->Add(text, 0, wxEXPAND|wxALIGN_CENTER_VERTICAL|wxALL, 5 );
695 sizerTop->Add(sizerRow, 0, wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL|wxALL, 5 );
696
697 SetAutoLayout(TRUE);
698 SetSizer(sizerTop);
699
700 sizerTop->SetSizeHints(this);
701 sizerTop->Fit(this);
702
703 btnOK->SetFocus();
704 btnOK->SetDefault();
705 }
706