1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/mac/carbon/scrolbar.cpp
3 // Purpose: wxScrollBar
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #include "wx/wxprec.h"
19 #include "wx/settings.h"
20 #include "wx/scrolbar.h"
21 #include "wx/mac/uma.h"
23 IMPLEMENT_DYNAMIC_CLASS(wxScrollBar
, wxControl
)
25 BEGIN_EVENT_TABLE(wxScrollBar
, wxControl
)
29 bool wxScrollBar::Create( wxWindow
*parent
,
34 const wxValidator
& validator
,
35 const wxString
& name
)
37 m_macIsUserPane
= false;
39 if ( !wxControl::Create( parent
, id
, pos
, size
, style
, validator
, name
) )
42 Rect bounds
= wxMacGetBoundsForControl( this, pos
, size
);
44 m_peer
= new wxMacControl( this );
45 OSStatus err
= CreateScrollBarControl(
46 MAC_WXHWND(parent
->MacGetTopLevelWindowRef()), &bounds
,
47 0, 0, 100, 1, true /* liveTracking */,
48 GetwxMacLiveScrollbarActionProc(),
49 m_peer
->GetControlRefAddr() );
52 MacPostControlCreate( pos
, size
);
57 wxScrollBar::~wxScrollBar()
61 void wxScrollBar::SetThumbPosition( int viewStart
)
63 m_peer
->SetValue( viewStart
);
66 int wxScrollBar::GetThumbPosition() const
68 return m_peer
->GetValue();
71 void wxScrollBar::SetScrollbar( int position
, int thumbSize
, int range
, int pageSize
, bool refresh
)
73 m_pageSize
= pageSize
;
74 m_viewSize
= thumbSize
;
77 int range1
= wxMax( (m_objectSize
- m_viewSize
), 0 );
79 m_peer
->SetMinimum( 0 );
80 m_peer
->SetMaximum( range1
);
81 m_peer
->SetValue( position
);
82 m_peer
->SetViewSize( m_viewSize
);
85 void wxScrollBar::Command( wxCommandEvent
& event
)
87 SetThumbPosition( event
.GetInt() );
88 ProcessCommand( event
);
91 void wxScrollBar::MacHandleControlClick( WXWidget control
, wxInt16 controlpart
, bool mouseStillDown
)
93 int position
= m_peer
->GetValue();
94 int minPos
= m_peer
->GetMinimum();
95 int maxPos
= m_peer
->GetMaximum();
97 wxEventType scrollEvent
= wxEVT_NULL
;
100 // all events have already been reported during mouse down, except for THUMBRELEASE
101 if ( !mouseStillDown
&& controlpart
!= kControlIndicatorPart
)
104 switch ( controlpart
)
106 case kControlUpButtonPart
:
108 scrollEvent
= wxEVT_SCROLL_LINEUP
;
111 case kControlDownButtonPart
:
113 scrollEvent
= wxEVT_SCROLL_LINEDOWN
;
116 case kControlPageUpPart
:
117 nScrollInc
= -m_pageSize
;
118 scrollEvent
= wxEVT_SCROLL_PAGEUP
;
121 case kControlPageDownPart
:
122 nScrollInc
= m_pageSize
;
123 scrollEvent
= wxEVT_SCROLL_PAGEDOWN
;
126 case kControlIndicatorPart
:
128 if ( mouseStillDown
)
129 scrollEvent
= wxEVT_SCROLL_THUMBTRACK
;
131 scrollEvent
= wxEVT_SCROLL_THUMBRELEASE
;
135 wxFAIL_MSG(wxT("unknown scrollbar selector"));
139 int new_pos
= position
+ nScrollInc
;
141 if (new_pos
< minPos
)
143 else if (new_pos
> maxPos
)
147 SetThumbPosition( new_pos
);
149 wxScrollEvent
event( scrollEvent
, m_windowId
);
150 if ( m_windowStyle
& wxHORIZONTAL
)
151 event
.SetOrientation( wxHORIZONTAL
);
153 event
.SetOrientation( wxVERTICAL
);
155 event
.SetPosition( new_pos
);
156 event
.SetEventObject( this );
158 wxWindow
* window
= GetParent();
159 if (window
&& window
->MacIsWindowScrollbar( this ))
161 window
->MacOnScroll( event
);
163 GetEventHandler()->ProcessEvent( event
);
166 wxInt32
wxScrollBar::MacControlHit( WXEVENTHANDLERREF handler
, WXEVENTREF mevent
)
168 int position
= m_peer
->GetValue();
169 int minPos
= m_peer
->GetMinimum();
170 int maxPos
= m_peer
->GetMaximum();
172 wxEventType scrollEvent
= wxEVT_NULL
;
175 wxMacCarbonEvent
cEvent( (EventRef
)mevent
);
176 ControlPartCode controlpart
= cEvent
.GetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
);
178 // all events have already been reported during mouse down, except for THUMBRELEASE
179 // NB: this may need to be reviewed in light of the fact that scroll wheel events
180 // aren't being handled properly
181 if ( controlpart
!= kControlIndicatorPart
)
182 return eventNotHandledErr
;
184 switch ( controlpart
)
186 case kControlIndicatorPart
:
188 scrollEvent
= wxEVT_SCROLL_THUMBRELEASE
;
192 wxFAIL_MSG(wxT("unknown scrollbar selector"));
196 int new_pos
= position
+ nScrollInc
;
198 if (new_pos
< minPos
)
200 else if (new_pos
> maxPos
)
204 SetThumbPosition( new_pos
);
206 wxScrollEvent
event( scrollEvent
, m_windowId
);
207 if ( m_windowStyle
& wxHORIZONTAL
)
208 event
.SetOrientation( wxHORIZONTAL
);
210 event
.SetOrientation( wxVERTICAL
);
212 event
.SetPosition( new_pos
);
213 event
.SetEventObject( this );
214 wxWindow
* window
= GetParent();
215 if (window
&& window
->MacIsWindowScrollbar( this ))
217 window
->MacOnScroll( event
);
219 GetEventHandler()->ProcessEvent( event
);
225 wxSize
wxScrollBar::DoGetBestSize() const
232 w
= wxSystemSettings::GetMetric(wxSYS_VSCROLL_X
);
236 h
= wxSystemSettings::GetMetric(wxSYS_HSCROLL_Y
);