1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxScrollBar
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "scrolbar.h"
23 #include "wx/scrolbar.h"
24 #include "wx/mac/uma.h"
26 #if !USE_SHARED_LIBRARY
27 IMPLEMENT_DYNAMIC_CLASS(wxScrollBar
, wxControl
)
29 BEGIN_EVENT_TABLE(wxScrollBar
, wxControl
)
34 extern ControlActionUPP wxMacLiveScrollbarActionUPP
;
37 bool wxScrollBar::Create(wxWindow
*parent
, wxWindowID id
,
39 const wxSize
& size
, long style
,
40 const wxValidator
& validator
,
43 m_macIsUserPane
= FALSE
;
45 if ( !wxControl::Create(parent
, id
, pos
, size
, style
, validator
, name
) )
48 Rect bounds
= wxMacGetBoundsForControl( this , pos
, size
) ;
50 verify_noerr ( CreateScrollBarControl( MAC_WXHWND(parent
->MacGetTopLevelWindowRef()) , &bounds
,
51 0 , 0 , 100 , 1 , true /* liveTracking */ , wxMacLiveScrollbarActionUPP
, (ControlRef
*) &m_macControl
) ) ;
53 MacPostControlCreate(pos
,size
) ;
58 wxScrollBar::~wxScrollBar()
62 void wxScrollBar::SetThumbPosition(int viewStart
)
64 ::SetControl32BitValue( (ControlRef
) m_macControl
, viewStart
) ;
67 int wxScrollBar::GetThumbPosition() const
69 return ::GetControl32BitValue( (ControlRef
) m_macControl
) ;
72 void wxScrollBar::SetScrollbar(int position
, int thumbSize
, int range
, int pageSize
,
75 m_pageSize
= pageSize
;
76 m_viewSize
= thumbSize
;
79 int range1
= wxMax((m_objectSize
- m_viewSize
), 0) ;
81 SetControl32BitMaximum( (ControlRef
) m_macControl
, range1
) ;
82 SetControl32BitMinimum( (ControlRef
) m_macControl
, 0 ) ;
83 SetControl32BitValue( (ControlRef
) m_macControl
, position
) ;
84 SetControlViewSize( (ControlRef
) m_macControl
, m_viewSize
) ;
91 void wxScrollBar::Command(wxCommandEvent
& event
)
93 SetThumbPosition(event
.m_commandInt
);
94 ProcessCommand(event
);
97 void wxScrollBar::MacHandleControlClick( WXWidget control
, wxInt16 controlpart
, bool mouseStillDown
)
99 int position
= GetControl32BitValue( (ControlRef
) m_macControl
) ;
100 int minPos
= GetControl32BitMinimum( (ControlRef
) m_macControl
) ;
101 int maxPos
= GetControl32BitMaximum( (ControlRef
) m_macControl
) ;
103 wxEventType scrollEvent
= wxEVT_NULL
;
106 // all events have already been reported during mouse down, except for THUMBRELEASE
107 if ( !mouseStillDown
&& controlpart
!=kControlIndicatorPart
)
110 switch( controlpart
)
112 case kControlUpButtonPart
:
114 scrollEvent
= wxEVT_SCROLL_LINEUP
;
116 case kControlDownButtonPart
:
118 scrollEvent
= wxEVT_SCROLL_LINEDOWN
;
120 case kControlPageUpPart
:
121 nScrollInc
= -m_pageSize
;
122 scrollEvent
= wxEVT_SCROLL_PAGEUP
;
124 case kControlPageDownPart
:
125 nScrollInc
= m_pageSize
;
126 scrollEvent
= wxEVT_SCROLL_PAGEDOWN
;
128 case kControlIndicatorPart
:
130 if ( mouseStillDown
)
131 scrollEvent
= wxEVT_SCROLL_THUMBTRACK
;
133 scrollEvent
= wxEVT_SCROLL_THUMBRELEASE
;
136 wxFAIL_MSG(wxT("illegal scrollbar selector"));
140 int new_pos
= position
+ nScrollInc
;
142 if (new_pos
< minPos
)
144 if (new_pos
> maxPos
)
147 SetThumbPosition(new_pos
);
149 wxScrollEvent
event(scrollEvent
, m_windowId
);
150 if ( m_windowStyle
& wxHORIZONTAL
)
152 event
.SetOrientation( wxHORIZONTAL
) ;
156 event
.SetOrientation( wxVERTICAL
) ;
158 event
.SetPosition(new_pos
);
159 event
.SetEventObject( this );
160 wxWindow
* window
= GetParent() ;
161 if (window
&& window
->MacIsWindowScrollbar(this) )
164 window
->MacOnScroll(event
);
167 GetEventHandler()->ProcessEvent(event
);
170 wxInt32
wxScrollBar::MacControlHit( WXEVENTHANDLERREF handler
, WXEVENTREF mevent
)
172 int position
= GetControl32BitValue( (ControlRef
) m_macControl
) ;
173 int minPos
= GetControl32BitMinimum( (ControlRef
) m_macControl
) ;
174 int maxPos
= GetControl32BitMaximum( (ControlRef
) m_macControl
) ;
176 wxEventType scrollEvent
= wxEVT_NULL
;
179 wxMacCarbonEvent
cEvent( (EventRef
) mevent
) ;
180 ControlPartCode controlpart
= cEvent
.GetParameter
<ControlPartCode
>(kEventParamControlPart
,typeControlPartCode
) ;
182 // all events have already been reported during mouse down, except for THUMBRELEASE
183 if ( controlpart
!=kControlIndicatorPart
)
184 return eventNotHandledErr
;
186 switch( controlpart
)
188 case kControlIndicatorPart
:
190 scrollEvent
= wxEVT_SCROLL_THUMBRELEASE
;
193 wxFAIL_MSG(wxT("illegal scrollbar selector"));
197 int new_pos
= position
+ nScrollInc
;
199 if (new_pos
< minPos
)
201 if (new_pos
> maxPos
)
204 SetThumbPosition(new_pos
);
206 wxScrollEvent
event(scrollEvent
, m_windowId
);
207 if ( m_windowStyle
& wxHORIZONTAL
)
209 event
.SetOrientation( wxHORIZONTAL
) ;
213 event
.SetOrientation( wxVERTICAL
) ;
215 event
.SetPosition(new_pos
);
216 event
.SetEventObject( this );
217 wxWindow
* window
= GetParent() ;
218 if (window
&& window
->MacIsWindowScrollbar(this) )
221 window
->MacOnScroll(event
);
224 GetEventHandler()->ProcessEvent(event
);