]> git.saurik.com Git - wxWidgets.git/blame - src/mac/carbon/scrolbar.cpp
positioning of the insertion point at the end
[wxWidgets.git] / src / mac / carbon / scrolbar.cpp
CommitLineData
e9576ca5
SC
1/////////////////////////////////////////////////////////////////////////////
2// Name: scrolbar.cpp
3// Purpose: wxScrollBar
a31a5f85 4// Author: Stefan Csomor
e9576ca5 5// Modified by:
a31a5f85 6// Created: 1998-01-01
e9576ca5 7// RCS-ID: $Id$
a31a5f85 8// Copyright: (c) Stefan Csomor
e40298d5 9// Licence: wxWindows licence
e9576ca5
SC
10/////////////////////////////////////////////////////////////////////////////
11
12#ifdef __GNUG__
13#pragma implementation "scrolbar.h"
14#endif
15
d8c736e5
GD
16#include "wx/defs.h"
17
8140eec9
SC
18#ifndef WX_PRECOMP
19 #include "wx/intl.h"
20 #include "wx/log.h"
21#endif // WX_PRECOMP
22
e9576ca5 23#include "wx/scrolbar.h"
519cb848 24#include "wx/mac/uma.h"
e9576ca5 25
2f1ae414 26#if !USE_SHARED_LIBRARY
e9576ca5
SC
27IMPLEMENT_DYNAMIC_CLASS(wxScrollBar, wxControl)
28
169935ad
SC
29BEGIN_EVENT_TABLE(wxScrollBar, wxControl)
30END_EVENT_TABLE()
31
2f1ae414 32#endif
e9576ca5 33
519cb848
SC
34extern ControlActionUPP wxMacLiveScrollbarActionUPP ;
35
e9576ca5
SC
36// Scrollbar
37bool wxScrollBar::Create(wxWindow *parent, wxWindowID id,
38 const wxPoint& pos,
39 const wxSize& size, long style,
40 const wxValidator& validator,
41 const wxString& name)
42{
facd6764
SC
43 m_macIsUserPane = FALSE ;
44
b45ed7a2
VZ
45 if ( !wxControl::Create(parent, id, pos, size, style, validator, name) )
46 return FALSE;
47
facd6764 48 Rect bounds = wxMacGetBoundsForControl( this , pos , size ) ;
b45ed7a2 49
4c37f124
SC
50 verify_noerr ( CreateScrollBarControl( MAC_WXHWND(parent->MacGetTopLevelWindowRef()) , &bounds ,
51 0 , 0 , 100 , 1 , true /* liveTracking */ , wxMacLiveScrollbarActionUPP , (ControlRef*) &m_macControl ) ) ;
e9576ca5 52
facd6764 53 MacPostControlCreate(pos,size) ;
e9576ca5 54
b45ed7a2 55 return TRUE;
e9576ca5
SC
56}
57
58wxScrollBar::~wxScrollBar()
59{
60}
61
62void wxScrollBar::SetThumbPosition(int viewStart)
63{
facd6764 64 ::SetControl32BitValue( (ControlRef) m_macControl , viewStart ) ;
e9576ca5
SC
65}
66
67int wxScrollBar::GetThumbPosition() const
68{
facd6764 69 return ::GetControl32BitValue( (ControlRef) m_macControl ) ;
e9576ca5
SC
70}
71
72void wxScrollBar::SetScrollbar(int position, int thumbSize, int range, int pageSize,
73 bool refresh)
74{
4b1c4c21
SC
75 m_pageSize = pageSize;
76 m_viewSize = thumbSize;
e9576ca5
SC
77 m_objectSize = range;
78
4c37f124 79 int range1 = wxMax((m_objectSize - m_viewSize), 0) ;
519cb848 80
facd6764
SC
81 SetControl32BitMaximum( (ControlRef) m_macControl , range1 ) ;
82 SetControl32BitMinimum( (ControlRef) m_macControl , 0 ) ;
83 SetControl32BitValue( (ControlRef) m_macControl , position ) ;
4c37f124 84 SetControlViewSize( (ControlRef) m_macControl , m_viewSize ) ;
519cb848 85
66a09d47
SC
86 if ( refresh )
87 MacRedrawControl() ;
e9576ca5
SC
88}
89
90
91void wxScrollBar::Command(wxCommandEvent& event)
92{
93 SetThumbPosition(event.m_commandInt);
94 ProcessCommand(event);
95}
96
4b26b60f 97void wxScrollBar::MacHandleControlClick( WXWidget control , wxInt16 controlpart , bool mouseStillDown )
519cb848 98{
facd6764
SC
99 int position = GetControl32BitValue( (ControlRef) m_macControl) ;
100 int minPos = GetControl32BitMinimum( (ControlRef) m_macControl) ;
101 int maxPos = GetControl32BitMaximum( (ControlRef) m_macControl) ;
e40298d5
JS
102
103 wxEventType scrollEvent = wxEVT_NULL;
56fc3fa5 104 int nScrollInc = 0;
e40298d5 105
4b26b60f
SC
106 // all events have already been reported during mouse down, except for THUMBRELEASE
107 if ( !mouseStillDown && controlpart !=kControlIndicatorPart )
108 return ;
109
e40298d5
JS
110 switch( controlpart )
111 {
112 case kControlUpButtonPart :
4b1c4c21 113 nScrollInc = -1;
519cb848 114 scrollEvent = wxEVT_SCROLL_LINEUP;
e40298d5
JS
115 break ;
116 case kControlDownButtonPart :
4b1c4c21 117 nScrollInc = 1;
519cb848 118 scrollEvent = wxEVT_SCROLL_LINEDOWN;
e40298d5
JS
119 break ;
120 case kControlPageUpPart :
4b1c4c21 121 nScrollInc = -m_pageSize;
519cb848 122 scrollEvent = wxEVT_SCROLL_PAGEUP;
e40298d5
JS
123 break ;
124 case kControlPageDownPart :
4b1c4c21 125 nScrollInc = m_pageSize;
519cb848 126 scrollEvent = wxEVT_SCROLL_PAGEDOWN;
e40298d5
JS
127 break ;
128 case kControlIndicatorPart :
519cb848 129 nScrollInc = 0 ;
4b26b60f
SC
130 if ( mouseStillDown )
131 scrollEvent = wxEVT_SCROLL_THUMBTRACK;
132 else
133 scrollEvent = wxEVT_SCROLL_THUMBRELEASE;
e40298d5
JS
134 break ;
135 default :
136 wxFAIL_MSG(wxT("illegal scrollbar selector"));
137 break ;
138 }
139
140 int new_pos = position + nScrollInc;
141
142 if (new_pos < minPos)
143 new_pos = minPos;
144 if (new_pos > maxPos)
145 new_pos = maxPos;
146 if ( nScrollInc )
147 SetThumbPosition(new_pos);
148
149 wxScrollEvent event(scrollEvent, m_windowId);
150 if ( m_windowStyle & wxHORIZONTAL )
151 {
152 event.SetOrientation( wxHORIZONTAL ) ;
153 }
154 else
155 {
156 event.SetOrientation( wxVERTICAL ) ;
157 }
158 event.SetPosition(new_pos);
159 event.SetEventObject( this );
160 wxWindow* window = GetParent() ;
161 if (window && window->MacIsWindowScrollbar(this) )
162 {
163 // this is hardcoded
164 window->MacOnScroll(event);
165 }
166 else
167 GetEventHandler()->ProcessEvent(event);
519cb848
SC
168}
169
4c37f124
SC
170wxInt32 wxScrollBar::MacControlHit( WXEVENTHANDLERREF handler , WXEVENTREF mevent )
171{
172 int position = GetControl32BitValue( (ControlRef) m_macControl) ;
173 int minPos = GetControl32BitMinimum( (ControlRef) m_macControl) ;
174 int maxPos = GetControl32BitMaximum( (ControlRef) m_macControl) ;
175
176 wxEventType scrollEvent = wxEVT_NULL;
177 int nScrollInc = 0;
178
179 wxMacCarbonEvent cEvent( (EventRef) mevent ) ;
180 ControlPartCode controlpart = cEvent.GetParameter<ControlPartCode>(kEventParamControlPart,typeControlPartCode) ;
181
182 // all events have already been reported during mouse down, except for THUMBRELEASE
183 if ( controlpart !=kControlIndicatorPart )
184 return eventNotHandledErr ;
185
186 switch( controlpart )
187 {
188 case kControlIndicatorPart :
189 nScrollInc = 0 ;
190 scrollEvent = wxEVT_SCROLL_THUMBRELEASE;
191 break ;
192 default :
193 wxFAIL_MSG(wxT("illegal scrollbar selector"));
194 break ;
195 }
196
197 int new_pos = position + nScrollInc;
198
199 if (new_pos < minPos)
200 new_pos = minPos;
201 if (new_pos > maxPos)
202 new_pos = maxPos;
203 if ( nScrollInc )
204 SetThumbPosition(new_pos);
205
206 wxScrollEvent event(scrollEvent, m_windowId);
207 if ( m_windowStyle & wxHORIZONTAL )
208 {
209 event.SetOrientation( wxHORIZONTAL ) ;
210 }
211 else
212 {
213 event.SetOrientation( wxVERTICAL ) ;
214 }
215 event.SetPosition(new_pos);
216 event.SetEventObject( this );
217 wxWindow* window = GetParent() ;
218 if (window && window->MacIsWindowScrollbar(this) )
219 {
220 // this is hardcoded
221 window->MacOnScroll(event);
222 }
223 else
224 GetEventHandler()->ProcessEvent(event);
225 return noErr ;
226}
227
228