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