]>
Commit | Line | Data |
---|---|---|
e9576ca5 | 1 | ///////////////////////////////////////////////////////////////////////////// |
f3078f07 | 2 | // Name: src/mac/carbon/checkbox.cpp |
e9576ca5 | 3 | // Purpose: wxCheckBox |
a31a5f85 | 4 | // Author: Stefan Csomor |
e9576ca5 SC |
5 | // Modified by: |
6 | // Created: 04/01/98 | |
7 | // RCS-ID: $Id$ | |
a31a5f85 | 8 | // Copyright: (c) Stefan Csomor |
65571936 | 9 | // Licence: wxWindows licence |
e9576ca5 SC |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
a8e9860d | 12 | #include "wx/wxprec.h" |
d8c736e5 | 13 | |
179e085f RN |
14 | #if wxUSE_CHECKBOX |
15 | ||
e9576ca5 | 16 | #include "wx/checkbox.h" |
bcb3a164 DS |
17 | #include "wx/mac/uma.h" |
18 | ||
e9576ca5 | 19 | |
e9576ca5 SC |
20 | IMPLEMENT_DYNAMIC_CLASS(wxCheckBox, wxControl) |
21 | IMPLEMENT_DYNAMIC_CLASS(wxBitmapCheckBox, wxCheckBox) | |
e9576ca5 | 22 | |
519cb848 | 23 | |
e9576ca5 | 24 | // Single check box item |
bcb3a164 DS |
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) | |
e9576ca5 | 33 | { |
bcb3a164 DS |
34 | m_macIsUserPane = false ; |
35 | ||
b45ed7a2 VZ |
36 | if ( !wxCheckBoxBase::Create(parent, id, pos, size, style, validator, name) ) |
37 | return false; | |
38 | ||
ab0f37b9 | 39 | m_labelOrig = m_label = label ; |
e9576ca5 | 40 | |
4c37f124 | 41 | SInt32 maxValue = 1 /* kControlCheckboxCheckedValue */; |
9c9ceb48 | 42 | if (style & wxCHK_3STATE) |
8941fa88 | 43 | maxValue = 2 /* kControlCheckboxMixedValue */; |
facd6764 SC |
44 | |
45 | Rect bounds = wxMacGetBoundsForControl( this , pos , size ) ; | |
bcb3a164 | 46 | m_peer = new wxMacControl( this ) ; |
4c37f124 | 47 | verify_noerr( CreateCheckBoxControl(MAC_WXHWND(parent->MacGetTopLevelWindowRef()), &bounds , |
5ca0d812 | 48 | CFSTR("") , 0 , false , m_peer->GetControlRefAddr() ) ); |
bcb3a164 | 49 | |
21fd5529 | 50 | m_peer->SetMaximum( maxValue ) ; |
e9576ca5 | 51 | |
bcb3a164 DS |
52 | MacPostControlCreate(pos, size) ; |
53 | ||
54 | return true; | |
e9576ca5 SC |
55 | } |
56 | ||
57 | void wxCheckBox::SetValue(bool val) | |
58 | { | |
8941fa88 | 59 | if (val) |
8941fa88 | 60 | Set3StateValue(wxCHK_CHECKED); |
8941fa88 | 61 | else |
8941fa88 | 62 | Set3StateValue(wxCHK_UNCHECKED); |
e9576ca5 SC |
63 | } |
64 | ||
65 | bool wxCheckBox::GetValue() const | |
66 | { | |
8941fa88 | 67 | return (DoGet3StateValue() != 0); |
e9576ca5 SC |
68 | } |
69 | ||
bcb3a164 | 70 | void wxCheckBox::Command(wxCommandEvent & event) |
e9576ca5 | 71 | { |
8941fa88 VZ |
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 | ||
bcb3a164 | 78 | Set3StateValue((wxCheckBoxState)state); |
8941fa88 VZ |
79 | |
80 | ProcessCommand(event); | |
81 | } | |
82 | ||
83 | wxCheckBoxState wxCheckBox::DoGet3StateValue() const | |
84 | { | |
bcb3a164 | 85 | return (wxCheckBoxState)m_peer->GetValue() ; |
8941fa88 VZ |
86 | } |
87 | ||
88 | void wxCheckBox::DoSet3StateValue(wxCheckBoxState val) | |
89 | { | |
21fd5529 | 90 | m_peer->SetValue( val ) ; |
e9576ca5 SC |
91 | } |
92 | ||
bcb3a164 | 93 | wxInt32 wxCheckBox::MacControlHit( WXEVENTHANDLERREF WXUNUSED(handler) , WXEVENTREF WXUNUSED(event) ) |
519cb848 | 94 | { |
bcb3a164 | 95 | wxCheckBoxState origState, newState; |
8941fa88 | 96 | |
bcb3a164 DS |
97 | newState = origState = Get3StateValue(); |
98 | ||
99 | switch (origState) | |
8941fa88 | 100 | { |
f3078f07 | 101 | case wxCHK_UNCHECKED: |
bcb3a164 DS |
102 | newState = wxCHK_CHECKED; |
103 | break; | |
104 | ||
f3078f07 | 105 | case wxCHK_CHECKED: |
bcb3a164 DS |
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 | ||
f3078f07 | 111 | case wxCHK_UNDETERMINED: |
bcb3a164 DS |
112 | newState = wxCHK_UNCHECKED; |
113 | break; | |
114 | ||
f3078f07 | 115 | default: |
bcb3a164 | 116 | break; |
8941fa88 | 117 | } |
bcb3a164 DS |
118 | |
119 | if (newState != origState) | |
8941fa88 | 120 | { |
bcb3a164 | 121 | Set3StateValue( newState ); |
8941fa88 | 122 | |
bcb3a164 DS |
123 | wxCommandEvent event( wxEVT_COMMAND_CHECKBOX_CLICKED, m_windowId ); |
124 | event.SetInt( newState ); | |
125 | event.SetEventObject( this ); | |
126 | ProcessCommand( event ); | |
127 | } | |
4c37f124 | 128 | |
bcb3a164 | 129 | return noErr; |
519cb848 SC |
130 | } |
131 | ||
e9576ca5 | 132 | // Bitmap checkbox |
bcb3a164 DS |
133 | bool wxBitmapCheckBox::Create(wxWindow *parent, |
134 | wxWindowID id, | |
89954433 VZ |
135 | const wxBitmap *WXUNUSED(label), |
136 | const wxPoint& WXUNUSED(pos), | |
137 | const wxSize& WXUNUSED(size), | |
bcb3a164 | 138 | long style, |
43147cef | 139 | const wxValidator& wxVALIDATOR_PARAM(validator), |
bcb3a164 | 140 | const wxString& name) |
e9576ca5 SC |
141 | { |
142 | SetName(name); | |
43147cef | 143 | #if wxUSE_VALIDATORS |
e9576ca5 | 144 | SetValidator(validator); |
43147cef | 145 | #endif |
e9576ca5 SC |
146 | m_windowStyle = style; |
147 | ||
bcb3a164 DS |
148 | if (parent) |
149 | parent->AddChild(this); | |
e9576ca5 SC |
150 | |
151 | if ( id == -1 ) | |
152 | m_windowId = NewControlId(); | |
153 | else | |
154 | m_windowId = id; | |
155 | ||
156 | // TODO: Create the bitmap checkbox | |
157 | ||
bcb3a164 | 158 | return false; |
e9576ca5 SC |
159 | } |
160 | ||
89954433 | 161 | void wxBitmapCheckBox::SetLabel(const wxBitmap *WXUNUSED(bitmap)) |
e9576ca5 SC |
162 | { |
163 | // TODO | |
0c32c930 | 164 | wxFAIL_MSG(wxT("wxBitmapCheckBox::SetLabel() not yet implemented")); |
e9576ca5 SC |
165 | } |
166 | ||
167 | void wxBitmapCheckBox::SetSize(int x, int y, int width, int height, int sizeFlags) | |
168 | { | |
519cb848 | 169 | wxControl::SetSize( x , y , width , height , sizeFlags ) ; |
e9576ca5 SC |
170 | } |
171 | ||
89954433 | 172 | void wxBitmapCheckBox::SetValue(bool WXUNUSED(val)) |
e9576ca5 SC |
173 | { |
174 | // TODO | |
0c32c930 | 175 | wxFAIL_MSG(wxT("wxBitmapCheckBox::SetValue() not yet implemented")); |
e9576ca5 SC |
176 | } |
177 | ||
178 | bool wxBitmapCheckBox::GetValue() const | |
179 | { | |
0c32c930 GD |
180 | // TODO |
181 | wxFAIL_MSG(wxT("wxBitmapCheckBox::GetValue() not yet implemented")); | |
bcb3a164 DS |
182 | |
183 | return false; | |
e9576ca5 SC |
184 | } |
185 | ||
179e085f | 186 | #endif |