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;
79 // ----------------------------------------------------------------------------
80 // control window creation
81 // ----------------------------------------------------------------------------
83 bool wxControl::Create(wxWindow
*parent
,
88 const wxValidator
& wxVALIDATOR_PARAM(validator
),
91 if ( !wxWindow::Create(parent
, id
, pos
, size
, style
, name
) )
95 SetValidator(validator
);
101 bool wxControl::PalmCreateControl(ControlStyleType style
,
102 const wxString
& label
,
107 FormType
* form
= GetParentForm();
111 ControlType
*control
= CtlNewControl(
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
,
128 m_palmControl
= true;
135 bool wxControl::PalmCreateField(const wxString
& label
,
140 JustificationType justification
)
142 FormType
* form
= GetParentForm();
148 FieldType
*field
= FldNewField(
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
,
177 // ----------------------------------------------------------------------------
179 // ----------------------------------------------------------------------------
181 FormType
* wxControl::GetParentForm() const
183 wxWindow
* parentTLW
= GetParent();
184 while ( parentTLW
&& !parentTLW
->IsTopLevel() )
186 parentTLW
= parentTLW
->GetParent();
188 wxTopLevelWindowPalm
* tlw
= wxDynamicCast(parentTLW
, wxTopLevelWindowPalm
);
191 return tlw
->GetForm();
194 uint16_t wxControl::GetObjectIndex() const
196 FormType
* form
= GetParentForm();
197 if(form
==NULL
)return frmInvalidObjectId
;
198 return FrmGetObjectIndex(form
, GetId());
201 void* wxControl::GetObjectPtr() const
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
);
210 wxBorder
wxControl::GetDefaultBorder() const
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
;
218 void wxControl::SetIntValue(int val
)
220 FormType
* form
= GetParentForm();
223 uint16_t index
= FrmGetObjectIndex(form
, GetId());
224 if(index
==frmInvalidObjectId
)
226 FrmSetControlValue(form
, index
, val
);
229 void wxControl::SetBoolValue(bool val
)
231 SetIntValue(val
?1:0);
234 bool wxControl::GetBoolValue() const
236 FormType
* form
= GetParentForm();
239 uint16_t index
= FrmGetObjectIndex(form
, GetId());
240 if(index
==frmInvalidObjectId
)
242 return ( FrmGetControlValue(form
, index
) == 1 );
245 wxSize
wxControl::DoGetBestSize() const
247 return wxSize(16, 16);
250 void wxControl::DoGetBounds( RectangleType
&rect
) const
252 FormType
* form
= GetParentForm();
255 uint16_t index
= FrmGetObjectIndex(form
,GetId());
256 if(index
==frmInvalidObjectId
)
258 FrmGetObjectBounds(form
,index
,&rect
);
261 void wxControl::DoGetPosition( int *x
, int *y
) const
271 void wxControl::DoGetSize( int *width
, int *height
) const
276 *width
= rect
.extent
.x
;
278 *height
= rect
.extent
.y
;
281 bool wxControl::Enable(bool enable
)
283 ControlType
*control
= (ControlType
*)GetObjectPtr();
284 if( (IsPalmControl()) || (control
== NULL
))
286 if( CtlEnabled(control
) == enable
)
288 CtlSetEnabled( control
, enable
);
292 bool wxControl::IsEnabled() const
294 ControlType
*control
= (ControlType
*)GetObjectPtr();
295 if( (IsPalmControl()) || (control
== NULL
))
297 return CtlEnabled(control
);
300 bool wxControl::IsShown() const
302 return StatGetAttribute ( statAttrBarVisible
, NULL
);
305 bool wxControl::Show( bool show
)
307 FormType
* form
= GetParentForm();
310 uint16_t index
= FrmGetObjectIndex(form
,GetId());
311 if(index
==frmInvalidObjectId
)
314 FrmShowObject(form
,index
);
316 FrmHideObject(form
,index
);
320 void wxControl::SetFieldLabel(const wxString
& label
)
322 FieldType
* field
= (FieldType
*)GetObjectPtr();
326 uint16_t newSize
= label
.Length() + 1;
327 MemHandle strHandle
= FldGetTextHandle(field
);
328 FldSetTextHandle(field
, NULL
);
331 if(MemHandleResize(strHandle
, newSize
)!=errNone
)
336 strHandle
= MemHandleNew( newSize
);
341 char* str
= (char*) MemHandleLock( strHandle
);
345 strcpy(str
, label
.c_str());
346 MemHandleUnlock(strHandle
);
347 FldSetTextHandle(field
, strHandle
);
348 FldRecalculateField(field
, true);
351 void wxControl::SetControlLabel(const wxString
& label
)
353 ControlType
* control
= (ControlType
*)GetObjectPtr();
356 CtlSetLabel(control
,wxEmptyString
);
359 CtlSetLabel(control
,m_label
.c_str());
362 void wxControl::SetLabel(const wxString
& label
)
365 SetFieldLabel(label
);
367 // unlike other native controls, slider has no label
368 if(IsPalmControl() && !wxDynamicCast(this,wxSlider
))
369 SetControlLabel(label
);
372 wxString
wxControl::GetFieldLabel()
374 FieldType
* field
= (FieldType
*)GetObjectPtr();
376 return wxEmptyString
;
377 return FldGetTextPtr(field
);
380 wxString
wxControl::GetControlLabel()
382 ControlType
* control
= (ControlType
*)GetObjectPtr();
384 return wxEmptyString
;
385 return CtlGetLabel(control
);
388 wxString
wxControl::GetLabel()
391 return GetFieldLabel();
393 // unlike other native controls, slider has no label
394 if(IsPalmControl() && !wxDynamicCast(this,wxSlider
))
395 return GetControlLabel();
397 return wxEmptyString
;
400 /* static */ wxVisualAttributes
401 wxControl::GetClassDefaultAttributes(wxWindowVariant
WXUNUSED(variant
))
403 wxVisualAttributes attrs
;
405 // old school (i.e. not "common") controls use the standard dialog font
407 attrs
.font
= wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
);
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
);
418 // another version for the "composite", i.e. non simple controls
419 /* static */ wxVisualAttributes
420 wxControl::GetCompositeControlsDefaultAttributes(wxWindowVariant
WXUNUSED(variant
))
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
);
430 // ----------------------------------------------------------------------------
432 // ----------------------------------------------------------------------------
434 bool wxControl::ProcessCommand(wxCommandEvent
& event
)
436 return GetEventHandler()->ProcessEvent(event
);
439 void wxControl::OnEraseBackground(wxEraseEvent
& event
)
443 WXHBRUSH
wxControl::OnCtlColor(WXHDC pDC
, WXHWND
WXUNUSED(pWnd
), WXUINT
WXUNUSED(nCtlColor
),
444 WXUINT
WXUNUSED(message
),
445 WXWPARAM
WXUNUSED(wParam
),
446 WXLPARAM
WXUNUSED(lParam
)
452 // ---------------------------------------------------------------------------
454 // ---------------------------------------------------------------------------
456 #endif // wxUSE_CONTROLS