]> git.saurik.com Git - wxWidgets.git/blame - src/mac/carbon/checkbox.cpp
changing asserts to debug info
[wxWidgets.git] / src / mac / carbon / checkbox.cpp
CommitLineData
e9576ca5 1/////////////////////////////////////////////////////////////////////////////
f3078f07 2// Name: src/mac/carbon/checkbox.cpp
e9576ca5 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
65571936 9// Licence: wxWindows licence
e9576ca5
SC
10/////////////////////////////////////////////////////////////////////////////
11
a8e9860d 12#include "wx/wxprec.h"
d8c736e5 13
179e085f
RN
14#if wxUSE_CHECKBOX
15
e9576ca5 16#include "wx/checkbox.h"
bcb3a164
DS
17#include "wx/mac/uma.h"
18
e9576ca5 19
e9576ca5
SC
20IMPLEMENT_DYNAMIC_CLASS(wxCheckBox, wxControl)
21IMPLEMENT_DYNAMIC_CLASS(wxBitmapCheckBox, wxCheckBox)
e9576ca5 22
519cb848 23
e9576ca5 24// Single check box item
bcb3a164
DS
25bool wxCheckBox::Create(wxWindow *parent,
26 wxWindowID id,
27 const wxString& label,
28 const wxPoint& pos,
29 const wxSize& size,
30 long style,
31 const wxValidator& validator,
32 const wxString& name)
e9576ca5 33{
bcb3a164
DS
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 ) ;
bcb3a164 46 m_peer = new wxMacControl( this ) ;
4c37f124 47 verify_noerr( CreateCheckBoxControl(MAC_WXHWND(parent->MacGetTopLevelWindowRef()), &bounds ,
5ca0d812 48 CFSTR("") , 0 , false , m_peer->GetControlRefAddr() ) );
bcb3a164 49
21fd5529 50 m_peer->SetMaximum( maxValue ) ;
e9576ca5 51
bcb3a164
DS
52 MacPostControlCreate(pos, size) ;
53
54 return true;
e9576ca5
SC
55}
56
57void wxCheckBox::SetValue(bool val)
58{
8941fa88 59 if (val)
8941fa88 60 Set3StateValue(wxCHK_CHECKED);
8941fa88 61 else
8941fa88 62 Set3StateValue(wxCHK_UNCHECKED);
e9576ca5
SC
63}
64
65bool wxCheckBox::GetValue() const
66{
8941fa88 67 return (DoGet3StateValue() != 0);
e9576ca5
SC
68}
69
bcb3a164 70void wxCheckBox::Command(wxCommandEvent & event)
e9576ca5 71{
8941fa88
VZ
72 int state = event.GetInt();
73
74 wxCHECK_RET( (state == wxCHK_UNCHECKED) || (state == wxCHK_CHECKED)
75 || (state == wxCHK_UNDETERMINED),
76 wxT("event.GetInt() returned an invalid checkbox state") );
77
bcb3a164 78 Set3StateValue((wxCheckBoxState)state);
8941fa88
VZ
79
80 ProcessCommand(event);
81}
82
83wxCheckBoxState wxCheckBox::DoGet3StateValue() const
84{
bcb3a164 85 return (wxCheckBoxState)m_peer->GetValue() ;
8941fa88
VZ
86}
87
88void wxCheckBox::DoSet3StateValue(wxCheckBoxState val)
89{
21fd5529 90 m_peer->SetValue( val ) ;
e9576ca5
SC
91}
92
bcb3a164 93wxInt32 wxCheckBox::MacControlHit( WXEVENTHANDLERREF WXUNUSED(handler) , WXEVENTREF WXUNUSED(event) )
519cb848 94{
bcb3a164 95 wxCheckBoxState origState, newState;
8941fa88 96
bcb3a164
DS
97 newState = origState = Get3StateValue();
98
99 switch (origState)
8941fa88 100 {
f3078f07 101 case wxCHK_UNCHECKED:
bcb3a164
DS
102 newState = wxCHK_CHECKED;
103 break;
104
f3078f07 105 case wxCHK_CHECKED:
bcb3a164
DS
106 // If the style flag to allow the user setting the undetermined state is set,
107 // then set the state to undetermined; otherwise set state to unchecked.
108 newState = Is3rdStateAllowedForUser() ? wxCHK_UNDETERMINED : wxCHK_UNCHECKED;
109 break;
110
f3078f07 111 case wxCHK_UNDETERMINED:
bcb3a164
DS
112 newState = wxCHK_UNCHECKED;
113 break;
114
f3078f07 115 default:
bcb3a164 116 break;
8941fa88 117 }
bcb3a164
DS
118
119 if (newState != origState)
8941fa88 120 {
bcb3a164 121 Set3StateValue( newState );
8941fa88 122
bcb3a164
DS
123 wxCommandEvent event( wxEVT_COMMAND_CHECKBOX_CLICKED, m_windowId );
124 event.SetInt( newState );
125 event.SetEventObject( this );
126 ProcessCommand( event );
127 }
4c37f124 128
bcb3a164 129 return noErr;
519cb848
SC
130}
131
e9576ca5 132// Bitmap checkbox
bcb3a164
DS
133bool wxBitmapCheckBox::Create(wxWindow *parent,
134 wxWindowID id,
135 const wxBitmap *label,
136 const wxPoint& pos,
137 const wxSize& size,
138 long style,
139 const wxValidator& validator,
140 const wxString& name)
e9576ca5
SC
141{
142 SetName(name);
143 SetValidator(validator);
144 m_windowStyle = style;
145
bcb3a164
DS
146 if (parent)
147 parent->AddChild(this);
e9576ca5
SC
148
149 if ( id == -1 )
150 m_windowId = NewControlId();
151 else
152 m_windowId = id;
153
154 // TODO: Create the bitmap checkbox
155
bcb3a164 156 return false;
e9576ca5
SC
157}
158
159void wxBitmapCheckBox::SetLabel(const wxBitmap *bitmap)
160{
161 // TODO
0c32c930 162 wxFAIL_MSG(wxT("wxBitmapCheckBox::SetLabel() not yet implemented"));
e9576ca5
SC
163}
164
165void wxBitmapCheckBox::SetSize(int x, int y, int width, int height, int sizeFlags)
166{
519cb848 167 wxControl::SetSize( x , y , width , height , sizeFlags ) ;
e9576ca5
SC
168}
169
170void wxBitmapCheckBox::SetValue(bool val)
171{
172 // TODO
0c32c930 173 wxFAIL_MSG(wxT("wxBitmapCheckBox::SetValue() not yet implemented"));
e9576ca5
SC
174}
175
176bool wxBitmapCheckBox::GetValue() const
177{
0c32c930
GD
178 // TODO
179 wxFAIL_MSG(wxT("wxBitmapCheckBox::GetValue() not yet implemented"));
bcb3a164
DS
180
181 return false;
e9576ca5
SC
182}
183
179e085f 184#endif