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 licence
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"
34 #include "wx/generic/stattextg.h"
38 #ifndef wxHAS_IMAGES_IN_RESOURCES
39 #include "../sample.xpm"
43 // ----------------------------------------------------------------------------
45 // ----------------------------------------------------------------------------
51 if ( !wxApp::OnInit() )
54 // Create the main frame window
55 MyFrame
*frame
= new MyFrame
;
62 // ----------------------------------------------------------------------------
64 // ----------------------------------------------------------------------------
66 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
67 EVT_MENU(LAYOUT_ABOUT
, MyFrame::OnAbout
)
68 EVT_MENU(LAYOUT_QUIT
, MyFrame::OnQuit
)
70 EVT_MENU(LAYOUT_TEST_PROPORTIONS
, MyFrame::TestProportions
)
71 EVT_MENU(LAYOUT_TEST_SIZER
, MyFrame::TestFlexSizers
)
72 EVT_MENU(LAYOUT_TEST_NB_SIZER
, MyFrame::TestNotebookSizers
)
73 EVT_MENU(LAYOUT_TEST_GB_SIZER
, MyFrame::TestGridBagSizer
)
74 EVT_MENU(LAYOUT_TEST_SET_MINIMAL
, MyFrame::TestSetMinimal
)
75 EVT_MENU(LAYOUT_TEST_NESTED
, MyFrame::TestNested
)
76 EVT_MENU(LAYOUT_TEST_WRAP
, MyFrame::TestWrap
)
79 // Define my frame constructor
81 : wxFrame(NULL
, wxID_ANY
, wxT("wxWidgets Layout Demo"))
83 SetIcon(wxICON(sample
));
86 wxMenu
*file_menu
= new wxMenu
;
88 file_menu
->Append(LAYOUT_TEST_PROPORTIONS
, wxT("&Proportions demo...\tF1"));
89 file_menu
->Append(LAYOUT_TEST_SIZER
, wxT("Test wx&FlexSizer...\tF2"));
90 file_menu
->Append(LAYOUT_TEST_NB_SIZER
, wxT("Test ¬ebook sizers...\tF3"));
91 file_menu
->Append(LAYOUT_TEST_GB_SIZER
, wxT("Test &gridbag sizer...\tF4"));
92 file_menu
->Append(LAYOUT_TEST_SET_MINIMAL
, wxT("Test Set&ItemMinSize...\tF5"));
93 file_menu
->Append(LAYOUT_TEST_NESTED
, wxT("Test nested sizer in a wxPanel...\tF6"));
94 file_menu
->Append(LAYOUT_TEST_WRAP
, wxT("Test wrap sizers...\tF7"));
96 file_menu
->AppendSeparator();
97 file_menu
->Append(LAYOUT_QUIT
, wxT("E&xit"), wxT("Quit program"));
99 wxMenu
*help_menu
= new wxMenu
;
100 help_menu
->Append(LAYOUT_ABOUT
, wxT("&About"), wxT("About layout demo..."));
102 wxMenuBar
*menu_bar
= new wxMenuBar
;
104 menu_bar
->Append(file_menu
, wxT("&File"));
105 menu_bar
->Append(help_menu
, wxT("&Help"));
107 // Associate the menu bar with the frame
108 SetMenuBar(menu_bar
);
112 SetStatusText(wxT("wxWidgets layout demo"));
113 #endif // wxUSE_STATUSBAR
115 wxPanel
* p
= new wxPanel(this, wxID_ANY
);
117 // we want to get a dialog that is stretchable because it
118 // has a text ctrl in the middle. at the bottom, we have
119 // two buttons which.
121 wxBoxSizer
*topsizer
= new wxBoxSizer( wxVERTICAL
);
123 // 1) top: create wxStaticText with minimum size equal to its default size
125 new wxStaticText( p
, wxID_ANY
, wxT("An explanation (wxALIGN_RIGHT).") ),
126 wxSizerFlags().Align(wxALIGN_RIGHT
).Border(wxALL
& ~wxBOTTOM
, 5));
128 new wxStaticText( p
, wxID_ANY
, wxT("An explanation (wxALIGN_LEFT).") ),
129 wxSizerFlags().Align(wxALIGN_LEFT
).Border(wxALL
& ~wxBOTTOM
, 5));
131 new wxStaticText( p
, wxID_ANY
, wxT("An explanation (wxALIGN_CENTRE_HORIZONTAL).") ),
132 wxSizerFlags().Align(wxALIGN_CENTRE_HORIZONTAL
).Border(wxALL
& ~wxBOTTOM
, 5));
134 // 2) top: create wxTextCtrl with minimum size (100x60)
136 new wxTextCtrl( p
, wxID_ANY
, wxT("My text (wxEXPAND)."), wxDefaultPosition
, wxSize(100,60), wxTE_MULTILINE
),
137 wxSizerFlags(1).Expand().Border(wxALL
, 5));
139 // 2.5) Gratuitous test of wxStaticBoxSizers
140 wxBoxSizer
*statsizer
= new wxStaticBoxSizer(
141 new wxStaticBox(p
, wxID_ANY
, wxT("A wxStaticBoxSizer")), wxVERTICAL
);
143 new wxStaticText(p
, wxID_ANY
, wxT("And some TEXT inside it")),
144 wxSizerFlags().Border(wxALL
, 30));
147 wxSizerFlags(1).Expand().Border(wxALL
, 10));
149 // 2.7) And a test of wxGridSizer
150 wxGridSizer
*gridsizer
= new wxGridSizer(2, 5, 5);
151 gridsizer
->Add(new wxStaticText(p
, wxID_ANY
, wxT("Label")),
152 wxSizerFlags().Align(wxALIGN_RIGHT
| wxALIGN_CENTER_VERTICAL
));
153 gridsizer
->Add(new wxTextCtrl(p
, wxID_ANY
, wxT("Grid sizer demo")),
154 wxSizerFlags(1).Align(wxGROW
| wxALIGN_CENTER_VERTICAL
));
155 gridsizer
->Add(new wxStaticText(p
, wxID_ANY
, wxT("Another label")),
156 wxSizerFlags().Align(wxALIGN_RIGHT
| wxALIGN_CENTER_VERTICAL
));
157 gridsizer
->Add(new wxTextCtrl(p
, wxID_ANY
, wxT("More text")),
158 wxSizerFlags(1).Align(wxGROW
| wxALIGN_CENTER_VERTICAL
));
159 gridsizer
->Add(new wxStaticText(p
, wxID_ANY
, wxT("Final label")),
160 wxSizerFlags().Align(wxALIGN_RIGHT
| wxALIGN_CENTER_VERTICAL
));
161 gridsizer
->Add(new wxTextCtrl(p
, wxID_ANY
, wxT("And yet more text")),
162 wxSizerFlags().Align(wxGROW
| wxALIGN_CENTER_VERTICAL
));
165 wxSizerFlags().Proportion(1).Expand().Border(wxALL
, 10));
169 // 3) middle: create wxStaticLine with minimum size (3x3)
171 new wxStaticLine( p
, wxID_ANY
, wxDefaultPosition
, wxSize(3,3), wxHORIZONTAL
),
172 wxSizerFlags().Expand());
173 #endif // wxUSE_STATLINE
176 // 4) bottom: create two centred wxButtons
177 wxBoxSizer
*button_box
= new wxBoxSizer( wxHORIZONTAL
);
179 new wxButton( p
, wxID_ANY
, wxT("Two buttons in a box") ),
180 wxSizerFlags().Border(wxALL
, 7));
182 new wxButton( p
, wxID_ANY
, wxT("(wxCENTER)") ),
183 wxSizerFlags().Border(wxALL
, 7));
185 topsizer
->Add(button_box
, wxSizerFlags().Center());
187 p
->SetSizer( topsizer
);
189 // don't allow frame to get smaller than what the sizers tell it and also set
190 // the initial size as calculated by the sizers
191 topsizer
->SetSizeHints( this );
194 void MyFrame::OnQuit(wxCommandEvent
& WXUNUSED(event
))
199 void MyFrame::TestProportions(wxCommandEvent
& WXUNUSED(event
))
201 (new MyProportionsFrame(this))->Show();
204 void MyFrame::TestFlexSizers(wxCommandEvent
& WXUNUSED(event
) )
206 MyFlexSizerFrame
*newFrame
= new MyFlexSizerFrame(wxT("Flex Sizer Test Frame"), 50, 50);
207 newFrame
->Show(true);
210 void MyFrame::TestNotebookSizers(wxCommandEvent
& WXUNUSED(event
) )
212 MySizerDialog
dialog( this, wxT("Notebook Sizer Test Dialog") );
217 void MyFrame::TestSetMinimal(wxCommandEvent
& WXUNUSED(event
) )
219 MySimpleSizerFrame
*newFrame
= new MySimpleSizerFrame(wxT("Simple Sizer Test Frame"), 50, 50);
220 newFrame
->Show(true);
223 void MyFrame::TestNested(wxCommandEvent
& WXUNUSED(event
) )
225 MyNestedSizerFrame
*newFrame
= new MyNestedSizerFrame(wxT("Nested Sizer Test Frame"), 50, 50);
226 newFrame
->Show(true);
229 void MyFrame::TestWrap(wxCommandEvent
& WXUNUSED(event
) )
231 MyWrapSizerFrame
*newFrame
= new MyWrapSizerFrame(wxT("Wrap Sizer Test Frame"), 50, 50);
232 newFrame
->Show(true);
236 void MyFrame::OnAbout(wxCommandEvent
& WXUNUSED(event
) )
238 (void)wxMessageBox(wxT("wxWidgets GUI library layout demo\n"),
239 wxT("About Layout Demo"), wxOK
|wxICON_INFORMATION
);
242 void MyFrame::TestGridBagSizer(wxCommandEvent
& WXUNUSED(event
) )
244 MyGridBagSizerFrame
*newFrame
= new
245 MyGridBagSizerFrame(wxT("wxGridBagSizer Test Frame"), 50, 50);
246 newFrame
->Show(true);
249 // ----------------------------------------------------------------------------
250 // MyProportionsFrame
251 // ----------------------------------------------------------------------------
253 MyProportionsFrame::MyProportionsFrame(wxFrame
*parent
)
254 : wxFrame(parent
, wxID_ANY
, wxT("Box Sizer Proportions Demo"))
258 // create the controls
259 wxPanel
*panel
= new wxPanel(this, wxID_ANY
);
260 for ( n
= 0; n
< WXSIZEOF(m_spins
); n
++ )
262 m_spins
[n
] = new wxSpinCtrl(panel
);
263 m_spins
[n
]->SetValue(n
);
267 m_sizer
= new wxStaticBoxSizer(wxHORIZONTAL
, panel
,
268 wxT("Try changing elements proportions and resizing the window"));
269 for ( n
= 0; n
< WXSIZEOF(m_spins
); n
++ )
270 m_sizer
->Add(m_spins
[n
], wxSizerFlags().Border());
272 // put everything together
273 panel
->SetSizer(m_sizer
);
274 wxSizer
*sizerTop
= new wxBoxSizer(wxVERTICAL
);
275 sizerTop
->Add(panel
, wxSizerFlags(1).Expand().Border());
277 SetSizerAndFit(sizerTop
);
279 // and connect the events
280 Connect(wxEVT_COMMAND_TEXT_UPDATED
,
281 wxCommandEventHandler(MyProportionsFrame::OnProportionUpdated
));
282 Connect(wxEVT_COMMAND_SPINCTRL_UPDATED
,
283 wxSpinEventHandler(MyProportionsFrame::OnProportionChanged
));
286 void MyProportionsFrame::UpdateProportions()
288 for ( size_t n
= 0; n
< WXSIZEOF(m_spins
); n
++ )
290 m_sizer
->GetItem(n
)->SetProportion(m_spins
[n
]->GetValue());
296 void MyProportionsFrame::OnProportionUpdated(wxCommandEvent
& WXUNUSED(event
))
301 void MyProportionsFrame::OnProportionChanged(wxSpinEvent
& WXUNUSED(event
))
306 // ----------------------------------------------------------------------------
308 // ----------------------------------------------------------------------------
310 void MyFlexSizerFrame::InitFlexSizer(wxFlexGridSizer
*sizer
, wxWindow
* parent
)
312 for ( int i
= 0; i
< 3; i
++ )
314 for ( int j
= 0; j
< 3; j
++ )
316 wxWindow
* const cell
= new wxGenericStaticText
320 wxString::Format("(%d, %d)",
324 cell
->SetBackgroundColour( *wxLIGHT_GREY
);
325 sizer
->Add(cell
, 0, wxEXPAND
| wxALIGN_CENTER_VERTICAL
| wxALL
, 3);
330 MyFlexSizerFrame::MyFlexSizerFrame(const wxString
&title
, int x
, int y
)
331 : wxFrame(NULL
, wxID_ANY
, title
, wxPoint(x
, y
) )
333 wxFlexGridSizer
*sizerFlex
;
334 wxPanel
* p
= new wxPanel(this, wxID_ANY
);
336 // consttuct the first column
337 wxSizer
*sizerCol1
= new wxBoxSizer(wxVERTICAL
);
338 sizerCol1
->Add(new wxStaticText(p
, wxID_ANY
, wxT("Ungrowable:")), 0, wxCENTER
| wxTOP
, 20);
339 sizerFlex
= new wxFlexGridSizer(3, 3, wxSize(5, 5));
340 InitFlexSizer(sizerFlex
, p
);
341 sizerCol1
->Add(sizerFlex
, 1, wxALL
| wxEXPAND
, 10);
343 sizerCol1
->Add(new wxStaticText(p
, wxID_ANY
, wxT("Growable middle column:")), 0, wxCENTER
| wxTOP
, 20);
344 sizerFlex
= new wxFlexGridSizer(3, 3, wxSize(5, 5));
345 InitFlexSizer(sizerFlex
, p
);
346 sizerFlex
->AddGrowableCol(1);
347 sizerCol1
->Add(sizerFlex
, 1, wxALL
| wxEXPAND
, 10);
349 sizerCol1
->Add(new wxStaticText(p
, wxID_ANY
, wxT("Growable middle row:")), 0, wxCENTER
| wxTOP
, 20);
350 sizerFlex
= new wxFlexGridSizer(3, 3, wxSize(5, 5));
351 InitFlexSizer(sizerFlex
, p
);
352 sizerFlex
->AddGrowableRow(1);
353 sizerCol1
->Add(sizerFlex
, 1, wxALL
| wxEXPAND
, 10);
355 sizerCol1
->Add(new wxStaticText(p
, wxID_ANY
, wxT("All growable columns:")), 0, wxCENTER
| wxTOP
, 20);
356 sizerFlex
= new wxFlexGridSizer(3, 3, wxSize(5, 5));
357 InitFlexSizer(sizerFlex
, p
);
358 sizerFlex
->AddGrowableCol(0, 1);
359 sizerFlex
->AddGrowableCol(1, 2);
360 sizerFlex
->AddGrowableCol(2, 3);
361 sizerCol1
->Add(sizerFlex
, 1, wxALL
| wxEXPAND
, 10);
364 wxSizer
*sizerCol2
= new wxBoxSizer(wxVERTICAL
);
365 sizerCol2
->Add(new wxStaticText(p
, wxID_ANY
, wxT("Growable middle row and column:")), 0, wxCENTER
| wxTOP
, 20);
366 sizerFlex
= new wxFlexGridSizer(3, 3, wxSize(5, 5));
367 InitFlexSizer(sizerFlex
, p
);
368 sizerFlex
->AddGrowableCol(1);
369 sizerFlex
->AddGrowableRow(1);
370 sizerCol2
->Add(sizerFlex
, 1, wxALL
| wxEXPAND
, 10);
372 sizerCol2
->Add(new wxStaticText(p
, wxID_ANY
, wxT("Same with horz flex direction")), 0, wxCENTER
| wxTOP
, 20);
373 sizerFlex
= new wxFlexGridSizer(3, 3, wxSize(5, 5));
374 InitFlexSizer(sizerFlex
, p
);
375 sizerFlex
->AddGrowableCol(1);
376 sizerFlex
->AddGrowableRow(1);
377 sizerFlex
->SetFlexibleDirection(wxHORIZONTAL
);
378 sizerCol2
->Add(sizerFlex
, 1, wxALL
| wxEXPAND
, 10);
380 sizerCol2
->Add(new wxStaticText(p
, wxID_ANY
, wxT("Same with grow mode == \"none\"")), 0, wxCENTER
| wxTOP
, 20);
381 sizerFlex
= new wxFlexGridSizer(3, 3, wxSize(5, 5));
382 InitFlexSizer(sizerFlex
, p
);
383 sizerFlex
->AddGrowableCol(1);
384 sizerFlex
->AddGrowableRow(1);
385 sizerFlex
->SetFlexibleDirection(wxHORIZONTAL
);
386 sizerFlex
->SetNonFlexibleGrowMode(wxFLEX_GROWMODE_NONE
);
387 sizerCol2
->Add(sizerFlex
, 1, wxALL
| wxEXPAND
, 10);
389 sizerCol2
->Add(new wxStaticText(p
, wxID_ANY
, wxT("Same with grow mode == \"all\"")), 0, wxCENTER
| wxTOP
, 20);
390 sizerFlex
= new wxFlexGridSizer(3, 3, wxSize(5, 5));
391 InitFlexSizer(sizerFlex
, p
);
392 sizerFlex
->AddGrowableCol(1);
393 sizerFlex
->AddGrowableRow(1);
394 sizerFlex
->SetFlexibleDirection(wxHORIZONTAL
);
395 sizerFlex
->SetNonFlexibleGrowMode(wxFLEX_GROWMODE_ALL
);
396 sizerCol2
->Add(sizerFlex
, 1, wxALL
| wxEXPAND
, 10);
398 // add both columns to grid sizer
399 wxGridSizer
*sizerTop
= new wxGridSizer(2, 0, 20);
400 sizerTop
->Add(sizerCol1
, 1, wxEXPAND
);
401 sizerTop
->Add(sizerCol2
, 1, wxEXPAND
);
403 p
->SetSizer(sizerTop
);
404 sizerTop
->SetSizeHints(this);
407 // ----------------------------------------------------------------------------
409 // ----------------------------------------------------------------------------
411 MySizerDialog::MySizerDialog(wxWindow
*parent
, const wxString
&title
)
412 : wxDialog(parent
, wxID_ANY
, wxString(title
))
414 // Begin with first hierarchy: a notebook at the top and
415 // and OK button at the bottom.
417 wxBoxSizer
*topsizer
= new wxBoxSizer( wxVERTICAL
);
419 wxNotebook
*notebook
= new wxNotebook( this, wxID_ANY
);
420 topsizer
->Add( notebook
, 1, wxGROW
);
422 wxButton
*button
= new wxButton( this, wxID_OK
, wxT("OK") );
423 topsizer
->Add( button
, 0, wxALIGN_RIGHT
| wxALL
, 10 );
425 // First page: one big text ctrl
426 wxTextCtrl
*multi
= new wxTextCtrl( notebook
, wxID_ANY
, wxT("TextCtrl."), wxDefaultPosition
, wxDefaultSize
, wxTE_MULTILINE
);
427 notebook
->AddPage( multi
, wxT("Page One") );
429 // Second page: a text ctrl and a button
430 wxPanel
*panel
= new wxPanel( notebook
, wxID_ANY
);
431 notebook
->AddPage( panel
, wxT("Page Two") );
433 wxSizer
*panelsizer
= new wxBoxSizer( wxVERTICAL
);
435 wxTextCtrl
*text
= new wxTextCtrl( panel
, wxID_ANY
, wxT("TextLine 1."), wxDefaultPosition
, wxSize(250,wxDefaultCoord
) );
436 panelsizer
->Add( text
, 0, wxGROW
|wxALL
, 30 );
437 text
= new wxTextCtrl( panel
, wxID_ANY
, wxT("TextLine 2."), wxDefaultPosition
, wxSize(250,wxDefaultCoord
) );
438 panelsizer
->Add( text
, 0, wxGROW
|wxALL
, 30 );
439 wxButton
*button2
= new wxButton( panel
, wxID_ANY
, wxT("Hallo") );
440 panelsizer
->Add( button2
, 0, wxALIGN_RIGHT
| wxLEFT
|wxRIGHT
|wxBOTTOM
, 30 );
442 panel
->SetSizer( panelsizer
);
444 // Tell dialog to use sizer
445 SetSizerAndFit( topsizer
);
448 // ----------------------------------------------------------------------------
449 // MyGridBagSizerFrame
450 // ----------------------------------------------------------------------------
452 // some simple macros to help make the sample code below more clear
453 #define TEXTCTRL(text) new wxTextCtrl(p, wxID_ANY, wxT(text))
454 #define MLTEXTCTRL(text) new wxTextCtrl(p, wxID_ANY, wxT(text), wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE)
455 #define POS(r, c) wxGBPosition(r,c)
456 #define SPAN(r, c) wxGBSpan(r,c)
458 const wxChar gbsDescription
[] =wxT("\
459 The wxGridBagSizer is similar to the wxFlexGridSizer except the items are explicitly positioned\n\
460 in a virtual cell of the layout grid, and column or row spanning is allowed. For example, this\n\
461 static text is positioned at (0,0) and it spans 7 columns.");
475 BEGIN_EVENT_TABLE(MyGridBagSizerFrame
, wxFrame
)
476 EVT_BUTTON( GBS_HIDE_BTN
, MyGridBagSizerFrame::OnHideBtn
)
477 EVT_BUTTON( GBS_SHOW_BTN
, MyGridBagSizerFrame::OnShowBtn
)
478 EVT_BUTTON( GBS_MOVE_BTN1
, MyGridBagSizerFrame::OnMoveBtn
)
479 EVT_BUTTON( GBS_MOVE_BTN2
, MyGridBagSizerFrame::OnMoveBtn
)
483 MyGridBagSizerFrame::MyGridBagSizerFrame(const wxString
&title
, int x
, int y
)
484 : wxFrame( NULL
, wxID_ANY
, title
, wxPoint(x
, y
) )
486 wxPanel
* p
= new wxPanel(this, wxID_ANY
);
488 m_gbs
= new wxGridBagSizer();
491 m_gbs
->Add( new wxStaticText(p
, wxID_ANY
, gbsDescription
),
492 POS(0,0), SPAN(1, 7),
493 wxALIGN_CENTER
| wxALL
, 5);
495 m_gbs
->Add( TEXTCTRL("pos(1,0)"), POS(1,0) );
496 m_gbs
->Add( TEXTCTRL("pos(1,1)"), POS(1,1) );
497 m_gbs
->Add( TEXTCTRL("pos(2,0)"), POS(2,0) );
498 m_gbs
->Add( TEXTCTRL("pos(2,1)"), POS(2,1) );
499 m_gbs
->Add( MLTEXTCTRL("pos(3,2), span(1,2)\nthis row and col are growable"),
500 POS(3,2), SPAN(1,2), wxEXPAND
);
501 m_gbs
->Add( MLTEXTCTRL("pos(4,3)\nspan(3,1)"),
502 POS(4,3), SPAN(3,1), wxEXPAND
);
503 m_gbs
->Add( TEXTCTRL("pos(5,4)"), POS(5,4), wxDefaultSpan
, wxEXPAND
);
504 m_gbs
->Add( TEXTCTRL("pos(6,5)"), POS(6,5), wxDefaultSpan
, wxEXPAND
);
505 m_gbs
->Add( TEXTCTRL("pos(7,6)"), POS(7,6) );
507 //m_gbs->Add( TEXTCTRL("bad position"), POS(4,3) ); // Test for assert
508 //m_gbs->Add( TEXTCTRL("bad position"), POS(5,3) ); // Test for assert
511 m_moveBtn1
= new wxButton(p
, GBS_MOVE_BTN1
, wxT("Move this to (3,6)"));
512 m_moveBtn2
= new wxButton(p
, GBS_MOVE_BTN2
, wxT("Move this to (3,6)"));
513 m_gbs
->Add( m_moveBtn1
, POS(10,2) );
514 m_gbs
->Add( m_moveBtn2
, POS(10,3) );
516 m_hideBtn
= new wxButton(p
, GBS_HIDE_BTN
, wxT("Hide this item -->"));
517 m_gbs
->Add(m_hideBtn
, POS(12, 3));
519 m_hideTxt
= new wxTextCtrl(p
, wxID_ANY
, wxT("pos(12,4), size(150, wxDefaultCoord)"),
520 wxDefaultPosition
, wxSize(150,wxDefaultCoord
));
521 m_gbs
->Add( m_hideTxt
, POS(12,4) );
523 m_showBtn
= new wxButton(p
, GBS_SHOW_BTN
, wxT("<-- Show it again"));
524 m_gbs
->Add(m_showBtn
, POS(12, 5));
525 m_showBtn
->Disable();
527 m_gbs
->Add(10,10, POS(14,0));
529 m_gbs
->AddGrowableRow(3);
530 m_gbs
->AddGrowableCol(2);
532 p
->SetSizerAndFit(m_gbs
);
533 SetClientSize(p
->GetSize());
537 void MyGridBagSizerFrame::OnHideBtn(wxCommandEvent
&)
539 m_gbs
->Hide(m_hideTxt
);
540 m_hideBtn
->Disable();
545 void MyGridBagSizerFrame::OnShowBtn(wxCommandEvent
&)
547 m_gbs
->Show(m_hideTxt
);
549 m_showBtn
->Disable();
554 void MyGridBagSizerFrame::OnMoveBtn(wxCommandEvent
& event
)
556 wxButton
* btn
= (wxButton
*)event
.GetEventObject();
557 wxGBPosition curPos
= m_gbs
->GetItemPosition(btn
);
559 // if it's already at the "other" spot then move it back
560 if (curPos
== wxGBPosition(3,6))
562 m_gbs
->SetItemPosition(btn
, m_lastPos
);
563 btn
->SetLabel(wxT("Move this to (3,6)"));
567 if ( m_gbs
->CheckForIntersection(wxGBPosition(3,6), wxGBSpan(1,1)) )
569 wxT("wxGridBagSizer will not allow items to be in the same cell as\n\
570 another item, so this operation will fail. You will also get an assert\n\
571 when compiled in debug mode."), wxT("Warning"), wxOK
| wxICON_INFORMATION
);
573 if ( m_gbs
->SetItemPosition(btn
, wxGBPosition(3,6)) )
576 btn
->SetLabel(wxT("Move it back"));
582 // ----------------------------------------------------------------------------
583 // MySimpleSizerFrame
584 // ----------------------------------------------------------------------------
592 BEGIN_EVENT_TABLE(MySimpleSizerFrame
, wxFrame
)
593 EVT_MENU( ID_SET_SMALL
, MySimpleSizerFrame::OnSetSmallSize
)
594 EVT_MENU( ID_SET_BIG
, MySimpleSizerFrame::OnSetBigSize
)
597 MySimpleSizerFrame::MySimpleSizerFrame(const wxString
&title
, int x
, int y
)
598 : wxFrame( NULL
, wxID_ANY
, title
, wxPoint(x
, y
) )
600 wxMenu
*menu
= new wxMenu
;
602 menu
->Append(ID_SET_SMALL
, wxT("Make text control small\tF4"));
603 menu
->Append(ID_SET_BIG
, wxT("Make text control big\tF5"));
605 wxMenuBar
*menu_bar
= new wxMenuBar
;
606 menu_bar
->Append(menu
, wxT("&File"));
608 SetMenuBar( menu_bar
);
610 wxBoxSizer
*main_sizer
= new wxBoxSizer( wxHORIZONTAL
);
612 m_target
= new wxTextCtrl( this, wxID_ANY
, wxEmptyString
, wxDefaultPosition
, wxSize( 80, wxDefaultCoord
) );
613 main_sizer
->Add( m_target
, 1, wxALL
, 5 );
615 main_sizer
->Add( new wxStaticText( this, wxID_ANY
, wxT("Set alternating sizes using F4 and F5") ), 0, wxALL
, 5 );
617 SetSizer( main_sizer
);
620 GetSizer()->Fit( this );
623 void MySimpleSizerFrame::OnSetSmallSize( wxCommandEvent
& WXUNUSED(event
))
625 GetSizer()->SetItemMinSize( m_target
, 40, -1 );
627 GetSizer()->Fit( this );
630 void MySimpleSizerFrame::OnSetBigSize( wxCommandEvent
& WXUNUSED(event
))
632 GetSizer()->SetItemMinSize( m_target
, 140, -1 );
634 GetSizer()->Fit( this );
638 // ----------------------------------------------------------------------------
639 // MyNestedSizerFrame
640 // ----------------------------------------------------------------------------
643 MyNestedSizerFrame::MyNestedSizerFrame(const wxString
&title
, int x
, int y
)
644 : wxFrame( NULL
, wxID_ANY
, title
, wxPoint(x
, y
) )
646 wxMenu
*menu
= new wxMenu
;
648 menu
->Append(wxID_ABOUT
, wxT("Do nothing"));
650 wxMenuBar
*menu_bar
= new wxMenuBar
;
651 menu_bar
->Append(menu
, wxT("&File"));
653 SetMenuBar( menu_bar
);
655 wxBoxSizer
*main_sizer
= new wxBoxSizer( wxVERTICAL
);
657 main_sizer
->Add( new wxStaticText( this, -1, wxT("Hello outside") ), 0, wxALIGN_CENTER
);
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
);
662 wxPanel
*panel
= new wxPanel( this, -1, wxDefaultPosition
, wxDefaultSize
,
663 wxTAB_TRAVERSAL
| wxSUNKEN_BORDER
);
664 main_sizer
->Add( panel
, 0, wxALIGN_CENTER
);
665 wxBoxSizer
*panel_sizer
= new wxBoxSizer( wxVERTICAL
);
666 panel
->SetSizer( panel_sizer
);
667 panel_sizer
->Add( new wxStaticText( panel
, -1, wxT("Hello inside") ) );
668 panel_sizer
->Add( new wxStaticText( panel
, -1, wxT("Hello inside") ) );
669 panel_sizer
->Add( new wxStaticText( panel
, -1, wxT("Hello inside") ) );
671 main_sizer
->Add( new wxStaticText( this, -1, wxT("Hello outside") ), 0, wxALIGN_CENTER
);
673 m_target
= new wxTextCtrl( this, wxID_ANY
, wxEmptyString
, wxDefaultPosition
, wxSize( 80, wxDefaultCoord
) );
674 main_sizer
->Add( m_target
, 1, wxALL
|wxGROW
, 5 );
676 SetSizerAndFit( main_sizer
);
680 // ----------------------------------------------------------------------------
682 // ----------------------------------------------------------------------------
684 BEGIN_EVENT_TABLE(MyWrapSizerFrame
, wxFrame
)
685 EVT_MENU(wxID_ADD
, MyWrapSizerFrame::OnAddCheckbox
)
686 EVT_MENU(wxID_REMOVE
, MyWrapSizerFrame::OnRemoveCheckbox
)
689 MyWrapSizerFrame::MyWrapSizerFrame(const wxString
&title
, int x
, int y
)
690 : wxFrame( NULL
, wxID_ANY
, title
, wxPoint(x
, y
), wxSize(200,-1) )
692 wxMenu
*menu
= new wxMenu
;
694 menu
->Append(wxID_ADD
, "&Add a checkbox\tCtrl-+");
695 menu
->Append(wxID_REMOVE
, "&Remove a checkbox\tCtrl--");
697 wxMenuBar
*menu_bar
= new wxMenuBar
;
698 menu_bar
->Append(menu
, "&Wrap sizer");
700 SetMenuBar( menu_bar
);
702 wxBoxSizer
*root
= new wxBoxSizer( wxVERTICAL
);
704 wxStaticBoxSizer
*topSizer
= new wxStaticBoxSizer( wxVERTICAL
, this, "Wrapping check-boxes" );
705 m_checkboxParent
= topSizer
->GetStaticBox();
706 m_wrapSizer
= new wxWrapSizer(wxHORIZONTAL
);
708 // A number of checkboxes inside a wrap sizer
709 for( int i
= 0; i
< 6; i
++ )
712 topSizer
->Add( m_wrapSizer
, wxSizerFlags(1).Expand());
713 root
->Add( topSizer
, wxSizerFlags().Expand().Border());
715 // A shaped item inside a box sizer
716 wxSizer
*bottomSizer
= new wxStaticBoxSizer( wxVERTICAL
, this, "With wxSHAPED item" );
717 wxSizer
*horzBoxSizer
= new wxBoxSizer(wxHORIZONTAL
);
718 bottomSizer
->Add( horzBoxSizer
, 100, wxEXPAND
);
719 horzBoxSizer
->Add( new wxListBox(this,wxID_ANY
,wxPoint(0,0),wxSize(70,70)), 0, wxEXPAND
|wxSHAPED
);
720 horzBoxSizer
->Add( 10,10 );
721 horzBoxSizer
->Add( new wxCheckBox(this,wxID_ANY
,"A much longer option..."), 100, 0, 5 );
723 root
->Add( bottomSizer
, 1, wxEXPAND
| wxALL
, 5 );
725 // Set sizer for window
726 SetSizerAndFit( root
);
729 void MyWrapSizerFrame::DoAddCheckbox()
731 m_wrapSizer
->Add(new wxCheckBox
738 (int)m_wrapSizer
->GetItemCount() + 1
741 wxSizerFlags().Centre().Border());
744 void MyWrapSizerFrame::OnAddCheckbox(wxCommandEvent
& WXUNUSED(event
))
750 void MyWrapSizerFrame::OnRemoveCheckbox(wxCommandEvent
& WXUNUSED(event
))
752 if ( m_wrapSizer
->IsEmpty() )
754 wxLogStatus(this, "No more checkboxes to remove.");
758 delete m_wrapSizer
->GetItem(m_wrapSizer
->GetItemCount() - 1)->GetWindow();