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