]>
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 | // ---------------------------------------------------------------------------- | |
be2577e4 RD |
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 | |
be5a51fb | 28 | // need because it includes almost all "standard" wxWidgets headers |
be2577e4 RD |
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 | |
618f2efa | 39 | #if defined(__WXGTK__) || defined(__WXX11__) || defined(__WXMOTIF__) || defined(__WXMAC__) || defined(__WXMGL__) |
be2577e4 RD |
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: | |
be5a51fb | 72 | // any class wishing to process wxWidgets events must use this macro |
be2577e4 RD |
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 | |
004f4002 | 84 | Minimal_Quit = 1 |
be2577e4 RD |
85 | }; |
86 | ||
87 | // ---------------------------------------------------------------------------- | |
be5a51fb | 88 | // event tables and other macros for wxWidgets |
be2577e4 RD |
89 | // ---------------------------------------------------------------------------- |
90 | ||
be5a51fb | 91 | // the event tables connect the wxWidgets events with the functions (event |
be2577e4 RD |
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) | |
aec18ff7 | 96 | EVT_MENU(wxID_ABOUT, MyFrame::OnAbout) |
be2577e4 RD |
97 | END_EVENT_TABLE() |
98 | ||
be5a51fb | 99 | // Create a new application object: this macro will allow wxWidgets to create |
be2577e4 RD |
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 | // Create the main application window | |
600683ca | 118 | MyFrame *frame = new MyFrame(_T("Proportional resize"), |
be2577e4 RD |
119 | wxPoint(50, 50), wxSize(450, 340)); |
120 | ||
121 | // Show it and tell the application that it's our main window | |
122 | // @@@ what does it do exactly, in fact? is it necessary here? | |
b62ca03d | 123 | frame->Show(true); |
be2577e4 RD |
124 | SetTopWindow(frame); |
125 | ||
126 | // success: wxApp::OnRun() will be called which will enter the main message | |
b62ca03d | 127 | // loop and the application will run. If we returned false here, the |
be2577e4 | 128 | // application would exit immediately. |
b62ca03d | 129 | return true; |
be2577e4 RD |
130 | } |
131 | ||
132 | // ---------------------------------------------------------------------------- | |
133 | // main frame | |
134 | // ---------------------------------------------------------------------------- | |
135 | ||
136 | // frame constructor | |
137 | MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size) | |
b62ca03d | 138 | : wxFrame((wxFrame *)NULL, wxID_ANY, title, pos, size) |
be2577e4 RD |
139 | { |
140 | // set the frame icon | |
141 | SetIcon(wxICON(mondrian)); | |
142 | ||
143 | // create a menu bar | |
600683ca | 144 | wxMenu *menuFile = new wxMenu(_T(""), wxMENU_TEAROFF); |
be2577e4 | 145 | |
600683ca | 146 | menuFile->Append(wxID_ABOUT, _T("&About...\tCtrl-A"), _T("Show about dialog")); |
be2577e4 | 147 | menuFile->AppendSeparator(); |
600683ca | 148 | menuFile->Append(Minimal_Quit, _T("E&xit\tAlt-X"), _T("Quit this program")); |
be2577e4 RD |
149 | |
150 | // now append the freshly created menu to the menu bar... | |
151 | wxMenuBar *menuBar = new wxMenuBar(); | |
600683ca | 152 | menuBar->Append(menuFile, _T("&File")); |
be2577e4 RD |
153 | |
154 | // ... and attach this menu bar to the frame | |
155 | SetMenuBar(menuBar); | |
156 | ||
157 | #if wxUSE_STATUSBAR | |
158 | // create a status bar just for fun (by default with 1 pane only) | |
159 | CreateStatusBar(1); | |
600683ca | 160 | SetStatusText(_T("Resize the frame to see how controls react")); |
be2577e4 RD |
161 | #endif // wxUSE_STATUSBAR |
162 | ||
cbf311dd WS |
163 | #if wxUSE_STATLINE |
164 | #define AddLine(orient) \ | |
165 | Add( new wxStaticLine( this, wxID_ANY, wxDefaultPosition, wxSize(2,2), orient), \ | |
166 | 0, wxEXPAND) | |
167 | #else | |
168 | #define AddLine(orient) \ | |
169 | Add( 2, 2) | |
170 | #endif // wxUSE_STATLINE | |
aec18ff7 | 171 | |
be2577e4 | 172 | #define AddButton(label,align) Add( \ |
b62ca03d | 173 | new wxButton( this, wxID_ANY, label, wxDefaultPosition, wxSize(100,50)), \ |
aec18ff7 MB |
174 | 1, wxSHAPED | align) |
175 | ||
176 | wxBoxSizer *topsizer = new wxBoxSizer( wxVERTICAL ); | |
177 | // top row -- top-aligned | |
178 | wxBoxSizer *hsizer1 = new wxBoxSizer( wxHORIZONTAL ); | |
600683ca | 179 | hsizer1->AddButton( _T("one"), wxALIGN_LEFT | wxALIGN_TOP); |
aec18ff7 | 180 | hsizer1->AddLine(wxVERTICAL); |
600683ca | 181 | hsizer1->AddButton( _T("two"), wxALIGN_CENTER_HORIZONTAL | wxALIGN_TOP); |
aec18ff7 | 182 | hsizer1->AddLine(wxVERTICAL); |
600683ca | 183 | hsizer1->AddButton( _T("three"), wxALIGN_RIGHT | wxALIGN_TOP); |
aec18ff7 MB |
184 | |
185 | topsizer->Add(hsizer1, 1, wxEXPAND); | |
186 | topsizer->AddLine(wxHORIZONTAL); | |
187 | ||
188 | wxBoxSizer *hsizer2 = new wxBoxSizer( wxHORIZONTAL ); | |
600683ca | 189 | hsizer2->AddButton( _T("four"), wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL); |
aec18ff7 MB |
190 | hsizer2->AddLine(wxVERTICAL); |
191 | // sizer that preserves it's shape | |
192 | wxBoxSizer *vsizer = new wxBoxSizer( wxVERTICAL ); | |
193 | vsizer->Add( | |
b62ca03d | 194 | new wxButton( this, wxID_ANY, _T("up"), wxDefaultPosition, wxSize(100,25) ), |
aec18ff7 MB |
195 | 1, wxEXPAND); |
196 | ||
197 | vsizer->Add( | |
b62ca03d | 198 | new wxButton( this, wxID_ANY, _T("down"), wxDefaultPosition, wxSize(100,25) ), |
aec18ff7 MB |
199 | 1, wxEXPAND); |
200 | ||
201 | hsizer2->Add(vsizer, 1, wxSHAPED | wxALIGN_CENTER); | |
202 | hsizer2->AddLine(wxVERTICAL); | |
600683ca | 203 | hsizer2->AddButton( _T("six"), wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL); |
aec18ff7 MB |
204 | |
205 | topsizer->Add(hsizer2, 1, wxEXPAND); | |
206 | topsizer->AddLine(wxHORIZONTAL); | |
207 | ||
208 | wxBoxSizer *hsizer3 = new wxBoxSizer( wxHORIZONTAL ); | |
600683ca | 209 | hsizer3->AddButton( _T("seven"), wxALIGN_LEFT | wxALIGN_BOTTOM); |
aec18ff7 | 210 | hsizer3->AddLine(wxVERTICAL); |
600683ca | 211 | hsizer3->AddButton( _T("eight"), wxALIGN_CENTER_HORIZONTAL | wxALIGN_BOTTOM); |
aec18ff7 MB |
212 | hsizer3->AddLine(wxVERTICAL); |
213 | // wxEXPAND should have no effect | |
600683ca | 214 | hsizer3->AddButton( _T("nine"), wxEXPAND | wxALIGN_RIGHT | wxALIGN_BOTTOM); |
aec18ff7 MB |
215 | |
216 | topsizer->Add(hsizer3, 1, wxEXPAND); | |
217 | ||
218 | // set frame to minimum size | |
219 | topsizer->Fit( this ); | |
220 | ||
221 | // don't allow frame to get smaller than what the sizers tell ye | |
222 | // topsizer->SetSizeHints( this ); | |
223 | ||
224 | SetSizer( topsizer ); | |
be2577e4 RD |
225 | } |
226 | ||
227 | ||
228 | // event handlers | |
229 | ||
230 | void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event)) | |
231 | { | |
b62ca03d WS |
232 | // true is to force the frame to close |
233 | Close(true); | |
be2577e4 RD |
234 | } |
235 | ||
236 | void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event)) | |
237 | { | |
238 | wxString msg; | |
239 | msg.Printf( _T("This is the about dialog of proportional sizer test.\n") | |
240 | _T("Welcome to %s") | |
241 | #ifdef wxBETA_NUMBER | |
242 | _T(" (beta %d)!") | |
243 | #endif // wxBETA_NUMBER | |
244 | , wxVERSION_STRING | |
245 | #ifdef wxBETA_NUMBER | |
246 | , wxBETA_NUMBER | |
247 | #endif // wxBETA_NUMBER | |
248 | ); | |
249 | ||
600683ca | 250 | wxMessageBox(msg, _T("About Shaped Sizer"), wxOK | wxICON_INFORMATION, this); |
be2577e4 | 251 | } |