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