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