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