]> git.saurik.com Git - wxWidgets.git/blame - samples/html/about/about.cpp
Exclude zlib 3rd party sources from our checks too.
[wxWidgets.git] / samples / html / about / about.cpp
CommitLineData
5526e819 1/////////////////////////////////////////////////////////////////////////////
197ab43d
FM
2// Name: about.cpp
3// Purpose: wxHtml sample: about dialog test
4// Author: ?
5// Modified by:
6// Created: ?
197ab43d
FM
7// Copyright: (c) wxWidgets team
8// Licence: wxWindows licence
5526e819
VS
9/////////////////////////////////////////////////////////////////////////////
10
5526e819 11// For compilers that support precompilation, includes "wx/wx.h".
92a19c2e 12#include "wx/wxprec.h"
5526e819
VS
13
14#ifdef __BORLANDC__
15 #pragma hdrstop
16#endif
17
18// for all others, include the necessary headers (this file is usually all you
be5a51fb 19// need because it includes almost all "standard" wxWidgets headers
5526e819 20#ifndef WX_PRECOMP
67547666 21 #include "wx/wx.h"
5526e819
VS
22#endif
23
67547666
GD
24#include "wx/image.h"
25#include "wx/imagpng.h"
26#include "wx/wxhtml.h"
27#include "wx/statline.h"
5526e819 28
e7092398 29#ifndef wxHAS_IMAGES_IN_RESOURCES
197ab43d
FM
30 #include "../../sample.xpm"
31#endif
32
33
5526e819
VS
34// ----------------------------------------------------------------------------
35// private classes
36// ----------------------------------------------------------------------------
37
38
39// Define a new application type, each program should derive a class from wxApp
140316c2
VZ
40class MyApp : public wxApp
41{
42public:
5526e819
VS
43 // override base class virtuals
44 // ----------------------------
48e74ff5 45
5526e819
VS
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)
140316c2
VZ
49 virtual bool OnInit();
50};
5526e819
VS
51
52// Define a new frame type: this is going to be our main frame
140316c2
VZ
53class MyFrame : public wxFrame
54{
55public:
5526e819 56 // ctor(s)
140316c2 57 MyFrame(const wxString& title);
48e74ff5 58
5526e819 59 // event handlers (these functions should _not_ be virtual)
140316c2
VZ
60 void OnQuit(wxCommandEvent& event);
61 void OnAbout(wxCommandEvent& event);
5526e819 62
140316c2 63private:
be5a51fb 64 // any class wishing to process wxWidgets events must use this macro
5526e819 65 DECLARE_EVENT_TABLE()
140316c2 66};
5526e819
VS
67
68// ----------------------------------------------------------------------------
be5a51fb 69// event tables and other macros for wxWidgets
5526e819
VS
70// ----------------------------------------------------------------------------
71
be5a51fb 72// the event tables connect the wxWidgets events with the functions (event
5526e819
VS
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.
140316c2
VZ
75BEGIN_EVENT_TABLE(MyFrame, wxFrame)
76 EVT_MENU(wxID_ABOUT, MyFrame::OnAbout)
77 EVT_MENU(wxID_EXIT, MyFrame::OnQuit)
78END_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)
85IMPLEMENT_APP(MyApp)
86
87// ============================================================================
88// implementation
89// ============================================================================
48e74ff5 90
140316c2
VZ
91// ----------------------------------------------------------------------------
92// the application class
93// ----------------------------------------------------------------------------
5526e819 94
140316c2
VZ
95// `Main program' equivalent: the program execution "starts" here
96bool MyApp::OnInit()
97{
45e6e6f8
VZ
98 if ( !wxApp::OnInit() )
99 return false;
100
140316c2
VZ
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();
5526e819
VS
107
108 // success: wxApp::OnRun() will be called which will enter the main message
348469c2 109 // loop and the application will run. If we returned false here, the
5526e819 110 // application would exit immediately.
140316c2
VZ
111 return true;
112}
5526e819
VS
113
114// ----------------------------------------------------------------------------
115// main frame
116// ----------------------------------------------------------------------------
117
5526e819 118// frame constructor
140316c2
VZ
119MyFrame::MyFrame(const wxString& title)
120 : wxFrame((wxFrame *)NULL, wxID_ANY, title)
121{
197ab43d
FM
122 SetIcon(wxICON(sample));
123
5526e819 124 // create a menu bar
140316c2 125 wxMenu *menuFile = new wxMenu;
5526e819 126
140316c2
VZ
127 menuFile->Append(wxID_ABOUT);
128 menuFile->Append(wxID_EXIT);
5526e819
VS
129
130 // now append the freshly created menu to the menu bar...
140316c2
VZ
131 wxMenuBar *menuBar = new wxMenuBar;
132 menuBar->Append(menuFile, _("&File"));
5526e819
VS
133
134 // ... and attach this menu bar to the frame
140316c2
VZ
135 SetMenuBar(menuBar);
136}
5526e819
VS
137
138
139// event handlers
140
140316c2
VZ
141void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
142{
348469c2 143 // true is to force the frame to close
140316c2
VZ
144 Close(true);
145}
5526e819 146
140316c2
VZ
147void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
148{
149 wxBoxSizer *topsizer;
150 wxHtmlWindow *html;
151 wxDialog dlg(this, wxID_ANY, wxString(_("About")));
0f91df4f 152
140316c2 153 topsizer = new wxBoxSizer(wxVERTICAL);
5526e819 154
140316c2
VZ
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());
0f91df4f 160
140316c2 161 topsizer -> Add(html, 1, wxALL, 10);
0f91df4f 162
83f98b0d 163#if wxUSE_STATLINE
140316c2 164 topsizer -> Add(new wxStaticLine(&dlg, wxID_ANY), 0, wxEXPAND | wxLEFT | wxRIGHT, 10);
83f98b0d 165#endif // wxUSE_STATLINE
dabbc6a5 166
140316c2
VZ
167 wxButton *bu1 = new wxButton(&dlg, wxID_OK, _("OK"));
168 bu1 -> SetDefault();
0f91df4f 169
140316c2 170 topsizer -> Add(bu1, 0, wxALL | wxALIGN_RIGHT, 15);
0f91df4f 171
140316c2
VZ
172 dlg.SetSizer(topsizer);
173 topsizer -> Fit(&dlg);
0f91df4f 174
140316c2
VZ
175 dlg.ShowModal();
176}
5526e819 177