]>
git.saurik.com Git - wxWidgets.git/blob - src/osx/spinbutt_osx.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/osx/private.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 m_peer
= wxWidgetImpl::CreateSpinButton( this , parent
, id
, 0, m_min
, m_max
, pos
, size
,
45 style
, GetExtraStyle() );
47 MacPostControlCreate( pos
, size
);
52 wxSpinButton::~wxSpinButton()
56 void wxSpinButton::SetValue( int val
)
58 m_peer
->SetValue( val
);
61 int wxSpinButton::GetValue() const
63 return m_peer
->GetValue();
66 void wxSpinButton::SetRange(int minVal
, int maxVal
)
70 m_peer
->SetMaximum( maxVal
);
71 m_peer
->SetMinimum( minVal
);
74 void wxSpinButton::SendThumbTrackEvent()
76 wxSpinEvent
event( wxEVT_SCROLL_THUMBTRACK
, GetId() );
77 event
.SetPosition( GetValue() );
78 event
.SetEventObject( this );
79 HandleWindowEvent( event
);
82 bool wxSpinButton::OSXHandleClicked( double WXUNUSED(timestampsec
) )
84 // all events have already been processed
88 wxSize
wxSpinButton::DoGetBestSize() const
90 return wxSize( 16, 24 );
93 void wxSpinButton::TriggerScrollEvent(wxEventType scrollEvent
)
97 if ( scrollEvent
== wxEVT_SCROLL_LINEUP
)
101 else if ( scrollEvent
== wxEVT_SCROLL_LINEDOWN
)
106 // trigger scroll events
108 int oldValue
= GetValue() ;
110 int newValue
= oldValue
+ inc
;
112 if (newValue
< m_min
)
114 if ( m_windowStyle
& wxSP_WRAP
)
120 if (newValue
> m_max
)
122 if ( m_windowStyle
& wxSP_WRAP
)
128 if ( newValue
- oldValue
== -1 )
129 scrollEvent
= wxEVT_SCROLL_LINEDOWN
;
130 else if ( newValue
- oldValue
== 1 )
131 scrollEvent
= wxEVT_SCROLL_LINEUP
;
133 scrollEvent
= wxEVT_SCROLL_THUMBTRACK
;
135 // Do not send an event if the value has not actually changed
136 // (Also works for wxSpinCtrl)
137 if ( newValue
== oldValue
)
140 if ( scrollEvent
!= wxEVT_SCROLL_THUMBTRACK
)
142 wxSpinEvent
event( scrollEvent
, m_windowId
);
144 event
.SetPosition( newValue
);
145 event
.SetEventObject( this );
146 if ((HandleWindowEvent( event
)) && !event
.IsAllowed())
150 m_peer
->SetValue( newValue
);
152 // always send a thumbtrack event
153 SendThumbTrackEvent() ;
156 #endif // wxUSE_SPINBTN