]> git.saurik.com Git - wxWidgets.git/blame - include/wx/checkbox.h
Make wxGCDC::GetGraphicsContext() const.
[wxWidgets.git] / include / wx / checkbox.h
CommitLineData
1e6feb95
VZ
1///////////////////////////////////////////////////////////////////////////////
2// Name: wx/checkbox.h
3// Purpose: wxCheckBox class interface
4// Author: Vadim Zeitlin
5// Modified by:
6// Created: 07.09.00
7// RCS-ID: $Id$
77ffb593 8// Copyright: (c) wxWidgets team
65571936 9// Licence: wxWindows licence
1e6feb95
VZ
10///////////////////////////////////////////////////////////////////////////////
11
34138703
JS
12#ifndef _WX_CHECKBOX_H_BASE_
13#define _WX_CHECKBOX_H_BASE_
c801d85f 14
997176a3
VZ
15#include "wx/defs.h"
16
1e6feb95
VZ
17#if wxUSE_CHECKBOX
18
19#include "wx/control.h"
20
8941fa88
VZ
21
22/*
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'.
f254e242
VZ
28 *
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
31 * flag is preferred).
8941fa88 32 */
f254e242 33#define wxCHK_2STATE 0x4000
8941fa88
VZ
34#define wxCHK_3STATE 0x1000
35
36/*
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.
41 */
42#define wxCHK_ALLOW_3RD_STATE_FOR_USER 0x2000
43
44/*
45 * The possible states of a 3-state checkbox (Compatible
46 * with the 2-state checkbox).
47 */
48enum wxCheckBoxState
49{
50 wxCHK_UNCHECKED,
51 wxCHK_CHECKED,
52 wxCHK_UNDETERMINED /* 3-state checkbox only */
53};
54
55
53a2db12 56extern WXDLLIMPEXP_DATA_CORE(const char) wxCheckBoxNameStr[];
1e6feb95
VZ
57
58// ----------------------------------------------------------------------------
59// wxCheckBox: a control which shows a label and a box which may be checked
60// ----------------------------------------------------------------------------
61
53a2db12 62class WXDLLIMPEXP_CORE wxCheckBoxBase : public wxControl
1e6feb95
VZ
63{
64public:
6463b9f5 65 wxCheckBoxBase() { }
fc7a2a60 66
1e6feb95 67 // set/get the checked status of the listbox
2b2a5a8c 68 virtual void SetValue(bool value) = 0;
1e6feb95
VZ
69 virtual bool GetValue() const = 0;
70
8941fa88
VZ
71 bool IsChecked() const
72 {
73 wxASSERT_MSG( !Is3State(), wxT("Calling IsChecked() doesn't make sense for")
74 wxT(" a three state checkbox, Use Get3StateValue() instead") );
75
76 return GetValue();
77 }
78
79 wxCheckBoxState Get3StateValue() const
80 {
81 wxCheckBoxState state = DoGet3StateValue();
82
83 if ( state == wxCHK_UNDETERMINED && !Is3State() )
84 {
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") );
88
89 state = wxCHK_UNCHECKED;
90 }
91
92 return state;
93 }
94
95 void Set3StateValue(wxCheckBoxState state)
96 {
97 if ( state == wxCHK_UNDETERMINED && !Is3State() )
98 {
99 wxFAIL_MSG(wxT("Setting a 2-state checkbox to undetermined state"));
100 state = wxCHK_UNCHECKED;
101 }
102
103 DoSet3StateValue(state);
104 }
105
f4992e37 106 bool Is3State() const { return HasFlag(wxCHK_3STATE); }
8941fa88
VZ
107
108 bool Is3rdStateAllowedForUser() const
109 {
f4992e37 110 return HasFlag(wxCHK_ALLOW_3RD_STATE_FOR_USER);
8941fa88
VZ
111 }
112
7c7a653b 113 virtual bool HasTransparentBackground() { return true; }
bd507486 114
a3a4105d
VZ
115 // wxCheckBox-specific processing after processing the update event
116 virtual void DoUpdateWindowUI(wxUpdateUIEvent& event)
117 {
84b2e376
VS
118 wxControl::DoUpdateWindowUI(event);
119
a3a4105d
VZ
120 if ( event.GetSetChecked() )
121 SetValue(event.GetChecked());
122 }
123
8941fa88 124protected:
dc797d8e
JS
125 // choose the default border for this window
126 virtual wxBorder GetDefaultBorder() const { return wxBORDER_NONE; }
127
8941fa88
VZ
128 virtual void DoSet3StateValue(wxCheckBoxState WXUNUSED(state)) { wxFAIL; }
129
130 virtual wxCheckBoxState DoGet3StateValue() const
131 {
132 wxFAIL;
133 return wxCHK_UNCHECKED;
134 }
fc7a2a60 135
f254e242
VZ
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)
140 {
141 long& style = *stylePtr;
142
3a61f5db 143 if ( !(style & (wxCHK_2STATE | wxCHK_3STATE)) )
f254e242
VZ
144 {
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
3a61f5db
VZ
147 // existing code uses 0 instead of it. Moreover, some code even
148 // uses some non-0 style, e.g. wxBORDER_XXX, but doesn't specify
149 // neither wxCHK_2STATE nor wxCHK_3STATE -- to avoid breaking it,
150 // assume (much more common) 2 state checkbox by default.
151 style |= wxCHK_2STATE;
f254e242 152 }
3a61f5db
VZ
153
154 if ( style & wxCHK_3STATE )
f254e242
VZ
155 {
156 if ( style & wxCHK_2STATE )
157 {
158 wxFAIL_MSG( "wxCHK_2STATE and wxCHK_3STATE can't be used "
159 "together" );
160 style &= ~wxCHK_3STATE;
161 }
162 }
163 else // No wxCHK_3STATE
164 {
f254e242
VZ
165 if ( style & wxCHK_ALLOW_3RD_STATE_FOR_USER )
166 {
167 wxFAIL_MSG( "wxCHK_ALLOW_3RD_STATE_FOR_USER doesn't make sense "
168 "without wxCHK_3STATE" );
169 style &= ~wxCHK_ALLOW_3RD_STATE_FOR_USER;
170 }
171 }
172 }
173
fc7a2a60 174private:
c0c133e1 175 wxDECLARE_NO_COPY_CLASS(wxCheckBoxBase);
1e6feb95
VZ
176};
177
817b7b0e
VZ
178// Most ports support 3 state checkboxes so define this by default.
179#define wxHAS_3STATE_CHECKBOX
180
1e6feb95
VZ
181#if defined(__WXUNIVERSAL__)
182 #include "wx/univ/checkbox.h"
183#elif defined(__WXMSW__)
184 #include "wx/msw/checkbox.h"
2049ba38 185#elif defined(__WXMOTIF__)
1e6feb95 186 #include "wx/motif/checkbox.h"
1be7a35c 187#elif defined(__WXGTK20__)
1e6feb95 188 #include "wx/gtk/checkbox.h"
1be7a35c 189#elif defined(__WXGTK__)
817b7b0e 190 #undef wxHAS_3STATE_CHECKBOX
1be7a35c 191 #include "wx/gtk1/checkbox.h"
34138703 192#elif defined(__WXMAC__)
ef0e9220 193 #include "wx/osx/checkbox.h"
e64df9bc
DE
194#elif defined(__WXCOCOA__)
195 #include "wx/cocoa/checkbox.h"
1777b9bb 196#elif defined(__WXPM__)
817b7b0e 197 #undef wxHAS_3STATE_CHECKBOX
1e6feb95 198 #include "wx/os2/checkbox.h"
bdb54365
WS
199#elif defined(__WXPALMOS__)
200 #include "wx/palmos/checkbox.h"
c801d85f
KB
201#endif
202
1e6feb95
VZ
203#endif // wxUSE_CHECKBOX
204
817b7b0e 205#endif // _WX_CHECKBOX_H_BASE_