]>
Commit | Line | Data |
---|---|---|
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" | |
ffecfa5a JS |
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 | { | |
db101bd3 | 67 | m_isBeingDeleted = true; |
ffecfa5a JS |
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) ) | |
db101bd3 | 83 | return false; |
ffecfa5a JS |
84 | |
85 | #if wxUSE_VALIDATORS | |
86 | SetValidator(validator); | |
87 | #endif | |
88 | ||
db101bd3 | 89 | return true; |
ffecfa5a JS |
90 | } |
91 | ||
db101bd3 WS |
92 | bool wxControl::PalmCreateControl(ControlStyleType style, |
93 | wxWindow *parent, | |
94 | wxWindowID id, | |
95 | const wxString& label, | |
96 | const wxPoint& pos, | |
97 | const wxSize& size) | |
ffecfa5a | 98 | { |
ba889513 WS |
99 | SetParent(parent); |
100 | SetId( id == wxID_ANY ? NewControlId() : id ); | |
101 | FormType* form = GetParentForm(); | |
102 | if(form==NULL) | |
bdb54365 | 103 | return false; |
bdb54365 | 104 | |
ba889513 | 105 | m_label = label; |
bdb54365 WS |
106 | |
107 | m_control = CtlNewControl( | |
db101bd3 | 108 | (void **)&form, |
ba889513 | 109 | GetId(), |
db101bd3 | 110 | style, |
ba889513 WS |
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, | |
db101bd3 WS |
116 | boldFont, |
117 | 0, | |
118 | false | |
119 | ); | |
120 | ||
121 | if(m_control==NULL) | |
122 | return false; | |
123 | ||
db101bd3 WS |
124 | Show(); |
125 | return true; | |
ffecfa5a JS |
126 | } |
127 | ||
128 | // ---------------------------------------------------------------------------- | |
129 | // various accessors | |
130 | // ---------------------------------------------------------------------------- | |
131 | ||
ba889513 WS |
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 | ||
ffecfa5a JS |
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 | ||
ba889513 WS |
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 | ||
db101bd3 | 180 | wxSize wxControl::DoGetBestSize() const |
ffecfa5a | 181 | { |
db101bd3 | 182 | return wxSize(16, 16); |
ffecfa5a JS |
183 | } |
184 | ||
db101bd3 | 185 | bool wxControl::Enable(bool enable) |
ffecfa5a | 186 | { |
db101bd3 WS |
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 | { | |
ba889513 WS |
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; | |
db101bd3 | 215 | if(show) |
ba889513 | 216 | FrmShowObject(form,index); |
db101bd3 | 217 | else |
ba889513 | 218 | FrmHideObject(form,index); |
db101bd3 | 219 | return true; |
ffecfa5a JS |
220 | } |
221 | ||
bdb54365 WS |
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 | { | |
ba889513 WS |
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); | |
bdb54365 WS |
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 | { | |
ba889513 | 243 | return m_label; |
bdb54365 WS |
244 | } |
245 | ||
246 | return wxEmptyString; | |
247 | } | |
248 | ||
ffecfa5a JS |
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 | ||
ffecfa5a JS |
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 |