X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/524c47aa3adf2af11a3069fd5da035a604f08f66..da6f998486f1070e205f2e0a54f22a1b67cb32a4:/src/osx/slider_osx.cpp diff --git a/src/osx/slider_osx.cpp b/src/osx/slider_osx.cpp index 45b335899d..5d658fe181 100644 --- a/src/osx/slider_osx.cpp +++ b/src/osx/slider_osx.cpp @@ -4,7 +4,6 @@ // Author: Stefan Csomor // Modified by: // Created: 1998-01-01 -// RCS-ID: $Id: slider.cpp 54129 2008-06-11 19:30:52Z SC $ // Copyright: (c) Stefan Csomor // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// @@ -16,14 +15,17 @@ #include "wx/slider.h" #include "wx/osx/private.h" -IMPLEMENT_DYNAMIC_CLASS(wxSlider, wxControl) - BEGIN_EVENT_TABLE(wxSlider, wxControl) END_EVENT_TABLE() // The dimensions of the different styles of sliders (from Aqua document) -#define wxSLIDER_DIMENSIONACROSS_WITHTICKMARKS 24 -#define wxSLIDER_DIMENSIONACROSS_ARROW 18 +#if wxOSX_USE_COCOA + #define wxSLIDER_DIMENSIONACROSS_WITHTICKMARKS 28 + #define wxSLIDER_DIMENSIONACROSS_ARROW 21 +#else + #define wxSLIDER_DIMENSIONACROSS_WITHTICKMARKS 24 + #define wxSLIDER_DIMENSIONACROSS_ARROW 18 +#endif // Distance between slider and text #define wxSLIDER_BORDERTEXT 5 @@ -54,9 +56,9 @@ bool wxSlider::Create(wxWindow *parent, const wxSize& size, long style, const wxValidator& validator, const wxString& name) -{ - m_macIsUserPane = false; - +{ + DontCreatePeer(); + m_macMinimumStatic = NULL; m_macMaximumStatic = NULL; m_macValueStatic = NULL; @@ -100,8 +102,9 @@ bool wxSlider::Create(wxWindow *parent, if ( !wxControl::Create(parent, id, pos, size, style, validator, name) ) return false; - m_peer = wxWidgetImpl::CreateSlider( this, parent, id, value, minValue, maxValue, pos, size, style, GetExtraStyle() ); + SetPeer(wxWidgetImpl::CreateSlider( this, parent, id, value, minValue, maxValue, pos, size, style, GetExtraStyle() )); +#if 0 if (style & wxSL_VERTICAL) // Forces SetSize to use the proper width SetSizeHints(10, -1, 10, -1); @@ -112,7 +115,8 @@ bool wxSlider::Create(wxWindow *parent, // NB: SetSizeHints is overloaded by wxSlider and will substitute 10 with the // proper dimensions, it also means other people cannot bugger the slider with // other values - +#endif + if (style & wxSL_LABELS) { m_macMinimumStatic = new wxStaticText( parent, wxID_ANY, wxEmptyString ); @@ -143,7 +147,7 @@ wxSlider::~wxSlider() int wxSlider::GetValue() const { // We may need to invert the value returned by the widget - return ValueInvertOrNot( m_peer->GetValue() ) ; + return ValueInvertOrNot( GetPeer()->GetValue() ) ; } void wxSlider::SetValue(int value) @@ -156,18 +160,24 @@ void wxSlider::SetValue(int value) } // We only invert for the setting of the actual native widget - m_peer->SetValue( ValueInvertOrNot( value ) ); + GetPeer()->SetValue( ValueInvertOrNot( value ) ); } void wxSlider::SetRange(int minValue, int maxValue) { + // Changing the range preserves the value of the native control but may + // change our logical value if we're inverting the native value to get it + // as ValueInvertOrNot() depends on the range so preserve it before + // changing the range. + const int valueOld = GetValue(); + wxString value; m_rangeMin = minValue; m_rangeMax = maxValue; - m_peer->SetMinimum( m_rangeMin ); - m_peer->SetMaximum( m_rangeMax ); + GetPeer()->SetMinimum( m_rangeMin ); + GetPeer()->SetMaximum( m_rangeMax ); if (m_macMinimumStatic) { @@ -181,9 +191,9 @@ void wxSlider::SetRange(int minValue, int maxValue) m_macMaximumStatic->SetLabel( value ); } - // If the range is out of bounds, set it to a + // If the range is out of bounds, set it to a // value that is within bounds - // RN: Testing reveals OSX does its own + // RN: Testing reveals OSX does its own // bounding, perhaps this isn't needed? int currentValue = GetValue(); @@ -191,10 +201,13 @@ void wxSlider::SetRange(int minValue, int maxValue) SetValue(m_rangeMin); else if(currentValue > m_rangeMax) SetValue(m_rangeMax); + + // Ensure that our value didn't change. + SetValue(valueOld); } // For trackbars only -void wxSlider::SetTickFreq(int n, int WXUNUSED(pos)) +void wxSlider::DoSetTickFreq(int n) { // TODO m_tickFreq = n; @@ -272,45 +285,28 @@ void wxSlider::Command(wxCommandEvent &event) ProcessCommand(event); } -void wxSlider::MacHandleControlClick(WXWidget WXUNUSED(control), - wxInt16 WXUNUSED(controlpart), - bool WXUNUSED(mouseStillDown)) +void wxSlider::TriggerScrollEvent( wxEventType scrollEvent) { // Whatever the native value is, we may need to invert it for calling // SetValue and putting the possibly inverted value in the event - int value = ValueInvertOrNot( m_peer->GetValue() ); + int value = ValueInvertOrNot( GetPeer()->GetValue() ); SetValue( value ); - wxScrollEvent event( wxEVT_SCROLL_THUMBTRACK, m_windowId ); + wxScrollEvent event( scrollEvent, m_windowId ); event.SetPosition( value ); event.SetEventObject( this ); HandleWindowEvent( event ); - wxCommandEvent cevent( wxEVT_COMMAND_SLIDER_UPDATED, m_windowId ); + wxCommandEvent cevent( wxEVT_SLIDER, m_windowId ); cevent.SetInt( value ); cevent.SetEventObject( this ); HandleWindowEvent( cevent ); } -bool wxSlider::HandleClicked( double timestampsec ) +bool wxSlider::OSXHandleClicked( double WXUNUSED(timestampsec) ) { - // Whatever the native value is, we may need to invert it for calling - // SetValue and putting the possibly inverted value in the event - int value = ValueInvertOrNot( m_peer->GetValue() ) ; - - SetValue( value ) ; - - wxScrollEvent event( wxEVT_SCROLL_THUMBRELEASE, m_windowId ); - event.SetPosition( value ); - event.SetEventObject( this ); - HandleWindowEvent( event ); - - wxCommandEvent cevent( wxEVT_COMMAND_SLIDER_UPDATED, m_windowId ); - cevent.SetInt( value ); - cevent.SetEventObject( this ); - - HandleWindowEvent( cevent ); + TriggerScrollEvent(wxEVT_SCROLL_THUMBRELEASE); return true; } @@ -441,7 +437,7 @@ void wxSlider::DoSetSize(int x, int y, int w, int h, int sizeFlags) if (GetWindowStyle() & wxSL_VERTICAL) // If vertical, use current value - text.Printf(wxT("%d"), (int)m_peer->GetValue()); + text.Printf(wxT("%d"), (int)GetPeer()->GetValue()); else // Use max so that the current value doesn't drift as centering would need to change text.Printf(wxT("%d"), m_rangeMax); @@ -481,6 +477,7 @@ void wxSlider::DoSetSize(int x, int y, int w, int h, int sizeFlags) // yet another hack since this is a composite control // when wxSlider has it's size hardcoded, we're not allowed to // change the size. But when the control has labels, we DO need + // to resize the internal Mac control to accommodate the text labels. // We need to trick the wxWidgets resize mechanism so that we can // resize the slider part of the control ONLY. @@ -491,7 +488,7 @@ void wxSlider::DoSetSize(int x, int y, int w, int h, int sizeFlags) if (GetWindowStyle() & wxSL_LABELS) { - // make sure we don't allow the entire control to be resized accidently + // make sure we don't allow the entire control to be resized accidentally if (width == GetSize().x) m_minWidth = -1; }