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" 
  33 #include "wx/wrapsizer.h" 
  37 // ---------------------------------------------------------------------------- 
  39 // ---------------------------------------------------------------------------- 
  45   if ( !wxApp::OnInit() ) 
  48   // Create the main frame window 
  49   MyFrame 
*frame 
= new MyFrame
; 
  56 // ---------------------------------------------------------------------------- 
  58 // ---------------------------------------------------------------------------- 
  60 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
) 
  61   EVT_MENU(LAYOUT_ABOUT
, MyFrame::OnAbout
) 
  62   EVT_MENU(LAYOUT_QUIT
, MyFrame::OnQuit
) 
  64   EVT_MENU(LAYOUT_TEST_PROPORTIONS
, MyFrame::TestProportions
) 
  65   EVT_MENU(LAYOUT_TEST_SIZER
, MyFrame::TestFlexSizers
) 
  66   EVT_MENU(LAYOUT_TEST_NB_SIZER
, MyFrame::TestNotebookSizers
) 
  67   EVT_MENU(LAYOUT_TEST_GB_SIZER
, MyFrame::TestGridBagSizer
) 
  68   EVT_MENU(LAYOUT_TEST_SET_MINIMAL
, MyFrame::TestSetMinimal
) 
  69   EVT_MENU(LAYOUT_TEST_NESTED
, MyFrame::TestNested
) 
  70   EVT_MENU(LAYOUT_TEST_WRAP
, MyFrame::TestWrap
) 
  73 // Define my frame constructor 
  75        : wxFrame(NULL
, wxID_ANY
, _T("wxWidgets Layout Demo"), 
  76                  wxPoint(30,30), wxDefaultSize
, 
  77                  wxDEFAULT_FRAME_STYLE 
| wxNO_FULL_REPAINT_ON_RESIZE
) 
  80   wxMenu 
*file_menu 
= new wxMenu
; 
  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")); 
  86   file_menu
->Append(LAYOUT_TEST_SET_MINIMAL
, _T("Test Set&ItemMinSize...\tF5")); 
  87   file_menu
->Append(LAYOUT_TEST_NESTED
, _T("Test nested sizer in a wxPanel...\tF6")); 
  88   file_menu
->Append(LAYOUT_TEST_WRAP
, _T("Test wrap sizers...\tF7")); 
  90   file_menu
->AppendSeparator(); 
  91   file_menu
->Append(LAYOUT_QUIT
, _T("E&xit"), _T("Quit program")); 
  93   wxMenu 
*help_menu 
= new wxMenu
; 
  94   help_menu
->Append(LAYOUT_ABOUT
, _T("&About"), _T("About layout demo...")); 
  96   wxMenuBar 
*menu_bar 
= new wxMenuBar
; 
  98   menu_bar
->Append(file_menu
, _T("&File")); 
  99   menu_bar
->Append(help_menu
, _T("&Help")); 
 101   // Associate the menu bar with the frame 
 102   SetMenuBar(menu_bar
); 
 106   SetStatusText(_T("wxWidgets layout demo")); 
 107 #endif // wxUSE_STATUSBAR 
 109   wxPanel
* p 
= new wxPanel(this, wxID_ANY
); 
 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. 
 115   wxBoxSizer 
*topsizer 
= new wxBoxSizer( wxVERTICAL 
); 
 117   // 1) top: create wxStaticText with minimum size equal to its default size 
 119     new wxStaticText( p
, wxID_ANY
, _T("An explanation (wxALIGN_RIGHT).") ), 
 120     wxSizerFlags().Align(wxALIGN_RIGHT
).Border(wxALL 
& ~wxBOTTOM
, 5)); 
 122     new wxStaticText( p
, wxID_ANY
, _T("An explanation (wxALIGN_LEFT).") ), 
 123     wxSizerFlags().Align(wxALIGN_LEFT
).Border(wxALL 
& ~wxBOTTOM
, 5)); 
 125     new wxStaticText( p
, wxID_ANY
, _T("An explanation (wxALIGN_CENTRE_HORIZONTAL).") ), 
 126     wxSizerFlags().Align(wxALIGN_CENTRE_HORIZONTAL
).Border(wxALL 
& ~wxBOTTOM
, 5)); 
 128   // 2) top: create wxTextCtrl with minimum size (100x60) 
 130     new wxTextCtrl( p
, wxID_ANY
, _T("My text (wxEXPAND)."), wxDefaultPosition
, wxSize(100,60), wxTE_MULTILINE
), 
 131     wxSizerFlags(1).Expand().Border(wxALL
, 5)); 
 133   // 2.5) Gratuitous test of wxStaticBoxSizers 
 134   wxBoxSizer 
*statsizer 
= new wxStaticBoxSizer( 
 135     new wxStaticBox(p
, wxID_ANY
, _T("A wxStaticBoxSizer")), wxVERTICAL 
); 
 137     new wxStaticText(p
, wxID_ANY
, _T("And some TEXT inside it")), 
 138     wxSizerFlags().Border(wxALL
, 30)); 
 141     wxSizerFlags(1).Expand().Border(wxALL
, 10)); 
 143     // 2.7) And a test of wxGridSizer 
 144     wxGridSizer 
*gridsizer 
= new wxGridSizer(2, 5, 5); 
 145     gridsizer
->Add(new wxStaticText(p
, wxID_ANY
, _T("Label")), 
 146                    wxSizerFlags().Align(wxALIGN_RIGHT 
| wxALIGN_CENTER_VERTICAL
)); 
 147     gridsizer
->Add(new wxTextCtrl(p
, wxID_ANY
, _T("Grid sizer demo")), 
 148                    wxSizerFlags(1).Align(wxGROW 
| wxALIGN_CENTER_VERTICAL
)); 
 149     gridsizer
->Add(new wxStaticText(p
, wxID_ANY
, _T("Another label")), 
 150                    wxSizerFlags().Align(wxALIGN_RIGHT 
| wxALIGN_CENTER_VERTICAL
)); 
 151     gridsizer
->Add(new wxTextCtrl(p
, wxID_ANY
, _T("More text")), 
 152                    wxSizerFlags(1).Align(wxGROW 
| wxALIGN_CENTER_VERTICAL
)); 
 153     gridsizer
->Add(new wxStaticText(p
, wxID_ANY
, _T("Final label")), 
 154                    wxSizerFlags().Align(wxALIGN_RIGHT 
| wxALIGN_CENTER_VERTICAL
)); 
 155     gridsizer
->Add(new wxTextCtrl(p
, wxID_ANY
, _T("And yet more text")), 
 156                    wxSizerFlags().Align(wxGROW 
| wxALIGN_CENTER_VERTICAL
)); 
 159         wxSizerFlags().Proportion(1).Expand().Border(wxALL
, 10)); 
 163   // 3) middle: create wxStaticLine with minimum size (3x3) 
 165      new wxStaticLine( p
, wxID_ANY
, wxDefaultPosition
, wxSize(3,3), wxHORIZONTAL
), 
 166      wxSizerFlags().Expand()); 
 167 #endif // wxUSE_STATLINE 
 170   // 4) bottom: create two centred wxButtons 
 171   wxBoxSizer 
*button_box 
= new wxBoxSizer( wxHORIZONTAL 
); 
 173      new wxButton( p
, wxID_ANY
, _T("Two buttons in a box") ), 
 174      wxSizerFlags().Border(wxALL
, 7)); 
 176      new wxButton( p
, wxID_ANY
, _T("(wxCENTER)") ), 
 177      wxSizerFlags().Border(wxALL
, 7)); 
 179   topsizer
->Add(button_box
, wxSizerFlags().Center()); 
 181   p
->SetSizer( topsizer 
); 
 183   // don't allow frame to get smaller than what the sizers tell it and also set 
 184   // the initial size as calculated by the sizers 
 185   topsizer
->SetSizeHints( this ); 
 188 void MyFrame::OnQuit(wxCommandEvent
& WXUNUSED(event
)) 
 193 void MyFrame::TestProportions(wxCommandEvent
& WXUNUSED(event
)) 
 195     (new MyProportionsFrame(this))->Show(); 
 198 void MyFrame::TestFlexSizers(wxCommandEvent
& WXUNUSED(event
) ) 
 200     MyFlexSizerFrame 
*newFrame 
= new MyFlexSizerFrame(_T("Flex Sizer Test Frame"), 50, 50); 
 201     newFrame
->Show(true); 
 204 void MyFrame::TestNotebookSizers(wxCommandEvent
& WXUNUSED(event
) ) 
 206     MySizerDialog 
dialog( this, _T("Notebook Sizer Test Dialog") ); 
 211 void MyFrame::TestSetMinimal(wxCommandEvent
& WXUNUSED(event
) ) 
 213     MySimpleSizerFrame 
*newFrame 
= new MySimpleSizerFrame(_T("Simple Sizer Test Frame"), 50, 50); 
 214     newFrame
->Show(true); 
 217 void MyFrame::TestNested(wxCommandEvent
& WXUNUSED(event
) ) 
 219     MyNestedSizerFrame 
*newFrame 
= new MyNestedSizerFrame(_T("Nested Sizer Test Frame"), 50, 50); 
 220     newFrame
->Show(true); 
 223 void MyFrame::TestWrap(wxCommandEvent
& WXUNUSED(event
) ) 
 225     MyWrapSizerFrame 
*newFrame 
= new MyWrapSizerFrame(_T("Wrap Sizer Test Frame"), 50, 50); 
 226     newFrame
->Show(true); 
 230 void MyFrame::OnAbout(wxCommandEvent
& WXUNUSED(event
) ) 
 232     (void)wxMessageBox(_T("wxWidgets GUI library layout demo\n"), 
 233             _T("About Layout Demo"), wxOK
|wxICON_INFORMATION
); 
 236 void MyFrame::TestGridBagSizer(wxCommandEvent
& WXUNUSED(event
) ) 
 238     MyGridBagSizerFrame 
*newFrame 
= new 
 239         MyGridBagSizerFrame(_T("wxGridBagSizer Test Frame"), 50, 50); 
 240     newFrame
->Show(true); 
 243 // ---------------------------------------------------------------------------- 
 244 // MyProportionsFrame 
 245 // ---------------------------------------------------------------------------- 
 247 MyProportionsFrame::MyProportionsFrame(wxFrame 
*parent
) 
 248                   : wxFrame(parent
, wxID_ANY
, _T("Box Sizer Proportions Demo")) 
 252     // create the controls 
 253     wxPanel 
*panel 
= new wxPanel(this, wxID_ANY
); 
 254     for ( n 
= 0; n 
< WXSIZEOF(m_spins
); n
++ ) 
 256         m_spins
[n
] = new wxSpinCtrl(panel
); 
 257         m_spins
[n
]->SetValue(n
); 
 261     m_sizer 
= new wxStaticBoxSizer(wxHORIZONTAL
, panel
, 
 262                 _T("Try changing elements proportions and resizing the window")); 
 263     for ( n 
= 0; n 
< WXSIZEOF(m_spins
); n
++ ) 
 264         m_sizer
->Add(m_spins
[n
], wxSizerFlags().Border()); 
 266     // put everything together 
 267     panel
->SetSizer(m_sizer
); 
 268     wxSizer 
*sizerTop 
= new wxBoxSizer(wxVERTICAL
); 
 269     sizerTop
->Add(panel
, wxSizerFlags(1).Expand().Border()); 
 271     SetSizerAndFit(sizerTop
); 
 273     // and connect the events 
 274     Connect(wxEVT_COMMAND_TEXT_UPDATED
, 
 275                 wxCommandEventHandler(MyProportionsFrame::OnProportionUpdated
)); 
 276     Connect(wxEVT_COMMAND_SPINCTRL_UPDATED
, 
 277             wxSpinEventHandler(MyProportionsFrame::OnProportionChanged
)); 
 280 void MyProportionsFrame::UpdateProportions() 
 282     for ( size_t n 
= 0; n 
< WXSIZEOF(m_spins
); n
++ ) 
 284         m_sizer
->GetItem(n
)->SetProportion(m_spins
[n
]->GetValue()); 
 290 void MyProportionsFrame::OnProportionUpdated(wxCommandEvent
& WXUNUSED(event
)) 
 295 void MyProportionsFrame::OnProportionChanged(wxSpinEvent
& WXUNUSED(event
)) 
 300 // ---------------------------------------------------------------------------- 
 302 // ---------------------------------------------------------------------------- 
 304 void MyFlexSizerFrame::InitFlexSizer(wxFlexGridSizer 
*sizer
, wxWindow
* parent
) 
 306     for ( int i 
= 0; i 
< 3; i
++ ) 
 308         for ( int j 
= 0; j 
< 3; j
++ ) 
 310             sizer
->Add(new wxStaticText
 
 314                             wxString::Format(_T("(%d, %d)"), i 
+ 1, j 
+ 1), 
 319                        0, wxEXPAND 
| wxALIGN_CENTER_VERTICAL 
| wxALL
, 3); 
 324 MyFlexSizerFrame::MyFlexSizerFrame(const wxString 
&title
, int x
, int y 
) 
 325             : wxFrame(NULL
, wxID_ANY
, title
, wxPoint(x
, y
) ) 
 327     wxFlexGridSizer 
*sizerFlex
; 
 328     wxPanel
* p 
= new wxPanel(this, wxID_ANY
); 
 330     // consttuct the first column 
 331     wxSizer 
*sizerCol1 
= new wxBoxSizer(wxVERTICAL
); 
 332     sizerCol1
->Add(new wxStaticText(p
, wxID_ANY
, _T("Ungrowable:")), 0, wxCENTER 
| wxTOP
, 20); 
 333     sizerFlex 
= new wxFlexGridSizer(3, 3); 
 334     InitFlexSizer(sizerFlex
, p
); 
 335     sizerCol1
->Add(sizerFlex
, 1, wxALL 
| wxEXPAND
, 10); 
 337     sizerCol1
->Add(new wxStaticText(p
, wxID_ANY
, _T("Growable middle column:")), 0, wxCENTER 
| wxTOP
, 20); 
 338     sizerFlex 
= new wxFlexGridSizer(3, 3); 
 339     InitFlexSizer(sizerFlex
, p
); 
 340     sizerFlex
->AddGrowableCol(1); 
 341     sizerCol1
->Add(sizerFlex
, 1, wxALL 
| wxEXPAND
, 10); 
 343     sizerCol1
->Add(new wxStaticText(p
, wxID_ANY
, _T("Growable middle row:")), 0, wxCENTER 
| wxTOP
, 20); 
 344     sizerFlex 
= new wxFlexGridSizer(3, 3); 
 345     InitFlexSizer(sizerFlex
, p
); 
 346     sizerFlex
->AddGrowableRow(1); 
 347     sizerCol1
->Add(sizerFlex
, 1, wxALL 
| wxEXPAND
, 10); 
 349     sizerCol1
->Add(new wxStaticText(p
, wxID_ANY
, _T("All growable columns:")), 0, wxCENTER 
| wxTOP
, 20); 
 350     sizerFlex 
= new wxFlexGridSizer(3, 3); 
 351     InitFlexSizer(sizerFlex
, p
); 
 352     sizerFlex
->AddGrowableCol(0, 1); 
 353     sizerFlex
->AddGrowableCol(1, 2); 
 354     sizerFlex
->AddGrowableCol(2, 3); 
 355     sizerCol1
->Add(sizerFlex
, 1, wxALL 
| wxEXPAND
, 10); 
 358     wxSizer 
*sizerCol2 
= new wxBoxSizer(wxVERTICAL
); 
 359     sizerCol2
->Add(new wxStaticText(p
, wxID_ANY
, _T("Growable middle row and column:")), 0, wxCENTER 
| wxTOP
, 20); 
 360     sizerFlex 
= new wxFlexGridSizer(3, 3); 
 361     InitFlexSizer(sizerFlex
, p
); 
 362     sizerFlex
->AddGrowableCol(1); 
 363     sizerFlex
->AddGrowableRow(1); 
 364     sizerCol2
->Add(sizerFlex
, 1, wxALL 
| wxEXPAND
, 10); 
 366     sizerCol2
->Add(new wxStaticText(p
, wxID_ANY
, _T("Same with horz flex direction")), 0, wxCENTER 
| wxTOP
, 20); 
 367     sizerFlex 
= new wxFlexGridSizer(3, 3); 
 368     InitFlexSizer(sizerFlex
, p
); 
 369     sizerFlex
->AddGrowableCol(1); 
 370     sizerFlex
->AddGrowableRow(1); 
 371     sizerFlex
->SetFlexibleDirection(wxHORIZONTAL
); 
 372     sizerCol2
->Add(sizerFlex
, 1, wxALL 
| wxEXPAND
, 10); 
 374     sizerCol2
->Add(new wxStaticText(p
, wxID_ANY
, _T("Same with grow mode == \"none\"")), 0, wxCENTER 
| wxTOP
, 20); 
 375     sizerFlex 
= new wxFlexGridSizer(3, 3); 
 376     InitFlexSizer(sizerFlex
, p
); 
 377     sizerFlex
->AddGrowableCol(1); 
 378     sizerFlex
->AddGrowableRow(1); 
 379     sizerFlex
->SetFlexibleDirection(wxHORIZONTAL
); 
 380     sizerFlex
->SetNonFlexibleGrowMode(wxFLEX_GROWMODE_NONE
); 
 381     sizerCol2
->Add(sizerFlex
, 1, wxALL 
| wxEXPAND
, 10); 
 383     sizerCol2
->Add(new wxStaticText(p
, wxID_ANY
, _T("Same with grow mode == \"all\"")), 0, wxCENTER 
| wxTOP
, 20); 
 384     sizerFlex 
= new wxFlexGridSizer(3, 3); 
 385     InitFlexSizer(sizerFlex
, p
); 
 386     sizerFlex
->AddGrowableCol(1); 
 387     sizerFlex
->AddGrowableRow(1); 
 388     sizerFlex
->SetFlexibleDirection(wxHORIZONTAL
); 
 389     sizerFlex
->SetNonFlexibleGrowMode(wxFLEX_GROWMODE_ALL
); 
 390     sizerCol2
->Add(sizerFlex
, 1, wxALL 
| wxEXPAND
, 10); 
 392     // add both columns to grid sizer 
 393     wxGridSizer 
*sizerTop 
= new wxGridSizer(2, 0, 20); 
 394     sizerTop
->Add(sizerCol1
, 1, wxEXPAND
); 
 395     sizerTop
->Add(sizerCol2
, 1, wxEXPAND
); 
 397     p
->SetSizer(sizerTop
); 
 398     sizerTop
->SetSizeHints(this); 
 401 // ---------------------------------------------------------------------------- 
 403 // ---------------------------------------------------------------------------- 
 405 MySizerDialog::MySizerDialog(wxWindow 
*parent
, const wxString 
&title
) 
 406              : wxDialog(parent
, wxID_ANY
, wxString(title
)) 
 408     // Begin with first hierarchy: a notebook at the top and 
 409     // and OK button at the bottom. 
 411     wxBoxSizer 
*topsizer 
= new wxBoxSizer( wxVERTICAL 
); 
 413     wxNotebook 
*notebook 
= new wxNotebook( this, wxID_ANY 
); 
 414     topsizer
->Add( notebook
, 1, wxGROW 
); 
 416     wxButton 
*button 
= new wxButton( this, wxID_OK
, _T("OK") ); 
 417     topsizer
->Add( button
, 0, wxALIGN_RIGHT 
| wxALL
, 10 ); 
 419     // First page: one big text ctrl 
 420     wxTextCtrl 
*multi 
= new wxTextCtrl( notebook
, wxID_ANY
, _T("TextCtrl."), wxDefaultPosition
, wxDefaultSize
, wxTE_MULTILINE 
); 
 421     notebook
->AddPage( multi
, _T("Page One") ); 
 423     // Second page: a text ctrl and a button 
 424     wxPanel 
*panel 
= new wxPanel( notebook
, wxID_ANY 
); 
 425     notebook
->AddPage( panel
, _T("Page Two") ); 
 427     wxSizer 
*panelsizer 
= new wxBoxSizer( wxVERTICAL 
); 
 429     wxTextCtrl 
*text 
= new wxTextCtrl( panel
, wxID_ANY
, _T("TextLine 1."), wxDefaultPosition
, wxSize(250,wxDefaultCoord
) ); 
 430     panelsizer
->Add( text
, 0, wxGROW
|wxALL
, 30 ); 
 431     text 
= new wxTextCtrl( panel
, wxID_ANY
, _T("TextLine 2."), wxDefaultPosition
, wxSize(250,wxDefaultCoord
) ); 
 432     panelsizer
->Add( text
, 0, wxGROW
|wxALL
, 30 ); 
 433     wxButton 
*button2 
= new wxButton( panel
, wxID_ANY
, _T("Hallo") ); 
 434     panelsizer
->Add( button2
, 0, wxALIGN_RIGHT 
| wxLEFT
|wxRIGHT
|wxBOTTOM
, 30 ); 
 436     panel
->SetSizer( panelsizer 
); 
 438     // Tell dialog to use sizer 
 439     SetSizerAndFit( topsizer 
); 
 442 // ---------------------------------------------------------------------------- 
 443 // MyGridBagSizerFrame 
 444 // ---------------------------------------------------------------------------- 
 446 // some simple macros to help make the sample code below more clear 
 447 #define TEXTCTRL(text)   new wxTextCtrl(p, wxID_ANY, _T(text)) 
 448 #define MLTEXTCTRL(text) new wxTextCtrl(p, wxID_ANY, _T(text), wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE) 
 449 #define POS(r, c)        wxGBPosition(r,c) 
 450 #define SPAN(r, c)       wxGBSpan(r,c) 
 452 const wxChar gbsDescription
[] =_T("\ 
 453 The wxGridBagSizer is similar to the wxFlexGridSizer except the items are explicitly positioned\n\ 
 454 in a virtual cell of the layout grid, and column or row spanning is allowed.  For example, this\n\ 
 455 static text is positioned at (0,0) and it spans 7 columns."); 
 469 BEGIN_EVENT_TABLE(MyGridBagSizerFrame
, wxFrame
) 
 470     EVT_BUTTON( GBS_HIDE_BTN
,  MyGridBagSizerFrame::OnHideBtn
) 
 471     EVT_BUTTON( GBS_SHOW_BTN
,  MyGridBagSizerFrame::OnShowBtn
) 
 472     EVT_BUTTON( GBS_MOVE_BTN1
, MyGridBagSizerFrame::OnMoveBtn
) 
 473     EVT_BUTTON( GBS_MOVE_BTN2
, MyGridBagSizerFrame::OnMoveBtn
) 
 477 MyGridBagSizerFrame::MyGridBagSizerFrame(const wxString 
&title
, int x
, int y 
) 
 478     : wxFrame( NULL
, wxID_ANY
, title
, wxPoint(x
, y
) ) 
 480     wxPanel
* p 
= new wxPanel(this, wxID_ANY
); 
 482     m_gbs 
= new wxGridBagSizer(); 
 485     m_gbs
->Add( new wxStaticText(p
, wxID_ANY
, gbsDescription
), 
 486                 POS(0,0), SPAN(1, 7), 
 487                 wxALIGN_CENTER 
| wxALL
, 5); 
 489     m_gbs
->Add( TEXTCTRL("pos(1,0)"),   POS(1,0) ); 
 490     m_gbs
->Add( TEXTCTRL("pos(1,1)"),   POS(1,1) ); 
 491     m_gbs
->Add( TEXTCTRL("pos(2,0)"),   POS(2,0) ); 
 492     m_gbs
->Add( TEXTCTRL("pos(2,1)"),   POS(2,1) ); 
 493     m_gbs
->Add( MLTEXTCTRL("pos(3,2), span(1,2)\nthis row and col are growable"), 
 494               POS(3,2), SPAN(1,2), wxEXPAND 
); 
 495     m_gbs
->Add( MLTEXTCTRL("pos(4,3)\nspan(3,1)"), 
 496               POS(4,3), SPAN(3,1), wxEXPAND 
); 
 497     m_gbs
->Add( TEXTCTRL("pos(5,4)"),   POS(5,4), wxDefaultSpan
, wxEXPAND 
); 
 498     m_gbs
->Add( TEXTCTRL("pos(6,5)"),   POS(6,5), wxDefaultSpan
, wxEXPAND 
); 
 499     m_gbs
->Add( TEXTCTRL("pos(7,6)"),   POS(7,6) ); 
 501     //m_gbs->Add( TEXTCTRL("bad position"), POS(4,3) );  // Test for assert 
 502     //m_gbs->Add( TEXTCTRL("bad position"), POS(5,3) );  // Test for assert 
 505     m_moveBtn1 
= new wxButton(p
, GBS_MOVE_BTN1
, _T("Move this to (3,6)")); 
 506     m_moveBtn2 
= new wxButton(p
, GBS_MOVE_BTN2
, _T("Move this to (3,6)")); 
 507     m_gbs
->Add( m_moveBtn1
, POS(10,2) ); 
 508     m_gbs
->Add( m_moveBtn2
, POS(10,3) ); 
 510     m_hideBtn 
= new wxButton(p
, GBS_HIDE_BTN
, _T("Hide this item -->")); 
 511     m_gbs
->Add(m_hideBtn
, POS(12, 3)); 
 513     m_hideTxt 
= new wxTextCtrl(p
, wxID_ANY
, _T("pos(12,4), size(150, wxDefaultCoord)"), 
 514                                 wxDefaultPosition
, wxSize(150,wxDefaultCoord
)); 
 515     m_gbs
->Add( m_hideTxt
, POS(12,4) ); 
 517     m_showBtn 
= new wxButton(p
, GBS_SHOW_BTN
, _T("<-- Show it again")); 
 518     m_gbs
->Add(m_showBtn
, POS(12, 5)); 
 519     m_showBtn
->Disable(); 
 521     m_gbs
->Add(10,10, POS(14,0)); 
 523     m_gbs
->AddGrowableRow(3); 
 524     m_gbs
->AddGrowableCol(2); 
 526     p
->SetSizerAndFit(m_gbs
); 
 527     SetClientSize(p
->GetSize()); 
 531 void MyGridBagSizerFrame::OnHideBtn(wxCommandEvent
&) 
 533     m_gbs
->Hide(m_hideTxt
); 
 534     m_hideBtn
->Disable(); 
 539 void MyGridBagSizerFrame::OnShowBtn(wxCommandEvent
&) 
 541     m_gbs
->Show(m_hideTxt
); 
 543     m_showBtn
->Disable(); 
 548 void MyGridBagSizerFrame::OnMoveBtn(wxCommandEvent
& event
) 
 550     wxButton
* btn 
= (wxButton
*)event
.GetEventObject(); 
 551     wxGBPosition curPos 
= m_gbs
->GetItemPosition(btn
); 
 553     // if it's already at the "other" spot then move it back 
 554     if (curPos 
== wxGBPosition(3,6)) 
 556         m_gbs
->SetItemPosition(btn
, m_lastPos
); 
 557         btn
->SetLabel(_T("Move this to (3,6)")); 
 561         if ( m_gbs
->CheckForIntersection(wxGBPosition(3,6), wxGBSpan(1,1)) ) 
 563 _T("wxGridBagSizer will not allow items to be in the same cell as\n\ 
 564 another item, so this operation will fail.  You will also get an assert\n\ 
 565 when compiled in debug mode."), _T("Warning"), wxOK 
| wxICON_INFORMATION
); 
 567         if ( m_gbs
->SetItemPosition(btn
, wxGBPosition(3,6)) ) 
 570             btn
->SetLabel(_T("Move it back")); 
 576 // ---------------------------------------------------------------------------- 
 577 // MySimpleSizerFrame 
 578 // ---------------------------------------------------------------------------- 
 586 BEGIN_EVENT_TABLE(MySimpleSizerFrame
, wxFrame
) 
 587     EVT_MENU( ID_SET_SMALL
, MySimpleSizerFrame::OnSetSmallSize
) 
 588     EVT_MENU( ID_SET_BIG
, MySimpleSizerFrame::OnSetBigSize
) 
 591 MySimpleSizerFrame::MySimpleSizerFrame(const wxString 
&title
, int x
, int y 
) 
 592     : wxFrame( NULL
, wxID_ANY
, title
, wxPoint(x
, y
) ) 
 594     wxMenu 
*menu 
= new wxMenu
; 
 596     menu
->Append(ID_SET_SMALL
, _T("Make text control small\tF4")); 
 597     menu
->Append(ID_SET_BIG
, _T("Make text control big\tF5")); 
 599     wxMenuBar 
*menu_bar 
= new wxMenuBar
; 
 600     menu_bar
->Append(menu
, _T("&File")); 
 602     SetMenuBar( menu_bar 
); 
 604     wxBoxSizer 
*main_sizer 
= new wxBoxSizer( wxHORIZONTAL 
); 
 606     m_target 
= new wxTextCtrl( this, wxID_ANY
, wxEmptyString
, wxDefaultPosition
, wxSize( 80, wxDefaultCoord 
) ); 
 607     main_sizer
->Add( m_target
, 1, wxALL
, 5 ); 
 609     main_sizer
->Add( new wxStaticText( this, wxID_ANY
, wxT("Set alternating sizes using F4 and F5") ), 0, wxALL
, 5 ); 
 611     SetSizer( main_sizer
); 
 614     GetSizer()->Fit( this ); 
 617 void MySimpleSizerFrame::OnSetSmallSize( wxCommandEvent
& WXUNUSED(event
)) 
 619     GetSizer()->SetItemMinSize( m_target
, 40, -1 ); 
 621     GetSizer()->Fit( this ); 
 624 void MySimpleSizerFrame::OnSetBigSize( wxCommandEvent
& WXUNUSED(event
)) 
 626     GetSizer()->SetItemMinSize( m_target
, 140, -1 ); 
 628     GetSizer()->Fit( this ); 
 632 // ---------------------------------------------------------------------------- 
 633 // MyNestedSizerFrame 
 634 // ---------------------------------------------------------------------------- 
 637 MyNestedSizerFrame::MyNestedSizerFrame(const wxString 
&title
, int x
, int y 
) 
 638     : wxFrame( NULL
, wxID_ANY
, title
, wxPoint(x
, y
) ) 
 640     wxMenu 
*menu 
= new wxMenu
; 
 642     menu
->Append(wxID_ABOUT
, _T("Do nothing")); 
 644     wxMenuBar 
*menu_bar 
= new wxMenuBar
; 
 645     menu_bar
->Append(menu
, _T("&File")); 
 647     SetMenuBar( menu_bar 
); 
 649     wxBoxSizer 
*main_sizer 
= new wxBoxSizer( wxVERTICAL 
); 
 651     main_sizer
->Add( new wxStaticText( this, -1, wxT("Hello outside") ), 0, wxALIGN_CENTER 
); 
 652     main_sizer
->Add( new wxStaticText( this, -1, wxT("Hello outside") ), 0, wxALIGN_CENTER 
); 
 653     main_sizer
->Add( new wxStaticText( this, -1, wxT("Hello outside") ), 0, wxALIGN_CENTER 
); 
 654     main_sizer
->Add( new wxStaticText( this, -1, wxT("Hello outside") ), 0, wxALIGN_CENTER 
); 
 656     wxPanel 
*panel 
= new wxPanel( this, -1, wxDefaultPosition
, wxDefaultSize
,  
 657                                   wxTAB_TRAVERSAL 
| wxSUNKEN_BORDER 
); 
 658     main_sizer
->Add( panel
, 0, wxALIGN_CENTER 
); 
 659     wxBoxSizer 
*panel_sizer 
= new wxBoxSizer( wxVERTICAL 
); 
 660     panel
->SetSizer( panel_sizer 
); 
 661     panel_sizer
->Add( new wxStaticText( panel
, -1, wxT("Hello inside") ) ); 
 662     panel_sizer
->Add( new wxStaticText( panel
, -1, wxT("Hello inside") ) ); 
 663     panel_sizer
->Add( new wxStaticText( panel
, -1, wxT("Hello inside") ) ); 
 665     main_sizer
->Add( new wxStaticText( this, -1, wxT("Hello outside") ), 0, wxALIGN_CENTER 
); 
 667     m_target 
= new wxTextCtrl( this, wxID_ANY
, wxEmptyString
, wxDefaultPosition
, wxSize( 80, wxDefaultCoord 
) ); 
 668     main_sizer
->Add( m_target
, 1, wxALL
|wxGROW
, 5 ); 
 670     SetSizerAndFit( main_sizer
); 
 674 // ---------------------------------------------------------------------------- 
 676 // ---------------------------------------------------------------------------- 
 679 MyWrapSizerFrame::MyWrapSizerFrame(const wxString 
&title
, int x
, int y 
) 
 680     : wxFrame( NULL
, wxID_ANY
, title
, wxPoint(x
, y
), wxSize(200,-1) ) 
 682     wxMenu 
*menu 
= new wxMenu
; 
 684     menu
->Append(wxID_ABOUT
, "Do nothing"); 
 686     wxMenuBar 
*menu_bar 
= new wxMenuBar
; 
 687     menu_bar
->Append(menu
, "&File"); 
 689     SetMenuBar( menu_bar 
); 
 691     wxBoxSizer 
*root 
= new wxBoxSizer( wxVERTICAL 
); 
 694     wxSizer 
*row 
= new wxWrapSizer
; 
 696     for (i 
= 0; i 
< 4; i
++) 
 697        row
->Add( new wxButton( this, -1, "Hello" ), 0, wxALL
, 10 ); 
 698     root
->Add( row
, 0, wxGROW 
); 
 700     row 
= new wxWrapSizer
; 
 701     for (i 
= 0; i 
< 4; i
++) 
 702        row
->Add( new wxButton( this, -1, "Hello" ) ); 
 703     root
->Add( row
, 0, wxGROW 
); 
 706     // A number of checkboxes inside a wrap sizer  
 707     wxSizer 
*ps_mid 
= new wxStaticBoxSizer( wxVERTICAL
, this, "Wrapping check-boxes" ); 
 708     wxSizer 
*ps_mid_wrap 
= new wxWrapSizer(wxHORIZONTAL
); 
 709     ps_mid
->Add( ps_mid_wrap
, 100, wxEXPAND 
); 
 710     for( int ix
=0; ix
<6; ix
++ ) 
 711             ps_mid_wrap
->Add( new wxCheckBox(this,wxID_ANY
,wxString::Format("Option %d",ix
+1)), 0, wxALIGN_CENTRE
|wxALIGN_CENTER_VERTICAL
|wxALL
, 5 ); 
 712     root
->Add( ps_mid
, 0, wxEXPAND 
| wxALL
, 5 ); 
 714     // A shaped item inside a box sizer 
 715     wxSizer 
*ps_bottom 
= new wxStaticBoxSizer( wxVERTICAL
, this, "With wxSHAPED item" ); 
 716     wxSizer 
*ps_bottom_box 
= new wxBoxSizer(wxHORIZONTAL
); 
 717     ps_bottom
->Add( ps_bottom_box
, 100, wxEXPAND 
); 
 718     ps_bottom_box
->Add( new wxListBox(this,wxID_ANY
,wxPoint(0,0),wxSize(70,70)), 0, wxEXPAND
|wxSHAPED 
); 
 719     ps_bottom_box
->Add( 10,10 ); 
 720     ps_bottom_box
->Add( new wxCheckBox(this,wxID_ANY
,"A much longer option..."), 100, 0, 5 ); 
 722     root
->Add( ps_bottom
, 1, wxEXPAND 
| wxALL
, 5 ); 
 725     // Set sizer for window 
 726     SetSizerAndFit( root 
);