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