]> git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/checkbox.cpp
cast corrected
[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 #ifdef __GNUG__
13 #pragma implementation "checkbox.h"
14 #endif
15
16 #include "wx/defs.h"
17
18 #include "wx/checkbox.h"
19
20 #if !USE_SHARED_LIBRARY
21 IMPLEMENT_DYNAMIC_CLASS(wxCheckBox, wxControl)
22 IMPLEMENT_DYNAMIC_CLASS(wxBitmapCheckBox, wxCheckBox)
23 #endif
24
25 #include "wx/mac/uma.h"
26
27 // Single check box item
28 bool wxCheckBox::Create(wxWindow *parent, wxWindowID id, const wxString& label,
29 const wxPoint& pos,
30 const wxSize& size, long style,
31 const wxValidator& validator,
32 const wxString& name)
33 {
34 m_macIsUserPane = FALSE ;
35
36 if ( !wxCheckBoxBase::Create(parent, id, pos, size, style, validator, name) )
37 return false;
38
39 m_label = label ;
40
41 SInt16 maxValue = 1 /* kControlCheckboxCheckedValue */;
42 if (style & wxCHK_3STATE)
43 {
44 maxValue = 2 /* kControlCheckboxMixedValue */;
45 }
46
47
48 Rect bounds = wxMacGetBoundsForControl( this , pos , size ) ;
49 m_macControl = (WXWidget) ::NewControl( MAC_WXHWND(parent->MacGetTopLevelWindowRef()) , &bounds , "\p" , true , 0 , 0 , maxValue,
50 kControlCheckBoxProc , (long) this ) ;
51
52 MacPostControlCreate(pos,size) ;
53
54 return TRUE;
55 }
56
57 void wxCheckBox::SetValue(bool val)
58 {
59 if (val)
60 {
61 Set3StateValue(wxCHK_CHECKED);
62 }
63 else
64 {
65 Set3StateValue(wxCHK_UNCHECKED);
66 }
67 }
68
69 bool wxCheckBox::GetValue() const
70 {
71 return (DoGet3StateValue() != 0);
72 }
73
74 void wxCheckBox::Command (wxCommandEvent & event)
75 {
76 int state = event.GetInt();
77
78 wxCHECK_RET( (state == wxCHK_UNCHECKED) || (state == wxCHK_CHECKED)
79 || (state == wxCHK_UNDETERMINED),
80 wxT("event.GetInt() returned an invalid checkbox state") );
81
82 Set3StateValue((wxCheckBoxState) state);
83
84 ProcessCommand(event);
85 }
86
87 wxCheckBoxState wxCheckBox::DoGet3StateValue() const
88 {
89 return (wxCheckBoxState) ::GetControl32BitValue( (ControlRef) m_macControl );
90 }
91
92 void wxCheckBox::DoSet3StateValue(wxCheckBoxState val)
93 {
94 ::SetControl32BitValue( (ControlRef) m_macControl , (int) val) ;
95 MacRedrawControl() ;
96 }
97
98 void wxCheckBox::MacHandleControlClick( WXWidget WXUNUSED(control), wxInt16 WXUNUSED(controlpart) , bool WXUNUSED(mouseStillDown) )
99 {
100 wxCommandEvent event(wxEVT_COMMAND_CHECKBOX_CLICKED, m_windowId );
101 wxCheckBoxState state = Get3StateValue();
102
103 if (state == wxCHK_UNCHECKED)
104 {
105 state = wxCHK_CHECKED;
106 }
107 else if (state == wxCHK_CHECKED)
108 {
109 // If the style flag to allow the user setting the undetermined state
110 // is set, then set the state to undetermined. Otherwise set state to
111 // unchecked.
112 if ( Is3rdStateAllowedForUser() )
113 {
114 state = wxCHK_UNDETERMINED;
115 }
116 else
117 {
118 state = wxCHK_UNCHECKED;
119 }
120 }
121 else if (state == wxCHK_UNDETERMINED)
122 {
123 state = wxCHK_UNCHECKED;
124 }
125 Set3StateValue(state);
126
127 event.SetInt(state);
128 event.SetEventObject(this);
129 ProcessCommand(event);
130 }
131
132 // Bitmap checkbox
133 bool wxBitmapCheckBox::Create(wxWindow *parent, wxWindowID id,
134 const wxBitmap *label,
135 const wxPoint& pos,
136 const wxSize& size, long style,
137 const wxValidator& validator,
138 const wxString& name)
139 {
140 SetName(name);
141 SetValidator(validator);
142 m_windowStyle = style;
143
144 if (parent) parent->AddChild(this);
145
146 if ( id == -1 )
147 m_windowId = NewControlId();
148 else
149 m_windowId = id;
150
151 // TODO: Create the bitmap checkbox
152
153 return FALSE;
154 }
155
156 void wxBitmapCheckBox::SetLabel(const wxBitmap *bitmap)
157 {
158 // TODO
159 wxFAIL_MSG(wxT("wxBitmapCheckBox::SetLabel() not yet implemented"));
160 }
161
162 void wxBitmapCheckBox::SetSize(int x, int y, int width, int height, int sizeFlags)
163 {
164 wxControl::SetSize( x , y , width , height , sizeFlags ) ;
165 }
166
167 void wxBitmapCheckBox::SetValue(bool val)
168 {
169 // TODO
170 wxFAIL_MSG(wxT("wxBitmapCheckBox::SetValue() not yet implemented"));
171 }
172
173 bool wxBitmapCheckBox::GetValue() const
174 {
175 // TODO
176 wxFAIL_MSG(wxT("wxBitmapCheckBox::GetValue() not yet implemented"));
177 return FALSE;
178 }
179
180