1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxScrollBar
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
19 #include "wx/scrolbar.h"
20 #include "wx/mac/uma.h"
22 IMPLEMENT_DYNAMIC_CLASS(wxScrollBar
, wxControl
)
24 BEGIN_EVENT_TABLE(wxScrollBar
, wxControl
)
27 extern ControlActionUPP wxMacLiveScrollbarActionUPP
;
30 bool wxScrollBar::Create(wxWindow
*parent
, wxWindowID id
,
32 const wxSize
& size
, long style
,
33 const wxValidator
& validator
,
36 if ( !wxControl::Create(parent
, id
, pos
, size
, style
, validator
, name
) )
42 MacPreControlCreate( parent
, id
, wxEmptyString
, pos
, size
,style
, validator
, name
, &bounds
, title
) ;
44 m_macControl
= (WXWidget
) ::NewControl(MAC_WXHWND(parent
->MacGetRootWindow()) ,
45 &bounds
, title
, false , 0 , 0 , 100,
46 kControlScrollBarLiveProc
, (long) this) ;
48 wxASSERT_MSG( (ControlHandle
) m_macControl
!= NULL
, wxT("No valid mac control") ) ;
50 ::SetControlAction( (ControlHandle
) m_macControl
, wxMacLiveScrollbarActionUPP
) ;
52 MacPostControlCreate() ;
57 wxScrollBar::~wxScrollBar()
61 void wxScrollBar::SetThumbPosition(int viewStart
)
63 ::SetControl32BitValue( (ControlHandle
) m_macControl
, viewStart
) ;
66 int wxScrollBar::GetThumbPosition() const
68 return ::GetControl32BitValue( (ControlHandle
) m_macControl
) ;
71 void wxScrollBar::SetScrollbar(int position
, int thumbSize
, int range
, int pageSize
,
74 m_pageSize
= pageSize
;
75 m_viewSize
= thumbSize
;
78 int range1
= wxMax((m_objectSize
- m_viewSize
), 0) ;
80 SetControl32BitMaximum( (ControlHandle
) m_macControl
, range1
) ;
81 SetControl32BitMinimum( (ControlHandle
) m_macControl
, 0 ) ;
82 SetControl32BitValue( (ControlHandle
) m_macControl
, position
) ;
84 if ( UMAGetAppearanceVersion() >= 0x0110 )
86 if ( SetControlViewSize
!= (void*) kUnresolvedCFragSymbolAddress
)
88 SetControlViewSize( (ControlHandle
) m_macControl
, m_viewSize
) ;
96 void wxScrollBar::Command(wxCommandEvent
& event
)
98 SetThumbPosition(event
.GetInt());
99 ProcessCommand(event
);
102 void wxScrollBar::MacHandleControlClick( WXWidget control
, wxInt16 controlpart
, bool mouseStillDown
)
104 if ( (ControlHandle
) m_macControl
== NULL
)
107 int position
= GetControl32BitValue( (ControlHandle
) m_macControl
) ;
108 int minPos
= GetControl32BitMinimum( (ControlHandle
) m_macControl
) ;
109 int maxPos
= GetControl32BitMaximum( (ControlHandle
) m_macControl
) ;
111 wxEventType scrollEvent
= wxEVT_NULL
;
114 // all events have already been reported during mouse down, except for THUMBRELEASE
115 if ( !mouseStillDown
&& controlpart
!=kControlIndicatorPart
)
118 switch( controlpart
)
120 case kControlUpButtonPart
:
122 scrollEvent
= wxEVT_SCROLL_LINEUP
;
124 case kControlDownButtonPart
:
126 scrollEvent
= wxEVT_SCROLL_LINEDOWN
;
128 case kControlPageUpPart
:
129 nScrollInc
= -m_pageSize
;
130 scrollEvent
= wxEVT_SCROLL_PAGEUP
;
132 case kControlPageDownPart
:
133 nScrollInc
= m_pageSize
;
134 scrollEvent
= wxEVT_SCROLL_PAGEDOWN
;
136 case kControlIndicatorPart
:
138 if ( mouseStillDown
)
139 scrollEvent
= wxEVT_SCROLL_THUMBTRACK
;
141 scrollEvent
= wxEVT_SCROLL_THUMBRELEASE
;
144 wxFAIL_MSG(wxT("illegal scrollbar selector"));
148 int new_pos
= position
+ nScrollInc
;
150 if (new_pos
< minPos
)
152 if (new_pos
> maxPos
)
155 SetThumbPosition(new_pos
);
157 wxScrollEvent
event(scrollEvent
, m_windowId
);
158 if ( m_windowStyle
& wxHORIZONTAL
)
160 event
.SetOrientation( wxHORIZONTAL
) ;
164 event
.SetOrientation( wxVERTICAL
) ;
166 event
.SetPosition(new_pos
);
167 event
.SetEventObject( this );
168 wxWindow
* window
= GetParent() ;
169 if (window
&& window
->MacIsWindowScrollbar(this) )
172 window
->MacOnScroll(event
);
175 GetEventHandler()->ProcessEvent(event
);