X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/524c47aa3adf2af11a3069fd5da035a604f08f66..60372b0d54379701d62edf5595a7dc25c48330e1:/src/osx/spinbutt_osx.cpp diff --git a/src/osx/spinbutt_osx.cpp b/src/osx/spinbutt_osx.cpp index 340678c273..b8ef24b732 100644 --- a/src/osx/spinbutt_osx.cpp +++ b/src/osx/spinbutt_osx.cpp @@ -1,10 +1,10 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: spinbutt.cpp +// Name: src/osx/spinbutt_osx.cpp // Purpose: wxSpinButton // Author: Stefan Csomor // Modified by: // Created: 1998-01-01 -// RCS-ID: $Id: spinbutt.cpp 54129 2008-06-11 19:30:52Z SC $ +// RCS-ID: $Id$ // Copyright: (c) Stefan Csomor // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// @@ -17,10 +17,6 @@ #include "wx/osx/private.h" -IMPLEMENT_DYNAMIC_CLASS(wxSpinButton, wxControl) -IMPLEMENT_DYNAMIC_CLASS(wxSpinEvent, wxScrollEvent) - - wxSpinButton::wxSpinButton() : wxSpinButtonBase() { @@ -29,9 +25,8 @@ wxSpinButton::wxSpinButton() bool wxSpinButton::Create( wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style, const wxString& name ) -{ - m_macIsUserPane = false; - +{ + DontCreatePeer(); if ( !wxSpinButtonBase::Create( parent, id, pos, size, style, wxDefaultValidator, name ) ) return false; @@ -40,10 +35,10 @@ bool wxSpinButton::Create( wxWindow *parent, if (!parent) return false; - - m_peer = wxWidgetImpl::CreateSpinButton( this , parent, id, 0, m_min, m_max, pos, size, - style, GetExtraStyle() ); - + + SetPeer(wxWidgetImpl::CreateSpinButton( this , parent, id, 0, m_min, m_max, pos, size, + style, GetExtraStyle() )); + MacPostControlCreate( pos, size ); return true; @@ -55,23 +50,23 @@ wxSpinButton::~wxSpinButton() void wxSpinButton::SetValue( int val ) { - m_peer->SetValue( val ); + GetPeer()->SetValue( val ); } int wxSpinButton::GetValue() const { - return m_peer->GetValue(); + return GetPeer()->GetValue(); } void wxSpinButton::SetRange(int minVal, int maxVal) { m_min = minVal; m_max = maxVal; - m_peer->SetMaximum( maxVal ); - m_peer->SetMinimum( minVal ); -} - -void wxSpinButton::SendThumbTrackEvent() + GetPeer()->SetMaximum( maxVal ); + GetPeer()->SetMinimum( minVal ); +} + +void wxSpinButton::SendThumbTrackEvent() { wxSpinEvent event( wxEVT_SCROLL_THUMBTRACK, GetId() ); event.SetPosition( GetValue() ); @@ -79,14 +74,9 @@ void wxSpinButton::SendThumbTrackEvent() HandleWindowEvent( event ); } -bool wxSpinButton::HandleClicked( double timestampsec ) +bool wxSpinButton::OSXHandleClicked( double WXUNUSED(timestampsec) ) { -#if wxOSX_USE_CARBON - // these have been handled by the live action proc already -#else - SendThumbTrackEvent() ; -#endif - + // all events have already been processed return true; } @@ -95,4 +85,67 @@ wxSize wxSpinButton::DoGetBestSize() const return wxSize( 16, 24 ); } +void wxSpinButton::TriggerScrollEvent(wxEventType scrollEvent) +{ + int inc = 0; + + if ( scrollEvent == wxEVT_SCROLL_LINEUP ) + { + inc = 1; + } + else if ( scrollEvent == wxEVT_SCROLL_LINEDOWN ) + { + inc = -1; + } + + // trigger scroll events + + int oldValue = GetValue() ; + + int newValue = oldValue + inc; + + if (newValue < m_min) + { + if ( m_windowStyle & wxSP_WRAP ) + newValue = m_max; + else + newValue = m_min; + } + + if (newValue > m_max) + { + if ( m_windowStyle & wxSP_WRAP ) + newValue = m_min; + else + newValue = m_max; + } + + if ( newValue - oldValue == -1 ) + scrollEvent = wxEVT_SCROLL_LINEDOWN; + else if ( newValue - oldValue == 1 ) + scrollEvent = wxEVT_SCROLL_LINEUP; + else + scrollEvent = wxEVT_SCROLL_THUMBTRACK; + + // Do not send an event if the value has not actually changed + // (Also works for wxSpinCtrl) + if ( newValue == oldValue ) + return; + + if ( scrollEvent != wxEVT_SCROLL_THUMBTRACK ) + { + wxSpinEvent event( scrollEvent, m_windowId ); + + event.SetPosition( newValue ); + event.SetEventObject( this ); + if ((HandleWindowEvent( event )) && !event.IsAllowed()) + newValue = oldValue; + } + + GetPeer()->SetValue( newValue ); + + // always send a thumbtrack event + SendThumbTrackEvent() ; +} + #endif // wxUSE_SPINBTN