1 ///////////////////////////////////////////////////////////////////////////// 
   2 // Name:        src/mac/carbon/scrolbar.cpp 
   3 // Purpose:     wxScrollBar 
   4 // Author:      Stefan Csomor 
   8 // Copyright:   (c) Stefan Csomor 
   9 // Licence:       wxWindows licence 
  10 ///////////////////////////////////////////////////////////////////////////// 
  12 #include "wx/wxprec.h" 
  14 #include "wx/scrolbar.h" 
  19     #include "wx/settings.h" 
  22 #include "wx/mac/uma.h" 
  24 IMPLEMENT_DYNAMIC_CLASS(wxScrollBar
, wxControl
) 
  26 BEGIN_EVENT_TABLE(wxScrollBar
, wxControl
) 
  30 bool wxScrollBar::Create( wxWindow 
*parent
, 
  35     const wxValidator
& validator
, 
  36     const wxString
& name 
) 
  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     OSStatus err 
= CreateScrollBarControl( 
  47         MAC_WXHWND(parent
->MacGetTopLevelWindowRef()), &bounds
, 
  48         0, 0, 100, 1, true /* liveTracking */, 
  49         GetwxMacLiveScrollbarActionProc(), 
  50         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
, bool refresh 
) 
  74     m_pageSize 
= pageSize
; 
  75     m_viewSize 
= thumbSize
; 
  78    int range1 
= wxMax( (m_objectSize 
- m_viewSize
), 0 ); 
  80     m_peer
->SetMinimum( 0 ); 
  81     m_peer
->SetMaximum( range1 
); 
  82     m_peer
->SetValue( position 
); 
  83     m_peer
->SetViewSize( m_viewSize 
); 
  86 void wxScrollBar::Command( wxCommandEvent
& event 
) 
  88     SetThumbPosition( event
.GetInt() ); 
  89     ProcessCommand( event 
); 
  92 void wxScrollBar::MacHandleControlClick( WXWidget control
, wxInt16 controlpart
, bool mouseStillDown 
) 
  94     int position 
= m_peer
->GetValue(); 
  95     int minPos 
= m_peer
->GetMinimum(); 
  96     int maxPos 
= m_peer
->GetMaximum(); 
  98     wxEventType scrollEvent 
= wxEVT_NULL
; 
 101     // all events have already been reported during mouse down, except for THUMBRELEASE 
 102     if ( !mouseStillDown 
&& controlpart 
!= kControlIndicatorPart 
) 
 105     switch ( controlpart 
) 
 107     case kControlUpButtonPart
: 
 109         scrollEvent 
= wxEVT_SCROLL_LINEUP
; 
 112     case kControlDownButtonPart
: 
 114         scrollEvent 
= wxEVT_SCROLL_LINEDOWN
; 
 117     case kControlPageUpPart
: 
 118         nScrollInc 
= -m_pageSize
; 
 119         scrollEvent 
= wxEVT_SCROLL_PAGEUP
; 
 122     case kControlPageDownPart
: 
 123         nScrollInc 
= m_pageSize
; 
 124         scrollEvent 
= wxEVT_SCROLL_PAGEDOWN
; 
 127     case kControlIndicatorPart
: 
 129         if ( mouseStillDown 
) 
 130             scrollEvent 
= wxEVT_SCROLL_THUMBTRACK
; 
 132             scrollEvent 
= wxEVT_SCROLL_THUMBRELEASE
; 
 136         wxFAIL_MSG(wxT("unknown scrollbar selector")); 
 140     int new_pos 
= position 
+ nScrollInc
; 
 142     if (new_pos 
< minPos
) 
 144     else if (new_pos 
> maxPos
) 
 148         SetThumbPosition( new_pos 
); 
 150     wxScrollEvent 
event( scrollEvent
, m_windowId 
); 
 151     if ( m_windowStyle 
& wxHORIZONTAL 
) 
 152         event
.SetOrientation( wxHORIZONTAL 
); 
 154         event
.SetOrientation( wxVERTICAL 
); 
 156     event
.SetPosition( new_pos 
); 
 157     event
.SetEventObject( this ); 
 159     wxWindow
* window 
= GetParent(); 
 160     if (window 
&& window
->MacIsWindowScrollbar( this )) 
 162         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     // NB: this may need to be reviewed in light of the fact that scroll wheel events 
 181     // aren't being handled properly 
 182     if ( controlpart 
!= kControlIndicatorPart 
) 
 183         return eventNotHandledErr
; 
 185     switch ( controlpart 
) 
 187     case kControlIndicatorPart
: 
 189         scrollEvent 
= wxEVT_SCROLL_THUMBRELEASE
; 
 193         wxFAIL_MSG(wxT("unknown scrollbar selector")); 
 197     int new_pos 
= position 
+ nScrollInc
; 
 199     if (new_pos 
< minPos
) 
 201     else if (new_pos 
> maxPos
) 
 205         SetThumbPosition( new_pos 
); 
 207     wxScrollEvent 
event( scrollEvent
, m_windowId 
); 
 208     if ( m_windowStyle 
& wxHORIZONTAL 
) 
 209         event
.SetOrientation( wxHORIZONTAL 
); 
 211         event
.SetOrientation( wxVERTICAL 
); 
 213     event
.SetPosition( new_pos 
); 
 214     event
.SetEventObject( this ); 
 215     wxWindow
* window 
= GetParent(); 
 216     if (window 
&& window
->MacIsWindowScrollbar( this )) 
 218         window
->MacOnScroll( event 
); 
 220         GetEventHandler()->ProcessEvent( event 
); 
 226 wxSize 
wxScrollBar::DoGetBestSize() const 
 233         w 
= wxSystemSettings::GetMetric(wxSYS_VSCROLL_X
); 
 237         h 
= wxSystemSettings::GetMetric(wxSYS_HSCROLL_Y
);