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