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"
38 #include "../sample.xpm"
42 // ----------------------------------------------------------------------------
44 // ----------------------------------------------------------------------------
50 if ( !wxApp::OnInit() )
53 // Create the main frame window
54 MyFrame
*frame
= new MyFrame
;
61 // ----------------------------------------------------------------------------
63 // ----------------------------------------------------------------------------
65 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
66 EVT_MENU(LAYOUT_ABOUT
, MyFrame::OnAbout
)
67 EVT_MENU(LAYOUT_QUIT
, MyFrame::OnQuit
)
69 EVT_MENU(LAYOUT_TEST_PROPORTIONS
, MyFrame::TestProportions
)
70 EVT_MENU(LAYOUT_TEST_SIZER
, MyFrame::TestFlexSizers
)
71 EVT_MENU(LAYOUT_TEST_NB_SIZER
, MyFrame::TestNotebookSizers
)
72 EVT_MENU(LAYOUT_TEST_GB_SIZER
, MyFrame::TestGridBagSizer
)
73 EVT_MENU(LAYOUT_TEST_SET_MINIMAL
, MyFrame::TestSetMinimal
)
74 EVT_MENU(LAYOUT_TEST_NESTED
, MyFrame::TestNested
)
75 EVT_MENU(LAYOUT_TEST_WRAP
, MyFrame::TestWrap
)
78 // Define my frame constructor
80 : wxFrame(NULL
, wxID_ANY
, wxT("wxWidgets Layout Demo"),
81 wxPoint(30,30), wxDefaultSize
,
82 wxDEFAULT_FRAME_STYLE
| wxNO_FULL_REPAINT_ON_RESIZE
)
84 SetIcon(wxICON(sample
));
87 wxMenu
*file_menu
= new wxMenu
;
89 file_menu
->Append(LAYOUT_TEST_PROPORTIONS
, wxT("&Proportions demo...\tF1"));
90 file_menu
->Append(LAYOUT_TEST_SIZER
, wxT("Test wx&FlexSizer...\tF2"));
91 file_menu
->Append(LAYOUT_TEST_NB_SIZER
, wxT("Test ¬ebook sizers...\tF3"));
92 file_menu
->Append(LAYOUT_TEST_GB_SIZER
, wxT("Test &gridbag sizer...\tF4"));
93 file_menu
->Append(LAYOUT_TEST_SET_MINIMAL
, wxT("Test Set&ItemMinSize...\tF5"));
94 file_menu
->Append(LAYOUT_TEST_NESTED
, wxT("Test nested sizer in a wxPanel...\tF6"));
95 file_menu
->Append(LAYOUT_TEST_WRAP
, wxT("Test wrap sizers...\tF7"));
97 file_menu
->AppendSeparator();
98 file_menu
->Append(LAYOUT_QUIT
, wxT("E&xit"), wxT("Quit program"));
100 wxMenu
*help_menu
= new wxMenu
;
101 help_menu
->Append(LAYOUT_ABOUT
, wxT("&About"), wxT("About layout demo..."));
103 wxMenuBar
*menu_bar
= new wxMenuBar
;
105 menu_bar
->Append(file_menu
, wxT("&File"));
106 menu_bar
->Append(help_menu
, wxT("&Help"));
108 // Associate the menu bar with the frame
109 SetMenuBar(menu_bar
);
113 SetStatusText(wxT("wxWidgets layout demo"));
114 #endif // wxUSE_STATUSBAR
116 wxPanel
* p
= new wxPanel(this, wxID_ANY
);
118 // we want to get a dialog that is stretchable because it
119 // has a text ctrl in the middle. at the bottom, we have
120 // two buttons which.
122 wxBoxSizer
*topsizer
= new wxBoxSizer( wxVERTICAL
);
124 // 1) top: create wxStaticText with minimum size equal to its default size
126 new wxStaticText( p
, wxID_ANY
, wxT("An explanation (wxALIGN_RIGHT).") ),
127 wxSizerFlags().Align(wxALIGN_RIGHT
).Border(wxALL
& ~wxBOTTOM
, 5));
129 new wxStaticText( p
, wxID_ANY
, wxT("An explanation (wxALIGN_LEFT).") ),
130 wxSizerFlags().Align(wxALIGN_LEFT
).Border(wxALL
& ~wxBOTTOM
, 5));
132 new wxStaticText( p
, wxID_ANY
, wxT("An explanation (wxALIGN_CENTRE_HORIZONTAL).") ),
133 wxSizerFlags().Align(wxALIGN_CENTRE_HORIZONTAL
).Border(wxALL
& ~wxBOTTOM
, 5));
135 // 2) top: create wxTextCtrl with minimum size (100x60)
137 new wxTextCtrl( p
, wxID_ANY
, wxT("My text (wxEXPAND)."), wxDefaultPosition
, wxSize(100,60), wxTE_MULTILINE
),
138 wxSizerFlags(1).Expand().Border(wxALL
, 5));
140 // 2.5) Gratuitous test of wxStaticBoxSizers
141 wxBoxSizer
*statsizer
= new wxStaticBoxSizer(
142 new wxStaticBox(p
, wxID_ANY
, wxT("A wxStaticBoxSizer")), wxVERTICAL
);
144 new wxStaticText(p
, wxID_ANY
, wxT("And some TEXT inside it")),
145 wxSizerFlags().Border(wxALL
, 30));
148 wxSizerFlags(1).Expand().Border(wxALL
, 10));
150 // 2.7) And a test of wxGridSizer
151 wxGridSizer
*gridsizer
= new wxGridSizer(2, 5, 5);
152 gridsizer
->Add(new wxStaticText(p
, wxID_ANY
, wxT("Label")),
153 wxSizerFlags().Align(wxALIGN_RIGHT
| wxALIGN_CENTER_VERTICAL
));
154 gridsizer
->Add(new wxTextCtrl(p
, wxID_ANY
, wxT("Grid sizer demo")),
155 wxSizerFlags(1).Align(wxGROW
| wxALIGN_CENTER_VERTICAL
));
156 gridsizer
->Add(new wxStaticText(p
, wxID_ANY
, wxT("Another label")),
157 wxSizerFlags().Align(wxALIGN_RIGHT
| wxALIGN_CENTER_VERTICAL
));
158 gridsizer
->Add(new wxTextCtrl(p
, wxID_ANY
, wxT("More text")),
159 wxSizerFlags(1).Align(wxGROW
| wxALIGN_CENTER_VERTICAL
));
160 gridsizer
->Add(new wxStaticText(p
, wxID_ANY
, wxT("Final label")),
161 wxSizerFlags().Align(wxALIGN_RIGHT
| wxALIGN_CENTER_VERTICAL
));
162 gridsizer
->Add(new wxTextCtrl(p
, wxID_ANY
, wxT("And yet more text")),
163 wxSizerFlags().Align(wxGROW
| wxALIGN_CENTER_VERTICAL
));
166 wxSizerFlags().Proportion(1).Expand().Border(wxALL
, 10));
170 // 3) middle: create wxStaticLine with minimum size (3x3)
172 new wxStaticLine( p
, wxID_ANY
, wxDefaultPosition
, wxSize(3,3), wxHORIZONTAL
),
173 wxSizerFlags().Expand());
174 #endif // wxUSE_STATLINE
177 // 4) bottom: create two centred wxButtons
178 wxBoxSizer
*button_box
= new wxBoxSizer( wxHORIZONTAL
);
180 new wxButton( p
, wxID_ANY
, wxT("Two buttons in a box") ),
181 wxSizerFlags().Border(wxALL
, 7));
183 new wxButton( p
, wxID_ANY
, wxT("(wxCENTER)") ),
184 wxSizerFlags().Border(wxALL
, 7));
186 topsizer
->Add(button_box
, wxSizerFlags().Center());
188 p
->SetSizer( topsizer
);
190 // don't allow frame to get smaller than what the sizers tell it and also set
191 // the initial size as calculated by the sizers
192 topsizer
->SetSizeHints( this );
195 void MyFrame::OnQuit(wxCommandEvent
& WXUNUSED(event
))
200 void MyFrame::TestProportions(wxCommandEvent
& WXUNUSED(event
))
202 (new MyProportionsFrame(this))->Show();
205 void MyFrame::TestFlexSizers(wxCommandEvent
& WXUNUSED(event
) )
207 MyFlexSizerFrame
*newFrame
= new MyFlexSizerFrame(wxT("Flex Sizer Test Frame"), 50, 50);
208 newFrame
->Show(true);
211 void MyFrame::TestNotebookSizers(wxCommandEvent
& WXUNUSED(event
) )
213 MySizerDialog
dialog( this, wxT("Notebook Sizer Test Dialog") );
218 void MyFrame::TestSetMinimal(wxCommandEvent
& WXUNUSED(event
) )
220 MySimpleSizerFrame
*newFrame
= new MySimpleSizerFrame(wxT("Simple Sizer Test Frame"), 50, 50);
221 newFrame
->Show(true);
224 void MyFrame::TestNested(wxCommandEvent
& WXUNUSED(event
) )
226 MyNestedSizerFrame
*newFrame
= new MyNestedSizerFrame(wxT("Nested Sizer Test Frame"), 50, 50);
227 newFrame
->Show(true);
230 void MyFrame::TestWrap(wxCommandEvent
& WXUNUSED(event
) )
232 MyWrapSizerFrame
*newFrame
= new MyWrapSizerFrame(wxT("Wrap Sizer Test Frame"), 50, 50);
233 newFrame
->Show(true);
237 void MyFrame::OnAbout(wxCommandEvent
& WXUNUSED(event
) )
239 (void)wxMessageBox(wxT("wxWidgets GUI library layout demo\n"),
240 wxT("About Layout Demo"), wxOK
|wxICON_INFORMATION
);
243 void MyFrame::TestGridBagSizer(wxCommandEvent
& WXUNUSED(event
) )
245 MyGridBagSizerFrame
*newFrame
= new
246 MyGridBagSizerFrame(wxT("wxGridBagSizer Test Frame"), 50, 50);
247 newFrame
->Show(true);
250 // ----------------------------------------------------------------------------
251 // MyProportionsFrame
252 // ----------------------------------------------------------------------------
254 MyProportionsFrame::MyProportionsFrame(wxFrame
*parent
)
255 : wxFrame(parent
, wxID_ANY
, wxT("Box Sizer Proportions Demo"))
259 // create the controls
260 wxPanel
*panel
= new wxPanel(this, wxID_ANY
);
261 for ( n
= 0; n
< WXSIZEOF(m_spins
); n
++ )
263 m_spins
[n
] = new wxSpinCtrl(panel
);
264 m_spins
[n
]->SetValue(n
);
268 m_sizer
= new wxStaticBoxSizer(wxHORIZONTAL
, panel
,
269 wxT("Try changing elements proportions and resizing the window"));
270 for ( n
= 0; n
< WXSIZEOF(m_spins
); n
++ )
271 m_sizer
->Add(m_spins
[n
], wxSizerFlags().Border());
273 // put everything together
274 panel
->SetSizer(m_sizer
);
275 wxSizer
*sizerTop
= new wxBoxSizer(wxVERTICAL
);
276 sizerTop
->Add(panel
, wxSizerFlags(1).Expand().Border());
278 SetSizerAndFit(sizerTop
);
280 // and connect the events
281 Connect(wxEVT_COMMAND_TEXT_UPDATED
,
282 wxCommandEventHandler(MyProportionsFrame::OnProportionUpdated
));
283 Connect(wxEVT_COMMAND_SPINCTRL_UPDATED
,
284 wxSpinEventHandler(MyProportionsFrame::OnProportionChanged
));
287 void MyProportionsFrame::UpdateProportions()
289 for ( size_t n
= 0; n
< WXSIZEOF(m_spins
); n
++ )
291 m_sizer
->GetItem(n
)->SetProportion(m_spins
[n
]->GetValue());
297 void MyProportionsFrame::OnProportionUpdated(wxCommandEvent
& WXUNUSED(event
))
302 void MyProportionsFrame::OnProportionChanged(wxSpinEvent
& WXUNUSED(event
))
307 // ----------------------------------------------------------------------------
309 // ----------------------------------------------------------------------------
311 void MyFlexSizerFrame::InitFlexSizer(wxFlexGridSizer
*sizer
, wxWindow
* parent
)
313 for ( int i
= 0; i
< 3; i
++ )
315 for ( int j
= 0; j
< 3; j
++ )
317 sizer
->Add(new wxStaticText
321 wxString::Format(wxT("(%d, %d)"), i
+ 1, j
+ 1),
326 0, wxEXPAND
| wxALIGN_CENTER_VERTICAL
| wxALL
, 3);
331 MyFlexSizerFrame::MyFlexSizerFrame(const wxString
&title
, int x
, int y
)
332 : wxFrame(NULL
, wxID_ANY
, title
, wxPoint(x
, y
) )
334 wxFlexGridSizer
*sizerFlex
;
335 wxPanel
* p
= new wxPanel(this, wxID_ANY
);
337 // consttuct the first column
338 wxSizer
*sizerCol1
= new wxBoxSizer(wxVERTICAL
);
339 sizerCol1
->Add(new wxStaticText(p
, wxID_ANY
, wxT("Ungrowable:")), 0, wxCENTER
| wxTOP
, 20);
340 sizerFlex
= new wxFlexGridSizer(3, 3, wxSize(5, 5));
341 InitFlexSizer(sizerFlex
, p
);
342 sizerCol1
->Add(sizerFlex
, 1, wxALL
| wxEXPAND
, 10);
344 sizerCol1
->Add(new wxStaticText(p
, wxID_ANY
, wxT("Growable middle column:")), 0, wxCENTER
| wxTOP
, 20);
345 sizerFlex
= new wxFlexGridSizer(3, 3, wxSize(5, 5));
346 InitFlexSizer(sizerFlex
, p
);
347 sizerFlex
->AddGrowableCol(1);
348 sizerCol1
->Add(sizerFlex
, 1, wxALL
| wxEXPAND
, 10);
350 sizerCol1
->Add(new wxStaticText(p
, wxID_ANY
, wxT("Growable middle row:")), 0, wxCENTER
| wxTOP
, 20);
351 sizerFlex
= new wxFlexGridSizer(3, 3, wxSize(5, 5));
352 InitFlexSizer(sizerFlex
, p
);
353 sizerFlex
->AddGrowableRow(1);
354 sizerCol1
->Add(sizerFlex
, 1, wxALL
| wxEXPAND
, 10);
356 sizerCol1
->Add(new wxStaticText(p
, wxID_ANY
, wxT("All growable columns:")), 0, wxCENTER
| wxTOP
, 20);
357 sizerFlex
= new wxFlexGridSizer(3, 3, wxSize(5, 5));
358 InitFlexSizer(sizerFlex
, p
);
359 sizerFlex
->AddGrowableCol(0, 1);
360 sizerFlex
->AddGrowableCol(1, 2);
361 sizerFlex
->AddGrowableCol(2, 3);
362 sizerCol1
->Add(sizerFlex
, 1, wxALL
| wxEXPAND
, 10);
365 wxSizer
*sizerCol2
= new wxBoxSizer(wxVERTICAL
);
366 sizerCol2
->Add(new wxStaticText(p
, wxID_ANY
, wxT("Growable middle row and column:")), 0, wxCENTER
| wxTOP
, 20);
367 sizerFlex
= new wxFlexGridSizer(3, 3, wxSize(5, 5));
368 InitFlexSizer(sizerFlex
, p
);
369 sizerFlex
->AddGrowableCol(1);
370 sizerFlex
->AddGrowableRow(1);
371 sizerCol2
->Add(sizerFlex
, 1, wxALL
| wxEXPAND
, 10);
373 sizerCol2
->Add(new wxStaticText(p
, wxID_ANY
, wxT("Same with horz flex direction")), 0, wxCENTER
| wxTOP
, 20);
374 sizerFlex
= new wxFlexGridSizer(3, 3, wxSize(5, 5));
375 InitFlexSizer(sizerFlex
, p
);
376 sizerFlex
->AddGrowableCol(1);
377 sizerFlex
->AddGrowableRow(1);
378 sizerFlex
->SetFlexibleDirection(wxHORIZONTAL
);
379 sizerCol2
->Add(sizerFlex
, 1, wxALL
| wxEXPAND
, 10);
381 sizerCol2
->Add(new wxStaticText(p
, wxID_ANY
, wxT("Same with grow mode == \"none\"")), 0, wxCENTER
| wxTOP
, 20);
382 sizerFlex
= new wxFlexGridSizer(3, 3, wxSize(5, 5));
383 InitFlexSizer(sizerFlex
, p
);
384 sizerFlex
->AddGrowableCol(1);
385 sizerFlex
->AddGrowableRow(1);
386 sizerFlex
->SetFlexibleDirection(wxHORIZONTAL
);
387 sizerFlex
->SetNonFlexibleGrowMode(wxFLEX_GROWMODE_NONE
);
388 sizerCol2
->Add(sizerFlex
, 1, wxALL
| wxEXPAND
, 10);
390 sizerCol2
->Add(new wxStaticText(p
, wxID_ANY
, wxT("Same with grow mode == \"all\"")), 0, wxCENTER
| wxTOP
, 20);
391 sizerFlex
= new wxFlexGridSizer(3, 3, wxSize(5, 5));
392 InitFlexSizer(sizerFlex
, p
);
393 sizerFlex
->AddGrowableCol(1);
394 sizerFlex
->AddGrowableRow(1);
395 sizerFlex
->SetFlexibleDirection(wxHORIZONTAL
);
396 sizerFlex
->SetNonFlexibleGrowMode(wxFLEX_GROWMODE_ALL
);
397 sizerCol2
->Add(sizerFlex
, 1, wxALL
| wxEXPAND
, 10);
399 // add both columns to grid sizer
400 wxGridSizer
*sizerTop
= new wxGridSizer(2, 0, 20);
401 sizerTop
->Add(sizerCol1
, 1, wxEXPAND
);
402 sizerTop
->Add(sizerCol2
, 1, wxEXPAND
);
404 p
->SetSizer(sizerTop
);
405 sizerTop
->SetSizeHints(this);
408 // ----------------------------------------------------------------------------
410 // ----------------------------------------------------------------------------
412 MySizerDialog::MySizerDialog(wxWindow
*parent
, const wxString
&title
)
413 : wxDialog(parent
, wxID_ANY
, wxString(title
))
415 // Begin with first hierarchy: a notebook at the top and
416 // and OK button at the bottom.
418 wxBoxSizer
*topsizer
= new wxBoxSizer( wxVERTICAL
);
420 wxNotebook
*notebook
= new wxNotebook( this, wxID_ANY
);
421 topsizer
->Add( notebook
, 1, wxGROW
);
423 wxButton
*button
= new wxButton( this, wxID_OK
, wxT("OK") );
424 topsizer
->Add( button
, 0, wxALIGN_RIGHT
| wxALL
, 10 );
426 // First page: one big text ctrl
427 wxTextCtrl
*multi
= new wxTextCtrl( notebook
, wxID_ANY
, wxT("TextCtrl."), wxDefaultPosition
, wxDefaultSize
, wxTE_MULTILINE
);
428 notebook
->AddPage( multi
, wxT("Page One") );
430 // Second page: a text ctrl and a button
431 wxPanel
*panel
= new wxPanel( notebook
, wxID_ANY
);
432 notebook
->AddPage( panel
, wxT("Page Two") );
434 wxSizer
*panelsizer
= new wxBoxSizer( wxVERTICAL
);
436 wxTextCtrl
*text
= new wxTextCtrl( panel
, wxID_ANY
, wxT("TextLine 1."), wxDefaultPosition
, wxSize(250,wxDefaultCoord
) );
437 panelsizer
->Add( text
, 0, wxGROW
|wxALL
, 30 );
438 text
= new wxTextCtrl( panel
, wxID_ANY
, wxT("TextLine 2."), wxDefaultPosition
, wxSize(250,wxDefaultCoord
) );
439 panelsizer
->Add( text
, 0, wxGROW
|wxALL
, 30 );
440 wxButton
*button2
= new wxButton( panel
, wxID_ANY
, wxT("Hallo") );
441 panelsizer
->Add( button2
, 0, wxALIGN_RIGHT
| wxLEFT
|wxRIGHT
|wxBOTTOM
, 30 );
443 panel
->SetSizer( panelsizer
);
445 // Tell dialog to use sizer
446 SetSizerAndFit( topsizer
);
449 // ----------------------------------------------------------------------------
450 // MyGridBagSizerFrame
451 // ----------------------------------------------------------------------------
453 // some simple macros to help make the sample code below more clear
454 #define TEXTCTRL(text) new wxTextCtrl(p, wxID_ANY, wxT(text))
455 #define MLTEXTCTRL(text) new wxTextCtrl(p, wxID_ANY, wxT(text), wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE)
456 #define POS(r, c) wxGBPosition(r,c)
457 #define SPAN(r, c) wxGBSpan(r,c)
459 const wxChar gbsDescription
[] =wxT("\
460 The wxGridBagSizer is similar to the wxFlexGridSizer except the items are explicitly positioned\n\
461 in a virtual cell of the layout grid, and column or row spanning is allowed. For example, this\n\
462 static text is positioned at (0,0) and it spans 7 columns.");
476 BEGIN_EVENT_TABLE(MyGridBagSizerFrame
, wxFrame
)
477 EVT_BUTTON( GBS_HIDE_BTN
, MyGridBagSizerFrame::OnHideBtn
)
478 EVT_BUTTON( GBS_SHOW_BTN
, MyGridBagSizerFrame::OnShowBtn
)
479 EVT_BUTTON( GBS_MOVE_BTN1
, MyGridBagSizerFrame::OnMoveBtn
)
480 EVT_BUTTON( GBS_MOVE_BTN2
, MyGridBagSizerFrame::OnMoveBtn
)
484 MyGridBagSizerFrame::MyGridBagSizerFrame(const wxString
&title
, int x
, int y
)
485 : wxFrame( NULL
, wxID_ANY
, title
, wxPoint(x
, y
) )
487 wxPanel
* p
= new wxPanel(this, wxID_ANY
);
489 m_gbs
= new wxGridBagSizer();
492 m_gbs
->Add( new wxStaticText(p
, wxID_ANY
, gbsDescription
),
493 POS(0,0), SPAN(1, 7),
494 wxALIGN_CENTER
| wxALL
, 5);
496 m_gbs
->Add( TEXTCTRL("pos(1,0)"), POS(1,0) );
497 m_gbs
->Add( TEXTCTRL("pos(1,1)"), POS(1,1) );
498 m_gbs
->Add( TEXTCTRL("pos(2,0)"), POS(2,0) );
499 m_gbs
->Add( TEXTCTRL("pos(2,1)"), POS(2,1) );
500 m_gbs
->Add( MLTEXTCTRL("pos(3,2), span(1,2)\nthis row and col are growable"),
501 POS(3,2), SPAN(1,2), wxEXPAND
);
502 m_gbs
->Add( MLTEXTCTRL("pos(4,3)\nspan(3,1)"),
503 POS(4,3), SPAN(3,1), wxEXPAND
);
504 m_gbs
->Add( TEXTCTRL("pos(5,4)"), POS(5,4), wxDefaultSpan
, wxEXPAND
);
505 m_gbs
->Add( TEXTCTRL("pos(6,5)"), POS(6,5), wxDefaultSpan
, wxEXPAND
);
506 m_gbs
->Add( TEXTCTRL("pos(7,6)"), POS(7,6) );
508 //m_gbs->Add( TEXTCTRL("bad position"), POS(4,3) ); // Test for assert
509 //m_gbs->Add( TEXTCTRL("bad position"), POS(5,3) ); // Test for assert
512 m_moveBtn1
= new wxButton(p
, GBS_MOVE_BTN1
, wxT("Move this to (3,6)"));
513 m_moveBtn2
= new wxButton(p
, GBS_MOVE_BTN2
, wxT("Move this to (3,6)"));
514 m_gbs
->Add( m_moveBtn1
, POS(10,2) );
515 m_gbs
->Add( m_moveBtn2
, POS(10,3) );
517 m_hideBtn
= new wxButton(p
, GBS_HIDE_BTN
, wxT("Hide this item -->"));
518 m_gbs
->Add(m_hideBtn
, POS(12, 3));
520 m_hideTxt
= new wxTextCtrl(p
, wxID_ANY
, wxT("pos(12,4), size(150, wxDefaultCoord)"),
521 wxDefaultPosition
, wxSize(150,wxDefaultCoord
));
522 m_gbs
->Add( m_hideTxt
, POS(12,4) );
524 m_showBtn
= new wxButton(p
, GBS_SHOW_BTN
, wxT("<-- Show it again"));
525 m_gbs
->Add(m_showBtn
, POS(12, 5));
526 m_showBtn
->Disable();
528 m_gbs
->Add(10,10, POS(14,0));
530 m_gbs
->AddGrowableRow(3);
531 m_gbs
->AddGrowableCol(2);
533 p
->SetSizerAndFit(m_gbs
);
534 SetClientSize(p
->GetSize());
538 void MyGridBagSizerFrame::OnHideBtn(wxCommandEvent
&)
540 m_gbs
->Hide(m_hideTxt
);
541 m_hideBtn
->Disable();
546 void MyGridBagSizerFrame::OnShowBtn(wxCommandEvent
&)
548 m_gbs
->Show(m_hideTxt
);
550 m_showBtn
->Disable();
555 void MyGridBagSizerFrame::OnMoveBtn(wxCommandEvent
& event
)
557 wxButton
* btn
= (wxButton
*)event
.GetEventObject();
558 wxGBPosition curPos
= m_gbs
->GetItemPosition(btn
);
560 // if it's already at the "other" spot then move it back
561 if (curPos
== wxGBPosition(3,6))
563 m_gbs
->SetItemPosition(btn
, m_lastPos
);
564 btn
->SetLabel(wxT("Move this to (3,6)"));
568 if ( m_gbs
->CheckForIntersection(wxGBPosition(3,6), wxGBSpan(1,1)) )
570 wxT("wxGridBagSizer will not allow items to be in the same cell as\n\
571 another item, so this operation will fail. You will also get an assert\n\
572 when compiled in debug mode."), wxT("Warning"), wxOK
| wxICON_INFORMATION
);
574 if ( m_gbs
->SetItemPosition(btn
, wxGBPosition(3,6)) )
577 btn
->SetLabel(wxT("Move it back"));
583 // ----------------------------------------------------------------------------
584 // MySimpleSizerFrame
585 // ----------------------------------------------------------------------------
593 BEGIN_EVENT_TABLE(MySimpleSizerFrame
, wxFrame
)
594 EVT_MENU( ID_SET_SMALL
, MySimpleSizerFrame::OnSetSmallSize
)
595 EVT_MENU( ID_SET_BIG
, MySimpleSizerFrame::OnSetBigSize
)
598 MySimpleSizerFrame::MySimpleSizerFrame(const wxString
&title
, int x
, int y
)
599 : wxFrame( NULL
, wxID_ANY
, title
, wxPoint(x
, y
) )
601 wxMenu
*menu
= new wxMenu
;
603 menu
->Append(ID_SET_SMALL
, wxT("Make text control small\tF4"));
604 menu
->Append(ID_SET_BIG
, wxT("Make text control big\tF5"));
606 wxMenuBar
*menu_bar
= new wxMenuBar
;
607 menu_bar
->Append(menu
, wxT("&File"));
609 SetMenuBar( menu_bar
);
611 wxBoxSizer
*main_sizer
= new wxBoxSizer( wxHORIZONTAL
);
613 m_target
= new wxTextCtrl( this, wxID_ANY
, wxEmptyString
, wxDefaultPosition
, wxSize( 80, wxDefaultCoord
) );
614 main_sizer
->Add( m_target
, 1, wxALL
, 5 );
616 main_sizer
->Add( new wxStaticText( this, wxID_ANY
, wxT("Set alternating sizes using F4 and F5") ), 0, wxALL
, 5 );
618 SetSizer( main_sizer
);
621 GetSizer()->Fit( this );
624 void MySimpleSizerFrame::OnSetSmallSize( wxCommandEvent
& WXUNUSED(event
))
626 GetSizer()->SetItemMinSize( m_target
, 40, -1 );
628 GetSizer()->Fit( this );
631 void MySimpleSizerFrame::OnSetBigSize( wxCommandEvent
& WXUNUSED(event
))
633 GetSizer()->SetItemMinSize( m_target
, 140, -1 );
635 GetSizer()->Fit( this );
639 // ----------------------------------------------------------------------------
640 // MyNestedSizerFrame
641 // ----------------------------------------------------------------------------
644 MyNestedSizerFrame::MyNestedSizerFrame(const wxString
&title
, int x
, int y
)
645 : wxFrame( NULL
, wxID_ANY
, title
, wxPoint(x
, y
) )
647 wxMenu
*menu
= new wxMenu
;
649 menu
->Append(wxID_ABOUT
, wxT("Do nothing"));
651 wxMenuBar
*menu_bar
= new wxMenuBar
;
652 menu_bar
->Append(menu
, wxT("&File"));
654 SetMenuBar( menu_bar
);
656 wxBoxSizer
*main_sizer
= new wxBoxSizer( wxVERTICAL
);
658 main_sizer
->Add( new wxStaticText( this, -1, wxT("Hello outside") ), 0, wxALIGN_CENTER
);
659 main_sizer
->Add( new wxStaticText( this, -1, wxT("Hello outside") ), 0, wxALIGN_CENTER
);
660 main_sizer
->Add( new wxStaticText( this, -1, wxT("Hello outside") ), 0, wxALIGN_CENTER
);
661 main_sizer
->Add( new wxStaticText( this, -1, wxT("Hello outside") ), 0, wxALIGN_CENTER
);
663 wxPanel
*panel
= new wxPanel( this, -1, wxDefaultPosition
, wxDefaultSize
,
664 wxTAB_TRAVERSAL
| wxSUNKEN_BORDER
);
665 main_sizer
->Add( panel
, 0, wxALIGN_CENTER
);
666 wxBoxSizer
*panel_sizer
= new wxBoxSizer( wxVERTICAL
);
667 panel
->SetSizer( panel_sizer
);
668 panel_sizer
->Add( new wxStaticText( panel
, -1, wxT("Hello inside") ) );
669 panel_sizer
->Add( new wxStaticText( panel
, -1, wxT("Hello inside") ) );
670 panel_sizer
->Add( new wxStaticText( panel
, -1, wxT("Hello inside") ) );
672 main_sizer
->Add( new wxStaticText( this, -1, wxT("Hello outside") ), 0, wxALIGN_CENTER
);
674 m_target
= new wxTextCtrl( this, wxID_ANY
, wxEmptyString
, wxDefaultPosition
, wxSize( 80, wxDefaultCoord
) );
675 main_sizer
->Add( m_target
, 1, wxALL
|wxGROW
, 5 );
677 SetSizerAndFit( main_sizer
);
681 // ----------------------------------------------------------------------------
683 // ----------------------------------------------------------------------------
686 MyWrapSizerFrame::MyWrapSizerFrame(const wxString
&title
, int x
, int y
)
687 : wxFrame( NULL
, wxID_ANY
, title
, wxPoint(x
, y
), wxSize(200,-1) )
689 wxMenu
*menu
= new wxMenu
;
691 menu
->Append(wxID_ABOUT
, "Do nothing");
693 wxMenuBar
*menu_bar
= new wxMenuBar
;
694 menu_bar
->Append(menu
, "&File");
696 SetMenuBar( menu_bar
);
698 wxBoxSizer
*root
= new wxBoxSizer( wxVERTICAL
);
701 wxSizer
*row
= new wxWrapSizer
;
703 for (i
= 0; i
< 4; i
++)
704 row
->Add( new wxButton( this, -1, "Hello" ), 0, wxALL
, 10 );
705 root
->Add( row
, 0, wxGROW
);
707 row
= new wxWrapSizer
;
708 for (i
= 0; i
< 4; i
++)
709 row
->Add( new wxButton( this, -1, "Hello" ) );
710 root
->Add( row
, 0, wxGROW
);
713 // A number of checkboxes inside a wrap sizer
714 wxSizer
*ps_mid
= new wxStaticBoxSizer( wxVERTICAL
, this, "Wrapping check-boxes" );
715 wxSizer
*ps_mid_wrap
= new wxWrapSizer(wxHORIZONTAL
);
716 ps_mid
->Add( ps_mid_wrap
, 100, wxEXPAND
);
717 for( int ix
=0; ix
<6; ix
++ )
718 ps_mid_wrap
->Add( new wxCheckBox(this,wxID_ANY
,wxString::Format("Option %d",ix
+1)), 0, wxALIGN_CENTRE
|wxALIGN_CENTER_VERTICAL
|wxALL
, 5 );
719 root
->Add( ps_mid
, 0, wxEXPAND
| wxALL
, 5 );
721 // A shaped item inside a box sizer
722 wxSizer
*ps_bottom
= new wxStaticBoxSizer( wxVERTICAL
, this, "With wxSHAPED item" );
723 wxSizer
*ps_bottom_box
= new wxBoxSizer(wxHORIZONTAL
);
724 ps_bottom
->Add( ps_bottom_box
, 100, wxEXPAND
);
725 ps_bottom_box
->Add( new wxListBox(this,wxID_ANY
,wxPoint(0,0),wxSize(70,70)), 0, wxEXPAND
|wxSHAPED
);
726 ps_bottom_box
->Add( 10,10 );
727 ps_bottom_box
->Add( new wxCheckBox(this,wxID_ANY
,"A much longer option..."), 100, 0, 5 );
729 root
->Add( ps_bottom
, 1, wxEXPAND
| wxALL
, 5 );
732 // Set sizer for window
733 SetSizerAndFit( root
);