1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxScrollBar
8 // Copyright: (c) AUTHOR
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "scrolbar.h"
16 #include "wx/scrolbar.h"
17 #include "wx/mac/uma.h"
19 #if !USE_SHARED_LIBRARY
20 IMPLEMENT_DYNAMIC_CLASS(wxScrollBar
, wxControl
)
22 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
,
42 MacPreControlCreate( parent
, id
, "" , pos
, size
,style
, validator
, name
, &bounds
, title
) ;
44 m_macControl
= UMANewControl( parent
->GetMacRootWindow() , &bounds
, title
, true , 0 , 0 , 100,
45 kControlScrollBarLiveProc
, (long) this ) ;
47 wxASSERT_MSG( m_macControl
!= NULL
, "No valid mac control" ) ;
49 ::SetControlAction( m_macControl
, wxMacLiveScrollbarActionUPP
) ;
51 MacPostControlCreate() ;
56 wxScrollBar::~wxScrollBar()
60 void wxScrollBar::SetThumbPosition(int viewStart
)
62 ::SetControlValue( m_macControl
, viewStart
) ;
65 int wxScrollBar::GetThumbPosition() const
67 return ::GetControlValue( m_macControl
) ;
70 void wxScrollBar::SetScrollbar(int position
, int thumbSize
, int range
, int pageSize
,
73 m_viewSize
= pageSize
;
74 m_pageSize
= thumbSize
;
77 int range1
= wxMax((m_objectSize
- m_pageSize
), 0) ;
79 SetControlMaximum( m_macControl
, range1
) ;
80 SetControlMinimum( m_macControl
, 0 ) ;
81 SetControlValue( m_macControl
, position
) ;
83 if ( UMAGetAppearanceVersion() >= 0x0110 )
86 SetControlViewSize( m_macControl
, m_pageSize
) ;
93 void wxScrollBar::Command(wxCommandEvent
& event
)
95 SetThumbPosition(event
.m_commandInt
);
96 ProcessCommand(event
);
99 void wxScrollBar::MacHandleControlClick( ControlHandle control
, SInt16 controlpart
)
101 if ( m_macControl
== NULL
)
104 int position
= GetControlValue( m_macControl
) ;
105 int minPos
= GetControlMinimum( m_macControl
) ;
106 int maxPos
= GetControlMaximum( m_macControl
) ;
108 wxEventType scrollEvent
= wxEVT_NULL
;
111 switch( controlpart
)
113 case kControlUpButtonPart
:
115 scrollEvent
= wxEVT_SCROLL_LINEUP
;
117 case kControlDownButtonPart
:
119 scrollEvent
= wxEVT_SCROLL_LINEDOWN
;
121 case kControlPageUpPart
:
122 nScrollInc
= -m_pageSize
;
123 scrollEvent
= wxEVT_SCROLL_PAGEUP
;
125 case kControlPageDownPart
:
126 nScrollInc
= m_pageSize
;
127 scrollEvent
= wxEVT_SCROLL_PAGEDOWN
;
129 case kControlIndicatorPart
:
131 scrollEvent
= wxEVT_SCROLL_THUMBTRACK
;
135 int new_pos
= position
+ nScrollInc
;
139 if (new_pos
> maxPos
)
142 SetThumbPosition(new_pos
);
144 wxScrollEvent
event(scrollEvent
, m_windowId
);
145 if ( m_windowStyle
& wxHORIZONTAL
)
147 event
.SetOrientation( wxHORIZONTAL
) ;
151 event
.SetOrientation( wxVERTICAL
) ;
153 event
.SetPosition(new_pos
);
154 event
.SetEventObject( this );
155 GetEventHandler()->ProcessEvent(event
);