]>
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"
32 #include "wx/dcclient.h"
34 #include "wx/settings.h"
35 #include "wx/button.h"
38 #include "wx/control.h"
39 #include "wx/toplevel.h"
40 #include "wx/checkbox.h"
41 #include "wx/tglbtn.h"
42 #include "wx/radiobut.h"
43 #include "wx/slider.h"
47 #include <StatusBar.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
= (FormType
*)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(int style
,
111 const wxString
& label
,
116 FormType
* form
= (FormType
*)GetParentForm();
121 wxCoord x
= pos
.x
== wxDefaultCoord
? 0 : pos
.x
,
122 y
= pos
.y
== wxDefaultCoord
? 0 : pos
.y
,
123 w
= size
.x
== wxDefaultCoord
? 1 : size
.x
,
124 h
= size
.y
== wxDefaultCoord
? 1 : size
.y
;
126 wxWindow
*win
= this;
127 while(win
->GetParent())
129 win
= win
->GetParent();
130 wxPoint
pt(win
->GetClientAreaOrigin());
135 ControlType
*control
= CtlNewControl(
138 (ControlStyleType
)style
,
152 m_palmControl
= true;
154 SetInitialBestSize(size
);
160 bool wxControl::PalmCreateField(const wxString
& label
,
167 FormType
* form
= (FormType
*)GetParentForm();
173 wxCoord x
= pos
.x
== wxDefaultCoord
? 0 : pos
.x
,
174 y
= pos
.y
== wxDefaultCoord
? 0 : pos
.y
,
175 w
= size
.x
== wxDefaultCoord
? 1 : size
.x
,
176 h
= size
.y
== wxDefaultCoord
? 1 : size
.y
;
178 AdjustForParentClientOrigin(x
, y
);
180 FieldType
*field
= FldNewField(
193 (JustificationType
)justification
,
204 SetInitialBestSize(size
);
210 // ----------------------------------------------------------------------------
212 // ----------------------------------------------------------------------------
214 WXFORMPTR
wxControl::GetParentForm() const
216 wxWindow
* parentTLW
= GetParent();
217 while ( parentTLW
&& !parentTLW
->IsTopLevel() )
219 parentTLW
= parentTLW
->GetParent();
221 wxTopLevelWindowPalm
* tlw
= wxDynamicCast(parentTLW
, wxTopLevelWindowPalm
);
224 return tlw
->GetForm();
227 WXFORMPTR
wxControl::GetObjectFormIndex(uint16_t& index
) const
229 FormType
* form
= (FormType
* )GetParentForm();
231 index
= FrmGetObjectIndex(form
, GetId());
233 index
= frmInvalidObjectId
;
237 void* wxControl::GetObjectPtr() const
240 FormType
* form
= (FormType
*)GetObjectFormIndex(index
);
241 if(form
==NULL
|| index
==frmInvalidObjectId
)return NULL
;
242 return FrmGetObjectPtr(form
,index
);
245 wxBorder
wxControl::GetDefaultBorder() const
247 // we want to automatically give controls a sunken style (confusingly,
248 // it may not really mean sunken at all as we map it to WS_EX_CLIENTEDGE
249 // which is not sunken at all under Windows XP -- rather, just the default)
250 return wxBORDER_SUNKEN
;
253 void wxControl::SetIntValue(int val
)
255 FormType
* form
= (FormType
*)GetParentForm();
258 uint16_t index
= FrmGetObjectIndex(form
, GetId());
259 if(index
==frmInvalidObjectId
)
261 FrmSetControlValue(form
, index
, val
);
264 void wxControl::SetBoolValue(bool val
)
266 SetIntValue(val
?1:0);
269 bool wxControl::GetBoolValue() const
271 FormType
* form
= (FormType
*)GetParentForm();
274 uint16_t index
= FrmGetObjectIndex(form
, GetId());
275 if(index
==frmInvalidObjectId
)
277 return ( FrmGetControlValue(form
, index
) == 1 );
280 wxSize
wxControl::DoGetBestSize() const
282 return wxSize(16, 16);
285 void wxControl::DoGetBounds( WXRECTANGLEPTR rect
) const
289 FormType
* form
= (FormType
*)GetParentForm();
292 uint16_t index
= FrmGetObjectIndex(form
,GetId());
293 if(index
==frmInvalidObjectId
)
295 FrmGetObjectBounds(form
,index
,(RectangleType
*)rect
);
298 void wxControl::DoSetBounds( WXRECTANGLEPTR rect
)
302 FormType
* form
= (FormType
*)GetParentForm();
305 uint16_t index
= FrmGetObjectIndex(form
,GetId());
306 if(index
==frmInvalidObjectId
)
308 FrmSetObjectBounds(form
,index
,(RectangleType
*)rect
);
311 void wxControl::DoGetPosition( int *x
, int *y
) const
314 AdjustForParentClientOrigin(ox
, oy
);
320 *x
= rect
.topLeft
.x
- ox
;
322 *y
= rect
.topLeft
.y
- oy
;
325 void wxControl::DoGetSize( int *width
, int *height
) const
331 *width
= rect
.extent
.x
;
333 *height
= rect
.extent
.y
;
336 void wxControl::DoMoveWindow(int x
, int y
, int width
, int height
)
338 wxRect area
= GetRect();
342 rect
.extent
.x
= width
;
343 rect
.extent
.y
= height
;
345 GetParent()->Refresh(true, &area
);
348 bool wxControl::Enable(bool enable
)
350 ControlType
*control
= (ControlType
*)GetObjectPtr();
351 if( !IsPalmControl() || (control
== NULL
))
353 if( CtlEnabled(control
) == enable
)
355 CtlSetEnabled( control
, enable
);
359 bool wxControl::IsEnabled() const
361 ControlType
*control
= (ControlType
*)GetObjectPtr();
362 if( !IsPalmControl() || (control
== NULL
))
364 return CtlEnabled(control
);
367 bool wxControl::IsShown() const
369 return StatGetAttribute ( statAttrBarVisible
, NULL
);
372 bool wxControl::Show( bool show
)
374 FormType
* form
= (FormType
*)GetParentForm();
377 uint16_t index
= FrmGetObjectIndex(form
,GetId());
378 if(index
==frmInvalidObjectId
)
381 FrmShowObject(form
,index
);
383 FrmHideObject(form
,index
);
387 void wxControl::SetFieldLabel(const wxString
& label
)
389 FieldType
* field
= (FieldType
*)GetObjectPtr();
393 uint16_t newSize
= label
.length() + 1;
394 MemHandle strHandle
= FldGetTextHandle(field
);
395 FldSetTextHandle(field
, NULL
);
398 if(MemHandleResize(strHandle
, newSize
)!=errNone
)
403 strHandle
= MemHandleNew( newSize
);
408 char* str
= (char*) MemHandleLock( strHandle
);
412 strcpy(str
, label
.c_str());
413 MemHandleUnlock(strHandle
);
414 FldSetTextHandle(field
, strHandle
);
415 FldRecalculateField(field
, true);
418 void wxControl::SetControlLabel(const wxString
& label
)
420 ControlType
* control
= (ControlType
*)GetObjectPtr();
423 CtlSetLabel(control
,wxEmptyString
);
426 CtlSetLabel(control
,m_label
.c_str());
429 void wxControl::SetLabel(const wxString
& label
)
432 SetFieldLabel(label
);
434 // unlike other native controls, slider has no label
435 if(IsPalmControl() && !wxDynamicCast(this,wxSlider
))
436 SetControlLabel(label
);
439 wxString
wxControl::GetFieldLabel()
441 FieldType
* field
= (FieldType
*)GetObjectPtr();
443 return wxEmptyString
;
444 return FldGetTextPtr(field
);
447 wxString
wxControl::GetControlLabel()
449 ControlType
* control
= (ControlType
*)GetObjectPtr();
451 return wxEmptyString
;
452 return CtlGetLabel(control
);
455 wxString
wxControl::GetLabel()
458 return GetFieldLabel();
460 // unlike other native controls, slider has no label
461 if(IsPalmControl() && !wxDynamicCast(this,wxSlider
))
462 return GetControlLabel();
464 return wxEmptyString
;
467 /* static */ wxVisualAttributes
468 wxControl::GetClassDefaultAttributes(wxWindowVariant
WXUNUSED(variant
))
470 wxVisualAttributes attrs
;
472 // old school (i.e. not "common") controls use the standard dialog font
474 attrs
.font
= wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
);
476 // most, or at least many, of the controls use the same colours as the
477 // buttons -- others will have to override this (and possibly simply call
478 // GetCompositeControlsDefaultAttributes() from their versions)
479 attrs
.colFg
= wxSystemSettings::GetColour(wxSYS_COLOUR_BTNTEXT
);
480 attrs
.colBg
= wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE
);
485 // another version for the "composite", i.e. non simple controls
486 /* static */ wxVisualAttributes
487 wxControl::GetCompositeControlsDefaultAttributes(wxWindowVariant
WXUNUSED(variant
))
489 wxVisualAttributes attrs
;
490 attrs
.font
= wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
);
491 attrs
.colFg
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
);
492 attrs
.colBg
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
);
497 // ----------------------------------------------------------------------------
499 // ----------------------------------------------------------------------------
501 bool wxControl::ProcessCommand(wxCommandEvent
& event
)
503 return GetEventHandler()->ProcessEvent(event
);
506 void wxControl::OnEraseBackground(wxEraseEvent
& event
)
510 #endif // wxUSE_CONTROLS