demo.cpp 24 KB

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