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