]>
git.saurik.com Git - wxWidgets.git/blob - src/palmos/control.cpp
66dd535de7b2720861c1229ee20e74003f1fef92
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()
82 SetLabel(wxEmptyString
);
87 FormType
* form
= (FormType
*)GetObjectFormIndex(index
);
88 if(form
!=NULL
&& index
!=frmInvalidObjectId
)
90 FrmRemoveObject((FormType
**)&form
,index
);
94 // ----------------------------------------------------------------------------
95 // control window creation
96 // ----------------------------------------------------------------------------
98 bool wxControl::Create(wxWindow
*parent
,
103 const wxValidator
& wxVALIDATOR_PARAM(validator
),
104 const wxString
& name
)
106 if ( !wxWindow::Create(parent
, id
, pos
, size
, style
, name
) )
110 SetValidator(validator
);
116 bool wxControl::PalmCreateControl(int style
,
117 const wxString
& label
,
122 FormType
* form
= (FormType
*)GetParentForm();
127 wxCoord x
= pos
.x
== wxDefaultCoord
? 0 : pos
.x
,
128 y
= pos
.y
== wxDefaultCoord
? 0 : pos
.y
,
129 w
= size
.x
== wxDefaultCoord
? 1 : size
.x
,
130 h
= size
.y
== wxDefaultCoord
? 1 : size
.y
;
132 wxWindow
*win
= this;
133 while(win
->GetParent())
135 win
= win
->GetParent();
136 wxPoint
pt(win
->GetClientAreaOrigin());
141 ControlType
*control
= CtlNewControl(
144 (ControlStyleType
)style
,
158 m_palmControl
= true;
160 SetInitialSize(size
);
166 bool wxControl::PalmCreateField(const wxString
& label
,
173 FormType
* form
= (FormType
*)GetParentForm();
179 wxCoord x
= pos
.x
== wxDefaultCoord
? 0 : pos
.x
,
180 y
= pos
.y
== wxDefaultCoord
? 0 : pos
.y
,
181 w
= size
.x
== wxDefaultCoord
? 1 : size
.x
,
182 h
= size
.y
== wxDefaultCoord
? 1 : size
.y
;
184 AdjustForParentClientOrigin(x
, y
);
186 FieldType
*field
= FldNewField(
199 (JustificationType
)justification
,
210 SetInitialSize(size
);
216 // ----------------------------------------------------------------------------
218 // ----------------------------------------------------------------------------
220 WXFORMPTR
wxControl::GetParentForm() const
222 wxWindow
* parentTLW
= GetParent();
223 while ( parentTLW
&& !parentTLW
->IsTopLevel() )
225 parentTLW
= parentTLW
->GetParent();
227 wxTopLevelWindowPalm
* tlw
= wxDynamicCast(parentTLW
, wxTopLevelWindowPalm
);
230 return tlw
->GetForm();
233 WXFORMPTR
wxControl::GetObjectFormIndex(uint16_t& index
) const
235 FormType
* form
= (FormType
* )GetParentForm();
237 index
= FrmGetObjectIndex(form
, GetId());
239 index
= frmInvalidObjectId
;
243 void* wxControl::GetObjectPtr() const
246 FormType
* form
= (FormType
*)GetObjectFormIndex(index
);
247 if(form
==NULL
|| index
==frmInvalidObjectId
)return NULL
;
248 return FrmGetObjectPtr(form
,index
);
251 wxBorder
wxControl::GetDefaultBorder() const
253 // we want to automatically give controls a sunken style (confusingly,
254 // it may not really mean sunken at all as we map it to WS_EX_CLIENTEDGE
255 // which is not sunken at all under Windows XP -- rather, just the default)
256 return wxBORDER_SUNKEN
;
259 void wxControl::SetIntValue(int val
)
261 FormType
* form
= (FormType
*)GetParentForm();
264 uint16_t index
= FrmGetObjectIndex(form
, GetId());
265 if(index
==frmInvalidObjectId
)
267 FrmSetControlValue(form
, index
, val
);
270 void wxControl::SetBoolValue(bool val
)
272 SetIntValue(val
?1:0);
275 bool wxControl::GetBoolValue() const
277 FormType
* form
= (FormType
*)GetParentForm();
280 uint16_t index
= FrmGetObjectIndex(form
, GetId());
281 if(index
==frmInvalidObjectId
)
283 return ( FrmGetControlValue(form
, index
) == 1 );
286 wxSize
wxControl::DoGetBestSize() const
288 return wxSize(16, 16);
291 void wxControl::DoGetBounds( WXRECTANGLEPTR rect
) const
295 FormType
* form
= (FormType
*)GetParentForm();
298 uint16_t index
= FrmGetObjectIndex(form
,GetId());
299 if(index
==frmInvalidObjectId
)
301 FrmGetObjectBounds(form
,index
,(RectangleType
*)rect
);
304 void wxControl::DoSetBounds( WXRECTANGLEPTR rect
)
308 FormType
* form
= (FormType
*)GetParentForm();
311 uint16_t index
= FrmGetObjectIndex(form
,GetId());
312 if(index
==frmInvalidObjectId
)
314 FrmSetObjectBounds(form
,index
,(RectangleType
*)rect
);
317 void wxControl::DoGetPosition( int *x
, int *y
) const
320 AdjustForParentClientOrigin(ox
, oy
);
326 *x
= rect
.topLeft
.x
- ox
;
328 *y
= rect
.topLeft
.y
- oy
;
331 void wxControl::DoGetSize( int *width
, int *height
) const
337 *width
= rect
.extent
.x
;
339 *height
= rect
.extent
.y
;
342 void wxControl::DoMoveWindow(int x
, int y
, int width
, int height
)
344 wxRect area
= GetRect();
348 rect
.extent
.x
= width
;
349 rect
.extent
.y
= height
;
351 GetParent()->Refresh(true, &area
);
354 bool wxControl::Enable(bool enable
)
356 ControlType
*control
= (ControlType
*)GetObjectPtr();
357 if( !IsPalmControl() || (control
== NULL
))
359 if( CtlEnabled(control
) == enable
)
361 CtlSetEnabled( control
, enable
);
365 bool wxControl::IsEnabled() const
367 ControlType
*control
= (ControlType
*)GetObjectPtr();
368 if( !IsPalmControl() || (control
== NULL
))
370 return CtlEnabled(control
);
373 bool wxControl::IsShown() const
375 return StatGetAttribute ( statAttrBarVisible
, NULL
);
378 bool wxControl::Show( bool show
)
380 FormType
* form
= (FormType
*)GetParentForm();
383 uint16_t index
= FrmGetObjectIndex(form
,GetId());
384 if(index
==frmInvalidObjectId
)
387 FrmShowObject(form
,index
);
389 FrmHideObject(form
,index
);
393 void wxControl::SetFieldLabel(const wxString
& label
)
395 FieldType
* field
= (FieldType
*)GetObjectPtr();
399 uint16_t newSize
= label
.length() + 1;
400 MemHandle strHandle
= FldGetTextHandle(field
);
401 FldSetTextHandle(field
, NULL
);
404 if(MemHandleResize(strHandle
, newSize
)!=errNone
)
409 strHandle
= MemHandleNew( newSize
);
414 char* str
= (char*) MemHandleLock( strHandle
);
418 strcpy(str
, label
.c_str());
419 MemHandleUnlock(strHandle
);
420 FldSetTextHandle(field
, strHandle
);
421 FldRecalculateField(field
, true);
424 void wxControl::SetControlLabel(const wxString
& label
)
426 ControlType
* control
= (ControlType
*)GetObjectPtr();
429 CtlSetLabel(control
, "");
432 CtlSetLabel(control
,m_label
.c_str());
435 void wxControl::SetLabel(const wxString
& label
)
438 SetFieldLabel(label
);
440 // unlike other native controls, slider has no label
441 if(IsPalmControl() && !wxDynamicCast(this,wxSlider
))
442 SetControlLabel(label
);
445 wxString
wxControl::GetFieldLabel()
447 FieldType
* field
= (FieldType
*)GetObjectPtr();
449 return wxEmptyString
;
450 return FldGetTextPtr(field
);
453 wxString
wxControl::GetControlLabel()
455 ControlType
* control
= (ControlType
*)GetObjectPtr();
457 return wxEmptyString
;
458 return CtlGetLabel(control
);
461 wxString
wxControl::GetLabel()
464 return GetFieldLabel();
466 // unlike other native controls, slider has no label
467 if(IsPalmControl() && !wxDynamicCast(this,wxSlider
))
468 return GetControlLabel();
470 return wxEmptyString
;
473 /* static */ wxVisualAttributes
474 wxControl::GetClassDefaultAttributes(wxWindowVariant
WXUNUSED(variant
))
476 wxVisualAttributes attrs
;
478 // old school (i.e. not "common") controls use the standard dialog font
480 attrs
.font
= wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
);
482 // most, or at least many, of the controls use the same colours as the
483 // buttons -- others will have to override this (and possibly simply call
484 // GetCompositeControlsDefaultAttributes() from their versions)
485 attrs
.colFg
= wxSystemSettings::GetColour(wxSYS_COLOUR_BTNTEXT
);
486 attrs
.colBg
= wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE
);
491 // another version for the "composite", i.e. non simple controls
492 /* static */ wxVisualAttributes
493 wxControl::GetCompositeControlsDefaultAttributes(wxWindowVariant
WXUNUSED(variant
))
495 wxVisualAttributes attrs
;
496 attrs
.font
= wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
);
497 attrs
.colFg
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
);
498 attrs
.colBg
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
);
503 // ----------------------------------------------------------------------------
505 // ----------------------------------------------------------------------------
507 bool wxControl::ProcessCommand(wxCommandEvent
& event
)
509 return HandleWindowEvent(event
);
512 void wxControl::OnEraseBackground(wxEraseEvent
& event
)
516 #endif // wxUSE_CONTROLS