]> git.saurik.com Git - wxWidgets.git/blame - src/palmos/control.cpp
Fixed bug preventing dir enumeration from working on WinCE
[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{
9a727a3b 75 SetLabel(wxEmptyString);
db101bd3 76 m_isBeingDeleted = true;
5b72333d
WS
77
78 DestroyChildren();
79
80 uint16_t index;
81 FormType* form = GetObjectFormIndex(index);
82 if(form!=NULL && index!=frmInvalidObjectId)
83 {
84 FrmRemoveObject((FormType **)&form,index);
85 }
ffecfa5a
JS
86}
87
88// ----------------------------------------------------------------------------
89// control window creation
90// ----------------------------------------------------------------------------
91
92bool wxControl::Create(wxWindow *parent,
93 wxWindowID id,
94 const wxPoint& pos,
95 const wxSize& size,
96 long style,
97 const wxValidator& wxVALIDATOR_PARAM(validator),
98 const wxString& name)
99{
100 if ( !wxWindow::Create(parent, id, pos, size, style, name) )
db101bd3 101 return false;
ffecfa5a
JS
102
103#if wxUSE_VALIDATORS
104 SetValidator(validator);
105#endif
106
db101bd3 107 return true;
ffecfa5a
JS
108}
109
db101bd3 110bool wxControl::PalmCreateControl(ControlStyleType style,
db101bd3
WS
111 const wxString& label,
112 const wxPoint& pos,
a152561c 113 const wxSize& size,
8be10866 114 uint8_t groupID)
ffecfa5a 115{
ba889513
WS
116 FormType* form = GetParentForm();
117 if(form==NULL)
bdb54365 118 return false;
bdb54365 119
be4e4e27
WS
120
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;
125
d2893292
WS
126 wxWindow *win = this;
127 while(win->GetParent())
128 {
129 win = win->GetParent();
130 wxPoint pt(win->GetClientAreaOrigin());
131 x += pt.x;
132 y += pt.y;
133 }
be4e4e27 134
a152561c
WS
135 ControlType *control = CtlNewControl(
136 (void **)&form,
137 GetId(),
138 style,
9a727a3b 139 wxEmptyString,
be4e4e27
WS
140 x,
141 y,
142 w,
143 h,
a152561c
WS
144 stdFont,
145 groupID,
5b72333d 146 true
a152561c
WS
147 );
148
149 if(control==NULL)
db101bd3
WS
150 return false;
151
a152561c
WS
152 m_palmControl = true;
153
be4e4e27 154 SetInitialBestSize(size);
9a727a3b 155 SetLabel(label);
db101bd3
WS
156 Show();
157 return true;
ffecfa5a
JS
158}
159
a152561c
WS
160bool wxControl::PalmCreateField(const wxString& label,
161 const wxPoint& pos,
162 const wxSize& size,
163 bool editable,
164 bool underlined,
165 JustificationType justification)
166{
167 FormType* form = GetParentForm();
168 if(form==NULL)
169 return false;
170
171 m_label = label;
172
be4e4e27
WS
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;
177
178 AdjustForParentClientOrigin(x, y);
179
a152561c
WS
180 FieldType *field = FldNewField(
181 (void **)&form,
182 GetId(),
be4e4e27
WS
183 x,
184 y,
185 w,
186 h,
a152561c
WS
187 stdFont,
188 10,
189 editable,
190 underlined,
191 false,
192 false,
193 justification,
194 false,
195 false,
196 false
197 );
198
199 if(field==NULL)
200 return false;
201
202 m_palmField = true;
203
be4e4e27 204 SetInitialBestSize(size);
a152561c 205 SetLabel(label);
be4e4e27 206 Show();
a152561c
WS
207 return true;
208}
209
ffecfa5a
JS
210// ----------------------------------------------------------------------------
211// various accessors
212// ----------------------------------------------------------------------------
213
ba889513
WS
214FormType* wxControl::GetParentForm() const
215{
216 wxWindow* parentTLW = GetParent();
217 while ( parentTLW && !parentTLW->IsTopLevel() )
218 {
219 parentTLW = parentTLW->GetParent();
220 }
221 wxTopLevelWindowPalm* tlw = wxDynamicCast(parentTLW, wxTopLevelWindowPalm);
222 if(!tlw)
223 return NULL;
224 return tlw->GetForm();
225}
226
5b72333d 227FormType* wxControl::GetObjectFormIndex(uint16_t& index) const
a152561c
WS
228{
229 FormType* form = GetParentForm();
5b72333d
WS
230 if(form!=NULL)
231 index = FrmGetObjectIndex(form, GetId());
232 else
233 index = frmInvalidObjectId;
234 return form;
a152561c
WS
235}
236
237void* wxControl::GetObjectPtr() const
238{
5b72333d
WS
239 uint16_t index;
240 FormType* form = GetObjectFormIndex(index);
241 if(form==NULL || index==frmInvalidObjectId)return NULL;
a152561c
WS
242 return FrmGetObjectPtr(form,index);
243}
244
ffecfa5a
JS
245wxBorder wxControl::GetDefaultBorder() const
246{
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;
251}
252
ba889513
WS
253void wxControl::SetIntValue(int val)
254{
255 FormType* form = GetParentForm();
256 if(form==NULL)
257 return;
258 uint16_t index = FrmGetObjectIndex(form, GetId());
259 if(index==frmInvalidObjectId)
260 return;
261 FrmSetControlValue(form, index, val);
262}
263
264void wxControl::SetBoolValue(bool val)
265{
266 SetIntValue(val?1:0);
267}
268
269bool wxControl::GetBoolValue() const
270{
271 FormType* form = GetParentForm();
272 if(form==NULL)
273 return false;
274 uint16_t index = FrmGetObjectIndex(form, GetId());
275 if(index==frmInvalidObjectId)
276 return false;
277 return ( FrmGetControlValue(form, index) == 1 );
278}
279
db101bd3 280wxSize wxControl::DoGetBestSize() const
ffecfa5a 281{
db101bd3 282 return wxSize(16, 16);
ffecfa5a
JS
283}
284
808e3bce
WS
285void wxControl::DoGetBounds( RectangleType &rect ) const
286{
287 FormType* form = GetParentForm();
288 if(form==NULL)
289 return;
290 uint16_t index = FrmGetObjectIndex(form,GetId());
291 if(index==frmInvalidObjectId)
292 return;
293 FrmGetObjectBounds(form,index,&rect);
294}
295
324eeecb
WS
296void wxControl::DoSetBounds( RectangleType &rect )
297{
298 FormType* form = GetParentForm();
299 if(form==NULL)
300 return;
301 uint16_t index = FrmGetObjectIndex(form,GetId());
302 if(index==frmInvalidObjectId)
303 return;
304 FrmSetObjectBounds(form,index,&rect);
305}
306
808e3bce
WS
307void wxControl::DoGetPosition( int *x, int *y ) const
308{
d2893292
WS
309 int ox = 0, oy = 0;
310 AdjustForParentClientOrigin(ox, oy);
311
808e3bce
WS
312 RectangleType rect;
313 DoGetBounds(rect);
d2893292 314
808e3bce 315 if(x)
d2893292 316 *x = rect.topLeft.x - ox;
808e3bce 317 if(y)
d2893292 318 *y = rect.topLeft.y - oy;
808e3bce
WS
319}
320
321void wxControl::DoGetSize( int *width, int *height ) const
322{
323 RectangleType rect;
324 DoGetBounds(rect);
d2893292 325
808e3bce
WS
326 if(width)
327 *width = rect.extent.x;
328 if(height)
329 *height = rect.extent.y;
330}
331
324eeecb
WS
332void wxControl::DoMoveWindow(int x, int y, int width, int height)
333{
334 wxRect area = GetRect();
335 RectangleType rect;
336 rect.topLeft.x = x;
337 rect.topLeft.y = y;
338 rect.extent.x = width;
339 rect.extent.y = height;
340 DoSetBounds(rect);
341 GetParent()->Refresh(true, &area);
342}
343
db101bd3 344bool wxControl::Enable(bool enable)
ffecfa5a 345{
a152561c 346 ControlType *control = (ControlType *)GetObjectPtr();
1a87edf2 347 if( !IsPalmControl() || (control == NULL))
db101bd3 348 return false;
a152561c 349 if( CtlEnabled(control) == enable)
db101bd3 350 return false;
a152561c 351 CtlSetEnabled( control, enable);
db101bd3
WS
352 return true;
353}
354
355bool wxControl::IsEnabled() const
356{
a152561c 357 ControlType *control = (ControlType *)GetObjectPtr();
1a87edf2 358 if( !IsPalmControl() || (control == NULL))
db101bd3 359 return false;
a152561c 360 return CtlEnabled(control);
db101bd3
WS
361}
362
363bool wxControl::IsShown() const
364{
365 return StatGetAttribute ( statAttrBarVisible , NULL );
366}
367
368bool wxControl::Show( bool show )
369{
ba889513
WS
370 FormType* form = GetParentForm();
371 if(form==NULL)
372 return false;
373 uint16_t index = FrmGetObjectIndex(form,GetId());
374 if(index==frmInvalidObjectId)
375 return false;
db101bd3 376 if(show)
ba889513 377 FrmShowObject(form,index);
db101bd3 378 else
ba889513 379 FrmHideObject(form,index);
db101bd3 380 return true;
ffecfa5a
JS
381}
382
a152561c 383void wxControl::SetFieldLabel(const wxString& label)
bdb54365 384{
a152561c
WS
385 FieldType* field = (FieldType*)GetObjectPtr();
386 if(field==NULL)
387 return;
388
389 uint16_t newSize = label.Length() + 1;
390 MemHandle strHandle = FldGetTextHandle(field);
391 FldSetTextHandle(field, NULL );
392 if (strHandle)
bdb54365 393 {
a152561c
WS
394 if(MemHandleResize(strHandle, newSize)!=errNone)
395 strHandle = 0;
bdb54365 396 }
a152561c
WS
397 else
398 {
399 strHandle = MemHandleNew( newSize );
400 }
401 if(!strHandle)
402 return;
403
404 char* str = (char*) MemHandleLock( strHandle );
405 if(str==NULL)
406 return;
407
408 strcpy(str, label.c_str());
409 MemHandleUnlock(strHandle);
410 FldSetTextHandle(field, strHandle);
411 FldRecalculateField(field, true);
412}
413
414void wxControl::SetControlLabel(const wxString& label)
415{
9a727a3b
WS
416 ControlType* control = (ControlType*)GetObjectPtr();
417 if(control==NULL)
418 return;
419 CtlSetLabel(control,wxEmptyString);
420 m_label = label;
421 if(!m_label.empty())
422 CtlSetLabel(control,m_label.c_str());
a152561c
WS
423}
424
425void wxControl::SetLabel(const wxString& label)
426{
427 if(IsPalmField())
428 SetFieldLabel(label);
429
430 // unlike other native controls, slider has no label
431 if(IsPalmControl() && !wxDynamicCast(this,wxSlider))
432 SetControlLabel(label);
433}
434
435wxString wxControl::GetFieldLabel()
436{
437 FieldType* field = (FieldType*)GetObjectPtr();
438 if(field==NULL)
439 return wxEmptyString;
440 return FldGetTextPtr(field);
441}
442
443wxString wxControl::GetControlLabel()
444{
445 ControlType* control = (ControlType*)GetObjectPtr();
446 if(control==NULL)
447 return wxEmptyString;
448 return CtlGetLabel(control);
bdb54365
WS
449}
450
451wxString wxControl::GetLabel()
452{
a152561c
WS
453 if(IsPalmField())
454 return GetFieldLabel();
455
456 // unlike other native controls, slider has no label
457 if(IsPalmControl() && !wxDynamicCast(this,wxSlider))
458 return GetControlLabel();
bdb54365
WS
459
460 return wxEmptyString;
461}
462
ffecfa5a
JS
463/* static */ wxVisualAttributes
464wxControl::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant))
465{
466 wxVisualAttributes attrs;
467
468 // old school (i.e. not "common") controls use the standard dialog font
469 // by default
470 attrs.font = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT);
471
472 // most, or at least many, of the controls use the same colours as the
473 // buttons -- others will have to override this (and possibly simply call
474 // GetCompositeControlsDefaultAttributes() from their versions)
475 attrs.colFg = wxSystemSettings::GetColour(wxSYS_COLOUR_BTNTEXT);
476 attrs.colBg = wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE);
477
478 return attrs;
479}
480
481// another version for the "composite", i.e. non simple controls
482/* static */ wxVisualAttributes
483wxControl::GetCompositeControlsDefaultAttributes(wxWindowVariant WXUNUSED(variant))
484{
485 wxVisualAttributes attrs;
486 attrs.font = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT);
487 attrs.colFg = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT);
488 attrs.colBg = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW);
489
490 return attrs;
491}
492
493// ----------------------------------------------------------------------------
494// message handling
495// ----------------------------------------------------------------------------
496
497bool wxControl::ProcessCommand(wxCommandEvent& event)
498{
499 return GetEventHandler()->ProcessEvent(event);
500}
501
ffecfa5a
JS
502void wxControl::OnEraseBackground(wxEraseEvent& event)
503{
504}
505
ffecfa5a 506#endif // wxUSE_CONTROLS