]> git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/scrolbar.cpp
Removed unused event table entries
[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 #ifdef __GNUG__
13 #pragma implementation "scrolbar.h"
14 #endif
15
16 #include "wx/defs.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() ;
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 if ( refresh )
89 MacRedrawControl() ;
90 }
91
92
93 void wxScrollBar::Command(wxCommandEvent& event)
94 {
95 SetThumbPosition(event.m_commandInt);
96 ProcessCommand(event);
97 }
98
99 void wxScrollBar::MacHandleControlClick( WXWidget control , wxInt16 controlpart , bool mouseStillDown )
100 {
101 int position = m_peer->GetValue() ;
102 int minPos = m_peer->GetMinimum() ;
103 int maxPos = m_peer->GetMaximum() ;
104
105 wxEventType scrollEvent = wxEVT_NULL;
106 int nScrollInc = 0;
107
108 // all events have already been reported during mouse down, except for THUMBRELEASE
109 if ( !mouseStillDown && controlpart !=kControlIndicatorPart )
110 return ;
111
112 switch( controlpart )
113 {
114 case kControlUpButtonPart :
115 nScrollInc = -1;
116 scrollEvent = wxEVT_SCROLL_LINEUP;
117 break ;
118 case kControlDownButtonPart :
119 nScrollInc = 1;
120 scrollEvent = wxEVT_SCROLL_LINEDOWN;
121 break ;
122 case kControlPageUpPart :
123 nScrollInc = -m_pageSize;
124 scrollEvent = wxEVT_SCROLL_PAGEUP;
125 break ;
126 case kControlPageDownPart :
127 nScrollInc = m_pageSize;
128 scrollEvent = wxEVT_SCROLL_PAGEDOWN;
129 break ;
130 case kControlIndicatorPart :
131 nScrollInc = 0 ;
132 if ( mouseStillDown )
133 scrollEvent = wxEVT_SCROLL_THUMBTRACK;
134 else
135 scrollEvent = wxEVT_SCROLL_THUMBRELEASE;
136 break ;
137 default :
138 wxFAIL_MSG(wxT("illegal scrollbar selector"));
139 break ;
140 }
141
142 int new_pos = position + nScrollInc;
143
144 if (new_pos < minPos)
145 new_pos = minPos;
146 if (new_pos > maxPos)
147 new_pos = maxPos;
148 if ( nScrollInc )
149 SetThumbPosition(new_pos);
150
151 wxScrollEvent event(scrollEvent, m_windowId);
152 if ( m_windowStyle & wxHORIZONTAL )
153 {
154 event.SetOrientation( wxHORIZONTAL ) ;
155 }
156 else
157 {
158 event.SetOrientation( wxVERTICAL ) ;
159 }
160 event.SetPosition(new_pos);
161 event.SetEventObject( this );
162 wxWindow* window = GetParent() ;
163 if (window && window->MacIsWindowScrollbar(this) )
164 {
165 // this is hardcoded
166 window->MacOnScroll(event);
167 }
168 else
169 GetEventHandler()->ProcessEvent(event);
170 }
171
172 wxInt32 wxScrollBar::MacControlHit( WXEVENTHANDLERREF handler , WXEVENTREF mevent )
173 {
174 int position = m_peer->GetValue() ;
175 int minPos = m_peer->GetMinimum() ;
176 int maxPos = m_peer->GetMaximum() ;
177
178 wxEventType scrollEvent = wxEVT_NULL;
179 int nScrollInc = 0;
180
181 wxMacCarbonEvent cEvent( (EventRef) mevent ) ;
182 ControlPartCode controlpart = cEvent.GetParameter<ControlPartCode>(kEventParamControlPart,typeControlPartCode) ;
183
184 // all events have already been reported during mouse down, except for THUMBRELEASE
185 if ( controlpart !=kControlIndicatorPart )
186 return eventNotHandledErr ;
187
188 switch( controlpart )
189 {
190 case kControlIndicatorPart :
191 nScrollInc = 0 ;
192 scrollEvent = wxEVT_SCROLL_THUMBRELEASE;
193 break ;
194 default :
195 wxFAIL_MSG(wxT("illegal scrollbar selector"));
196 break ;
197 }
198
199 int new_pos = position + nScrollInc;
200
201 if (new_pos < minPos)
202 new_pos = minPos;
203 if (new_pos > maxPos)
204 new_pos = maxPos;
205 if ( nScrollInc )
206 SetThumbPosition(new_pos);
207
208 wxScrollEvent event(scrollEvent, m_windowId);
209 if ( m_windowStyle & wxHORIZONTAL )
210 {
211 event.SetOrientation( wxHORIZONTAL ) ;
212 }
213 else
214 {
215 event.SetOrientation( wxVERTICAL ) ;
216 }
217 event.SetPosition(new_pos);
218 event.SetEventObject( this );
219 wxWindow* window = GetParent() ;
220 if (window && window->MacIsWindowScrollbar(this) )
221 {
222 // this is hardcoded
223 window->MacOnScroll(event);
224 }
225 else
226 GetEventHandler()->ProcessEvent(event);
227 return noErr ;
228 }
229
230