]> git.saurik.com Git - wxWidgets.git/blame - src/osx/checkbox_osx.cpp
Correctly align background brush when erasing owner drawn bitmaps in wxMSW.
[wxWidgets.git] / src / osx / checkbox_osx.cpp
CommitLineData
e53b3d16 1/////////////////////////////////////////////////////////////////////////////
80fdcdb9 2// Name: src/osx/checkbox_osx.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
e53b3d16
SC
19IMPLEMENT_DYNAMIC_CLASS(wxBitmapCheckBox, wxCheckBox)
20
21// Single check box item
22bool wxCheckBox::Create(wxWindow *parent,
23 wxWindowID id,
24 const wxString& label,
25 const wxPoint& pos,
26 const wxSize& size,
27 long style,
28 const wxValidator& validator,
29 const wxString& name)
d15694e8
SC
30{
31 DontCreatePeer();
32
e53b3d16
SC
33 if ( !wxCheckBoxBase::Create(parent, id, pos, size, style, validator, name) )
34 return false;
35
36 m_labelOrig = m_label = label ;
37
f254e242 38 WXValidateStyle( &style );
22756322 39 SetPeer(wxWidgetImpl::CreateCheckBox( this, parent, id, label, pos, size, style, GetExtraStyle() )) ;
e53b3d16
SC
40
41 MacPostControlCreate(pos, size) ;
42
43 return true;
44}
45
46
47void wxCheckBox::SetValue(bool val)
48{
49 if (val)
50 Set3StateValue(wxCHK_CHECKED);
51 else
52 Set3StateValue(wxCHK_UNCHECKED);
53}
54
55bool wxCheckBox::GetValue() const
56{
57 return (DoGet3StateValue() != 0);
58}
59
60void wxCheckBox::Command(wxCommandEvent & event)
61{
62 int state = event.GetInt();
63
64 wxCHECK_RET( (state == wxCHK_UNCHECKED) || (state == wxCHK_CHECKED)
65 || (state == wxCHK_UNDETERMINED),
66 wxT("event.GetInt() returned an invalid checkbox state") );
67
68 Set3StateValue((wxCheckBoxState)state);
69
70 ProcessCommand(event);
71}
72
73wxCheckBoxState wxCheckBox::DoGet3StateValue() const
74{
22756322 75 return (wxCheckBoxState)GetPeer()->GetValue() ;
e53b3d16
SC
76}
77
78void wxCheckBox::DoSet3StateValue(wxCheckBoxState val)
79{
22756322 80 GetPeer()->SetValue( val ) ;
e53b3d16
SC
81}
82
03647350 83bool wxCheckBox::OSXHandleClicked( double WXUNUSED(timestampsec) )
e53b3d16 84{
524c47aa
SC
85 bool sendEvent = true;
86 wxCheckBoxState newState = Get3StateValue();
03647350 87
22756322 88 if ( !GetPeer()->ButtonClickDidStateChange() )
e53b3d16 89 {
524c47aa
SC
90 wxCheckBoxState origState ;
91
92 newState = origState = Get3StateValue();
93
94 switch (origState)
95 {
96 case wxCHK_UNCHECKED:
97 newState = wxCHK_CHECKED;
98 break;
99
100 case wxCHK_CHECKED:
101 // If the style flag to allow the user setting the undetermined state is set,
102 // then set the state to undetermined; otherwise set state to unchecked.
103 newState = Is3rdStateAllowedForUser() ? wxCHK_UNDETERMINED : wxCHK_UNCHECKED;
104 break;
105
106 case wxCHK_UNDETERMINED:
107 newState = wxCHK_UNCHECKED;
108 break;
109
110 default:
111 break;
112 }
113 if (newState == origState)
114 sendEvent = false;
e53b3d16
SC
115 }
116
524c47aa 117 if (sendEvent)
e53b3d16
SC
118 {
119 Set3StateValue( newState );
120
121 wxCommandEvent event( wxEVT_COMMAND_CHECKBOX_CLICKED, m_windowId );
122 event.SetInt( newState );
123 event.SetEventObject( this );
124 ProcessCommand( event );
125 }
126
127 return true;
128}
129
130// Bitmap checkbox
131bool wxBitmapCheckBox::Create(wxWindow *parent,
132 wxWindowID id,
133 const wxBitmap *WXUNUSED(label),
134 const wxPoint& WXUNUSED(pos),
135 const wxSize& WXUNUSED(size),
136 long style,
137 const wxValidator& wxVALIDATOR_PARAM(validator),
138 const wxString& name)
139{
140 SetName(name);
141#if wxUSE_VALIDATORS
142 SetValidator(validator);
143#endif
144 m_windowStyle = style;
145
146 if (parent)
147 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 *WXUNUSED(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 WXUNUSED(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
181 return false;
182}
183
184#endif