]> git.saurik.com Git - wxWidgets.git/blame - samples/html/about/about.cpp
ensure that IsDialogMessage() is not called in the situations when it may hang not...
[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
30 class MyApp : public wxApp
31 {
32 public:
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)
39 virtual bool OnInit();
40 };
41
42// Define a new frame type: this is going to be our main frame
43 class MyFrame : public wxFrame
44 {
45 public:
46 // ctor(s)
47 MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size);
48e74ff5 48
5526e819
VS
49 // event handlers (these functions should _not_ be virtual)
50 void OnQuit(wxCommandEvent& event);
51 void OnAbout(wxCommandEvent& event);
52
53 private:
be5a51fb 54 // any class wishing to process wxWidgets events must use this macro
5526e819
VS
55 DECLARE_EVENT_TABLE()
56 };
57
58// ----------------------------------------------------------------------------
59// constants
60// ----------------------------------------------------------------------------
61
62// IDs for the controls and the menu commands
63 enum
64 {
65 // menu items
66 Minimal_Quit = 1,
67 Minimal_About,
68 Minimal_Back,
69 Minimal_Forward,
48e74ff5 70
5526e819 71 // controls start here (the numbers are, of course, arbitrary)
b6fa52db 72 Minimal_Text = 1000
5526e819
VS
73 };
74
75// ----------------------------------------------------------------------------
be5a51fb 76// event tables and other macros for wxWidgets
5526e819
VS
77// ----------------------------------------------------------------------------
78
be5a51fb 79// the event tables connect the wxWidgets events with the functions (event
5526e819
VS
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)
85 END_EVENT_TABLE()
48e74ff5 86
be5a51fb 87 // Create a new application object: this macro will allow wxWidgets to create
5526e819
VS
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
91 // not wxApp)
92 IMPLEMENT_APP(MyApp)
48e74ff5 93
5526e819
VS
94 // ============================================================================
95 // implementation
96 // ============================================================================
48e74ff5 97
5526e819
VS
98 // ----------------------------------------------------------------------------
99 // the application class
100 // ----------------------------------------------------------------------------
101 // `Main program' equivalent: the program execution "starts" here
102 bool MyApp::OnInit()
103 {
104 wxImage::AddHandler(new wxPNGHandler);
105 // Create the main application window
2b5f62a0 106 MyFrame *frame = new MyFrame(_("wxHtmlWindow testing application"),
16f26dad 107 wxDefaultPosition, wxDefaultSize);
48e74ff5 108
5526e819
VS
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?
348469c2 111 frame->Show(true);
5526e819
VS
112 SetTopWindow(frame);
113
114
115 // success: wxApp::OnRun() will be called which will enter the main message
348469c2 116 // loop and the application will run. If we returned false here, the
5526e819 117 // application would exit immediately.
348469c2 118 return true;
5526e819
VS
119 }
120
121// ----------------------------------------------------------------------------
122// main frame
123// ----------------------------------------------------------------------------
124
125
126// frame constructor
127 MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size)
348469c2 128 : wxFrame((wxFrame *)NULL, wxID_ANY, title, pos, size)
5526e819
VS
129 {
130 // create a menu bar
131 wxMenu *menuFile = new wxMenu;
132
2b5f62a0
VZ
133 menuFile->Append(Minimal_About, _("&About"));
134 menuFile->Append(Minimal_Quit, _("E&xit"));
5526e819
VS
135
136 // now append the freshly created menu to the menu bar...
137 wxMenuBar *menuBar = new wxMenuBar;
2b5f62a0 138 menuBar->Append(menuFile, _("&File"));
5526e819
VS
139
140 // ... and attach this menu bar to the frame
141 SetMenuBar(menuBar);
142 }
143
144
145// event handlers
146
147 void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
148 {
348469c2
WS
149 // true is to force the frame to close
150 Close(true);
5526e819
VS
151 }
152
153 void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
154 {
0f91df4f 155 wxBoxSizer *topsizer;
5526e819 156 wxHtmlWindow *html;
348469c2 157 wxDialog dlg(this, wxID_ANY, wxString(_("About")));
0f91df4f
VS
158
159 topsizer = new wxBoxSizer(wxVERTICAL);
5526e819 160
348469c2 161 html = new wxHtmlWindow(&dlg, wxID_ANY, wxDefaultPosition, wxSize(380, 160), wxHW_SCROLLBAR_NEVER);
5526e819 162 html -> SetBorders(0);
2b5f62a0 163 html -> LoadPage(wxT("data/about.htm"));
dabbc6a5 164 html -> SetSize(html -> GetInternalRepresentation() -> GetWidth(),
0f91df4f
VS
165 html -> GetInternalRepresentation() -> GetHeight());
166
167 topsizer -> Add(html, 1, wxALL, 10);
168
83f98b0d 169#if wxUSE_STATLINE
348469c2 170 topsizer -> Add(new wxStaticLine(&dlg, wxID_ANY), 0, wxEXPAND | wxLEFT | wxRIGHT, 10);
83f98b0d 171#endif // wxUSE_STATLINE
dabbc6a5 172
2b5f62a0 173 wxButton *bu1 = new wxButton(&dlg, wxID_OK, _("OK"));
5526e819 174 bu1 -> SetDefault();
0f91df4f
VS
175
176 topsizer -> Add(bu1, 0, wxALL | wxALIGN_RIGHT, 15);
177
0f91df4f
VS
178 dlg.SetSizer(topsizer);
179 topsizer -> Fit(&dlg);
180
5526e819
VS
181 dlg.ShowModal();
182 }
183