]>
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 // ----------------------------------------------------------------------------
59 #if wxUSE_EXTENDED_RTTI
60 IMPLEMENT_DYNAMIC_CLASS_XTI(wxSpinButton
, wxControl
,"wx/spinbut.h")
62 WX_BEGIN_PROPERTIES_TABLE(wxSpinButton
)
63 WX_PROPERTY( Value
, int , SetValue
, GetValue
, 0 )
64 WX_PROPERTY( Min
, int , SetMin
, GetMin
, 0 )
65 WX_PROPERTY( Max
, int , SetMax
, GetMax
, 0 )
68 style wxSP_VERTICAL | wxSP_ARROW_KEYS
70 WX_END_PROPERTIES_TABLE()
72 WX_BEGIN_HANDLERS_TABLE(wxSpinButton
)
73 WX_END_HANDLERS_TABLE()
75 WX_CONSTRUCTOR_5( wxSpinButton
, wxWindow
* , Parent
, wxWindowID
, Id
, wxPoint
, Position
, wxSize
, Size
, long , WindowStyle
)
77 IMPLEMENT_DYNAMIC_CLASS(wxSpinButton
, wxControl
)
82 // ----------------------------------------------------------------------------
84 // ----------------------------------------------------------------------------
86 bool wxSpinButton::Create(wxWindow
*parent
,
93 // basic initialization
96 m_windowId
= (id
== -1) ? NewControlId() : id
;
98 m_backgroundColour
= parent
->GetBackgroundColour() ;
99 m_foregroundColour
= parent
->GetForegroundColour() ;
108 m_windowStyle
= style
;
112 // get the right size for the control
113 if ( width
<= 0 || height
<= 0 )
115 wxSize size
= DoGetBestSize();
127 // translate the styles
128 DWORD wstyle
= WS_VISIBLE
| WS_CHILD
| WS_TABSTOP
| /* WS_CLIPSIBLINGS | */
129 UDS_NOTHOUSANDS
| // never useful, sometimes harmful
130 UDS_SETBUDDYINT
; // it doesn't harm if we don't have buddy
132 if ( m_windowStyle
& wxCLIP_SIBLINGS
)
133 wstyle
|= WS_CLIPSIBLINGS
;
134 if ( m_windowStyle
& wxSP_HORIZONTAL
)
136 if ( m_windowStyle
& wxSP_ARROW_KEYS
)
137 wstyle
|= UDS_ARROWKEYS
;
138 if ( m_windowStyle
& wxSP_WRAP
)
141 // create the UpDown control.
142 m_hWnd
= (WXHWND
)CreateUpDownControl
151 m_min
// initial position
156 wxLogLastError(wxT("CreateUpDownControl"));
163 parent
->AddChild(this);
171 wxSpinButton::~wxSpinButton()
175 // ----------------------------------------------------------------------------
177 // ----------------------------------------------------------------------------
179 wxSize
wxSpinButton::DoGetBestSize() const
181 if ( (GetWindowStyle() & wxSP_VERTICAL
) != 0 )
184 return wxSize(GetSystemMetrics(SM_CXVSCROLL
),
185 2*GetSystemMetrics(SM_CYVSCROLL
));
189 // horizontal control
190 return wxSize(2*GetSystemMetrics(SM_CXHSCROLL
),
191 GetSystemMetrics(SM_CYHSCROLL
));
195 // ----------------------------------------------------------------------------
197 // ----------------------------------------------------------------------------
199 int wxSpinButton::GetValue() const
202 if ( wxTheApp
->GetComCtl32Version() >= 580 )
204 // use the full 32 bit range if available
205 return ::SendMessage(GetHwnd(), UDM_GETPOS32
, 0, 0);
207 #endif // UDM_GETPOS32
209 // we're limited to 16 bit
210 return (short)LOWORD(::SendMessage(GetHwnd(), UDM_GETPOS
, 0, 0));
213 void wxSpinButton::SetValue(int val
)
215 // wxSpinButtonBase::SetValue(val); -- no, it is pure virtual
218 if ( wxTheApp
->GetComCtl32Version() >= 580 )
220 // use the full 32 bit range if available
221 ::SendMessage(GetHwnd(), UDM_SETPOS32
, 0, val
);
223 else // we're limited to 16 bit
224 #endif // UDM_SETPOS32
226 ::SendMessage(GetHwnd(), UDM_SETPOS
, 0, MAKELONG((short) val
, 0));
230 void wxSpinButton::SetRange(int minVal
, int maxVal
)
232 wxSpinButtonBase::SetRange(minVal
, maxVal
);
234 #ifdef UDM_SETRANGE32
235 if ( wxTheApp
->GetComCtl32Version() >= 471 )
237 // use the full 32 bit range if available
238 ::SendMessage(GetHwnd(), UDM_SETRANGE32
, minVal
, maxVal
);
240 else // we're limited to 16 bit
241 #endif // UDM_SETRANGE32
243 ::SendMessage(GetHwnd(), UDM_SETRANGE
, 0,
244 (LPARAM
) MAKELONG((short)maxVal
, (short)minVal
));
248 bool wxSpinButton::MSWOnScroll(int WXUNUSED(orientation
), WXWORD wParam
,
249 WXWORD pos
, WXHWND control
)
251 wxCHECK_MSG( control
, FALSE
, wxT("scrolling what?") )
253 if ( wParam
!= SB_THUMBPOSITION
)
255 // probable SB_ENDSCROLL - we don't react to it
259 wxSpinEvent
event(wxEVT_SCROLL_THUMBTRACK
, m_windowId
);
260 event
.SetPosition((short)pos
); // cast is important for negative values!
261 event
.SetEventObject(this);
263 return GetEventHandler()->ProcessEvent(event
);
266 bool wxSpinButton::MSWOnNotify(int WXUNUSED(idCtrl
), WXLPARAM lParam
, WXLPARAM
*result
)
268 NM_UPDOWN
*lpnmud
= (NM_UPDOWN
*)lParam
;
270 if (lpnmud
->hdr
.hwndFrom
!= GetHwnd()) // make sure it is the right control
273 wxSpinEvent
event(lpnmud
->iDelta
> 0 ? wxEVT_SCROLL_LINEUP
274 : wxEVT_SCROLL_LINEDOWN
,
276 event
.SetPosition(lpnmud
->iPos
+ lpnmud
->iDelta
);
277 event
.SetEventObject(this);
279 bool processed
= GetEventHandler()->ProcessEvent(event
);
281 *result
= event
.IsAllowed() ? 0 : 1;
286 bool wxSpinButton::MSWCommand(WXUINT
WXUNUSED(cmd
), WXWORD
WXUNUSED(id
))
288 // No command messages