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 wxWindow
*win
= this;
127 while(win
->GetParent())
129 win
= win
->GetParent();
130 wxPoint
pt(win
->GetClientAreaOrigin());
135 ControlType
*control
= CtlNewControl(
152 m_palmControl
= true;
154 SetInitialBestSize(size
);
160 bool wxControl::PalmCreateField(const wxString
& label
,
165 JustificationType justification
)
167 FormType
* form
= GetParentForm();
173 wxCoord x
= pos
.x
== wxDefaultCoord
? 0 : pos
.x
,
174 y
= pos
.y
== wxDefaultCoord
? 0 : pos
.y
,
175 w
= size
.x
== wxDefaultCoord
? 1 : size
.x
,
176 h
= size
.y
== wxDefaultCoord
? 1 : size
.y
;
178 AdjustForParentClientOrigin(x
, y
);
180 FieldType
*field
= FldNewField(
204 SetInitialBestSize(size
);
210 // ----------------------------------------------------------------------------
212 // ----------------------------------------------------------------------------
214 FormType
* wxControl::GetParentForm() const
216 wxWindow
* parentTLW
= GetParent();
217 while ( parentTLW
&& !parentTLW
->IsTopLevel() )
219 parentTLW
= parentTLW
->GetParent();
221 wxTopLevelWindowPalm
* tlw
= wxDynamicCast(parentTLW
, wxTopLevelWindowPalm
);
224 return tlw
->GetForm();
227 FormType
* wxControl::GetObjectFormIndex(uint16_t& index
) const
229 FormType
* form
= GetParentForm();
231 index
= FrmGetObjectIndex(form
, GetId());
233 index
= frmInvalidObjectId
;
237 void* wxControl::GetObjectPtr() const
240 FormType
* form
= GetObjectFormIndex(index
);
241 if(form
==NULL
|| index
==frmInvalidObjectId
)return NULL
;
242 return FrmGetObjectPtr(form
,index
);
245 wxBorder
wxControl::GetDefaultBorder() const
247 // we want to automatically give controls a sunken style (confusingly,
248 // it may not really mean sunken at all as we map it to WS_EX_CLIENTEDGE
249 // which is not sunken at all under Windows XP -- rather, just the default)
250 return wxBORDER_SUNKEN
;
253 void wxControl::SetIntValue(int val
)
255 FormType
* form
= GetParentForm();
258 uint16_t index
= FrmGetObjectIndex(form
, GetId());
259 if(index
==frmInvalidObjectId
)
261 FrmSetControlValue(form
, index
, val
);
264 void wxControl::SetBoolValue(bool val
)
266 SetIntValue(val
?1:0);
269 bool wxControl::GetBoolValue() const
271 FormType
* form
= GetParentForm();
274 uint16_t index
= FrmGetObjectIndex(form
, GetId());
275 if(index
==frmInvalidObjectId
)
277 return ( FrmGetControlValue(form
, index
) == 1 );
280 wxSize
wxControl::DoGetBestSize() const
282 return wxSize(16, 16);
285 void wxControl::DoGetBounds( RectangleType
&rect
) const
287 FormType
* form
= GetParentForm();
290 uint16_t index
= FrmGetObjectIndex(form
,GetId());
291 if(index
==frmInvalidObjectId
)
293 FrmGetObjectBounds(form
,index
,&rect
);
296 void wxControl::DoSetBounds( RectangleType
&rect
)
298 FormType
* form
= GetParentForm();
301 uint16_t index
= FrmGetObjectIndex(form
,GetId());
302 if(index
==frmInvalidObjectId
)
304 FrmSetObjectBounds(form
,index
,&rect
);
307 void wxControl::DoGetPosition( int *x
, int *y
) const
310 AdjustForParentClientOrigin(ox
, oy
);
316 *x
= rect
.topLeft
.x
- ox
;
318 *y
= rect
.topLeft
.y
- oy
;
321 void wxControl::DoGetSize( int *width
, int *height
) const
327 *width
= rect
.extent
.x
;
329 *height
= rect
.extent
.y
;
332 void wxControl::DoMoveWindow(int x
, int y
, int width
, int height
)
334 wxRect area
= GetRect();
338 rect
.extent
.x
= width
;
339 rect
.extent
.y
= height
;
341 GetParent()->Refresh(true, &area
);
344 bool wxControl::Enable(bool enable
)
346 ControlType
*control
= (ControlType
*)GetObjectPtr();
347 if( !IsPalmControl() || (control
== NULL
))
349 if( CtlEnabled(control
) == enable
)
351 CtlSetEnabled( control
, enable
);
355 bool wxControl::IsEnabled() const
357 ControlType
*control
= (ControlType
*)GetObjectPtr();
358 if( !IsPalmControl() || (control
== NULL
))
360 return CtlEnabled(control
);
363 bool wxControl::IsShown() const
365 return StatGetAttribute ( statAttrBarVisible
, NULL
);
368 bool wxControl::Show( bool show
)
370 FormType
* form
= GetParentForm();
373 uint16_t index
= FrmGetObjectIndex(form
,GetId());
374 if(index
==frmInvalidObjectId
)
377 FrmShowObject(form
,index
);
379 FrmHideObject(form
,index
);
383 void wxControl::SetFieldLabel(const wxString
& label
)
385 FieldType
* field
= (FieldType
*)GetObjectPtr();
389 uint16_t newSize
= label
.Length() + 1;
390 MemHandle strHandle
= FldGetTextHandle(field
);
391 FldSetTextHandle(field
, NULL
);
394 if(MemHandleResize(strHandle
, newSize
)!=errNone
)
399 strHandle
= MemHandleNew( newSize
);
404 char* str
= (char*) MemHandleLock( strHandle
);
408 strcpy(str
, label
.c_str());
409 MemHandleUnlock(strHandle
);
410 FldSetTextHandle(field
, strHandle
);
411 FldRecalculateField(field
, true);
414 void wxControl::SetControlLabel(const wxString
& label
)
416 ControlType
* control
= (ControlType
*)GetObjectPtr();
419 CtlSetLabel(control
,wxEmptyString
);
422 CtlSetLabel(control
,m_label
.c_str());
425 void wxControl::SetLabel(const wxString
& label
)
428 SetFieldLabel(label
);
430 // unlike other native controls, slider has no label
431 if(IsPalmControl() && !wxDynamicCast(this,wxSlider
))
432 SetControlLabel(label
);
435 wxString
wxControl::GetFieldLabel()
437 FieldType
* field
= (FieldType
*)GetObjectPtr();
439 return wxEmptyString
;
440 return FldGetTextPtr(field
);
443 wxString
wxControl::GetControlLabel()
445 ControlType
* control
= (ControlType
*)GetObjectPtr();
447 return wxEmptyString
;
448 return CtlGetLabel(control
);
451 wxString
wxControl::GetLabel()
454 return GetFieldLabel();
456 // unlike other native controls, slider has no label
457 if(IsPalmControl() && !wxDynamicCast(this,wxSlider
))
458 return GetControlLabel();
460 return wxEmptyString
;
463 /* static */ wxVisualAttributes
464 wxControl::GetClassDefaultAttributes(wxWindowVariant
WXUNUSED(variant
))
466 wxVisualAttributes attrs
;
468 // old school (i.e. not "common") controls use the standard dialog font
470 attrs
.font
= wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
);
472 // most, or at least many, of the controls use the same colours as the
473 // buttons -- others will have to override this (and possibly simply call
474 // GetCompositeControlsDefaultAttributes() from their versions)
475 attrs
.colFg
= wxSystemSettings::GetColour(wxSYS_COLOUR_BTNTEXT
);
476 attrs
.colBg
= wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE
);
481 // another version for the "composite", i.e. non simple controls
482 /* static */ wxVisualAttributes
483 wxControl::GetCompositeControlsDefaultAttributes(wxWindowVariant
WXUNUSED(variant
))
485 wxVisualAttributes attrs
;
486 attrs
.font
= wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
);
487 attrs
.colFg
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
);
488 attrs
.colBg
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
);
493 // ----------------------------------------------------------------------------
495 // ----------------------------------------------------------------------------
497 bool wxControl::ProcessCommand(wxCommandEvent
& event
)
499 return GetEventHandler()->ProcessEvent(event
);
502 void wxControl::OnEraseBackground(wxEraseEvent
& event
)
506 #endif // wxUSE_CONTROLS