]>
Commit | Line | Data |
---|---|---|
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 | { | |
b466e85a | 26 | WXCOCOAIMPL_COMMON_MEMBERS |
dbeddfb9 SC |
27 | } |
28 | ||
b466e85a SC |
29 | WXCOCOAIMPL_COMMON_INTERFACE |
30 | ||
dbeddfb9 SC |
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 | ||
b466e85a | 56 | WXCOCOAIMPL_COMMON_IMPLEMENTATION |
dbeddfb9 SC |
57 | |
58 | @end | |
59 | ||
60 | class wxOSXScrollBarCocoaImpl : public wxWidgetCocoaImpl | |
61 | { | |
62 | public : | |
63 | wxOSXScrollBarCocoaImpl( wxWindowMac* peer, WXWidget w) : wxWidgetCocoaImpl( peer, w ) | |
64 | { | |
65 | } | |
66 | ||
67 | void SetMaximum(wxInt32 v) | |
68 | { | |
69 | m_maximum = v; | |
70 | } | |
71 | ||
72 | void SetScrollThumb( wxInt32 value, wxInt32 thumbSize ) | |
73 | { | |
74 | double v = ((double) value)/m_maximum; | |
75 | double t = ((double) thumbSize)/m_maximum; | |
76 | #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5 | |
77 | [(wxNSScroller*) m_osxView setFloatValue:v knobProportion:t]; | |
78 | #else | |
79 | [(wxNSScroller*) m_osxView setDoubleValue:v]; | |
80 | [(wxNSScroller*) m_osxView setKnobProportion:t]; | |
81 | #endif | |
82 | } | |
83 | ||
84 | wxInt32 GetValue() const | |
85 | { | |
86 | return [(wxNSScroller*) m_osxView floatValue] * m_maximum; | |
87 | } | |
88 | protected: | |
89 | wxInt32 m_maximum; | |
90 | }; | |
91 | ||
92 | wxWidgetImplType* wxWidgetImpl::CreateScrollBar( wxWindowMac* wxpeer, | |
93 | wxWindowMac* parent, | |
94 | wxWindowID id, | |
95 | const wxPoint& pos, | |
96 | const wxSize& size, | |
97 | long style, | |
98 | long extraStyle) | |
99 | { | |
dbeddfb9 SC |
100 | NSRect r = wxOSXGetFrameForControl( wxpeer, pos , size ) ; |
101 | wxNSScroller* v = [[wxNSScroller alloc] initWithFrame:r]; | |
102 | ||
dbeddfb9 SC |
103 | wxWidgetCocoaImpl* c = new wxOSXScrollBarCocoaImpl( wxpeer, v ); |
104 | [v setImplementation:c]; | |
105 | return c; | |
106 | } |