From 780220b099a8016b02a4b78a1e3f0b0c6849b51f Mon Sep 17 00:00:00 2001 From: David Elliott Date: Thu, 6 Sep 2007 16:41:31 +0000 Subject: [PATCH] Make a slider control created with a particular size/position adjust itself to the only size that works and adjust the positioning accordingly. Implement the wxSL_AUTOTICKS style. Patch from Mark Oxenham. Copyright 2007 Software 2000 Ltd. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@48589 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/cocoa/slider.mm | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/cocoa/slider.mm b/src/cocoa/slider.mm index b5041e9949..888a5d809f 100644 --- a/src/cocoa/slider.mm +++ b/src/cocoa/slider.mm @@ -42,11 +42,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 +71,25 @@ 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); + // arg2 needed a value, doesnt do anything + SetTickFreq(tickMarks,1); return true; }