]>
git.saurik.com Git - wxWidgets.git/blob - src/osx/spinbutt_osx.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/spinbutt_osx.cpp
3 // Purpose: wxSpinButton
4 // Author: Stefan Csomor
7 // Copyright: (c) Stefan Csomor
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 #include "wx/wxprec.h"
15 #include "wx/spinbutt.h"
16 #include "wx/osx/private.h"
19 wxSpinButton::wxSpinButton()
24 bool wxSpinButton::Create( wxWindow
*parent
,
25 wxWindowID id
, const wxPoint
& pos
, const wxSize
& size
,
26 long style
, const wxString
& name
)
29 if ( !wxSpinButtonBase::Create( parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
38 SetPeer(wxWidgetImpl::CreateSpinButton( this , parent
, id
, 0, m_min
, m_max
, pos
, size
,
39 style
, GetExtraStyle() ));
41 MacPostControlCreate( pos
, size
);
46 wxSpinButton::~wxSpinButton()
50 void wxSpinButton::SetValue( int val
)
52 GetPeer()->SetValue( val
);
55 int wxSpinButton::GetValue() const
57 return GetPeer()->GetValue();
60 void wxSpinButton::SetRange(int minVal
, int maxVal
)
64 GetPeer()->SetMaximum( maxVal
);
65 GetPeer()->SetMinimum( minVal
);
68 void wxSpinButton::SendThumbTrackEvent()
70 wxSpinEvent
event( wxEVT_SCROLL_THUMBTRACK
, GetId() );
71 event
.SetPosition( GetValue() );
72 event
.SetEventObject( this );
73 HandleWindowEvent( event
);
76 bool wxSpinButton::OSXHandleClicked( double WXUNUSED(timestampsec
) )
78 // all events have already been processed
82 wxSize
wxSpinButton::DoGetBestSize() const
84 return wxSize( 16, 24 );
87 void wxSpinButton::TriggerScrollEvent(wxEventType scrollEvent
)
91 if ( scrollEvent
== wxEVT_SCROLL_LINEUP
)
95 else if ( scrollEvent
== wxEVT_SCROLL_LINEDOWN
)
100 // trigger scroll events
102 int oldValue
= GetValue() ;
104 int newValue
= oldValue
+ inc
;
106 if (newValue
< m_min
)
108 if ( m_windowStyle
& wxSP_WRAP
)
114 if (newValue
> m_max
)
116 if ( m_windowStyle
& wxSP_WRAP
)
122 if ( newValue
- oldValue
== -1 )
123 scrollEvent
= wxEVT_SCROLL_LINEDOWN
;
124 else if ( newValue
- oldValue
== 1 )
125 scrollEvent
= wxEVT_SCROLL_LINEUP
;
127 scrollEvent
= wxEVT_SCROLL_THUMBTRACK
;
129 // Do not send an event if the value has not actually changed
130 // (Also works for wxSpinCtrl)
131 if ( newValue
== oldValue
)
134 if ( scrollEvent
!= wxEVT_SCROLL_THUMBTRACK
)
136 wxSpinEvent
event( scrollEvent
, m_windowId
);
138 event
.SetPosition( newValue
);
139 event
.SetEventObject( this );
140 if ((HandleWindowEvent( event
)) && !event
.IsAllowed())
144 GetPeer()->SetValue( newValue
);
146 // always send a thumbtrack event
147 SendThumbTrackEvent() ;
150 #endif // wxUSE_SPINBTN