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"
14 #include "wx/scrolbar.h"
19 #include "wx/settings.h"
22 #include "wx/mac/uma.h"
24 IMPLEMENT_DYNAMIC_CLASS(wxScrollBar
, wxControl
)
26 BEGIN_EVENT_TABLE(wxScrollBar
, wxControl
)
30 bool wxScrollBar::Create( wxWindow
*parent
,
35 const wxValidator
& validator
,
36 const wxString
& name
)
38 m_macIsUserPane
= false;
40 if ( !wxControl::Create( parent
, id
, pos
, size
, style
, validator
, name
) )
43 Rect bounds
= wxMacGetBoundsForControl( this, pos
, size
);
45 m_peer
= new wxMacControl( this );
46 OSStatus err
= CreateScrollBarControl(
47 MAC_WXHWND(parent
->MacGetTopLevelWindowRef()), &bounds
,
48 0, 0, 100, 1, true /* liveTracking */,
49 GetwxMacLiveScrollbarActionProc(),
50 m_peer
->GetControlRefAddr() );
53 MacPostControlCreate( pos
, size
);
58 wxScrollBar::~wxScrollBar()
62 void wxScrollBar::SetThumbPosition( int viewStart
)
64 m_peer
->SetValue( viewStart
);
67 int wxScrollBar::GetThumbPosition() const
69 return m_peer
->GetValue();
72 void wxScrollBar::SetScrollbar( int position
,
76 bool WXUNUSED(refresh
) )
78 m_pageSize
= pageSize
;
79 m_viewSize
= thumbSize
;
82 int range1
= wxMax( (m_objectSize
- m_viewSize
), 0 );
84 m_peer
->SetMinimum( 0 );
85 m_peer
->SetMaximum( range1
);
86 m_peer
->SetValue( position
);
87 m_peer
->SetViewSize( m_viewSize
);
90 void wxScrollBar::Command( wxCommandEvent
& event
)
92 SetThumbPosition( event
.GetInt() );
93 ProcessCommand( event
);
96 void wxScrollBar::MacHandleControlClick( WXWidget
WXUNUSED(control
), wxInt16 controlpart
, bool mouseStillDown
)
98 int position
= m_peer
->GetValue();
99 int minPos
= m_peer
->GetMinimum();
100 int maxPos
= m_peer
->GetMaximum();
102 wxEventType scrollEvent
= wxEVT_NULL
;
105 // all events have already been reported during mouse down, except for THUMBRELEASE
106 if ( !mouseStillDown
&& controlpart
!= kControlIndicatorPart
)
109 switch ( controlpart
)
111 case kControlUpButtonPart
:
113 scrollEvent
= wxEVT_SCROLL_LINEUP
;
116 case kControlDownButtonPart
:
118 scrollEvent
= wxEVT_SCROLL_LINEDOWN
;
121 case kControlPageUpPart
:
122 nScrollInc
= -m_pageSize
;
123 scrollEvent
= wxEVT_SCROLL_PAGEUP
;
126 case kControlPageDownPart
:
127 nScrollInc
= m_pageSize
;
128 scrollEvent
= wxEVT_SCROLL_PAGEDOWN
;
131 case kControlIndicatorPart
:
133 if ( mouseStillDown
)
134 scrollEvent
= wxEVT_SCROLL_THUMBTRACK
;
136 scrollEvent
= wxEVT_SCROLL_THUMBRELEASE
;
140 wxFAIL_MSG(wxT("unknown scrollbar selector"));
144 int new_pos
= position
+ nScrollInc
;
146 if (new_pos
< minPos
)
148 else if (new_pos
> maxPos
)
152 SetThumbPosition( new_pos
);
154 wxScrollEvent
event( scrollEvent
, m_windowId
);
155 if ( m_windowStyle
& wxHORIZONTAL
)
156 event
.SetOrientation( wxHORIZONTAL
);
158 event
.SetOrientation( wxVERTICAL
);
160 event
.SetPosition( new_pos
);
161 event
.SetEventObject( this );
163 wxWindow
* window
= GetParent();
164 if (window
&& window
->MacIsWindowScrollbar( this ))
166 window
->MacOnScroll( event
);
168 HandleWindowEvent( event
);
171 wxInt32
wxScrollBar::MacControlHit( WXEVENTHANDLERREF
WXUNUSED(handler
), WXEVENTREF mevent
)
173 int position
= m_peer
->GetValue();
174 int minPos
= m_peer
->GetMinimum();
175 int maxPos
= m_peer
->GetMaximum();
177 wxEventType scrollEvent
= wxEVT_NULL
;
180 wxMacCarbonEvent
cEvent( (EventRef
)mevent
);
181 ControlPartCode controlpart
= cEvent
.GetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
);
183 // all events have already been reported during mouse down, except for THUMBRELEASE
184 // NB: this may need to be reviewed in light of the fact that scroll wheel events
185 // aren't being handled properly
186 if ( controlpart
!= kControlIndicatorPart
)
187 return eventNotHandledErr
;
189 switch ( controlpart
)
191 case kControlIndicatorPart
:
193 scrollEvent
= wxEVT_SCROLL_THUMBRELEASE
;
197 wxFAIL_MSG(wxT("unknown scrollbar selector"));
201 int new_pos
= position
+ nScrollInc
;
203 if (new_pos
< minPos
)
205 else if (new_pos
> maxPos
)
209 SetThumbPosition( new_pos
);
211 wxScrollEvent
event( scrollEvent
, m_windowId
);
212 if ( m_windowStyle
& wxHORIZONTAL
)
213 event
.SetOrientation( wxHORIZONTAL
);
215 event
.SetOrientation( wxVERTICAL
);
217 event
.SetPosition( new_pos
);
218 event
.SetEventObject( this );
219 wxWindow
* window
= GetParent();
220 if (window
&& window
->MacIsWindowScrollbar( this ))
222 window
->MacOnScroll( event
);
224 HandleWindowEvent( event
);
230 wxSize
wxScrollBar::DoGetBestSize() const
237 w
= wxSystemSettings::GetMetric(wxSYS_VSCROLL_X
);
241 h
= wxSystemSettings::GetMetric(wxSYS_HSCROLL_Y
);