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