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