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