]>
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 #include "wx/msw/private.h"
43 #include "wx/msw/wrapcctl.h"
45 // ============================================================================
47 // ============================================================================
49 // ----------------------------------------------------------------------------
51 // ----------------------------------------------------------------------------
54 #if wxUSE_EXTENDED_RTTI
55 WX_DEFINE_FLAGS( wxSpinButtonStyle
)
57 wxBEGIN_FLAGS( wxSpinButtonStyle
)
58 // new style border flags, we put them first to
59 // use them for streaming out
60 wxFLAGS_MEMBER(wxBORDER_SIMPLE
)
61 wxFLAGS_MEMBER(wxBORDER_SUNKEN
)
62 wxFLAGS_MEMBER(wxBORDER_DOUBLE
)
63 wxFLAGS_MEMBER(wxBORDER_RAISED
)
64 wxFLAGS_MEMBER(wxBORDER_STATIC
)
65 wxFLAGS_MEMBER(wxBORDER_NONE
)
67 // old style border flags
68 wxFLAGS_MEMBER(wxSIMPLE_BORDER
)
69 wxFLAGS_MEMBER(wxSUNKEN_BORDER
)
70 wxFLAGS_MEMBER(wxDOUBLE_BORDER
)
71 wxFLAGS_MEMBER(wxRAISED_BORDER
)
72 wxFLAGS_MEMBER(wxSTATIC_BORDER
)
73 wxFLAGS_MEMBER(wxBORDER
)
75 // standard window styles
76 wxFLAGS_MEMBER(wxTAB_TRAVERSAL
)
77 wxFLAGS_MEMBER(wxCLIP_CHILDREN
)
78 wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW
)
79 wxFLAGS_MEMBER(wxWANTS_CHARS
)
80 wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE
)
81 wxFLAGS_MEMBER(wxALWAYS_SHOW_SB
)
82 wxFLAGS_MEMBER(wxVSCROLL
)
83 wxFLAGS_MEMBER(wxHSCROLL
)
85 wxFLAGS_MEMBER(wxSP_HORIZONTAL
)
86 wxFLAGS_MEMBER(wxSP_VERTICAL
)
87 wxFLAGS_MEMBER(wxSP_ARROW_KEYS
)
88 wxFLAGS_MEMBER(wxSP_WRAP
)
90 wxEND_FLAGS( wxSpinButtonStyle
)
92 IMPLEMENT_DYNAMIC_CLASS_XTI(wxSpinButton
, wxControl
,"wx/spinbut.h")
94 wxBEGIN_PROPERTIES_TABLE(wxSpinButton
)
95 wxEVENT_RANGE_PROPERTY( Spin
, wxEVT_SCROLL_TOP
, wxEVT_SCROLL_ENDSCROLL
, wxSpinEvent
)
97 wxPROPERTY( Value
, int , SetValue
, GetValue
, 0 , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
98 wxPROPERTY( Min
, int , SetMin
, GetMin
, 0 , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
99 wxPROPERTY( Max
, int , SetMax
, GetMax
, 0 , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
100 wxPROPERTY_FLAGS( WindowStyle
, wxSpinButtonStyle
, long , SetWindowStyleFlag
, GetWindowStyleFlag
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style
101 wxEND_PROPERTIES_TABLE()
103 wxBEGIN_HANDLERS_TABLE(wxSpinButton
)
104 wxEND_HANDLERS_TABLE()
106 wxCONSTRUCTOR_5( wxSpinButton
, wxWindow
* , Parent
, wxWindowID
, Id
, wxPoint
, Position
, wxSize
, Size
, long , WindowStyle
)
108 IMPLEMENT_DYNAMIC_CLASS(wxSpinButton
, wxControl
)
113 // ----------------------------------------------------------------------------
115 // ----------------------------------------------------------------------------
117 bool wxSpinButton::Create(wxWindow
*parent
,
122 const wxString
& name
)
124 // basic initialization
125 m_windowId
= (id
== wxID_ANY
) ? NewControlId() : id
;
134 m_windowStyle
= style
;
138 // get the right size for the control
139 if ( width
<= 0 || height
<= 0 )
141 wxSize size
= DoGetBestSize();
153 // translate the styles
154 DWORD wstyle
= WS_VISIBLE
| WS_CHILD
| WS_TABSTOP
| /* WS_CLIPSIBLINGS | */
155 UDS_NOTHOUSANDS
| // never useful, sometimes harmful
156 UDS_SETBUDDYINT
; // it doesn't harm if we don't have buddy
158 if ( m_windowStyle
& wxCLIP_SIBLINGS
)
159 wstyle
|= WS_CLIPSIBLINGS
;
160 if ( m_windowStyle
& wxSP_HORIZONTAL
)
162 if ( m_windowStyle
& wxSP_ARROW_KEYS
)
163 wstyle
|= UDS_ARROWKEYS
;
164 if ( m_windowStyle
& wxSP_WRAP
)
167 // create the UpDown control.
168 m_hWnd
= (WXHWND
)CreateUpDownControl
177 m_min
// initial position
182 wxLogLastError(wxT("CreateUpDownControl"));
189 parent
->AddChild(this);
199 wxSpinButton::~wxSpinButton()
203 // ----------------------------------------------------------------------------
205 // ----------------------------------------------------------------------------
207 wxSize
wxSpinButton::DoGetBestSize() const
209 return GetBestSpinnerSize( (GetWindowStyle() & wxSP_VERTICAL
) != 0 );
212 // ----------------------------------------------------------------------------
214 // ----------------------------------------------------------------------------
216 int wxSpinButton::GetValue() const
220 if ( wxTheApp
->GetComCtl32Version() >= 580 )
222 // use the full 32 bit range if available
223 n
= ::SendMessage(GetHwnd(), UDM_GETPOS32
, 0, 0);
226 #endif // UDM_GETPOS32
228 // we're limited to 16 bit
229 n
= (short)LOWORD(::SendMessage(GetHwnd(), UDM_GETPOS
, 0, 0));
232 if (n
< m_min
) n
= m_min
;
233 if (n
> m_max
) n
= m_max
;
238 void wxSpinButton::SetValue(int val
)
240 // wxSpinButtonBase::SetValue(val); -- no, it is pure virtual
243 if ( wxTheApp
->GetComCtl32Version() >= 580 )
245 // use the full 32 bit range if available
246 ::SendMessage(GetHwnd(), UDM_SETPOS32
, 0, val
);
248 else // we're limited to 16 bit
249 #endif // UDM_SETPOS32
251 ::SendMessage(GetHwnd(), UDM_SETPOS
, 0, MAKELONG((short) val
, 0));
255 void wxSpinButton::SetRange(int minVal
, int maxVal
)
257 wxSpinButtonBase::SetRange(minVal
, maxVal
);
259 #ifdef UDM_SETRANGE32
260 if ( wxTheApp
->GetComCtl32Version() >= 471 )
262 // use the full 32 bit range if available
263 ::SendMessage(GetHwnd(), UDM_SETRANGE32
, minVal
, maxVal
);
265 else // we're limited to 16 bit
266 #endif // UDM_SETRANGE32
268 ::SendMessage(GetHwnd(), UDM_SETRANGE
, 0,
269 (LPARAM
) MAKELONG((short)maxVal
, (short)minVal
));
273 bool wxSpinButton::MSWOnScroll(int WXUNUSED(orientation
), WXWORD wParam
,
274 WXWORD pos
, WXHWND control
)
276 wxCHECK_MSG( control
, false, wxT("scrolling what?") )
278 if ( wParam
!= SB_THUMBPOSITION
)
280 // probable SB_ENDSCROLL - we don't react to it
284 wxSpinEvent
event(wxEVT_SCROLL_THUMBTRACK
, m_windowId
);
285 event
.SetPosition((short)pos
); // cast is important for negative values!
286 event
.SetEventObject(this);
288 return GetEventHandler()->ProcessEvent(event
);
291 bool wxSpinButton::MSWOnNotify(int WXUNUSED(idCtrl
), WXLPARAM lParam
, WXLPARAM
*result
)
293 NM_UPDOWN
*lpnmud
= (NM_UPDOWN
*)lParam
;
295 if (lpnmud
->hdr
.hwndFrom
!= GetHwnd()) // make sure it is the right control
298 wxSpinEvent
event(lpnmud
->iDelta
> 0 ? wxEVT_SCROLL_LINEUP
299 : wxEVT_SCROLL_LINEDOWN
,
301 event
.SetPosition(lpnmud
->iPos
+ lpnmud
->iDelta
);
302 event
.SetEventObject(this);
304 bool processed
= GetEventHandler()->ProcessEvent(event
);
306 *result
= event
.IsAllowed() ? 0 : 1;
311 bool wxSpinButton::MSWCommand(WXUINT
WXUNUSED(cmd
), WXWORD
WXUNUSED(id
))
313 // No command messages
317 #endif // wxUSE_SPINBTN