]>
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 wxSpinButton::wxSpinButton()
25 bool wxSpinButton::Create( wxWindow
*parent
,
26 wxWindowID id
, const wxPoint
& pos
, const wxSize
& size
,
27 long style
, const wxString
& name
)
29 m_macIsUserPane
= false;
31 if ( !wxSpinButtonBase::Create( parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
40 m_peer
= wxWidgetImpl::CreateSpinButton( this , parent
, id
, 0, m_min
, m_max
, pos
, size
,
41 style
, GetExtraStyle() );
43 MacPostControlCreate( pos
, size
);
48 wxSpinButton::~wxSpinButton()
52 void wxSpinButton::SetValue( int val
)
54 m_peer
->SetValue( val
);
57 int wxSpinButton::GetValue() const
59 return m_peer
->GetValue();
62 void wxSpinButton::SetRange(int minVal
, int maxVal
)
66 m_peer
->SetMaximum( maxVal
);
67 m_peer
->SetMinimum( minVal
);
70 void wxSpinButton::SendThumbTrackEvent()
72 wxSpinEvent
event( wxEVT_SCROLL_THUMBTRACK
, GetId() );
73 event
.SetPosition( GetValue() );
74 event
.SetEventObject( this );
75 HandleWindowEvent( event
);
78 bool wxSpinButton::OSXHandleClicked( double WXUNUSED(timestampsec
) )
80 // all events have already been processed
84 wxSize
wxSpinButton::DoGetBestSize() const
86 return wxSize( 16, 24 );
89 void wxSpinButton::TriggerScrollEvent(wxEventType scrollEvent
)
93 if ( scrollEvent
== wxEVT_SCROLL_LINEUP
)
97 else if ( scrollEvent
== wxEVT_SCROLL_LINEDOWN
)
102 // trigger scroll events
104 int oldValue
= GetValue() ;
106 int newValue
= oldValue
+ inc
;
108 if (newValue
< m_min
)
110 if ( m_windowStyle
& wxSP_WRAP
)
116 if (newValue
> m_max
)
118 if ( m_windowStyle
& wxSP_WRAP
)
124 if ( newValue
- oldValue
== -1 )
125 scrollEvent
= wxEVT_SCROLL_LINEDOWN
;
126 else if ( newValue
- oldValue
== 1 )
127 scrollEvent
= wxEVT_SCROLL_LINEUP
;
129 scrollEvent
= wxEVT_SCROLL_THUMBTRACK
;
131 // Do not send an event if the value has not actually changed
132 // (Also works for wxSpinCtrl)
133 if ( newValue
== oldValue
)
136 if ( scrollEvent
!= wxEVT_SCROLL_THUMBTRACK
)
138 wxSpinEvent
event( scrollEvent
, m_windowId
);
140 event
.SetPosition( newValue
);
141 event
.SetEventObject( this );
142 if ((HandleWindowEvent( event
)) && !event
.IsAllowed())
146 m_peer
->SetValue( newValue
);
148 // always send a thumbtrack event
149 SendThumbTrackEvent() ;
152 #endif // wxUSE_SPINBTN