]> git.saurik.com Git - wxWidgets.git/blame - src/mac/carbon/scrolbar.cpp
removed code refreshing toolbar on every MDI child move -- no idea why was it there...
[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
65571936 9// Licence: wxWindows licence
e9576ca5
SC
10/////////////////////////////////////////////////////////////////////////////
11
3d1a4878 12#include "wx/wxprec.h"
d8c736e5 13
8140eec9
SC
14#ifndef WX_PRECOMP
15 #include "wx/intl.h"
16 #include "wx/log.h"
17#endif // WX_PRECOMP
18
e9576ca5 19#include "wx/scrolbar.h"
519cb848 20#include "wx/mac/uma.h"
e9576ca5 21
e9576ca5
SC
22IMPLEMENT_DYNAMIC_CLASS(wxScrollBar, wxControl)
23
169935ad
SC
24BEGIN_EVENT_TABLE(wxScrollBar, wxControl)
25END_EVENT_TABLE()
26
4792d192
DS
27
28bool wxScrollBar::Create(wxWindow *parent,
29 wxWindowID id,
30 const wxPoint& pos,
31 const wxSize& size,
32 long style,
33 const wxValidator& validator,
34 const wxString& name)
e9576ca5 35{
4792d192
DS
36 m_macIsUserPane = false ;
37
b45ed7a2 38 if ( !wxControl::Create(parent, id, pos, size, style, validator, name) )
4792d192 39 return false;
b45ed7a2 40
facd6764 41 Rect bounds = wxMacGetBoundsForControl( this , pos , size ) ;
b45ed7a2 42
b905d6cc 43 m_peer = new wxMacControl(this) ;
4792d192 44 verify_noerr( CreateScrollBarControl( MAC_WXHWND(parent->MacGetTopLevelWindowRef()) , &bounds ,
cd780027 45 0 , 0 , 100 , 1 , true /* liveTracking */ , GetwxMacLiveScrollbarActionProc() , m_peer->GetControlRefAddr() ) );
e9576ca5 46
4792d192 47 MacPostControlCreate( pos, size ) ;
e9576ca5 48
4792d192 49 return true;
e9576ca5
SC
50}
51
52wxScrollBar::~wxScrollBar()
53{
54}
55
56void wxScrollBar::SetThumbPosition(int viewStart)
57{
5ca0d812 58 m_peer->SetValue( viewStart ) ;
e9576ca5
SC
59}
60
61int wxScrollBar::GetThumbPosition() const
62{
5ca0d812 63 return m_peer->GetValue() ;
e9576ca5
SC
64}
65
4792d192 66void wxScrollBar::SetScrollbar(int position, int thumbSize, int range, int pageSize, bool refresh)
e9576ca5 67{
4b1c4c21
SC
68 m_pageSize = pageSize;
69 m_viewSize = thumbSize;
e9576ca5
SC
70 m_objectSize = range;
71
4c37f124 72 int range1 = wxMax((m_objectSize - m_viewSize), 0) ;
519cb848 73
5ca0d812
SC
74 m_peer->SetMaximum( range1 ) ;
75 m_peer->SetMinimum( 0 ) ;
76 m_peer->SetValue( position ) ;
77 m_peer->SetViewSize( m_viewSize ) ;
e9576ca5
SC
78}
79
e9576ca5
SC
80void wxScrollBar::Command(wxCommandEvent& event)
81{
687706f5 82 SetThumbPosition(event.GetInt());
e9576ca5
SC
83 ProcessCommand(event);
84}
85
4792d192 86void wxScrollBar::MacHandleControlClick( WXWidget control , wxInt16 controlpart , bool mouseStillDown )
519cb848 87{
5ca0d812
SC
88 int position = m_peer->GetValue() ;
89 int minPos = m_peer->GetMinimum() ;
90 int maxPos = m_peer->GetMaximum() ;
4792d192 91
e40298d5 92 wxEventType scrollEvent = wxEVT_NULL;
56fc3fa5 93 int nScrollInc = 0;
4792d192 94
4b26b60f 95 // all events have already been reported during mouse down, except for THUMBRELEASE
4792d192 96 if ( !mouseStillDown && controlpart != kControlIndicatorPart )
4b26b60f 97 return ;
4792d192
DS
98
99 switch ( controlpart )
e40298d5
JS
100 {
101 case kControlUpButtonPart :
4b1c4c21 102 nScrollInc = -1;
519cb848 103 scrollEvent = wxEVT_SCROLL_LINEUP;
e40298d5 104 break ;
4792d192 105
e40298d5 106 case kControlDownButtonPart :
4b1c4c21 107 nScrollInc = 1;
519cb848 108 scrollEvent = wxEVT_SCROLL_LINEDOWN;
e40298d5 109 break ;
4792d192 110
e40298d5 111 case kControlPageUpPart :
4b1c4c21 112 nScrollInc = -m_pageSize;
519cb848 113 scrollEvent = wxEVT_SCROLL_PAGEUP;
e40298d5 114 break ;
4792d192 115
e40298d5 116 case kControlPageDownPart :
4b1c4c21 117 nScrollInc = m_pageSize;
519cb848 118 scrollEvent = wxEVT_SCROLL_PAGEDOWN;
e40298d5 119 break ;
4792d192 120
e40298d5 121 case kControlIndicatorPart :
519cb848 122 nScrollInc = 0 ;
4b26b60f
SC
123 if ( mouseStillDown )
124 scrollEvent = wxEVT_SCROLL_THUMBTRACK;
125 else
126 scrollEvent = wxEVT_SCROLL_THUMBRELEASE;
e40298d5 127 break ;
4792d192 128
e40298d5
JS
129 default :
130 wxFAIL_MSG(wxT("illegal scrollbar selector"));
131 break ;
132 }
4792d192 133
e40298d5 134 int new_pos = position + nScrollInc;
4792d192 135
e40298d5
JS
136 if (new_pos < minPos)
137 new_pos = minPos;
4792d192 138 else if (new_pos > maxPos)
e40298d5 139 new_pos = maxPos;
4792d192 140
e40298d5
JS
141 if ( nScrollInc )
142 SetThumbPosition(new_pos);
4792d192 143
e40298d5
JS
144 wxScrollEvent event(scrollEvent, m_windowId);
145 if ( m_windowStyle & wxHORIZONTAL )
e40298d5 146 event.SetOrientation( wxHORIZONTAL ) ;
e40298d5 147 else
e40298d5 148 event.SetOrientation( wxVERTICAL ) ;
4792d192 149
e40298d5
JS
150 event.SetPosition(new_pos);
151 event.SetEventObject( this );
4792d192 152
e40298d5
JS
153 wxWindow* window = GetParent() ;
154 if (window && window->MacIsWindowScrollbar(this) )
e40298d5
JS
155 // this is hardcoded
156 window->MacOnScroll(event);
e40298d5
JS
157 else
158 GetEventHandler()->ProcessEvent(event);
519cb848
SC
159}
160
4792d192 161wxInt32 wxScrollBar::MacControlHit( WXEVENTHANDLERREF handler , WXEVENTREF mevent )
4c37f124 162{
5ca0d812
SC
163 int position = m_peer->GetValue() ;
164 int minPos = m_peer->GetMinimum() ;
165 int maxPos = m_peer->GetMaximum() ;
4792d192 166
4c37f124
SC
167 wxEventType scrollEvent = wxEVT_NULL;
168 int nScrollInc = 0;
4792d192 169
4c37f124 170 wxMacCarbonEvent cEvent( (EventRef) mevent ) ;
4792d192
DS
171 ControlPartCode controlpart = cEvent.GetParameter<ControlPartCode>(kEventParamControlPart, typeControlPartCode) ;
172
4c37f124 173 // all events have already been reported during mouse down, except for THUMBRELEASE
4792d192 174 if ( controlpart != kControlIndicatorPart )
4c37f124 175 return eventNotHandledErr ;
4792d192
DS
176
177 switch ( controlpart )
4c37f124
SC
178 {
179 case kControlIndicatorPart :
180 nScrollInc = 0 ;
181 scrollEvent = wxEVT_SCROLL_THUMBRELEASE;
182 break ;
4792d192 183
4c37f124
SC
184 default :
185 wxFAIL_MSG(wxT("illegal scrollbar selector"));
186 break ;
187 }
4792d192 188
4c37f124 189 int new_pos = position + nScrollInc;
4792d192 190
4c37f124
SC
191 if (new_pos < minPos)
192 new_pos = minPos;
4792d192 193 else if (new_pos > maxPos)
4c37f124 194 new_pos = maxPos;
4792d192 195
4c37f124
SC
196 if ( nScrollInc )
197 SetThumbPosition(new_pos);
4792d192 198
4c37f124
SC
199 wxScrollEvent event(scrollEvent, m_windowId);
200 if ( m_windowStyle & wxHORIZONTAL )
4792d192 201 event.SetOrientation( wxHORIZONTAL );
4c37f124 202 else
4792d192
DS
203 event.SetOrientation( wxVERTICAL );
204
4c37f124
SC
205 event.SetPosition(new_pos);
206 event.SetEventObject( this );
207 wxWindow* window = GetParent() ;
208 if (window && window->MacIsWindowScrollbar(this) )
4c37f124
SC
209 // this is hardcoded
210 window->MacOnScroll(event);
4c37f124
SC
211 else
212 GetEventHandler()->ProcessEvent(event);
4792d192 213
4c37f124
SC
214 return noErr ;
215}