]> git.saurik.com Git - wxWidgets.git/blame - include/wx/checkbox.h
Applied #15226 wxRichTextCtrl: Implement setting properties with undo for objects...
[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
77ffb593 7// Copyright: (c) wxWidgets team
65571936 8// Licence: wxWindows licence
1e6feb95
VZ
9///////////////////////////////////////////////////////////////////////////////
10
34138703
JS
11#ifndef _WX_CHECKBOX_H_BASE_
12#define _WX_CHECKBOX_H_BASE_
c801d85f 13
997176a3
VZ
14#include "wx/defs.h"
15
1e6feb95
VZ
16#if wxUSE_CHECKBOX
17
18#include "wx/control.h"
19
8941fa88
VZ
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'.
f254e242
VZ
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).
8941fa88 31 */
f254e242 32#define wxCHK_2STATE 0x4000
8941fa88
VZ
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
53a2db12 43extern WXDLLIMPEXP_DATA_CORE(const char) wxCheckBoxNameStr[];
1e6feb95
VZ
44
45// ----------------------------------------------------------------------------
46// wxCheckBox: a control which shows a label and a box which may be checked
47// ----------------------------------------------------------------------------
48
53a2db12 49class WXDLLIMPEXP_CORE wxCheckBoxBase : public wxControl
1e6feb95
VZ
50{
51public:
6463b9f5 52 wxCheckBoxBase() { }
fc7a2a60 53
1e6feb95 54 // set/get the checked status of the listbox
2b2a5a8c 55 virtual void SetValue(bool value) = 0;
1e6feb95
VZ
56 virtual bool GetValue() const = 0;
57
8941fa88
VZ
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
f4992e37 93 bool Is3State() const { return HasFlag(wxCHK_3STATE); }
8941fa88
VZ
94
95 bool Is3rdStateAllowedForUser() const
96 {
f4992e37 97 return HasFlag(wxCHK_ALLOW_3RD_STATE_FOR_USER);
8941fa88
VZ
98 }
99
7c7a653b 100 virtual bool HasTransparentBackground() { return true; }
bd507486 101
a3a4105d
VZ
102 // wxCheckBox-specific processing after processing the update event
103 virtual void DoUpdateWindowUI(wxUpdateUIEvent& event)
104 {
84b2e376
VS
105 wxControl::DoUpdateWindowUI(event);
106
a3a4105d
VZ
107 if ( event.GetSetChecked() )
108 SetValue(event.GetChecked());
109 }
110
8941fa88 111protected:
dc797d8e
JS
112 // choose the default border for this window
113 virtual wxBorder GetDefaultBorder() const { return wxBORDER_NONE; }
114
8941fa88
VZ
115 virtual void DoSet3StateValue(wxCheckBoxState WXUNUSED(state)) { wxFAIL; }
116
117 virtual wxCheckBoxState DoGet3StateValue() const
118 {
119 wxFAIL;
120 return wxCHK_UNCHECKED;
121 }
fc7a2a60 122
f254e242
VZ
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
3a61f5db 130 if ( !(style & (wxCHK_2STATE | wxCHK_3STATE)) )
f254e242
VZ
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
3a61f5db
VZ
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;
f254e242 139 }
3a61f5db
VZ
140
141 if ( style & wxCHK_3STATE )
f254e242
VZ
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 {
f254e242
VZ
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
fc7a2a60 161private:
c0c133e1 162 wxDECLARE_NO_COPY_CLASS(wxCheckBoxBase);
1e6feb95
VZ
163};
164
817b7b0e
VZ
165// Most ports support 3 state checkboxes so define this by default.
166#define wxHAS_3STATE_CHECKBOX
167
1e6feb95
VZ
168#if defined(__WXUNIVERSAL__)
169 #include "wx/univ/checkbox.h"
170#elif defined(__WXMSW__)
171 #include "wx/msw/checkbox.h"
2049ba38 172#elif defined(__WXMOTIF__)
1e6feb95 173 #include "wx/motif/checkbox.h"
1be7a35c 174#elif defined(__WXGTK20__)
1e6feb95 175 #include "wx/gtk/checkbox.h"
1be7a35c 176#elif defined(__WXGTK__)
817b7b0e 177 #undef wxHAS_3STATE_CHECKBOX
1be7a35c 178 #include "wx/gtk1/checkbox.h"
34138703 179#elif defined(__WXMAC__)
ef0e9220 180 #include "wx/osx/checkbox.h"
e64df9bc
DE
181#elif defined(__WXCOCOA__)
182 #include "wx/cocoa/checkbox.h"
1777b9bb 183#elif defined(__WXPM__)
817b7b0e 184 #undef wxHAS_3STATE_CHECKBOX
1e6feb95 185 #include "wx/os2/checkbox.h"
c801d85f
KB
186#endif
187
1e6feb95
VZ
188#endif // wxUSE_CHECKBOX
189
817b7b0e 190#endif // _WX_CHECKBOX_H_BASE_