]> git.saurik.com Git - wxWidgets.git/blame - src/palmos/control.cpp
fixes for animated GIFs playing (patch 1097003)
[wxWidgets.git] / src / palmos / control.cpp
CommitLineData
ffecfa5a 1/////////////////////////////////////////////////////////////////////////////
e2731512 2// Name: src/palmos/control.cpp
ffecfa5a 3// Purpose: wxControl class
e2731512 4// Author: William Osborne - minimal working wxPalmOS port
bdb54365 5// Modified by: Wlodzimierz ABX Skiba - native implementation
ffecfa5a 6// Created: 10/13/04
e2731512 7// RCS-ID: $Id$
bdb54365 8// Copyright: (c) William Osborne, Wlodzimierz Skiba
ffecfa5a
JS
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"
bdb54365
WS
42#include "wx/toplevel.h"
43#include "wx/button.h"
44#include "wx/checkbox.h"
45#include "wx/tglbtn.h"
808e3bce 46#include "wx/radiobut.h"
a152561c 47#include "wx/slider.h"
ffecfa5a
JS
48
49// ----------------------------------------------------------------------------
50// wxWin macros
51// ----------------------------------------------------------------------------
52
53IMPLEMENT_ABSTRACT_CLASS(wxControl, wxWindow)
54
55BEGIN_EVENT_TABLE(wxControl, wxWindow)
56 EVT_ERASE_BACKGROUND(wxControl::OnEraseBackground)
57END_EVENT_TABLE()
58
59// ============================================================================
60// wxControl implementation
61// ============================================================================
62
63// ----------------------------------------------------------------------------
64// wxControl ctor/dtor
65// ----------------------------------------------------------------------------
66
a152561c
WS
67void wxControl::Init()
68{
69 m_palmControl = false;
70 m_palmField = false;
71}
72
ffecfa5a
JS
73wxControl::~wxControl()
74{
db101bd3 75 m_isBeingDeleted = true;
ffecfa5a
JS
76}
77
78// ----------------------------------------------------------------------------
79// control window creation
80// ----------------------------------------------------------------------------
81
82bool wxControl::Create(wxWindow *parent,
83 wxWindowID id,
84 const wxPoint& pos,
85 const wxSize& size,
86 long style,
87 const wxValidator& wxVALIDATOR_PARAM(validator),
88 const wxString& name)
89{
90 if ( !wxWindow::Create(parent, id, pos, size, style, name) )
db101bd3 91 return false;
ffecfa5a
JS
92
93#if wxUSE_VALIDATORS
94 SetValidator(validator);
95#endif
96
db101bd3 97 return true;
ffecfa5a
JS
98}
99
db101bd3 100bool wxControl::PalmCreateControl(ControlStyleType style,
db101bd3
WS
101 const wxString& label,
102 const wxPoint& pos,
a152561c
WS
103 const wxSize& size,
104 int groupID)
ffecfa5a 105{
ba889513
WS
106 FormType* form = GetParentForm();
107 if(form==NULL)
bdb54365 108 return false;
bdb54365 109
ba889513 110 m_label = label;
bdb54365 111
a152561c
WS
112 ControlType *control = CtlNewControl(
113 (void **)&form,
114 GetId(),
115 style,
116 m_label.c_str(),
117 ( pos.x == wxDefaultCoord ) ? winUndefConstraint : pos.x,
118 ( pos.y == wxDefaultCoord ) ? winUndefConstraint : pos.y,
119 ( size.x == wxDefaultCoord ) ? winUndefConstraint : size.x,
120 ( size.y == wxDefaultCoord ) ? winUndefConstraint : size.y,
121 stdFont,
122 groupID,
123 false
124 );
125
126 if(control==NULL)
db101bd3
WS
127 return false;
128
a152561c
WS
129 m_palmControl = true;
130
db101bd3
WS
131 Show();
132 return true;
ffecfa5a
JS
133}
134
a152561c
WS
135bool wxControl::PalmCreateField(const wxString& label,
136 const wxPoint& pos,
137 const wxSize& size,
138 bool editable,
139 bool underlined,
140 JustificationType justification)
141{
142 FormType* form = GetParentForm();
143 if(form==NULL)
144 return false;
145
146 m_label = label;
147
148 FieldType *field = FldNewField(
149 (void **)&form,
150 GetId(),
151 ( pos.x == wxDefaultCoord ) ? winUndefConstraint : pos.x,
152 ( pos.y == wxDefaultCoord ) ? winUndefConstraint : pos.y,
153 ( size.x == wxDefaultCoord ) ? winUndefConstraint : size.x,
154 ( size.y == wxDefaultCoord ) ? winUndefConstraint : size.y,
155 stdFont,
156 10,
157 editable,
158 underlined,
159 false,
160 false,
161 justification,
162 false,
163 false,
164 false
165 );
166
167 if(field==NULL)
168 return false;
169
170 m_palmField = true;
171
172 Show();
173 SetLabel(label);
174 return true;
175}
176
ffecfa5a
JS
177// ----------------------------------------------------------------------------
178// various accessors
179// ----------------------------------------------------------------------------
180
ba889513
WS
181FormType* wxControl::GetParentForm() const
182{
183 wxWindow* parentTLW = GetParent();
184 while ( parentTLW && !parentTLW->IsTopLevel() )
185 {
186 parentTLW = parentTLW->GetParent();
187 }
188 wxTopLevelWindowPalm* tlw = wxDynamicCast(parentTLW, wxTopLevelWindowPalm);
189 if(!tlw)
190 return NULL;
191 return tlw->GetForm();
192}
193
a152561c
WS
194uint16_t wxControl::GetObjectIndex() const
195{
196 FormType* form = GetParentForm();
197 if(form==NULL)return frmInvalidObjectId;
198 return FrmGetObjectIndex(form, GetId());
199}
200
201void* wxControl::GetObjectPtr() const
202{
203 FormType* form = GetParentForm();
204 if(form==NULL)return NULL;
205 uint16_t index = FrmGetObjectIndex(form, GetId());
206 if(index==frmInvalidObjectId)return NULL;
207 return FrmGetObjectPtr(form,index);
208}
209
ffecfa5a
JS
210wxBorder wxControl::GetDefaultBorder() const
211{
212 // we want to automatically give controls a sunken style (confusingly,
213 // it may not really mean sunken at all as we map it to WS_EX_CLIENTEDGE
214 // which is not sunken at all under Windows XP -- rather, just the default)
215 return wxBORDER_SUNKEN;
216}
217
ba889513
WS
218void wxControl::SetIntValue(int val)
219{
220 FormType* form = GetParentForm();
221 if(form==NULL)
222 return;
223 uint16_t index = FrmGetObjectIndex(form, GetId());
224 if(index==frmInvalidObjectId)
225 return;
226 FrmSetControlValue(form, index, val);
227}
228
229void wxControl::SetBoolValue(bool val)
230{
231 SetIntValue(val?1:0);
232}
233
234bool wxControl::GetBoolValue() const
235{
236 FormType* form = GetParentForm();
237 if(form==NULL)
238 return false;
239 uint16_t index = FrmGetObjectIndex(form, GetId());
240 if(index==frmInvalidObjectId)
241 return false;
242 return ( FrmGetControlValue(form, index) == 1 );
243}
244
db101bd3 245wxSize wxControl::DoGetBestSize() const
ffecfa5a 246{
db101bd3 247 return wxSize(16, 16);
ffecfa5a
JS
248}
249
808e3bce
WS
250void wxControl::DoGetBounds( RectangleType &rect ) const
251{
252 FormType* form = GetParentForm();
253 if(form==NULL)
254 return;
255 uint16_t index = FrmGetObjectIndex(form,GetId());
256 if(index==frmInvalidObjectId)
257 return;
258 FrmGetObjectBounds(form,index,&rect);
259}
260
261void wxControl::DoGetPosition( int *x, int *y ) const
262{
263 RectangleType rect;
264 DoGetBounds(rect);
265 if(x)
266 *x = rect.topLeft.x;
267 if(y)
268 *y = rect.topLeft.y;
269}
270
271void wxControl::DoGetSize( int *width, int *height ) const
272{
273 RectangleType rect;
274 DoGetBounds(rect);
275 if(width)
276 *width = rect.extent.x;
277 if(height)
278 *height = rect.extent.y;
279}
280
db101bd3 281bool wxControl::Enable(bool enable)
ffecfa5a 282{
a152561c
WS
283 ControlType *control = (ControlType *)GetObjectPtr();
284 if( (IsPalmControl()) || (control == NULL))
db101bd3 285 return false;
a152561c 286 if( CtlEnabled(control) == enable)
db101bd3 287 return false;
a152561c 288 CtlSetEnabled( control, enable);
db101bd3
WS
289 return true;
290}
291
292bool wxControl::IsEnabled() const
293{
a152561c
WS
294 ControlType *control = (ControlType *)GetObjectPtr();
295 if( (IsPalmControl()) || (control == NULL))
db101bd3 296 return false;
a152561c 297 return CtlEnabled(control);
db101bd3
WS
298}
299
300bool wxControl::IsShown() const
301{
302 return StatGetAttribute ( statAttrBarVisible , NULL );
303}
304
305bool wxControl::Show( bool show )
306{
ba889513
WS
307 FormType* form = GetParentForm();
308 if(form==NULL)
309 return false;
310 uint16_t index = FrmGetObjectIndex(form,GetId());
311 if(index==frmInvalidObjectId)
312 return false;
db101bd3 313 if(show)
ba889513 314 FrmShowObject(form,index);
db101bd3 315 else
ba889513 316 FrmHideObject(form,index);
db101bd3 317 return true;
ffecfa5a
JS
318}
319
a152561c 320void wxControl::SetFieldLabel(const wxString& label)
bdb54365 321{
a152561c
WS
322 FieldType* field = (FieldType*)GetObjectPtr();
323 if(field==NULL)
324 return;
325
326 uint16_t newSize = label.Length() + 1;
327 MemHandle strHandle = FldGetTextHandle(field);
328 FldSetTextHandle(field, NULL );
329 if (strHandle)
bdb54365 330 {
a152561c
WS
331 if(MemHandleResize(strHandle, newSize)!=errNone)
332 strHandle = 0;
bdb54365 333 }
a152561c
WS
334 else
335 {
336 strHandle = MemHandleNew( newSize );
337 }
338 if(!strHandle)
339 return;
340
341 char* str = (char*) MemHandleLock( strHandle );
342 if(str==NULL)
343 return;
344
345 strcpy(str, label.c_str());
346 MemHandleUnlock(strHandle);
347 FldSetTextHandle(field, strHandle);
348 FldRecalculateField(field, true);
349}
350
351void wxControl::SetControlLabel(const wxString& label)
352{
353}
354
355void wxControl::SetLabel(const wxString& label)
356{
357 if(IsPalmField())
358 SetFieldLabel(label);
359
360 // unlike other native controls, slider has no label
361 if(IsPalmControl() && !wxDynamicCast(this,wxSlider))
362 SetControlLabel(label);
363}
364
365wxString wxControl::GetFieldLabel()
366{
367 FieldType* field = (FieldType*)GetObjectPtr();
368 if(field==NULL)
369 return wxEmptyString;
370 return FldGetTextPtr(field);
371}
372
373wxString wxControl::GetControlLabel()
374{
375 ControlType* control = (ControlType*)GetObjectPtr();
376 if(control==NULL)
377 return wxEmptyString;
378 return CtlGetLabel(control);
bdb54365
WS
379}
380
381wxString wxControl::GetLabel()
382{
a152561c
WS
383 if(IsPalmField())
384 return GetFieldLabel();
385
386 // unlike other native controls, slider has no label
387 if(IsPalmControl() && !wxDynamicCast(this,wxSlider))
388 return GetControlLabel();
bdb54365
WS
389
390 return wxEmptyString;
391}
392
ffecfa5a
JS
393/* static */ wxVisualAttributes
394wxControl::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant))
395{
396 wxVisualAttributes attrs;
397
398 // old school (i.e. not "common") controls use the standard dialog font
399 // by default
400 attrs.font = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT);
401
402 // most, or at least many, of the controls use the same colours as the
403 // buttons -- others will have to override this (and possibly simply call
404 // GetCompositeControlsDefaultAttributes() from their versions)
405 attrs.colFg = wxSystemSettings::GetColour(wxSYS_COLOUR_BTNTEXT);
406 attrs.colBg = wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE);
407
408 return attrs;
409}
410
411// another version for the "composite", i.e. non simple controls
412/* static */ wxVisualAttributes
413wxControl::GetCompositeControlsDefaultAttributes(wxWindowVariant WXUNUSED(variant))
414{
415 wxVisualAttributes attrs;
416 attrs.font = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT);
417 attrs.colFg = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT);
418 attrs.colBg = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW);
419
420 return attrs;
421}
422
423// ----------------------------------------------------------------------------
424// message handling
425// ----------------------------------------------------------------------------
426
427bool wxControl::ProcessCommand(wxCommandEvent& event)
428{
429 return GetEventHandler()->ProcessEvent(event);
430}
431
ffecfa5a
JS
432void wxControl::OnEraseBackground(wxEraseEvent& event)
433{
434}
435
436WXHBRUSH wxControl::OnCtlColor(WXHDC pDC, WXHWND WXUNUSED(pWnd), WXUINT WXUNUSED(nCtlColor),
ffecfa5a
JS
437 WXUINT WXUNUSED(message),
438 WXWPARAM WXUNUSED(wParam),
439 WXLPARAM WXUNUSED(lParam)
ffecfa5a
JS
440 )
441{
442 return (WXHBRUSH)0;
443}
444
445// ---------------------------------------------------------------------------
446// global functions
447// ---------------------------------------------------------------------------
448
449#endif // wxUSE_CONTROLS