1 /////////////////////////////////////////////////////////////////////////////
 
   2 // Name:        src/osx/cocoa/slider.mm
 
   4 // Author:      Stefan Csomor
 
   7 // Copyright:   (c) Stefan Csomor
 
   8 // Licence:       wxWindows licence
 
   9 /////////////////////////////////////////////////////////////////////////////
 
  11 #include "wx/wxprec.h"
 
  15 #include "wx/slider.h"
 
  16 #include "wx/osx/private.h"
 
  18 @interface wxNSSlider : NSSlider
 
  23 @implementation wxNSSlider
 
  27     static BOOL initialized = NO;
 
  31         wxOSXCocoaClassAddWXMethods(self);
 
  37 class wxSliderCocoaImpl : public wxWidgetCocoaImpl
 
  40     wxSliderCocoaImpl(wxWindowMac* peer , WXWidget w) :
 
  41         wxWidgetCocoaImpl(peer, w)
 
  49     virtual void controlAction(WXWidget slf, void* _cmd, void *sender);
 
  50     virtual void mouseEvent(WX_NSEvent event, WXWidget slf, void* _cmd);
 
  53 // we will have a mouseDown, then in the native
 
  54 // implementation of mouseDown the tracking code
 
  55 // is calling clickedAction, therefore we wire this
 
  56 // to thumbtrack and only after super mouseDown
 
  57 // returns we will call the thumbrelease
 
  59 void wxSliderCocoaImpl::controlAction( WXWidget WXUNUSED(slf), void *WXUNUSED(_cmd), void *WXUNUSED(sender))
 
  61     wxWindow* wxpeer = (wxWindow*) GetWXPeer();
 
  63         wxpeer->TriggerScrollEvent(wxEVT_SCROLL_THUMBTRACK);
 
  66 void wxSliderCocoaImpl::mouseEvent(WX_NSEvent event, WXWidget slf, void *_cmd)
 
  68     wxWidgetCocoaImpl::mouseEvent(event, slf, _cmd);
 
  70     if ( strcmp( sel_getName((SEL) _cmd) , "mouseDown:") == 0 )
 
  72         wxWindow* wxpeer = (wxWindow*) GetWXPeer();
 
  74             wxpeer->OSXHandleClicked(0);
 
  80 wxWidgetImplType* wxWidgetImpl::CreateSlider( wxWindowMac* wxpeer,
 
  81                                     wxWindowMac* WXUNUSED(parent),
 
  82                                     wxWindowID WXUNUSED(id),
 
  89                                     long WXUNUSED(extraStyle))
 
  91     NSRect r = wxOSXGetFrameForControl( wxpeer, pos , size ) ;
 
  92     if ( size == wxDefaultSize )
 
  94         if ( style & wxSL_VERTICAL )
 
  95             r.size.height = r.size.width * 2;
 
  97             r.size.width = r.size.height * 2;
 
  99     wxNSSlider* v = [[wxNSSlider alloc] initWithFrame:r];
 
 102     if ( style & wxSL_AUTOTICKS )
 
 104         tickMarks = (maximum - minimum) + 1; // +1 for the 0 value
 
 106         // keep the number of tickmarks from becoming unwieldly, therefore below it is ok to cast
 
 108         while (tickMarks > 20)
 
 111         [v setNumberOfTickMarks:tickMarks];
 
 112         [v setTickMarkPosition:NSTickMarkBelow];
 
 115     [v setMinValue: minimum];
 
 116     [v setMaxValue: maximum];
 
 117     [v setFloatValue: (double) value];
 
 118     wxWidgetCocoaImpl* c = new wxSliderCocoaImpl( wxpeer, v );
 
 122 #endif // wxUSE_SLIDER