]> git.saurik.com Git - wxWidgets.git/blame - src/osx/checkbox_osx.cpp
Fix generic implementation of wxDC::GradientFillConcentric().
[wxWidgets.git] / src / osx / checkbox_osx.cpp
CommitLineData
e53b3d16 1/////////////////////////////////////////////////////////////////////////////
524c47aa 2// Name: src/osx/carbon/checkbox.cpp
e53b3d16
SC
3// Purpose: wxCheckBox
4// Author: Stefan Csomor
5// Modified by:
6// Created: 04/01/98
b5b208a1 7// RCS-ID: $Id$
e53b3d16
SC
8// Copyright: (c) Stefan Csomor
9// Licence: wxWindows licence
10/////////////////////////////////////////////////////////////////////////////
11
12#include "wx/wxprec.h"
13
14#if wxUSE_CHECKBOX
15
16#include "wx/checkbox.h"
17#include "wx/osx/private.h"
18
19IMPLEMENT_DYNAMIC_CLASS(wxCheckBox, wxControl)
20IMPLEMENT_DYNAMIC_CLASS(wxBitmapCheckBox, wxCheckBox)
21
22// Single check box item
23bool wxCheckBox::Create(wxWindow *parent,
24 wxWindowID id,
25 const wxString& label,
26 const wxPoint& pos,
27 const wxSize& size,
28 long style,
29 const wxValidator& validator,
30 const wxString& name)
31{
32 m_macIsUserPane = false ;
33
34 if ( !wxCheckBoxBase::Create(parent, id, pos, size, style, validator, name) )
35 return false;
36
37 m_labelOrig = m_label = label ;
38
f254e242 39 WXValidateStyle( &style );
e53b3d16
SC
40 m_peer = wxWidgetImpl::CreateCheckBox( this, parent, id, label, pos, size, style, GetExtraStyle() ) ;
41
42 MacPostControlCreate(pos, size) ;
43
44 return true;
45}
46
47
48void wxCheckBox::SetValue(bool val)
49{
50 if (val)
51 Set3StateValue(wxCHK_CHECKED);
52 else
53 Set3StateValue(wxCHK_UNCHECKED);
54}
55
56bool wxCheckBox::GetValue() const
57{
58 return (DoGet3StateValue() != 0);
59}
60
61void wxCheckBox::Command(wxCommandEvent & event)
62{
63 int state = event.GetInt();
64
65 wxCHECK_RET( (state == wxCHK_UNCHECKED) || (state == wxCHK_CHECKED)
66 || (state == wxCHK_UNDETERMINED),
67 wxT("event.GetInt() returned an invalid checkbox state") );
68
69 Set3StateValue((wxCheckBoxState)state);
70
71 ProcessCommand(event);
72}
73
74wxCheckBoxState wxCheckBox::DoGet3StateValue() const
75{
76 return (wxCheckBoxState)m_peer->GetValue() ;
77}
78
79void wxCheckBox::DoSet3StateValue(wxCheckBoxState val)
80{
81 m_peer->SetValue( val ) ;
82}
83
03647350 84bool wxCheckBox::OSXHandleClicked( double WXUNUSED(timestampsec) )
e53b3d16 85{
524c47aa
SC
86 bool sendEvent = true;
87 wxCheckBoxState newState = Get3StateValue();
03647350 88
524c47aa 89 if ( !m_peer->ButtonClickDidStateChange() )
e53b3d16 90 {
524c47aa
SC
91 wxCheckBoxState origState ;
92
93 newState = origState = Get3StateValue();
94
95 switch (origState)
96 {
97 case wxCHK_UNCHECKED:
98 newState = wxCHK_CHECKED;
99 break;
100
101 case wxCHK_CHECKED:
102 // If the style flag to allow the user setting the undetermined state is set,
103 // then set the state to undetermined; otherwise set state to unchecked.
104 newState = Is3rdStateAllowedForUser() ? wxCHK_UNDETERMINED : wxCHK_UNCHECKED;
105 break;
106
107 case wxCHK_UNDETERMINED:
108 newState = wxCHK_UNCHECKED;
109 break;
110
111 default:
112 break;
113 }
114 if (newState == origState)
115 sendEvent = false;
e53b3d16
SC
116 }
117
524c47aa 118 if (sendEvent)
e53b3d16
SC
119 {
120 Set3StateValue( newState );
121
122 wxCommandEvent event( wxEVT_COMMAND_CHECKBOX_CLICKED, m_windowId );
123 event.SetInt( newState );
124 event.SetEventObject( this );
125 ProcessCommand( event );
126 }
127
128 return true;
129}
130
131// Bitmap checkbox
132bool wxBitmapCheckBox::Create(wxWindow *parent,
133 wxWindowID id,
134 const wxBitmap *WXUNUSED(label),
135 const wxPoint& WXUNUSED(pos),
136 const wxSize& WXUNUSED(size),
137 long style,
138 const wxValidator& wxVALIDATOR_PARAM(validator),
139 const wxString& name)
140{
141 SetName(name);
142#if wxUSE_VALIDATORS
143 SetValidator(validator);
144#endif
145 m_windowStyle = style;
146
147 if (parent)
148 parent->AddChild(this);
149
150 if ( id == -1 )
151 m_windowId = NewControlId();
152 else
153 m_windowId = id;
154
155 // TODO: Create the bitmap checkbox
156
157 return false;
158}
159
160void wxBitmapCheckBox::SetLabel(const wxBitmap *WXUNUSED(bitmap))
161{
162 // TODO
163 wxFAIL_MSG(wxT("wxBitmapCheckBox::SetLabel() not yet implemented"));
164}
165
166void wxBitmapCheckBox::SetSize(int x, int y, int width, int height, int sizeFlags)
167{
168 wxControl::SetSize( x , y , width , height , sizeFlags ) ;
169}
170
171void wxBitmapCheckBox::SetValue(bool WXUNUSED(val))
172{
173 // TODO
174 wxFAIL_MSG(wxT("wxBitmapCheckBox::SetValue() not yet implemented"));
175}
176
177bool wxBitmapCheckBox::GetValue() const
178{
179 // TODO
180 wxFAIL_MSG(wxT("wxBitmapCheckBox::GetValue() not yet implemented"));
181
182 return false;
183}
184
185#endif