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"
24 class WrapSizerFrame
: public wxFrame
28 : wxFrame(NULL
, wxID_ANY
, "wxWrapSizer Sample")
30 // Root sizer, vertical
31 wxSizer
* const sizerRoot
= new wxBoxSizer(wxVERTICAL
);
33 // Some toolbars in a wrap sizer
34 wxSizer
* const sizerTop
= new wxWrapSizer( wxHORIZONTAL
);
35 sizerTop
->Add(MakeToolBar());
37 sizerTop
->Add(MakeToolBar());
39 sizerTop
->Add(MakeToolBar());
40 sizerRoot
->Add(sizerTop
, wxSizerFlags().Expand().Border());
42 // A number of checkboxes inside a wrap sizer
43 wxSizer
*sizerMid
= new wxStaticBoxSizer(wxVERTICAL
, this,
45 wxSizer
* const sizerMidWrap
= new wxWrapSizer(wxHORIZONTAL
);
46 for ( int nCheck
= 0; nCheck
< 6; nCheck
++ )
48 wxCheckBox
*chk
= new wxCheckBox
52 wxString::Format("Option %d", nCheck
)
55 sizerMidWrap
->Add(chk
, wxSizerFlags().Centre().Border());
58 sizerMid
->Add(sizerMidWrap
, wxSizerFlags(100).Expand());
59 sizerRoot
->Add(sizerMid
, wxSizerFlags(100).Expand().Border());
62 // A shaped item inside a box sizer
63 wxSizer
*sizerBottom
= new wxStaticBoxSizer(wxVERTICAL
, this,
64 "With wxSHAPED item");
65 wxSizer
*sizerBottomBox
= new wxBoxSizer(wxHORIZONTAL
);
66 sizerBottom
->Add(sizerBottomBox
, wxSizerFlags(100).Expand());
68 sizerBottomBox
->Add(new wxListBox(this, wxID_ANY
,
69 wxPoint(0, 0), wxSize(70, 70)),
70 wxSizerFlags().Expand().Shaped());
71 sizerBottomBox
->AddSpacer(10);
72 sizerBottomBox
->Add(new wxCheckBox(this, wxID_ANY
,
73 "A much longer option..."),
74 wxSizerFlags(100).Border());
75 sizerRoot
->Add(sizerBottom
, wxSizerFlags(100).Expand().Border());
78 sizerRoot
->Add(new wxButton(this, wxID_OK
),
79 wxSizerFlags().Centre().DoubleBorder());
80 Connect(wxID_OK
, wxEVT_COMMAND_BUTTON_CLICKED
,
81 wxCommandEventHandler(WrapSizerFrame::OnButton
));
83 // Set sizer for window
84 SetSizerAndFit(sizerRoot
);
90 void OnButton(wxCommandEvent
& WXUNUSED(event
))
95 void AddToolBarButton(wxToolBar
*tb
,
96 const wxString
& label
,
97 const wxString
& artid
)
100 bm
= wxArtProvider::GetBitmap(artid
, wxART_TOOLBAR
, wxSize(16, 16));
101 tb
->AddTool(wxID_ANY
, label
, bm
);
104 wxToolBar
*MakeToolBar()
106 wxToolBar
*tb
= new wxToolBar(this, wxID_ANY
,
107 wxDefaultPosition
, wxDefaultSize
,
109 AddToolBarButton(tb
, "Help", wxART_HELP_BOOK
);
111 AddToolBarButton(tb
, "Open", wxART_FILE_OPEN
);
113 AddToolBarButton(tb
, "Up", wxART_GO_DIR_UP
);
114 AddToolBarButton(tb
, "Execute", wxART_EXECUTABLE_FILE
);
123 class WrapSizerApp
: public wxApp
128 virtual bool OnInit()
135 IMPLEMENT_APP(WrapSizerApp
);