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(this, 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
);
70 class WrapSizerApp
: public wxApp
82 IMPLEMENT_APP(WrapSizerApp
);
85 // ----------------------------------------------------------------------------
87 // ----------------------------------------------------------------------------
89 WrapSizerFrame::WrapSizerFrame()
90 : wxFrame(NULL
, wxID_ANY
, "wxWrapSizer Sample")
92 SetIcon(wxICON(sample
));
94 // Root sizer, vertical
95 wxSizer
* const sizerRoot
= new wxBoxSizer(wxVERTICAL
);
97 // Some toolbars in a wrap sizer
98 wxSizer
* const sizerTop
= new wxWrapSizer( wxHORIZONTAL
);
99 sizerTop
->Add(MakeToolBar());
100 sizerTop
->Add(20, 1);
101 sizerTop
->Add(MakeToolBar());
102 sizerTop
->Add(20, 1);
103 sizerTop
->Add(MakeToolBar());
104 sizerRoot
->Add(sizerTop
, wxSizerFlags().Expand().Border());
106 // A number of checkboxes inside a wrap sizer
107 wxSizer
*sizerMid
= new wxStaticBoxSizer(wxVERTICAL
, this,
109 wxSizer
* const sizerMidWrap
= new wxWrapSizer(wxHORIZONTAL
);
110 for ( int nCheck
= 0; nCheck
< 6; nCheck
++ )
112 wxCheckBox
*chk
= new wxCheckBox
116 wxString::Format("Option %d", nCheck
)
119 sizerMidWrap
->Add(chk
, wxSizerFlags().Centre().Border());
122 sizerMid
->Add(sizerMidWrap
, wxSizerFlags(100).Expand());
123 sizerRoot
->Add(sizerMid
, wxSizerFlags(100).Expand().Border());
126 // A shaped item inside a box sizer
127 wxSizer
*sizerBottom
= new wxStaticBoxSizer(wxVERTICAL
, this,
128 "With wxSHAPED item");
129 wxSizer
*sizerBottomBox
= new wxBoxSizer(wxHORIZONTAL
);
130 sizerBottom
->Add(sizerBottomBox
, wxSizerFlags(100).Expand());
132 sizerBottomBox
->Add(new wxListBox(this, wxID_ANY
,
133 wxPoint(0, 0), wxSize(70, 70)),
134 wxSizerFlags().Expand().Shaped());
135 sizerBottomBox
->AddSpacer(10);
136 sizerBottomBox
->Add(new wxCheckBox(this, wxID_ANY
,
137 "A much longer option..."),
138 wxSizerFlags(100).Border());
139 sizerRoot
->Add(sizerBottom
, wxSizerFlags(100).Expand().Border());
142 sizerRoot
->Add(new wxButton(this, wxID_OK
),
143 wxSizerFlags().Centre().DoubleBorder());
144 Connect(wxID_OK
, wxEVT_COMMAND_BUTTON_CLICKED
,
145 wxCommandEventHandler(WrapSizerFrame::OnButton
));
147 // Set sizer for window
148 SetSizerAndFit(sizerRoot
);