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