]>
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
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
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 #if defined(__WIN95__)
44 #include "wx/msw/private.h"
46 #if defined(__WIN95__) && !(defined(__GNUWIN32_OLD__) && !defined(__CYGWIN10__))
50 // ============================================================================
52 // ============================================================================
54 // ----------------------------------------------------------------------------
56 // ----------------------------------------------------------------------------
58 IMPLEMENT_DYNAMIC_CLASS(wxSpinButton
, wxControl
)
63 style wxSP_VERTICAL | wxSP_ARROW_KEYS
64 value wxSP_DEFAULT_VALUE
70 // ----------------------------------------------------------------------------
72 // ----------------------------------------------------------------------------
74 bool wxSpinButton::Create(wxWindow
*parent
,
81 // basic initialization
84 m_windowId
= (id
== -1) ? NewControlId() : id
;
86 m_backgroundColour
= parent
->GetBackgroundColour() ;
87 m_foregroundColour
= parent
->GetForegroundColour() ;
96 m_windowStyle
= style
;
100 // get the right size for the control
101 if ( width
<= 0 || height
<= 0 )
103 wxSize size
= DoGetBestSize();
115 // translate the styles
116 DWORD wstyle
= WS_VISIBLE
| WS_CHILD
| WS_TABSTOP
| /* WS_CLIPSIBLINGS | */
117 UDS_NOTHOUSANDS
| // never useful, sometimes harmful
118 UDS_SETBUDDYINT
; // it doesn't harm if we don't have buddy
120 if ( m_windowStyle
& wxCLIP_SIBLINGS
)
121 wstyle
|= WS_CLIPSIBLINGS
;
122 if ( m_windowStyle
& wxSP_HORIZONTAL
)
124 if ( m_windowStyle
& wxSP_ARROW_KEYS
)
125 wstyle
|= UDS_ARROWKEYS
;
126 if ( m_windowStyle
& wxSP_WRAP
)
129 // create the UpDown control.
130 m_hWnd
= (WXHWND
)CreateUpDownControl
139 m_min
// initial position
144 wxLogLastError(wxT("CreateUpDownControl"));
151 parent
->AddChild(this);
159 wxSpinButton::~wxSpinButton()
163 // ----------------------------------------------------------------------------
165 // ----------------------------------------------------------------------------
167 wxSize
wxSpinButton::DoGetBestSize() const
169 if ( (GetWindowStyle() & wxSP_VERTICAL
) != 0 )
172 return wxSize(GetSystemMetrics(SM_CXVSCROLL
),
173 2*GetSystemMetrics(SM_CYVSCROLL
));
177 // horizontal control
178 return wxSize(2*GetSystemMetrics(SM_CXHSCROLL
),
179 GetSystemMetrics(SM_CYHSCROLL
));
183 // ----------------------------------------------------------------------------
185 // ----------------------------------------------------------------------------
187 int wxSpinButton::GetValue() const
190 if ( wxTheApp
->GetComCtl32Version() >= 580 )
192 // use the full 32 bit range if available
193 return ::SendMessage(GetHwnd(), UDM_GETPOS32
, 0, 0);
195 #endif // UDM_GETPOS32
197 // we're limited to 16 bit
198 return (short)LOWORD(::SendMessage(GetHwnd(), UDM_GETPOS
, 0, 0));
201 void wxSpinButton::SetValue(int val
)
203 // wxSpinButtonBase::SetValue(val); -- no, it is pure virtual
206 if ( wxTheApp
->GetComCtl32Version() >= 580 )
208 // use the full 32 bit range if available
209 ::SendMessage(GetHwnd(), UDM_SETPOS32
, 0, val
);
211 else // we're limited to 16 bit
212 #endif // UDM_SETPOS32
214 ::SendMessage(GetHwnd(), UDM_SETPOS
, 0, MAKELONG((short) val
, 0));
218 void wxSpinButton::SetRange(int minVal
, int maxVal
)
220 wxSpinButtonBase::SetRange(minVal
, maxVal
);
222 #ifdef UDM_SETRANGE32
223 if ( wxTheApp
->GetComCtl32Version() >= 471 )
225 // use the full 32 bit range if available
226 ::SendMessage(GetHwnd(), UDM_SETRANGE32
, minVal
, maxVal
);
228 else // we're limited to 16 bit
229 #endif // UDM_SETRANGE32
231 ::SendMessage(GetHwnd(), UDM_SETRANGE
, 0,
232 (LPARAM
) MAKELONG((short)maxVal
, (short)minVal
));
236 bool wxSpinButton::MSWOnScroll(int WXUNUSED(orientation
), WXWORD wParam
,
237 WXWORD pos
, WXHWND control
)
239 wxCHECK_MSG( control
, FALSE
, wxT("scrolling what?") )
241 if ( wParam
!= SB_THUMBPOSITION
)
243 // probable SB_ENDSCROLL - we don't react to it
247 wxSpinEvent
event(wxEVT_SCROLL_THUMBTRACK
, m_windowId
);
248 event
.SetPosition((short)pos
); // cast is important for negative values!
249 event
.SetEventObject(this);
251 return GetEventHandler()->ProcessEvent(event
);
254 bool wxSpinButton::MSWOnNotify(int WXUNUSED(idCtrl
), WXLPARAM lParam
, WXLPARAM
*result
)
256 NM_UPDOWN
*lpnmud
= (NM_UPDOWN
*)lParam
;
258 if (lpnmud
->hdr
.hwndFrom
!= GetHwnd()) // make sure it is the right control
261 wxSpinEvent
event(lpnmud
->iDelta
> 0 ? wxEVT_SCROLL_LINEUP
262 : wxEVT_SCROLL_LINEDOWN
,
264 event
.SetPosition(lpnmud
->iPos
+ lpnmud
->iDelta
);
265 event
.SetEventObject(this);
267 bool processed
= GetEventHandler()->ProcessEvent(event
);
269 *result
= event
.IsAllowed() ? 0 : 1;
274 bool wxSpinButton::MSWCommand(WXUINT
WXUNUSED(cmd
), WXWORD
WXUNUSED(id
))
276 // No command messages