]>
Commit | Line | Data |
---|---|---|
e53b3d16 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: checkbox.cpp 54129 2008-06-11 19:30:52Z 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 | ||
19 | IMPLEMENT_DYNAMIC_CLASS(wxCheckBox, wxControl) | |
20 | IMPLEMENT_DYNAMIC_CLASS(wxBitmapCheckBox, wxCheckBox) | |
21 | ||
22 | // Single check box item | |
23 | bool wxCheckBox::Create(wxWindow *parent, | |
24 | wxWindowID id, | |
25 | const wxString& label, | |
26 | const wxPoint& pos, | |
27 | const wxSize& size, | |
28 | long style, | |
29 | const wxValidator& validator, | |
30 | const wxString& name) | |
31 | { | |
32 | m_macIsUserPane = false ; | |
33 | ||
34 | if ( !wxCheckBoxBase::Create(parent, id, pos, size, style, validator, name) ) | |
35 | return false; | |
36 | ||
37 | m_labelOrig = m_label = label ; | |
38 | ||
39 | m_peer = wxWidgetImpl::CreateCheckBox( this, parent, id, label, pos, size, style, GetExtraStyle() ) ; | |
40 | ||
41 | MacPostControlCreate(pos, size) ; | |
42 | ||
43 | return true; | |
44 | } | |
45 | ||
46 | ||
47 | void wxCheckBox::SetValue(bool val) | |
48 | { | |
49 | if (val) | |
50 | Set3StateValue(wxCHK_CHECKED); | |
51 | else | |
52 | Set3StateValue(wxCHK_UNCHECKED); | |
53 | } | |
54 | ||
55 | bool wxCheckBox::GetValue() const | |
56 | { | |
57 | return (DoGet3StateValue() != 0); | |
58 | } | |
59 | ||
60 | void 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 | ||
73 | wxCheckBoxState wxCheckBox::DoGet3StateValue() const | |
74 | { | |
75 | return (wxCheckBoxState)m_peer->GetValue() ; | |
76 | } | |
77 | ||
78 | void wxCheckBox::DoSet3StateValue(wxCheckBoxState val) | |
79 | { | |
80 | m_peer->SetValue( val ) ; | |
81 | } | |
82 | ||
83 | bool wxCheckBox::HandleClicked( double timestampsec ) | |
84 | { | |
85 | wxCheckBoxState origState, newState; | |
86 | ||
87 | newState = origState = Get3StateValue(); | |
88 | ||
89 | switch (origState) | |
90 | { | |
91 | case wxCHK_UNCHECKED: | |
92 | newState = wxCHK_CHECKED; | |
93 | break; | |
94 | ||
95 | case wxCHK_CHECKED: | |
96 | // If the style flag to allow the user setting the undetermined state is set, | |
97 | // then set the state to undetermined; otherwise set state to unchecked. | |
98 | newState = Is3rdStateAllowedForUser() ? wxCHK_UNDETERMINED : wxCHK_UNCHECKED; | |
99 | break; | |
100 | ||
101 | case wxCHK_UNDETERMINED: | |
102 | newState = wxCHK_UNCHECKED; | |
103 | break; | |
104 | ||
105 | default: | |
106 | break; | |
107 | } | |
108 | ||
109 | if (newState != origState) | |
110 | { | |
111 | Set3StateValue( newState ); | |
112 | ||
113 | wxCommandEvent event( wxEVT_COMMAND_CHECKBOX_CLICKED, m_windowId ); | |
114 | event.SetInt( newState ); | |
115 | event.SetEventObject( this ); | |
116 | ProcessCommand( event ); | |
117 | } | |
118 | ||
119 | return true; | |
120 | } | |
121 | ||
122 | // Bitmap checkbox | |
123 | bool wxBitmapCheckBox::Create(wxWindow *parent, | |
124 | wxWindowID id, | |
125 | const wxBitmap *WXUNUSED(label), | |
126 | const wxPoint& WXUNUSED(pos), | |
127 | const wxSize& WXUNUSED(size), | |
128 | long style, | |
129 | const wxValidator& wxVALIDATOR_PARAM(validator), | |
130 | const wxString& name) | |
131 | { | |
132 | SetName(name); | |
133 | #if wxUSE_VALIDATORS | |
134 | SetValidator(validator); | |
135 | #endif | |
136 | m_windowStyle = style; | |
137 | ||
138 | if (parent) | |
139 | parent->AddChild(this); | |
140 | ||
141 | if ( id == -1 ) | |
142 | m_windowId = NewControlId(); | |
143 | else | |
144 | m_windowId = id; | |
145 | ||
146 | // TODO: Create the bitmap checkbox | |
147 | ||
148 | return false; | |
149 | } | |
150 | ||
151 | void wxBitmapCheckBox::SetLabel(const wxBitmap *WXUNUSED(bitmap)) | |
152 | { | |
153 | // TODO | |
154 | wxFAIL_MSG(wxT("wxBitmapCheckBox::SetLabel() not yet implemented")); | |
155 | } | |
156 | ||
157 | void wxBitmapCheckBox::SetSize(int x, int y, int width, int height, int sizeFlags) | |
158 | { | |
159 | wxControl::SetSize( x , y , width , height , sizeFlags ) ; | |
160 | } | |
161 | ||
162 | void wxBitmapCheckBox::SetValue(bool WXUNUSED(val)) | |
163 | { | |
164 | // TODO | |
165 | wxFAIL_MSG(wxT("wxBitmapCheckBox::SetValue() not yet implemented")); | |
166 | } | |
167 | ||
168 | bool wxBitmapCheckBox::GetValue() const | |
169 | { | |
170 | // TODO | |
171 | wxFAIL_MSG(wxT("wxBitmapCheckBox::GetValue() not yet implemented")); | |
172 | ||
173 | return false; | |
174 | } | |
175 | ||
176 | #endif |