1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxSpinButton
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "spinbutt.h"
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
27 // Can't resolve reference to CreateUpDownControl in
28 // TWIN32, but could probably use normal CreateWindow instead.
30 #if defined(__WIN95__) && !defined(__TWIN32__)
32 #include "wx/spinbutt.h"
33 #include "wx/msw/private.h"
35 #if !defined(__GNUWIN32__) || defined(__TWIN32__)
39 #if !USE_SHARED_LIBRARY
40 IMPLEMENT_DYNAMIC_CLASS(wxSpinButton
, wxControl
)
41 IMPLEMENT_DYNAMIC_CLASS(wxSpinEvent
, wxScrollEvent
);
44 bool wxSpinButton::Create(wxWindow
*parent
,
51 wxSystemSettings settings
;
52 m_backgroundColour
= parent
->GetBackgroundColour() ;
53 m_foregroundColour
= parent
->GetForegroundColour() ;
62 m_windowStyle
= style
;
77 m_windowId
= (id
== -1) ? NewControlId() : id
;
79 DWORD wstyle
= WS_VISIBLE
| WS_CHILD
| WS_TABSTOP
;
81 if ( m_windowStyle
& wxSP_HORIZONTAL
)
83 if ( m_windowStyle
& wxSP_ARROW_KEYS
)
84 wstyle
|= UDS_ARROWKEYS
;
85 if ( m_windowStyle
& wxSP_WRAP
)
88 // Create the ListView control.
89 HWND hWndListControl
= CreateUpDownControl(wstyle
,
91 (HWND
) parent
->GetHWND(),
97 m_hWnd
= (WXHWND
) hWndListControl
;
98 if (parent
) parent
->AddChild(this);
100 // TODO: have this for all controls.
104 SubclassWin((WXHWND
) m_hWnd
);
109 wxSpinButton::~wxSpinButton()
114 ////////////////////////////////////////////////////////////////////////////
116 int wxSpinButton::GetValue() const
118 return (short)LOWORD(::SendMessage(GetHwnd(), UDM_GETPOS
, 0, 0));
121 void wxSpinButton::SetValue(int val
)
123 ::SendMessage(GetHwnd(), UDM_SETPOS
, 0, (LPARAM
) MAKELONG((short) val
, 0));
126 void wxSpinButton::SetRange(int minVal
, int maxVal
)
128 wxSpinButtonBase::SetRange(minVal
, maxVal
);
129 ::SendMessage(GetHwnd(), UDM_SETRANGE
, 0,
130 (LPARAM
) MAKELONG((short)maxVal
, (short)minVal
));
133 bool wxSpinButton::MSWOnScroll(int orientation
, WXWORD wParam
,
134 WXWORD pos
, WXHWND control
)
136 wxCHECK_MSG( control
, FALSE
, _T("scrolling what?") )
138 if ( wParam
!= SB_THUMBPOSITION
)
140 // probable SB_ENDSCROLL - we don't react to it
144 wxSpinEvent
event(wxEVT_SCROLL_THUMBTRACK
, m_windowId
);
145 event
.SetPosition((short)pos
); // cast is important for negative values!
146 event
.SetEventObject(this);
148 return GetEventHandler()->ProcessEvent(event
);
151 bool wxSpinButton::MSWOnNotify(int idCtrl
, WXLPARAM lParam
, WXLPARAM
*result
)
154 LPNMUPDOWN lpnmud
= (LPNMUPDOWN
)lParam
;
156 wxSpinEvent
event(lpnmud
->iDelta
> 0 ? wxEVT_SCROLL_LINEUP
157 : wxEVT_SCROLL_LINEDOWN
,
159 event
.SetPosition(lpnmud
->iPos
+ lpnmud
->iDelta
);
160 event
.SetEventObject(this);
162 bool processed
= GetEventHandler()->ProcessEvent(event
);
164 *result
= event
.IsAllowed() ? 0 : 1;
172 bool wxSpinButton::MSWCommand(WXUINT cmd
, WXWORD id
)
174 // No command messages