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::DoGetPosition( int *x
, int *y
) const
299 void wxControl::DoGetSize( int *width
, int *height
) const
304 *width
= rect
.extent
.x
;
306 *height
= rect
.extent
.y
;
309 bool wxControl::Enable(bool enable
)
311 ControlType
*control
= (ControlType
*)GetObjectPtr();
312 if( (IsPalmControl()) || (control
== NULL
))
314 if( CtlEnabled(control
) == enable
)
316 CtlSetEnabled( control
, enable
);
320 bool wxControl::IsEnabled() const
322 ControlType
*control
= (ControlType
*)GetObjectPtr();
323 if( (IsPalmControl()) || (control
== NULL
))
325 return CtlEnabled(control
);
328 bool wxControl::IsShown() const
330 return StatGetAttribute ( statAttrBarVisible
, NULL
);
333 bool wxControl::Show( bool show
)
335 FormType
* form
= GetParentForm();
338 uint16_t index
= FrmGetObjectIndex(form
,GetId());
339 if(index
==frmInvalidObjectId
)
342 FrmShowObject(form
,index
);
344 FrmHideObject(form
,index
);
348 void wxControl::SetFieldLabel(const wxString
& label
)
350 FieldType
* field
= (FieldType
*)GetObjectPtr();
354 uint16_t newSize
= label
.Length() + 1;
355 MemHandle strHandle
= FldGetTextHandle(field
);
356 FldSetTextHandle(field
, NULL
);
359 if(MemHandleResize(strHandle
, newSize
)!=errNone
)
364 strHandle
= MemHandleNew( newSize
);
369 char* str
= (char*) MemHandleLock( strHandle
);
373 strcpy(str
, label
.c_str());
374 MemHandleUnlock(strHandle
);
375 FldSetTextHandle(field
, strHandle
);
376 FldRecalculateField(field
, true);
379 void wxControl::SetControlLabel(const wxString
& label
)
381 ControlType
* control
= (ControlType
*)GetObjectPtr();
384 CtlSetLabel(control
,wxEmptyString
);
387 CtlSetLabel(control
,m_label
.c_str());
390 void wxControl::SetLabel(const wxString
& label
)
393 SetFieldLabel(label
);
395 // unlike other native controls, slider has no label
396 if(IsPalmControl() && !wxDynamicCast(this,wxSlider
))
397 SetControlLabel(label
);
400 wxString
wxControl::GetFieldLabel()
402 FieldType
* field
= (FieldType
*)GetObjectPtr();
404 return wxEmptyString
;
405 return FldGetTextPtr(field
);
408 wxString
wxControl::GetControlLabel()
410 ControlType
* control
= (ControlType
*)GetObjectPtr();
412 return wxEmptyString
;
413 return CtlGetLabel(control
);
416 wxString
wxControl::GetLabel()
419 return GetFieldLabel();
421 // unlike other native controls, slider has no label
422 if(IsPalmControl() && !wxDynamicCast(this,wxSlider
))
423 return GetControlLabel();
425 return wxEmptyString
;
428 /* static */ wxVisualAttributes
429 wxControl::GetClassDefaultAttributes(wxWindowVariant
WXUNUSED(variant
))
431 wxVisualAttributes attrs
;
433 // old school (i.e. not "common") controls use the standard dialog font
435 attrs
.font
= wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
);
437 // most, or at least many, of the controls use the same colours as the
438 // buttons -- others will have to override this (and possibly simply call
439 // GetCompositeControlsDefaultAttributes() from their versions)
440 attrs
.colFg
= wxSystemSettings::GetColour(wxSYS_COLOUR_BTNTEXT
);
441 attrs
.colBg
= wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE
);
446 // another version for the "composite", i.e. non simple controls
447 /* static */ wxVisualAttributes
448 wxControl::GetCompositeControlsDefaultAttributes(wxWindowVariant
WXUNUSED(variant
))
450 wxVisualAttributes attrs
;
451 attrs
.font
= wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
);
452 attrs
.colFg
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
);
453 attrs
.colBg
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
);
458 // ----------------------------------------------------------------------------
460 // ----------------------------------------------------------------------------
462 bool wxControl::ProcessCommand(wxCommandEvent
& event
)
464 return GetEventHandler()->ProcessEvent(event
);
467 void wxControl::OnEraseBackground(wxEraseEvent
& event
)
471 WXHBRUSH
wxControl::OnCtlColor(WXHDC pDC
, WXHWND
WXUNUSED(pWnd
), WXUINT
WXUNUSED(nCtlColor
),
472 WXUINT
WXUNUSED(message
),
473 WXWPARAM
WXUNUSED(wParam
),
474 WXLPARAM
WXUNUSED(lParam
)
480 // ---------------------------------------------------------------------------
482 // ---------------------------------------------------------------------------
484 #endif // wxUSE_CONTROLS