]> git.saurik.com Git - wxWidgets.git/blob - src/osx/checkbox_osx.cpp
Fixed wxRichTextCtrl caret test case
[wxWidgets.git] / src / osx / checkbox_osx.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/checkbox_osx.cpp
3 // Purpose: wxCheckBox
4 // Author: Stefan Csomor
5 // Modified by:
6 // Created: 04/01/98
7 // RCS-ID: $Id$
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
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)
30 {
31 DontCreatePeer();
32
33 if ( !wxCheckBoxBase::Create(parent, id, pos, size, style, validator, name) )
34 return false;
35
36 m_labelOrig = m_label = label ;
37
38 WXValidateStyle( &style );
39 SetPeer(wxWidgetImpl::CreateCheckBox( this, parent, id, label, pos, size, style, GetExtraStyle() )) ;
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 {
75 return (wxCheckBoxState)GetPeer()->GetValue() ;
76 }
77
78 void wxCheckBox::DoSet3StateValue(wxCheckBoxState val)
79 {
80 GetPeer()->SetValue( val ) ;
81 }
82
83 bool wxCheckBox::OSXHandleClicked( double WXUNUSED(timestampsec) )
84 {
85 bool sendEvent = true;
86 wxCheckBoxState newState = Get3StateValue();
87
88 if ( !GetPeer()->ButtonClickDidStateChange() )
89 {
90 wxCheckBoxState origState ;
91
92 origState = Get3StateValue();
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 }
113
114 if (newState == origState)
115 sendEvent = false;
116 else
117 Set3StateValue( newState );
118 }
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
129 if (sendEvent)
130 {
131 wxCommandEvent event( wxEVT_COMMAND_CHECKBOX_CLICKED, m_windowId );
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