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 WX_DEFINE_FLAGS( wxSpinButtonStyle
)
62 WX_BEGIN_FLAGS( wxSpinButtonStyle
)
63 // new style border flags, we put them first to
64 // use them for streaming out
65 WX_FLAGS_MEMBER(wxBORDER_SIMPLE
)
66 WX_FLAGS_MEMBER(wxBORDER_SUNKEN
)
67 WX_FLAGS_MEMBER(wxBORDER_DOUBLE
)
68 WX_FLAGS_MEMBER(wxBORDER_RAISED
)
69 WX_FLAGS_MEMBER(wxBORDER_STATIC
)
70 WX_FLAGS_MEMBER(wxBORDER_NONE
)
72 // old style border flags
73 WX_FLAGS_MEMBER(wxSIMPLE_BORDER
)
74 WX_FLAGS_MEMBER(wxSUNKEN_BORDER
)
75 WX_FLAGS_MEMBER(wxDOUBLE_BORDER
)
76 WX_FLAGS_MEMBER(wxRAISED_BORDER
)
77 WX_FLAGS_MEMBER(wxSTATIC_BORDER
)
78 WX_FLAGS_MEMBER(wxNO_BORDER
)
80 // standard window styles
81 WX_FLAGS_MEMBER(wxTAB_TRAVERSAL
)
82 WX_FLAGS_MEMBER(wxCLIP_CHILDREN
)
83 WX_FLAGS_MEMBER(wxTRANSPARENT_WINDOW
)
84 WX_FLAGS_MEMBER(wxWANTS_CHARS
)
85 WX_FLAGS_MEMBER(wxNO_FULL_REPAINT_ON_RESIZE
)
86 WX_FLAGS_MEMBER(wxALWAYS_SHOW_SB
)
87 WX_FLAGS_MEMBER(wxVSCROLL
)
88 WX_FLAGS_MEMBER(wxHSCROLL
)
90 WX_FLAGS_MEMBER(wxSP_HORIZONTAL
)
91 WX_FLAGS_MEMBER(wxSP_VERTICAL
)
92 WX_FLAGS_MEMBER(wxSP_ARROW_KEYS
)
93 WX_FLAGS_MEMBER(wxSP_WRAP
)
95 WX_END_FLAGS( wxSpinButtonStyle
)
97 IMPLEMENT_DYNAMIC_CLASS_XTI(wxSpinButton
, wxControl
,"wx/spinbut.h")
99 WX_BEGIN_PROPERTIES_TABLE(wxSpinButton
)
100 WX_PROPERTY( Value
, int , SetValue
, GetValue
, 0 , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
101 WX_PROPERTY( Min
, int , SetMin
, GetMin
, 0 , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
102 WX_PROPERTY( Max
, int , SetMax
, GetMax
, 0 , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
103 WX_PROPERTY_FLAGS( WindowStyle
, wxSpinButtonStyle
, long , SetWindowStyleFlag
, GetWindowStyleFlag
, , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style
104 WX_END_PROPERTIES_TABLE()
106 WX_BEGIN_HANDLERS_TABLE(wxSpinButton
)
107 WX_END_HANDLERS_TABLE()
109 WX_CONSTRUCTOR_5( wxSpinButton
, wxWindow
* , Parent
, wxWindowID
, Id
, wxPoint
, Position
, wxSize
, Size
, long , WindowStyle
)
111 IMPLEMENT_DYNAMIC_CLASS(wxSpinButton
, wxControl
)
116 // ----------------------------------------------------------------------------
118 // ----------------------------------------------------------------------------
120 bool wxSpinButton::Create(wxWindow
*parent
,
125 const wxString
& name
)
127 // basic initialization
130 m_windowId
= (id
== -1) ? NewControlId() : id
;
132 m_backgroundColour
= parent
->GetBackgroundColour() ;
133 m_foregroundColour
= parent
->GetForegroundColour() ;
142 m_windowStyle
= style
;
146 // get the right size for the control
147 if ( width
<= 0 || height
<= 0 )
149 wxSize size
= DoGetBestSize();
161 // translate the styles
162 DWORD wstyle
= WS_VISIBLE
| WS_CHILD
| WS_TABSTOP
| /* WS_CLIPSIBLINGS | */
163 UDS_NOTHOUSANDS
| // never useful, sometimes harmful
164 UDS_SETBUDDYINT
; // it doesn't harm if we don't have buddy
166 if ( m_windowStyle
& wxCLIP_SIBLINGS
)
167 wstyle
|= WS_CLIPSIBLINGS
;
168 if ( m_windowStyle
& wxSP_HORIZONTAL
)
170 if ( m_windowStyle
& wxSP_ARROW_KEYS
)
171 wstyle
|= UDS_ARROWKEYS
;
172 if ( m_windowStyle
& wxSP_WRAP
)
175 // create the UpDown control.
176 m_hWnd
= (WXHWND
)CreateUpDownControl
185 m_min
// initial position
190 wxLogLastError(wxT("CreateUpDownControl"));
197 parent
->AddChild(this);
205 wxSpinButton::~wxSpinButton()
209 // ----------------------------------------------------------------------------
211 // ----------------------------------------------------------------------------
213 wxSize
wxSpinButton::DoGetBestSize() const
215 if ( (GetWindowStyle() & wxSP_VERTICAL
) != 0 )
218 return wxSize(GetSystemMetrics(SM_CXVSCROLL
),
219 2*GetSystemMetrics(SM_CYVSCROLL
));
223 // horizontal control
224 return wxSize(2*GetSystemMetrics(SM_CXHSCROLL
),
225 GetSystemMetrics(SM_CYHSCROLL
));
229 // ----------------------------------------------------------------------------
231 // ----------------------------------------------------------------------------
233 int wxSpinButton::GetValue() const
236 if ( wxTheApp
->GetComCtl32Version() >= 580 )
238 // use the full 32 bit range if available
239 return ::SendMessage(GetHwnd(), UDM_GETPOS32
, 0, 0);
241 #endif // UDM_GETPOS32
243 // we're limited to 16 bit
244 return (short)LOWORD(::SendMessage(GetHwnd(), UDM_GETPOS
, 0, 0));
247 void wxSpinButton::SetValue(int val
)
249 // wxSpinButtonBase::SetValue(val); -- no, it is pure virtual
252 if ( wxTheApp
->GetComCtl32Version() >= 580 )
254 // use the full 32 bit range if available
255 ::SendMessage(GetHwnd(), UDM_SETPOS32
, 0, val
);
257 else // we're limited to 16 bit
258 #endif // UDM_SETPOS32
260 ::SendMessage(GetHwnd(), UDM_SETPOS
, 0, MAKELONG((short) val
, 0));
264 void wxSpinButton::SetRange(int minVal
, int maxVal
)
266 wxSpinButtonBase::SetRange(minVal
, maxVal
);
268 #ifdef UDM_SETRANGE32
269 if ( wxTheApp
->GetComCtl32Version() >= 471 )
271 // use the full 32 bit range if available
272 ::SendMessage(GetHwnd(), UDM_SETRANGE32
, minVal
, maxVal
);
274 else // we're limited to 16 bit
275 #endif // UDM_SETRANGE32
277 ::SendMessage(GetHwnd(), UDM_SETRANGE
, 0,
278 (LPARAM
) MAKELONG((short)maxVal
, (short)minVal
));
282 bool wxSpinButton::MSWOnScroll(int WXUNUSED(orientation
), WXWORD wParam
,
283 WXWORD pos
, WXHWND control
)
285 wxCHECK_MSG( control
, FALSE
, wxT("scrolling what?") )
287 if ( wParam
!= SB_THUMBPOSITION
)
289 // probable SB_ENDSCROLL - we don't react to it
293 wxSpinEvent
event(wxEVT_SCROLL_THUMBTRACK
, m_windowId
);
294 event
.SetPosition((short)pos
); // cast is important for negative values!
295 event
.SetEventObject(this);
297 return GetEventHandler()->ProcessEvent(event
);
300 bool wxSpinButton::MSWOnNotify(int WXUNUSED(idCtrl
), WXLPARAM lParam
, WXLPARAM
*result
)
302 NM_UPDOWN
*lpnmud
= (NM_UPDOWN
*)lParam
;
304 if (lpnmud
->hdr
.hwndFrom
!= GetHwnd()) // make sure it is the right control
307 wxSpinEvent
event(lpnmud
->iDelta
> 0 ? wxEVT_SCROLL_LINEUP
308 : wxEVT_SCROLL_LINEDOWN
,
310 event
.SetPosition(lpnmud
->iPos
+ lpnmud
->iDelta
);
311 event
.SetEventObject(this);
313 bool processed
= GetEventHandler()->ProcessEvent(event
);
315 *result
= event
.IsAllowed() ? 0 : 1;
320 bool wxSpinButton::MSWCommand(WXUINT
WXUNUSED(cmd
), WXWORD
WXUNUSED(id
))
322 // No command messages