X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/4f46c20bc4cc5be9b358a6e6caad39c1f8498cae..0d53638f7147c18153f63fdfc096b17be6e22a27:/src/cocoa/slider.mm?ds=sidebyside diff --git a/src/cocoa/slider.mm b/src/cocoa/slider.mm index b5041e9949..afa3767d3f 100644 --- a/src/cocoa/slider.mm +++ b/src/cocoa/slider.mm @@ -5,10 +5,9 @@ // Mark Oxenham // Modified by: // Created: 2003/06/19 -// RCS-ID: $Id$ // Copyright: (c) 2003 David Elliott // (c) 2007 Software 2000 Ltd. -// Licence: wxWidgets licence +// Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// #include "wx/wxprec.h" @@ -26,8 +25,7 @@ #import #import -IMPLEMENT_DYNAMIC_CLASS(wxSlider, wxControl) - BEGIN_EVENT_TABLE(wxSlider, wxSliderBase) +BEGIN_EVENT_TABLE(wxSlider, wxSliderBase) END_EVENT_TABLE() WX_IMPLEMENT_COCOA_OWNER(wxSlider,NSSlider,NSControl,NSView) @@ -42,11 +40,14 @@ inline void AdjustDimension( const int dimension = (size.*GetDimension)(); const int minSize = (isTicksStyle) ? 23 : 20; + // prevent clipping of overly "thin" sliders if (dimension < minSize) { (size.*SetDimension)(minSize); } + // move the slider control to the middle of the dimension that is not + // being used to define its length pos += (dimension - (size.*GetDimension)() + 1) / 2; } @@ -68,17 +69,24 @@ bool wxSlider::Create(wxWindow *parent, wxWindowID winid, AdjustDimension(isTicksStyle, adjustedPos.x, adjustedSize, &wxSize::GetWidth, &wxSize::SetWidth); } - if(!CreateControl(parent,winid,pos,size,style,validator,name)) + if(!CreateControl(parent,winid,adjustedPos,adjustedSize,style,validator,name)) return false; - SetNSSlider([[WX_GET_OBJC_CLASS(WXNSSlider) alloc] initWithFrame: MakeDefaultNSRect(size)]); + SetNSSlider([[WX_GET_OBJC_CLASS(WXNSSlider) alloc] initWithFrame: MakeDefaultNSRect(adjustedSize)]); [m_cocoaNSView release]; if(m_parent) m_parent->CocoaAddChild(this); - SetInitialFrameRect(pos,size); + SetInitialFrameRect(adjustedPos,adjustedSize); SetRange(minValue, maxValue); SetValue(value); + + // -1 default for wxSL_AUTOTICKS == false + int tickMarks = -1; + // minValue > maxValue not handled, tickMarks set to 0 + if ( style & wxSL_AUTOTICKS ) + tickMarks = ((maxValue - minValue >= 0) ? (maxValue - minValue) : 0); + SetTickFreq(tickMarks); return true; } @@ -100,7 +108,7 @@ void wxSlider::ProcessEventType(wxEventType commandType) { wxScrollEvent event(commandType, GetId(), GetValue(), HasFlag(wxSL_VERTICAL)?wxVERTICAL:wxHORIZONTAL); event.SetEventObject(this); - GetEventHandler()->ProcessEvent(event); + HandleWindowEvent(event); } static inline wxEventType wxSliderEventTypeForKeyFromEvent(NSEvent *theEvent) @@ -196,7 +204,7 @@ int wxSlider::GetMax() const return [GetNSSlider() maxValue]; } -void wxSlider::SetTickFreq(int n, int pos) +void wxSlider::DoSetTickFreq(int n) { const int numTicks = (n > 0) ? ((GetMax() - GetMin()) / n) + 1 : 0; [GetNSSlider() setNumberOfTickMarks:numTicks];