]>
Commit | Line | Data |
---|---|---|
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 | ||
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 |
27 | IMPLEMENT_DYNAMIC_CLASS(wxScrollBar, wxControl) |
28 | ||
169935ad SC |
29 | BEGIN_EVENT_TABLE(wxScrollBar, wxControl) |
30 | END_EVENT_TABLE() | |
31 | ||
2f1ae414 | 32 | #endif |
e9576ca5 | 33 | |
519cb848 SC |
34 | extern ControlActionUPP wxMacLiveScrollbarActionUPP ; |
35 | ||
e9576ca5 SC |
36 | // Scrollbar |
37 | bool 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 | 48 | Rect bounds = wxMacGetBoundsForControl( this , pos , size ) ; |
b45ed7a2 | 49 | |
21fd5529 | 50 | m_peer = new wxMacControl() ; |
4c37f124 | 51 | verify_noerr ( CreateScrollBarControl( MAC_WXHWND(parent->MacGetTopLevelWindowRef()) , &bounds , |
5ca0d812 | 52 | 0 , 0 , 100 , 1 , true /* liveTracking */ , wxMacLiveScrollbarActionUPP , m_peer->GetControlRefAddr() ) ); |
21fd5529 | 53 | |
e9576ca5 | 54 | |
facd6764 | 55 | MacPostControlCreate(pos,size) ; |
e9576ca5 | 56 | |
b45ed7a2 | 57 | return TRUE; |
e9576ca5 SC |
58 | } |
59 | ||
60 | wxScrollBar::~wxScrollBar() | |
61 | { | |
62 | } | |
63 | ||
64 | void wxScrollBar::SetThumbPosition(int viewStart) | |
65 | { | |
5ca0d812 | 66 | m_peer->SetValue( viewStart ) ; |
e9576ca5 SC |
67 | } |
68 | ||
69 | int wxScrollBar::GetThumbPosition() const | |
70 | { | |
5ca0d812 | 71 | return m_peer->GetValue() ; |
e9576ca5 SC |
72 | } |
73 | ||
74 | void wxScrollBar::SetScrollbar(int position, int thumbSize, int range, int pageSize, | |
75 | bool refresh) | |
76 | { | |
4b1c4c21 SC |
77 | m_pageSize = pageSize; |
78 | m_viewSize = thumbSize; | |
e9576ca5 SC |
79 | m_objectSize = range; |
80 | ||
4c37f124 | 81 | int range1 = wxMax((m_objectSize - m_viewSize), 0) ; |
519cb848 | 82 | |
5ca0d812 SC |
83 | m_peer->SetMaximum( range1 ) ; |
84 | m_peer->SetMinimum( 0 ) ; | |
85 | m_peer->SetValue( position ) ; | |
86 | m_peer->SetViewSize( m_viewSize ) ; | |
519cb848 | 87 | |
66a09d47 SC |
88 | if ( refresh ) |
89 | MacRedrawControl() ; | |
e9576ca5 SC |
90 | } |
91 | ||
92 | ||
93 | void wxScrollBar::Command(wxCommandEvent& event) | |
94 | { | |
95 | SetThumbPosition(event.m_commandInt); | |
96 | ProcessCommand(event); | |
97 | } | |
98 | ||
4b26b60f | 99 | void wxScrollBar::MacHandleControlClick( WXWidget control , wxInt16 controlpart , bool mouseStillDown ) |
519cb848 | 100 | { |
5ca0d812 SC |
101 | int position = m_peer->GetValue() ; |
102 | int minPos = m_peer->GetMinimum() ; | |
103 | int maxPos = m_peer->GetMaximum() ; | |
e40298d5 JS |
104 | |
105 | wxEventType scrollEvent = wxEVT_NULL; | |
56fc3fa5 | 106 | int nScrollInc = 0; |
e40298d5 | 107 | |
4b26b60f SC |
108 | // all events have already been reported during mouse down, except for THUMBRELEASE |
109 | if ( !mouseStillDown && controlpart !=kControlIndicatorPart ) | |
110 | return ; | |
111 | ||
e40298d5 JS |
112 | switch( controlpart ) |
113 | { | |
114 | case kControlUpButtonPart : | |
4b1c4c21 | 115 | nScrollInc = -1; |
519cb848 | 116 | scrollEvent = wxEVT_SCROLL_LINEUP; |
e40298d5 JS |
117 | break ; |
118 | case kControlDownButtonPart : | |
4b1c4c21 | 119 | nScrollInc = 1; |
519cb848 | 120 | scrollEvent = wxEVT_SCROLL_LINEDOWN; |
e40298d5 JS |
121 | break ; |
122 | case kControlPageUpPart : | |
4b1c4c21 | 123 | nScrollInc = -m_pageSize; |
519cb848 | 124 | scrollEvent = wxEVT_SCROLL_PAGEUP; |
e40298d5 JS |
125 | break ; |
126 | case kControlPageDownPart : | |
4b1c4c21 | 127 | nScrollInc = m_pageSize; |
519cb848 | 128 | scrollEvent = wxEVT_SCROLL_PAGEDOWN; |
e40298d5 JS |
129 | break ; |
130 | case kControlIndicatorPart : | |
519cb848 | 131 | nScrollInc = 0 ; |
4b26b60f SC |
132 | if ( mouseStillDown ) |
133 | scrollEvent = wxEVT_SCROLL_THUMBTRACK; | |
134 | else | |
135 | scrollEvent = wxEVT_SCROLL_THUMBRELEASE; | |
e40298d5 JS |
136 | break ; |
137 | default : | |
138 | wxFAIL_MSG(wxT("illegal scrollbar selector")); | |
139 | break ; | |
140 | } | |
141 | ||
142 | int new_pos = position + nScrollInc; | |
143 | ||
144 | if (new_pos < minPos) | |
145 | new_pos = minPos; | |
146 | if (new_pos > maxPos) | |
147 | new_pos = maxPos; | |
148 | if ( nScrollInc ) | |
149 | SetThumbPosition(new_pos); | |
150 | ||
151 | wxScrollEvent event(scrollEvent, m_windowId); | |
152 | if ( m_windowStyle & wxHORIZONTAL ) | |
153 | { | |
154 | event.SetOrientation( wxHORIZONTAL ) ; | |
155 | } | |
156 | else | |
157 | { | |
158 | event.SetOrientation( wxVERTICAL ) ; | |
159 | } | |
160 | event.SetPosition(new_pos); | |
161 | event.SetEventObject( this ); | |
162 | wxWindow* window = GetParent() ; | |
163 | if (window && window->MacIsWindowScrollbar(this) ) | |
164 | { | |
165 | // this is hardcoded | |
166 | window->MacOnScroll(event); | |
167 | } | |
168 | else | |
169 | GetEventHandler()->ProcessEvent(event); | |
519cb848 SC |
170 | } |
171 | ||
4c37f124 SC |
172 | wxInt32 wxScrollBar::MacControlHit( WXEVENTHANDLERREF handler , WXEVENTREF mevent ) |
173 | { | |
5ca0d812 SC |
174 | int position = m_peer->GetValue() ; |
175 | int minPos = m_peer->GetMinimum() ; | |
176 | int maxPos = m_peer->GetMaximum() ; | |
4c37f124 SC |
177 | |
178 | wxEventType scrollEvent = wxEVT_NULL; | |
179 | int nScrollInc = 0; | |
180 | ||
181 | wxMacCarbonEvent cEvent( (EventRef) mevent ) ; | |
182 | ControlPartCode controlpart = cEvent.GetParameter<ControlPartCode>(kEventParamControlPart,typeControlPartCode) ; | |
183 | ||
184 | // all events have already been reported during mouse down, except for THUMBRELEASE | |
185 | if ( controlpart !=kControlIndicatorPart ) | |
186 | return eventNotHandledErr ; | |
187 | ||
188 | switch( controlpart ) | |
189 | { | |
190 | case kControlIndicatorPart : | |
191 | nScrollInc = 0 ; | |
192 | scrollEvent = wxEVT_SCROLL_THUMBRELEASE; | |
193 | break ; | |
194 | default : | |
195 | wxFAIL_MSG(wxT("illegal scrollbar selector")); | |
196 | break ; | |
197 | } | |
198 | ||
199 | int new_pos = position + nScrollInc; | |
200 | ||
201 | if (new_pos < minPos) | |
202 | new_pos = minPos; | |
203 | if (new_pos > maxPos) | |
204 | new_pos = maxPos; | |
205 | if ( nScrollInc ) | |
206 | SetThumbPosition(new_pos); | |
207 | ||
208 | wxScrollEvent event(scrollEvent, m_windowId); | |
209 | if ( m_windowStyle & wxHORIZONTAL ) | |
210 | { | |
211 | event.SetOrientation( wxHORIZONTAL ) ; | |
212 | } | |
213 | else | |
214 | { | |
215 | event.SetOrientation( wxVERTICAL ) ; | |
216 | } | |
217 | event.SetPosition(new_pos); | |
218 | event.SetEventObject( this ); | |
219 | wxWindow* window = GetParent() ; | |
220 | if (window && window->MacIsWindowScrollbar(this) ) | |
221 | { | |
222 | // this is hardcoded | |
223 | window->MacOnScroll(event); | |
224 | } | |
225 | else | |
226 | GetEventHandler()->ProcessEvent(event); | |
227 | return noErr ; | |
228 | } | |
229 | ||
230 |