]> git.saurik.com Git - wxWidgets.git/blame - src/palmos/control.cpp
wxSL_INVERSE for MSW. Heavily modified patch 1096922.
[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
a152561c
WS
120 ControlType *control = CtlNewControl(
121 (void **)&form,
122 GetId(),
123 style,
9a727a3b 124 wxEmptyString,
a152561c
WS
125 ( pos.x == wxDefaultCoord ) ? winUndefConstraint : pos.x,
126 ( pos.y == wxDefaultCoord ) ? winUndefConstraint : pos.y,
127 ( size.x == wxDefaultCoord ) ? winUndefConstraint : size.x,
128 ( size.y == wxDefaultCoord ) ? winUndefConstraint : size.y,
129 stdFont,
130 groupID,
5b72333d 131 true
a152561c
WS
132 );
133
134 if(control==NULL)
db101bd3
WS
135 return false;
136
a152561c
WS
137 m_palmControl = true;
138
9a727a3b 139 SetLabel(label);
db101bd3
WS
140 Show();
141 return true;
ffecfa5a
JS
142}
143
a152561c
WS
144bool wxControl::PalmCreateField(const wxString& label,
145 const wxPoint& pos,
146 const wxSize& size,
147 bool editable,
148 bool underlined,
149 JustificationType justification)
150{
151 FormType* form = GetParentForm();
152 if(form==NULL)
153 return false;
154
155 m_label = label;
156
157 FieldType *field = FldNewField(
158 (void **)&form,
159 GetId(),
160 ( pos.x == wxDefaultCoord ) ? winUndefConstraint : pos.x,
161 ( pos.y == wxDefaultCoord ) ? winUndefConstraint : pos.y,
162 ( size.x == wxDefaultCoord ) ? winUndefConstraint : size.x,
163 ( size.y == wxDefaultCoord ) ? winUndefConstraint : size.y,
164 stdFont,
165 10,
166 editable,
167 underlined,
168 false,
169 false,
170 justification,
171 false,
172 false,
173 false
174 );
175
176 if(field==NULL)
177 return false;
178
179 m_palmField = true;
180
181 Show();
182 SetLabel(label);
183 return true;
184}
185
ffecfa5a
JS
186// ----------------------------------------------------------------------------
187// various accessors
188// ----------------------------------------------------------------------------
189
ba889513
WS
190FormType* wxControl::GetParentForm() const
191{
192 wxWindow* parentTLW = GetParent();
193 while ( parentTLW && !parentTLW->IsTopLevel() )
194 {
195 parentTLW = parentTLW->GetParent();
196 }
197 wxTopLevelWindowPalm* tlw = wxDynamicCast(parentTLW, wxTopLevelWindowPalm);
198 if(!tlw)
199 return NULL;
200 return tlw->GetForm();
201}
202
5b72333d 203FormType* wxControl::GetObjectFormIndex(uint16_t& index) const
a152561c
WS
204{
205 FormType* form = GetParentForm();
5b72333d
WS
206 if(form!=NULL)
207 index = FrmGetObjectIndex(form, GetId());
208 else
209 index = frmInvalidObjectId;
210 return form;
a152561c
WS
211}
212
213void* wxControl::GetObjectPtr() const
214{
5b72333d
WS
215 uint16_t index;
216 FormType* form = GetObjectFormIndex(index);
217 if(form==NULL || index==frmInvalidObjectId)return NULL;
a152561c
WS
218 return FrmGetObjectPtr(form,index);
219}
220
ffecfa5a
JS
221wxBorder wxControl::GetDefaultBorder() const
222{
223 // we want to automatically give controls a sunken style (confusingly,
224 // it may not really mean sunken at all as we map it to WS_EX_CLIENTEDGE
225 // which is not sunken at all under Windows XP -- rather, just the default)
226 return wxBORDER_SUNKEN;
227}
228
ba889513
WS
229void wxControl::SetIntValue(int val)
230{
231 FormType* form = GetParentForm();
232 if(form==NULL)
233 return;
234 uint16_t index = FrmGetObjectIndex(form, GetId());
235 if(index==frmInvalidObjectId)
236 return;
237 FrmSetControlValue(form, index, val);
238}
239
240void wxControl::SetBoolValue(bool val)
241{
242 SetIntValue(val?1:0);
243}
244
245bool wxControl::GetBoolValue() const
246{
247 FormType* form = GetParentForm();
248 if(form==NULL)
249 return false;
250 uint16_t index = FrmGetObjectIndex(form, GetId());
251 if(index==frmInvalidObjectId)
252 return false;
253 return ( FrmGetControlValue(form, index) == 1 );
254}
255
db101bd3 256wxSize wxControl::DoGetBestSize() const
ffecfa5a 257{
db101bd3 258 return wxSize(16, 16);
ffecfa5a
JS
259}
260
808e3bce
WS
261void wxControl::DoGetBounds( RectangleType &rect ) const
262{
263 FormType* form = GetParentForm();
264 if(form==NULL)
265 return;
266 uint16_t index = FrmGetObjectIndex(form,GetId());
267 if(index==frmInvalidObjectId)
268 return;
269 FrmGetObjectBounds(form,index,&rect);
270}
271
272void wxControl::DoGetPosition( int *x, int *y ) const
273{
274 RectangleType rect;
275 DoGetBounds(rect);
276 if(x)
277 *x = rect.topLeft.x;
278 if(y)
279 *y = rect.topLeft.y;
280}
281
282void wxControl::DoGetSize( int *width, int *height ) const
283{
284 RectangleType rect;
285 DoGetBounds(rect);
286 if(width)
287 *width = rect.extent.x;
288 if(height)
289 *height = rect.extent.y;
290}
291
db101bd3 292bool wxControl::Enable(bool enable)
ffecfa5a 293{
a152561c
WS
294 ControlType *control = (ControlType *)GetObjectPtr();
295 if( (IsPalmControl()) || (control == NULL))
db101bd3 296 return false;
a152561c 297 if( CtlEnabled(control) == enable)
db101bd3 298 return false;
a152561c 299 CtlSetEnabled( control, enable);
db101bd3
WS
300 return true;
301}
302
303bool wxControl::IsEnabled() const
304{
a152561c
WS
305 ControlType *control = (ControlType *)GetObjectPtr();
306 if( (IsPalmControl()) || (control == NULL))
db101bd3 307 return false;
a152561c 308 return CtlEnabled(control);
db101bd3
WS
309}
310
311bool wxControl::IsShown() const
312{
313 return StatGetAttribute ( statAttrBarVisible , NULL );
314}
315
316bool wxControl::Show( bool show )
317{
ba889513
WS
318 FormType* form = GetParentForm();
319 if(form==NULL)
320 return false;
321 uint16_t index = FrmGetObjectIndex(form,GetId());
322 if(index==frmInvalidObjectId)
323 return false;
db101bd3 324 if(show)
ba889513 325 FrmShowObject(form,index);
db101bd3 326 else
ba889513 327 FrmHideObject(form,index);
db101bd3 328 return true;
ffecfa5a
JS
329}
330
a152561c 331void wxControl::SetFieldLabel(const wxString& label)
bdb54365 332{
a152561c
WS
333 FieldType* field = (FieldType*)GetObjectPtr();
334 if(field==NULL)
335 return;
336
337 uint16_t newSize = label.Length() + 1;
338 MemHandle strHandle = FldGetTextHandle(field);
339 FldSetTextHandle(field, NULL );
340 if (strHandle)
bdb54365 341 {
a152561c
WS
342 if(MemHandleResize(strHandle, newSize)!=errNone)
343 strHandle = 0;
bdb54365 344 }
a152561c
WS
345 else
346 {
347 strHandle = MemHandleNew( newSize );
348 }
349 if(!strHandle)
350 return;
351
352 char* str = (char*) MemHandleLock( strHandle );
353 if(str==NULL)
354 return;
355
356 strcpy(str, label.c_str());
357 MemHandleUnlock(strHandle);
358 FldSetTextHandle(field, strHandle);
359 FldRecalculateField(field, true);
360}
361
362void wxControl::SetControlLabel(const wxString& label)
363{
9a727a3b
WS
364 ControlType* control = (ControlType*)GetObjectPtr();
365 if(control==NULL)
366 return;
367 CtlSetLabel(control,wxEmptyString);
368 m_label = label;
369 if(!m_label.empty())
370 CtlSetLabel(control,m_label.c_str());
a152561c
WS
371}
372
373void wxControl::SetLabel(const wxString& label)
374{
375 if(IsPalmField())
376 SetFieldLabel(label);
377
378 // unlike other native controls, slider has no label
379 if(IsPalmControl() && !wxDynamicCast(this,wxSlider))
380 SetControlLabel(label);
381}
382
383wxString wxControl::GetFieldLabel()
384{
385 FieldType* field = (FieldType*)GetObjectPtr();
386 if(field==NULL)
387 return wxEmptyString;
388 return FldGetTextPtr(field);
389}
390
391wxString wxControl::GetControlLabel()
392{
393 ControlType* control = (ControlType*)GetObjectPtr();
394 if(control==NULL)
395 return wxEmptyString;
396 return CtlGetLabel(control);
bdb54365
WS
397}
398
399wxString wxControl::GetLabel()
400{
a152561c
WS
401 if(IsPalmField())
402 return GetFieldLabel();
403
404 // unlike other native controls, slider has no label
405 if(IsPalmControl() && !wxDynamicCast(this,wxSlider))
406 return GetControlLabel();
bdb54365
WS
407
408 return wxEmptyString;
409}
410
ffecfa5a
JS
411/* static */ wxVisualAttributes
412wxControl::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant))
413{
414 wxVisualAttributes attrs;
415
416 // old school (i.e. not "common") controls use the standard dialog font
417 // by default
418 attrs.font = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT);
419
420 // most, or at least many, of the controls use the same colours as the
421 // buttons -- others will have to override this (and possibly simply call
422 // GetCompositeControlsDefaultAttributes() from their versions)
423 attrs.colFg = wxSystemSettings::GetColour(wxSYS_COLOUR_BTNTEXT);
424 attrs.colBg = wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE);
425
426 return attrs;
427}
428
429// another version for the "composite", i.e. non simple controls
430/* static */ wxVisualAttributes
431wxControl::GetCompositeControlsDefaultAttributes(wxWindowVariant WXUNUSED(variant))
432{
433 wxVisualAttributes attrs;
434 attrs.font = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT);
435 attrs.colFg = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT);
436 attrs.colBg = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW);
437
438 return attrs;
439}
440
441// ----------------------------------------------------------------------------
442// message handling
443// ----------------------------------------------------------------------------
444
445bool wxControl::ProcessCommand(wxCommandEvent& event)
446{
447 return GetEventHandler()->ProcessEvent(event);
448}
449
ffecfa5a
JS
450void wxControl::OnEraseBackground(wxEraseEvent& event)
451{
452}
453
454WXHBRUSH wxControl::OnCtlColor(WXHDC pDC, WXHWND WXUNUSED(pWnd), WXUINT WXUNUSED(nCtlColor),
ffecfa5a
JS
455 WXUINT WXUNUSED(message),
456 WXWPARAM WXUNUSED(wParam),
457 WXLPARAM WXUNUSED(lParam)
ffecfa5a
JS
458 )
459{
460 return (WXHBRUSH)0;
461}
462
463// ---------------------------------------------------------------------------
464// global functions
465// ---------------------------------------------------------------------------
466
467#endif // wxUSE_CONTROLS