1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/scrolbar_osx.cpp
3 // Purpose: wxScrollBar
4 // Author: Stefan Csomor
7 // Copyright: (c) Stefan Csomor
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 #include "wx/wxprec.h"
13 #include "wx/scrolbar.h"
18 #include "wx/settings.h"
21 #include "wx/osx/private.h"
25 BEGIN_EVENT_TABLE(wxScrollBar
, wxControl
)
29 bool wxScrollBar::Create( wxWindow
*parent
,
34 const wxValidator
& validator
,
35 const wxString
& name
)
39 if ( !wxControl::Create( parent
, id
, pos
, size
, style
, validator
, name
) )
42 SetPeer(wxWidgetImpl::CreateScrollBar( this, parent
, id
, pos
, size
, style
, GetExtraStyle() ));
44 MacPostControlCreate( pos
, size
);
49 wxScrollBar::~wxScrollBar()
53 void wxScrollBar::SetThumbPosition( int viewStart
)
55 GetPeer()->SetScrollThumb( viewStart
, m_viewSize
);
58 int wxScrollBar::GetThumbPosition() const
60 return GetPeer()->GetValue();
63 void wxScrollBar::SetScrollbar( int position
,
67 bool WXUNUSED(refresh
) )
69 m_pageSize
= pageSize
;
70 m_viewSize
= thumbSize
;
73 int range1
= wxMax( (m_objectSize
- m_viewSize
), 0 );
75 GetPeer()->SetMaximum( range1
);
76 GetPeer()->SetScrollThumb( position
, m_viewSize
);
79 void wxScrollBar::Command( wxCommandEvent
& event
)
81 SetThumbPosition( event
.GetInt() );
82 ProcessCommand( event
);
85 bool wxScrollBar::OSXHandleClicked( double WXUNUSED(timestampsec
) )
87 int new_pos
= GetPeer()->GetValue();
89 wxScrollEvent
event( wxEVT_SCROLL_THUMBRELEASE
, m_windowId
);
90 if ( m_windowStyle
& wxHORIZONTAL
)
91 event
.SetOrientation( wxHORIZONTAL
);
93 event
.SetOrientation( wxVERTICAL
);
95 event
.SetPosition( new_pos
);
96 event
.SetEventObject( this );
97 wxWindow
* window
= GetParent();
98 if (window
&& window
->MacIsWindowScrollbar( this ))
100 window
->MacOnScroll( event
);
102 HandleWindowEvent( event
);
108 wxSize
wxScrollBar::DoGetBestSize() const
115 w
= wxSystemSettings::GetMetric(wxSYS_VSCROLL_X
);
119 h
= wxSystemSettings::GetMetric(wxSYS_HSCROLL_Y
);
127 void wxScrollBar::TriggerScrollEvent( wxEventType scrollEvent
)
129 int position
= GetPeer()->GetValue();
131 int maxPos
= GetPeer()->GetMaximum();
134 if ( scrollEvent
== wxEVT_SCROLL_LINEUP
)
138 else if ( scrollEvent
== wxEVT_SCROLL_LINEDOWN
)
142 else if ( scrollEvent
== wxEVT_SCROLL_PAGEUP
)
144 nScrollInc
= -m_pageSize
;
146 else if ( scrollEvent
== wxEVT_SCROLL_PAGEDOWN
)
148 nScrollInc
= m_pageSize
;
151 int new_pos
= position
+ nScrollInc
;
153 if (new_pos
< minPos
)
155 else if (new_pos
> maxPos
)
159 SetThumbPosition( new_pos
);
161 wxScrollEvent
event( scrollEvent
, m_windowId
);
162 if ( m_windowStyle
& wxHORIZONTAL
)
163 event
.SetOrientation( wxHORIZONTAL
);
165 event
.SetOrientation( wxVERTICAL
);
167 event
.SetPosition( new_pos
);
168 event
.SetEventObject( this );
170 wxWindow
* window
= GetParent();
171 if (window
&& window
->MacIsWindowScrollbar( this ))
173 window
->MacOnScroll( event
);
175 HandleWindowEvent( event
);