1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Layout sample
4 // Author: Julian Smart
5 // Modified by: Robin Dunn, Vadim Zeitlin
8 // Copyright: (c) 1998 Julian Smart
10 // Licence: wxWindows license
11 /////////////////////////////////////////////////////////////////////////////
13 // ----------------------------------------------------------------------------
15 // ----------------------------------------------------------------------------
17 // For compilers that support precompilation, includes "wx/wx.h".
18 #include "wx/wxprec.h"
29 #include "wx/gbsizer.h"
30 #include "wx/statline.h"
31 #include "wx/notebook.h"
32 #include "wx/spinctrl.h"
36 // ----------------------------------------------------------------------------
38 // ----------------------------------------------------------------------------
44 // Create the main frame window
45 MyFrame
*frame
= new MyFrame
;
52 // ----------------------------------------------------------------------------
54 // ----------------------------------------------------------------------------
56 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
57 EVT_MENU(LAYOUT_ABOUT
, MyFrame::OnAbout
)
58 EVT_MENU(LAYOUT_QUIT
, MyFrame::OnQuit
)
60 EVT_MENU(LAYOUT_TEST_PROPORTIONS
, MyFrame::TestProportions
)
61 EVT_MENU(LAYOUT_TEST_SIZER
, MyFrame::TestFlexSizers
)
62 EVT_MENU(LAYOUT_TEST_NB_SIZER
, MyFrame::TestNotebookSizers
)
63 EVT_MENU(LAYOUT_TEST_GB_SIZER
, MyFrame::TestGridBagSizer
)
64 EVT_MENU(LAYOUT_TEST_SET_MINIMAL
, MyFrame::TestSetMinimal
)
65 EVT_MENU(LAYOUT_TEST_NESTED
, MyFrame::TestNested
)
68 // Define my frame constructor
70 : wxFrame(NULL
, wxID_ANY
, _T("wxWidgets Layout Demo"),
71 wxDefaultPosition
, wxDefaultSize
,
72 wxDEFAULT_FRAME_STYLE
| wxNO_FULL_REPAINT_ON_RESIZE
)
75 wxMenu
*file_menu
= new wxMenu
;
77 file_menu
->Append(LAYOUT_TEST_PROPORTIONS
, _T("&Proportions demo...\tF1"));
78 file_menu
->Append(LAYOUT_TEST_SIZER
, _T("Test wx&FlexSizer...\tF2"));
79 file_menu
->Append(LAYOUT_TEST_NB_SIZER
, _T("Test ¬ebook sizers...\tF3"));
80 file_menu
->Append(LAYOUT_TEST_GB_SIZER
, _T("Test &gridbag sizer...\tF4"));
81 file_menu
->Append(LAYOUT_TEST_SET_MINIMAL
, _T("Test Set&ItemMinSize...\tF5"));
82 file_menu
->Append(LAYOUT_TEST_NESTED
, _T("Test nested sizer in a wxPanel...\tF6"));
84 file_menu
->AppendSeparator();
85 file_menu
->Append(LAYOUT_QUIT
, _T("E&xit"), _T("Quit program"));
87 wxMenu
*help_menu
= new wxMenu
;
88 help_menu
->Append(LAYOUT_ABOUT
, _T("&About"), _T("About layout demo..."));
90 wxMenuBar
*menu_bar
= new wxMenuBar
;
92 menu_bar
->Append(file_menu
, _T("&File"));
93 menu_bar
->Append(help_menu
, _T("&Help"));
95 // Associate the menu bar with the frame
100 SetStatusText(_T("wxWidgets layout demo"));
101 #endif // wxUSE_STATUSBAR
103 wxPanel
* p
= new wxPanel(this, wxID_ANY
);
105 // we want to get a dialog that is stretchable because it
106 // has a text ctrl in the middle. at the bottom, we have
107 // two buttons which.
109 wxBoxSizer
*topsizer
= new wxBoxSizer( wxVERTICAL
);
111 // 1) top: create wxStaticText with minimum size equal to its default size
113 new wxStaticText( p
, wxID_ANY
, _T("An explanation (wxALIGN_RIGHT).") ),
114 wxSizerFlags().Align(wxALIGN_RIGHT
).Border(wxALL
& ~wxBOTTOM
, 5));
116 // 2) top: create wxTextCtrl with minimum size (100x60)
118 new wxTextCtrl( p
, wxID_ANY
, _T("My text (wxEXPAND)."), wxDefaultPosition
, wxSize(100,60), wxTE_MULTILINE
),
119 wxSizerFlags(1).Expand().Border(wxALL
, 5));
121 // 2.5) Gratuitous test of wxStaticBoxSizers
122 wxBoxSizer
*statsizer
= new wxStaticBoxSizer(
123 new wxStaticBox(p
, wxID_ANY
, _T("A wxStaticBoxSizer")), wxVERTICAL
);
125 new wxStaticText(p
, wxID_ANY
, _T("And some TEXT inside it")),
126 wxSizerFlags().Center().Border(wxALL
, 30));
129 wxSizerFlags(1).Expand().Border(wxALL
, 10));
131 // 2.7) And a test of wxGridSizer
132 wxGridSizer
*gridsizer
= new wxGridSizer(2, 5, 5);
133 gridsizer
->Add(new wxStaticText(p
, wxID_ANY
, _T("Label")),
134 wxSizerFlags().Align(wxALIGN_RIGHT
| wxALIGN_CENTER_VERTICAL
));
135 gridsizer
->Add(new wxTextCtrl(p
, wxID_ANY
, _T("Grid sizer demo")),
136 wxSizerFlags(1).Align(wxGROW
| wxALIGN_CENTER_VERTICAL
));
137 gridsizer
->Add(new wxStaticText(p
, wxID_ANY
, _T("Another label")),
138 wxSizerFlags().Align(wxALIGN_RIGHT
| wxALIGN_CENTER_VERTICAL
));
139 gridsizer
->Add(new wxTextCtrl(p
, wxID_ANY
, _T("More text")),
140 wxSizerFlags(1).Align(wxGROW
| wxALIGN_CENTER_VERTICAL
));
141 gridsizer
->Add(new wxStaticText(p
, wxID_ANY
, _T("Final label")),
142 wxSizerFlags().Align(wxALIGN_RIGHT
| wxALIGN_CENTER_VERTICAL
));
143 gridsizer
->Add(new wxTextCtrl(p
, wxID_ANY
, _T("And yet more text")),
144 wxSizerFlags().Align(wxGROW
| wxALIGN_CENTER_VERTICAL
));
147 wxSizerFlags().Proportion(1).Expand().Border(wxALL
, 10));
151 // 3) middle: create wxStaticLine with minimum size (3x3)
153 new wxStaticLine( p
, wxID_ANY
, wxDefaultPosition
, wxSize(3,3), wxHORIZONTAL
),
154 wxSizerFlags().Expand());
155 #endif // wxUSE_STATLINE
158 // 4) bottom: create two centred wxButtons
159 wxBoxSizer
*button_box
= new wxBoxSizer( wxHORIZONTAL
);
161 new wxButton( p
, wxID_ANY
, _T("Two buttons in a box") ),
162 wxSizerFlags().Border(wxALL
, 7));
164 new wxButton( p
, wxID_ANY
, _T("(wxCENTER)") ),
165 wxSizerFlags().Border(wxALL
, 7));
167 topsizer
->Add(button_box
, wxSizerFlags().Center());
169 p
->SetSizer( topsizer
);
171 // don't allow frame to get smaller than what the sizers tell it and also set
172 // the initial size as calculated by the sizers
173 topsizer
->SetSizeHints( this );
176 void MyFrame::OnQuit(wxCommandEvent
& WXUNUSED(event
))
181 void MyFrame::TestProportions(wxCommandEvent
& WXUNUSED(event
))
183 (new MyProportionsFrame(this))->Show();
186 void MyFrame::TestFlexSizers(wxCommandEvent
& WXUNUSED(event
) )
188 MyFlexSizerFrame
*newFrame
= new MyFlexSizerFrame(_T("Flex Sizer Test Frame"), 50, 50);
189 newFrame
->Show(true);
192 void MyFrame::TestNotebookSizers(wxCommandEvent
& WXUNUSED(event
) )
194 MySizerDialog
dialog( this, _T("Notebook Sizer Test Dialog") );
199 void MyFrame::TestSetMinimal(wxCommandEvent
& WXUNUSED(event
) )
201 MySimpleSizerFrame
*newFrame
= new MySimpleSizerFrame(_T("Simple Sizer Test Frame"), 50, 50);
202 newFrame
->Show(true);
205 void MyFrame::TestNested(wxCommandEvent
& WXUNUSED(event
) )
207 MyNestedSizerFrame
*newFrame
= new MyNestedSizerFrame(_T("Nested Sizer Test Frame"), 50, 50);
208 newFrame
->Show(true);
212 void MyFrame::OnAbout(wxCommandEvent
& WXUNUSED(event
) )
214 (void)wxMessageBox(_T("wxWidgets GUI library layout demo\n"),
215 _T("About Layout Demo"), wxOK
|wxICON_INFORMATION
);
218 void MyFrame::TestGridBagSizer(wxCommandEvent
& WXUNUSED(event
) )
220 MyGridBagSizerFrame
*newFrame
= new
221 MyGridBagSizerFrame(_T("wxGridBagSizer Test Frame"), 50, 50);
222 newFrame
->Show(true);
225 // ----------------------------------------------------------------------------
226 // MyProportionsFrame
227 // ----------------------------------------------------------------------------
229 MyProportionsFrame::MyProportionsFrame(wxFrame
*parent
)
230 : wxFrame(parent
, wxID_ANY
, _T("Box Sizer Proportions Demo"))
234 // create the controls
235 wxPanel
*panel
= new wxPanel(this, wxID_ANY
);
236 for ( n
= 0; n
< WXSIZEOF(m_spins
); n
++ )
238 m_spins
[n
] = new wxSpinCtrl(panel
);
239 m_spins
[n
]->SetValue(n
);
243 m_sizer
= new wxStaticBoxSizer(wxHORIZONTAL
, panel
,
244 _T("Try changing elements proportions and resizing the window"));
245 for ( n
= 0; n
< WXSIZEOF(m_spins
); n
++ )
246 m_sizer
->Add(m_spins
[n
], wxSizerFlags().Border());
248 // put everything together
249 panel
->SetSizer(m_sizer
);
250 wxSizer
*sizerTop
= new wxBoxSizer(wxVERTICAL
);
251 sizerTop
->Add(panel
, wxSizerFlags(1).Expand().Border());
253 SetSizerAndFit(sizerTop
);
255 // and connect the events
256 Connect(wxEVT_COMMAND_TEXT_UPDATED
,
257 wxCommandEventHandler(MyProportionsFrame::OnProportionUpdated
));
258 Connect(wxEVT_COMMAND_SPINCTRL_UPDATED
,
259 wxSpinEventHandler(MyProportionsFrame::OnProportionChanged
));
262 void MyProportionsFrame::UpdateProportions()
264 for ( size_t n
= 0; n
< WXSIZEOF(m_spins
); n
++ )
266 m_sizer
->GetItem(n
)->SetProportion(m_spins
[n
]->GetValue());
272 void MyProportionsFrame::OnProportionUpdated(wxCommandEvent
& WXUNUSED(event
))
277 void MyProportionsFrame::OnProportionChanged(wxSpinEvent
& WXUNUSED(event
))
282 // ----------------------------------------------------------------------------
284 // ----------------------------------------------------------------------------
286 void MyFlexSizerFrame::InitFlexSizer(wxFlexGridSizer
*sizer
, wxWindow
* parent
)
288 for ( int i
= 0; i
< 3; i
++ )
290 for ( int j
= 0; j
< 3; j
++ )
292 sizer
->Add(new wxStaticText
296 wxString::Format(_T("(%d, %d)"), i
+ 1, j
+ 1),
301 0, wxEXPAND
| wxALIGN_CENTER_VERTICAL
| wxALL
, 3);
306 MyFlexSizerFrame::MyFlexSizerFrame(const wxChar
*title
, int x
, int y
)
307 : wxFrame(NULL
, wxID_ANY
, title
, wxPoint(x
, y
) )
309 wxFlexGridSizer
*sizerFlex
;
310 wxPanel
* p
= new wxPanel(this, wxID_ANY
);
312 // consttuct the first column
313 wxSizer
*sizerCol1
= new wxBoxSizer(wxVERTICAL
);
314 sizerCol1
->Add(new wxStaticText(p
, wxID_ANY
, _T("Ungrowable:")), 0, wxCENTER
| wxTOP
, 20);
315 sizerFlex
= new wxFlexGridSizer(3, 3);
316 InitFlexSizer(sizerFlex
, p
);
317 sizerCol1
->Add(sizerFlex
, 1, wxALL
| wxEXPAND
, 10);
319 sizerCol1
->Add(new wxStaticText(p
, wxID_ANY
, _T("Growable middle column:")), 0, wxCENTER
| wxTOP
, 20);
320 sizerFlex
= new wxFlexGridSizer(3, 3);
321 InitFlexSizer(sizerFlex
, p
);
322 sizerFlex
->AddGrowableCol(1);
323 sizerCol1
->Add(sizerFlex
, 1, wxALL
| wxEXPAND
, 10);
325 sizerCol1
->Add(new wxStaticText(p
, wxID_ANY
, _T("Growable middle row:")), 0, wxCENTER
| wxTOP
, 20);
326 sizerFlex
= new wxFlexGridSizer(3, 3);
327 InitFlexSizer(sizerFlex
, p
);
328 sizerFlex
->AddGrowableRow(1);
329 sizerCol1
->Add(sizerFlex
, 1, wxALL
| wxEXPAND
, 10);
331 sizerCol1
->Add(new wxStaticText(p
, wxID_ANY
, _T("All growable columns:")), 0, wxCENTER
| wxTOP
, 20);
332 sizerFlex
= new wxFlexGridSizer(3, 3);
333 InitFlexSizer(sizerFlex
, p
);
334 sizerFlex
->AddGrowableCol(0, 1);
335 sizerFlex
->AddGrowableCol(1, 2);
336 sizerFlex
->AddGrowableCol(2, 3);
337 sizerCol1
->Add(sizerFlex
, 1, wxALL
| wxEXPAND
, 10);
340 wxSizer
*sizerCol2
= new wxBoxSizer(wxVERTICAL
);
341 sizerCol2
->Add(new wxStaticText(p
, wxID_ANY
, _T("Growable middle row and column:")), 0, wxCENTER
| wxTOP
, 20);
342 sizerFlex
= new wxFlexGridSizer(3, 3);
343 InitFlexSizer(sizerFlex
, p
);
344 sizerFlex
->AddGrowableCol(1);
345 sizerFlex
->AddGrowableRow(1);
346 sizerCol2
->Add(sizerFlex
, 1, wxALL
| wxEXPAND
, 10);
348 sizerCol2
->Add(new wxStaticText(p
, wxID_ANY
, _T("Same with horz flex direction")), 0, wxCENTER
| wxTOP
, 20);
349 sizerFlex
= new wxFlexGridSizer(3, 3);
350 InitFlexSizer(sizerFlex
, p
);
351 sizerFlex
->AddGrowableCol(1);
352 sizerFlex
->AddGrowableRow(1);
353 sizerFlex
->SetFlexibleDirection(wxHORIZONTAL
);
354 sizerCol2
->Add(sizerFlex
, 1, wxALL
| wxEXPAND
, 10);
356 sizerCol2
->Add(new wxStaticText(p
, wxID_ANY
, _T("Same with grow mode == \"none\"")), 0, wxCENTER
| wxTOP
, 20);
357 sizerFlex
= new wxFlexGridSizer(3, 3);
358 InitFlexSizer(sizerFlex
, p
);
359 sizerFlex
->AddGrowableCol(1);
360 sizerFlex
->AddGrowableRow(1);
361 sizerFlex
->SetFlexibleDirection(wxHORIZONTAL
);
362 sizerFlex
->SetNonFlexibleGrowMode(wxFLEX_GROWMODE_NONE
);
363 sizerCol2
->Add(sizerFlex
, 1, wxALL
| wxEXPAND
, 10);
365 sizerCol2
->Add(new wxStaticText(p
, wxID_ANY
, _T("Same with grow mode == \"all\"")), 0, wxCENTER
| wxTOP
, 20);
366 sizerFlex
= new wxFlexGridSizer(3, 3);
367 InitFlexSizer(sizerFlex
, p
);
368 sizerFlex
->AddGrowableCol(1);
369 sizerFlex
->AddGrowableRow(1);
370 sizerFlex
->SetFlexibleDirection(wxHORIZONTAL
);
371 sizerFlex
->SetNonFlexibleGrowMode(wxFLEX_GROWMODE_ALL
);
372 sizerCol2
->Add(sizerFlex
, 1, wxALL
| wxEXPAND
, 10);
374 // add both columns to grid sizer
375 wxGridSizer
*sizerTop
= new wxGridSizer(2, 0, 20);
376 sizerTop
->Add(sizerCol1
, 1, wxEXPAND
);
377 sizerTop
->Add(sizerCol2
, 1, wxEXPAND
);
379 p
->SetSizer(sizerTop
);
380 sizerTop
->SetSizeHints(this);
383 // ----------------------------------------------------------------------------
385 // ----------------------------------------------------------------------------
387 MySizerDialog::MySizerDialog(wxWindow
*parent
, const wxChar
*title
)
388 : wxDialog(parent
, wxID_ANY
, wxString(title
))
390 // Begin with first hierarchy: a notebook at the top and
391 // and OK button at the bottom.
393 wxBoxSizer
*topsizer
= new wxBoxSizer( wxVERTICAL
);
395 wxNotebook
*notebook
= new wxNotebook( this, wxID_ANY
);
396 topsizer
->Add( notebook
, 1, wxGROW
);
398 wxButton
*button
= new wxButton( this, wxID_OK
, _T("OK") );
399 topsizer
->Add( button
, 0, wxALIGN_RIGHT
| wxALL
, 10 );
401 // First page: one big text ctrl
402 wxTextCtrl
*multi
= new wxTextCtrl( notebook
, wxID_ANY
, _T("TextCtrl."), wxDefaultPosition
, wxDefaultSize
, wxTE_MULTILINE
);
403 notebook
->AddPage( multi
, _T("Page One") );
405 // Second page: a text ctrl and a button
406 wxPanel
*panel
= new wxPanel( notebook
, wxID_ANY
);
407 notebook
->AddPage( panel
, _T("Page Two") );
409 wxSizer
*panelsizer
= new wxBoxSizer( wxVERTICAL
);
411 wxTextCtrl
*text
= new wxTextCtrl( panel
, wxID_ANY
, _T("TextLine 1."), wxDefaultPosition
, wxSize(250,wxDefaultCoord
) );
412 panelsizer
->Add( text
, 0, wxGROW
|wxALL
, 30 );
413 text
= new wxTextCtrl( panel
, wxID_ANY
, _T("TextLine 2."), wxDefaultPosition
, wxSize(250,wxDefaultCoord
) );
414 panelsizer
->Add( text
, 0, wxGROW
|wxALL
, 30 );
415 wxButton
*button2
= new wxButton( panel
, wxID_ANY
, _T("Hallo") );
416 panelsizer
->Add( button2
, 0, wxALIGN_RIGHT
| wxLEFT
|wxRIGHT
|wxBOTTOM
, 30 );
418 panel
->SetAutoLayout( true );
419 panel
->SetSizer( panelsizer
);
421 // Tell dialog to use sizer
422 SetSizer( topsizer
);
423 topsizer
->SetSizeHints( this );
426 // ----------------------------------------------------------------------------
427 // MyGridBagSizerFrame
428 // ----------------------------------------------------------------------------
430 // some simple macros to help make the sample code below more clear
431 #define TEXTCTRL(text) new wxTextCtrl(p, wxID_ANY, _T(text))
432 #define MLTEXTCTRL(text) new wxTextCtrl(p, wxID_ANY, _T(text), wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE)
433 #define POS(r, c) wxGBPosition(r,c)
434 #define SPAN(r, c) wxGBSpan(r,c)
436 const wxChar gbsDescription
[] =_T("\
437 The wxGridBagSizer is similar to the wxFlexGridSizer except the items are explicitly positioned\n\
438 in a virtual cell of the layout grid, and column or row spanning is allowed. For example, this\n\
439 static text is positioned at (0,0) and it spans 7 columns.");
453 BEGIN_EVENT_TABLE(MyGridBagSizerFrame
, wxFrame
)
454 EVT_BUTTON( GBS_HIDE_BTN
, MyGridBagSizerFrame::OnHideBtn
)
455 EVT_BUTTON( GBS_SHOW_BTN
, MyGridBagSizerFrame::OnShowBtn
)
456 EVT_BUTTON( GBS_MOVE_BTN1
, MyGridBagSizerFrame::OnMoveBtn
)
457 EVT_BUTTON( GBS_MOVE_BTN2
, MyGridBagSizerFrame::OnMoveBtn
)
461 MyGridBagSizerFrame::MyGridBagSizerFrame(const wxChar
*title
, int x
, int y
)
462 : wxFrame( NULL
, wxID_ANY
, title
, wxPoint(x
, y
) )
464 wxPanel
* p
= new wxPanel(this, wxID_ANY
);
466 m_gbs
= new wxGridBagSizer();
469 m_gbs
->Add( new wxStaticText(p
, wxID_ANY
, gbsDescription
),
470 POS(0,0), SPAN(1, 7),
471 wxALIGN_CENTER
| wxALL
, 5);
473 m_gbs
->Add( TEXTCTRL("pos(1,0)"), POS(1,0) );
474 m_gbs
->Add( TEXTCTRL("pos(1,1)"), POS(1,1) );
475 m_gbs
->Add( TEXTCTRL("pos(2,0)"), POS(2,0) );
476 m_gbs
->Add( TEXTCTRL("pos(2,1)"), POS(2,1) );
477 m_gbs
->Add( MLTEXTCTRL("pos(3,2), span(1,2)\nthis row and col are growable"),
478 POS(3,2), SPAN(1,2), wxEXPAND
);
479 m_gbs
->Add( MLTEXTCTRL("pos(4,3)\nspan(3,1)"),
480 POS(4,3), SPAN(3,1), wxEXPAND
);
481 m_gbs
->Add( TEXTCTRL("pos(5,4)"), POS(5,4), wxDefaultSpan
, wxEXPAND
);
482 m_gbs
->Add( TEXTCTRL("pos(6,5)"), POS(6,5), wxDefaultSpan
, wxEXPAND
);
483 m_gbs
->Add( TEXTCTRL("pos(7,6)"), POS(7,6) );
485 //m_gbs->Add( TEXTCTRL("bad position"), POS(4,3) ); // Test for assert
486 //m_gbs->Add( TEXTCTRL("bad position"), POS(5,3) ); // Test for assert
489 m_moveBtn1
= new wxButton(p
, GBS_MOVE_BTN1
, _T("Move this to (3,6)"));
490 m_moveBtn2
= new wxButton(p
, GBS_MOVE_BTN2
, _T("Move this to (3,6)"));
491 m_gbs
->Add( m_moveBtn1
, POS(10,2) );
492 m_gbs
->Add( m_moveBtn2
, POS(10,3) );
494 m_hideBtn
= new wxButton(p
, GBS_HIDE_BTN
, _T("Hide this item -->"));
495 m_gbs
->Add(m_hideBtn
, POS(12, 3));
497 m_hideTxt
= new wxTextCtrl(p
, wxID_ANY
, _T("pos(12,4), size(150, wxDefaultCoord)"),
498 wxDefaultPosition
, wxSize(150,wxDefaultCoord
));
499 m_gbs
->Add( m_hideTxt
, POS(12,4) );
501 m_showBtn
= new wxButton(p
, GBS_SHOW_BTN
, _T("<-- Show it again"));
502 m_gbs
->Add(m_showBtn
, POS(12, 5));
503 m_showBtn
->Disable();
505 m_gbs
->Add(10,10, POS(14,0));
507 m_gbs
->AddGrowableRow(3);
508 m_gbs
->AddGrowableCol(2);
510 p
->SetSizerAndFit(m_gbs
);
511 SetClientSize(p
->GetSize());
515 void MyGridBagSizerFrame::OnHideBtn(wxCommandEvent
&)
517 m_gbs
->Hide(m_hideTxt
);
518 m_hideBtn
->Disable();
523 void MyGridBagSizerFrame::OnShowBtn(wxCommandEvent
&)
525 m_gbs
->Show(m_hideTxt
);
527 m_showBtn
->Disable();
532 void MyGridBagSizerFrame::OnMoveBtn(wxCommandEvent
& event
)
534 wxButton
* btn
= (wxButton
*)event
.GetEventObject();
535 wxGBPosition curPos
= m_gbs
->GetItemPosition(btn
);
537 // if it's already at the "other" spot then move it back
538 if (curPos
== wxGBPosition(3,6))
540 m_gbs
->SetItemPosition(btn
, m_lastPos
);
541 btn
->SetLabel(_T("Move this to (3,6)"));
545 if ( m_gbs
->CheckForIntersection(wxGBPosition(3,6), wxGBSpan(1,1)) )
547 _T("wxGridBagSizer will not allow items to be in the same cell as\n\
548 another item, so this operation will fail. You will also get an assert\n\
549 when compiled in debug mode."), _T("Warning"), wxOK
| wxICON_INFORMATION
);
551 if ( m_gbs
->SetItemPosition(btn
, wxGBPosition(3,6)) )
554 btn
->SetLabel(_T("Move it back"));
560 // ----------------------------------------------------------------------------
561 // MySimpleSizerFrame
562 // ----------------------------------------------------------------------------
570 BEGIN_EVENT_TABLE(MySimpleSizerFrame
, wxFrame
)
571 EVT_MENU( ID_SET_SMALL
, MySimpleSizerFrame::OnSetSmallSize
)
572 EVT_MENU( ID_SET_BIG
, MySimpleSizerFrame::OnSetBigSize
)
575 MySimpleSizerFrame::MySimpleSizerFrame(const wxChar
*title
, int x
, int y
)
576 : wxFrame( NULL
, wxID_ANY
, title
, wxPoint(x
, y
) )
578 wxMenu
*menu
= new wxMenu
;
580 menu
->Append(ID_SET_SMALL
, _T("Make text control small\tF4"));
581 menu
->Append(ID_SET_BIG
, _T("Make text control big\tF5"));
583 wxMenuBar
*menu_bar
= new wxMenuBar
;
584 menu_bar
->Append(menu
, _T("&File"));
586 SetMenuBar( menu_bar
);
588 wxBoxSizer
*main_sizer
= new wxBoxSizer( wxHORIZONTAL
);
590 m_target
= new wxTextCtrl( this, wxID_ANY
, wxEmptyString
, wxDefaultPosition
, wxSize( 80, wxDefaultCoord
) );
591 main_sizer
->Add( m_target
, 1, wxALL
, 5 );
593 main_sizer
->Add( new wxStaticText( this, wxID_ANY
, wxT("Set alternating sizes using F4 and F5") ), 0, wxALL
, 5 );
595 SetSizer( main_sizer
);
598 GetSizer()->Fit( this );
601 void MySimpleSizerFrame::OnSetSmallSize( wxCommandEvent
& WXUNUSED(event
))
603 GetSizer()->SetItemMinSize( m_target
, 40, -1 );
605 GetSizer()->Fit( this );
608 void MySimpleSizerFrame::OnSetBigSize( wxCommandEvent
& WXUNUSED(event
))
610 GetSizer()->SetItemMinSize( m_target
, 140, -1 );
612 GetSizer()->Fit( this );
616 // ----------------------------------------------------------------------------
617 // MyNestedSizerFrame
618 // ----------------------------------------------------------------------------
621 MyNestedSizerFrame::MyNestedSizerFrame(const wxChar
*title
, int x
, int y
)
622 : wxFrame( NULL
, wxID_ANY
, title
, wxPoint(x
, y
) )
624 wxMenu
*menu
= new wxMenu
;
626 menu
->Append(wxID_ABOUT
, _T("Do nothing"));
628 wxMenuBar
*menu_bar
= new wxMenuBar
;
629 menu_bar
->Append(menu
, _T("&File"));
631 SetMenuBar( menu_bar
);
633 wxBoxSizer
*main_sizer
= new wxBoxSizer( wxVERTICAL
);
635 main_sizer
->Add( new wxStaticText( this, -1, wxT("Hello outside") ), 0, wxALIGN_CENTER
);
636 main_sizer
->Add( new wxStaticText( this, -1, wxT("Hello outside") ), 0, wxALIGN_CENTER
);
637 main_sizer
->Add( new wxStaticText( this, -1, wxT("Hello outside") ), 0, wxALIGN_CENTER
);
638 main_sizer
->Add( new wxStaticText( this, -1, wxT("Hello outside") ), 0, wxALIGN_CENTER
);
640 wxPanel
*panel
= new wxPanel( this, -1, wxDefaultPosition
, wxDefaultSize
,
641 wxTAB_TRAVERSAL
| wxSUNKEN_BORDER
);
642 main_sizer
->Add( panel
, 0, wxALIGN_CENTER
);
643 wxBoxSizer
*panel_sizer
= new wxBoxSizer( wxVERTICAL
);
644 panel
->SetSizer( panel_sizer
);
645 panel_sizer
->Add( new wxStaticText( panel
, -1, wxT("Hello inside") ) );
646 panel_sizer
->Add( new wxStaticText( panel
, -1, wxT("Hello inside") ) );
647 panel_sizer
->Add( new wxStaticText( panel
, -1, wxT("Hello inside") ) );
649 main_sizer
->Add( new wxStaticText( this, -1, wxT("Hello outside") ), 0, wxALIGN_CENTER
);
651 m_target
= new wxTextCtrl( this, wxID_ANY
, wxEmptyString
, wxDefaultPosition
, wxSize( 80, wxDefaultCoord
) );
652 main_sizer
->Add( m_target
, 1, wxALL
|wxGROW
, 5 );
654 SetSizer( main_sizer
);
657 GetSizer()->Fit( this );
658 GetSizer()->SetSizeHints( this );