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 m_peer
= new wxMacControl() ;
51 verify_noerr ( CreateScrollBarControl( MAC_WXHWND(parent
->MacGetTopLevelWindowRef()) , &bounds
,
52 0 , 0 , 100 , 1 , true /* liveTracking */ , wxMacLiveScrollbarActionUPP
, m_peer
->GetControlRefAddr() ) );
55 MacPostControlCreate(pos
,size
) ;
60 wxScrollBar::~wxScrollBar()
64 void wxScrollBar::SetThumbPosition(int viewStart
)
66 m_peer
->SetValue( viewStart
) ;
69 int wxScrollBar::GetThumbPosition() const
71 return m_peer
->GetValue() ;
74 void wxScrollBar::SetScrollbar(int position
, int thumbSize
, int range
, int pageSize
,
77 m_pageSize
= pageSize
;
78 m_viewSize
= thumbSize
;
81 int range1
= wxMax((m_objectSize
- m_viewSize
), 0) ;
83 m_peer
->SetMaximum( range1
) ;
84 m_peer
->SetMinimum( 0 ) ;
85 m_peer
->SetValue( position
) ;
86 m_peer
->SetViewSize( m_viewSize
) ;
93 void wxScrollBar::Command(wxCommandEvent
& event
)
95 SetThumbPosition(event
.m_commandInt
);
96 ProcessCommand(event
);
99 void wxScrollBar::MacHandleControlClick( WXWidget control
, wxInt16 controlpart
, bool mouseStillDown
)
101 int position
= m_peer
->GetValue() ;
102 int minPos
= m_peer
->GetMinimum() ;
103 int maxPos
= m_peer
->GetMaximum() ;
105 wxEventType scrollEvent
= wxEVT_NULL
;
108 // all events have already been reported during mouse down, except for THUMBRELEASE
109 if ( !mouseStillDown
&& controlpart
!=kControlIndicatorPart
)
112 switch( controlpart
)
114 case kControlUpButtonPart
:
116 scrollEvent
= wxEVT_SCROLL_LINEUP
;
118 case kControlDownButtonPart
:
120 scrollEvent
= wxEVT_SCROLL_LINEDOWN
;
122 case kControlPageUpPart
:
123 nScrollInc
= -m_pageSize
;
124 scrollEvent
= wxEVT_SCROLL_PAGEUP
;
126 case kControlPageDownPart
:
127 nScrollInc
= m_pageSize
;
128 scrollEvent
= wxEVT_SCROLL_PAGEDOWN
;
130 case kControlIndicatorPart
:
132 if ( mouseStillDown
)
133 scrollEvent
= wxEVT_SCROLL_THUMBTRACK
;
135 scrollEvent
= wxEVT_SCROLL_THUMBRELEASE
;
138 wxFAIL_MSG(wxT("illegal scrollbar selector"));
142 int new_pos
= position
+ nScrollInc
;
144 if (new_pos
< minPos
)
146 if (new_pos
> maxPos
)
149 SetThumbPosition(new_pos
);
151 wxScrollEvent
event(scrollEvent
, m_windowId
);
152 if ( m_windowStyle
& wxHORIZONTAL
)
154 event
.SetOrientation( wxHORIZONTAL
) ;
158 event
.SetOrientation( wxVERTICAL
) ;
160 event
.SetPosition(new_pos
);
161 event
.SetEventObject( this );
162 wxWindow
* window
= GetParent() ;
163 if (window
&& window
->MacIsWindowScrollbar(this) )
166 window
->MacOnScroll(event
);
169 GetEventHandler()->ProcessEvent(event
);
172 wxInt32
wxScrollBar::MacControlHit( WXEVENTHANDLERREF handler
, WXEVENTREF mevent
)
174 int position
= m_peer
->GetValue() ;
175 int minPos
= m_peer
->GetMinimum() ;
176 int maxPos
= m_peer
->GetMaximum() ;
178 wxEventType scrollEvent
= wxEVT_NULL
;
181 wxMacCarbonEvent
cEvent( (EventRef
) mevent
) ;
182 ControlPartCode controlpart
= cEvent
.GetParameter
<ControlPartCode
>(kEventParamControlPart
,typeControlPartCode
) ;
184 // all events have already been reported during mouse down, except for THUMBRELEASE
185 if ( controlpart
!=kControlIndicatorPart
)
186 return eventNotHandledErr
;
188 switch( controlpart
)
190 case kControlIndicatorPart
:
192 scrollEvent
= wxEVT_SCROLL_THUMBRELEASE
;
195 wxFAIL_MSG(wxT("illegal scrollbar selector"));
199 int new_pos
= position
+ nScrollInc
;
201 if (new_pos
< minPos
)
203 if (new_pos
> maxPos
)
206 SetThumbPosition(new_pos
);
208 wxScrollEvent
event(scrollEvent
, m_windowId
);
209 if ( m_windowStyle
& wxHORIZONTAL
)
211 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) )
223 window
->MacOnScroll(event
);
226 GetEventHandler()->ProcessEvent(event
);