1
/////////////////////////////////////////////////////////////////////////////
3
// Purpose: wxHtml testing example
4
/////////////////////////////////////////////////////////////////////////////
6
#if defined(__GNUG__) && !defined(__APPLE__)
7
#pragma implementation "test.cpp"
8
#pragma interface "test.cpp"
11
// For compilers that support precompilation, includes "wx/wx.h".
12
#include "wx/wxprec.h"
18
// for all others, include the necessary headers (this file is usually all you
19
// need because it includes almost all "standard" wxWidgets headers
25
#include "wx/imagpng.h"
26
#include "wx/wxhtml.h"
27
#include "wx/statline.h"
29
// ----------------------------------------------------------------------------
31
// ----------------------------------------------------------------------------
34
// Define a new application type, each program should derive a class from wxApp
35
class MyApp : public wxApp
38
// override base class virtuals
39
// ----------------------------
41
// this one is called on application startup and is a good place for the app
42
// initialization (doing it here and not in the ctor allows to have an error
43
// return: if OnInit() returns false, the application terminates)
44
virtual bool OnInit();
47
// Define a new frame type: this is going to be our main frame
48
class MyFrame : public wxFrame
52
MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size);
54
// event handlers (these functions should _not_ be virtual)
55
void OnQuit(wxCommandEvent& event);
56
void OnAbout(wxCommandEvent& event);
59
// any class wishing to process wxWidgets events must use this macro
63
// ----------------------------------------------------------------------------
65
// ----------------------------------------------------------------------------
67
// IDs for the controls and the menu commands
76
// controls start here (the numbers are, of course, arbitrary)
80
// ----------------------------------------------------------------------------
81
// event tables and other macros for wxWidgets
82
// ----------------------------------------------------------------------------
84
// the event tables connect the wxWidgets events with the functions (event
85
// handlers) which process them. It can be also done at run-time, but for the
86
// simple menu events like this the static method is much simpler.
87
BEGIN_EVENT_TABLE(MyFrame, wxFrame)
88
EVT_MENU(Minimal_Quit, MyFrame::OnQuit)
89
EVT_MENU(Minimal_About, MyFrame::OnAbout)
92
// Create a new application object: this macro will allow wxWidgets to create
93
// the application object during program execution (it's better than using a
94
// static object for many reasons) and also declares the accessor function
95
// wxGetApp() which will return the reference of the right type (i.e. MyApp and
99
// ============================================================================
101
// ============================================================================
103
// ----------------------------------------------------------------------------
104
// the application class
105
// ----------------------------------------------------------------------------
106
// `Main program' equivalent: the program execution "starts" here
109
wxImage::AddHandler(new wxPNGHandler);
110
// Create the main application window
111
MyFrame *frame = new MyFrame(_("wxHtmlWindow testing application"),
112
wxDefaultPosition, wxDefaultSize);
114
// Show it and tell the application that it's our main window
115
// @@@ what does it do exactly, in fact? is it necessary here?
120
// success: wxApp::OnRun() will be called which will enter the main message
121
// loop and the application will run. If we returned false here, the
122
// application would exit immediately.
126
// ----------------------------------------------------------------------------
128
// ----------------------------------------------------------------------------
132
MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size)
133
: wxFrame((wxFrame *)NULL, wxID_ANY, title, pos, size)
136
wxMenu *menuFile = new wxMenu;
138
menuFile->Append(Minimal_About, _("&About"));
139
menuFile->Append(Minimal_Quit, _("E&xit"));
141
// now append the freshly created menu to the menu bar...
142
wxMenuBar *menuBar = new wxMenuBar;
143
menuBar->Append(menuFile, _("&File"));
145
// ... and attach this menu bar to the frame
152
void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
154
// true is to force the frame to close
158
void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
160
wxBoxSizer *topsizer;
162
wxDialog dlg(this, wxID_ANY, wxString(_("About")));
164
topsizer = new wxBoxSizer(wxVERTICAL);
166
html = new wxHtmlWindow(&dlg, wxID_ANY, wxDefaultPosition, wxSize(380, 160), wxHW_SCROLLBAR_NEVER);
167
html -> SetBorders(0);
168
html -> LoadPage(wxT("data/about.htm"));
169
html -> SetSize(html -> GetInternalRepresentation() -> GetWidth(),
170
html -> GetInternalRepresentation() -> GetHeight());
172
topsizer -> Add(html, 1, wxALL, 10);
175
topsizer -> Add(new wxStaticLine(&dlg, wxID_ANY), 0, wxEXPAND | wxLEFT | wxRIGHT, 10);
176
#endif // wxUSE_STATLINE
178
wxButton *bu1 = new wxButton(&dlg, wxID_OK, _("OK"));
181
topsizer -> Add(bu1, 0, wxALL | wxALIGN_RIGHT, 15);
183
dlg.SetSizer(topsizer);
184
topsizer -> Fit(&dlg);