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 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
)
139 wxSpinEvent
event(wxEVT_NULL
, m_windowId
);
140 event
.SetPosition(pos
);
141 event
.SetOrientation(orientation
);
142 event
.SetEventObject(this);
147 event
.m_eventType
= wxEVT_SCROLL_TOP
;
151 event
.m_eventType
= wxEVT_SCROLL_BOTTOM
;
155 event
.m_eventType
= wxEVT_SCROLL_LINEUP
;
159 event
.m_eventType
= wxEVT_SCROLL_LINEDOWN
;
163 event
.m_eventType
= wxEVT_SCROLL_PAGEUP
;
167 event
.m_eventType
= wxEVT_SCROLL_PAGEDOWN
;
171 case SB_THUMBPOSITION
:
172 event
.m_eventType
= wxEVT_SCROLL_THUMBTRACK
;
179 return GetEventHandler()->ProcessEvent(event
);
182 bool wxSpinButton::MSWCommand(WXUINT cmd
, WXWORD id
)
184 // No command messages