]>
git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/spinbutt.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxSpinButton
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #include "wx/wxprec.h"
16 #include "wx/spinbutt.h"
17 #include "wx/mac/uma.h"
20 IMPLEMENT_DYNAMIC_CLASS(wxSpinButton
, wxControl
)
21 IMPLEMENT_DYNAMIC_CLASS(wxSpinEvent
, wxScrollEvent
)
24 wxSpinButton::wxSpinButton()
29 bool wxSpinButton::Create( wxWindow
*parent
,
30 wxWindowID id
, const wxPoint
& pos
, const wxSize
& size
,
31 long style
, const wxString
& name
)
33 m_macIsUserPane
= false;
35 if ( !wxSpinButtonBase::Create( parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
44 Rect bounds
= wxMacGetBoundsForControl( this , pos
, size
);
46 m_peer
= new wxMacControl( this );
47 OSStatus err
= CreateLittleArrowsControl(
48 MAC_WXHWND(parent
->MacGetTopLevelWindowRef()), &bounds
, 0, m_min
, m_max
, 1,
49 m_peer
->GetControlRefAddr() );
52 m_peer
->SetActionProc( GetwxMacLiveScrollbarActionProc() );
53 MacPostControlCreate( pos
, size
);
58 wxSpinButton::~wxSpinButton()
62 int wxSpinButton::GetMin() const
67 int wxSpinButton::GetMax() const
72 int wxSpinButton::GetValue() const
84 void wxSpinButton::SetValue(int val
)
89 void wxSpinButton::SetRange(int minVal
, int maxVal
)
93 m_peer
->SetMaximum( maxVal
);
94 m_peer
->SetMinimum( minVal
);
97 void wxSpinButton::MacHandleValueChanged( int inc
)
99 wxEventType scrollEvent
= wxEVT_NULL
;
100 int oldValue
= m_value
;
102 m_value
= oldValue
+ inc
;
106 if ( m_windowStyle
& wxSP_WRAP
)
114 if ( m_windowStyle
& wxSP_WRAP
)
120 if ( m_value
- oldValue
== -1 )
121 scrollEvent
= wxEVT_SCROLL_LINEDOWN
;
122 else if ( m_value
- oldValue
== 1 )
123 scrollEvent
= wxEVT_SCROLL_LINEUP
;
125 scrollEvent
= wxEVT_SCROLL_THUMBTRACK
;
127 wxSpinEvent
event( scrollEvent
, m_windowId
);
129 event
.SetPosition( m_value
);
130 event
.SetEventObject( this );
131 if ((GetEventHandler()->ProcessEvent( event
)) && !event
.IsAllowed())
134 m_peer
->SetValue( m_value
);
136 // always send a thumbtrack event
137 if (scrollEvent
!= wxEVT_SCROLL_THUMBTRACK
)
139 scrollEvent
= wxEVT_SCROLL_THUMBTRACK
;
140 wxSpinEvent
event2( scrollEvent
, GetId() );
141 event2
.SetPosition( m_value
);
142 event2
.SetEventObject( this );
143 GetEventHandler()->ProcessEvent( event2
);
147 void wxSpinButton::MacHandleControlClick( WXWidget control
, wxInt16 controlpart
, bool mouseStillDown
)
151 switch ( controlpart
)
153 case kControlUpButtonPart
:
157 case kControlDownButtonPart
:
165 MacHandleValueChanged( nScrollInc
) ;
168 wxInt32
wxSpinButton::MacControlHit(WXEVENTHANDLERREF
WXUNUSED(handler
) , WXEVENTREF event
)
171 // these have been handled by the live action proc already
173 wxMacCarbonEvent
cEvent( (EventRef
)event
);
175 switch ( cEvent
.GetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
) )
177 case kControlUpButtonPart
:
181 case kControlDownButtonPart
:
189 MacHandleValueChanged( nScrollInc
) ;
195 wxSize
wxSpinButton::DoGetBestSize() const
197 return wxSize( 16, 24 );
200 #endif // wxUSE_SPINBTN