1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxScrollBar
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
13 #pragma implementation "scrolbar.h"
16 #include "wx/wxprec.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(this) ;
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
) ;
90 void wxScrollBar::Command(wxCommandEvent
& event
)
92 SetThumbPosition(event
.GetInt());
93 ProcessCommand(event
);
96 void wxScrollBar::MacHandleControlClick( WXWidget 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
;
115 case kControlDownButtonPart
:
117 scrollEvent
= wxEVT_SCROLL_LINEDOWN
;
119 case kControlPageUpPart
:
120 nScrollInc
= -m_pageSize
;
121 scrollEvent
= wxEVT_SCROLL_PAGEUP
;
123 case kControlPageDownPart
:
124 nScrollInc
= m_pageSize
;
125 scrollEvent
= wxEVT_SCROLL_PAGEDOWN
;
127 case kControlIndicatorPart
:
129 if ( mouseStillDown
)
130 scrollEvent
= wxEVT_SCROLL_THUMBTRACK
;
132 scrollEvent
= wxEVT_SCROLL_THUMBRELEASE
;
135 wxFAIL_MSG(wxT("illegal scrollbar selector"));
139 int new_pos
= position
+ nScrollInc
;
141 if (new_pos
< minPos
)
143 if (new_pos
> maxPos
)
146 SetThumbPosition(new_pos
);
148 wxScrollEvent
event(scrollEvent
, m_windowId
);
149 if ( m_windowStyle
& wxHORIZONTAL
)
151 event
.SetOrientation( wxHORIZONTAL
) ;
155 event
.SetOrientation( wxVERTICAL
) ;
157 event
.SetPosition(new_pos
);
158 event
.SetEventObject( this );
159 wxWindow
* window
= GetParent() ;
160 if (window
&& window
->MacIsWindowScrollbar(this) )
163 window
->MacOnScroll(event
);
166 GetEventHandler()->ProcessEvent(event
);
169 wxInt32
wxScrollBar::MacControlHit( WXEVENTHANDLERREF handler
, WXEVENTREF mevent
)
171 int position
= m_peer
->GetValue() ;
172 int minPos
= m_peer
->GetMinimum() ;
173 int maxPos
= m_peer
->GetMaximum() ;
175 wxEventType scrollEvent
= wxEVT_NULL
;
178 wxMacCarbonEvent
cEvent( (EventRef
) mevent
) ;
179 ControlPartCode controlpart
= cEvent
.GetParameter
<ControlPartCode
>(kEventParamControlPart
,typeControlPartCode
) ;
181 // all events have already been reported during mouse down, except for THUMBRELEASE
182 if ( controlpart
!=kControlIndicatorPart
)
183 return eventNotHandledErr
;
185 switch( controlpart
)
187 case kControlIndicatorPart
:
189 scrollEvent
= wxEVT_SCROLL_THUMBRELEASE
;
192 wxFAIL_MSG(wxT("illegal scrollbar selector"));
196 int new_pos
= position
+ nScrollInc
;
198 if (new_pos
< minPos
)
200 if (new_pos
> maxPos
)
203 SetThumbPosition(new_pos
);
205 wxScrollEvent
event(scrollEvent
, m_windowId
);
206 if ( m_windowStyle
& wxHORIZONTAL
)
208 event
.SetOrientation( wxHORIZONTAL
) ;
212 event
.SetOrientation( wxVERTICAL
) ;
214 event
.SetPosition(new_pos
);
215 event
.SetEventObject( this );
216 wxWindow
* window
= GetParent() ;
217 if (window
&& window
->MacIsWindowScrollbar(this) )
220 window
->MacOnScroll(event
);
223 GetEventHandler()->ProcessEvent(event
);