1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxScrollBar
8 // Copyright: (c) AUTHOR
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "scrolbar.h"
18 #include "wx/scrolbar.h"
19 #include "wx/mac/uma.h"
21 #if !USE_SHARED_LIBRARY
22 IMPLEMENT_DYNAMIC_CLASS(wxScrollBar
, wxControl
)
24 BEGIN_EVENT_TABLE(wxScrollBar
, wxControl
)
29 extern ControlActionUPP wxMacLiveScrollbarActionUPP
;
32 bool wxScrollBar::Create(wxWindow
*parent
, wxWindowID id
,
34 const wxSize
& size
, long style
,
35 const wxValidator
& validator
,
44 MacPreControlCreate( parent
, id
, "" , pos
, size
,style
, validator
, name
, &bounds
, title
) ;
46 m_macControl
= ::NewControl( parent
->MacGetRootWindow() , &bounds
, title
, true , 0 , 0 , 100,
47 kControlScrollBarLiveProc
, (long) this ) ;
49 wxASSERT_MSG( m_macControl
!= NULL
, "No valid mac control" ) ;
51 ::SetControlAction( m_macControl
, wxMacLiveScrollbarActionUPP
) ;
53 MacPostControlCreate() ;
58 wxScrollBar::~wxScrollBar()
62 void wxScrollBar::SetThumbPosition(int viewStart
)
64 ::SetControlValue( m_macControl
, viewStart
) ;
67 int wxScrollBar::GetThumbPosition() const
69 return ::GetControlValue( m_macControl
) ;
72 void wxScrollBar::SetScrollbar(int position
, int thumbSize
, int range
, int pageSize
,
75 m_viewSize
= pageSize
;
76 m_pageSize
= thumbSize
;
79 int range1
= wxMax((m_objectSize
- m_pageSize
), 0) ;
81 SetControlMaximum( m_macControl
, range1
) ;
82 SetControlMinimum( m_macControl
, 0 ) ;
83 SetControlValue( m_macControl
, position
) ;
85 if ( UMAGetAppearanceVersion() >= 0x0110 )
87 if ( SetControlViewSize
!= (void*) kUnresolvedCFragSymbolAddress
)
89 SetControlViewSize( m_macControl
, m_pageSize
) ;
96 void wxScrollBar::Command(wxCommandEvent
& event
)
98 SetThumbPosition(event
.m_commandInt
);
99 ProcessCommand(event
);
102 void wxScrollBar::MacHandleControlClick( ControlHandle control
, SInt16 controlpart
)
104 if ( m_macControl
== NULL
)
107 int position
= GetControlValue( m_macControl
) ;
108 int minPos
= GetControlMinimum( m_macControl
) ;
109 int maxPos
= GetControlMaximum( m_macControl
) ;
111 wxEventType scrollEvent
= wxEVT_NULL
;
114 switch( controlpart
)
116 case kControlUpButtonPart
:
117 nScrollInc
= -m_pageSize
;
118 scrollEvent
= wxEVT_SCROLL_LINEUP
;
120 case kControlDownButtonPart
:
121 nScrollInc
= m_pageSize
;
122 scrollEvent
= wxEVT_SCROLL_LINEDOWN
;
124 case kControlPageUpPart
:
125 nScrollInc
= -m_viewSize
;
126 scrollEvent
= wxEVT_SCROLL_PAGEUP
;
128 case kControlPageDownPart
:
129 nScrollInc
= m_viewSize
;
130 scrollEvent
= wxEVT_SCROLL_PAGEDOWN
;
132 case kControlIndicatorPart
:
134 scrollEvent
= wxEVT_SCROLL_THUMBTRACK
;
138 int new_pos
= position
+ nScrollInc
;
142 if (new_pos
> maxPos
)
145 SetThumbPosition(new_pos
);
147 wxScrollEvent
event(scrollEvent
, m_windowId
);
148 if ( m_windowStyle
& wxHORIZONTAL
)
150 event
.SetOrientation( wxHORIZONTAL
) ;
154 event
.SetOrientation( wxVERTICAL
) ;
156 event
.SetPosition(new_pos
);
157 event
.SetEventObject( this );
158 wxWindow
* window
= GetParent() ;
159 if (window
&& window
->MacIsWindowScrollbar(this) )
162 window
->MacOnScroll(event
);
165 GetEventHandler()->ProcessEvent(event
);