]> git.saurik.com Git - wxWidgets.git/blob - src/palmos/control.cpp
Add support for wxSL_INVERSE flag. Also uses new inverse logic to make Mac vertical...
[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
47 // ----------------------------------------------------------------------------
48 // wxWin macros
49 // ----------------------------------------------------------------------------
50
51 IMPLEMENT_ABSTRACT_CLASS(wxControl, wxWindow)
52
53 BEGIN_EVENT_TABLE(wxControl, wxWindow)
54 EVT_ERASE_BACKGROUND(wxControl::OnEraseBackground)
55 END_EVENT_TABLE()
56
57 // ============================================================================
58 // wxControl implementation
59 // ============================================================================
60
61 // ----------------------------------------------------------------------------
62 // wxControl ctor/dtor
63 // ----------------------------------------------------------------------------
64
65 wxControl::~wxControl()
66 {
67 m_isBeingDeleted = true;
68 }
69
70 // ----------------------------------------------------------------------------
71 // control window creation
72 // ----------------------------------------------------------------------------
73
74 bool wxControl::Create(wxWindow *parent,
75 wxWindowID id,
76 const wxPoint& pos,
77 const wxSize& size,
78 long style,
79 const wxValidator& wxVALIDATOR_PARAM(validator),
80 const wxString& name)
81 {
82 if ( !wxWindow::Create(parent, id, pos, size, style, name) )
83 return false;
84
85 #if wxUSE_VALIDATORS
86 SetValidator(validator);
87 #endif
88
89 return true;
90 }
91
92 bool wxControl::PalmCreateControl(ControlStyleType style,
93 wxWindow *parent,
94 wxWindowID id,
95 const wxString& label,
96 const wxPoint& pos,
97 const wxSize& size)
98 {
99 SetParent(parent);
100 SetId( id == wxID_ANY ? NewControlId() : id );
101 FormType* form = GetParentForm();
102 if(form==NULL)
103 return false;
104
105 m_label = label;
106
107 m_control = CtlNewControl(
108 (void **)&form,
109 GetId(),
110 style,
111 m_label.c_str(),
112 ( pos.x == wxDefaultCoord ) ? winUndefConstraint : pos.x,
113 ( pos.y == wxDefaultCoord ) ? winUndefConstraint : pos.y,
114 ( size.x == wxDefaultCoord ) ? winUndefConstraint : size.x,
115 ( size.y == wxDefaultCoord ) ? winUndefConstraint : size.y,
116 boldFont,
117 0,
118 false
119 );
120
121 if(m_control==NULL)
122 return false;
123
124 Show();
125 return true;
126 }
127
128 // ----------------------------------------------------------------------------
129 // various accessors
130 // ----------------------------------------------------------------------------
131
132 FormType* wxControl::GetParentForm() const
133 {
134 wxWindow* parentTLW = GetParent();
135 while ( parentTLW && !parentTLW->IsTopLevel() )
136 {
137 parentTLW = parentTLW->GetParent();
138 }
139 wxTopLevelWindowPalm* tlw = wxDynamicCast(parentTLW, wxTopLevelWindowPalm);
140 if(!tlw)
141 return NULL;
142 return tlw->GetForm();
143 }
144
145 wxBorder wxControl::GetDefaultBorder() const
146 {
147 // we want to automatically give controls a sunken style (confusingly,
148 // it may not really mean sunken at all as we map it to WS_EX_CLIENTEDGE
149 // which is not sunken at all under Windows XP -- rather, just the default)
150 return wxBORDER_SUNKEN;
151 }
152
153 void wxControl::SetIntValue(int val)
154 {
155 FormType* form = GetParentForm();
156 if(form==NULL)
157 return;
158 uint16_t index = FrmGetObjectIndex(form, GetId());
159 if(index==frmInvalidObjectId)
160 return;
161 FrmSetControlValue(form, index, val);
162 }
163
164 void wxControl::SetBoolValue(bool val)
165 {
166 SetIntValue(val?1:0);
167 }
168
169 bool wxControl::GetBoolValue() const
170 {
171 FormType* form = GetParentForm();
172 if(form==NULL)
173 return false;
174 uint16_t index = FrmGetObjectIndex(form, GetId());
175 if(index==frmInvalidObjectId)
176 return false;
177 return ( FrmGetControlValue(form, index) == 1 );
178 }
179
180 wxSize wxControl::DoGetBestSize() const
181 {
182 return wxSize(16, 16);
183 }
184
185 bool wxControl::Enable(bool enable)
186 {
187 if( m_control == NULL )
188 return false;
189 if( IsEnabled() == enable)
190 return false;
191 CtlSetEnabled( m_control, enable);
192 return true;
193 }
194
195 bool wxControl::IsEnabled() const
196 {
197 if( m_control == NULL )
198 return false;
199 return CtlEnabled(m_control);
200 }
201
202 bool wxControl::IsShown() const
203 {
204 return StatGetAttribute ( statAttrBarVisible , NULL );
205 }
206
207 bool wxControl::Show( bool show )
208 {
209 FormType* form = GetParentForm();
210 if(form==NULL)
211 return false;
212 uint16_t index = FrmGetObjectIndex(form,GetId());
213 if(index==frmInvalidObjectId)
214 return false;
215 if(show)
216 FrmShowObject(form,index);
217 else
218 FrmHideObject(form,index);
219 return true;
220 }
221
222 void wxControl::SetLabel(const wxString& label)
223 {
224 // setting in wrong control causes crash
225 if ( ( wxDynamicCast(this,wxButton) != NULL ) ||
226 ( wxDynamicCast(this,wxCheckBox) != NULL ) ||
227 ( wxDynamicCast(this,wxToggleButton) != NULL ) )
228 {
229 m_label = label;
230 // TODO: as manual states, it crashes here
231 // needs own manipulation on used string pointers
232 // CtlSetLabel(m_control,m_label);
233 }
234 }
235
236 wxString wxControl::GetLabel()
237 {
238 // setting in wrong control causes crash
239 if ( wxDynamicCast(this,wxButton) ||
240 wxDynamicCast(this,wxCheckBox) ||
241 wxDynamicCast(this,wxToggleButton) )
242 {
243 return m_label;
244 }
245
246 return wxEmptyString;
247 }
248
249 /* static */ wxVisualAttributes
250 wxControl::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant))
251 {
252 wxVisualAttributes attrs;
253
254 // old school (i.e. not "common") controls use the standard dialog font
255 // by default
256 attrs.font = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT);
257
258 // most, or at least many, of the controls use the same colours as the
259 // buttons -- others will have to override this (and possibly simply call
260 // GetCompositeControlsDefaultAttributes() from their versions)
261 attrs.colFg = wxSystemSettings::GetColour(wxSYS_COLOUR_BTNTEXT);
262 attrs.colBg = wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE);
263
264 return attrs;
265 }
266
267 // another version for the "composite", i.e. non simple controls
268 /* static */ wxVisualAttributes
269 wxControl::GetCompositeControlsDefaultAttributes(wxWindowVariant WXUNUSED(variant))
270 {
271 wxVisualAttributes attrs;
272 attrs.font = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT);
273 attrs.colFg = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT);
274 attrs.colBg = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW);
275
276 return attrs;
277 }
278
279 // ----------------------------------------------------------------------------
280 // message handling
281 // ----------------------------------------------------------------------------
282
283 bool wxControl::ProcessCommand(wxCommandEvent& event)
284 {
285 return GetEventHandler()->ProcessEvent(event);
286 }
287
288 void wxControl::OnEraseBackground(wxEraseEvent& event)
289 {
290 }
291
292 WXHBRUSH wxControl::OnCtlColor(WXHDC pDC, WXHWND WXUNUSED(pWnd), WXUINT WXUNUSED(nCtlColor),
293 #if wxUSE_CTL3D
294 WXUINT message,
295 WXWPARAM wParam,
296 WXLPARAM lParam
297 #else
298 WXUINT WXUNUSED(message),
299 WXWPARAM WXUNUSED(wParam),
300 WXLPARAM WXUNUSED(lParam)
301 #endif
302 )
303 {
304 return (WXHBRUSH)0;
305 }
306
307 // ---------------------------------------------------------------------------
308 // global functions
309 // ---------------------------------------------------------------------------
310
311 #endif // wxUSE_CONTROLS