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(void)
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(void)
116 ////////////////////////////////////////////////////////////////////////////
118 int wxSpinButton::GetValue(void) const
120 return (int) ::SendMessage((HWND
) GetHWND(), UDM_GETPOS
, 0, 0);
123 void wxSpinButton::SetValue(int val
)
125 ::SendMessage((HWND
) GetHWND(), UDM_SETPOS
, 0, (LPARAM
) MAKELONG((short) val
, 0));
128 void wxSpinButton::SetRange(int minVal
, int maxVal
)
132 ::SendMessage((HWND
) GetHWND(), UDM_SETRANGE
, 0,
133 (LPARAM
) MAKELONG((short)maxVal
, (short)minVal
));
136 void wxSpinButton::MSWOnVScroll(WXWORD wParam
, WXWORD pos
, WXHWND control
)
140 wxSpinEvent
event(wxEVT_NULL
, m_windowId
);
141 event
.SetPosition(pos
);
142 event
.SetOrientation(wxVERTICAL
);
143 event
.SetEventObject( this );
148 event
.m_eventType
= wxEVT_SCROLL_TOP
;
152 event
.m_eventType
= wxEVT_SCROLL_BOTTOM
;
156 event
.m_eventType
= wxEVT_SCROLL_LINEUP
;
160 event
.m_eventType
= wxEVT_SCROLL_LINEDOWN
;
164 event
.m_eventType
= wxEVT_SCROLL_PAGEUP
;
168 event
.m_eventType
= wxEVT_SCROLL_PAGEDOWN
;
172 case SB_THUMBPOSITION
:
173 event
.m_eventType
= wxEVT_SCROLL_THUMBTRACK
;
180 if (!GetEventHandler()->ProcessEvent(event
))
185 void wxSpinButton::MSWOnHScroll( WXWORD wParam
, WXWORD pos
, WXHWND control
)
189 wxSpinEvent
event(wxEVT_NULL
, m_windowId
);
190 event
.SetPosition(pos
);
191 event
.SetOrientation(wxHORIZONTAL
);
192 event
.SetEventObject( this );
197 event
.m_eventType
= wxEVT_SCROLL_TOP
;
201 event
.m_eventType
= wxEVT_SCROLL_BOTTOM
;
205 event
.m_eventType
= wxEVT_SCROLL_LINEUP
;
209 event
.m_eventType
= wxEVT_SCROLL_LINEDOWN
;
213 event
.m_eventType
= wxEVT_SCROLL_PAGEUP
;
217 event
.m_eventType
= wxEVT_SCROLL_PAGEDOWN
;
221 case SB_THUMBPOSITION
:
222 event
.m_eventType
= wxEVT_SCROLL_THUMBTRACK
;
229 if (!GetEventHandler()->ProcessEvent(event
))
234 bool wxSpinButton::MSWCommand(WXUINT cmd
, WXWORD id
)
236 // No command messages
240 bool wxSpinButton::MSWNotify(WXWPARAM wParam
, WXLPARAM lParam
, WXLPARAM
* result
)
242 NMHDR
* hdr1
= (NMHDR
*) lParam
;
243 switch ( hdr1
->code
)
245 /* We don't process this message, currently */
249 return wxControl::MSWNotify(wParam
, lParam
, result
);
253 event.eventObject = this;
254 event.SetEventType(eventType);
256 if ( !GetEventHandler()->ProcessEvent(event) )
263 IMPLEMENT_DYNAMIC_CLASS(wxSpinEvent
, wxScrollEvent
)
265 wxSpinEvent::wxSpinEvent(wxEventType commandType
, int id
):
266 wxScrollEvent(commandType
, id
)