]>
Commit | Line | Data |
---|---|---|
e53b3d16 | 1 | ///////////////////////////////////////////////////////////////////////////// |
80fdcdb9 | 2 | // Name: src/osx/checkbox_osx.cpp |
e53b3d16 SC |
3 | // Purpose: wxCheckBox |
4 | // Author: Stefan Csomor | |
5 | // Modified by: | |
6 | // Created: 04/01/98 | |
b5b208a1 | 7 | // RCS-ID: $Id$ |
e53b3d16 SC |
8 | // Copyright: (c) Stefan Csomor |
9 | // Licence: wxWindows licence | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | #include "wx/wxprec.h" | |
13 | ||
14 | #if wxUSE_CHECKBOX | |
15 | ||
16 | #include "wx/checkbox.h" | |
17 | #include "wx/osx/private.h" | |
18 | ||
e53b3d16 SC |
19 | IMPLEMENT_DYNAMIC_CLASS(wxBitmapCheckBox, wxCheckBox) |
20 | ||
21 | // Single check box item | |
22 | bool wxCheckBox::Create(wxWindow *parent, | |
23 | wxWindowID id, | |
24 | const wxString& label, | |
25 | const wxPoint& pos, | |
26 | const wxSize& size, | |
27 | long style, | |
28 | const wxValidator& validator, | |
29 | const wxString& name) | |
d15694e8 SC |
30 | { |
31 | DontCreatePeer(); | |
32 | ||
e53b3d16 SC |
33 | if ( !wxCheckBoxBase::Create(parent, id, pos, size, style, validator, name) ) |
34 | return false; | |
35 | ||
36 | m_labelOrig = m_label = label ; | |
37 | ||
f254e242 | 38 | WXValidateStyle( &style ); |
22756322 | 39 | SetPeer(wxWidgetImpl::CreateCheckBox( this, parent, id, label, pos, size, style, GetExtraStyle() )) ; |
e53b3d16 SC |
40 | |
41 | MacPostControlCreate(pos, size) ; | |
42 | ||
43 | return true; | |
44 | } | |
45 | ||
46 | ||
47 | void wxCheckBox::SetValue(bool val) | |
48 | { | |
49 | if (val) | |
50 | Set3StateValue(wxCHK_CHECKED); | |
51 | else | |
52 | Set3StateValue(wxCHK_UNCHECKED); | |
53 | } | |
54 | ||
55 | bool wxCheckBox::GetValue() const | |
56 | { | |
57 | return (DoGet3StateValue() != 0); | |
58 | } | |
59 | ||
60 | void wxCheckBox::Command(wxCommandEvent & event) | |
61 | { | |
62 | int state = event.GetInt(); | |
63 | ||
64 | wxCHECK_RET( (state == wxCHK_UNCHECKED) || (state == wxCHK_CHECKED) | |
65 | || (state == wxCHK_UNDETERMINED), | |
66 | wxT("event.GetInt() returned an invalid checkbox state") ); | |
67 | ||
68 | Set3StateValue((wxCheckBoxState)state); | |
69 | ||
70 | ProcessCommand(event); | |
71 | } | |
72 | ||
73 | wxCheckBoxState wxCheckBox::DoGet3StateValue() const | |
74 | { | |
22756322 | 75 | return (wxCheckBoxState)GetPeer()->GetValue() ; |
e53b3d16 SC |
76 | } |
77 | ||
78 | void wxCheckBox::DoSet3StateValue(wxCheckBoxState val) | |
79 | { | |
22756322 | 80 | GetPeer()->SetValue( val ) ; |
e53b3d16 SC |
81 | } |
82 | ||
03647350 | 83 | bool wxCheckBox::OSXHandleClicked( double WXUNUSED(timestampsec) ) |
e53b3d16 | 84 | { |
524c47aa SC |
85 | bool sendEvent = true; |
86 | wxCheckBoxState newState = Get3StateValue(); | |
03647350 | 87 | |
22756322 | 88 | if ( !GetPeer()->ButtonClickDidStateChange() ) |
e53b3d16 | 89 | { |
524c47aa SC |
90 | wxCheckBoxState origState ; |
91 | ||
361937c7 | 92 | origState = Get3StateValue(); |
524c47aa SC |
93 | |
94 | switch (origState) | |
95 | { | |
96 | case wxCHK_UNCHECKED: | |
97 | newState = wxCHK_CHECKED; | |
98 | break; | |
99 | ||
100 | case wxCHK_CHECKED: | |
101 | // If the style flag to allow the user setting the undetermined state is set, | |
102 | // then set the state to undetermined; otherwise set state to unchecked. | |
103 | newState = Is3rdStateAllowedForUser() ? wxCHK_UNDETERMINED : wxCHK_UNCHECKED; | |
104 | break; | |
105 | ||
106 | case wxCHK_UNDETERMINED: | |
107 | newState = wxCHK_UNCHECKED; | |
108 | break; | |
109 | ||
110 | default: | |
111 | break; | |
112 | } | |
91116a35 | 113 | |
524c47aa SC |
114 | if (newState == origState) |
115 | sendEvent = false; | |
91116a35 SC |
116 | else |
117 | Set3StateValue( newState ); | |
e53b3d16 | 118 | } |
91116a35 SC |
119 | else |
120 | { | |
121 | // in case we cannot avoid this user state change natively (eg cocoa) we intercept it here | |
122 | if ( newState == wxCHK_UNDETERMINED && !Is3rdStateAllowedForUser() ) | |
123 | { | |
124 | newState = wxCHK_CHECKED; | |
125 | Set3StateValue( newState ); | |
126 | } | |
127 | } | |
128 | ||
524c47aa | 129 | if (sendEvent) |
e53b3d16 | 130 | { |
ce7fe42e | 131 | wxCommandEvent event( wxEVT_CHECKBOX, m_windowId ); |
e53b3d16 SC |
132 | event.SetInt( newState ); |
133 | event.SetEventObject( this ); | |
134 | ProcessCommand( event ); | |
135 | } | |
136 | ||
137 | return true; | |
138 | } | |
139 | ||
140 | // Bitmap checkbox | |
141 | bool wxBitmapCheckBox::Create(wxWindow *parent, | |
142 | wxWindowID id, | |
143 | const wxBitmap *WXUNUSED(label), | |
144 | const wxPoint& WXUNUSED(pos), | |
145 | const wxSize& WXUNUSED(size), | |
146 | long style, | |
147 | const wxValidator& wxVALIDATOR_PARAM(validator), | |
148 | const wxString& name) | |
149 | { | |
150 | SetName(name); | |
151 | #if wxUSE_VALIDATORS | |
152 | SetValidator(validator); | |
153 | #endif | |
154 | m_windowStyle = style; | |
155 | ||
156 | if (parent) | |
157 | parent->AddChild(this); | |
158 | ||
159 | if ( id == -1 ) | |
160 | m_windowId = NewControlId(); | |
161 | else | |
162 | m_windowId = id; | |
163 | ||
164 | // TODO: Create the bitmap checkbox | |
165 | ||
166 | return false; | |
167 | } | |
168 | ||
169 | void wxBitmapCheckBox::SetLabel(const wxBitmap *WXUNUSED(bitmap)) | |
170 | { | |
171 | // TODO | |
172 | wxFAIL_MSG(wxT("wxBitmapCheckBox::SetLabel() not yet implemented")); | |
173 | } | |
174 | ||
175 | void wxBitmapCheckBox::SetSize(int x, int y, int width, int height, int sizeFlags) | |
176 | { | |
177 | wxControl::SetSize( x , y , width , height , sizeFlags ) ; | |
178 | } | |
179 | ||
180 | void wxBitmapCheckBox::SetValue(bool WXUNUSED(val)) | |
181 | { | |
182 | // TODO | |
183 | wxFAIL_MSG(wxT("wxBitmapCheckBox::SetValue() not yet implemented")); | |
184 | } | |
185 | ||
186 | bool wxBitmapCheckBox::GetValue() const | |
187 | { | |
188 | // TODO | |
189 | wxFAIL_MSG(wxT("wxBitmapCheckBox::GetValue() not yet implemented")); | |
190 | ||
191 | return false; | |
192 | } | |
193 | ||
194 | #endif |