]> git.saurik.com Git - wxWidgets.git/blob - samples/wrapsizer/wrapsizer.cpp
Make storing non-trivial data in wxThreadSpecificInfo possible.
[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 // 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
23 #ifndef wxHAS_IMAGES_IN_RESOURCES
24 #include "../sample.xpm"
25 #endif
26
27
28 // ----------------------------------------------------------------------------
29 // definitions
30 // ----------------------------------------------------------------------------
31
32 class WrapSizerFrame : public wxFrame
33 {
34 public:
35 WrapSizerFrame();
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 {
54 wxToolBar *tb = new wxToolBar(m_panel, wxID_ANY,
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 }
67
68 wxPanel *m_panel;
69 };
70
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);
84
85
86 // ----------------------------------------------------------------------------
87 // WrapSizerFrame
88 // ----------------------------------------------------------------------------
89
90 WrapSizerFrame::WrapSizerFrame()
91 : wxFrame(NULL, wxID_ANY, "wxWrapSizer Sample")
92 {
93 SetIcon(wxICON(sample));
94
95 m_panel = new wxPanel(this);
96
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
110 wxSizer *sizerMid = new wxStaticBoxSizer(wxVERTICAL, m_panel,
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 (
117 m_panel,
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
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());
134
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());
143
144 // OK Button
145 sizerRoot->Add(new wxButton(m_panel, wxID_OK),
146 wxSizerFlags().Centre().DoubleBorder());
147 Connect(wxID_OK, wxEVT_BUTTON,
148 wxCommandEventHandler(WrapSizerFrame::OnButton));
149
150 // Set sizer for the panel
151 m_panel->SetSizer(sizerRoot);
152
153 Show();
154 }
155