]> git.saurik.com Git - wxWidgets.git/blame - src/osx/cocoa/scrolbar.mm
minor fixes; replace references to Windows95 with references to wxMSW where possible
[wxWidgets.git] / src / osx / cocoa / scrolbar.mm
CommitLineData
dbeddfb9
SC
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 wxWidgetImpl* impl;
27}
28
29- (void)setImplementation: (wxWidgetImpl *) theImplementation;
30- (wxWidgetImpl*) implementation;
31- (BOOL) isFlipped;
32 - (void) clickedAction: (id) sender;
33
34@end
35
36@implementation wxNSScroller
37
38- (id)initWithFrame:(NSRect)frame
39{
40 [super initWithFrame:frame];
41 impl = NULL;
42 [self setTarget: self];
43 [self setAction: @selector(clickedAction:)];
44 return self;
45}
46
47- (void) clickedAction: (id) sender
48{
49 if ( impl )
50 {
51 wxWindow* wxpeer = (wxWindow*) impl->GetWXPeer();
52 if ( wxpeer )
53 wxpeer->HandleClicked(0);
54 }
55}
56
57- (void)setImplementation: (wxWidgetImpl *) theImplementation
58{
59 impl = theImplementation;
60}
61
62- (wxWidgetImpl*) implementation
63{
64 return impl ;
65}
66
67- (BOOL) isFlipped
68{
69 return YES;
70}
71
72@end
73
74class wxOSXScrollBarCocoaImpl : public wxWidgetCocoaImpl
75{
76public :
77 wxOSXScrollBarCocoaImpl( wxWindowMac* peer, WXWidget w) : wxWidgetCocoaImpl( peer, w )
78 {
79 }
80
81 void SetMaximum(wxInt32 v)
82 {
83 m_maximum = v;
84 }
85
86 void SetScrollThumb( wxInt32 value, wxInt32 thumbSize )
87 {
88 double v = ((double) value)/m_maximum;
89 double t = ((double) thumbSize)/m_maximum;
90#if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
91 [(wxNSScroller*) m_osxView setFloatValue:v knobProportion:t];
92#else
93 [(wxNSScroller*) m_osxView setDoubleValue:v];
94 [(wxNSScroller*) m_osxView setKnobProportion:t];
95#endif
96 }
97
98 wxInt32 GetValue() const
99 {
100 return [(wxNSScroller*) m_osxView floatValue] * m_maximum;
101 }
102protected:
103 wxInt32 m_maximum;
104};
105
106wxWidgetImplType* wxWidgetImpl::CreateScrollBar( wxWindowMac* wxpeer,
107 wxWindowMac* parent,
108 wxWindowID id,
109 const wxPoint& pos,
110 const wxSize& size,
111 long style,
112 long extraStyle)
113{
dbeddfb9
SC
114 NSRect r = wxOSXGetFrameForControl( wxpeer, pos , size ) ;
115 wxNSScroller* v = [[wxNSScroller alloc] initWithFrame:r];
116
dbeddfb9
SC
117 wxWidgetCocoaImpl* c = new wxOSXScrollBarCocoaImpl( wxpeer, v );
118 [v setImplementation:c];
119 return c;
120}