]>
Commit | Line | Data |
---|---|---|
489468fe SC |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: src/mac/carbon/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 | #include "wx/wxprec.h" | |
13 | ||
14 | #if wxUSE_CHECKBOX | |
15 | ||
16 | #include "wx/checkbox.h" | |
1f0c8f31 | 17 | #include "wx/osx/uma.h" |
489468fe SC |
18 | |
19 | ||
20 | IMPLEMENT_DYNAMIC_CLASS(wxCheckBox, wxControl) | |
21 | IMPLEMENT_DYNAMIC_CLASS(wxBitmapCheckBox, wxCheckBox) | |
22 | ||
23 | ||
24 | // Single check box item | |
25 | bool wxCheckBox::Create(wxWindow *parent, | |
26 | wxWindowID id, | |
27 | const wxString& label, | |
28 | const wxPoint& pos, | |
29 | const wxSize& size, | |
30 | long style, | |
31 | const wxValidator& validator, | |
32 | const wxString& name) | |
33 | { | |
34 | m_macIsUserPane = false ; | |
35 | ||
36 | if ( !wxCheckBoxBase::Create(parent, id, pos, size, style, validator, name) ) | |
37 | return false; | |
38 | ||
39 | m_labelOrig = m_label = label ; | |
40 | ||
41 | SInt32 maxValue = 1 /* kControlCheckboxCheckedValue */; | |
42 | if (style & wxCHK_3STATE) | |
43 | maxValue = 2 /* kControlCheckboxMixedValue */; | |
44 | ||
45 | Rect bounds = wxMacGetBoundsForControl( this , pos , size ) ; | |
46 | m_peer = new wxMacControl( this ) ; | |
47 | verify_noerr( CreateCheckBoxControl(MAC_WXHWND(parent->MacGetTopLevelWindowRef()), &bounds , | |
48 | CFSTR("") , 0 , false , m_peer->GetControlRefAddr() ) ); | |
49 | ||
50 | m_peer->SetMaximum( maxValue ) ; | |
51 | ||
52 | MacPostControlCreate(pos, size) ; | |
53 | ||
54 | return true; | |
55 | } | |
56 | ||
57 | void wxCheckBox::SetValue(bool val) | |
58 | { | |
59 | if (val) | |
60 | Set3StateValue(wxCHK_CHECKED); | |
61 | else | |
62 | Set3StateValue(wxCHK_UNCHECKED); | |
63 | } | |
64 | ||
65 | bool wxCheckBox::GetValue() const | |
66 | { | |
67 | return (DoGet3StateValue() != 0); | |
68 | } | |
69 | ||
70 | void wxCheckBox::Command(wxCommandEvent & event) | |
71 | { | |
72 | int state = event.GetInt(); | |
73 | ||
74 | wxCHECK_RET( (state == wxCHK_UNCHECKED) || (state == wxCHK_CHECKED) | |
75 | || (state == wxCHK_UNDETERMINED), | |
76 | wxT("event.GetInt() returned an invalid checkbox state") ); | |
77 | ||
78 | Set3StateValue((wxCheckBoxState)state); | |
79 | ||
80 | ProcessCommand(event); | |
81 | } | |
82 | ||
83 | wxCheckBoxState wxCheckBox::DoGet3StateValue() const | |
84 | { | |
85 | return (wxCheckBoxState)m_peer->GetValue() ; | |
86 | } | |
87 | ||
88 | void wxCheckBox::DoSet3StateValue(wxCheckBoxState val) | |
89 | { | |
90 | m_peer->SetValue( val ) ; | |
91 | } | |
92 | ||
93 | wxInt32 wxCheckBox::MacControlHit( WXEVENTHANDLERREF WXUNUSED(handler) , WXEVENTREF WXUNUSED(event) ) | |
94 | { | |
95 | wxCheckBoxState origState, newState; | |
96 | ||
97 | newState = origState = Get3StateValue(); | |
98 | ||
99 | switch (origState) | |
100 | { | |
101 | case wxCHK_UNCHECKED: | |
102 | newState = wxCHK_CHECKED; | |
103 | break; | |
104 | ||
105 | case wxCHK_CHECKED: | |
106 | // If the style flag to allow the user setting the undetermined state is set, | |
107 | // then set the state to undetermined; otherwise set state to unchecked. | |
108 | newState = Is3rdStateAllowedForUser() ? wxCHK_UNDETERMINED : wxCHK_UNCHECKED; | |
109 | break; | |
110 | ||
111 | case wxCHK_UNDETERMINED: | |
112 | newState = wxCHK_UNCHECKED; | |
113 | break; | |
114 | ||
115 | default: | |
116 | break; | |
117 | } | |
118 | ||
119 | if (newState != origState) | |
120 | { | |
121 | Set3StateValue( newState ); | |
122 | ||
123 | wxCommandEvent event( wxEVT_COMMAND_CHECKBOX_CLICKED, m_windowId ); | |
124 | event.SetInt( newState ); | |
125 | event.SetEventObject( this ); | |
126 | ProcessCommand( event ); | |
127 | } | |
128 | ||
129 | return noErr; | |
130 | } | |
131 | ||
132 | // Bitmap checkbox | |
133 | bool wxBitmapCheckBox::Create(wxWindow *parent, | |
134 | wxWindowID id, | |
135 | const wxBitmap *WXUNUSED(label), | |
136 | const wxPoint& WXUNUSED(pos), | |
137 | const wxSize& WXUNUSED(size), | |
138 | long style, | |
139 | const wxValidator& wxVALIDATOR_PARAM(validator), | |
140 | const wxString& name) | |
141 | { | |
142 | SetName(name); | |
143 | #if wxUSE_VALIDATORS | |
144 | SetValidator(validator); | |
145 | #endif | |
146 | m_windowStyle = style; | |
147 | ||
148 | if (parent) | |
149 | parent->AddChild(this); | |
150 | ||
151 | if ( id == -1 ) | |
152 | m_windowId = NewControlId(); | |
153 | else | |
154 | m_windowId = id; | |
155 | ||
156 | // TODO: Create the bitmap checkbox | |
157 | ||
158 | return false; | |
159 | } | |
160 | ||
161 | void wxBitmapCheckBox::SetLabel(const wxBitmap *WXUNUSED(bitmap)) | |
162 | { | |
163 | // TODO | |
164 | wxFAIL_MSG(wxT("wxBitmapCheckBox::SetLabel() not yet implemented")); | |
165 | } | |
166 | ||
167 | void wxBitmapCheckBox::SetSize(int x, int y, int width, int height, int sizeFlags) | |
168 | { | |
169 | wxControl::SetSize( x , y , width , height , sizeFlags ) ; | |
170 | } | |
171 | ||
172 | void wxBitmapCheckBox::SetValue(bool WXUNUSED(val)) | |
173 | { | |
174 | // TODO | |
175 | wxFAIL_MSG(wxT("wxBitmapCheckBox::SetValue() not yet implemented")); | |
176 | } | |
177 | ||
178 | bool wxBitmapCheckBox::GetValue() const | |
179 | { | |
180 | // TODO | |
181 | wxFAIL_MSG(wxT("wxBitmapCheckBox::GetValue() not yet implemented")); | |
182 | ||
183 | return false; | |
184 | } | |
185 | ||
186 | #endif |