]> git.saurik.com Git - wxWidgets.git/blobdiff - src/osx/cocoa/spinbutt.mm
Move body of SetMinSize and SetMaxSize from header to cpp file for easier debugging...
[wxWidgets.git] / src / osx / cocoa / spinbutt.mm
index 9fbce04a936122eebb7bea0961a5c5c991081d69..da57bbea789765a65db782a19cf1d07585621a23 100644 (file)
 
 @interface wxNSStepper : NSStepper
 {
-    wxWidgetImpl* impl;
+    WXCOCOAIMPL_COMMON_MEMBERS
+    int formerValue;
 }
 
-- (void)setImplementation: (wxWidgetImpl *) theImplementation;
-- (wxWidgetImpl*) implementation;
-- (BOOL) isFlipped;
+WXCOCOAIMPL_COMMON_INTERFACE
+
  - (void) clickedAction: (id) sender;
 
 @end
@@ -34,6 +34,7 @@
 {
     [super initWithFrame:frame];
     impl = NULL;
+    formerValue = 0;
     [self setTarget: self];
     [self setAction: @selector(clickedAction:)];
     return self;
     {
         wxWindow* wxpeer = (wxWindow*) impl->GetWXPeer();
         if ( wxpeer )
-            wxpeer->HandleClicked(0);
+        {
+            // because wx expects to be able to veto 
+            // a change we must revert the value change
+            // and expose it
+            int currentValue = [self intValue];
+            [self setIntValue:formerValue];
+            int inc = currentValue-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);
+
+            formerValue = [self intValue];
+        }
     }
 }
 
-- (void)setImplementation: (wxWidgetImpl *) theImplementation
+-(void)mouseDown:(NSEvent *)event 
 {
-    impl = theImplementation;
+    formerValue = [self intValue];
+    if ( !impl->DoHandleMouseEvent(event) )
+        [super mouseDown:event];
 }
 
-- (wxWidgetImpl*) implementation
-{
-    return impl;
-}
-
-- (BOOL) isFlipped
-{
-    return YES;
-}
+WXCOCOAIMPL_COMMON_IMPLEMENTATION_NO_MOUSEDOWN
 
 @end
 
@@ -77,8 +92,6 @@ wxWidgetImplType* wxWidgetImpl::CreateSpinButton( wxWindowMac* wxpeer,
                                     long style, 
                                     long extraStyle)
 {
-    NSView* sv = (wxpeer->GetParent()->GetHandle() );
-    
     NSRect r = wxOSXGetFrameForControl( wxpeer, pos , size ) ;
     wxNSStepper* v = [[wxNSStepper alloc] initWithFrame:r];
 
@@ -89,7 +102,6 @@ wxWidgetImplType* wxWidgetImpl::CreateSpinButton( wxWindowMac* wxpeer,
     if ( style & wxSP_WRAP )
         [v setValueWraps:YES];
     
-    [sv addSubview:v];
     wxWidgetCocoaImpl* c = new wxWidgetCocoaImpl( wxpeer, v );
     [v setImplementation:c];
     return c;