1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/carbon/scrolbar.cpp
3 // Purpose: wxScrollBar
4 // Author: Stefan Csomor
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"
26 IMPLEMENT_DYNAMIC_CLASS(wxScrollBar
, wxControl
)
28 BEGIN_EVENT_TABLE(wxScrollBar
, wxControl
)
32 bool wxScrollBar::Create( wxWindow
*parent
,
37 const wxValidator
& validator
,
38 const wxString
& name
)
40 m_macIsUserPane
= false;
42 if ( !wxControl::Create( parent
, id
, pos
, size
, style
, validator
, name
) )
45 m_peer
= wxWidgetImpl::CreateScrollBar( this, parent
, id
, pos
, size
, style
, GetExtraStyle() );
47 MacPostControlCreate( pos
, size
);
52 wxScrollBar::~wxScrollBar()
56 void wxScrollBar::SetThumbPosition( int viewStart
)
58 m_peer
->SetScrollThumb( viewStart
, m_viewSize
);
61 int wxScrollBar::GetThumbPosition() const
63 return m_peer
->GetValue();
66 void wxScrollBar::SetScrollbar( int position
,
70 bool WXUNUSED(refresh
) )
72 m_pageSize
= pageSize
;
73 m_viewSize
= thumbSize
;
76 int range1
= wxMax( (m_objectSize
- m_viewSize
), 0 );
78 m_peer
->SetMaximum( range1
);
79 m_peer
->SetScrollThumb( position
, m_viewSize
);
82 void wxScrollBar::Command( wxCommandEvent
& event
)
84 SetThumbPosition( event
.GetInt() );
85 ProcessCommand( event
);
88 bool wxScrollBar::OSXHandleClicked( double WXUNUSED(timestampsec
) )
90 int new_pos
= m_peer
->GetValue();
92 wxScrollEvent
event( wxEVT_SCROLL_THUMBRELEASE
, m_windowId
);
93 if ( m_windowStyle
& wxHORIZONTAL
)
94 event
.SetOrientation( wxHORIZONTAL
);
96 event
.SetOrientation( wxVERTICAL
);
98 event
.SetPosition( new_pos
);
99 event
.SetEventObject( this );
100 wxWindow
* window
= GetParent();
101 if (window
&& window
->MacIsWindowScrollbar( this ))
103 window
->MacOnScroll( event
);
105 HandleWindowEvent( event
);
111 wxSize
wxScrollBar::DoGetBestSize() const
118 w
= wxSystemSettings::GetMetric(wxSYS_VSCROLL_X
);
122 h
= wxSystemSettings::GetMetric(wxSYS_HSCROLL_Y
);
130 void wxScrollBar::TriggerScrollEvent( wxEventType scrollEvent
)
132 int position
= m_peer
->GetValue();
134 int maxPos
= m_peer
->GetMaximum();
137 if ( scrollEvent
== wxEVT_SCROLL_LINEUP
)
141 else if ( scrollEvent
== wxEVT_SCROLL_LINEDOWN
)
145 else if ( scrollEvent
== wxEVT_SCROLL_PAGEUP
)
147 nScrollInc
= -m_pageSize
;
149 else if ( scrollEvent
== wxEVT_SCROLL_PAGEDOWN
)
151 nScrollInc
= m_pageSize
;
154 int new_pos
= position
+ nScrollInc
;
156 if (new_pos
< minPos
)
158 else if (new_pos
> maxPos
)
162 SetThumbPosition( new_pos
);
164 wxScrollEvent
event( scrollEvent
, m_windowId
);
165 if ( m_windowStyle
& wxHORIZONTAL
)
166 event
.SetOrientation( wxHORIZONTAL
);
168 event
.SetOrientation( wxVERTICAL
);
170 event
.SetPosition( new_pos
);
171 event
.SetEventObject( this );
173 wxWindow
* window
= GetParent();
174 if (window
&& window
->MacIsWindowScrollbar( this ))
176 window
->MacOnScroll( event
);
178 HandleWindowEvent( event
);