1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxSpinButton
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "spinbutt.h"
14 #pragma implementation "spinbuttbase.h"
17 #include "wx/spinbutt.h"
18 #include "wx/mac/uma.h"
20 // ============================================================================
22 // ============================================================================
24 // ----------------------------------------------------------------------------
26 // ----------------------------------------------------------------------------
28 #if !USE_SHARED_LIBRARY
29 IMPLEMENT_DYNAMIC_CLASS(wxSpinButton
, wxControl
)
30 IMPLEMENT_DYNAMIC_CLASS(wxSpinEvent
, wxScrollEvent
)
33 extern ControlActionUPP wxMacLiveScrollbarActionUPP
;
35 wxSpinButton::wxSpinButton()
40 bool wxSpinButton::Create(wxWindow
*parent
, wxWindowID id
, const wxPoint
& pos
, const wxSize
& size
,
41 long style
, const wxString
& name
)
43 m_macIsUserPane
= FALSE
;
45 if ( !wxSpinButtonBase::Create(parent
, id
, pos
, size
,
46 style
, wxDefaultValidator
, name
) )
55 Rect bounds
= wxMacGetBoundsForControl( this , pos
, size
) ;
57 verify_noerr ( CreateLittleArrowsControl( MAC_WXHWND(parent
->MacGetTopLevelWindowRef()) , &bounds
, 0 , m_min
, m_max
, 1 ,
58 (ControlRef
*) &m_macControl
) ) ;
59 SetControlAction( (ControlRef
) m_macControl
, wxMacLiveScrollbarActionUPP
) ;
60 MacPostControlCreate(pos
,size
) ;
65 wxSpinButton::~wxSpinButton()
70 ////////////////////////////////////////////////////////////////////////////
72 int wxSpinButton::GetMin() const
77 int wxSpinButton::GetMax() const
82 int wxSpinButton::GetValue() const
87 void wxSpinButton::SetValue(int val
)
92 void wxSpinButton::SetRange(int minVal
, int maxVal
)
96 SetControl32BitMaximum( (ControlRef
) m_macControl
, maxVal
) ;
97 SetControl32BitMinimum((ControlRef
) m_macControl
, minVal
) ;
100 void wxSpinButton::MacHandleValueChanged( int inc
)
103 wxEventType scrollEvent
= wxEVT_NULL
;
104 int oldValue
= m_value
;
106 m_value
= oldValue
+ inc
;
110 if ( m_windowStyle
& wxSP_WRAP
)
118 if ( m_windowStyle
& wxSP_WRAP
)
124 if ( m_value
- oldValue
== -1 )
125 scrollEvent
= wxEVT_SCROLL_LINEDOWN
;
126 else if ( m_value
- oldValue
== 1 )
127 scrollEvent
= wxEVT_SCROLL_LINEUP
;
129 scrollEvent
= wxEVT_SCROLL_THUMBTRACK
;
131 wxSpinEvent
event(scrollEvent
, m_windowId
);
133 event
.SetPosition(m_value
);
134 event
.SetEventObject( this );
135 if ((GetEventHandler()->ProcessEvent( event
)) &&
140 SetControl32BitValue( (ControlRef
) m_macControl
, m_value
) ;
142 /* always send a thumbtrack event */
143 if (scrollEvent
!= wxEVT_SCROLL_THUMBTRACK
)
145 scrollEvent
= wxEVT_SCROLL_THUMBTRACK
;
146 wxSpinEvent
event2( scrollEvent
, GetId());
147 event2
.SetPosition( m_value
);
148 event2
.SetEventObject( this );
149 GetEventHandler()->ProcessEvent( event2
);
153 void wxSpinButton::MacHandleControlClick( WXWidget control
, wxInt16 controlpart
, bool mouseStillDown
)
157 switch( controlpart
)
159 case kControlUpButtonPart
:
162 case kControlDownButtonPart
:
166 MacHandleValueChanged( nScrollInc
) ;
169 wxInt32
wxSpinButton::MacControlHit(WXEVENTHANDLERREF
WXUNUSED(handler
) , WXEVENTREF event
)
172 // these have been handled by the live action proc already
174 wxMacCarbonEvent cEvent( (EventRef) event ) ;
176 switch( cEvent.GetParameter<ControlPartCode>(kEventParamControlPart,typeControlPartCode) )
178 case kControlUpButtonPart :
181 case kControlDownButtonPart :
185 MacHandleValueChanged( nScrollInc ) ;
190 // ----------------------------------------------------------------------------
192 // ----------------------------------------------------------------------------
194 wxSize
wxSpinButton::DoGetBestSize() const
196 return wxSize(16,24);