Remove all lines containing cvs/svn "$Id$" keyword.
[wxWidgets.git] / include / wx / checkbox.h
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: wx/checkbox.h
3 // Purpose: wxCheckBox class interface
4 // Author: Vadim Zeitlin
5 // Modified by:
6 // Created: 07.09.00
7 // Copyright: (c) wxWidgets team
8 // Licence: wxWindows licence
9 ///////////////////////////////////////////////////////////////////////////////
10
11 #ifndef _WX_CHECKBOX_H_BASE_
12 #define _WX_CHECKBOX_H_BASE_
13
14 #include "wx/defs.h"
15
16 #if wxUSE_CHECKBOX
17
18 #include "wx/control.h"
19
20
21 /*
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'.
27 *
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
30 * flag is preferred).
31 */
32 #define wxCHK_2STATE 0x4000
33 #define wxCHK_3STATE 0x1000
34
35 /*
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.
40 */
41 #define wxCHK_ALLOW_3RD_STATE_FOR_USER 0x2000
42
43 extern WXDLLIMPEXP_DATA_CORE(const char) wxCheckBoxNameStr[];
44
45 // ----------------------------------------------------------------------------
46 // wxCheckBox: a control which shows a label and a box which may be checked
47 // ----------------------------------------------------------------------------
48
49 class WXDLLIMPEXP_CORE wxCheckBoxBase : public wxControl
50 {
51 public:
52 wxCheckBoxBase() { }
53
54 // set/get the checked status of the listbox
55 virtual void SetValue(bool value) = 0;
56 virtual bool GetValue() const = 0;
57
58 bool IsChecked() const
59 {
60 wxASSERT_MSG( !Is3State(), wxT("Calling IsChecked() doesn't make sense for")
61 wxT(" a three state checkbox, Use Get3StateValue() instead") );
62
63 return GetValue();
64 }
65
66 wxCheckBoxState Get3StateValue() const
67 {
68 wxCheckBoxState state = DoGet3StateValue();
69
70 if ( state == wxCHK_UNDETERMINED && !Is3State() )
71 {
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") );
75
76 state = wxCHK_UNCHECKED;
77 }
78
79 return state;
80 }
81
82 void Set3StateValue(wxCheckBoxState state)
83 {
84 if ( state == wxCHK_UNDETERMINED && !Is3State() )
85 {
86 wxFAIL_MSG(wxT("Setting a 2-state checkbox to undetermined state"));
87 state = wxCHK_UNCHECKED;
88 }
89
90 DoSet3StateValue(state);
91 }
92
93 bool Is3State() const { return HasFlag(wxCHK_3STATE); }
94
95 bool Is3rdStateAllowedForUser() const
96 {
97 return HasFlag(wxCHK_ALLOW_3RD_STATE_FOR_USER);
98 }
99
100 virtual bool HasTransparentBackground() { return true; }
101
102 // wxCheckBox-specific processing after processing the update event
103 virtual void DoUpdateWindowUI(wxUpdateUIEvent& event)
104 {
105 wxControl::DoUpdateWindowUI(event);
106
107 if ( event.GetSetChecked() )
108 SetValue(event.GetChecked());
109 }
110
111 protected:
112 // choose the default border for this window
113 virtual wxBorder GetDefaultBorder() const { return wxBORDER_NONE; }
114
115 virtual void DoSet3StateValue(wxCheckBoxState WXUNUSED(state)) { wxFAIL; }
116
117 virtual wxCheckBoxState DoGet3StateValue() const
118 {
119 wxFAIL;
120 return wxCHK_UNCHECKED;
121 }
122
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)
127 {
128 long& style = *stylePtr;
129
130 if ( !(style & (wxCHK_2STATE | wxCHK_3STATE)) )
131 {
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;
139 }
140
141 if ( style & wxCHK_3STATE )
142 {
143 if ( style & wxCHK_2STATE )
144 {
145 wxFAIL_MSG( "wxCHK_2STATE and wxCHK_3STATE can't be used "
146 "together" );
147 style &= ~wxCHK_3STATE;
148 }
149 }
150 else // No wxCHK_3STATE
151 {
152 if ( style & wxCHK_ALLOW_3RD_STATE_FOR_USER )
153 {
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;
157 }
158 }
159 }
160
161 private:
162 wxDECLARE_NO_COPY_CLASS(wxCheckBoxBase);
163 };
164
165 // Most ports support 3 state checkboxes so define this by default.
166 #define wxHAS_3STATE_CHECKBOX
167
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"
186 #endif
187
188 #endif // wxUSE_CHECKBOX
189
190 #endif // _WX_CHECKBOX_H_BASE_