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 m_isBeingDeleted
= true;
78 // ----------------------------------------------------------------------------
79 // control window creation
80 // ----------------------------------------------------------------------------
82 bool wxControl::Create(wxWindow
*parent
,
87 const wxValidator
& wxVALIDATOR_PARAM(validator
),
90 if ( !wxWindow::Create(parent
, id
, pos
, size
, style
, name
) )
94 SetValidator(validator
);
100 bool wxControl::PalmCreateControl(ControlStyleType style
,
101 const wxString
& label
,
106 FormType
* form
= GetParentForm();
112 ControlType
*control
= CtlNewControl(
117 ( pos
.x
== wxDefaultCoord
) ? winUndefConstraint
: pos
.x
,
118 ( pos
.y
== wxDefaultCoord
) ? winUndefConstraint
: pos
.y
,
119 ( size
.x
== wxDefaultCoord
) ? winUndefConstraint
: size
.x
,
120 ( size
.y
== wxDefaultCoord
) ? winUndefConstraint
: size
.y
,
129 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
)
355 void wxControl::SetLabel(const wxString
& label
)
358 SetFieldLabel(label
);
360 // unlike other native controls, slider has no label
361 if(IsPalmControl() && !wxDynamicCast(this,wxSlider
))
362 SetControlLabel(label
);
365 wxString
wxControl::GetFieldLabel()
367 FieldType
* field
= (FieldType
*)GetObjectPtr();
369 return wxEmptyString
;
370 return FldGetTextPtr(field
);
373 wxString
wxControl::GetControlLabel()
375 ControlType
* control
= (ControlType
*)GetObjectPtr();
377 return wxEmptyString
;
378 return CtlGetLabel(control
);
381 wxString
wxControl::GetLabel()
384 return GetFieldLabel();
386 // unlike other native controls, slider has no label
387 if(IsPalmControl() && !wxDynamicCast(this,wxSlider
))
388 return GetControlLabel();
390 return wxEmptyString
;
393 /* static */ wxVisualAttributes
394 wxControl::GetClassDefaultAttributes(wxWindowVariant
WXUNUSED(variant
))
396 wxVisualAttributes attrs
;
398 // old school (i.e. not "common") controls use the standard dialog font
400 attrs
.font
= wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
);
402 // most, or at least many, of the controls use the same colours as the
403 // buttons -- others will have to override this (and possibly simply call
404 // GetCompositeControlsDefaultAttributes() from their versions)
405 attrs
.colFg
= wxSystemSettings::GetColour(wxSYS_COLOUR_BTNTEXT
);
406 attrs
.colBg
= wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE
);
411 // another version for the "composite", i.e. non simple controls
412 /* static */ wxVisualAttributes
413 wxControl::GetCompositeControlsDefaultAttributes(wxWindowVariant
WXUNUSED(variant
))
415 wxVisualAttributes attrs
;
416 attrs
.font
= wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
);
417 attrs
.colFg
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
);
418 attrs
.colBg
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
);
423 // ----------------------------------------------------------------------------
425 // ----------------------------------------------------------------------------
427 bool wxControl::ProcessCommand(wxCommandEvent
& event
)
429 return GetEventHandler()->ProcessEvent(event
);
432 void wxControl::OnEraseBackground(wxEraseEvent
& event
)
436 WXHBRUSH
wxControl::OnCtlColor(WXHDC pDC
, WXHWND
WXUNUSED(pWnd
), WXUINT
WXUNUSED(nCtlColor
),
437 WXUINT
WXUNUSED(message
),
438 WXWPARAM
WXUNUSED(wParam
),
439 WXLPARAM
WXUNUSED(lParam
)
445 // ---------------------------------------------------------------------------
447 // ---------------------------------------------------------------------------
449 #endif // wxUSE_CONTROLS