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