]> git.saurik.com Git - wxWidgets.git/blame - src/mac/carbon/checkbox.cpp
allowing shaped windows again
[wxWidgets.git] / src / mac / carbon / checkbox.cpp
CommitLineData
e9576ca5
SC
1/////////////////////////////////////////////////////////////////////////////
2// Name: checkbox.cpp
3// Purpose: wxCheckBox
a31a5f85 4// Author: Stefan Csomor
e9576ca5
SC
5// Modified by:
6// Created: 04/01/98
7// RCS-ID: $Id$
a31a5f85 8// Copyright: (c) Stefan Csomor
e40298d5 9// Licence: wxWindows licence
e9576ca5
SC
10/////////////////////////////////////////////////////////////////////////////
11
12#ifdef __GNUG__
13#pragma implementation "checkbox.h"
14#endif
15
d8c736e5
GD
16#include "wx/defs.h"
17
e9576ca5
SC
18#include "wx/checkbox.h"
19
2f1ae414 20#if !USE_SHARED_LIBRARY
e9576ca5
SC
21IMPLEMENT_DYNAMIC_CLASS(wxCheckBox, wxControl)
22IMPLEMENT_DYNAMIC_CLASS(wxBitmapCheckBox, wxCheckBox)
2f1ae414 23#endif
e9576ca5 24
d497dca4 25#include "wx/mac/uma.h"
519cb848 26
e9576ca5
SC
27// Single check box item
28bool 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{
facd6764
SC
34 m_macIsUserPane = FALSE ;
35
b45ed7a2
VZ
36 if ( !wxCheckBoxBase::Create(parent, id, pos, size, style, validator, name) )
37 return false;
38
facd6764 39 m_label = label ;
e9576ca5 40
4c37f124 41 SInt32 maxValue = 1 /* kControlCheckboxCheckedValue */;
9c9ceb48 42 if (style & wxCHK_3STATE)
8941fa88 43 maxValue = 2 /* kControlCheckboxMixedValue */;
facd6764
SC
44
45 Rect bounds = wxMacGetBoundsForControl( this , pos , size ) ;
4c37f124
SC
46 verify_noerr( CreateCheckBoxControl(MAC_WXHWND(parent->MacGetTopLevelWindowRef()), &bounds ,
47 CFSTR("") , 0 , false , (ControlRef*) &m_macControl ) ) ;
48
49 SetControl32BitMaximum( (ControlRef) m_macControl , maxValue ) ;
e40298d5 50
facd6764 51 MacPostControlCreate(pos,size) ;
e9576ca5 52
519cb848 53 return TRUE;
e9576ca5
SC
54}
55
56void wxCheckBox::SetValue(bool val)
57{
8941fa88
VZ
58 if (val)
59 {
60 Set3StateValue(wxCHK_CHECKED);
61 }
62 else
63 {
64 Set3StateValue(wxCHK_UNCHECKED);
65 }
e9576ca5
SC
66}
67
68bool wxCheckBox::GetValue() const
69{
8941fa88 70 return (DoGet3StateValue() != 0);
e9576ca5
SC
71}
72
73void wxCheckBox::Command (wxCommandEvent & event)
74{
8941fa88
VZ
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
86wxCheckBoxState wxCheckBox::DoGet3StateValue() const
87{
facd6764 88 return (wxCheckBoxState) ::GetControl32BitValue( (ControlRef) m_macControl );
8941fa88
VZ
89}
90
91void wxCheckBox::DoSet3StateValue(wxCheckBoxState val)
92{
facd6764 93 ::SetControl32BitValue( (ControlRef) m_macControl , (int) val) ;
8941fa88 94 MacRedrawControl() ;
e9576ca5
SC
95}
96
4c37f124 97wxInt32 wxCheckBox::MacControlHit(WXEVENTHANDLERREF WXUNUSED(handler) , WXEVENTREF WXUNUSED(event) )
519cb848 98{
8208e181 99 wxCommandEvent event(wxEVT_COMMAND_CHECKBOX_CLICKED, m_windowId );
8941fa88
VZ
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 }
4c37f124 124 Set3StateValue(state);
8941fa88
VZ
125
126 event.SetInt(state);
8208e181
SC
127 event.SetEventObject(this);
128 ProcessCommand(event);
4c37f124
SC
129
130 return noErr ;
519cb848
SC
131}
132
e9576ca5 133// Bitmap checkbox
f2af4afb
GD
134bool 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)
e9576ca5
SC
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
157void wxBitmapCheckBox::SetLabel(const wxBitmap *bitmap)
158{
159 // TODO
0c32c930 160 wxFAIL_MSG(wxT("wxBitmapCheckBox::SetLabel() not yet implemented"));
e9576ca5
SC
161}
162
163void wxBitmapCheckBox::SetSize(int x, int y, int width, int height, int sizeFlags)
164{
519cb848 165 wxControl::SetSize( x , y , width , height , sizeFlags ) ;
e9576ca5
SC
166}
167
168void wxBitmapCheckBox::SetValue(bool val)
169{
170 // TODO
0c32c930 171 wxFAIL_MSG(wxT("wxBitmapCheckBox::SetValue() not yet implemented"));
e9576ca5
SC
172}
173
174bool wxBitmapCheckBox::GetValue() const
175{
0c32c930
GD
176 // TODO
177 wxFAIL_MSG(wxT("wxBitmapCheckBox::GetValue() not yet implemented"));
e9576ca5
SC
178 return FALSE;
179}
180
181