]> git.saurik.com Git - wxWidgets.git/blame - samples/layout/layout.cpp
Fixed compile error
[wxWidgets.git] / samples / layout / layout.cpp
CommitLineData
c801d85f
KB
1/////////////////////////////////////////////////////////////////////////////
2// Name: layout.cpp
3// Purpose: Layout sample
4// Author: Julian Smart
5// Modified by:
6// Created: 04/01/98
7// RCS-ID: $Id$
6aa89a22 8// Copyright: (c) Julian Smart
2f6c54eb 9// Licence: wxWindows license
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"
c62ac5b6 31
c801d85f
KB
32#include "layout.h"
33
9e023db7
VZ
34// ----------------------------------------------------------------------------
35// MyApp
36// ----------------------------------------------------------------------------
c801d85f
KB
37
38IMPLEMENT_APP(MyApp)
39
c801d85f
KB
40MyApp::MyApp()
41{
42}
43
83edc0a5 44bool MyApp::OnInit()
c801d85f
KB
45{
46 // Create the main frame window
9e023db7
VZ
47 MyFrame *frame = new MyFrame;
48
9230b621 49 frame->Show(true);
9e023db7 50
9230b621 51 return true;
9e023db7
VZ
52}
53
54// ----------------------------------------------------------------------------
55// MyFrame
56// ----------------------------------------------------------------------------
c801d85f 57
9e023db7
VZ
58BEGIN_EVENT_TABLE(MyFrame, wxFrame)
59 EVT_MENU(LAYOUT_ABOUT, MyFrame::OnAbout)
60 EVT_MENU(LAYOUT_QUIT, MyFrame::OnQuit)
c801d85f 61
9e023db7
VZ
62 EVT_MENU(LAYOUT_TEST_SIZER, MyFrame::TestFlexSizers)
63 EVT_MENU(LAYOUT_TEST_NB_SIZER, MyFrame::TestNotebookSizers)
20b35a69 64 EVT_MENU(LAYOUT_TEST_GB_SIZER, MyFrame::TestGridBagSizer)
9e023db7 65END_EVENT_TABLE()
c801d85f 66
9e023db7
VZ
67// Define my frame constructor
68MyFrame::MyFrame()
be5a51fb 69 : wxFrame(NULL, wxID_ANY, _T("wxWidgets Layout Demo"),
9e023db7
VZ
70 wxDefaultPosition, wxDefaultSize,
71 wxDEFAULT_FRAME_STYLE | wxNO_FULL_REPAINT_ON_RESIZE)
72{
c801d85f
KB
73 // Make a menubar
74 wxMenu *file_menu = new wxMenu;
75
9e023db7
VZ
76 file_menu->Append(LAYOUT_TEST_SIZER, _T("Test wx&FlexSizer"));
77 file_menu->Append(LAYOUT_TEST_NB_SIZER, _T("&Test notebook sizers"));
20b35a69 78 file_menu->Append(LAYOUT_TEST_GB_SIZER, _T("Test &gridbag sizer"));
c801d85f
KB
79
80 file_menu->AppendSeparator();
9e023db7 81 file_menu->Append(LAYOUT_QUIT, _T("E&xit"), _T("Quit program"));
c801d85f
KB
82
83 wxMenu *help_menu = new wxMenu;
9e023db7 84 help_menu->Append(LAYOUT_ABOUT, _T("&About"), _T("About layout demo"));
c801d85f 85
9e023db7 86 wxMenuBar *menu_bar = new wxMenuBar;
c801d85f 87
42ed7532
MB
88 menu_bar->Append(file_menu, _T("&File"));
89 menu_bar->Append(help_menu, _T("&Help"));
c801d85f
KB
90
91 // Associate the menu bar with the frame
9e023db7
VZ
92 SetMenuBar(menu_bar);
93
8520f137 94#if wxUSE_STATUSBAR
9e023db7 95 CreateStatusBar(2);
be5a51fb 96 SetStatusText(_T("wxWidgets layout demo"));
8520f137 97#endif // wxUSE_STATUSBAR
9e023db7
VZ
98
99 // we want to get a dialog that is stretchable because it
100 // has a text ctrl in the middle. at the bottom, we have
101 // two buttons which.
102
103 wxBoxSizer *topsizer = new wxBoxSizer( wxVERTICAL );
104
105 // 1) top: create wxStaticText with minimum size equal to its default size
106 topsizer->Add(
9230b621 107 new wxStaticText( this, wxID_ANY, _T("An explanation (wxALIGN_RIGHT).") ),
9e023db7
VZ
108 0, // make vertically unstretchable
109 wxALIGN_RIGHT | // right align text
110 wxTOP | wxLEFT | wxRIGHT, // make border all around except wxBOTTOM
111 5 ); // set border width to 5
112
113 // 2) top: create wxTextCtrl with minimum size (100x60)
114 topsizer->Add(
9230b621 115 new wxTextCtrl( this, wxID_ANY, _T("My text (wxEXPAND)."), wxDefaultPosition, wxSize(100,60), wxTE_MULTILINE),
9e023db7
VZ
116 1, // make vertically stretchable
117 wxEXPAND | // make horizontally stretchable
118 wxALL, // and make border all around
119 5 ); // set border width to 5
120
121 // 2.5) Gratuitous test of wxStaticBoxSizers
122 wxBoxSizer *statsizer = new wxStaticBoxSizer(
9230b621 123 new wxStaticBox(this, wxID_ANY, _T("A wxStaticBoxSizer")),
9e023db7
VZ
124 wxVERTICAL );
125 statsizer->Add(
9230b621 126 new wxStaticText(this, wxID_ANY, _T("And some TEXT inside it")),
9e023db7
VZ
127 0,
128 wxCENTER |
129 wxALL,
130 30);
131 topsizer->Add(statsizer, 1, wxEXPAND | wxALL, 10);
132
133 // 2.7) And a test of wxGridSizer
134 wxGridSizer *gridsizer = new wxGridSizer(2, 5, 5);
9230b621 135 gridsizer->Add(new wxStaticText(this, wxID_ANY, _T("Label")), 0,
9e023db7 136 wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL);
9230b621 137 gridsizer->Add(new wxTextCtrl(this, wxID_ANY, _T("Grid sizer demo")), 1,
9e023db7 138 wxGROW | wxALIGN_CENTER_VERTICAL);
9230b621 139 gridsizer->Add(new wxStaticText(this, wxID_ANY, _T("Another label")), 0,
9e023db7 140 wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL);
9230b621 141 gridsizer->Add(new wxTextCtrl(this, wxID_ANY, _T("More text")), 1,
9e023db7 142 wxGROW | wxALIGN_CENTER_VERTICAL);
9230b621 143 gridsizer->Add(new wxStaticText(this, wxID_ANY, _T("Final label")), 0,
9e023db7 144 wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL);
9230b621 145 gridsizer->Add(new wxTextCtrl(this, wxID_ANY, _T("And yet more text")), 1,
9e023db7
VZ
146 wxGROW | wxALIGN_CENTER_VERTICAL);
147 topsizer->Add(gridsizer, 1, wxGROW | wxALL, 10);
148
149
4aa0bd9b 150#if wxUSE_STATLINE
9e023db7
VZ
151 // 3) middle: create wxStaticLine with minimum size (3x3)
152 topsizer->Add(
9230b621 153 new wxStaticLine( this, wxID_ANY, wxDefaultPosition, wxSize(3,3), wxHORIZONTAL),
9e023db7
VZ
154 0, // make vertically unstretchable
155 wxEXPAND | // make horizontally stretchable
156 wxALL, // and make border all around
157 5 ); // set border width to 5
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(
9230b621 164 new wxButton( this, wxID_ANY, _T("Two buttons in a box") ),
9e023db7
VZ
165 0, // make horizontally unstretchable
166 wxALL, // make border all around
167 7 ); // set border width to 7
168 button_box->Add(
9230b621 169 new wxButton( this, wxID_ANY, _T("(wxCENTER)") ),
9e023db7
VZ
170 0, // make horizontally unstretchable
171 wxALL, // make border all around
172 7 ); // set border width to 7
173
174 topsizer->Add(
175 button_box,
176 0, // make vertically unstretchable
177 wxCENTER ); // no border and centre horizontally
178
179 // don't allow frame to get smaller than what the sizers tell it and also set
180 // the initial size as calculated by the sizers
181 topsizer->SetSizeHints( this );
182
183 SetSizer( topsizer );
184}
185
186void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event) )
187{
9230b621 188 Close(true);
9e023db7
VZ
189}
190
191void MyFrame::TestFlexSizers(wxCommandEvent& WXUNUSED(event) )
192{
193 MyFlexSizerFrame *newFrame = new MyFlexSizerFrame(_T("Flex Sizer Test Frame"), 50, 50);
9230b621 194 newFrame->Show(true);
9e023db7
VZ
195}
196
197void MyFrame::TestNotebookSizers(wxCommandEvent& WXUNUSED(event) )
198{
199 MySizerDialog dialog( this, _T("Notebook Sizer Test Dialog") );
200
201 dialog.ShowModal();
202}
203
c801d85f 204
9e023db7
VZ
205void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event) )
206{
be5a51fb 207 (void)wxMessageBox(_T("wxWidgets GUI library layout demo\n"),
9e023db7
VZ
208 _T("About Layout Demo"), wxOK|wxICON_INFORMATION);
209}
210
20b35a69
RD
211void MyFrame::TestGridBagSizer(wxCommandEvent& WXUNUSED(event) )
212{
213 MyGridBagSizerFrame *newFrame = new
214 MyGridBagSizerFrame(_T("wxGridBagSizer Test Frame"), 50, 50);
9230b621 215 newFrame->Show(true);
20b35a69
RD
216}
217
218
9e023db7
VZ
219// ----------------------------------------------------------------------------
220// MyFlexSizerFrame
221// ----------------------------------------------------------------------------
c62ac5b6 222
9e023db7 223void MyFlexSizerFrame::InitFlexSizer(wxFlexGridSizer *sizer)
c801d85f 224{
9e023db7
VZ
225 for ( int i = 0; i < 3; i++ )
226 {
227 for ( int j = 0; j < 3; j++ )
228 {
229 sizer->Add(new wxStaticText
230 (
231 this,
9230b621 232 wxID_ANY,
9e023db7
VZ
233 wxString::Format(_T("(%d, %d)"), i + 1, j + 1),
234 wxDefaultPosition,
235 wxDefaultSize,
236 wxALIGN_CENTER
237 ),
238 0, wxEXPAND | wxALIGN_CENTER_VERTICAL | wxALL, 3);
239 }
240 }
c801d85f
KB
241}
242
9e023db7 243MyFlexSizerFrame::MyFlexSizerFrame(const wxChar *title, int x, int y )
9230b621 244 : wxFrame(NULL, wxID_ANY, title, wxPoint(x, y) )
c801d85f 245{
9e023db7
VZ
246 wxFlexGridSizer *sizerFlex;
247
248 // consttuct the first column
249 wxSizer *sizerCol1 = new wxBoxSizer(wxVERTICAL);
9230b621 250 sizerCol1->Add(new wxStaticText(this, wxID_ANY, _T("Ungrowable:")), 0, wxCENTER | wxTOP, 20);
9e023db7
VZ
251 sizerFlex = new wxFlexGridSizer(3, 3);
252 InitFlexSizer(sizerFlex);
253 sizerCol1->Add(sizerFlex, 1, wxALL | wxEXPAND, 10);
254
9230b621 255 sizerCol1->Add(new wxStaticText(this, wxID_ANY, _T("Growable middle column:")), 0, wxCENTER | wxTOP, 20);
9e023db7
VZ
256 sizerFlex = new wxFlexGridSizer(3, 3);
257 InitFlexSizer(sizerFlex);
258 sizerFlex->AddGrowableCol(1);
259 sizerCol1->Add(sizerFlex, 1, wxALL | wxEXPAND, 10);
260
9230b621 261 sizerCol1->Add(new wxStaticText(this, wxID_ANY, _T("Growable middle row:")), 0, wxCENTER | wxTOP, 20);
9e023db7
VZ
262 sizerFlex = new wxFlexGridSizer(3, 3);
263 InitFlexSizer(sizerFlex);
264 sizerFlex->AddGrowableRow(1);
265 sizerCol1->Add(sizerFlex, 1, wxALL | wxEXPAND, 10);
266
9230b621 267 sizerCol1->Add(new wxStaticText(this, wxID_ANY, _T("All growable columns:")), 0, wxCENTER | wxTOP, 20);
9e023db7
VZ
268 sizerFlex = new wxFlexGridSizer(3, 3);
269 InitFlexSizer(sizerFlex);
270 sizerFlex->AddGrowableCol(0, 1);
271 sizerFlex->AddGrowableCol(1, 2);
272 sizerFlex->AddGrowableCol(2, 3);
273 sizerCol1->Add(sizerFlex, 1, wxALL | wxEXPAND, 10);
274
275 // the second one
276 wxSizer *sizerCol2 = new wxBoxSizer(wxVERTICAL);
9230b621 277 sizerCol2->Add(new wxStaticText(this, wxID_ANY, _T("Growable middle row and column:")), 0, wxCENTER | wxTOP, 20);
9e023db7
VZ
278 sizerFlex = new wxFlexGridSizer(3, 3);
279 InitFlexSizer(sizerFlex);
280 sizerFlex->AddGrowableCol(1);
281 sizerFlex->AddGrowableRow(1);
282 sizerCol2->Add(sizerFlex, 1, wxALL | wxEXPAND, 10);
283
9230b621 284 sizerCol2->Add(new wxStaticText(this, wxID_ANY, _T("Same with horz flex direction")), 0, wxCENTER | wxTOP, 20);
9e023db7
VZ
285 sizerFlex = new wxFlexGridSizer(3, 3);
286 InitFlexSizer(sizerFlex);
287 sizerFlex->AddGrowableCol(1);
288 sizerFlex->AddGrowableRow(1);
289 sizerFlex->SetFlexibleDirection(wxHORIZONTAL);
290 sizerCol2->Add(sizerFlex, 1, wxALL | wxEXPAND, 10);
291
9230b621 292 sizerCol2->Add(new wxStaticText(this, wxID_ANY, _T("Same with grow mode == \"none\"")), 0, wxCENTER | wxTOP, 20);
9e023db7
VZ
293 sizerFlex = new wxFlexGridSizer(3, 3);
294 InitFlexSizer(sizerFlex);
295 sizerFlex->AddGrowableCol(1);
296 sizerFlex->AddGrowableRow(1);
297 sizerFlex->SetFlexibleDirection(wxHORIZONTAL);
298 sizerFlex->SetNonFlexibleGrowMode(wxFLEX_GROWMODE_NONE);
299 sizerCol2->Add(sizerFlex, 1, wxALL | wxEXPAND, 10);
300
9230b621 301 sizerCol2->Add(new wxStaticText(this, wxID_ANY, _T("Same with grow mode == \"all\"")), 0, wxCENTER | wxTOP, 20);
9e023db7
VZ
302 sizerFlex = new wxFlexGridSizer(3, 3);
303 InitFlexSizer(sizerFlex);
304 sizerFlex->AddGrowableCol(1);
305 sizerFlex->AddGrowableRow(1);
306 sizerFlex->SetFlexibleDirection(wxHORIZONTAL);
307 sizerFlex->SetNonFlexibleGrowMode(wxFLEX_GROWMODE_ALL);
308 sizerCol2->Add(sizerFlex, 1, wxALL | wxEXPAND, 10);
309
310 // add both columns to grid sizer
311 wxGridSizer *sizerTop = new wxGridSizer(2, 0, 20);
312 sizerTop->Add(sizerCol1, 1, wxEXPAND);
313 sizerTop->Add(sizerCol2, 1, wxEXPAND);
314
315 SetSizer(sizerTop);
316 sizerTop->SetSizeHints(this);
c801d85f
KB
317}
318
9e023db7
VZ
319// ----------------------------------------------------------------------------
320// MySizerDialog
321// ----------------------------------------------------------------------------
c801d85f 322
9e023db7 323MySizerDialog::MySizerDialog(wxWindow *parent, const wxChar *title)
9230b621 324 : wxDialog(parent, wxID_ANY, wxString(title))
83edc0a5 325{
83edc0a5
RR
326 // Begin with first hierarchy: a notebook at the top and
327 // and OK button at the bottom.
328
329 wxBoxSizer *topsizer = new wxBoxSizer( wxVERTICAL );
56ac3e75 330
9230b621 331 wxNotebook *notebook = new wxNotebook( this, wxID_ANY );
adbf2d73 332 topsizer->Add( notebook, 1, wxGROW );
56ac3e75 333
9e023db7 334 wxButton *button = new wxButton( this, wxID_OK, _T("OK") );
83edc0a5
RR
335 topsizer->Add( button, 0, wxALIGN_RIGHT | wxALL, 10 );
336
337 // First page: one big text ctrl
9230b621 338 wxTextCtrl *multi = new wxTextCtrl( notebook, wxID_ANY, _T("TextCtrl."), wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE );
42ed7532 339 notebook->AddPage( multi, _T("Page One") );
56ac3e75 340
83edc0a5 341 // Second page: a text ctrl and a button
9230b621 342 wxPanel *panel = new wxPanel( notebook, wxID_ANY );
42ed7532 343 notebook->AddPage( panel, _T("Page Two") );
56ac3e75 344
f6bcfd97 345 wxSizer *panelsizer = new wxBoxSizer( wxVERTICAL );
56ac3e75 346
9230b621 347 wxTextCtrl *text = new wxTextCtrl( panel, wxID_ANY, _T("TextLine 1."), wxDefaultPosition, wxSize(250,-1) );
83edc0a5 348 panelsizer->Add( text, 0, wxGROW|wxALL, 30 );
9230b621 349 text = new wxTextCtrl( panel, wxID_ANY, _T("TextLine 2."), wxDefaultPosition, wxSize(250,-1) );
83edc0a5 350 panelsizer->Add( text, 0, wxGROW|wxALL, 30 );
9230b621 351 wxButton *button2 = new wxButton( panel, wxID_ANY, _T("Hallo") );
83edc0a5 352 panelsizer->Add( button2, 0, wxALIGN_RIGHT | wxLEFT|wxRIGHT|wxBOTTOM, 30 );
56ac3e75 353
9230b621 354 panel->SetAutoLayout( true );
83edc0a5 355 panel->SetSizer( panelsizer );
56ac3e75 356
83edc0a5 357 // Tell dialog to use sizer
9e023db7
VZ
358 SetSizer( topsizer );
359 topsizer->SetSizeHints( this );
c62ac5b6
RR
360}
361
20b35a69
RD
362// ----------------------------------------------------------------------------
363// MyGridBagSizerFrame
364// ----------------------------------------------------------------------------
365
366// some simple macros to help make the sample code below more clear
9230b621
VS
367#define TEXTCTRL(text) new wxTextCtrl(p, wxID_ANY, _T(text))
368#define MLTEXTCTRL(text) new wxTextCtrl(p, wxID_ANY, _T(text), wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE)
20b35a69
RD
369#define POS(r, c) wxGBPosition(r,c)
370#define SPAN(r, c) wxGBSpan(r,c)
371
77c5e923
RD
372wxChar* gbsDescription =_T("\
373The wxGridBagSizer is similar to the wxFlexGridSizer except the items are explicitly positioned\n\
374in a virtual cell of the layout grid, and column or row spanning is allowed. For example, this\n\
375static text is positioned at (0,0) and it spans 7 columns.");
20b35a69
RD
376
377
378// Some IDs
379enum {
380 GBS_HIDE_BTN = 1212,
381 GBS_SHOW_BTN,
382 GBS_MOVE_BTN1,
383 GBS_MOVE_BTN2,
384
385 GBS_MAX,
386};
387
388
389BEGIN_EVENT_TABLE(MyGridBagSizerFrame, wxFrame)
390 EVT_BUTTON( GBS_HIDE_BTN, MyGridBagSizerFrame::OnHideBtn)
391 EVT_BUTTON( GBS_SHOW_BTN, MyGridBagSizerFrame::OnShowBtn)
392 EVT_BUTTON( GBS_MOVE_BTN1, MyGridBagSizerFrame::OnMoveBtn)
393 EVT_BUTTON( GBS_MOVE_BTN2, MyGridBagSizerFrame::OnMoveBtn)
394END_EVENT_TABLE()
395
396
397MyGridBagSizerFrame::MyGridBagSizerFrame(const wxChar *title, int x, int y )
9230b621 398 : wxFrame( NULL, wxID_ANY, title, wxPoint(x, y) )
20b35a69 399{
9230b621 400 wxPanel* p = new wxPanel(this, wxID_ANY);
20b35a69
RD
401 m_panel = p;
402 m_gbs = new wxGridBagSizer();
403
404
9230b621 405 m_gbs->Add( new wxStaticText(p, wxID_ANY, gbsDescription),
77c5e923
RD
406 POS(0,0), SPAN(1, 7),
407 wxALIGN_CENTER | wxALL, 5);
20b35a69
RD
408
409 m_gbs->Add( TEXTCTRL("pos(1,0)"), POS(1,0) );
410 m_gbs->Add( TEXTCTRL("pos(1,1)"), POS(1,1) );
411 m_gbs->Add( TEXTCTRL("pos(2,0)"), POS(2,0) );
412 m_gbs->Add( TEXTCTRL("pos(2,1)"), POS(2,1) );
413 m_gbs->Add( MLTEXTCTRL("pos(3,2), span(1,2)\nthis row and col are growable"),
414 POS(3,2), SPAN(1,2), wxEXPAND );
415 m_gbs->Add( MLTEXTCTRL("pos(4,3)\nspan(3,1)"),
416 POS(4,3), SPAN(3,1), wxEXPAND );
417 m_gbs->Add( TEXTCTRL("pos(5,4)"), POS(5,4), wxDefaultSpan, wxEXPAND );
418 m_gbs->Add( TEXTCTRL("pos(6,5)"), POS(6,5), wxDefaultSpan, wxEXPAND );
419 m_gbs->Add( TEXTCTRL("pos(7,6)"), POS(7,6) );
77c5e923 420
20b35a69
RD
421 //m_gbs->Add( TEXTCTRL("bad position"), POS(4,3) ); // Test for assert
422 //m_gbs->Add( TEXTCTRL("bad position"), POS(5,3) ); // Test for assert
423
424
77c5e923
RD
425 m_moveBtn1 = new wxButton(p, GBS_MOVE_BTN1, _T("Move this to (3,6)"));
426 m_moveBtn2 = new wxButton(p, GBS_MOVE_BTN2, _T("Move this to (3,6)"));
20b35a69
RD
427 m_gbs->Add( m_moveBtn1, POS(10,2) );
428 m_gbs->Add( m_moveBtn2, POS(10,3) );
429
77c5e923 430 m_hideBtn = new wxButton(p, GBS_HIDE_BTN, _T("Hide this item -->"));
20b35a69
RD
431 m_gbs->Add(m_hideBtn, POS(12, 3));
432
9230b621 433 m_hideTxt = new wxTextCtrl(p, wxID_ANY, _T("pos(12,4), size(150, -1)"),
6c1ad2a8 434 wxDefaultPosition, wxSize(150,-1));
20b35a69
RD
435 m_gbs->Add( m_hideTxt, POS(12,4) );
436
77c5e923 437 m_showBtn = new wxButton(p, GBS_SHOW_BTN, _T("<-- Show it again"));
20b35a69
RD
438 m_gbs->Add(m_showBtn, POS(12, 5));
439 m_showBtn->Disable();
440
441 m_gbs->Add(10,10, POS(14,0));
442
443 m_gbs->AddGrowableRow(3);
444 m_gbs->AddGrowableCol(2);
445
446 p->SetSizerAndFit(m_gbs);
447 SetClientSize(p->GetSize());
448}
449
450
451void MyGridBagSizerFrame::OnHideBtn(wxCommandEvent&)
452{
453 m_gbs->Hide(m_hideTxt);
454 m_hideBtn->Disable();
455 m_showBtn->Enable();
456 m_gbs->Layout();
457}
458
459void MyGridBagSizerFrame::OnShowBtn(wxCommandEvent&)
460{
461 m_gbs->Show(m_hideTxt);
462 m_hideBtn->Enable();
463 m_showBtn->Disable();
464 m_gbs->Layout();
465}
466
467
468void MyGridBagSizerFrame::OnMoveBtn(wxCommandEvent& event)
469{
470 wxButton* btn = (wxButton*)event.GetEventObject();
471 wxGBPosition curPos = m_gbs->GetItemPosition(btn);
472
473 // if it's already at the "other" spot then move it back
474 if (curPos == wxGBPosition(3,6))
475 {
476 m_gbs->SetItemPosition(btn, m_lastPos);
77c5e923 477 btn->SetLabel(_T("Move this to (3,6)"));
20b35a69 478 }
77c5e923 479 else
20b35a69 480 {
77c5e923
RD
481 if ( m_gbs->CheckForIntersection(wxGBPosition(3,6), wxGBSpan(1,1)) )
482 wxMessageBox(
483_T("wxGridBagSizer will not allow items to be in the same cell as\n\
484another item, so this operation will fail. You will also get an assert\n\
485when compiled in debug mode."), _T("Warning"), wxOK | wxICON_INFORMATION);
486
487 if ( m_gbs->SetItemPosition(btn, wxGBPosition(3,6)) )
488 {
489 m_lastPos = curPos;
490 btn->SetLabel(_T("Move it back"));
491 }
20b35a69
RD
492 }
493 m_gbs->Layout();
494}