]> git.saurik.com Git - wxWidgets.git/blame - src/mac/carbon/scrolbar.cpp
revert last change (r48897)
[wxWidgets.git] / src / mac / carbon / scrolbar.cpp
CommitLineData
e9576ca5 1/////////////////////////////////////////////////////////////////////////////
0f85d5e7 2// Name: src/mac/carbon/scrolbar.cpp
e9576ca5 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#include "wx/wxprec.h"
d8c736e5 13
851dee09
WS
14#include "wx/scrolbar.h"
15
8140eec9
SC
16#ifndef WX_PRECOMP
17 #include "wx/intl.h"
18 #include "wx/log.h"
9eddec69 19 #include "wx/settings.h"
0f85d5e7 20#endif
8140eec9 21
519cb848 22#include "wx/mac/uma.h"
e9576ca5 23
e9576ca5
SC
24IMPLEMENT_DYNAMIC_CLASS(wxScrollBar, wxControl)
25
169935ad
SC
26BEGIN_EVENT_TABLE(wxScrollBar, wxControl)
27END_EVENT_TABLE()
28
4792d192 29
0f85d5e7 30bool wxScrollBar::Create( wxWindow *parent,
4792d192
DS
31 wxWindowID id,
32 const wxPoint& pos,
33 const wxSize& size,
34 long style,
35 const wxValidator& validator,
0f85d5e7 36 const wxString& name )
e9576ca5 37{
0f85d5e7 38 m_macIsUserPane = false;
4792d192 39
0f85d5e7 40 if ( !wxControl::Create( parent, id, pos, size, style, validator, name ) )
4792d192 41 return false;
b45ed7a2 42
0f85d5e7 43 Rect bounds = wxMacGetBoundsForControl( this, pos, size );
b45ed7a2 44
0f85d5e7
DS
45 m_peer = new wxMacControl( this );
46 OSStatus err = CreateScrollBarControl(
47 MAC_WXHWND(parent->MacGetTopLevelWindowRef()), &bounds,
48 0, 0, 100, 1, true /* liveTracking */,
49 GetwxMacLiveScrollbarActionProc(),
50 m_peer->GetControlRefAddr() );
51 verify_noerr( err );
e9576ca5 52
0f85d5e7 53 MacPostControlCreate( pos, size );
e9576ca5 54
4792d192 55 return true;
e9576ca5
SC
56}
57
58wxScrollBar::~wxScrollBar()
59{
60}
61
0f85d5e7 62void wxScrollBar::SetThumbPosition( int viewStart )
e9576ca5 63{
0f85d5e7 64 m_peer->SetValue( viewStart );
e9576ca5
SC
65}
66
67int wxScrollBar::GetThumbPosition() const
68{
0f85d5e7 69 return m_peer->GetValue();
e9576ca5
SC
70}
71
0f85d5e7 72void wxScrollBar::SetScrollbar( int position, int thumbSize, int range, int pageSize, bool refresh )
e9576ca5 73{
4b1c4c21
SC
74 m_pageSize = pageSize;
75 m_viewSize = thumbSize;
e9576ca5
SC
76 m_objectSize = range;
77
0f85d5e7 78 int range1 = wxMax( (m_objectSize - m_viewSize), 0 );
519cb848 79
0f85d5e7
DS
80 m_peer->SetMinimum( 0 );
81 m_peer->SetMaximum( range1 );
82 m_peer->SetValue( position );
83 m_peer->SetViewSize( m_viewSize );
e9576ca5
SC
84}
85
0f85d5e7 86void wxScrollBar::Command( wxCommandEvent& event )
e9576ca5 87{
0f85d5e7
DS
88 SetThumbPosition( event.GetInt() );
89 ProcessCommand( event );
e9576ca5
SC
90}
91
0f85d5e7 92void wxScrollBar::MacHandleControlClick( WXWidget control, wxInt16 controlpart, bool mouseStillDown )
519cb848 93{
0f85d5e7
DS
94 int position = m_peer->GetValue();
95 int minPos = m_peer->GetMinimum();
96 int maxPos = m_peer->GetMaximum();
4792d192 97
e40298d5 98 wxEventType scrollEvent = wxEVT_NULL;
56fc3fa5 99 int nScrollInc = 0;
4792d192 100
4b26b60f 101 // all events have already been reported during mouse down, except for THUMBRELEASE
4792d192 102 if ( !mouseStillDown && controlpart != kControlIndicatorPart )
0f85d5e7 103 return;
4792d192
DS
104
105 switch ( controlpart )
e40298d5 106 {
0f85d5e7 107 case kControlUpButtonPart:
4b1c4c21 108 nScrollInc = -1;
519cb848 109 scrollEvent = wxEVT_SCROLL_LINEUP;
0f85d5e7 110 break;
4792d192 111
0f85d5e7 112 case kControlDownButtonPart:
4b1c4c21 113 nScrollInc = 1;
519cb848 114 scrollEvent = wxEVT_SCROLL_LINEDOWN;
0f85d5e7 115 break;
4792d192 116
0f85d5e7 117 case kControlPageUpPart:
4b1c4c21 118 nScrollInc = -m_pageSize;
519cb848 119 scrollEvent = wxEVT_SCROLL_PAGEUP;
0f85d5e7 120 break;
4792d192 121
0f85d5e7 122 case kControlPageDownPart:
4b1c4c21 123 nScrollInc = m_pageSize;
519cb848 124 scrollEvent = wxEVT_SCROLL_PAGEDOWN;
0f85d5e7 125 break;
4792d192 126
0f85d5e7
DS
127 case kControlIndicatorPart:
128 nScrollInc = 0;
4b26b60f
SC
129 if ( mouseStillDown )
130 scrollEvent = wxEVT_SCROLL_THUMBTRACK;
131 else
132 scrollEvent = wxEVT_SCROLL_THUMBRELEASE;
0f85d5e7 133 break;
4792d192 134
0f85d5e7
DS
135 default:
136 wxFAIL_MSG(wxT("unknown scrollbar selector"));
137 break;
e40298d5 138 }
4792d192 139
e40298d5 140 int new_pos = position + nScrollInc;
4792d192 141
e40298d5
JS
142 if (new_pos < minPos)
143 new_pos = minPos;
4792d192 144 else if (new_pos > maxPos)
e40298d5 145 new_pos = maxPos;
4792d192 146
e40298d5 147 if ( nScrollInc )
0f85d5e7 148 SetThumbPosition( new_pos );
4792d192 149
0f85d5e7 150 wxScrollEvent event( scrollEvent, m_windowId );
e40298d5 151 if ( m_windowStyle & wxHORIZONTAL )
0f85d5e7 152 event.SetOrientation( wxHORIZONTAL );
e40298d5 153 else
0f85d5e7 154 event.SetOrientation( wxVERTICAL );
4792d192 155
0f85d5e7 156 event.SetPosition( new_pos );
e40298d5 157 event.SetEventObject( this );
4792d192 158
0f85d5e7
DS
159 wxWindow* window = GetParent();
160 if (window && window->MacIsWindowScrollbar( this ))
e40298d5 161 // this is hardcoded
0f85d5e7 162 window->MacOnScroll( event );
e40298d5 163 else
0f85d5e7 164 GetEventHandler()->ProcessEvent( event );
519cb848
SC
165}
166
0f85d5e7 167wxInt32 wxScrollBar::MacControlHit( WXEVENTHANDLERREF handler, WXEVENTREF mevent )
4c37f124 168{
0f85d5e7
DS
169 int position = m_peer->GetValue();
170 int minPos = m_peer->GetMinimum();
171 int maxPos = m_peer->GetMaximum();
4792d192 172
4c37f124
SC
173 wxEventType scrollEvent = wxEVT_NULL;
174 int nScrollInc = 0;
4792d192 175
0f85d5e7
DS
176 wxMacCarbonEvent cEvent( (EventRef)mevent );
177 ControlPartCode controlpart = cEvent.GetParameter<ControlPartCode>(kEventParamControlPart, typeControlPartCode);
4792d192 178
4c37f124 179 // all events have already been reported during mouse down, except for THUMBRELEASE
0f85d5e7
DS
180 // NB: this may need to be reviewed in light of the fact that scroll wheel events
181 // aren't being handled properly
4792d192 182 if ( controlpart != kControlIndicatorPart )
0f85d5e7 183 return eventNotHandledErr;
4792d192
DS
184
185 switch ( controlpart )
4c37f124 186 {
0f85d5e7
DS
187 case kControlIndicatorPart:
188 nScrollInc = 0;
4c37f124 189 scrollEvent = wxEVT_SCROLL_THUMBRELEASE;
0f85d5e7 190 break;
4792d192 191
0f85d5e7
DS
192 default:
193 wxFAIL_MSG(wxT("unknown scrollbar selector"));
194 break;
4c37f124 195 }
4792d192 196
4c37f124 197 int new_pos = position + nScrollInc;
4792d192 198
4c37f124
SC
199 if (new_pos < minPos)
200 new_pos = minPos;
4792d192 201 else if (new_pos > maxPos)
4c37f124 202 new_pos = maxPos;
4792d192 203
4c37f124 204 if ( nScrollInc )
0f85d5e7 205 SetThumbPosition( new_pos );
4792d192 206
0f85d5e7 207 wxScrollEvent event( scrollEvent, m_windowId );
4c37f124 208 if ( m_windowStyle & wxHORIZONTAL )
4792d192 209 event.SetOrientation( wxHORIZONTAL );
4c37f124 210 else
4792d192
DS
211 event.SetOrientation( wxVERTICAL );
212
0f85d5e7 213 event.SetPosition( new_pos );
4c37f124 214 event.SetEventObject( this );
0f85d5e7
DS
215 wxWindow* window = GetParent();
216 if (window && window->MacIsWindowScrollbar( this ))
4c37f124 217 // this is hardcoded
0f85d5e7 218 window->MacOnScroll( event );
4c37f124 219 else
0f85d5e7 220 GetEventHandler()->ProcessEvent( event );
4792d192 221
0f85d5e7 222 return noErr;
4c37f124 223}
10ae0adb
RD
224
225
226wxSize wxScrollBar::DoGetBestSize() const
227{
228 int w = 100;
229 int h = 100;
230
231 if ( IsVertical() )
232 {
233 w = wxSystemSettings::GetMetric(wxSYS_VSCROLL_X);
234 }
235 else
236 {
237 h = wxSystemSettings::GetMetric(wxSYS_HSCROLL_Y);
238 }
239
240 wxSize best(w, h);
241 CacheBestSize(best);
9eddec69 242 return best;
10ae0adb 243}