1 ///////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxCheckBox class interface
4 // Author: Vadim Zeitlin
7 // Copyright: (c) wxWidgets team
8 // Licence: wxWindows licence
9 ///////////////////////////////////////////////////////////////////////////////
11 #ifndef _WX_CHECKBOX_H_BASE_
12 #define _WX_CHECKBOX_H_BASE_
18 #include "wx/control.h"
22 * wxCheckBox style flags
23 * (Using wxCHK_* because wxCB_* is used by wxComboBox).
24 * Determine whether to use a 3-state or 2-state
25 * checkbox. 3-state enables to differentiate
26 * between 'unchecked', 'checked' and 'undetermined'.
28 * In addition to the styles here it is also possible to specify just 0 which
29 * is treated the same as wxCHK_2STATE for compatibility (but using explicit
32 #define wxCHK_2STATE 0x4000
33 #define wxCHK_3STATE 0x1000
36 * If this style is set the user can set the checkbox to the
37 * undetermined state. If not set the undetermined set can only
38 * be set programmatically.
39 * This style can only be used with 3 state checkboxes.
41 #define wxCHK_ALLOW_3RD_STATE_FOR_USER 0x2000
43 extern WXDLLIMPEXP_DATA_CORE(const char) wxCheckBoxNameStr
[];
45 // ----------------------------------------------------------------------------
46 // wxCheckBox: a control which shows a label and a box which may be checked
47 // ----------------------------------------------------------------------------
49 class WXDLLIMPEXP_CORE wxCheckBoxBase
: public wxControl
54 // set/get the checked status of the listbox
55 virtual void SetValue(bool value
) = 0;
56 virtual bool GetValue() const = 0;
58 bool IsChecked() const
60 wxASSERT_MSG( !Is3State(), wxT("Calling IsChecked() doesn't make sense for")
61 wxT(" a three state checkbox, Use Get3StateValue() instead") );
66 wxCheckBoxState
Get3StateValue() const
68 wxCheckBoxState state
= DoGet3StateValue();
70 if ( state
== wxCHK_UNDETERMINED
&& !Is3State() )
72 // Undetermined state with a 2-state checkbox??
73 wxFAIL_MSG( wxT("DoGet3StateValue() says the 2-state checkbox is ")
74 wxT("in an undetermined/third state") );
76 state
= wxCHK_UNCHECKED
;
82 void Set3StateValue(wxCheckBoxState state
)
84 if ( state
== wxCHK_UNDETERMINED
&& !Is3State() )
86 wxFAIL_MSG(wxT("Setting a 2-state checkbox to undetermined state"));
87 state
= wxCHK_UNCHECKED
;
90 DoSet3StateValue(state
);
93 bool Is3State() const { return HasFlag(wxCHK_3STATE
); }
95 bool Is3rdStateAllowedForUser() const
97 return HasFlag(wxCHK_ALLOW_3RD_STATE_FOR_USER
);
100 virtual bool HasTransparentBackground() { return true; }
102 // wxCheckBox-specific processing after processing the update event
103 virtual void DoUpdateWindowUI(wxUpdateUIEvent
& event
)
105 wxControl::DoUpdateWindowUI(event
);
107 if ( event
.GetSetChecked() )
108 SetValue(event
.GetChecked());
112 // choose the default border for this window
113 virtual wxBorder
GetDefaultBorder() const { return wxBORDER_NONE
; }
115 virtual void DoSet3StateValue(wxCheckBoxState
WXUNUSED(state
)) { wxFAIL
; }
117 virtual wxCheckBoxState
DoGet3StateValue() const
120 return wxCHK_UNCHECKED
;
123 // Helper function to be called from derived classes Create()
124 // implementations: it checks that the style doesn't contain any
125 // incompatible bits and modifies it to be sane if it does.
126 static void WXValidateStyle(long *stylePtr
)
128 long& style
= *stylePtr
;
130 if ( !(style
& (wxCHK_2STATE
| wxCHK_3STATE
)) )
132 // For compatibility we use absence of style flags as wxCHK_2STATE
133 // because wxCHK_2STATE used to have the value of 0 and some
134 // existing code uses 0 instead of it. Moreover, some code even
135 // uses some non-0 style, e.g. wxBORDER_XXX, but doesn't specify
136 // neither wxCHK_2STATE nor wxCHK_3STATE -- to avoid breaking it,
137 // assume (much more common) 2 state checkbox by default.
138 style
|= wxCHK_2STATE
;
141 if ( style
& wxCHK_3STATE
)
143 if ( style
& wxCHK_2STATE
)
145 wxFAIL_MSG( "wxCHK_2STATE and wxCHK_3STATE can't be used "
147 style
&= ~wxCHK_3STATE
;
150 else // No wxCHK_3STATE
152 if ( style
& wxCHK_ALLOW_3RD_STATE_FOR_USER
)
154 wxFAIL_MSG( "wxCHK_ALLOW_3RD_STATE_FOR_USER doesn't make sense "
155 "without wxCHK_3STATE" );
156 style
&= ~wxCHK_ALLOW_3RD_STATE_FOR_USER
;
162 wxDECLARE_NO_COPY_CLASS(wxCheckBoxBase
);
165 // Most ports support 3 state checkboxes so define this by default.
166 #define wxHAS_3STATE_CHECKBOX
168 #if defined(__WXUNIVERSAL__)
169 #include "wx/univ/checkbox.h"
170 #elif defined(__WXMSW__)
171 #include "wx/msw/checkbox.h"
172 #elif defined(__WXMOTIF__)
173 #include "wx/motif/checkbox.h"
174 #elif defined(__WXGTK20__)
175 #include "wx/gtk/checkbox.h"
176 #elif defined(__WXGTK__)
177 #undef wxHAS_3STATE_CHECKBOX
178 #include "wx/gtk1/checkbox.h"
179 #elif defined(__WXMAC__)
180 #include "wx/osx/checkbox.h"
181 #elif defined(__WXCOCOA__)
182 #include "wx/cocoa/checkbox.h"
183 #elif defined(__WXPM__)
184 #undef wxHAS_3STATE_CHECKBOX
185 #include "wx/os2/checkbox.h"
188 #endif // wxUSE_CHECKBOX
190 #endif // _WX_CHECKBOX_H_BASE_