1 ///////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxCheckBox class interface
4 // Author: Vadim Zeitlin
8 // Copyright: (c) wxWidgets team
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_CHECKBOX_H_BASE_
13 #define _WX_CHECKBOX_H_BASE_
19 #include "wx/control.h"
23 * wxCheckBox style flags
24 * (Using wxCHK_* because wxCB_* is used by wxComboBox).
25 * Determine whether to use a 3-state or 2-state
26 * checkbox. 3-state enables to differentiate
27 * between 'unchecked', 'checked' and 'undetermined'.
29 * In addition to the styles here it is also possible to specify just 0 which
30 * is treated the same as wxCHK_2STATE for compatibility (but using explicit
33 #define wxCHK_2STATE 0x4000
34 #define wxCHK_3STATE 0x1000
37 * If this style is set the user can set the checkbox to the
38 * undetermined state. If not set the undetermined set can only
39 * be set programmatically.
40 * This style can only be used with 3 state checkboxes.
42 #define wxCHK_ALLOW_3RD_STATE_FOR_USER 0x2000
45 * The possible states of a 3-state checkbox (Compatible
46 * with the 2-state checkbox).
52 wxCHK_UNDETERMINED
/* 3-state checkbox only */
56 extern WXDLLIMPEXP_DATA_CORE(const char) wxCheckBoxNameStr
[];
58 // ----------------------------------------------------------------------------
59 // wxCheckBox: a control which shows a label and a box which may be checked
60 // ----------------------------------------------------------------------------
62 class WXDLLIMPEXP_CORE wxCheckBoxBase
: public wxControl
67 // set/get the checked status of the listbox
68 virtual void SetValue(bool value
) = 0;
69 virtual bool GetValue() const = 0;
71 bool IsChecked() const
73 wxASSERT_MSG( !Is3State(), wxT("Calling IsChecked() doesn't make sense for")
74 wxT(" a three state checkbox, Use Get3StateValue() instead") );
79 wxCheckBoxState
Get3StateValue() const
81 wxCheckBoxState state
= DoGet3StateValue();
83 if ( state
== wxCHK_UNDETERMINED
&& !Is3State() )
85 // Undetermined state with a 2-state checkbox??
86 wxFAIL_MSG( wxT("DoGet3StateValue() says the 2-state checkbox is ")
87 wxT("in an undetermined/third state") );
89 state
= wxCHK_UNCHECKED
;
95 void Set3StateValue(wxCheckBoxState state
)
97 if ( state
== wxCHK_UNDETERMINED
&& !Is3State() )
99 wxFAIL_MSG(wxT("Setting a 2-state checkbox to undetermined state"));
100 state
= wxCHK_UNCHECKED
;
103 DoSet3StateValue(state
);
106 bool Is3State() const { return HasFlag(wxCHK_3STATE
); }
108 bool Is3rdStateAllowedForUser() const
110 return HasFlag(wxCHK_ALLOW_3RD_STATE_FOR_USER
);
113 virtual bool HasTransparentBackground() { return true; }
115 // wxCheckBox-specific processing after processing the update event
116 virtual void DoUpdateWindowUI(wxUpdateUIEvent
& event
)
118 wxControl::DoUpdateWindowUI(event
);
120 if ( event
.GetSetChecked() )
121 SetValue(event
.GetChecked());
125 // choose the default border for this window
126 virtual wxBorder
GetDefaultBorder() const { return wxBORDER_NONE
; }
128 virtual void DoSet3StateValue(wxCheckBoxState
WXUNUSED(state
)) { wxFAIL
; }
130 virtual wxCheckBoxState
DoGet3StateValue() const
133 return wxCHK_UNCHECKED
;
136 // Helper function to be called from derived classes Create()
137 // implementations: it checks that the style doesn't contain any
138 // incompatible bits and modifies it to be sane if it does.
139 static void WXValidateStyle(long *stylePtr
)
141 long& style
= *stylePtr
;
145 // For compatibility we use absence of style flags as wxCHK_2STATE
146 // because wxCHK_2STATE used to have the value of 0 and some
147 // existing code may use 0 instead of it.
148 style
= wxCHK_2STATE
;
150 else if ( style
& wxCHK_3STATE
)
152 if ( style
& wxCHK_2STATE
)
154 wxFAIL_MSG( "wxCHK_2STATE and wxCHK_3STATE can't be used "
156 style
&= ~wxCHK_3STATE
;
159 else // No wxCHK_3STATE
161 if ( !(style
& wxCHK_2STATE
) )
163 wxFAIL_MSG( "Either wxCHK_2STATE or wxCHK_3STATE must be "
165 style
|= wxCHK_2STATE
;
168 if ( style
& wxCHK_ALLOW_3RD_STATE_FOR_USER
)
170 wxFAIL_MSG( "wxCHK_ALLOW_3RD_STATE_FOR_USER doesn't make sense "
171 "without wxCHK_3STATE" );
172 style
&= ~wxCHK_ALLOW_3RD_STATE_FOR_USER
;
178 wxDECLARE_NO_COPY_CLASS(wxCheckBoxBase
);
181 // Most ports support 3 state checkboxes so define this by default.
182 #define wxHAS_3STATE_CHECKBOX
184 #if defined(__WXUNIVERSAL__)
185 #include "wx/univ/checkbox.h"
186 #elif defined(__WXMSW__)
187 #include "wx/msw/checkbox.h"
188 #elif defined(__WXMOTIF__)
189 #include "wx/motif/checkbox.h"
190 #elif defined(__WXGTK20__)
191 #include "wx/gtk/checkbox.h"
192 #elif defined(__WXGTK__)
193 #undef wxHAS_3STATE_CHECKBOX
194 #include "wx/gtk1/checkbox.h"
195 #elif defined(__WXMAC__)
196 #include "wx/osx/checkbox.h"
197 #elif defined(__WXCOCOA__)
198 #include "wx/cocoa/checkbox.h"
199 #elif defined(__WXPM__)
200 #undef wxHAS_3STATE_CHECKBOX
201 #include "wx/os2/checkbox.h"
202 #elif defined(__WXPALMOS__)
203 #include "wx/palmos/checkbox.h"
206 #endif // wxUSE_CHECKBOX
208 #endif // _WX_CHECKBOX_H_BASE_