]>
git.saurik.com Git - wxWidgets.git/blob - src/msw/spinbutt.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: msw/spinbutt.cpp
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"
38 #include "wx/spinbutt.h"
40 IMPLEMENT_DYNAMIC_CLASS(wxSpinEvent
, wxNotifyEvent
)
42 // Can't resolve reference to CreateUpDownControl in
43 // TWIN32, but could probably use normal CreateWindow instead.
44 #if defined(__WIN95__) && !defined(__TWIN32__)
46 #include "wx/msw/private.h"
48 #if defined(__WIN95__) && !((defined(__GNUWIN32_OLD__) || defined(__TWIN32__)) && !defined(__CYGWIN10__))
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
| /* WS_CLIPSIBLINGS | */
109 UDS_NOTHOUSANDS
| // never useful, sometimes harmful
110 UDS_SETBUDDYINT
; // it doesn't harm if we don't have buddy
112 if ( m_windowStyle
& wxCLIP_SIBLINGS
)
113 wstyle
|= WS_CLIPSIBLINGS
;
114 if ( m_windowStyle
& wxSP_HORIZONTAL
)
116 if ( m_windowStyle
& wxSP_ARROW_KEYS
)
117 wstyle
|= UDS_ARROWKEYS
;
118 if ( m_windowStyle
& wxSP_WRAP
)
121 // create the UpDown control.
122 m_hWnd
= (WXHWND
)CreateUpDownControl
131 m_min
// initial position
136 wxLogLastError(wxT("CreateUpDownControl"));
143 parent
->AddChild(this);
151 wxSpinButton::~wxSpinButton()
155 // ----------------------------------------------------------------------------
157 // ----------------------------------------------------------------------------
159 wxSize
wxSpinButton::DoGetBestSize() const
161 if ( (GetWindowStyle() & wxSP_VERTICAL
) != 0 )
164 return wxSize(GetSystemMetrics(SM_CXVSCROLL
),
165 2*GetSystemMetrics(SM_CYVSCROLL
));
169 // horizontal control
170 return wxSize(2*GetSystemMetrics(SM_CXHSCROLL
),
171 GetSystemMetrics(SM_CYHSCROLL
));
175 // ----------------------------------------------------------------------------
177 // ----------------------------------------------------------------------------
179 int wxSpinButton::GetValue() const
182 if ( wxTheApp
->GetComCtl32Version() >= 580 )
184 // use the full 32 bit range if available
185 return ::SendMessage(GetHwnd(), UDM_GETPOS32
, 0, 0);
187 #endif // UDM_GETPOS32
189 // we're limited to 16 bit
190 return (short)LOWORD(::SendMessage(GetHwnd(), UDM_GETPOS
, 0, 0));
193 void wxSpinButton::SetValue(int val
)
195 // wxSpinButtonBase::SetValue(val); -- no, it is pure virtual
198 if ( wxTheApp
->GetComCtl32Version() >= 580 )
200 // use the full 32 bit range if available
201 ::SendMessage(GetHwnd(), UDM_SETPOS32
, 0, val
);
203 else // we're limited to 16 bit
204 #endif // UDM_SETPOS32
206 ::SendMessage(GetHwnd(), UDM_SETPOS
, 0, MAKELONG((short) val
, 0));
210 void wxSpinButton::SetRange(int minVal
, int maxVal
)
212 wxSpinButtonBase::SetRange(minVal
, maxVal
);
214 #ifdef UDM_SETRANGE32
215 if ( wxTheApp
->GetComCtl32Version() >= 471 )
217 // use the full 32 bit range if available
218 ::SendMessage(GetHwnd(), UDM_SETRANGE32
, minVal
, maxVal
);
220 else // we're limited to 16 bit
221 #endif // UDM_SETRANGE32
223 ::SendMessage(GetHwnd(), UDM_SETRANGE
, 0,
224 (LPARAM
) MAKELONG((short)maxVal
, (short)minVal
));
228 bool wxSpinButton::MSWOnScroll(int WXUNUSED(orientation
), WXWORD wParam
,
229 WXWORD pos
, WXHWND control
)
231 wxCHECK_MSG( control
, FALSE
, wxT("scrolling what?") )
233 if ( wParam
!= SB_THUMBPOSITION
)
235 // probable SB_ENDSCROLL - we don't react to it
239 wxSpinEvent
event(wxEVT_SCROLL_THUMBTRACK
, m_windowId
);
240 event
.SetPosition((short)pos
); // cast is important for negative values!
241 event
.SetEventObject(this);
243 return GetEventHandler()->ProcessEvent(event
);
246 bool wxSpinButton::MSWOnNotify(int WXUNUSED(idCtrl
), WXLPARAM lParam
, WXLPARAM
*result
)
248 NM_UPDOWN
*lpnmud
= (NM_UPDOWN
*)lParam
;
250 if (lpnmud
->hdr
.hwndFrom
!= GetHwnd()) // make sure it is the right control
253 wxSpinEvent
event(lpnmud
->iDelta
> 0 ? wxEVT_SCROLL_LINEUP
254 : wxEVT_SCROLL_LINEDOWN
,
256 event
.SetPosition(lpnmud
->iPos
+ lpnmud
->iDelta
);
257 event
.SetEventObject(this);
259 bool processed
= GetEventHandler()->ProcessEvent(event
);
261 *result
= event
.IsAllowed() ? 0 : 1;
266 bool wxSpinButton::MSWCommand(WXUINT
WXUNUSED(cmd
), WXWORD
WXUNUSED(id
))
268 // No command messages