]> git.saurik.com Git - wxWidgets.git/blobdiff - src/osx/cocoa/spinbutt.mm
Applied Blit system options optimization to StretchBlit
[wxWidgets.git] / src / osx / cocoa / spinbutt.mm
index 436576b8b37416c3d2be3925ae6e093b07c81a69..907fac8b1439198155ef123a70b34e1d5c2b4210 100644 (file)
@@ -1,10 +1,10 @@
 /////////////////////////////////////////////////////////////////////////////
 /////////////////////////////////////////////////////////////////////////////
-// Name:        spinbutt.cpp
+// Name:        src/osx/cocoa/spinbutt.mm
 // Purpose:     wxSpinButton
 // Author:      Stefan Csomor
 // Modified by:
 // Created:     1998-01-01
 // Purpose:     wxSpinButton
 // Author:      Stefan Csomor
 // Modified by:
 // Created:     1998-01-01
-// RCS-ID:      $Id: spinbutt.cpp 54129 2008-06-11 19:30:52Z SC $
+// RCS-ID:      $Id$
 // Copyright:   (c) Stefan Csomor
 // Licence:       wxWindows licence
 /////////////////////////////////////////////////////////////////////////////
 // Copyright:   (c) Stefan Csomor
 // Licence:       wxWindows licence
 /////////////////////////////////////////////////////////////////////////////
 
 @interface wxNSStepper : NSStepper
 {
 
 @interface wxNSStepper : NSStepper
 {
-    wxWidgetImpl* impl;
 }
 }
-
-- (void)setImplementation: (wxWidgetImpl *) theImplementation;
-- (wxWidgetImpl*) implementation;
-- (BOOL) isFlipped;
- - (void) clickedAction: (id) sender;
-
 @end
 
 @implementation wxNSStepper
 
 @end
 
 @implementation wxNSStepper
 
-- (id)initWithFrame:(NSRect)frame
++ (void)initialize
 {
 {
-    [super initWithFrame:frame];
-    impl = NULL;
-    [self setTarget: self];
-    [self setAction: @selector(clickedAction:)];
-    return self;
+    static BOOL initialized = NO;
+    if (!initialized)
+    {
+        initialized = YES;
+        wxOSXCocoaClassAddWXMethods(self);
+    }
 }
 
 }
 
-- (void) clickedAction: (id) sender
+@end
+
+class wxSpinButtonCocoaImpl : public wxWidgetCocoaImpl
 {
 {
-    if ( impl )
+public :
+    wxSpinButtonCocoaImpl(wxWindowMac* peer , WXWidget w) :
+        wxWidgetCocoaImpl(peer, w)
     {
     {
-        wxWindow* wxpeer = (wxWindow*) impl->GetWXPeer();
-        if ( wxpeer )
-            wxpeer->HandleClicked(0);
+        m_formerValue = 0;
     }
     }
-}
 
 
-- (void)setImplementation: (wxWidgetImpl *) theImplementation
-{
-    impl = theImplementation;
-}
+    ~wxSpinButtonCocoaImpl()
+    {
+    }
 
 
-- (wxWidgetImpl*) implementation
+    virtual void controlAction(WXWidget slf, void* _cmd, void *sender);
+    virtual void mouseEvent(WX_NSEvent event, WXWidget slf, void* _cmd);
+private:
+    int m_formerValue;
+};
+
+void wxSpinButtonCocoaImpl::mouseEvent(WX_NSEvent event, WXWidget slf, void *_cmd)
 {
 {
-    return impl;
+
+    // send a release event in case we've been tracking the thumb
+    if ( strcmp( sel_getName((SEL) _cmd) , "mouseDown:") == 0 )
+    {
+        m_formerValue = [(NSStepper*)m_osxView intValue];
+    }
+
+    wxWidgetCocoaImpl::mouseEvent(event, slf, _cmd);
 }
 
 }
 
-- (BOOL) isFlipped
+void wxSpinButtonCocoaImpl::controlAction( WXWidget WXUNUSED(slf), void *WXUNUSED(_cmd), void *WXUNUSED(sender))
 {
 {
-    return YES;
+    wxWindow* wxpeer = (wxWindow*) GetWXPeer();
+    if ( wxpeer )
+    {
+        // because wx expects to be able to veto
+        // a change we must revert the value change
+        // and expose it
+        int currentValue = [(NSStepper*)m_osxView intValue];
+        [(NSStepper*)m_osxView setIntValue:m_formerValue];
+        int inc = currentValue-m_formerValue;
+
+        // adjust for wrap arounds
+        if ( inc > 1 )
+            inc = -1;
+        else if (inc < -1 )
+            inc = 1;
+
+        if ( inc == 1 )
+            wxpeer->TriggerScrollEvent(wxEVT_SCROLL_LINEUP);
+        else if ( inc == -1 )
+            wxpeer->TriggerScrollEvent(wxEVT_SCROLL_LINEDOWN);
+
+        m_formerValue = [(NSStepper*)m_osxView intValue];
+    }
 }
 
 }
 
-@end
-
-wxWidgetImplType* wxWidgetImpl::CreateSpinButton( wxWindowMac* wxpeer, 
-                                    wxWindowMac* parent, 
-                                    wxWindowID id, 
+wxWidgetImplType* wxWidgetImpl::CreateSpinButton( wxWindowMac* wxpeer,
+                                    wxWindowMac* WXUNUSED(parent),
+                                    wxWindowID WXUNUSED(id),
                                     wxInt32 value,
                                     wxInt32 minimum,
                                     wxInt32 maximum,
                                     wxInt32 value,
                                     wxInt32 minimum,
                                     wxInt32 maximum,
-                                    const wxPoint& pos, 
+                                    const wxPoint& pos,
                                     const wxSize& size,
                                     const wxSize& size,
-                                    long style, 
-                                    long extraStyle)
+                                    long style,
+                                    long WXUNUSED(extraStyle))
 {
     NSRect r = wxOSXGetFrameForControl( wxpeer, pos , size ) ;
     wxNSStepper* v = [[wxNSStepper alloc] initWithFrame:r];
 {
     NSRect r = wxOSXGetFrameForControl( wxpeer, pos , size ) ;
     wxNSStepper* v = [[wxNSStepper alloc] initWithFrame:r];
@@ -83,12 +110,11 @@ wxWidgetImplType* wxWidgetImpl::CreateSpinButton( wxWindowMac* wxpeer,
     [v setMinValue: minimum];
     [v setMaxValue: maximum];
     [v setIntValue: value];
     [v setMinValue: minimum];
     [v setMaxValue: maximum];
     [v setIntValue: value];
-    
+
     if ( style & wxSP_WRAP )
         [v setValueWraps:YES];
     if ( style & wxSP_WRAP )
         [v setValueWraps:YES];
-    
-    wxWidgetCocoaImpl* c = new wxWidgetCocoaImpl( wxpeer, v );
-    [v setImplementation:c];
+
+    wxWidgetCocoaImpl* c = new wxSpinButtonCocoaImpl( wxpeer, v );
     return c;
 }
 
     return c;
 }