]>
git.saurik.com Git - wxWidgets.git/blob - src/msw/spinbutt.cpp
826c4a5e1b8bf8e520cb951c38e6aac4eb2dc560
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 IMPLEMENT_DYNAMIC_CLASS(wxSpinEvent
, wxNotifyEvent
)
43 #if defined(__WIN95__) && !defined(__TWIN32__)
45 #include "wx/spinbutt.h"
46 #include "wx/msw/private.h"
48 #if defined(__WIN95__) && !(defined(__GNUWIN32_OLD__) || defined(__TWIN32__))
52 // ============================================================================
54 // ============================================================================
56 // ----------------------------------------------------------------------------
58 // ----------------------------------------------------------------------------
60 IMPLEMENT_DYNAMIC_CLASS(wxSpinButton
, wxControl
)
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_NOTHOUSANDS
| // never useful, sometimes harmful
110 UDS_SETBUDDYINT
; // it doesn't harm if we don't have buddy
112 if ( m_windowStyle
& wxSP_HORIZONTAL
)
114 if ( m_windowStyle
& wxSP_ARROW_KEYS
)
115 wstyle
|= UDS_ARROWKEYS
;
116 if ( m_windowStyle
& wxSP_WRAP
)
119 // create the UpDown control.
120 m_hWnd
= (WXHWND
)CreateUpDownControl
129 m_min
// initial position
134 wxLogLastError("CreateUpDownControl");
141 parent
->AddChild(this);
149 wxSpinButton::~wxSpinButton()
153 // ----------------------------------------------------------------------------
155 // ----------------------------------------------------------------------------
157 wxSize
wxSpinButton::DoGetBestSize() const
159 if ( (GetWindowStyle() & wxSP_VERTICAL
) != 0 )
162 return wxSize(GetSystemMetrics(SM_CXVSCROLL
),
163 2*GetSystemMetrics(SM_CYVSCROLL
));
167 // horizontal control
168 return wxSize(2*GetSystemMetrics(SM_CXHSCROLL
),
169 GetSystemMetrics(SM_CYHSCROLL
));
173 // ----------------------------------------------------------------------------
175 // ----------------------------------------------------------------------------
177 int wxSpinButton::GetValue() const
179 return (short)LOWORD(::SendMessage(GetHwnd(), UDM_GETPOS
, 0, 0));
182 void wxSpinButton::SetValue(int val
)
184 ::SendMessage(GetHwnd(), UDM_SETPOS
, 0, (LPARAM
) MAKELONG((short) val
, 0));
187 void wxSpinButton::SetRange(int minVal
, int maxVal
)
189 wxSpinButtonBase::SetRange(minVal
, maxVal
);
190 ::SendMessage(GetHwnd(), UDM_SETRANGE
, 0,
191 (LPARAM
) MAKELONG((short)maxVal
, (short)minVal
));
194 bool wxSpinButton::MSWOnScroll(int orientation
, WXWORD wParam
,
195 WXWORD pos
, WXHWND control
)
197 wxCHECK_MSG( control
, FALSE
, wxT("scrolling what?") )
199 if ( wParam
!= SB_THUMBPOSITION
)
201 // probable SB_ENDSCROLL - we don't react to it
205 wxSpinEvent
event(wxEVT_SCROLL_THUMBTRACK
, m_windowId
);
206 event
.SetPosition((short)pos
); // cast is important for negative values!
207 event
.SetEventObject(this);
209 return GetEventHandler()->ProcessEvent(event
);
212 bool wxSpinButton::MSWOnNotify(int idCtrl
, WXLPARAM lParam
, WXLPARAM
*result
)
215 #if defined(__BORLANDC__) || defined(__WATCOMC__)
216 LPNM_UPDOWN lpnmud
= (LPNM_UPDOWN
)lParam
;
217 #elif defined(__VISUALC__) && (__VISUALC__ >= 1000) && (__VISUALC__ < 1020)
218 LPNM_UPDOWN lpnmud
= (LPNM_UPDOWN
)lParam
;
220 LPNMUPDOWN lpnmud
= (LPNMUPDOWN
)lParam
;
223 wxSpinEvent
event(lpnmud
->iDelta
> 0 ? wxEVT_SCROLL_LINEUP
224 : wxEVT_SCROLL_LINEDOWN
,
226 event
.SetPosition(lpnmud
->iPos
+ lpnmud
->iDelta
);
227 event
.SetEventObject(this);
229 bool processed
= GetEventHandler()->ProcessEvent(event
);
231 *result
= event
.IsAllowed() ? 0 : 1;
239 bool wxSpinButton::MSWCommand(WXUINT cmd
, WXWORD id
)
241 // No command messages