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