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