1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/carbon/checkbox.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(wxCheckBox
, wxControl
)
20 IMPLEMENT_DYNAMIC_CLASS(wxBitmapCheckBox
, wxCheckBox
)
22 // Single check box item
23 bool wxCheckBox::Create(wxWindow
*parent
,
25 const wxString
& label
,
29 const wxValidator
& validator
,
32 m_macIsUserPane
= false ;
34 if ( !wxCheckBoxBase::Create(parent
, id
, pos
, size
, style
, validator
, name
) )
37 m_labelOrig
= m_label
= label
;
39 WXValidateStyle( &style
);
40 m_peer
= wxWidgetImpl::CreateCheckBox( this, parent
, id
, label
, pos
, size
, style
, GetExtraStyle() ) ;
42 MacPostControlCreate(pos
, size
) ;
48 void wxCheckBox::SetValue(bool val
)
51 Set3StateValue(wxCHK_CHECKED
);
53 Set3StateValue(wxCHK_UNCHECKED
);
56 bool wxCheckBox::GetValue() const
58 return (DoGet3StateValue() != 0);
61 void wxCheckBox::Command(wxCommandEvent
& event
)
63 int state
= event
.GetInt();
65 wxCHECK_RET( (state
== wxCHK_UNCHECKED
) || (state
== wxCHK_CHECKED
)
66 || (state
== wxCHK_UNDETERMINED
),
67 wxT("event.GetInt() returned an invalid checkbox state") );
69 Set3StateValue((wxCheckBoxState
)state
);
71 ProcessCommand(event
);
74 wxCheckBoxState
wxCheckBox::DoGet3StateValue() const
76 return (wxCheckBoxState
)m_peer
->GetValue() ;
79 void wxCheckBox::DoSet3StateValue(wxCheckBoxState val
)
81 m_peer
->SetValue( val
) ;
84 bool wxCheckBox::OSXHandleClicked( double WXUNUSED(timestampsec
) )
86 bool sendEvent
= true;
87 wxCheckBoxState newState
= Get3StateValue();
89 if ( !m_peer
->ButtonClickDidStateChange() )
91 wxCheckBoxState origState
;
93 newState
= origState
= Get3StateValue();
98 newState
= wxCHK_CHECKED
;
102 // If the style flag to allow the user setting the undetermined state is set,
103 // then set the state to undetermined; otherwise set state to unchecked.
104 newState
= Is3rdStateAllowedForUser() ? wxCHK_UNDETERMINED
: wxCHK_UNCHECKED
;
107 case wxCHK_UNDETERMINED
:
108 newState
= wxCHK_UNCHECKED
;
114 if (newState
== origState
)
120 Set3StateValue( newState
);
122 wxCommandEvent
event( wxEVT_COMMAND_CHECKBOX_CLICKED
, m_windowId
);
123 event
.SetInt( newState
);
124 event
.SetEventObject( this );
125 ProcessCommand( event
);
132 bool wxBitmapCheckBox::Create(wxWindow
*parent
,
134 const wxBitmap
*WXUNUSED(label
),
135 const wxPoint
& WXUNUSED(pos
),
136 const wxSize
& WXUNUSED(size
),
138 const wxValidator
& wxVALIDATOR_PARAM(validator
),
139 const wxString
& name
)
143 SetValidator(validator
);
145 m_windowStyle
= style
;
148 parent
->AddChild(this);
151 m_windowId
= NewControlId();
155 // TODO: Create the bitmap checkbox
160 void wxBitmapCheckBox::SetLabel(const wxBitmap
*WXUNUSED(bitmap
))
163 wxFAIL_MSG(wxT("wxBitmapCheckBox::SetLabel() not yet implemented"));
166 void wxBitmapCheckBox::SetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
168 wxControl::SetSize( x
, y
, width
, height
, sizeFlags
) ;
171 void wxBitmapCheckBox::SetValue(bool WXUNUSED(val
))
174 wxFAIL_MSG(wxT("wxBitmapCheckBox::SetValue() not yet implemented"));
177 bool wxBitmapCheckBox::GetValue() const
180 wxFAIL_MSG(wxT("wxBitmapCheckBox::GetValue() not yet implemented"));