]>
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.
38 #if defined(__WIN95__) && !defined(__TWIN32__)
40 #include "wx/spinbutt.h"
41 #include "wx/msw/private.h"
43 #if !defined(__GNUWIN32__) || defined(__TWIN32__) || defined(wxUSE_NORLANDER_HEADERS)
47 // ============================================================================
49 // ============================================================================
51 // ----------------------------------------------------------------------------
53 // ----------------------------------------------------------------------------
55 #if !USE_SHARED_LIBRARY
56 IMPLEMENT_DYNAMIC_CLASS(wxSpinButton
, wxControl
)
57 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_SETBUDDYINT
; // it doesn't harm if we don't have buddy
109 if ( m_windowStyle
& wxSP_HORIZONTAL
)
111 if ( m_windowStyle
& wxSP_ARROW_KEYS
)
112 wstyle
|= UDS_ARROWKEYS
;
113 if ( m_windowStyle
& wxSP_WRAP
)
116 // create the UpDown control.
117 m_hWnd
= (WXHWND
)CreateUpDownControl
126 m_min
// initial position
131 wxLogLastError("CreateUpDownControl");
138 parent
->AddChild(this);
146 wxSpinButton::~wxSpinButton()
150 // ----------------------------------------------------------------------------
152 // ----------------------------------------------------------------------------
154 wxSize
wxSpinButton::DoGetBestSize()
156 if ( (GetWindowStyle() & wxSP_VERTICAL
) != 0 )
159 return wxSize(GetSystemMetrics(SM_CXVSCROLL
),
160 2*GetSystemMetrics(SM_CYVSCROLL
));
164 // horizontal control
165 return wxSize(2*GetSystemMetrics(SM_CXHSCROLL
),
166 GetSystemMetrics(SM_CYHSCROLL
));
170 // ----------------------------------------------------------------------------
172 // ----------------------------------------------------------------------------
174 int wxSpinButton::GetValue() const
176 return (short)LOWORD(::SendMessage(GetHwnd(), UDM_GETPOS
, 0, 0));
179 void wxSpinButton::SetValue(int val
)
181 ::SendMessage(GetHwnd(), UDM_SETPOS
, 0, (LPARAM
) MAKELONG((short) val
, 0));
184 void wxSpinButton::SetRange(int minVal
, int maxVal
)
186 wxSpinButtonBase::SetRange(minVal
, maxVal
);
187 ::SendMessage(GetHwnd(), UDM_SETRANGE
, 0,
188 (LPARAM
) MAKELONG((short)maxVal
, (short)minVal
));
191 bool wxSpinButton::MSWOnScroll(int orientation
, WXWORD wParam
,
192 WXWORD pos
, WXHWND control
)
194 wxCHECK_MSG( control
, FALSE
, wxT("scrolling what?") )
196 if ( wParam
!= SB_THUMBPOSITION
)
198 // probable SB_ENDSCROLL - we don't react to it
202 wxSpinEvent
event(wxEVT_SCROLL_THUMBTRACK
, m_windowId
);
203 event
.SetPosition((short)pos
); // cast is important for negative values!
204 event
.SetEventObject(this);
206 return GetEventHandler()->ProcessEvent(event
);
209 bool wxSpinButton::MSWOnNotify(int idCtrl
, WXLPARAM lParam
, WXLPARAM
*result
)
212 #if defined(__BORLANDC__) || defined(__WATCOMC__)
213 LPNM_UPDOWN lpnmud
= (LPNM_UPDOWN
)lParam
;
214 #elif defined(__VISUALC__) && (__VISUALC__ == 1010)
215 LPNM_UPDOWN lpnmud
= (LPNM_UPDOWN
)lParam
;
217 LPNMUPDOWN lpnmud
= (LPNMUPDOWN
)lParam
;
220 wxSpinEvent
event(lpnmud
->iDelta
> 0 ? wxEVT_SCROLL_LINEUP
221 : wxEVT_SCROLL_LINEDOWN
,
223 event
.SetPosition(lpnmud
->iPos
+ lpnmud
->iDelta
);
224 event
.SetEventObject(this);
226 bool processed
= GetEventHandler()->ProcessEvent(event
);
228 *result
= event
.IsAllowed() ? 0 : 1;
236 bool wxSpinButton::MSWCommand(WXUINT cmd
, WXWORD id
)
238 // No command messages