]>
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 // ----------------------------------------------------------------------------
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
)
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
| /* WS_CLIPSIBLINGS | */
107 UDS_NOTHOUSANDS
| // never useful, sometimes harmful
108 UDS_SETBUDDYINT
; // it doesn't harm if we don't have buddy
110 if ( m_windowStyle
& wxCLIP_SIBLINGS
)
111 wstyle
|= WS_CLIPSIBLINGS
;
112 if ( m_windowStyle
& wxSP_HORIZONTAL
)
114 if ( m_windowStyle
& wxSP_ARROW_KEYS
)
115 wstyle
|= UDS_ARROWKEYS
;
116 if ( m_windowStyle
& wxSP_WRAP
)
119 // create the UpDown control.
120 m_hWnd
= (WXHWND
)CreateUpDownControl
129 m_min
// initial position
134 wxLogLastError(wxT("CreateUpDownControl"));
141 parent
->AddChild(this);
149 wxSpinButton::~wxSpinButton()
153 // ----------------------------------------------------------------------------
155 // ----------------------------------------------------------------------------
157 wxSize
wxSpinButton::DoGetBestSize() const
159 if ( (GetWindowStyle() & wxSP_VERTICAL
) != 0 )
162 return wxSize(GetSystemMetrics(SM_CXVSCROLL
),
163 2*GetSystemMetrics(SM_CYVSCROLL
));
167 // horizontal control
168 return wxSize(2*GetSystemMetrics(SM_CXHSCROLL
),
169 GetSystemMetrics(SM_CYHSCROLL
));
173 // ----------------------------------------------------------------------------
175 // ----------------------------------------------------------------------------
177 int wxSpinButton::GetValue() const
180 if ( wxTheApp
->GetComCtl32Version() >= 580 )
182 // use the full 32 bit range if available
183 return ::SendMessage(GetHwnd(), UDM_GETPOS32
, 0, 0);
185 #endif // UDM_GETPOS32
187 // we're limited to 16 bit
188 return (short)LOWORD(::SendMessage(GetHwnd(), UDM_GETPOS
, 0, 0));
191 void wxSpinButton::SetValue(int val
)
193 // wxSpinButtonBase::SetValue(val); -- no, it is pure virtual
196 if ( wxTheApp
->GetComCtl32Version() >= 580 )
198 // use the full 32 bit range if available
199 ::SendMessage(GetHwnd(), UDM_SETPOS32
, 0, val
);
201 else // we're limited to 16 bit
202 #endif // UDM_SETPOS32
204 ::SendMessage(GetHwnd(), UDM_SETPOS
, 0, MAKELONG((short) val
, 0));
208 void wxSpinButton::SetRange(int minVal
, int maxVal
)
210 wxSpinButtonBase::SetRange(minVal
, maxVal
);
212 #ifdef UDM_SETRANGE32
213 if ( wxTheApp
->GetComCtl32Version() >= 471 )
215 // use the full 32 bit range if available
216 ::SendMessage(GetHwnd(), UDM_SETRANGE32
, minVal
, maxVal
);
218 else // we're limited to 16 bit
219 #endif // UDM_SETRANGE32
221 ::SendMessage(GetHwnd(), UDM_SETRANGE
, 0,
222 (LPARAM
) MAKELONG((short)maxVal
, (short)minVal
));
226 bool wxSpinButton::MSWOnScroll(int WXUNUSED(orientation
), WXWORD wParam
,
227 WXWORD pos
, WXHWND control
)
229 wxCHECK_MSG( control
, FALSE
, wxT("scrolling what?") )
231 if ( wParam
!= SB_THUMBPOSITION
)
233 // probable SB_ENDSCROLL - we don't react to it
237 wxSpinEvent
event(wxEVT_SCROLL_THUMBTRACK
, m_windowId
);
238 event
.SetPosition((short)pos
); // cast is important for negative values!
239 event
.SetEventObject(this);
241 return GetEventHandler()->ProcessEvent(event
);
244 bool wxSpinButton::MSWOnNotify(int WXUNUSED(idCtrl
), WXLPARAM lParam
, WXLPARAM
*result
)
246 NM_UPDOWN
*lpnmud
= (NM_UPDOWN
*)lParam
;
248 if (lpnmud
->hdr
.hwndFrom
!= GetHwnd()) // make sure it is the right control
251 wxSpinEvent
event(lpnmud
->iDelta
> 0 ? wxEVT_SCROLL_LINEUP
252 : wxEVT_SCROLL_LINEDOWN
,
254 event
.SetPosition(lpnmud
->iPos
+ lpnmud
->iDelta
);
255 event
.SetEventObject(this);
257 bool processed
= GetEventHandler()->ProcessEvent(event
);
259 *result
= event
.IsAllowed() ? 0 : 1;
264 bool wxSpinButton::MSWCommand(WXUINT
WXUNUSED(cmd
), WXWORD
WXUNUSED(id
))
266 // No command messages