]>
git.saurik.com Git - wxWidgets.git/blob - samples/html/about/about.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxHtml testing example
4 /////////////////////////////////////////////////////////////////////////////
6 // For compilers that support precompilation, includes "wx/wx.h".
13 // for all others, include the necessary headers (this file is usually all you
14 // need because it includes almost all "standard" wxWidgets headers
20 #include "wx/imagpng.h"
21 #include "wx/wxhtml.h"
22 #include "wx/statline.h"
24 // ----------------------------------------------------------------------------
26 // ----------------------------------------------------------------------------
29 // Define a new application type, each program should derive a class from wxApp
30 class MyApp
: public wxApp
33 // override base class virtuals
34 // ----------------------------
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)
39 virtual bool OnInit();
42 // Define a new frame type: this is going to be our main frame
43 class MyFrame
: public wxFrame
47 MyFrame(const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
);
49 // event handlers (these functions should _not_ be virtual)
50 void OnQuit(wxCommandEvent
& event
);
51 void OnAbout(wxCommandEvent
& event
);
54 // any class wishing to process wxWidgets events must use this macro
58 // ----------------------------------------------------------------------------
60 // ----------------------------------------------------------------------------
62 // IDs for the controls and the menu commands
71 // controls start here (the numbers are, of course, arbitrary)
75 // ----------------------------------------------------------------------------
76 // event tables and other macros for wxWidgets
77 // ----------------------------------------------------------------------------
79 // the event tables connect the wxWidgets events with the functions (event
80 // handlers) which process them. It can be also done at run-time, but for the
81 // simple menu events like this the static method is much simpler.
82 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
83 EVT_MENU(Minimal_Quit
, MyFrame::OnQuit
)
84 EVT_MENU(Minimal_About
, MyFrame::OnAbout
)
87 // Create a new application object: this macro will allow wxWidgets to create
88 // the application object during program execution (it's better than using a
89 // static object for many reasons) and also declares the accessor function
90 // wxGetApp() which will return the reference of the right type (i.e. MyApp and
94 // ============================================================================
96 // ============================================================================
98 // ----------------------------------------------------------------------------
99 // the application class
100 // ----------------------------------------------------------------------------
101 // `Main program' equivalent: the program execution "starts" here
104 wxImage::AddHandler(new wxPNGHandler
);
105 // Create the main application window
106 MyFrame
*frame
= new MyFrame(_("wxHtmlWindow testing application"),
107 wxDefaultPosition
, wxDefaultSize
);
109 // Show it and tell the application that it's our main window
110 // @@@ what does it do exactly, in fact? is it necessary here?
115 // success: wxApp::OnRun() will be called which will enter the main message
116 // loop and the application will run. If we returned false here, the
117 // application would exit immediately.
121 // ----------------------------------------------------------------------------
123 // ----------------------------------------------------------------------------
127 MyFrame::MyFrame(const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
)
128 : wxFrame((wxFrame
*)NULL
, wxID_ANY
, title
, pos
, size
)
131 wxMenu
*menuFile
= new wxMenu
;
133 menuFile
->Append(Minimal_About
, _("&About"));
134 menuFile
->Append(Minimal_Quit
, _("E&xit"));
136 // now append the freshly created menu to the menu bar...
137 wxMenuBar
*menuBar
= new wxMenuBar
;
138 menuBar
->Append(menuFile
, _("&File"));
140 // ... and attach this menu bar to the frame
147 void MyFrame::OnQuit(wxCommandEvent
& WXUNUSED(event
))
149 // true is to force the frame to close
153 void MyFrame::OnAbout(wxCommandEvent
& WXUNUSED(event
))
155 wxBoxSizer
*topsizer
;
157 wxDialog
dlg(this, wxID_ANY
, wxString(_("About")));
159 topsizer
= new wxBoxSizer(wxVERTICAL
);
161 html
= new wxHtmlWindow(&dlg
, wxID_ANY
, wxDefaultPosition
, wxSize(380, 160), wxHW_SCROLLBAR_NEVER
);
162 html
-> SetBorders(0);
163 html
-> LoadPage(wxT("data/about.htm"));
164 html
-> SetSize(html
-> GetInternalRepresentation() -> GetWidth(),
165 html
-> GetInternalRepresentation() -> GetHeight());
167 topsizer
-> Add(html
, 1, wxALL
, 10);
170 topsizer
-> Add(new wxStaticLine(&dlg
, wxID_ANY
), 0, wxEXPAND
| wxLEFT
| wxRIGHT
, 10);
171 #endif // wxUSE_STATLINE
173 wxButton
*bu1
= new wxButton(&dlg
, wxID_OK
, _("OK"));
176 topsizer
-> Add(bu1
, 0, wxALL
| wxALIGN_RIGHT
, 15);
178 dlg
.SetSizer(topsizer
);
179 topsizer
-> Fit(&dlg
);