]>
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"
43 #include "wx/toplevel.h"
44 #include "wx/tglbtn.h"
48 #include <StatusBar.h>
50 // ----------------------------------------------------------------------------
52 // ----------------------------------------------------------------------------
54 IMPLEMENT_ABSTRACT_CLASS(wxControl
, wxWindow
)
56 BEGIN_EVENT_TABLE(wxControl
, wxWindow
)
57 EVT_ERASE_BACKGROUND(wxControl::OnEraseBackground
)
60 // ============================================================================
61 // wxControl implementation
62 // ============================================================================
64 // ----------------------------------------------------------------------------
65 // wxControl ctor/dtor
66 // ----------------------------------------------------------------------------
68 void wxControl::Init()
70 m_palmControl
= false;
74 wxControl::~wxControl()
76 SetLabel(wxEmptyString
);
77 m_isBeingDeleted
= true;
82 FormType
* form
= (FormType
*)GetObjectFormIndex(index
);
83 if(form
!=NULL
&& index
!=frmInvalidObjectId
)
85 FrmRemoveObject((FormType
**)&form
,index
);
89 // ----------------------------------------------------------------------------
90 // control window creation
91 // ----------------------------------------------------------------------------
93 bool wxControl::Create(wxWindow
*parent
,
98 const wxValidator
& wxVALIDATOR_PARAM(validator
),
101 if ( !wxWindow::Create(parent
, id
, pos
, size
, style
, name
) )
105 SetValidator(validator
);
111 bool wxControl::PalmCreateControl(int style
,
112 const wxString
& label
,
117 FormType
* form
= (FormType
*)GetParentForm();
122 wxCoord x
= pos
.x
== wxDefaultCoord
? 0 : pos
.x
,
123 y
= pos
.y
== wxDefaultCoord
? 0 : pos
.y
,
124 w
= size
.x
== wxDefaultCoord
? 1 : size
.x
,
125 h
= size
.y
== wxDefaultCoord
? 1 : size
.y
;
127 wxWindow
*win
= this;
128 while(win
->GetParent())
130 win
= win
->GetParent();
131 wxPoint
pt(win
->GetClientAreaOrigin());
136 ControlType
*control
= CtlNewControl(
139 (ControlStyleType
)style
,
153 m_palmControl
= true;
155 SetInitialBestSize(size
);
161 bool wxControl::PalmCreateField(const wxString
& label
,
168 FormType
* form
= (FormType
*)GetParentForm();
174 wxCoord x
= pos
.x
== wxDefaultCoord
? 0 : pos
.x
,
175 y
= pos
.y
== wxDefaultCoord
? 0 : pos
.y
,
176 w
= size
.x
== wxDefaultCoord
? 1 : size
.x
,
177 h
= size
.y
== wxDefaultCoord
? 1 : size
.y
;
179 AdjustForParentClientOrigin(x
, y
);
181 FieldType
*field
= FldNewField(
194 (JustificationType
)justification
,
205 SetInitialBestSize(size
);
211 // ----------------------------------------------------------------------------
213 // ----------------------------------------------------------------------------
215 WXFORMPTR
wxControl::GetParentForm() const
217 wxWindow
* parentTLW
= GetParent();
218 while ( parentTLW
&& !parentTLW
->IsTopLevel() )
220 parentTLW
= parentTLW
->GetParent();
222 wxTopLevelWindowPalm
* tlw
= wxDynamicCast(parentTLW
, wxTopLevelWindowPalm
);
225 return tlw
->GetForm();
228 WXFORMPTR
wxControl::GetObjectFormIndex(uint16_t& index
) const
230 FormType
* form
= (FormType
* )GetParentForm();
232 index
= FrmGetObjectIndex(form
, GetId());
234 index
= frmInvalidObjectId
;
238 void* wxControl::GetObjectPtr() const
241 FormType
* form
= (FormType
*)GetObjectFormIndex(index
);
242 if(form
==NULL
|| index
==frmInvalidObjectId
)return NULL
;
243 return FrmGetObjectPtr(form
,index
);
246 wxBorder
wxControl::GetDefaultBorder() const
248 // we want to automatically give controls a sunken style (confusingly,
249 // it may not really mean sunken at all as we map it to WS_EX_CLIENTEDGE
250 // which is not sunken at all under Windows XP -- rather, just the default)
251 return wxBORDER_SUNKEN
;
254 void wxControl::SetIntValue(int val
)
256 FormType
* form
= (FormType
*)GetParentForm();
259 uint16_t index
= FrmGetObjectIndex(form
, GetId());
260 if(index
==frmInvalidObjectId
)
262 FrmSetControlValue(form
, index
, val
);
265 void wxControl::SetBoolValue(bool val
)
267 SetIntValue(val
?1:0);
270 bool wxControl::GetBoolValue() const
272 FormType
* form
= (FormType
*)GetParentForm();
275 uint16_t index
= FrmGetObjectIndex(form
, GetId());
276 if(index
==frmInvalidObjectId
)
278 return ( FrmGetControlValue(form
, index
) == 1 );
281 wxSize
wxControl::DoGetBestSize() const
283 return wxSize(16, 16);
286 void wxControl::DoGetBounds( WXRECTANGLEPTR rect
) const
290 FormType
* form
= (FormType
*)GetParentForm();
293 uint16_t index
= FrmGetObjectIndex(form
,GetId());
294 if(index
==frmInvalidObjectId
)
296 FrmGetObjectBounds(form
,index
,(RectangleType
*)rect
);
299 void wxControl::DoSetBounds( WXRECTANGLEPTR rect
)
303 FormType
* form
= (FormType
*)GetParentForm();
306 uint16_t index
= FrmGetObjectIndex(form
,GetId());
307 if(index
==frmInvalidObjectId
)
309 FrmSetObjectBounds(form
,index
,(RectangleType
*)rect
);
312 void wxControl::DoGetPosition( int *x
, int *y
) const
315 AdjustForParentClientOrigin(ox
, oy
);
321 *x
= rect
.topLeft
.x
- ox
;
323 *y
= rect
.topLeft
.y
- oy
;
326 void wxControl::DoGetSize( int *width
, int *height
) const
332 *width
= rect
.extent
.x
;
334 *height
= rect
.extent
.y
;
337 void wxControl::DoMoveWindow(int x
, int y
, int width
, int height
)
339 wxRect area
= GetRect();
343 rect
.extent
.x
= width
;
344 rect
.extent
.y
= height
;
346 GetParent()->Refresh(true, &area
);
349 bool wxControl::Enable(bool enable
)
351 ControlType
*control
= (ControlType
*)GetObjectPtr();
352 if( !IsPalmControl() || (control
== NULL
))
354 if( CtlEnabled(control
) == enable
)
356 CtlSetEnabled( control
, enable
);
360 bool wxControl::IsEnabled() const
362 ControlType
*control
= (ControlType
*)GetObjectPtr();
363 if( !IsPalmControl() || (control
== NULL
))
365 return CtlEnabled(control
);
368 bool wxControl::IsShown() const
370 return StatGetAttribute ( statAttrBarVisible
, NULL
);
373 bool wxControl::Show( bool show
)
375 FormType
* form
= (FormType
*)GetParentForm();
378 uint16_t index
= FrmGetObjectIndex(form
,GetId());
379 if(index
==frmInvalidObjectId
)
382 FrmShowObject(form
,index
);
384 FrmHideObject(form
,index
);
388 void wxControl::SetFieldLabel(const wxString
& label
)
390 FieldType
* field
= (FieldType
*)GetObjectPtr();
394 uint16_t newSize
= label
.length() + 1;
395 MemHandle strHandle
= FldGetTextHandle(field
);
396 FldSetTextHandle(field
, NULL
);
399 if(MemHandleResize(strHandle
, newSize
)!=errNone
)
404 strHandle
= MemHandleNew( newSize
);
409 char* str
= (char*) MemHandleLock( strHandle
);
413 strcpy(str
, label
.c_str());
414 MemHandleUnlock(strHandle
);
415 FldSetTextHandle(field
, strHandle
);
416 FldRecalculateField(field
, true);
419 void wxControl::SetControlLabel(const wxString
& label
)
421 ControlType
* control
= (ControlType
*)GetObjectPtr();
424 CtlSetLabel(control
,wxEmptyString
);
427 CtlSetLabel(control
,m_label
.c_str());
430 void wxControl::SetLabel(const wxString
& label
)
433 SetFieldLabel(label
);
435 // unlike other native controls, slider has no label
436 if(IsPalmControl() && !wxDynamicCast(this,wxSlider
))
437 SetControlLabel(label
);
440 wxString
wxControl::GetFieldLabel()
442 FieldType
* field
= (FieldType
*)GetObjectPtr();
444 return wxEmptyString
;
445 return FldGetTextPtr(field
);
448 wxString
wxControl::GetControlLabel()
450 ControlType
* control
= (ControlType
*)GetObjectPtr();
452 return wxEmptyString
;
453 return CtlGetLabel(control
);
456 wxString
wxControl::GetLabel()
459 return GetFieldLabel();
461 // unlike other native controls, slider has no label
462 if(IsPalmControl() && !wxDynamicCast(this,wxSlider
))
463 return GetControlLabel();
465 return wxEmptyString
;
468 /* static */ wxVisualAttributes
469 wxControl::GetClassDefaultAttributes(wxWindowVariant
WXUNUSED(variant
))
471 wxVisualAttributes attrs
;
473 // old school (i.e. not "common") controls use the standard dialog font
475 attrs
.font
= wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
);
477 // most, or at least many, of the controls use the same colours as the
478 // buttons -- others will have to override this (and possibly simply call
479 // GetCompositeControlsDefaultAttributes() from their versions)
480 attrs
.colFg
= wxSystemSettings::GetColour(wxSYS_COLOUR_BTNTEXT
);
481 attrs
.colBg
= wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE
);
486 // another version for the "composite", i.e. non simple controls
487 /* static */ wxVisualAttributes
488 wxControl::GetCompositeControlsDefaultAttributes(wxWindowVariant
WXUNUSED(variant
))
490 wxVisualAttributes attrs
;
491 attrs
.font
= wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
);
492 attrs
.colFg
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
);
493 attrs
.colBg
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
);
498 // ----------------------------------------------------------------------------
500 // ----------------------------------------------------------------------------
502 bool wxControl::ProcessCommand(wxCommandEvent
& event
)
504 return GetEventHandler()->ProcessEvent(event
);
507 void wxControl::OnEraseBackground(wxEraseEvent
& event
)
511 #endif // wxUSE_CONTROLS