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