]> git.saurik.com Git - wxWidgets.git/blob - src/osx/checkbox_osx.cpp
fixing selectors
[wxWidgets.git] / src / osx / checkbox_osx.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/carbon/checkbox.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(wxCheckBox, wxControl)
20 IMPLEMENT_DYNAMIC_CLASS(wxBitmapCheckBox, wxCheckBox)
21
22 // Single check box item
23 bool wxCheckBox::Create(wxWindow *parent,
24 wxWindowID id,
25 const wxString& label,
26 const wxPoint& pos,
27 const wxSize& size,
28 long style,
29 const wxValidator& validator,
30 const wxString& name)
31 {
32 m_macIsUserPane = false ;
33
34 if ( !wxCheckBoxBase::Create(parent, id, pos, size, style, validator, name) )
35 return false;
36
37 m_labelOrig = m_label = label ;
38
39 WXValidateStyle( &style );
40 m_peer = wxWidgetImpl::CreateCheckBox( this, parent, id, label, pos, size, style, GetExtraStyle() ) ;
41
42 MacPostControlCreate(pos, size) ;
43
44 return true;
45 }
46
47
48 void wxCheckBox::SetValue(bool val)
49 {
50 if (val)
51 Set3StateValue(wxCHK_CHECKED);
52 else
53 Set3StateValue(wxCHK_UNCHECKED);
54 }
55
56 bool wxCheckBox::GetValue() const
57 {
58 return (DoGet3StateValue() != 0);
59 }
60
61 void wxCheckBox::Command(wxCommandEvent & event)
62 {
63 int state = event.GetInt();
64
65 wxCHECK_RET( (state == wxCHK_UNCHECKED) || (state == wxCHK_CHECKED)
66 || (state == wxCHK_UNDETERMINED),
67 wxT("event.GetInt() returned an invalid checkbox state") );
68
69 Set3StateValue((wxCheckBoxState)state);
70
71 ProcessCommand(event);
72 }
73
74 wxCheckBoxState wxCheckBox::DoGet3StateValue() const
75 {
76 return (wxCheckBoxState)m_peer->GetValue() ;
77 }
78
79 void wxCheckBox::DoSet3StateValue(wxCheckBoxState val)
80 {
81 m_peer->SetValue( val ) ;
82 }
83
84 bool wxCheckBox::OSXHandleClicked( double WXUNUSED(timestampsec) )
85 {
86 bool sendEvent = true;
87 wxCheckBoxState newState = Get3StateValue();
88
89 if ( !m_peer->ButtonClickDidStateChange() )
90 {
91 wxCheckBoxState origState ;
92
93 newState = origState = Get3StateValue();
94
95 switch (origState)
96 {
97 case wxCHK_UNCHECKED:
98 newState = wxCHK_CHECKED;
99 break;
100
101 case wxCHK_CHECKED:
102 // If the style flag to allow the user setting the undetermined state is set,
103 // then set the state to undetermined; otherwise set state to unchecked.
104 newState = Is3rdStateAllowedForUser() ? wxCHK_UNDETERMINED : wxCHK_UNCHECKED;
105 break;
106
107 case wxCHK_UNDETERMINED:
108 newState = wxCHK_UNCHECKED;
109 break;
110
111 default:
112 break;
113 }
114 if (newState == origState)
115 sendEvent = false;
116 }
117
118 if (sendEvent)
119 {
120 Set3StateValue( newState );
121
122 wxCommandEvent event( wxEVT_COMMAND_CHECKBOX_CLICKED, m_windowId );
123 event.SetInt( newState );
124 event.SetEventObject( this );
125 ProcessCommand( event );
126 }
127
128 return true;
129 }
130
131 // Bitmap checkbox
132 bool wxBitmapCheckBox::Create(wxWindow *parent,
133 wxWindowID id,
134 const wxBitmap *WXUNUSED(label),
135 const wxPoint& WXUNUSED(pos),
136 const wxSize& WXUNUSED(size),
137 long style,
138 const wxValidator& wxVALIDATOR_PARAM(validator),
139 const wxString& name)
140 {
141 SetName(name);
142 #if wxUSE_VALIDATORS
143 SetValidator(validator);
144 #endif
145 m_windowStyle = style;
146
147 if (parent)
148 parent->AddChild(this);
149
150 if ( id == -1 )
151 m_windowId = NewControlId();
152 else
153 m_windowId = id;
154
155 // TODO: Create the bitmap checkbox
156
157 return false;
158 }
159
160 void wxBitmapCheckBox::SetLabel(const wxBitmap *WXUNUSED(bitmap))
161 {
162 // TODO
163 wxFAIL_MSG(wxT("wxBitmapCheckBox::SetLabel() not yet implemented"));
164 }
165
166 void wxBitmapCheckBox::SetSize(int x, int y, int width, int height, int sizeFlags)
167 {
168 wxControl::SetSize( x , y , width , height , sizeFlags ) ;
169 }
170
171 void wxBitmapCheckBox::SetValue(bool WXUNUSED(val))
172 {
173 // TODO
174 wxFAIL_MSG(wxT("wxBitmapCheckBox::SetValue() not yet implemented"));
175 }
176
177 bool wxBitmapCheckBox::GetValue() const
178 {
179 // TODO
180 wxFAIL_MSG(wxT("wxBitmapCheckBox::GetValue() not yet implemented"));
181
182 return false;
183 }
184
185 #endif