]>
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__)) && !defined(__CYGWIN10__))
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
183 if ( wxTheApp
->GetComCtl32Version() >= 580 )
185 // use the full 32 bit range if available
186 return ::SendMessage(GetHwnd(), UDM_GETPOS32
, 0, 0);
188 #endif // UDM_GETPOS32
190 // we're limited to 16 bit
191 return (short)LOWORD(::SendMessage(GetHwnd(), UDM_GETPOS
, 0, 0));
194 void wxSpinButton::SetValue(int val
)
196 // wxSpinButtonBase::SetValue(val); -- no, it is pure virtual
199 if ( wxTheApp
->GetComCtl32Version() >= 580 )
201 // use the full 32 bit range if available
202 ::SendMessage(GetHwnd(), UDM_SETPOS32
, 0, val
);
204 else // we're limited to 16 bit
205 #endif // UDM_SETPOS32
207 ::SendMessage(GetHwnd(), UDM_SETPOS
, 0, MAKELONG((short) val
, 0));
211 void wxSpinButton::SetRange(int minVal
, int maxVal
)
213 wxSpinButtonBase::SetRange(minVal
, maxVal
);
215 #ifdef UDM_SETRANGE32
216 if ( wxTheApp
->GetComCtl32Version() >= 471 )
218 // use the full 32 bit range if available
219 ::SendMessage(GetHwnd(), UDM_SETRANGE32
, minVal
, maxVal
);
221 else // we're limited to 16 bit
222 #endif // UDM_SETRANGE32
224 ::SendMessage(GetHwnd(), UDM_SETRANGE
, 0,
225 (LPARAM
) MAKELONG((short)maxVal
, (short)minVal
));
229 bool wxSpinButton::MSWOnScroll(int WXUNUSED(orientation
), WXWORD wParam
,
230 WXWORD pos
, WXHWND control
)
232 wxCHECK_MSG( control
, FALSE
, wxT("scrolling what?") )
234 if ( wParam
!= SB_THUMBPOSITION
)
236 // probable SB_ENDSCROLL - we don't react to it
240 wxSpinEvent
event(wxEVT_SCROLL_THUMBTRACK
, m_windowId
);
241 event
.SetPosition((short)pos
); // cast is important for negative values!
242 event
.SetEventObject(this);
244 return GetEventHandler()->ProcessEvent(event
);
247 bool wxSpinButton::MSWOnNotify(int WXUNUSED(idCtrl
), WXLPARAM lParam
, WXLPARAM
*result
)
249 LPNM_UPDOWN lpnmud
= (LPNM_UPDOWN
)lParam
;
251 if (lpnmud
->hdr
.hwndFrom
!= GetHwnd()) // make sure it is the right control
254 wxSpinEvent
event(lpnmud
->iDelta
> 0 ? wxEVT_SCROLL_LINEUP
255 : wxEVT_SCROLL_LINEDOWN
,
257 event
.SetPosition(lpnmud
->iPos
+ lpnmud
->iDelta
);
258 event
.SetEventObject(this);
260 bool processed
= GetEventHandler()->ProcessEvent(event
);
262 *result
= event
.IsAllowed() ? 0 : 1;
267 bool wxSpinButton::MSWCommand(WXUINT
WXUNUSED(cmd
), WXWORD
WXUNUSED(id
))
269 // No command messages