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