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