1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxScrollBar
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "scrolbar.h"
23 #include "wx/scrolbar.h"
24 #include "wx/mac/uma.h"
26 #if !USE_SHARED_LIBRARY
27 IMPLEMENT_DYNAMIC_CLASS(wxScrollBar
, wxControl
)
29 BEGIN_EVENT_TABLE(wxScrollBar
, wxControl
)
34 extern ControlActionUPP wxMacLiveScrollbarActionUPP
;
37 bool wxScrollBar::Create(wxWindow
*parent
, wxWindowID id
,
39 const wxSize
& size
, long style
,
40 const wxValidator
& validator
,
49 MacPreControlCreate( parent
, id
, wxEmptyString
, pos
, size
,style
, validator
, name
, &bounds
, title
) ;
51 m_macControl
= ::NewControl( MAC_WXHWND(parent
->MacGetRootWindow()) , &bounds
, title
, true , 0 , 0 , 100,
52 kControlScrollBarLiveProc
, (long) this ) ;
54 wxASSERT_MSG( (ControlHandle
) m_macControl
!= NULL
, wxT("No valid mac control") ) ;
56 ::SetControlAction( (ControlHandle
) m_macControl
, wxMacLiveScrollbarActionUPP
) ;
58 MacPostControlCreate() ;
63 wxScrollBar::~wxScrollBar()
67 void wxScrollBar::SetThumbPosition(int viewStart
)
69 ::SetControl32BitValue( (ControlHandle
) m_macControl
, viewStart
) ;
72 int wxScrollBar::GetThumbPosition() const
74 return ::GetControl32BitValue( (ControlHandle
) m_macControl
) ;
77 void wxScrollBar::SetScrollbar(int position
, int thumbSize
, int range
, int pageSize
,
80 m_pageSize
= pageSize
;
81 m_viewSize
= thumbSize
;
84 int range1
= wxMax((m_objectSize
- m_viewSize
), 0) ;
86 SetControl32BitMaximum( (ControlHandle
) m_macControl
, range1
) ;
87 SetControl32BitMinimum( (ControlHandle
) m_macControl
, 0 ) ;
88 SetControl32BitValue( (ControlHandle
) m_macControl
, position
) ;
90 if ( UMAGetAppearanceVersion() >= 0x0110 )
92 if ( SetControlViewSize
!= (void*) kUnresolvedCFragSymbolAddress
)
94 SetControlViewSize( (ControlHandle
) m_macControl
, m_viewSize
) ;
102 void wxScrollBar::Command(wxCommandEvent
& event
)
104 SetThumbPosition(event
.m_commandInt
);
105 ProcessCommand(event
);
108 void wxScrollBar::MacHandleControlClick( WXWidget control
, wxInt16 controlpart
, bool mouseStillDown
)
110 if ( (ControlHandle
) m_macControl
== NULL
)
113 int position
= GetControl32BitValue( (ControlHandle
) m_macControl
) ;
114 int minPos
= GetControl32BitMinimum( (ControlHandle
) m_macControl
) ;
115 int maxPos
= GetControl32BitMaximum( (ControlHandle
) m_macControl
) ;
117 wxEventType scrollEvent
= wxEVT_NULL
;
120 // all events have already been reported during mouse down, except for THUMBRELEASE
121 if ( !mouseStillDown
&& controlpart
!=kControlIndicatorPart
)
124 switch( controlpart
)
126 case kControlUpButtonPart
:
128 scrollEvent
= wxEVT_SCROLL_LINEUP
;
130 case kControlDownButtonPart
:
132 scrollEvent
= wxEVT_SCROLL_LINEDOWN
;
134 case kControlPageUpPart
:
135 nScrollInc
= -m_pageSize
;
136 scrollEvent
= wxEVT_SCROLL_PAGEUP
;
138 case kControlPageDownPart
:
139 nScrollInc
= m_pageSize
;
140 scrollEvent
= wxEVT_SCROLL_PAGEDOWN
;
142 case kControlIndicatorPart
:
144 if ( mouseStillDown
)
145 scrollEvent
= wxEVT_SCROLL_THUMBTRACK
;
147 scrollEvent
= wxEVT_SCROLL_THUMBRELEASE
;
150 wxFAIL_MSG(wxT("illegal scrollbar selector"));
154 int new_pos
= position
+ nScrollInc
;
156 if (new_pos
< minPos
)
158 if (new_pos
> maxPos
)
161 SetThumbPosition(new_pos
);
163 wxScrollEvent
event(scrollEvent
, m_windowId
);
164 if ( m_windowStyle
& wxHORIZONTAL
)
166 event
.SetOrientation( wxHORIZONTAL
) ;
170 event
.SetOrientation( wxVERTICAL
) ;
172 event
.SetPosition(new_pos
);
173 event
.SetEventObject( this );
174 wxWindow
* window
= GetParent() ;
175 if (window
&& window
->MacIsWindowScrollbar(this) )
178 window
->MacOnScroll(event
);
181 GetEventHandler()->ProcessEvent(event
);