]> git.saurik.com Git - wxWidgets.git/blob - src/palmos/control.cpp
wxButton, wxCheckBox, wxSlider, wxToggleButton native implementations for PalmOS.
[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 wxWindow* parentTLW = parent;
100 while ( parentTLW && !parentTLW->IsTopLevel() )
101 {
102 parentTLW = parentTLW->GetParent();
103 }
104 wxTopLevelWindowPalm* tlw = wxDynamicCast(parentTLW, wxTopLevelWindowPalm);
105 if(!tlw)
106 return false;
107 FormType* form = tlw->GetForm();
108
109 SetParent(parent);
110
111 m_control = CtlNewControl(
112 (void **)&form,
113 id,
114 style,
115 label.c_str(),
116 pos.x,
117 pos.y,
118 size.x,
119 size.y,
120 boldFont,
121 0,
122 false
123 );
124
125 if(m_control==NULL)
126 return false;
127
128 Show();
129 return true;
130 }
131
132 // ----------------------------------------------------------------------------
133 // various accessors
134 // ----------------------------------------------------------------------------
135
136 wxBorder wxControl::GetDefaultBorder() const
137 {
138 // we want to automatically give controls a sunken style (confusingly,
139 // it may not really mean sunken at all as we map it to WS_EX_CLIENTEDGE
140 // which is not sunken at all under Windows XP -- rather, just the default)
141 return wxBORDER_SUNKEN;
142 }
143
144 wxSize wxControl::DoGetBestSize() const
145 {
146 return wxSize(16, 16);
147 }
148
149 bool wxControl::Enable(bool enable)
150 {
151 if( m_control == NULL )
152 return false;
153 if( IsEnabled() == enable)
154 return false;
155 CtlSetEnabled( m_control, enable);
156 return true;
157 }
158
159 bool wxControl::IsEnabled() const
160 {
161 if( m_control == NULL )
162 return false;
163 return CtlEnabled(m_control);
164 }
165
166 bool wxControl::IsShown() const
167 {
168 return StatGetAttribute ( statAttrBarVisible , NULL );
169 }
170
171 bool wxControl::Show( bool show )
172 {
173 if(show)
174 CtlShowControl(m_control);
175 else
176 CtlHideControl(m_control);
177 return true;
178 }
179
180 void wxControl::SetLabel(const wxString& label)
181 {
182 // setting in wrong control causes crash
183 if ( ( wxDynamicCast(this,wxButton) != NULL ) ||
184 ( wxDynamicCast(this,wxCheckBox) != NULL ) ||
185 ( wxDynamicCast(this,wxToggleButton) != NULL ) )
186 {
187 CtlSetLabel(m_control,label);
188 }
189 }
190
191 wxString wxControl::GetLabel()
192 {
193 // setting in wrong control causes crash
194 if ( wxDynamicCast(this,wxButton) ||
195 wxDynamicCast(this,wxCheckBox) ||
196 wxDynamicCast(this,wxToggleButton) )
197 {
198 return CtlGetLabel(m_control);
199 }
200
201 return wxEmptyString;
202 }
203
204 /* static */ wxVisualAttributes
205 wxControl::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant))
206 {
207 wxVisualAttributes attrs;
208
209 // old school (i.e. not "common") controls use the standard dialog font
210 // by default
211 attrs.font = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT);
212
213 // most, or at least many, of the controls use the same colours as the
214 // buttons -- others will have to override this (and possibly simply call
215 // GetCompositeControlsDefaultAttributes() from their versions)
216 attrs.colFg = wxSystemSettings::GetColour(wxSYS_COLOUR_BTNTEXT);
217 attrs.colBg = wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE);
218
219 return attrs;
220 }
221
222 // another version for the "composite", i.e. non simple controls
223 /* static */ wxVisualAttributes
224 wxControl::GetCompositeControlsDefaultAttributes(wxWindowVariant WXUNUSED(variant))
225 {
226 wxVisualAttributes attrs;
227 attrs.font = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT);
228 attrs.colFg = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT);
229 attrs.colBg = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW);
230
231 return attrs;
232 }
233
234 // ----------------------------------------------------------------------------
235 // message handling
236 // ----------------------------------------------------------------------------
237
238 bool wxControl::ProcessCommand(wxCommandEvent& event)
239 {
240 return GetEventHandler()->ProcessEvent(event);
241 }
242
243 void wxControl::OnEraseBackground(wxEraseEvent& event)
244 {
245 }
246
247 WXHBRUSH wxControl::OnCtlColor(WXHDC pDC, WXHWND WXUNUSED(pWnd), WXUINT WXUNUSED(nCtlColor),
248 #if wxUSE_CTL3D
249 WXUINT message,
250 WXWPARAM wParam,
251 WXLPARAM lParam
252 #else
253 WXUINT WXUNUSED(message),
254 WXWPARAM WXUNUSED(wParam),
255 WXLPARAM WXUNUSED(lParam)
256 #endif
257 )
258 {
259 return (WXHBRUSH)0;
260 }
261
262 // ---------------------------------------------------------------------------
263 // global functions
264 // ---------------------------------------------------------------------------
265
266 #endif // wxUSE_CONTROLS