]>
Commit | Line | Data |
---|---|---|
13a38887 VZ |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: wrapsizer.cpp | |
3 | // Purpose: wxWidgets sample demonstrating wxWrapSizer use | |
4 | // Author: Arne Steinarson | |
5 | // Created: 21.01.2008 | |
13a38887 VZ |
6 | // Copyright: (c) Arne Steinarson |
7 | // Licence: wxWindows licence | |
8 | ///////////////////////////////////////////////////////////////////////////// | |
9 | ||
10 | #include "wx/wxprec.h" | |
11 | ||
12 | #ifdef __BORLANDC__ | |
13 | #pragma hdrstop | |
14 | #endif | |
15 | #ifndef WX_PRECOMP | |
16 | #include "wx/wx.h" | |
17 | #endif | |
18 | ||
19 | #include "wx/log.h" | |
20 | #include "wx/wrapsizer.h" | |
21 | #include "wx/artprov.h" | |
22 | ||
e7092398 | 23 | #ifndef wxHAS_IMAGES_IN_RESOURCES |
41f02b9a FM |
24 | #include "../sample.xpm" |
25 | #endif | |
26 | ||
27 | ||
28 | // ---------------------------------------------------------------------------- | |
29 | // definitions | |
30 | // ---------------------------------------------------------------------------- | |
31 | ||
13a38887 VZ |
32 | class WrapSizerFrame : public wxFrame |
33 | { | |
34 | public: | |
41f02b9a | 35 | WrapSizerFrame(); |
13a38887 VZ |
36 | |
37 | private: | |
38 | void OnButton(wxCommandEvent& WXUNUSED(event)) | |
39 | { | |
40 | Close(); | |
41 | } | |
42 | ||
43 | void AddToolBarButton(wxToolBar *tb, | |
44 | const wxString& label, | |
45 | const wxString& artid) | |
46 | { | |
47 | wxBitmap | |
48 | bm = wxArtProvider::GetBitmap(artid, wxART_TOOLBAR, wxSize(16, 16)); | |
49 | tb->AddTool(wxID_ANY, label, bm); | |
50 | } | |
51 | ||
52 | wxToolBar *MakeToolBar() | |
53 | { | |
27607839 | 54 | wxToolBar *tb = new wxToolBar(m_panel, wxID_ANY, |
13a38887 VZ |
55 | wxDefaultPosition, wxDefaultSize, |
56 | wxTB_NODIVIDER); | |
57 | AddToolBarButton(tb, "Help", wxART_HELP_BOOK); | |
58 | tb->AddSeparator( ); | |
59 | AddToolBarButton(tb, "Open", wxART_FILE_OPEN); | |
60 | tb->AddSeparator( ); | |
61 | AddToolBarButton(tb, "Up", wxART_GO_DIR_UP); | |
62 | AddToolBarButton(tb, "Execute", wxART_EXECUTABLE_FILE); | |
63 | ||
64 | tb->Realize( ); | |
65 | return tb; | |
66 | } | |
27607839 VZ |
67 | |
68 | wxPanel *m_panel; | |
13a38887 VZ |
69 | }; |
70 | ||
13a38887 VZ |
71 | class WrapSizerApp : public wxApp |
72 | { | |
73 | public: | |
74 | WrapSizerApp() {} | |
75 | ||
76 | virtual bool OnInit() | |
77 | { | |
78 | new WrapSizerFrame; | |
79 | return true; | |
80 | } | |
81 | }; | |
82 | ||
83 | IMPLEMENT_APP(WrapSizerApp); | |
41f02b9a FM |
84 | |
85 | ||
86 | // ---------------------------------------------------------------------------- | |
87 | // WrapSizerFrame | |
88 | // ---------------------------------------------------------------------------- | |
89 | ||
90 | WrapSizerFrame::WrapSizerFrame() | |
91 | : wxFrame(NULL, wxID_ANY, "wxWrapSizer Sample") | |
92 | { | |
93 | SetIcon(wxICON(sample)); | |
94 | ||
27607839 VZ |
95 | m_panel = new wxPanel(this); |
96 | ||
41f02b9a FM |
97 | // Root sizer, vertical |
98 | wxSizer * const sizerRoot = new wxBoxSizer(wxVERTICAL); | |
99 | ||
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()); | |
108 | ||
109 | // A number of checkboxes inside a wrap sizer | |
27607839 | 110 | wxSizer *sizerMid = new wxStaticBoxSizer(wxVERTICAL, m_panel, |
41f02b9a FM |
111 | "With check-boxes"); |
112 | wxSizer * const sizerMidWrap = new wxWrapSizer(wxHORIZONTAL); | |
113 | for ( int nCheck = 0; nCheck < 6; nCheck++ ) | |
114 | { | |
115 | wxCheckBox *chk = new wxCheckBox | |
116 | ( | |
27607839 | 117 | m_panel, |
41f02b9a FM |
118 | wxID_ANY, |
119 | wxString::Format("Option %d", nCheck) | |
120 | ); | |
121 | ||
122 | sizerMidWrap->Add(chk, wxSizerFlags().Centre().Border()); | |
123 | } | |
124 | ||
125 | sizerMid->Add(sizerMidWrap, wxSizerFlags(100).Expand()); | |
126 | sizerRoot->Add(sizerMid, wxSizerFlags(100).Expand().Border()); | |
127 | ||
128 | ||
129 | // A shaped item inside a box sizer | |
27607839 | 130 | wxSizer *sizerBottom = new wxStaticBoxSizer(wxVERTICAL, m_panel, |
41f02b9a FM |
131 | "With wxSHAPED item"); |
132 | wxSizer *sizerBottomBox = new wxBoxSizer(wxHORIZONTAL); | |
133 | sizerBottom->Add(sizerBottomBox, wxSizerFlags(100).Expand()); | |
134 | ||
27607839 | 135 | sizerBottomBox->Add(new wxListBox(m_panel, wxID_ANY, |
41f02b9a FM |
136 | wxPoint(0, 0), wxSize(70, 70)), |
137 | wxSizerFlags().Expand().Shaped()); | |
138 | sizerBottomBox->AddSpacer(10); | |
27607839 | 139 | sizerBottomBox->Add(new wxCheckBox(m_panel, wxID_ANY, |
41f02b9a FM |
140 | "A much longer option..."), |
141 | wxSizerFlags(100).Border()); | |
142 | sizerRoot->Add(sizerBottom, wxSizerFlags(100).Expand().Border()); | |
143 | ||
144 | // OK Button | |
27607839 | 145 | sizerRoot->Add(new wxButton(m_panel, wxID_OK), |
41f02b9a | 146 | wxSizerFlags().Centre().DoubleBorder()); |
ce7fe42e | 147 | Connect(wxID_OK, wxEVT_BUTTON, |
41f02b9a FM |
148 | wxCommandEventHandler(WrapSizerFrame::OnButton)); |
149 | ||
27607839 VZ |
150 | // Set sizer for the panel |
151 | m_panel->SetSizer(sizerRoot); | |
41f02b9a FM |
152 | |
153 | Show(); | |
154 | } | |
155 |