| 1 | ///////////////////////////////////////////////////////////////////////////// |
| 2 | // Name: demo.cpp |
| 3 | // Purpose: wxHelpController demo |
| 4 | // Author: Karsten Ballueder |
| 5 | // Modified by: |
| 6 | // Created: 04/01/98 |
| 7 | // RCS-ID: $Id$ |
| 8 | // Copyright: (c) Karsten Ballueder, Julian Smart |
| 9 | // Licence: wxWindows licence |
| 10 | ///////////////////////////////////////////////////////////////////////////// |
| 11 | |
| 12 | // ============================================================================ |
| 13 | // declarations |
| 14 | // ============================================================================ |
| 15 | |
| 16 | // ---------------------------------------------------------------------------- |
| 17 | // headers |
| 18 | // ---------------------------------------------------------------------------- |
| 19 | |
| 20 | // For compilers that support precompilation, includes "wx/wx.h". |
| 21 | #include "wx/wxprec.h" |
| 22 | |
| 23 | #ifdef __BORLANDC__ |
| 24 | # pragma hdrstop |
| 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 |
| 30 | # include "wx/wx.h" |
| 31 | #endif |
| 32 | |
| 33 | # include "wx/image.h" |
| 34 | # include "wx/help.h" |
| 35 | # include "wx/cshelp.h" |
| 36 | |
| 37 | #if wxUSE_TOOLTIPS |
| 38 | # include "wx/tooltip.h" |
| 39 | #endif |
| 40 | |
| 41 | // define this to 1 to use HTML help even under Windows (by default, Windows |
| 42 | // version will use WinHelp). |
| 43 | // Please also see samples/html/helpview. |
| 44 | |
| 45 | #define USE_HTML_HELP 1 |
| 46 | |
| 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 | |
| 52 | #if !wxUSE_HTML |
| 53 | #undef USE_HTML_HELP |
| 54 | #define USE_HTML_HELP 0 |
| 55 | #endif |
| 56 | |
| 57 | #if USE_HTML_HELP |
| 58 | #include "wx/filesys.h" |
| 59 | #include "wx/fs_zip.h" |
| 60 | |
| 61 | #include "wx/html/helpctrl.h" |
| 62 | #endif |
| 63 | |
| 64 | #if wxUSE_MS_HTML_HELP |
| 65 | #include "wx/msw/helpchm.h" |
| 66 | #endif |
| 67 | |
| 68 | #if wxUSE_MS_HTML_HELP && wxUSE_WXHTML_HELP |
| 69 | #include "wx/msw/helpbest.h" |
| 70 | #endif |
| 71 | |
| 72 | // ---------------------------------------------------------------------------- |
| 73 | // ressources |
| 74 | // ---------------------------------------------------------------------------- |
| 75 | // the application icon |
| 76 | #if defined(__WXGTK__) || defined(__WXX11__) || defined(__WXMOTIF__) || defined(__WXMAC__) || defined(__WXMGL__) |
| 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(); |
| 95 | |
| 96 | // do some clean up here |
| 97 | virtual int OnExit(); |
| 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 | |
| 107 | wxHelpController& GetHelpController() { return m_help; } |
| 108 | |
| 109 | #if USE_HTML_HELP |
| 110 | wxHtmlHelpController& GetAdvancedHtmlHelpController() { return m_advancedHtmlHelp; } |
| 111 | #endif |
| 112 | #if wxUSE_MS_HTML_HELP |
| 113 | wxCHMHelpController& GetMSHtmlHelpController() { return m_msHtmlHelp; } |
| 114 | #endif |
| 115 | #if wxUSE_MS_HTML_HELP && wxUSE_WXHTML_HELP |
| 116 | wxBestHelpController& GetBestHelpController() { return m_bestHelp; } |
| 117 | #endif |
| 118 | |
| 119 | // event handlers (these functions should _not_ be virtual) |
| 120 | void OnQuit(wxCommandEvent& event); |
| 121 | void OnHelp(wxCommandEvent& event); |
| 122 | void OnAdvancedHtmlHelp(wxCommandEvent& event); |
| 123 | void OnMSHtmlHelp(wxCommandEvent& event); |
| 124 | void OnBestHelp(wxCommandEvent& event); |
| 125 | |
| 126 | void OnShowContextHelp(wxCommandEvent& event); |
| 127 | void OnShowDialogContextHelp(wxCommandEvent& event); |
| 128 | |
| 129 | void ShowHelp(int commandId, wxHelpControllerBase& helpController); |
| 130 | |
| 131 | private: |
| 132 | wxHelpController m_help; |
| 133 | |
| 134 | #if USE_HTML_HELP |
| 135 | wxHtmlHelpController m_advancedHtmlHelp; |
| 136 | #endif |
| 137 | |
| 138 | #if wxUSE_MS_HTML_HELP |
| 139 | wxCHMHelpController m_msHtmlHelp; |
| 140 | #endif |
| 141 | |
| 142 | #if wxUSE_MS_HTML_HELP && wxUSE_WXHTML_HELP |
| 143 | wxBestHelpController m_bestHelp; |
| 144 | #endif |
| 145 | |
| 146 | // any class wishing to process wxWindows events must use this macro |
| 147 | DECLARE_EVENT_TABLE() |
| 148 | }; |
| 149 | |
| 150 | // A custom modal dialog |
| 151 | class MyModalDialog : public wxDialog |
| 152 | { |
| 153 | public: |
| 154 | MyModalDialog(wxWindow *parent); |
| 155 | |
| 156 | private: |
| 157 | |
| 158 | DECLARE_EVENT_TABLE() |
| 159 | }; |
| 160 | |
| 161 | // ---------------------------------------------------------------------------- |
| 162 | // constants |
| 163 | // ---------------------------------------------------------------------------- |
| 164 | |
| 165 | // IDs for the controls and the menu commands |
| 166 | enum |
| 167 | { |
| 168 | // menu items |
| 169 | HelpDemo_Quit = 100, |
| 170 | HelpDemo_Help_Index, |
| 171 | HelpDemo_Help_Classes, |
| 172 | HelpDemo_Help_Functions, |
| 173 | HelpDemo_Help_Help, |
| 174 | HelpDemo_Help_Search, |
| 175 | HelpDemo_Help_ContextHelp, |
| 176 | HelpDemo_Help_DialogContextHelp, |
| 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 | |
| 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 | |
| 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 | |
| 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 | |
| 202 | HelpDemo_Help_KDE, |
| 203 | HelpDemo_Help_GNOME, |
| 204 | HelpDemo_Help_Netscape, |
| 205 | // controls start here (the numbers are, of course, arbitrary) |
| 206 | HelpDemo_Text = 1000, |
| 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) |
| 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) |
| 222 | EVT_MENU(HelpDemo_Help_Search, MyFrame::OnHelp) |
| 223 | EVT_MENU(HelpDemo_Help_ContextHelp, MyFrame::OnShowContextHelp) |
| 224 | EVT_MENU(HelpDemo_Help_DialogContextHelp, MyFrame::OnShowDialogContextHelp) |
| 225 | |
| 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 | |
| 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 | |
| 238 | EVT_MENU(HelpDemo_Best_Help_Index, MyFrame::OnBestHelp) |
| 239 | |
| 240 | EVT_MENU(HelpDemo_Help_KDE, MyFrame::OnHelp) |
| 241 | EVT_MENU(HelpDemo_Help_GNOME, MyFrame::OnHelp) |
| 242 | EVT_MENU(HelpDemo_Help_Netscape, MyFrame::OnHelp) |
| 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 | { |
| 263 | // Create a simple help provider to make SetHelpText() do something. |
| 264 | // Note that this must be set before any SetHelpText() calls are made. |
| 265 | #if USE_SIMPLE_HELP_PROVIDER |
| 266 | wxSimpleHelpProvider* provider = new wxSimpleHelpProvider; |
| 267 | #else |
| 268 | wxHelpControllerHelpProvider* provider = new wxHelpControllerHelpProvider; |
| 269 | #endif |
| 270 | wxHelpProvider::Set(provider); |
| 271 | |
| 272 | #if wxUSE_HTML |
| 273 | #if wxUSE_GIF |
| 274 | // Required for images in the online documentation |
| 275 | wxImage::AddHandler(new wxGIFHandler); |
| 276 | |
| 277 | // Required for advanced HTML help |
| 278 | #if wxUSE_STREAMS && wxUSE_ZIPSTREAM && wxUSE_ZLIB |
| 279 | wxFileSystem::AddHandler(new wxZipFSHandler); |
| 280 | #endif |
| 281 | |
| 282 | #endif |
| 283 | #endif |
| 284 | |
| 285 | // Create the main application window |
| 286 | MyFrame *frame = new MyFrame(_T("HelpDemo wxWindows App"), |
| 287 | wxPoint(50, 50), wxSize(450, 340)); |
| 288 | |
| 289 | #if !USE_SIMPLE_HELP_PROVIDER |
| 290 | #if wxUSE_MS_HTML_HELP |
| 291 | provider->SetHelpController(& frame->GetMSHtmlHelpController()); |
| 292 | #else |
| 293 | provider->SetHelpController(& frame->GetHelpController()); |
| 294 | #endif |
| 295 | #endif |
| 296 | |
| 297 | frame->Show(TRUE); |
| 298 | SetTopWindow(frame); |
| 299 | |
| 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 |
| 303 | if ( !frame->GetHelpController().Initialize(_T("doc")) ) |
| 304 | { |
| 305 | wxLogError(wxT("Cannot initialize the help system, aborting.")); |
| 306 | |
| 307 | return FALSE; |
| 308 | } |
| 309 | |
| 310 | #if wxUSE_MS_HTML_HELP |
| 311 | if( !frame->GetMSHtmlHelpController().Initialize(_T("doc")) ) |
| 312 | { |
| 313 | wxLogError(wxT("Cannot initialize the MS HTML Help system.")); |
| 314 | } |
| 315 | #endif |
| 316 | |
| 317 | #if wxUSE_MS_HTML_HELP && wxUSE_WXHTML_HELP |
| 318 | // you need to call Initialize in order to use wxBestHelpController |
| 319 | if( !frame->GetBestHelpController().Initialize(_T("doc")) ) |
| 320 | { |
| 321 | wxLogError(wxT("Cannot initialize the best help system, aborting.")); |
| 322 | } |
| 323 | #endif |
| 324 | |
| 325 | #if USE_HTML_HELP |
| 326 | // initialise the advanced HTML help system: this means that the HTML docs are in .htb |
| 327 | // (zipped) form |
| 328 | if ( !frame->GetAdvancedHtmlHelpController().Initialize(_T("doc")) ) |
| 329 | { |
| 330 | wxLogError(wxT("Cannot initialize the advanced HTML help system, aborting.")); |
| 331 | |
| 332 | return FALSE; |
| 333 | } |
| 334 | #endif |
| 335 | |
| 336 | #if 0 |
| 337 | // defined(__WXMSW__) && wxUSE_MS_HTML_HELP |
| 338 | wxString path(wxGetCwd()); |
| 339 | if ( !frame->GetMSHtmlHelpController().Initialize(path + _T("\\doc.chm")) ) |
| 340 | { |
| 341 | wxLogError("Cannot initialize the MS HTML help system, aborting."); |
| 342 | |
| 343 | return FALSE; |
| 344 | } |
| 345 | #endif |
| 346 | |
| 347 | return TRUE; |
| 348 | } |
| 349 | |
| 350 | int MyApp::OnExit() |
| 351 | { |
| 352 | // clean up |
| 353 | delete wxHelpProvider::Set(NULL); |
| 354 | |
| 355 | return 0; |
| 356 | } |
| 357 | |
| 358 | // ---------------------------------------------------------------------------- |
| 359 | // main frame |
| 360 | // ---------------------------------------------------------------------------- |
| 361 | |
| 362 | // frame constructor |
| 363 | MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size) |
| 364 | : wxFrame((wxFrame *)NULL, 300, title, pos, size) |
| 365 | { |
| 366 | // set the frame icon |
| 367 | SetIcon(wxICON(mondrian)); |
| 368 | |
| 369 | // create a menu bar |
| 370 | wxMenu *menuFile = new wxMenu; |
| 371 | |
| 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...")); |
| 379 | #if USE_HTML_HELP |
| 380 | menuFile->AppendSeparator(); |
| 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...")); |
| 386 | #endif |
| 387 | |
| 388 | #if wxUSE_MS_HTML_HELP |
| 389 | menuFile->AppendSeparator(); |
| 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...")); |
| 395 | #endif |
| 396 | |
| 397 | #if wxUSE_MS_HTML_HELP && wxUSE_WXHTML_HELP |
| 398 | menuFile->AppendSeparator(); |
| 399 | menuFile->Append(HelpDemo_Best_Help_Index, _T("Best &Help Index...")); |
| 400 | #endif |
| 401 | |
| 402 | #ifndef __WXMSW__ |
| 403 | #if !wxUSE_HTML |
| 404 | menuFile->AppendSeparator(); |
| 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")); |
| 408 | #endif |
| 409 | #endif |
| 410 | menuFile->AppendSeparator(); |
| 411 | menuFile->Append(HelpDemo_Quit, _T("E&xit")); |
| 412 | |
| 413 | // now append the freshly created menu to the menu bar... |
| 414 | wxMenuBar *menuBar = new wxMenuBar; |
| 415 | menuBar->Append(menuFile, _T("&File")); |
| 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(); |
| 422 | SetStatusText(_T("Welcome to wxWindows!")); |
| 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 |
| 428 | wxPanel *panel = new wxPanel(this, 301, wxPoint(0, 0), wxSize(400, 200)); |
| 429 | panel->SetHelpText(_("This panel just holds a static text control.")); |
| 430 | //panel->SetHelpText(wxContextId(300)); |
| 431 | |
| 432 | // and a static control whose parent is the panel |
| 433 | wxStaticText* staticText = new wxStaticText(panel, 302, _T("Hello, world!"), wxPoint(10, 10)); |
| 434 | staticText->SetHelpText(_("This static text control isn't doing a lot right now.")); |
| 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 | { |
| 448 | ShowHelp(event.GetId(), m_help); |
| 449 | } |
| 450 | |
| 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 | |
| 458 | void MyFrame::OnShowDialogContextHelp(wxCommandEvent& event) |
| 459 | { |
| 460 | MyModalDialog dialog(this); |
| 461 | dialog.ShowModal(); |
| 462 | } |
| 463 | |
| 464 | void MyFrame::OnAdvancedHtmlHelp(wxCommandEvent& event) |
| 465 | { |
| 466 | #if USE_HTML_HELP |
| 467 | ShowHelp(event.GetId(), m_advancedHtmlHelp); |
| 468 | #endif |
| 469 | } |
| 470 | |
| 471 | void MyFrame::OnMSHtmlHelp(wxCommandEvent& event) |
| 472 | { |
| 473 | #if wxUSE_MS_HTML_HELP |
| 474 | ShowHelp(event.GetId(), m_msHtmlHelp); |
| 475 | #endif |
| 476 | } |
| 477 | |
| 478 | void MyFrame::OnBestHelp(wxCommandEvent& event) |
| 479 | { |
| 480 | #if wxUSE_MS_HTML_HELP && wxUSE_WXHTML_HELP |
| 481 | ShowHelp(event.GetId(), m_bestHelp); |
| 482 | #endif |
| 483 | } |
| 484 | |
| 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 | |
| 552 | void MyFrame::ShowHelp(int commandId, wxHelpControllerBase& helpController) |
| 553 | { |
| 554 | switch(commandId) |
| 555 | { |
| 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 | { |
| 588 | wxString key = wxGetTextFromUser(_T("Search for?"), |
| 589 | _T("Search help for keyword"), |
| 590 | _T(""), |
| 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: |
| 608 | helpController.SetViewer(_T("kdehelp")); |
| 609 | break; |
| 610 | case HelpDemo_Help_GNOME: |
| 611 | helpController.SetViewer(_T("gnome-help-browser")); |
| 612 | break; |
| 613 | case HelpDemo_Help_Netscape: |
| 614 | helpController.SetViewer(_T("netscape"), wxHELP_NETSCAPE); |
| 615 | break; |
| 616 | } |
| 617 | } |
| 618 | |
| 619 | // ---------------------------------------------------------------------------- |
| 620 | // MyModalDialog |
| 621 | // Demonstrates context-sensitive help |
| 622 | // ---------------------------------------------------------------------------- |
| 623 | |
| 624 | BEGIN_EVENT_TABLE(MyModalDialog, wxDialog) |
| 625 | END_EVENT_TABLE() |
| 626 | |
| 627 | MyModalDialog::MyModalDialog(wxWindow *parent) |
| 628 | : wxDialog() |
| 629 | { |
| 630 | // Add the context-sensitive help button on the caption for MSW |
| 631 | #ifdef __WXMSW__ |
| 632 | SetExtraStyle(wxDIALOG_EX_CONTEXTHELP); |
| 633 | #endif |
| 634 | |
| 635 | wxDialog::Create(parent, -1, wxString(_T("Modal dialog"))); |
| 636 | |
| 637 | wxBoxSizer *sizerTop = new wxBoxSizer(wxVERTICAL); |
| 638 | wxBoxSizer *sizerRow = new wxBoxSizer(wxHORIZONTAL); |
| 639 | |
| 640 | wxButton* btnOK = new wxButton(this, wxID_OK, _T("&OK")); |
| 641 | btnOK->SetHelpText(_("The OK button confirms the dialog choices.")); |
| 642 | |
| 643 | wxButton* btnCancel = new wxButton(this, wxID_CANCEL, _T("&Cancel")); |
| 644 | btnCancel->SetHelpText(_("The Cancel button cancels the dialog.")); |
| 645 | |
| 646 | sizerRow->Add(btnOK, 0, wxALIGN_CENTER | wxALL, 5); |
| 647 | sizerRow->Add(btnCancel, 0, wxALIGN_CENTER | wxALL, 5); |
| 648 | |
| 649 | // Add explicit context-sensitive help button for non-MSW |
| 650 | #ifndef __WXMSW__ |
| 651 | sizerRow->Add(new wxContextHelpButton(this), 0, wxALIGN_CENTER | wxALL, 5); |
| 652 | #endif |
| 653 | |
| 654 | wxTextCtrl *text = new wxTextCtrl(this, -1, wxT("A demo text control"), |
| 655 | wxDefaultPosition, wxSize(300, 100), |
| 656 | wxTE_MULTILINE); |
| 657 | text->SetHelpText(_("Type text here if you have got nothing more interesting to do")); |
| 658 | sizerTop->Add(text, 0, wxEXPAND|wxALIGN_CENTER_VERTICAL|wxALL, 5 ); |
| 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 | |