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( MAC_WXHWND(parent
->MacGetRootWindow()) , &bounds
, title
, true , 0 , 0 , 100,
47 kControlScrollBarLiveProc
, (long) this ) ;
49 wxASSERT_MSG( (ControlHandle
) m_macControl
!= NULL
, "No valid mac control" ) ;
51 ::SetControlAction( (ControlHandle
) m_macControl
, wxMacLiveScrollbarActionUPP
) ;
53 MacPostControlCreate() ;
58 wxScrollBar::~wxScrollBar()
62 void wxScrollBar::SetThumbPosition(int viewStart
)
64 ::SetControlValue( (ControlHandle
) m_macControl
, viewStart
) ;
67 int wxScrollBar::GetThumbPosition() const
69 return ::GetControlValue( (ControlHandle
) m_macControl
) ;
72 void wxScrollBar::SetScrollbar(int position
, int thumbSize
, int range
, int pageSize
,
75 m_pageSize
= pageSize
;
76 m_viewSize
= thumbSize
;
79 int range1
= wxMax((m_objectSize
- m_viewSize
), 0) ;
81 SetControlMaximum( (ControlHandle
) m_macControl
, range1
) ;
82 SetControlMinimum( (ControlHandle
) m_macControl
, 0 ) ;
83 SetControlValue( (ControlHandle
) m_macControl
, position
) ;
85 if ( UMAGetAppearanceVersion() >= 0x0110 )
87 if ( SetControlViewSize
!= (void*) kUnresolvedCFragSymbolAddress
)
89 SetControlViewSize( (ControlHandle
) m_macControl
, m_viewSize
) ;
97 void wxScrollBar::Command(wxCommandEvent
& event
)
99 SetThumbPosition(event
.m_commandInt
);
100 ProcessCommand(event
);
103 void wxScrollBar::MacHandleControlClick( WXWidget control
, wxInt16 controlpart
)
105 if ( (ControlHandle
) m_macControl
== NULL
)
108 int position
= GetControlValue( (ControlHandle
) m_macControl
) ;
109 int minPos
= GetControlMinimum( (ControlHandle
) m_macControl
) ;
110 int maxPos
= GetControlMaximum( (ControlHandle
) m_macControl
) ;
112 wxEventType scrollEvent
= wxEVT_NULL
;
115 switch( controlpart
)
117 case kControlUpButtonPart
:
119 scrollEvent
= wxEVT_SCROLL_LINEUP
;
121 case kControlDownButtonPart
:
123 scrollEvent
= wxEVT_SCROLL_LINEDOWN
;
125 case kControlPageUpPart
:
126 nScrollInc
= -m_pageSize
;
127 scrollEvent
= wxEVT_SCROLL_PAGEUP
;
129 case kControlPageDownPart
:
130 nScrollInc
= m_pageSize
;
131 scrollEvent
= wxEVT_SCROLL_PAGEDOWN
;
133 case kControlIndicatorPart
:
135 scrollEvent
= wxEVT_SCROLL_THUMBTRACK
;
139 int new_pos
= position
+ nScrollInc
;
143 if (new_pos
> maxPos
)
146 SetThumbPosition(new_pos
);
148 wxScrollEvent
event(scrollEvent
, m_windowId
);
149 if ( m_windowStyle
& wxHORIZONTAL
)
151 event
.SetOrientation( wxHORIZONTAL
) ;
155 event
.SetOrientation( wxVERTICAL
) ;
157 event
.SetPosition(new_pos
);
158 event
.SetEventObject( this );
159 wxWindow
* window
= GetParent() ;
160 if (window
&& window
->MacIsWindowScrollbar(this) )
163 window
->MacOnScroll(event
);
166 GetEventHandler()->ProcessEvent(event
);