]>
git.saurik.com Git - wxWidgets.git/blob - src/msw/spinbutt.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/msw/spinbutt.cpp
3 // Purpose: wxSpinButton
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
28 #include "wx/msw/wrapcctl.h" // include <commctrl.h> "properly"
34 #include "wx/spinbutt.h"
36 #include "wx/msw/private.h"
38 #ifndef UDM_SETRANGE32
39 #define UDM_SETRANGE32 (WM_USER+111)
43 #define UDM_SETPOS32 (WM_USER+113)
44 #define UDM_GETPOS32 (WM_USER+114)
47 // ============================================================================
49 // ============================================================================
51 // ----------------------------------------------------------------------------
53 // ----------------------------------------------------------------------------
55 // ----------------------------------------------------------------------------
57 // ----------------------------------------------------------------------------
59 bool wxSpinButton::Create(wxWindow
*parent
,
66 // basic initialization
67 m_windowId
= (id
== wxID_ANY
) ? NewControlId() : id
;
76 m_windowStyle
= style
;
80 // get the right size for the control
81 if ( width
<= 0 || height
<= 0 )
83 wxSize size
= DoGetBestSize();
95 // translate the styles
96 DWORD wstyle
= WS_VISIBLE
| WS_CHILD
| WS_TABSTOP
| /* WS_CLIPSIBLINGS | */
97 UDS_NOTHOUSANDS
| // never useful, sometimes harmful
98 UDS_SETBUDDYINT
; // it doesn't harm if we don't have buddy
100 if ( m_windowStyle
& wxCLIP_SIBLINGS
)
101 wstyle
|= WS_CLIPSIBLINGS
;
102 if ( m_windowStyle
& wxSP_HORIZONTAL
)
104 if ( m_windowStyle
& wxSP_ARROW_KEYS
)
105 wstyle
|= UDS_ARROWKEYS
;
106 if ( m_windowStyle
& wxSP_WRAP
)
109 // create the UpDown control.
110 m_hWnd
= (WXHWND
)CreateUpDownControl
119 m_min
// initial position
124 wxLogLastError(wxT("CreateUpDownControl"));
131 parent
->AddChild(this);
136 SetInitialSize(size
);
141 wxSpinButton::~wxSpinButton()
145 // ----------------------------------------------------------------------------
147 // ----------------------------------------------------------------------------
149 wxSize
wxSpinButton::DoGetBestSize() const
151 return GetBestSpinnerSize( (GetWindowStyle() & wxSP_VERTICAL
) != 0 );
154 // ----------------------------------------------------------------------------
156 // ----------------------------------------------------------------------------
158 int wxSpinButton::GetValue() const
162 if ( wxApp::GetComCtl32Version() >= 580 )
164 // use the full 32 bit range if available
165 n
= ::SendMessage(GetHwnd(), UDM_GETPOS32
, 0, 0);
168 #endif // UDM_GETPOS32
170 // we're limited to 16 bit
171 n
= (short)LOWORD(::SendMessage(GetHwnd(), UDM_GETPOS
, 0, 0));
174 if (n
< m_min
) n
= m_min
;
175 if (n
> m_max
) n
= m_max
;
180 void wxSpinButton::SetValue(int val
)
182 // wxSpinButtonBase::SetValue(val); -- no, it is pure virtual
185 if ( wxApp::GetComCtl32Version() >= 580 )
187 // use the full 32 bit range if available
188 ::SendMessage(GetHwnd(), UDM_SETPOS32
, 0, val
);
190 else // we're limited to 16 bit
191 #endif // UDM_SETPOS32
193 ::SendMessage(GetHwnd(), UDM_SETPOS
, 0, MAKELONG((short) val
, 0));
197 void wxSpinButton::NormalizeValue()
199 SetValue( GetValue() );
202 void wxSpinButton::SetRange(int minVal
, int maxVal
)
204 const bool hadRange
= m_min
< m_max
;
206 wxSpinButtonBase::SetRange(minVal
, maxVal
);
208 #ifdef UDM_SETRANGE32
209 if ( wxApp::GetComCtl32Version() >= 471 )
211 // use the full 32 bit range if available
212 ::SendMessage(GetHwnd(), UDM_SETRANGE32
, minVal
, maxVal
);
214 else // we're limited to 16 bit
215 #endif // UDM_SETRANGE32
217 ::SendMessage(GetHwnd(), UDM_SETRANGE
, 0,
218 (LPARAM
) MAKELONG((short)maxVal
, (short)minVal
));
221 // the current value might be out of the new range, force it to be in it
224 // if range was valid but becomes degenerated (min == max) now or vice
225 // versa then the spin buttons are automatically disabled/enabled back
226 // but don't update themselves for some reason, so do it manually
227 if ( hadRange
!= (m_min
< m_max
) )
229 // update the visual state of the button
234 bool wxSpinButton::MSWOnScroll(int WXUNUSED(orientation
), WXWORD wParam
,
235 WXWORD
WXUNUSED(pos
), WXHWND control
)
237 wxCHECK_MSG( control
, false, wxT("scrolling what?") );
239 if ( wParam
!= SB_THUMBPOSITION
)
241 // probable SB_ENDSCROLL - we don't react to it
245 wxSpinEvent
event(wxEVT_SCROLL_THUMBTRACK
, m_windowId
);
246 // We can't use 16 bit position provided in this message for spin buttons
247 // using 32 bit range.
248 event
.SetPosition(GetValue());
249 event
.SetEventObject(this);
251 return HandleWindowEvent(event
);
254 bool wxSpinButton::MSWOnNotify(int WXUNUSED(idCtrl
), WXLPARAM lParam
, WXLPARAM
*result
)
256 NM_UPDOWN
*lpnmud
= (NM_UPDOWN
*)lParam
;
258 if (lpnmud
->hdr
.hwndFrom
!= GetHwnd()) // make sure it is the right control
261 wxSpinEvent
event(lpnmud
->iDelta
> 0 ? wxEVT_SCROLL_LINEUP
262 : wxEVT_SCROLL_LINEDOWN
,
264 event
.SetPosition(lpnmud
->iPos
+ lpnmud
->iDelta
);
265 event
.SetEventObject(this);
267 bool processed
= HandleWindowEvent(event
);
269 *result
= event
.IsAllowed() ? 0 : 1;
274 bool wxSpinButton::MSWCommand(WXUINT
WXUNUSED(cmd
), WXWORD
WXUNUSED(id
))
276 // No command messages
280 #endif // wxUSE_SPINBTN