]> git.saurik.com Git - wxWidgets.git/blob - src/osx/cocoa/scrolbar.mm
fixed typo in XRC error message
[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 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
74 class wxOSXScrollBarCocoaImpl : public wxWidgetCocoaImpl
75 {
76 public :
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 }
102 protected:
103 wxInt32 m_maximum;
104 };
105
106 wxWidgetImplType* 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 {
114 NSView* sv = (wxpeer->GetParent()->GetHandle() );
115
116 NSRect r = wxOSXGetFrameForControl( wxpeer, pos , size ) ;
117 wxNSScroller* v = [[wxNSScroller alloc] initWithFrame:r];
118
119 [sv addSubview:v];
120 wxWidgetCocoaImpl* c = new wxOSXScrollBarCocoaImpl( wxpeer, v );
121 [v setImplementation:c];
122 return c;
123 }