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