]>
git.saurik.com Git - wxWidgets.git/blob - samples/widgets/toggle.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Program: wxWidgets Widgets Sample
4 // Purpose: Part of the widgets sample showing toggle control
5 // Author: Dimitri Schoolwerth, Vadim Zeitlin
6 // Created: 27 Sep 2003
8 // Copyright: (c) 2006 Wlodzmierz Skiba
9 // License: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 // for compilers that support precompilation, includes "wx/wx.h".
21 #include "wx/wxprec.h"
29 #include "wx/tglbtn.h"
33 // for all others, include the necessary headers
36 #include "wx/statbox.h"
37 #include "wx/textctrl.h"
40 #include "icons/toggle.xpm"
42 // ----------------------------------------------------------------------------
44 // ----------------------------------------------------------------------------
49 TogglePage_Reset
= wxID_HIGHEST
,
50 TogglePage_ChangeLabel
,
54 // ----------------------------------------------------------------------------
55 // CheckBoxWidgetsPage
56 // ----------------------------------------------------------------------------
58 class ToggleWidgetsPage
: public WidgetsPage
61 ToggleWidgetsPage(WidgetsBookCtrl
*book
, wxImageList
*imaglist
);
62 virtual ~ToggleWidgetsPage(){};
64 virtual wxControl
*GetWidget() const { return m_toggle
; }
65 virtual void RecreateWidget() { CreateToggle(); }
67 // lazy creation of the content
68 virtual void CreateContent();
72 void OnButtonReset(wxCommandEvent
& event
);
73 void OnButtonChangeLabel(wxCommandEvent
& event
);
75 // reset the toggle parameters
78 // (re)create the toggle
84 // the checkbox itself and the sizer it is in
85 wxToggleButton
*m_toggle
;
86 wxSizer
*m_sizerToggle
;
88 // the text entries for command parameters
89 wxTextCtrl
*m_textLabel
;
93 DECLARE_WIDGETS_PAGE(ToggleWidgetsPage
)
96 // ----------------------------------------------------------------------------
98 // ----------------------------------------------------------------------------
100 BEGIN_EVENT_TABLE(ToggleWidgetsPage
, WidgetsPage
)
101 EVT_BUTTON(TogglePage_Reset
, ToggleWidgetsPage::OnButtonReset
)
102 EVT_BUTTON(TogglePage_ChangeLabel
, ToggleWidgetsPage::OnButtonChangeLabel
)
105 // ============================================================================
107 // ============================================================================
109 #if defined(__WXUNIVERSAL__)
110 #define FAMILY_CTRLS UNIVERSAL_CTRLS
112 #define FAMILY_CTRLS NATIVE_CTRLS
115 IMPLEMENT_WIDGETS_PAGE(ToggleWidgetsPage
, wxT("ToggleButton"),
119 ToggleWidgetsPage::ToggleWidgetsPage(WidgetsBookCtrl
*book
,
120 wxImageList
*imaglist
)
121 :WidgetsPage(book
, imaglist
, toggle_xpm
)
125 void ToggleWidgetsPage::CreateContent()
127 wxSizer
*sizerTop
= new wxBoxSizer(wxHORIZONTAL
);
130 // wxStaticBox *box = new wxStaticBox(this, wxID_ANY, wxT("Styles"));
132 // wxSizer *sizerLeft = new wxStaticBoxSizer(box, wxVERTICAL);
135 wxStaticBox
*box2
= new wxStaticBox(this, wxID_ANY
, _T("&Operations"));
136 wxSizer
*sizerMiddle
= new wxStaticBoxSizer(box2
, wxVERTICAL
);
138 wxSizer
*sizerRow
= CreateSizerWithTextAndButton(TogglePage_ChangeLabel
,
142 m_textLabel
->SetValue(_T("&Toggle me!"));
144 sizerMiddle
->Add(sizerRow
, 0, wxALL
| wxGROW
, 5);
147 wxSizer
*sizerRight
= new wxBoxSizer(wxHORIZONTAL
);
149 m_toggle
= new wxToggleButton(this, TogglePage_Picker
, wxT("Toggle Button"));
151 sizerRight
->Add(0, 0, 1, wxCENTRE
);
152 sizerRight
->Add(m_toggle
, 1, wxCENTRE
);
153 sizerRight
->Add(0, 0, 1, wxCENTRE
);
154 sizerRight
->SetMinSize(150, 0);
155 m_sizerToggle
= sizerRight
; // save it to modify it later
157 // the 3 panes panes compose the window
158 // sizerTop->Add(sizerLeft, 0, (wxALL & ~wxLEFT), 10);
159 sizerTop
->Add(sizerMiddle
, 1, wxGROW
| wxALL
, 10);
160 sizerTop
->Add(sizerRight
, 1, wxGROW
| (wxALL
& ~wxRIGHT
), 10);
162 // final initializations
170 void ToggleWidgetsPage::Reset()
172 m_toggle
->SetValue(false);
175 void ToggleWidgetsPage::CreateToggle()
177 const bool value
= m_toggle
->GetValue();
179 size_t count
= m_sizerToggle
->GetChildren().GetCount();
180 for ( size_t n
= 0; n
< count
; n
++ )
182 m_sizerToggle
->Remove(0);
187 m_toggle
= new wxToggleButton(this, TogglePage_Picker
, wxT("Toggle Button"));
189 m_toggle
->SetValue(value
);
191 m_sizerToggle
->Add(0, 0, 1, wxCENTRE
);
192 m_sizerToggle
->Add(m_toggle
, 1, wxCENTRE
);
193 m_sizerToggle
->Add(0, 0, 1, wxCENTRE
);
194 m_sizerToggle
->Layout();
197 // ----------------------------------------------------------------------------
199 // ----------------------------------------------------------------------------
201 void ToggleWidgetsPage::OnButtonReset(wxCommandEvent
& WXUNUSED(event
))
208 void ToggleWidgetsPage::OnButtonChangeLabel(wxCommandEvent
& WXUNUSED(event
))
210 m_toggle
->SetLabel(m_textLabel
->GetValue());
213 #endif // wxUSE_TOGGLEBTN