]>
git.saurik.com Git - wxWidgets.git/blob - src/osx/spinbutt_osx.cpp
b8ef24b73248048dd739d77783fa28b6efd91d13
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/spinbutt_osx.cpp
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 wxSpinButton::wxSpinButton()
25 bool wxSpinButton::Create( wxWindow
*parent
,
26 wxWindowID id
, const wxPoint
& pos
, const wxSize
& size
,
27 long style
, const wxString
& name
)
30 if ( !wxSpinButtonBase::Create( parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
39 SetPeer(wxWidgetImpl::CreateSpinButton( this , parent
, id
, 0, m_min
, m_max
, pos
, size
,
40 style
, GetExtraStyle() ));
42 MacPostControlCreate( pos
, size
);
47 wxSpinButton::~wxSpinButton()
51 void wxSpinButton::SetValue( int val
)
53 GetPeer()->SetValue( val
);
56 int wxSpinButton::GetValue() const
58 return GetPeer()->GetValue();
61 void wxSpinButton::SetRange(int minVal
, int maxVal
)
65 GetPeer()->SetMaximum( maxVal
);
66 GetPeer()->SetMinimum( minVal
);
69 void wxSpinButton::SendThumbTrackEvent()
71 wxSpinEvent
event( wxEVT_SCROLL_THUMBTRACK
, GetId() );
72 event
.SetPosition( GetValue() );
73 event
.SetEventObject( this );
74 HandleWindowEvent( event
);
77 bool wxSpinButton::OSXHandleClicked( double WXUNUSED(timestampsec
) )
79 // all events have already been processed
83 wxSize
wxSpinButton::DoGetBestSize() const
85 return wxSize( 16, 24 );
88 void wxSpinButton::TriggerScrollEvent(wxEventType scrollEvent
)
92 if ( scrollEvent
== wxEVT_SCROLL_LINEUP
)
96 else if ( scrollEvent
== wxEVT_SCROLL_LINEDOWN
)
101 // trigger scroll events
103 int oldValue
= GetValue() ;
105 int newValue
= oldValue
+ inc
;
107 if (newValue
< m_min
)
109 if ( m_windowStyle
& wxSP_WRAP
)
115 if (newValue
> m_max
)
117 if ( m_windowStyle
& wxSP_WRAP
)
123 if ( newValue
- oldValue
== -1 )
124 scrollEvent
= wxEVT_SCROLL_LINEDOWN
;
125 else if ( newValue
- oldValue
== 1 )
126 scrollEvent
= wxEVT_SCROLL_LINEUP
;
128 scrollEvent
= wxEVT_SCROLL_THUMBTRACK
;
130 // Do not send an event if the value has not actually changed
131 // (Also works for wxSpinCtrl)
132 if ( newValue
== oldValue
)
135 if ( scrollEvent
!= wxEVT_SCROLL_THUMBTRACK
)
137 wxSpinEvent
event( scrollEvent
, m_windowId
);
139 event
.SetPosition( newValue
);
140 event
.SetEventObject( this );
141 if ((HandleWindowEvent( event
)) && !event
.IsAllowed())
145 GetPeer()->SetValue( newValue
);
147 // always send a thumbtrack event
148 SendThumbTrackEvent() ;
151 #endif // wxUSE_SPINBTN