]> git.saurik.com Git - wxWidgets.git/blob - src/palmos/control.cpp
Don't fail assertion about image size mismatch if the size hasn't been
[wxWidgets.git] / 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
6 // Created: 10/13/04
7 // RCS-ID: $Id$
8 // Copyright: (c) William Osborne, Wlodzimierz Skiba
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 // ============================================================================
13 // declarations
14 // ============================================================================
15
16 // ----------------------------------------------------------------------------
17 // headers
18 // ----------------------------------------------------------------------------
19
20 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
21 #pragma implementation "control.h"
22 #endif
23
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
26
27 #ifdef __BORLANDC__
28 #pragma hdrstop
29 #endif
30
31 #if wxUSE_CONTROLS
32
33 #ifndef WX_PRECOMP
34 #include "wx/event.h"
35 #include "wx/app.h"
36 #include "wx/dcclient.h"
37 #include "wx/log.h"
38 #include "wx/settings.h"
39 #endif
40
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
48 // ----------------------------------------------------------------------------
49 // wxWin macros
50 // ----------------------------------------------------------------------------
51
52 IMPLEMENT_ABSTRACT_CLASS(wxControl, wxWindow)
53
54 BEGIN_EVENT_TABLE(wxControl, wxWindow)
55 EVT_ERASE_BACKGROUND(wxControl::OnEraseBackground)
56 END_EVENT_TABLE()
57
58 // ============================================================================
59 // wxControl implementation
60 // ============================================================================
61
62 // ----------------------------------------------------------------------------
63 // wxControl ctor/dtor
64 // ----------------------------------------------------------------------------
65
66 wxControl::~wxControl()
67 {
68 m_isBeingDeleted = true;
69 }
70
71 // ----------------------------------------------------------------------------
72 // control window creation
73 // ----------------------------------------------------------------------------
74
75 bool wxControl::Create(wxWindow *parent,
76 wxWindowID id,
77 const wxPoint& pos,
78 const wxSize& size,
79 long style,
80 const wxValidator& wxVALIDATOR_PARAM(validator),
81 const wxString& name)
82 {
83 if ( !wxWindow::Create(parent, id, pos, size, style, name) )
84 return false;
85
86 #if wxUSE_VALIDATORS
87 SetValidator(validator);
88 #endif
89
90 return true;
91 }
92
93 bool wxControl::PalmCreateControl(ControlStyleType style,
94 wxWindow *parent,
95 wxWindowID id,
96 const wxString& label,
97 const wxPoint& pos,
98 const wxSize& size)
99 {
100 SetParent(parent);
101 SetId( id == wxID_ANY ? NewControlId() : id );
102 FormType* form = GetParentForm();
103 if(form==NULL)
104 return false;
105
106 m_label = label;
107
108 m_control = CtlNewControl(
109 (void **)&form,
110 GetId(),
111 style,
112 m_label.c_str(),
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,
117 stdFont,
118 0,
119 false
120 );
121
122 if(m_control==NULL)
123 return false;
124
125 Show();
126 return true;
127 }
128
129 // ----------------------------------------------------------------------------
130 // various accessors
131 // ----------------------------------------------------------------------------
132
133 FormType* wxControl::GetParentForm() const
134 {
135 wxWindow* parentTLW = GetParent();
136 while ( parentTLW && !parentTLW->IsTopLevel() )
137 {
138 parentTLW = parentTLW->GetParent();
139 }
140 wxTopLevelWindowPalm* tlw = wxDynamicCast(parentTLW, wxTopLevelWindowPalm);
141 if(!tlw)
142 return NULL;
143 return tlw->GetForm();
144 }
145
146 wxBorder wxControl::GetDefaultBorder() const
147 {
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;
152 }
153
154 void wxControl::SetIntValue(int val)
155 {
156 FormType* form = GetParentForm();
157 if(form==NULL)
158 return;
159 uint16_t index = FrmGetObjectIndex(form, GetId());
160 if(index==frmInvalidObjectId)
161 return;
162 FrmSetControlValue(form, index, val);
163 }
164
165 void wxControl::SetBoolValue(bool val)
166 {
167 SetIntValue(val?1:0);
168 }
169
170 bool wxControl::GetBoolValue() const
171 {
172 FormType* form = GetParentForm();
173 if(form==NULL)
174 return false;
175 uint16_t index = FrmGetObjectIndex(form, GetId());
176 if(index==frmInvalidObjectId)
177 return false;
178 return ( FrmGetControlValue(form, index) == 1 );
179 }
180
181 wxSize wxControl::DoGetBestSize() const
182 {
183 return wxSize(16, 16);
184 }
185
186 void wxControl::DoGetBounds( RectangleType &rect ) const
187 {
188 FormType* form = GetParentForm();
189 if(form==NULL)
190 return;
191 uint16_t index = FrmGetObjectIndex(form,GetId());
192 if(index==frmInvalidObjectId)
193 return;
194 FrmGetObjectBounds(form,index,&rect);
195 }
196
197 void wxControl::DoGetPosition( int *x, int *y ) const
198 {
199 RectangleType rect;
200 DoGetBounds(rect);
201 if(x)
202 *x = rect.topLeft.x;
203 if(y)
204 *y = rect.topLeft.y;
205 }
206
207 void wxControl::DoGetSize( int *width, int *height ) const
208 {
209 RectangleType rect;
210 DoGetBounds(rect);
211 if(width)
212 *width = rect.extent.x;
213 if(height)
214 *height = rect.extent.y;
215 }
216
217 bool wxControl::Enable(bool enable)
218 {
219 if( m_control == NULL )
220 return false;
221 if( IsEnabled() == enable)
222 return false;
223 CtlSetEnabled( m_control, enable);
224 return true;
225 }
226
227 bool wxControl::IsEnabled() const
228 {
229 if( m_control == NULL )
230 return false;
231 return CtlEnabled(m_control);
232 }
233
234 bool wxControl::IsShown() const
235 {
236 return StatGetAttribute ( statAttrBarVisible , NULL );
237 }
238
239 bool wxControl::Show( bool show )
240 {
241 FormType* form = GetParentForm();
242 if(form==NULL)
243 return false;
244 uint16_t index = FrmGetObjectIndex(form,GetId());
245 if(index==frmInvalidObjectId)
246 return false;
247 if(show)
248 FrmShowObject(form,index);
249 else
250 FrmHideObject(form,index);
251 return true;
252 }
253
254 void wxControl::SetLabel(const wxString& label)
255 {
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 ) )
261 {
262 m_label = label;
263 // TODO: as manual states, it crashes here
264 // needs own manipulation on used string pointers
265 // CtlSetLabel(m_control,m_label);
266 }
267 }
268
269 wxString wxControl::GetLabel()
270 {
271 // setting in wrong control causes crash
272 if ( wxDynamicCast(this,wxButton) ||
273 wxDynamicCast(this,wxCheckBox) ||
274 wxDynamicCast(this,wxRadioButton) ||
275 wxDynamicCast(this,wxToggleButton) )
276 {
277 return m_label;
278 }
279
280 return wxEmptyString;
281 }
282
283 /* static */ wxVisualAttributes
284 wxControl::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant))
285 {
286 wxVisualAttributes attrs;
287
288 // old school (i.e. not "common") controls use the standard dialog font
289 // by default
290 attrs.font = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT);
291
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);
297
298 return attrs;
299 }
300
301 // another version for the "composite", i.e. non simple controls
302 /* static */ wxVisualAttributes
303 wxControl::GetCompositeControlsDefaultAttributes(wxWindowVariant WXUNUSED(variant))
304 {
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);
309
310 return attrs;
311 }
312
313 // ----------------------------------------------------------------------------
314 // message handling
315 // ----------------------------------------------------------------------------
316
317 bool wxControl::ProcessCommand(wxCommandEvent& event)
318 {
319 return GetEventHandler()->ProcessEvent(event);
320 }
321
322 void wxControl::OnEraseBackground(wxEraseEvent& event)
323 {
324 }
325
326 WXHBRUSH wxControl::OnCtlColor(WXHDC pDC, WXHWND WXUNUSED(pWnd), WXUINT WXUNUSED(nCtlColor),
327 WXUINT WXUNUSED(message),
328 WXWPARAM WXUNUSED(wParam),
329 WXLPARAM WXUNUSED(lParam)
330 )
331 {
332 return (WXHBRUSH)0;
333 }
334
335 // ---------------------------------------------------------------------------
336 // global functions
337 // ---------------------------------------------------------------------------
338
339 #endif // wxUSE_CONTROLS