1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/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/osx/private.h"
24 class wxOSXScrollBarCarbonImpl
: public wxMacControl
27 wxOSXScrollBarCarbonImpl( wxWindowMac
* peer
) : wxMacControl( peer
)
31 void SetScrollThumb( wxInt32 value
, wxInt32 thumbSize
)
34 SetControlViewSize(m_controlRef
, thumbSize
);
39 wxWidgetImplType
* wxWidgetImpl::CreateScrollBar( wxWindowMac
* wxpeer
,
47 Rect bounds
= wxMacGetBoundsForControl( wxpeer
, pos
, size
);
49 wxMacControl
* peer
= new wxOSXScrollBarCarbonImpl( wxpeer
);
50 OSStatus err
= CreateScrollBarControl(
51 MAC_WXHWND(parent
->MacGetTopLevelWindowRef()), &bounds
,
52 0, 0, 100, 1, true /* liveTracking */,
53 GetwxMacLiveScrollbarActionProc(),
54 peer
->GetControlRefAddr() );
59 void wxScrollBar::MacHandleControlClick( WXWidget
WXUNUSED(control
), wxInt16 controlpart
, bool mouseStillDown
)
63 int position
= m_peer
->GetValue();
65 int maxPos
= m_peer
->GetMaximum();
67 wxEventType scrollEvent
= wxEVT_NULL
;
70 // all events have already been reported during mouse down, except for THUMBRELEASE
71 if ( !mouseStillDown
&& controlpart
!= kControlIndicatorPart
)
74 switch ( controlpart
)
76 case kControlUpButtonPart
:
78 scrollEvent
= wxEVT_SCROLL_LINEUP
;
81 case kControlDownButtonPart
:
83 scrollEvent
= wxEVT_SCROLL_LINEDOWN
;
86 case kControlPageUpPart
:
87 nScrollInc
= -m_pageSize
;
88 scrollEvent
= wxEVT_SCROLL_PAGEUP
;
91 case kControlPageDownPart
:
92 nScrollInc
= m_pageSize
;
93 scrollEvent
= wxEVT_SCROLL_PAGEDOWN
;
96 case kControlIndicatorPart
:
99 scrollEvent
= wxEVT_SCROLL_THUMBTRACK
;
101 scrollEvent
= wxEVT_SCROLL_THUMBRELEASE
;
105 wxFAIL_MSG(wxT("unknown scrollbar selector"));
109 int new_pos
= position
+ nScrollInc
;
111 if (new_pos
< minPos
)
113 else if (new_pos
> maxPos
)
117 SetThumbPosition( new_pos
);
119 wxScrollEvent
event( scrollEvent
, m_windowId
);
120 if ( m_windowStyle
& wxHORIZONTAL
)
121 event
.SetOrientation( wxHORIZONTAL
);
123 event
.SetOrientation( wxVERTICAL
);
125 event
.SetPosition( new_pos
);
126 event
.SetEventObject( this );
128 wxWindow
* window
= GetParent();
129 if (window
&& window
->MacIsWindowScrollbar( this ))
131 window
->MacOnScroll( event
);
133 HandleWindowEvent( event
);