]>
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"
47 // ----------------------------------------------------------------------------
49 // ----------------------------------------------------------------------------
51 IMPLEMENT_ABSTRACT_CLASS(wxControl
, wxWindow
)
53 BEGIN_EVENT_TABLE(wxControl
, wxWindow
)
54 EVT_ERASE_BACKGROUND(wxControl::OnEraseBackground
)
57 // ============================================================================
58 // wxControl implementation
59 // ============================================================================
61 // ----------------------------------------------------------------------------
62 // wxControl ctor/dtor
63 // ----------------------------------------------------------------------------
65 wxControl::~wxControl()
67 m_isBeingDeleted
= true;
70 // ----------------------------------------------------------------------------
71 // control window creation
72 // ----------------------------------------------------------------------------
74 bool wxControl::Create(wxWindow
*parent
,
79 const wxValidator
& wxVALIDATOR_PARAM(validator
),
82 if ( !wxWindow::Create(parent
, id
, pos
, size
, style
, name
) )
86 SetValidator(validator
);
92 bool wxControl::PalmCreateControl(ControlStyleType style
,
95 const wxString
& label
,
100 SetId( id
== wxID_ANY
? NewControlId() : id
);
101 FormType
* form
= GetParentForm();
107 m_control
= CtlNewControl(
112 ( pos
.x
== wxDefaultCoord
) ? winUndefConstraint
: pos
.x
,
113 ( pos
.y
== wxDefaultCoord
) ? winUndefConstraint
: pos
.y
,
114 ( size
.x
== wxDefaultCoord
) ? winUndefConstraint
: size
.x
,
115 ( size
.y
== wxDefaultCoord
) ? winUndefConstraint
: size
.y
,
128 // ----------------------------------------------------------------------------
130 // ----------------------------------------------------------------------------
132 FormType
* wxControl::GetParentForm() const
134 wxWindow
* parentTLW
= GetParent();
135 while ( parentTLW
&& !parentTLW
->IsTopLevel() )
137 parentTLW
= parentTLW
->GetParent();
139 wxTopLevelWindowPalm
* tlw
= wxDynamicCast(parentTLW
, wxTopLevelWindowPalm
);
142 return tlw
->GetForm();
145 wxBorder
wxControl::GetDefaultBorder() const
147 // we want to automatically give controls a sunken style (confusingly,
148 // it may not really mean sunken at all as we map it to WS_EX_CLIENTEDGE
149 // which is not sunken at all under Windows XP -- rather, just the default)
150 return wxBORDER_SUNKEN
;
153 void wxControl::SetIntValue(int val
)
155 FormType
* form
= GetParentForm();
158 uint16_t index
= FrmGetObjectIndex(form
, GetId());
159 if(index
==frmInvalidObjectId
)
161 FrmSetControlValue(form
, index
, val
);
164 void wxControl::SetBoolValue(bool val
)
166 SetIntValue(val
?1:0);
169 bool wxControl::GetBoolValue() const
171 FormType
* form
= GetParentForm();
174 uint16_t index
= FrmGetObjectIndex(form
, GetId());
175 if(index
==frmInvalidObjectId
)
177 return ( FrmGetControlValue(form
, index
) == 1 );
180 wxSize
wxControl::DoGetBestSize() const
182 return wxSize(16, 16);
185 bool wxControl::Enable(bool enable
)
187 if( m_control
== NULL
)
189 if( IsEnabled() == enable
)
191 CtlSetEnabled( m_control
, enable
);
195 bool wxControl::IsEnabled() const
197 if( m_control
== NULL
)
199 return CtlEnabled(m_control
);
202 bool wxControl::IsShown() const
204 return StatGetAttribute ( statAttrBarVisible
, NULL
);
207 bool wxControl::Show( bool show
)
209 FormType
* form
= GetParentForm();
212 uint16_t index
= FrmGetObjectIndex(form
,GetId());
213 if(index
==frmInvalidObjectId
)
216 FrmShowObject(form
,index
);
218 FrmHideObject(form
,index
);
222 void wxControl::SetLabel(const wxString
& label
)
224 // setting in wrong control causes crash
225 if ( ( wxDynamicCast(this,wxButton
) != NULL
) ||
226 ( wxDynamicCast(this,wxCheckBox
) != NULL
) ||
227 ( wxDynamicCast(this,wxToggleButton
) != NULL
) )
230 // TODO: as manual states, it crashes here
231 // needs own manipulation on used string pointers
232 // CtlSetLabel(m_control,m_label);
236 wxString
wxControl::GetLabel()
238 // setting in wrong control causes crash
239 if ( wxDynamicCast(this,wxButton
) ||
240 wxDynamicCast(this,wxCheckBox
) ||
241 wxDynamicCast(this,wxToggleButton
) )
246 return wxEmptyString
;
249 /* static */ wxVisualAttributes
250 wxControl::GetClassDefaultAttributes(wxWindowVariant
WXUNUSED(variant
))
252 wxVisualAttributes attrs
;
254 // old school (i.e. not "common") controls use the standard dialog font
256 attrs
.font
= wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
);
258 // most, or at least many, of the controls use the same colours as the
259 // buttons -- others will have to override this (and possibly simply call
260 // GetCompositeControlsDefaultAttributes() from their versions)
261 attrs
.colFg
= wxSystemSettings::GetColour(wxSYS_COLOUR_BTNTEXT
);
262 attrs
.colBg
= wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE
);
267 // another version for the "composite", i.e. non simple controls
268 /* static */ wxVisualAttributes
269 wxControl::GetCompositeControlsDefaultAttributes(wxWindowVariant
WXUNUSED(variant
))
271 wxVisualAttributes attrs
;
272 attrs
.font
= wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
);
273 attrs
.colFg
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
);
274 attrs
.colBg
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
);
279 // ----------------------------------------------------------------------------
281 // ----------------------------------------------------------------------------
283 bool wxControl::ProcessCommand(wxCommandEvent
& event
)
285 return GetEventHandler()->ProcessEvent(event
);
288 void wxControl::OnEraseBackground(wxEraseEvent
& event
)
292 WXHBRUSH
wxControl::OnCtlColor(WXHDC pDC
, WXHWND
WXUNUSED(pWnd
), WXUINT
WXUNUSED(nCtlColor
),
298 WXUINT
WXUNUSED(message
),
299 WXWPARAM
WXUNUSED(wParam
),
300 WXLPARAM
WXUNUSED(lParam
)
307 // ---------------------------------------------------------------------------
309 // ---------------------------------------------------------------------------
311 #endif // wxUSE_CONTROLS