1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/palmos/control.cpp
3 // Purpose: wxControl class
4 // Author: William Osborne - minimal working wxPalmOS port
5 // Modified by: Wlodzimierz ABX Skiba - native implementation
8 // Copyright: (c) William Osborne, Wlodzimierz Skiba
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
21 #pragma implementation "control.h"
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
36 #include "wx/dcclient.h"
38 #include "wx/settings.h"
41 #include "wx/control.h"
42 #include "wx/toplevel.h"
43 #include "wx/button.h"
44 #include "wx/checkbox.h"
45 #include "wx/tglbtn.h"
46 #include "wx/radiobut.h"
47 #include "wx/slider.h"
49 // ----------------------------------------------------------------------------
51 // ----------------------------------------------------------------------------
53 IMPLEMENT_ABSTRACT_CLASS(wxControl
, wxWindow
)
55 BEGIN_EVENT_TABLE(wxControl
, wxWindow
)
56 EVT_ERASE_BACKGROUND(wxControl::OnEraseBackground
)
59 // ============================================================================
60 // wxControl implementation
61 // ============================================================================
63 // ----------------------------------------------------------------------------
64 // wxControl ctor/dtor
65 // ----------------------------------------------------------------------------
67 void wxControl::Init()
69 m_palmControl
= false;
73 wxControl::~wxControl()
75 SetLabel(wxEmptyString
);
76 m_isBeingDeleted
= true;
81 FormType
* form
= GetObjectFormIndex(index
);
82 if(form
!=NULL
&& index
!=frmInvalidObjectId
)
84 FrmRemoveObject((FormType
**)&form
,index
);
88 // ----------------------------------------------------------------------------
89 // control window creation
90 // ----------------------------------------------------------------------------
92 bool wxControl::Create(wxWindow
*parent
,
97 const wxValidator
& wxVALIDATOR_PARAM(validator
),
100 if ( !wxWindow::Create(parent
, id
, pos
, size
, style
, name
) )
104 SetValidator(validator
);
110 bool wxControl::PalmCreateControl(ControlStyleType style
,
111 const wxString
& label
,
116 FormType
* form
= GetParentForm();
121 wxCoord x
= pos
.x
== wxDefaultCoord
? 0 : pos
.x
,
122 y
= pos
.y
== wxDefaultCoord
? 0 : pos
.y
,
123 w
= size
.x
== wxDefaultCoord
? 1 : size
.x
,
124 h
= size
.y
== wxDefaultCoord
? 1 : size
.y
;
126 AdjustForParentClientOrigin(x
, y
);
128 ControlType
*control
= CtlNewControl(
145 m_palmControl
= true;
147 SetInitialBestSize(size
);
153 bool wxControl::PalmCreateField(const wxString
& label
,
158 JustificationType justification
)
160 FormType
* form
= GetParentForm();
166 wxCoord x
= pos
.x
== wxDefaultCoord
? 0 : pos
.x
,
167 y
= pos
.y
== wxDefaultCoord
? 0 : pos
.y
,
168 w
= size
.x
== wxDefaultCoord
? 1 : size
.x
,
169 h
= size
.y
== wxDefaultCoord
? 1 : size
.y
;
171 AdjustForParentClientOrigin(x
, y
);
173 FieldType
*field
= FldNewField(
197 SetInitialBestSize(size
);
203 // ----------------------------------------------------------------------------
205 // ----------------------------------------------------------------------------
207 FormType
* wxControl::GetParentForm() const
209 wxWindow
* parentTLW
= GetParent();
210 while ( parentTLW
&& !parentTLW
->IsTopLevel() )
212 parentTLW
= parentTLW
->GetParent();
214 wxTopLevelWindowPalm
* tlw
= wxDynamicCast(parentTLW
, wxTopLevelWindowPalm
);
217 return tlw
->GetForm();
220 FormType
* wxControl::GetObjectFormIndex(uint16_t& index
) const
222 FormType
* form
= GetParentForm();
224 index
= FrmGetObjectIndex(form
, GetId());
226 index
= frmInvalidObjectId
;
230 void* wxControl::GetObjectPtr() const
233 FormType
* form
= GetObjectFormIndex(index
);
234 if(form
==NULL
|| index
==frmInvalidObjectId
)return NULL
;
235 return FrmGetObjectPtr(form
,index
);
238 wxBorder
wxControl::GetDefaultBorder() const
240 // we want to automatically give controls a sunken style (confusingly,
241 // it may not really mean sunken at all as we map it to WS_EX_CLIENTEDGE
242 // which is not sunken at all under Windows XP -- rather, just the default)
243 return wxBORDER_SUNKEN
;
246 void wxControl::SetIntValue(int val
)
248 FormType
* form
= GetParentForm();
251 uint16_t index
= FrmGetObjectIndex(form
, GetId());
252 if(index
==frmInvalidObjectId
)
254 FrmSetControlValue(form
, index
, val
);
257 void wxControl::SetBoolValue(bool val
)
259 SetIntValue(val
?1:0);
262 bool wxControl::GetBoolValue() const
264 FormType
* form
= GetParentForm();
267 uint16_t index
= FrmGetObjectIndex(form
, GetId());
268 if(index
==frmInvalidObjectId
)
270 return ( FrmGetControlValue(form
, index
) == 1 );
273 wxSize
wxControl::DoGetBestSize() const
275 return wxSize(16, 16);
278 void wxControl::DoGetBounds( RectangleType
&rect
) const
280 FormType
* form
= GetParentForm();
283 uint16_t index
= FrmGetObjectIndex(form
,GetId());
284 if(index
==frmInvalidObjectId
)
286 FrmGetObjectBounds(form
,index
,&rect
);
289 void wxControl::DoSetBounds( RectangleType
&rect
)
291 FormType
* form
= GetParentForm();
294 uint16_t index
= FrmGetObjectIndex(form
,GetId());
295 if(index
==frmInvalidObjectId
)
297 FrmSetObjectBounds(form
,index
,&rect
);
300 void wxControl::DoGetPosition( int *x
, int *y
) const
310 void wxControl::DoGetSize( int *width
, int *height
) const
315 *width
= rect
.extent
.x
;
317 *height
= rect
.extent
.y
;
320 void wxControl::DoMoveWindow(int x
, int y
, int width
, int height
)
322 wxRect area
= GetRect();
326 rect
.extent
.x
= width
;
327 rect
.extent
.y
= height
;
329 GetParent()->Refresh(true, &area
);
332 bool wxControl::Enable(bool enable
)
334 ControlType
*control
= (ControlType
*)GetObjectPtr();
335 if( !IsPalmControl() || (control
== NULL
))
337 if( CtlEnabled(control
) == enable
)
339 CtlSetEnabled( control
, enable
);
343 bool wxControl::IsEnabled() const
345 ControlType
*control
= (ControlType
*)GetObjectPtr();
346 if( !IsPalmControl() || (control
== NULL
))
348 return CtlEnabled(control
);
351 bool wxControl::IsShown() const
353 return StatGetAttribute ( statAttrBarVisible
, NULL
);
356 bool wxControl::Show( bool show
)
358 FormType
* form
= GetParentForm();
361 uint16_t index
= FrmGetObjectIndex(form
,GetId());
362 if(index
==frmInvalidObjectId
)
365 FrmShowObject(form
,index
);
367 FrmHideObject(form
,index
);
371 void wxControl::SetFieldLabel(const wxString
& label
)
373 FieldType
* field
= (FieldType
*)GetObjectPtr();
377 uint16_t newSize
= label
.Length() + 1;
378 MemHandle strHandle
= FldGetTextHandle(field
);
379 FldSetTextHandle(field
, NULL
);
382 if(MemHandleResize(strHandle
, newSize
)!=errNone
)
387 strHandle
= MemHandleNew( newSize
);
392 char* str
= (char*) MemHandleLock( strHandle
);
396 strcpy(str
, label
.c_str());
397 MemHandleUnlock(strHandle
);
398 FldSetTextHandle(field
, strHandle
);
399 FldRecalculateField(field
, true);
402 void wxControl::SetControlLabel(const wxString
& label
)
404 ControlType
* control
= (ControlType
*)GetObjectPtr();
407 CtlSetLabel(control
,wxEmptyString
);
410 CtlSetLabel(control
,m_label
.c_str());
413 void wxControl::SetLabel(const wxString
& label
)
416 SetFieldLabel(label
);
418 // unlike other native controls, slider has no label
419 if(IsPalmControl() && !wxDynamicCast(this,wxSlider
))
420 SetControlLabel(label
);
423 wxString
wxControl::GetFieldLabel()
425 FieldType
* field
= (FieldType
*)GetObjectPtr();
427 return wxEmptyString
;
428 return FldGetTextPtr(field
);
431 wxString
wxControl::GetControlLabel()
433 ControlType
* control
= (ControlType
*)GetObjectPtr();
435 return wxEmptyString
;
436 return CtlGetLabel(control
);
439 wxString
wxControl::GetLabel()
442 return GetFieldLabel();
444 // unlike other native controls, slider has no label
445 if(IsPalmControl() && !wxDynamicCast(this,wxSlider
))
446 return GetControlLabel();
448 return wxEmptyString
;
451 /* static */ wxVisualAttributes
452 wxControl::GetClassDefaultAttributes(wxWindowVariant
WXUNUSED(variant
))
454 wxVisualAttributes attrs
;
456 // old school (i.e. not "common") controls use the standard dialog font
458 attrs
.font
= wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
);
460 // most, or at least many, of the controls use the same colours as the
461 // buttons -- others will have to override this (and possibly simply call
462 // GetCompositeControlsDefaultAttributes() from their versions)
463 attrs
.colFg
= wxSystemSettings::GetColour(wxSYS_COLOUR_BTNTEXT
);
464 attrs
.colBg
= wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE
);
469 // another version for the "composite", i.e. non simple controls
470 /* static */ wxVisualAttributes
471 wxControl::GetCompositeControlsDefaultAttributes(wxWindowVariant
WXUNUSED(variant
))
473 wxVisualAttributes attrs
;
474 attrs
.font
= wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
);
475 attrs
.colFg
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
);
476 attrs
.colBg
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
);
481 // ----------------------------------------------------------------------------
483 // ----------------------------------------------------------------------------
485 bool wxControl::ProcessCommand(wxCommandEvent
& event
)
487 return GetEventHandler()->ProcessEvent(event
);
490 void wxControl::OnEraseBackground(wxEraseEvent
& event
)
494 #endif // wxUSE_CONTROLS