]> git.saurik.com Git - wxWidgets.git/blob - src/mac/checkbox.cpp
dbf5b7d4e2b13ec58991ac67972879b43d2e0d57
[wxWidgets.git] / src / mac / 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 if ( !wxCheckBoxBase::Create(parent, id, pos, size, style, validator, name) )
35 return false;
36
37 m_style = style;
38
39 Rect bounds ;
40 Str255 title ;
41
42 MacPreControlCreate( parent , id , label , pos , size ,style, validator , name , &bounds , title ) ;
43
44 SInt16 maxValue = 1 /* kControlCheckboxCheckedValue */;
45 if (style & wxCHK_3STATE)
46 {
47 maxValue = 2 /* kControlCheckboxMixedValue */;
48 }
49
50 m_macControl = ::NewControl( MAC_WXHWND(parent->MacGetRootWindow()) , &bounds , title , false , 0 , 0 , maxValue,
51 kControlCheckBoxProc , (long) this ) ;
52
53 MacPostControlCreate() ;
54
55 return TRUE;
56 }
57
58 void wxCheckBox::SetValue(bool val)
59 {
60 if (val)
61 {
62 Set3StateValue(wxCHK_CHECKED);
63 }
64 else
65 {
66 Set3StateValue(wxCHK_UNCHECKED);
67 }
68 }
69
70 bool wxCheckBox::GetValue() const
71 {
72 return (DoGet3StateValue() != 0);
73 }
74
75 void wxCheckBox::Command (wxCommandEvent & event)
76 {
77 int state = event.GetInt();
78
79 wxCHECK_RET( (state == wxCHK_UNCHECKED) || (state == wxCHK_CHECKED)
80 || (state == wxCHK_UNDETERMINED),
81 wxT("event.GetInt() returned an invalid checkbox state") );
82
83 Set3StateValue((wxCheckBoxState) state);
84
85 ProcessCommand(event);
86 }
87
88 wxCheckBoxState wxCheckBox::DoGet3StateValue() const
89 {
90 return (wxCheckBoxState) ::GetControl32BitValue( (ControlHandle) m_macControl );
91 }
92
93 void wxCheckBox::DoSet3StateValue(wxCheckBoxState val)
94 {
95 ::SetControl32BitValue( (ControlHandle) m_macControl , (int) val) ;
96 MacRedrawControl() ;
97 }
98
99 void wxCheckBox::MacHandleControlClick( WXWidget WXUNUSED(control), wxInt16 WXUNUSED(controlpart) , bool WXUNUSED(mouseStillDown) )
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
133 // Bitmap checkbox
134 bool wxBitmapCheckBox::Create(wxWindow *parent, wxWindowID id,
135 const wxBitmap *label,
136 const wxPoint& pos,
137 const wxSize& size, long style,
138 const wxValidator& validator,
139 const wxString& name)
140 {
141 SetName(name);
142 SetValidator(validator);
143 m_windowStyle = style;
144
145 if (parent) parent->AddChild(this);
146
147 if ( id == -1 )
148 m_windowId = NewControlId();
149 else
150 m_windowId = id;
151
152 // TODO: Create the bitmap checkbox
153
154 return FALSE;
155 }
156
157 void wxBitmapCheckBox::SetLabel(const wxBitmap *bitmap)
158 {
159 // TODO
160 wxFAIL_MSG(wxT("wxBitmapCheckBox::SetLabel() not yet implemented"));
161 }
162
163 void wxBitmapCheckBox::SetSize(int x, int y, int width, int height, int sizeFlags)
164 {
165 wxControl::SetSize( x , y , width , height , sizeFlags ) ;
166 }
167
168 void wxBitmapCheckBox::SetValue(bool val)
169 {
170 // TODO
171 wxFAIL_MSG(wxT("wxBitmapCheckBox::SetValue() not yet implemented"));
172 }
173
174 bool wxBitmapCheckBox::GetValue() const
175 {
176 // TODO
177 wxFAIL_MSG(wxT("wxBitmapCheckBox::GetValue() not yet implemented"));
178 return FALSE;
179 }
180
181