]> git.saurik.com Git - wxWidgets.git/blobdiff - src/cocoa/slider.mm
Applied patch [ 1736135 ] AUI: Clicking caption ignored on centered panel
[wxWidgets.git] / src / cocoa / slider.mm
index 0f0fdc364a129c426d4ca69388e811d6c45182cf..b5041e9949fcc82354f54e2d28d6590c492e5847 100644 (file)
     #include "wx/app.h"
 #endif //WX_PRECOMP
 
     #include "wx/app.h"
 #endif //WX_PRECOMP
 
-#import <AppKit/NSSlider.h>
+#import <Foundation/NSString.h>
+#include "wx/cocoa/objc/NSSlider.h"
+#import <AppKit/NSEvent.h>
+#import <AppKit/NSWindow.h>
 
 IMPLEMENT_DYNAMIC_CLASS(wxSlider, wxControl)
     BEGIN_EVENT_TABLE(wxSlider, wxSliderBase)
 
 IMPLEMENT_DYNAMIC_CLASS(wxSlider, wxControl)
     BEGIN_EVENT_TABLE(wxSlider, wxSliderBase)
@@ -67,7 +70,7 @@ bool wxSlider::Create(wxWindow *parent, wxWindowID winid,
     
     if(!CreateControl(parent,winid,pos,size,style,validator,name))
         return false;
     
     if(!CreateControl(parent,winid,pos,size,style,validator,name))
         return false;
-    SetNSView([[NSSlider alloc] initWithFrame: MakeDefaultNSRect(size)]);
+    SetNSSlider([[WX_GET_OBJC_CLASS(WXNSSlider) alloc] initWithFrame: MakeDefaultNSRect(size)]);
     [m_cocoaNSView release];
     
     if(m_parent)
     [m_cocoaNSView release];
     
     if(m_parent)
@@ -85,6 +88,14 @@ wxSlider::~wxSlider()
     DisassociateNSSlider(GetNSSlider());
 }
 
     DisassociateNSSlider(GetNSSlider());
 }
 
+void wxSlider::AssociateNSSlider(WX_NSSlider theSlider)
+{
+    wxCocoaNSSlider::AssociateNSSlider(theSlider);
+    // Set the target/action.. we don't really need to unset these
+    [theSlider setTarget:wxCocoaNSControl::sm_cocoaTarget];
+    [theSlider setAction:@selector(wxNSControlAction:)];
+}
+
 void wxSlider::ProcessEventType(wxEventType commandType)
 {
     wxScrollEvent event(commandType, GetId(), GetValue(), HasFlag(wxSL_VERTICAL)?wxVERTICAL:wxHORIZONTAL);
 void wxSlider::ProcessEventType(wxEventType commandType)
 {
     wxScrollEvent event(commandType, GetId(), GetValue(), HasFlag(wxSL_VERTICAL)?wxVERTICAL:wxHORIZONTAL);
@@ -92,6 +103,51 @@ void wxSlider::ProcessEventType(wxEventType commandType)
     GetEventHandler()->ProcessEvent(event);
 }
 
     GetEventHandler()->ProcessEvent(event);
 }
 
+static inline wxEventType wxSliderEventTypeForKeyFromEvent(NSEvent *theEvent)
+{
+    NSString *theEventCharacters = [theEvent charactersIgnoringModifiers];
+
+    if ([theEventCharacters length] == 1)
+    {
+        switch ([theEventCharacters characterAtIndex:0])
+        {
+            case NSUpArrowFunctionKey:
+            case NSRightArrowFunctionKey:   return wxEVT_SCROLL_PAGEDOWN;
+            case NSDownArrowFunctionKey:
+            case NSLeftArrowFunctionKey:    return wxEVT_SCROLL_PAGEUP;
+            case NSPageUpFunctionKey:       return wxEVT_SCROLL_BOTTOM;
+            case NSPageDownFunctionKey:     return wxEVT_SCROLL_TOP;
+        }
+    }
+    // Overload wxEVT_ANY to mean we can't determine the event type.
+    return wxEVT_ANY;
+}
+
+void wxSlider::CocoaTarget_action()
+{
+    wxEventType sliderEventType;
+    SEL theSelector = wxCocoaNSSlider::GetLastResponderSelector();
+    
+    if(         theSelector == @selector(moveUp:)
+            ||  theSelector == @selector(moveRight:))
+        sliderEventType = wxEVT_SCROLL_PAGEDOWN;
+    else if(    theSelector == @selector(moveDown:)
+            ||  theSelector == @selector(moveLeft:))
+        sliderEventType = wxEVT_SCROLL_PAGEUP;
+    else if(    theSelector == @selector(pageUp:))
+        sliderEventType = wxEVT_SCROLL_BOTTOM;
+    else if(    theSelector == @selector(pageDown:))
+        sliderEventType = wxEVT_SCROLL_TOP;
+    else if(    theSelector == @selector(keyDown:))
+        // This case should ideally never be reached.
+        sliderEventType = wxSliderEventTypeForKeyFromEvent([[GetNSSlider() window] currentEvent]);
+    else
+        // Don't generate an event.
+        return;
+    if(sliderEventType != wxEVT_ANY)
+        ProcessEventType(sliderEventType);
+}
+
 void wxSlider::CocoaNotification_startTracking(WX_NSNotification notification)
 {
     CocoaNotification_continueTracking(notification);
 void wxSlider::CocoaNotification_startTracking(WX_NSNotification notification)
 {
     CocoaNotification_continueTracking(notification);