]>
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 IMPLEMENT_DYNAMIC_CLASS(wxSpinButton
, wxControl
)
58 IMPLEMENT_DYNAMIC_CLASS(wxSpinEvent
, wxScrollEvent
);
60 // ----------------------------------------------------------------------------
62 // ----------------------------------------------------------------------------
64 bool wxSpinButton::Create(wxWindow
*parent
,
71 // basic initialization
74 m_windowId
= (id
== -1) ? NewControlId() : id
;
76 m_backgroundColour
= parent
->GetBackgroundColour() ;
77 m_foregroundColour
= parent
->GetForegroundColour() ;
86 m_windowStyle
= style
;
90 // get the right size for the control
91 if ( width
<= 0 || height
<= 0 )
93 wxSize size
= DoGetBestSize();
105 // translate the styles
106 DWORD wstyle
= WS_VISIBLE
| WS_CHILD
| WS_TABSTOP
|
107 UDS_NOTHOUSANDS
| // never useful, sometimes harmful
108 UDS_SETBUDDYINT
; // it doesn't harm if we don't have buddy
110 if ( m_windowStyle
& wxSP_HORIZONTAL
)
112 if ( m_windowStyle
& wxSP_ARROW_KEYS
)
113 wstyle
|= UDS_ARROWKEYS
;
114 if ( m_windowStyle
& wxSP_WRAP
)
117 // create the UpDown control.
118 m_hWnd
= (WXHWND
)CreateUpDownControl
127 m_min
// initial position
132 wxLogLastError("CreateUpDownControl");
139 parent
->AddChild(this);
147 wxSpinButton::~wxSpinButton()
151 // ----------------------------------------------------------------------------
153 // ----------------------------------------------------------------------------
155 wxSize
wxSpinButton::DoGetBestSize() const
157 if ( (GetWindowStyle() & wxSP_VERTICAL
) != 0 )
160 return wxSize(GetSystemMetrics(SM_CXVSCROLL
),
161 2*GetSystemMetrics(SM_CYVSCROLL
));
165 // horizontal control
166 return wxSize(2*GetSystemMetrics(SM_CXHSCROLL
),
167 GetSystemMetrics(SM_CYHSCROLL
));
171 // ----------------------------------------------------------------------------
173 // ----------------------------------------------------------------------------
175 int wxSpinButton::GetValue() const
177 return (short)LOWORD(::SendMessage(GetHwnd(), UDM_GETPOS
, 0, 0));
180 void wxSpinButton::SetValue(int val
)
182 ::SendMessage(GetHwnd(), UDM_SETPOS
, 0, (LPARAM
) MAKELONG((short) val
, 0));
185 void wxSpinButton::SetRange(int minVal
, int maxVal
)
187 wxSpinButtonBase::SetRange(minVal
, maxVal
);
188 ::SendMessage(GetHwnd(), UDM_SETRANGE
, 0,
189 (LPARAM
) MAKELONG((short)maxVal
, (short)minVal
));
192 bool wxSpinButton::MSWOnScroll(int orientation
, WXWORD wParam
,
193 WXWORD pos
, WXHWND control
)
195 wxCHECK_MSG( control
, FALSE
, wxT("scrolling what?") )
197 if ( wParam
!= SB_THUMBPOSITION
)
199 // probable SB_ENDSCROLL - we don't react to it
203 wxSpinEvent
event(wxEVT_SCROLL_THUMBTRACK
, m_windowId
);
204 event
.SetPosition((short)pos
); // cast is important for negative values!
205 event
.SetEventObject(this);
207 return GetEventHandler()->ProcessEvent(event
);
210 bool wxSpinButton::MSWOnNotify(int idCtrl
, WXLPARAM lParam
, WXLPARAM
*result
)
213 #if defined(__BORLANDC__) || defined(__WATCOMC__)
214 LPNM_UPDOWN lpnmud
= (LPNM_UPDOWN
)lParam
;
215 #elif defined(__VISUALC__) && (__VISUALC__ >= 1000) && (__VISUALC__ < 1020)
216 LPNM_UPDOWN lpnmud
= (LPNM_UPDOWN
)lParam
;
218 LPNMUPDOWN lpnmud
= (LPNMUPDOWN
)lParam
;
221 wxSpinEvent
event(lpnmud
->iDelta
> 0 ? wxEVT_SCROLL_LINEUP
222 : wxEVT_SCROLL_LINEDOWN
,
224 event
.SetPosition(lpnmud
->iPos
+ lpnmud
->iDelta
);
225 event
.SetEventObject(this);
227 bool processed
= GetEventHandler()->ProcessEvent(event
);
229 *result
= event
.IsAllowed() ? 0 : 1;
237 bool wxSpinButton::MSWCommand(WXUINT cmd
, WXWORD id
)
239 // No command messages