]> git.saurik.com Git - wxWidgets.git/blame_incremental - samples/widgets/checkbox.cpp
compilation fix for gcc (closes bug 996701)
[wxWidgets.git] / samples / widgets / checkbox.cpp
... / ...
CommitLineData
1/////////////////////////////////////////////////////////////////////////////
2// Program: wxWidgets Widgets Sample
3// Name: checkbox.cpp
4// Purpose: Part of the widgets sample showing wxCheckBox
5// Author: Dimitri Schoolwerth
6// Created: 27 Sep 2003
7// Id: $Id$
8// Copyright: (c) 2003 wxWindows team
9// License: wxWindows license
10/////////////////////////////////////////////////////////////////////////////
11
12// ============================================================================
13// declarations
14// ============================================================================
15
16// ----------------------------------------------------------------------------
17// headers
18// ----------------------------------------------------------------------------
19
20// for compilers that support precompilation, includes "wx/wx.h".
21#include "wx/wxprec.h"
22
23#ifdef __BORLANDC__
24 #pragma hdrstop
25#endif
26
27// for all others, include the necessary headers
28#ifndef WX_PRECOMP
29 #include "wx/app.h"
30 #include "wx/log.h"
31
32 #include "wx/bitmap.h"
33 #include "wx/button.h"
34 #include "wx/checkbox.h"
35
36 #include "wx/sizer.h"
37
38#endif
39
40#include "widgets.h"
41
42#include "icons/checkbox.xpm"
43
44// ----------------------------------------------------------------------------
45// CheckBoxWidgetsPage
46// ----------------------------------------------------------------------------
47
48class CheckBoxWidgetsPage : public WidgetsPage
49{
50public:
51 CheckBoxWidgetsPage(wxNotebook *notebook, wxImageList *imaglist);
52 virtual ~CheckBoxWidgetsPage();
53
54protected:
55 // event handlers
56 void OnCheckBox(wxCommandEvent& event);
57
58 void OnButton(wxCommandEvent& event);
59
60 // the controls
61 // ------------
62
63 wxCheckBox *m_chk2States,
64 *m_chk3States,
65 *m_chk3StatesAllows3rdStateForUser;
66
67 wxButton *m_button;
68
69private:
70 DECLARE_EVENT_TABLE()
71 DECLARE_WIDGETS_PAGE(CheckBoxWidgetsPage)
72};
73
74// ----------------------------------------------------------------------------
75// event tables
76// ----------------------------------------------------------------------------
77
78BEGIN_EVENT_TABLE(CheckBoxWidgetsPage, WidgetsPage)
79 EVT_CHECKBOX(wxID_ANY, CheckBoxWidgetsPage::OnCheckBox)
80 EVT_BUTTON(wxID_ANY, CheckBoxWidgetsPage::OnButton)
81END_EVENT_TABLE()
82
83// ============================================================================
84// implementation
85// ============================================================================
86
87IMPLEMENT_WIDGETS_PAGE(CheckBoxWidgetsPage, wxT("CheckBox"));
88
89CheckBoxWidgetsPage::CheckBoxWidgetsPage(wxNotebook *notebook,
90 wxImageList *imaglist)
91 : WidgetsPage(notebook)
92{
93 imaglist->Add(wxBitmap(checkbox_xpm));
94
95 m_chk2States = new wxCheckBox( this, wxID_ANY,
96 wxT("I'm a standard 2-state checkbox") );
97 m_chk3States = new wxCheckBox( this, wxID_ANY,
98 wxT("I'm a 3-state checkbox that disallows setting the undetermined")
99 wxT(" state by the user" ),
100 wxDefaultPosition, wxDefaultSize, wxCHK_3STATE);
101 m_button = new wxButton( this, wxID_ANY, wxT("&Programmatically set this")
102 wxT(" checkbox to undetermined state") );
103
104 m_chk3StatesAllows3rdStateForUser = new wxCheckBox(this, wxID_ANY,
105 wxT("I'm a 3-state checkbox that allows setting the 3rd state by the user"),
106 wxDefaultPosition, wxDefaultSize, wxCHK_3STATE
107 | wxCHK_ALLOW_3RD_STATE_FOR_USER);
108
109 wxSizer *sizerTop = new wxBoxSizer(wxVERTICAL);
110
111 sizerTop->Add(0, 0, 1, wxEXPAND);
112 sizerTop->Add(m_chk2States, 0, wxEXPAND);
113 sizerTop->Add(0, 0, 1, wxEXPAND);
114 wxSizer *sizerCheckBoxAndButton = new wxBoxSizer(wxHORIZONTAL);
115 {
116 wxSizer *szr = sizerCheckBoxAndButton;
117 szr->Add(m_chk3States, 0, wxEXPAND);
118 szr->Add(0, 0, 1, wxEXPAND);
119 szr->Add(m_button, 0, wxEXPAND);
120
121 sizerTop->Add(szr, 0, wxEXPAND);
122 }
123
124 sizerTop->Add(0, 0, 1, wxEXPAND);
125 sizerTop->Add(m_chk3StatesAllows3rdStateForUser, 0, wxEXPAND);
126 sizerTop->Add(0, 0, 1, wxEXPAND);
127
128 SetSizer(sizerTop);
129
130 sizerTop->Fit(this);
131}
132
133CheckBoxWidgetsPage::~CheckBoxWidgetsPage()
134{
135}
136
137// ----------------------------------------------------------------------------
138// event handlers
139// ----------------------------------------------------------------------------
140
141void CheckBoxWidgetsPage::OnCheckBox(wxCommandEvent& event)
142{
143 static const wxString stateNames[] =
144 {
145 wxT("unchecked"),
146 wxT("checked"),
147 wxT("undetermined/mixed"),
148 };
149 wxCheckBoxState state = (wxCheckBoxState) event.GetInt();
150
151 wxCHECK_RET( (state >= (wxCheckBoxState)0) && (state < (wxCheckBoxState)WXSIZEOF(stateNames)),
152 _T("event.GetInt() returned an invalid wxCheckBoxState") );
153
154 wxLogMessage(wxT("Checkbox now set to state: %s"),
155 stateNames[state].c_str());
156}
157
158void CheckBoxWidgetsPage::OnButton(wxCommandEvent& WXUNUSED(event))
159{
160 m_chk3States->Set3StateValue(wxCHK_UNDETERMINED);
161}