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"
21 #include "wx/spinbutt.h"
22 #include "wx/mac/uma.h"
24 // ============================================================================
26 // ============================================================================
28 // ----------------------------------------------------------------------------
30 // ----------------------------------------------------------------------------
32 #if !USE_SHARED_LIBRARY
33 IMPLEMENT_DYNAMIC_CLASS(wxSpinButton
, wxControl
)
34 IMPLEMENT_DYNAMIC_CLASS(wxSpinEvent
, wxScrollEvent
)
37 extern ControlActionUPP wxMacLiveScrollbarActionUPP
;
39 wxSpinButton::wxSpinButton()
44 bool wxSpinButton::Create(wxWindow
*parent
, wxWindowID id
, const wxPoint
& pos
, const wxSize
& size
,
45 long style
, const wxString
& name
)
47 m_macIsUserPane
= false ;
49 if ( !wxSpinButtonBase::Create(parent
, id
, pos
, size
,
50 style
, wxDefaultValidator
, name
) )
59 Rect bounds
= wxMacGetBoundsForControl( this , pos
, size
) ;
61 m_peer
= new wxMacControl() ;
62 verify_noerr ( CreateLittleArrowsControl( MAC_WXHWND(parent
->MacGetTopLevelWindowRef()) , &bounds
, 0 , m_min
, m_max
, 1 ,
63 m_peer
->GetControlRefAddr() ) );
65 m_peer
->SetActionProc( wxMacLiveScrollbarActionUPP
) ;
66 MacPostControlCreate(pos
,size
) ;
71 wxSpinButton::~wxSpinButton()
76 ////////////////////////////////////////////////////////////////////////////
78 int wxSpinButton::GetMin() const
83 int wxSpinButton::GetMax() const
88 int wxSpinButton::GetValue() const
93 void wxSpinButton::SetValue(int val
)
98 void wxSpinButton::SetRange(int minVal
, int maxVal
)
102 m_peer
->SetMaximum( maxVal
) ;
103 m_peer
->SetMinimum( minVal
) ;
106 void wxSpinButton::MacHandleValueChanged( int inc
)
109 wxEventType scrollEvent
= wxEVT_NULL
;
110 int oldValue
= m_value
;
112 m_value
= oldValue
+ inc
;
116 if ( m_windowStyle
& wxSP_WRAP
)
124 if ( m_windowStyle
& wxSP_WRAP
)
130 if ( m_value
- oldValue
== -1 )
131 scrollEvent
= wxEVT_SCROLL_LINEDOWN
;
132 else if ( m_value
- oldValue
== 1 )
133 scrollEvent
= wxEVT_SCROLL_LINEUP
;
135 scrollEvent
= wxEVT_SCROLL_THUMBTRACK
;
137 wxSpinEvent
event(scrollEvent
, m_windowId
);
139 event
.SetPosition(m_value
);
140 event
.SetEventObject( this );
141 if ((GetEventHandler()->ProcessEvent( event
)) &&
146 m_peer
->SetValue( m_value
) ;
148 /* always send a thumbtrack event */
149 if (scrollEvent
!= wxEVT_SCROLL_THUMBTRACK
)
151 scrollEvent
= wxEVT_SCROLL_THUMBTRACK
;
152 wxSpinEvent
event2( scrollEvent
, GetId());
153 event2
.SetPosition( m_value
);
154 event2
.SetEventObject( this );
155 GetEventHandler()->ProcessEvent( event2
);
159 void wxSpinButton::MacHandleControlClick( WXWidget control
, wxInt16 controlpart
, bool mouseStillDown
)
163 switch( controlpart
)
165 case kControlUpButtonPart
:
168 case kControlDownButtonPart
:
172 MacHandleValueChanged( nScrollInc
) ;
175 wxInt32
wxSpinButton::MacControlHit(WXEVENTHANDLERREF
WXUNUSED(handler
) , WXEVENTREF event
)
178 // these have been handled by the live action proc already
180 wxMacCarbonEvent cEvent( (EventRef) event ) ;
182 switch( cEvent.GetParameter<ControlPartCode>(kEventParamControlPart,typeControlPartCode) )
184 case kControlUpButtonPart :
187 case kControlDownButtonPart :
191 MacHandleValueChanged( nScrollInc ) ;
196 // ----------------------------------------------------------------------------
198 // ----------------------------------------------------------------------------
200 wxSize
wxSpinButton::DoGetBestSize() const
202 return wxSize(16,24);
205 #endif // wxUSE_SPINBTN