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