]> git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/checkbox.cpp
int warning
[wxWidgets.git] / src / mac / carbon / checkbox.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/mac/carbon/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 #if wxUSE_CHECKBOX
15
16 #include "wx/checkbox.h"
17 #include "wx/mac/uma.h"
18
19
20 IMPLEMENT_DYNAMIC_CLASS(wxCheckBox, wxControl)
21 IMPLEMENT_DYNAMIC_CLASS(wxBitmapCheckBox, wxCheckBox)
22
23
24 // Single check box item
25 bool 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)
33 {
34 m_macIsUserPane = false ;
35
36 if ( !wxCheckBoxBase::Create(parent, id, pos, size, style, validator, name) )
37 return false;
38
39 m_label = label ;
40
41 SInt32 maxValue = 1 /* kControlCheckboxCheckedValue */;
42 if (style & wxCHK_3STATE)
43 maxValue = 2 /* kControlCheckboxMixedValue */;
44
45 Rect bounds = wxMacGetBoundsForControl( this , pos , size ) ;
46 m_peer = new wxMacControl( this ) ;
47 verify_noerr( CreateCheckBoxControl(MAC_WXHWND(parent->MacGetTopLevelWindowRef()), &bounds ,
48 CFSTR("") , 0 , false , m_peer->GetControlRefAddr() ) );
49
50 m_peer->SetMaximum( maxValue ) ;
51
52 MacPostControlCreate(pos, size) ;
53
54 return true;
55 }
56
57 void wxCheckBox::SetValue(bool val)
58 {
59 if (val)
60 Set3StateValue(wxCHK_CHECKED);
61 else
62 Set3StateValue(wxCHK_UNCHECKED);
63 }
64
65 bool wxCheckBox::GetValue() const
66 {
67 return (DoGet3StateValue() != 0);
68 }
69
70 void wxCheckBox::Command(wxCommandEvent & event)
71 {
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
78 Set3StateValue((wxCheckBoxState)state);
79
80 ProcessCommand(event);
81 }
82
83 wxCheckBoxState wxCheckBox::DoGet3StateValue() const
84 {
85 return (wxCheckBoxState)m_peer->GetValue() ;
86 }
87
88 void wxCheckBox::DoSet3StateValue(wxCheckBoxState val)
89 {
90 m_peer->SetValue( val ) ;
91 }
92
93 wxInt32 wxCheckBox::MacControlHit( WXEVENTHANDLERREF WXUNUSED(handler) , WXEVENTREF WXUNUSED(event) )
94 {
95 wxCheckBoxState origState, newState;
96
97 newState = origState = Get3StateValue();
98
99 switch (origState)
100 {
101 case wxCHK_UNCHECKED:
102 newState = wxCHK_CHECKED;
103 break;
104
105 case wxCHK_CHECKED:
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
111 case wxCHK_UNDETERMINED:
112 newState = wxCHK_UNCHECKED;
113 break;
114
115 default:
116 break;
117 }
118
119 if (newState != origState)
120 {
121 Set3StateValue( newState );
122
123 wxCommandEvent event( wxEVT_COMMAND_CHECKBOX_CLICKED, m_windowId );
124 event.SetInt( newState );
125 event.SetEventObject( this );
126 ProcessCommand( event );
127 }
128
129 return noErr;
130 }
131
132 // Bitmap checkbox
133 bool 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)
141 {
142 SetName(name);
143 SetValidator(validator);
144 m_windowStyle = style;
145
146 if (parent)
147 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
159 void wxBitmapCheckBox::SetLabel(const wxBitmap *bitmap)
160 {
161 // TODO
162 wxFAIL_MSG(wxT("wxBitmapCheckBox::SetLabel() not yet implemented"));
163 }
164
165 void wxBitmapCheckBox::SetSize(int x, int y, int width, int height, int sizeFlags)
166 {
167 wxControl::SetSize( x , y , width , height , sizeFlags ) ;
168 }
169
170 void wxBitmapCheckBox::SetValue(bool val)
171 {
172 // TODO
173 wxFAIL_MSG(wxT("wxBitmapCheckBox::SetValue() not yet implemented"));
174 }
175
176 bool wxBitmapCheckBox::GetValue() const
177 {
178 // TODO
179 wxFAIL_MSG(wxT("wxBitmapCheckBox::GetValue() not yet implemented"));
180
181 return false;
182 }
183
184 #endif