about.cpp 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: about.cpp
  3. // Purpose: wxHtml sample: about dialog test
  4. // Author: ?
  5. // Modified by:
  6. // Created: ?
  7. // Copyright: (c) wxWidgets team
  8. // Licence: wxWindows licence
  9. /////////////////////////////////////////////////////////////////////////////
  10. // For compilers that support precompilation, includes "wx/wx.h".
  11. #include "wx/wxprec.h"
  12. #ifdef __BORLANDC__
  13. #pragma hdrstop
  14. #endif
  15. // for all others, include the necessary headers (this file is usually all you
  16. // need because it includes almost all "standard" wxWidgets headers
  17. #ifndef WX_PRECOMP
  18. #include "wx/wx.h"
  19. #endif
  20. #include "wx/image.h"
  21. #include "wx/imagpng.h"
  22. #include "wx/wxhtml.h"
  23. #include "wx/statline.h"
  24. #ifndef wxHAS_IMAGES_IN_RESOURCES
  25. #include "../../sample.xpm"
  26. #endif
  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. };
  41. // Define a new frame type: this is going to be our main frame
  42. class MyFrame : public wxFrame
  43. {
  44. public:
  45. // ctor(s)
  46. MyFrame(const wxString& title);
  47. // event handlers (these functions should _not_ be virtual)
  48. void OnQuit(wxCommandEvent& event);
  49. void OnAbout(wxCommandEvent& event);
  50. private:
  51. // any class wishing to process wxWidgets events must use this macro
  52. wxDECLARE_EVENT_TABLE();
  53. };
  54. // ----------------------------------------------------------------------------
  55. // event tables and other macros for wxWidgets
  56. // ----------------------------------------------------------------------------
  57. // the event tables connect the wxWidgets events with the functions (event
  58. // handlers) which process them. It can be also done at run-time, but for the
  59. // simple menu events like this the static method is much simpler.
  60. wxBEGIN_EVENT_TABLE(MyFrame, wxFrame)
  61. EVT_MENU(wxID_ABOUT, MyFrame::OnAbout)
  62. EVT_MENU(wxID_EXIT, MyFrame::OnQuit)
  63. wxEND_EVENT_TABLE()
  64. // Create a new application object: this macro will allow wxWidgets to create
  65. // the application object during program execution (it's better than using a
  66. // static object for many reasons) and also declares the accessor function
  67. // wxGetApp() which will return the reference of the right type (i.e. MyApp and
  68. // not wxApp)
  69. IMPLEMENT_APP(MyApp)
  70. // ============================================================================
  71. // implementation
  72. // ============================================================================
  73. // ----------------------------------------------------------------------------
  74. // the application class
  75. // ----------------------------------------------------------------------------
  76. // `Main program' equivalent: the program execution "starts" here
  77. bool MyApp::OnInit()
  78. {
  79. if ( !wxApp::OnInit() )
  80. return false;
  81. // we use a PNG image in our HTML page
  82. wxImage::AddHandler(new wxPNGHandler);
  83. // create and show the main application window
  84. MyFrame *frame = new MyFrame(_("wxHtmlWindow testing application"));
  85. frame->Show();
  86. // success: wxApp::OnRun() will be called which will enter the main message
  87. // loop and the application will run. If we returned false here, the
  88. // application would exit immediately.
  89. return true;
  90. }
  91. // ----------------------------------------------------------------------------
  92. // main frame
  93. // ----------------------------------------------------------------------------
  94. // frame constructor
  95. MyFrame::MyFrame(const wxString& title)
  96. : wxFrame((wxFrame *)NULL, wxID_ANY, title)
  97. {
  98. SetIcon(wxICON(sample));
  99. // create a menu bar
  100. wxMenu *menuFile = new wxMenu;
  101. menuFile->Append(wxID_ABOUT);
  102. menuFile->Append(wxID_EXIT);
  103. // now append the freshly created menu to the menu bar...
  104. wxMenuBar *menuBar = new wxMenuBar;
  105. menuBar->Append(menuFile, _("&File"));
  106. // ... and attach this menu bar to the frame
  107. SetMenuBar(menuBar);
  108. }
  109. // event handlers
  110. void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
  111. {
  112. // true is to force the frame to close
  113. Close(true);
  114. }
  115. void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
  116. {
  117. wxBoxSizer *topsizer;
  118. wxHtmlWindow *html;
  119. wxDialog dlg(this, wxID_ANY, wxString(_("About")));
  120. topsizer = new wxBoxSizer(wxVERTICAL);
  121. html = new wxHtmlWindow(&dlg, wxID_ANY, wxDefaultPosition, wxSize(380, 160), wxHW_SCROLLBAR_NEVER);
  122. html -> SetBorders(0);
  123. html -> LoadPage(wxT("data/about.htm"));
  124. html -> SetSize(html -> GetInternalRepresentation() -> GetWidth(),
  125. html -> GetInternalRepresentation() -> GetHeight());
  126. topsizer -> Add(html, 1, wxALL, 10);
  127. #if wxUSE_STATLINE
  128. topsizer -> Add(new wxStaticLine(&dlg, wxID_ANY), 0, wxEXPAND | wxLEFT | wxRIGHT, 10);
  129. #endif // wxUSE_STATLINE
  130. wxButton *bu1 = new wxButton(&dlg, wxID_OK, _("OK"));
  131. bu1 -> SetDefault();
  132. topsizer -> Add(bu1, 0, wxALL | wxALIGN_RIGHT, 15);
  133. dlg.SetSizer(topsizer);
  134. topsizer -> Fit(&dlg);
  135. dlg.ShowModal();
  136. }