]> git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/checkbox.cpp
Use empty check consistent with other parts.
[wxWidgets.git] / src / mac / carbon / checkbox.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: 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 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
13 #pragma implementation "checkbox.h"
14 #endif
15
16 #include "wx/wxprec.h"
17
18 #if wxUSE_CHECKBOX
19
20 #include "wx/checkbox.h"
21
22 #if !USE_SHARED_LIBRARY
23 IMPLEMENT_DYNAMIC_CLASS(wxCheckBox, wxControl)
24 IMPLEMENT_DYNAMIC_CLASS(wxBitmapCheckBox, wxCheckBox)
25 #endif
26
27 #include "wx/mac/uma.h"
28
29 // Single check box item
30 bool wxCheckBox::Create(wxWindow *parent, wxWindowID id, const wxString& label,
31 const wxPoint& pos,
32 const wxSize& size, long style,
33 const wxValidator& validator,
34 const wxString& name)
35 {
36 m_macIsUserPane = FALSE ;
37
38 if ( !wxCheckBoxBase::Create(parent, id, pos, size, style, validator, name) )
39 return false;
40
41 m_label = label ;
42
43 SInt32 maxValue = 1 /* kControlCheckboxCheckedValue */;
44 if (style & wxCHK_3STATE)
45 maxValue = 2 /* kControlCheckboxMixedValue */;
46
47 Rect bounds = wxMacGetBoundsForControl( this , pos , size ) ;
48 m_peer = new wxMacControl(this) ;
49 verify_noerr( CreateCheckBoxControl(MAC_WXHWND(parent->MacGetTopLevelWindowRef()), &bounds ,
50 CFSTR("") , 0 , false , m_peer->GetControlRefAddr() ) );
51
52 m_peer->SetMaximum( maxValue ) ;
53
54 MacPostControlCreate(pos,size) ;
55
56 return TRUE;
57 }
58
59 void wxCheckBox::SetValue(bool val)
60 {
61 if (val)
62 {
63 Set3StateValue(wxCHK_CHECKED);
64 }
65 else
66 {
67 Set3StateValue(wxCHK_UNCHECKED);
68 }
69 }
70
71 bool wxCheckBox::GetValue() const
72 {
73 return (DoGet3StateValue() != 0);
74 }
75
76 void wxCheckBox::Command (wxCommandEvent & event)
77 {
78 int state = event.GetInt();
79
80 wxCHECK_RET( (state == wxCHK_UNCHECKED) || (state == wxCHK_CHECKED)
81 || (state == wxCHK_UNDETERMINED),
82 wxT("event.GetInt() returned an invalid checkbox state") );
83
84 Set3StateValue((wxCheckBoxState) state);
85
86 ProcessCommand(event);
87 }
88
89 wxCheckBoxState wxCheckBox::DoGet3StateValue() const
90 {
91 return (wxCheckBoxState) m_peer->GetValue() ;
92 }
93
94 void wxCheckBox::DoSet3StateValue(wxCheckBoxState val)
95 {
96 m_peer->SetValue( val ) ;
97 }
98
99 wxInt32 wxCheckBox::MacControlHit(WXEVENTHANDLERREF WXUNUSED(handler) , WXEVENTREF WXUNUSED(event) )
100 {
101 wxCommandEvent event(wxEVT_COMMAND_CHECKBOX_CLICKED, m_windowId );
102 wxCheckBoxState state = Get3StateValue();
103
104 if (state == wxCHK_UNCHECKED)
105 {
106 state = wxCHK_CHECKED;
107 }
108 else if (state == wxCHK_CHECKED)
109 {
110 // If the style flag to allow the user setting the undetermined state
111 // is set, then set the state to undetermined. Otherwise set state to
112 // unchecked.
113 if ( Is3rdStateAllowedForUser() )
114 {
115 state = wxCHK_UNDETERMINED;
116 }
117 else
118 {
119 state = wxCHK_UNCHECKED;
120 }
121 }
122 else if (state == wxCHK_UNDETERMINED)
123 {
124 state = wxCHK_UNCHECKED;
125 }
126 Set3StateValue(state);
127
128 event.SetInt(state);
129 event.SetEventObject(this);
130 ProcessCommand(event);
131
132 return noErr ;
133 }
134
135 // Bitmap checkbox
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)
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
162 wxFAIL_MSG(wxT("wxBitmapCheckBox::SetLabel() not yet implemented"));
163 }
164
165 void wxBitmapCheckBox::SetSize(int x, int y, int width, int height, int sizeFlags)
166 {
167 wxControl::SetSize( x , y , width , height , sizeFlags ) ;
168 }
169
170 void wxBitmapCheckBox::SetValue(bool val)
171 {
172 // TODO
173 wxFAIL_MSG(wxT("wxBitmapCheckBox::SetValue() not yet implemented"));
174 }
175
176 bool wxBitmapCheckBox::GetValue() const
177 {
178 // TODO
179 wxFAIL_MSG(wxT("wxBitmapCheckBox::GetValue() not yet implemented"));
180 return FALSE;
181 }
182
183 #endif