1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/checkbox_osx.cpp
4 // Author: Stefan Csomor
7 // Copyright: (c) Stefan Csomor
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 #include "wx/wxprec.h"
15 #include "wx/checkbox.h"
16 #include "wx/osx/private.h"
18 IMPLEMENT_DYNAMIC_CLASS(wxBitmapCheckBox
, wxCheckBox
)
20 // Single check box item
21 bool wxCheckBox::Create(wxWindow
*parent
,
23 const wxString
& label
,
27 const wxValidator
& validator
,
32 if ( !wxCheckBoxBase::Create(parent
, id
, pos
, size
, style
, validator
, name
) )
35 m_labelOrig
= m_label
= label
;
37 WXValidateStyle( &style
);
38 SetPeer(wxWidgetImpl::CreateCheckBox( this, parent
, id
, label
, pos
, size
, style
, GetExtraStyle() )) ;
40 MacPostControlCreate(pos
, size
) ;
46 void wxCheckBox::SetValue(bool val
)
49 Set3StateValue(wxCHK_CHECKED
);
51 Set3StateValue(wxCHK_UNCHECKED
);
54 bool wxCheckBox::GetValue() const
56 return (DoGet3StateValue() != 0);
59 void wxCheckBox::Command(wxCommandEvent
& event
)
61 int state
= event
.GetInt();
63 wxCHECK_RET( (state
== wxCHK_UNCHECKED
) || (state
== wxCHK_CHECKED
)
64 || (state
== wxCHK_UNDETERMINED
),
65 wxT("event.GetInt() returned an invalid checkbox state") );
67 Set3StateValue((wxCheckBoxState
)state
);
69 ProcessCommand(event
);
72 wxCheckBoxState
wxCheckBox::DoGet3StateValue() const
74 return (wxCheckBoxState
)GetPeer()->GetValue() ;
77 void wxCheckBox::DoSet3StateValue(wxCheckBoxState val
)
79 GetPeer()->SetValue( val
) ;
82 bool wxCheckBox::OSXHandleClicked( double WXUNUSED(timestampsec
) )
84 bool sendEvent
= true;
85 wxCheckBoxState newState
= Get3StateValue();
87 if ( !GetPeer()->ButtonClickDidStateChange() )
89 wxCheckBoxState origState
;
91 origState
= Get3StateValue();
96 newState
= 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
;
105 case wxCHK_UNDETERMINED
:
106 newState
= wxCHK_UNCHECKED
;
113 if (newState
== origState
)
116 Set3StateValue( newState
);
120 // in case we cannot avoid this user state change natively (eg cocoa) we intercept it here
121 if ( newState
== wxCHK_UNDETERMINED
&& !Is3rdStateAllowedForUser() )
123 newState
= wxCHK_CHECKED
;
124 Set3StateValue( newState
);
130 wxCommandEvent
event( wxEVT_CHECKBOX
, m_windowId
);
131 event
.SetInt( newState
);
132 event
.SetEventObject( this );
133 ProcessCommand( event
);
140 bool wxBitmapCheckBox::Create(wxWindow
*parent
,
142 const wxBitmap
*WXUNUSED(label
),
143 const wxPoint
& WXUNUSED(pos
),
144 const wxSize
& WXUNUSED(size
),
146 const wxValidator
& wxVALIDATOR_PARAM(validator
),
147 const wxString
& name
)
151 SetValidator(validator
);
153 m_windowStyle
= style
;
156 parent
->AddChild(this);
159 m_windowId
= NewControlId();
163 // TODO: Create the bitmap checkbox
168 void wxBitmapCheckBox::SetLabel(const wxBitmap
*WXUNUSED(bitmap
))
171 wxFAIL_MSG(wxT("wxBitmapCheckBox::SetLabel() not yet implemented"));
174 void wxBitmapCheckBox::SetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
176 wxControl::SetSize( x
, y
, width
, height
, sizeFlags
) ;
179 void wxBitmapCheckBox::SetValue(bool WXUNUSED(val
))
182 wxFAIL_MSG(wxT("wxBitmapCheckBox::SetValue() not yet implemented"));
185 bool wxBitmapCheckBox::GetValue() const
188 wxFAIL_MSG(wxT("wxBitmapCheckBox::GetValue() not yet implemented"));