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