]> git.saurik.com Git - wxWidgets.git/blob - samples/propsize/propsize.cpp
1. Derive wxMessageDialogBase from wxDialog (why did we use multiple
[wxWidgets.git] / samples / propsize / propsize.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: propsize.cpp
3 // Purpose: wxWidgets propsize sample
4 // Author: Julian Smart
5 // Modified by:
6 // Created: 04/01/98
7 // RCS-ID: $Id$
8 // Copyright: (c) Julian Smart
9 // License: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
11
12 // ============================================================================
13 // declarations
14 // ============================================================================
15
16 // ----------------------------------------------------------------------------
17 // headers
18 // ----------------------------------------------------------------------------
19
20 // For compilers that support precompilation, includes "wx/wx.h".
21 #include "wx/wxprec.h"
22
23 #ifdef __BORLANDC__
24 #pragma hdrstop
25 #endif
26
27 // for all others, include the necessary headers (this file is usually all you
28 // need because it includes almost all "standard" wxWidgets headers
29 #ifndef WX_PRECOMP
30 #include "wx/wx.h"
31 #endif
32
33 #include "wx/statline.h"
34
35 // ----------------------------------------------------------------------------
36 // ressources
37 // ----------------------------------------------------------------------------
38 // the application icon
39 #if defined(__WXGTK__) || defined(__WXX11__) || defined(__WXMOTIF__) || defined(__WXMAC__) || defined(__WXMGL__)
40 #include "mondrian.xpm"
41 #endif
42
43 // ----------------------------------------------------------------------------
44 // private classes
45 // ----------------------------------------------------------------------------
46
47 // Define a new application type, each program should derive a class from wxApp
48 class MyApp : public wxApp
49 {
50 public:
51 // override base class virtuals
52 // ----------------------------
53
54 // this one is called on application startup and is a good place for the app
55 // initialization (doing it here and not in the ctor allows to have an error
56 // return: if OnInit() returns false, the application terminates)
57 virtual bool OnInit();
58 };
59
60 // Define a new frame type: this is going to be our main frame
61 class MyFrame : public wxFrame
62 {
63 public:
64 // ctor(s)
65 MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size);
66
67 // event handlers (these functions should _not_ be virtual)
68 void OnQuit(wxCommandEvent& event);
69 void OnAbout(wxCommandEvent& event);
70
71 private:
72 // any class wishing to process wxWidgets events must use this macro
73 DECLARE_EVENT_TABLE()
74 };
75
76 // ----------------------------------------------------------------------------
77 // constants
78 // ----------------------------------------------------------------------------
79
80 // IDs for the controls and the menu commands
81 enum
82 {
83 // menu items
84 Minimal_Quit = 1
85 };
86
87 // ----------------------------------------------------------------------------
88 // event tables and other macros for wxWidgets
89 // ----------------------------------------------------------------------------
90
91 // the event tables connect the wxWidgets events with the functions (event
92 // handlers) which process them. It can be also done at run-time, but for the
93 // simple menu events like this the static method is much simpler.
94 BEGIN_EVENT_TABLE(MyFrame, wxFrame)
95 EVT_MENU(Minimal_Quit, MyFrame::OnQuit)
96 EVT_MENU(wxID_ABOUT, MyFrame::OnAbout)
97 END_EVENT_TABLE()
98
99 // Create a new application object: this macro will allow wxWidgets to create
100 // the application object during program execution (it's better than using a
101 // static object for many reasons) and also declares the accessor function
102 // wxGetApp() which will return the reference of the right type (i.e. MyApp and
103 // not wxApp)
104 IMPLEMENT_APP(MyApp)
105
106 // ============================================================================
107 // implementation
108 // ============================================================================
109
110 // ----------------------------------------------------------------------------
111 // the application class
112 // ----------------------------------------------------------------------------
113
114 // `Main program' equivalent: the program execution "starts" here
115 bool MyApp::OnInit()
116 {
117 if ( !wxApp::OnInit() )
118 return false;
119
120 // Create the main application window
121 MyFrame *frame = new MyFrame(_T("Proportional resize"),
122 wxPoint(50, 50), wxSize(450, 340));
123
124 // Show it and tell the application that it's our main window
125 // @@@ what does it do exactly, in fact? is it necessary here?
126 frame->Show(true);
127 SetTopWindow(frame);
128
129 // success: wxApp::OnRun() will be called which will enter the main message
130 // loop and the application will run. If we returned false here, the
131 // application would exit immediately.
132 return true;
133 }
134
135 // ----------------------------------------------------------------------------
136 // main frame
137 // ----------------------------------------------------------------------------
138
139 // frame constructor
140 MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size)
141 : wxFrame((wxFrame *)NULL, wxID_ANY, title, pos, size)
142 {
143 // set the frame icon
144 SetIcon(wxICON(mondrian));
145
146 // create a menu bar
147 wxMenu *menuFile = new wxMenu(_T(""), wxMENU_TEAROFF);
148
149 menuFile->Append(wxID_ABOUT, _T("&About...\tCtrl-A"), _T("Show about dialog"));
150 menuFile->AppendSeparator();
151 menuFile->Append(Minimal_Quit, _T("E&xit\tAlt-X"), _T("Quit this program"));
152
153 // now append the freshly created menu to the menu bar...
154 wxMenuBar *menuBar = new wxMenuBar();
155 menuBar->Append(menuFile, _T("&File"));
156
157 // ... and attach this menu bar to the frame
158 SetMenuBar(menuBar);
159
160 #if wxUSE_STATUSBAR
161 // create a status bar just for fun (by default with 1 pane only)
162 CreateStatusBar(1);
163 SetStatusText(_T("Resize the frame to see how controls react"));
164 #endif // wxUSE_STATUSBAR
165
166 #if wxUSE_STATLINE
167 #define AddLine(orient) \
168 Add( new wxStaticLine( this, wxID_ANY, wxDefaultPosition, wxSize(2,2), orient), \
169 0, wxEXPAND)
170 #else
171 #define AddLine(orient) \
172 Add( 2, 2)
173 #endif // wxUSE_STATLINE
174
175 #define AddButton(label,align) Add( \
176 new wxButton( this, wxID_ANY, label, wxDefaultPosition, wxSize(100,50)), \
177 1, wxSHAPED | align)
178
179 wxBoxSizer *topsizer = new wxBoxSizer( wxVERTICAL );
180 // top row -- top-aligned
181 wxBoxSizer *hsizer1 = new wxBoxSizer( wxHORIZONTAL );
182 hsizer1->AddButton( _T("one"), wxALIGN_LEFT | wxALIGN_TOP);
183 hsizer1->AddLine(wxVERTICAL);
184 hsizer1->AddButton( _T("two"), wxALIGN_CENTER_HORIZONTAL | wxALIGN_TOP);
185 hsizer1->AddLine(wxVERTICAL);
186 hsizer1->AddButton( _T("three"), wxALIGN_RIGHT | wxALIGN_TOP);
187
188 topsizer->Add(hsizer1, 1, wxEXPAND);
189 topsizer->AddLine(wxHORIZONTAL);
190
191 wxBoxSizer *hsizer2 = new wxBoxSizer( wxHORIZONTAL );
192 hsizer2->AddButton( _T("four"), wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL);
193 hsizer2->AddLine(wxVERTICAL);
194 // sizer that preserves it's shape
195 wxBoxSizer *vsizer = new wxBoxSizer( wxVERTICAL );
196 vsizer->Add(
197 new wxButton( this, wxID_ANY, _T("up"), wxDefaultPosition, wxSize(100,25) ),
198 1, wxEXPAND);
199
200 vsizer->Add(
201 new wxButton( this, wxID_ANY, _T("down"), wxDefaultPosition, wxSize(100,25) ),
202 1, wxEXPAND);
203
204 hsizer2->Add(vsizer, 1, wxSHAPED | wxALIGN_CENTER);
205 hsizer2->AddLine(wxVERTICAL);
206 hsizer2->AddButton( _T("six"), wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL);
207
208 topsizer->Add(hsizer2, 1, wxEXPAND);
209 topsizer->AddLine(wxHORIZONTAL);
210
211 wxBoxSizer *hsizer3 = new wxBoxSizer( wxHORIZONTAL );
212 hsizer3->AddButton( _T("seven"), wxALIGN_LEFT | wxALIGN_BOTTOM);
213 hsizer3->AddLine(wxVERTICAL);
214 hsizer3->AddButton( _T("eight"), wxALIGN_CENTER_HORIZONTAL | wxALIGN_BOTTOM);
215 hsizer3->AddLine(wxVERTICAL);
216 // wxEXPAND should have no effect
217 hsizer3->AddButton( _T("nine"), wxEXPAND | wxALIGN_RIGHT | wxALIGN_BOTTOM);
218
219 topsizer->Add(hsizer3, 1, wxEXPAND);
220
221 // set frame to minimum size
222 topsizer->Fit( this );
223
224 // don't allow frame to get smaller than what the sizers tell ye
225 // topsizer->SetSizeHints( this );
226
227 SetSizer( topsizer );
228 }
229
230
231 // event handlers
232
233 void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
234 {
235 // true is to force the frame to close
236 Close(true);
237 }
238
239 void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
240 {
241 wxString msg;
242 msg.Printf( _T("This is the about dialog of proportional sizer test.\n")
243 _T("Welcome to %s")
244 #ifdef wxBETA_NUMBER
245 _T(" (beta %d)!")
246 #endif // wxBETA_NUMBER
247 , wxVERSION_STRING
248 #ifdef wxBETA_NUMBER
249 , wxBETA_NUMBER
250 #endif // wxBETA_NUMBER
251 );
252
253 wxMessageBox(msg, _T("About Shaped Sizer"), wxOK | wxICON_INFORMATION, this);
254 }