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