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
, wxWindowID id
,
30 const wxSize
& size
, long style
,
31 const wxValidator
& validator
,
34 m_macIsUserPane
= FALSE
;
36 if ( !wxControl::Create(parent
, id
, pos
, size
, style
, validator
, name
) )
39 Rect bounds
= wxMacGetBoundsForControl( this , pos
, size
) ;
41 m_peer
= new wxMacControl(this) ;
42 verify_noerr ( CreateScrollBarControl( MAC_WXHWND(parent
->MacGetTopLevelWindowRef()) , &bounds
,
43 0 , 0 , 100 , 1 , true /* liveTracking */ , GetwxMacLiveScrollbarActionProc() , m_peer
->GetControlRefAddr() ) );
46 MacPostControlCreate(pos
,size
) ;
51 wxScrollBar::~wxScrollBar()
55 void wxScrollBar::SetThumbPosition(int viewStart
)
57 m_peer
->SetValue( viewStart
) ;
60 int wxScrollBar::GetThumbPosition() const
62 return m_peer
->GetValue() ;
65 void wxScrollBar::SetScrollbar(int position
, int thumbSize
, int range
, int pageSize
,
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
) ;
81 void wxScrollBar::Command(wxCommandEvent
& event
)
83 SetThumbPosition(event
.GetInt());
84 ProcessCommand(event
);
87 void wxScrollBar::MacHandleControlClick( WXWidget control
, wxInt16 controlpart
, bool mouseStillDown
)
89 int position
= m_peer
->GetValue() ;
90 int minPos
= m_peer
->GetMinimum() ;
91 int maxPos
= m_peer
->GetMaximum() ;
93 wxEventType scrollEvent
= wxEVT_NULL
;
96 // all events have already been reported during mouse down, except for THUMBRELEASE
97 if ( !mouseStillDown
&& controlpart
!=kControlIndicatorPart
)
100 switch( controlpart
)
102 case kControlUpButtonPart
:
104 scrollEvent
= wxEVT_SCROLL_LINEUP
;
106 case kControlDownButtonPart
:
108 scrollEvent
= wxEVT_SCROLL_LINEDOWN
;
110 case kControlPageUpPart
:
111 nScrollInc
= -m_pageSize
;
112 scrollEvent
= wxEVT_SCROLL_PAGEUP
;
114 case kControlPageDownPart
:
115 nScrollInc
= m_pageSize
;
116 scrollEvent
= wxEVT_SCROLL_PAGEDOWN
;
118 case kControlIndicatorPart
:
120 if ( mouseStillDown
)
121 scrollEvent
= wxEVT_SCROLL_THUMBTRACK
;
123 scrollEvent
= wxEVT_SCROLL_THUMBRELEASE
;
126 wxFAIL_MSG(wxT("illegal scrollbar selector"));
130 int new_pos
= position
+ nScrollInc
;
132 if (new_pos
< minPos
)
134 if (new_pos
> maxPos
)
137 SetThumbPosition(new_pos
);
139 wxScrollEvent
event(scrollEvent
, m_windowId
);
140 if ( m_windowStyle
& wxHORIZONTAL
)
142 event
.SetOrientation( wxHORIZONTAL
) ;
146 event
.SetOrientation( wxVERTICAL
) ;
148 event
.SetPosition(new_pos
);
149 event
.SetEventObject( this );
150 wxWindow
* window
= GetParent() ;
151 if (window
&& window
->MacIsWindowScrollbar(this) )
154 window
->MacOnScroll(event
);
157 GetEventHandler()->ProcessEvent(event
);
160 wxInt32
wxScrollBar::MacControlHit( WXEVENTHANDLERREF handler
, WXEVENTREF mevent
)
162 int position
= m_peer
->GetValue() ;
163 int minPos
= m_peer
->GetMinimum() ;
164 int maxPos
= m_peer
->GetMaximum() ;
166 wxEventType scrollEvent
= wxEVT_NULL
;
169 wxMacCarbonEvent
cEvent( (EventRef
) mevent
) ;
170 ControlPartCode controlpart
= cEvent
.GetParameter
<ControlPartCode
>(kEventParamControlPart
,typeControlPartCode
) ;
172 // all events have already been reported during mouse down, except for THUMBRELEASE
173 if ( controlpart
!=kControlIndicatorPart
)
174 return eventNotHandledErr
;
176 switch( controlpart
)
178 case kControlIndicatorPart
:
180 scrollEvent
= wxEVT_SCROLL_THUMBRELEASE
;
183 wxFAIL_MSG(wxT("illegal scrollbar selector"));
187 int new_pos
= position
+ nScrollInc
;
189 if (new_pos
< minPos
)
191 if (new_pos
> maxPos
)
194 SetThumbPosition(new_pos
);
196 wxScrollEvent
event(scrollEvent
, m_windowId
);
197 if ( m_windowStyle
& wxHORIZONTAL
)
199 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) )
211 window
->MacOnScroll(event
);
214 GetEventHandler()->ProcessEvent(event
);