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