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