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