]>
Commit | Line | Data |
---|---|---|
e9576ca5 SC |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: checkbox.cpp | |
3 | // Purpose: wxCheckBox | |
a31a5f85 | 4 | // Author: Stefan Csomor |
e9576ca5 SC |
5 | // Modified by: |
6 | // Created: 04/01/98 | |
7 | // RCS-ID: $Id$ | |
a31a5f85 | 8 | // Copyright: (c) Stefan Csomor |
e40298d5 | 9 | // Licence: wxWindows licence |
e9576ca5 SC |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
12 | #ifdef __GNUG__ | |
13 | #pragma implementation "checkbox.h" | |
14 | #endif | |
15 | ||
d8c736e5 GD |
16 | #include "wx/defs.h" |
17 | ||
e9576ca5 SC |
18 | #include "wx/checkbox.h" |
19 | ||
2f1ae414 | 20 | #if !USE_SHARED_LIBRARY |
e9576ca5 SC |
21 | IMPLEMENT_DYNAMIC_CLASS(wxCheckBox, wxControl) |
22 | IMPLEMENT_DYNAMIC_CLASS(wxBitmapCheckBox, wxCheckBox) | |
2f1ae414 | 23 | #endif |
e9576ca5 | 24 | |
d497dca4 | 25 | #include "wx/mac/uma.h" |
519cb848 | 26 | |
1169a919 JS |
27 | wxCheckBoxBase::wxCheckBoxBase() |
28 | { | |
29 | } | |
30 | ||
e9576ca5 SC |
31 | // Single check box item |
32 | bool wxCheckBox::Create(wxWindow *parent, wxWindowID id, const wxString& label, | |
33 | const wxPoint& pos, | |
34 | const wxSize& size, long style, | |
35 | const wxValidator& validator, | |
36 | const wxString& name) | |
37 | { | |
b45ed7a2 VZ |
38 | if ( !wxCheckBoxBase::Create(parent, id, pos, size, style, validator, name) ) |
39 | return false; | |
40 | ||
e40298d5 JS |
41 | Rect bounds ; |
42 | Str255 title ; | |
43 | ||
44 | MacPreControlCreate( parent , id , label , pos , size ,style, validator , name , &bounds , title ) ; | |
e9576ca5 | 45 | |
8941fa88 | 46 | SInt16 maxValue = 1 /* kControlCheckboxCheckedValue */; |
9c9ceb48 | 47 | if (style & wxCHK_3STATE) |
8941fa88 VZ |
48 | { |
49 | maxValue = 2 /* kControlCheckboxMixedValue */; | |
50 | } | |
51 | ||
52 | m_macControl = ::NewControl( MAC_WXHWND(parent->MacGetRootWindow()) , &bounds , title , false , 0 , 0 , maxValue, | |
e40298d5 JS |
53 | kControlCheckBoxProc , (long) this ) ; |
54 | ||
55 | MacPostControlCreate() ; | |
e9576ca5 | 56 | |
519cb848 | 57 | return TRUE; |
e9576ca5 SC |
58 | } |
59 | ||
60 | void wxCheckBox::SetValue(bool val) | |
61 | { | |
8941fa88 VZ |
62 | if (val) |
63 | { | |
64 | Set3StateValue(wxCHK_CHECKED); | |
65 | } | |
66 | else | |
67 | { | |
68 | Set3StateValue(wxCHK_UNCHECKED); | |
69 | } | |
e9576ca5 SC |
70 | } |
71 | ||
72 | bool wxCheckBox::GetValue() const | |
73 | { | |
8941fa88 | 74 | return (DoGet3StateValue() != 0); |
e9576ca5 SC |
75 | } |
76 | ||
77 | void wxCheckBox::Command (wxCommandEvent & event) | |
78 | { | |
8941fa88 VZ |
79 | int state = event.GetInt(); |
80 | ||
81 | wxCHECK_RET( (state == wxCHK_UNCHECKED) || (state == wxCHK_CHECKED) | |
82 | || (state == wxCHK_UNDETERMINED), | |
83 | wxT("event.GetInt() returned an invalid checkbox state") ); | |
84 | ||
85 | Set3StateValue((wxCheckBoxState) state); | |
86 | ||
87 | ProcessCommand(event); | |
88 | } | |
89 | ||
90 | wxCheckBoxState wxCheckBox::DoGet3StateValue() const | |
91 | { | |
92 | return (wxCheckBoxState) ::GetControl32BitValue( (ControlHandle) m_macControl ); | |
93 | } | |
94 | ||
95 | void wxCheckBox::DoSet3StateValue(wxCheckBoxState val) | |
96 | { | |
97 | ::SetControl32BitValue( (ControlHandle) m_macControl , (int) val) ; | |
98 | MacRedrawControl() ; | |
e9576ca5 SC |
99 | } |
100 | ||
4b26b60f | 101 | void wxCheckBox::MacHandleControlClick( WXWidget WXUNUSED(control), wxInt16 WXUNUSED(controlpart) , bool WXUNUSED(mouseStillDown) ) |
519cb848 | 102 | { |
8208e181 | 103 | wxCommandEvent event(wxEVT_COMMAND_CHECKBOX_CLICKED, m_windowId ); |
8941fa88 VZ |
104 | wxCheckBoxState state = Get3StateValue(); |
105 | ||
106 | if (state == wxCHK_UNCHECKED) | |
107 | { | |
108 | state = wxCHK_CHECKED; | |
109 | } | |
110 | else if (state == wxCHK_CHECKED) | |
111 | { | |
112 | // If the style flag to allow the user setting the undetermined state | |
113 | // is set, then set the state to undetermined. Otherwise set state to | |
114 | // unchecked. | |
115 | if ( Is3rdStateAllowedForUser() ) | |
116 | { | |
117 | state = wxCHK_UNDETERMINED; | |
118 | } | |
119 | else | |
120 | { | |
121 | state = wxCHK_UNCHECKED; | |
122 | } | |
123 | } | |
124 | else if (state == wxCHK_UNDETERMINED) | |
125 | { | |
126 | state = wxCHK_UNCHECKED; | |
127 | } | |
128 | Set3StateValue(state); | |
129 | ||
130 | event.SetInt(state); | |
8208e181 SC |
131 | event.SetEventObject(this); |
132 | ProcessCommand(event); | |
519cb848 SC |
133 | } |
134 | ||
e9576ca5 | 135 | // Bitmap checkbox |
f2af4afb GD |
136 | bool wxBitmapCheckBox::Create(wxWindow *parent, wxWindowID id, |
137 | const wxBitmap *label, | |
138 | const wxPoint& pos, | |
139 | const wxSize& size, long style, | |
140 | const wxValidator& validator, | |
141 | const wxString& name) | |
e9576ca5 SC |
142 | { |
143 | SetName(name); | |
144 | SetValidator(validator); | |
145 | m_windowStyle = style; | |
146 | ||
147 | if (parent) parent->AddChild(this); | |
148 | ||
149 | if ( id == -1 ) | |
150 | m_windowId = NewControlId(); | |
151 | else | |
152 | m_windowId = id; | |
153 | ||
154 | // TODO: Create the bitmap checkbox | |
155 | ||
156 | return FALSE; | |
157 | } | |
158 | ||
159 | void wxBitmapCheckBox::SetLabel(const wxBitmap *bitmap) | |
160 | { | |
161 | // TODO | |
0c32c930 | 162 | wxFAIL_MSG(wxT("wxBitmapCheckBox::SetLabel() not yet implemented")); |
e9576ca5 SC |
163 | } |
164 | ||
165 | void wxBitmapCheckBox::SetSize(int x, int y, int width, int height, int sizeFlags) | |
166 | { | |
519cb848 | 167 | wxControl::SetSize( x , y , width , height , sizeFlags ) ; |
e9576ca5 SC |
168 | } |
169 | ||
170 | void wxBitmapCheckBox::SetValue(bool val) | |
171 | { | |
172 | // TODO | |
0c32c930 | 173 | wxFAIL_MSG(wxT("wxBitmapCheckBox::SetValue() not yet implemented")); |
e9576ca5 SC |
174 | } |
175 | ||
176 | bool wxBitmapCheckBox::GetValue() const | |
177 | { | |
0c32c930 GD |
178 | // TODO |
179 | wxFAIL_MSG(wxT("wxBitmapCheckBox::GetValue() not yet implemented")); | |
e9576ca5 SC |
180 | return FALSE; |
181 | } | |
182 | ||
183 |