]> git.saurik.com Git - wxWidgets.git/blame - include/wx/checkbox.h
Fix wrong tab order in wxAuiNotebook after dragging.
[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
53a2db12 44extern WXDLLIMPEXP_DATA_CORE(const char) wxCheckBoxNameStr[];
1e6feb95
VZ
45
46// ----------------------------------------------------------------------------
47// wxCheckBox: a control which shows a label and a box which may be checked
48// ----------------------------------------------------------------------------
49
53a2db12 50class WXDLLIMPEXP_CORE wxCheckBoxBase : public wxControl
1e6feb95
VZ
51{
52public:
6463b9f5 53 wxCheckBoxBase() { }
fc7a2a60 54
1e6feb95 55 // set/get the checked status of the listbox
2b2a5a8c 56 virtual void SetValue(bool value) = 0;
1e6feb95
VZ
57 virtual bool GetValue() const = 0;
58
8941fa88
VZ
59 bool IsChecked() const
60 {
61 wxASSERT_MSG( !Is3State(), wxT("Calling IsChecked() doesn't make sense for")
62 wxT(" a three state checkbox, Use Get3StateValue() instead") );
63
64 return GetValue();
65 }
66
67 wxCheckBoxState Get3StateValue() const
68 {
69 wxCheckBoxState state = DoGet3StateValue();
70
71 if ( state == wxCHK_UNDETERMINED && !Is3State() )
72 {
73 // Undetermined state with a 2-state checkbox??
74 wxFAIL_MSG( wxT("DoGet3StateValue() says the 2-state checkbox is ")
75 wxT("in an undetermined/third state") );
76
77 state = wxCHK_UNCHECKED;
78 }
79
80 return state;
81 }
82
83 void Set3StateValue(wxCheckBoxState state)
84 {
85 if ( state == wxCHK_UNDETERMINED && !Is3State() )
86 {
87 wxFAIL_MSG(wxT("Setting a 2-state checkbox to undetermined state"));
88 state = wxCHK_UNCHECKED;
89 }
90
91 DoSet3StateValue(state);
92 }
93
f4992e37 94 bool Is3State() const { return HasFlag(wxCHK_3STATE); }
8941fa88
VZ
95
96 bool Is3rdStateAllowedForUser() const
97 {
f4992e37 98 return HasFlag(wxCHK_ALLOW_3RD_STATE_FOR_USER);
8941fa88
VZ
99 }
100
7c7a653b 101 virtual bool HasTransparentBackground() { return true; }
bd507486 102
a3a4105d
VZ
103 // wxCheckBox-specific processing after processing the update event
104 virtual void DoUpdateWindowUI(wxUpdateUIEvent& event)
105 {
84b2e376
VS
106 wxControl::DoUpdateWindowUI(event);
107
a3a4105d
VZ
108 if ( event.GetSetChecked() )
109 SetValue(event.GetChecked());
110 }
111
8941fa88 112protected:
dc797d8e
JS
113 // choose the default border for this window
114 virtual wxBorder GetDefaultBorder() const { return wxBORDER_NONE; }
115
8941fa88
VZ
116 virtual void DoSet3StateValue(wxCheckBoxState WXUNUSED(state)) { wxFAIL; }
117
118 virtual wxCheckBoxState DoGet3StateValue() const
119 {
120 wxFAIL;
121 return wxCHK_UNCHECKED;
122 }
fc7a2a60 123
f254e242
VZ
124 // Helper function to be called from derived classes Create()
125 // implementations: it checks that the style doesn't contain any
126 // incompatible bits and modifies it to be sane if it does.
127 static void WXValidateStyle(long *stylePtr)
128 {
129 long& style = *stylePtr;
130
3a61f5db 131 if ( !(style & (wxCHK_2STATE | wxCHK_3STATE)) )
f254e242
VZ
132 {
133 // For compatibility we use absence of style flags as wxCHK_2STATE
134 // because wxCHK_2STATE used to have the value of 0 and some
3a61f5db
VZ
135 // existing code uses 0 instead of it. Moreover, some code even
136 // uses some non-0 style, e.g. wxBORDER_XXX, but doesn't specify
137 // neither wxCHK_2STATE nor wxCHK_3STATE -- to avoid breaking it,
138 // assume (much more common) 2 state checkbox by default.
139 style |= wxCHK_2STATE;
f254e242 140 }
3a61f5db
VZ
141
142 if ( style & wxCHK_3STATE )
f254e242
VZ
143 {
144 if ( style & wxCHK_2STATE )
145 {
146 wxFAIL_MSG( "wxCHK_2STATE and wxCHK_3STATE can't be used "
147 "together" );
148 style &= ~wxCHK_3STATE;
149 }
150 }
151 else // No wxCHK_3STATE
152 {
f254e242
VZ
153 if ( style & wxCHK_ALLOW_3RD_STATE_FOR_USER )
154 {
155 wxFAIL_MSG( "wxCHK_ALLOW_3RD_STATE_FOR_USER doesn't make sense "
156 "without wxCHK_3STATE" );
157 style &= ~wxCHK_ALLOW_3RD_STATE_FOR_USER;
158 }
159 }
160 }
161
fc7a2a60 162private:
c0c133e1 163 wxDECLARE_NO_COPY_CLASS(wxCheckBoxBase);
1e6feb95
VZ
164};
165
817b7b0e
VZ
166// Most ports support 3 state checkboxes so define this by default.
167#define wxHAS_3STATE_CHECKBOX
168
1e6feb95
VZ
169#if defined(__WXUNIVERSAL__)
170 #include "wx/univ/checkbox.h"
171#elif defined(__WXMSW__)
172 #include "wx/msw/checkbox.h"
2049ba38 173#elif defined(__WXMOTIF__)
1e6feb95 174 #include "wx/motif/checkbox.h"
1be7a35c 175#elif defined(__WXGTK20__)
1e6feb95 176 #include "wx/gtk/checkbox.h"
1be7a35c 177#elif defined(__WXGTK__)
817b7b0e 178 #undef wxHAS_3STATE_CHECKBOX
1be7a35c 179 #include "wx/gtk1/checkbox.h"
34138703 180#elif defined(__WXMAC__)
ef0e9220 181 #include "wx/osx/checkbox.h"
e64df9bc
DE
182#elif defined(__WXCOCOA__)
183 #include "wx/cocoa/checkbox.h"
1777b9bb 184#elif defined(__WXPM__)
817b7b0e 185 #undef wxHAS_3STATE_CHECKBOX
1e6feb95 186 #include "wx/os2/checkbox.h"
c801d85f
KB
187#endif
188
1e6feb95
VZ
189#endif // wxUSE_CHECKBOX
190
817b7b0e 191#endif // _WX_CHECKBOX_H_BASE_