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();
120 ControlType
*control
= CtlNewControl(
125 ( pos
.x
== wxDefaultCoord
) ? winUndefConstraint
: pos
.x
,
126 ( pos
.y
== wxDefaultCoord
) ? winUndefConstraint
: pos
.y
,
127 ( size
.x
== wxDefaultCoord
) ? winUndefConstraint
: size
.x
,
128 ( size
.y
== wxDefaultCoord
) ? winUndefConstraint
: size
.y
,
137 m_palmControl
= true;
144 bool wxControl::PalmCreateField(const wxString
& label
,
149 JustificationType justification
)
151 FormType
* form
= GetParentForm();
157 FieldType
*field
= FldNewField(
160 ( pos
.x
== wxDefaultCoord
) ? winUndefConstraint
: pos
.x
,
161 ( pos
.y
== wxDefaultCoord
) ? winUndefConstraint
: pos
.y
,
162 ( size
.x
== wxDefaultCoord
) ? winUndefConstraint
: size
.x
,
163 ( size
.y
== wxDefaultCoord
) ? winUndefConstraint
: size
.y
,
186 // ----------------------------------------------------------------------------
188 // ----------------------------------------------------------------------------
190 FormType
* wxControl::GetParentForm() const
192 wxWindow
* parentTLW
= GetParent();
193 while ( parentTLW
&& !parentTLW
->IsTopLevel() )
195 parentTLW
= parentTLW
->GetParent();
197 wxTopLevelWindowPalm
* tlw
= wxDynamicCast(parentTLW
, wxTopLevelWindowPalm
);
200 return tlw
->GetForm();
203 FormType
* wxControl::GetObjectFormIndex(uint16_t& index
) const
205 FormType
* form
= GetParentForm();
207 index
= FrmGetObjectIndex(form
, GetId());
209 index
= frmInvalidObjectId
;
213 void* wxControl::GetObjectPtr() const
216 FormType
* form
= GetObjectFormIndex(index
);
217 if(form
==NULL
|| index
==frmInvalidObjectId
)return NULL
;
218 return FrmGetObjectPtr(form
,index
);
221 wxBorder
wxControl::GetDefaultBorder() const
223 // we want to automatically give controls a sunken style (confusingly,
224 // it may not really mean sunken at all as we map it to WS_EX_CLIENTEDGE
225 // which is not sunken at all under Windows XP -- rather, just the default)
226 return wxBORDER_SUNKEN
;
229 void wxControl::SetIntValue(int val
)
231 FormType
* form
= GetParentForm();
234 uint16_t index
= FrmGetObjectIndex(form
, GetId());
235 if(index
==frmInvalidObjectId
)
237 FrmSetControlValue(form
, index
, val
);
240 void wxControl::SetBoolValue(bool val
)
242 SetIntValue(val
?1:0);
245 bool wxControl::GetBoolValue() const
247 FormType
* form
= GetParentForm();
250 uint16_t index
= FrmGetObjectIndex(form
, GetId());
251 if(index
==frmInvalidObjectId
)
253 return ( FrmGetControlValue(form
, index
) == 1 );
256 wxSize
wxControl::DoGetBestSize() const
258 return wxSize(16, 16);
261 void wxControl::DoGetBounds( RectangleType
&rect
) const
263 FormType
* form
= GetParentForm();
266 uint16_t index
= FrmGetObjectIndex(form
,GetId());
267 if(index
==frmInvalidObjectId
)
269 FrmGetObjectBounds(form
,index
,&rect
);
272 void wxControl::DoGetPosition( int *x
, int *y
) const
282 void wxControl::DoGetSize( int *width
, int *height
) const
287 *width
= rect
.extent
.x
;
289 *height
= rect
.extent
.y
;
292 bool wxControl::Enable(bool enable
)
294 ControlType
*control
= (ControlType
*)GetObjectPtr();
295 if( (IsPalmControl()) || (control
== NULL
))
297 if( CtlEnabled(control
) == enable
)
299 CtlSetEnabled( control
, enable
);
303 bool wxControl::IsEnabled() const
305 ControlType
*control
= (ControlType
*)GetObjectPtr();
306 if( (IsPalmControl()) || (control
== NULL
))
308 return CtlEnabled(control
);
311 bool wxControl::IsShown() const
313 return StatGetAttribute ( statAttrBarVisible
, NULL
);
316 bool wxControl::Show( bool show
)
318 FormType
* form
= GetParentForm();
321 uint16_t index
= FrmGetObjectIndex(form
,GetId());
322 if(index
==frmInvalidObjectId
)
325 FrmShowObject(form
,index
);
327 FrmHideObject(form
,index
);
331 void wxControl::SetFieldLabel(const wxString
& label
)
333 FieldType
* field
= (FieldType
*)GetObjectPtr();
337 uint16_t newSize
= label
.Length() + 1;
338 MemHandle strHandle
= FldGetTextHandle(field
);
339 FldSetTextHandle(field
, NULL
);
342 if(MemHandleResize(strHandle
, newSize
)!=errNone
)
347 strHandle
= MemHandleNew( newSize
);
352 char* str
= (char*) MemHandleLock( strHandle
);
356 strcpy(str
, label
.c_str());
357 MemHandleUnlock(strHandle
);
358 FldSetTextHandle(field
, strHandle
);
359 FldRecalculateField(field
, true);
362 void wxControl::SetControlLabel(const wxString
& label
)
364 ControlType
* control
= (ControlType
*)GetObjectPtr();
367 CtlSetLabel(control
,wxEmptyString
);
370 CtlSetLabel(control
,m_label
.c_str());
373 void wxControl::SetLabel(const wxString
& label
)
376 SetFieldLabel(label
);
378 // unlike other native controls, slider has no label
379 if(IsPalmControl() && !wxDynamicCast(this,wxSlider
))
380 SetControlLabel(label
);
383 wxString
wxControl::GetFieldLabel()
385 FieldType
* field
= (FieldType
*)GetObjectPtr();
387 return wxEmptyString
;
388 return FldGetTextPtr(field
);
391 wxString
wxControl::GetControlLabel()
393 ControlType
* control
= (ControlType
*)GetObjectPtr();
395 return wxEmptyString
;
396 return CtlGetLabel(control
);
399 wxString
wxControl::GetLabel()
402 return GetFieldLabel();
404 // unlike other native controls, slider has no label
405 if(IsPalmControl() && !wxDynamicCast(this,wxSlider
))
406 return GetControlLabel();
408 return wxEmptyString
;
411 /* static */ wxVisualAttributes
412 wxControl::GetClassDefaultAttributes(wxWindowVariant
WXUNUSED(variant
))
414 wxVisualAttributes attrs
;
416 // old school (i.e. not "common") controls use the standard dialog font
418 attrs
.font
= wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
);
420 // most, or at least many, of the controls use the same colours as the
421 // buttons -- others will have to override this (and possibly simply call
422 // GetCompositeControlsDefaultAttributes() from their versions)
423 attrs
.colFg
= wxSystemSettings::GetColour(wxSYS_COLOUR_BTNTEXT
);
424 attrs
.colBg
= wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE
);
429 // another version for the "composite", i.e. non simple controls
430 /* static */ wxVisualAttributes
431 wxControl::GetCompositeControlsDefaultAttributes(wxWindowVariant
WXUNUSED(variant
))
433 wxVisualAttributes attrs
;
434 attrs
.font
= wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
);
435 attrs
.colFg
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
);
436 attrs
.colBg
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
);
441 // ----------------------------------------------------------------------------
443 // ----------------------------------------------------------------------------
445 bool wxControl::ProcessCommand(wxCommandEvent
& event
)
447 return GetEventHandler()->ProcessEvent(event
);
450 void wxControl::OnEraseBackground(wxEraseEvent
& event
)
454 WXHBRUSH
wxControl::OnCtlColor(WXHDC pDC
, WXHWND
WXUNUSED(pWnd
), WXUINT
WXUNUSED(nCtlColor
),
455 WXUINT
WXUNUSED(message
),
456 WXWPARAM
WXUNUSED(wParam
),
457 WXLPARAM
WXUNUSED(lParam
)
463 // ---------------------------------------------------------------------------
465 // ---------------------------------------------------------------------------
467 #endif // wxUSE_CONTROLS