]>
Commit | Line | Data |
---|---|---|
ffecfa5a | 1 | ///////////////////////////////////////////////////////////////////////////// |
e2731512 | 2 | // Name: src/palmos/control.cpp |
ffecfa5a | 3 | // Purpose: wxControl class |
e2731512 | 4 | // Author: William Osborne - minimal working wxPalmOS port |
bdb54365 | 5 | // Modified by: Wlodzimierz ABX Skiba - native implementation |
ffecfa5a | 6 | // Created: 10/13/04 |
e2731512 | 7 | // RCS-ID: $Id$ |
bdb54365 | 8 | // Copyright: (c) William Osborne, Wlodzimierz Skiba |
ffecfa5a JS |
9 | // Licence: wxWindows licence |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | // ============================================================================ | |
13 | // declarations | |
14 | // ============================================================================ | |
15 | ||
16 | // ---------------------------------------------------------------------------- | |
17 | // headers | |
18 | // ---------------------------------------------------------------------------- | |
19 | ||
20 | #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) | |
21 | #pragma implementation "control.h" | |
22 | #endif | |
23 | ||
24 | // For compilers that support precompilation, includes "wx.h". | |
25 | #include "wx/wxprec.h" | |
26 | ||
27 | #ifdef __BORLANDC__ | |
28 | #pragma hdrstop | |
29 | #endif | |
30 | ||
31 | #if wxUSE_CONTROLS | |
32 | ||
33 | #ifndef WX_PRECOMP | |
34 | #include "wx/event.h" | |
35 | #include "wx/app.h" | |
36 | #include "wx/dcclient.h" | |
37 | #include "wx/log.h" | |
38 | #include "wx/settings.h" | |
39 | #endif | |
40 | ||
41 | #include "wx/control.h" | |
bdb54365 WS |
42 | #include "wx/toplevel.h" |
43 | #include "wx/button.h" | |
44 | #include "wx/checkbox.h" | |
45 | #include "wx/tglbtn.h" | |
808e3bce | 46 | #include "wx/radiobut.h" |
ffecfa5a JS |
47 | |
48 | // ---------------------------------------------------------------------------- | |
49 | // wxWin macros | |
50 | // ---------------------------------------------------------------------------- | |
51 | ||
52 | IMPLEMENT_ABSTRACT_CLASS(wxControl, wxWindow) | |
53 | ||
54 | BEGIN_EVENT_TABLE(wxControl, wxWindow) | |
55 | EVT_ERASE_BACKGROUND(wxControl::OnEraseBackground) | |
56 | END_EVENT_TABLE() | |
57 | ||
58 | // ============================================================================ | |
59 | // wxControl implementation | |
60 | // ============================================================================ | |
61 | ||
62 | // ---------------------------------------------------------------------------- | |
63 | // wxControl ctor/dtor | |
64 | // ---------------------------------------------------------------------------- | |
65 | ||
66 | wxControl::~wxControl() | |
67 | { | |
db101bd3 | 68 | m_isBeingDeleted = true; |
ffecfa5a JS |
69 | } |
70 | ||
71 | // ---------------------------------------------------------------------------- | |
72 | // control window creation | |
73 | // ---------------------------------------------------------------------------- | |
74 | ||
75 | bool wxControl::Create(wxWindow *parent, | |
76 | wxWindowID id, | |
77 | const wxPoint& pos, | |
78 | const wxSize& size, | |
79 | long style, | |
80 | const wxValidator& wxVALIDATOR_PARAM(validator), | |
81 | const wxString& name) | |
82 | { | |
83 | if ( !wxWindow::Create(parent, id, pos, size, style, name) ) | |
db101bd3 | 84 | return false; |
ffecfa5a JS |
85 | |
86 | #if wxUSE_VALIDATORS | |
87 | SetValidator(validator); | |
88 | #endif | |
89 | ||
db101bd3 | 90 | return true; |
ffecfa5a JS |
91 | } |
92 | ||
db101bd3 WS |
93 | bool wxControl::PalmCreateControl(ControlStyleType style, |
94 | wxWindow *parent, | |
95 | wxWindowID id, | |
96 | const wxString& label, | |
97 | const wxPoint& pos, | |
98 | const wxSize& size) | |
ffecfa5a | 99 | { |
ba889513 WS |
100 | SetParent(parent); |
101 | SetId( id == wxID_ANY ? NewControlId() : id ); | |
102 | FormType* form = GetParentForm(); | |
103 | if(form==NULL) | |
bdb54365 | 104 | return false; |
bdb54365 | 105 | |
ba889513 | 106 | m_label = label; |
bdb54365 WS |
107 | |
108 | m_control = CtlNewControl( | |
db101bd3 | 109 | (void **)&form, |
ba889513 | 110 | GetId(), |
db101bd3 | 111 | style, |
ba889513 WS |
112 | m_label.c_str(), |
113 | ( pos.x == wxDefaultCoord ) ? winUndefConstraint : pos.x, | |
114 | ( pos.y == wxDefaultCoord ) ? winUndefConstraint : pos.y, | |
115 | ( size.x == wxDefaultCoord ) ? winUndefConstraint : size.x, | |
116 | ( size.y == wxDefaultCoord ) ? winUndefConstraint : size.y, | |
808e3bce | 117 | stdFont, |
db101bd3 WS |
118 | 0, |
119 | false | |
120 | ); | |
121 | ||
122 | if(m_control==NULL) | |
123 | return false; | |
124 | ||
db101bd3 WS |
125 | Show(); |
126 | return true; | |
ffecfa5a JS |
127 | } |
128 | ||
129 | // ---------------------------------------------------------------------------- | |
130 | // various accessors | |
131 | // ---------------------------------------------------------------------------- | |
132 | ||
ba889513 WS |
133 | FormType* wxControl::GetParentForm() const |
134 | { | |
135 | wxWindow* parentTLW = GetParent(); | |
136 | while ( parentTLW && !parentTLW->IsTopLevel() ) | |
137 | { | |
138 | parentTLW = parentTLW->GetParent(); | |
139 | } | |
140 | wxTopLevelWindowPalm* tlw = wxDynamicCast(parentTLW, wxTopLevelWindowPalm); | |
141 | if(!tlw) | |
142 | return NULL; | |
143 | return tlw->GetForm(); | |
144 | } | |
145 | ||
ffecfa5a JS |
146 | wxBorder wxControl::GetDefaultBorder() const |
147 | { | |
148 | // we want to automatically give controls a sunken style (confusingly, | |
149 | // it may not really mean sunken at all as we map it to WS_EX_CLIENTEDGE | |
150 | // which is not sunken at all under Windows XP -- rather, just the default) | |
151 | return wxBORDER_SUNKEN; | |
152 | } | |
153 | ||
ba889513 WS |
154 | void wxControl::SetIntValue(int val) |
155 | { | |
156 | FormType* form = GetParentForm(); | |
157 | if(form==NULL) | |
158 | return; | |
159 | uint16_t index = FrmGetObjectIndex(form, GetId()); | |
160 | if(index==frmInvalidObjectId) | |
161 | return; | |
162 | FrmSetControlValue(form, index, val); | |
163 | } | |
164 | ||
165 | void wxControl::SetBoolValue(bool val) | |
166 | { | |
167 | SetIntValue(val?1:0); | |
168 | } | |
169 | ||
170 | bool wxControl::GetBoolValue() const | |
171 | { | |
172 | FormType* form = GetParentForm(); | |
173 | if(form==NULL) | |
174 | return false; | |
175 | uint16_t index = FrmGetObjectIndex(form, GetId()); | |
176 | if(index==frmInvalidObjectId) | |
177 | return false; | |
178 | return ( FrmGetControlValue(form, index) == 1 ); | |
179 | } | |
180 | ||
db101bd3 | 181 | wxSize wxControl::DoGetBestSize() const |
ffecfa5a | 182 | { |
db101bd3 | 183 | return wxSize(16, 16); |
ffecfa5a JS |
184 | } |
185 | ||
808e3bce WS |
186 | void wxControl::DoGetBounds( RectangleType &rect ) const |
187 | { | |
188 | FormType* form = GetParentForm(); | |
189 | if(form==NULL) | |
190 | return; | |
191 | uint16_t index = FrmGetObjectIndex(form,GetId()); | |
192 | if(index==frmInvalidObjectId) | |
193 | return; | |
194 | FrmGetObjectBounds(form,index,&rect); | |
195 | } | |
196 | ||
197 | void wxControl::DoGetPosition( int *x, int *y ) const | |
198 | { | |
199 | RectangleType rect; | |
200 | DoGetBounds(rect); | |
201 | if(x) | |
202 | *x = rect.topLeft.x; | |
203 | if(y) | |
204 | *y = rect.topLeft.y; | |
205 | } | |
206 | ||
207 | void wxControl::DoGetSize( int *width, int *height ) const | |
208 | { | |
209 | RectangleType rect; | |
210 | DoGetBounds(rect); | |
211 | if(width) | |
212 | *width = rect.extent.x; | |
213 | if(height) | |
214 | *height = rect.extent.y; | |
215 | } | |
216 | ||
db101bd3 | 217 | bool wxControl::Enable(bool enable) |
ffecfa5a | 218 | { |
db101bd3 WS |
219 | if( m_control == NULL ) |
220 | return false; | |
221 | if( IsEnabled() == enable) | |
222 | return false; | |
223 | CtlSetEnabled( m_control, enable); | |
224 | return true; | |
225 | } | |
226 | ||
227 | bool wxControl::IsEnabled() const | |
228 | { | |
229 | if( m_control == NULL ) | |
230 | return false; | |
231 | return CtlEnabled(m_control); | |
232 | } | |
233 | ||
234 | bool wxControl::IsShown() const | |
235 | { | |
236 | return StatGetAttribute ( statAttrBarVisible , NULL ); | |
237 | } | |
238 | ||
239 | bool wxControl::Show( bool show ) | |
240 | { | |
ba889513 WS |
241 | FormType* form = GetParentForm(); |
242 | if(form==NULL) | |
243 | return false; | |
244 | uint16_t index = FrmGetObjectIndex(form,GetId()); | |
245 | if(index==frmInvalidObjectId) | |
246 | return false; | |
db101bd3 | 247 | if(show) |
ba889513 | 248 | FrmShowObject(form,index); |
db101bd3 | 249 | else |
ba889513 | 250 | FrmHideObject(form,index); |
db101bd3 | 251 | return true; |
ffecfa5a JS |
252 | } |
253 | ||
bdb54365 WS |
254 | void wxControl::SetLabel(const wxString& label) |
255 | { | |
256 | // setting in wrong control causes crash | |
257 | if ( ( wxDynamicCast(this,wxButton) != NULL ) || | |
258 | ( wxDynamicCast(this,wxCheckBox) != NULL ) || | |
808e3bce | 259 | ( wxDynamicCast(this,wxRadioButton) != NULL ) || |
bdb54365 WS |
260 | ( wxDynamicCast(this,wxToggleButton) != NULL ) ) |
261 | { | |
ba889513 WS |
262 | m_label = label; |
263 | // TODO: as manual states, it crashes here | |
264 | // needs own manipulation on used string pointers | |
265 | // CtlSetLabel(m_control,m_label); | |
bdb54365 WS |
266 | } |
267 | } | |
268 | ||
269 | wxString wxControl::GetLabel() | |
270 | { | |
271 | // setting in wrong control causes crash | |
272 | if ( wxDynamicCast(this,wxButton) || | |
273 | wxDynamicCast(this,wxCheckBox) || | |
808e3bce | 274 | wxDynamicCast(this,wxRadioButton) || |
bdb54365 WS |
275 | wxDynamicCast(this,wxToggleButton) ) |
276 | { | |
ba889513 | 277 | return m_label; |
bdb54365 WS |
278 | } |
279 | ||
280 | return wxEmptyString; | |
281 | } | |
282 | ||
ffecfa5a JS |
283 | /* static */ wxVisualAttributes |
284 | wxControl::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant)) | |
285 | { | |
286 | wxVisualAttributes attrs; | |
287 | ||
288 | // old school (i.e. not "common") controls use the standard dialog font | |
289 | // by default | |
290 | attrs.font = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT); | |
291 | ||
292 | // most, or at least many, of the controls use the same colours as the | |
293 | // buttons -- others will have to override this (and possibly simply call | |
294 | // GetCompositeControlsDefaultAttributes() from their versions) | |
295 | attrs.colFg = wxSystemSettings::GetColour(wxSYS_COLOUR_BTNTEXT); | |
296 | attrs.colBg = wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE); | |
297 | ||
298 | return attrs; | |
299 | } | |
300 | ||
301 | // another version for the "composite", i.e. non simple controls | |
302 | /* static */ wxVisualAttributes | |
303 | wxControl::GetCompositeControlsDefaultAttributes(wxWindowVariant WXUNUSED(variant)) | |
304 | { | |
305 | wxVisualAttributes attrs; | |
306 | attrs.font = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT); | |
307 | attrs.colFg = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT); | |
308 | attrs.colBg = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW); | |
309 | ||
310 | return attrs; | |
311 | } | |
312 | ||
313 | // ---------------------------------------------------------------------------- | |
314 | // message handling | |
315 | // ---------------------------------------------------------------------------- | |
316 | ||
317 | bool wxControl::ProcessCommand(wxCommandEvent& event) | |
318 | { | |
319 | return GetEventHandler()->ProcessEvent(event); | |
320 | } | |
321 | ||
ffecfa5a JS |
322 | void wxControl::OnEraseBackground(wxEraseEvent& event) |
323 | { | |
324 | } | |
325 | ||
326 | WXHBRUSH wxControl::OnCtlColor(WXHDC pDC, WXHWND WXUNUSED(pWnd), WXUINT WXUNUSED(nCtlColor), | |
ffecfa5a JS |
327 | WXUINT WXUNUSED(message), |
328 | WXWPARAM WXUNUSED(wParam), | |
329 | WXLPARAM WXUNUSED(lParam) | |
ffecfa5a JS |
330 | ) |
331 | { | |
332 | return (WXHBRUSH)0; | |
333 | } | |
334 | ||
335 | // --------------------------------------------------------------------------- | |
336 | // global functions | |
337 | // --------------------------------------------------------------------------- | |
338 | ||
339 | #endif // wxUSE_CONTROLS |