helpview.cpp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: helpview.cpp
  3. // Purpose: wxHtml sample: help browser
  4. // Author: ?
  5. // Modified by:
  6. // Created: ?
  7. // Copyright: (c) wxWidgets team
  8. // Licence: wxWindows licence
  9. /////////////////////////////////////////////////////////////////////////////
  10. // Please note: see utils/helpview for a more fully-featured
  11. // standalone help browser.
  12. // For compilers that support precompilation, includes "wx/wx.h".
  13. #include "wx/wxprec.h"
  14. #ifdef __BORLANDC__
  15. #pragma hdrstop
  16. #endif
  17. // for all others, include the necessary headers (this file is usually all you
  18. // need because it includes almost all "standard" wxWidgets headers
  19. #ifndef WX_PRECOMP
  20. #include "wx/wx.h"
  21. #endif
  22. #include "wx/image.h"
  23. #include "wx/wxhtml.h"
  24. #include "wx/fs_zip.h"
  25. #include "wx/log.h"
  26. #include "wx/filedlg.h"
  27. // ----------------------------------------------------------------------------
  28. // private classes
  29. // ----------------------------------------------------------------------------
  30. // Define a new application type, each program should derive a class from wxApp
  31. class MyApp : public wxApp
  32. {
  33. public:
  34. // override base class virtuals
  35. // ----------------------------
  36. // this one is called on application startup and is a good place for the app
  37. // initialization (doing it here and not in the ctor allows to have an error
  38. // return: if OnInit() returns false, the application terminates)
  39. virtual bool OnInit();
  40. virtual int OnExit();
  41. private:
  42. wxHtmlHelpController *help;
  43. };
  44. IMPLEMENT_APP(MyApp)
  45. bool MyApp::OnInit()
  46. {
  47. #ifdef __WXMOTIF__
  48. delete wxLog::SetActiveTarget(new wxLogStderr); // So dialog boxes aren't used
  49. #endif
  50. wxInitAllImageHandlers();
  51. wxFileSystem::AddHandler(new wxZipFSHandler);
  52. SetVendorName(wxT("wxWidgets"));
  53. SetAppName(wxT("wxHTMLHelp"));
  54. wxConfig::Get(); // create an instance
  55. help = new wxHtmlHelpController;
  56. if (argc < 2) {
  57. wxLogError(wxT("Usage : helpview <helpfile> [<more helpfiles>]"));
  58. wxLogError(wxT(" helpfile may be .hhp, .zip or .htb"));
  59. return false;
  60. }
  61. for (int i = 1; i < argc; i++)
  62. help->AddBook(wxFileName(argv[i]));
  63. #ifdef __WXMOTIF__
  64. delete wxLog::SetActiveTarget(new wxLogGui);
  65. #endif
  66. help->SetShouldPreventAppExit(true);
  67. help -> DisplayContents();
  68. return true;
  69. }
  70. int MyApp::OnExit()
  71. {
  72. delete help;
  73. delete wxConfig::Set(NULL);
  74. return 0;
  75. }