]> git.saurik.com Git - wxWidgets.git/blame - samples/wrapsizer/wrapsizer.cpp
Applied patch #15286: documentation and col/rowspan demo by dghart
[wxWidgets.git] / samples / wrapsizer / wrapsizer.cpp
CommitLineData
13a38887
VZ
1/////////////////////////////////////////////////////////////////////////////
2// Name: wrapsizer.cpp
3// Purpose: wxWidgets sample demonstrating wxWrapSizer use
4// Author: Arne Steinarson
5// Created: 21.01.2008
41f02b9a 6// RCS-ID: $Id$
13a38887
VZ
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
e7092398 24#ifndef wxHAS_IMAGES_IN_RESOURCES
41f02b9a
FM
25 #include "../sample.xpm"
26#endif
27
28
29// ----------------------------------------------------------------------------
30// definitions
31// ----------------------------------------------------------------------------
32
13a38887
VZ
33class WrapSizerFrame : public wxFrame
34{
35public:
41f02b9a 36 WrapSizerFrame();
13a38887
VZ
37
38private:
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 {
27607839 55 wxToolBar *tb = new wxToolBar(m_panel, wxID_ANY,
13a38887
VZ
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 }
27607839
VZ
68
69 wxPanel *m_panel;
13a38887
VZ
70};
71
13a38887
VZ
72class WrapSizerApp : public wxApp
73{
74public:
75 WrapSizerApp() {}
76
77 virtual bool OnInit()
78 {
79 new WrapSizerFrame;
80 return true;
81 }
82};
83
84IMPLEMENT_APP(WrapSizerApp);
41f02b9a
FM
85
86
87// ----------------------------------------------------------------------------
88// WrapSizerFrame
89// ----------------------------------------------------------------------------
90
91WrapSizerFrame::WrapSizerFrame()
92 : wxFrame(NULL, wxID_ANY, "wxWrapSizer Sample")
93{
94 SetIcon(wxICON(sample));
95
27607839
VZ
96 m_panel = new wxPanel(this);
97
41f02b9a
FM
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
27607839 111 wxSizer *sizerMid = new wxStaticBoxSizer(wxVERTICAL, m_panel,
41f02b9a
FM
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 (
27607839 118 m_panel,
41f02b9a
FM
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
27607839 131 wxSizer *sizerBottom = new wxStaticBoxSizer(wxVERTICAL, m_panel,
41f02b9a
FM
132 "With wxSHAPED item");
133 wxSizer *sizerBottomBox = new wxBoxSizer(wxHORIZONTAL);
134 sizerBottom->Add(sizerBottomBox, wxSizerFlags(100).Expand());
135
27607839 136 sizerBottomBox->Add(new wxListBox(m_panel, wxID_ANY,
41f02b9a
FM
137 wxPoint(0, 0), wxSize(70, 70)),
138 wxSizerFlags().Expand().Shaped());
139 sizerBottomBox->AddSpacer(10);
27607839 140 sizerBottomBox->Add(new wxCheckBox(m_panel, wxID_ANY,
41f02b9a
FM
141 "A much longer option..."),
142 wxSizerFlags(100).Border());
143 sizerRoot->Add(sizerBottom, wxSizerFlags(100).Expand().Border());
144
145 // OK Button
27607839 146 sizerRoot->Add(new wxButton(m_panel, wxID_OK),
41f02b9a 147 wxSizerFlags().Centre().DoubleBorder());
ce7fe42e 148 Connect(wxID_OK, wxEVT_BUTTON,
41f02b9a
FM
149 wxCommandEventHandler(WrapSizerFrame::OnButton));
150
27607839
VZ
151 // Set sizer for the panel
152 m_panel->SetSizer(sizerRoot);
41f02b9a
FM
153
154 Show();
155}
156