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