Major wxCocoa wxSlider overhaul from Mark Oxenham.
Copyright 2007 Software 2000 Ltd. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@48010 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
53
include/wx/cocoa/NSSlider.h
Normal file
53
include/wx/cocoa/NSSlider.h
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
// Name: wx/cocoa/NSSlider.h
|
||||||
|
// Purpose: wxCocoaNSSlider class
|
||||||
|
// Author: Mark Oxenham
|
||||||
|
// Modified by:
|
||||||
|
// Created: 2007/08/10
|
||||||
|
// RCS-ID: $Id: $
|
||||||
|
// Copyright: (c) 2007 Software 2000 Ltd. All rights reserved.
|
||||||
|
// Licence: wxWidgets licence
|
||||||
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
#ifndef _WXNSSLIDER_H_
|
||||||
|
#define _WXNSSLIDER_H_
|
||||||
|
|
||||||
|
#include "wx/hashmap.h"
|
||||||
|
#include "wx/cocoa/ObjcAssociate.h"
|
||||||
|
#include "wx/cocoa/ObjcRef.h"
|
||||||
|
|
||||||
|
DECLARE_WXCOCOA_OBJC_CLASS(NSSlider);
|
||||||
|
|
||||||
|
WX_DECLARE_OBJC_HASHMAP(NSSlider);
|
||||||
|
|
||||||
|
class wxCocoaNSSlider
|
||||||
|
{
|
||||||
|
WX_DECLARE_OBJC_INTERFACE_HASHMAP(NSSlider);
|
||||||
|
public:
|
||||||
|
void AssociateNSSlider(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_continueTracking(WX_NSNotification notification) = 0;
|
||||||
|
virtual void CocoaNotification_stopTracking(WX_NSNotification notification) = 0;
|
||||||
|
virtual ~wxCocoaNSSlider() { }
|
||||||
|
|
||||||
|
protected:
|
||||||
|
static const wxObjcAutoRefFromAlloc<struct objc_object*> sm_cocoaTarget;
|
||||||
|
static struct objc_object *sm_cocoaObserver;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
@@ -2,26 +2,28 @@
|
|||||||
// Name: wx/cocoa/slider.h
|
// Name: wx/cocoa/slider.h
|
||||||
// Purpose: wxSlider class
|
// Purpose: wxSlider class
|
||||||
// Author: David Elliott
|
// Author: David Elliott
|
||||||
|
// Mark Oxenham
|
||||||
// Modified by:
|
// Modified by:
|
||||||
// Created: 2003/06/19
|
// Created: 2003/06/19
|
||||||
// RCS-ID: $Id$
|
// RCS-ID: $Id$
|
||||||
// Copyright: (c) 2003 David Elliott
|
// Copyright: (c) 2003 David Elliott
|
||||||
|
// (c) 2007 Software 2000 Ltd.
|
||||||
// Licence: wxWindows licence
|
// Licence: wxWindows licence
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#ifndef __WX_COCOA_SLIDER_H__
|
#ifndef __WX_COCOA_SLIDER_H__
|
||||||
#define __WX_COCOA_SLIDER_H__
|
#define __WX_COCOA_SLIDER_H__
|
||||||
|
|
||||||
// #include "wx/cocoa/NSSlider.h"
|
#include "wx/cocoa/NSSlider.h"
|
||||||
|
|
||||||
// ========================================================================
|
// ========================================================================
|
||||||
// wxSlider
|
// wxSlider
|
||||||
// ========================================================================
|
// ========================================================================
|
||||||
class WXDLLEXPORT wxSlider: public wxSliderBase// , protected wxCocoaNSSlider
|
class WXDLLEXPORT wxSlider: public wxSliderBase, protected wxCocoaNSSlider
|
||||||
{
|
{
|
||||||
DECLARE_DYNAMIC_CLASS(wxSlider)
|
DECLARE_DYNAMIC_CLASS(wxSlider)
|
||||||
DECLARE_EVENT_TABLE()
|
DECLARE_EVENT_TABLE()
|
||||||
// WX_DECLARE_COCOA_OWNER(NSSlider,NSControl,NSView)
|
WX_DECLARE_COCOA_OWNER(NSSlider,NSControl,NSView)
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
// initialization
|
// initialization
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
@@ -52,30 +54,56 @@ public:
|
|||||||
// Cocoa callbacks
|
// Cocoa callbacks
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
protected:
|
protected:
|
||||||
|
// from NSSLider
|
||||||
|
virtual void ProcessEventType(wxEventType commandType);
|
||||||
|
virtual void Cocoa_wxNSSliderUpArrowKeyDown(void) { ProcessEventType(wxEVT_SCROLL_PAGEDOWN); }
|
||||||
|
virtual void Cocoa_wxNSSliderDownArrowKeyDown(void) { ProcessEventType(wxEVT_SCROLL_PAGEUP); }
|
||||||
|
virtual void Cocoa_wxNSSliderLeftArrowKeyDown(void) { ProcessEventType(wxEVT_SCROLL_PAGEUP); }
|
||||||
|
virtual void Cocoa_wxNSSliderRightArrowKeyDown(void) { ProcessEventType(wxEVT_SCROLL_PAGEDOWN); }
|
||||||
|
virtual void Cocoa_wxNSSliderPageUpKeyDown(void) { ProcessEventType(wxEVT_SCROLL_BOTTOM); }
|
||||||
|
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_continueTracking(WX_NSNotification notification);
|
||||||
|
virtual void CocoaNotification_stopTracking(WX_NSNotification notification);
|
||||||
|
|
||||||
|
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
// Implementation
|
// Implementation
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
public:
|
public:
|
||||||
// Pure Virtuals
|
// Pure Virtuals
|
||||||
virtual int GetValue() const { return 0; }
|
virtual int GetValue() const;
|
||||||
virtual void SetValue(int value) { }
|
virtual void SetValue(int value);
|
||||||
|
|
||||||
// retrieve/change the range
|
// retrieve/change the range
|
||||||
virtual void SetRange(int minValue, int maxValue) { }
|
virtual void SetRange(int minValue, int maxValue);
|
||||||
virtual int GetMin() const { return 0; }
|
virtual int GetMin() const;
|
||||||
virtual int GetMax() const { return 0; }
|
virtual int GetMax() const;
|
||||||
|
|
||||||
// the line/page size is the increment by which the slider moves when
|
// the line/page size is the increment by which the slider moves when
|
||||||
// cursor arrow key/page up or down are pressed (clicking the mouse is like
|
// cursor arrow key/page up or down are pressed (clicking the mouse is like
|
||||||
// pressing PageUp/Down) and are by default set to 1 and 1/10 of the range
|
// pressing PageUp/Down) and are by default set to 1 and 1/10 of the range
|
||||||
virtual void SetLineSize(int lineSize) { }
|
virtual void SetLineSize(int lineSize);
|
||||||
virtual void SetPageSize(int pageSize) { }
|
virtual void SetPageSize(int pageSize);
|
||||||
virtual int GetLineSize() const { return 0; }
|
virtual int GetLineSize() const;
|
||||||
virtual int GetPageSize() const { return 0; }
|
virtual int GetPageSize() const;
|
||||||
|
|
||||||
// these methods get/set the length of the slider pointer in pixels
|
// these methods get/set the length of the slider pointer in pixels
|
||||||
virtual void SetThumbLength(int lenPixels) { }
|
virtual void SetThumbLength(int lenPixels);
|
||||||
virtual int GetThumbLength() const { return 0; }
|
virtual int GetThumbLength() const;
|
||||||
|
|
||||||
|
// copied from (wxSliderCocoa.h)
|
||||||
|
virtual void SetTickFreq(int n, int pos);
|
||||||
|
virtual int GetTickFreq() const;
|
||||||
|
virtual void ClearTicks() { SetTickFreq(0, 0); }
|
||||||
|
|
||||||
|
virtual void SetTickPos(int pos);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
328
src/cocoa/NSSlider.mm
Normal file
328
src/cocoa/NSSlider.mm
Normal file
@@ -0,0 +1,328 @@
|
|||||||
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
// Name: src/cocoa/NSSlider.mm
|
||||||
|
// Purpose: wxCocoaNSSlider class
|
||||||
|
// Author: Mark Oxenham
|
||||||
|
// Modified by:
|
||||||
|
// Created: 2007/08/10
|
||||||
|
// RCS-ID: $Id: $
|
||||||
|
// Copyright: (c) 2007 Software 2000 Ltd. All rights reserved.
|
||||||
|
// Licence: wxWidgets licence
|
||||||
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
#include "wx/wxprec.h"
|
||||||
|
|
||||||
|
#ifndef WX_PRECOMP
|
||||||
|
#include "wx/log.h"
|
||||||
|
#endif // WX_PRECOMP
|
||||||
|
|
||||||
|
#include "wx/cocoa/ObjcPose.h"
|
||||||
|
#include "wx/cocoa/NSSlider.h"
|
||||||
|
|
||||||
|
#import <Foundation/NSNotification.h>
|
||||||
|
#import <Foundation/NSString.h>
|
||||||
|
#import <AppKit/NSEvent.h>
|
||||||
|
#import <AppKit/NSSlider.h>
|
||||||
|
|
||||||
|
WX_IMPLEMENT_OBJC_INTERFACE_HASHMAP(NSSlider)
|
||||||
|
|
||||||
|
// ============================================================================
|
||||||
|
// @class wxNSSliderTarget
|
||||||
|
// ============================================================================
|
||||||
|
@interface wxNSSliderTarget : NSObject
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)wxNSSliderUpArrowKeyDown: (id)sender;
|
||||||
|
- (void)wxNSSliderDownArrowKeyDown: (id)sender;
|
||||||
|
- (void)wxNSSliderLeftArrowKeyDown: (id)sender;
|
||||||
|
- (void)wxNSSliderRightArrowKeyDown: (id)sender;
|
||||||
|
- (void)wxNSSliderPageUpKeyDown: (id)sender;
|
||||||
|
- (void)wxNSSliderPageDownKeyDown: (id)sender;
|
||||||
|
- (void)wxNSSliderMoveUp: (id)sender;
|
||||||
|
- (void)wxNSSliderMoveDown: (id)sender;
|
||||||
|
- (void)wxNSSliderMoveLeft: (id)sender;
|
||||||
|
- (void)wxNSSliderMoveRight: (id)sender;
|
||||||
|
- (void)wxNSSliderPageUp: (id)sender;
|
||||||
|
- (void)wxNSSliderPageDown: (id)sender;
|
||||||
|
@end // wxNSSliderTarget
|
||||||
|
|
||||||
|
@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 wxPoserNSSlider
|
||||||
|
// ============================================================================
|
||||||
|
|
||||||
|
@interface wxPoserNSSlider : NSSlider
|
||||||
|
@end
|
||||||
|
|
||||||
|
WX_IMPLEMENT_POSER(wxPoserNSSlider);
|
||||||
|
@implementation wxPoserNSSlider : NSSlider
|
||||||
|
|
||||||
|
- (void)keyDown:(NSEvent *)theEvent
|
||||||
|
{
|
||||||
|
SEL originalAction = [self action];
|
||||||
|
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];
|
||||||
|
[self setAction:originalAction];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)moveUp:(id)sender
|
||||||
|
{
|
||||||
|
SEL originalAction = [self action];
|
||||||
|
|
||||||
|
[self setAction:@selector(wxNSSliderMoveUp:)];
|
||||||
|
[super moveUp:sender];
|
||||||
|
[self setAction:originalAction];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)moveDown:(id)sender
|
||||||
|
{
|
||||||
|
SEL originalAction = [self action];
|
||||||
|
|
||||||
|
[self setAction:@selector(wxNSSliderMoveDown:)];
|
||||||
|
[super moveDown:sender];
|
||||||
|
[self setAction:originalAction];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)moveLeft:(id)sender
|
||||||
|
{
|
||||||
|
SEL originalAction = [self action];
|
||||||
|
|
||||||
|
[self setAction:@selector(wxNSSliderMoveLeft:)];
|
||||||
|
[super moveLeft:sender];
|
||||||
|
[self setAction:originalAction];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)moveRight:(id)sender
|
||||||
|
{
|
||||||
|
SEL originalAction = [self action];
|
||||||
|
|
||||||
|
[self setAction:@selector(wxNSSliderMoveRight:)];
|
||||||
|
[super moveRight:sender];
|
||||||
|
[self setAction:originalAction];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)pageUp:(id)sender
|
||||||
|
{
|
||||||
|
SEL originalAction = [self action];
|
||||||
|
|
||||||
|
[self setAction:@selector(wxNSSliderPageUp:)];
|
||||||
|
[super pageUp:sender];
|
||||||
|
[self setAction:originalAction];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)pageDown:(id)sender
|
||||||
|
{
|
||||||
|
SEL originalAction = [self action];
|
||||||
|
|
||||||
|
[self setAction:@selector(wxNSSliderPageDown:)];
|
||||||
|
[super pageDown:sender];
|
||||||
|
[self setAction:originalAction];
|
||||||
|
}
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
|
// ============================================================================
|
||||||
|
// @class wxPoserNSSliderCell
|
||||||
|
// ============================================================================
|
||||||
|
|
||||||
|
#define kwxNSSliderStartTracking @"wxNSSliderStartTracking"
|
||||||
|
#define kwxNSSliderContinueTracking @"wxNSSliderContinueTracking"
|
||||||
|
#define kwxNSSliderStopTracking @"wxNSSliderStopTracking"
|
||||||
|
|
||||||
|
@interface wxPoserNSSliderCell : NSSliderCell
|
||||||
|
@end
|
||||||
|
|
||||||
|
WX_IMPLEMENT_POSER(wxPoserNSSliderCell);
|
||||||
|
@implementation wxPoserNSSliderCell : NSSliderCell
|
||||||
|
- (BOOL)startTrackingAt:(NSPoint)startPoint inView:(NSView *)controlView
|
||||||
|
{
|
||||||
|
BOOL result = [super startTrackingAt:startPoint inView:controlView];
|
||||||
|
[[NSNotificationCenter defaultCenter] postNotificationName:kwxNSSliderStartTracking object:controlView];
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (BOOL)continueTracking:(NSPoint)lastPoint at:(NSPoint)currentPoint inView:(NSView *)controlView
|
||||||
|
{
|
||||||
|
BOOL result = [super continueTracking:lastPoint at:currentPoint inView:controlView];
|
||||||
|
[[NSNotificationCenter defaultCenter] postNotificationName:kwxNSSliderContinueTracking object:controlView];
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)stopTracking:(NSPoint)lastPoint at:(NSPoint)stopPoint inView:(NSView *)controlView mouseIsUp:(BOOL)flag
|
||||||
|
{
|
||||||
|
[super stopTracking:lastPoint at:stopPoint inView:controlView mouseIsUp:flag];
|
||||||
|
[[NSNotificationCenter defaultCenter] postNotificationName:kwxNSSliderStopTracking object:controlView];
|
||||||
|
}
|
||||||
|
@end
|
||||||
|
|
||||||
|
// ============================================================================
|
||||||
|
// @class wxNSSliderNotificationObserver
|
||||||
|
// ============================================================================
|
||||||
|
@interface wxNSSliderNotificationObserver : NSObject
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
struct objc_object *wxCocoaNSSlider::sm_cocoaObserver = [[wxNSSliderNotificationObserver alloc] init];
|
||||||
|
|
||||||
|
- (void)startTracking: (NSNotification *)notification;
|
||||||
|
- (void)continueTracking: (NSNotification *)notification;
|
||||||
|
- (void)stopTracking: (NSNotification *)notification;
|
||||||
|
@end // interface wxNSSliderNotificationObserver
|
||||||
|
|
||||||
|
@implementation wxNSSliderNotificationObserver : NSObject
|
||||||
|
|
||||||
|
- (void)startTracking: (NSNotification *)notification;
|
||||||
|
{
|
||||||
|
wxCocoaNSSlider *slider = wxCocoaNSSlider::GetFromCocoa([notification object]);
|
||||||
|
wxCHECK_RET(slider,wxT("startTracking received but no wxSlider exists"));
|
||||||
|
slider->CocoaNotification_startTracking(notification);
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)continueTracking: (NSNotification *)notification;
|
||||||
|
{
|
||||||
|
wxCocoaNSSlider *slider = wxCocoaNSSlider::GetFromCocoa([notification object]);
|
||||||
|
wxCHECK_RET(slider,wxT("continueTracking received but no wxSlider exists"));
|
||||||
|
slider->CocoaNotification_continueTracking(notification);
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)stopTracking: (NSNotification *)notification;
|
||||||
|
{
|
||||||
|
wxCocoaNSSlider *slider = wxCocoaNSSlider::GetFromCocoa([notification object]);
|
||||||
|
wxCHECK_RET(slider,wxT("stopTracking received but no wxSlider exists"));
|
||||||
|
slider->CocoaNotification_stopTracking(notification);
|
||||||
|
}
|
||||||
|
|
||||||
|
@end // implementation wxNSSliderNotificationObserver
|
||||||
|
|
||||||
|
// ============================================================================
|
||||||
|
// class wxCocoaNSSlider
|
||||||
|
// ============================================================================
|
||||||
|
const wxObjcAutoRefFromAlloc<struct objc_object*> wxCocoaNSSlider::sm_cocoaTarget = [[wxNSSliderTarget alloc] init];
|
||||||
|
|
||||||
|
|
||||||
|
void wxCocoaNSSlider::AssociateNSSlider(WX_NSSlider cocoaNSSlider)
|
||||||
|
{
|
||||||
|
if(cocoaNSSlider)
|
||||||
|
{
|
||||||
|
sm_cocoaHash.insert(wxCocoaNSSliderHash::value_type(cocoaNSSlider,this));
|
||||||
|
[[NSNotificationCenter defaultCenter] addObserver:(id)sm_cocoaObserver selector:@selector(startTracking:) name:kwxNSSliderStartTracking object:cocoaNSSlider];
|
||||||
|
[[NSNotificationCenter defaultCenter] addObserver:(id)sm_cocoaObserver selector:@selector(continueTracking:) name:kwxNSSliderContinueTracking object:cocoaNSSlider];
|
||||||
|
[[NSNotificationCenter defaultCenter] addObserver:(id)sm_cocoaObserver selector:@selector(stopTracking:) name:kwxNSSliderStopTracking object:cocoaNSSlider];
|
||||||
|
[cocoaNSSlider setTarget:sm_cocoaTarget];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxCocoaNSSlider::DisassociateNSSlider(WX_NSSlider cocoaNSSlider)
|
||||||
|
{
|
||||||
|
if(cocoaNSSlider)
|
||||||
|
{
|
||||||
|
sm_cocoaHash.erase(cocoaNSSlider);
|
||||||
|
[[NSNotificationCenter defaultCenter] removeObserver:(id)sm_cocoaObserver name:kwxNSSliderStartTracking object:cocoaNSSlider];
|
||||||
|
[[NSNotificationCenter defaultCenter] removeObserver:(id)sm_cocoaObserver name:kwxNSSliderContinueTracking object:cocoaNSSlider];
|
||||||
|
[[NSNotificationCenter defaultCenter] removeObserver:(id)sm_cocoaObserver name:kwxNSSliderStopTracking object:cocoaNSSlider];
|
||||||
|
}
|
||||||
|
}
|
@@ -2,10 +2,12 @@
|
|||||||
// Name: src/cocoa/slider.mm
|
// Name: src/cocoa/slider.mm
|
||||||
// Purpose: wxSlider
|
// Purpose: wxSlider
|
||||||
// Author: David Elliott
|
// Author: David Elliott
|
||||||
|
// Mark Oxenham
|
||||||
// Modified by:
|
// Modified by:
|
||||||
// Created: 2003/06/19
|
// Created: 2003/06/19
|
||||||
// RCS-ID: $Id$
|
// RCS-ID: $Id$
|
||||||
// Copyright: (c) 2003 David Elliott
|
// Copyright: (c) 2003 David Elliott
|
||||||
|
// (c) 2007 Software 2000 Ltd.
|
||||||
// Licence: wxWidgets licence
|
// Licence: wxWidgets licence
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
@@ -24,26 +26,177 @@
|
|||||||
IMPLEMENT_DYNAMIC_CLASS(wxSlider, wxControl)
|
IMPLEMENT_DYNAMIC_CLASS(wxSlider, wxControl)
|
||||||
BEGIN_EVENT_TABLE(wxSlider, wxSliderBase)
|
BEGIN_EVENT_TABLE(wxSlider, wxSliderBase)
|
||||||
END_EVENT_TABLE()
|
END_EVENT_TABLE()
|
||||||
// WX_IMPLEMENT_COCOA_OWNER(wxSlider,NSSlider,NSControl,NSView)
|
WX_IMPLEMENT_COCOA_OWNER(wxSlider,NSSlider,NSControl,NSView)
|
||||||
|
|
||||||
|
|
||||||
|
inline void AdjustDimension(
|
||||||
|
bool isTicksStyle,
|
||||||
|
int &pos,
|
||||||
|
wxSize &size,
|
||||||
|
int (wxSize::*GetDimension)() const,
|
||||||
|
void (wxSize::*SetDimension)(int))
|
||||||
|
{
|
||||||
|
const int dimension = (size.*GetDimension)();
|
||||||
|
const int minSize = (isTicksStyle) ? 23 : 20;
|
||||||
|
|
||||||
|
if (dimension < minSize)
|
||||||
|
{
|
||||||
|
(size.*SetDimension)(minSize);
|
||||||
|
}
|
||||||
|
|
||||||
|
pos += (dimension - (size.*GetDimension)() + 1) / 2;
|
||||||
|
}
|
||||||
|
|
||||||
bool wxSlider::Create(wxWindow *parent, wxWindowID winid,
|
bool wxSlider::Create(wxWindow *parent, wxWindowID winid,
|
||||||
int value, int minValue, int maxValue,
|
int value, int minValue, int maxValue,
|
||||||
const wxPoint& pos, const wxSize& size, long style,
|
const wxPoint& pos, const wxSize& size, long style,
|
||||||
const wxValidator& validator, const wxString& name)
|
const wxValidator& validator, const wxString& name)
|
||||||
{
|
{
|
||||||
|
wxSize adjustedSize(size);
|
||||||
|
wxPoint adjustedPos(pos);
|
||||||
|
const bool isTicksStyle = (style & wxSL_TICKS) != 0;
|
||||||
|
|
||||||
|
if ((style & wxSL_HORIZONTAL) && (size.GetHeight() != wxDefaultCoord))
|
||||||
|
{
|
||||||
|
AdjustDimension(isTicksStyle, adjustedPos.y, adjustedSize, &wxSize::GetHeight, &wxSize::SetHeight);
|
||||||
|
}
|
||||||
|
else if ((style & wxSL_VERTICAL) && (size.GetWidth() != wxDefaultCoord))
|
||||||
|
{
|
||||||
|
AdjustDimension(isTicksStyle, adjustedPos.x, adjustedSize, &wxSize::GetWidth, &wxSize::SetWidth);
|
||||||
|
}
|
||||||
|
|
||||||
if(!CreateControl(parent,winid,pos,size,style,validator,name))
|
if(!CreateControl(parent,winid,pos,size,style,validator,name))
|
||||||
return false;
|
return false;
|
||||||
SetNSView([[NSSlider alloc] initWithFrame: MakeDefaultNSRect(size)]);
|
SetNSView([[NSSlider alloc] initWithFrame: MakeDefaultNSRect(size)]);
|
||||||
[m_cocoaNSView release];
|
[m_cocoaNSView release];
|
||||||
|
|
||||||
if(m_parent)
|
if(m_parent)
|
||||||
m_parent->CocoaAddChild(this);
|
m_parent->CocoaAddChild(this);
|
||||||
SetInitialFrameRect(pos,size);
|
SetInitialFrameRect(pos,size);
|
||||||
|
|
||||||
|
SetRange(minValue, maxValue);
|
||||||
|
SetValue(value);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
wxSlider::~wxSlider()
|
wxSlider::~wxSlider()
|
||||||
{
|
{
|
||||||
|
DisassociateNSSlider(GetNSSlider());
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxSlider::ProcessEventType(wxEventType commandType)
|
||||||
|
{
|
||||||
|
wxScrollEvent event(commandType, GetId(), GetValue(), HasFlag(wxSL_VERTICAL)?wxVERTICAL:wxHORIZONTAL);
|
||||||
|
event.SetEventObject(this);
|
||||||
|
GetEventHandler()->ProcessEvent(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxSlider::CocoaNotification_startTracking(WX_NSNotification notification)
|
||||||
|
{
|
||||||
|
CocoaNotification_continueTracking(notification);
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxSlider::CocoaNotification_continueTracking(WX_NSNotification notification)
|
||||||
|
{
|
||||||
|
const double realValue = [GetNSSlider() doubleValue];
|
||||||
|
|
||||||
|
if (realValue != [GetNSSlider() intValue])
|
||||||
|
{
|
||||||
|
SetValue(rint(realValue));
|
||||||
|
}
|
||||||
|
|
||||||
|
ProcessEventType(wxEVT_SCROLL_THUMBTRACK);
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxSlider::CocoaNotification_stopTracking(WX_NSNotification notification)
|
||||||
|
{
|
||||||
|
ProcessEventType(wxEVT_SCROLL_THUMBRELEASE);
|
||||||
|
}
|
||||||
|
|
||||||
|
int wxSlider::GetValue() const
|
||||||
|
{
|
||||||
|
return [GetNSSlider() intValue];
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxSlider::SetValue(int value)
|
||||||
|
{
|
||||||
|
[GetNSSlider() setIntValue:value];
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxSlider::SetRange(int minValue, int maxValue)
|
||||||
|
{
|
||||||
|
[GetNSSlider() setMinValue:minValue];
|
||||||
|
[GetNSSlider() setMaxValue:maxValue];
|
||||||
|
}
|
||||||
|
|
||||||
|
int wxSlider::GetMin() const
|
||||||
|
{
|
||||||
|
return [GetNSSlider() minValue];
|
||||||
|
}
|
||||||
|
|
||||||
|
int wxSlider::GetMax() const
|
||||||
|
{
|
||||||
|
return [GetNSSlider() maxValue];
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxSlider::SetTickFreq(int n, int pos)
|
||||||
|
{
|
||||||
|
const int numTicks = (n > 0) ? ((GetMax() - GetMin()) / n) + 1 : 0;
|
||||||
|
[GetNSSlider() setNumberOfTickMarks:numTicks];
|
||||||
|
}
|
||||||
|
|
||||||
|
int wxSlider::GetTickFreq() const
|
||||||
|
{
|
||||||
|
const int numTicks = [GetNSSlider() numberOfTickMarks];
|
||||||
|
return ((numTicks != 0) ? (GetMax() - GetMin()) / (numTicks - 1) : 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxSlider::SetTickPos(int pos)
|
||||||
|
{
|
||||||
|
NSTickMarkPosition thePos = NSTickMarkBelow;
|
||||||
|
wxSize size = GetSize();
|
||||||
|
|
||||||
|
if (size.GetWidth() < size.GetHeight()) // NSSlider isVertical method can return -1 if it has not been displayed.
|
||||||
|
{
|
||||||
|
thePos = (pos != 1) ? NSTickMarkLeft : NSTickMarkRight;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
thePos = (pos != 1) ? NSTickMarkBelow : NSTickMarkAbove;
|
||||||
|
}
|
||||||
|
|
||||||
|
[GetNSSlider() setTickMarkPosition:thePos];
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxSlider::SetLineSize(int lineSize)
|
||||||
|
{
|
||||||
|
// to do
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxSlider::SetPageSize(int pageSize)
|
||||||
|
{
|
||||||
|
// to do
|
||||||
|
}
|
||||||
|
|
||||||
|
int wxSlider::GetLineSize() const
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int wxSlider::GetPageSize() const
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int wxSlider::GetThumbLength() const
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxSlider::SetThumbLength(int lenPixels)
|
||||||
|
{
|
||||||
|
// to do
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // wxUSE_SLIDER
|
#endif // wxUSE_SLIDER
|
||||||
|
Reference in New Issue
Block a user