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
, wxWindowID id
, const wxPoint
& pos
, const wxSize
& size
,
47 long style
, const wxString
& name
)
49 wxSystemSettings settings
;
50 m_backgroundColour
= parent
->GetBackgroundColour() ;
51 m_foregroundColour
= parent
->GetForegroundColour() ;
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(int val
)
122 ::SendMessage((HWND
) GetHWND(), UDM_SETPOS
, 0, (LPARAM
) MAKELONG((short) val
, 0));
125 void wxSpinButton::SetRange(int minVal
, int maxVal
)
129 ::SendMessage((HWND
) GetHWND(), UDM_SETRANGE
, 0,
130 (LPARAM
) MAKELONG((short)maxVal
, (short)minVal
));
133 void wxSpinButton::MSWOnVScroll(WXWORD wParam
, WXWORD pos
, WXHWND control
)
137 wxSpinEvent
event(wxEVT_NULL
, m_windowId
);
138 event
.SetPosition(pos
);
139 event
.SetOrientation(wxVERTICAL
);
140 event
.SetEventObject( this );
145 event
.m_eventType
= wxEVT_SCROLL_TOP
;
149 event
.m_eventType
= wxEVT_SCROLL_BOTTOM
;
153 event
.m_eventType
= wxEVT_SCROLL_LINEUP
;
157 event
.m_eventType
= wxEVT_SCROLL_LINEDOWN
;
161 event
.m_eventType
= wxEVT_SCROLL_PAGEUP
;
165 event
.m_eventType
= wxEVT_SCROLL_PAGEDOWN
;
169 case SB_THUMBPOSITION
:
170 event
.m_eventType
= wxEVT_SCROLL_THUMBTRACK
;
177 if (!GetEventHandler()->ProcessEvent(event
))
182 void wxSpinButton::MSWOnHScroll( WXWORD wParam
, WXWORD pos
, WXHWND control
)
186 wxSpinEvent
event(wxEVT_NULL
, m_windowId
);
187 event
.SetPosition(pos
);
188 event
.SetOrientation(wxHORIZONTAL
);
189 event
.SetEventObject( this );
194 event
.m_eventType
= wxEVT_SCROLL_TOP
;
198 event
.m_eventType
= wxEVT_SCROLL_BOTTOM
;
202 event
.m_eventType
= wxEVT_SCROLL_LINEUP
;
206 event
.m_eventType
= wxEVT_SCROLL_LINEDOWN
;
210 event
.m_eventType
= wxEVT_SCROLL_PAGEUP
;
214 event
.m_eventType
= wxEVT_SCROLL_PAGEDOWN
;
218 case SB_THUMBPOSITION
:
219 event
.m_eventType
= wxEVT_SCROLL_THUMBTRACK
;
226 if (!GetEventHandler()->ProcessEvent(event
))
231 bool wxSpinButton::MSWCommand(WXUINT cmd
, WXWORD id
)
233 // No command messages
237 bool wxSpinButton::MSWNotify(WXWPARAM wParam
, WXLPARAM lParam
, WXLPARAM
* result
)
239 NMHDR
* hdr1
= (NMHDR
*) lParam
;
240 switch ( hdr1
->code
)
242 /* We don't process this message, currently */
246 return wxControl::MSWNotify(wParam
, lParam
, result
);
250 event.eventObject = this;
251 event.SetEventType(eventType);
253 if ( !GetEventHandler()->ProcessEvent(event) )
260 IMPLEMENT_DYNAMIC_CLASS(wxSpinEvent
, wxScrollEvent
)
262 wxSpinEvent::wxSpinEvent(wxEventType commandType
, int id
):
263 wxScrollEvent(commandType
, id
)