1 /////////////////////////////////////////////////////////////////////////////
2 // Program: wxWindows Widgets Sample
4 // Purpose: Part of the widgets sample showing wxCheckBox
5 // Author: Dimitri Schoolwerth
6 // Created: 27 Sep 2003
8 // Copyright: (c) 2003 wxWindows team
9 // License: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 // for compilers that support precompilation, includes "wx/wx.h".
21 #include "wx/wxprec.h"
27 // for all others, include the necessary headers
32 #include "wx/bitmap.h"
33 #include "wx/button.h"
34 #include "wx/checkbox.h"
42 #include "icons/checkbox.xpm"
44 // ----------------------------------------------------------------------------
45 // CheckBoxWidgetsPage
46 // ----------------------------------------------------------------------------
48 class CheckBoxWidgetsPage
: public WidgetsPage
51 CheckBoxWidgetsPage(wxNotebook
*notebook
, wxImageList
*imaglist
);
52 virtual ~CheckBoxWidgetsPage();
56 void OnCheckBox(wxCommandEvent
& event
);
58 void OnButton(wxCommandEvent
& event
);
63 wxCheckBox
*m_chk2States
,
65 *m_chk3StatesAllows3rdStateForUser
;
71 DECLARE_WIDGETS_PAGE(CheckBoxWidgetsPage
)
74 // ----------------------------------------------------------------------------
76 // ----------------------------------------------------------------------------
78 BEGIN_EVENT_TABLE(CheckBoxWidgetsPage
, WidgetsPage
)
79 EVT_CHECKBOX(wxID_ANY
, CheckBoxWidgetsPage::OnCheckBox
)
80 EVT_BUTTON(wxID_ANY
, CheckBoxWidgetsPage::OnButton
)
83 // ============================================================================
85 // ============================================================================
87 IMPLEMENT_WIDGETS_PAGE(CheckBoxWidgetsPage
, wxT("CheckBox"));
89 CheckBoxWidgetsPage::CheckBoxWidgetsPage(wxNotebook
*notebook
,
90 wxImageList
*imaglist
)
91 : WidgetsPage(notebook
)
93 imaglist
->Add(wxBitmap(checkbox_xpm
));
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") );
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
);
109 wxSizer
*sizerTop
= new wxBoxSizer(wxVERTICAL
);
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
);
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
);
121 sizerTop
->Add(szr
, 0, wxEXPAND
);
124 sizerTop
->Add(0, 0, 1, wxEXPAND
);
125 sizerTop
->Add(m_chk3StatesAllows3rdStateForUser
, 0, wxEXPAND
);
126 sizerTop
->Add(0, 0, 1, wxEXPAND
);
133 CheckBoxWidgetsPage::~CheckBoxWidgetsPage()
137 // ----------------------------------------------------------------------------
139 // ----------------------------------------------------------------------------
141 void CheckBoxWidgetsPage::OnCheckBox(wxCommandEvent
& event
)
143 static const wxString stateNames
[] =
147 wxT("undetermined/mixed"),
149 wxCheckBoxState state
= (wxCheckBoxState
) event
.GetInt();
151 wxCHECK_RET( (state
>= (wxCheckBoxState
)0) && (state
< (wxCheckBoxState
)WXSIZEOF(stateNames
)),
152 _T("event.GetInt() returned an invalid wxCheckBoxState") );
154 wxLogMessage(wxT("Checkbox now set to state: %s"),
155 stateNames
[state
].c_str());
158 void CheckBoxWidgetsPage::OnButton(wxCommandEvent
& WXUNUSED(event
))
160 m_chk3States
->Set3StateValue(wxCHK_UNDETERMINED
);