]>
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"
48 // ----------------------------------------------------------------------------
50 // ----------------------------------------------------------------------------
52 IMPLEMENT_ABSTRACT_CLASS(wxControl
, wxWindow
)
54 BEGIN_EVENT_TABLE(wxControl
, wxWindow
)
55 EVT_ERASE_BACKGROUND(wxControl::OnEraseBackground
)
58 // ============================================================================
59 // wxControl implementation
60 // ============================================================================
62 // ----------------------------------------------------------------------------
63 // wxControl ctor/dtor
64 // ----------------------------------------------------------------------------
66 wxControl::~wxControl()
68 m_isBeingDeleted
= true;
71 // ----------------------------------------------------------------------------
72 // control window creation
73 // ----------------------------------------------------------------------------
75 bool wxControl::Create(wxWindow
*parent
,
80 const wxValidator
& wxVALIDATOR_PARAM(validator
),
83 if ( !wxWindow::Create(parent
, id
, pos
, size
, style
, name
) )
87 SetValidator(validator
);
93 bool wxControl::PalmCreateControl(ControlStyleType style
,
96 const wxString
& label
,
101 SetId( id
== wxID_ANY
? NewControlId() : id
);
102 FormType
* form
= GetParentForm();
108 m_control
= CtlNewControl(
113 ( pos
.x
== wxDefaultCoord
) ? winUndefConstraint
: pos
.x
,
114 ( pos
.y
== wxDefaultCoord
) ? winUndefConstraint
: pos
.y
,
115 ( size
.x
== wxDefaultCoord
) ? winUndefConstraint
: size
.x
,
116 ( size
.y
== wxDefaultCoord
) ? winUndefConstraint
: size
.y
,
129 // ----------------------------------------------------------------------------
131 // ----------------------------------------------------------------------------
133 FormType
* wxControl::GetParentForm() const
135 wxWindow
* parentTLW
= GetParent();
136 while ( parentTLW
&& !parentTLW
->IsTopLevel() )
138 parentTLW
= parentTLW
->GetParent();
140 wxTopLevelWindowPalm
* tlw
= wxDynamicCast(parentTLW
, wxTopLevelWindowPalm
);
143 return tlw
->GetForm();
146 wxBorder
wxControl::GetDefaultBorder() const
148 // we want to automatically give controls a sunken style (confusingly,
149 // it may not really mean sunken at all as we map it to WS_EX_CLIENTEDGE
150 // which is not sunken at all under Windows XP -- rather, just the default)
151 return wxBORDER_SUNKEN
;
154 void wxControl::SetIntValue(int val
)
156 FormType
* form
= GetParentForm();
159 uint16_t index
= FrmGetObjectIndex(form
, GetId());
160 if(index
==frmInvalidObjectId
)
162 FrmSetControlValue(form
, index
, val
);
165 void wxControl::SetBoolValue(bool val
)
167 SetIntValue(val
?1:0);
170 bool wxControl::GetBoolValue() const
172 FormType
* form
= GetParentForm();
175 uint16_t index
= FrmGetObjectIndex(form
, GetId());
176 if(index
==frmInvalidObjectId
)
178 return ( FrmGetControlValue(form
, index
) == 1 );
181 wxSize
wxControl::DoGetBestSize() const
183 return wxSize(16, 16);
186 void wxControl::DoGetBounds( RectangleType
&rect
) const
188 FormType
* form
= GetParentForm();
191 uint16_t index
= FrmGetObjectIndex(form
,GetId());
192 if(index
==frmInvalidObjectId
)
194 FrmGetObjectBounds(form
,index
,&rect
);
197 void wxControl::DoGetPosition( int *x
, int *y
) const
207 void wxControl::DoGetSize( int *width
, int *height
) const
212 *width
= rect
.extent
.x
;
214 *height
= rect
.extent
.y
;
217 bool wxControl::Enable(bool enable
)
219 if( m_control
== NULL
)
221 if( IsEnabled() == enable
)
223 CtlSetEnabled( m_control
, enable
);
227 bool wxControl::IsEnabled() const
229 if( m_control
== NULL
)
231 return CtlEnabled(m_control
);
234 bool wxControl::IsShown() const
236 return StatGetAttribute ( statAttrBarVisible
, NULL
);
239 bool wxControl::Show( bool show
)
241 FormType
* form
= GetParentForm();
244 uint16_t index
= FrmGetObjectIndex(form
,GetId());
245 if(index
==frmInvalidObjectId
)
248 FrmShowObject(form
,index
);
250 FrmHideObject(form
,index
);
254 void wxControl::SetLabel(const wxString
& label
)
256 // setting in wrong control causes crash
257 if ( ( wxDynamicCast(this,wxButton
) != NULL
) ||
258 ( wxDynamicCast(this,wxCheckBox
) != NULL
) ||
259 ( wxDynamicCast(this,wxRadioButton
) != NULL
) ||
260 ( wxDynamicCast(this,wxToggleButton
) != NULL
) )
263 // TODO: as manual states, it crashes here
264 // needs own manipulation on used string pointers
265 // CtlSetLabel(m_control,m_label);
269 wxString
wxControl::GetLabel()
271 // setting in wrong control causes crash
272 if ( wxDynamicCast(this,wxButton
) ||
273 wxDynamicCast(this,wxCheckBox
) ||
274 wxDynamicCast(this,wxRadioButton
) ||
275 wxDynamicCast(this,wxToggleButton
) )
280 return wxEmptyString
;
283 /* static */ wxVisualAttributes
284 wxControl::GetClassDefaultAttributes(wxWindowVariant
WXUNUSED(variant
))
286 wxVisualAttributes attrs
;
288 // old school (i.e. not "common") controls use the standard dialog font
290 attrs
.font
= wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
);
292 // most, or at least many, of the controls use the same colours as the
293 // buttons -- others will have to override this (and possibly simply call
294 // GetCompositeControlsDefaultAttributes() from their versions)
295 attrs
.colFg
= wxSystemSettings::GetColour(wxSYS_COLOUR_BTNTEXT
);
296 attrs
.colBg
= wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE
);
301 // another version for the "composite", i.e. non simple controls
302 /* static */ wxVisualAttributes
303 wxControl::GetCompositeControlsDefaultAttributes(wxWindowVariant
WXUNUSED(variant
))
305 wxVisualAttributes attrs
;
306 attrs
.font
= wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
);
307 attrs
.colFg
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
);
308 attrs
.colBg
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
);
313 // ----------------------------------------------------------------------------
315 // ----------------------------------------------------------------------------
317 bool wxControl::ProcessCommand(wxCommandEvent
& event
)
319 return GetEventHandler()->ProcessEvent(event
);
322 void wxControl::OnEraseBackground(wxEraseEvent
& event
)
326 WXHBRUSH
wxControl::OnCtlColor(WXHDC pDC
, WXHWND
WXUNUSED(pWnd
), WXUINT
WXUNUSED(nCtlColor
),
327 WXUINT
WXUNUSED(message
),
328 WXWPARAM
WXUNUSED(wParam
),
329 WXLPARAM
WXUNUSED(lParam
)
335 // ---------------------------------------------------------------------------
337 // ---------------------------------------------------------------------------
339 #endif // wxUSE_CONTROLS