]> git.saurik.com Git - wxWidgets.git/blob - src/osx/cocoa/scrolbar.mm
mouse and cursor additions for cocoa, see #10361
[wxWidgets.git] / src / osx / cocoa / scrolbar.mm
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/cocoa/scrolbar.mm
3 // Purpose: wxScrollBar
4 // Author: Stefan Csomor
5 // Modified by:
6 // Created: 1998-01-01
7 // RCS-ID: $Id: scrolbar.cpp 54129 2008-06-11 19:30:52Z SC $
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #include "wx/wxprec.h"
13
14 #include "wx/scrolbar.h"
15
16 #ifndef WX_PRECOMP
17 #include "wx/intl.h"
18 #include "wx/log.h"
19 #include "wx/settings.h"
20 #endif
21
22 #include "wx/osx/private.h"
23
24 @interface wxNSScroller : NSScroller
25 {
26 WXCOCOAIMPL_COMMON_MEMBERS
27 }
28
29 WXCOCOAIMPL_COMMON_INTERFACE
30
31 - (void) clickedAction: (id) sender;
32
33 @end
34
35 @implementation wxNSScroller
36
37 - (id)initWithFrame:(NSRect)frame
38 {
39 [super initWithFrame:frame];
40 impl = NULL;
41 [self setTarget: self];
42 [self setAction: @selector(clickedAction:)];
43 return self;
44 }
45
46 - (void) clickedAction: (id) sender
47 {
48 if ( impl )
49 {
50 wxWindow* wxpeer = (wxWindow*) impl->GetWXPeer();
51 if ( wxpeer )
52 wxpeer->HandleClicked(0);
53 }
54 }
55
56 WXCOCOAIMPL_COMMON_IMPLEMENTATION
57
58 @end
59
60 class wxOSXScrollBarCocoaImpl : public wxWidgetCocoaImpl
61 {
62 public :
63 wxOSXScrollBarCocoaImpl( wxWindowMac* peer, WXWidget w) : wxWidgetCocoaImpl( peer, w )
64 {
65 m_maximum = 1;
66 }
67
68 void SetMaximum(wxInt32 v)
69 {
70 m_maximum = (v == 0) ? 1 : v;
71 }
72
73 void SetScrollThumb( wxInt32 value, wxInt32 thumbSize )
74 {
75 double v = ((double) value)/m_maximum;
76 double t = ((double) thumbSize)/m_maximum;
77 #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
78 [(wxNSScroller*) m_osxView setFloatValue:v knobProportion:t];
79 #else
80 [(wxNSScroller*) m_osxView setDoubleValue:v];
81 [(wxNSScroller*) m_osxView setKnobProportion:t];
82 #endif
83 }
84
85 wxInt32 GetValue() const
86 {
87 return [(wxNSScroller*) m_osxView floatValue] * m_maximum;
88 }
89 protected:
90 wxInt32 m_maximum;
91 };
92
93 wxWidgetImplType* wxWidgetImpl::CreateScrollBar( wxWindowMac* wxpeer,
94 wxWindowMac* parent,
95 wxWindowID id,
96 const wxPoint& pos,
97 const wxSize& size,
98 long style,
99 long extraStyle)
100 {
101 NSRect r = wxOSXGetFrameForControl( wxpeer, pos , size ) ;
102 wxNSScroller* v = [[wxNSScroller alloc] initWithFrame:r];
103
104 wxWidgetCocoaImpl* c = new wxOSXScrollBarCocoaImpl( wxpeer, v );
105 [v setImplementation:c];
106 [v setEnabled:YES];
107 return c;
108 }