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 #if defined(__WIN95__)
29 #include "wx/spinbutt.h"
30 #include "wx/msw/private.h"
36 #if !USE_SHARED_LIBRARY
37 IMPLEMENT_DYNAMIC_CLASS(wxSpinButton
, wxControl
)
40 wxSpinButton::wxSpinButton(void)
46 bool wxSpinButton::Create(wxWindow
*parent
, const wxWindowID id
, const wxPoint
& pos
, const wxSize
& size
,
47 const long style
, const wxString
& name
)
49 wxSystemSettings settings
;
50 m_backgroundColour
= parent
->GetDefaultBackgroundColour() ;
51 m_foregroundColour
= parent
->GetDefaultForegroundColour() ;
60 m_windowStyle
= style
;
76 m_windowId
= (id
== -1) ? NewControlId() : id
;
78 DWORD wstyle
= WS_VISIBLE
| WS_CHILD
| WS_TABSTOP
;
80 if ( m_windowStyle
& wxSP_HORIZONTAL
)
82 if ( m_windowStyle
& wxSP_ARROW_KEYS
)
83 wstyle
|= UDS_ARROWKEYS
;
84 if ( m_windowStyle
& wxSP_WRAP
)
87 // Create the ListView control.
88 HWND hWndListControl
= CreateUpDownControl(wstyle
,
90 (HWND
) parent
->GetHWND(),
96 m_hWnd
= (WXHWND
) hWndListControl
;
97 if (parent
) parent
->AddChild(this);
99 // TODO: have this for all controls.
103 SubclassWin((WXHWND
) m_hWnd
);
108 wxSpinButton::~wxSpinButton(void)
113 ////////////////////////////////////////////////////////////////////////////
115 int wxSpinButton::GetValue(void) const
117 return (int) ::SendMessage((HWND
) GetHWND(), UDM_GETPOS
, 0, 0);
120 void wxSpinButton::SetValue(const int val
)
122 ::SendMessage((HWND
) GetHWND(), UDM_SETPOS
, 0, (LPARAM
) MAKELONG((short) val
, 0));
125 void wxSpinButton::SetRange(const int minVal
, const int maxVal
)
129 ::SendMessage((HWND
) GetHWND(), UDM_SETRANGE
, 0, (LPARAM
) MAKELONG((short) minVal
, (short) maxVal
));
132 void wxSpinButton::MSWOnVScroll(const WXWORD wParam
, const WXWORD pos
, const WXHWND control
)
136 wxSpinEvent
event(0, m_windowId
);
137 event
.SetPosition(pos
);
138 event
.SetOrientation(wxVERTICAL
);
139 event
.SetEventObject( this );
144 event
.m_eventType
= wxEVT_SCROLL_TOP
;
148 event
.m_eventType
= wxEVT_SCROLL_BOTTOM
;
152 event
.m_eventType
= wxEVT_SCROLL_LINEUP
;
156 event
.m_eventType
= wxEVT_SCROLL_LINEDOWN
;
160 event
.m_eventType
= wxEVT_SCROLL_PAGEUP
;
164 event
.m_eventType
= wxEVT_SCROLL_PAGEDOWN
;
168 case SB_THUMBPOSITION
:
169 event
.m_eventType
= wxEVT_SCROLL_THUMBTRACK
;
176 if (!GetEventHandler()->ProcessEvent(event
))
181 void wxSpinButton::MSWOnHScroll( const WXWORD wParam
, const WXWORD pos
, const WXHWND control
)
185 wxSpinEvent
event(0, m_windowId
);
186 event
.SetPosition(pos
);
187 event
.SetOrientation(wxHORIZONTAL
);
188 event
.SetEventObject( this );
193 event
.m_eventType
= wxEVT_SCROLL_TOP
;
197 event
.m_eventType
= wxEVT_SCROLL_BOTTOM
;
201 event
.m_eventType
= wxEVT_SCROLL_LINEUP
;
205 event
.m_eventType
= wxEVT_SCROLL_LINEDOWN
;
209 event
.m_eventType
= wxEVT_SCROLL_PAGEUP
;
213 event
.m_eventType
= wxEVT_SCROLL_PAGEDOWN
;
217 case SB_THUMBPOSITION
:
218 event
.m_eventType
= wxEVT_SCROLL_THUMBTRACK
;
225 if (!GetEventHandler()->ProcessEvent(event
))
230 bool wxSpinButton::MSWCommand(const WXUINT cmd
, const WXWORD id
)
232 // No command messages
236 bool wxSpinButton::MSWNotify(const WXWPARAM wParam
, const WXLPARAM lParam
)
238 NMHDR
* hdr1
= (NMHDR
*) lParam
;
239 switch ( hdr1
->code
)
241 /* We don't process this message, currently */
244 return wxControl::MSWNotify(wParam
, lParam
);
248 return wxControl::MSWNotify(wParam
, lParam
);
252 event.eventObject = this;
253 event.SetEventType(eventType);
255 if ( !ProcessEvent(event) )
262 IMPLEMENT_DYNAMIC_CLASS(wxSpinEvent
, wxScrollEvent
)
264 wxSpinEvent::wxSpinEvent(WXTYPE commandType
, int id
):
265 wxScrollEvent(commandType
, id
)