]> git.saurik.com Git - wxWidgets.git/blame - src/palmos/control.cpp
Compilation fix for wxMSW build without PCH.
[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
ffecfa5a
JS
20// For compilers that support precompilation, includes "wx.h".
21#include "wx/wxprec.h"
22
23#ifdef __BORLANDC__
24 #pragma hdrstop
25#endif
26
27#if wxUSE_CONTROLS
28
93fbbe07
WS
29#include "wx/control.h"
30
ffecfa5a
JS
31#ifndef WX_PRECOMP
32 #include "wx/event.h"
33 #include "wx/app.h"
34 #include "wx/dcclient.h"
35 #include "wx/log.h"
36 #include "wx/settings.h"
f1e01716 37 #include "wx/button.h"
ab1ce969 38 #include "wx/checkbox.h"
b0b5881a 39 #include "wx/radiobut.h"
f4da9a94 40 #include "wx/slider.h"
1832043f 41 #include "wx/toplevel.h"
ffecfa5a
JS
42#endif
43
bdb54365 44#include "wx/tglbtn.h"
ffecfa5a 45
20bc5ad8
WS
46#include <Control.h>
47#include <Form.h>
6afc1b46
VZ
48#ifdef __WXPALMOS6__
49 #include <StatusBar.h>
50#else
51 #include <PenInputMgr.h>
52#endif // __WXPALMOS6__
20bc5ad8 53
ffecfa5a
JS
54// ----------------------------------------------------------------------------
55// wxWin macros
56// ----------------------------------------------------------------------------
57
58IMPLEMENT_ABSTRACT_CLASS(wxControl, wxWindow)
59
60BEGIN_EVENT_TABLE(wxControl, wxWindow)
61 EVT_ERASE_BACKGROUND(wxControl::OnEraseBackground)
62END_EVENT_TABLE()
63
64// ============================================================================
65// wxControl implementation
66// ============================================================================
67
68// ----------------------------------------------------------------------------
69// wxControl ctor/dtor
70// ----------------------------------------------------------------------------
71
a152561c
WS
72void wxControl::Init()
73{
74 m_palmControl = false;
75 m_palmField = false;
76}
77
ffecfa5a
JS
78wxControl::~wxControl()
79{
c6212a0c
VZ
80 SendDestroyEvent();
81
9a727a3b 82 SetLabel(wxEmptyString);
5b72333d
WS
83
84 DestroyChildren();
85
86 uint16_t index;
20bc5ad8 87 FormType* form = (FormType*)GetObjectFormIndex(index);
5b72333d
WS
88 if(form!=NULL && index!=frmInvalidObjectId)
89 {
90 FrmRemoveObject((FormType **)&form,index);
91 }
ffecfa5a
JS
92}
93
94// ----------------------------------------------------------------------------
95// control window creation
96// ----------------------------------------------------------------------------
97
98bool wxControl::Create(wxWindow *parent,
99 wxWindowID id,
100 const wxPoint& pos,
101 const wxSize& size,
102 long style,
103 const wxValidator& wxVALIDATOR_PARAM(validator),
104 const wxString& name)
105{
106 if ( !wxWindow::Create(parent, id, pos, size, style, name) )
db101bd3 107 return false;
ffecfa5a
JS
108
109#if wxUSE_VALIDATORS
110 SetValidator(validator);
111#endif
112
db101bd3 113 return true;
ffecfa5a
JS
114}
115
20bc5ad8 116bool wxControl::PalmCreateControl(int style,
db101bd3
WS
117 const wxString& label,
118 const wxPoint& pos,
a152561c 119 const wxSize& size,
8be10866 120 uint8_t groupID)
ffecfa5a 121{
20bc5ad8 122 FormType* form = (FormType*)GetParentForm();
ba889513 123 if(form==NULL)
bdb54365 124 return false;
bdb54365 125
be4e4e27
WS
126
127 wxCoord x = pos.x == wxDefaultCoord ? 0 : pos.x,
128 y = pos.y == wxDefaultCoord ? 0 : pos.y,
129 w = size.x == wxDefaultCoord ? 1 : size.x,
130 h = size.y == wxDefaultCoord ? 1 : size.y;
131
d2893292
WS
132 wxWindow *win = this;
133 while(win->GetParent())
134 {
135 win = win->GetParent();
136 wxPoint pt(win->GetClientAreaOrigin());
137 x += pt.x;
138 y += pt.y;
139 }
be4e4e27 140
a152561c
WS
141 ControlType *control = CtlNewControl(
142 (void **)&form,
143 GetId(),
20bc5ad8 144 (ControlStyleType)style,
e2fc40b4 145 NULL,
be4e4e27
WS
146 x,
147 y,
148 w,
149 h,
a152561c
WS
150 stdFont,
151 groupID,
5b72333d 152 true
a152561c
WS
153 );
154
155 if(control==NULL)
db101bd3
WS
156 return false;
157
a152561c
WS
158 m_palmControl = true;
159
170acdc9 160 SetInitialSize(size);
9a727a3b 161 SetLabel(label);
db101bd3
WS
162 Show();
163 return true;
ffecfa5a
JS
164}
165
a152561c
WS
166bool wxControl::PalmCreateField(const wxString& label,
167 const wxPoint& pos,
168 const wxSize& size,
169 bool editable,
170 bool underlined,
20bc5ad8 171 int justification)
a152561c 172{
20bc5ad8 173 FormType* form = (FormType*)GetParentForm();
a152561c
WS
174 if(form==NULL)
175 return false;
176
177 m_label = label;
178
be4e4e27
WS
179 wxCoord x = pos.x == wxDefaultCoord ? 0 : pos.x,
180 y = pos.y == wxDefaultCoord ? 0 : pos.y,
181 w = size.x == wxDefaultCoord ? 1 : size.x,
182 h = size.y == wxDefaultCoord ? 1 : size.y;
183
184 AdjustForParentClientOrigin(x, y);
185
a152561c
WS
186 FieldType *field = FldNewField(
187 (void **)&form,
188 GetId(),
be4e4e27
WS
189 x,
190 y,
191 w,
192 h,
a152561c
WS
193 stdFont,
194 10,
195 editable,
196 underlined,
197 false,
198 false,
20bc5ad8 199 (JustificationType)justification,
a152561c
WS
200 false,
201 false,
202 false
203 );
204
205 if(field==NULL)
206 return false;
207
208 m_palmField = true;
209
170acdc9 210 SetInitialSize(size);
a152561c 211 SetLabel(label);
be4e4e27 212 Show();
a152561c
WS
213 return true;
214}
215
ffecfa5a
JS
216// ----------------------------------------------------------------------------
217// various accessors
218// ----------------------------------------------------------------------------
219
20bc5ad8 220WXFORMPTR wxControl::GetParentForm() const
ba889513
WS
221{
222 wxWindow* parentTLW = GetParent();
223 while ( parentTLW && !parentTLW->IsTopLevel() )
224 {
225 parentTLW = parentTLW->GetParent();
226 }
227 wxTopLevelWindowPalm* tlw = wxDynamicCast(parentTLW, wxTopLevelWindowPalm);
228 if(!tlw)
229 return NULL;
230 return tlw->GetForm();
231}
232
20bc5ad8 233WXFORMPTR wxControl::GetObjectFormIndex(uint16_t& index) const
a152561c 234{
20bc5ad8 235 FormType* form = (FormType* )GetParentForm();
5b72333d
WS
236 if(form!=NULL)
237 index = FrmGetObjectIndex(form, GetId());
238 else
239 index = frmInvalidObjectId;
240 return form;
a152561c
WS
241}
242
243void* wxControl::GetObjectPtr() const
244{
5b72333d 245 uint16_t index;
20bc5ad8 246 FormType* form = (FormType*)GetObjectFormIndex(index);
5b72333d 247 if(form==NULL || index==frmInvalidObjectId)return NULL;
a152561c
WS
248 return FrmGetObjectPtr(form,index);
249}
250
ffecfa5a
JS
251wxBorder wxControl::GetDefaultBorder() const
252{
253 // we want to automatically give controls a sunken style (confusingly,
254 // it may not really mean sunken at all as we map it to WS_EX_CLIENTEDGE
255 // which is not sunken at all under Windows XP -- rather, just the default)
256 return wxBORDER_SUNKEN;
257}
258
ba889513
WS
259void wxControl::SetIntValue(int val)
260{
20bc5ad8 261 FormType* form = (FormType*)GetParentForm();
ba889513
WS
262 if(form==NULL)
263 return;
264 uint16_t index = FrmGetObjectIndex(form, GetId());
265 if(index==frmInvalidObjectId)
266 return;
267 FrmSetControlValue(form, index, val);
268}
269
270void wxControl::SetBoolValue(bool val)
271{
272 SetIntValue(val?1:0);
273}
274
275bool wxControl::GetBoolValue() const
276{
20bc5ad8 277 FormType* form = (FormType*)GetParentForm();
ba889513
WS
278 if(form==NULL)
279 return false;
280 uint16_t index = FrmGetObjectIndex(form, GetId());
281 if(index==frmInvalidObjectId)
282 return false;
283 return ( FrmGetControlValue(form, index) == 1 );
284}
285
db101bd3 286wxSize wxControl::DoGetBestSize() const
ffecfa5a 287{
db101bd3 288 return wxSize(16, 16);
ffecfa5a
JS
289}
290
20bc5ad8 291void wxControl::DoGetBounds( WXRECTANGLEPTR rect ) const
808e3bce 292{
20bc5ad8
WS
293 if(rect==NULL)
294 return;
295 FormType* form = (FormType*)GetParentForm();
808e3bce
WS
296 if(form==NULL)
297 return;
298 uint16_t index = FrmGetObjectIndex(form,GetId());
299 if(index==frmInvalidObjectId)
300 return;
20bc5ad8 301 FrmGetObjectBounds(form,index,(RectangleType*)rect);
808e3bce
WS
302}
303
20bc5ad8 304void wxControl::DoSetBounds( WXRECTANGLEPTR rect )
324eeecb 305{
20bc5ad8
WS
306 if(rect==NULL)
307 return;
308 FormType* form = (FormType*)GetParentForm();
324eeecb
WS
309 if(form==NULL)
310 return;
311 uint16_t index = FrmGetObjectIndex(form,GetId());
312 if(index==frmInvalidObjectId)
313 return;
20bc5ad8 314 FrmSetObjectBounds(form,index,(RectangleType*)rect);
324eeecb
WS
315}
316
808e3bce
WS
317void wxControl::DoGetPosition( int *x, int *y ) const
318{
d2893292
WS
319 int ox = 0, oy = 0;
320 AdjustForParentClientOrigin(ox, oy);
321
808e3bce 322 RectangleType rect;
20bc5ad8 323 DoGetBounds(&rect);
d2893292 324
808e3bce 325 if(x)
d2893292 326 *x = rect.topLeft.x - ox;
808e3bce 327 if(y)
d2893292 328 *y = rect.topLeft.y - oy;
808e3bce
WS
329}
330
331void wxControl::DoGetSize( int *width, int *height ) const
332{
333 RectangleType rect;
20bc5ad8 334 DoGetBounds(&rect);
d2893292 335
808e3bce
WS
336 if(width)
337 *width = rect.extent.x;
338 if(height)
339 *height = rect.extent.y;
340}
341
324eeecb
WS
342void wxControl::DoMoveWindow(int x, int y, int width, int height)
343{
344 wxRect area = GetRect();
345 RectangleType rect;
346 rect.topLeft.x = x;
347 rect.topLeft.y = y;
348 rect.extent.x = width;
349 rect.extent.y = height;
20bc5ad8 350 DoSetBounds(&rect);
324eeecb
WS
351 GetParent()->Refresh(true, &area);
352}
353
db101bd3 354bool wxControl::Enable(bool enable)
ffecfa5a 355{
a152561c 356 ControlType *control = (ControlType *)GetObjectPtr();
1a87edf2 357 if( !IsPalmControl() || (control == NULL))
db101bd3 358 return false;
a152561c 359 if( CtlEnabled(control) == enable)
db101bd3 360 return false;
a152561c 361 CtlSetEnabled( control, enable);
db101bd3
WS
362 return true;
363}
364
365bool wxControl::IsEnabled() const
366{
a152561c 367 ControlType *control = (ControlType *)GetObjectPtr();
1a87edf2 368 if( !IsPalmControl() || (control == NULL))
db101bd3 369 return false;
a152561c 370 return CtlEnabled(control);
db101bd3
WS
371}
372
373bool wxControl::IsShown() const
374{
375 return StatGetAttribute ( statAttrBarVisible , NULL );
376}
377
378bool wxControl::Show( bool show )
379{
20bc5ad8 380 FormType* form = (FormType*)GetParentForm();
ba889513
WS
381 if(form==NULL)
382 return false;
383 uint16_t index = FrmGetObjectIndex(form,GetId());
384 if(index==frmInvalidObjectId)
385 return false;
db101bd3 386 if(show)
ba889513 387 FrmShowObject(form,index);
db101bd3 388 else
ba889513 389 FrmHideObject(form,index);
db101bd3 390 return true;
ffecfa5a
JS
391}
392
a152561c 393void wxControl::SetFieldLabel(const wxString& label)
bdb54365 394{
a152561c
WS
395 FieldType* field = (FieldType*)GetObjectPtr();
396 if(field==NULL)
397 return;
398
f1e01716 399 uint16_t newSize = label.length() + 1;
a152561c
WS
400 MemHandle strHandle = FldGetTextHandle(field);
401 FldSetTextHandle(field, NULL );
402 if (strHandle)
bdb54365 403 {
a152561c
WS
404 if(MemHandleResize(strHandle, newSize)!=errNone)
405 strHandle = 0;
bdb54365 406 }
a152561c
WS
407 else
408 {
409 strHandle = MemHandleNew( newSize );
410 }
411 if(!strHandle)
412 return;
413
414 char* str = (char*) MemHandleLock( strHandle );
415 if(str==NULL)
416 return;
417
418 strcpy(str, label.c_str());
419 MemHandleUnlock(strHandle);
420 FldSetTextHandle(field, strHandle);
421 FldRecalculateField(field, true);
422}
423
424void wxControl::SetControlLabel(const wxString& label)
425{
9a727a3b
WS
426 ControlType* control = (ControlType*)GetObjectPtr();
427 if(control==NULL)
428 return;
e2fc40b4 429 CtlSetLabel(control, "");
9a727a3b
WS
430 m_label = label;
431 if(!m_label.empty())
432 CtlSetLabel(control,m_label.c_str());
a152561c
WS
433}
434
435void wxControl::SetLabel(const wxString& label)
436{
437 if(IsPalmField())
438 SetFieldLabel(label);
439
440 // unlike other native controls, slider has no label
441 if(IsPalmControl() && !wxDynamicCast(this,wxSlider))
442 SetControlLabel(label);
443}
444
445wxString wxControl::GetFieldLabel()
446{
447 FieldType* field = (FieldType*)GetObjectPtr();
448 if(field==NULL)
449 return wxEmptyString;
450 return FldGetTextPtr(field);
451}
452
453wxString wxControl::GetControlLabel()
454{
455 ControlType* control = (ControlType*)GetObjectPtr();
456 if(control==NULL)
457 return wxEmptyString;
458 return CtlGetLabel(control);
bdb54365 459}
e2fc40b4 460#if 0
bdb54365
WS
461wxString wxControl::GetLabel()
462{
a152561c
WS
463 if(IsPalmField())
464 return GetFieldLabel();
465
466 // unlike other native controls, slider has no label
467 if(IsPalmControl() && !wxDynamicCast(this,wxSlider))
468 return GetControlLabel();
bdb54365
WS
469
470 return wxEmptyString;
471}
e2fc40b4 472#endif
ffecfa5a
JS
473/* static */ wxVisualAttributes
474wxControl::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant))
475{
476 wxVisualAttributes attrs;
477
478 // old school (i.e. not "common") controls use the standard dialog font
479 // by default
480 attrs.font = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT);
481
482 // most, or at least many, of the controls use the same colours as the
483 // buttons -- others will have to override this (and possibly simply call
484 // GetCompositeControlsDefaultAttributes() from their versions)
485 attrs.colFg = wxSystemSettings::GetColour(wxSYS_COLOUR_BTNTEXT);
486 attrs.colBg = wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE);
487
488 return attrs;
489}
490
491// another version for the "composite", i.e. non simple controls
492/* static */ wxVisualAttributes
493wxControl::GetCompositeControlsDefaultAttributes(wxWindowVariant WXUNUSED(variant))
494{
495 wxVisualAttributes attrs;
496 attrs.font = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT);
497 attrs.colFg = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT);
498 attrs.colBg = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW);
499
500 return attrs;
501}
502
503// ----------------------------------------------------------------------------
504// message handling
505// ----------------------------------------------------------------------------
506
507bool wxControl::ProcessCommand(wxCommandEvent& event)
508{
937013e0 509 return HandleWindowEvent(event);
ffecfa5a
JS
510}
511
ffecfa5a
JS
512void wxControl::OnEraseBackground(wxEraseEvent& event)
513{
514}
515
ffecfa5a 516#endif // wxUSE_CONTROLS