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/scrolbar.h"
20 #include "wx/mac/uma.h"
22 IMPLEMENT_DYNAMIC_CLASS(wxScrollBar
, wxControl
)
24 BEGIN_EVENT_TABLE(wxScrollBar
, wxControl
)
28 bool wxScrollBar::Create( wxWindow
*parent
,
33 const wxValidator
& validator
,
34 const wxString
& name
)
36 m_macIsUserPane
= false;
38 if ( !wxControl::Create( parent
, id
, pos
, size
, style
, validator
, name
) )
41 Rect bounds
= wxMacGetBoundsForControl( this, pos
, size
);
43 m_peer
= new wxMacControl( this );
44 OSStatus err
= CreateScrollBarControl(
45 MAC_WXHWND(parent
->MacGetTopLevelWindowRef()), &bounds
,
46 0, 0, 100, 1, true /* liveTracking */,
47 GetwxMacLiveScrollbarActionProc(),
48 m_peer
->GetControlRefAddr() );
51 MacPostControlCreate( pos
, size
);
56 wxScrollBar::~wxScrollBar()
60 void wxScrollBar::SetThumbPosition( int viewStart
)
62 m_peer
->SetValue( viewStart
);
65 int wxScrollBar::GetThumbPosition() const
67 return m_peer
->GetValue();
70 void wxScrollBar::SetScrollbar( int position
, int thumbSize
, int range
, int pageSize
, bool refresh
)
72 m_pageSize
= pageSize
;
73 m_viewSize
= thumbSize
;
76 int range1
= wxMax( (m_objectSize
- m_viewSize
), 0 );
78 m_peer
->SetMinimum( 0 );
79 m_peer
->SetMaximum( range1
);
80 m_peer
->SetValue( position
);
81 m_peer
->SetViewSize( m_viewSize
);
84 void wxScrollBar::Command( wxCommandEvent
& event
)
86 SetThumbPosition( event
.GetInt() );
87 ProcessCommand( event
);
90 void wxScrollBar::MacHandleControlClick( WXWidget control
, wxInt16 controlpart
, bool mouseStillDown
)
92 int position
= m_peer
->GetValue();
93 int minPos
= m_peer
->GetMinimum();
94 int maxPos
= m_peer
->GetMaximum();
96 wxEventType scrollEvent
= wxEVT_NULL
;
99 // all events have already been reported during mouse down, except for THUMBRELEASE
100 if ( !mouseStillDown
&& controlpart
!= kControlIndicatorPart
)
103 switch ( controlpart
)
105 case kControlUpButtonPart
:
107 scrollEvent
= wxEVT_SCROLL_LINEUP
;
110 case kControlDownButtonPart
:
112 scrollEvent
= wxEVT_SCROLL_LINEDOWN
;
115 case kControlPageUpPart
:
116 nScrollInc
= -m_pageSize
;
117 scrollEvent
= wxEVT_SCROLL_PAGEUP
;
120 case kControlPageDownPart
:
121 nScrollInc
= m_pageSize
;
122 scrollEvent
= wxEVT_SCROLL_PAGEDOWN
;
125 case kControlIndicatorPart
:
127 if ( mouseStillDown
)
128 scrollEvent
= wxEVT_SCROLL_THUMBTRACK
;
130 scrollEvent
= wxEVT_SCROLL_THUMBRELEASE
;
134 wxFAIL_MSG(wxT("unknown scrollbar selector"));
138 int new_pos
= position
+ nScrollInc
;
140 if (new_pos
< minPos
)
142 else if (new_pos
> maxPos
)
146 SetThumbPosition( new_pos
);
148 wxScrollEvent
event( scrollEvent
, m_windowId
);
149 if ( m_windowStyle
& wxHORIZONTAL
)
150 event
.SetOrientation( wxHORIZONTAL
);
152 event
.SetOrientation( wxVERTICAL
);
154 event
.SetPosition( new_pos
);
155 event
.SetEventObject( this );
157 wxWindow
* window
= GetParent();
158 if (window
&& window
->MacIsWindowScrollbar( this ))
160 window
->MacOnScroll( event
);
162 GetEventHandler()->ProcessEvent( event
);
165 wxInt32
wxScrollBar::MacControlHit( WXEVENTHANDLERREF handler
, WXEVENTREF mevent
)
167 int position
= m_peer
->GetValue();
168 int minPos
= m_peer
->GetMinimum();
169 int maxPos
= m_peer
->GetMaximum();
171 wxEventType scrollEvent
= wxEVT_NULL
;
174 wxMacCarbonEvent
cEvent( (EventRef
)mevent
);
175 ControlPartCode controlpart
= cEvent
.GetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
);
177 // all events have already been reported during mouse down, except for THUMBRELEASE
178 // NB: this may need to be reviewed in light of the fact that scroll wheel events
179 // aren't being handled properly
180 if ( controlpart
!= kControlIndicatorPart
)
181 return eventNotHandledErr
;
183 switch ( controlpart
)
185 case kControlIndicatorPart
:
187 scrollEvent
= wxEVT_SCROLL_THUMBRELEASE
;
191 wxFAIL_MSG(wxT("unknown scrollbar selector"));
195 int new_pos
= position
+ nScrollInc
;
197 if (new_pos
< minPos
)
199 else if (new_pos
> maxPos
)
203 SetThumbPosition( new_pos
);
205 wxScrollEvent
event( scrollEvent
, m_windowId
);
206 if ( m_windowStyle
& wxHORIZONTAL
)
207 event
.SetOrientation( wxHORIZONTAL
);
209 event
.SetOrientation( wxVERTICAL
);
211 event
.SetPosition( new_pos
);
212 event
.SetEventObject( this );
213 wxWindow
* window
= GetParent();
214 if (window
&& window
->MacIsWindowScrollbar( this ))
216 window
->MacOnScroll( event
);
218 GetEventHandler()->ProcessEvent( event
);