]>
git.saurik.com Git - wxWidgets.git/blob - src/palmos/control.cpp
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 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
29 #include "wx/control.h"
34 #include "wx/dcclient.h"
36 #include "wx/settings.h"
37 #include "wx/button.h"
38 #include "wx/checkbox.h"
39 #include "wx/radiobut.h"
40 #include "wx/slider.h"
41 #include "wx/toplevel.h"
44 #include "wx/tglbtn.h"
49 #include <StatusBar.h>
51 #include <PenInputMgr.h>
52 #endif // __WXPALMOS6__
54 // ----------------------------------------------------------------------------
56 // ----------------------------------------------------------------------------
58 IMPLEMENT_ABSTRACT_CLASS(wxControl
, wxWindow
)
60 BEGIN_EVENT_TABLE(wxControl
, wxWindow
)
61 EVT_ERASE_BACKGROUND(wxControl::OnEraseBackground
)
64 // ============================================================================
65 // wxControl implementation
66 // ============================================================================
68 // ----------------------------------------------------------------------------
69 // wxControl ctor/dtor
70 // ----------------------------------------------------------------------------
72 void wxControl::Init()
74 m_palmControl
= false;
78 wxControl::~wxControl()
80 SetLabel(wxEmptyString
);
81 m_isBeingDeleted
= true;
86 FormType
* form
= (FormType
*)GetObjectFormIndex(index
);
87 if(form
!=NULL
&& index
!=frmInvalidObjectId
)
89 FrmRemoveObject((FormType
**)&form
,index
);
93 // ----------------------------------------------------------------------------
94 // control window creation
95 // ----------------------------------------------------------------------------
97 bool wxControl::Create(wxWindow
*parent
,
102 const wxValidator
& wxVALIDATOR_PARAM(validator
),
103 const wxString
& name
)
105 if ( !wxWindow::Create(parent
, id
, pos
, size
, style
, name
) )
109 SetValidator(validator
);
115 bool wxControl::PalmCreateControl(int style
,
116 const wxString
& label
,
121 FormType
* form
= (FormType
*)GetParentForm();
126 wxCoord x
= pos
.x
== wxDefaultCoord
? 0 : pos
.x
,
127 y
= pos
.y
== wxDefaultCoord
? 0 : pos
.y
,
128 w
= size
.x
== wxDefaultCoord
? 1 : size
.x
,
129 h
= size
.y
== wxDefaultCoord
? 1 : size
.y
;
131 wxWindow
*win
= this;
132 while(win
->GetParent())
134 win
= win
->GetParent();
135 wxPoint
pt(win
->GetClientAreaOrigin());
140 ControlType
*control
= CtlNewControl(
143 (ControlStyleType
)style
,
157 m_palmControl
= true;
159 SetInitialSize(size
);
165 bool wxControl::PalmCreateField(const wxString
& label
,
172 FormType
* form
= (FormType
*)GetParentForm();
178 wxCoord x
= pos
.x
== wxDefaultCoord
? 0 : pos
.x
,
179 y
= pos
.y
== wxDefaultCoord
? 0 : pos
.y
,
180 w
= size
.x
== wxDefaultCoord
? 1 : size
.x
,
181 h
= size
.y
== wxDefaultCoord
? 1 : size
.y
;
183 AdjustForParentClientOrigin(x
, y
);
185 FieldType
*field
= FldNewField(
198 (JustificationType
)justification
,
209 SetInitialSize(size
);
215 // ----------------------------------------------------------------------------
217 // ----------------------------------------------------------------------------
219 WXFORMPTR
wxControl::GetParentForm() const
221 wxWindow
* parentTLW
= GetParent();
222 while ( parentTLW
&& !parentTLW
->IsTopLevel() )
224 parentTLW
= parentTLW
->GetParent();
226 wxTopLevelWindowPalm
* tlw
= wxDynamicCast(parentTLW
, wxTopLevelWindowPalm
);
229 return tlw
->GetForm();
232 WXFORMPTR
wxControl::GetObjectFormIndex(uint16_t& index
) const
234 FormType
* form
= (FormType
* )GetParentForm();
236 index
= FrmGetObjectIndex(form
, GetId());
238 index
= frmInvalidObjectId
;
242 void* wxControl::GetObjectPtr() const
245 FormType
* form
= (FormType
*)GetObjectFormIndex(index
);
246 if(form
==NULL
|| index
==frmInvalidObjectId
)return NULL
;
247 return FrmGetObjectPtr(form
,index
);
250 wxBorder
wxControl::GetDefaultBorder() const
252 // we want to automatically give controls a sunken style (confusingly,
253 // it may not really mean sunken at all as we map it to WS_EX_CLIENTEDGE
254 // which is not sunken at all under Windows XP -- rather, just the default)
255 return wxBORDER_SUNKEN
;
258 void wxControl::SetIntValue(int val
)
260 FormType
* form
= (FormType
*)GetParentForm();
263 uint16_t index
= FrmGetObjectIndex(form
, GetId());
264 if(index
==frmInvalidObjectId
)
266 FrmSetControlValue(form
, index
, val
);
269 void wxControl::SetBoolValue(bool val
)
271 SetIntValue(val
?1:0);
274 bool wxControl::GetBoolValue() const
276 FormType
* form
= (FormType
*)GetParentForm();
279 uint16_t index
= FrmGetObjectIndex(form
, GetId());
280 if(index
==frmInvalidObjectId
)
282 return ( FrmGetControlValue(form
, index
) == 1 );
285 wxSize
wxControl::DoGetBestSize() const
287 return wxSize(16, 16);
290 void wxControl::DoGetBounds( WXRECTANGLEPTR rect
) const
294 FormType
* form
= (FormType
*)GetParentForm();
297 uint16_t index
= FrmGetObjectIndex(form
,GetId());
298 if(index
==frmInvalidObjectId
)
300 FrmGetObjectBounds(form
,index
,(RectangleType
*)rect
);
303 void wxControl::DoSetBounds( WXRECTANGLEPTR rect
)
307 FormType
* form
= (FormType
*)GetParentForm();
310 uint16_t index
= FrmGetObjectIndex(form
,GetId());
311 if(index
==frmInvalidObjectId
)
313 FrmSetObjectBounds(form
,index
,(RectangleType
*)rect
);
316 void wxControl::DoGetPosition( int *x
, int *y
) const
319 AdjustForParentClientOrigin(ox
, oy
);
325 *x
= rect
.topLeft
.x
- ox
;
327 *y
= rect
.topLeft
.y
- oy
;
330 void wxControl::DoGetSize( int *width
, int *height
) const
336 *width
= rect
.extent
.x
;
338 *height
= rect
.extent
.y
;
341 void wxControl::DoMoveWindow(int x
, int y
, int width
, int height
)
343 wxRect area
= GetRect();
347 rect
.extent
.x
= width
;
348 rect
.extent
.y
= height
;
350 GetParent()->Refresh(true, &area
);
353 bool wxControl::Enable(bool enable
)
355 ControlType
*control
= (ControlType
*)GetObjectPtr();
356 if( !IsPalmControl() || (control
== NULL
))
358 if( CtlEnabled(control
) == enable
)
360 CtlSetEnabled( control
, enable
);
364 bool wxControl::IsEnabled() const
366 ControlType
*control
= (ControlType
*)GetObjectPtr();
367 if( !IsPalmControl() || (control
== NULL
))
369 return CtlEnabled(control
);
372 bool wxControl::IsShown() const
374 return StatGetAttribute ( statAttrBarVisible
, NULL
);
377 bool wxControl::Show( bool show
)
379 FormType
* form
= (FormType
*)GetParentForm();
382 uint16_t index
= FrmGetObjectIndex(form
,GetId());
383 if(index
==frmInvalidObjectId
)
386 FrmShowObject(form
,index
);
388 FrmHideObject(form
,index
);
392 void wxControl::SetFieldLabel(const wxString
& label
)
394 FieldType
* field
= (FieldType
*)GetObjectPtr();
398 uint16_t newSize
= label
.length() + 1;
399 MemHandle strHandle
= FldGetTextHandle(field
);
400 FldSetTextHandle(field
, NULL
);
403 if(MemHandleResize(strHandle
, newSize
)!=errNone
)
408 strHandle
= MemHandleNew( newSize
);
413 char* str
= (char*) MemHandleLock( strHandle
);
417 strcpy(str
, label
.c_str());
418 MemHandleUnlock(strHandle
);
419 FldSetTextHandle(field
, strHandle
);
420 FldRecalculateField(field
, true);
423 void wxControl::SetControlLabel(const wxString
& label
)
425 ControlType
* control
= (ControlType
*)GetObjectPtr();
428 CtlSetLabel(control
, "");
431 CtlSetLabel(control
,m_label
.c_str());
434 void wxControl::SetLabel(const wxString
& label
)
437 SetFieldLabel(label
);
439 // unlike other native controls, slider has no label
440 if(IsPalmControl() && !wxDynamicCast(this,wxSlider
))
441 SetControlLabel(label
);
444 wxString
wxControl::GetFieldLabel()
446 FieldType
* field
= (FieldType
*)GetObjectPtr();
448 return wxEmptyString
;
449 return FldGetTextPtr(field
);
452 wxString
wxControl::GetControlLabel()
454 ControlType
* control
= (ControlType
*)GetObjectPtr();
456 return wxEmptyString
;
457 return CtlGetLabel(control
);
460 wxString
wxControl::GetLabel()
463 return GetFieldLabel();
465 // unlike other native controls, slider has no label
466 if(IsPalmControl() && !wxDynamicCast(this,wxSlider
))
467 return GetControlLabel();
469 return wxEmptyString
;
472 /* static */ wxVisualAttributes
473 wxControl::GetClassDefaultAttributes(wxWindowVariant
WXUNUSED(variant
))
475 wxVisualAttributes attrs
;
477 // old school (i.e. not "common") controls use the standard dialog font
479 attrs
.font
= wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
);
481 // most, or at least many, of the controls use the same colours as the
482 // buttons -- others will have to override this (and possibly simply call
483 // GetCompositeControlsDefaultAttributes() from their versions)
484 attrs
.colFg
= wxSystemSettings::GetColour(wxSYS_COLOUR_BTNTEXT
);
485 attrs
.colBg
= wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE
);
490 // another version for the "composite", i.e. non simple controls
491 /* static */ wxVisualAttributes
492 wxControl::GetCompositeControlsDefaultAttributes(wxWindowVariant
WXUNUSED(variant
))
494 wxVisualAttributes attrs
;
495 attrs
.font
= wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
);
496 attrs
.colFg
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
);
497 attrs
.colBg
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
);
502 // ----------------------------------------------------------------------------
504 // ----------------------------------------------------------------------------
506 bool wxControl::ProcessCommand(wxCommandEvent
& event
)
508 return HandleWindowEvent(event
);
511 void wxControl::OnEraseBackground(wxEraseEvent
& event
)
515 #endif // wxUSE_CONTROLS