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 IMPLEMENT_DYNAMIC_CLASS(wxScrollBar
, wxControl
)
21 BEGIN_EVENT_TABLE(wxScrollBar
, wxControl
)
25 extern ControlActionUPP wxMacLiveScrollbarActionUPP
;
28 bool wxScrollBar::Create(wxWindow
*parent
, wxWindowID id
,
30 const wxSize
& size
, long style
,
31 const wxValidator
& validator
,
40 MacPreControlCreate( parent
, id
, "" , pos
, size
,style
, validator
, name
, &bounds
, title
) ;
42 m_macControl
= UMANewControl( parent
->GetMacRootWindow() , &bounds
, title
, true , 0 , 0 , 100,
43 kControlScrollBarLiveProc
, (long) this ) ;
45 wxASSERT_MSG( m_macControl
!= NULL
, "No valid mac control" ) ;
47 ::SetControlAction( m_macControl
, wxMacLiveScrollbarActionUPP
) ;
49 MacPostControlCreate() ;
54 wxScrollBar::~wxScrollBar()
58 void wxScrollBar::SetThumbPosition(int viewStart
)
60 ::SetControlValue( m_macControl
, viewStart
) ;
63 int wxScrollBar::GetThumbPosition() const
65 return ::GetControlValue( m_macControl
) ;
68 void wxScrollBar::SetScrollbar(int position
, int thumbSize
, int range
, int pageSize
,
71 m_viewSize
= pageSize
;
72 m_pageSize
= thumbSize
;
75 int range1
= wxMax((m_objectSize
- m_pageSize
), 0) ;
77 SetControlMaximum( m_macControl
, range1
) ;
78 SetControlMinimum( m_macControl
, 0 ) ;
79 SetControlValue( m_macControl
, position
) ;
81 if ( UMAGetAppearanceVersion() >= 0x0110 )
84 SetControlViewSize( m_macControl
, m_pageSize
) ;
91 void wxScrollBar::Command(wxCommandEvent
& event
)
93 SetThumbPosition(event
.m_commandInt
);
94 ProcessCommand(event
);
97 void wxScrollBar::MacHandleControlClick( ControlHandle control
, SInt16 controlpart
)
99 if ( m_macControl
== NULL
)
102 int position
= GetControlValue( m_macControl
) ;
103 int minPos
= GetControlMinimum( m_macControl
) ;
104 int maxPos
= GetControlMaximum( m_macControl
) ;
106 wxEventType scrollEvent
= wxEVT_NULL
;
109 switch( controlpart
)
111 case kControlUpButtonPart
:
113 scrollEvent
= wxEVT_SCROLL_LINEUP
;
115 case kControlDownButtonPart
:
117 scrollEvent
= wxEVT_SCROLL_LINEDOWN
;
119 case kControlPageUpPart
:
120 nScrollInc
= -m_pageSize
;
121 scrollEvent
= wxEVT_SCROLL_PAGEUP
;
123 case kControlPageDownPart
:
124 nScrollInc
= m_pageSize
;
125 scrollEvent
= wxEVT_SCROLL_PAGEDOWN
;
127 case kControlIndicatorPart
:
129 scrollEvent
= wxEVT_SCROLL_THUMBTRACK
;
133 int new_pos
= position
+ nScrollInc
;
137 if (new_pos
> maxPos
)
140 SetThumbPosition(new_pos
);
142 wxScrollEvent
event(scrollEvent
, m_windowId
);
143 if ( m_windowStyle
& wxHORIZONTAL
)
145 event
.SetOrientation( wxHORIZONTAL
) ;
149 event
.SetOrientation( wxVERTICAL
) ;
151 event
.SetPosition(new_pos
);
152 event
.SetEventObject( this );
153 wxWindow
* window
= GetParent() ;
154 if (window
&& window
->MacIsWindowScrollbar(this) )
157 window
->MacOnScroll(event
);
160 GetEventHandler()->ProcessEvent(event
);