]> git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/checkbox.cpp
ATSU Support in font extended
[wxWidgets.git] / src / mac / carbon / checkbox.cpp
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
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
13 #pragma implementation "checkbox.h"
14 #endif
15
16 #include "wx/wxprec.h"
17
18 #include "wx/checkbox.h"
19
20 #if !USE_SHARED_LIBRARY
21 IMPLEMENT_DYNAMIC_CLASS(wxCheckBox, wxControl)
22 IMPLEMENT_DYNAMIC_CLASS(wxBitmapCheckBox, wxCheckBox)
23 #endif
24
25 #include "wx/mac/uma.h"
26
27 // Single check box item
28 bool 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 {
34 m_macIsUserPane = FALSE ;
35
36 if ( !wxCheckBoxBase::Create(parent, id, pos, size, style, validator, name) )
37 return false;
38
39 m_label = label ;
40
41 SInt32 maxValue = 1 /* kControlCheckboxCheckedValue */;
42 if (style & wxCHK_3STATE)
43 maxValue = 2 /* kControlCheckboxMixedValue */;
44
45 Rect bounds = wxMacGetBoundsForControl( this , pos , size ) ;
46 m_peer = new wxMacControl() ;
47 verify_noerr( CreateCheckBoxControl(MAC_WXHWND(parent->MacGetTopLevelWindowRef()), &bounds ,
48 CFSTR("") , 0 , false , m_peer->GetControlRefAddr() ) );
49
50 m_peer->SetMaximum( maxValue ) ;
51
52 MacPostControlCreate(pos,size) ;
53
54 return TRUE;
55 }
56
57 void wxCheckBox::SetValue(bool val)
58 {
59 if (val)
60 {
61 Set3StateValue(wxCHK_CHECKED);
62 }
63 else
64 {
65 Set3StateValue(wxCHK_UNCHECKED);
66 }
67 }
68
69 bool wxCheckBox::GetValue() const
70 {
71 return (DoGet3StateValue() != 0);
72 }
73
74 void wxCheckBox::Command (wxCommandEvent & event)
75 {
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
87 wxCheckBoxState wxCheckBox::DoGet3StateValue() const
88 {
89 return (wxCheckBoxState) m_peer->GetValue() ;
90 }
91
92 void wxCheckBox::DoSet3StateValue(wxCheckBoxState val)
93 {
94 m_peer->SetValue( val ) ;
95 }
96
97 wxInt32 wxCheckBox::MacControlHit(WXEVENTHANDLERREF WXUNUSED(handler) , WXEVENTREF WXUNUSED(event) )
98 {
99 wxCommandEvent event(wxEVT_COMMAND_CHECKBOX_CLICKED, m_windowId );
100 wxCheckBoxState state = Get3StateValue();
101
102 if (state == wxCHK_UNCHECKED)
103 {
104 state = wxCHK_CHECKED;
105 }
106 else if (state == wxCHK_CHECKED)
107 {
108 // If the style flag to allow the user setting the undetermined state
109 // is set, then set the state to undetermined. Otherwise set state to
110 // unchecked.
111 if ( Is3rdStateAllowedForUser() )
112 {
113 state = wxCHK_UNDETERMINED;
114 }
115 else
116 {
117 state = wxCHK_UNCHECKED;
118 }
119 }
120 else if (state == wxCHK_UNDETERMINED)
121 {
122 state = wxCHK_UNCHECKED;
123 }
124 Set3StateValue(state);
125
126 event.SetInt(state);
127 event.SetEventObject(this);
128 ProcessCommand(event);
129
130 return noErr ;
131 }
132
133 // Bitmap checkbox
134 bool wxBitmapCheckBox::Create(wxWindow *parent, wxWindowID id,
135 const wxBitmap *label,
136 const wxPoint& pos,
137 const wxSize& size, long style,
138 const wxValidator& validator,
139 const wxString& name)
140 {
141 SetName(name);
142 SetValidator(validator);
143 m_windowStyle = style;
144
145 if (parent) parent->AddChild(this);
146
147 if ( id == -1 )
148 m_windowId = NewControlId();
149 else
150 m_windowId = id;
151
152 // TODO: Create the bitmap checkbox
153
154 return FALSE;
155 }
156
157 void wxBitmapCheckBox::SetLabel(const wxBitmap *bitmap)
158 {
159 // TODO
160 wxFAIL_MSG(wxT("wxBitmapCheckBox::SetLabel() not yet implemented"));
161 }
162
163 void wxBitmapCheckBox::SetSize(int x, int y, int width, int height, int sizeFlags)
164 {
165 wxControl::SetSize( x , y , width , height , sizeFlags ) ;
166 }
167
168 void wxBitmapCheckBox::SetValue(bool val)
169 {
170 // TODO
171 wxFAIL_MSG(wxT("wxBitmapCheckBox::SetValue() not yet implemented"));
172 }
173
174 bool wxBitmapCheckBox::GetValue() const
175 {
176 // TODO
177 wxFAIL_MSG(wxT("wxBitmapCheckBox::GetValue() not yet implemented"));
178 return FALSE;
179 }
180
181