1 /////////////////////////////////////////////////////////////////////////////
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
,
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 verify_noerr( CreateScrollBarControl( MAC_WXHWND(parent
->MacGetTopLevelWindowRef()) , &bounds
,
45 0 , 0 , 100 , 1 , true /* liveTracking */ , GetwxMacLiveScrollbarActionProc() , m_peer
->GetControlRefAddr() ) );
47 MacPostControlCreate( pos
, size
) ;
52 wxScrollBar::~wxScrollBar()
56 void wxScrollBar::SetThumbPosition(int viewStart
)
58 m_peer
->SetValue( viewStart
) ;
61 int wxScrollBar::GetThumbPosition() const
63 return m_peer
->GetValue() ;
66 void wxScrollBar::SetScrollbar(int position
, int thumbSize
, int range
, int pageSize
, bool refresh
)
68 m_pageSize
= pageSize
;
69 m_viewSize
= thumbSize
;
72 int range1
= wxMax((m_objectSize
- m_viewSize
), 0) ;
74 m_peer
->SetMaximum( range1
) ;
75 m_peer
->SetMinimum( 0 ) ;
76 m_peer
->SetValue( position
) ;
77 m_peer
->SetViewSize( m_viewSize
) ;
80 void wxScrollBar::Command(wxCommandEvent
& event
)
82 SetThumbPosition(event
.GetInt());
83 ProcessCommand(event
);
86 void wxScrollBar::MacHandleControlClick( WXWidget control
, wxInt16 controlpart
, bool mouseStillDown
)
88 int position
= m_peer
->GetValue() ;
89 int minPos
= m_peer
->GetMinimum() ;
90 int maxPos
= m_peer
->GetMaximum() ;
92 wxEventType scrollEvent
= wxEVT_NULL
;
95 // all events have already been reported during mouse down, except for THUMBRELEASE
96 if ( !mouseStillDown
&& controlpart
!= kControlIndicatorPart
)
99 switch ( controlpart
)
101 case kControlUpButtonPart
:
103 scrollEvent
= wxEVT_SCROLL_LINEUP
;
106 case kControlDownButtonPart
:
108 scrollEvent
= wxEVT_SCROLL_LINEDOWN
;
111 case kControlPageUpPart
:
112 nScrollInc
= -m_pageSize
;
113 scrollEvent
= wxEVT_SCROLL_PAGEUP
;
116 case kControlPageDownPart
:
117 nScrollInc
= m_pageSize
;
118 scrollEvent
= wxEVT_SCROLL_PAGEDOWN
;
121 case kControlIndicatorPart
:
123 if ( mouseStillDown
)
124 scrollEvent
= wxEVT_SCROLL_THUMBTRACK
;
126 scrollEvent
= wxEVT_SCROLL_THUMBRELEASE
;
130 wxFAIL_MSG(wxT("illegal scrollbar selector"));
134 int new_pos
= position
+ nScrollInc
;
136 if (new_pos
< minPos
)
138 else if (new_pos
> maxPos
)
142 SetThumbPosition(new_pos
);
144 wxScrollEvent
event(scrollEvent
, m_windowId
);
145 if ( m_windowStyle
& wxHORIZONTAL
)
146 event
.SetOrientation( wxHORIZONTAL
) ;
148 event
.SetOrientation( wxVERTICAL
) ;
150 event
.SetPosition(new_pos
);
151 event
.SetEventObject( this );
153 wxWindow
* window
= GetParent() ;
154 if (window
&& window
->MacIsWindowScrollbar(this) )
156 window
->MacOnScroll(event
);
158 GetEventHandler()->ProcessEvent(event
);
161 wxInt32
wxScrollBar::MacControlHit( WXEVENTHANDLERREF handler
, WXEVENTREF mevent
)
163 int position
= m_peer
->GetValue() ;
164 int minPos
= m_peer
->GetMinimum() ;
165 int maxPos
= m_peer
->GetMaximum() ;
167 wxEventType scrollEvent
= wxEVT_NULL
;
170 wxMacCarbonEvent
cEvent( (EventRef
) mevent
) ;
171 ControlPartCode controlpart
= cEvent
.GetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
) ;
173 // all events have already been reported during mouse down, except for THUMBRELEASE
174 if ( controlpart
!= kControlIndicatorPart
)
175 return eventNotHandledErr
;
177 switch ( controlpart
)
179 case kControlIndicatorPart
:
181 scrollEvent
= wxEVT_SCROLL_THUMBRELEASE
;
185 wxFAIL_MSG(wxT("illegal scrollbar selector"));
189 int new_pos
= position
+ nScrollInc
;
191 if (new_pos
< minPos
)
193 else if (new_pos
> maxPos
)
197 SetThumbPosition(new_pos
);
199 wxScrollEvent
event(scrollEvent
, m_windowId
);
200 if ( m_windowStyle
& wxHORIZONTAL
)
201 event
.SetOrientation( wxHORIZONTAL
);
203 event
.SetOrientation( wxVERTICAL
);
205 event
.SetPosition(new_pos
);
206 event
.SetEventObject( this );
207 wxWindow
* window
= GetParent() ;
208 if (window
&& window
->MacIsWindowScrollbar(this) )
210 window
->MacOnScroll(event
);
212 GetEventHandler()->ProcessEvent(event
);