]>
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(); }
69 void OnButtonReset(wxCommandEvent
& event
);
70 void OnButtonChangeLabel(wxCommandEvent
& event
);
72 // reset the toggle parameters
75 // (re)create the toggle
81 // the checkbox itself and the sizer it is in
82 wxToggleButton
*m_toggle
;
83 wxSizer
*m_sizerToggle
;
85 // the text entries for command parameters
86 wxTextCtrl
*m_textLabel
;
90 DECLARE_WIDGETS_PAGE(ToggleWidgetsPage
)
93 // ----------------------------------------------------------------------------
95 // ----------------------------------------------------------------------------
97 BEGIN_EVENT_TABLE(ToggleWidgetsPage
, WidgetsPage
)
98 EVT_BUTTON(TogglePage_Reset
, ToggleWidgetsPage::OnButtonReset
)
99 EVT_BUTTON(TogglePage_ChangeLabel
, ToggleWidgetsPage::OnButtonChangeLabel
)
102 // ============================================================================
104 // ============================================================================
106 #if defined(__WXUNIVERSAL__)
107 #define FAMILY_CTRLS UNIVERSAL_CTRLS
109 #define FAMILY_CTRLS NATIVE_CTRLS
112 IMPLEMENT_WIDGETS_PAGE(ToggleWidgetsPage
, wxT("ToggleButton"),
116 ToggleWidgetsPage::ToggleWidgetsPage(WidgetsBookCtrl
*book
,
117 wxImageList
*imaglist
)
118 :WidgetsPage(book
, imaglist
, toggle_xpm
)
120 wxSizer
*sizerTop
= new wxBoxSizer(wxHORIZONTAL
);
123 // wxStaticBox *box = new wxStaticBox(this, wxID_ANY, wxT("Styles"));
125 // wxSizer *sizerLeft = new wxStaticBoxSizer(box, wxVERTICAL);
128 wxStaticBox
*box2
= new wxStaticBox(this, wxID_ANY
, _T("&Operations"));
129 wxSizer
*sizerMiddle
= new wxStaticBoxSizer(box2
, wxVERTICAL
);
131 wxSizer
*sizerRow
= CreateSizerWithTextAndButton(TogglePage_ChangeLabel
,
135 m_textLabel
->SetValue(_T("&Toggle me!"));
137 sizerMiddle
->Add(sizerRow
, 0, wxALL
| wxGROW
, 5);
140 wxSizer
*sizerRight
= new wxBoxSizer(wxHORIZONTAL
);
142 m_toggle
= new wxToggleButton(this, TogglePage_Picker
, wxT("Toggle Button"));
144 sizerRight
->Add(0, 0, 1, wxCENTRE
);
145 sizerRight
->Add(m_toggle
, 1, wxCENTRE
);
146 sizerRight
->Add(0, 0, 1, wxCENTRE
);
147 sizerRight
->SetMinSize(150, 0);
148 m_sizerToggle
= sizerRight
; // save it to modify it later
150 // the 3 panes panes compose the window
151 // sizerTop->Add(sizerLeft, 0, (wxALL & ~wxLEFT), 10);
152 sizerTop
->Add(sizerMiddle
, 1, wxGROW
| wxALL
, 10);
153 sizerTop
->Add(sizerRight
, 1, wxGROW
| (wxALL
& ~wxRIGHT
), 10);
155 // final initializations
163 void ToggleWidgetsPage::Reset()
165 m_toggle
->SetValue(false);
168 void ToggleWidgetsPage::CreateToggle()
170 const bool value
= m_toggle
->GetValue();
172 size_t count
= m_sizerToggle
->GetChildren().GetCount();
173 for ( size_t n
= 0; n
< count
; n
++ )
175 m_sizerToggle
->Remove(0);
180 m_toggle
= new wxToggleButton(this, TogglePage_Picker
, wxT("Toggle Button"));
182 m_toggle
->SetValue(value
);
184 m_sizerToggle
->Add(0, 0, 1, wxCENTRE
);
185 m_sizerToggle
->Add(m_toggle
, 1, wxCENTRE
);
186 m_sizerToggle
->Add(0, 0, 1, wxCENTRE
);
187 m_sizerToggle
->Layout();
190 // ----------------------------------------------------------------------------
192 // ----------------------------------------------------------------------------
194 void ToggleWidgetsPage::OnButtonReset(wxCommandEvent
& WXUNUSED(event
))
201 void ToggleWidgetsPage::OnButtonChangeLabel(wxCommandEvent
& WXUNUSED(event
))
203 m_toggle
->SetLabel(m_textLabel
->GetValue());
206 #endif // wxUSE_TOGGLEBTN