1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #include "wx/wxprec.h"
16 #include "wx/checkbox.h"
18 IMPLEMENT_DYNAMIC_CLASS(wxCheckBox
, wxControl
)
19 IMPLEMENT_DYNAMIC_CLASS(wxBitmapCheckBox
, wxCheckBox
)
21 #include "wx/mac/uma.h"
23 // Single check box item
24 bool wxCheckBox::Create(wxWindow
*parent
, wxWindowID id
, const wxString
& label
,
26 const wxSize
& size
, long style
,
27 const wxValidator
& validator
,
30 m_macIsUserPane
= FALSE
;
32 if ( !wxCheckBoxBase::Create(parent
, id
, pos
, size
, style
, validator
, name
) )
37 SInt32 maxValue
= 1 /* kControlCheckboxCheckedValue */;
38 if (style
& wxCHK_3STATE
)
39 maxValue
= 2 /* kControlCheckboxMixedValue */;
41 Rect bounds
= wxMacGetBoundsForControl( this , pos
, size
) ;
42 m_peer
= new wxMacControl(this) ;
43 verify_noerr( CreateCheckBoxControl(MAC_WXHWND(parent
->MacGetTopLevelWindowRef()), &bounds
,
44 CFSTR("") , 0 , false , m_peer
->GetControlRefAddr() ) );
46 m_peer
->SetMaximum( maxValue
) ;
48 MacPostControlCreate(pos
,size
) ;
53 void wxCheckBox::SetValue(bool val
)
57 Set3StateValue(wxCHK_CHECKED
);
61 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 wxCommandEvent
event(wxEVT_COMMAND_CHECKBOX_CLICKED
, m_windowId
);
96 wxCheckBoxState state
= Get3StateValue();
98 if (state
== wxCHK_UNCHECKED
)
100 state
= wxCHK_CHECKED
;
102 else if (state
== wxCHK_CHECKED
)
104 // If the style flag to allow the user setting the undetermined state
105 // is set, then set the state to undetermined. Otherwise set state to
107 if ( Is3rdStateAllowedForUser() )
109 state
= wxCHK_UNDETERMINED
;
113 state
= wxCHK_UNCHECKED
;
116 else if (state
== wxCHK_UNDETERMINED
)
118 state
= wxCHK_UNCHECKED
;
120 Set3StateValue(state
);
123 event
.SetEventObject(this);
124 ProcessCommand(event
);
130 bool wxBitmapCheckBox::Create(wxWindow
*parent
, wxWindowID id
,
131 const wxBitmap
*label
,
133 const wxSize
& size
, long style
,
134 const wxValidator
& validator
,
135 const wxString
& name
)
138 SetValidator(validator
);
139 m_windowStyle
= style
;
141 if (parent
) parent
->AddChild(this);
144 m_windowId
= NewControlId();
148 // TODO: Create the bitmap checkbox
153 void wxBitmapCheckBox::SetLabel(const wxBitmap
*bitmap
)
156 wxFAIL_MSG(wxT("wxBitmapCheckBox::SetLabel() not yet implemented"));
159 void wxBitmapCheckBox::SetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
161 wxControl::SetSize( x
, y
, width
, height
, sizeFlags
) ;
164 void wxBitmapCheckBox::SetValue(bool val
)
167 wxFAIL_MSG(wxT("wxBitmapCheckBox::SetValue() not yet implemented"));
170 bool wxBitmapCheckBox::GetValue() const
173 wxFAIL_MSG(wxT("wxBitmapCheckBox::GetValue() not yet implemented"));