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