]> git.saurik.com Git - wxWidgets.git/blame - src/mac/carbon/checkbox.cpp
wxUSE_XXX related fixes
[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
65571936 9// Licence: wxWindows licence
e9576ca5
SC
10/////////////////////////////////////////////////////////////////////////////
11
a8e9860d 12#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
e9576ca5
SC
13#pragma implementation "checkbox.h"
14#endif
15
a8e9860d 16#include "wx/wxprec.h"
d8c736e5 17
179e085f
RN
18#if wxUSE_CHECKBOX
19
e9576ca5
SC
20#include "wx/checkbox.h"
21
2f1ae414 22#if !USE_SHARED_LIBRARY
e9576ca5
SC
23IMPLEMENT_DYNAMIC_CLASS(wxCheckBox, wxControl)
24IMPLEMENT_DYNAMIC_CLASS(wxBitmapCheckBox, wxCheckBox)
2f1ae414 25#endif
e9576ca5 26
d497dca4 27#include "wx/mac/uma.h"
519cb848 28
e9576ca5
SC
29// Single check box item
30bool wxCheckBox::Create(wxWindow *parent, wxWindowID id, const wxString& label,
31 const wxPoint& pos,
32 const wxSize& size, long style,
33 const wxValidator& validator,
34 const wxString& name)
35{
facd6764
SC
36 m_macIsUserPane = FALSE ;
37
b45ed7a2
VZ
38 if ( !wxCheckBoxBase::Create(parent, id, pos, size, style, validator, name) )
39 return false;
40
facd6764 41 m_label = label ;
e9576ca5 42
4c37f124 43 SInt32 maxValue = 1 /* kControlCheckboxCheckedValue */;
9c9ceb48 44 if (style & wxCHK_3STATE)
8941fa88 45 maxValue = 2 /* kControlCheckboxMixedValue */;
facd6764
SC
46
47 Rect bounds = wxMacGetBoundsForControl( this , pos , size ) ;
21fd5529 48 m_peer = new wxMacControl() ;
4c37f124 49 verify_noerr( CreateCheckBoxControl(MAC_WXHWND(parent->MacGetTopLevelWindowRef()), &bounds ,
5ca0d812 50 CFSTR("") , 0 , false , m_peer->GetControlRefAddr() ) );
21fd5529
SC
51
52 m_peer->SetMaximum( maxValue ) ;
e40298d5 53
facd6764 54 MacPostControlCreate(pos,size) ;
e9576ca5 55
519cb848 56 return TRUE;
e9576ca5
SC
57}
58
59void wxCheckBox::SetValue(bool val)
60{
8941fa88
VZ
61 if (val)
62 {
63 Set3StateValue(wxCHK_CHECKED);
64 }
65 else
66 {
67 Set3StateValue(wxCHK_UNCHECKED);
68 }
e9576ca5
SC
69}
70
71bool wxCheckBox::GetValue() const
72{
8941fa88 73 return (DoGet3StateValue() != 0);
e9576ca5
SC
74}
75
76void wxCheckBox::Command (wxCommandEvent & event)
77{
8941fa88
VZ
78 int state = event.GetInt();
79
80 wxCHECK_RET( (state == wxCHK_UNCHECKED) || (state == wxCHK_CHECKED)
81 || (state == wxCHK_UNDETERMINED),
82 wxT("event.GetInt() returned an invalid checkbox state") );
83
84 Set3StateValue((wxCheckBoxState) state);
85
86 ProcessCommand(event);
87}
88
89wxCheckBoxState wxCheckBox::DoGet3StateValue() const
90{
21fd5529 91 return (wxCheckBoxState) m_peer->GetValue() ;
8941fa88
VZ
92}
93
94void wxCheckBox::DoSet3StateValue(wxCheckBoxState val)
95{
21fd5529 96 m_peer->SetValue( val ) ;
e9576ca5
SC
97}
98
4c37f124 99wxInt32 wxCheckBox::MacControlHit(WXEVENTHANDLERREF WXUNUSED(handler) , WXEVENTREF WXUNUSED(event) )
519cb848 100{
8208e181 101 wxCommandEvent event(wxEVT_COMMAND_CHECKBOX_CLICKED, m_windowId );
8941fa88
VZ
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 }
4c37f124 126 Set3StateValue(state);
8941fa88
VZ
127
128 event.SetInt(state);
8208e181
SC
129 event.SetEventObject(this);
130 ProcessCommand(event);
4c37f124
SC
131
132 return noErr ;
519cb848
SC
133}
134
e9576ca5 135// Bitmap checkbox
f2af4afb
GD
136bool wxBitmapCheckBox::Create(wxWindow *parent, wxWindowID id,
137 const wxBitmap *label,
138 const wxPoint& pos,
139 const wxSize& size, long style,
140 const wxValidator& validator,
141 const wxString& name)
e9576ca5
SC
142{
143 SetName(name);
144 SetValidator(validator);
145 m_windowStyle = style;
146
147 if (parent) parent->AddChild(this);
148
149 if ( id == -1 )
150 m_windowId = NewControlId();
151 else
152 m_windowId = id;
153
154 // TODO: Create the bitmap checkbox
155
156 return FALSE;
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"));
e9576ca5
SC
180 return FALSE;
181}
182
179e085f 183#endif