]> git.saurik.com Git - wxWidgets.git/blob - src/osx/scrolbar_osx.cpp
changing to allow for 2x ramping up NSApp run
[wxWidgets.git] / src / osx / scrolbar_osx.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/scrolbar_osx.cpp
3 // Purpose: wxScrollBar
4 // Author: Stefan Csomor
5 // Modified by:
6 // Created: 1998-01-01
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
23 #if wxUSE_SCROLLBAR
24
25 BEGIN_EVENT_TABLE(wxScrollBar, wxControl)
26 END_EVENT_TABLE()
27
28
29 bool 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 )
36 {
37 DontCreatePeer();
38
39 if ( !wxControl::Create( parent, id, pos, size, style, validator, name ) )
40 return false;
41
42 SetPeer(wxWidgetImpl::CreateScrollBar( this, parent, id, pos, size, style, GetExtraStyle() ));
43
44 MacPostControlCreate( pos, size );
45
46 return true;
47 }
48
49 wxScrollBar::~wxScrollBar()
50 {
51 }
52
53 void wxScrollBar::SetThumbPosition( int viewStart )
54 {
55 GetPeer()->SetScrollThumb( viewStart, m_viewSize );
56 }
57
58 int wxScrollBar::GetThumbPosition() const
59 {
60 return GetPeer()->GetValue();
61 }
62
63 void 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 );
74
75 GetPeer()->SetMaximum( range1 );
76 GetPeer()->SetScrollThumb( position, m_viewSize );
77 }
78
79 void wxScrollBar::Command( wxCommandEvent& event )
80 {
81 SetThumbPosition( event.GetInt() );
82 ProcessCommand( event );
83 }
84
85 bool wxScrollBar::OSXHandleClicked( double WXUNUSED(timestampsec) )
86 {
87 int new_pos = GetPeer()->GetValue();
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
108 wxSize 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 }
126
127 void wxScrollBar::TriggerScrollEvent( wxEventType scrollEvent )
128 {
129 int position = GetPeer()->GetValue();
130 int minPos = 0 ;
131 int maxPos = GetPeer()->GetMaximum();
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 );
176 }
177
178 #endif