]> git.saurik.com Git - wxWidgets.git/blame - src/mac/scrolbar.cpp
Don't leave behind trails from glowing OS X button (By extending invisible button...
[wxWidgets.git] / src / mac / scrolbar.cpp
CommitLineData
e9576ca5
SC
1/////////////////////////////////////////////////////////////////////////////
2// Name: scrolbar.cpp
3// Purpose: wxScrollBar
a31a5f85 4// Author: Stefan Csomor
e9576ca5 5// Modified by:
a31a5f85 6// Created: 1998-01-01
e9576ca5 7// RCS-ID: $Id$
a31a5f85 8// Copyright: (c) Stefan Csomor
e40298d5 9// Licence: wxWindows licence
e9576ca5
SC
10/////////////////////////////////////////////////////////////////////////////
11
12#ifdef __GNUG__
13#pragma implementation "scrolbar.h"
14#endif
15
d8c736e5
GD
16#include "wx/defs.h"
17
8140eec9
SC
18#ifndef WX_PRECOMP
19 #include "wx/intl.h"
20 #include "wx/log.h"
21#endif // WX_PRECOMP
22
e9576ca5 23#include "wx/scrolbar.h"
519cb848 24#include "wx/mac/uma.h"
e9576ca5 25
2f1ae414 26#if !USE_SHARED_LIBRARY
e9576ca5
SC
27IMPLEMENT_DYNAMIC_CLASS(wxScrollBar, wxControl)
28
169935ad
SC
29BEGIN_EVENT_TABLE(wxScrollBar, wxControl)
30END_EVENT_TABLE()
31
2f1ae414 32#endif
e9576ca5 33
519cb848
SC
34extern ControlActionUPP wxMacLiveScrollbarActionUPP ;
35
e9576ca5
SC
36// Scrollbar
37bool wxScrollBar::Create(wxWindow *parent, wxWindowID id,
38 const wxPoint& pos,
39 const wxSize& size, long style,
40 const wxValidator& validator,
41 const wxString& name)
42{
b45ed7a2
VZ
43 if ( !wxControl::Create(parent, id, pos, size, style, validator, name) )
44 return FALSE;
45
e40298d5
JS
46 Rect bounds ;
47 Str255 title ;
b45ed7a2 48
427ff662 49 MacPreControlCreate( parent , id , wxEmptyString , pos , size ,style, validator , name , &bounds , title ) ;
519cb848 50
b45ed7a2 51 m_macControl = ::NewControl(MAC_WXHWND(parent->MacGetRootWindow()) ,
dbe931ab 52 &bounds , title , false , 0 , 0 , 100,
b45ed7a2
VZ
53 kControlScrollBarLiveProc , (long) this) ;
54
427ff662 55 wxASSERT_MSG( (ControlHandle) m_macControl != NULL , wxT("No valid mac control") ) ;
519cb848 56
e40298d5 57 ::SetControlAction( (ControlHandle) m_macControl , wxMacLiveScrollbarActionUPP ) ;
e9576ca5 58
e40298d5 59 MacPostControlCreate() ;
e9576ca5 60
b45ed7a2 61 return TRUE;
e9576ca5
SC
62}
63
64wxScrollBar::~wxScrollBar()
65{
66}
67
68void wxScrollBar::SetThumbPosition(int viewStart)
69{
467e3168 70 ::SetControl32BitValue( (ControlHandle) m_macControl , viewStart ) ;
e9576ca5
SC
71}
72
73int wxScrollBar::GetThumbPosition() const
74{
467e3168 75 return ::GetControl32BitValue( (ControlHandle) m_macControl ) ;
e9576ca5
SC
76}
77
78void wxScrollBar::SetScrollbar(int position, int thumbSize, int range, int pageSize,
79 bool refresh)
80{
4b1c4c21
SC
81 m_pageSize = pageSize;
82 m_viewSize = thumbSize;
e9576ca5
SC
83 m_objectSize = range;
84
e40298d5 85 int range1 = wxMax((m_objectSize - m_viewSize), 0) ;
519cb848 86
467e3168
SC
87 SetControl32BitMaximum( (ControlHandle) m_macControl , range1 ) ;
88 SetControl32BitMinimum( (ControlHandle) m_macControl , 0 ) ;
89 SetControl32BitValue( (ControlHandle) m_macControl , position ) ;
519cb848
SC
90
91 if ( UMAGetAppearanceVersion() >= 0x0110 )
92 {
a49afa93
SC
93 if ( SetControlViewSize != (void*) kUnresolvedCFragSymbolAddress )
94 {
e40298d5 95 SetControlViewSize( (ControlHandle) m_macControl , m_viewSize ) ;
a49afa93 96 }
519cb848 97 }
66a09d47
SC
98 if ( refresh )
99 MacRedrawControl() ;
e9576ca5
SC
100}
101
102
103void wxScrollBar::Command(wxCommandEvent& event)
104{
105 SetThumbPosition(event.m_commandInt);
106 ProcessCommand(event);
107}
108
4b26b60f 109void wxScrollBar::MacHandleControlClick( WXWidget control , wxInt16 controlpart , bool mouseStillDown )
519cb848 110{
e40298d5
JS
111 if ( (ControlHandle) m_macControl == NULL )
112 return ;
113
114 int position = GetControl32BitValue( (ControlHandle) m_macControl) ;
115 int minPos = GetControl32BitMinimum( (ControlHandle) m_macControl) ;
116 int maxPos = GetControl32BitMaximum( (ControlHandle) m_macControl) ;
117
118 wxEventType scrollEvent = wxEVT_NULL;
119 int nScrollInc;
120
4b26b60f
SC
121 // all events have already been reported during mouse down, except for THUMBRELEASE
122 if ( !mouseStillDown && controlpart !=kControlIndicatorPart )
123 return ;
124
e40298d5
JS
125 switch( controlpart )
126 {
127 case kControlUpButtonPart :
4b1c4c21 128 nScrollInc = -1;
519cb848 129 scrollEvent = wxEVT_SCROLL_LINEUP;
e40298d5
JS
130 break ;
131 case kControlDownButtonPart :
4b1c4c21 132 nScrollInc = 1;
519cb848 133 scrollEvent = wxEVT_SCROLL_LINEDOWN;
e40298d5
JS
134 break ;
135 case kControlPageUpPart :
4b1c4c21 136 nScrollInc = -m_pageSize;
519cb848 137 scrollEvent = wxEVT_SCROLL_PAGEUP;
e40298d5
JS
138 break ;
139 case kControlPageDownPart :
4b1c4c21 140 nScrollInc = m_pageSize;
519cb848 141 scrollEvent = wxEVT_SCROLL_PAGEDOWN;
e40298d5
JS
142 break ;
143 case kControlIndicatorPart :
519cb848 144 nScrollInc = 0 ;
4b26b60f
SC
145 if ( mouseStillDown )
146 scrollEvent = wxEVT_SCROLL_THUMBTRACK;
147 else
148 scrollEvent = wxEVT_SCROLL_THUMBRELEASE;
e40298d5
JS
149 break ;
150 default :
151 wxFAIL_MSG(wxT("illegal scrollbar selector"));
152 break ;
153 }
154
155 int new_pos = position + nScrollInc;
156
157 if (new_pos < minPos)
158 new_pos = minPos;
159 if (new_pos > maxPos)
160 new_pos = maxPos;
161 if ( nScrollInc )
162 SetThumbPosition(new_pos);
163
164 wxScrollEvent event(scrollEvent, m_windowId);
165 if ( m_windowStyle & wxHORIZONTAL )
166 {
167 event.SetOrientation( wxHORIZONTAL ) ;
168 }
169 else
170 {
171 event.SetOrientation( wxVERTICAL ) ;
172 }
173 event.SetPosition(new_pos);
174 event.SetEventObject( this );
175 wxWindow* window = GetParent() ;
176 if (window && window->MacIsWindowScrollbar(this) )
177 {
178 // this is hardcoded
179 window->MacOnScroll(event);
180 }
181 else
182 GetEventHandler()->ProcessEvent(event);
519cb848
SC
183}
184