1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxSpinButton
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
13 #pragma implementation "spinbutt.h"
14 #pragma implementation "spinbuttbase.h"
17 #include "wx/wxprec.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
92 if (n
< m_min
) n
= m_min
;
93 if (n
> m_max
) n
= m_max
;
98 void wxSpinButton::SetValue(int val
)
103 void wxSpinButton::SetRange(int minVal
, int maxVal
)
107 m_peer
->SetMaximum( maxVal
) ;
108 m_peer
->SetMinimum( minVal
) ;
111 void wxSpinButton::MacHandleValueChanged( int inc
)
114 wxEventType scrollEvent
= wxEVT_NULL
;
115 int oldValue
= m_value
;
117 m_value
= oldValue
+ inc
;
121 if ( m_windowStyle
& wxSP_WRAP
)
129 if ( m_windowStyle
& wxSP_WRAP
)
135 if ( m_value
- oldValue
== -1 )
136 scrollEvent
= wxEVT_SCROLL_LINEDOWN
;
137 else if ( m_value
- oldValue
== 1 )
138 scrollEvent
= wxEVT_SCROLL_LINEUP
;
140 scrollEvent
= wxEVT_SCROLL_THUMBTRACK
;
142 wxSpinEvent
event(scrollEvent
, m_windowId
);
144 event
.SetPosition(m_value
);
145 event
.SetEventObject( this );
146 if ((GetEventHandler()->ProcessEvent( event
)) &&
151 m_peer
->SetValue( m_value
) ;
153 /* always send a thumbtrack event */
154 if (scrollEvent
!= wxEVT_SCROLL_THUMBTRACK
)
156 scrollEvent
= wxEVT_SCROLL_THUMBTRACK
;
157 wxSpinEvent
event2( scrollEvent
, GetId());
158 event2
.SetPosition( m_value
);
159 event2
.SetEventObject( this );
160 GetEventHandler()->ProcessEvent( event2
);
164 void wxSpinButton::MacHandleControlClick( WXWidget control
, wxInt16 controlpart
, bool mouseStillDown
)
168 switch( controlpart
)
170 case kControlUpButtonPart
:
173 case kControlDownButtonPart
:
177 MacHandleValueChanged( nScrollInc
) ;
180 wxInt32
wxSpinButton::MacControlHit(WXEVENTHANDLERREF
WXUNUSED(handler
) , WXEVENTREF event
)
183 // these have been handled by the live action proc already
185 wxMacCarbonEvent cEvent( (EventRef) event ) ;
187 switch( cEvent.GetParameter<ControlPartCode>(kEventParamControlPart,typeControlPartCode) )
189 case kControlUpButtonPart :
192 case kControlDownButtonPart :
196 MacHandleValueChanged( nScrollInc ) ;
201 // ----------------------------------------------------------------------------
203 // ----------------------------------------------------------------------------
205 wxSize
wxSpinButton::DoGetBestSize() const
207 return wxSize(16,24);
210 #endif // wxUSE_SPINBTN