Further simplificiation of the NSSlider/wxSlider interface such that the
various responder methods don't change the controls action but instead send all actions through the normal wxCocoaNSControl action handling mechanism. To determine what caused the action we save the message selector in a global variable (safe since Cocoa does single-threaded event handling). git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@48078 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -2,7 +2,7 @@
|
|||||||
// Name: wx/cocoa/NSSlider.h
|
// Name: wx/cocoa/NSSlider.h
|
||||||
// Purpose: wxCocoaNSSlider class
|
// Purpose: wxCocoaNSSlider class
|
||||||
// Author: Mark Oxenham
|
// Author: Mark Oxenham
|
||||||
// Modified by:
|
// Modified by: David Elliott
|
||||||
// Created: 2007/08/10
|
// Created: 2007/08/10
|
||||||
// RCS-ID: $Id$
|
// RCS-ID: $Id$
|
||||||
// Copyright: (c) 2007 Software 2000 Ltd. All rights reserved.
|
// Copyright: (c) 2007 Software 2000 Ltd. All rights reserved.
|
||||||
@@ -20,34 +20,28 @@ DECLARE_WXCOCOA_OBJC_CLASS(NSSlider);
|
|||||||
|
|
||||||
WX_DECLARE_OBJC_HASHMAP(NSSlider);
|
WX_DECLARE_OBJC_HASHMAP(NSSlider);
|
||||||
|
|
||||||
|
// For when we're not in Objective-C mode:
|
||||||
|
typedef struct objc_selector *SEL;
|
||||||
|
|
||||||
|
class wxCocoaNSSliderLastSelectorChanger;
|
||||||
|
|
||||||
class wxCocoaNSSlider
|
class wxCocoaNSSlider
|
||||||
{
|
{
|
||||||
|
friend class wxCocoaNSSliderLastSelectorChanger;
|
||||||
WX_DECLARE_OBJC_INTERFACE_HASHMAP(NSSlider);
|
WX_DECLARE_OBJC_INTERFACE_HASHMAP(NSSlider);
|
||||||
public:
|
public:
|
||||||
void AssociateNSSlider(WX_NSSlider cocoaNSSlider);
|
void AssociateNSSlider(WX_NSSlider cocoaNSSlider);
|
||||||
void DisassociateNSSlider(WX_NSSlider cocoaNSSlider);
|
void DisassociateNSSlider(WX_NSSlider cocoaNSSlider);
|
||||||
|
|
||||||
virtual void Cocoa_wxNSSliderUpArrowKeyDown(void) = 0;
|
|
||||||
virtual void Cocoa_wxNSSliderDownArrowKeyDown(void) = 0;
|
|
||||||
virtual void Cocoa_wxNSSliderLeftArrowKeyDown(void) = 0;
|
|
||||||
virtual void Cocoa_wxNSSliderRightArrowKeyDown(void) = 0;
|
|
||||||
virtual void Cocoa_wxNSSliderPageUpKeyDown(void) = 0;
|
|
||||||
virtual void Cocoa_wxNSSliderPageDownKeyDown(void) = 0;
|
|
||||||
virtual void Cocoa_wxNSSliderMoveUp(void) = 0;
|
|
||||||
virtual void Cocoa_wxNSSliderMoveDown(void) = 0;
|
|
||||||
virtual void Cocoa_wxNSSliderMoveLeft(void) = 0;
|
|
||||||
virtual void Cocoa_wxNSSliderMoveRight(void) = 0;
|
|
||||||
virtual void Cocoa_wxNSSliderPageUp(void) = 0;
|
|
||||||
virtual void Cocoa_wxNSSliderPageDown(void) = 0;
|
|
||||||
virtual void CocoaNotification_startTracking(WX_NSNotification notification) = 0;
|
virtual void CocoaNotification_startTracking(WX_NSNotification notification) = 0;
|
||||||
virtual void CocoaNotification_continueTracking(WX_NSNotification notification) = 0;
|
virtual void CocoaNotification_continueTracking(WX_NSNotification notification) = 0;
|
||||||
virtual void CocoaNotification_stopTracking(WX_NSNotification notification) = 0;
|
virtual void CocoaNotification_stopTracking(WX_NSNotification notification) = 0;
|
||||||
virtual ~wxCocoaNSSlider() { }
|
|
||||||
|
|
||||||
|
static SEL GetLastResponderSelector()
|
||||||
|
{ return sm_lastResponderSelector; }
|
||||||
protected:
|
protected:
|
||||||
static const wxObjcAutoRefFromAlloc<struct objc_object*> sm_cocoaTarget;
|
virtual ~wxCocoaNSSlider() { }
|
||||||
static struct objc_object *sm_cocoaObserver;
|
static SEL sm_lastResponderSelector;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@@ -54,25 +54,20 @@ public:
|
|||||||
// Cocoa callbacks
|
// Cocoa callbacks
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
protected:
|
protected:
|
||||||
// from NSSLider
|
// Override this so we can use wxCocoaNSControl's target
|
||||||
|
void AssociateNSSlider(WX_NSSlider theSlider);
|
||||||
|
|
||||||
|
// Helper method to do the real work
|
||||||
virtual void ProcessEventType(wxEventType commandType);
|
virtual void ProcessEventType(wxEventType commandType);
|
||||||
virtual void Cocoa_wxNSSliderUpArrowKeyDown(void) { ProcessEventType(wxEVT_SCROLL_PAGEDOWN); }
|
|
||||||
virtual void Cocoa_wxNSSliderDownArrowKeyDown(void) { ProcessEventType(wxEVT_SCROLL_PAGEUP); }
|
// from wxCocoaNSControl:
|
||||||
virtual void Cocoa_wxNSSliderLeftArrowKeyDown(void) { ProcessEventType(wxEVT_SCROLL_PAGEUP); }
|
virtual void CocoaTarget_action();
|
||||||
virtual void Cocoa_wxNSSliderRightArrowKeyDown(void) { ProcessEventType(wxEVT_SCROLL_PAGEDOWN); }
|
|
||||||
virtual void Cocoa_wxNSSliderPageUpKeyDown(void) { ProcessEventType(wxEVT_SCROLL_BOTTOM); }
|
// from wxCocoaNSSlider:
|
||||||
virtual void Cocoa_wxNSSliderPageDownKeyDown(void) { ProcessEventType(wxEVT_SCROLL_TOP); }
|
|
||||||
virtual void Cocoa_wxNSSliderMoveUp(void) { ProcessEventType(wxEVT_SCROLL_PAGEDOWN); }
|
|
||||||
virtual void Cocoa_wxNSSliderMoveDown(void) { ProcessEventType(wxEVT_SCROLL_PAGEUP); }
|
|
||||||
virtual void Cocoa_wxNSSliderMoveLeft(void) { ProcessEventType(wxEVT_SCROLL_PAGEUP); }
|
|
||||||
virtual void Cocoa_wxNSSliderMoveRight(void) { ProcessEventType(wxEVT_SCROLL_PAGEDOWN); }
|
|
||||||
virtual void Cocoa_wxNSSliderPageUp(void) { ProcessEventType(wxEVT_SCROLL_BOTTOM); }
|
|
||||||
virtual void Cocoa_wxNSSliderPageDown(void) { ProcessEventType(wxEVT_SCROLL_TOP); }
|
|
||||||
virtual void CocoaNotification_startTracking(WX_NSNotification notification);
|
virtual void CocoaNotification_startTracking(WX_NSNotification notification);
|
||||||
virtual void CocoaNotification_continueTracking(WX_NSNotification notification);
|
virtual void CocoaNotification_continueTracking(WX_NSNotification notification);
|
||||||
virtual void CocoaNotification_stopTracking(WX_NSNotification notification);
|
virtual void CocoaNotification_stopTracking(WX_NSNotification notification);
|
||||||
|
|
||||||
|
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
// Implementation
|
// Implementation
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
|
@@ -24,120 +24,30 @@
|
|||||||
|
|
||||||
WX_IMPLEMENT_OBJC_INTERFACE_HASHMAP(NSSlider)
|
WX_IMPLEMENT_OBJC_INTERFACE_HASHMAP(NSSlider)
|
||||||
|
|
||||||
// ============================================================================
|
class wxCocoaNSSliderLastSelectorChanger
|
||||||
// @class wxNSSliderTarget
|
|
||||||
// ============================================================================
|
|
||||||
@interface wxNSSliderTarget : NSObject
|
|
||||||
{
|
{
|
||||||
}
|
public:
|
||||||
|
wxCocoaNSSliderLastSelectorChanger(SEL newSelector)
|
||||||
- (void)wxNSSliderUpArrowKeyDown: (id)sender;
|
{
|
||||||
- (void)wxNSSliderDownArrowKeyDown: (id)sender;
|
m_savedResponderSelector = wxCocoaNSSlider::sm_lastResponderSelector;
|
||||||
- (void)wxNSSliderLeftArrowKeyDown: (id)sender;
|
wxCocoaNSSlider::sm_lastResponderSelector = newSelector;
|
||||||
- (void)wxNSSliderRightArrowKeyDown: (id)sender;
|
}
|
||||||
- (void)wxNSSliderPageUpKeyDown: (id)sender;
|
~wxCocoaNSSliderLastSelectorChanger()
|
||||||
- (void)wxNSSliderPageDownKeyDown: (id)sender;
|
{
|
||||||
- (void)wxNSSliderMoveUp: (id)sender;
|
wxCocoaNSSlider::sm_lastResponderSelector = m_savedResponderSelector;
|
||||||
- (void)wxNSSliderMoveDown: (id)sender;
|
}
|
||||||
- (void)wxNSSliderMoveLeft: (id)sender;
|
private:
|
||||||
- (void)wxNSSliderMoveRight: (id)sender;
|
SEL m_savedResponderSelector;
|
||||||
- (void)wxNSSliderPageUp: (id)sender;
|
// Don't allow any default or copy construction
|
||||||
- (void)wxNSSliderPageDown: (id)sender;
|
wxCocoaNSSliderLastSelectorChanger();
|
||||||
@end // wxNSSliderTarget
|
wxCocoaNSSliderLastSelectorChanger(const wxCocoaNSSliderLastSelectorChanger&);
|
||||||
|
void operator=(const wxCocoaNSSliderLastSelectorChanger&);
|
||||||
@implementation wxNSSliderTarget : NSObject
|
};
|
||||||
|
|
||||||
- (void)wxNSSliderUpArrowKeyDown: (id)sender
|
|
||||||
{
|
|
||||||
wxCocoaNSSlider *slider = wxCocoaNSSlider::GetFromCocoa(sender);
|
|
||||||
wxCHECK_RET(slider,wxT("wxNSSliderUpArrowKeyDown received without associated wx object"));
|
|
||||||
slider->Cocoa_wxNSSliderUpArrowKeyDown();
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)wxNSSliderDownArrowKeyDown: (id)sender
|
|
||||||
{
|
|
||||||
wxCocoaNSSlider *slider = wxCocoaNSSlider::GetFromCocoa(sender);
|
|
||||||
wxCHECK_RET(slider,wxT("wxNSSliderDownArrowKeyDown received without associated wx object"));
|
|
||||||
slider->Cocoa_wxNSSliderDownArrowKeyDown();
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)wxNSSliderLeftArrowKeyDown: (id)sender
|
|
||||||
{
|
|
||||||
wxCocoaNSSlider *slider = wxCocoaNSSlider::GetFromCocoa(sender);
|
|
||||||
wxCHECK_RET(slider,wxT("wxNSSliderLeftArrowKeyDown received without associated wx object"));
|
|
||||||
slider->Cocoa_wxNSSliderLeftArrowKeyDown();
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)wxNSSliderRightArrowKeyDown: (id)sender
|
|
||||||
{
|
|
||||||
wxCocoaNSSlider *slider = wxCocoaNSSlider::GetFromCocoa(sender);
|
|
||||||
wxCHECK_RET(slider,wxT("wxNSSliderRightArrowKeyDown received without associated wx object"));
|
|
||||||
slider->Cocoa_wxNSSliderRightArrowKeyDown();
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)wxNSSliderPageUpKeyDown: (id)sender
|
|
||||||
{
|
|
||||||
wxCocoaNSSlider *slider = wxCocoaNSSlider::GetFromCocoa(sender);
|
|
||||||
wxCHECK_RET(slider,wxT("wxNSSliderPageUpKeyDown received without associated wx object"));
|
|
||||||
slider->Cocoa_wxNSSliderPageUpKeyDown();
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)wxNSSliderPageDownKeyDown: (id)sender
|
|
||||||
{
|
|
||||||
wxCocoaNSSlider *slider = wxCocoaNSSlider::GetFromCocoa(sender);
|
|
||||||
wxCHECK_RET(slider,wxT("wxNSSliderPageDownKeyDown received without associated wx object"));
|
|
||||||
slider->Cocoa_wxNSSliderPageDownKeyDown();
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)wxNSSliderMoveUp: (id)sender
|
|
||||||
{
|
|
||||||
wxCocoaNSSlider *slider = wxCocoaNSSlider::GetFromCocoa(sender);
|
|
||||||
wxCHECK_RET(slider,wxT("wxNSSliderMoveUp received without associated wx object"));
|
|
||||||
slider->Cocoa_wxNSSliderMoveUp();
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)wxNSSliderMoveDown: (id)sender
|
|
||||||
{
|
|
||||||
wxCocoaNSSlider *slider = wxCocoaNSSlider::GetFromCocoa(sender);
|
|
||||||
wxCHECK_RET(slider,wxT("wxNSSliderMoveDown received without associated wx object"));
|
|
||||||
slider->Cocoa_wxNSSliderMoveDown();
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)wxNSSliderMoveLeft: (id)sender
|
|
||||||
{
|
|
||||||
wxCocoaNSSlider *slider = wxCocoaNSSlider::GetFromCocoa(sender);
|
|
||||||
wxCHECK_RET(slider,wxT("wxNSSliderMoveLeft received without associated wx object"));
|
|
||||||
slider->Cocoa_wxNSSliderMoveLeft();
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)wxNSSliderMoveRight: (id)sender
|
|
||||||
{
|
|
||||||
wxCocoaNSSlider *slider = wxCocoaNSSlider::GetFromCocoa(sender);
|
|
||||||
wxCHECK_RET(slider,wxT("wxNSSliderMoveRight received without associated wx object"));
|
|
||||||
slider->Cocoa_wxNSSliderMoveRight();
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)wxNSSliderPageUp: (id)sender
|
|
||||||
{
|
|
||||||
wxCocoaNSSlider *slider = wxCocoaNSSlider::GetFromCocoa(sender);
|
|
||||||
wxCHECK_RET(slider,wxT("wxNSSliderPageUp received without associated wx object"));
|
|
||||||
slider->Cocoa_wxNSSliderPageUp();
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)wxNSSliderPageDown: (id)sender
|
|
||||||
{
|
|
||||||
wxCocoaNSSlider *slider = wxCocoaNSSlider::GetFromCocoa(sender);
|
|
||||||
wxCHECK_RET(slider,wxT("wxNSSliderPageDown received without associated wx object"));
|
|
||||||
slider->Cocoa_wxNSSliderPageDown();
|
|
||||||
}
|
|
||||||
|
|
||||||
@end // implementation wxNSSliderTarget
|
|
||||||
|
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
// @class WXNSSlider
|
// @class WXNSSlider
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
|
|
||||||
|
|
||||||
@implementation WXNSSlider : NSSlider
|
@implementation WXNSSlider : NSSlider
|
||||||
|
|
||||||
// Override to ensure that WXNSSlider gets created with a WXNSSliderCell
|
// Override to ensure that WXNSSlider gets created with a WXNSSliderCell
|
||||||
@@ -146,83 +56,53 @@ WX_IMPLEMENT_OBJC_INTERFACE_HASHMAP(NSSlider)
|
|||||||
return [WX_GET_OBJC_CLASS(WXNSSliderCell) class];
|
return [WX_GET_OBJC_CLASS(WXNSSliderCell) class];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// The following methods are all NSResponder methods which NSSlider responds
|
||||||
|
// to in order to change its state and send the action message. We override
|
||||||
|
// them simply to record which one was called. This allows code listening
|
||||||
|
// only for the action message to determine what caused the action.
|
||||||
|
// Note that this is perfectly fine being a global because Cocoa processes
|
||||||
|
// events synchronously and only in the main thread.
|
||||||
|
|
||||||
- (void)keyDown:(NSEvent *)theEvent
|
- (void)keyDown:(NSEvent *)theEvent
|
||||||
{
|
{
|
||||||
SEL originalAction = [self action];
|
wxCocoaNSSliderLastSelectorChanger savedSelector(_cmd);
|
||||||
SEL newAction = originalAction;
|
|
||||||
NSString *theEventCharacters = [theEvent charactersIgnoringModifiers];
|
|
||||||
|
|
||||||
if ([theEventCharacters length] == 1)
|
|
||||||
{
|
|
||||||
switch ([theEventCharacters characterAtIndex:0])
|
|
||||||
{
|
|
||||||
case NSUpArrowFunctionKey: newAction = @selector(wxNSSliderUpArrowKeyDown:); break;
|
|
||||||
case NSDownArrowFunctionKey: newAction = @selector(wxNSSliderDownArrowKeyDown:); break;
|
|
||||||
case NSLeftArrowFunctionKey: newAction = @selector(wxNSSliderLeftArrowKeyDown:); break;
|
|
||||||
case NSRightArrowFunctionKey: newAction = @selector(wxNSSliderRightArrowKeyDown:); break;
|
|
||||||
case NSPageUpFunctionKey: newAction = @selector(wxNSSliderPageUpKeyDown:); break;
|
|
||||||
case NSPageDownFunctionKey: newAction = @selector(wxNSSliderPageDownKeyDown:); break;
|
|
||||||
default: break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
[self setAction:newAction];
|
|
||||||
[super keyDown:theEvent];
|
[super keyDown:theEvent];
|
||||||
[self setAction:originalAction];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)moveUp:(id)sender
|
- (void)moveUp:(id)sender
|
||||||
{
|
{
|
||||||
SEL originalAction = [self action];
|
wxCocoaNSSliderLastSelectorChanger savedSelector(_cmd);
|
||||||
|
|
||||||
[self setAction:@selector(wxNSSliderMoveUp:)];
|
|
||||||
[super moveUp:sender];
|
[super moveUp:sender];
|
||||||
[self setAction:originalAction];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)moveDown:(id)sender
|
- (void)moveDown:(id)sender
|
||||||
{
|
{
|
||||||
SEL originalAction = [self action];
|
wxCocoaNSSliderLastSelectorChanger savedSelector(_cmd);
|
||||||
|
|
||||||
[self setAction:@selector(wxNSSliderMoveDown:)];
|
|
||||||
[super moveDown:sender];
|
[super moveDown:sender];
|
||||||
[self setAction:originalAction];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)moveLeft:(id)sender
|
- (void)moveLeft:(id)sender
|
||||||
{
|
{
|
||||||
SEL originalAction = [self action];
|
wxCocoaNSSliderLastSelectorChanger savedSelector(_cmd);
|
||||||
|
|
||||||
[self setAction:@selector(wxNSSliderMoveLeft:)];
|
|
||||||
[super moveLeft:sender];
|
[super moveLeft:sender];
|
||||||
[self setAction:originalAction];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)moveRight:(id)sender
|
- (void)moveRight:(id)sender
|
||||||
{
|
{
|
||||||
SEL originalAction = [self action];
|
wxCocoaNSSliderLastSelectorChanger savedSelector(_cmd);
|
||||||
|
|
||||||
[self setAction:@selector(wxNSSliderMoveRight:)];
|
|
||||||
[super moveRight:sender];
|
[super moveRight:sender];
|
||||||
[self setAction:originalAction];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)pageUp:(id)sender
|
- (void)pageUp:(id)sender
|
||||||
{
|
{
|
||||||
SEL originalAction = [self action];
|
wxCocoaNSSliderLastSelectorChanger savedSelector(_cmd);
|
||||||
|
|
||||||
[self setAction:@selector(wxNSSliderPageUp:)];
|
|
||||||
[super pageUp:sender];
|
[super pageUp:sender];
|
||||||
[self setAction:originalAction];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)pageDown:(id)sender
|
- (void)pageDown:(id)sender
|
||||||
{
|
{
|
||||||
SEL originalAction = [self action];
|
wxCocoaNSSliderLastSelectorChanger savedSelector(_cmd);
|
||||||
|
|
||||||
[self setAction:@selector(wxNSSliderPageDown:)];
|
|
||||||
[super pageDown:sender];
|
[super pageDown:sender];
|
||||||
[self setAction:originalAction];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
@@ -232,10 +112,6 @@ WX_IMPLEMENT_GET_OBJC_CLASS(WXNSSlider,NSSlider)
|
|||||||
// @class WXNSSliderCell
|
// @class WXNSSliderCell
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
|
|
||||||
#define kwxNSSliderStartTracking @"wxNSSliderStartTracking"
|
|
||||||
#define kwxNSSliderContinueTracking @"wxNSSliderContinueTracking"
|
|
||||||
#define kwxNSSliderStopTracking @"wxNSSliderStopTracking"
|
|
||||||
|
|
||||||
@implementation WXNSSliderCell : NSSliderCell
|
@implementation WXNSSliderCell : NSSliderCell
|
||||||
- (BOOL)startTrackingAt:(NSPoint)startPoint inView:(NSView *)controlView
|
- (BOOL)startTrackingAt:(NSPoint)startPoint inView:(NSView *)controlView
|
||||||
{
|
{
|
||||||
@@ -273,15 +149,14 @@ WX_IMPLEMENT_GET_OBJC_CLASS(WXNSSliderCell,NSSliderCell)
|
|||||||
// ============================================================================
|
// ============================================================================
|
||||||
// class wxCocoaNSSlider
|
// class wxCocoaNSSlider
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
const wxObjcAutoRefFromAlloc<struct objc_object*> wxCocoaNSSlider::sm_cocoaTarget = [[wxNSSliderTarget alloc] init];
|
|
||||||
|
|
||||||
|
SEL wxCocoaNSSlider::sm_lastResponderSelector;
|
||||||
|
|
||||||
void wxCocoaNSSlider::AssociateNSSlider(WX_NSSlider cocoaNSSlider)
|
void wxCocoaNSSlider::AssociateNSSlider(WX_NSSlider cocoaNSSlider)
|
||||||
{
|
{
|
||||||
if(cocoaNSSlider)
|
if(cocoaNSSlider)
|
||||||
{
|
{
|
||||||
sm_cocoaHash.insert(wxCocoaNSSliderHash::value_type(cocoaNSSlider,this));
|
sm_cocoaHash.insert(wxCocoaNSSliderHash::value_type(cocoaNSSlider,this));
|
||||||
[cocoaNSSlider setTarget:sm_cocoaTarget];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -21,7 +21,10 @@
|
|||||||
#include "wx/app.h"
|
#include "wx/app.h"
|
||||||
#endif //WX_PRECOMP
|
#endif //WX_PRECOMP
|
||||||
|
|
||||||
|
#import <Foundation/NSString.h>
|
||||||
#include "wx/cocoa/objc/NSSlider.h"
|
#include "wx/cocoa/objc/NSSlider.h"
|
||||||
|
#import <AppKit/NSEvent.h>
|
||||||
|
#import <AppKit/NSWindow.h>
|
||||||
|
|
||||||
IMPLEMENT_DYNAMIC_CLASS(wxSlider, wxControl)
|
IMPLEMENT_DYNAMIC_CLASS(wxSlider, wxControl)
|
||||||
BEGIN_EVENT_TABLE(wxSlider, wxSliderBase)
|
BEGIN_EVENT_TABLE(wxSlider, wxSliderBase)
|
||||||
@@ -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)
|
void wxSlider::ProcessEventType(wxEventType commandType)
|
||||||
{
|
{
|
||||||
wxScrollEvent event(commandType, GetId(), GetValue(), HasFlag(wxSL_VERTICAL)?wxVERTICAL:wxHORIZONTAL);
|
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)
|
void wxSlider::CocoaNotification_startTracking(WX_NSNotification notification)
|
||||||
{
|
{
|
||||||
CocoaNotification_continueTracking(notification);
|
CocoaNotification_continueTracking(notification);
|
||||||
|
Reference in New Issue
Block a user