]> git.saurik.com Git - wxWidgets.git/blobdiff - src/osx/cocoa/slider.mm
Use UTF-8 for all non-ASCII characters in the sources.
[wxWidgets.git] / src / osx / cocoa / slider.mm
index a56acbeaddfa1750e19c74eeb3f86fec8aca088d..fbde6dc22a2f1b777e8047a8a26936526107ff2d 100644 (file)
 
 @interface wxNSSlider : NSSlider
 {
-    WXCOCOAIMPL_COMMON_MEMBERS
 }
+@end
 
-WXCOCOAIMPL_COMMON_INTERFACE
+@implementation wxNSSlider
 
- - (void) clickedAction: (id) sender;
++ (void)initialize
+{
+    static BOOL initialized = NO;
+    if (!initialized)
+    {
+        initialized = YES;
+        wxOSXCocoaClassAddWXMethods(self);
+    }
+}
 
 @end
 
-@implementation wxNSSlider
+class wxSliderCocoaImpl : public wxWidgetCocoaImpl
+{
+public :
+    wxSliderCocoaImpl(wxWindowMac* peer , WXWidget w) :
+        wxWidgetCocoaImpl(peer, w)
+    {
+    }
+
+    ~wxSliderCocoaImpl()
+    {
+    }
+
+    virtual void controlAction(WXWidget slf, void* _cmd, void *sender);
+    virtual void mouseEvent(WX_NSEvent event, WXWidget slf, void* _cmd);
+};
 
-- (id)initWithFrame:(NSRect)frame
+// we will have a mouseDown, then in the native
+// implementation of mouseDown the tracking code
+// is calling clickedAction, therefore we wire this
+// to thumbtrack and only after super mouseDown
+// returns we will call the thumbrelease
+
+void wxSliderCocoaImpl::controlAction( WXWidget WXUNUSED(slf), void *WXUNUSED(_cmd), void *WXUNUSED(sender))
 {
-    [super initWithFrame:frame];
-    impl = NULL;
-    [self setTarget: self];
-    [self setAction: @selector(clickedAction:)];
-    return self;
+    wxWindow* wxpeer = (wxWindow*) GetWXPeer();
+    if ( wxpeer )
+        wxpeer->TriggerScrollEvent(wxEVT_SCROLL_THUMBTRACK);
 }
 
-- (void) clickedAction: (id) sender
+void wxSliderCocoaImpl::mouseEvent(WX_NSEvent event, WXWidget slf, void *_cmd)
 {
-    if ( impl )
+    wxWidgetCocoaImpl::mouseEvent(event, slf, _cmd);
+
+    if ( strcmp( sel_getName((SEL) _cmd) , "mouseDown:") == 0 )
     {
-        wxWindow* wxpeer = (wxWindow*) impl->GetWXPeer();
+        wxWindow* wxpeer = (wxWindow*) GetWXPeer();
         if ( wxpeer )
-            wxpeer->HandleClicked(0);
+            wxpeer->OSXHandleClicked(0);
     }
 }
 
-WXCOCOAIMPL_COMMON_IMPLEMENTATION
 
-@end
 
-wxWidgetImplType* wxWidgetImpl::CreateSlider( wxWindowMac* wxpeer, 
-                                    wxWindowMac* parent, 
-                                    wxWindowID id, 
+wxWidgetImplType* wxWidgetImpl::CreateSlider( wxWindowMac* wxpeer,
+                                    wxWindowMac* WXUNUSED(parent),
+                                    wxWindowID WXUNUSED(id),
                                     wxInt32 value,
                                     wxInt32 minimum,
                                     wxInt32 maximum,
-                                    const wxPoint& pos, 
+                                    const wxPoint& pos,
                                     const wxSize& size,
-                                    long style, 
-                                    long extraStyle)
+                                    long style,
+                                    long WXUNUSED(extraStyle))
 {
     NSRect r = wxOSXGetFrameForControl( wxpeer, pos , size ) ;
     wxNSSlider* v = [[wxNSSlider alloc] initWithFrame:r];
@@ -75,7 +101,7 @@ wxWidgetImplType* wxWidgetImpl::CreateSlider( wxWindowMac* wxpeer,
         // it to a UInt16
         while (tickMarks > 20)
             tickMarks /= 5;
-            
+
         [v setNumberOfTickMarks:tickMarks];
         [v setTickMarkPosition:NSTickMarkBelow];
     }
@@ -83,8 +109,7 @@ wxWidgetImplType* wxWidgetImpl::CreateSlider( wxWindowMac* wxpeer,
     [v setMinValue: minimum];
     [v setMaxValue: maximum];
     [v setFloatValue: (double) value];
-    wxWidgetCocoaImpl* c = new wxWidgetCocoaImpl( wxpeer, v );
-    [v setImplementation:c];
+    wxWidgetCocoaImpl* c = new wxSliderCocoaImpl( wxpeer, v );
     return c;
 }