]>
git.saurik.com Git - wxWidgets.git/blob - samples/widgets/toggle.cpp
626bc0c2bb4af89d39390b6b8b5f26ddb2e0473a
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"
39 #include "icons/toggle.xpm"
41 // ----------------------------------------------------------------------------
43 // ----------------------------------------------------------------------------
48 TogglePage_Reset
= wxID_HIGHEST
,
49 TogglePage_ChangeLabel
,
53 // ----------------------------------------------------------------------------
54 // CheckBoxWidgetsPage
55 // ----------------------------------------------------------------------------
57 class ToggleWidgetsPage
: public WidgetsPage
60 ToggleWidgetsPage(WidgetsBookCtrl
*book
, wxImageList
*imaglist
);
61 virtual ~ToggleWidgetsPage(){};
63 virtual wxControl
*GetWidget() const { return m_toggle
; }
64 virtual void RecreateWidget() { CreateToggle(); }
68 void OnButtonReset(wxCommandEvent
& event
);
69 void OnButtonChangeLabel(wxCommandEvent
& event
);
71 // reset the toggle parameters
74 // (re)create the toggle
80 // the checkbox itself and the sizer it is in
81 wxToggleButton
*m_toggle
;
82 wxSizer
*m_sizerToggle
;
84 // the text entries for command parameters
85 wxTextCtrl
*m_textLabel
;
89 DECLARE_WIDGETS_PAGE(ToggleWidgetsPage
)
92 // ----------------------------------------------------------------------------
94 // ----------------------------------------------------------------------------
96 BEGIN_EVENT_TABLE(ToggleWidgetsPage
, WidgetsPage
)
97 EVT_BUTTON(TogglePage_Reset
, ToggleWidgetsPage::OnButtonReset
)
98 EVT_BUTTON(TogglePage_ChangeLabel
, ToggleWidgetsPage::OnButtonChangeLabel
)
101 // ============================================================================
103 // ============================================================================
105 #if defined(__WXUNIVERSAL__)
106 #define FAMILY_CTRLS UNIVERSAL_CTRLS
108 #define FAMILY_CTRLS NATIVE_CTRLS
111 IMPLEMENT_WIDGETS_PAGE(ToggleWidgetsPage
, wxT("ToggleButton"),
115 ToggleWidgetsPage::ToggleWidgetsPage(WidgetsBookCtrl
*book
,
116 wxImageList
*imaglist
)
119 imaglist
->Add(wxBitmap(toggle_xpm
));
121 wxSizer
*sizerTop
= new wxBoxSizer(wxHORIZONTAL
);
124 // wxStaticBox *box = new wxStaticBox(this, wxID_ANY, wxT("Styles"));
126 // wxSizer *sizerLeft = new wxStaticBoxSizer(box, wxVERTICAL);
129 wxStaticBox
*box2
= new wxStaticBox(this, wxID_ANY
, _T("&Operations"));
130 wxSizer
*sizerMiddle
= new wxStaticBoxSizer(box2
, wxVERTICAL
);
132 wxSizer
*sizerRow
= CreateSizerWithTextAndButton(TogglePage_ChangeLabel
,
136 m_textLabel
->SetValue(_T("&Toggle me!"));
138 sizerMiddle
->Add(sizerRow
, 0, wxALL
| wxGROW
, 5);
141 wxSizer
*sizerRight
= new wxBoxSizer(wxHORIZONTAL
);
143 m_toggle
= new wxToggleButton(this, TogglePage_Picker
, wxT("Toggle Button"));
145 sizerRight
->Add(0, 0, 1, wxCENTRE
);
146 sizerRight
->Add(m_toggle
, 1, wxCENTRE
);
147 sizerRight
->Add(0, 0, 1, wxCENTRE
);
148 sizerRight
->SetMinSize(150, 0);
149 m_sizerToggle
= sizerRight
; // save it to modify it later
151 // the 3 panes panes compose the window
152 // sizerTop->Add(sizerLeft, 0, (wxALL & ~wxLEFT), 10);
153 sizerTop
->Add(sizerMiddle
, 1, wxGROW
| wxALL
, 10);
154 sizerTop
->Add(sizerRight
, 1, wxGROW
| (wxALL
& ~wxRIGHT
), 10);
156 // final initializations
164 void ToggleWidgetsPage::Reset()
166 m_toggle
->SetValue(false);
169 void ToggleWidgetsPage::CreateToggle()
171 const bool value
= m_toggle
->GetValue();
173 size_t count
= m_sizerToggle
->GetChildren().GetCount();
174 for ( size_t n
= 0; n
< count
; n
++ )
176 m_sizerToggle
->Remove(0);
181 m_toggle
= new wxToggleButton(this, TogglePage_Picker
, wxT("Toggle Button"));
183 m_toggle
->SetValue(value
);
185 m_sizerToggle
->Add(0, 0, 1, wxCENTRE
);
186 m_sizerToggle
->Add(m_toggle
, 1, wxCENTRE
);
187 m_sizerToggle
->Add(0, 0, 1, wxCENTRE
);
188 m_sizerToggle
->Layout();
191 // ----------------------------------------------------------------------------
193 // ----------------------------------------------------------------------------
195 void ToggleWidgetsPage::OnButtonReset(wxCommandEvent
& WXUNUSED(event
))
202 void ToggleWidgetsPage::OnButtonChangeLabel(wxCommandEvent
& WXUNUSED(event
))
204 m_toggle
->SetLabel(m_textLabel
->GetValue());
207 #endif // wxUSE_TOGGLEBTN