]>
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"
19 // ============================================================================
21 // ============================================================================
23 // ----------------------------------------------------------------------------
25 // ----------------------------------------------------------------------------
27 IMPLEMENT_DYNAMIC_CLASS(wxSpinButton
, wxControl
)
28 IMPLEMENT_DYNAMIC_CLASS(wxSpinEvent
, wxScrollEvent
)
30 wxSpinButton::wxSpinButton()
35 bool wxSpinButton::Create(wxWindow
*parent
, wxWindowID id
, const wxPoint
& pos
, const wxSize
& size
,
36 long style
, const wxString
& name
)
38 m_macIsUserPane
= false ;
40 if ( !wxSpinButtonBase::Create(parent
, id
, pos
, size
,
41 style
, wxDefaultValidator
, name
) )
50 Rect bounds
= wxMacGetBoundsForControl( this , pos
, size
) ;
52 m_peer
= new wxMacControl(this) ;
53 verify_noerr ( CreateLittleArrowsControl( MAC_WXHWND(parent
->MacGetTopLevelWindowRef()) , &bounds
, 0 , m_min
, m_max
, 1 ,
54 m_peer
->GetControlRefAddr() ) );
56 m_peer
->SetActionProc( GetwxMacLiveScrollbarActionProc() ) ;
57 MacPostControlCreate(pos
,size
) ;
62 wxSpinButton::~wxSpinButton()
67 ////////////////////////////////////////////////////////////////////////////
69 int wxSpinButton::GetMin() const
74 int wxSpinButton::GetMax() const
79 int wxSpinButton::GetValue() const
83 if (n
< m_min
) n
= m_min
;
84 if (n
> m_max
) n
= m_max
;
89 void wxSpinButton::SetValue(int val
)
94 void wxSpinButton::SetRange(int minVal
, int maxVal
)
98 m_peer
->SetMaximum( maxVal
) ;
99 m_peer
->SetMinimum( 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 m_peer
->SetValue( 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);
201 #endif // wxUSE_SPINBTN