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