]> git.saurik.com Git - wxWidgets.git/blob - samples/wrapsizer/wrapsizer.cpp
Applied #10917: wxGTK wxFileDialog::SetDirectory and ::SetFilename problems
[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 __WXMSW__
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(this, 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
70 class WrapSizerApp : public wxApp
71 {
72 public:
73 WrapSizerApp() {}
74
75 virtual bool OnInit()
76 {
77 new WrapSizerFrame;
78 return true;
79 }
80 };
81
82 IMPLEMENT_APP(WrapSizerApp);
83
84
85 // ----------------------------------------------------------------------------
86 // WrapSizerFrame
87 // ----------------------------------------------------------------------------
88
89 WrapSizerFrame::WrapSizerFrame()
90 : wxFrame(NULL, wxID_ANY, "wxWrapSizer Sample")
91 {
92 SetIcon(wxICON(sample));
93
94 // Root sizer, vertical
95 wxSizer * const sizerRoot = new wxBoxSizer(wxVERTICAL);
96
97 // Some toolbars in a wrap sizer
98 wxSizer * const sizerTop = new wxWrapSizer( wxHORIZONTAL );
99 sizerTop->Add(MakeToolBar());
100 sizerTop->Add(20, 1);
101 sizerTop->Add(MakeToolBar());
102 sizerTop->Add(20, 1);
103 sizerTop->Add(MakeToolBar());
104 sizerRoot->Add(sizerTop, wxSizerFlags().Expand().Border());
105
106 // A number of checkboxes inside a wrap sizer
107 wxSizer *sizerMid = new wxStaticBoxSizer(wxVERTICAL, this,
108 "With check-boxes");
109 wxSizer * const sizerMidWrap = new wxWrapSizer(wxHORIZONTAL);
110 for ( int nCheck = 0; nCheck < 6; nCheck++ )
111 {
112 wxCheckBox *chk = new wxCheckBox
113 (
114 this,
115 wxID_ANY,
116 wxString::Format("Option %d", nCheck)
117 );
118
119 sizerMidWrap->Add(chk, wxSizerFlags().Centre().Border());
120 }
121
122 sizerMid->Add(sizerMidWrap, wxSizerFlags(100).Expand());
123 sizerRoot->Add(sizerMid, wxSizerFlags(100).Expand().Border());
124
125
126 // A shaped item inside a box sizer
127 wxSizer *sizerBottom = new wxStaticBoxSizer(wxVERTICAL, this,
128 "With wxSHAPED item");
129 wxSizer *sizerBottomBox = new wxBoxSizer(wxHORIZONTAL);
130 sizerBottom->Add(sizerBottomBox, wxSizerFlags(100).Expand());
131
132 sizerBottomBox->Add(new wxListBox(this, wxID_ANY,
133 wxPoint(0, 0), wxSize(70, 70)),
134 wxSizerFlags().Expand().Shaped());
135 sizerBottomBox->AddSpacer(10);
136 sizerBottomBox->Add(new wxCheckBox(this, wxID_ANY,
137 "A much longer option..."),
138 wxSizerFlags(100).Border());
139 sizerRoot->Add(sizerBottom, wxSizerFlags(100).Expand().Border());
140
141 // OK Button
142 sizerRoot->Add(new wxButton(this, wxID_OK),
143 wxSizerFlags().Centre().DoubleBorder());
144 Connect(wxID_OK, wxEVT_COMMAND_BUTTON_CLICKED,
145 wxCommandEventHandler(WrapSizerFrame::OnButton));
146
147 // Set sizer for window
148 SetSizerAndFit(sizerRoot);
149
150 Show();
151 }
152