]> git.saurik.com Git - wxWidgets.git/blame - src/mac/carbon/scrolbar.cpp
adapting to bitmaprefdata changes
[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
65571936 9// Licence: wxWindows licence
e9576ca5
SC
10/////////////////////////////////////////////////////////////////////////////
11
3d1a4878 12#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
e9576ca5
SC
13#pragma implementation "scrolbar.h"
14#endif
15
3d1a4878 16#include "wx/wxprec.h"
d8c736e5 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
21fd5529 50 m_peer = new wxMacControl() ;
4c37f124 51 verify_noerr ( CreateScrollBarControl( MAC_WXHWND(parent->MacGetTopLevelWindowRef()) , &bounds ,
5ca0d812 52 0 , 0 , 100 , 1 , true /* liveTracking */ , wxMacLiveScrollbarActionUPP , m_peer->GetControlRefAddr() ) );
21fd5529 53
e9576ca5 54
facd6764 55 MacPostControlCreate(pos,size) ;
e9576ca5 56
b45ed7a2 57 return TRUE;
e9576ca5
SC
58}
59
60wxScrollBar::~wxScrollBar()
61{
62}
63
64void wxScrollBar::SetThumbPosition(int viewStart)
65{
5ca0d812 66 m_peer->SetValue( viewStart ) ;
e9576ca5
SC
67}
68
69int wxScrollBar::GetThumbPosition() const
70{
5ca0d812 71 return m_peer->GetValue() ;
e9576ca5
SC
72}
73
74void wxScrollBar::SetScrollbar(int position, int thumbSize, int range, int pageSize,
75 bool refresh)
76{
4b1c4c21
SC
77 m_pageSize = pageSize;
78 m_viewSize = thumbSize;
e9576ca5
SC
79 m_objectSize = range;
80
4c37f124 81 int range1 = wxMax((m_objectSize - m_viewSize), 0) ;
519cb848 82
5ca0d812
SC
83 m_peer->SetMaximum( range1 ) ;
84 m_peer->SetMinimum( 0 ) ;
85 m_peer->SetValue( position ) ;
86 m_peer->SetViewSize( m_viewSize ) ;
e9576ca5
SC
87}
88
89
90void wxScrollBar::Command(wxCommandEvent& event)
91{
687706f5 92 SetThumbPosition(event.GetInt());
e9576ca5
SC
93 ProcessCommand(event);
94}
95
4b26b60f 96void wxScrollBar::MacHandleControlClick( WXWidget control , wxInt16 controlpart , bool mouseStillDown )
519cb848 97{
5ca0d812
SC
98 int position = m_peer->GetValue() ;
99 int minPos = m_peer->GetMinimum() ;
100 int maxPos = m_peer->GetMaximum() ;
e40298d5
JS
101
102 wxEventType scrollEvent = wxEVT_NULL;
56fc3fa5 103 int nScrollInc = 0;
e40298d5 104
4b26b60f
SC
105 // all events have already been reported during mouse down, except for THUMBRELEASE
106 if ( !mouseStillDown && controlpart !=kControlIndicatorPart )
107 return ;
108
e40298d5
JS
109 switch( controlpart )
110 {
111 case kControlUpButtonPart :
4b1c4c21 112 nScrollInc = -1;
519cb848 113 scrollEvent = wxEVT_SCROLL_LINEUP;
e40298d5
JS
114 break ;
115 case kControlDownButtonPart :
4b1c4c21 116 nScrollInc = 1;
519cb848 117 scrollEvent = wxEVT_SCROLL_LINEDOWN;
e40298d5
JS
118 break ;
119 case kControlPageUpPart :
4b1c4c21 120 nScrollInc = -m_pageSize;
519cb848 121 scrollEvent = wxEVT_SCROLL_PAGEUP;
e40298d5
JS
122 break ;
123 case kControlPageDownPart :
4b1c4c21 124 nScrollInc = m_pageSize;
519cb848 125 scrollEvent = wxEVT_SCROLL_PAGEDOWN;
e40298d5
JS
126 break ;
127 case kControlIndicatorPart :
519cb848 128 nScrollInc = 0 ;
4b26b60f
SC
129 if ( mouseStillDown )
130 scrollEvent = wxEVT_SCROLL_THUMBTRACK;
131 else
132 scrollEvent = wxEVT_SCROLL_THUMBRELEASE;
e40298d5
JS
133 break ;
134 default :
135 wxFAIL_MSG(wxT("illegal scrollbar selector"));
136 break ;
137 }
138
139 int new_pos = position + nScrollInc;
140
141 if (new_pos < minPos)
142 new_pos = minPos;
143 if (new_pos > maxPos)
144 new_pos = maxPos;
145 if ( nScrollInc )
146 SetThumbPosition(new_pos);
147
148 wxScrollEvent event(scrollEvent, m_windowId);
149 if ( m_windowStyle & wxHORIZONTAL )
150 {
151 event.SetOrientation( wxHORIZONTAL ) ;
152 }
153 else
154 {
155 event.SetOrientation( wxVERTICAL ) ;
156 }
157 event.SetPosition(new_pos);
158 event.SetEventObject( this );
159 wxWindow* window = GetParent() ;
160 if (window && window->MacIsWindowScrollbar(this) )
161 {
162 // this is hardcoded
163 window->MacOnScroll(event);
164 }
165 else
166 GetEventHandler()->ProcessEvent(event);
519cb848
SC
167}
168
4c37f124
SC
169wxInt32 wxScrollBar::MacControlHit( WXEVENTHANDLERREF handler , WXEVENTREF mevent )
170{
5ca0d812
SC
171 int position = m_peer->GetValue() ;
172 int minPos = m_peer->GetMinimum() ;
173 int maxPos = m_peer->GetMaximum() ;
4c37f124
SC
174
175 wxEventType scrollEvent = wxEVT_NULL;
176 int nScrollInc = 0;
177
178 wxMacCarbonEvent cEvent( (EventRef) mevent ) ;
179 ControlPartCode controlpart = cEvent.GetParameter<ControlPartCode>(kEventParamControlPart,typeControlPartCode) ;
180
181 // all events have already been reported during mouse down, except for THUMBRELEASE
182 if ( controlpart !=kControlIndicatorPart )
183 return eventNotHandledErr ;
184
185 switch( controlpart )
186 {
187 case kControlIndicatorPart :
188 nScrollInc = 0 ;
189 scrollEvent = wxEVT_SCROLL_THUMBRELEASE;
190 break ;
191 default :
192 wxFAIL_MSG(wxT("illegal scrollbar selector"));
193 break ;
194 }
195
196 int new_pos = position + nScrollInc;
197
198 if (new_pos < minPos)
199 new_pos = minPos;
200 if (new_pos > maxPos)
201 new_pos = maxPos;
202 if ( nScrollInc )
203 SetThumbPosition(new_pos);
204
205 wxScrollEvent event(scrollEvent, m_windowId);
206 if ( m_windowStyle & wxHORIZONTAL )
207 {
208 event.SetOrientation( wxHORIZONTAL ) ;
209 }
210 else
211 {
212 event.SetOrientation( wxVERTICAL ) ;
213 }
214 event.SetPosition(new_pos);
215 event.SetEventObject( this );
216 wxWindow* window = GetParent() ;
217 if (window && window->MacIsWindowScrollbar(this) )
218 {
219 // this is hardcoded
220 window->MacOnScroll(event);
221 }
222 else
223 GetEventHandler()->ProcessEvent(event);
224 return noErr ;
225}
226
227