]>
Commit | Line | Data |
---|---|---|
1 | ///////////////////////////////////////////////////////////////////////////// | |
2 | // Name: 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" | |
17 | ||
18 | IMPLEMENT_DYNAMIC_CLASS(wxCheckBox, wxControl) | |
19 | IMPLEMENT_DYNAMIC_CLASS(wxBitmapCheckBox, wxCheckBox) | |
20 | ||
21 | #include "wx/mac/uma.h" | |
22 | ||
23 | // Single check box item | |
24 | bool wxCheckBox::Create(wxWindow *parent, wxWindowID id, const wxString& label, | |
25 | const wxPoint& pos, | |
26 | const wxSize& size, long style, | |
27 | const wxValidator& validator, | |
28 | const wxString& name) | |
29 | { | |
30 | m_macIsUserPane = FALSE ; | |
31 | ||
32 | if ( !wxCheckBoxBase::Create(parent, id, pos, size, style, validator, name) ) | |
33 | return false; | |
34 | ||
35 | m_label = label ; | |
36 | ||
37 | SInt32 maxValue = 1 /* kControlCheckboxCheckedValue */; | |
38 | if (style & wxCHK_3STATE) | |
39 | maxValue = 2 /* kControlCheckboxMixedValue */; | |
40 | ||
41 | Rect bounds = wxMacGetBoundsForControl( this , pos , size ) ; | |
42 | m_peer = new wxMacControl(this) ; | |
43 | verify_noerr( CreateCheckBoxControl(MAC_WXHWND(parent->MacGetTopLevelWindowRef()), &bounds , | |
44 | CFSTR("") , 0 , false , m_peer->GetControlRefAddr() ) ); | |
45 | ||
46 | m_peer->SetMaximum( maxValue ) ; | |
47 | ||
48 | MacPostControlCreate(pos,size) ; | |
49 | ||
50 | return TRUE; | |
51 | } | |
52 | ||
53 | void wxCheckBox::SetValue(bool val) | |
54 | { | |
55 | if (val) | |
56 | { | |
57 | Set3StateValue(wxCHK_CHECKED); | |
58 | } | |
59 | else | |
60 | { | |
61 | Set3StateValue(wxCHK_UNCHECKED); | |
62 | } | |
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 | wxCommandEvent event(wxEVT_COMMAND_CHECKBOX_CLICKED, m_windowId ); | |
96 | wxCheckBoxState state = Get3StateValue(); | |
97 | ||
98 | if (state == wxCHK_UNCHECKED) | |
99 | { | |
100 | state = wxCHK_CHECKED; | |
101 | } | |
102 | else if (state == wxCHK_CHECKED) | |
103 | { | |
104 | // If the style flag to allow the user setting the undetermined state | |
105 | // is set, then set the state to undetermined. Otherwise set state to | |
106 | // unchecked. | |
107 | if ( Is3rdStateAllowedForUser() ) | |
108 | { | |
109 | state = wxCHK_UNDETERMINED; | |
110 | } | |
111 | else | |
112 | { | |
113 | state = wxCHK_UNCHECKED; | |
114 | } | |
115 | } | |
116 | else if (state == wxCHK_UNDETERMINED) | |
117 | { | |
118 | state = wxCHK_UNCHECKED; | |
119 | } | |
120 | Set3StateValue(state); | |
121 | ||
122 | event.SetInt(state); | |
123 | event.SetEventObject(this); | |
124 | ProcessCommand(event); | |
125 | ||
126 | return noErr ; | |
127 | } | |
128 | ||
129 | // Bitmap checkbox | |
130 | bool 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 | ||
150 | return FALSE; | |
151 | } | |
152 | ||
153 | void wxBitmapCheckBox::SetLabel(const wxBitmap *bitmap) | |
154 | { | |
155 | // TODO | |
156 | wxFAIL_MSG(wxT("wxBitmapCheckBox::SetLabel() not yet implemented")); | |
157 | } | |
158 | ||
159 | void wxBitmapCheckBox::SetSize(int x, int y, int width, int height, int sizeFlags) | |
160 | { | |
161 | wxControl::SetSize( x , y , width , height , sizeFlags ) ; | |
162 | } | |
163 | ||
164 | void wxBitmapCheckBox::SetValue(bool val) | |
165 | { | |
166 | // TODO | |
167 | wxFAIL_MSG(wxT("wxBitmapCheckBox::SetValue() not yet implemented")); | |
168 | } | |
169 | ||
170 | bool wxBitmapCheckBox::GetValue() const | |
171 | { | |
172 | // TODO | |
173 | wxFAIL_MSG(wxT("wxBitmapCheckBox::GetValue() not yet implemented")); | |
174 | return FALSE; | |
175 | } | |
176 | ||
177 | #endif |