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