]> git.saurik.com Git - wxWidgets.git/blame - src/osx/cocoa/scrolbar.mm
Update the wxSpinCtrlDouble documentation so SetIncrement refers to SetDigits
[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
a9a4f229 7// RCS-ID: $Id$
dbeddfb9
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
c22ace4d 22#include "wx/math.h"
dbeddfb9
SC
23#include "wx/osx/private.h"
24
25@interface wxNSScroller : NSScroller
26{
dbeddfb9 27}
dbeddfb9
SC
28@end
29
30@implementation wxNSScroller
31
4dd9fdf8 32+ (void)initialize
dbeddfb9 33{
4dd9fdf8 34 static BOOL initialized = NO;
03647350 35 if (!initialized)
19c7ac3d 36 {
4dd9fdf8
SC
37 initialized = YES;
38 wxOSXCocoaClassAddWXMethods(self);
19c7ac3d
SC
39 }
40}
dbeddfb9
SC
41
42@end
43
44class wxOSXScrollBarCocoaImpl : public wxWidgetCocoaImpl
45{
46public :
47 wxOSXScrollBarCocoaImpl( wxWindowMac* peer, WXWidget w) : wxWidgetCocoaImpl( peer, w )
48 {
54f11060 49 m_maximum = 1;
dbeddfb9 50 }
03647350 51
dbeddfb9
SC
52 void SetMaximum(wxInt32 v)
53 {
54f11060 54 m_maximum = (v == 0) ? 1 : v;
dbeddfb9 55 }
03647350
VZ
56
57 void SetScrollThumb( wxInt32 value, wxInt32 thumbSize )
dbeddfb9
SC
58 {
59 double v = ((double) value)/m_maximum;
4dd9fdf8 60 double t = ((double) thumbSize)/(m_maximum+thumbSize);
dbeddfb9
SC
61#if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
62 [(wxNSScroller*) m_osxView setFloatValue:v knobProportion:t];
63#else
64 [(wxNSScroller*) m_osxView setDoubleValue:v];
65 [(wxNSScroller*) m_osxView setKnobProportion:t];
66#endif
67 }
03647350 68
4dd9fdf8 69 virtual wxInt32 GetValue() const
dbeddfb9 70 {
c22ace4d 71 return wxRound([(wxNSScroller*) m_osxView floatValue] * m_maximum);
dbeddfb9 72 }
03647350 73
4dd9fdf8 74 virtual wxInt32 GetMaximum() const
19c7ac3d
SC
75 {
76 return m_maximum;
77 }
4dd9fdf8 78
e32090ba 79 virtual void controlAction(WXWidget slf, void* _cmd, void *sender);
4dd9fdf8 80 virtual void mouseEvent(WX_NSEvent event, WXWidget slf, void* _cmd);
dbeddfb9
SC
81protected:
82 wxInt32 m_maximum;
83};
84
03647350 85// we will have a mouseDown, then in the native
4dd9fdf8
SC
86// implementation of mouseDown the tracking code
87// is calling clickedAction, therefore we wire this
03647350 88// to thumbtrack and only after super mouseDown
4dd9fdf8
SC
89// returns we will call the thumbrelease
90
d8207702 91void wxOSXScrollBarCocoaImpl::controlAction( WXWidget WXUNUSED(slf), void *WXUNUSED(_cmd), void *WXUNUSED(sender))
4dd9fdf8
SC
92{
93 wxEventType scrollEvent = wxEVT_NULL;
03647350 94 switch ([(NSScroller*)m_osxView hitPart])
4dd9fdf8
SC
95 {
96 case NSScrollerIncrementLine:
97 scrollEvent = wxEVT_SCROLL_LINEDOWN;
98 break;
99 case NSScrollerIncrementPage:
100 scrollEvent = wxEVT_SCROLL_PAGEDOWN;
101 break;
102 case NSScrollerDecrementLine:
103 scrollEvent = wxEVT_SCROLL_LINEUP;
104 break;
105 case NSScrollerDecrementPage:
106 scrollEvent = wxEVT_SCROLL_PAGEUP;
107 break;
108 case NSScrollerKnob:
109 case NSScrollerKnobSlot:
110 scrollEvent = wxEVT_SCROLL_THUMBTRACK;
111 break;
112 case NSScrollerNoPart:
113 default:
114 return;
115 }
116
117 wxWindow* wxpeer = (wxWindow*) GetWXPeer();
118 if ( wxpeer )
119 wxpeer->TriggerScrollEvent(scrollEvent);
120}
121
122void wxOSXScrollBarCocoaImpl::mouseEvent(WX_NSEvent event, WXWidget slf, void *_cmd)
123{
124 wxWidgetCocoaImpl::mouseEvent(event, slf, _cmd);
03647350 125
4dd9fdf8
SC
126 // send a release event in case we've been tracking the thumb
127 if ( strcmp( sel_getName((SEL) _cmd) , "mouseDown:") == 0 )
128 {
129 NSScrollerPart hit = [(NSScroller*)m_osxView hitPart];
130 if ( (hit == NSScrollerKnob || hit == NSScrollerKnobSlot) )
131 {
132 wxWindow* wxpeer = (wxWindow*) GetWXPeer();
133 if ( wxpeer )
134 wxpeer->OSXHandleClicked(0);
135 }
136 }
137}
138
03647350
VZ
139wxWidgetImplType* wxWidgetImpl::CreateScrollBar( wxWindowMac* wxpeer,
140 wxWindowMac* WXUNUSED(parent),
141 wxWindowID WXUNUSED(id),
142 const wxPoint& pos,
dbeddfb9 143 const wxSize& size,
03647350 144 long style,
d8207702 145 long WXUNUSED(extraStyle))
dbeddfb9 146{
dbeddfb9 147 NSRect r = wxOSXGetFrameForControl( wxpeer, pos , size ) ;
03647350 148 // the creation rect defines the orientation
c2dad387
SC
149 NSRect createRect = ( style & wxSB_HORIZONTAL ) ? NSMakeRect(r.origin.x, r.origin.y , 17, 16) :
150 NSMakeRect(r.origin.x, r.origin.y , 16, 17);
151 wxNSScroller* v = [[wxNSScroller alloc] initWithFrame:createRect];
152 [v setFrame:r];
dbeddfb9 153
dbeddfb9 154 wxWidgetCocoaImpl* c = new wxOSXScrollBarCocoaImpl( wxpeer, v );
54f11060 155 [v setEnabled:YES];
dbeddfb9
SC
156 return c;
157}