1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/checkbox_osx.cpp
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #include "wx/wxprec.h"
16 #include "wx/checkbox.h"
17 #include "wx/osx/private.h"
19 IMPLEMENT_DYNAMIC_CLASS(wxBitmapCheckBox
, wxCheckBox
)
21 // Single check box item
22 bool wxCheckBox::Create(wxWindow
*parent
,
24 const wxString
& label
,
28 const wxValidator
& validator
,
33 if ( !wxCheckBoxBase::Create(parent
, id
, pos
, size
, style
, validator
, name
) )
36 m_labelOrig
= m_label
= label
;
38 WXValidateStyle( &style
);
39 SetPeer(wxWidgetImpl::CreateCheckBox( this, parent
, id
, label
, pos
, size
, style
, GetExtraStyle() )) ;
41 MacPostControlCreate(pos
, size
) ;
47 void wxCheckBox::SetValue(bool val
)
50 Set3StateValue(wxCHK_CHECKED
);
52 Set3StateValue(wxCHK_UNCHECKED
);
55 bool wxCheckBox::GetValue() const
57 return (DoGet3StateValue() != 0);
60 void wxCheckBox::Command(wxCommandEvent
& event
)
62 int state
= event
.GetInt();
64 wxCHECK_RET( (state
== wxCHK_UNCHECKED
) || (state
== wxCHK_CHECKED
)
65 || (state
== wxCHK_UNDETERMINED
),
66 wxT("event.GetInt() returned an invalid checkbox state") );
68 Set3StateValue((wxCheckBoxState
)state
);
70 ProcessCommand(event
);
73 wxCheckBoxState
wxCheckBox::DoGet3StateValue() const
75 return (wxCheckBoxState
)GetPeer()->GetValue() ;
78 void wxCheckBox::DoSet3StateValue(wxCheckBoxState val
)
80 GetPeer()->SetValue( val
) ;
83 bool wxCheckBox::OSXHandleClicked( double WXUNUSED(timestampsec
) )
85 bool sendEvent
= true;
86 wxCheckBoxState newState
= Get3StateValue();
88 if ( !GetPeer()->ButtonClickDidStateChange() )
90 wxCheckBoxState origState
;
92 origState
= Get3StateValue();
97 newState
= wxCHK_CHECKED
;
101 // If the style flag to allow the user setting the undetermined state is set,
102 // then set the state to undetermined; otherwise set state to unchecked.
103 newState
= Is3rdStateAllowedForUser() ? wxCHK_UNDETERMINED
: wxCHK_UNCHECKED
;
106 case wxCHK_UNDETERMINED
:
107 newState
= wxCHK_UNCHECKED
;
114 if (newState
== origState
)
117 Set3StateValue( newState
);
121 // in case we cannot avoid this user state change natively (eg cocoa) we intercept it here
122 if ( newState
== wxCHK_UNDETERMINED
&& !Is3rdStateAllowedForUser() )
124 newState
= wxCHK_CHECKED
;
125 Set3StateValue( newState
);
131 wxCommandEvent
event( wxEVT_CHECKBOX
, m_windowId
);
132 event
.SetInt( newState
);
133 event
.SetEventObject( this );
134 ProcessCommand( event
);
141 bool wxBitmapCheckBox::Create(wxWindow
*parent
,
143 const wxBitmap
*WXUNUSED(label
),
144 const wxPoint
& WXUNUSED(pos
),
145 const wxSize
& WXUNUSED(size
),
147 const wxValidator
& wxVALIDATOR_PARAM(validator
),
148 const wxString
& name
)
152 SetValidator(validator
);
154 m_windowStyle
= style
;
157 parent
->AddChild(this);
160 m_windowId
= NewControlId();
164 // TODO: Create the bitmap checkbox
169 void wxBitmapCheckBox::SetLabel(const wxBitmap
*WXUNUSED(bitmap
))
172 wxFAIL_MSG(wxT("wxBitmapCheckBox::SetLabel() not yet implemented"));
175 void wxBitmapCheckBox::SetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
177 wxControl::SetSize( x
, y
, width
, height
, sizeFlags
) ;
180 void wxBitmapCheckBox::SetValue(bool WXUNUSED(val
))
183 wxFAIL_MSG(wxT("wxBitmapCheckBox::SetValue() not yet implemented"));
186 bool wxBitmapCheckBox::GetValue() const
189 wxFAIL_MSG(wxT("wxBitmapCheckBox::GetValue() not yet implemented"));