1998-05-20 14:01:55 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: layout.cpp
|
|
|
|
// Purpose: Layout sample
|
|
|
|
// Author: Julian Smart
|
2005-07-13 10:08:52 +00:00
|
|
|
// Modified by: Robin Dunn, Vadim Zeitlin
|
1998-05-20 14:01:55 +00:00
|
|
|
// Created: 04/01/98
|
2005-07-13 10:08:52 +00:00
|
|
|
// Copyright: (c) 1998 Julian Smart
|
|
|
|
// 2005 Vadim Zeitlin
|
2010-07-13 13:29:13 +00:00
|
|
|
// Licence: wxWindows licence
|
1998-05-20 14:01:55 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2003-02-27 12:02:22 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// headers
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
1998-05-20 14:01:55 +00:00
|
|
|
// For compilers that support precompilation, includes "wx/wx.h".
|
|
|
|
#include "wx/wxprec.h"
|
|
|
|
|
|
|
|
#ifdef __BORLANDC__
|
|
|
|
#pragma hdrstop
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef WX_PRECOMP
|
|
|
|
#include "wx/wx.h"
|
|
|
|
#endif
|
|
|
|
|
1999-08-08 16:45:57 +00:00
|
|
|
#include "wx/sizer.h"
|
2003-11-06 01:31:44 +00:00
|
|
|
#include "wx/gbsizer.h"
|
1999-08-08 21:09:59 +00:00
|
|
|
#include "wx/statline.h"
|
1999-12-11 15:07:14 +00:00
|
|
|
#include "wx/notebook.h"
|
2005-07-13 10:08:52 +00:00
|
|
|
#include "wx/spinctrl.h"
|
2008-06-01 15:32:41 +00:00
|
|
|
#include "wx/wrapsizer.h"
|
2009-12-08 15:56:26 +00:00
|
|
|
#include "wx/generic/stattextg.h"
|
1999-08-08 16:45:57 +00:00
|
|
|
|
1998-05-20 14:01:55 +00:00
|
|
|
#include "layout.h"
|
|
|
|
|
2012-03-04 00:28:58 +00:00
|
|
|
#ifndef wxHAS_IMAGES_IN_RESOURCES
|
2009-02-08 01:01:00 +00:00
|
|
|
#include "../sample.xpm"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2003-02-27 12:02:22 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// MyApp
|
|
|
|
// ----------------------------------------------------------------------------
|
1998-05-20 14:01:55 +00:00
|
|
|
|
|
|
|
IMPLEMENT_APP(MyApp)
|
|
|
|
|
1999-12-11 15:07:14 +00:00
|
|
|
bool MyApp::OnInit()
|
1998-05-20 14:01:55 +00:00
|
|
|
{
|
2007-02-04 00:34:18 +00:00
|
|
|
if ( !wxApp::OnInit() )
|
|
|
|
return false;
|
|
|
|
|
1998-05-20 14:01:55 +00:00
|
|
|
// Create the main frame window
|
2003-02-27 12:02:22 +00:00
|
|
|
MyFrame *frame = new MyFrame;
|
|
|
|
|
2004-02-28 10:46:36 +00:00
|
|
|
frame->Show(true);
|
2003-02-27 12:02:22 +00:00
|
|
|
|
2004-02-28 10:46:36 +00:00
|
|
|
return true;
|
2003-02-27 12:02:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// MyFrame
|
|
|
|
// ----------------------------------------------------------------------------
|
1998-05-20 14:01:55 +00:00
|
|
|
|
2014-03-30 07:07:55 +00:00
|
|
|
wxBEGIN_EVENT_TABLE(MyFrame, wxFrame)
|
2003-02-27 12:02:22 +00:00
|
|
|
EVT_MENU(LAYOUT_ABOUT, MyFrame::OnAbout)
|
|
|
|
EVT_MENU(LAYOUT_QUIT, MyFrame::OnQuit)
|
1998-05-20 14:01:55 +00:00
|
|
|
|
2005-07-13 10:08:52 +00:00
|
|
|
EVT_MENU(LAYOUT_TEST_PROPORTIONS, MyFrame::TestProportions)
|
2003-02-27 12:02:22 +00:00
|
|
|
EVT_MENU(LAYOUT_TEST_SIZER, MyFrame::TestFlexSizers)
|
|
|
|
EVT_MENU(LAYOUT_TEST_NB_SIZER, MyFrame::TestNotebookSizers)
|
2004-10-06 20:54:57 +00:00
|
|
|
EVT_MENU(LAYOUT_TEST_GB_SIZER, MyFrame::TestGridBagSizer)
|
2006-10-10 08:57:46 +00:00
|
|
|
EVT_MENU(LAYOUT_TEST_SET_MINIMAL, MyFrame::TestSetMinimal)
|
2006-10-29 18:10:32 +00:00
|
|
|
EVT_MENU(LAYOUT_TEST_NESTED, MyFrame::TestNested)
|
2007-12-08 11:37:17 +00:00
|
|
|
EVT_MENU(LAYOUT_TEST_WRAP, MyFrame::TestWrap)
|
2014-03-30 07:07:55 +00:00
|
|
|
wxEND_EVENT_TABLE()
|
1998-05-20 14:01:55 +00:00
|
|
|
|
2003-02-27 12:02:22 +00:00
|
|
|
// Define my frame constructor
|
|
|
|
MyFrame::MyFrame()
|
2009-12-08 15:56:26 +00:00
|
|
|
: wxFrame(NULL, wxID_ANY, wxT("wxWidgets Layout Demo"))
|
2003-02-27 12:02:22 +00:00
|
|
|
{
|
2009-02-08 01:01:00 +00:00
|
|
|
SetIcon(wxICON(sample));
|
1998-05-20 14:01:55 +00:00
|
|
|
|
2009-02-08 01:01:00 +00:00
|
|
|
// Make a menubar
|
|
|
|
wxMenu *file_menu = new wxMenu;
|
1998-05-20 14:01:55 +00:00
|
|
|
|
2009-07-23 20:30:22 +00:00
|
|
|
file_menu->Append(LAYOUT_TEST_PROPORTIONS, wxT("&Proportions demo...\tF1"));
|
|
|
|
file_menu->Append(LAYOUT_TEST_SIZER, wxT("Test wx&FlexSizer...\tF2"));
|
|
|
|
file_menu->Append(LAYOUT_TEST_NB_SIZER, wxT("Test ¬ebook sizers...\tF3"));
|
|
|
|
file_menu->Append(LAYOUT_TEST_GB_SIZER, wxT("Test &gridbag sizer...\tF4"));
|
|
|
|
file_menu->Append(LAYOUT_TEST_SET_MINIMAL, wxT("Test Set&ItemMinSize...\tF5"));
|
|
|
|
file_menu->Append(LAYOUT_TEST_NESTED, wxT("Test nested sizer in a wxPanel...\tF6"));
|
|
|
|
file_menu->Append(LAYOUT_TEST_WRAP, wxT("Test wrap sizers...\tF7"));
|
1998-05-20 14:01:55 +00:00
|
|
|
|
2009-02-08 01:01:00 +00:00
|
|
|
file_menu->AppendSeparator();
|
2009-07-23 20:30:22 +00:00
|
|
|
file_menu->Append(LAYOUT_QUIT, wxT("E&xit"), wxT("Quit program"));
|
1998-05-20 14:01:55 +00:00
|
|
|
|
2009-02-08 01:01:00 +00:00
|
|
|
wxMenu *help_menu = new wxMenu;
|
2009-07-23 20:30:22 +00:00
|
|
|
help_menu->Append(LAYOUT_ABOUT, wxT("&About"), wxT("About layout demo..."));
|
1998-05-20 14:01:55 +00:00
|
|
|
|
2009-02-08 01:01:00 +00:00
|
|
|
wxMenuBar *menu_bar = new wxMenuBar;
|
|
|
|
|
2009-07-23 20:30:22 +00:00
|
|
|
menu_bar->Append(file_menu, wxT("&File"));
|
|
|
|
menu_bar->Append(help_menu, wxT("&Help"));
|
1998-05-20 14:01:55 +00:00
|
|
|
|
2009-02-08 01:01:00 +00:00
|
|
|
// Associate the menu bar with the frame
|
|
|
|
SetMenuBar(menu_bar);
|
2003-02-27 12:02:22 +00:00
|
|
|
|
2004-07-19 15:36:01 +00:00
|
|
|
#if wxUSE_STATUSBAR
|
2009-02-08 01:01:00 +00:00
|
|
|
CreateStatusBar(2);
|
2009-07-23 20:30:22 +00:00
|
|
|
SetStatusText(wxT("wxWidgets layout demo"));
|
2004-07-19 15:36:01 +00:00
|
|
|
#endif // wxUSE_STATUSBAR
|
2003-02-27 12:02:22 +00:00
|
|
|
|
2009-02-08 01:01:00 +00:00
|
|
|
wxPanel* p = new wxPanel(this, wxID_ANY);
|
|
|
|
|
|
|
|
// we want to get a dialog that is stretchable because it
|
|
|
|
// has a text ctrl in the middle. at the bottom, we have
|
|
|
|
// two buttons which.
|
|
|
|
|
|
|
|
wxBoxSizer *topsizer = new wxBoxSizer( wxVERTICAL );
|
|
|
|
|
|
|
|
// 1) top: create wxStaticText with minimum size equal to its default size
|
|
|
|
topsizer->Add(
|
2009-07-23 20:30:22 +00:00
|
|
|
new wxStaticText( p, wxID_ANY, wxT("An explanation (wxALIGN_RIGHT).") ),
|
2009-02-08 01:01:00 +00:00
|
|
|
wxSizerFlags().Align(wxALIGN_RIGHT).Border(wxALL & ~wxBOTTOM, 5));
|
|
|
|
topsizer->Add(
|
2009-07-23 20:30:22 +00:00
|
|
|
new wxStaticText( p, wxID_ANY, wxT("An explanation (wxALIGN_LEFT).") ),
|
2009-02-08 01:01:00 +00:00
|
|
|
wxSizerFlags().Align(wxALIGN_LEFT).Border(wxALL & ~wxBOTTOM, 5));
|
|
|
|
topsizer->Add(
|
2009-07-23 20:30:22 +00:00
|
|
|
new wxStaticText( p, wxID_ANY, wxT("An explanation (wxALIGN_CENTRE_HORIZONTAL).") ),
|
2009-02-08 01:01:00 +00:00
|
|
|
wxSizerFlags().Align(wxALIGN_CENTRE_HORIZONTAL).Border(wxALL & ~wxBOTTOM, 5));
|
|
|
|
|
|
|
|
// 2) top: create wxTextCtrl with minimum size (100x60)
|
|
|
|
topsizer->Add(
|
2009-07-23 20:30:22 +00:00
|
|
|
new wxTextCtrl( p, wxID_ANY, wxT("My text (wxEXPAND)."), wxDefaultPosition, wxSize(100,60), wxTE_MULTILINE),
|
2009-02-08 01:01:00 +00:00
|
|
|
wxSizerFlags(1).Expand().Border(wxALL, 5));
|
|
|
|
|
|
|
|
// 2.5) Gratuitous test of wxStaticBoxSizers
|
|
|
|
wxBoxSizer *statsizer = new wxStaticBoxSizer(
|
2009-07-23 20:30:22 +00:00
|
|
|
new wxStaticBox(p, wxID_ANY, wxT("A wxStaticBoxSizer")), wxVERTICAL );
|
2009-02-08 01:01:00 +00:00
|
|
|
statsizer->Add(
|
2009-07-23 20:30:22 +00:00
|
|
|
new wxStaticText(p, wxID_ANY, wxT("And some TEXT inside it")),
|
2009-02-08 01:01:00 +00:00
|
|
|
wxSizerFlags().Border(wxALL, 30));
|
|
|
|
topsizer->Add(
|
|
|
|
statsizer,
|
|
|
|
wxSizerFlags(1).Expand().Border(wxALL, 10));
|
2003-02-27 12:02:22 +00:00
|
|
|
|
|
|
|
// 2.7) And a test of wxGridSizer
|
|
|
|
wxGridSizer *gridsizer = new wxGridSizer(2, 5, 5);
|
2009-07-23 20:30:22 +00:00
|
|
|
gridsizer->Add(new wxStaticText(p, wxID_ANY, wxT("Label")),
|
2009-02-08 01:01:00 +00:00
|
|
|
wxSizerFlags().Align(wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL));
|
2009-07-23 20:30:22 +00:00
|
|
|
gridsizer->Add(new wxTextCtrl(p, wxID_ANY, wxT("Grid sizer demo")),
|
2009-02-08 01:01:00 +00:00
|
|
|
wxSizerFlags(1).Align(wxGROW | wxALIGN_CENTER_VERTICAL));
|
2009-07-23 20:30:22 +00:00
|
|
|
gridsizer->Add(new wxStaticText(p, wxID_ANY, wxT("Another label")),
|
2009-02-08 01:01:00 +00:00
|
|
|
wxSizerFlags().Align(wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL));
|
2009-07-23 20:30:22 +00:00
|
|
|
gridsizer->Add(new wxTextCtrl(p, wxID_ANY, wxT("More text")),
|
2009-02-08 01:01:00 +00:00
|
|
|
wxSizerFlags(1).Align(wxGROW | wxALIGN_CENTER_VERTICAL));
|
2009-07-23 20:30:22 +00:00
|
|
|
gridsizer->Add(new wxStaticText(p, wxID_ANY, wxT("Final label")),
|
2009-02-08 01:01:00 +00:00
|
|
|
wxSizerFlags().Align(wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL));
|
2009-07-23 20:30:22 +00:00
|
|
|
gridsizer->Add(new wxTextCtrl(p, wxID_ANY, wxT("And yet more text")),
|
2009-02-08 01:01:00 +00:00
|
|
|
wxSizerFlags().Align(wxGROW | wxALIGN_CENTER_VERTICAL));
|
2004-09-17 21:44:00 +00:00
|
|
|
topsizer->Add(
|
|
|
|
gridsizer,
|
|
|
|
wxSizerFlags().Proportion(1).Expand().Border(wxALL, 10));
|
2003-02-27 12:02:22 +00:00
|
|
|
|
|
|
|
|
2004-07-22 19:34:59 +00:00
|
|
|
#if wxUSE_STATLINE
|
2009-02-08 01:01:00 +00:00
|
|
|
// 3) middle: create wxStaticLine with minimum size (3x3)
|
|
|
|
topsizer->Add(
|
|
|
|
new wxStaticLine( p, wxID_ANY, wxDefaultPosition, wxSize(3,3), wxHORIZONTAL),
|
|
|
|
wxSizerFlags().Expand());
|
2004-07-22 19:34:59 +00:00
|
|
|
#endif // wxUSE_STATLINE
|
2003-02-27 12:02:22 +00:00
|
|
|
|
|
|
|
|
2009-02-08 01:01:00 +00:00
|
|
|
// 4) bottom: create two centred wxButtons
|
|
|
|
wxBoxSizer *button_box = new wxBoxSizer( wxHORIZONTAL );
|
|
|
|
button_box->Add(
|
2009-07-23 20:30:22 +00:00
|
|
|
new wxButton( p, wxID_ANY, wxT("Two buttons in a box") ),
|
2009-02-08 01:01:00 +00:00
|
|
|
wxSizerFlags().Border(wxALL, 7));
|
|
|
|
button_box->Add(
|
2009-07-23 20:30:22 +00:00
|
|
|
new wxButton( p, wxID_ANY, wxT("(wxCENTER)") ),
|
2009-02-08 01:01:00 +00:00
|
|
|
wxSizerFlags().Border(wxALL, 7));
|
2003-02-27 12:02:22 +00:00
|
|
|
|
2009-02-08 01:01:00 +00:00
|
|
|
topsizer->Add(button_box, wxSizerFlags().Center());
|
2003-02-27 12:02:22 +00:00
|
|
|
|
2009-02-08 01:01:00 +00:00
|
|
|
p->SetSizer( topsizer );
|
2006-10-10 12:08:52 +00:00
|
|
|
|
2009-02-08 01:01:00 +00:00
|
|
|
// don't allow frame to get smaller than what the sizers tell it and also set
|
|
|
|
// the initial size as calculated by the sizers
|
|
|
|
topsizer->SetSizeHints( this );
|
2003-02-27 12:02:22 +00:00
|
|
|
}
|
|
|
|
|
2005-07-13 10:08:52 +00:00
|
|
|
void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
|
2003-02-27 12:02:22 +00:00
|
|
|
{
|
2004-02-28 10:46:36 +00:00
|
|
|
Close(true);
|
2003-02-27 12:02:22 +00:00
|
|
|
}
|
|
|
|
|
2005-07-13 10:08:52 +00:00
|
|
|
void MyFrame::TestProportions(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
|
|
|
(new MyProportionsFrame(this))->Show();
|
|
|
|
}
|
|
|
|
|
2003-02-27 12:02:22 +00:00
|
|
|
void MyFrame::TestFlexSizers(wxCommandEvent& WXUNUSED(event) )
|
|
|
|
{
|
2013-05-31 23:21:21 +00:00
|
|
|
(new MyFlexSizerFrame(this))->Show();
|
2003-02-27 12:02:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MyFrame::TestNotebookSizers(wxCommandEvent& WXUNUSED(event) )
|
|
|
|
{
|
2009-07-23 20:30:22 +00:00
|
|
|
MySizerDialog dialog( this, wxT("Notebook Sizer Test Dialog") );
|
2003-02-27 12:02:22 +00:00
|
|
|
|
|
|
|
dialog.ShowModal();
|
|
|
|
}
|
|
|
|
|
2006-10-10 08:57:46 +00:00
|
|
|
void MyFrame::TestSetMinimal(wxCommandEvent& WXUNUSED(event) )
|
|
|
|
{
|
2013-05-31 23:21:21 +00:00
|
|
|
(new MySimpleSizerFrame(this))->Show();
|
2006-10-10 08:57:46 +00:00
|
|
|
}
|
|
|
|
|
2006-10-29 18:10:32 +00:00
|
|
|
void MyFrame::TestNested(wxCommandEvent& WXUNUSED(event) )
|
|
|
|
{
|
2013-05-31 23:21:21 +00:00
|
|
|
(new MyNestedSizerFrame(this))->Show();
|
2006-10-29 18:10:32 +00:00
|
|
|
}
|
|
|
|
|
2007-12-08 11:37:17 +00:00
|
|
|
void MyFrame::TestWrap(wxCommandEvent& WXUNUSED(event) )
|
|
|
|
{
|
2013-05-31 23:21:21 +00:00
|
|
|
(new MyWrapSizerFrame(this))->Show();
|
2007-12-08 11:37:17 +00:00
|
|
|
}
|
|
|
|
|
1998-05-20 14:01:55 +00:00
|
|
|
|
2003-02-27 12:02:22 +00:00
|
|
|
void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event) )
|
|
|
|
{
|
2009-07-23 20:30:22 +00:00
|
|
|
(void)wxMessageBox(wxT("wxWidgets GUI library layout demo\n"),
|
|
|
|
wxT("About Layout Demo"), wxOK|wxICON_INFORMATION);
|
2003-02-27 12:02:22 +00:00
|
|
|
}
|
|
|
|
|
2003-11-06 01:31:44 +00:00
|
|
|
void MyFrame::TestGridBagSizer(wxCommandEvent& WXUNUSED(event) )
|
|
|
|
{
|
2013-05-31 23:21:21 +00:00
|
|
|
(new MyGridBagSizerFrame(this))->Show();
|
2003-11-06 01:31:44 +00:00
|
|
|
}
|
|
|
|
|
2005-07-13 10:08:52 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// MyProportionsFrame
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
MyProportionsFrame::MyProportionsFrame(wxFrame *parent)
|
2009-07-23 20:30:22 +00:00
|
|
|
: wxFrame(parent, wxID_ANY, wxT("Box Sizer Proportions Demo"))
|
2005-07-13 10:08:52 +00:00
|
|
|
{
|
|
|
|
size_t n;
|
|
|
|
|
|
|
|
// create the controls
|
|
|
|
wxPanel *panel = new wxPanel(this, wxID_ANY);
|
|
|
|
for ( n = 0; n < WXSIZEOF(m_spins); n++ )
|
|
|
|
{
|
|
|
|
m_spins[n] = new wxSpinCtrl(panel);
|
|
|
|
m_spins[n]->SetValue(n);
|
|
|
|
}
|
|
|
|
|
|
|
|
// lay them out
|
|
|
|
m_sizer = new wxStaticBoxSizer(wxHORIZONTAL, panel,
|
2009-07-23 20:30:22 +00:00
|
|
|
wxT("Try changing elements proportions and resizing the window"));
|
2005-07-13 10:08:52 +00:00
|
|
|
for ( n = 0; n < WXSIZEOF(m_spins); n++ )
|
|
|
|
m_sizer->Add(m_spins[n], wxSizerFlags().Border());
|
|
|
|
|
|
|
|
// put everything together
|
|
|
|
panel->SetSizer(m_sizer);
|
|
|
|
wxSizer *sizerTop = new wxBoxSizer(wxVERTICAL);
|
|
|
|
sizerTop->Add(panel, wxSizerFlags(1).Expand().Border());
|
|
|
|
UpdateProportions();
|
|
|
|
SetSizerAndFit(sizerTop);
|
|
|
|
|
|
|
|
// and connect the events
|
2013-04-25 10:11:03 +00:00
|
|
|
Connect(wxEVT_TEXT,
|
2005-07-13 10:08:52 +00:00
|
|
|
wxCommandEventHandler(MyProportionsFrame::OnProportionUpdated));
|
2013-04-25 10:11:03 +00:00
|
|
|
Connect(wxEVT_SPINCTRL,
|
2005-07-13 10:08:52 +00:00
|
|
|
wxSpinEventHandler(MyProportionsFrame::OnProportionChanged));
|
|
|
|
}
|
|
|
|
|
|
|
|
void MyProportionsFrame::UpdateProportions()
|
|
|
|
{
|
|
|
|
for ( size_t n = 0; n < WXSIZEOF(m_spins); n++ )
|
|
|
|
{
|
|
|
|
m_sizer->GetItem(n)->SetProportion(m_spins[n]->GetValue());
|
|
|
|
}
|
|
|
|
|
|
|
|
m_sizer->Layout();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MyProportionsFrame::OnProportionUpdated(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
|
|
|
UpdateProportions();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MyProportionsFrame::OnProportionChanged(wxSpinEvent& WXUNUSED(event))
|
|
|
|
{
|
|
|
|
UpdateProportions();
|
|
|
|
}
|
2003-11-06 01:31:44 +00:00
|
|
|
|
2003-02-27 12:02:22 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// MyFlexSizerFrame
|
|
|
|
// ----------------------------------------------------------------------------
|
1999-08-08 16:45:57 +00:00
|
|
|
|
2005-01-18 21:21:57 +00:00
|
|
|
void MyFlexSizerFrame::InitFlexSizer(wxFlexGridSizer *sizer, wxWindow* parent)
|
1998-05-20 14:01:55 +00:00
|
|
|
{
|
2003-02-27 12:02:22 +00:00
|
|
|
for ( int i = 0; i < 3; i++ )
|
|
|
|
{
|
|
|
|
for ( int j = 0; j < 3; j++ )
|
|
|
|
{
|
2009-12-08 15:56:26 +00:00
|
|
|
wxWindow * const cell = new wxGenericStaticText
|
|
|
|
(
|
|
|
|
parent,
|
|
|
|
wxID_ANY,
|
|
|
|
wxString::Format("(%d, %d)",
|
|
|
|
i + 1, j + 1)
|
|
|
|
);
|
|
|
|
if ( (i + j) % 2 )
|
|
|
|
cell->SetBackgroundColour( *wxLIGHT_GREY );
|
|
|
|
sizer->Add(cell, 0, wxEXPAND | wxALIGN_CENTER_VERTICAL | wxALL, 3);
|
2003-02-27 12:02:22 +00:00
|
|
|
}
|
|
|
|
}
|
1998-05-20 14:01:55 +00:00
|
|
|
}
|
|
|
|
|
2013-05-31 23:21:21 +00:00
|
|
|
MyFlexSizerFrame::MyFlexSizerFrame(wxFrame* parent)
|
|
|
|
: wxFrame(parent, wxID_ANY, "Flex Sizer Test Frame")
|
1998-05-20 14:01:55 +00:00
|
|
|
{
|
2003-02-27 12:02:22 +00:00
|
|
|
wxFlexGridSizer *sizerFlex;
|
2006-10-10 12:08:52 +00:00
|
|
|
wxPanel* p = new wxPanel(this, wxID_ANY);
|
2003-02-27 12:02:22 +00:00
|
|
|
|
|
|
|
// consttuct the first column
|
|
|
|
wxSizer *sizerCol1 = new wxBoxSizer(wxVERTICAL);
|
2009-07-23 20:30:22 +00:00
|
|
|
sizerCol1->Add(new wxStaticText(p, wxID_ANY, wxT("Ungrowable:")), 0, wxCENTER | wxTOP, 20);
|
2009-08-11 10:54:40 +00:00
|
|
|
sizerFlex = new wxFlexGridSizer(3, 3, wxSize(5, 5));
|
2005-01-18 21:21:57 +00:00
|
|
|
InitFlexSizer(sizerFlex, p);
|
2003-02-27 12:02:22 +00:00
|
|
|
sizerCol1->Add(sizerFlex, 1, wxALL | wxEXPAND, 10);
|
|
|
|
|
2009-07-23 20:30:22 +00:00
|
|
|
sizerCol1->Add(new wxStaticText(p, wxID_ANY, wxT("Growable middle column:")), 0, wxCENTER | wxTOP, 20);
|
2009-08-11 10:54:40 +00:00
|
|
|
sizerFlex = new wxFlexGridSizer(3, 3, wxSize(5, 5));
|
2005-01-18 21:21:57 +00:00
|
|
|
InitFlexSizer(sizerFlex, p);
|
2003-02-27 12:02:22 +00:00
|
|
|
sizerFlex->AddGrowableCol(1);
|
|
|
|
sizerCol1->Add(sizerFlex, 1, wxALL | wxEXPAND, 10);
|
|
|
|
|
2009-07-23 20:30:22 +00:00
|
|
|
sizerCol1->Add(new wxStaticText(p, wxID_ANY, wxT("Growable middle row:")), 0, wxCENTER | wxTOP, 20);
|
2009-08-11 10:54:40 +00:00
|
|
|
sizerFlex = new wxFlexGridSizer(3, 3, wxSize(5, 5));
|
2005-01-18 21:21:57 +00:00
|
|
|
InitFlexSizer(sizerFlex, p);
|
2003-02-27 12:02:22 +00:00
|
|
|
sizerFlex->AddGrowableRow(1);
|
|
|
|
sizerCol1->Add(sizerFlex, 1, wxALL | wxEXPAND, 10);
|
|
|
|
|
2009-07-23 20:30:22 +00:00
|
|
|
sizerCol1->Add(new wxStaticText(p, wxID_ANY, wxT("All growable columns:")), 0, wxCENTER | wxTOP, 20);
|
2009-08-11 10:54:40 +00:00
|
|
|
sizerFlex = new wxFlexGridSizer(3, 3, wxSize(5, 5));
|
2005-01-18 21:21:57 +00:00
|
|
|
InitFlexSizer(sizerFlex, p);
|
2003-02-27 12:02:22 +00:00
|
|
|
sizerFlex->AddGrowableCol(0, 1);
|
|
|
|
sizerFlex->AddGrowableCol(1, 2);
|
|
|
|
sizerFlex->AddGrowableCol(2, 3);
|
|
|
|
sizerCol1->Add(sizerFlex, 1, wxALL | wxEXPAND, 10);
|
|
|
|
|
|
|
|
// the second one
|
|
|
|
wxSizer *sizerCol2 = new wxBoxSizer(wxVERTICAL);
|
2009-07-23 20:30:22 +00:00
|
|
|
sizerCol2->Add(new wxStaticText(p, wxID_ANY, wxT("Growable middle row and column:")), 0, wxCENTER | wxTOP, 20);
|
2009-08-11 10:54:40 +00:00
|
|
|
sizerFlex = new wxFlexGridSizer(3, 3, wxSize(5, 5));
|
2005-01-18 21:21:57 +00:00
|
|
|
InitFlexSizer(sizerFlex, p);
|
2003-02-27 12:02:22 +00:00
|
|
|
sizerFlex->AddGrowableCol(1);
|
|
|
|
sizerFlex->AddGrowableRow(1);
|
|
|
|
sizerCol2->Add(sizerFlex, 1, wxALL | wxEXPAND, 10);
|
|
|
|
|
2009-07-23 20:30:22 +00:00
|
|
|
sizerCol2->Add(new wxStaticText(p, wxID_ANY, wxT("Same with horz flex direction")), 0, wxCENTER | wxTOP, 20);
|
2009-08-11 10:54:40 +00:00
|
|
|
sizerFlex = new wxFlexGridSizer(3, 3, wxSize(5, 5));
|
2005-01-18 21:21:57 +00:00
|
|
|
InitFlexSizer(sizerFlex, p);
|
2003-02-27 12:02:22 +00:00
|
|
|
sizerFlex->AddGrowableCol(1);
|
|
|
|
sizerFlex->AddGrowableRow(1);
|
|
|
|
sizerFlex->SetFlexibleDirection(wxHORIZONTAL);
|
|
|
|
sizerCol2->Add(sizerFlex, 1, wxALL | wxEXPAND, 10);
|
|
|
|
|
2009-07-23 20:30:22 +00:00
|
|
|
sizerCol2->Add(new wxStaticText(p, wxID_ANY, wxT("Same with grow mode == \"none\"")), 0, wxCENTER | wxTOP, 20);
|
2009-08-11 10:54:40 +00:00
|
|
|
sizerFlex = new wxFlexGridSizer(3, 3, wxSize(5, 5));
|
2005-01-18 21:21:57 +00:00
|
|
|
InitFlexSizer(sizerFlex, p);
|
2003-02-27 12:02:22 +00:00
|
|
|
sizerFlex->AddGrowableCol(1);
|
|
|
|
sizerFlex->AddGrowableRow(1);
|
|
|
|
sizerFlex->SetFlexibleDirection(wxHORIZONTAL);
|
|
|
|
sizerFlex->SetNonFlexibleGrowMode(wxFLEX_GROWMODE_NONE);
|
|
|
|
sizerCol2->Add(sizerFlex, 1, wxALL | wxEXPAND, 10);
|
|
|
|
|
2009-07-23 20:30:22 +00:00
|
|
|
sizerCol2->Add(new wxStaticText(p, wxID_ANY, wxT("Same with grow mode == \"all\"")), 0, wxCENTER | wxTOP, 20);
|
2009-08-11 10:54:40 +00:00
|
|
|
sizerFlex = new wxFlexGridSizer(3, 3, wxSize(5, 5));
|
2005-01-18 21:21:57 +00:00
|
|
|
InitFlexSizer(sizerFlex, p);
|
2003-02-27 12:02:22 +00:00
|
|
|
sizerFlex->AddGrowableCol(1);
|
|
|
|
sizerFlex->AddGrowableRow(1);
|
|
|
|
sizerFlex->SetFlexibleDirection(wxHORIZONTAL);
|
|
|
|
sizerFlex->SetNonFlexibleGrowMode(wxFLEX_GROWMODE_ALL);
|
|
|
|
sizerCol2->Add(sizerFlex, 1, wxALL | wxEXPAND, 10);
|
|
|
|
|
|
|
|
// add both columns to grid sizer
|
|
|
|
wxGridSizer *sizerTop = new wxGridSizer(2, 0, 20);
|
|
|
|
sizerTop->Add(sizerCol1, 1, wxEXPAND);
|
|
|
|
sizerTop->Add(sizerCol2, 1, wxEXPAND);
|
|
|
|
|
2005-01-18 21:21:57 +00:00
|
|
|
p->SetSizer(sizerTop);
|
2003-02-27 12:02:22 +00:00
|
|
|
sizerTop->SetSizeHints(this);
|
1998-05-20 14:01:55 +00:00
|
|
|
}
|
|
|
|
|
2003-02-27 12:02:22 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// MySizerDialog
|
|
|
|
// ----------------------------------------------------------------------------
|
1998-05-20 14:01:55 +00:00
|
|
|
|
2007-12-08 11:37:17 +00:00
|
|
|
MySizerDialog::MySizerDialog(wxWindow *parent, const wxString &title)
|
2004-02-28 10:46:36 +00:00
|
|
|
: wxDialog(parent, wxID_ANY, wxString(title))
|
1999-12-11 15:07:14 +00:00
|
|
|
{
|
|
|
|
// Begin with first hierarchy: a notebook at the top and
|
|
|
|
// and OK button at the bottom.
|
|
|
|
|
|
|
|
wxBoxSizer *topsizer = new wxBoxSizer( wxVERTICAL );
|
1999-12-11 19:38:07 +00:00
|
|
|
|
2004-02-28 10:46:36 +00:00
|
|
|
wxNotebook *notebook = new wxNotebook( this, wxID_ANY );
|
2004-06-24 11:58:06 +00:00
|
|
|
topsizer->Add( notebook, 1, wxGROW );
|
1999-12-11 19:38:07 +00:00
|
|
|
|
2009-07-23 20:30:22 +00:00
|
|
|
wxButton *button = new wxButton( this, wxID_OK, wxT("OK") );
|
1999-12-11 15:07:14 +00:00
|
|
|
topsizer->Add( button, 0, wxALIGN_RIGHT | wxALL, 10 );
|
|
|
|
|
|
|
|
// First page: one big text ctrl
|
2009-07-23 20:30:22 +00:00
|
|
|
wxTextCtrl *multi = new wxTextCtrl( notebook, wxID_ANY, wxT("TextCtrl."), wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE );
|
|
|
|
notebook->AddPage( multi, wxT("Page One") );
|
1999-12-11 19:38:07 +00:00
|
|
|
|
1999-12-11 15:07:14 +00:00
|
|
|
// Second page: a text ctrl and a button
|
2004-02-28 10:46:36 +00:00
|
|
|
wxPanel *panel = new wxPanel( notebook, wxID_ANY );
|
2009-07-23 20:30:22 +00:00
|
|
|
notebook->AddPage( panel, wxT("Page Two") );
|
1999-12-11 19:38:07 +00:00
|
|
|
|
2000-07-15 19:51:35 +00:00
|
|
|
wxSizer *panelsizer = new wxBoxSizer( wxVERTICAL );
|
1999-12-11 19:38:07 +00:00
|
|
|
|
2009-07-23 20:30:22 +00:00
|
|
|
wxTextCtrl *text = new wxTextCtrl( panel, wxID_ANY, wxT("TextLine 1."), wxDefaultPosition, wxSize(250,wxDefaultCoord) );
|
1999-12-11 15:07:14 +00:00
|
|
|
panelsizer->Add( text, 0, wxGROW|wxALL, 30 );
|
2009-07-23 20:30:22 +00:00
|
|
|
text = new wxTextCtrl( panel, wxID_ANY, wxT("TextLine 2."), wxDefaultPosition, wxSize(250,wxDefaultCoord) );
|
1999-12-11 15:07:14 +00:00
|
|
|
panelsizer->Add( text, 0, wxGROW|wxALL, 30 );
|
2009-07-23 20:30:22 +00:00
|
|
|
wxButton *button2 = new wxButton( panel, wxID_ANY, wxT("Hallo") );
|
1999-12-11 15:07:14 +00:00
|
|
|
panelsizer->Add( button2, 0, wxALIGN_RIGHT | wxLEFT|wxRIGHT|wxBOTTOM, 30 );
|
1999-12-11 19:38:07 +00:00
|
|
|
|
1999-12-11 15:07:14 +00:00
|
|
|
panel->SetSizer( panelsizer );
|
1999-12-11 19:38:07 +00:00
|
|
|
|
1999-12-11 15:07:14 +00:00
|
|
|
// Tell dialog to use sizer
|
2008-03-15 02:08:02 +00:00
|
|
|
SetSizerAndFit( topsizer );
|
1999-08-08 16:45:57 +00:00
|
|
|
}
|
|
|
|
|
2003-11-06 01:31:44 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// MyGridBagSizerFrame
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// some simple macros to help make the sample code below more clear
|
2009-07-23 20:30:22 +00:00
|
|
|
#define TEXTCTRL(text) new wxTextCtrl(p, wxID_ANY, wxT(text))
|
|
|
|
#define MLTEXTCTRL(text) new wxTextCtrl(p, wxID_ANY, wxT(text), wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE)
|
2003-11-06 01:31:44 +00:00
|
|
|
#define POS(r, c) wxGBPosition(r,c)
|
|
|
|
#define SPAN(r, c) wxGBSpan(r,c)
|
|
|
|
|
2009-07-23 20:30:22 +00:00
|
|
|
const wxChar gbsDescription[] =wxT("\
|
2003-11-06 18:53:45 +00:00
|
|
|
The wxGridBagSizer is similar to the wxFlexGridSizer except the items are explicitly positioned\n\
|
|
|
|
in a virtual cell of the layout grid, and column or row spanning is allowed. For example, this\n\
|
|
|
|
static text is positioned at (0,0) and it spans 7 columns.");
|
2003-11-06 01:31:44 +00:00
|
|
|
|
|
|
|
|
|
|
|
// Some IDs
|
|
|
|
enum {
|
|
|
|
GBS_HIDE_BTN = 1212,
|
|
|
|
GBS_SHOW_BTN,
|
|
|
|
GBS_MOVE_BTN1,
|
|
|
|
GBS_MOVE_BTN2,
|
2004-10-06 20:54:57 +00:00
|
|
|
|
2006-08-13 01:17:53 +00:00
|
|
|
GBS_MAX
|
2003-11-06 01:31:44 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-03-30 07:07:55 +00:00
|
|
|
wxBEGIN_EVENT_TABLE(MyGridBagSizerFrame, wxFrame)
|
2003-11-06 01:31:44 +00:00
|
|
|
EVT_BUTTON( GBS_HIDE_BTN, MyGridBagSizerFrame::OnHideBtn)
|
|
|
|
EVT_BUTTON( GBS_SHOW_BTN, MyGridBagSizerFrame::OnShowBtn)
|
|
|
|
EVT_BUTTON( GBS_MOVE_BTN1, MyGridBagSizerFrame::OnMoveBtn)
|
|
|
|
EVT_BUTTON( GBS_MOVE_BTN2, MyGridBagSizerFrame::OnMoveBtn)
|
2014-03-30 07:07:55 +00:00
|
|
|
wxEND_EVENT_TABLE()
|
2003-11-06 01:31:44 +00:00
|
|
|
|
|
|
|
|
2013-05-31 23:21:21 +00:00
|
|
|
MyGridBagSizerFrame::MyGridBagSizerFrame(wxFrame* parent)
|
|
|
|
: wxFrame(parent, wxID_ANY, "wxGridBagSizer Test Frame")
|
2003-11-06 01:31:44 +00:00
|
|
|
{
|
2004-02-28 10:46:36 +00:00
|
|
|
wxPanel* p = new wxPanel(this, wxID_ANY);
|
2003-11-06 01:31:44 +00:00
|
|
|
m_panel = p;
|
|
|
|
m_gbs = new wxGridBagSizer();
|
|
|
|
|
2004-10-06 20:54:57 +00:00
|
|
|
|
2004-02-28 10:46:36 +00:00
|
|
|
m_gbs->Add( new wxStaticText(p, wxID_ANY, gbsDescription),
|
2003-11-06 18:53:45 +00:00
|
|
|
POS(0,0), SPAN(1, 7),
|
|
|
|
wxALIGN_CENTER | wxALL, 5);
|
2004-10-06 20:54:57 +00:00
|
|
|
|
2003-11-06 01:31:44 +00:00
|
|
|
m_gbs->Add( TEXTCTRL("pos(1,0)"), POS(1,0) );
|
|
|
|
m_gbs->Add( TEXTCTRL("pos(1,1)"), POS(1,1) );
|
|
|
|
m_gbs->Add( TEXTCTRL("pos(2,0)"), POS(2,0) );
|
|
|
|
m_gbs->Add( TEXTCTRL("pos(2,1)"), POS(2,1) );
|
|
|
|
m_gbs->Add( MLTEXTCTRL("pos(3,2), span(1,2)\nthis row and col are growable"),
|
|
|
|
POS(3,2), SPAN(1,2), wxEXPAND );
|
|
|
|
m_gbs->Add( MLTEXTCTRL("pos(4,3)\nspan(3,1)"),
|
|
|
|
POS(4,3), SPAN(3,1), wxEXPAND );
|
|
|
|
m_gbs->Add( TEXTCTRL("pos(5,4)"), POS(5,4), wxDefaultSpan, wxEXPAND );
|
|
|
|
m_gbs->Add( TEXTCTRL("pos(6,5)"), POS(6,5), wxDefaultSpan, wxEXPAND );
|
|
|
|
m_gbs->Add( TEXTCTRL("pos(7,6)"), POS(7,6) );
|
2004-10-06 20:54:57 +00:00
|
|
|
|
2003-11-06 01:31:44 +00:00
|
|
|
//m_gbs->Add( TEXTCTRL("bad position"), POS(4,3) ); // Test for assert
|
|
|
|
//m_gbs->Add( TEXTCTRL("bad position"), POS(5,3) ); // Test for assert
|
|
|
|
|
|
|
|
|
2009-07-23 20:30:22 +00:00
|
|
|
m_moveBtn1 = new wxButton(p, GBS_MOVE_BTN1, wxT("Move this to (3,6)"));
|
|
|
|
m_moveBtn2 = new wxButton(p, GBS_MOVE_BTN2, wxT("Move this to (3,6)"));
|
2003-11-06 01:31:44 +00:00
|
|
|
m_gbs->Add( m_moveBtn1, POS(10,2) );
|
|
|
|
m_gbs->Add( m_moveBtn2, POS(10,3) );
|
2004-10-06 20:54:57 +00:00
|
|
|
|
2009-07-23 20:30:22 +00:00
|
|
|
m_hideBtn = new wxButton(p, GBS_HIDE_BTN, wxT("Hide this item -->"));
|
2003-11-06 01:31:44 +00:00
|
|
|
m_gbs->Add(m_hideBtn, POS(12, 3));
|
|
|
|
|
2009-07-23 20:30:22 +00:00
|
|
|
m_hideTxt = new wxTextCtrl(p, wxID_ANY, wxT("pos(12,4), size(150, wxDefaultCoord)"),
|
2006-10-10 12:08:52 +00:00
|
|
|
wxDefaultPosition, wxSize(150,wxDefaultCoord));
|
2003-11-06 01:31:44 +00:00
|
|
|
m_gbs->Add( m_hideTxt, POS(12,4) );
|
2004-10-06 20:54:57 +00:00
|
|
|
|
2009-07-23 20:30:22 +00:00
|
|
|
m_showBtn = new wxButton(p, GBS_SHOW_BTN, wxT("<-- Show it again"));
|
2003-11-06 01:31:44 +00:00
|
|
|
m_gbs->Add(m_showBtn, POS(12, 5));
|
|
|
|
m_showBtn->Disable();
|
|
|
|
|
|
|
|
m_gbs->Add(10,10, POS(14,0));
|
2004-10-06 20:54:57 +00:00
|
|
|
|
2003-11-06 01:31:44 +00:00
|
|
|
m_gbs->AddGrowableRow(3);
|
|
|
|
m_gbs->AddGrowableCol(2);
|
2004-10-06 20:54:57 +00:00
|
|
|
|
2003-11-06 01:31:44 +00:00
|
|
|
p->SetSizerAndFit(m_gbs);
|
|
|
|
SetClientSize(p->GetSize());
|
|
|
|
}
|
|
|
|
|
2004-10-06 20:54:57 +00:00
|
|
|
|
2003-11-06 01:31:44 +00:00
|
|
|
void MyGridBagSizerFrame::OnHideBtn(wxCommandEvent&)
|
|
|
|
{
|
|
|
|
m_gbs->Hide(m_hideTxt);
|
|
|
|
m_hideBtn->Disable();
|
|
|
|
m_showBtn->Enable();
|
|
|
|
m_gbs->Layout();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MyGridBagSizerFrame::OnShowBtn(wxCommandEvent&)
|
|
|
|
{
|
|
|
|
m_gbs->Show(m_hideTxt);
|
|
|
|
m_hideBtn->Enable();
|
|
|
|
m_showBtn->Disable();
|
|
|
|
m_gbs->Layout();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MyGridBagSizerFrame::OnMoveBtn(wxCommandEvent& event)
|
|
|
|
{
|
|
|
|
wxButton* btn = (wxButton*)event.GetEventObject();
|
|
|
|
wxGBPosition curPos = m_gbs->GetItemPosition(btn);
|
|
|
|
|
|
|
|
// if it's already at the "other" spot then move it back
|
|
|
|
if (curPos == wxGBPosition(3,6))
|
|
|
|
{
|
|
|
|
m_gbs->SetItemPosition(btn, m_lastPos);
|
2009-07-23 20:30:22 +00:00
|
|
|
btn->SetLabel(wxT("Move this to (3,6)"));
|
2003-11-06 01:31:44 +00:00
|
|
|
}
|
2004-10-06 20:54:57 +00:00
|
|
|
else
|
2003-11-06 01:31:44 +00:00
|
|
|
{
|
2003-11-06 18:53:45 +00:00
|
|
|
if ( m_gbs->CheckForIntersection(wxGBPosition(3,6), wxGBSpan(1,1)) )
|
|
|
|
wxMessageBox(
|
2009-07-23 20:30:22 +00:00
|
|
|
wxT("wxGridBagSizer will not allow items to be in the same cell as\n\
|
2003-11-06 18:53:45 +00:00
|
|
|
another item, so this operation will fail. You will also get an assert\n\
|
2009-07-23 20:30:22 +00:00
|
|
|
when compiled in debug mode."), wxT("Warning"), wxOK | wxICON_INFORMATION);
|
2004-10-06 20:54:57 +00:00
|
|
|
|
2003-11-06 18:53:45 +00:00
|
|
|
if ( m_gbs->SetItemPosition(btn, wxGBPosition(3,6)) )
|
|
|
|
{
|
|
|
|
m_lastPos = curPos;
|
2009-07-23 20:30:22 +00:00
|
|
|
btn->SetLabel(wxT("Move it back"));
|
2003-11-06 18:53:45 +00:00
|
|
|
}
|
2003-11-06 01:31:44 +00:00
|
|
|
}
|
|
|
|
m_gbs->Layout();
|
|
|
|
}
|
2006-10-10 08:57:46 +00:00
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// MySimpleSizerFrame
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// Some IDs
|
|
|
|
enum {
|
|
|
|
ID_SET_SMALL = 1300,
|
|
|
|
ID_SET_BIG
|
|
|
|
};
|
|
|
|
|
2014-03-30 07:07:55 +00:00
|
|
|
wxBEGIN_EVENT_TABLE(MySimpleSizerFrame, wxFrame)
|
2006-10-10 08:57:46 +00:00
|
|
|
EVT_MENU( ID_SET_SMALL, MySimpleSizerFrame::OnSetSmallSize)
|
|
|
|
EVT_MENU( ID_SET_BIG, MySimpleSizerFrame::OnSetBigSize)
|
2014-03-30 07:07:55 +00:00
|
|
|
wxEND_EVENT_TABLE()
|
2006-10-10 08:57:46 +00:00
|
|
|
|
2013-05-31 23:21:21 +00:00
|
|
|
MySimpleSizerFrame::MySimpleSizerFrame(wxFrame* parent)
|
|
|
|
: wxFrame(parent, wxID_ANY, "Simple Sizer Test Frame")
|
2006-10-10 08:57:46 +00:00
|
|
|
{
|
|
|
|
wxMenu *menu = new wxMenu;
|
2006-10-10 12:08:52 +00:00
|
|
|
|
2009-07-23 20:30:22 +00:00
|
|
|
menu->Append(ID_SET_SMALL, wxT("Make text control small\tF4"));
|
|
|
|
menu->Append(ID_SET_BIG, wxT("Make text control big\tF5"));
|
2006-10-10 12:08:52 +00:00
|
|
|
|
2006-10-10 08:57:46 +00:00
|
|
|
wxMenuBar *menu_bar = new wxMenuBar;
|
2009-07-23 20:30:22 +00:00
|
|
|
menu_bar->Append(menu, wxT("&File"));
|
2006-10-10 08:57:46 +00:00
|
|
|
|
|
|
|
SetMenuBar( menu_bar );
|
|
|
|
|
|
|
|
wxBoxSizer *main_sizer = new wxBoxSizer( wxHORIZONTAL );
|
|
|
|
|
2006-10-10 12:08:52 +00:00
|
|
|
m_target = new wxTextCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize( 80, wxDefaultCoord ) );
|
2006-10-10 08:57:46 +00:00
|
|
|
main_sizer->Add( m_target, 1, wxALL, 5 );
|
2006-10-10 12:08:52 +00:00
|
|
|
|
|
|
|
main_sizer->Add( new wxStaticText( this, wxID_ANY, wxT("Set alternating sizes using F4 and F5") ), 0, wxALL, 5 );
|
|
|
|
|
2006-10-10 08:57:46 +00:00
|
|
|
SetSizer( main_sizer);
|
2006-10-10 12:08:52 +00:00
|
|
|
|
2006-10-10 08:57:46 +00:00
|
|
|
Layout();
|
|
|
|
GetSizer()->Fit( this );
|
|
|
|
}
|
|
|
|
|
2006-10-10 12:08:52 +00:00
|
|
|
void MySimpleSizerFrame::OnSetSmallSize( wxCommandEvent& WXUNUSED(event))
|
2006-10-10 08:57:46 +00:00
|
|
|
{
|
|
|
|
GetSizer()->SetItemMinSize( m_target, 40, -1 );
|
|
|
|
Layout();
|
|
|
|
GetSizer()->Fit( this );
|
|
|
|
}
|
|
|
|
|
2006-10-10 12:08:52 +00:00
|
|
|
void MySimpleSizerFrame::OnSetBigSize( wxCommandEvent& WXUNUSED(event))
|
2006-10-10 08:57:46 +00:00
|
|
|
{
|
|
|
|
GetSizer()->SetItemMinSize( m_target, 140, -1 );
|
|
|
|
Layout();
|
|
|
|
GetSizer()->Fit( this );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-10-29 18:10:32 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// MyNestedSizerFrame
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
2013-05-31 23:21:21 +00:00
|
|
|
MyNestedSizerFrame::MyNestedSizerFrame(wxFrame* parent)
|
|
|
|
: wxFrame(parent, wxID_ANY, "Nested Sizer Test Frame")
|
2006-10-29 18:10:32 +00:00
|
|
|
{
|
|
|
|
wxMenu *menu = new wxMenu;
|
|
|
|
|
2009-07-23 20:30:22 +00:00
|
|
|
menu->Append(wxID_ABOUT, wxT("Do nothing"));
|
2006-10-29 18:10:32 +00:00
|
|
|
|
|
|
|
wxMenuBar *menu_bar = new wxMenuBar;
|
2009-07-23 20:30:22 +00:00
|
|
|
menu_bar->Append(menu, wxT("&File"));
|
2006-10-29 18:10:32 +00:00
|
|
|
|
|
|
|
SetMenuBar( menu_bar );
|
|
|
|
|
|
|
|
wxBoxSizer *main_sizer = new wxBoxSizer( wxVERTICAL );
|
|
|
|
|
|
|
|
main_sizer->Add( new wxStaticText( this, -1, wxT("Hello outside") ), 0, wxALIGN_CENTER );
|
|
|
|
main_sizer->Add( new wxStaticText( this, -1, wxT("Hello outside") ), 0, wxALIGN_CENTER );
|
|
|
|
main_sizer->Add( new wxStaticText( this, -1, wxT("Hello outside") ), 0, wxALIGN_CENTER );
|
|
|
|
main_sizer->Add( new wxStaticText( this, -1, wxT("Hello outside") ), 0, wxALIGN_CENTER );
|
|
|
|
|
2009-02-08 01:01:00 +00:00
|
|
|
wxPanel *panel = new wxPanel( this, -1, wxDefaultPosition, wxDefaultSize,
|
2006-10-29 18:10:32 +00:00
|
|
|
wxTAB_TRAVERSAL | wxSUNKEN_BORDER );
|
|
|
|
main_sizer->Add( panel, 0, wxALIGN_CENTER );
|
|
|
|
wxBoxSizer *panel_sizer = new wxBoxSizer( wxVERTICAL );
|
|
|
|
panel->SetSizer( panel_sizer );
|
|
|
|
panel_sizer->Add( new wxStaticText( panel, -1, wxT("Hello inside") ) );
|
|
|
|
panel_sizer->Add( new wxStaticText( panel, -1, wxT("Hello inside") ) );
|
|
|
|
panel_sizer->Add( new wxStaticText( panel, -1, wxT("Hello inside") ) );
|
2009-02-08 01:01:00 +00:00
|
|
|
|
2006-10-29 18:10:32 +00:00
|
|
|
main_sizer->Add( new wxStaticText( this, -1, wxT("Hello outside") ), 0, wxALIGN_CENTER );
|
|
|
|
|
|
|
|
m_target = new wxTextCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize( 80, wxDefaultCoord ) );
|
|
|
|
main_sizer->Add( m_target, 1, wxALL|wxGROW, 5 );
|
|
|
|
|
2008-03-15 02:08:02 +00:00
|
|
|
SetSizerAndFit( main_sizer);
|
2006-10-29 18:10:32 +00:00
|
|
|
}
|
|
|
|
|
2007-12-08 11:37:17 +00:00
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// MyWrapSizerFrame
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2014-03-30 07:07:55 +00:00
|
|
|
wxBEGIN_EVENT_TABLE(MyWrapSizerFrame, wxFrame)
|
2012-09-22 16:16:30 +00:00
|
|
|
EVT_MENU(wxID_ADD, MyWrapSizerFrame::OnAddCheckbox)
|
|
|
|
EVT_MENU(wxID_REMOVE, MyWrapSizerFrame::OnRemoveCheckbox)
|
2014-03-30 07:07:55 +00:00
|
|
|
wxEND_EVENT_TABLE()
|
2007-12-08 11:37:17 +00:00
|
|
|
|
2013-05-31 23:21:21 +00:00
|
|
|
MyWrapSizerFrame::MyWrapSizerFrame(wxFrame* parent)
|
|
|
|
: wxFrame(parent, wxID_ANY, "Wrap Sizer Test Frame",
|
|
|
|
wxDefaultPosition, wxSize(200,-1))
|
2007-12-08 11:37:17 +00:00
|
|
|
{
|
|
|
|
wxMenu *menu = new wxMenu;
|
|
|
|
|
2012-09-22 16:16:30 +00:00
|
|
|
menu->Append(wxID_ADD, "&Add a checkbox\tCtrl-+");
|
|
|
|
menu->Append(wxID_REMOVE, "&Remove a checkbox\tCtrl--");
|
2007-12-08 11:37:17 +00:00
|
|
|
|
|
|
|
wxMenuBar *menu_bar = new wxMenuBar;
|
2012-09-22 16:16:30 +00:00
|
|
|
menu_bar->Append(menu, "&Wrap sizer");
|
2007-12-08 11:37:17 +00:00
|
|
|
|
|
|
|
SetMenuBar( menu_bar );
|
|
|
|
|
|
|
|
wxBoxSizer *root = new wxBoxSizer( wxVERTICAL );
|
|
|
|
|
2012-09-22 16:16:30 +00:00
|
|
|
wxStaticBoxSizer *topSizer = new wxStaticBoxSizer( wxVERTICAL, this, "Wrapping check-boxes" );
|
|
|
|
m_checkboxParent = topSizer->GetStaticBox();
|
|
|
|
m_wrapSizer = new wxWrapSizer(wxHORIZONTAL);
|
2009-02-08 01:01:00 +00:00
|
|
|
|
|
|
|
// A number of checkboxes inside a wrap sizer
|
2012-09-22 16:16:30 +00:00
|
|
|
for( int i = 0; i < 6; i++ )
|
|
|
|
DoAddCheckbox();
|
|
|
|
|
|
|
|
topSizer->Add( m_wrapSizer, wxSizerFlags(1).Expand());
|
|
|
|
root->Add( topSizer, wxSizerFlags().Expand().Border());
|
2007-12-08 11:37:17 +00:00
|
|
|
|
|
|
|
// A shaped item inside a box sizer
|
2012-09-22 16:16:30 +00:00
|
|
|
wxSizer *bottomSizer = new wxStaticBoxSizer( wxVERTICAL, this, "With wxSHAPED item" );
|
|
|
|
wxSizer *horzBoxSizer = new wxBoxSizer(wxHORIZONTAL);
|
|
|
|
bottomSizer->Add( horzBoxSizer, 100, wxEXPAND );
|
|
|
|
horzBoxSizer->Add( new wxListBox(this,wxID_ANY,wxPoint(0,0),wxSize(70,70)), 0, wxEXPAND|wxSHAPED );
|
|
|
|
horzBoxSizer->Add( 10,10 );
|
|
|
|
horzBoxSizer->Add( new wxCheckBox(this,wxID_ANY,"A much longer option..."), 100, 0, 5 );
|
|
|
|
|
|
|
|
root->Add( bottomSizer, 1, wxEXPAND | wxALL, 5 );
|
2009-02-08 01:01:00 +00:00
|
|
|
|
2007-12-08 11:37:17 +00:00
|
|
|
// Set sizer for window
|
2008-03-15 02:08:02 +00:00
|
|
|
SetSizerAndFit( root );
|
2007-12-08 11:37:17 +00:00
|
|
|
}
|
|
|
|
|
2012-09-22 16:16:30 +00:00
|
|
|
void MyWrapSizerFrame::DoAddCheckbox()
|
|
|
|
{
|
|
|
|
m_wrapSizer->Add(new wxCheckBox
|
|
|
|
(
|
|
|
|
m_checkboxParent,
|
|
|
|
wxID_ANY,
|
|
|
|
wxString::Format
|
|
|
|
(
|
|
|
|
"Option %d",
|
|
|
|
(int)m_wrapSizer->GetItemCount() + 1
|
|
|
|
)
|
|
|
|
),
|
|
|
|
wxSizerFlags().Centre().Border());
|
|
|
|
}
|
|
|
|
|
|
|
|
void MyWrapSizerFrame::OnAddCheckbox(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
|
|
|
DoAddCheckbox();
|
|
|
|
Layout();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MyWrapSizerFrame::OnRemoveCheckbox(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
|
|
|
if ( m_wrapSizer->IsEmpty() )
|
|
|
|
{
|
|
|
|
wxLogStatus(this, "No more checkboxes to remove.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
delete m_wrapSizer->GetItem(m_wrapSizer->GetItemCount() - 1)->GetWindow();
|
|
|
|
Layout();
|
|
|
|
}
|