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