1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/mac/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/mac/uma.h"
20 IMPLEMENT_DYNAMIC_CLASS(wxCheckBox
, wxControl
)
21 IMPLEMENT_DYNAMIC_CLASS(wxBitmapCheckBox
, wxCheckBox
)
24 // Single check box item
25 bool wxCheckBox::Create(wxWindow
*parent
,
27 const wxString
& label
,
31 const wxValidator
& validator
,
34 m_macIsUserPane
= false ;
36 if ( !wxCheckBoxBase::Create(parent
, id
, pos
, size
, style
, validator
, name
) )
41 SInt32 maxValue
= 1 /* kControlCheckboxCheckedValue */;
42 if (style
& wxCHK_3STATE
)
43 maxValue
= 2 /* kControlCheckboxMixedValue */;
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() ) );
50 m_peer
->SetMaximum( maxValue
) ;
52 MacPostControlCreate(pos
, size
) ;
57 void wxCheckBox::SetValue(bool val
)
60 Set3StateValue(wxCHK_CHECKED
);
62 Set3StateValue(wxCHK_UNCHECKED
);
65 bool wxCheckBox::GetValue() const
67 return (DoGet3StateValue() != 0);
70 void wxCheckBox::Command(wxCommandEvent
& event
)
72 int state
= event
.GetInt();
74 wxCHECK_RET( (state
== wxCHK_UNCHECKED
) || (state
== wxCHK_CHECKED
)
75 || (state
== wxCHK_UNDETERMINED
),
76 wxT("event.GetInt() returned an invalid checkbox state") );
78 Set3StateValue((wxCheckBoxState
)state
);
80 ProcessCommand(event
);
83 wxCheckBoxState
wxCheckBox::DoGet3StateValue() const
85 return (wxCheckBoxState
)m_peer
->GetValue() ;
88 void wxCheckBox::DoSet3StateValue(wxCheckBoxState val
)
90 m_peer
->SetValue( val
) ;
93 wxInt32
wxCheckBox::MacControlHit( WXEVENTHANDLERREF
WXUNUSED(handler
) , WXEVENTREF
WXUNUSED(event
) )
95 wxCheckBoxState origState
, newState
;
97 newState
= origState
= Get3StateValue();
101 case wxCHK_UNCHECKED
:
102 newState
= 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
;
111 case wxCHK_UNDETERMINED
:
112 newState
= wxCHK_UNCHECKED
;
119 if (newState
!= origState
)
121 Set3StateValue( newState
);
123 wxCommandEvent
event( wxEVT_COMMAND_CHECKBOX_CLICKED
, m_windowId
);
124 event
.SetInt( newState
);
125 event
.SetEventObject( this );
126 ProcessCommand( event
);
133 bool wxBitmapCheckBox::Create(wxWindow
*parent
,
135 const wxBitmap
*label
,
139 const wxValidator
& wxVALIDATOR_PARAM(validator
),
140 const wxString
& name
)
144 SetValidator(validator
);
146 m_windowStyle
= style
;
149 parent
->AddChild(this);
152 m_windowId
= NewControlId();
156 // TODO: Create the bitmap checkbox
161 void wxBitmapCheckBox::SetLabel(const wxBitmap
*bitmap
)
164 wxFAIL_MSG(wxT("wxBitmapCheckBox::SetLabel() not yet implemented"));
167 void wxBitmapCheckBox::SetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
169 wxControl::SetSize( x
, y
, width
, height
, sizeFlags
) ;
172 void wxBitmapCheckBox::SetValue(bool val
)
175 wxFAIL_MSG(wxT("wxBitmapCheckBox::SetValue() not yet implemented"));
178 bool wxBitmapCheckBox::GetValue() const
181 wxFAIL_MSG(wxT("wxBitmapCheckBox::GetValue() not yet implemented"));