]>
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 #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 IMPLEMENT_DYNAMIC_CLASS(wxSpinButton
, wxControl
)
33 IMPLEMENT_DYNAMIC_CLASS(wxSpinEvent
, wxScrollEvent
)
35 wxSpinButton::wxSpinButton()
40 bool wxSpinButton::Create(wxWindow
*parent
, wxWindowID id
, const wxPoint
& pos
, const wxSize
& size
,
41 long style
, const wxString
& name
)
43 m_macIsUserPane
= false ;
45 if ( !wxSpinButtonBase::Create(parent
, id
, pos
, size
,
46 style
, wxDefaultValidator
, name
) )
55 Rect bounds
= wxMacGetBoundsForControl( this , pos
, size
) ;
57 m_peer
= new wxMacControl(this) ;
58 verify_noerr ( CreateLittleArrowsControl( MAC_WXHWND(parent
->MacGetTopLevelWindowRef()) , &bounds
, 0 , m_min
, m_max
, 1 ,
59 m_peer
->GetControlRefAddr() ) );
61 m_peer
->SetActionProc( GetwxMacLiveScrollbarActionProc() ) ;
62 MacPostControlCreate(pos
,size
) ;
67 wxSpinButton::~wxSpinButton()
72 ////////////////////////////////////////////////////////////////////////////
74 int wxSpinButton::GetMin() const
79 int wxSpinButton::GetMax() const
84 int wxSpinButton::GetValue() const
88 if (n
< m_min
) n
= m_min
;
89 if (n
> m_max
) n
= m_max
;
94 void wxSpinButton::SetValue(int val
)
99 void wxSpinButton::SetRange(int minVal
, int maxVal
)
103 m_peer
->SetMaximum( maxVal
) ;
104 m_peer
->SetMinimum( minVal
) ;
107 void wxSpinButton::MacHandleValueChanged( int inc
)
110 wxEventType scrollEvent
= wxEVT_NULL
;
111 int oldValue
= m_value
;
113 m_value
= oldValue
+ inc
;
117 if ( m_windowStyle
& wxSP_WRAP
)
125 if ( m_windowStyle
& wxSP_WRAP
)
131 if ( m_value
- oldValue
== -1 )
132 scrollEvent
= wxEVT_SCROLL_LINEDOWN
;
133 else if ( m_value
- oldValue
== 1 )
134 scrollEvent
= wxEVT_SCROLL_LINEUP
;
136 scrollEvent
= wxEVT_SCROLL_THUMBTRACK
;
138 wxSpinEvent
event(scrollEvent
, m_windowId
);
140 event
.SetPosition(m_value
);
141 event
.SetEventObject( this );
142 if ((GetEventHandler()->ProcessEvent( event
)) &&
147 m_peer
->SetValue( m_value
) ;
149 /* always send a thumbtrack event */
150 if (scrollEvent
!= wxEVT_SCROLL_THUMBTRACK
)
152 scrollEvent
= wxEVT_SCROLL_THUMBTRACK
;
153 wxSpinEvent
event2( scrollEvent
, GetId());
154 event2
.SetPosition( m_value
);
155 event2
.SetEventObject( this );
156 GetEventHandler()->ProcessEvent( event2
);
160 void wxSpinButton::MacHandleControlClick( WXWidget control
, wxInt16 controlpart
, bool mouseStillDown
)
164 switch( controlpart
)
166 case kControlUpButtonPart
:
169 case kControlDownButtonPart
:
173 MacHandleValueChanged( nScrollInc
) ;
176 wxInt32
wxSpinButton::MacControlHit(WXEVENTHANDLERREF
WXUNUSED(handler
) , WXEVENTREF 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 :
188 case kControlDownButtonPart :
192 MacHandleValueChanged( nScrollInc ) ;
197 // ----------------------------------------------------------------------------
199 // ----------------------------------------------------------------------------
201 wxSize
wxSpinButton::DoGetBestSize() const
203 return wxSize(16,24);
206 #endif // wxUSE_SPINBTN