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