]>
Commit | Line | Data |
---|---|---|
c801d85f KB |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: layout.cpp | |
3 | // Purpose: Layout sample | |
4 | // Author: Julian Smart | |
7235f8e1 | 5 | // Modified by: Robin Dunn, Vadim Zeitlin |
c801d85f KB |
6 | // Created: 04/01/98 |
7 | // RCS-ID: $Id$ | |
7235f8e1 VZ |
8 | // Copyright: (c) 1998 Julian Smart |
9 | // 2005 Vadim Zeitlin | |
2f6c54eb | 10 | // Licence: wxWindows license |
c801d85f KB |
11 | ///////////////////////////////////////////////////////////////////////////// |
12 | ||
9e023db7 VZ |
13 | // ---------------------------------------------------------------------------- |
14 | // headers | |
15 | // ---------------------------------------------------------------------------- | |
16 | ||
c801d85f KB |
17 | // For compilers that support precompilation, includes "wx/wx.h". |
18 | #include "wx/wxprec.h" | |
19 | ||
20 | #ifdef __BORLANDC__ | |
21 | #pragma hdrstop | |
22 | #endif | |
23 | ||
24 | #ifndef WX_PRECOMP | |
25 | #include "wx/wx.h" | |
26 | #endif | |
27 | ||
c62ac5b6 | 28 | #include "wx/sizer.h" |
20b35a69 | 29 | #include "wx/gbsizer.h" |
61d514bb | 30 | #include "wx/statline.h" |
83edc0a5 | 31 | #include "wx/notebook.h" |
7235f8e1 | 32 | #include "wx/spinctrl.h" |
c62ac5b6 | 33 | |
c801d85f KB |
34 | #include "layout.h" |
35 | ||
9e023db7 VZ |
36 | // ---------------------------------------------------------------------------- |
37 | // MyApp | |
38 | // ---------------------------------------------------------------------------- | |
c801d85f KB |
39 | |
40 | IMPLEMENT_APP(MyApp) | |
41 | ||
83edc0a5 | 42 | bool MyApp::OnInit() |
c801d85f KB |
43 | { |
44 | // Create the main frame window | |
9e023db7 VZ |
45 | MyFrame *frame = new MyFrame; |
46 | ||
9230b621 | 47 | frame->Show(true); |
9e023db7 | 48 | |
9230b621 | 49 | return true; |
9e023db7 VZ |
50 | } |
51 | ||
52 | // ---------------------------------------------------------------------------- | |
53 | // MyFrame | |
54 | // ---------------------------------------------------------------------------- | |
c801d85f | 55 | |
9e023db7 VZ |
56 | BEGIN_EVENT_TABLE(MyFrame, wxFrame) |
57 | EVT_MENU(LAYOUT_ABOUT, MyFrame::OnAbout) | |
58 | EVT_MENU(LAYOUT_QUIT, MyFrame::OnQuit) | |
c801d85f | 59 | |
7235f8e1 | 60 | EVT_MENU(LAYOUT_TEST_PROPORTIONS, MyFrame::TestProportions) |
9e023db7 VZ |
61 | EVT_MENU(LAYOUT_TEST_SIZER, MyFrame::TestFlexSizers) |
62 | EVT_MENU(LAYOUT_TEST_NB_SIZER, MyFrame::TestNotebookSizers) | |
925e9792 | 63 | EVT_MENU(LAYOUT_TEST_GB_SIZER, MyFrame::TestGridBagSizer) |
92c0c172 | 64 | EVT_MENU(LAYOUT_TEST_SET_MINIMAL, MyFrame::TestSetMinimal) |
a1a3bffc | 65 | EVT_MENU(LAYOUT_TEST_NESTED, MyFrame::TestNested) |
9e023db7 | 66 | END_EVENT_TABLE() |
c801d85f | 67 | |
9e023db7 VZ |
68 | // Define my frame constructor |
69 | MyFrame::MyFrame() | |
be5a51fb | 70 | : wxFrame(NULL, wxID_ANY, _T("wxWidgets Layout Demo"), |
9e023db7 VZ |
71 | wxDefaultPosition, wxDefaultSize, |
72 | wxDEFAULT_FRAME_STYLE | wxNO_FULL_REPAINT_ON_RESIZE) | |
73 | { | |
c801d85f KB |
74 | // Make a menubar |
75 | wxMenu *file_menu = new wxMenu; | |
76 | ||
7235f8e1 VZ |
77 | file_menu->Append(LAYOUT_TEST_PROPORTIONS, _T("&Proportions demo...\tF1")); |
78 | file_menu->Append(LAYOUT_TEST_SIZER, _T("Test wx&FlexSizer...\tF2")); | |
79 | file_menu->Append(LAYOUT_TEST_NB_SIZER, _T("Test ¬ebook sizers...\tF3")); | |
80 | file_menu->Append(LAYOUT_TEST_GB_SIZER, _T("Test &gridbag sizer...\tF4")); | |
92c0c172 | 81 | file_menu->Append(LAYOUT_TEST_SET_MINIMAL, _T("Test Set&ItemMinSize...\tF5")); |
a1a3bffc | 82 | file_menu->Append(LAYOUT_TEST_NESTED, _T("Test nested sizer in a wxPanel...\tF6")); |
c801d85f KB |
83 | |
84 | file_menu->AppendSeparator(); | |
9e023db7 | 85 | file_menu->Append(LAYOUT_QUIT, _T("E&xit"), _T("Quit program")); |
c801d85f KB |
86 | |
87 | wxMenu *help_menu = new wxMenu; | |
7235f8e1 | 88 | help_menu->Append(LAYOUT_ABOUT, _T("&About"), _T("About layout demo...")); |
c801d85f | 89 | |
9e023db7 | 90 | wxMenuBar *menu_bar = new wxMenuBar; |
c801d85f | 91 | |
42ed7532 MB |
92 | menu_bar->Append(file_menu, _T("&File")); |
93 | menu_bar->Append(help_menu, _T("&Help")); | |
c801d85f KB |
94 | |
95 | // Associate the menu bar with the frame | |
9e023db7 VZ |
96 | SetMenuBar(menu_bar); |
97 | ||
8520f137 | 98 | #if wxUSE_STATUSBAR |
9e023db7 | 99 | CreateStatusBar(2); |
be5a51fb | 100 | SetStatusText(_T("wxWidgets layout demo")); |
8520f137 | 101 | #endif // wxUSE_STATUSBAR |
9e023db7 | 102 | |
6bbb8a8d WS |
103 | wxPanel* p = new wxPanel(this, wxID_ANY); |
104 | ||
9e023db7 VZ |
105 | // we want to get a dialog that is stretchable because it |
106 | // has a text ctrl in the middle. at the bottom, we have | |
107 | // two buttons which. | |
108 | ||
109 | wxBoxSizer *topsizer = new wxBoxSizer( wxVERTICAL ); | |
110 | ||
111 | // 1) top: create wxStaticText with minimum size equal to its default size | |
112 | topsizer->Add( | |
bdbb07ed | 113 | new wxStaticText( p, wxID_ANY, _T("An explanation (wxALIGN_RIGHT).") ), |
e5544e77 | 114 | wxSizerFlags().Align(wxALIGN_RIGHT).Border(wxALL & ~wxBOTTOM, 5)); |
9e023db7 VZ |
115 | |
116 | // 2) top: create wxTextCtrl with minimum size (100x60) | |
117 | topsizer->Add( | |
bdbb07ed | 118 | new wxTextCtrl( p, wxID_ANY, _T("My text (wxEXPAND)."), wxDefaultPosition, wxSize(100,60), wxTE_MULTILINE), |
e5544e77 | 119 | wxSizerFlags(1).Expand().Border(wxALL, 5)); |
9e023db7 VZ |
120 | |
121 | // 2.5) Gratuitous test of wxStaticBoxSizers | |
122 | wxBoxSizer *statsizer = new wxStaticBoxSizer( | |
bdbb07ed | 123 | new wxStaticBox(p, wxID_ANY, _T("A wxStaticBoxSizer")), wxVERTICAL ); |
9e023db7 | 124 | statsizer->Add( |
bdbb07ed | 125 | new wxStaticText(p, wxID_ANY, _T("And some TEXT inside it")), |
e5544e77 VZ |
126 | wxSizerFlags().Center().Border(wxALL, 30)); |
127 | topsizer->Add( | |
128 | statsizer, | |
129 | wxSizerFlags(1).Expand().Border(wxALL, 10)); | |
9e023db7 VZ |
130 | |
131 | // 2.7) And a test of wxGridSizer | |
132 | wxGridSizer *gridsizer = new wxGridSizer(2, 5, 5); | |
bdbb07ed | 133 | gridsizer->Add(new wxStaticText(p, wxID_ANY, _T("Label")), |
e5544e77 | 134 | wxSizerFlags().Align(wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL)); |
bdbb07ed | 135 | gridsizer->Add(new wxTextCtrl(p, wxID_ANY, _T("Grid sizer demo")), |
e5544e77 | 136 | wxSizerFlags(1).Align(wxGROW | wxALIGN_CENTER_VERTICAL)); |
bdbb07ed | 137 | gridsizer->Add(new wxStaticText(p, wxID_ANY, _T("Another label")), |
e5544e77 | 138 | wxSizerFlags().Align(wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL)); |
bdbb07ed | 139 | gridsizer->Add(new wxTextCtrl(p, wxID_ANY, _T("More text")), |
e5544e77 | 140 | wxSizerFlags(1).Align(wxGROW | wxALIGN_CENTER_VERTICAL)); |
bdbb07ed | 141 | gridsizer->Add(new wxStaticText(p, wxID_ANY, _T("Final label")), |
e5544e77 | 142 | wxSizerFlags().Align(wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL)); |
bdbb07ed | 143 | gridsizer->Add(new wxTextCtrl(p, wxID_ANY, _T("And yet more text")), |
e5544e77 VZ |
144 | wxSizerFlags().Align(wxGROW | wxALIGN_CENTER_VERTICAL)); |
145 | topsizer->Add( | |
146 | gridsizer, | |
147 | wxSizerFlags().Proportion(1).Expand().Border(wxALL, 10)); | |
9e023db7 VZ |
148 | |
149 | ||
4aa0bd9b | 150 | #if wxUSE_STATLINE |
9e023db7 VZ |
151 | // 3) middle: create wxStaticLine with minimum size (3x3) |
152 | topsizer->Add( | |
bdbb07ed | 153 | new wxStaticLine( p, wxID_ANY, wxDefaultPosition, wxSize(3,3), wxHORIZONTAL), |
e5544e77 | 154 | wxSizerFlags().Expand()); |
4aa0bd9b | 155 | #endif // wxUSE_STATLINE |
9e023db7 VZ |
156 | |
157 | ||
158 | // 4) bottom: create two centred wxButtons | |
159 | wxBoxSizer *button_box = new wxBoxSizer( wxHORIZONTAL ); | |
160 | button_box->Add( | |
bdbb07ed | 161 | new wxButton( p, wxID_ANY, _T("Two buttons in a box") ), |
e5544e77 | 162 | wxSizerFlags().Border(wxALL, 7)); |
9e023db7 | 163 | button_box->Add( |
bdbb07ed | 164 | new wxButton( p, wxID_ANY, _T("(wxCENTER)") ), |
e5544e77 | 165 | wxSizerFlags().Border(wxALL, 7)); |
9e023db7 | 166 | |
e5544e77 | 167 | topsizer->Add(button_box, wxSizerFlags().Center()); |
9e023db7 | 168 | |
bdbb07ed | 169 | p->SetSizer( topsizer ); |
6bbb8a8d | 170 | |
9e023db7 VZ |
171 | // don't allow frame to get smaller than what the sizers tell it and also set |
172 | // the initial size as calculated by the sizers | |
173 | topsizer->SetSizeHints( this ); | |
9e023db7 VZ |
174 | } |
175 | ||
7235f8e1 | 176 | void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event)) |
9e023db7 | 177 | { |
9230b621 | 178 | Close(true); |
9e023db7 VZ |
179 | } |
180 | ||
7235f8e1 VZ |
181 | void MyFrame::TestProportions(wxCommandEvent& WXUNUSED(event)) |
182 | { | |
183 | (new MyProportionsFrame(this))->Show(); | |
184 | } | |
185 | ||
9e023db7 VZ |
186 | void MyFrame::TestFlexSizers(wxCommandEvent& WXUNUSED(event) ) |
187 | { | |
188 | MyFlexSizerFrame *newFrame = new MyFlexSizerFrame(_T("Flex Sizer Test Frame"), 50, 50); | |
9230b621 | 189 | newFrame->Show(true); |
9e023db7 VZ |
190 | } |
191 | ||
192 | void MyFrame::TestNotebookSizers(wxCommandEvent& WXUNUSED(event) ) | |
193 | { | |
194 | MySizerDialog dialog( this, _T("Notebook Sizer Test Dialog") ); | |
195 | ||
196 | dialog.ShowModal(); | |
197 | } | |
198 | ||
92c0c172 RR |
199 | void MyFrame::TestSetMinimal(wxCommandEvent& WXUNUSED(event) ) |
200 | { | |
201 | MySimpleSizerFrame *newFrame = new MySimpleSizerFrame(_T("Simple Sizer Test Frame"), 50, 50); | |
202 | newFrame->Show(true); | |
203 | } | |
204 | ||
a1a3bffc RR |
205 | void MyFrame::TestNested(wxCommandEvent& WXUNUSED(event) ) |
206 | { | |
207 | MyNestedSizerFrame *newFrame = new MyNestedSizerFrame(_T("Nested Sizer Test Frame"), 50, 50); | |
208 | newFrame->Show(true); | |
209 | } | |
210 | ||
c801d85f | 211 | |
9e023db7 VZ |
212 | void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event) ) |
213 | { | |
be5a51fb | 214 | (void)wxMessageBox(_T("wxWidgets GUI library layout demo\n"), |
9e023db7 VZ |
215 | _T("About Layout Demo"), wxOK|wxICON_INFORMATION); |
216 | } | |
217 | ||
20b35a69 RD |
218 | void MyFrame::TestGridBagSizer(wxCommandEvent& WXUNUSED(event) ) |
219 | { | |
220 | MyGridBagSizerFrame *newFrame = new | |
221 | MyGridBagSizerFrame(_T("wxGridBagSizer Test Frame"), 50, 50); | |
9230b621 | 222 | newFrame->Show(true); |
20b35a69 RD |
223 | } |
224 | ||
7235f8e1 VZ |
225 | // ---------------------------------------------------------------------------- |
226 | // MyProportionsFrame | |
227 | // ---------------------------------------------------------------------------- | |
228 | ||
229 | MyProportionsFrame::MyProportionsFrame(wxFrame *parent) | |
230 | : wxFrame(parent, wxID_ANY, _T("Box Sizer Proportions Demo")) | |
231 | { | |
232 | size_t n; | |
233 | ||
234 | // create the controls | |
235 | wxPanel *panel = new wxPanel(this, wxID_ANY); | |
236 | for ( n = 0; n < WXSIZEOF(m_spins); n++ ) | |
237 | { | |
238 | m_spins[n] = new wxSpinCtrl(panel); | |
239 | m_spins[n]->SetValue(n); | |
240 | } | |
241 | ||
242 | // lay them out | |
243 | m_sizer = new wxStaticBoxSizer(wxHORIZONTAL, panel, | |
244 | _T("Try changing elements proportions and resizing the window")); | |
245 | for ( n = 0; n < WXSIZEOF(m_spins); n++ ) | |
246 | m_sizer->Add(m_spins[n], wxSizerFlags().Border()); | |
247 | ||
248 | // put everything together | |
249 | panel->SetSizer(m_sizer); | |
250 | wxSizer *sizerTop = new wxBoxSizer(wxVERTICAL); | |
251 | sizerTop->Add(panel, wxSizerFlags(1).Expand().Border()); | |
252 | UpdateProportions(); | |
253 | SetSizerAndFit(sizerTop); | |
254 | ||
255 | // and connect the events | |
256 | Connect(wxEVT_COMMAND_TEXT_UPDATED, | |
257 | wxCommandEventHandler(MyProportionsFrame::OnProportionUpdated)); | |
258 | Connect(wxEVT_COMMAND_SPINCTRL_UPDATED, | |
259 | wxSpinEventHandler(MyProportionsFrame::OnProportionChanged)); | |
260 | } | |
261 | ||
262 | void MyProportionsFrame::UpdateProportions() | |
263 | { | |
264 | for ( size_t n = 0; n < WXSIZEOF(m_spins); n++ ) | |
265 | { | |
266 | m_sizer->GetItem(n)->SetProportion(m_spins[n]->GetValue()); | |
267 | } | |
268 | ||
269 | m_sizer->Layout(); | |
270 | } | |
271 | ||
272 | void MyProportionsFrame::OnProportionUpdated(wxCommandEvent& WXUNUSED(event)) | |
273 | { | |
274 | UpdateProportions(); | |
275 | } | |
276 | ||
277 | void MyProportionsFrame::OnProportionChanged(wxSpinEvent& WXUNUSED(event)) | |
278 | { | |
279 | UpdateProportions(); | |
280 | } | |
20b35a69 | 281 | |
9e023db7 VZ |
282 | // ---------------------------------------------------------------------------- |
283 | // MyFlexSizerFrame | |
284 | // ---------------------------------------------------------------------------- | |
c62ac5b6 | 285 | |
bdbb07ed | 286 | void MyFlexSizerFrame::InitFlexSizer(wxFlexGridSizer *sizer, wxWindow* parent) |
c801d85f | 287 | { |
9e023db7 VZ |
288 | for ( int i = 0; i < 3; i++ ) |
289 | { | |
290 | for ( int j = 0; j < 3; j++ ) | |
291 | { | |
292 | sizer->Add(new wxStaticText | |
293 | ( | |
bdbb07ed | 294 | parent, |
9230b621 | 295 | wxID_ANY, |
9e023db7 VZ |
296 | wxString::Format(_T("(%d, %d)"), i + 1, j + 1), |
297 | wxDefaultPosition, | |
298 | wxDefaultSize, | |
299 | wxALIGN_CENTER | |
300 | ), | |
301 | 0, wxEXPAND | wxALIGN_CENTER_VERTICAL | wxALL, 3); | |
302 | } | |
303 | } | |
c801d85f KB |
304 | } |
305 | ||
9e023db7 | 306 | MyFlexSizerFrame::MyFlexSizerFrame(const wxChar *title, int x, int y ) |
9230b621 | 307 | : wxFrame(NULL, wxID_ANY, title, wxPoint(x, y) ) |
c801d85f | 308 | { |
9e023db7 | 309 | wxFlexGridSizer *sizerFlex; |
6bbb8a8d | 310 | wxPanel* p = new wxPanel(this, wxID_ANY); |
9e023db7 VZ |
311 | |
312 | // consttuct the first column | |
313 | wxSizer *sizerCol1 = new wxBoxSizer(wxVERTICAL); | |
bdbb07ed | 314 | sizerCol1->Add(new wxStaticText(p, wxID_ANY, _T("Ungrowable:")), 0, wxCENTER | wxTOP, 20); |
9e023db7 | 315 | sizerFlex = new wxFlexGridSizer(3, 3); |
bdbb07ed | 316 | InitFlexSizer(sizerFlex, p); |
9e023db7 VZ |
317 | sizerCol1->Add(sizerFlex, 1, wxALL | wxEXPAND, 10); |
318 | ||
bdbb07ed | 319 | sizerCol1->Add(new wxStaticText(p, wxID_ANY, _T("Growable middle column:")), 0, wxCENTER | wxTOP, 20); |
9e023db7 | 320 | sizerFlex = new wxFlexGridSizer(3, 3); |
bdbb07ed | 321 | InitFlexSizer(sizerFlex, p); |
9e023db7 VZ |
322 | sizerFlex->AddGrowableCol(1); |
323 | sizerCol1->Add(sizerFlex, 1, wxALL | wxEXPAND, 10); | |
324 | ||
bdbb07ed | 325 | sizerCol1->Add(new wxStaticText(p, wxID_ANY, _T("Growable middle row:")), 0, wxCENTER | wxTOP, 20); |
9e023db7 | 326 | sizerFlex = new wxFlexGridSizer(3, 3); |
bdbb07ed | 327 | InitFlexSizer(sizerFlex, p); |
9e023db7 VZ |
328 | sizerFlex->AddGrowableRow(1); |
329 | sizerCol1->Add(sizerFlex, 1, wxALL | wxEXPAND, 10); | |
330 | ||
bdbb07ed | 331 | sizerCol1->Add(new wxStaticText(p, wxID_ANY, _T("All growable columns:")), 0, wxCENTER | wxTOP, 20); |
9e023db7 | 332 | sizerFlex = new wxFlexGridSizer(3, 3); |
bdbb07ed | 333 | InitFlexSizer(sizerFlex, p); |
9e023db7 VZ |
334 | sizerFlex->AddGrowableCol(0, 1); |
335 | sizerFlex->AddGrowableCol(1, 2); | |
336 | sizerFlex->AddGrowableCol(2, 3); | |
337 | sizerCol1->Add(sizerFlex, 1, wxALL | wxEXPAND, 10); | |
338 | ||
339 | // the second one | |
340 | wxSizer *sizerCol2 = new wxBoxSizer(wxVERTICAL); | |
bdbb07ed | 341 | sizerCol2->Add(new wxStaticText(p, wxID_ANY, _T("Growable middle row and column:")), 0, wxCENTER | wxTOP, 20); |
9e023db7 | 342 | sizerFlex = new wxFlexGridSizer(3, 3); |
bdbb07ed | 343 | InitFlexSizer(sizerFlex, p); |
9e023db7 VZ |
344 | sizerFlex->AddGrowableCol(1); |
345 | sizerFlex->AddGrowableRow(1); | |
346 | sizerCol2->Add(sizerFlex, 1, wxALL | wxEXPAND, 10); | |
347 | ||
bdbb07ed | 348 | sizerCol2->Add(new wxStaticText(p, wxID_ANY, _T("Same with horz flex direction")), 0, wxCENTER | wxTOP, 20); |
9e023db7 | 349 | sizerFlex = new wxFlexGridSizer(3, 3); |
bdbb07ed | 350 | InitFlexSizer(sizerFlex, p); |
9e023db7 VZ |
351 | sizerFlex->AddGrowableCol(1); |
352 | sizerFlex->AddGrowableRow(1); | |
353 | sizerFlex->SetFlexibleDirection(wxHORIZONTAL); | |
354 | sizerCol2->Add(sizerFlex, 1, wxALL | wxEXPAND, 10); | |
355 | ||
bdbb07ed | 356 | sizerCol2->Add(new wxStaticText(p, wxID_ANY, _T("Same with grow mode == \"none\"")), 0, wxCENTER | wxTOP, 20); |
9e023db7 | 357 | sizerFlex = new wxFlexGridSizer(3, 3); |
bdbb07ed | 358 | InitFlexSizer(sizerFlex, p); |
9e023db7 VZ |
359 | sizerFlex->AddGrowableCol(1); |
360 | sizerFlex->AddGrowableRow(1); | |
361 | sizerFlex->SetFlexibleDirection(wxHORIZONTAL); | |
362 | sizerFlex->SetNonFlexibleGrowMode(wxFLEX_GROWMODE_NONE); | |
363 | sizerCol2->Add(sizerFlex, 1, wxALL | wxEXPAND, 10); | |
364 | ||
bdbb07ed | 365 | sizerCol2->Add(new wxStaticText(p, wxID_ANY, _T("Same with grow mode == \"all\"")), 0, wxCENTER | wxTOP, 20); |
9e023db7 | 366 | sizerFlex = new wxFlexGridSizer(3, 3); |
bdbb07ed | 367 | InitFlexSizer(sizerFlex, p); |
9e023db7 VZ |
368 | sizerFlex->AddGrowableCol(1); |
369 | sizerFlex->AddGrowableRow(1); | |
370 | sizerFlex->SetFlexibleDirection(wxHORIZONTAL); | |
371 | sizerFlex->SetNonFlexibleGrowMode(wxFLEX_GROWMODE_ALL); | |
372 | sizerCol2->Add(sizerFlex, 1, wxALL | wxEXPAND, 10); | |
373 | ||
374 | // add both columns to grid sizer | |
375 | wxGridSizer *sizerTop = new wxGridSizer(2, 0, 20); | |
376 | sizerTop->Add(sizerCol1, 1, wxEXPAND); | |
377 | sizerTop->Add(sizerCol2, 1, wxEXPAND); | |
378 | ||
bdbb07ed | 379 | p->SetSizer(sizerTop); |
9e023db7 | 380 | sizerTop->SetSizeHints(this); |
c801d85f KB |
381 | } |
382 | ||
9e023db7 VZ |
383 | // ---------------------------------------------------------------------------- |
384 | // MySizerDialog | |
385 | // ---------------------------------------------------------------------------- | |
c801d85f | 386 | |
9e023db7 | 387 | MySizerDialog::MySizerDialog(wxWindow *parent, const wxChar *title) |
9230b621 | 388 | : wxDialog(parent, wxID_ANY, wxString(title)) |
83edc0a5 | 389 | { |
83edc0a5 RR |
390 | // Begin with first hierarchy: a notebook at the top and |
391 | // and OK button at the bottom. | |
392 | ||
393 | wxBoxSizer *topsizer = new wxBoxSizer( wxVERTICAL ); | |
56ac3e75 | 394 | |
9230b621 | 395 | wxNotebook *notebook = new wxNotebook( this, wxID_ANY ); |
adbf2d73 | 396 | topsizer->Add( notebook, 1, wxGROW ); |
56ac3e75 | 397 | |
9e023db7 | 398 | wxButton *button = new wxButton( this, wxID_OK, _T("OK") ); |
83edc0a5 RR |
399 | topsizer->Add( button, 0, wxALIGN_RIGHT | wxALL, 10 ); |
400 | ||
401 | // First page: one big text ctrl | |
9230b621 | 402 | wxTextCtrl *multi = new wxTextCtrl( notebook, wxID_ANY, _T("TextCtrl."), wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE ); |
42ed7532 | 403 | notebook->AddPage( multi, _T("Page One") ); |
56ac3e75 | 404 | |
83edc0a5 | 405 | // Second page: a text ctrl and a button |
9230b621 | 406 | wxPanel *panel = new wxPanel( notebook, wxID_ANY ); |
42ed7532 | 407 | notebook->AddPage( panel, _T("Page Two") ); |
56ac3e75 | 408 | |
f6bcfd97 | 409 | wxSizer *panelsizer = new wxBoxSizer( wxVERTICAL ); |
56ac3e75 | 410 | |
6bbb8a8d | 411 | wxTextCtrl *text = new wxTextCtrl( panel, wxID_ANY, _T("TextLine 1."), wxDefaultPosition, wxSize(250,wxDefaultCoord) ); |
83edc0a5 | 412 | panelsizer->Add( text, 0, wxGROW|wxALL, 30 ); |
6bbb8a8d | 413 | text = new wxTextCtrl( panel, wxID_ANY, _T("TextLine 2."), wxDefaultPosition, wxSize(250,wxDefaultCoord) ); |
83edc0a5 | 414 | panelsizer->Add( text, 0, wxGROW|wxALL, 30 ); |
9230b621 | 415 | wxButton *button2 = new wxButton( panel, wxID_ANY, _T("Hallo") ); |
83edc0a5 | 416 | panelsizer->Add( button2, 0, wxALIGN_RIGHT | wxLEFT|wxRIGHT|wxBOTTOM, 30 ); |
56ac3e75 | 417 | |
9230b621 | 418 | panel->SetAutoLayout( true ); |
83edc0a5 | 419 | panel->SetSizer( panelsizer ); |
56ac3e75 | 420 | |
83edc0a5 | 421 | // Tell dialog to use sizer |
9e023db7 VZ |
422 | SetSizer( topsizer ); |
423 | topsizer->SetSizeHints( this ); | |
c62ac5b6 RR |
424 | } |
425 | ||
20b35a69 RD |
426 | // ---------------------------------------------------------------------------- |
427 | // MyGridBagSizerFrame | |
428 | // ---------------------------------------------------------------------------- | |
429 | ||
430 | // some simple macros to help make the sample code below more clear | |
9230b621 VS |
431 | #define TEXTCTRL(text) new wxTextCtrl(p, wxID_ANY, _T(text)) |
432 | #define MLTEXTCTRL(text) new wxTextCtrl(p, wxID_ANY, _T(text), wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE) | |
20b35a69 RD |
433 | #define POS(r, c) wxGBPosition(r,c) |
434 | #define SPAN(r, c) wxGBSpan(r,c) | |
435 | ||
fbfb8bcc | 436 | const wxChar gbsDescription[] =_T("\ |
77c5e923 RD |
437 | The wxGridBagSizer is similar to the wxFlexGridSizer except the items are explicitly positioned\n\ |
438 | in a virtual cell of the layout grid, and column or row spanning is allowed. For example, this\n\ | |
439 | static text is positioned at (0,0) and it spans 7 columns."); | |
20b35a69 RD |
440 | |
441 | ||
442 | // Some IDs | |
443 | enum { | |
444 | GBS_HIDE_BTN = 1212, | |
445 | GBS_SHOW_BTN, | |
446 | GBS_MOVE_BTN1, | |
447 | GBS_MOVE_BTN2, | |
925e9792 | 448 | |
004f4002 | 449 | GBS_MAX |
20b35a69 RD |
450 | }; |
451 | ||
452 | ||
453 | BEGIN_EVENT_TABLE(MyGridBagSizerFrame, wxFrame) | |
454 | EVT_BUTTON( GBS_HIDE_BTN, MyGridBagSizerFrame::OnHideBtn) | |
455 | EVT_BUTTON( GBS_SHOW_BTN, MyGridBagSizerFrame::OnShowBtn) | |
456 | EVT_BUTTON( GBS_MOVE_BTN1, MyGridBagSizerFrame::OnMoveBtn) | |
457 | EVT_BUTTON( GBS_MOVE_BTN2, MyGridBagSizerFrame::OnMoveBtn) | |
458 | END_EVENT_TABLE() | |
459 | ||
460 | ||
461 | MyGridBagSizerFrame::MyGridBagSizerFrame(const wxChar *title, int x, int y ) | |
9230b621 | 462 | : wxFrame( NULL, wxID_ANY, title, wxPoint(x, y) ) |
20b35a69 | 463 | { |
9230b621 | 464 | wxPanel* p = new wxPanel(this, wxID_ANY); |
20b35a69 RD |
465 | m_panel = p; |
466 | m_gbs = new wxGridBagSizer(); | |
467 | ||
925e9792 | 468 | |
9230b621 | 469 | m_gbs->Add( new wxStaticText(p, wxID_ANY, gbsDescription), |
77c5e923 RD |
470 | POS(0,0), SPAN(1, 7), |
471 | wxALIGN_CENTER | wxALL, 5); | |
925e9792 | 472 | |
20b35a69 RD |
473 | m_gbs->Add( TEXTCTRL("pos(1,0)"), POS(1,0) ); |
474 | m_gbs->Add( TEXTCTRL("pos(1,1)"), POS(1,1) ); | |
475 | m_gbs->Add( TEXTCTRL("pos(2,0)"), POS(2,0) ); | |
476 | m_gbs->Add( TEXTCTRL("pos(2,1)"), POS(2,1) ); | |
477 | m_gbs->Add( MLTEXTCTRL("pos(3,2), span(1,2)\nthis row and col are growable"), | |
478 | POS(3,2), SPAN(1,2), wxEXPAND ); | |
479 | m_gbs->Add( MLTEXTCTRL("pos(4,3)\nspan(3,1)"), | |
480 | POS(4,3), SPAN(3,1), wxEXPAND ); | |
481 | m_gbs->Add( TEXTCTRL("pos(5,4)"), POS(5,4), wxDefaultSpan, wxEXPAND ); | |
482 | m_gbs->Add( TEXTCTRL("pos(6,5)"), POS(6,5), wxDefaultSpan, wxEXPAND ); | |
483 | m_gbs->Add( TEXTCTRL("pos(7,6)"), POS(7,6) ); | |
925e9792 | 484 | |
20b35a69 RD |
485 | //m_gbs->Add( TEXTCTRL("bad position"), POS(4,3) ); // Test for assert |
486 | //m_gbs->Add( TEXTCTRL("bad position"), POS(5,3) ); // Test for assert | |
487 | ||
488 | ||
77c5e923 RD |
489 | m_moveBtn1 = new wxButton(p, GBS_MOVE_BTN1, _T("Move this to (3,6)")); |
490 | m_moveBtn2 = new wxButton(p, GBS_MOVE_BTN2, _T("Move this to (3,6)")); | |
20b35a69 RD |
491 | m_gbs->Add( m_moveBtn1, POS(10,2) ); |
492 | m_gbs->Add( m_moveBtn2, POS(10,3) ); | |
925e9792 | 493 | |
77c5e923 | 494 | m_hideBtn = new wxButton(p, GBS_HIDE_BTN, _T("Hide this item -->")); |
20b35a69 RD |
495 | m_gbs->Add(m_hideBtn, POS(12, 3)); |
496 | ||
6bbb8a8d WS |
497 | m_hideTxt = new wxTextCtrl(p, wxID_ANY, _T("pos(12,4), size(150, wxDefaultCoord)"), |
498 | wxDefaultPosition, wxSize(150,wxDefaultCoord)); | |
20b35a69 | 499 | m_gbs->Add( m_hideTxt, POS(12,4) ); |
925e9792 | 500 | |
77c5e923 | 501 | m_showBtn = new wxButton(p, GBS_SHOW_BTN, _T("<-- Show it again")); |
20b35a69 RD |
502 | m_gbs->Add(m_showBtn, POS(12, 5)); |
503 | m_showBtn->Disable(); | |
504 | ||
505 | m_gbs->Add(10,10, POS(14,0)); | |
925e9792 | 506 | |
20b35a69 RD |
507 | m_gbs->AddGrowableRow(3); |
508 | m_gbs->AddGrowableCol(2); | |
925e9792 | 509 | |
20b35a69 RD |
510 | p->SetSizerAndFit(m_gbs); |
511 | SetClientSize(p->GetSize()); | |
512 | } | |
513 | ||
925e9792 | 514 | |
20b35a69 RD |
515 | void MyGridBagSizerFrame::OnHideBtn(wxCommandEvent&) |
516 | { | |
517 | m_gbs->Hide(m_hideTxt); | |
518 | m_hideBtn->Disable(); | |
519 | m_showBtn->Enable(); | |
520 | m_gbs->Layout(); | |
521 | } | |
522 | ||
523 | void MyGridBagSizerFrame::OnShowBtn(wxCommandEvent&) | |
524 | { | |
525 | m_gbs->Show(m_hideTxt); | |
526 | m_hideBtn->Enable(); | |
527 | m_showBtn->Disable(); | |
528 | m_gbs->Layout(); | |
529 | } | |
530 | ||
531 | ||
532 | void MyGridBagSizerFrame::OnMoveBtn(wxCommandEvent& event) | |
533 | { | |
534 | wxButton* btn = (wxButton*)event.GetEventObject(); | |
535 | wxGBPosition curPos = m_gbs->GetItemPosition(btn); | |
536 | ||
537 | // if it's already at the "other" spot then move it back | |
538 | if (curPos == wxGBPosition(3,6)) | |
539 | { | |
540 | m_gbs->SetItemPosition(btn, m_lastPos); | |
77c5e923 | 541 | btn->SetLabel(_T("Move this to (3,6)")); |
20b35a69 | 542 | } |
925e9792 | 543 | else |
20b35a69 | 544 | { |
77c5e923 RD |
545 | if ( m_gbs->CheckForIntersection(wxGBPosition(3,6), wxGBSpan(1,1)) ) |
546 | wxMessageBox( | |
547 | _T("wxGridBagSizer will not allow items to be in the same cell as\n\ | |
548 | another item, so this operation will fail. You will also get an assert\n\ | |
549 | when compiled in debug mode."), _T("Warning"), wxOK | wxICON_INFORMATION); | |
925e9792 | 550 | |
77c5e923 RD |
551 | if ( m_gbs->SetItemPosition(btn, wxGBPosition(3,6)) ) |
552 | { | |
553 | m_lastPos = curPos; | |
554 | btn->SetLabel(_T("Move it back")); | |
555 | } | |
20b35a69 RD |
556 | } |
557 | m_gbs->Layout(); | |
558 | } | |
92c0c172 RR |
559 | |
560 | // ---------------------------------------------------------------------------- | |
561 | // MySimpleSizerFrame | |
562 | // ---------------------------------------------------------------------------- | |
563 | ||
564 | // Some IDs | |
565 | enum { | |
566 | ID_SET_SMALL = 1300, | |
567 | ID_SET_BIG | |
568 | }; | |
569 | ||
570 | BEGIN_EVENT_TABLE(MySimpleSizerFrame, wxFrame) | |
571 | EVT_MENU( ID_SET_SMALL, MySimpleSizerFrame::OnSetSmallSize) | |
572 | EVT_MENU( ID_SET_BIG, MySimpleSizerFrame::OnSetBigSize) | |
573 | END_EVENT_TABLE() | |
574 | ||
575 | MySimpleSizerFrame::MySimpleSizerFrame(const wxChar *title, int x, int y ) | |
576 | : wxFrame( NULL, wxID_ANY, title, wxPoint(x, y) ) | |
577 | { | |
578 | wxMenu *menu = new wxMenu; | |
6bbb8a8d | 579 | |
92c0c172 RR |
580 | menu->Append(ID_SET_SMALL, _T("Make text control small\tF4")); |
581 | menu->Append(ID_SET_BIG, _T("Make text control big\tF5")); | |
6bbb8a8d | 582 | |
92c0c172 RR |
583 | wxMenuBar *menu_bar = new wxMenuBar; |
584 | menu_bar->Append(menu, _T("&File")); | |
585 | ||
586 | SetMenuBar( menu_bar ); | |
587 | ||
588 | wxBoxSizer *main_sizer = new wxBoxSizer( wxHORIZONTAL ); | |
589 | ||
6bbb8a8d | 590 | m_target = new wxTextCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize( 80, wxDefaultCoord ) ); |
92c0c172 | 591 | main_sizer->Add( m_target, 1, wxALL, 5 ); |
6bbb8a8d WS |
592 | |
593 | main_sizer->Add( new wxStaticText( this, wxID_ANY, wxT("Set alternating sizes using F4 and F5") ), 0, wxALL, 5 ); | |
594 | ||
92c0c172 | 595 | SetSizer( main_sizer); |
6bbb8a8d | 596 | |
92c0c172 RR |
597 | Layout(); |
598 | GetSizer()->Fit( this ); | |
599 | } | |
600 | ||
6bbb8a8d | 601 | void MySimpleSizerFrame::OnSetSmallSize( wxCommandEvent& WXUNUSED(event)) |
92c0c172 RR |
602 | { |
603 | GetSizer()->SetItemMinSize( m_target, 40, -1 ); | |
604 | Layout(); | |
605 | GetSizer()->Fit( this ); | |
606 | } | |
607 | ||
6bbb8a8d | 608 | void MySimpleSizerFrame::OnSetBigSize( wxCommandEvent& WXUNUSED(event)) |
92c0c172 RR |
609 | { |
610 | GetSizer()->SetItemMinSize( m_target, 140, -1 ); | |
611 | Layout(); | |
612 | GetSizer()->Fit( this ); | |
613 | } | |
614 | ||
615 | ||
a1a3bffc RR |
616 | // ---------------------------------------------------------------------------- |
617 | // MyNestedSizerFrame | |
618 | // ---------------------------------------------------------------------------- | |
619 | ||
620 | ||
621 | MyNestedSizerFrame::MyNestedSizerFrame(const wxChar *title, int x, int y ) | |
622 | : wxFrame( NULL, wxID_ANY, title, wxPoint(x, y) ) | |
623 | { | |
624 | wxMenu *menu = new wxMenu; | |
625 | ||
626 | menu->Append(wxID_ABOUT, _T("Do nothing")); | |
627 | ||
628 | wxMenuBar *menu_bar = new wxMenuBar; | |
629 | menu_bar->Append(menu, _T("&File")); | |
630 | ||
631 | SetMenuBar( menu_bar ); | |
632 | ||
633 | wxBoxSizer *main_sizer = new wxBoxSizer( wxVERTICAL ); | |
634 | ||
635 | main_sizer->Add( new wxStaticText( this, -1, wxT("Hello outside") ), 0, wxALIGN_CENTER ); | |
636 | main_sizer->Add( new wxStaticText( this, -1, wxT("Hello outside") ), 0, wxALIGN_CENTER ); | |
637 | main_sizer->Add( new wxStaticText( this, -1, wxT("Hello outside") ), 0, wxALIGN_CENTER ); | |
638 | main_sizer->Add( new wxStaticText( this, -1, wxT("Hello outside") ), 0, wxALIGN_CENTER ); | |
639 | ||
640 | wxPanel *panel = new wxPanel( this, -1, wxDefaultPosition, wxDefaultSize, | |
641 | wxTAB_TRAVERSAL | wxSUNKEN_BORDER ); | |
642 | main_sizer->Add( panel, 0, wxALIGN_CENTER ); | |
643 | wxBoxSizer *panel_sizer = new wxBoxSizer( wxVERTICAL ); | |
644 | panel->SetSizer( panel_sizer ); | |
645 | panel_sizer->Add( new wxStaticText( panel, -1, wxT("Hello inside") ) ); | |
646 | panel_sizer->Add( new wxStaticText( panel, -1, wxT("Hello inside") ) ); | |
647 | panel_sizer->Add( new wxStaticText( panel, -1, wxT("Hello inside") ) ); | |
648 | ||
649 | main_sizer->Add( new wxStaticText( this, -1, wxT("Hello outside") ), 0, wxALIGN_CENTER ); | |
650 | ||
651 | m_target = new wxTextCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize( 80, wxDefaultCoord ) ); | |
652 | main_sizer->Add( m_target, 1, wxALL|wxGROW, 5 ); | |
653 | ||
654 | SetSizer( main_sizer); | |
655 | ||
656 | Layout(); | |
657 | GetSizer()->Fit( this ); | |
658 | GetSizer()->SetSizeHints( this ); | |
659 | } | |
660 |