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