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