]> git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/scrolbar.cpp
making implementation independent of a wx-peer of that control
[wxWidgets.git] / src / mac / carbon / scrolbar.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: 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 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
13 #pragma implementation "scrolbar.h"
14 #endif
15
16 #include "wx/wxprec.h"
17
18 #ifndef WX_PRECOMP
19 #include "wx/intl.h"
20 #include "wx/log.h"
21 #endif // WX_PRECOMP
22
23 #include "wx/scrolbar.h"
24 #include "wx/mac/uma.h"
25
26 #if !USE_SHARED_LIBRARY
27 IMPLEMENT_DYNAMIC_CLASS(wxScrollBar, wxControl)
28
29 BEGIN_EVENT_TABLE(wxScrollBar, wxControl)
30 END_EVENT_TABLE()
31
32 #endif
33
34 extern ControlActionUPP wxMacLiveScrollbarActionUPP ;
35
36 // Scrollbar
37 bool 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 {
43 m_macIsUserPane = FALSE ;
44
45 if ( !wxControl::Create(parent, id, pos, size, style, validator, name) )
46 return FALSE;
47
48 Rect bounds = wxMacGetBoundsForControl( this , pos , size ) ;
49
50 m_peer = new wxMacControl(this) ;
51 verify_noerr ( CreateScrollBarControl( MAC_WXHWND(parent->MacGetTopLevelWindowRef()) , &bounds ,
52 0 , 0 , 100 , 1 , true /* liveTracking */ , wxMacLiveScrollbarActionUPP , m_peer->GetControlRefAddr() ) );
53
54
55 MacPostControlCreate(pos,size) ;
56
57 return TRUE;
58 }
59
60 wxScrollBar::~wxScrollBar()
61 {
62 }
63
64 void wxScrollBar::SetThumbPosition(int viewStart)
65 {
66 m_peer->SetValue( viewStart ) ;
67 }
68
69 int wxScrollBar::GetThumbPosition() const
70 {
71 return m_peer->GetValue() ;
72 }
73
74 void wxScrollBar::SetScrollbar(int position, int thumbSize, int range, int pageSize,
75 bool refresh)
76 {
77 m_pageSize = pageSize;
78 m_viewSize = thumbSize;
79 m_objectSize = range;
80
81 int range1 = wxMax((m_objectSize - m_viewSize), 0) ;
82
83 m_peer->SetMaximum( range1 ) ;
84 m_peer->SetMinimum( 0 ) ;
85 m_peer->SetValue( position ) ;
86 m_peer->SetViewSize( m_viewSize ) ;
87 }
88
89
90 void wxScrollBar::Command(wxCommandEvent& event)
91 {
92 SetThumbPosition(event.GetInt());
93 ProcessCommand(event);
94 }
95
96 void wxScrollBar::MacHandleControlClick( WXWidget control , wxInt16 controlpart , bool mouseStillDown )
97 {
98 int position = m_peer->GetValue() ;
99 int minPos = m_peer->GetMinimum() ;
100 int maxPos = m_peer->GetMaximum() ;
101
102 wxEventType scrollEvent = wxEVT_NULL;
103 int nScrollInc = 0;
104
105 // all events have already been reported during mouse down, except for THUMBRELEASE
106 if ( !mouseStillDown && controlpart !=kControlIndicatorPart )
107 return ;
108
109 switch( controlpart )
110 {
111 case kControlUpButtonPart :
112 nScrollInc = -1;
113 scrollEvent = wxEVT_SCROLL_LINEUP;
114 break ;
115 case kControlDownButtonPart :
116 nScrollInc = 1;
117 scrollEvent = wxEVT_SCROLL_LINEDOWN;
118 break ;
119 case kControlPageUpPart :
120 nScrollInc = -m_pageSize;
121 scrollEvent = wxEVT_SCROLL_PAGEUP;
122 break ;
123 case kControlPageDownPart :
124 nScrollInc = m_pageSize;
125 scrollEvent = wxEVT_SCROLL_PAGEDOWN;
126 break ;
127 case kControlIndicatorPart :
128 nScrollInc = 0 ;
129 if ( mouseStillDown )
130 scrollEvent = wxEVT_SCROLL_THUMBTRACK;
131 else
132 scrollEvent = wxEVT_SCROLL_THUMBRELEASE;
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);
167 }
168
169 wxInt32 wxScrollBar::MacControlHit( WXEVENTHANDLERREF handler , WXEVENTREF mevent )
170 {
171 int position = m_peer->GetValue() ;
172 int minPos = m_peer->GetMinimum() ;
173 int maxPos = m_peer->GetMaximum() ;
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