|
1 /* |
|
2 * Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * Version : %version: MM_44 % << Don't touch! Updated by Synergy at check-out. |
|
16 * |
|
17 */ |
|
18 |
|
19 #include <AknUtils.h> |
|
20 |
|
21 #include "mmdraweranimator.h" |
|
22 #include "mmlistboxitemdrawer.h" |
|
23 #include "mmfloatingitem.h" |
|
24 #include "mmwidgetcontainer.h" |
|
25 |
|
26 // ----------------------------------------------------------------------------- |
|
27 // |
|
28 // ----------------------------------------------------------------------------- |
|
29 // |
|
30 CMmDrawerAnimator::CMmDrawerAnimator( CMmListBoxItemDrawer& aDrawer ) : |
|
31 CActive( AknLayoutUtils::PenEnabled() |
|
32 ? EPriorityAbsoluteVeryLow |
|
33 : EPriorityAbsoluteRealTime8 ), iDrawer( aDrawer ), |
|
34 iLastNotedHighlight( KErrNotFound ), iLastNotedTopItem( KErrNotFound ), |
|
35 iLastNotedVerticalOffset( 0 ), |
|
36 iUsualAnimationFramesCount( AknLayoutUtils::PenEnabled() |
|
37 ? MmEffects::KUsualAnimationFramesCount |
|
38 : MmEffects::KUsualAnimationFramesCountNonTouch ), |
|
39 iPreparedForGarbage( EFalse ) |
|
40 { |
|
41 } |
|
42 |
|
43 // ----------------------------------------------------------------------------- |
|
44 // |
|
45 // ----------------------------------------------------------------------------- |
|
46 // |
|
47 CMmDrawerAnimator* CMmDrawerAnimator::NewLC( CMmListBoxItemDrawer& aDrawer ) |
|
48 { |
|
49 CMmDrawerAnimator* self = new ( ELeave ) CMmDrawerAnimator( aDrawer ); |
|
50 CleanupStack::PushL( self ); |
|
51 self->ConstructL(); |
|
52 return self; |
|
53 } |
|
54 |
|
55 // ----------------------------------------------------------------------------- |
|
56 // |
|
57 // ----------------------------------------------------------------------------- |
|
58 // |
|
59 CMmDrawerAnimator* CMmDrawerAnimator::NewL( CMmListBoxItemDrawer& aDrawer ) |
|
60 { |
|
61 CMmDrawerAnimator* self = CMmDrawerAnimator::NewLC( aDrawer ); |
|
62 CleanupStack::Pop( self ); |
|
63 return self; |
|
64 } |
|
65 |
|
66 // ----------------------------------------------------------------------------- |
|
67 // |
|
68 // ----------------------------------------------------------------------------- |
|
69 // |
|
70 void CMmDrawerAnimator::ConstructL() |
|
71 { |
|
72 User::LeaveIfError( iTimer.CreateLocal() ); // Initialize timer |
|
73 CActiveScheduler::Add( this ); // Add to scheduler |
|
74 } |
|
75 |
|
76 // ----------------------------------------------------------------------------- |
|
77 // |
|
78 // ----------------------------------------------------------------------------- |
|
79 // |
|
80 CMmDrawerAnimator::~CMmDrawerAnimator() |
|
81 { |
|
82 Cancel(); // Cancel any request, if outstanding |
|
83 iTimer.Close(); // Destroy the RTimer object |
|
84 // Delete instance variables if any |
|
85 } |
|
86 |
|
87 // ----------------------------------------------------------------------------- |
|
88 // |
|
89 // ----------------------------------------------------------------------------- |
|
90 // |
|
91 void CMmDrawerAnimator::DoCancel() |
|
92 { |
|
93 iTimer.Cancel(); |
|
94 if( iDrawer.GetFloatingItemCount() == 0 ) |
|
95 { |
|
96 TRAP_IGNORE(TriggerMoveItemL()); |
|
97 } |
|
98 } |
|
99 |
|
100 // ----------------------------------------------------------------------------- |
|
101 // |
|
102 // ----------------------------------------------------------------------------- |
|
103 // |
|
104 void CMmDrawerAnimator::RunL() |
|
105 { |
|
106 if( iPreparedForGarbage ) |
|
107 { |
|
108 return; |
|
109 } |
|
110 |
|
111 if( iDrawer.GetFloatingItemCount() > 0 ) |
|
112 { |
|
113 TRect refreshRect; |
|
114 for( int i = 0; i < iDrawer.GetFloatingItemCount(); i++ ) |
|
115 { |
|
116 TMmFloatingItem& current = iDrawer.GetFloatingItemAtIndex( i ); |
|
117 TSize itemSize = iDrawer.GetItemSize(current.GetDrawnItemIndex(), EFalse); |
|
118 |
|
119 TRect beforeRect( current.GetItemPosition(), itemSize ); |
|
120 current.MakeStep(); |
|
121 TRect afterRect( current.GetItemPosition(), itemSize ); |
|
122 |
|
123 if( ( current.GetFloatingItemType() == EDrag |
|
124 && iDrawer.GetFloatingItemIndex( EDragStart ) == KErrNotFound ) |
|
125 || current.GetFloatingItemType() == EDragStart ) |
|
126 { |
|
127 TInt dragTrail = iDrawer.GetFloatingItemIndex( EPostDragRefreshItem ); |
|
128 if( dragTrail != KErrNotFound ) |
|
129 { |
|
130 refreshRect = ( refreshRect == TRect() ) ? beforeRect : refreshRect; |
|
131 refreshRect.BoundingRect( afterRect ); |
|
132 static_cast<CMmWidgetContainer*> ( iDrawer.Widget()->Parent() )-> |
|
133 SetAllowMove( EFalse ); |
|
134 } |
|
135 } |
|
136 else if( ( current.GetFloatingItemType() == EDrag |
|
137 && iDrawer.GetFloatingItemIndex( EDragStart ) == KErrNotFound ) |
|
138 || current.GetFloatingItemType() != EDrag ) |
|
139 { |
|
140 refreshRect = (refreshRect == TRect() ) ? beforeRect : refreshRect; |
|
141 refreshRect.BoundingRect( beforeRect ); |
|
142 refreshRect.BoundingRect( afterRect ); |
|
143 } |
|
144 } |
|
145 const TInt highlightedItemIndex = iDrawer.Widget()->View()->CurrentItemIndex(); |
|
146 if( iLastNotedHighlight != highlightedItemIndex ) |
|
147 { |
|
148 TRect highlightedItemRect( |
|
149 iDrawer.Widget()->View()->ItemPos( highlightedItemIndex ), |
|
150 iDrawer.Widget()->View()->ItemSize( highlightedItemIndex ) ); |
|
151 refreshRect.BoundingRect( highlightedItemRect ); |
|
152 iLastNotedHighlight = highlightedItemIndex; |
|
153 } |
|
154 |
|
155 |
|
156 TInt currentVerticalOffset = static_cast<CMmWidgetContainer*>( |
|
157 iDrawer.Widget()->Parent() )->VerticalItemOffset(); |
|
158 |
|
159 if( iLastNotedTopItem != iDrawer.Widget()->TopItemIndex() |
|
160 || iLastNotedVerticalOffset != currentVerticalOffset ) |
|
161 { |
|
162 iDrawer.Widget()->DrawNow(); |
|
163 iLastNotedTopItem = iDrawer.Widget()->TopItemIndex(); |
|
164 iLastNotedVerticalOffset = currentVerticalOffset; |
|
165 } |
|
166 else |
|
167 { |
|
168 if( refreshRect != TRect() ) |
|
169 { |
|
170 TRect prev( iPreviousRefreshRect ); |
|
171 iPreviousRefreshRect = refreshRect; |
|
172 refreshRect.BoundingRect( prev ); |
|
173 |
|
174 // expand rect if non-touch |
|
175 refreshRect = TRect( AdjustRefreshRectToNonTouch( refreshRect ) ); |
|
176 |
|
177 // never draw on the outside of widget's view rectangle |
|
178 refreshRect.Intersection( iDrawer.Widget()->View()->ViewRect() ); |
|
179 |
|
180 iDrawer.Widget()->View()->Draw( &refreshRect ); |
|
181 } |
|
182 } |
|
183 } |
|
184 |
|
185 if( iDrawer.GetFloatingItemCount() > 0 ) |
|
186 { |
|
187 Trigger(); |
|
188 } |
|
189 else |
|
190 { |
|
191 TriggerMoveItemL(); |
|
192 Cancel(); |
|
193 |
|
194 #ifdef RD_UI_TRANSITION_EFFECTS_LIST |
|
195 if( iTransTfx && iTransTfxInternal->EffectsDisabled() ) |
|
196 { |
|
197 iTransTfx->EnableEffects( ETrue ); |
|
198 |
|
199 if( iTransTfx ) |
|
200 { |
|
201 iTransTfxInternal->Remove( MAknListBoxTfxInternal::EListEverything ); |
|
202 iDrawer.Widget()->DrawNow(); |
|
203 iTransTfxInternal->Draw( iDrawer.Widget()->Rect() ); |
|
204 } |
|
205 } |
|
206 #endif |
|
207 } |
|
208 } |
|
209 |
|
210 // ----------------------------------------------------------------------------- |
|
211 // |
|
212 // ----------------------------------------------------------------------------- |
|
213 // |
|
214 TRect CMmDrawerAnimator::AdjustRefreshRectToNonTouch( const TRect& aRefreshRect ) |
|
215 { |
|
216 TRect rect( aRefreshRect ); |
|
217 if( !AknLayoutUtils::PenEnabled() ) |
|
218 { |
|
219 TRect indicatorRect( iDrawer.GetIndicatorRect() ); |
|
220 TSize itemSize( iDrawer.GetItemSize( |
|
221 iDrawer.Widget()->CurrentItemIndex(), ETrue ) ); |
|
222 |
|
223 TInt horizontalMargin( ( indicatorRect.Width() - itemSize.iWidth ) / 2 ); |
|
224 TInt verticalMargin( ( indicatorRect.Height() - itemSize.iHeight ) / 2 ); |
|
225 rect.Grow(horizontalMargin, verticalMargin); |
|
226 } |
|
227 return rect; |
|
228 } |
|
229 |
|
230 // ----------------------------------------------------------------------------- |
|
231 // |
|
232 // ----------------------------------------------------------------------------- |
|
233 // |
|
234 TInt CMmDrawerAnimator::Trigger() |
|
235 { |
|
236 if( iPreparedForGarbage ) |
|
237 { |
|
238 return KErrCancel; |
|
239 } |
|
240 |
|
241 if( !IsActive() && iDrawer.GetFloatingItemCount() > 0 ) |
|
242 { |
|
243 #ifdef RD_UI_TRANSITION_EFFECTS_LIST |
|
244 iTransTfx = CAknListLoader::TfxApi( iDrawer.Gc() ); |
|
245 iTransTfxInternal = CAknListLoader::TfxApiInternal( iDrawer.Gc() ); |
|
246 |
|
247 if( iTransTfx && !iTransTfxInternal->EffectsDisabled() ) |
|
248 { |
|
249 iTransTfx->EnableEffects( EFalse ); |
|
250 |
|
251 if( iTransTfxInternal ) |
|
252 { |
|
253 iTransTfxInternal->Remove( MAknListBoxTfxInternal::EListEverything ); |
|
254 iTransTfxInternal->Draw( iDrawer.Widget()->Rect() ); |
|
255 } |
|
256 } |
|
257 #endif |
|
258 |
|
259 iTimer.After( iStatus, TTimeIntervalMicroSeconds32( |
|
260 MmEffects::KAnimationFrameDelay ) ); |
|
261 SetActive(); |
|
262 } |
|
263 return KErrNone; |
|
264 } |
|
265 |
|
266 // ----------------------------------------------------------------------------- |
|
267 // |
|
268 // ----------------------------------------------------------------------------- |
|
269 // |
|
270 TInt CMmDrawerAnimator::RunError( TInt aError ) |
|
271 { |
|
272 return aError; |
|
273 } |
|
274 |
|
275 // ----------------------------------------------------------------------------- |
|
276 // |
|
277 // ----------------------------------------------------------------------------- |
|
278 // |
|
279 void CMmDrawerAnimator::AnimateDragItemTransitionL() |
|
280 { |
|
281 if( KErrNotFound != iDrawer.GetFloatingItemIndex( EDrag ) |
|
282 || KErrNotFound != iDrawer.GetFloatingItemIndex( EDragStart ) ) |
|
283 { |
|
284 TMmFloatingItemType floatingType = |
|
285 iDrawer.GetFloatingItemIndex( EDrag ) != KErrNotFound |
|
286 ? EDrag : EDragStart; |
|
287 TMmFloatingItem floatingItem( |
|
288 iDrawer.GetFloatingItemL( floatingType ).GetDrawnItemIndex(), |
|
289 iDrawer.GetFloatingItemL( floatingType ).GetItemPosition(), |
|
290 EDragTransition, floatingType == EDrag |
|
291 ? iUsualAnimationFramesCount : MmEffects::KNoAnimationFramesCount, |
|
292 iDrawer.Widget()->View() ); |
|
293 TPoint pointEnd = iDrawer.Widget()->View()->ItemPos( floatingItem.GetDrawnItemIndex() ); |
|
294 floatingItem.SetPositionStep( pointEnd - floatingItem.GetItemPosition() ); |
|
295 iDrawer.AddFloatingItemL( floatingItem, 0 ); |
|
296 |
|
297 TMmFloatingItem postDragRefresh( |
|
298 iDrawer.GetFloatingItemL( floatingType ).GetDrawnItemIndex(), |
|
299 pointEnd, EPostDragRefreshItem, |
|
300 MmEffects::KNoAnimationFramesCount, iDrawer.Widget()->View() ); |
|
301 iDrawer.AddFloatingItemL( postDragRefresh ); |
|
302 |
|
303 iDrawer.RemoveFloatingItem( iDrawer.GetFloatingItemIndex( EDrag ) ); |
|
304 iDrawer.RemoveFloatingItem( iDrawer.GetFloatingItemIndex( EDragStart ) ); |
|
305 } |
|
306 } |
|
307 |
|
308 // ----------------------------------------------------------------------------- |
|
309 // |
|
310 // ----------------------------------------------------------------------------- |
|
311 // |
|
312 TBool CMmDrawerAnimator::IsReadyForNewAnimation() |
|
313 { |
|
314 if( iPreparedForGarbage ) |
|
315 { |
|
316 return EFalse; |
|
317 } |
|
318 |
|
319 for( int i = 0; i < iDrawer.GetFloatingItemCount(); i++ ) |
|
320 { |
|
321 TMmFloatingItemType type = |
|
322 iDrawer.GetFloatingItemAtIndex( i ).GetFloatingItemType(); |
|
323 if( type != EDrag && type != EZoomTransition ) |
|
324 { |
|
325 return EFalse; |
|
326 } |
|
327 } |
|
328 return ETrue; |
|
329 } |
|
330 |
|
331 // ----------------------------------------------------------------------------- |
|
332 // |
|
333 // ----------------------------------------------------------------------------- |
|
334 // |
|
335 void CMmDrawerAnimator::CancelAnimationsL() |
|
336 { |
|
337 for( int i = 0; i < iDrawer.GetFloatingItemCount(); i++ ) |
|
338 { |
|
339 TMmFloatingItem& current = iDrawer.GetFloatingItemAtIndex( i ); |
|
340 if( current.GetFloatingItemType() != EDrag ) |
|
341 { |
|
342 current.InvalidateFloatingItem(); |
|
343 } |
|
344 } |
|
345 } |
|
346 |
|
347 // ----------------------------------------------------------------------------- |
|
348 // |
|
349 // ----------------------------------------------------------------------------- |
|
350 // |
|
351 void CMmDrawerAnimator::AnimateItemSwapL( TInt aItemFrom, TInt aItemTo ) |
|
352 { |
|
353 TMmFloatingItem floatingItem( aItemTo, |
|
354 iDrawer.Widget()->View()->ItemPos( aItemFrom ), |
|
355 ESwapTransition, iUsualAnimationFramesCount, |
|
356 iDrawer.Widget()->View() ); |
|
357 |
|
358 for( int i = 0; i < iDrawer.GetFloatingItemCount(); i++ ) |
|
359 { |
|
360 TMmFloatingItem& current = iDrawer.GetFloatingItemAtIndex( i ); |
|
361 |
|
362 if( current.GetFloatingItemType() == EZoomTransition |
|
363 && current.GetDrawnItemIndex() == aItemFrom ) |
|
364 { |
|
365 current.InvalidateFloatingItem(); |
|
366 floatingItem.SetSizeStep( current.GetCurrentZoomRatio(), 1.0f ); |
|
367 break; |
|
368 } |
|
369 } |
|
370 |
|
371 floatingItem.SetPositionStep( iDrawer.Widget()->View()->ItemPos(aItemTo) |
|
372 - iDrawer.Widget()->View()->ItemPos(aItemFrom) ); |
|
373 iDrawer.AddFloatingItemL( floatingItem ); |
|
374 } |
|
375 |
|
376 // ----------------------------------------------------------------------------- |
|
377 // |
|
378 // ----------------------------------------------------------------------------- |
|
379 // |
|
380 void CMmDrawerAnimator::AnimateItemZoomL( TInt aItemIndex, TBool aZoomIn ) |
|
381 { |
|
382 TMmFloatingItem floatingItem( aItemIndex, |
|
383 iDrawer.Widget()->View()->ItemPos( aItemIndex ), |
|
384 EZoomTransition, iUsualAnimationFramesCount, |
|
385 iDrawer.Widget()->View() ); |
|
386 floatingItem.SetManualDelete( aZoomIn ); |
|
387 floatingItem.SetSizeStep( |
|
388 (aZoomIn) ? KNormalStateZoomRatio : KZoomStateZoomRatio, |
|
389 (aZoomIn) ? KZoomStateZoomRatio : KNormalStateZoomRatio ); |
|
390 |
|
391 TInt animationFound = EFalse; |
|
392 for( int i = 0; i < iDrawer.GetFloatingItemCount(); i++ ) |
|
393 { |
|
394 TMmFloatingItem& current = iDrawer.GetFloatingItemAtIndex( i ); |
|
395 if( current.GetFloatingItemType() == EZoomTransition |
|
396 && current.GetDrawnItemIndex() == aItemIndex ) |
|
397 { |
|
398 current.InvalidateFloatingItem(); |
|
399 floatingItem.SetSizeStep( current.GetCurrentZoomRatio(), |
|
400 (aZoomIn) ? KZoomStateZoomRatio : KNormalStateZoomRatio); |
|
401 animationFound = ETrue; |
|
402 static_cast<CMmWidgetContainer*> ( iDrawer.Widget()->Parent() )-> |
|
403 SetAllowMove( EFalse ); |
|
404 break; |
|
405 } |
|
406 } |
|
407 |
|
408 if( ( aZoomIn != EFalse || animationFound != EFalse ) ) |
|
409 { |
|
410 // This covers the situation, when a zoom out animation is requested |
|
411 // whilst no zoom in occured earlier. In this case the request is |
|
412 // neglected. |
|
413 iDrawer.AddFloatingItemL( floatingItem ); |
|
414 } |
|
415 } |
|
416 |
|
417 // ----------------------------------------------------------------------------- |
|
418 // |
|
419 // ----------------------------------------------------------------------------- |
|
420 // |
|
421 void CMmDrawerAnimator::SetNextRedrawToWholeScreen() |
|
422 { |
|
423 iPreviousRefreshRect = iDrawer.Widget()->View()->ViewRect(); |
|
424 } |
|
425 |
|
426 // ----------------------------------------------------------------------------- |
|
427 // |
|
428 // ----------------------------------------------------------------------------- |
|
429 // |
|
430 void CMmDrawerAnimator::PrepareForGarbage() |
|
431 { |
|
432 // Cancel any outstanding requests |
|
433 Cancel(); |
|
434 iPreparedForGarbage = ETrue; |
|
435 } |
|
436 |
|
437 // ----------------------------------------------------------------------------- |
|
438 // |
|
439 // ----------------------------------------------------------------------------- |
|
440 // |
|
441 void CMmDrawerAnimator::TriggerMoveItemL() |
|
442 { |
|
443 static_cast<CMmWidgetContainer*> ( iDrawer.Widget()->Parent() )-> |
|
444 TriggerMoveItemL(); |
|
445 } |
|
446 |
|
447 // ----------------------------------------------------------------------------- |
|
448 // |
|
449 // ----------------------------------------------------------------------------- |
|
450 // |
|
451 void CMmDrawerAnimator::AnimateDragItemStartL( TInt aDraggedIndex, TPoint aPoint ) |
|
452 { |
|
453 TMmFloatingItem floatingItem( |
|
454 aDraggedIndex, |
|
455 iDrawer.Widget()->View()->ItemPos( aDraggedIndex ), |
|
456 EDragStart, |
|
457 MmEffects::KUsualAnimationFramesCountNonTouch, |
|
458 iDrawer.Widget()->View() ); |
|
459 floatingItem.SetPositionStep( aPoint - floatingItem.GetItemPosition() ); |
|
460 iDrawer.AddFloatingItemL( floatingItem, 0 ); |
|
461 } |
|
462 //End of file |