]>
Commit | Line | Data |
---|---|---|
b782f2e0 VZ |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: msw/spinctrl.cpp | |
3 | // Purpose: wxSpinCtrl class implementation for Win32 | |
4 | // Author: Vadim Zeitlin | |
5 | // Modified by: | |
6 | // Created: 22.07.99 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Vadim Zeitlin | |
9 | // Licence: wxWindows licence | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | // ============================================================================ | |
13 | // declarations | |
14 | // ============================================================================ | |
15 | ||
14f355c2 | 16 | #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) |
b782f2e0 VZ |
17 | #pragma implementation "spinctrlbase.h" |
18 | #pragma implementation "spinctrl.h" | |
19 | #endif | |
20 | ||
21 | // ---------------------------------------------------------------------------- | |
22 | // headers | |
23 | // ---------------------------------------------------------------------------- | |
24 | ||
25 | // for compilers that support precompilation, includes "wx.h". | |
26 | #include "wx/wxprec.h" | |
27 | ||
28 | #ifdef __BORLANDC__ | |
29 | #pragma hdrstop | |
30 | #endif | |
31 | ||
32 | #ifndef WX_PRECOMP | |
33 | #include "wx/wx.h" | |
34 | #endif | |
35 | ||
0e528b99 JS |
36 | #if wxUSE_SPINCTRL |
37 | ||
b782f2e0 VZ |
38 | #if defined(__WIN95__) |
39 | ||
40 | #include "wx/spinctrl.h" | |
41 | #include "wx/msw/private.h" | |
42 | ||
b39dbf34 | 43 | #if defined(__WIN95__) && !(defined(__GNUWIN32_OLD__) && !defined(__CYGWIN10__)) |
4c0a2c5c JS |
44 | #include <commctrl.h> |
45 | #endif | |
b782f2e0 | 46 | |
678cd6de VZ |
47 | #include <limits.h> // for INT_MIN |
48 | ||
b782f2e0 VZ |
49 | // ---------------------------------------------------------------------------- |
50 | // macros | |
51 | // ---------------------------------------------------------------------------- | |
52 | ||
f0a126fe | 53 | #if wxUSE_EXTENDED_RTTI |
bc9fb572 JS |
54 | WX_DEFINE_FLAGS( wxSpinCtrlStyle ) |
55 | ||
56 | WX_BEGIN_FLAGS( wxSpinCtrlStyle ) | |
57 | // new style border flags, we put them first to | |
58 | // use them for streaming out | |
59 | WX_FLAGS_MEMBER(wxBORDER_SIMPLE) | |
60 | WX_FLAGS_MEMBER(wxBORDER_SUNKEN) | |
61 | WX_FLAGS_MEMBER(wxBORDER_DOUBLE) | |
62 | WX_FLAGS_MEMBER(wxBORDER_RAISED) | |
63 | WX_FLAGS_MEMBER(wxBORDER_STATIC) | |
64 | WX_FLAGS_MEMBER(wxBORDER_NONE) | |
65 | ||
66 | // old style border flags | |
67 | WX_FLAGS_MEMBER(wxSIMPLE_BORDER) | |
68 | WX_FLAGS_MEMBER(wxSUNKEN_BORDER) | |
69 | WX_FLAGS_MEMBER(wxDOUBLE_BORDER) | |
70 | WX_FLAGS_MEMBER(wxRAISED_BORDER) | |
71 | WX_FLAGS_MEMBER(wxSTATIC_BORDER) | |
72 | WX_FLAGS_MEMBER(wxNO_BORDER) | |
73 | ||
74 | // standard window styles | |
75 | WX_FLAGS_MEMBER(wxTAB_TRAVERSAL) | |
76 | WX_FLAGS_MEMBER(wxCLIP_CHILDREN) | |
77 | WX_FLAGS_MEMBER(wxTRANSPARENT_WINDOW) | |
78 | WX_FLAGS_MEMBER(wxWANTS_CHARS) | |
79 | WX_FLAGS_MEMBER(wxNO_FULL_REPAINT_ON_RESIZE) | |
80 | WX_FLAGS_MEMBER(wxALWAYS_SHOW_SB ) | |
81 | WX_FLAGS_MEMBER(wxVSCROLL) | |
82 | WX_FLAGS_MEMBER(wxHSCROLL) | |
83 | ||
84 | WX_FLAGS_MEMBER(wxSP_HORIZONTAL) | |
85 | WX_FLAGS_MEMBER(wxSP_VERTICAL) | |
86 | WX_FLAGS_MEMBER(wxSP_ARROW_KEYS) | |
87 | WX_FLAGS_MEMBER(wxSP_WRAP) | |
88 | ||
89 | WX_END_FLAGS( wxSpinCtrlStyle ) | |
90 | ||
51741307 | 91 | IMPLEMENT_DYNAMIC_CLASS_XTI(wxSpinCtrl, wxControl,"wx/spinbut.h") |
9750fc42 | 92 | |
51741307 | 93 | WX_BEGIN_PROPERTIES_TABLE(wxSpinCtrl) |
ffca575c SC |
94 | WX_EVENT_RANGE_PROPERTY( Spin , wxEVT_SCROLL_TOP , wxEVT_SCROLL_ENDSCROLL , wxSpinEvent ) |
95 | WX_EVENT_PROPERTY( Updated , wxEVT_COMMAND_SPINCTRL_UPDATED , wxCommandEvent ) | |
96 | WX_EVENT_PROPERTY( TextUpdated , wxEVT_COMMAND_TEXT_UPDATED , wxCommandEvent ) | |
97 | WX_EVENT_PROPERTY( TextEnter , wxEVT_COMMAND_TEXT_ENTER , wxCommandEvent ) | |
c5ca409b | 98 | |
067e9be6 SC |
99 | WX_PROPERTY( ValueString , wxString , SetValue , GetValue , , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) ; |
100 | WX_PROPERTY( Value , int , SetValue, GetValue, 0 , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) | |
101 | WX_PROPERTY( Min , int , SetMin, GetMin, 0, 0 /*flags*/ , wxT("Helpstring") , wxT("group") ) | |
102 | WX_PROPERTY( Max , int , SetMax, GetMax, 0 , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) | |
bc9fb572 | 103 | WX_PROPERTY_FLAGS( WindowStyle , wxSpinCtrlStyle , long , SetWindowStyleFlag , GetWindowStyleFlag , , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style |
066f1b7a SC |
104 | /* |
105 | TODO PROPERTIES | |
106 | style wxSP_ARROW_KEYS | |
066f1b7a | 107 | */ |
51741307 SC |
108 | WX_END_PROPERTIES_TABLE() |
109 | ||
110 | WX_BEGIN_HANDLERS_TABLE(wxSpinCtrl) | |
111 | WX_END_HANDLERS_TABLE() | |
112 | ||
f0a126fe | 113 | WX_CONSTRUCTOR_6( wxSpinCtrl , wxWindow* , Parent , wxWindowID , Id , wxString , ValueString , wxPoint , Position , wxSize , Size , long , WindowStyle ) |
51741307 SC |
114 | #else |
115 | IMPLEMENT_DYNAMIC_CLASS(wxSpinCtrl, wxControl) | |
116 | #endif | |
066f1b7a | 117 | |
9750fc42 | 118 | BEGIN_EVENT_TABLE(wxSpinCtrl, wxSpinButton) |
e3582f7f | 119 | EVT_CHAR(wxSpinCtrl::OnChar) |
c5c04fab VZ |
120 | |
121 | EVT_SET_FOCUS(wxSpinCtrl::OnSetFocus) | |
122 | ||
9750fc42 VZ |
123 | EVT_SPIN(-1, wxSpinCtrl::OnSpinChange) |
124 | END_EVENT_TABLE() | |
b782f2e0 | 125 | |
6fe19057 VZ |
126 | #define GetBuddyHwnd() (HWND)(m_hwndBuddy) |
127 | ||
b782f2e0 VZ |
128 | // ---------------------------------------------------------------------------- |
129 | // constants | |
130 | // ---------------------------------------------------------------------------- | |
131 | ||
baccb514 VZ |
132 | // the margin between the up-down control and its buddy (can be arbitrary, |
133 | // choose what you like - or may be decide during run-time depending on the | |
134 | // font size?) | |
135 | static const int MARGIN_BETWEEN = 1; | |
b782f2e0 VZ |
136 | |
137 | // ============================================================================ | |
138 | // implementation | |
139 | // ============================================================================ | |
140 | ||
6fe19057 VZ |
141 | wxArraySpins wxSpinCtrl::ms_allSpins; |
142 | ||
f6bcfd97 BP |
143 | // ---------------------------------------------------------------------------- |
144 | // wnd proc for the buddy text ctrl | |
145 | // ---------------------------------------------------------------------------- | |
146 | ||
147 | LRESULT APIENTRY _EXPORT wxBuddyTextWndProc(HWND hwnd, | |
148 | UINT message, | |
149 | WPARAM wParam, | |
150 | LPARAM lParam) | |
151 | { | |
152 | wxSpinCtrl *spin = (wxSpinCtrl *)::GetWindowLong(hwnd, GWL_USERDATA); | |
153 | ||
93c4157c VZ |
154 | // forward some messages (the key and focus ones only so far) to |
155 | // the spin ctrl | |
f6bcfd97 BP |
156 | switch ( message ) |
157 | { | |
93c4157c | 158 | case WM_SETFOCUS: |
c5c04fab VZ |
159 | // if the focus comes from the spin control itself, don't set it |
160 | // back to it -- we don't want to go into an infinite loop | |
161 | if ( wParam == spin->GetHWND() ) | |
162 | break; | |
163 | //else: fall through | |
164 | ||
93c4157c | 165 | case WM_KILLFOCUS: |
f6bcfd97 BP |
166 | case WM_CHAR: |
167 | case WM_DEADCHAR: | |
168 | case WM_KEYUP: | |
169 | case WM_KEYDOWN: | |
170 | spin->MSWWindowProc(message, wParam, lParam); | |
e3582f7f JS |
171 | |
172 | // The control may have been deleted at this point, so check. | |
173 | if (!(::IsWindow(hwnd) && ((wxSpinCtrl *)::GetWindowLong(hwnd, GWL_USERDATA)) == spin)) | |
174 | return 0; | |
f6bcfd97 | 175 | break; |
350ba193 VZ |
176 | |
177 | case WM_GETDLGCODE: | |
178 | // we want to get WXK_RETURN in order to generate the event for it | |
179 | return DLGC_WANTCHARS; | |
f6bcfd97 | 180 | } |
350ba193 | 181 | |
f6bcfd97 BP |
182 | return ::CallWindowProc(CASTWNDPROC spin->GetBuddyWndProc(), |
183 | hwnd, message, wParam, lParam); | |
184 | } | |
185 | ||
6fe19057 VZ |
186 | /* static */ |
187 | wxSpinCtrl *wxSpinCtrl::GetSpinForTextCtrl(WXHWND hwndBuddy) | |
188 | { | |
189 | wxSpinCtrl *spin = (wxSpinCtrl *)::GetWindowLong((HWND)hwndBuddy, | |
190 | GWL_USERDATA); | |
191 | ||
192 | int i = ms_allSpins.Index(spin); | |
193 | ||
194 | if ( i == wxNOT_FOUND ) | |
195 | return NULL; | |
196 | ||
197 | // sanity check | |
198 | wxASSERT_MSG( spin->m_hwndBuddy == hwndBuddy, | |
199 | _T("wxSpinCtrl has incorrect buddy HWND!") ); | |
200 | ||
201 | return spin; | |
202 | } | |
203 | ||
204 | // process a WM_COMMAND generated by the buddy text control | |
205 | bool wxSpinCtrl::ProcessTextCommand(WXWORD cmd, WXWORD WXUNUSED(id)) | |
206 | { | |
e3582f7f | 207 | switch (cmd) |
6fe19057 | 208 | { |
e3582f7f JS |
209 | case EN_CHANGE: |
210 | { | |
211 | wxCommandEvent event(wxEVT_COMMAND_TEXT_UPDATED, GetId()); | |
212 | event.SetEventObject(this); | |
213 | wxString val = wxGetWindowText(m_hwndBuddy); | |
214 | event.SetString(val); | |
215 | event.SetInt(GetValue()); | |
216 | return GetEventHandler()->ProcessEvent(event); | |
217 | } | |
218 | case EN_SETFOCUS: | |
219 | case EN_KILLFOCUS: | |
220 | { | |
221 | wxFocusEvent event(cmd == EN_KILLFOCUS ? wxEVT_KILL_FOCUS | |
222 | : wxEVT_SET_FOCUS, | |
223 | m_windowId); | |
224 | event.SetEventObject( this ); | |
225 | return GetEventHandler()->ProcessEvent(event); | |
226 | } | |
227 | default: | |
228 | break; | |
6fe19057 VZ |
229 | } |
230 | ||
231 | // not processed | |
232 | return FALSE; | |
233 | } | |
234 | ||
e3582f7f JS |
235 | void wxSpinCtrl::OnChar(wxKeyEvent& event) |
236 | { | |
77e00fe9 | 237 | switch ( event.GetKeyCode() ) |
e3582f7f JS |
238 | { |
239 | case WXK_RETURN: | |
240 | { | |
241 | wxCommandEvent event(wxEVT_COMMAND_TEXT_ENTER, m_windowId); | |
242 | InitCommandEvent(event); | |
243 | wxString val = wxGetWindowText(m_hwndBuddy); | |
244 | event.SetString(val); | |
245 | event.SetInt(GetValue()); | |
246 | if ( GetEventHandler()->ProcessEvent(event) ) | |
247 | return; | |
248 | break; | |
249 | } | |
250 | ||
251 | case WXK_TAB: | |
252 | // always produce navigation event - even if we process TAB | |
253 | // ourselves the fact that we got here means that the user code | |
254 | // decided to skip processing of this TAB - probably to let it | |
255 | // do its default job. | |
256 | { | |
257 | wxNavigationKeyEvent eventNav; | |
258 | eventNav.SetDirection(!event.ShiftDown()); | |
259 | eventNav.SetWindowChange(event.ControlDown()); | |
260 | eventNav.SetEventObject(this); | |
261 | ||
262 | if ( GetParent()->GetEventHandler()->ProcessEvent(eventNav) ) | |
263 | return; | |
264 | } | |
265 | break; | |
266 | } | |
267 | ||
268 | // no, we didn't process it | |
269 | event.Skip(); | |
270 | } | |
271 | ||
c5c04fab VZ |
272 | void wxSpinCtrl::OnSetFocus(wxFocusEvent& event) |
273 | { | |
274 | // when we get focus, give it to our buddy window as it needs it more than | |
275 | // we do | |
276 | ::SetFocus((HWND)m_hwndBuddy); | |
277 | ||
278 | event.Skip(); | |
279 | } | |
280 | ||
b782f2e0 VZ |
281 | // ---------------------------------------------------------------------------- |
282 | // construction | |
283 | // ---------------------------------------------------------------------------- | |
284 | ||
285 | bool wxSpinCtrl::Create(wxWindow *parent, | |
286 | wxWindowID id, | |
678cd6de | 287 | const wxString& value, |
b782f2e0 VZ |
288 | const wxPoint& pos, |
289 | const wxSize& size, | |
290 | long style, | |
291 | int min, int max, int initial, | |
292 | const wxString& name) | |
293 | { | |
294 | // before using DoGetBestSize(), have to set style to let the base class | |
295 | // know whether this is a horizontal or vertical control (we're always | |
296 | // vertical) | |
882a8f40 | 297 | style |= wxSP_VERTICAL; |
c76b1a30 JS |
298 | |
299 | if ( (style & wxBORDER_MASK) == wxBORDER_DEFAULT ) | |
300 | style |= wxBORDER_SUNKEN; | |
301 | ||
882a8f40 | 302 | SetWindowStyle(style); |
b782f2e0 | 303 | |
fe3d9123 JS |
304 | WXDWORD exStyle = 0; |
305 | WXDWORD msStyle = MSWGetStyle(GetWindowStyle(), & exStyle) ; | |
306 | ||
b782f2e0 VZ |
307 | // calculate the sizes: the size given is the toal size for both controls |
308 | // and we need to fit them both in the given width (height is the same) | |
309 | wxSize sizeText(size), sizeBtn(size); | |
310 | sizeBtn.x = wxSpinButton::DoGetBestSize().x; | |
baccb514 VZ |
311 | if ( sizeText.x <= 0 ) |
312 | { | |
313 | // DEFAULT_ITEM_WIDTH is the default width for the text control | |
314 | sizeText.x = DEFAULT_ITEM_WIDTH + MARGIN_BETWEEN + sizeBtn.x; | |
315 | } | |
316 | ||
b782f2e0 VZ |
317 | sizeText.x -= sizeBtn.x + MARGIN_BETWEEN; |
318 | if ( sizeText.x <= 0 ) | |
319 | { | |
320 | wxLogDebug(_T("not enough space for wxSpinCtrl!")); | |
321 | } | |
322 | ||
323 | wxPoint posBtn(pos); | |
324 | posBtn.x += sizeText.x + MARGIN_BETWEEN; | |
325 | ||
c5c04fab VZ |
326 | // we must create the text control before the spin button for the purpose |
327 | // of the dialog navigation: if there is a static text just before the spin | |
328 | // control, activating it by Alt-letter should give focus to the text | |
329 | // control, not the spin and the dialog navigation code will give focus to | |
330 | // the next control (at Windows level), not the one after it | |
b782f2e0 | 331 | |
c5c04fab | 332 | // create the text window |
b782f2e0 | 333 | |
b782f2e0 VZ |
334 | m_hwndBuddy = (WXHWND)::CreateWindowEx |
335 | ( | |
c5c04fab | 336 | exStyle, // sunken border |
baccb514 VZ |
337 | _T("EDIT"), // window class |
338 | NULL, // no window title | |
c5c04fab | 339 | msStyle, // style (will be shown later) |
baccb514 VZ |
340 | pos.x, pos.y, // position |
341 | 0, 0, // size (will be set later) | |
342 | GetHwndOf(parent), // parent | |
343 | (HMENU)-1, // control id | |
344 | wxGetInstance(), // app instance | |
345 | NULL // unused client data | |
b782f2e0 VZ |
346 | ); |
347 | ||
348 | if ( !m_hwndBuddy ) | |
349 | { | |
f6bcfd97 | 350 | wxLogLastError(wxT("CreateWindow(buddy text window)")); |
b782f2e0 VZ |
351 | |
352 | return FALSE; | |
353 | } | |
354 | ||
c5c04fab VZ |
355 | |
356 | // create the spin button | |
357 | if ( !wxSpinButton::Create(parent, id, posBtn, sizeBtn, style, name) ) | |
358 | { | |
359 | return FALSE; | |
360 | } | |
361 | ||
362 | SetRange(min, max); | |
363 | SetValue(initial); | |
364 | ||
f6bcfd97 | 365 | // subclass the text ctrl to be able to intercept some events |
6fe19057 VZ |
366 | m_wndProcBuddy = (WXFARPROC)::GetWindowLong(GetBuddyHwnd(), GWL_WNDPROC); |
367 | ::SetWindowLong(GetBuddyHwnd(), GWL_USERDATA, (LONG)this); | |
368 | ::SetWindowLong(GetBuddyHwnd(), GWL_WNDPROC, (LONG)wxBuddyTextWndProc); | |
f6bcfd97 | 369 | |
b782f2e0 | 370 | // should have the same font as the other controls |
baccb514 VZ |
371 | SetFont(GetParent()->GetFont()); |
372 | ||
373 | // set the size of the text window - can do it only now, because we | |
374 | // couldn't call DoGetBestSize() before as font wasn't set | |
375 | if ( sizeText.y <= 0 ) | |
376 | { | |
882a8f40 VZ |
377 | int cx, cy; |
378 | wxGetCharSize(GetHWND(), &cx, &cy, &GetFont()); | |
379 | ||
380 | sizeText.y = EDIT_HEIGHT_FROM_CHAR_HEIGHT(cy); | |
baccb514 VZ |
381 | } |
382 | ||
383 | DoMoveWindow(pos.x, pos.y, | |
384 | sizeText.x + sizeBtn.x + MARGIN_BETWEEN, sizeText.y); | |
385 | ||
6fe19057 | 386 | (void)::ShowWindow(GetBuddyHwnd(), SW_SHOW); |
b782f2e0 VZ |
387 | |
388 | // associate the text window with the spin button | |
baccb514 VZ |
389 | (void)::SendMessage(GetHwnd(), UDM_SETBUDDY, (WPARAM)m_hwndBuddy, 0); |
390 | ||
678cd6de VZ |
391 | if ( !value.IsEmpty() ) |
392 | { | |
393 | SetValue(value); | |
394 | } | |
395 | ||
6fe19057 VZ |
396 | // do it after finishing with m_hwndBuddy creation to avoid generating |
397 | // initial wxEVT_COMMAND_TEXT_UPDATED message | |
398 | ms_allSpins.Add(this); | |
399 | ||
baccb514 VZ |
400 | return TRUE; |
401 | } | |
402 | ||
f6bcfd97 BP |
403 | wxSpinCtrl::~wxSpinCtrl() |
404 | { | |
6fe19057 VZ |
405 | ms_allSpins.Remove(this); |
406 | ||
5648c0ad JS |
407 | // This removes spurious memory leak reporting |
408 | if (ms_allSpins.GetCount() == 0) | |
409 | ms_allSpins.Clear(); | |
410 | ||
f6bcfd97 BP |
411 | // destroy the buddy window because this pointer which wxBuddyTextWndProc |
412 | // uses will not soon be valid any more | |
6fe19057 | 413 | ::DestroyWindow(GetBuddyHwnd()); |
f6bcfd97 BP |
414 | } |
415 | ||
678cd6de VZ |
416 | // ---------------------------------------------------------------------------- |
417 | // wxTextCtrl-like methods | |
418 | // ---------------------------------------------------------------------------- | |
419 | ||
420 | void wxSpinCtrl::SetValue(const wxString& text) | |
421 | { | |
6fe19057 | 422 | if ( !::SetWindowText(GetBuddyHwnd(), text.c_str()) ) |
678cd6de | 423 | { |
f6bcfd97 | 424 | wxLogLastError(wxT("SetWindowText(buddy)")); |
678cd6de VZ |
425 | } |
426 | } | |
427 | ||
428 | int wxSpinCtrl::GetValue() const | |
429 | { | |
430 | wxString val = wxGetWindowText(m_hwndBuddy); | |
431 | ||
432 | long n; | |
433 | if ( (wxSscanf(val, wxT("%lu"), &n) != 1) ) | |
434 | n = INT_MIN; | |
435 | ||
436 | return n; | |
437 | } | |
438 | ||
07901ec9 VZ |
439 | void wxSpinCtrl::SetSelection(long from, long to) |
440 | { | |
441 | // if from and to are both -1, it means (in wxWindows) that all text should | |
442 | // be selected - translate into Windows convention | |
443 | if ( (from == -1) && (to == -1) ) | |
444 | { | |
445 | from = 0; | |
446 | } | |
447 | ||
448 | ::SendMessage((HWND)m_hwndBuddy, EM_SETSEL, (WPARAM)from, (LPARAM)to); | |
449 | } | |
450 | ||
baccb514 | 451 | // ---------------------------------------------------------------------------- |
882a8f40 | 452 | // forward some methods to subcontrols |
baccb514 VZ |
453 | // ---------------------------------------------------------------------------- |
454 | ||
455 | bool wxSpinCtrl::SetFont(const wxFont& font) | |
456 | { | |
457 | if ( !wxWindowBase::SetFont(font) ) | |
458 | { | |
459 | // nothing to do | |
460 | return FALSE; | |
461 | } | |
462 | ||
463 | WXHANDLE hFont = GetFont().GetResourceHandle(); | |
6fe19057 | 464 | (void)::SendMessage(GetBuddyHwnd(), WM_SETFONT, (WPARAM)hFont, TRUE); |
b782f2e0 VZ |
465 | |
466 | return TRUE; | |
467 | } | |
468 | ||
882a8f40 VZ |
469 | bool wxSpinCtrl::Show(bool show) |
470 | { | |
471 | if ( !wxControl::Show(show) ) | |
472 | { | |
473 | return FALSE; | |
474 | } | |
475 | ||
6fe19057 | 476 | ::ShowWindow(GetBuddyHwnd(), show ? SW_SHOW : SW_HIDE); |
882a8f40 VZ |
477 | |
478 | return TRUE; | |
479 | } | |
480 | ||
481 | bool wxSpinCtrl::Enable(bool enable) | |
482 | { | |
483 | if ( !wxControl::Enable(enable) ) | |
484 | { | |
485 | return FALSE; | |
486 | } | |
487 | ||
6fe19057 | 488 | ::EnableWindow(GetBuddyHwnd(), enable); |
882a8f40 VZ |
489 | |
490 | return TRUE; | |
491 | } | |
492 | ||
8bf3196d GRG |
493 | void wxSpinCtrl::SetFocus() |
494 | { | |
6fe19057 | 495 | ::SetFocus(GetBuddyHwnd()); |
8bf3196d GRG |
496 | } |
497 | ||
9750fc42 VZ |
498 | // ---------------------------------------------------------------------------- |
499 | // event processing | |
500 | // ---------------------------------------------------------------------------- | |
501 | ||
502 | void wxSpinCtrl::OnSpinChange(wxSpinEvent& eventSpin) | |
503 | { | |
504 | wxCommandEvent event(wxEVT_COMMAND_SPINCTRL_UPDATED, GetId()); | |
505 | event.SetEventObject(this); | |
506 | event.SetInt(eventSpin.GetPosition()); | |
507 | ||
508 | (void)GetEventHandler()->ProcessEvent(event); | |
509 | ||
510 | if ( eventSpin.GetSkipped() ) | |
511 | { | |
512 | event.Skip(); | |
513 | } | |
514 | } | |
515 | ||
b782f2e0 VZ |
516 | // ---------------------------------------------------------------------------- |
517 | // size calculations | |
518 | // ---------------------------------------------------------------------------- | |
519 | ||
f68586e5 | 520 | wxSize wxSpinCtrl::DoGetBestSize() const |
baccb514 VZ |
521 | { |
522 | wxSize sizeBtn = wxSpinButton::DoGetBestSize(); | |
523 | sizeBtn.x += DEFAULT_ITEM_WIDTH + MARGIN_BETWEEN; | |
524 | ||
525 | int y; | |
526 | wxGetCharSize(GetHWND(), NULL, &y, &GetFont()); | |
527 | y = EDIT_HEIGHT_FROM_CHAR_HEIGHT(y); | |
528 | ||
529 | if ( sizeBtn.y < y ) | |
530 | { | |
531 | // make the text tall enough | |
532 | sizeBtn.y = y; | |
533 | } | |
534 | ||
535 | return sizeBtn; | |
536 | } | |
537 | ||
b782f2e0 VZ |
538 | void wxSpinCtrl::DoMoveWindow(int x, int y, int width, int height) |
539 | { | |
baccb514 | 540 | int widthBtn = wxSpinButton::DoGetBestSize().x; |
b782f2e0 VZ |
541 | int widthText = width - widthBtn - MARGIN_BETWEEN; |
542 | if ( widthText <= 0 ) | |
543 | { | |
544 | wxLogDebug(_T("not enough space for wxSpinCtrl!")); | |
545 | } | |
546 | ||
6fe19057 | 547 | if ( !::MoveWindow(GetBuddyHwnd(), x, y, widthText, height, TRUE) ) |
b782f2e0 | 548 | { |
f6bcfd97 | 549 | wxLogLastError(wxT("MoveWindow(buddy)")); |
b782f2e0 VZ |
550 | } |
551 | ||
552 | x += widthText + MARGIN_BETWEEN; | |
553 | if ( !::MoveWindow(GetHwnd(), x, y, widthBtn, height, TRUE) ) | |
554 | { | |
f6bcfd97 | 555 | wxLogLastError(wxT("MoveWindow")); |
b782f2e0 VZ |
556 | } |
557 | } | |
558 | ||
f6bcfd97 BP |
559 | // get total size of the control |
560 | void wxSpinCtrl::DoGetSize(int *x, int *y) const | |
561 | { | |
562 | RECT spinrect, textrect, ctrlrect; | |
563 | GetWindowRect(GetHwnd(), &spinrect); | |
6fe19057 | 564 | GetWindowRect(GetBuddyHwnd(), &textrect); |
f6bcfd97 BP |
565 | UnionRect(&ctrlrect,&textrect, &spinrect); |
566 | ||
567 | if ( x ) | |
568 | *x = ctrlrect.right - ctrlrect.left; | |
569 | if ( y ) | |
570 | *y = ctrlrect.bottom - ctrlrect.top; | |
571 | } | |
572 | ||
573 | void wxSpinCtrl::DoGetPosition(int *x, int *y) const | |
574 | { | |
575 | // hack: pretend that our HWND is the text control just for a moment | |
576 | WXHWND hWnd = GetHWND(); | |
577 | wxConstCast(this, wxSpinCtrl)->m_hWnd = m_hwndBuddy; | |
578 | ||
579 | wxSpinButton::DoGetPosition(x, y); | |
580 | ||
581 | wxConstCast(this, wxSpinCtrl)->m_hWnd = hWnd; | |
582 | } | |
583 | ||
b782f2e0 | 584 | #endif // __WIN95__ |
0e528b99 JS |
585 | |
586 | #endif | |
587 | // wxUSE_SPINCTRL | |
588 |