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
)
43 wxSpinButton::wxSpinButton()
49 bool wxSpinButton::Create(wxWindow
*parent
, wxWindowID id
, const wxPoint
& pos
, const wxSize
& size
,
50 long style
, const wxString
& name
)
52 wxSystemSettings settings
;
53 m_backgroundColour
= parent
->GetBackgroundColour() ;
54 m_foregroundColour
= parent
->GetForegroundColour() ;
63 m_windowStyle
= style
;
79 m_windowId
= (id
== -1) ? NewControlId() : id
;
81 DWORD wstyle
= WS_VISIBLE
| WS_CHILD
| WS_TABSTOP
;
83 if ( m_windowStyle
& wxSP_HORIZONTAL
)
85 if ( m_windowStyle
& wxSP_ARROW_KEYS
)
86 wstyle
|= UDS_ARROWKEYS
;
87 if ( m_windowStyle
& wxSP_WRAP
)
90 // Create the ListView control.
91 HWND hWndListControl
= CreateUpDownControl(wstyle
,
93 (HWND
) parent
->GetHWND(),
99 m_hWnd
= (WXHWND
) hWndListControl
;
100 if (parent
) parent
->AddChild(this);
102 // TODO: have this for all controls.
106 SubclassWin((WXHWND
) m_hWnd
);
111 wxSpinButton::~wxSpinButton()
116 ////////////////////////////////////////////////////////////////////////////
118 int wxSpinButton::GetValue() const
120 return LOWORD(::SendMessage(GetHwnd(), UDM_GETPOS
, 0, 0));
123 void wxSpinButton::SetValue(int val
)
125 ::SendMessage(GetHwnd(), UDM_SETPOS
, 0, (LPARAM
) MAKELONG((short) val
, 0));
128 void wxSpinButton::SetRange(int minVal
, int maxVal
)
132 ::SendMessage(GetHwnd(), UDM_SETRANGE
, 0,
133 (LPARAM
) MAKELONG((short)maxVal
, (short)minVal
));
136 bool wxSpinButton::MSWOnScroll(int orientation
, WXWORD wParam
,
137 WXWORD pos
, WXHWND control
)
142 wxSpinEvent
event(wxEVT_NULL
, m_windowId
);
143 event
.SetPosition(pos
);
144 event
.SetOrientation(orientation
);
145 event
.SetEventObject(this);
150 event
.m_eventType
= wxEVT_SCROLL_TOP
;
154 event
.m_eventType
= wxEVT_SCROLL_BOTTOM
;
158 event
.m_eventType
= wxEVT_SCROLL_LINEUP
;
162 event
.m_eventType
= wxEVT_SCROLL_LINEDOWN
;
166 event
.m_eventType
= wxEVT_SCROLL_PAGEUP
;
170 event
.m_eventType
= wxEVT_SCROLL_PAGEDOWN
;
174 case SB_THUMBPOSITION
:
175 event
.m_eventType
= wxEVT_SCROLL_THUMBTRACK
;
182 return GetEventHandler()->ProcessEvent(event
);
185 bool wxSpinButton::MSWCommand(WXUINT cmd
, WXWORD id
)
187 // No command messages
192 IMPLEMENT_DYNAMIC_CLASS(wxSpinEvent
, wxScrollEvent
)
194 wxSpinEvent::wxSpinEvent(wxEventType commandType
, int id
)
195 : wxScrollEvent(commandType
, id
)