diff --git a/Makefile.in b/Makefile.in index dd0652be84..7f0e3269c7 100644 --- a/Makefile.in +++ b/Makefile.in @@ -1937,6 +1937,7 @@ COND_TOOLKIT_COCOA_GUI_HDR = \ wx/cocoa/NSMenu.h \ wx/cocoa/NSPanel.h \ wx/cocoa/NSScroller.h \ + wx/cocoa/NSSlider.h \ wx/cocoa/NSTabView.h \ wx/cocoa/NSTableView.h \ wx/cocoa/NSTextField.h \ @@ -4050,6 +4051,7 @@ COND_TOOLKIT_COCOA___GUI_SRC_OBJECTS = \ monodll_NSMenu.o \ monodll_NSPanel.o \ monodll_NSScroller.o \ + monodll_NSSlider.o \ monodll_NSTabView.o \ monodll_NSTableView.o \ monodll_NSTextField.o \ @@ -5836,6 +5838,7 @@ COND_TOOLKIT_COCOA___GUI_SRC_OBJECTS_1 = \ monolib_NSMenu.o \ monolib_NSPanel.o \ monolib_NSScroller.o \ + monolib_NSSlider.o \ monolib_NSTabView.o \ monolib_NSTableView.o \ monolib_NSTextField.o \ @@ -7850,6 +7853,7 @@ COND_TOOLKIT_COCOA___GUI_SRC_OBJECTS_2 = \ coredll_NSMenu.o \ coredll_NSPanel.o \ coredll_NSScroller.o \ + coredll_NSSlider.o \ coredll_NSTabView.o \ coredll_NSTableView.o \ coredll_NSTextField.o \ @@ -9308,6 +9312,7 @@ COND_TOOLKIT_COCOA___GUI_SRC_OBJECTS_3 = \ corelib_NSMenu.o \ corelib_NSPanel.o \ corelib_NSScroller.o \ + corelib_NSSlider.o \ corelib_NSTabView.o \ corelib_NSTableView.o \ corelib_NSTextField.o \ @@ -12973,6 +12978,9 @@ monodll_NSPanel.o: $(srcdir)/src/cocoa/NSPanel.mm $(MONODLL_ODEP) monodll_NSScroller.o: $(srcdir)/src/cocoa/NSScroller.mm $(MONODLL_ODEP) $(CXXC) -c -o $@ $(MONODLL_CXXFLAGS) $(srcdir)/src/cocoa/NSScroller.mm +monodll_NSSlider.o: $(srcdir)/src/cocoa/NSSlider.mm $(MONODLL_ODEP) + $(CXXC) -c -o $@ $(MONODLL_CXXFLAGS) $(srcdir)/src/cocoa/NSSlider.mm + monodll_NSTabView.o: $(srcdir)/src/cocoa/NSTabView.mm $(MONODLL_ODEP) $(CXXC) -c -o $@ $(MONODLL_CXXFLAGS) $(srcdir)/src/cocoa/NSTabView.mm @@ -17098,6 +17106,9 @@ monolib_NSPanel.o: $(srcdir)/src/cocoa/NSPanel.mm $(MONOLIB_ODEP) monolib_NSScroller.o: $(srcdir)/src/cocoa/NSScroller.mm $(MONOLIB_ODEP) $(CXXC) -c -o $@ $(MONOLIB_CXXFLAGS) $(srcdir)/src/cocoa/NSScroller.mm +monolib_NSSlider.o: $(srcdir)/src/cocoa/NSSlider.mm $(MONOLIB_ODEP) + $(CXXC) -c -o $@ $(MONOLIB_CXXFLAGS) $(srcdir)/src/cocoa/NSSlider.mm + monolib_NSTabView.o: $(srcdir)/src/cocoa/NSTabView.mm $(MONOLIB_ODEP) $(CXXC) -c -o $@ $(MONOLIB_CXXFLAGS) $(srcdir)/src/cocoa/NSTabView.mm @@ -22222,6 +22233,9 @@ coredll_NSPanel.o: $(srcdir)/src/cocoa/NSPanel.mm $(COREDLL_ODEP) coredll_NSScroller.o: $(srcdir)/src/cocoa/NSScroller.mm $(COREDLL_ODEP) $(CXXC) -c -o $@ $(COREDLL_CXXFLAGS) $(srcdir)/src/cocoa/NSScroller.mm +coredll_NSSlider.o: $(srcdir)/src/cocoa/NSSlider.mm $(COREDLL_ODEP) + $(CXXC) -c -o $@ $(COREDLL_CXXFLAGS) $(srcdir)/src/cocoa/NSSlider.mm + coredll_NSTabView.o: $(srcdir)/src/cocoa/NSTabView.mm $(COREDLL_ODEP) $(CXXC) -c -o $@ $(COREDLL_CXXFLAGS) $(srcdir)/src/cocoa/NSTabView.mm @@ -25180,6 +25194,9 @@ corelib_NSPanel.o: $(srcdir)/src/cocoa/NSPanel.mm $(CORELIB_ODEP) corelib_NSScroller.o: $(srcdir)/src/cocoa/NSScroller.mm $(CORELIB_ODEP) $(CXXC) -c -o $@ $(CORELIB_CXXFLAGS) $(srcdir)/src/cocoa/NSScroller.mm +corelib_NSSlider.o: $(srcdir)/src/cocoa/NSSlider.mm $(CORELIB_ODEP) + $(CXXC) -c -o $@ $(CORELIB_CXXFLAGS) $(srcdir)/src/cocoa/NSSlider.mm + corelib_NSTabView.o: $(srcdir)/src/cocoa/NSTabView.mm $(CORELIB_ODEP) $(CXXC) -c -o $@ $(CORELIB_CXXFLAGS) $(srcdir)/src/cocoa/NSTabView.mm diff --git a/build/bakefiles/files.bkl b/build/bakefiles/files.bkl index 4c85c02af3..dc787db34b 100644 --- a/build/bakefiles/files.bkl +++ b/build/bakefiles/files.bkl @@ -2371,6 +2371,7 @@ IMPORTANT: please read docs/tech/tn0016.txt before modifying this file! src/cocoa/NSMenu.mm src/cocoa/NSPanel.mm src/cocoa/NSScroller.mm + src/cocoa/NSSlider.mm src/cocoa/NSTabView.mm src/cocoa/NSTableView.mm src/cocoa/NSTextField.mm @@ -2461,6 +2462,7 @@ IMPORTANT: please read docs/tech/tn0016.txt before modifying this file! wx/cocoa/NSMenu.h wx/cocoa/NSPanel.h wx/cocoa/NSScroller.h + wx/cocoa/NSSlider.h wx/cocoa/NSTabView.h wx/cocoa/NSTableView.h wx/cocoa/NSTextField.h diff --git a/include/wx/cocoa/NSSlider.h b/include/wx/cocoa/NSSlider.h new file mode 100644 index 0000000000..9dc637dc5e --- /dev/null +++ b/include/wx/cocoa/NSSlider.h @@ -0,0 +1,47 @@ +///////////////////////////////////////////////////////////////////////////// +// Name: wx/cocoa/NSSlider.h +// Purpose: wxCocoaNSSlider class +// Author: Mark Oxenham +// Modified by: David Elliott +// 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); + +// For when we're not in Objective-C mode: +typedef struct objc_selector *SEL; + +class wxCocoaNSSliderLastSelectorChanger; + +class wxCocoaNSSlider +{ + friend class wxCocoaNSSliderLastSelectorChanger; + WX_DECLARE_OBJC_INTERFACE_HASHMAP(NSSlider); +public: + void AssociateNSSlider(WX_NSSlider cocoaNSSlider); + void DisassociateNSSlider(WX_NSSlider cocoaNSSlider); + + virtual void CocoaNotification_startTracking(WX_NSNotification notification) = 0; + virtual void CocoaNotification_continueTracking(WX_NSNotification notification) = 0; + virtual void CocoaNotification_stopTracking(WX_NSNotification notification) = 0; + + static SEL GetLastResponderSelector() + { return sm_lastResponderSelector; } +protected: + virtual ~wxCocoaNSSlider() { } + static SEL sm_lastResponderSelector; +}; + +#endif diff --git a/include/wx/cocoa/objc/NSSlider.h b/include/wx/cocoa/objc/NSSlider.h new file mode 100644 index 0000000000..776d71cf0b --- /dev/null +++ b/include/wx/cocoa/objc/NSSlider.h @@ -0,0 +1,37 @@ +/////////////////////////////////////////////////////////////////////////////// +// Name: wx/cocoa/objc/NSView.h +// Purpose: WXNSSlider class +// Author: David Elliott +// Modified by: +// Created: 2007/08/10 (move from NSSlider.mm) +// RCS-ID: $Id$ +// Copyright: (c) 2007 Software 2000 Ltd. +// Licence: wxWidgets licence +/////////////////////////////////////////////////////////////////////////////// + +#ifndef __WX_COCOA_OBJC_NSSLIDER_H__ +#define __WX_COCOA_OBJC_NSSLIDER_H__ + +#include "wx/cocoa/objc/objc_uniquifying.h" + +#import + +// ============================================================================ +// @class WXNSSlider +// ============================================================================ + +@interface WXNSSlider : NSSlider +@end + +WX_DECLARE_GET_OBJC_CLASS(WXNSSlider,NSSlider) + +// ============================================================================ +// @class WXNSSliderCell +// ============================================================================ + +@interface WXNSSliderCell : NSSliderCell +@end + +WX_DECLARE_GET_OBJC_CLASS(WXNSSliderCell,NSSliderCell) + +#endif //ndef __WX_COCOA_OBJC_NSSLIDER_H__ diff --git a/include/wx/cocoa/slider.h b/include/wx/cocoa/slider.h index 6c6a482b27..1939da70f7 100644 --- a/include/wx/cocoa/slider.h +++ b/include/wx/cocoa/slider.h @@ -2,17 +2,19 @@ // Name: wx/cocoa/slider.h // Purpose: wxSlider class // Author: David Elliott +// Mark Oxenham // Modified by: // Created: 2003/06/19 // RCS-ID: $Id$ // Copyright: (c) 2003 David Elliott +// (c) 2007 Software 2000 Ltd. // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// #ifndef __WX_COCOA_SLIDER_H__ #define __WX_COCOA_SLIDER_H__ -// #include "wx/cocoa/NSSlider.h" +#include "wx/cocoa/NSSlider.h" // ======================================================================== // wxSlider @@ -21,7 +23,7 @@ class WXDLLEXPORT wxSlider: public wxSliderBase// , protected wxCocoaNSSlider { DECLARE_DYNAMIC_CLASS(wxSlider) DECLARE_EVENT_TABLE() -// WX_DECLARE_COCOA_OWNER(NSSlider,NSControl,NSView) + WX_DECLARE_COCOA_OWNER(NSSlider,NSControl,NSView) // ------------------------------------------------------------------------ // initialization // ------------------------------------------------------------------------ @@ -52,30 +54,52 @@ public: // Cocoa callbacks // ------------------------------------------------------------------------ protected: + // Override this so we can use wxCocoaNSControl's target + void AssociateNSSlider(WX_NSSlider theSlider); + void DisassociateNSSlider(WX_NSSlider theSlider); + + // Helper method to do the real work + void ProcessEventType(wxEventType commandType); + + // from wxCocoaNSControl: + virtual void CocoaTarget_action(); + + // from wxCocoaNSSlider: + /*virtual*/ void CocoaNotification_startTracking(WX_NSNotification notification); + /*virtual*/ void CocoaNotification_continueTracking(WX_NSNotification notification); + /*virtual*/ void CocoaNotification_stopTracking(WX_NSNotification notification); + // ------------------------------------------------------------------------ // Implementation // ------------------------------------------------------------------------ public: // Pure Virtuals - virtual int GetValue() const { return 0; } - virtual void SetValue(int value) { } + virtual int GetValue() const; + virtual void SetValue(int value); // retrieve/change the range - virtual void SetRange(int minValue, int maxValue) { } - virtual int GetMin() const { return 0; } - virtual int GetMax() const { return 0; } + virtual void SetRange(int minValue, int maxValue); + virtual int GetMin() const; + virtual int GetMax() const; // 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 // pressing PageUp/Down) and are by default set to 1 and 1/10 of the range - virtual void SetLineSize(int lineSize) { } - virtual void SetPageSize(int pageSize) { } - virtual int GetLineSize() const { return 0; } - virtual int GetPageSize() const { return 0; } + virtual void SetLineSize(int lineSize); + virtual void SetPageSize(int pageSize); + virtual int GetLineSize() const; + virtual int GetPageSize() const; // these methods get/set the length of the slider pointer in pixels - virtual void SetThumbLength(int lenPixels) { } - virtual int GetThumbLength() const { return 0; } + virtual void SetThumbLength(int lenPixels); + 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); }; diff --git a/src/cocoa/NSSlider.mm b/src/cocoa/NSSlider.mm new file mode 100644 index 0000000000..3233c5a55a --- /dev/null +++ b/src/cocoa/NSSlider.mm @@ -0,0 +1,169 @@ +///////////////////////////////////////////////////////////////////////////// +// Name: src/cocoa/NSSlider.mm +// Purpose: wxCocoaNSSlider class +// Author: Mark Oxenham +// Modified by: David Elliott +// 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/NSSlider.h" + +#import +#import +#import +#include "wx/cocoa/objc/NSSlider.h" + +WX_IMPLEMENT_OBJC_INTERFACE_HASHMAP(NSSlider) + +class wxCocoaNSSliderLastSelectorChanger +{ +public: + wxCocoaNSSliderLastSelectorChanger(SEL newSelector) + { + m_savedResponderSelector = wxCocoaNSSlider::sm_lastResponderSelector; + wxCocoaNSSlider::sm_lastResponderSelector = newSelector; + } + ~wxCocoaNSSliderLastSelectorChanger() + { + wxCocoaNSSlider::sm_lastResponderSelector = m_savedResponderSelector; + } +private: + SEL m_savedResponderSelector; +// Don't allow any default or copy construction + wxCocoaNSSliderLastSelectorChanger(); + wxCocoaNSSliderLastSelectorChanger(const wxCocoaNSSliderLastSelectorChanger&); + void operator=(const wxCocoaNSSliderLastSelectorChanger&); +}; + +// ============================================================================ +// @class WXNSSlider +// ============================================================================ + +@implementation WXNSSlider : NSSlider + +// Override to ensure that WXNSSlider gets created with a WXNSSliderCell ++ (Class)cellClass +{ + 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 +{ + wxCocoaNSSliderLastSelectorChanger savedSelector(_cmd); + [super keyDown:theEvent]; +} + +- (void)moveUp:(id)sender +{ + wxCocoaNSSliderLastSelectorChanger savedSelector(_cmd); + [super moveUp:sender]; +} + +- (void)moveDown:(id)sender +{ + wxCocoaNSSliderLastSelectorChanger savedSelector(_cmd); + [super moveDown:sender]; +} + +- (void)moveLeft:(id)sender +{ + wxCocoaNSSliderLastSelectorChanger savedSelector(_cmd); + [super moveLeft:sender]; +} + +- (void)moveRight:(id)sender +{ + wxCocoaNSSliderLastSelectorChanger savedSelector(_cmd); + [super moveRight:sender]; +} + +- (void)pageUp:(id)sender +{ + wxCocoaNSSliderLastSelectorChanger savedSelector(_cmd); + [super pageUp:sender]; +} + +- (void)pageDown:(id)sender +{ + wxCocoaNSSliderLastSelectorChanger savedSelector(_cmd); + [super pageDown:sender]; +} + +@end +WX_IMPLEMENT_GET_OBJC_CLASS(WXNSSlider,NSSlider) + +// ============================================================================ +// @class WXNSSliderCell +// ============================================================================ + +@implementation WXNSSliderCell : NSSliderCell +- (BOOL)startTrackingAt:(NSPoint)startPoint inView:(NSView *)controlView +{ + BOOL result = [super startTrackingAt:startPoint inView:controlView]; + + wxCocoaNSSlider *slider = wxCocoaNSSlider::GetFromCocoa(controlView); + if(slider) + slider->CocoaNotification_startTracking(NULL); + + return result; +} + +- (BOOL)continueTracking:(NSPoint)lastPoint at:(NSPoint)currentPoint inView:(NSView *)controlView +{ + BOOL result = [super continueTracking:lastPoint at:currentPoint inView:controlView]; + + wxCocoaNSSlider *slider = wxCocoaNSSlider::GetFromCocoa(controlView); + if(slider) + slider->CocoaNotification_continueTracking(NULL); + + return result; +} + +- (void)stopTracking:(NSPoint)lastPoint at:(NSPoint)stopPoint inView:(NSView *)controlView mouseIsUp:(BOOL)flag +{ + [super stopTracking:lastPoint at:stopPoint inView:controlView mouseIsUp:flag]; + + wxCocoaNSSlider *slider = wxCocoaNSSlider::GetFromCocoa(controlView); + if(slider) + slider->CocoaNotification_stopTracking(NULL); +} +@end +WX_IMPLEMENT_GET_OBJC_CLASS(WXNSSliderCell,NSSliderCell) + +// ============================================================================ +// class wxCocoaNSSlider +// ============================================================================ + +SEL wxCocoaNSSlider::sm_lastResponderSelector; + +void wxCocoaNSSlider::AssociateNSSlider(WX_NSSlider cocoaNSSlider) +{ + if(cocoaNSSlider) + { + sm_cocoaHash.insert(wxCocoaNSSliderHash::value_type(cocoaNSSlider,this)); + } +} + +void wxCocoaNSSlider::DisassociateNSSlider(WX_NSSlider cocoaNSSlider) +{ + if(cocoaNSSlider) + { + sm_cocoaHash.erase(cocoaNSSlider); + } +} diff --git a/src/cocoa/slider.mm b/src/cocoa/slider.mm index 9e3e790f42..24bf39391b 100644 --- a/src/cocoa/slider.mm +++ b/src/cocoa/slider.mm @@ -2,10 +2,12 @@ // Name: src/cocoa/slider.mm // Purpose: wxSlider // Author: David Elliott +// Mark Oxenham // Modified by: // Created: 2003/06/19 // RCS-ID: $Id$ // Copyright: (c) 2003 David Elliott +// (c) 2007 Software 2000 Ltd. // Licence: wxWidgets licence ///////////////////////////////////////////////////////////////////////////// @@ -19,31 +21,242 @@ #include "wx/app.h" #endif //WX_PRECOMP -#import +#import +#include "wx/cocoa/objc/NSSlider.h" +#import +#import IMPLEMENT_DYNAMIC_CLASS(wxSlider, wxControl) BEGIN_EVENT_TABLE(wxSlider, wxSliderBase) 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, int value, int minValue, int maxValue, const wxPoint& pos, const wxSize& size, long style, 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)) 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_parent->CocoaAddChild(this); SetInitialFrameRect(pos,size); + + SetRange(minValue, maxValue); + SetValue(value); return true; } wxSlider::~wxSlider() { + DisassociateNSSlider(GetNSSlider()); +} + +// NOTE: We don't derive from wxCocoaNSSlider in 2.8 due to ABI + +void wxSlider::AssociateNSSlider(WX_NSSlider theSlider) +{ + // Set the target/action.. we don't really need to unset these + [theSlider setTarget:wxCocoaNSControl::sm_cocoaTarget]; + [theSlider setAction:@selector(wxNSControlAction:)]; +} + +void wxSlider::DisassociateNSSlider(WX_NSSlider theSlider) +{ +} + +void wxSlider::ProcessEventType(wxEventType commandType) +{ + wxScrollEvent event(commandType, GetId(), GetValue(), HasFlag(wxSL_VERTICAL)?wxVERTICAL:wxHORIZONTAL); + event.SetEventObject(this); + 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; + } + } + return wxEVT_NULL; +} + +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_NULL) + ProcessEventType(sliderEventType); +} + +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