]> git.saurik.com Git - wxWidgets.git/blob - samples/wrapsizer/wrapsizer.cpp
Added wxPGChoices::Copy(), tweaked related documentation
[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 class WrapSizerFrame : public wxFrame
25 {
26 public:
27 WrapSizerFrame()
28 : wxFrame(NULL, wxID_ANY, "wxWrapSizer Sample")
29 {
30 // Root sizer, vertical
31 wxSizer * const sizerRoot = new wxBoxSizer(wxVERTICAL);
32
33 // Some toolbars in a wrap sizer
34 wxSizer * const sizerTop = new wxWrapSizer( wxHORIZONTAL );
35 sizerTop->Add(MakeToolBar());
36 sizerTop->Add(20, 1);
37 sizerTop->Add(MakeToolBar());
38 sizerTop->Add(20, 1);
39 sizerTop->Add(MakeToolBar());
40 sizerRoot->Add(sizerTop, wxSizerFlags().Expand().Border());
41
42 // A number of checkboxes inside a wrap sizer
43 wxSizer *sizerMid = new wxStaticBoxSizer(wxVERTICAL, this,
44 "With check-boxes");
45 wxSizer * const sizerMidWrap = new wxWrapSizer(wxHORIZONTAL);
46 for ( int nCheck = 0; nCheck < 6; nCheck++ )
47 {
48 wxCheckBox *chk = new wxCheckBox
49 (
50 this,
51 wxID_ANY,
52 wxString::Format("Option %d", nCheck)
53 );
54
55 sizerMidWrap->Add(chk, wxSizerFlags().Centre().Border());
56 }
57
58 sizerMid->Add(sizerMidWrap, wxSizerFlags(100).Expand());
59 sizerRoot->Add(sizerMid, wxSizerFlags(100).Expand().Border());
60
61
62 // A shaped item inside a box sizer
63 wxSizer *sizerBottom = new wxStaticBoxSizer(wxVERTICAL, this,
64 "With wxSHAPED item");
65 wxSizer *sizerBottomBox = new wxBoxSizer(wxHORIZONTAL);
66 sizerBottom->Add(sizerBottomBox, wxSizerFlags(100).Expand());
67
68 sizerBottomBox->Add(new wxListBox(this, wxID_ANY,
69 wxPoint(0, 0), wxSize(70, 70)),
70 wxSizerFlags().Expand().Shaped());
71 sizerBottomBox->AddSpacer(10);
72 sizerBottomBox->Add(new wxCheckBox(this, wxID_ANY,
73 "A much longer option..."),
74 wxSizerFlags(100).Border());
75 sizerRoot->Add(sizerBottom, wxSizerFlags(100).Expand().Border());
76
77 // OK Button
78 sizerRoot->Add(new wxButton(this, wxID_OK),
79 wxSizerFlags().Centre().DoubleBorder());
80 Connect(wxID_OK, wxEVT_COMMAND_BUTTON_CLICKED,
81 wxCommandEventHandler(WrapSizerFrame::OnButton));
82
83 // Set sizer for window
84 SetSizerAndFit(sizerRoot);
85
86 Show();
87 }
88
89 private:
90 void OnButton(wxCommandEvent& WXUNUSED(event))
91 {
92 Close();
93 }
94
95 void AddToolBarButton(wxToolBar *tb,
96 const wxString& label,
97 const wxString& artid)
98 {
99 wxBitmap
100 bm = wxArtProvider::GetBitmap(artid, wxART_TOOLBAR, wxSize(16, 16));
101 tb->AddTool(wxID_ANY, label, bm);
102 }
103
104 wxToolBar *MakeToolBar()
105 {
106 wxToolBar *tb = new wxToolBar(this, wxID_ANY,
107 wxDefaultPosition, wxDefaultSize,
108 wxTB_NODIVIDER);
109 AddToolBarButton(tb, "Help", wxART_HELP_BOOK);
110 tb->AddSeparator( );
111 AddToolBarButton(tb, "Open", wxART_FILE_OPEN);
112 tb->AddSeparator( );
113 AddToolBarButton(tb, "Up", wxART_GO_DIR_UP);
114 AddToolBarButton(tb, "Execute", wxART_EXECUTABLE_FILE);
115
116 tb->Realize( );
117 return tb;
118 }
119
120 };
121
122
123 class WrapSizerApp : public wxApp
124 {
125 public:
126 WrapSizerApp() {}
127
128 virtual bool OnInit()
129 {
130 new WrapSizerFrame;
131 return true;
132 }
133 };
134
135 IMPLEMENT_APP(WrapSizerApp);