]>
git.saurik.com Git - wxWidgets.git/blob - samples/wrapsizer/wrapsizer.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxWidgets sample demonstrating wxWrapSizer use
4 // Author: Arne Steinarson
6 // Copyright: (c) Arne Steinarson
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
10 #include "wx/wxprec.h"
20 #include "wx/wrapsizer.h"
21 #include "wx/artprov.h"
23 #ifndef wxHAS_IMAGES_IN_RESOURCES
24 #include "../sample.xpm"
28 // ----------------------------------------------------------------------------
30 // ----------------------------------------------------------------------------
32 class WrapSizerFrame
: public wxFrame
38 void OnButton(wxCommandEvent
& WXUNUSED(event
))
43 void AddToolBarButton(wxToolBar
*tb
,
44 const wxString
& label
,
45 const wxString
& artid
)
48 bm
= wxArtProvider::GetBitmap(artid
, wxART_TOOLBAR
, wxSize(16, 16));
49 tb
->AddTool(wxID_ANY
, label
, bm
);
52 wxToolBar
*MakeToolBar()
54 wxToolBar
*tb
= new wxToolBar(m_panel
, wxID_ANY
,
55 wxDefaultPosition
, wxDefaultSize
,
57 AddToolBarButton(tb
, "Help", wxART_HELP_BOOK
);
59 AddToolBarButton(tb
, "Open", wxART_FILE_OPEN
);
61 AddToolBarButton(tb
, "Up", wxART_GO_DIR_UP
);
62 AddToolBarButton(tb
, "Execute", wxART_EXECUTABLE_FILE
);
71 class WrapSizerApp
: public wxApp
83 IMPLEMENT_APP(WrapSizerApp
);
86 // ----------------------------------------------------------------------------
88 // ----------------------------------------------------------------------------
90 WrapSizerFrame::WrapSizerFrame()
91 : wxFrame(NULL
, wxID_ANY
, "wxWrapSizer Sample")
93 SetIcon(wxICON(sample
));
95 m_panel
= new wxPanel(this);
97 // Root sizer, vertical
98 wxSizer
* const sizerRoot
= new wxBoxSizer(wxVERTICAL
);
100 // Some toolbars in a wrap sizer
101 wxSizer
* const sizerTop
= new wxWrapSizer( wxHORIZONTAL
);
102 sizerTop
->Add(MakeToolBar());
103 sizerTop
->Add(20, 1);
104 sizerTop
->Add(MakeToolBar());
105 sizerTop
->Add(20, 1);
106 sizerTop
->Add(MakeToolBar());
107 sizerRoot
->Add(sizerTop
, wxSizerFlags().Expand().Border());
109 // A number of checkboxes inside a wrap sizer
110 wxSizer
*sizerMid
= new wxStaticBoxSizer(wxVERTICAL
, m_panel
,
112 wxSizer
* const sizerMidWrap
= new wxWrapSizer(wxHORIZONTAL
);
113 for ( int nCheck
= 0; nCheck
< 6; nCheck
++ )
115 wxCheckBox
*chk
= new wxCheckBox
119 wxString::Format("Option %d", nCheck
)
122 sizerMidWrap
->Add(chk
, wxSizerFlags().Centre().Border());
125 sizerMid
->Add(sizerMidWrap
, wxSizerFlags(100).Expand());
126 sizerRoot
->Add(sizerMid
, wxSizerFlags(100).Expand().Border());
129 // A shaped item inside a box sizer
130 wxSizer
*sizerBottom
= new wxStaticBoxSizer(wxVERTICAL
, m_panel
,
131 "With wxSHAPED item");
132 wxSizer
*sizerBottomBox
= new wxBoxSizer(wxHORIZONTAL
);
133 sizerBottom
->Add(sizerBottomBox
, wxSizerFlags(100).Expand());
135 sizerBottomBox
->Add(new wxListBox(m_panel
, wxID_ANY
,
136 wxPoint(0, 0), wxSize(70, 70)),
137 wxSizerFlags().Expand().Shaped());
138 sizerBottomBox
->AddSpacer(10);
139 sizerBottomBox
->Add(new wxCheckBox(m_panel
, wxID_ANY
,
140 "A much longer option..."),
141 wxSizerFlags(100).Border());
142 sizerRoot
->Add(sizerBottom
, wxSizerFlags(100).Expand().Border());
145 sizerRoot
->Add(new wxButton(m_panel
, wxID_OK
),
146 wxSizerFlags().Centre().DoubleBorder());
147 Connect(wxID_OK
, wxEVT_BUTTON
,
148 wxCommandEventHandler(WrapSizerFrame::OnButton
));
150 // Set sizer for the panel
151 m_panel
->SetSizer(sizerRoot
);