124 || (iLandscapeScrolling != aLandscapeScrolling); // different scrolling direction |
124 || (iLandscapeScrolling != aLandscapeScrolling); // different scrolling direction |
125 |
125 |
126 iViewSize = aViewSize; |
126 iViewSize = aViewSize; |
127 iLandscapeScrolling = aLandscapeScrolling; |
127 iLandscapeScrolling = aLandscapeScrolling; |
128 iHandlePosition.SetXY(0,0); |
128 iHandlePosition.SetXY(0,0); |
|
129 iHandlePos = 0.0; |
129 |
130 |
130 if(iLandscapeScrolling) |
131 if(iLandscapeScrolling) |
131 { |
132 { |
132 iTotalLength = iTotalSize.iWidth - iViewSize.iWidth; |
133 iTotalLength = iTotalSize.iWidth - iViewSize.iWidth; |
133 } |
134 } |
151 { |
152 { |
152 if(iLandscapeScrolling) |
153 if(iLandscapeScrolling) |
153 { |
154 { |
154 if (AknLayoutUtils::LayoutMirrored()) |
155 if (AknLayoutUtils::LayoutMirrored()) |
155 { |
156 { |
156 iHandlePosition.iX = (iScrollLength) * (1.0 - aPosition.iX / TReal(iTotalLength)); |
157 iHandlePos = 1.0 - (TReal(aPosition.iX) / TReal(iTotalLength)); |
157 } |
158 } |
158 else |
159 else |
159 { |
160 { |
160 iHandlePosition.iX = (iScrollLength) * (aPosition.iX / TReal(iTotalLength)); |
161 iHandlePos = TReal(aPosition.iX) / TReal(iTotalLength); |
161 } |
162 } |
162 } |
163 } |
163 else |
164 else |
164 { |
165 { |
165 iHandlePosition.iY = (iScrollLength) * (aPosition.iY / TReal(iTotalLength)); |
166 iHandlePos = TReal(aPosition.iY) / TReal(iTotalLength); |
166 } |
167 } |
167 CheckHandlePosition( EFalse ); |
168 CheckHandlePosition( EFalse ); |
168 } |
169 } |
169 } |
170 } |
170 |
171 |
184 TBool CHgScrollbar::HandleScrollBarPointerEvent( const TPointerEvent& aEvent ) |
185 TBool CHgScrollbar::HandleScrollBarPointerEvent( const TPointerEvent& aEvent ) |
185 { |
186 { |
186 TBool ret = EFalse; |
187 TBool ret = EFalse; |
187 // Quick and dirty hack, remove when logic for fetching the correct drag rect is available |
188 // Quick and dirty hack, remove when logic for fetching the correct drag rect is available |
188 TRect dragArea( iScrollbarRect ); |
189 TRect dragArea( iScrollbarRect ); |
189 dragArea.iBr.iX += KScrollAreaOffset; |
190 if (iLandscapeScrolling) |
190 dragArea.iTl.iX -= KScrollAreaOffset; |
191 { |
191 |
192 dragArea.iBr.iY += KScrollAreaOffset; |
|
193 dragArea.iTl.iY -= KScrollAreaOffset; |
|
194 } |
|
195 else |
|
196 { |
|
197 dragArea.iBr.iX += KScrollAreaOffset; |
|
198 dragArea.iTl.iX -= KScrollAreaOffset; |
|
199 } |
|
200 |
192 // Start drag |
201 // Start drag |
193 if( aEvent.iType == TPointerEvent::EButton1Down && dragArea.Contains(aEvent.iPosition)) |
202 if( aEvent.iType == TPointerEvent::EButton1Down && dragArea.Contains(aEvent.iPosition)) |
194 { |
203 { |
195 TSize size(iHandleSize); |
204 TSize size = iHandleSize; |
196 size.iWidth += KScrollAreaOffset*2; |
205 TRect handleRect; |
197 TRect handleRect( dragArea.iTl + iHandlePosition, size ); |
206 if (iLandscapeScrolling) |
|
207 { |
|
208 size.iHeight += KScrollAreaOffset*2; |
|
209 handleRect = TRect( dragArea.iTl + TPoint(iHandlePos*iScrollLength, 0), size ); |
|
210 } |
|
211 else |
|
212 { |
|
213 size.iWidth += KScrollAreaOffset*2; |
|
214 handleRect = TRect( dragArea.iTl + TPoint(0, iHandlePos*iScrollLength), size ); |
|
215 } |
198 iDragging = handleRect.Contains( aEvent.iPosition ); |
216 iDragging = handleRect.Contains( aEvent.iPosition ); |
199 iPrevDrag = aEvent.iPosition; |
217 iPrevDrag = aEvent.iPosition; |
200 iHandler = ret = ETrue; |
218 iHandler = ret = ETrue; |
201 CheckHandlePosition( !iStatic ); |
219 CheckHandlePosition( !iStatic ); |
202 } |
220 } |
206 { |
224 { |
207 if( iDragging ) |
225 if( iDragging ) |
208 { |
226 { |
209 if(iLandscapeScrolling) |
227 if(iLandscapeScrolling) |
210 { |
228 { |
211 iHandlePosition.iX -= iPrevDrag.iX - aEvent.iPosition.iX; |
229 iHandlePos -= (iPrevDrag.iX - aEvent.iPosition.iX)/TReal(iScrollLength); |
212 } |
230 } |
213 else |
231 else |
214 { |
232 { |
215 iHandlePosition.iY -= iPrevDrag.iY - aEvent.iPosition.iY; |
233 iHandlePos -= (iPrevDrag.iY - aEvent.iPosition.iY)/TReal(iScrollLength); |
216 } |
234 } |
217 CheckHandlePosition( !iStatic ); |
235 CheckHandlePosition( !iStatic ); |
218 |
236 |
219 iPrevDrag = aEvent.iPosition; |
237 iPrevDrag = aEvent.iPosition; |
220 } |
238 } |
225 if( aEvent.iType == TPointerEvent::EButton1Up && iHandler) |
243 if( aEvent.iType == TPointerEvent::EButton1Up && iHandler) |
226 { |
244 { |
227 if(!iDragging) |
245 if(!iDragging) |
228 { |
246 { |
229 TBool below = iLandscapeScrolling ? |
247 TBool below = iLandscapeScrolling ? |
230 aEvent.iPosition.iX > iHandlePosition.iX |
248 aEvent.iPosition.iX > iHandlePos*iScrollLength |
231 : aEvent.iPosition.iY > iHandlePosition.iY; |
249 : aEvent.iPosition.iY > iHandlePos*iScrollLength; |
232 iHandlePosition += below ? iHandleSize.AsPoint() : -iHandleSize.AsPoint(); |
250 if(below) |
|
251 { |
|
252 iHandlePos += iPageSize; |
|
253 } |
|
254 else |
|
255 { |
|
256 iHandlePos -= iPageSize; |
|
257 } |
233 } |
258 } |
234 CheckHandlePosition( !iStatic ); |
259 CheckHandlePosition( !iStatic ); |
235 iHandler = iDragging = EFalse; |
260 iHandler = iDragging = EFalse; |
236 ret = ETrue; |
261 ret = ETrue; |
237 } |
262 } |
296 void CHgScrollbar::CheckHandlePosition( TBool aReportChange ) |
321 void CHgScrollbar::CheckHandlePosition( TBool aReportChange ) |
297 { |
322 { |
298 |
323 |
299 if(iLandscapeScrolling) |
324 if(iLandscapeScrolling) |
300 { |
325 { |
301 iHandlePosition.iY = 0; |
326 if(iHandlePos < 0.0 ) |
302 if(iHandlePosition.iX < 0 ) |
327 iHandlePos = 0.0; |
303 iHandlePosition.iX = 0; |
328 if(iHandlePos > 1.0) |
304 if(iHandlePosition.iX > iScrollLength) |
329 iHandlePos = 1; |
305 iHandlePosition.iX = iScrollLength; |
330 |
|
331 iHandlePosition.SetXY(iHandlePos*iScrollLength, 0); |
306 } |
332 } |
307 else |
333 else |
308 { |
334 { |
309 iHandlePosition.iX = 0; |
335 if(iHandlePos < 0.0 ) |
310 if(iHandlePosition.iY < 0 ) |
336 iHandlePos = 0.0; |
311 iHandlePosition.iY = 0; |
337 if(iHandlePos > 1) |
312 if(iHandlePosition.iY > iScrollLength) |
338 iHandlePos = 1.0; |
313 iHandlePosition.iY = iScrollLength; |
339 |
|
340 iHandlePosition.SetXY(0, iHandlePos*iScrollLength); |
314 } |
341 } |
315 if( aReportChange ) |
342 if( aReportChange ) |
316 { |
343 { |
317 TPoint pos (iViewSize.iWidth/2, iViewSize.iHeight/2); |
344 TPoint pos (iViewSize.iWidth/2, iViewSize.iHeight/2); |
318 if(iLandscapeScrolling) |
345 if(iLandscapeScrolling) |
319 { |
346 { |
320 if (AknLayoutUtils::LayoutMirrored()) |
347 if (AknLayoutUtils::LayoutMirrored()) |
321 { |
348 { |
322 pos.iX += (1.0 - iHandlePosition.iX / TReal(iScrollLength)) * (iTotalLength); |
349 pos.iX += (1.0 - iHandlePos) * iTotalLength; |
323 } |
350 } |
324 else |
351 else |
325 { |
352 { |
326 pos.iX += (iHandlePosition.iX / TReal(iScrollLength)) * (iTotalLength); |
353 pos.iX += iHandlePos * iTotalLength; |
327 } |
354 } |
328 } |
355 } |
329 else |
356 else |
330 { |
357 { |
331 pos.iY += (iHandlePosition.iY / TReal(iScrollLength)) * (iTotalLength); |
358 pos.iY += iHandlePos * iTotalLength; |
332 } |
359 } |
333 |
360 |
334 iObserver.ScrollBarPositionChanged( pos ); |
361 iObserver.ScrollBarPositionChanged( pos ); |
335 } |
362 } |
336 } |
363 } |
352 CreateIconL(iScrollbarHandleBg, iScrollbarRect.Size()); |
379 CreateIconL(iScrollbarHandleBg, iScrollbarRect.Size()); |
353 } |
380 } |
354 |
381 |
355 TReal xFactor = iScrollbarRect.Width()/TReal(iTotalSize.iWidth); |
382 TReal xFactor = iScrollbarRect.Width()/TReal(iTotalSize.iWidth); |
356 TReal yFactor = iScrollbarRect.Height()/TReal(iTotalSize.iHeight); |
383 TReal yFactor = iScrollbarRect.Height()/TReal(iTotalSize.iHeight); |
357 |
384 |
358 iHandleSize = TSize ( iViewSize.iWidth * xFactor, iViewSize.iHeight * yFactor ); |
385 TReal handleSizeWidth = iViewSize.iWidth * xFactor; |
|
386 TReal handleSizeHeight = iViewSize.iHeight * yFactor; |
359 |
387 |
360 if(iLandscapeScrolling) |
388 if(iLandscapeScrolling) |
361 { |
389 { |
362 TInt min = 2*iHandleSize.iHeight; |
390 iPageSize = TReal(iViewSize.iWidth) / TReal(iTotalSize.iWidth - (iTotalSize.iWidth % iViewSize.iWidth) ); |
363 if( iHandleSize.iWidth < min ) |
391 TReal min = 2 * handleSizeHeight; |
364 { |
392 if( handleSizeWidth < min ) |
365 iHandleSize.iWidth = min; |
393 { |
366 } |
394 handleSizeWidth = min; |
367 iScrollLength = iScrollbarRect.Width() - iHandleSize.iWidth; |
395 } |
|
396 iScrollLength = TReal(iScrollbarRect.Width()) - handleSizeWidth; |
368 } |
397 } |
369 else |
398 else |
370 { |
399 { |
371 TInt min = 2*iHandleSize.iWidth; |
400 iPageSize = TReal(iViewSize.iHeight) / TReal(iTotalSize.iHeight - (iTotalSize.iHeight % iViewSize.iHeight) ); |
372 if( iHandleSize.iHeight < min ) |
401 TReal min = 2 * handleSizeWidth; |
373 { |
402 if( handleSizeHeight < min ) |
374 iHandleSize.iHeight = min; |
403 { |
375 } |
404 handleSizeHeight = min; |
376 iScrollLength = iScrollbarRect.Height() - iHandleSize.iHeight; |
405 } |
377 } |
406 iScrollLength = TReal(iScrollbarRect.Height()) - handleSizeHeight; |
|
407 } |
|
408 |
|
409 iHandleSize = TSize(handleSizeWidth,handleSizeHeight); |
378 |
410 |
379 delete iScrollbarHandle; iScrollbarHandle = NULL; |
411 delete iScrollbarHandle; iScrollbarHandle = NULL; |
380 delete iScrollbarHandleSelected; iScrollbarHandleSelected = NULL; |
412 delete iScrollbarHandleSelected; iScrollbarHandleSelected = NULL; |
381 |
413 |
382 CreateIconL(iScrollbarHandle, iHandleSize ); |
414 CreateIconL(iScrollbarHandle, iHandleSize ); |