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
,
43 m_macIsUserPane
= FALSE
;
45 if ( !wxControl::Create(parent
, id
, pos
, size
, style
, validator
, name
) )
48 Rect bounds
= wxMacGetBoundsForControl( this , pos
, size
) ;
49 m_macControl
= (WXWidget
) ::NewControl(MAC_WXHWND(parent
->MacGetTopLevelWindowRef()) ,
50 &bounds
, "\p" , true , 0 , 0 , 100,
51 kControlScrollBarLiveProc
, (long) this) ;
53 wxASSERT_MSG( (ControlRef
) m_macControl
!= NULL
, wxT("No valid mac control") ) ;
55 ::SetControlAction( (ControlRef
) m_macControl
, wxMacLiveScrollbarActionUPP
) ;
57 MacPostControlCreate(pos
,size
) ;
62 wxScrollBar::~wxScrollBar()
66 void wxScrollBar::SetThumbPosition(int viewStart
)
68 ::SetControl32BitValue( (ControlRef
) m_macControl
, viewStart
) ;
71 int wxScrollBar::GetThumbPosition() const
73 return ::GetControl32BitValue( (ControlRef
) m_macControl
) ;
76 void wxScrollBar::SetScrollbar(int position
, int thumbSize
, int range
, int pageSize
,
79 m_pageSize
= pageSize
;
80 m_viewSize
= thumbSize
;
83 int range1
= wxMax((m_objectSize
- m_viewSize
), 0) ;
85 SetControl32BitMaximum( (ControlRef
) m_macControl
, range1
) ;
86 SetControl32BitMinimum( (ControlRef
) m_macControl
, 0 ) ;
87 SetControl32BitValue( (ControlRef
) m_macControl
, position
) ;
89 if ( UMAGetAppearanceVersion() >= 0x0110 )
91 if ( SetControlViewSize
!= (void*) kUnresolvedCFragSymbolAddress
)
93 SetControlViewSize( (ControlRef
) m_macControl
, m_viewSize
) ;
101 void wxScrollBar::Command(wxCommandEvent
& event
)
103 SetThumbPosition(event
.m_commandInt
);
104 ProcessCommand(event
);
107 void wxScrollBar::MacHandleControlClick( WXWidget control
, wxInt16 controlpart
, bool mouseStillDown
)
109 if ( (ControlRef
) m_macControl
== NULL
)
112 int position
= GetControl32BitValue( (ControlRef
) m_macControl
) ;
113 int minPos
= GetControl32BitMinimum( (ControlRef
) m_macControl
) ;
114 int maxPos
= GetControl32BitMaximum( (ControlRef
) m_macControl
) ;
116 wxEventType scrollEvent
= wxEVT_NULL
;
119 // all events have already been reported during mouse down, except for THUMBRELEASE
120 if ( !mouseStillDown
&& controlpart
!=kControlIndicatorPart
)
123 switch( controlpart
)
125 case kControlUpButtonPart
:
127 scrollEvent
= wxEVT_SCROLL_LINEUP
;
129 case kControlDownButtonPart
:
131 scrollEvent
= wxEVT_SCROLL_LINEDOWN
;
133 case kControlPageUpPart
:
134 nScrollInc
= -m_pageSize
;
135 scrollEvent
= wxEVT_SCROLL_PAGEUP
;
137 case kControlPageDownPart
:
138 nScrollInc
= m_pageSize
;
139 scrollEvent
= wxEVT_SCROLL_PAGEDOWN
;
141 case kControlIndicatorPart
:
143 if ( mouseStillDown
)
144 scrollEvent
= wxEVT_SCROLL_THUMBTRACK
;
146 scrollEvent
= wxEVT_SCROLL_THUMBRELEASE
;
149 wxFAIL_MSG(wxT("illegal scrollbar selector"));
153 int new_pos
= position
+ nScrollInc
;
155 if (new_pos
< minPos
)
157 if (new_pos
> maxPos
)
160 SetThumbPosition(new_pos
);
162 wxScrollEvent
event(scrollEvent
, m_windowId
);
163 if ( m_windowStyle
& wxHORIZONTAL
)
165 event
.SetOrientation( wxHORIZONTAL
) ;
169 event
.SetOrientation( wxVERTICAL
) ;
171 event
.SetPosition(new_pos
);
172 event
.SetEventObject( this );
173 wxWindow
* window
= GetParent() ;
174 if (window
&& window
->MacIsWindowScrollbar(this) )
177 window
->MacOnScroll(event
);
180 GetEventHandler()->ProcessEvent(event
);