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