]>
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 // Do not send an event if the value has not actually changed
128 // (Also works for wxSpinCtrl)
129 if ( m_value
== oldValue
)
132 wxSpinEvent
event( scrollEvent
, m_windowId
);
134 event
.SetPosition( m_value
);
135 event
.SetEventObject( this );
136 if ((GetEventHandler()->ProcessEvent( event
)) && !event
.IsAllowed())
139 m_peer
->SetValue( m_value
);
141 // always send a thumbtrack event
142 if (scrollEvent
!= wxEVT_SCROLL_THUMBTRACK
)
144 scrollEvent
= wxEVT_SCROLL_THUMBTRACK
;
145 wxSpinEvent
event2( scrollEvent
, GetId() );
146 event2
.SetPosition( m_value
);
147 event2
.SetEventObject( this );
148 GetEventHandler()->ProcessEvent( event2
);
152 void wxSpinButton::MacHandleControlClick(WXWidget
WXUNUSED(control
),
154 bool WXUNUSED(mouseStillDown
))
158 switch ( controlpart
)
160 case kControlUpButtonPart
:
164 case kControlDownButtonPart
:
172 MacHandleValueChanged( nScrollInc
) ;
175 wxInt32
wxSpinButton::MacControlHit(WXEVENTHANDLERREF
WXUNUSED(handler
),
176 WXEVENTREF
WXUNUSED(event
))
179 // these have been handled by the live action proc already
181 wxMacCarbonEvent
cEvent( (EventRef
)event
);
183 switch ( cEvent
.GetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
) )
185 case kControlUpButtonPart
:
189 case kControlDownButtonPart
:
197 MacHandleValueChanged( nScrollInc
) ;
203 wxSize
wxSpinButton::DoGetBestSize() const
205 return wxSize( 16, 24 );
208 #endif // wxUSE_SPINBTN