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
, false , 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 )
85 if ( SetControlViewSize
!= (void*) kUnresolvedCFragSymbolAddress
)
87 SetControlViewSize( m_macControl
, m_pageSize
) ;
94 void wxScrollBar::Command(wxCommandEvent
& event
)
96 SetThumbPosition(event
.m_commandInt
);
97 ProcessCommand(event
);
100 void wxScrollBar::MacHandleControlClick( ControlHandle control
, SInt16 controlpart
)
102 if ( m_macControl
== NULL
)
105 int position
= GetControlValue( m_macControl
) ;
106 int minPos
= GetControlMinimum( m_macControl
) ;
107 int maxPos
= GetControlMaximum( m_macControl
) ;
109 wxEventType scrollEvent
= wxEVT_NULL
;
112 switch( controlpart
)
114 case kControlUpButtonPart
:
116 scrollEvent
= wxEVT_SCROLL_LINEUP
;
118 case kControlDownButtonPart
:
120 scrollEvent
= wxEVT_SCROLL_LINEDOWN
;
122 case kControlPageUpPart
:
123 nScrollInc
= -m_pageSize
;
124 scrollEvent
= wxEVT_SCROLL_PAGEUP
;
126 case kControlPageDownPart
:
127 nScrollInc
= m_pageSize
;
128 scrollEvent
= wxEVT_SCROLL_PAGEDOWN
;
130 case kControlIndicatorPart
:
132 scrollEvent
= wxEVT_SCROLL_THUMBTRACK
;
136 int new_pos
= position
+ nScrollInc
;
140 if (new_pos
> maxPos
)
143 SetThumbPosition(new_pos
);
145 wxScrollEvent
event(scrollEvent
, m_windowId
);
146 if ( m_windowStyle
& wxHORIZONTAL
)
148 event
.SetOrientation( wxHORIZONTAL
) ;
152 event
.SetOrientation( wxVERTICAL
) ;
154 event
.SetPosition(new_pos
);
155 event
.SetEventObject( this );
156 wxWindow
* window
= GetParent() ;
157 if (window
&& window
->MacIsWindowScrollbar(this) )
160 window
->MacOnScroll(event
);
163 GetEventHandler()->ProcessEvent(event
);