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