1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/mac/classic/scrolbar.cpp
3 // Purpose: wxScrollBar
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #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
)
31 extern ControlActionUPP wxMacLiveScrollbarActionUPP
;
34 bool wxScrollBar::Create(wxWindow
*parent
, wxWindowID id
,
36 const wxSize
& size
, long style
,
37 const wxValidator
& validator
,
40 if ( !wxControl::Create(parent
, id
, pos
, size
, style
, validator
, name
) )
46 MacPreControlCreate( parent
, id
, wxEmptyString
, pos
, size
,style
, validator
, name
, &bounds
, title
) ;
48 m_macControl
= (WXWidget
) ::NewControl(MAC_WXHWND(parent
->MacGetRootWindow()) ,
49 &bounds
, title
, false , 0 , 0 , 100,
50 kControlScrollBarLiveProc
, (long) this) ;
52 wxASSERT_MSG( (ControlHandle
) m_macControl
!= NULL
, wxT("No valid mac control") ) ;
54 ::SetControlAction( (ControlHandle
) m_macControl
, wxMacLiveScrollbarActionUPP
) ;
56 MacPostControlCreate() ;
61 wxScrollBar::~wxScrollBar()
65 void wxScrollBar::SetThumbPosition(int viewStart
)
67 ::SetControl32BitValue( (ControlHandle
) m_macControl
, viewStart
) ;
70 int wxScrollBar::GetThumbPosition() const
72 return ::GetControl32BitValue( (ControlHandle
) m_macControl
) ;
75 void wxScrollBar::SetScrollbar(int position
, int thumbSize
, int range
, int pageSize
,
78 m_pageSize
= pageSize
;
79 m_viewSize
= thumbSize
;
82 int range1
= wxMax((m_objectSize
- m_viewSize
), 0) ;
84 SetControl32BitMaximum( (ControlHandle
) m_macControl
, range1
) ;
85 SetControl32BitMinimum( (ControlHandle
) m_macControl
, 0 ) ;
86 SetControl32BitValue( (ControlHandle
) m_macControl
, position
) ;
88 if ( UMAGetAppearanceVersion() >= 0x0110 )
90 if ( SetControlViewSize
!= (void*) kUnresolvedCFragSymbolAddress
)
92 SetControlViewSize( (ControlHandle
) m_macControl
, m_viewSize
) ;
100 void wxScrollBar::Command(wxCommandEvent
& event
)
102 SetThumbPosition(event
.GetInt());
103 ProcessCommand(event
);
106 void wxScrollBar::MacHandleControlClick( WXWidget control
, wxInt16 controlpart
, bool mouseStillDown
)
108 if ( (ControlHandle
) m_macControl
== NULL
)
111 int position
= GetControl32BitValue( (ControlHandle
) m_macControl
) ;
112 int minPos
= GetControl32BitMinimum( (ControlHandle
) m_macControl
) ;
113 int maxPos
= GetControl32BitMaximum( (ControlHandle
) m_macControl
) ;
115 wxEventType scrollEvent
= wxEVT_NULL
;
118 // all events have already been reported during mouse down, except for THUMBRELEASE
119 if ( !mouseStillDown
&& controlpart
!=kControlIndicatorPart
)
122 switch( controlpart
)
124 case kControlUpButtonPart
:
126 scrollEvent
= wxEVT_SCROLL_LINEUP
;
128 case kControlDownButtonPart
:
130 scrollEvent
= wxEVT_SCROLL_LINEDOWN
;
132 case kControlPageUpPart
:
133 nScrollInc
= -m_pageSize
;
134 scrollEvent
= wxEVT_SCROLL_PAGEUP
;
136 case kControlPageDownPart
:
137 nScrollInc
= m_pageSize
;
138 scrollEvent
= wxEVT_SCROLL_PAGEDOWN
;
140 case kControlIndicatorPart
:
142 if ( mouseStillDown
)
143 scrollEvent
= wxEVT_SCROLL_THUMBTRACK
;
145 scrollEvent
= wxEVT_SCROLL_THUMBRELEASE
;
148 wxFAIL_MSG(wxT("illegal scrollbar selector"));
152 int new_pos
= position
+ nScrollInc
;
154 if (new_pos
< minPos
)
156 if (new_pos
> maxPos
)
159 SetThumbPosition(new_pos
);
161 wxScrollEvent
event(scrollEvent
, m_windowId
);
162 if ( m_windowStyle
& wxHORIZONTAL
)
164 event
.SetOrientation( wxHORIZONTAL
) ;
168 event
.SetOrientation( wxVERTICAL
) ;
170 event
.SetPosition(new_pos
);
171 event
.SetEventObject( this );
172 wxWindow
* window
= GetParent() ;
173 if (window
&& window
->MacIsWindowScrollbar(this) )
176 window
->MacOnScroll(event
);
179 GetEventHandler()->ProcessEvent(event
);