]> git.saurik.com Git - wxWidgets.git/blame - src/osx/checkbox_osx.cpp
No real changes, just make wxWindow::CanScroll() virtual.
[wxWidgets.git] / src / osx / checkbox_osx.cpp
CommitLineData
e53b3d16 1/////////////////////////////////////////////////////////////////////////////
80fdcdb9 2// Name: src/osx/checkbox_osx.cpp
e53b3d16
SC
3// Purpose: wxCheckBox
4// Author: Stefan Csomor
5// Modified by:
6// Created: 04/01/98
e53b3d16
SC
7// Copyright: (c) Stefan Csomor
8// Licence: wxWindows licence
9/////////////////////////////////////////////////////////////////////////////
10
11#include "wx/wxprec.h"
12
13#if wxUSE_CHECKBOX
14
15#include "wx/checkbox.h"
16#include "wx/osx/private.h"
17
e53b3d16
SC
18IMPLEMENT_DYNAMIC_CLASS(wxBitmapCheckBox, wxCheckBox)
19
20// Single check box item
21bool wxCheckBox::Create(wxWindow *parent,
22 wxWindowID id,
23 const wxString& label,
24 const wxPoint& pos,
25 const wxSize& size,
26 long style,
27 const wxValidator& validator,
28 const wxString& name)
d15694e8
SC
29{
30 DontCreatePeer();
31
e53b3d16
SC
32 if ( !wxCheckBoxBase::Create(parent, id, pos, size, style, validator, name) )
33 return false;
34
35 m_labelOrig = m_label = label ;
36
f254e242 37 WXValidateStyle( &style );
22756322 38 SetPeer(wxWidgetImpl::CreateCheckBox( this, parent, id, label, pos, size, style, GetExtraStyle() )) ;
e53b3d16
SC
39
40 MacPostControlCreate(pos, size) ;
41
42 return true;
43}
44
45
46void wxCheckBox::SetValue(bool val)
47{
48 if (val)
49 Set3StateValue(wxCHK_CHECKED);
50 else
51 Set3StateValue(wxCHK_UNCHECKED);
52}
53
54bool wxCheckBox::GetValue() const
55{
56 return (DoGet3StateValue() != 0);
57}
58
59void wxCheckBox::Command(wxCommandEvent & event)
60{
61 int state = event.GetInt();
62
63 wxCHECK_RET( (state == wxCHK_UNCHECKED) || (state == wxCHK_CHECKED)
64 || (state == wxCHK_UNDETERMINED),
65 wxT("event.GetInt() returned an invalid checkbox state") );
66
67 Set3StateValue((wxCheckBoxState)state);
68
69 ProcessCommand(event);
70}
71
72wxCheckBoxState wxCheckBox::DoGet3StateValue() const
73{
22756322 74 return (wxCheckBoxState)GetPeer()->GetValue() ;
e53b3d16
SC
75}
76
77void wxCheckBox::DoSet3StateValue(wxCheckBoxState val)
78{
22756322 79 GetPeer()->SetValue( val ) ;
e53b3d16
SC
80}
81
03647350 82bool wxCheckBox::OSXHandleClicked( double WXUNUSED(timestampsec) )
e53b3d16 83{
524c47aa
SC
84 bool sendEvent = true;
85 wxCheckBoxState newState = Get3StateValue();
03647350 86
22756322 87 if ( !GetPeer()->ButtonClickDidStateChange() )
e53b3d16 88 {
524c47aa
SC
89 wxCheckBoxState origState ;
90
361937c7 91 origState = Get3StateValue();
524c47aa
SC
92
93 switch (origState)
94 {
95 case wxCHK_UNCHECKED:
96 newState = wxCHK_CHECKED;
97 break;
98
99 case wxCHK_CHECKED:
100 // If the style flag to allow the user setting the undetermined state is set,
101 // then set the state to undetermined; otherwise set state to unchecked.
102 newState = Is3rdStateAllowedForUser() ? wxCHK_UNDETERMINED : wxCHK_UNCHECKED;
103 break;
104
105 case wxCHK_UNDETERMINED:
106 newState = wxCHK_UNCHECKED;
107 break;
108
109 default:
110 break;
111 }
91116a35 112
524c47aa
SC
113 if (newState == origState)
114 sendEvent = false;
91116a35
SC
115 else
116 Set3StateValue( newState );
e53b3d16 117 }
91116a35
SC
118 else
119 {
120 // in case we cannot avoid this user state change natively (eg cocoa) we intercept it here
121 if ( newState == wxCHK_UNDETERMINED && !Is3rdStateAllowedForUser() )
122 {
123 newState = wxCHK_CHECKED;
124 Set3StateValue( newState );
125 }
126 }
127
524c47aa 128 if (sendEvent)
e53b3d16 129 {
ce7fe42e 130 wxCommandEvent event( wxEVT_CHECKBOX, m_windowId );
e53b3d16
SC
131 event.SetInt( newState );
132 event.SetEventObject( this );
133 ProcessCommand( event );
134 }
135
136 return true;
137}
138
139// Bitmap checkbox
140bool wxBitmapCheckBox::Create(wxWindow *parent,
141 wxWindowID id,
142 const wxBitmap *WXUNUSED(label),
143 const wxPoint& WXUNUSED(pos),
144 const wxSize& WXUNUSED(size),
145 long style,
146 const wxValidator& wxVALIDATOR_PARAM(validator),
147 const wxString& name)
148{
149 SetName(name);
150#if wxUSE_VALIDATORS
151 SetValidator(validator);
152#endif
153 m_windowStyle = style;
154
155 if (parent)
156 parent->AddChild(this);
157
158 if ( id == -1 )
159 m_windowId = NewControlId();
160 else
161 m_windowId = id;
162
163 // TODO: Create the bitmap checkbox
164
165 return false;
166}
167
168void wxBitmapCheckBox::SetLabel(const wxBitmap *WXUNUSED(bitmap))
169{
170 // TODO
171 wxFAIL_MSG(wxT("wxBitmapCheckBox::SetLabel() not yet implemented"));
172}
173
174void wxBitmapCheckBox::SetSize(int x, int y, int width, int height, int sizeFlags)
175{
176 wxControl::SetSize( x , y , width , height , sizeFlags ) ;
177}
178
179void wxBitmapCheckBox::SetValue(bool WXUNUSED(val))
180{
181 // TODO
182 wxFAIL_MSG(wxT("wxBitmapCheckBox::SetValue() not yet implemented"));
183}
184
185bool wxBitmapCheckBox::GetValue() const
186{
187 // TODO
188 wxFAIL_MSG(wxT("wxBitmapCheckBox::GetValue() not yet implemented"));
189
190 return false;
191}
192
193#endif