]> git.saurik.com Git - wxWidgets.git/blame - samples/help/demo.cpp
Send delete item event just before the item is actually
[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
618f2efa 82#if defined(__WXGTK__) || defined(__WXX11__) || defined(__WXMOTIF__) || defined(__WXMAC__) || defined(__WXMGL__)
de5c0ba7
KB
83 #include "mondrian.xpm"
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{
5100cabf
JS
290 // Create a simple help provider to make SetHelpText() do something.
291 // Note that this must be set before any SetHelpText() calls are made.
8f2a41e9
JS
292#if USE_SIMPLE_HELP_PROVIDER
293 wxSimpleHelpProvider* provider = new wxSimpleHelpProvider;
294#else
5100cabf 295 wxHelpControllerHelpProvider* provider = new wxHelpControllerHelpProvider;
8f2a41e9 296#endif
5100cabf
JS
297 wxHelpProvider::Set(provider);
298
02f51f1f 299#if USE_HTML_HELP
a6c355d2
VZ
300 #if wxUSE_GIF
301 // Required for images in the online documentation
302 wxImage::AddHandler(new wxGIFHandler);
303 #endif // wxUSE_GIF
7b28757f
JS
304
305 // Required for advanced HTML help
a6c355d2
VZ
306 #if wxUSE_STREAMS && wxUSE_ZIPSTREAM && wxUSE_ZLIB
307 wxFileSystem::AddHandler(new wxZipFSHandler);
308 #endif
309#endif // wxUSE_HTML
7c4a59a8 310
de5c0ba7 311 // Create the main application window
be5a51fb 312 MyFrame *frame = new MyFrame(_T("HelpDemo wxWidgets App"),
de5c0ba7
KB
313 wxPoint(50, 50), wxSize(450, 340));
314
8f2a41e9 315#if !USE_SIMPLE_HELP_PROVIDER
3fe1edc2 316#if wxUSE_MS_HTML_HELP && !defined(__WXUNIVERSAL__)
5100cabf
JS
317 provider->SetHelpController(& frame->GetMSHtmlHelpController());
318#else
319 provider->SetHelpController(& frame->GetHelpController());
8f2a41e9 320#endif
a6c355d2 321#endif // !USE_SIMPLE_HELP_PROVIDER
5100cabf 322
3fe1edc2 323 frame->Show(true);
de5c0ba7
KB
324 SetTopWindow(frame);
325
e66ad5c6
VZ
326 // initialise the help system: this means that we'll use doc.hlp file under
327 // Windows and that the HTML docs are in the subdirectory doc for platforms
328 // using HTML help
42ed7532 329 if ( !frame->GetHelpController().Initialize(_T("doc")) )
e66ad5c6 330 {
4693b20c 331 wxLogError(wxT("Cannot initialize the help system, aborting."));
e66ad5c6 332
3fe1edc2 333 return false;
e66ad5c6
VZ
334 }
335
3fe1edc2 336#if wxUSE_MS_HTML_HELP && !defined(__WXUNIVERSAL__)
42ed7532 337 if( !frame->GetMSHtmlHelpController().Initialize(_T("doc")) )
3d285623 338 {
4693b20c 339 wxLogError(wxT("Cannot initialize the MS HTML Help system."));
3d285623
VS
340 }
341#endif
342
3fe1edc2 343#if wxUSE_MS_HTML_HELP && wxUSE_WXHTML_HELP && !defined(__WXUNIVERSAL__)
3d285623 344 // you need to call Initialize in order to use wxBestHelpController
42ed7532 345 if( !frame->GetBestHelpController().Initialize(_T("doc")) )
3d285623 346 {
4693b20c 347 wxLogError(wxT("Cannot initialize the best help system, aborting."));
3d285623
VS
348 }
349#endif
350
7c4a59a8 351#if USE_HTML_HELP
7b28757f
JS
352 // initialise the advanced HTML help system: this means that the HTML docs are in .htb
353 // (zipped) form
42ed7532 354 if ( !frame->GetAdvancedHtmlHelpController().Initialize(_T("doc")) )
7b28757f 355 {
4693b20c 356 wxLogError(wxT("Cannot initialize the advanced HTML help system, aborting."));
7b28757f 357
3fe1edc2 358 return false;
7b28757f 359 }
7c4a59a8
JS
360#endif
361
3d285623
VS
362#if 0
363 // defined(__WXMSW__) && wxUSE_MS_HTML_HELP
a1b8f548 364 wxString path(wxGetCwd());
42ed7532 365 if ( !frame->GetMSHtmlHelpController().Initialize(path + _T("\\doc.chm")) )
f6bcfd97
BP
366 {
367 wxLogError("Cannot initialize the MS HTML help system, aborting.");
368
3fe1edc2 369 return false;
f6bcfd97
BP
370 }
371#endif
372
3fe1edc2 373 return true;
de5c0ba7
KB
374}
375
bd83cb56
VZ
376int MyApp::OnExit()
377{
378 // clean up
379 delete wxHelpProvider::Set(NULL);
380
381 return 0;
382}
383
de5c0ba7
KB
384// ----------------------------------------------------------------------------
385// main frame
386// ----------------------------------------------------------------------------
387
388// frame constructor
389MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size)
5100cabf 390 : wxFrame((wxFrame *)NULL, 300, title, pos, size)
3755cfa6
JS
391#if USE_HTML_HELP
392 , m_embeddedHtmlHelp(wxHF_EMBEDDED|wxHF_DEFAULT_STYLE)
393#endif
de5c0ba7
KB
394{
395 // set the frame icon
396 SetIcon(wxICON(mondrian));
397
398 // create a menu bar
399 wxMenu *menuFile = new wxMenu;
400
42ed7532
MB
401 menuFile->Append(HelpDemo_Help_Index, _T("&Help Index..."));
402 menuFile->Append(HelpDemo_Help_Classes, _T("&Help on Classes..."));
403 menuFile->Append(HelpDemo_Help_Functions, _T("&Help on Functions..."));
404 menuFile->Append(HelpDemo_Help_ContextHelp, _T("&Context Help..."));
405 menuFile->Append(HelpDemo_Help_DialogContextHelp, _T("&Dialog Context Help...\tCtrl-H"));
406 menuFile->Append(HelpDemo_Help_Help, _T("&About Help Demo..."));
407 menuFile->Append(HelpDemo_Help_Search, _T("&Search help..."));
7c4a59a8 408#if USE_HTML_HELP
7b28757f 409 menuFile->AppendSeparator();
42ed7532
MB
410 menuFile->Append(HelpDemo_Advanced_Html_Help_Index, _T("Advanced HTML &Help Index..."));
411 menuFile->Append(HelpDemo_Advanced_Html_Help_Classes, _T("Advanced HTML &Help on Classes..."));
412 menuFile->Append(HelpDemo_Advanced_Html_Help_Functions, _T("Advanced HTML &Help on Functions..."));
413 menuFile->Append(HelpDemo_Advanced_Html_Help_Help, _T("Advanced HTML &About Help Demo..."));
414 menuFile->Append(HelpDemo_Advanced_Html_Help_Search, _T("Advanced HTML &Search help..."));
3755cfa6 415 menuFile->Append(HelpDemo_Advanced_Html_Help_Modal, _T("Advanced HTML Help &Modal Dialog..."));
7c4a59a8
JS
416#endif
417
3fe1edc2 418#if wxUSE_MS_HTML_HELP && !defined(__WXUNIVERSAL__)
f6bcfd97 419 menuFile->AppendSeparator();
42ed7532
MB
420 menuFile->Append(HelpDemo_MS_Html_Help_Index, _T("MS HTML &Help Index..."));
421 menuFile->Append(HelpDemo_MS_Html_Help_Classes, _T("MS HTML &Help on Classes..."));
422 menuFile->Append(HelpDemo_MS_Html_Help_Functions, _T("MS HTML &Help on Functions..."));
423 menuFile->Append(HelpDemo_MS_Html_Help_Help, _T("MS HTML &About Help Demo..."));
424 menuFile->Append(HelpDemo_MS_Html_Help_Search, _T("MS HTML &Search help..."));
f6bcfd97
BP
425#endif
426
3fe1edc2 427#if wxUSE_MS_HTML_HELP && wxUSE_WXHTML_HELP && !defined(__WXUNIVERSAL__)
3d285623 428 menuFile->AppendSeparator();
42ed7532 429 menuFile->Append(HelpDemo_Best_Help_Index, _T("Best &Help Index..."));
3d285623
VS
430#endif
431
29ea4a29 432#ifndef __WXMSW__
e66ad5c6 433#if !wxUSE_HTML
de5c0ba7 434 menuFile->AppendSeparator();
42ed7532
MB
435 menuFile->Append(HelpDemo_Help_KDE, _T("Use &KDE"));
436 menuFile->Append(HelpDemo_Help_GNOME, _T("Use &GNOME"));
437 menuFile->Append(HelpDemo_Help_Netscape, _T("Use &Netscape"));
29ea4a29 438#endif
33b64e6f
JS
439#endif
440 menuFile->AppendSeparator();
42ed7532 441 menuFile->Append(HelpDemo_Quit, _T("E&xit"));
de5c0ba7
KB
442
443 // now append the freshly created menu to the menu bar...
444 wxMenuBar *menuBar = new wxMenuBar;
42ed7532 445 menuBar->Append(menuFile, _T("&File"));
de5c0ba7
KB
446
447 // ... and attach this menu bar to the frame
448 SetMenuBar(menuBar);
449
8520f137 450#if wxUSE_STATUSBAR
de5c0ba7
KB
451 // create a status bar just for fun (by default with 1 pane only)
452 CreateStatusBar();
be5a51fb 453 SetStatusText(_T("Welcome to wxWidgets!"));
8520f137 454#endif // wxUSE_STATUSBAR
de5c0ba7 455
3755cfa6
JS
456#if USE_HTML_HELP
457 // Create embedded HTML Help window
458 m_embeddedHelpWindow = new wxHtmlHelpWindow;
459 // m_embeddedHtmlHelp.UseConfig(config, rootPath); // Can set your own config object here
460 m_embeddedHtmlHelp.SetHelpWindow(m_embeddedHelpWindow);
461
462 m_embeddedHelpWindow->Create(this,
463 wxID_ANY, wxDefaultPosition, GetClientSize(), wxTAB_TRAVERSAL|wxNO_BORDER, wxHF_DEFAULT_STYLE);
464
465 m_embeddedHtmlHelp.AddBook(wxFileName(_T("doc.zip")));
466 m_embeddedHtmlHelp.Display(_T("Introduction"));
467#else
de5c0ba7
KB
468 // now create some controls
469
470 // a panel first - if there were several controls, it would allow us to
471 // navigate between them from the keyboard
5100cabf 472 wxPanel *panel = new wxPanel(this, 301, wxPoint(0, 0), wxSize(400, 200));
5f9ab82d
JS
473 panel->SetHelpText(_("This panel just holds a static text control."));
474 //panel->SetHelpText(wxContextId(300));
de5c0ba7
KB
475
476 // and a static control whose parent is the panel
42ed7532 477 wxStaticText* staticText = new wxStaticText(panel, 302, _T("Hello, world!"), wxPoint(10, 10));
5100cabf 478 staticText->SetHelpText(_("This static text control isn't doing a lot right now."));
3755cfa6 479#endif
de5c0ba7
KB
480}
481
482
483// event handlers
484
485void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
486{
3fe1edc2
WS
487 // true is to force the frame to close
488 Close(true);
de5c0ba7
KB
489}
490
491void MyFrame::OnHelp(wxCommandEvent& event)
492{
5da69e38
JS
493 ShowHelp(event.GetId(), m_help);
494}
495
87728739 496void MyFrame::OnShowContextHelp(wxCommandEvent& WXUNUSED(event))
b96340e6
JS
497{
498 // This starts context help mode, then the user
499 // clicks on a window to send a help message
500 wxContextHelp contextHelp(this);
501}
502
87728739 503void MyFrame::OnShowDialogContextHelp(wxCommandEvent& WXUNUSED(event))
542acbee
JS
504{
505 MyModalDialog dialog(this);
506 dialog.ShowModal();
507}
508
5da69e38
JS
509void MyFrame::OnAdvancedHtmlHelp(wxCommandEvent& event)
510{
511#if USE_HTML_HELP
512 ShowHelp(event.GetId(), m_advancedHtmlHelp);
513#endif
514}
515
3fe1edc2 516#if wxUSE_MS_HTML_HELP && !defined(__WXUNIVERSAL__)
f6bcfd97
BP
517void MyFrame::OnMSHtmlHelp(wxCommandEvent& event)
518{
f6bcfd97 519 ShowHelp(event.GetId(), m_msHtmlHelp);
f6bcfd97 520}
3fe1edc2 521#endif
f6bcfd97 522
3fe1edc2 523#if wxUSE_MS_HTML_HELP && wxUSE_WXHTML_HELP && !defined(__WXUNIVERSAL__)
3d285623
VS
524void MyFrame::OnBestHelp(wxCommandEvent& event)
525{
3d285623 526 ShowHelp(event.GetId(), m_bestHelp);
3d285623 527}
3fe1edc2 528#endif
3d285623 529
3755cfa6
JS
530#if USE_HTML_HELP
531void MyFrame::OnModalHtmlHelp(wxCommandEvent& WXUNUSED(event))
532{
533 wxHtmlModalHelp modalHelp(this, wxT("doc.zip"), wxT("Introduction"));
534}
535#endif
536
f6bcfd97
BP
537/*
538 Notes: ShowHelp uses section ids for displaying particular topics,
539 but you might want to use a unique keyword to display a topic, instead.
540
541 Section ids are specified as follows for the different formats.
542
543 WinHelp
544
545 The [MAP] section specifies the topic to integer id mapping, e.g.
546
547 [MAP]
548 #define intro 100
549 #define functions 1
550 #define classes 2
551 #define about 3
552
553 The identifier name corresponds to the label used for that topic.
554 You could also put these in a .h file and #include it in both the MAP
555 section and your C++ source.
556
557 Note that Tex2RTF doesn't currently generate the MAP section automatically.
558
559 MS HTML Help
560
561 The [MAP] section specifies the HTML filename root to integer id mapping, e.g.
562
563 [MAP]
564 #define doc1 100
565 #define doc3 1
566 #define doc2 2
567 #define doc4 3
568
569 The identifier name corresponds to the HTML filename used for that topic.
570 You could also put these in a .h file and #include it in both the MAP
571 section and your C++ source.
572
573 Note that Tex2RTF doesn't currently generate the MAP section automatically.
574
575 Simple wxHTML Help and External HTML Help
576
577 A wxhelp.map file is used, for example:
578
be5a51fb
JS
579 0 wx.htm ; wxWidgets: Help index; additional keywords like overview
580 1 wx204.htm ; wxWidgets Function Reference
581 2 wx34.htm ; wxWidgets Class Reference
f6bcfd97
BP
582
583 Note that Tex2RTF doesn't currently generate the MAP section automatically.
584
585 Advanced HTML Help
586
587 An extension to the .hhc file format is used, specifying a new parameter
588 with name="ID":
589
590 <OBJECT type="text/sitemap">
591 <param name="Local" value="doc2.htm#classes">
592 <param name="Name" value="Classes">
593 <param name="ID" value=2>
594 </OBJECT>
595
596 Again, this is not generated automatically by Tex2RTF, though it could
597 be added quite easily.
598
599 Unfortunately adding the ID parameters appears to interfere with MS HTML Help,
600 so you should not try to compile a .chm file from a .hhc file with
601 this extension, or the contents will be messed up.
602 */
603
5da69e38
JS
604void MyFrame::ShowHelp(int commandId, wxHelpControllerBase& helpController)
605{
606 switch(commandId)
de5c0ba7 607 {
4c6b8d9e
VZ
608 case HelpDemo_Help_Classes:
609 case HelpDemo_Html_Help_Classes:
610 case HelpDemo_Advanced_Html_Help_Classes:
611 case HelpDemo_MS_Html_Help_Classes:
612 case HelpDemo_Best_Help_Classes:
613 helpController.DisplaySection(2);
614 //helpController.DisplaySection("Classes"); // An alternative form for most controllers
615 break;
616
617 case HelpDemo_Help_Functions:
618 case HelpDemo_Html_Help_Functions:
619 case HelpDemo_Advanced_Html_Help_Functions:
620 case HelpDemo_MS_Html_Help_Functions:
621 helpController.DisplaySection(1);
622 //helpController.DisplaySection("Functions"); // An alternative form for most controllers
623 break;
624
625 case HelpDemo_Help_Help:
626 case HelpDemo_Html_Help_Help:
627 case HelpDemo_Advanced_Html_Help_Help:
628 case HelpDemo_MS_Html_Help_Help:
629 case HelpDemo_Best_Help_Help:
630 helpController.DisplaySection(3);
631 //helpController.DisplaySection("About"); // An alternative form for most controllers
632 break;
633
634 case HelpDemo_Help_Search:
635 case HelpDemo_Html_Help_Search:
636 case HelpDemo_Advanced_Html_Help_Search:
637 case HelpDemo_MS_Html_Help_Search:
638 case HelpDemo_Best_Help_Search:
639 {
42ed7532
MB
640 wxString key = wxGetTextFromUser(_T("Search for?"),
641 _T("Search help for keyword"),
dabbc6a5 642 wxEmptyString,
4c6b8d9e
VZ
643 this);
644 if(! key.IsEmpty())
645 helpController.KeywordSearch(key);
646 }
647 break;
648
649 case HelpDemo_Help_Index:
650 case HelpDemo_Html_Help_Index:
651 case HelpDemo_Advanced_Html_Help_Index:
652 case HelpDemo_MS_Html_Help_Index:
653 case HelpDemo_Best_Help_Index:
654 helpController.DisplayContents();
655 break;
656
657 // These three calls are only used by wxExtHelpController
658
659 case HelpDemo_Help_KDE:
42ed7532 660 helpController.SetViewer(_T("kdehelp"));
4c6b8d9e
VZ
661 break;
662 case HelpDemo_Help_GNOME:
42ed7532 663 helpController.SetViewer(_T("gnome-help-browser"));
4c6b8d9e
VZ
664 break;
665 case HelpDemo_Help_Netscape:
42ed7532 666 helpController.SetViewer(_T("netscape"), wxHELP_NETSCAPE);
4c6b8d9e 667 break;
7b28757f 668 }
7b28757f
JS
669}
670
542acbee
JS
671// ----------------------------------------------------------------------------
672// MyModalDialog
673// Demonstrates context-sensitive help
674// ----------------------------------------------------------------------------
675
676BEGIN_EVENT_TABLE(MyModalDialog, wxDialog)
542acbee
JS
677END_EVENT_TABLE()
678
679MyModalDialog::MyModalDialog(wxWindow *parent)
42447c4f 680 : wxDialog(parent, wxID_ANY, wxString(_T("Modal dialog")))
542acbee 681{
42447c4f
VZ
682 // Add the context-sensitive help button on the caption for the platforms
683 // which support it (currently MSW only)
5100cabf 684 SetExtraStyle(wxDIALOG_EX_CONTEXTHELP);
5100cabf 685
542acbee
JS
686
687 wxBoxSizer *sizerTop = new wxBoxSizer(wxVERTICAL);
688 wxBoxSizer *sizerRow = new wxBoxSizer(wxHORIZONTAL);
689
42ed7532 690 wxButton* btnOK = new wxButton(this, wxID_OK, _T("&OK"));
5100cabf
JS
691 btnOK->SetHelpText(_("The OK button confirms the dialog choices."));
692
42ed7532 693 wxButton* btnCancel = new wxButton(this, wxID_CANCEL, _T("&Cancel"));
5100cabf
JS
694 btnCancel->SetHelpText(_("The Cancel button cancels the dialog."));
695
542acbee
JS
696 sizerRow->Add(btnOK, 0, wxALIGN_CENTER | wxALL, 5);
697 sizerRow->Add(btnCancel, 0, wxALIGN_CENTER | wxALL, 5);
698
5100cabf
JS
699 // Add explicit context-sensitive help button for non-MSW
700#ifndef __WXMSW__
542acbee
JS
701 sizerRow->Add(new wxContextHelpButton(this), 0, wxALIGN_CENTER | wxALL, 5);
702#endif
703
3fe1edc2 704 wxTextCtrl *text = new wxTextCtrl(this, wxID_ANY, wxT("A demo text control"),
bd83cb56
VZ
705 wxDefaultPosition, wxSize(300, 100),
706 wxTE_MULTILINE);
4693b20c 707 text->SetHelpText(_("Type text here if you have got nothing more interesting to do"));
bd83cb56 708 sizerTop->Add(text, 0, wxEXPAND|wxALIGN_CENTER_VERTICAL|wxALL, 5 );
542acbee
JS
709 sizerTop->Add(sizerRow, 0, wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL|wxALL, 5 );
710
542acbee
JS
711 SetSizer(sizerTop);
712
713 sizerTop->SetSizeHints(this);
714 sizerTop->Fit(this);
715
716 btnOK->SetFocus();
717 btnOK->SetDefault();
718}
719