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
)
35 bool wxScrollBar::Create(wxWindow
*parent
, wxWindowID id
,
37 const wxSize
& size
, long style
,
38 const wxValidator
& validator
,
41 m_macIsUserPane
= FALSE
;
43 if ( !wxControl::Create(parent
, id
, pos
, size
, style
, validator
, name
) )
46 Rect bounds
= wxMacGetBoundsForControl( this , pos
, size
) ;
48 m_peer
= new wxMacControl(this) ;
49 verify_noerr ( CreateScrollBarControl( MAC_WXHWND(parent
->MacGetTopLevelWindowRef()) , &bounds
,
50 0 , 0 , 100 , 1 , true /* liveTracking */ , GetwxMacLiveScrollbarActionProc() , m_peer
->GetControlRefAddr() ) );
53 MacPostControlCreate(pos
,size
) ;
58 wxScrollBar::~wxScrollBar()
62 void wxScrollBar::SetThumbPosition(int viewStart
)
64 m_peer
->SetValue( viewStart
) ;
67 int wxScrollBar::GetThumbPosition() const
69 return m_peer
->GetValue() ;
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 m_peer
->SetMaximum( range1
) ;
82 m_peer
->SetMinimum( 0 ) ;
83 m_peer
->SetValue( position
) ;
84 m_peer
->SetViewSize( m_viewSize
) ;
88 void wxScrollBar::Command(wxCommandEvent
& event
)
90 SetThumbPosition(event
.GetInt());
91 ProcessCommand(event
);
94 void wxScrollBar::MacHandleControlClick( WXWidget control
, wxInt16 controlpart
, bool mouseStillDown
)
96 int position
= m_peer
->GetValue() ;
97 int minPos
= m_peer
->GetMinimum() ;
98 int maxPos
= m_peer
->GetMaximum() ;
100 wxEventType scrollEvent
= wxEVT_NULL
;
103 // all events have already been reported during mouse down, except for THUMBRELEASE
104 if ( !mouseStillDown
&& controlpart
!=kControlIndicatorPart
)
107 switch( controlpart
)
109 case kControlUpButtonPart
:
111 scrollEvent
= wxEVT_SCROLL_LINEUP
;
113 case kControlDownButtonPart
:
115 scrollEvent
= wxEVT_SCROLL_LINEDOWN
;
117 case kControlPageUpPart
:
118 nScrollInc
= -m_pageSize
;
119 scrollEvent
= wxEVT_SCROLL_PAGEUP
;
121 case kControlPageDownPart
:
122 nScrollInc
= m_pageSize
;
123 scrollEvent
= wxEVT_SCROLL_PAGEDOWN
;
125 case kControlIndicatorPart
:
127 if ( mouseStillDown
)
128 scrollEvent
= wxEVT_SCROLL_THUMBTRACK
;
130 scrollEvent
= wxEVT_SCROLL_THUMBRELEASE
;
133 wxFAIL_MSG(wxT("illegal scrollbar selector"));
137 int new_pos
= position
+ nScrollInc
;
139 if (new_pos
< minPos
)
141 if (new_pos
> maxPos
)
144 SetThumbPosition(new_pos
);
146 wxScrollEvent
event(scrollEvent
, m_windowId
);
147 if ( m_windowStyle
& wxHORIZONTAL
)
149 event
.SetOrientation( wxHORIZONTAL
) ;
153 event
.SetOrientation( wxVERTICAL
) ;
155 event
.SetPosition(new_pos
);
156 event
.SetEventObject( this );
157 wxWindow
* window
= GetParent() ;
158 if (window
&& window
->MacIsWindowScrollbar(this) )
161 window
->MacOnScroll(event
);
164 GetEventHandler()->ProcessEvent(event
);
167 wxInt32
wxScrollBar::MacControlHit( WXEVENTHANDLERREF handler
, WXEVENTREF mevent
)
169 int position
= m_peer
->GetValue() ;
170 int minPos
= m_peer
->GetMinimum() ;
171 int maxPos
= m_peer
->GetMaximum() ;
173 wxEventType scrollEvent
= wxEVT_NULL
;
176 wxMacCarbonEvent
cEvent( (EventRef
) mevent
) ;
177 ControlPartCode controlpart
= cEvent
.GetParameter
<ControlPartCode
>(kEventParamControlPart
,typeControlPartCode
) ;
179 // all events have already been reported during mouse down, except for THUMBRELEASE
180 if ( controlpart
!=kControlIndicatorPart
)
181 return eventNotHandledErr
;
183 switch( controlpart
)
185 case kControlIndicatorPart
:
187 scrollEvent
= wxEVT_SCROLL_THUMBRELEASE
;
190 wxFAIL_MSG(wxT("illegal scrollbar selector"));
194 int new_pos
= position
+ nScrollInc
;
196 if (new_pos
< minPos
)
198 if (new_pos
> maxPos
)
201 SetThumbPosition(new_pos
);
203 wxScrollEvent
event(scrollEvent
, m_windowId
);
204 if ( m_windowStyle
& wxHORIZONTAL
)
206 event
.SetOrientation( wxHORIZONTAL
) ;
210 event
.SetOrientation( wxVERTICAL
) ;
212 event
.SetPosition(new_pos
);
213 event
.SetEventObject( this );
214 wxWindow
* window
= GetParent() ;
215 if (window
&& window
->MacIsWindowScrollbar(this) )
218 window
->MacOnScroll(event
);
221 GetEventHandler()->ProcessEvent(event
);