1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxWidgets sample demonstrating wxWrapSizer use
4 // Author: Arne Steinarson
7 // Copyright: (c) Arne Steinarson
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 #include "wx/wxprec.h"
21 #include "wx/wrapsizer.h"
22 #include "wx/artprov.h"
25 #include "../sample.xpm"
29 // ----------------------------------------------------------------------------
31 // ----------------------------------------------------------------------------
33 class WrapSizerFrame
: public wxFrame
39 void OnButton(wxCommandEvent
& WXUNUSED(event
))
44 void AddToolBarButton(wxToolBar
*tb
,
45 const wxString
& label
,
46 const wxString
& artid
)
49 bm
= wxArtProvider::GetBitmap(artid
, wxART_TOOLBAR
, wxSize(16, 16));
50 tb
->AddTool(wxID_ANY
, label
, bm
);
53 wxToolBar
*MakeToolBar()
55 wxToolBar
*tb
= new wxToolBar(m_panel
, wxID_ANY
,
56 wxDefaultPosition
, wxDefaultSize
,
58 AddToolBarButton(tb
, "Help", wxART_HELP_BOOK
);
60 AddToolBarButton(tb
, "Open", wxART_FILE_OPEN
);
62 AddToolBarButton(tb
, "Up", wxART_GO_DIR_UP
);
63 AddToolBarButton(tb
, "Execute", wxART_EXECUTABLE_FILE
);
72 class WrapSizerApp
: public wxApp
84 IMPLEMENT_APP(WrapSizerApp
);
87 // ----------------------------------------------------------------------------
89 // ----------------------------------------------------------------------------
91 WrapSizerFrame::WrapSizerFrame()
92 : wxFrame(NULL
, wxID_ANY
, "wxWrapSizer Sample")
94 SetIcon(wxICON(sample
));
96 m_panel
= new wxPanel(this);
98 // Root sizer, vertical
99 wxSizer
* const sizerRoot
= new wxBoxSizer(wxVERTICAL
);
101 // Some toolbars in a wrap sizer
102 wxSizer
* const sizerTop
= new wxWrapSizer( wxHORIZONTAL
);
103 sizerTop
->Add(MakeToolBar());
104 sizerTop
->Add(20, 1);
105 sizerTop
->Add(MakeToolBar());
106 sizerTop
->Add(20, 1);
107 sizerTop
->Add(MakeToolBar());
108 sizerRoot
->Add(sizerTop
, wxSizerFlags().Expand().Border());
110 // A number of checkboxes inside a wrap sizer
111 wxSizer
*sizerMid
= new wxStaticBoxSizer(wxVERTICAL
, m_panel
,
113 wxSizer
* const sizerMidWrap
= new wxWrapSizer(wxHORIZONTAL
);
114 for ( int nCheck
= 0; nCheck
< 6; nCheck
++ )
116 wxCheckBox
*chk
= new wxCheckBox
120 wxString::Format("Option %d", nCheck
)
123 sizerMidWrap
->Add(chk
, wxSizerFlags().Centre().Border());
126 sizerMid
->Add(sizerMidWrap
, wxSizerFlags(100).Expand());
127 sizerRoot
->Add(sizerMid
, wxSizerFlags(100).Expand().Border());
130 // A shaped item inside a box sizer
131 wxSizer
*sizerBottom
= new wxStaticBoxSizer(wxVERTICAL
, m_panel
,
132 "With wxSHAPED item");
133 wxSizer
*sizerBottomBox
= new wxBoxSizer(wxHORIZONTAL
);
134 sizerBottom
->Add(sizerBottomBox
, wxSizerFlags(100).Expand());
136 sizerBottomBox
->Add(new wxListBox(m_panel
, wxID_ANY
,
137 wxPoint(0, 0), wxSize(70, 70)),
138 wxSizerFlags().Expand().Shaped());
139 sizerBottomBox
->AddSpacer(10);
140 sizerBottomBox
->Add(new wxCheckBox(m_panel
, wxID_ANY
,
141 "A much longer option..."),
142 wxSizerFlags(100).Border());
143 sizerRoot
->Add(sizerBottom
, wxSizerFlags(100).Expand().Border());
146 sizerRoot
->Add(new wxButton(m_panel
, wxID_OK
),
147 wxSizerFlags().Centre().DoubleBorder());
148 Connect(wxID_OK
, wxEVT_COMMAND_BUTTON_CLICKED
,
149 wxCommandEventHandler(WrapSizerFrame::OnButton
));
151 // Set sizer for the panel
152 m_panel
->SetSizer(sizerRoot
);