]> git.saurik.com Git - wxWidgets.git/blame - src/mac/carbon/scrolbar.cpp
cleanup in toplevel activation, and switching to native carbon event notification...
[wxWidgets.git] / src / mac / carbon / 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{
facd6764
SC
43 m_macIsUserPane = FALSE ;
44
b45ed7a2
VZ
45 if ( !wxControl::Create(parent, id, pos, size, style, validator, name) )
46 return FALSE;
47
facd6764
SC
48 Rect bounds = wxMacGetBoundsForControl( this , pos , size ) ;
49 m_macControl = (WXWidget) ::NewControl(MAC_WXHWND(parent->MacGetTopLevelWindowRef()) ,
50 &bounds , "\p" , true , 0 , 0 , 100,
b45ed7a2
VZ
51 kControlScrollBarLiveProc , (long) this) ;
52
facd6764 53 wxASSERT_MSG( (ControlRef) m_macControl != NULL , wxT("No valid mac control") ) ;
519cb848 54
facd6764 55 ::SetControlAction( (ControlRef) m_macControl , wxMacLiveScrollbarActionUPP ) ;
e9576ca5 56
facd6764 57 MacPostControlCreate(pos,size) ;
e9576ca5 58
b45ed7a2 59 return TRUE;
e9576ca5
SC
60}
61
62wxScrollBar::~wxScrollBar()
63{
64}
65
66void wxScrollBar::SetThumbPosition(int viewStart)
67{
facd6764 68 ::SetControl32BitValue( (ControlRef) m_macControl , viewStart ) ;
e9576ca5
SC
69}
70
71int wxScrollBar::GetThumbPosition() const
72{
facd6764 73 return ::GetControl32BitValue( (ControlRef) m_macControl ) ;
e9576ca5
SC
74}
75
76void wxScrollBar::SetScrollbar(int position, int thumbSize, int range, int pageSize,
77 bool refresh)
78{
4b1c4c21
SC
79 m_pageSize = pageSize;
80 m_viewSize = thumbSize;
e9576ca5
SC
81 m_objectSize = range;
82
e40298d5 83 int range1 = wxMax((m_objectSize - m_viewSize), 0) ;
519cb848 84
facd6764
SC
85 SetControl32BitMaximum( (ControlRef) m_macControl , range1 ) ;
86 SetControl32BitMinimum( (ControlRef) m_macControl , 0 ) ;
87 SetControl32BitValue( (ControlRef) m_macControl , position ) ;
519cb848
SC
88
89 if ( UMAGetAppearanceVersion() >= 0x0110 )
90 {
a49afa93
SC
91 if ( SetControlViewSize != (void*) kUnresolvedCFragSymbolAddress )
92 {
facd6764 93 SetControlViewSize( (ControlRef) m_macControl , m_viewSize ) ;
a49afa93 94 }
519cb848 95 }
66a09d47
SC
96 if ( refresh )
97 MacRedrawControl() ;
e9576ca5
SC
98}
99
100
101void wxScrollBar::Command(wxCommandEvent& event)
102{
103 SetThumbPosition(event.m_commandInt);
104 ProcessCommand(event);
105}
106
4b26b60f 107void wxScrollBar::MacHandleControlClick( WXWidget control , wxInt16 controlpart , bool mouseStillDown )
519cb848 108{
facd6764 109 if ( (ControlRef) m_macControl == NULL )
e40298d5
JS
110 return ;
111
facd6764
SC
112 int position = GetControl32BitValue( (ControlRef) m_macControl) ;
113 int minPos = GetControl32BitMinimum( (ControlRef) m_macControl) ;
114 int maxPos = GetControl32BitMaximum( (ControlRef) m_macControl) ;
e40298d5
JS
115
116 wxEventType scrollEvent = wxEVT_NULL;
56fc3fa5 117 int nScrollInc = 0;
e40298d5 118
4b26b60f
SC
119 // all events have already been reported during mouse down, except for THUMBRELEASE
120 if ( !mouseStillDown && controlpart !=kControlIndicatorPart )
121 return ;
122
e40298d5
JS
123 switch( controlpart )
124 {
125 case kControlUpButtonPart :
4b1c4c21 126 nScrollInc = -1;
519cb848 127 scrollEvent = wxEVT_SCROLL_LINEUP;
e40298d5
JS
128 break ;
129 case kControlDownButtonPart :
4b1c4c21 130 nScrollInc = 1;
519cb848 131 scrollEvent = wxEVT_SCROLL_LINEDOWN;
e40298d5
JS
132 break ;
133 case kControlPageUpPart :
4b1c4c21 134 nScrollInc = -m_pageSize;
519cb848 135 scrollEvent = wxEVT_SCROLL_PAGEUP;
e40298d5
JS
136 break ;
137 case kControlPageDownPart :
4b1c4c21 138 nScrollInc = m_pageSize;
519cb848 139 scrollEvent = wxEVT_SCROLL_PAGEDOWN;
e40298d5
JS
140 break ;
141 case kControlIndicatorPart :
519cb848 142 nScrollInc = 0 ;
4b26b60f
SC
143 if ( mouseStillDown )
144 scrollEvent = wxEVT_SCROLL_THUMBTRACK;
145 else
146 scrollEvent = wxEVT_SCROLL_THUMBRELEASE;
e40298d5
JS
147 break ;
148 default :
149 wxFAIL_MSG(wxT("illegal scrollbar selector"));
150 break ;
151 }
152
153 int new_pos = position + nScrollInc;
154
155 if (new_pos < minPos)
156 new_pos = minPos;
157 if (new_pos > maxPos)
158 new_pos = maxPos;
159 if ( nScrollInc )
160 SetThumbPosition(new_pos);
161
162 wxScrollEvent event(scrollEvent, m_windowId);
163 if ( m_windowStyle & wxHORIZONTAL )
164 {
165 event.SetOrientation( wxHORIZONTAL ) ;
166 }
167 else
168 {
169 event.SetOrientation( wxVERTICAL ) ;
170 }
171 event.SetPosition(new_pos);
172 event.SetEventObject( this );
173 wxWindow* window = GetParent() ;
174 if (window && window->MacIsWindowScrollbar(this) )
175 {
176 // this is hardcoded
177 window->MacOnScroll(event);
178 }
179 else
180 GetEventHandler()->ProcessEvent(event);
519cb848
SC
181}
182