]>
git.saurik.com Git - wxWidgets.git/blob - src/msw/spinbutt.cpp
b5f99d385346f1d55386521f43a546fc9dc0a02c
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/msw/spinbutt.cpp
3 // Purpose: wxSpinButton
4 // Author: Julian Smart
7 // Copyright: (c) Julian Smart
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 // ============================================================================
13 // ============================================================================
15 // ----------------------------------------------------------------------------
17 // ----------------------------------------------------------------------------
19 // For compilers that support precompilation, includes "wx.h".
20 #include "wx/wxprec.h"
27 #include "wx/msw/wrapcctl.h" // include <commctrl.h> "properly"
33 #include "wx/spinbutt.h"
35 #include "wx/msw/private.h"
37 #ifndef UDM_SETRANGE32
38 #define UDM_SETRANGE32 (WM_USER+111)
42 #define UDM_SETPOS32 (WM_USER+113)
43 #define UDM_GETPOS32 (WM_USER+114)
46 // ============================================================================
48 // ============================================================================
50 // ----------------------------------------------------------------------------
52 // ----------------------------------------------------------------------------
54 // ----------------------------------------------------------------------------
56 // ----------------------------------------------------------------------------
58 bool wxSpinButton::Create(wxWindow
*parent
,
65 // basic initialization
66 m_windowId
= (id
== wxID_ANY
) ? NewControlId() : id
;
75 m_windowStyle
= style
;
79 // get the right size for the control
80 if ( width
<= 0 || height
<= 0 )
82 wxSize size
= DoGetBestSize();
94 // translate the styles
95 DWORD wstyle
= WS_VISIBLE
| WS_CHILD
| WS_TABSTOP
| /* WS_CLIPSIBLINGS | */
96 UDS_NOTHOUSANDS
| // never useful, sometimes harmful
97 UDS_SETBUDDYINT
; // it doesn't harm if we don't have buddy
99 if ( m_windowStyle
& wxCLIP_SIBLINGS
)
100 wstyle
|= WS_CLIPSIBLINGS
;
101 if ( m_windowStyle
& wxSP_HORIZONTAL
)
103 if ( m_windowStyle
& wxSP_ARROW_KEYS
)
104 wstyle
|= UDS_ARROWKEYS
;
105 if ( m_windowStyle
& wxSP_WRAP
)
108 // create the UpDown control.
109 m_hWnd
= (WXHWND
)CreateUpDownControl
118 m_min
// initial position
123 wxLogLastError(wxT("CreateUpDownControl"));
130 parent
->AddChild(this);
135 SetInitialSize(size
);
140 wxSpinButton::~wxSpinButton()
144 // ----------------------------------------------------------------------------
146 // ----------------------------------------------------------------------------
148 wxSize
wxSpinButton::DoGetBestSize() const
150 return GetBestSpinnerSize( (GetWindowStyle() & wxSP_VERTICAL
) != 0 );
153 // ----------------------------------------------------------------------------
155 // ----------------------------------------------------------------------------
157 int wxSpinButton::GetValue() const
161 if ( wxApp::GetComCtl32Version() >= 580 )
163 // use the full 32 bit range if available
164 n
= ::SendMessage(GetHwnd(), UDM_GETPOS32
, 0, 0);
167 #endif // UDM_GETPOS32
169 // we're limited to 16 bit
170 n
= (short)LOWORD(::SendMessage(GetHwnd(), UDM_GETPOS
, 0, 0));
173 if (n
< m_min
) n
= m_min
;
174 if (n
> m_max
) n
= m_max
;
179 void wxSpinButton::SetValue(int val
)
181 // wxSpinButtonBase::SetValue(val); -- no, it is pure virtual
184 if ( wxApp::GetComCtl32Version() >= 580 )
186 // use the full 32 bit range if available
187 ::SendMessage(GetHwnd(), UDM_SETPOS32
, 0, val
);
189 else // we're limited to 16 bit
190 #endif // UDM_SETPOS32
192 ::SendMessage(GetHwnd(), UDM_SETPOS
, 0, MAKELONG((short) val
, 0));
196 void wxSpinButton::NormalizeValue()
198 SetValue( GetValue() );
201 void wxSpinButton::SetRange(int minVal
, int maxVal
)
203 const bool hadRange
= m_min
< m_max
;
205 wxSpinButtonBase::SetRange(minVal
, maxVal
);
207 #ifdef UDM_SETRANGE32
208 if ( wxApp::GetComCtl32Version() >= 471 )
210 // use the full 32 bit range if available
211 ::SendMessage(GetHwnd(), UDM_SETRANGE32
, minVal
, maxVal
);
213 else // we're limited to 16 bit
214 #endif // UDM_SETRANGE32
216 ::SendMessage(GetHwnd(), UDM_SETRANGE
, 0,
217 (LPARAM
) MAKELONG((short)maxVal
, (short)minVal
));
220 // the current value might be out of the new range, force it to be in it
223 // if range was valid but becomes degenerated (min == max) now or vice
224 // versa then the spin buttons are automatically disabled/enabled back
225 // but don't update themselves for some reason, so do it manually
226 if ( hadRange
!= (m_min
< m_max
) )
228 // update the visual state of the button
233 bool wxSpinButton::MSWOnScroll(int WXUNUSED(orientation
), WXWORD wParam
,
234 WXWORD
WXUNUSED(pos
), WXHWND control
)
236 wxCHECK_MSG( control
, false, wxT("scrolling what?") );
238 if ( wParam
!= SB_THUMBPOSITION
)
240 // probable SB_ENDSCROLL - we don't react to it
244 wxSpinEvent
event(wxEVT_SCROLL_THUMBTRACK
, m_windowId
);
245 // We can't use 16 bit position provided in this message for spin buttons
246 // using 32 bit range.
247 event
.SetPosition(GetValue());
248 event
.SetEventObject(this);
250 return HandleWindowEvent(event
);
253 bool wxSpinButton::MSWOnNotify(int WXUNUSED(idCtrl
), WXLPARAM lParam
, WXLPARAM
*result
)
255 NM_UPDOWN
*lpnmud
= (NM_UPDOWN
*)lParam
;
257 if (lpnmud
->hdr
.hwndFrom
!= GetHwnd()) // make sure it is the right control
260 wxSpinEvent
event(lpnmud
->iDelta
> 0 ? wxEVT_SCROLL_LINEUP
261 : wxEVT_SCROLL_LINEDOWN
,
263 event
.SetPosition(lpnmud
->iPos
+ lpnmud
->iDelta
);
264 event
.SetEventObject(this);
266 bool processed
= HandleWindowEvent(event
);
268 *result
= event
.IsAllowed() ? 0 : 1;
273 bool wxSpinButton::MSWCommand(WXUINT
WXUNUSED(cmd
), WXWORD
WXUNUSED(id
))
275 // No command messages
279 #endif // wxUSE_SPINBTN