]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/osx/scrolbar_osx.cpp
Add missing WXK constants for the control keys
[wxWidgets.git] / src / osx / scrolbar_osx.cpp
... / ...
CommitLineData
1/////////////////////////////////////////////////////////////////////////////
2// Name: src/osx/scrolbar_osx.cpp
3// Purpose: wxScrollBar
4// Author: Stefan Csomor
5// Modified by:
6// Created: 1998-01-01
7// RCS-ID: $Id$
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
24#if wxUSE_SCROLLBAR
25
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 )
37{
38 DontCreatePeer();
39
40 if ( !wxControl::Create( parent, id, pos, size, style, validator, name ) )
41 return false;
42
43 SetPeer(wxWidgetImpl::CreateScrollBar( this, parent, id, pos, size, style, GetExtraStyle() ));
44
45 MacPostControlCreate( pos, size );
46
47 return true;
48}
49
50wxScrollBar::~wxScrollBar()
51{
52}
53
54void wxScrollBar::SetThumbPosition( int viewStart )
55{
56 GetPeer()->SetScrollThumb( viewStart, m_viewSize );
57}
58
59int wxScrollBar::GetThumbPosition() const
60{
61 return GetPeer()->GetValue();
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 );
75
76 GetPeer()->SetMaximum( range1 );
77 GetPeer()->SetScrollThumb( position, m_viewSize );
78}
79
80void wxScrollBar::Command( wxCommandEvent& event )
81{
82 SetThumbPosition( event.GetInt() );
83 ProcessCommand( event );
84}
85
86bool wxScrollBar::OSXHandleClicked( double WXUNUSED(timestampsec) )
87{
88 int new_pos = GetPeer()->GetValue();
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}
127
128void wxScrollBar::TriggerScrollEvent( wxEventType scrollEvent )
129{
130 int position = GetPeer()->GetValue();
131 int minPos = 0 ;
132 int maxPos = GetPeer()->GetMaximum();
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 );
177}
178
179#endif