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 m_peer
= new wxMacControl() ;
58 verify_noerr ( CreateLittleArrowsControl( MAC_WXHWND(parent
->MacGetTopLevelWindowRef()) , &bounds
, 0 , m_min
, m_max
, 1 ,
61 SetControlAction( *m_peer
, wxMacLiveScrollbarActionUPP
) ;
62 MacPostControlCreate(pos
,size
) ;
67 wxSpinButton::~wxSpinButton()
72 ////////////////////////////////////////////////////////////////////////////
74 int wxSpinButton::GetMin() const
79 int wxSpinButton::GetMax() const
84 int wxSpinButton::GetValue() const
89 void wxSpinButton::SetValue(int val
)
94 void wxSpinButton::SetRange(int minVal
, int maxVal
)
98 SetControl32BitMaximum( *m_peer
, maxVal
) ;
99 SetControl32BitMinimum(*m_peer
, minVal
) ;
102 void wxSpinButton::MacHandleValueChanged( int inc
)
105 wxEventType scrollEvent
= wxEVT_NULL
;
106 int oldValue
= m_value
;
108 m_value
= oldValue
+ inc
;
112 if ( m_windowStyle
& wxSP_WRAP
)
120 if ( m_windowStyle
& wxSP_WRAP
)
126 if ( m_value
- oldValue
== -1 )
127 scrollEvent
= wxEVT_SCROLL_LINEDOWN
;
128 else if ( m_value
- oldValue
== 1 )
129 scrollEvent
= wxEVT_SCROLL_LINEUP
;
131 scrollEvent
= wxEVT_SCROLL_THUMBTRACK
;
133 wxSpinEvent
event(scrollEvent
, m_windowId
);
135 event
.SetPosition(m_value
);
136 event
.SetEventObject( this );
137 if ((GetEventHandler()->ProcessEvent( event
)) &&
142 SetControl32BitValue( *m_peer
, m_value
) ;
144 /* always send a thumbtrack event */
145 if (scrollEvent
!= wxEVT_SCROLL_THUMBTRACK
)
147 scrollEvent
= wxEVT_SCROLL_THUMBTRACK
;
148 wxSpinEvent
event2( scrollEvent
, GetId());
149 event2
.SetPosition( m_value
);
150 event2
.SetEventObject( this );
151 GetEventHandler()->ProcessEvent( event2
);
155 void wxSpinButton::MacHandleControlClick( WXWidget control
, wxInt16 controlpart
, bool mouseStillDown
)
159 switch( controlpart
)
161 case kControlUpButtonPart
:
164 case kControlDownButtonPart
:
168 MacHandleValueChanged( nScrollInc
) ;
171 wxInt32
wxSpinButton::MacControlHit(WXEVENTHANDLERREF
WXUNUSED(handler
) , WXEVENTREF event
)
174 // these have been handled by the live action proc already
176 wxMacCarbonEvent cEvent( (EventRef) event ) ;
178 switch( cEvent.GetParameter<ControlPartCode>(kEventParamControlPart,typeControlPartCode) )
180 case kControlUpButtonPart :
183 case kControlDownButtonPart :
187 MacHandleValueChanged( nScrollInc ) ;
192 // ----------------------------------------------------------------------------
194 // ----------------------------------------------------------------------------
196 wxSize
wxSpinButton::DoGetBestSize() const
198 return wxSize(16,24);