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