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