]>
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 #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"
51 #include <StatusBar.h>
53 // ----------------------------------------------------------------------------
55 // ----------------------------------------------------------------------------
57 IMPLEMENT_ABSTRACT_CLASS(wxControl
, wxWindow
)
59 BEGIN_EVENT_TABLE(wxControl
, wxWindow
)
60 EVT_ERASE_BACKGROUND(wxControl::OnEraseBackground
)
63 // ============================================================================
64 // wxControl implementation
65 // ============================================================================
67 // ----------------------------------------------------------------------------
68 // wxControl ctor/dtor
69 // ----------------------------------------------------------------------------
71 void wxControl::Init()
73 m_palmControl
= false;
77 wxControl::~wxControl()
79 SetLabel(wxEmptyString
);
80 m_isBeingDeleted
= true;
85 FormType
* form
= (FormType
*)GetObjectFormIndex(index
);
86 if(form
!=NULL
&& index
!=frmInvalidObjectId
)
88 FrmRemoveObject((FormType
**)&form
,index
);
92 // ----------------------------------------------------------------------------
93 // control window creation
94 // ----------------------------------------------------------------------------
96 bool wxControl::Create(wxWindow
*parent
,
101 const wxValidator
& wxVALIDATOR_PARAM(validator
),
102 const wxString
& name
)
104 if ( !wxWindow::Create(parent
, id
, pos
, size
, style
, name
) )
108 SetValidator(validator
);
114 bool wxControl::PalmCreateControl(int style
,
115 const wxString
& label
,
120 FormType
* form
= (FormType
*)GetParentForm();
125 wxCoord x
= pos
.x
== wxDefaultCoord
? 0 : pos
.x
,
126 y
= pos
.y
== wxDefaultCoord
? 0 : pos
.y
,
127 w
= size
.x
== wxDefaultCoord
? 1 : size
.x
,
128 h
= size
.y
== wxDefaultCoord
? 1 : size
.y
;
130 wxWindow
*win
= this;
131 while(win
->GetParent())
133 win
= win
->GetParent();
134 wxPoint
pt(win
->GetClientAreaOrigin());
139 ControlType
*control
= CtlNewControl(
142 (ControlStyleType
)style
,
156 m_palmControl
= true;
158 SetInitialBestSize(size
);
164 bool wxControl::PalmCreateField(const wxString
& label
,
171 FormType
* form
= (FormType
*)GetParentForm();
177 wxCoord x
= pos
.x
== wxDefaultCoord
? 0 : pos
.x
,
178 y
= pos
.y
== wxDefaultCoord
? 0 : pos
.y
,
179 w
= size
.x
== wxDefaultCoord
? 1 : size
.x
,
180 h
= size
.y
== wxDefaultCoord
? 1 : size
.y
;
182 AdjustForParentClientOrigin(x
, y
);
184 FieldType
*field
= FldNewField(
197 (JustificationType
)justification
,
208 SetInitialBestSize(size
);
214 // ----------------------------------------------------------------------------
216 // ----------------------------------------------------------------------------
218 WXFORMPTR
wxControl::GetParentForm() const
220 wxWindow
* parentTLW
= GetParent();
221 while ( parentTLW
&& !parentTLW
->IsTopLevel() )
223 parentTLW
= parentTLW
->GetParent();
225 wxTopLevelWindowPalm
* tlw
= wxDynamicCast(parentTLW
, wxTopLevelWindowPalm
);
228 return tlw
->GetForm();
231 WXFORMPTR
wxControl::GetObjectFormIndex(uint16_t& index
) const
233 FormType
* form
= (FormType
* )GetParentForm();
235 index
= FrmGetObjectIndex(form
, GetId());
237 index
= frmInvalidObjectId
;
241 void* wxControl::GetObjectPtr() const
244 FormType
* form
= (FormType
*)GetObjectFormIndex(index
);
245 if(form
==NULL
|| index
==frmInvalidObjectId
)return NULL
;
246 return FrmGetObjectPtr(form
,index
);
249 wxBorder
wxControl::GetDefaultBorder() const
251 // we want to automatically give controls a sunken style (confusingly,
252 // it may not really mean sunken at all as we map it to WS_EX_CLIENTEDGE
253 // which is not sunken at all under Windows XP -- rather, just the default)
254 return wxBORDER_SUNKEN
;
257 void wxControl::SetIntValue(int val
)
259 FormType
* form
= (FormType
*)GetParentForm();
262 uint16_t index
= FrmGetObjectIndex(form
, GetId());
263 if(index
==frmInvalidObjectId
)
265 FrmSetControlValue(form
, index
, val
);
268 void wxControl::SetBoolValue(bool val
)
270 SetIntValue(val
?1:0);
273 bool wxControl::GetBoolValue() const
275 FormType
* form
= (FormType
*)GetParentForm();
278 uint16_t index
= FrmGetObjectIndex(form
, GetId());
279 if(index
==frmInvalidObjectId
)
281 return ( FrmGetControlValue(form
, index
) == 1 );
284 wxSize
wxControl::DoGetBestSize() const
286 return wxSize(16, 16);
289 void wxControl::DoGetBounds( WXRECTANGLEPTR rect
) const
293 FormType
* form
= (FormType
*)GetParentForm();
296 uint16_t index
= FrmGetObjectIndex(form
,GetId());
297 if(index
==frmInvalidObjectId
)
299 FrmGetObjectBounds(form
,index
,(RectangleType
*)rect
);
302 void wxControl::DoSetBounds( WXRECTANGLEPTR rect
)
306 FormType
* form
= (FormType
*)GetParentForm();
309 uint16_t index
= FrmGetObjectIndex(form
,GetId());
310 if(index
==frmInvalidObjectId
)
312 FrmSetObjectBounds(form
,index
,(RectangleType
*)rect
);
315 void wxControl::DoGetPosition( int *x
, int *y
) const
318 AdjustForParentClientOrigin(ox
, oy
);
324 *x
= rect
.topLeft
.x
- ox
;
326 *y
= rect
.topLeft
.y
- oy
;
329 void wxControl::DoGetSize( int *width
, int *height
) const
335 *width
= rect
.extent
.x
;
337 *height
= rect
.extent
.y
;
340 void wxControl::DoMoveWindow(int x
, int y
, int width
, int height
)
342 wxRect area
= GetRect();
346 rect
.extent
.x
= width
;
347 rect
.extent
.y
= height
;
349 GetParent()->Refresh(true, &area
);
352 bool wxControl::Enable(bool enable
)
354 ControlType
*control
= (ControlType
*)GetObjectPtr();
355 if( !IsPalmControl() || (control
== NULL
))
357 if( CtlEnabled(control
) == enable
)
359 CtlSetEnabled( control
, enable
);
363 bool wxControl::IsEnabled() const
365 ControlType
*control
= (ControlType
*)GetObjectPtr();
366 if( !IsPalmControl() || (control
== NULL
))
368 return CtlEnabled(control
);
371 bool wxControl::IsShown() const
373 return StatGetAttribute ( statAttrBarVisible
, NULL
);
376 bool wxControl::Show( bool show
)
378 FormType
* form
= (FormType
*)GetParentForm();
381 uint16_t index
= FrmGetObjectIndex(form
,GetId());
382 if(index
==frmInvalidObjectId
)
385 FrmShowObject(form
,index
);
387 FrmHideObject(form
,index
);
391 void wxControl::SetFieldLabel(const wxString
& label
)
393 FieldType
* field
= (FieldType
*)GetObjectPtr();
397 uint16_t newSize
= label
.Length() + 1;
398 MemHandle strHandle
= FldGetTextHandle(field
);
399 FldSetTextHandle(field
, NULL
);
402 if(MemHandleResize(strHandle
, newSize
)!=errNone
)
407 strHandle
= MemHandleNew( newSize
);
412 char* str
= (char*) MemHandleLock( strHandle
);
416 strcpy(str
, label
.c_str());
417 MemHandleUnlock(strHandle
);
418 FldSetTextHandle(field
, strHandle
);
419 FldRecalculateField(field
, true);
422 void wxControl::SetControlLabel(const wxString
& label
)
424 ControlType
* control
= (ControlType
*)GetObjectPtr();
427 CtlSetLabel(control
,wxEmptyString
);
430 CtlSetLabel(control
,m_label
.c_str());
433 void wxControl::SetLabel(const wxString
& label
)
436 SetFieldLabel(label
);
438 // unlike other native controls, slider has no label
439 if(IsPalmControl() && !wxDynamicCast(this,wxSlider
))
440 SetControlLabel(label
);
443 wxString
wxControl::GetFieldLabel()
445 FieldType
* field
= (FieldType
*)GetObjectPtr();
447 return wxEmptyString
;
448 return FldGetTextPtr(field
);
451 wxString
wxControl::GetControlLabel()
453 ControlType
* control
= (ControlType
*)GetObjectPtr();
455 return wxEmptyString
;
456 return CtlGetLabel(control
);
459 wxString
wxControl::GetLabel()
462 return GetFieldLabel();
464 // unlike other native controls, slider has no label
465 if(IsPalmControl() && !wxDynamicCast(this,wxSlider
))
466 return GetControlLabel();
468 return wxEmptyString
;
471 /* static */ wxVisualAttributes
472 wxControl::GetClassDefaultAttributes(wxWindowVariant
WXUNUSED(variant
))
474 wxVisualAttributes attrs
;
476 // old school (i.e. not "common") controls use the standard dialog font
478 attrs
.font
= wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
);
480 // most, or at least many, of the controls use the same colours as the
481 // buttons -- others will have to override this (and possibly simply call
482 // GetCompositeControlsDefaultAttributes() from their versions)
483 attrs
.colFg
= wxSystemSettings::GetColour(wxSYS_COLOUR_BTNTEXT
);
484 attrs
.colBg
= wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE
);
489 // another version for the "composite", i.e. non simple controls
490 /* static */ wxVisualAttributes
491 wxControl::GetCompositeControlsDefaultAttributes(wxWindowVariant
WXUNUSED(variant
))
493 wxVisualAttributes attrs
;
494 attrs
.font
= wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
);
495 attrs
.colFg
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
);
496 attrs
.colBg
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
);
501 // ----------------------------------------------------------------------------
503 // ----------------------------------------------------------------------------
505 bool wxControl::ProcessCommand(wxCommandEvent
& event
)
507 return GetEventHandler()->ProcessEvent(event
);
510 void wxControl::OnEraseBackground(wxEraseEvent
& event
)
514 #endif // wxUSE_CONTROLS