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