]>
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 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
33 #include "wx/spinbutt.h"
35 IMPLEMENT_DYNAMIC_CLASS(wxSpinEvent
, wxNotifyEvent
)
37 #include "wx/msw/private.h"
38 #include "wx/msw/wrapcctl.h"
40 // ============================================================================
42 // ============================================================================
44 // ----------------------------------------------------------------------------
46 // ----------------------------------------------------------------------------
49 #if wxUSE_EXTENDED_RTTI
50 WX_DEFINE_FLAGS( wxSpinButtonStyle
)
52 wxBEGIN_FLAGS( wxSpinButtonStyle
)
53 // new style border flags, we put them first to
54 // use them for streaming out
55 wxFLAGS_MEMBER(wxBORDER_SIMPLE
)
56 wxFLAGS_MEMBER(wxBORDER_SUNKEN
)
57 wxFLAGS_MEMBER(wxBORDER_DOUBLE
)
58 wxFLAGS_MEMBER(wxBORDER_RAISED
)
59 wxFLAGS_MEMBER(wxBORDER_STATIC
)
60 wxFLAGS_MEMBER(wxBORDER_NONE
)
62 // old style border flags
63 wxFLAGS_MEMBER(wxSIMPLE_BORDER
)
64 wxFLAGS_MEMBER(wxSUNKEN_BORDER
)
65 wxFLAGS_MEMBER(wxDOUBLE_BORDER
)
66 wxFLAGS_MEMBER(wxRAISED_BORDER
)
67 wxFLAGS_MEMBER(wxSTATIC_BORDER
)
68 wxFLAGS_MEMBER(wxBORDER
)
70 // standard window styles
71 wxFLAGS_MEMBER(wxTAB_TRAVERSAL
)
72 wxFLAGS_MEMBER(wxCLIP_CHILDREN
)
73 wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW
)
74 wxFLAGS_MEMBER(wxWANTS_CHARS
)
75 wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE
)
76 wxFLAGS_MEMBER(wxALWAYS_SHOW_SB
)
77 wxFLAGS_MEMBER(wxVSCROLL
)
78 wxFLAGS_MEMBER(wxHSCROLL
)
80 wxFLAGS_MEMBER(wxSP_HORIZONTAL
)
81 wxFLAGS_MEMBER(wxSP_VERTICAL
)
82 wxFLAGS_MEMBER(wxSP_ARROW_KEYS
)
83 wxFLAGS_MEMBER(wxSP_WRAP
)
85 wxEND_FLAGS( wxSpinButtonStyle
)
87 IMPLEMENT_DYNAMIC_CLASS_XTI(wxSpinButton
, wxControl
,"wx/spinbut.h")
89 wxBEGIN_PROPERTIES_TABLE(wxSpinButton
)
90 wxEVENT_RANGE_PROPERTY( Spin
, wxEVT_SCROLL_TOP
, wxEVT_SCROLL_ENDSCROLL
, wxSpinEvent
)
92 wxPROPERTY( Value
, int , SetValue
, GetValue
, 0 , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
93 wxPROPERTY( Min
, int , SetMin
, GetMin
, 0 , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
94 wxPROPERTY( Max
, int , SetMax
, GetMax
, 0 , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
95 wxPROPERTY_FLAGS( WindowStyle
, wxSpinButtonStyle
, long , SetWindowStyleFlag
, GetWindowStyleFlag
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style
96 wxEND_PROPERTIES_TABLE()
98 wxBEGIN_HANDLERS_TABLE(wxSpinButton
)
99 wxEND_HANDLERS_TABLE()
101 wxCONSTRUCTOR_5( wxSpinButton
, wxWindow
* , Parent
, wxWindowID
, Id
, wxPoint
, Position
, wxSize
, Size
, long , WindowStyle
)
103 IMPLEMENT_DYNAMIC_CLASS(wxSpinButton
, wxControl
)
108 // ----------------------------------------------------------------------------
110 // ----------------------------------------------------------------------------
112 bool wxSpinButton::Create(wxWindow
*parent
,
117 const wxString
& name
)
119 // basic initialization
120 m_windowId
= (id
== wxID_ANY
) ? NewControlId() : id
;
129 m_windowStyle
= style
;
133 // get the right size for the control
134 if ( width
<= 0 || height
<= 0 )
136 wxSize size
= DoGetBestSize();
148 // translate the styles
149 DWORD wstyle
= WS_VISIBLE
| WS_CHILD
| WS_TABSTOP
| /* WS_CLIPSIBLINGS | */
150 UDS_NOTHOUSANDS
| // never useful, sometimes harmful
151 UDS_SETBUDDYINT
; // it doesn't harm if we don't have buddy
153 if ( m_windowStyle
& wxCLIP_SIBLINGS
)
154 wstyle
|= WS_CLIPSIBLINGS
;
155 if ( m_windowStyle
& wxSP_HORIZONTAL
)
157 if ( m_windowStyle
& wxSP_ARROW_KEYS
)
158 wstyle
|= UDS_ARROWKEYS
;
159 if ( m_windowStyle
& wxSP_WRAP
)
162 // create the UpDown control.
163 m_hWnd
= (WXHWND
)CreateUpDownControl
172 m_min
// initial position
177 wxLogLastError(wxT("CreateUpDownControl"));
184 parent
->AddChild(this);
194 wxSpinButton::~wxSpinButton()
198 // ----------------------------------------------------------------------------
200 // ----------------------------------------------------------------------------
202 wxSize
wxSpinButton::DoGetBestSize() const
204 return GetBestSpinnerSize( (GetWindowStyle() & wxSP_VERTICAL
) != 0 );
207 // ----------------------------------------------------------------------------
209 // ----------------------------------------------------------------------------
211 int wxSpinButton::GetValue() const
215 if ( wxTheApp
->GetComCtl32Version() >= 580 )
217 // use the full 32 bit range if available
218 n
= ::SendMessage(GetHwnd(), UDM_GETPOS32
, 0, 0);
221 #endif // UDM_GETPOS32
223 // we're limited to 16 bit
224 n
= (short)LOWORD(::SendMessage(GetHwnd(), UDM_GETPOS
, 0, 0));
227 if (n
< m_min
) n
= m_min
;
228 if (n
> m_max
) n
= m_max
;
233 void wxSpinButton::SetValue(int val
)
235 // wxSpinButtonBase::SetValue(val); -- no, it is pure virtual
238 if ( wxTheApp
->GetComCtl32Version() >= 580 )
240 // use the full 32 bit range if available
241 ::SendMessage(GetHwnd(), UDM_SETPOS32
, 0, val
);
243 else // we're limited to 16 bit
244 #endif // UDM_SETPOS32
246 ::SendMessage(GetHwnd(), UDM_SETPOS
, 0, MAKELONG((short) val
, 0));
250 void wxSpinButton::SetRange(int minVal
, int maxVal
)
252 wxSpinButtonBase::SetRange(minVal
, maxVal
);
254 #ifdef UDM_SETRANGE32
255 if ( wxApp::GetComCtl32Version() >= 471 )
257 // use the full 32 bit range if available
258 ::SendMessage(GetHwnd(), UDM_SETRANGE32
, minVal
, maxVal
);
260 else // we're limited to 16 bit
261 #endif // UDM_SETRANGE32
263 ::SendMessage(GetHwnd(), UDM_SETRANGE
, 0,
264 (LPARAM
) MAKELONG((short)maxVal
, (short)minVal
));
268 bool wxSpinButton::MSWOnScroll(int WXUNUSED(orientation
), WXWORD wParam
,
269 WXWORD pos
, WXHWND control
)
271 wxCHECK_MSG( control
, false, wxT("scrolling what?") )
273 if ( wParam
!= SB_THUMBPOSITION
)
275 // probable SB_ENDSCROLL - we don't react to it
279 wxSpinEvent
event(wxEVT_SCROLL_THUMBTRACK
, m_windowId
);
280 event
.SetPosition((short)pos
); // cast is important for negative values!
281 event
.SetEventObject(this);
283 return GetEventHandler()->ProcessEvent(event
);
286 bool wxSpinButton::MSWOnNotify(int WXUNUSED(idCtrl
), WXLPARAM lParam
, WXLPARAM
*result
)
288 NM_UPDOWN
*lpnmud
= (NM_UPDOWN
*)lParam
;
290 if (lpnmud
->hdr
.hwndFrom
!= GetHwnd()) // make sure it is the right control
293 wxSpinEvent
event(lpnmud
->iDelta
> 0 ? wxEVT_SCROLL_LINEUP
294 : wxEVT_SCROLL_LINEDOWN
,
296 event
.SetPosition(lpnmud
->iPos
+ lpnmud
->iDelta
);
297 event
.SetEventObject(this);
299 bool processed
= GetEventHandler()->ProcessEvent(event
);
301 *result
= event
.IsAllowed() ? 0 : 1;
306 bool wxSpinButton::MSWCommand(WXUINT
WXUNUSED(cmd
), WXWORD
WXUNUSED(id
))
308 // No command messages
312 #endif // wxUSE_SPINBTN