]>
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"
22 #pragma implementation "spinbutbase.h"
25 // For compilers that support precompilation, includes "wx.h".
26 #include "wx/wxprec.h"
36 // Can't resolve reference to CreateUpDownControl in
37 // TWIN32, but could probably use normal CreateWindow instead.
41 #include "wx/spinbutt.h"
43 IMPLEMENT_DYNAMIC_CLASS(wxSpinEvent
, wxNotifyEvent
)
45 #if defined(__WIN95__) && !defined(__TWIN32__)
47 #include "wx/msw/private.h"
49 #if defined(__WIN95__) && !(defined(__GNUWIN32_OLD__) || defined(__TWIN32__))
53 // ============================================================================
55 // ============================================================================
57 // ----------------------------------------------------------------------------
59 // ----------------------------------------------------------------------------
61 IMPLEMENT_DYNAMIC_CLASS(wxSpinButton
, wxControl
)
63 // ----------------------------------------------------------------------------
65 // ----------------------------------------------------------------------------
67 bool wxSpinButton::Create(wxWindow
*parent
,
74 // basic initialization
77 m_windowId
= (id
== -1) ? NewControlId() : id
;
79 m_backgroundColour
= parent
->GetBackgroundColour() ;
80 m_foregroundColour
= parent
->GetForegroundColour() ;
89 m_windowStyle
= style
;
93 // get the right size for the control
94 if ( width
<= 0 || height
<= 0 )
96 wxSize size
= DoGetBestSize();
108 // translate the styles
109 DWORD wstyle
= WS_VISIBLE
| WS_CHILD
| WS_TABSTOP
| /* WS_CLIPSIBLINGS | */
110 UDS_NOTHOUSANDS
| // never useful, sometimes harmful
111 UDS_SETBUDDYINT
; // it doesn't harm if we don't have buddy
113 if ( m_windowStyle
& wxCLIP_SIBLINGS
)
114 wstyle
|= WS_CLIPSIBLINGS
;
115 if ( m_windowStyle
& wxSP_HORIZONTAL
)
117 if ( m_windowStyle
& wxSP_ARROW_KEYS
)
118 wstyle
|= UDS_ARROWKEYS
;
119 if ( m_windowStyle
& wxSP_WRAP
)
122 // create the UpDown control.
123 m_hWnd
= (WXHWND
)CreateUpDownControl
132 m_min
// initial position
137 wxLogLastError(wxT("CreateUpDownControl"));
144 parent
->AddChild(this);
152 wxSpinButton::~wxSpinButton()
156 // ----------------------------------------------------------------------------
158 // ----------------------------------------------------------------------------
160 wxSize
wxSpinButton::DoGetBestSize() const
162 if ( (GetWindowStyle() & wxSP_VERTICAL
) != 0 )
165 return wxSize(GetSystemMetrics(SM_CXVSCROLL
),
166 2*GetSystemMetrics(SM_CYVSCROLL
));
170 // horizontal control
171 return wxSize(2*GetSystemMetrics(SM_CXHSCROLL
),
172 GetSystemMetrics(SM_CYHSCROLL
));
176 // ----------------------------------------------------------------------------
178 // ----------------------------------------------------------------------------
180 int wxSpinButton::GetValue() const
182 return (short)LOWORD(::SendMessage(GetHwnd(), UDM_GETPOS
, 0, 0));
185 void wxSpinButton::SetValue(int val
)
187 ::SendMessage(GetHwnd(), UDM_SETPOS
, 0, (LPARAM
) MAKELONG((short) val
, 0));
190 void wxSpinButton::SetRange(int minVal
, int maxVal
)
192 wxSpinButtonBase::SetRange(minVal
, maxVal
);
193 ::SendMessage(GetHwnd(), UDM_SETRANGE
, 0,
194 (LPARAM
) MAKELONG((short)maxVal
, (short)minVal
));
197 bool wxSpinButton::MSWOnScroll(int WXUNUSED(orientation
), WXWORD wParam
,
198 WXWORD pos
, WXHWND control
)
200 wxCHECK_MSG( control
, FALSE
, wxT("scrolling what?") )
202 if ( wParam
!= SB_THUMBPOSITION
)
204 // probable SB_ENDSCROLL - we don't react to it
208 wxSpinEvent
event(wxEVT_SCROLL_THUMBTRACK
, m_windowId
);
209 event
.SetPosition((short)pos
); // cast is important for negative values!
210 event
.SetEventObject(this);
212 return GetEventHandler()->ProcessEvent(event
);
215 bool wxSpinButton::MSWOnNotify(int WXUNUSED(idCtrl
), WXLPARAM lParam
, WXLPARAM
*result
)
218 #if defined(__BORLANDC__) || defined(__WATCOMC__)
219 LPNM_UPDOWN lpnmud
= (LPNM_UPDOWN
)lParam
;
220 #elif defined(__VISUALC__) && (__VISUALC__ >= 1000) && (__VISUALC__ < 1020)
221 LPNM_UPDOWN lpnmud
= (LPNM_UPDOWN
)lParam
;
223 LPNMUPDOWN lpnmud
= (LPNMUPDOWN
)lParam
;
226 if (lpnmud
->hdr
.hwndFrom
!= GetHwnd()) // make sure it is the right control
229 wxSpinEvent
event(lpnmud
->iDelta
> 0 ? wxEVT_SCROLL_LINEUP
230 : wxEVT_SCROLL_LINEDOWN
,
232 event
.SetPosition(lpnmud
->iPos
+ lpnmud
->iDelta
);
233 event
.SetEventObject(this);
235 bool processed
= GetEventHandler()->ProcessEvent(event
);
237 *result
= event
.IsAllowed() ? 0 : 1;
245 bool wxSpinButton::MSWCommand(WXUINT
WXUNUSED(cmd
), WXWORD
WXUNUSED(id
))
247 // No command messages