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