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 IMPLEMENT_DYNAMIC_CLASS(wxScrollBar
, wxControl
)
28 BEGIN_EVENT_TABLE(wxScrollBar
, wxControl
)
32 bool wxScrollBar::Create(wxWindow
*parent
, wxWindowID id
,
34 const wxSize
& size
, long style
,
35 const wxValidator
& validator
,
38 m_macIsUserPane
= FALSE
;
40 if ( !wxControl::Create(parent
, id
, pos
, size
, style
, validator
, name
) )
43 Rect bounds
= wxMacGetBoundsForControl( this , pos
, size
) ;
45 m_peer
= new wxMacControl(this) ;
46 verify_noerr ( CreateScrollBarControl( MAC_WXHWND(parent
->MacGetTopLevelWindowRef()) , &bounds
,
47 0 , 0 , 100 , 1 , true /* liveTracking */ , GetwxMacLiveScrollbarActionProc() , m_peer
->GetControlRefAddr() ) );
50 MacPostControlCreate(pos
,size
) ;
55 wxScrollBar::~wxScrollBar()
59 void wxScrollBar::SetThumbPosition(int viewStart
)
61 m_peer
->SetValue( viewStart
) ;
64 int wxScrollBar::GetThumbPosition() const
66 return m_peer
->GetValue() ;
69 void wxScrollBar::SetScrollbar(int position
, int thumbSize
, int range
, int pageSize
,
72 m_pageSize
= pageSize
;
73 m_viewSize
= thumbSize
;
76 int range1
= wxMax((m_objectSize
- m_viewSize
), 0) ;
78 m_peer
->SetMaximum( range1
) ;
79 m_peer
->SetMinimum( 0 ) ;
80 m_peer
->SetValue( position
) ;
81 m_peer
->SetViewSize( m_viewSize
) ;
85 void wxScrollBar::Command(wxCommandEvent
& event
)
87 SetThumbPosition(event
.GetInt());
88 ProcessCommand(event
);
91 void wxScrollBar::MacHandleControlClick( WXWidget control
, wxInt16 controlpart
, bool mouseStillDown
)
93 int position
= m_peer
->GetValue() ;
94 int minPos
= m_peer
->GetMinimum() ;
95 int maxPos
= m_peer
->GetMaximum() ;
97 wxEventType scrollEvent
= wxEVT_NULL
;
100 // all events have already been reported during mouse down, except for THUMBRELEASE
101 if ( !mouseStillDown
&& controlpart
!=kControlIndicatorPart
)
104 switch( controlpart
)
106 case kControlUpButtonPart
:
108 scrollEvent
= wxEVT_SCROLL_LINEUP
;
110 case kControlDownButtonPart
:
112 scrollEvent
= wxEVT_SCROLL_LINEDOWN
;
114 case kControlPageUpPart
:
115 nScrollInc
= -m_pageSize
;
116 scrollEvent
= wxEVT_SCROLL_PAGEUP
;
118 case kControlPageDownPart
:
119 nScrollInc
= m_pageSize
;
120 scrollEvent
= wxEVT_SCROLL_PAGEDOWN
;
122 case kControlIndicatorPart
:
124 if ( mouseStillDown
)
125 scrollEvent
= wxEVT_SCROLL_THUMBTRACK
;
127 scrollEvent
= wxEVT_SCROLL_THUMBRELEASE
;
130 wxFAIL_MSG(wxT("illegal scrollbar selector"));
134 int new_pos
= position
+ nScrollInc
;
136 if (new_pos
< minPos
)
138 if (new_pos
> maxPos
)
141 SetThumbPosition(new_pos
);
143 wxScrollEvent
event(scrollEvent
, m_windowId
);
144 if ( m_windowStyle
& wxHORIZONTAL
)
146 event
.SetOrientation( wxHORIZONTAL
) ;
150 event
.SetOrientation( wxVERTICAL
) ;
152 event
.SetPosition(new_pos
);
153 event
.SetEventObject( this );
154 wxWindow
* window
= GetParent() ;
155 if (window
&& window
->MacIsWindowScrollbar(this) )
158 window
->MacOnScroll(event
);
161 GetEventHandler()->ProcessEvent(event
);
164 wxInt32
wxScrollBar::MacControlHit( WXEVENTHANDLERREF handler
, WXEVENTREF mevent
)
166 int position
= m_peer
->GetValue() ;
167 int minPos
= m_peer
->GetMinimum() ;
168 int maxPos
= m_peer
->GetMaximum() ;
170 wxEventType scrollEvent
= wxEVT_NULL
;
173 wxMacCarbonEvent
cEvent( (EventRef
) mevent
) ;
174 ControlPartCode controlpart
= cEvent
.GetParameter
<ControlPartCode
>(kEventParamControlPart
,typeControlPartCode
) ;
176 // all events have already been reported during mouse down, except for THUMBRELEASE
177 if ( controlpart
!=kControlIndicatorPart
)
178 return eventNotHandledErr
;
180 switch( controlpart
)
182 case kControlIndicatorPart
:
184 scrollEvent
= wxEVT_SCROLL_THUMBRELEASE
;
187 wxFAIL_MSG(wxT("illegal scrollbar selector"));
191 int new_pos
= position
+ nScrollInc
;
193 if (new_pos
< minPos
)
195 if (new_pos
> maxPos
)
198 SetThumbPosition(new_pos
);
200 wxScrollEvent
event(scrollEvent
, m_windowId
);
201 if ( m_windowStyle
& wxHORIZONTAL
)
203 event
.SetOrientation( wxHORIZONTAL
) ;
207 event
.SetOrientation( wxVERTICAL
) ;
209 event
.SetPosition(new_pos
);
210 event
.SetEventObject( this );
211 wxWindow
* window
= GetParent() ;
212 if (window
&& window
->MacIsWindowScrollbar(this) )
215 window
->MacOnScroll(event
);
218 GetEventHandler()->ProcessEvent(event
);