]> git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/scrolbar.cpp
switching to CreateXXX methods for Controls and to Hit Event Processing, thus support...
[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 verify_noerr ( CreateScrollBarControl( MAC_WXHWND(parent->MacGetTopLevelWindowRef()) , &bounds ,
51 0 , 0 , 100 , 1 , true /* liveTracking */ , wxMacLiveScrollbarActionUPP , (ControlRef*) &m_macControl ) ) ;
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 ::SetControl32BitValue( (ControlRef) m_macControl , viewStart ) ;
65 }
66
67 int wxScrollBar::GetThumbPosition() const
68 {
69 return ::GetControl32BitValue( (ControlRef) m_macControl ) ;
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 SetControl32BitMaximum( (ControlRef) m_macControl , range1 ) ;
82 SetControl32BitMinimum( (ControlRef) m_macControl , 0 ) ;
83 SetControl32BitValue( (ControlRef) m_macControl , position ) ;
84 SetControlViewSize( (ControlRef) m_macControl , m_viewSize ) ;
85
86 if ( refresh )
87 MacRedrawControl() ;
88 }
89
90
91 void wxScrollBar::Command(wxCommandEvent& event)
92 {
93 SetThumbPosition(event.m_commandInt);
94 ProcessCommand(event);
95 }
96
97 void wxScrollBar::MacHandleControlClick( WXWidget control , wxInt16 controlpart , bool mouseStillDown )
98 {
99 int position = GetControl32BitValue( (ControlRef) m_macControl) ;
100 int minPos = GetControl32BitMinimum( (ControlRef) m_macControl) ;
101 int maxPos = GetControl32BitMaximum( (ControlRef) m_macControl) ;
102
103 wxEventType scrollEvent = wxEVT_NULL;
104 int nScrollInc = 0;
105
106 // all events have already been reported during mouse down, except for THUMBRELEASE
107 if ( !mouseStillDown && controlpart !=kControlIndicatorPart )
108 return ;
109
110 switch( controlpart )
111 {
112 case kControlUpButtonPart :
113 nScrollInc = -1;
114 scrollEvent = wxEVT_SCROLL_LINEUP;
115 break ;
116 case kControlDownButtonPart :
117 nScrollInc = 1;
118 scrollEvent = wxEVT_SCROLL_LINEDOWN;
119 break ;
120 case kControlPageUpPart :
121 nScrollInc = -m_pageSize;
122 scrollEvent = wxEVT_SCROLL_PAGEUP;
123 break ;
124 case kControlPageDownPart :
125 nScrollInc = m_pageSize;
126 scrollEvent = wxEVT_SCROLL_PAGEDOWN;
127 break ;
128 case kControlIndicatorPart :
129 nScrollInc = 0 ;
130 if ( mouseStillDown )
131 scrollEvent = wxEVT_SCROLL_THUMBTRACK;
132 else
133 scrollEvent = wxEVT_SCROLL_THUMBRELEASE;
134 break ;
135 default :
136 wxFAIL_MSG(wxT("illegal scrollbar selector"));
137 break ;
138 }
139
140 int new_pos = position + nScrollInc;
141
142 if (new_pos < minPos)
143 new_pos = minPos;
144 if (new_pos > maxPos)
145 new_pos = maxPos;
146 if ( nScrollInc )
147 SetThumbPosition(new_pos);
148
149 wxScrollEvent event(scrollEvent, m_windowId);
150 if ( m_windowStyle & wxHORIZONTAL )
151 {
152 event.SetOrientation( wxHORIZONTAL ) ;
153 }
154 else
155 {
156 event.SetOrientation( wxVERTICAL ) ;
157 }
158 event.SetPosition(new_pos);
159 event.SetEventObject( this );
160 wxWindow* window = GetParent() ;
161 if (window && window->MacIsWindowScrollbar(this) )
162 {
163 // this is hardcoded
164 window->MacOnScroll(event);
165 }
166 else
167 GetEventHandler()->ProcessEvent(event);
168 }
169
170 wxInt32 wxScrollBar::MacControlHit( WXEVENTHANDLERREF handler , WXEVENTREF mevent )
171 {
172 int position = GetControl32BitValue( (ControlRef) m_macControl) ;
173 int minPos = GetControl32BitMinimum( (ControlRef) m_macControl) ;
174 int maxPos = GetControl32BitMaximum( (ControlRef) m_macControl) ;
175
176 wxEventType scrollEvent = wxEVT_NULL;
177 int nScrollInc = 0;
178
179 wxMacCarbonEvent cEvent( (EventRef) mevent ) ;
180 ControlPartCode controlpart = cEvent.GetParameter<ControlPartCode>(kEventParamControlPart,typeControlPartCode) ;
181
182 // all events have already been reported during mouse down, except for THUMBRELEASE
183 if ( controlpart !=kControlIndicatorPart )
184 return eventNotHandledErr ;
185
186 switch( controlpart )
187 {
188 case kControlIndicatorPart :
189 nScrollInc = 0 ;
190 scrollEvent = wxEVT_SCROLL_THUMBRELEASE;
191 break ;
192 default :
193 wxFAIL_MSG(wxT("illegal scrollbar selector"));
194 break ;
195 }
196
197 int new_pos = position + nScrollInc;
198
199 if (new_pos < minPos)
200 new_pos = minPos;
201 if (new_pos > maxPos)
202 new_pos = maxPos;
203 if ( nScrollInc )
204 SetThumbPosition(new_pos);
205
206 wxScrollEvent event(scrollEvent, m_windowId);
207 if ( m_windowStyle & wxHORIZONTAL )
208 {
209 event.SetOrientation( wxHORIZONTAL ) ;
210 }
211 else
212 {
213 event.SetOrientation( wxVERTICAL ) ;
214 }
215 event.SetPosition(new_pos);
216 event.SetEventObject( this );
217 wxWindow* window = GetParent() ;
218 if (window && window->MacIsWindowScrollbar(this) )
219 {
220 // this is hardcoded
221 window->MacOnScroll(event);
222 }
223 else
224 GetEventHandler()->ProcessEvent(event);
225 return noErr ;
226 }
227
228