]>
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" |
a152561c | 47 | #include "wx/slider.h" |
ffecfa5a JS |
48 | |
49 | // ---------------------------------------------------------------------------- | |
50 | // wxWin macros | |
51 | // ---------------------------------------------------------------------------- | |
52 | ||
53 | IMPLEMENT_ABSTRACT_CLASS(wxControl, wxWindow) | |
54 | ||
55 | BEGIN_EVENT_TABLE(wxControl, wxWindow) | |
56 | EVT_ERASE_BACKGROUND(wxControl::OnEraseBackground) | |
57 | END_EVENT_TABLE() | |
58 | ||
59 | // ============================================================================ | |
60 | // wxControl implementation | |
61 | // ============================================================================ | |
62 | ||
63 | // ---------------------------------------------------------------------------- | |
64 | // wxControl ctor/dtor | |
65 | // ---------------------------------------------------------------------------- | |
66 | ||
a152561c WS |
67 | void wxControl::Init() |
68 | { | |
69 | m_palmControl = false; | |
70 | m_palmField = false; | |
71 | } | |
72 | ||
ffecfa5a JS |
73 | wxControl::~wxControl() |
74 | { | |
9a727a3b | 75 | SetLabel(wxEmptyString); |
db101bd3 | 76 | m_isBeingDeleted = true; |
ffecfa5a JS |
77 | } |
78 | ||
79 | // ---------------------------------------------------------------------------- | |
80 | // control window creation | |
81 | // ---------------------------------------------------------------------------- | |
82 | ||
83 | bool wxControl::Create(wxWindow *parent, | |
84 | wxWindowID id, | |
85 | const wxPoint& pos, | |
86 | const wxSize& size, | |
87 | long style, | |
88 | const wxValidator& wxVALIDATOR_PARAM(validator), | |
89 | const wxString& name) | |
90 | { | |
91 | if ( !wxWindow::Create(parent, id, pos, size, style, name) ) | |
db101bd3 | 92 | return false; |
ffecfa5a JS |
93 | |
94 | #if wxUSE_VALIDATORS | |
95 | SetValidator(validator); | |
96 | #endif | |
97 | ||
db101bd3 | 98 | return true; |
ffecfa5a JS |
99 | } |
100 | ||
db101bd3 | 101 | bool wxControl::PalmCreateControl(ControlStyleType style, |
db101bd3 WS |
102 | const wxString& label, |
103 | const wxPoint& pos, | |
a152561c WS |
104 | const wxSize& size, |
105 | int groupID) | |
ffecfa5a | 106 | { |
ba889513 WS |
107 | FormType* form = GetParentForm(); |
108 | if(form==NULL) | |
bdb54365 | 109 | return false; |
bdb54365 | 110 | |
a152561c WS |
111 | ControlType *control = CtlNewControl( |
112 | (void **)&form, | |
113 | GetId(), | |
114 | style, | |
9a727a3b | 115 | wxEmptyString, |
a152561c WS |
116 | ( pos.x == wxDefaultCoord ) ? winUndefConstraint : pos.x, |
117 | ( pos.y == wxDefaultCoord ) ? winUndefConstraint : pos.y, | |
118 | ( size.x == wxDefaultCoord ) ? winUndefConstraint : size.x, | |
119 | ( size.y == wxDefaultCoord ) ? winUndefConstraint : size.y, | |
120 | stdFont, | |
121 | groupID, | |
122 | false | |
123 | ); | |
124 | ||
125 | if(control==NULL) | |
db101bd3 WS |
126 | return false; |
127 | ||
a152561c WS |
128 | m_palmControl = true; |
129 | ||
9a727a3b | 130 | SetLabel(label); |
db101bd3 WS |
131 | Show(); |
132 | return true; | |
ffecfa5a JS |
133 | } |
134 | ||
a152561c WS |
135 | bool wxControl::PalmCreateField(const wxString& label, |
136 | const wxPoint& pos, | |
137 | const wxSize& size, | |
138 | bool editable, | |
139 | bool underlined, | |
140 | JustificationType justification) | |
141 | { | |
142 | FormType* form = GetParentForm(); | |
143 | if(form==NULL) | |
144 | return false; | |
145 | ||
146 | m_label = label; | |
147 | ||
148 | FieldType *field = FldNewField( | |
149 | (void **)&form, | |
150 | GetId(), | |
151 | ( pos.x == wxDefaultCoord ) ? winUndefConstraint : pos.x, | |
152 | ( pos.y == wxDefaultCoord ) ? winUndefConstraint : pos.y, | |
153 | ( size.x == wxDefaultCoord ) ? winUndefConstraint : size.x, | |
154 | ( size.y == wxDefaultCoord ) ? winUndefConstraint : size.y, | |
155 | stdFont, | |
156 | 10, | |
157 | editable, | |
158 | underlined, | |
159 | false, | |
160 | false, | |
161 | justification, | |
162 | false, | |
163 | false, | |
164 | false | |
165 | ); | |
166 | ||
167 | if(field==NULL) | |
168 | return false; | |
169 | ||
170 | m_palmField = true; | |
171 | ||
172 | Show(); | |
173 | SetLabel(label); | |
174 | return true; | |
175 | } | |
176 | ||
ffecfa5a JS |
177 | // ---------------------------------------------------------------------------- |
178 | // various accessors | |
179 | // ---------------------------------------------------------------------------- | |
180 | ||
ba889513 WS |
181 | FormType* wxControl::GetParentForm() const |
182 | { | |
183 | wxWindow* parentTLW = GetParent(); | |
184 | while ( parentTLW && !parentTLW->IsTopLevel() ) | |
185 | { | |
186 | parentTLW = parentTLW->GetParent(); | |
187 | } | |
188 | wxTopLevelWindowPalm* tlw = wxDynamicCast(parentTLW, wxTopLevelWindowPalm); | |
189 | if(!tlw) | |
190 | return NULL; | |
191 | return tlw->GetForm(); | |
192 | } | |
193 | ||
a152561c WS |
194 | uint16_t wxControl::GetObjectIndex() const |
195 | { | |
196 | FormType* form = GetParentForm(); | |
197 | if(form==NULL)return frmInvalidObjectId; | |
198 | return FrmGetObjectIndex(form, GetId()); | |
199 | } | |
200 | ||
201 | void* wxControl::GetObjectPtr() const | |
202 | { | |
203 | FormType* form = GetParentForm(); | |
204 | if(form==NULL)return NULL; | |
205 | uint16_t index = FrmGetObjectIndex(form, GetId()); | |
206 | if(index==frmInvalidObjectId)return NULL; | |
207 | return FrmGetObjectPtr(form,index); | |
208 | } | |
209 | ||
ffecfa5a JS |
210 | wxBorder wxControl::GetDefaultBorder() const |
211 | { | |
212 | // we want to automatically give controls a sunken style (confusingly, | |
213 | // it may not really mean sunken at all as we map it to WS_EX_CLIENTEDGE | |
214 | // which is not sunken at all under Windows XP -- rather, just the default) | |
215 | return wxBORDER_SUNKEN; | |
216 | } | |
217 | ||
ba889513 WS |
218 | void wxControl::SetIntValue(int val) |
219 | { | |
220 | FormType* form = GetParentForm(); | |
221 | if(form==NULL) | |
222 | return; | |
223 | uint16_t index = FrmGetObjectIndex(form, GetId()); | |
224 | if(index==frmInvalidObjectId) | |
225 | return; | |
226 | FrmSetControlValue(form, index, val); | |
227 | } | |
228 | ||
229 | void wxControl::SetBoolValue(bool val) | |
230 | { | |
231 | SetIntValue(val?1:0); | |
232 | } | |
233 | ||
234 | bool wxControl::GetBoolValue() const | |
235 | { | |
236 | FormType* form = GetParentForm(); | |
237 | if(form==NULL) | |
238 | return false; | |
239 | uint16_t index = FrmGetObjectIndex(form, GetId()); | |
240 | if(index==frmInvalidObjectId) | |
241 | return false; | |
242 | return ( FrmGetControlValue(form, index) == 1 ); | |
243 | } | |
244 | ||
db101bd3 | 245 | wxSize wxControl::DoGetBestSize() const |
ffecfa5a | 246 | { |
db101bd3 | 247 | return wxSize(16, 16); |
ffecfa5a JS |
248 | } |
249 | ||
808e3bce WS |
250 | void wxControl::DoGetBounds( RectangleType &rect ) const |
251 | { | |
252 | FormType* form = GetParentForm(); | |
253 | if(form==NULL) | |
254 | return; | |
255 | uint16_t index = FrmGetObjectIndex(form,GetId()); | |
256 | if(index==frmInvalidObjectId) | |
257 | return; | |
258 | FrmGetObjectBounds(form,index,&rect); | |
259 | } | |
260 | ||
261 | void wxControl::DoGetPosition( int *x, int *y ) const | |
262 | { | |
263 | RectangleType rect; | |
264 | DoGetBounds(rect); | |
265 | if(x) | |
266 | *x = rect.topLeft.x; | |
267 | if(y) | |
268 | *y = rect.topLeft.y; | |
269 | } | |
270 | ||
271 | void wxControl::DoGetSize( int *width, int *height ) const | |
272 | { | |
273 | RectangleType rect; | |
274 | DoGetBounds(rect); | |
275 | if(width) | |
276 | *width = rect.extent.x; | |
277 | if(height) | |
278 | *height = rect.extent.y; | |
279 | } | |
280 | ||
db101bd3 | 281 | bool wxControl::Enable(bool enable) |
ffecfa5a | 282 | { |
a152561c WS |
283 | ControlType *control = (ControlType *)GetObjectPtr(); |
284 | if( (IsPalmControl()) || (control == NULL)) | |
db101bd3 | 285 | return false; |
a152561c | 286 | if( CtlEnabled(control) == enable) |
db101bd3 | 287 | return false; |
a152561c | 288 | CtlSetEnabled( control, enable); |
db101bd3 WS |
289 | return true; |
290 | } | |
291 | ||
292 | bool wxControl::IsEnabled() const | |
293 | { | |
a152561c WS |
294 | ControlType *control = (ControlType *)GetObjectPtr(); |
295 | if( (IsPalmControl()) || (control == NULL)) | |
db101bd3 | 296 | return false; |
a152561c | 297 | return CtlEnabled(control); |
db101bd3 WS |
298 | } |
299 | ||
300 | bool wxControl::IsShown() const | |
301 | { | |
302 | return StatGetAttribute ( statAttrBarVisible , NULL ); | |
303 | } | |
304 | ||
305 | bool wxControl::Show( bool show ) | |
306 | { | |
ba889513 WS |
307 | FormType* form = GetParentForm(); |
308 | if(form==NULL) | |
309 | return false; | |
310 | uint16_t index = FrmGetObjectIndex(form,GetId()); | |
311 | if(index==frmInvalidObjectId) | |
312 | return false; | |
db101bd3 | 313 | if(show) |
ba889513 | 314 | FrmShowObject(form,index); |
db101bd3 | 315 | else |
ba889513 | 316 | FrmHideObject(form,index); |
db101bd3 | 317 | return true; |
ffecfa5a JS |
318 | } |
319 | ||
a152561c | 320 | void wxControl::SetFieldLabel(const wxString& label) |
bdb54365 | 321 | { |
a152561c WS |
322 | FieldType* field = (FieldType*)GetObjectPtr(); |
323 | if(field==NULL) | |
324 | return; | |
325 | ||
326 | uint16_t newSize = label.Length() + 1; | |
327 | MemHandle strHandle = FldGetTextHandle(field); | |
328 | FldSetTextHandle(field, NULL ); | |
329 | if (strHandle) | |
bdb54365 | 330 | { |
a152561c WS |
331 | if(MemHandleResize(strHandle, newSize)!=errNone) |
332 | strHandle = 0; | |
bdb54365 | 333 | } |
a152561c WS |
334 | else |
335 | { | |
336 | strHandle = MemHandleNew( newSize ); | |
337 | } | |
338 | if(!strHandle) | |
339 | return; | |
340 | ||
341 | char* str = (char*) MemHandleLock( strHandle ); | |
342 | if(str==NULL) | |
343 | return; | |
344 | ||
345 | strcpy(str, label.c_str()); | |
346 | MemHandleUnlock(strHandle); | |
347 | FldSetTextHandle(field, strHandle); | |
348 | FldRecalculateField(field, true); | |
349 | } | |
350 | ||
351 | void wxControl::SetControlLabel(const wxString& label) | |
352 | { | |
9a727a3b WS |
353 | ControlType* control = (ControlType*)GetObjectPtr(); |
354 | if(control==NULL) | |
355 | return; | |
356 | CtlSetLabel(control,wxEmptyString); | |
357 | m_label = label; | |
358 | if(!m_label.empty()) | |
359 | CtlSetLabel(control,m_label.c_str()); | |
a152561c WS |
360 | } |
361 | ||
362 | void wxControl::SetLabel(const wxString& label) | |
363 | { | |
364 | if(IsPalmField()) | |
365 | SetFieldLabel(label); | |
366 | ||
367 | // unlike other native controls, slider has no label | |
368 | if(IsPalmControl() && !wxDynamicCast(this,wxSlider)) | |
369 | SetControlLabel(label); | |
370 | } | |
371 | ||
372 | wxString wxControl::GetFieldLabel() | |
373 | { | |
374 | FieldType* field = (FieldType*)GetObjectPtr(); | |
375 | if(field==NULL) | |
376 | return wxEmptyString; | |
377 | return FldGetTextPtr(field); | |
378 | } | |
379 | ||
380 | wxString wxControl::GetControlLabel() | |
381 | { | |
382 | ControlType* control = (ControlType*)GetObjectPtr(); | |
383 | if(control==NULL) | |
384 | return wxEmptyString; | |
385 | return CtlGetLabel(control); | |
bdb54365 WS |
386 | } |
387 | ||
388 | wxString wxControl::GetLabel() | |
389 | { | |
a152561c WS |
390 | if(IsPalmField()) |
391 | return GetFieldLabel(); | |
392 | ||
393 | // unlike other native controls, slider has no label | |
394 | if(IsPalmControl() && !wxDynamicCast(this,wxSlider)) | |
395 | return GetControlLabel(); | |
bdb54365 WS |
396 | |
397 | return wxEmptyString; | |
398 | } | |
399 | ||
ffecfa5a JS |
400 | /* static */ wxVisualAttributes |
401 | wxControl::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant)) | |
402 | { | |
403 | wxVisualAttributes attrs; | |
404 | ||
405 | // old school (i.e. not "common") controls use the standard dialog font | |
406 | // by default | |
407 | attrs.font = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT); | |
408 | ||
409 | // most, or at least many, of the controls use the same colours as the | |
410 | // buttons -- others will have to override this (and possibly simply call | |
411 | // GetCompositeControlsDefaultAttributes() from their versions) | |
412 | attrs.colFg = wxSystemSettings::GetColour(wxSYS_COLOUR_BTNTEXT); | |
413 | attrs.colBg = wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE); | |
414 | ||
415 | return attrs; | |
416 | } | |
417 | ||
418 | // another version for the "composite", i.e. non simple controls | |
419 | /* static */ wxVisualAttributes | |
420 | wxControl::GetCompositeControlsDefaultAttributes(wxWindowVariant WXUNUSED(variant)) | |
421 | { | |
422 | wxVisualAttributes attrs; | |
423 | attrs.font = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT); | |
424 | attrs.colFg = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT); | |
425 | attrs.colBg = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW); | |
426 | ||
427 | return attrs; | |
428 | } | |
429 | ||
430 | // ---------------------------------------------------------------------------- | |
431 | // message handling | |
432 | // ---------------------------------------------------------------------------- | |
433 | ||
434 | bool wxControl::ProcessCommand(wxCommandEvent& event) | |
435 | { | |
436 | return GetEventHandler()->ProcessEvent(event); | |
437 | } | |
438 | ||
ffecfa5a JS |
439 | void wxControl::OnEraseBackground(wxEraseEvent& event) |
440 | { | |
441 | } | |
442 | ||
443 | WXHBRUSH wxControl::OnCtlColor(WXHDC pDC, WXHWND WXUNUSED(pWnd), WXUINT WXUNUSED(nCtlColor), | |
ffecfa5a JS |
444 | WXUINT WXUNUSED(message), |
445 | WXWPARAM WXUNUSED(wParam), | |
446 | WXLPARAM WXUNUSED(lParam) | |
ffecfa5a JS |
447 | ) |
448 | { | |
449 | return (WXHBRUSH)0; | |
450 | } | |
451 | ||
452 | // --------------------------------------------------------------------------- | |
453 | // global functions | |
454 | // --------------------------------------------------------------------------- | |
455 | ||
456 | #endif // wxUSE_CONTROLS |