1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/carbon/scrolbar.cpp
3 // Purpose: wxScrollBar
4 // Author: Stefan Csomor
7 // RCS-ID: $Id: scrolbar.cpp 54129 2008-06-11 19:30:52Z SC $
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #include "wx/wxprec.h"
14 #include "wx/scrolbar.h"
19 #include "wx/settings.h"
22 #include "wx/osx/private.h"
24 IMPLEMENT_DYNAMIC_CLASS(wxScrollBar
, wxControl
)
26 BEGIN_EVENT_TABLE(wxScrollBar
, wxControl
)
30 bool wxScrollBar::Create( wxWindow
*parent
,
35 const wxValidator
& validator
,
36 const wxString
& name
)
38 m_macIsUserPane
= false;
40 if ( !wxControl::Create( parent
, id
, pos
, size
, style
, validator
, name
) )
43 m_peer
= wxWidgetImpl::CreateScrollBar( this, parent
, id
, pos
, size
, style
, GetExtraStyle() );
45 MacPostControlCreate( pos
, size
);
50 wxScrollBar::~wxScrollBar()
54 void wxScrollBar::SetThumbPosition( int viewStart
)
56 m_peer
->SetScrollThumb( viewStart
, m_viewSize
);
59 int wxScrollBar::GetThumbPosition() const
61 return m_peer
->GetValue();
64 void wxScrollBar::SetScrollbar( int position
,
68 bool WXUNUSED(refresh
) )
70 m_pageSize
= pageSize
;
71 m_viewSize
= thumbSize
;
74 int range1
= wxMax( (m_objectSize
- m_viewSize
), 0 );
76 m_peer
->SetMaximum( range1
);
77 m_peer
->SetScrollThumb( position
, m_viewSize
);
80 void wxScrollBar::Command( wxCommandEvent
& event
)
82 SetThumbPosition( event
.GetInt() );
83 ProcessCommand( event
);
86 bool wxScrollBar::OSXHandleClicked( double WXUNUSED(timestampsec
) )
88 int new_pos
= m_peer
->GetValue();
90 wxScrollEvent
event( wxEVT_SCROLL_THUMBRELEASE
, m_windowId
);
91 if ( m_windowStyle
& wxHORIZONTAL
)
92 event
.SetOrientation( wxHORIZONTAL
);
94 event
.SetOrientation( wxVERTICAL
);
96 event
.SetPosition( new_pos
);
97 event
.SetEventObject( this );
98 wxWindow
* window
= GetParent();
99 if (window
&& window
->MacIsWindowScrollbar( this ))
101 window
->MacOnScroll( event
);
103 HandleWindowEvent( event
);
109 wxSize
wxScrollBar::DoGetBestSize() const
116 w
= wxSystemSettings::GetMetric(wxSYS_VSCROLL_X
);
120 h
= wxSystemSettings::GetMetric(wxSYS_HSCROLL_Y
);
128 void wxScrollBar::TriggerScrollEvent( wxEventType scrollEvent
)
130 int position
= m_peer
->GetValue();
132 int maxPos
= m_peer
->GetMaximum();
135 if ( scrollEvent
== wxEVT_SCROLL_LINEUP
)
139 else if ( scrollEvent
== wxEVT_SCROLL_LINEDOWN
)
143 else if ( scrollEvent
== wxEVT_SCROLL_PAGEUP
)
145 nScrollInc
= -m_pageSize
;
147 else if ( scrollEvent
== wxEVT_SCROLL_PAGEDOWN
)
149 nScrollInc
= m_pageSize
;
152 int new_pos
= position
+ nScrollInc
;
154 if (new_pos
< minPos
)
156 else if (new_pos
> maxPos
)
160 SetThumbPosition( new_pos
);
162 wxScrollEvent
event( scrollEvent
, m_windowId
);
163 if ( m_windowStyle
& wxHORIZONTAL
)
164 event
.SetOrientation( wxHORIZONTAL
);
166 event
.SetOrientation( wxVERTICAL
);
168 event
.SetPosition( new_pos
);
169 event
.SetEventObject( this );
171 wxWindow
* window
= GetParent();
172 if (window
&& window
->MacIsWindowScrollbar( this ))
174 window
->MacOnScroll( event
);
176 HandleWindowEvent( event
);