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