|
1 /* |
|
2 * Copyright (c) 2009 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: Taskswitcher Fast Swap area UI |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <avkon.mbg> |
|
20 #include <aknlayoutscalable_apps.cdl.h> |
|
21 #include <layoutmetadata.cdl.h> |
|
22 #include <AknsFrameBackgroundControlContext.h> |
|
23 #include <touchfeedback.h> |
|
24 |
|
25 #include "tsfastswapgrid.h" |
|
26 |
|
27 /* ================================================================================ |
|
28 * CTsFastSwapGrid |
|
29 * ================================================================================ |
|
30 */ |
|
31 |
|
32 // ----------------------------------------------------------------------------- |
|
33 // CTsFastSwapGrid::CTsFastSwapGrid |
|
34 // ----------------------------------------------------------------------------- |
|
35 // |
|
36 CTsFastSwapGrid::CTsFastSwapGrid() |
|
37 : CAknGrid(), |
|
38 iCloseIconHitIdx( KErrNotFound ), |
|
39 iBehaviour( ETouchOnly ), |
|
40 iHighlightVisible( EFalse ) |
|
41 { |
|
42 } |
|
43 |
|
44 |
|
45 // ----------------------------------------------------------------------------- |
|
46 // CTsFastSwapGrid::~CTsFastSwapGrid |
|
47 // ----------------------------------------------------------------------------- |
|
48 // |
|
49 CTsFastSwapGrid::~CTsFastSwapGrid() |
|
50 { |
|
51 iCloseItems.Close(); |
|
52 delete iBgContext; |
|
53 iFullyVisibleItems.Close(); |
|
54 iPartialVisibleItems.Close(); |
|
55 } |
|
56 |
|
57 // ----------------------------------------------------------------------------- |
|
58 // CTsFastSwapGrid::ConstructL |
|
59 // ----------------------------------------------------------------------------- |
|
60 // |
|
61 void CTsFastSwapGrid::ConstructL( const CCoeControl* aParent ) |
|
62 { |
|
63 iParent = aParent; |
|
64 CAknGrid::ConstructL( aParent, EAknListBoxSelectionGrid ); |
|
65 SetPrimaryScrollingType(CAknGridView::EScrollFollowsItemsAndLoops); |
|
66 SetSecondaryScrollingType(CAknGridView::EScrollFollowsItemsAndLoops); |
|
67 iBgContext = CAknsFrameBackgroundControlContext::NewL( |
|
68 KAknsIIDQsnFrPopup, |
|
69 TRect(), |
|
70 TRect(), |
|
71 ETrue ); |
|
72 iBgContext->SetCenter( KAknsIIDQsnFrPopupCenter ); |
|
73 iVisibleViewRect = TRect( 0, 0, 0, 0 ); |
|
74 } |
|
75 |
|
76 // ----------------------------------------------------------------------------- |
|
77 // CTsFastSwapGrid::HandlePointerEventL |
|
78 // ----------------------------------------------------------------------------- |
|
79 // |
|
80 void CTsFastSwapGrid::HandlePointerEventL( const TPointerEvent &aPointerEvent ) |
|
81 { |
|
82 TBool eventHandled( EFalse ); |
|
83 if ( aPointerEvent.iType == TPointerEvent::EButton1Up || |
|
84 aPointerEvent.iType == TPointerEvent::EButton1Down ) |
|
85 { |
|
86 // Check if close icon has been hit |
|
87 // Find hit item |
|
88 TInt hitItem( KErrNotFound ); |
|
89 for ( TInt i = 0; i < Model()->NumberOfItems(); i++ ) |
|
90 { |
|
91 if ( GridView()->XYPosToItemIndex( aPointerEvent.iParentPosition, i ) ) |
|
92 { |
|
93 hitItem = i; |
|
94 break; |
|
95 } |
|
96 } |
|
97 if ( hitItem != KErrNotFound ) |
|
98 { |
|
99 // Item found, check if close icon has been hit |
|
100 TPoint itemPos = GridView()->ItemPos( hitItem ); |
|
101 TSize itemSize = GridView()->ItemSize( hitItem ); |
|
102 TRect itemRect( itemPos, itemSize ); |
|
103 CTsGridItemDrawer* itemDrawer = |
|
104 static_cast<CTsGridItemDrawer*>( ItemDrawer() ); |
|
105 TRect closeIconRect = itemDrawer->GetCloseButtonRect( itemRect ); |
|
106 if ( closeIconRect.Contains( aPointerEvent.iParentPosition ) ) |
|
107 { |
|
108 // Close icon hit |
|
109 if ( aPointerEvent.iType == TPointerEvent::EButton1Down ) |
|
110 { |
|
111 // pointer down - finish processing but do not forward to grid |
|
112 eventHandled = ETrue; |
|
113 } |
|
114 else |
|
115 { |
|
116 // Pointer up |
|
117 TInt hitDataIdx(hitItem); |
|
118 if ( AknLayoutUtils::LayoutMirrored() ) |
|
119 { |
|
120 // Calculate logical item index |
|
121 hitDataIdx = Model()->ItemTextArray()->MdcaCount() - 1 - hitItem; |
|
122 } |
|
123 iCloseIconHitIdx = hitDataIdx; |
|
124 eventHandled = ETrue; |
|
125 // Hide highlight to mark close icon |
|
126 HideHighlight(); |
|
127 // Update current item and redraw grid |
|
128 SetCurrentItemIndex( hitItem ); |
|
129 DrawNow(); |
|
130 if ( iFastSwapGridObserver ) |
|
131 { |
|
132 MTouchFeedback* feedback = MTouchFeedback::Instance(); |
|
133 feedback->InstantFeedback(this, |
|
134 ETouchFeedbackBasicButton, |
|
135 ETouchFeedbackVibra, |
|
136 aPointerEvent); |
|
137 iFastSwapGridObserver->HandleCloseEventL( hitDataIdx ); |
|
138 } |
|
139 ResetCloseHit(); |
|
140 if ( GridBehaviour() == EHybrid ) |
|
141 { |
|
142 ShowHighlight(); |
|
143 } |
|
144 else |
|
145 { |
|
146 Redraw(); |
|
147 } |
|
148 } |
|
149 } |
|
150 } |
|
151 } |
|
152 |
|
153 if ( !eventHandled ) |
|
154 { |
|
155 CTsGridItemDrawer* itemDrawer = |
|
156 static_cast<CTsGridItemDrawer*>( ItemDrawer() ); |
|
157 if( aPointerEvent.iType == TPointerEvent::EButton1Down ) |
|
158 { |
|
159 itemDrawer->SetRedrawBackground( ETrue ); |
|
160 } |
|
161 else if ( aPointerEvent.iType == TPointerEvent::EButton1Up ) |
|
162 { |
|
163 itemDrawer->SetRedrawBackground( EFalse ); |
|
164 } |
|
165 CAknGrid::HandlePointerEventL( aPointerEvent ); |
|
166 Redraw(); |
|
167 } |
|
168 } |
|
169 |
|
170 |
|
171 // ----------------------------------------------------------------------------- |
|
172 // CTsFastSwapGrid::HandleDeviceStateChanged |
|
173 // ----------------------------------------------------------------------------- |
|
174 // |
|
175 void CTsFastSwapGrid::HandleDeviceStateChanged( TChangeType aChangeType ) |
|
176 { |
|
177 if ( aChangeType == ESkin ) |
|
178 { |
|
179 LoadCloseIcon(); |
|
180 } |
|
181 } |
|
182 |
|
183 // ----------------------------------------------------------------------------- |
|
184 // CTsFastSwapGrid::MopSupplyObject |
|
185 // ----------------------------------------------------------------------------- |
|
186 // |
|
187 TTypeUid::Ptr CTsFastSwapGrid::MopSupplyObject( TTypeUid aId ) |
|
188 { |
|
189 if ( aId.iUid == MAknsControlContext::ETypeId ) |
|
190 { |
|
191 return MAknsControlContext::SupplyMopObject( aId, iBgContext ); |
|
192 } |
|
193 return CCoeControl::MopSupplyObject( aId ); |
|
194 } |
|
195 |
|
196 |
|
197 // ----------------------------------------------------------------------------- |
|
198 // CTsFastSwapGrid::HandleResourceChange |
|
199 // ----------------------------------------------------------------------------- |
|
200 // |
|
201 void CTsFastSwapGrid::HandleResourceChange( TInt aType ) |
|
202 { |
|
203 if ( aType != KEikDynamicLayoutVariantSwitch ) |
|
204 { |
|
205 CAknGrid::HandleResourceChange( aType ); |
|
206 } |
|
207 } |
|
208 |
|
209 |
|
210 // ----------------------------------------------------------------------------- |
|
211 // CTsFastSwapGrid::SizeChanged |
|
212 // ----------------------------------------------------------------------------- |
|
213 // |
|
214 void CTsFastSwapGrid::SizeChanged() |
|
215 { |
|
216 } |
|
217 |
|
218 |
|
219 // ----------------------------------------------------------------------------- |
|
220 // CTsFastSwapGrid::SetFastSwapGridObserver |
|
221 // ----------------------------------------------------------------------------- |
|
222 // |
|
223 void CTsFastSwapGrid::SetFastSwapGridObserver( MTsFastSwapGridObserver* aObserver ) |
|
224 { |
|
225 iFastSwapGridObserver = aObserver; |
|
226 } |
|
227 |
|
228 |
|
229 // ----------------------------------------------------------------------------- |
|
230 // CTsFastSwapGrid::CreateItemDrawerL |
|
231 // ----------------------------------------------------------------------------- |
|
232 // |
|
233 void CTsFastSwapGrid::CreateItemDrawerL() |
|
234 { |
|
235 TRect availableRect; |
|
236 AknLayoutUtils::LayoutMetricsRect(AknLayoutUtils::EScreen, availableRect); |
|
237 TAknLayoutRect fastSwapAreaPane; |
|
238 TInt variety = Layout_Meta_Data::IsLandscapeOrientation() ? 1 : 0; |
|
239 fastSwapAreaPane.LayoutRect( availableRect, |
|
240 AknLayoutScalable_Apps::tport_appsw_pane( variety ) ); |
|
241 const TInt leftOffset = fastSwapAreaPane.Rect().iTl.iX; |
|
242 const TInt rightOffset = availableRect.Width() - fastSwapAreaPane.Rect().iBr.iX; |
|
243 |
|
244 CFormattedCellGridData* data = CFormattedCellGridData::NewL(); |
|
245 CleanupStack::PushL( data ); |
|
246 CTsGridItemDrawer* itemDrawer = |
|
247 new ( ELeave ) CTsGridItemDrawer( this, data ); |
|
248 CleanupStack::PushL( itemDrawer ); |
|
249 itemDrawer->SetEdgeOffset( leftOffset, rightOffset ); |
|
250 iItemDrawer = itemDrawer; |
|
251 CleanupStack::Pop( itemDrawer ); |
|
252 CleanupStack::Pop( data ); |
|
253 LoadCloseIcon(); |
|
254 } |
|
255 |
|
256 |
|
257 // ----------------------------------------------------------------------------- |
|
258 // CTsFastSwapGrid::SetCloseItemsL |
|
259 // ----------------------------------------------------------------------------- |
|
260 // |
|
261 void CTsFastSwapGrid::SetCloseItemsL( RArray<TInt>& aItemIndex ) |
|
262 { |
|
263 iCloseItems.Close(); |
|
264 for ( TInt i = 0; i < aItemIndex.Count(); i++ ) |
|
265 { |
|
266 iCloseItems.AppendL( aItemIndex[i] ); |
|
267 } |
|
268 } |
|
269 |
|
270 |
|
271 // ----------------------------------------------------------------------------- |
|
272 // CTsFastSwapGrid::CanCloseItem |
|
273 // ----------------------------------------------------------------------------- |
|
274 // |
|
275 TBool CTsFastSwapGrid::CanCloseItem( TInt aItemIndex ) |
|
276 { |
|
277 return iCloseItems.Find(aItemIndex) != KErrNotFound; |
|
278 } |
|
279 |
|
280 |
|
281 // ----------------------------------------------------------------------------- |
|
282 // CTsFastSwapGrid::ItemCloseHit |
|
283 // ----------------------------------------------------------------------------- |
|
284 // |
|
285 TBool CTsFastSwapGrid::IsItemCloseHit( TInt aItemIndex ) |
|
286 { |
|
287 return iCloseIconHitIdx == aItemIndex; |
|
288 } |
|
289 |
|
290 |
|
291 // ----------------------------------------------------------------------------- |
|
292 // CTsFastSwapGrid::ResetCloseHit |
|
293 // ----------------------------------------------------------------------------- |
|
294 // |
|
295 void CTsFastSwapGrid::ResetCloseHit() |
|
296 { |
|
297 iCloseIconHitIdx = KErrNotFound; |
|
298 } |
|
299 |
|
300 |
|
301 // ----------------------------------------------------------------------------- |
|
302 // CTsFastSwapGrid::SetBehaviour |
|
303 // ----------------------------------------------------------------------------- |
|
304 // |
|
305 void CTsFastSwapGrid::SetGridBehaviour( TFastSwapGridBehaviour aBehaviour ) |
|
306 { |
|
307 iBehaviour = aBehaviour; |
|
308 switch ( iBehaviour ) |
|
309 { |
|
310 case ETouchOnly: |
|
311 { |
|
312 HideHighlight(); |
|
313 } |
|
314 break; |
|
315 default: |
|
316 { |
|
317 ShowHighlight(); |
|
318 } |
|
319 break; |
|
320 } |
|
321 } |
|
322 |
|
323 |
|
324 // ----------------------------------------------------------------------------- |
|
325 // CTsFastSwapGrid::GridBehaviour |
|
326 // ----------------------------------------------------------------------------- |
|
327 // |
|
328 CTsFastSwapGrid::TFastSwapGridBehaviour CTsFastSwapGrid::GridBehaviour() |
|
329 { |
|
330 return iBehaviour; |
|
331 } |
|
332 |
|
333 |
|
334 // ----------------------------------------------------------------------------- |
|
335 // CTsFastSwapGrid::ShowHighlight |
|
336 // ----------------------------------------------------------------------------- |
|
337 // |
|
338 void CTsFastSwapGrid::ShowHighlight() |
|
339 { |
|
340 if ( !iHighlightVisible ) |
|
341 { |
|
342 // Draw highlight |
|
343 iHighlightVisible = ETrue; |
|
344 Redraw(); |
|
345 } |
|
346 } |
|
347 |
|
348 |
|
349 // ----------------------------------------------------------------------------- |
|
350 // CTsFastSwapGrid::HideHighlight |
|
351 // ----------------------------------------------------------------------------- |
|
352 // |
|
353 void CTsFastSwapGrid::HideHighlight() |
|
354 { |
|
355 if ( iHighlightVisible ) |
|
356 { |
|
357 iHighlightVisible = EFalse; |
|
358 Redraw(); |
|
359 } |
|
360 } |
|
361 |
|
362 |
|
363 // ----------------------------------------------------------------------------- |
|
364 // CTsFastSwapGrid::IsHighlightVisible |
|
365 // ----------------------------------------------------------------------------- |
|
366 // |
|
367 TBool CTsFastSwapGrid::IsHighlightVisible() |
|
368 { |
|
369 return iHighlightVisible; |
|
370 } |
|
371 |
|
372 |
|
373 // ----------------------------------------------------------------------------- |
|
374 // CTsFastSwapGrid::SetVisibleViewRect |
|
375 // ----------------------------------------------------------------------------- |
|
376 // |
|
377 void CTsFastSwapGrid::SetVisibleViewRect( const TRect aRect ) |
|
378 { |
|
379 iVisibleViewRect = aRect; |
|
380 } |
|
381 |
|
382 |
|
383 // ----------------------------------------------------------------------------- |
|
384 // CTsFastSwapGrid::VisibleViewRect |
|
385 // ----------------------------------------------------------------------------- |
|
386 // |
|
387 TRect CTsFastSwapGrid::VisibleViewRect() |
|
388 { |
|
389 TRect retVal; |
|
390 TRect emptyRect = TRect( 0, 0, 0, 0 ); |
|
391 if ( iVisibleViewRect == emptyRect ) |
|
392 { |
|
393 retVal = Rect(); |
|
394 } |
|
395 else |
|
396 { |
|
397 retVal = iVisibleViewRect; |
|
398 } |
|
399 return retVal; |
|
400 } |
|
401 |
|
402 |
|
403 // ----------------------------------------------------------------------------- |
|
404 // CTsFastSwapGrid::LoadCloseIconL |
|
405 // ----------------------------------------------------------------------------- |
|
406 // |
|
407 void CTsFastSwapGrid::LoadCloseIcon() |
|
408 { |
|
409 // Load and set close icon |
|
410 CFbsBitmap* icon = NULL; |
|
411 CFbsBitmap* mask = NULL; |
|
412 |
|
413 TRAP_IGNORE(AknsUtils::CreateIconLC( AknsUtils::SkinInstance(), |
|
414 KAknsIIDQgnIndiItutListCollapse, |
|
415 icon, |
|
416 mask, |
|
417 KAvkonBitmapFile, |
|
418 EMbmAvkonQgn_indi_button_preview_close, |
|
419 EMbmAvkonQgn_indi_button_preview_close_mask |
|
420 ); |
|
421 CleanupStack::Pop( 2 ); // codescanner::cleanup |
|
422 ); |
|
423 |
|
424 TAknLayoutRect gridAppPane; |
|
425 TAknLayoutRect gridItem; |
|
426 TAknLayoutRect gridCloseButton; |
|
427 TAknLayoutRect gridCloseIcon; |
|
428 TInt variety = Layout_Meta_Data::IsLandscapeOrientation() ? 1 : 0; |
|
429 TRect source = iParent ? iParent->Rect() : Rect(); |
|
430 gridAppPane.LayoutRect( source, |
|
431 AknLayoutScalable_Apps::tport_appsw_pane( variety ) ); |
|
432 gridItem.LayoutRect( gridAppPane.Rect(), |
|
433 AknLayoutScalable_Apps::cell_tport_appsw_pane( variety, 0, 0 ) ); |
|
434 gridCloseButton.LayoutRect( gridItem.Rect(), |
|
435 AknLayoutScalable_Apps::bg_button_pane_cp16( variety, 0, 0 )); |
|
436 gridCloseIcon.LayoutRect( gridItem.Rect(), |
|
437 AknLayoutScalable_Apps::cell_tport_appsw_pane_g3( variety, 0, 0 )); |
|
438 AknIconUtils::SetSize( icon, gridCloseIcon.Rect().Size(), EAspectRatioPreserved ); |
|
439 AknIconUtils::SetSize( mask, gridCloseIcon.Rect().Size(), EAspectRatioPreserved ); |
|
440 CTsGridItemDrawer* itemDrawer = |
|
441 static_cast<CTsGridItemDrawer*>(iItemDrawer); |
|
442 itemDrawer->SetCloseIcon( icon, mask ); |
|
443 TRect relGridCloseButton = TRect( TPoint( gridCloseButton.Rect().iTl.iX - gridItem.Rect().iTl.iX, |
|
444 gridCloseButton.Rect().iTl.iY - gridItem.Rect().iTl.iY), |
|
445 gridCloseButton.Rect().Size() ); |
|
446 TRect relGridCloseIconRect = TRect( TPoint( gridCloseIcon.Rect().iTl.iX - gridItem.Rect().iTl.iX, |
|
447 gridCloseIcon.Rect().iTl.iY - gridItem.Rect().iTl.iY), |
|
448 gridCloseIcon.Rect().Size() ); |
|
449 itemDrawer->SetCloseIconRect( relGridCloseButton, relGridCloseIconRect ); |
|
450 } |
|
451 |
|
452 |
|
453 // ----------------------------------------------------------------------------- |
|
454 // CTsFastSwapGrid::Redraw |
|
455 // ----------------------------------------------------------------------------- |
|
456 // |
|
457 void CTsFastSwapGrid::Redraw() |
|
458 { |
|
459 DrawDeferred(); |
|
460 CCoeControl* ctrlToRedraw = Parent(); |
|
461 if ( ctrlToRedraw ) |
|
462 { |
|
463 ctrlToRedraw->DrawDeferred(); |
|
464 ctrlToRedraw = ctrlToRedraw->Parent(); |
|
465 if ( ctrlToRedraw ) |
|
466 { |
|
467 ctrlToRedraw->DrawNow(); |
|
468 } |
|
469 } |
|
470 } |
|
471 |
|
472 // ----------------------------------------------------------------------------- |
|
473 // CTsFastSwapGrid::LaunchTactileFeedback |
|
474 // ----------------------------------------------------------------------------- |
|
475 // |
|
476 void CTsFastSwapGrid::LaunchTactileFeedback() |
|
477 { |
|
478 if( !iTactileFeedbackSupport ) |
|
479 { |
|
480 return; |
|
481 } |
|
482 |
|
483 MTouchFeedback* feedback = MTouchFeedback::Instance(); |
|
484 if (feedback) |
|
485 { |
|
486 feedback->InstantFeedback(ETouchFeedbackSensitive); |
|
487 } |
|
488 } |
|
489 |
|
490 // ----------------------------------------------------------------------------- |
|
491 // CTsFastSwapGrid::SetTactileFeedbackSupport |
|
492 // ----------------------------------------------------------------------------- |
|
493 // |
|
494 void CTsFastSwapGrid::SetTactileFeedbackSupport(TBool aSupport) |
|
495 { |
|
496 iTactileFeedbackSupport = aSupport; |
|
497 } |
|
498 |
|
499 |
|
500 // ----------------------------------------------------------------------------- |
|
501 // CTsFastSwapGrid::RemoveFromVisibleItems |
|
502 // ----------------------------------------------------------------------------- |
|
503 // |
|
504 TBool CTsFastSwapGrid::RemoveFromVisibleItems(TInt aItem) const |
|
505 { |
|
506 TBool retVal(EFalse); |
|
507 TInt idx(0); |
|
508 idx = iFullyVisibleItems.Find(aItem); |
|
509 if( idx >= 0) |
|
510 { |
|
511 iFullyVisibleItems.Remove(idx); |
|
512 retVal = ETrue; |
|
513 } |
|
514 idx = iPartialVisibleItems.Find( aItem ); |
|
515 if( idx >= 0) |
|
516 { |
|
517 iPartialVisibleItems.Remove(idx); |
|
518 retVal = ETrue; |
|
519 } |
|
520 return retVal; |
|
521 } |
|
522 |
|
523 // ----------------------------------------------------------------------------- |
|
524 // CTsFastSwapGrid::AddToFullyVisibleItems |
|
525 // ----------------------------------------------------------------------------- |
|
526 // |
|
527 TBool CTsFastSwapGrid::AddToFullyVisibleItems( TInt aItem ) const |
|
528 { |
|
529 TBool retVal(EFalse); |
|
530 TInt idx(0); |
|
531 |
|
532 idx = iPartialVisibleItems.Find(aItem); |
|
533 if( idx >= 0) |
|
534 { |
|
535 iPartialVisibleItems.Remove(idx); |
|
536 } |
|
537 idx = iFullyVisibleItems.Find( aItem ); |
|
538 if( idx == KErrNotFound ) |
|
539 { |
|
540 iFullyVisibleItems.Append(aItem); |
|
541 retVal = ETrue; |
|
542 } |
|
543 return retVal; |
|
544 } |
|
545 |
|
546 // ----------------------------------------------------------------------------- |
|
547 // CTsFastSwapGrid::MoveToPartialVisibleItems |
|
548 // ----------------------------------------------------------------------------- |
|
549 // |
|
550 TBool CTsFastSwapGrid::MoveToPartialVisibleItems( TInt aItem ) const |
|
551 { |
|
552 TInt idx(0); |
|
553 idx = iFullyVisibleItems.Find(aItem); |
|
554 if( idx >= 0) |
|
555 { |
|
556 iFullyVisibleItems.Remove(idx); |
|
557 } |
|
558 idx = iPartialVisibleItems.Find( aItem ); |
|
559 if( idx == KErrNotFound ) |
|
560 { |
|
561 iPartialVisibleItems.Append(aItem); |
|
562 } |
|
563 return EFalse; |
|
564 } |
|
565 |
|
566 /* ================================================================================ |
|
567 * CTsGridItemDrawer |
|
568 * ================================================================================ |
|
569 */ |
|
570 |
|
571 // ----------------------------------------------------------------------------- |
|
572 // CTsGridItemDrawer::CTsGridItemDrawer |
|
573 // ----------------------------------------------------------------------------- |
|
574 // |
|
575 CTsGridItemDrawer::CTsGridItemDrawer( |
|
576 CTsFastSwapGrid* aGrid, |
|
577 CFormattedCellListBoxData* aData ) |
|
578 : CFormattedCellListBoxItemDrawer( aGrid->Model(), |
|
579 NULL, |
|
580 aData ), |
|
581 iGrid( aGrid ) |
|
582 { |
|
583 AknLayoutUtils::LayoutMetricsRect(AknLayoutUtils::EScreen, iScreenRect); |
|
584 } |
|
585 |
|
586 |
|
587 // ----------------------------------------------------------------------------- |
|
588 // CTsGridItemDrawer::~CTsGridItemDrawer |
|
589 // ----------------------------------------------------------------------------- |
|
590 // |
|
591 CTsGridItemDrawer::~CTsGridItemDrawer() |
|
592 { |
|
593 delete iCloseIcon; |
|
594 delete iCloseIconMask; |
|
595 } |
|
596 |
|
597 |
|
598 // ----------------------------------------------------------------------------- |
|
599 // CTsGridItemDrawer::SetCloseIcon |
|
600 // ----------------------------------------------------------------------------- |
|
601 // |
|
602 void CTsGridItemDrawer::SetCloseIcon( CFbsBitmap* aBmp, CFbsBitmap* aMask ) |
|
603 { |
|
604 delete iCloseIcon; |
|
605 iCloseIcon = aBmp; |
|
606 delete iCloseIconMask; |
|
607 iCloseIconMask = aMask; |
|
608 } |
|
609 |
|
610 |
|
611 // ----------------------------------------------------------------------------- |
|
612 // CTsGridItemDrawer::SetCloseIconRect |
|
613 // ----------------------------------------------------------------------------- |
|
614 // |
|
615 void CTsGridItemDrawer::SetCloseIconRect( const TRect& aButtonRect, const TRect& aIconRect ) |
|
616 { |
|
617 iCloseButtonRect = aButtonRect; |
|
618 iCloseIconRect = aIconRect; |
|
619 } |
|
620 |
|
621 |
|
622 // ----------------------------------------------------------------------------- |
|
623 // CTsGridItemDrawer::GetCloseButtonRect |
|
624 // ----------------------------------------------------------------------------- |
|
625 // |
|
626 TRect CTsGridItemDrawer::GetCloseButtonRect( const TRect& aItemRect ) const |
|
627 { |
|
628 TRect retVal; |
|
629 retVal = TRect( TPoint(aItemRect.iTl.iX + iCloseButtonRect.iTl.iX, |
|
630 aItemRect.iTl.iY + iCloseButtonRect.iTl.iY), |
|
631 iCloseButtonRect.Size() ); |
|
632 return retVal; |
|
633 } |
|
634 |
|
635 |
|
636 // ----------------------------------------------------------------------------- |
|
637 // CTsGridItemDrawer::SetEdgeOffset |
|
638 // ----------------------------------------------------------------------------- |
|
639 // |
|
640 void CTsGridItemDrawer::SetEdgeOffset( TInt aLeftOffset, TInt aRightOffset ) |
|
641 { |
|
642 iLeftOffset = aLeftOffset; |
|
643 iRightOffset = aRightOffset; |
|
644 } |
|
645 |
|
646 |
|
647 // ----------------------------------------------------------------------------- |
|
648 // CTsTeleportGridItemDrawer::SetRedrawBackground |
|
649 // ----------------------------------------------------------------------------- |
|
650 // |
|
651 void CTsGridItemDrawer::SetRedrawBackground( TBool aEnable ) |
|
652 { |
|
653 iRedrawBackground = aEnable; |
|
654 } |
|
655 |
|
656 |
|
657 // ----------------------------------------------------------------------------- |
|
658 // CTsGridItemDrawer::DrawActualItem |
|
659 // ----------------------------------------------------------------------------- |
|
660 // |
|
661 void CTsGridItemDrawer::DrawActualItem( TInt aItemIndex, const TRect& aActualItemRect, |
|
662 TBool aItemIsCurrent, TBool aViewIsEmphasized, |
|
663 TBool aViewIsDimmed, TBool aItemIsSelected ) const |
|
664 { |
|
665 TBool feedbackNeed(EFalse);//feedback when item disappear or fully appear |
|
666 |
|
667 if (IsItemRectVisible(aActualItemRect)) |
|
668 { |
|
669 // Calculate offset of the visible rectangle |
|
670 TRect drawRect = aActualItemRect; |
|
671 if ( drawRect.iTl.iX < iLeftOffset ) |
|
672 { |
|
673 drawRect.iTl.iX = iLeftOffset; |
|
674 } |
|
675 if ( iScreenRect.Width() - drawRect.iBr.iX < iRightOffset ) |
|
676 { |
|
677 drawRect.iBr.iX = iScreenRect.Width() - iRightOffset; |
|
678 } |
|
679 iGc->SetClippingRect(drawRect); |
|
680 |
|
681 if(IsRectContained( aActualItemRect, drawRect )) |
|
682 { |
|
683 feedbackNeed = iGrid->AddToFullyVisibleItems( aItemIndex ); |
|
684 } |
|
685 else |
|
686 { |
|
687 feedbackNeed = iGrid->MoveToPartialVisibleItems( aItemIndex ); |
|
688 } |
|
689 |
|
690 // Check for item highlight |
|
691 TBool itemIsCurrent = !iGrid->IsHighlightVisible() ? EFalse : aItemIsCurrent; |
|
692 |
|
693 // Draw background if necessary |
|
694 if ( iRedrawBackground ) |
|
695 { |
|
696 CCoeControl* targetCtrlCtx = iGrid->Parent(); |
|
697 if(targetCtrlCtx) |
|
698 { |
|
699 MAknsSkinInstance* skin = AknsUtils::SkinInstance(); |
|
700 MAknsControlContext* cc = AknsDrawUtils::ControlContext( targetCtrlCtx ); |
|
701 AknsDrawUtils::Background( skin, |
|
702 cc, |
|
703 targetCtrlCtx, |
|
704 *iGc, |
|
705 drawRect ); |
|
706 } |
|
707 } |
|
708 |
|
709 // Draw item |
|
710 CFormattedCellListBoxItemDrawer::DrawActualItem(aItemIndex, aActualItemRect, |
|
711 itemIsCurrent, aViewIsEmphasized, aViewIsDimmed, aItemIsSelected ); |
|
712 |
|
713 if ( iGrid->CanCloseItem( aItemIndex ) && iCloseIcon && iCloseIconMask ) |
|
714 { |
|
715 TRect closeIconRect = GetCloseButtonRect( aActualItemRect ); |
|
716 // Draw frame |
|
717 TRect outerRect = closeIconRect; |
|
718 TRect innerRect = CalculateInnerButtonRect( outerRect ); |
|
719 MAknsSkinInstance* skin = AknsUtils::SkinInstance(); |
|
720 if ( iGrid->IsItemCloseHit( aItemIndex ) ) |
|
721 { |
|
722 AknsDrawUtils::DrawFrame(skin, *iGc, outerRect, innerRect, |
|
723 KAknsIIDQgnFrSctrlButtonPressed, KAknsIIDQgnFrSctrlButtonCenterPressed); |
|
724 } |
|
725 else |
|
726 { |
|
727 AknsDrawUtils::DrawFrame(skin, *iGc, outerRect, innerRect, |
|
728 KAknsIIDQgnFrSctrlButton, KAknsIIDQgnFrSctrlButtonCenter); |
|
729 } |
|
730 // Draw close icon |
|
731 TRect sourceRect( TPoint(0,0), iCloseIcon->SizeInPixels() ); |
|
732 iGc->DrawBitmapMasked( innerRect, iCloseIcon, sourceRect, iCloseIconMask, ETrue ); |
|
733 } |
|
734 } |
|
735 else |
|
736 { |
|
737 feedbackNeed = iGrid->RemoveFromVisibleItems(aItemIndex); |
|
738 } |
|
739 if(feedbackNeed) |
|
740 { |
|
741 iGrid->LaunchTactileFeedback(); |
|
742 } |
|
743 } |
|
744 |
|
745 // ----------------------------------------------------------------------------- |
|
746 // CTsGridItemDrawer::DrawActualItem |
|
747 // ----------------------------------------------------------------------------- |
|
748 // |
|
749 TBool CTsGridItemDrawer::IsItemRectVisible( const TRect& aItemRect ) const |
|
750 { |
|
751 TBool retVal( EFalse ); |
|
752 TRect viewRect = iGrid->VisibleViewRect(); |
|
753 if ( // left edge of item rectangle on screen |
|
754 ( aItemRect.iTl.iX >= viewRect.iTl.iX && aItemRect.iTl.iX <= viewRect.iBr.iX ) || |
|
755 // right edge of item rectangle on screen |
|
756 ( aItemRect.iBr.iX >= viewRect.iTl.iX && aItemRect.iBr.iX <= viewRect.iBr.iX ) |
|
757 ) |
|
758 { |
|
759 retVal = ETrue; |
|
760 } |
|
761 return retVal; |
|
762 } |
|
763 |
|
764 // ----------------------------------------------------------------------------- |
|
765 // CTsGridItemDrawer::IsRectContained |
|
766 // ----------------------------------------------------------------------------- |
|
767 // |
|
768 TBool CTsGridItemDrawer::IsRectContained( |
|
769 const TRect& aRectContained, const TRect& aRectContainig) const |
|
770 { |
|
771 TBool retVal(EFalse); |
|
772 TRect intersectionRect(aRectContainig); |
|
773 intersectionRect.Intersection( aRectContained ); |
|
774 if( intersectionRect == aRectContained) |
|
775 { |
|
776 retVal = ETrue; |
|
777 } |
|
778 return retVal; |
|
779 } |
|
780 |
|
781 // ----------------------------------------------------------------------------- |
|
782 // CTsGridItemDrawer::CalculateInnerButtonRect |
|
783 // ----------------------------------------------------------------------------- |
|
784 // |
|
785 TRect CTsGridItemDrawer::CalculateInnerButtonRect( const TRect& aOuterRect ) const |
|
786 { |
|
787 TRect retVal(aOuterRect); |
|
788 retVal.iTl.iX += iCloseIconRect.iTl.iX - iCloseButtonRect.iTl.iX; |
|
789 retVal.iTl.iY += iCloseIconRect.iTl.iY - iCloseButtonRect.iTl.iY; |
|
790 retVal.iBr.iX -= iCloseButtonRect.iBr.iX - iCloseIconRect.iBr.iX; |
|
791 retVal.iBr.iY -= iCloseButtonRect.iBr.iY - iCloseIconRect.iBr.iY; |
|
792 return retVal; |
|
793 } |
|
794 |
|
795 |
|
796 |
|
797 /* ================================================================================ |
|
798 * CTsGridHighlightTimer |
|
799 * ================================================================================ |
|
800 */ |
|
801 |
|
802 // ----------------------------------------------------------------------------- |
|
803 // CTsGridHighlightTimer::CTsGridHighlightTimer |
|
804 // ----------------------------------------------------------------------------- |
|
805 // |
|
806 CTsFastSwapTimer::CTsFastSwapTimer( MTsFastSwapTimerObserver& aObserver ) |
|
807 : CTimer( EPriorityStandard ), |
|
808 iObserver( &aObserver ) |
|
809 { |
|
810 } |
|
811 |
|
812 |
|
813 // ----------------------------------------------------------------------------- |
|
814 // CTsGridHighlightTimer::CTsGridHighlightTimer |
|
815 // ----------------------------------------------------------------------------- |
|
816 // |
|
817 CTsFastSwapTimer::~CTsFastSwapTimer() |
|
818 { |
|
819 Cancel(); |
|
820 } |
|
821 |
|
822 |
|
823 // ----------------------------------------------------------------------------- |
|
824 // CTsGridHighlightTimer::ConstructL |
|
825 // ----------------------------------------------------------------------------- |
|
826 // |
|
827 void CTsFastSwapTimer::ConstructL() |
|
828 { |
|
829 CTimer::ConstructL(); |
|
830 CActiveScheduler::Add( this ); |
|
831 } |
|
832 |
|
833 |
|
834 // ----------------------------------------------------------------------------- |
|
835 // CTsGridHighlightTimer::CTsGridHighlightTimer |
|
836 // ----------------------------------------------------------------------------- |
|
837 // |
|
838 void CTsFastSwapTimer::RunL() |
|
839 { |
|
840 iObserver->TimerCompletedL(this); |
|
841 } |
|
842 |
|
843 // End of file |