]> git.saurik.com Git - wxWidgets.git/blame - src/osx/scrolbar_osx.cpp
added missing destructor
[wxWidgets.git] / src / osx / scrolbar_osx.cpp
CommitLineData
524c47aa
SC
1/////////////////////////////////////////////////////////////////////////////
2// Name: src/osx/carbon/scrolbar.cpp
3// Purpose: wxScrollBar
4// Author: Stefan Csomor
5// Modified by:
6// Created: 1998-01-01
7// RCS-ID: $Id: scrolbar.cpp 54129 2008-06-11 19:30:52Z SC $
8// Copyright: (c) Stefan Csomor
9// Licence: wxWindows licence
10/////////////////////////////////////////////////////////////////////////////
11
12#include "wx/wxprec.h"
13
14#include "wx/scrolbar.h"
15
16#ifndef WX_PRECOMP
17 #include "wx/intl.h"
18 #include "wx/log.h"
19 #include "wx/settings.h"
20#endif
21
22#include "wx/osx/private.h"
23
52147d1c
SC
24#if wxUSE_SCROLLBAR
25
524c47aa
SC
26IMPLEMENT_DYNAMIC_CLASS(wxScrollBar, wxControl)
27
28BEGIN_EVENT_TABLE(wxScrollBar, wxControl)
29END_EVENT_TABLE()
30
31
32bool wxScrollBar::Create( wxWindow *parent,
33 wxWindowID id,
34 const wxPoint& pos,
35 const wxSize& size,
36 long style,
37 const wxValidator& validator,
38 const wxString& name )
39{
40 m_macIsUserPane = false;
41
42 if ( !wxControl::Create( parent, id, pos, size, style, validator, name ) )
43 return false;
03647350 44
524c47aa
SC
45 m_peer = wxWidgetImpl::CreateScrollBar( this, parent, id, pos, size, style, GetExtraStyle() );
46
47 MacPostControlCreate( pos, size );
48
49 return true;
50}
51
52wxScrollBar::~wxScrollBar()
53{
54}
55
56void wxScrollBar::SetThumbPosition( int viewStart )
57{
58 m_peer->SetScrollThumb( viewStart, m_viewSize );
59}
60
61int wxScrollBar::GetThumbPosition() const
62{
63 return m_peer->GetValue();
64}
65
66void wxScrollBar::SetScrollbar( int position,
67 int thumbSize,
68 int range,
69 int pageSize,
70 bool WXUNUSED(refresh) )
71{
72 m_pageSize = pageSize;
73 m_viewSize = thumbSize;
74 m_objectSize = range;
75
76 int range1 = wxMax( (m_objectSize - m_viewSize), 0 );
03647350 77
524c47aa
SC
78 m_peer->SetMaximum( range1 );
79 m_peer->SetScrollThumb( position, m_viewSize );
80}
81
82void wxScrollBar::Command( wxCommandEvent& event )
83{
84 SetThumbPosition( event.GetInt() );
85 ProcessCommand( event );
86}
87
0faf03bf 88bool wxScrollBar::OSXHandleClicked( double WXUNUSED(timestampsec) )
524c47aa
SC
89{
90 int new_pos = m_peer->GetValue();
91
92 wxScrollEvent event( wxEVT_SCROLL_THUMBRELEASE, m_windowId );
93 if ( m_windowStyle & wxHORIZONTAL )
94 event.SetOrientation( wxHORIZONTAL );
95 else
96 event.SetOrientation( wxVERTICAL );
97
98 event.SetPosition( new_pos );
99 event.SetEventObject( this );
100 wxWindow* window = GetParent();
101 if (window && window->MacIsWindowScrollbar( this ))
102 // this is hardcoded
103 window->MacOnScroll( event );
104 else
105 HandleWindowEvent( event );
106
107 return true;
108}
109
110
111wxSize wxScrollBar::DoGetBestSize() const
112{
113 int w = 100;
114 int h = 100;
115
116 if ( IsVertical() )
117 {
118 w = wxSystemSettings::GetMetric(wxSYS_VSCROLL_X);
119 }
120 else
121 {
122 h = wxSystemSettings::GetMetric(wxSYS_HSCROLL_Y);
123 }
124
125 wxSize best(w, h);
126 CacheBestSize(best);
127 return best;
128}
19c7ac3d
SC
129
130void wxScrollBar::TriggerScrollEvent( wxEventType scrollEvent )
131{
132 int position = m_peer->GetValue();
133 int minPos = 0 ;
134 int maxPos = m_peer->GetMaximum();
135 int nScrollInc = 0;
136
137 if ( scrollEvent == wxEVT_SCROLL_LINEUP )
138 {
139 nScrollInc = -1;
140 }
141 else if ( scrollEvent == wxEVT_SCROLL_LINEDOWN )
142 {
143 nScrollInc = 1;
144 }
145 else if ( scrollEvent == wxEVT_SCROLL_PAGEUP )
146 {
147 nScrollInc = -m_pageSize;
148 }
149 else if ( scrollEvent == wxEVT_SCROLL_PAGEDOWN )
150 {
151 nScrollInc = m_pageSize;
152 }
153
154 int new_pos = position + nScrollInc;
155
156 if (new_pos < minPos)
157 new_pos = minPos;
158 else if (new_pos > maxPos)
159 new_pos = maxPos;
160
161 if ( nScrollInc )
162 SetThumbPosition( new_pos );
163
164 wxScrollEvent event( scrollEvent, m_windowId );
165 if ( m_windowStyle & wxHORIZONTAL )
166 event.SetOrientation( wxHORIZONTAL );
167 else
168 event.SetOrientation( wxVERTICAL );
169
170 event.SetPosition( new_pos );
171 event.SetEventObject( this );
172
173 wxWindow* window = GetParent();
174 if (window && window->MacIsWindowScrollbar( this ))
175 // this is hardcoded
176 window->MacOnScroll( event );
177 else
178 HandleWindowEvent( event );
52147d1c
SC
179}
180
181#endif