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