diff -r 1526727a5b85 -r 899e4666ea9a taskswitcher/taskswitcherui/taskswitcherapp/src/tsfastswapgrid.cpp --- a/taskswitcher/taskswitcherui/taskswitcherapp/src/tsfastswapgrid.cpp Fri Mar 26 15:15:17 2010 +0200 +++ b/taskswitcher/taskswitcherui/taskswitcherapp/src/tsfastswapgrid.cpp Wed May 12 13:12:59 2010 +0300 @@ -31,7 +31,8 @@ */ const TInt KCloseIconRedrawTime = 300000; // 0.3 second -const TInt KFeedbackTime = 0; + +const TInt KStrokeThickness = 1; // ----------------------------------------------------------------------------- // CTsFastSwapGrid::CTsFastSwapGrid @@ -41,7 +42,8 @@ : CAknGrid(), iCloseIconHitIdx( KErrNotFound ), iBehaviour( ETouchOnly ), - iHighlightVisible( EFalse ) + iHighlightVisible( EFalse ), + iAknEventHandlingEnabled(ETrue) { } @@ -53,11 +55,7 @@ CTsFastSwapGrid::~CTsFastSwapGrid() { iCloseItems.Close(); - delete iBgContext; delete iCloseIconRedrawTimer; - delete iFeedbackTimer; - iFullyVisibleItems.Close(); - iPartialVisibleItems.Close(); } // ----------------------------------------------------------------------------- @@ -73,16 +71,8 @@ CAknGrid::ConstructL( aParent, EAknListBoxSelectionGrid ); SetPrimaryScrollingType(CAknGridView::EScrollFollowsItemsAndLoops); SetSecondaryScrollingType(CAknGridView::EScrollFollowsItemsAndLoops); - iBgContext = CAknsFrameBackgroundControlContext::NewL( - KAknsIIDQsnFrPopup, - TRect(), - TRect(), - ETrue ); - iBgContext->SetCenter( KAknsIIDQsnFrPopupCenter ); iCloseIconRedrawTimer = new (ELeave) CTsFastSwapTimer( *this ); iCloseIconRedrawTimer->ConstructL(); - iFeedbackTimer = new (ELeave) CTsFastSwapTimer( *this ); - iFeedbackTimer->ConstructL(); TSLOG_OUT(); } @@ -123,27 +113,27 @@ if ( closeIconRect.Contains( aPointerEvent.iParentPosition ) ) { // Close icon hit + TInt hitDataIdx(hitItem); + if ( AknLayoutUtils::LayoutMirrored() ) + { + // Calculate logical item index + hitDataIdx = Model()->ItemTextArray()->MdcaCount() - 1 - hitItem; + } + iCloseIconHitIdx = hitDataIdx; + eventHandled = ETrue; + if ( aPointerEvent.iType == TPointerEvent::EButton1Down ) { - // pointer down - finish processing but do not forward to grid - eventHandled = ETrue; + // Update current item and redraw grid + SetCurrentItemIndex( hitItem ); + DrawNow(); + + iCloseIconRedrawTimer->Cancel(); + iCloseIconRedrawTimer->After(KCloseIconRedrawTime); } else { // Pointer up - TInt hitDataIdx(hitItem); - if ( AknLayoutUtils::LayoutMirrored() ) - { - // Calculate logical item index - hitDataIdx = Model()->ItemTextArray()->MdcaCount() - 1 - hitItem; - } - iCloseIconHitIdx = hitDataIdx; - eventHandled = ETrue; - // Hide highlight to mark close icon - HideHighlight(); - // Update current item and redraw grid - SetCurrentItemIndex( hitItem ); - DrawNow(); if ( iFastSwapGridObserver ) { MTouchFeedback* feedback = MTouchFeedback::Instance(); @@ -151,8 +141,6 @@ ETouchFeedbackBasicButton, ETouchFeedbackVibra, aPointerEvent); - iCloseIconRedrawTimer->Cancel(); - iCloseIconRedrawTimer->After(KCloseIconRedrawTime); } if ( GridBehaviour() == EHybrid ) { @@ -162,6 +150,8 @@ { Redraw(); } + iFastSwapGridObserver->HandleCloseEventL( hitDataIdx ); + ResetCloseHit(); } } } @@ -179,7 +169,10 @@ { itemDrawer->SetRedrawBackground( EFalse ); } - CAknGrid::HandlePointerEventL( aPointerEvent ); + if ( iAknEventHandlingEnabled ) + { + CAknGrid::HandlePointerEventL( aPointerEvent ); + } Redraw(); } @@ -198,25 +191,12 @@ if ( aChangeType == ESkin ) { - LoadCloseIcon(); + LoadCloseIconAndStrokeParams(); } TSLOG_OUT(); } -// ----------------------------------------------------------------------------- -// CTsFastSwapGrid::MopSupplyObject -// ----------------------------------------------------------------------------- -// -TTypeUid::Ptr CTsFastSwapGrid::MopSupplyObject( TTypeUid aId ) - { - if ( aId.iUid == MAknsControlContext::ETypeId ) - { - return MAknsControlContext::SupplyMopObject( aId, iBgContext ); - } - return CCoeControl::MopSupplyObject( aId ); - } - // ----------------------------------------------------------------------------- // CTsFastSwapGrid::HandleResourceChange @@ -247,6 +227,20 @@ // ----------------------------------------------------------------------------- +// CTsFastSwapGrid::Draw +// ----------------------------------------------------------------------------- +// +void CTsFastSwapGrid::Draw( const TRect& aRect ) const + { + CAknGrid::Draw(aRect); + if ( !Model()->ItemTextArray()->MdcaCount() ) + { + GridView()->DrawEmptyList(); + } + } + + +// ----------------------------------------------------------------------------- // CTsFastSwapGrid::SetFastSwapGridObserver // ----------------------------------------------------------------------------- // @@ -265,9 +259,31 @@ TSLOG_CONTEXT( CTsFastSwapGrid::CreateItemDrawerL, TSLOG_LOCAL ); TSLOG_IN(); + CFormattedCellGridData* data = CFormattedCellGridData::NewL(); + CleanupStack::PushL( data ); + CTsGridItemDrawer* itemDrawer = + new ( ELeave ) CTsGridItemDrawer( this, data ); + iItemDrawer = itemDrawer; + CleanupStack::Pop( data ); + + TSLOG_OUT(); + } + + +// ----------------------------------------------------------------------------- +// CTsFastSwapGrid::UpdateItemDrawerLayoutDataL +// ----------------------------------------------------------------------------- +// +void CTsFastSwapGrid::UpdateItemDrawerLayoutDataL() + { + CTsGridItemDrawer* itemDrawer = + static_cast( ItemDrawer() ); + TPixelsAndRotation screenSize; iEikonEnv->ScreenDevice()->GetDefaultScreenSizeAndRotation(screenSize); TRect availableRect = TRect( TPoint(0,0), screenSize.iPixelSize ); + itemDrawer->SetScreenRect(availableRect); + TAknLayoutRect fastSwapAreaPane; TInt variety = Layout_Meta_Data::IsLandscapeOrientation() ? 1 : 0; fastSwapAreaPane.LayoutRect( availableRect, @@ -275,19 +291,19 @@ const TInt leftOffset = iParent->Rect().iTl.iX; const TInt rightOffset = availableRect.Width() - iParent->Rect().iBr.iX; SetVisibleViewRect(fastSwapAreaPane.Rect()); + itemDrawer->SetEdgeOffset( leftOffset, rightOffset ); - CFormattedCellGridData* data = CFormattedCellGridData::NewL(); - CleanupStack::PushL( data ); - CTsGridItemDrawer* itemDrawer = - new ( ELeave ) CTsGridItemDrawer( this, data, availableRect ); - CleanupStack::PushL( itemDrawer ); - itemDrawer->SetEdgeOffset( leftOffset, rightOffset ); - iItemDrawer = itemDrawer; - CleanupStack::Pop( itemDrawer ); - CleanupStack::Pop( data ); - LoadCloseIcon(); - - TSLOG_OUT(); + LoadCloseIconAndStrokeParams(); + } + + +// ----------------------------------------------------------------------------- +// CTsFastSwapGrid::EnableAknEventHandling +// ----------------------------------------------------------------------------- +// +void CTsFastSwapGrid::EnableAknEventHandling( TBool aEnable ) + { + iAknEventHandlingEnabled = aEnable; } // ----------------------------------------------------------------------------- @@ -298,17 +314,7 @@ { if ( aSource == iCloseIconRedrawTimer ) { - TInt itemToClose = iCloseIconHitIdx; ResetCloseHit(); - iFastSwapGridObserver->HandleCloseEventL( itemToClose ); - } - else if ( aSource == iFeedbackTimer ) - { - MTouchFeedback* feedback = MTouchFeedback::Instance(); - if (feedback) - { - feedback->InstantFeedback(ETouchFeedbackSensitive); - } } } @@ -357,6 +363,27 @@ // ----------------------------------------------------------------------------- +// CTsFastSwapGrid::SetStrokeColor +// ----------------------------------------------------------------------------- +// +void CTsFastSwapGrid::SetStrokeColors( TRgb aColor, + TRgb aHighlightedColor ) + { + static_cast(iItemDrawer)->SetStrokeColors(aColor, aHighlightedColor); + } + + +// ----------------------------------------------------------------------------- +// CTsFastSwapGrid::SetStrokeItemsL +// ----------------------------------------------------------------------------- +// +void CTsFastSwapGrid::SetStrokeItemsL( RArray& aItemIndex ) + { + static_cast(iItemDrawer)->SetStrokeItemsL(aItemIndex); + } + + +// ----------------------------------------------------------------------------- // CTsFastSwapGrid::SetBehaviour // ----------------------------------------------------------------------------- // @@ -459,31 +486,38 @@ // ----------------------------------------------------------------------------- -// CTsFastSwapGrid::LoadCloseIconL +// CTsFastSwapGrid::LoadCloseIconAndStrokeParams // ----------------------------------------------------------------------------- // -void CTsFastSwapGrid::LoadCloseIcon() +void CTsFastSwapGrid::LoadCloseIconAndStrokeParams() { // Load and set close icon CFbsBitmap* icon = NULL; - CFbsBitmap* mask = NULL; - - TRAP_IGNORE(AknsUtils::CreateColorIconLC( AknsUtils::SkinInstance(), - KAknsIIDQgnIndiItutListCollapse, - KAknsIIDQsnTextColors, // we use text color here, eventhough this is an icon - EAknsCIQsnTextColorsCG13, // softkey text color + CFbsBitmap* iconMask = NULL; + CFbsBitmap* iconPressed = NULL; + CFbsBitmap* iconPressedMask = NULL; + + TRAP_IGNORE(AknsUtils::CreateIconL( AknsUtils::SkinInstance(), + KAknsIIDQgnIndiTsButtonClose, icon, - mask, + iconMask, KAvkonBitmapFile, EMbmAvkonQgn_indi_button_preview_close, - EMbmAvkonQgn_indi_button_preview_close_mask, - KRgbWhite - ); - CleanupStack::Pop( 2 ); // codescanner::cleanup - ); + EMbmAvkonQgn_indi_button_preview_close_mask + )); + + TRAP_IGNORE(AknsUtils::CreateIconL( AknsUtils::SkinInstance(), + KAknsIIDQgnIndiTsButtonClosePressed, + iconPressed, + iconPressedMask, + KAvkonBitmapFile, + EMbmAvkonQgn_indi_button_preview_close, + EMbmAvkonQgn_indi_button_preview_close_mask + )); TAknLayoutRect gridAppPane; TAknLayoutRect gridItem; + TAknLayoutRect gridImage; TAknLayoutRect gridCloseButton; TAknLayoutRect gridCloseIcon; TInt variety = Layout_Meta_Data::IsLandscapeOrientation() ? 1 : 0; @@ -492,15 +526,21 @@ AknLayoutScalable_Apps::tport_appsw_pane( variety ) ); gridItem.LayoutRect( gridAppPane.Rect(), AknLayoutScalable_Apps::cell_tport_appsw_pane( variety, 0, 0 ) ); + gridImage.LayoutRect( gridItem.Rect(), + AknLayoutScalable_Apps::cell_tport_appsw_pane_g1( variety ) ); gridCloseButton.LayoutRect( gridItem.Rect(), AknLayoutScalable_Apps::bg_button_pane_cp16( variety, 0, 0 )); gridCloseIcon.LayoutRect( gridItem.Rect(), AknLayoutScalable_Apps::cell_tport_appsw_pane_g3( variety, 0, 0 )); + + // Set icon size AknIconUtils::SetSize( icon, gridCloseIcon.Rect().Size(), EAspectRatioPreserved ); - AknIconUtils::SetSize( mask, gridCloseIcon.Rect().Size(), EAspectRatioPreserved ); + AknIconUtils::SetSize( iconPressed, gridCloseIcon.Rect().Size(), EAspectRatioPreserved ); CTsGridItemDrawer* itemDrawer = static_cast(iItemDrawer); - itemDrawer->SetCloseIcon( icon, mask ); + + // Setup close parameters + itemDrawer->SetCloseIcon( icon, iconMask, iconPressed, iconPressedMask ); TRect relGridCloseButton = TRect( TPoint( gridCloseButton.Rect().iTl.iX - gridItem.Rect().iTl.iX, gridCloseButton.Rect().iTl.iY - gridItem.Rect().iTl.iY), gridCloseButton.Rect().Size() ); @@ -508,6 +548,15 @@ gridCloseIcon.Rect().iTl.iY - gridItem.Rect().iTl.iY), gridCloseIcon.Rect().Size() ); itemDrawer->SetCloseIconRect( relGridCloseButton, relGridCloseIconRect ); + + // Setup stroke parameters + TPoint strokeOffset; + strokeOffset.iX = gridImage.Rect().iTl.iX - gridItem.Rect().iTl.iX - KStrokeThickness; + strokeOffset.iY = gridImage.Rect().iTl.iY - gridItem.Rect().iTl.iY - KStrokeThickness; + TSize strokeSize = gridImage.Rect().Size(); + strokeSize.iHeight += KStrokeThickness * 2; + strokeSize.iWidth += KStrokeThickness * 2; + itemDrawer->SetStrokeOffset( strokeOffset, strokeSize ); } @@ -530,96 +579,8 @@ } } -// ----------------------------------------------------------------------------- -// CTsFastSwapGrid::LaunchTactileFeedback -// ----------------------------------------------------------------------------- -// -void CTsFastSwapGrid::LaunchTactileFeedback() - { - if( !iTactileFeedbackSupport ) - { - return; - } - - iFeedbackTimer->Cancel(); - iFeedbackTimer->After(KFeedbackTime); - } - -// ----------------------------------------------------------------------------- -// CTsFastSwapGrid::SetTactileFeedbackSupport -// ----------------------------------------------------------------------------- -// -void CTsFastSwapGrid::SetTactileFeedbackSupport(TBool aSupport) - { - iTactileFeedbackSupport = aSupport; - } -// ----------------------------------------------------------------------------- -// CTsFastSwapGrid::RemoveFromVisibleItems -// ----------------------------------------------------------------------------- -// -TBool CTsFastSwapGrid::RemoveFromVisibleItems(TInt aItem) const - { - TBool retVal(EFalse); - TInt idx(0); - idx = iFullyVisibleItems.Find(aItem); - if( idx >= 0) - { - iFullyVisibleItems.Remove(idx); - retVal = ETrue; - } - idx = iPartialVisibleItems.Find( aItem ); - if( idx >= 0) - { - iPartialVisibleItems.Remove(idx); - retVal = ETrue; - } - return retVal; - } - -// ----------------------------------------------------------------------------- -// CTsFastSwapGrid::AddToFullyVisibleItems -// ----------------------------------------------------------------------------- -// -TBool CTsFastSwapGrid::AddToFullyVisibleItems( TInt aItem ) const - { - TBool retVal(EFalse); - TInt idx(0); - - idx = iPartialVisibleItems.Find(aItem); - if( idx >= 0) - { - iPartialVisibleItems.Remove(idx); - } - idx = iFullyVisibleItems.Find( aItem ); - if( idx == KErrNotFound ) - { - iFullyVisibleItems.Append(aItem); - retVal = ETrue; - } - return retVal; - } - -// ----------------------------------------------------------------------------- -// CTsFastSwapGrid::MoveToPartialVisibleItems -// ----------------------------------------------------------------------------- -// -TBool CTsFastSwapGrid::MoveToPartialVisibleItems( TInt aItem ) const - { - TInt idx(0); - idx = iFullyVisibleItems.Find(aItem); - if( idx >= 0) - { - iFullyVisibleItems.Remove(idx); - } - idx = iPartialVisibleItems.Find( aItem ); - if( idx == KErrNotFound ) - { - iPartialVisibleItems.Append(aItem); - } - return EFalse; - } /* ================================================================================ * CTsGridItemDrawer @@ -632,13 +593,13 @@ // CTsGridItemDrawer::CTsGridItemDrawer( CTsFastSwapGrid* aGrid, - CFormattedCellListBoxData* aData, - TRect aScreenRect ) + CFormattedCellListBoxData* aData ) : CFormattedCellListBoxItemDrawer( aGrid->Model(), NULL, aData ), iGrid( aGrid ), - iScreenRect(aScreenRect) + iStrokeColor( KRgbBlack ), + iHighlightStrokeColor( KRgbBlack ) { } @@ -651,6 +612,9 @@ { delete iCloseIcon; delete iCloseIconMask; + delete iCloseIconPressed; + delete iCloseIconPressedMask; + iStrokeItems.Close(); } @@ -658,12 +622,17 @@ // CTsGridItemDrawer::SetCloseIcon // ----------------------------------------------------------------------------- // -void CTsGridItemDrawer::SetCloseIcon( CFbsBitmap* aBmp, CFbsBitmap* aMask ) +void CTsGridItemDrawer::SetCloseIcon( CFbsBitmap* aBmp, CFbsBitmap* aBmpMask, + CFbsBitmap* aBmpPressed, CFbsBitmap* aBmpPressedMask ) { delete iCloseIcon; iCloseIcon = aBmp; delete iCloseIconMask; - iCloseIconMask = aMask; + iCloseIconMask = aBmpMask; + delete iCloseIconPressed; + iCloseIconPressed = aBmpPressed; + delete iCloseIconPressedMask; + iCloseIconPressedMask = aBmpPressedMask; } @@ -714,6 +683,52 @@ // ----------------------------------------------------------------------------- +// CTsGridItemDrawer::SetStrokeColor +// ----------------------------------------------------------------------------- +// +void CTsGridItemDrawer::SetStrokeColors( TRgb aColor, + TRgb aHighlightedColor ) + { + iStrokeColor = aColor; + iHighlightStrokeColor = aHighlightedColor; + } + + +// ----------------------------------------------------------------------------- +// CTsGridItemDrawer::SetStrokeItemsL +// ----------------------------------------------------------------------------- +// +void CTsGridItemDrawer::SetStrokeItemsL( RArray& aItemIndex ) + { + iStrokeItems.Close(); + for ( TInt i = 0; i < aItemIndex.Count(); i++ ) + { + iStrokeItems.AppendL( aItemIndex[i] ); + } + } + + +// ----------------------------------------------------------------------------- +// CTsGridItemDrawer::SetStrokeOffset +// ----------------------------------------------------------------------------- +// +void CTsGridItemDrawer::SetStrokeOffset( TPoint aStrokeOffset, TSize aStrokeSize ) + { + iStrokeRect = TRect( aStrokeOffset, aStrokeSize ); + } + + +// ----------------------------------------------------------------------------- +// CTsGridItemDrawer::SetScreenRect +// ----------------------------------------------------------------------------- +// +void CTsGridItemDrawer::SetScreenRect( TRect aRect ) + { + iScreenRect = aRect; + } + + +// ----------------------------------------------------------------------------- // CTsGridItemDrawer::DrawActualItem // ----------------------------------------------------------------------------- // @@ -721,8 +736,6 @@ TBool aItemIsCurrent, TBool aViewIsEmphasized, TBool aViewIsDimmed, TBool aItemIsSelected ) const { - TBool feedbackNeed(EFalse);//feedback when item disappear or fully appear - if (IsItemRectVisible(aActualItemRect)) { // Calculate offset of the visible rectangle @@ -736,15 +749,6 @@ drawRect.iBr.iX = iScreenRect.Width() - iRightOffset; } iGc->SetClippingRect(drawRect); - - if(IsRectContained( aActualItemRect, drawRect )) - { - feedbackNeed = iGrid->AddToFullyVisibleItems( aItemIndex ); - } - else - { - feedbackNeed = iGrid->MoveToPartialVisibleItems( aItemIndex ); - } // Check for item highlight TBool itemIsCurrent = !iGrid->IsHighlightVisible() ? EFalse : aItemIsCurrent; @@ -769,7 +773,25 @@ CFormattedCellListBoxItemDrawer::DrawActualItem(aItemIndex, aActualItemRect, itemIsCurrent, aViewIsEmphasized, aViewIsDimmed, aItemIsSelected ); - if ( iGrid->CanCloseItem( aItemIndex ) && iCloseIcon && iCloseIconMask ) + // Draw stroke + if ( iStrokeItems.Find( aItemIndex ) != KErrNotFound ) + { + TRect strokeRect = iStrokeRect; + strokeRect.Move( aActualItemRect.iTl ); + if ( itemIsCurrent ) + { + iGc->SetPenColor( iHighlightStrokeColor ); + } + else + { + iGc->SetPenColor( iStrokeColor ); + } + // Thumbnail stroke + iGc->DrawRect( strokeRect ); + } + + // Draw close button + if ( iGrid->CanCloseItem( aItemIndex ) && iCloseIcon && iCloseIconPressed ) { TRect closeIconRect = GetCloseButtonRect( aActualItemRect ); // Draw frame @@ -778,27 +800,24 @@ MAknsSkinInstance* skin = AknsUtils::SkinInstance(); if ( iGrid->IsItemCloseHit( aItemIndex ) ) { - AknsDrawUtils::DrawFrame(skin, *iGc, outerRect, innerRect, - KAknsIIDQgnFrSctrlButtonPressed, KAknsIIDQgnFrSctrlButtonCenterPressed); + TRect sourceRect( TPoint(0,0), iCloseIconPressed->SizeInPixels() ); + iGc->DrawBitmapMasked( innerRect, + iCloseIconPressed, + sourceRect, + iCloseIconPressedMask, + ETrue ); } else { - AknsDrawUtils::DrawFrame(skin, *iGc, outerRect, innerRect, - KAknsIIDQgnFrSctrlButton, KAknsIIDQgnFrSctrlButtonCenter); + TRect sourceRect( TPoint(0,0), iCloseIcon->SizeInPixels() ); + iGc->DrawBitmapMasked( innerRect, + iCloseIcon, + sourceRect, + iCloseIconMask, + ETrue ); } - // Draw close icon - TRect sourceRect( TPoint(0,0), iCloseIcon->SizeInPixels() ); - iGc->DrawBitmapMasked( innerRect, iCloseIcon, sourceRect, iCloseIconMask, ETrue ); } } - else - { - feedbackNeed = iGrid->RemoveFromVisibleItems(aItemIndex); - } - if(feedbackNeed) - { - iGrid->LaunchTactileFeedback(); - } } // -----------------------------------------------------------------------------