]> git.saurik.com Git - wxWidgets.git/blame - src/mac/classic/checkbox.cpp
linking commands on the individual window level, otherwise built-in handlers override...
[wxWidgets.git] / src / mac / classic / checkbox.cpp
CommitLineData
2646f485
SC
1/////////////////////////////////////////////////////////////////////////////
2// Name: checkbox.cpp
3// Purpose: wxCheckBox
4// Author: Stefan Csomor
5// Modified by:
6// Created: 04/01/98
7// RCS-ID: $Id$
8// Copyright: (c) Stefan Csomor
65571936 9// Licence: wxWindows licence
2646f485
SC
10/////////////////////////////////////////////////////////////////////////////
11
2646f485
SC
12#include "wx/defs.h"
13
14#include "wx/checkbox.h"
15
2646f485
SC
16IMPLEMENT_DYNAMIC_CLASS(wxCheckBox, wxControl)
17IMPLEMENT_DYNAMIC_CLASS(wxBitmapCheckBox, wxCheckBox)
2646f485
SC
18
19#include "wx/mac/uma.h"
20
21// Single check box item
22bool wxCheckBox::Create(wxWindow *parent, wxWindowID id, const wxString& label,
23 const wxPoint& pos,
24 const wxSize& size, long style,
25 const wxValidator& validator,
26 const wxString& name)
27{
28 if ( !wxCheckBoxBase::Create(parent, id, pos, size, style, validator, name) )
29 return false;
30
31 Rect bounds ;
32 Str255 title ;
33
34 MacPreControlCreate( parent , id , label , pos , size ,style, validator , name , &bounds , title ) ;
35
36 SInt16 maxValue = 1 /* kControlCheckboxCheckedValue */;
37 if (style & wxCHK_3STATE)
38 {
39 maxValue = 2 /* kControlCheckboxMixedValue */;
40 }
41
6bc3b8e9 42 m_macControl = (WXWidget) ::NewControl( MAC_WXHWND(parent->MacGetRootWindow()) , &bounds , title , false , 0 , 0 , maxValue,
2646f485
SC
43 kControlCheckBoxProc , (long) this ) ;
44
45 MacPostControlCreate() ;
46
47 return TRUE;
48}
49
50void wxCheckBox::SetValue(bool val)
51{
52 if (val)
53 {
54 Set3StateValue(wxCHK_CHECKED);
55 }
56 else
57 {
58 Set3StateValue(wxCHK_UNCHECKED);
59 }
60}
61
62bool wxCheckBox::GetValue() const
63{
64 return (DoGet3StateValue() != 0);
65}
66
67void wxCheckBox::Command (wxCommandEvent & event)
68{
69 int state = event.GetInt();
70
71 wxCHECK_RET( (state == wxCHK_UNCHECKED) || (state == wxCHK_CHECKED)
72 || (state == wxCHK_UNDETERMINED),
73 wxT("event.GetInt() returned an invalid checkbox state") );
74
75 Set3StateValue((wxCheckBoxState) state);
76
77 ProcessCommand(event);
78}
79
80wxCheckBoxState wxCheckBox::DoGet3StateValue() const
81{
82 return (wxCheckBoxState) ::GetControl32BitValue( (ControlHandle) m_macControl );
83}
84
85void wxCheckBox::DoSet3StateValue(wxCheckBoxState val)
86{
87 ::SetControl32BitValue( (ControlHandle) m_macControl , (int) val) ;
88 MacRedrawControl() ;
89}
90
91void wxCheckBox::MacHandleControlClick( WXWidget WXUNUSED(control), wxInt16 WXUNUSED(controlpart) , bool WXUNUSED(mouseStillDown) )
92{
93 wxCommandEvent event(wxEVT_COMMAND_CHECKBOX_CLICKED, m_windowId );
94 wxCheckBoxState state = Get3StateValue();
95
96 if (state == wxCHK_UNCHECKED)
97 {
98 state = wxCHK_CHECKED;
99 }
100 else if (state == wxCHK_CHECKED)
101 {
102 // If the style flag to allow the user setting the undetermined state
103 // is set, then set the state to undetermined. Otherwise set state to
104 // unchecked.
105 if ( Is3rdStateAllowedForUser() )
106 {
107 state = wxCHK_UNDETERMINED;
108 }
109 else
110 {
111 state = wxCHK_UNCHECKED;
112 }
113 }
114 else if (state == wxCHK_UNDETERMINED)
115 {
116 state = wxCHK_UNCHECKED;
117 }
118 Set3StateValue(state);
119
120 event.SetInt(state);
121 event.SetEventObject(this);
122 ProcessCommand(event);
123}
124
125// Bitmap checkbox
126bool wxBitmapCheckBox::Create(wxWindow *parent, wxWindowID id,
127 const wxBitmap *label,
128 const wxPoint& pos,
129 const wxSize& size, long style,
130 const wxValidator& validator,
131 const wxString& name)
132{
133 SetName(name);
134 SetValidator(validator);
135 m_windowStyle = style;
136
137 if (parent) parent->AddChild(this);
138
139 if ( id == -1 )
140 m_windowId = NewControlId();
141 else
142 m_windowId = id;
143
144 // TODO: Create the bitmap checkbox
145
146 return FALSE;
147}
148
149void wxBitmapCheckBox::SetLabel(const wxBitmap *bitmap)
150{
151 // TODO
152 wxFAIL_MSG(wxT("wxBitmapCheckBox::SetLabel() not yet implemented"));
153}
154
155void wxBitmapCheckBox::SetSize(int x, int y, int width, int height, int sizeFlags)
156{
157 wxControl::SetSize( x , y , width , height , sizeFlags ) ;
158}
159
160void wxBitmapCheckBox::SetValue(bool val)
161{
162 // TODO
163 wxFAIL_MSG(wxT("wxBitmapCheckBox::SetValue() not yet implemented"));
164}
165
166bool wxBitmapCheckBox::GetValue() const
167{
168 // TODO
169 wxFAIL_MSG(wxT("wxBitmapCheckBox::GetValue() not yet implemented"));
170 return FALSE;
171}
172
173