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