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