]>
git.saurik.com Git - wxWidgets.git/blob - src/msw/spinbutt.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxSpinButton
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
21 #pragma implementation "spinbutt.h"
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
35 // Can't resolve reference to CreateUpDownControl in
36 // TWIN32, but could probably use normal CreateWindow instead.
40 #if defined(__WIN95__) && !defined(__TWIN32__)
42 #include "wx/spinbutt.h"
43 #include "wx/msw/private.h"
45 #if !defined(__GNUWIN32__) || defined(__TWIN32__) || defined(wxUSE_NORLANDER_HEADERS)
49 // ============================================================================
51 // ============================================================================
53 // ----------------------------------------------------------------------------
55 // ----------------------------------------------------------------------------
57 #if !USE_SHARED_LIBRARY
58 IMPLEMENT_DYNAMIC_CLASS(wxSpinButton
, wxControl
)
59 IMPLEMENT_DYNAMIC_CLASS(wxSpinEvent
, wxScrollEvent
);
62 // ----------------------------------------------------------------------------
64 // ----------------------------------------------------------------------------
66 bool wxSpinButton::Create(wxWindow
*parent
,
73 // basic initialization
76 m_windowId
= (id
== -1) ? NewControlId() : id
;
78 m_backgroundColour
= parent
->GetBackgroundColour() ;
79 m_foregroundColour
= parent
->GetForegroundColour() ;
88 m_windowStyle
= style
;
92 // get the right size for the control
93 if ( width
<= 0 || height
<= 0 )
95 wxSize size
= DoGetBestSize();
107 // translate the styles
108 DWORD wstyle
= WS_VISIBLE
| WS_CHILD
| WS_TABSTOP
|
109 UDS_SETBUDDYINT
; // it doesn't harm if we don't have buddy
111 if ( m_windowStyle
& wxSP_HORIZONTAL
)
113 if ( m_windowStyle
& wxSP_ARROW_KEYS
)
114 wstyle
|= UDS_ARROWKEYS
;
115 if ( m_windowStyle
& wxSP_WRAP
)
118 // create the UpDown control.
119 m_hWnd
= (WXHWND
)CreateUpDownControl
128 m_min
// initial position
133 wxLogLastError("CreateUpDownControl");
140 parent
->AddChild(this);
148 wxSpinButton::~wxSpinButton()
152 // ----------------------------------------------------------------------------
154 // ----------------------------------------------------------------------------
156 wxSize
wxSpinButton::DoGetBestSize() const
158 if ( (GetWindowStyle() & wxSP_VERTICAL
) != 0 )
161 return wxSize(GetSystemMetrics(SM_CXVSCROLL
),
162 2*GetSystemMetrics(SM_CYVSCROLL
));
166 // horizontal control
167 return wxSize(2*GetSystemMetrics(SM_CXHSCROLL
),
168 GetSystemMetrics(SM_CYHSCROLL
));
172 // ----------------------------------------------------------------------------
174 // ----------------------------------------------------------------------------
176 int wxSpinButton::GetValue() const
178 return (short)LOWORD(::SendMessage(GetHwnd(), UDM_GETPOS
, 0, 0));
181 void wxSpinButton::SetValue(int val
)
183 ::SendMessage(GetHwnd(), UDM_SETPOS
, 0, (LPARAM
) MAKELONG((short) val
, 0));
186 void wxSpinButton::SetRange(int minVal
, int maxVal
)
188 wxSpinButtonBase::SetRange(minVal
, maxVal
);
189 ::SendMessage(GetHwnd(), UDM_SETRANGE
, 0,
190 (LPARAM
) MAKELONG((short)maxVal
, (short)minVal
));
193 bool wxSpinButton::MSWOnScroll(int orientation
, WXWORD wParam
,
194 WXWORD pos
, WXHWND control
)
196 wxCHECK_MSG( control
, FALSE
, wxT("scrolling what?") )
198 if ( wParam
!= SB_THUMBPOSITION
)
200 // probable SB_ENDSCROLL - we don't react to it
204 wxSpinEvent
event(wxEVT_SCROLL_THUMBTRACK
, m_windowId
);
205 event
.SetPosition((short)pos
); // cast is important for negative values!
206 event
.SetEventObject(this);
208 return GetEventHandler()->ProcessEvent(event
);
211 bool wxSpinButton::MSWOnNotify(int idCtrl
, WXLPARAM lParam
, WXLPARAM
*result
)
214 #if defined(__BORLANDC__) || defined(__WATCOMC__)
215 LPNM_UPDOWN lpnmud
= (LPNM_UPDOWN
)lParam
;
216 #elif defined(__VISUALC__) && (__VISUALC__ >= 1000) && (__VISUALC__ < 1020)
217 LPNM_UPDOWN lpnmud
= (LPNM_UPDOWN
)lParam
;
219 LPNMUPDOWN lpnmud
= (LPNMUPDOWN
)lParam
;
222 wxSpinEvent
event(lpnmud
->iDelta
> 0 ? wxEVT_SCROLL_LINEUP
223 : wxEVT_SCROLL_LINEDOWN
,
225 event
.SetPosition(lpnmud
->iPos
+ lpnmud
->iDelta
);
226 event
.SetEventObject(this);
228 bool processed
= GetEventHandler()->ProcessEvent(event
);
230 *result
= event
.IsAllowed() ? 0 : 1;
238 bool wxSpinButton::MSWCommand(WXUINT cmd
, WXWORD id
)
240 // No command messages