]>
Commit | Line | Data |
---|---|---|
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'. | |
28 | */ | |
29 | #define wxCHK_2STATE 0x0000 | |
30 | #define wxCHK_3STATE 0x1000 | |
31 | ||
32 | /* | |
33 | * If this style is set the user can set the checkbox to the | |
34 | * undetermined state. If not set the undetermined set can only | |
35 | * be set programmatically. | |
36 | * This style can only be used with 3 state checkboxes. | |
37 | */ | |
38 | #define wxCHK_ALLOW_3RD_STATE_FOR_USER 0x2000 | |
39 | ||
40 | /* | |
41 | * The possible states of a 3-state checkbox (Compatible | |
42 | * with the 2-state checkbox). | |
43 | */ | |
44 | enum wxCheckBoxState | |
45 | { | |
46 | wxCHK_UNCHECKED, | |
47 | wxCHK_CHECKED, | |
48 | wxCHK_UNDETERMINED /* 3-state checkbox only */ | |
49 | }; | |
50 | ||
51 | ||
63ec432b | 52 | extern WXDLLEXPORT_DATA(const wxChar) wxCheckBoxNameStr[]; |
1e6feb95 VZ |
53 | |
54 | // ---------------------------------------------------------------------------- | |
55 | // wxCheckBox: a control which shows a label and a box which may be checked | |
56 | // ---------------------------------------------------------------------------- | |
57 | ||
58 | class WXDLLEXPORT wxCheckBoxBase : public wxControl | |
59 | { | |
60 | public: | |
6463b9f5 | 61 | wxCheckBoxBase() { } |
fc7a2a60 | 62 | |
1e6feb95 | 63 | // set/get the checked status of the listbox |
2b2a5a8c | 64 | virtual void SetValue(bool value) = 0; |
1e6feb95 VZ |
65 | virtual bool GetValue() const = 0; |
66 | ||
8941fa88 VZ |
67 | bool IsChecked() const |
68 | { | |
69 | wxASSERT_MSG( !Is3State(), wxT("Calling IsChecked() doesn't make sense for") | |
70 | wxT(" a three state checkbox, Use Get3StateValue() instead") ); | |
71 | ||
72 | return GetValue(); | |
73 | } | |
74 | ||
75 | wxCheckBoxState Get3StateValue() const | |
76 | { | |
77 | wxCheckBoxState state = DoGet3StateValue(); | |
78 | ||
79 | if ( state == wxCHK_UNDETERMINED && !Is3State() ) | |
80 | { | |
81 | // Undetermined state with a 2-state checkbox?? | |
82 | wxFAIL_MSG( wxT("DoGet3StateValue() says the 2-state checkbox is ") | |
83 | wxT("in an undetermined/third state") ); | |
84 | ||
85 | state = wxCHK_UNCHECKED; | |
86 | } | |
87 | ||
88 | return state; | |
89 | } | |
90 | ||
91 | void Set3StateValue(wxCheckBoxState state) | |
92 | { | |
93 | if ( state == wxCHK_UNDETERMINED && !Is3State() ) | |
94 | { | |
95 | wxFAIL_MSG(wxT("Setting a 2-state checkbox to undetermined state")); | |
96 | state = wxCHK_UNCHECKED; | |
97 | } | |
98 | ||
99 | DoSet3StateValue(state); | |
100 | } | |
101 | ||
f4992e37 | 102 | bool Is3State() const { return HasFlag(wxCHK_3STATE); } |
8941fa88 VZ |
103 | |
104 | bool Is3rdStateAllowedForUser() const | |
105 | { | |
f4992e37 | 106 | return HasFlag(wxCHK_ALLOW_3RD_STATE_FOR_USER); |
8941fa88 VZ |
107 | } |
108 | ||
7c7a653b | 109 | virtual bool HasTransparentBackground() { return true; } |
bd507486 | 110 | |
a3a4105d VZ |
111 | // wxCheckBox-specific processing after processing the update event |
112 | virtual void DoUpdateWindowUI(wxUpdateUIEvent& event) | |
113 | { | |
114 | if ( event.GetSetChecked() ) | |
115 | SetValue(event.GetChecked()); | |
116 | } | |
117 | ||
8941fa88 | 118 | protected: |
8941fa88 VZ |
119 | virtual void DoSet3StateValue(wxCheckBoxState WXUNUSED(state)) { wxFAIL; } |
120 | ||
121 | virtual wxCheckBoxState DoGet3StateValue() const | |
122 | { | |
123 | wxFAIL; | |
124 | return wxCHK_UNCHECKED; | |
125 | } | |
fc7a2a60 VZ |
126 | |
127 | private: | |
128 | DECLARE_NO_COPY_CLASS(wxCheckBoxBase) | |
1e6feb95 VZ |
129 | }; |
130 | ||
131 | #if defined(__WXUNIVERSAL__) | |
132 | #include "wx/univ/checkbox.h" | |
133 | #elif defined(__WXMSW__) | |
134 | #include "wx/msw/checkbox.h" | |
2049ba38 | 135 | #elif defined(__WXMOTIF__) |
1e6feb95 | 136 | #include "wx/motif/checkbox.h" |
1be7a35c | 137 | #elif defined(__WXGTK20__) |
1e6feb95 | 138 | #include "wx/gtk/checkbox.h" |
1be7a35c MR |
139 | #elif defined(__WXGTK__) |
140 | #include "wx/gtk1/checkbox.h" | |
34138703 | 141 | #elif defined(__WXMAC__) |
1e6feb95 | 142 | #include "wx/mac/checkbox.h" |
e64df9bc DE |
143 | #elif defined(__WXCOCOA__) |
144 | #include "wx/cocoa/checkbox.h" | |
1777b9bb | 145 | #elif defined(__WXPM__) |
1e6feb95 | 146 | #include "wx/os2/checkbox.h" |
bdb54365 WS |
147 | #elif defined(__WXPALMOS__) |
148 | #include "wx/palmos/checkbox.h" | |
c801d85f KB |
149 | #endif |
150 | ||
1e6feb95 VZ |
151 | #endif // wxUSE_CHECKBOX |
152 | ||
c801d85f | 153 | #endif |
34138703 | 154 | // _WX_CHECKBOX_H_BASE_ |