phoneuis/easydialing/src/easydialinglistboxdata.cpp
branchRCL_3
changeset 81 c26cc2a7c548
parent 62 5266b1f337bd
equal deleted inserted replaced
73:e30d4a1b8bad 81:c26cc2a7c548
   129 // LOCAL FUNCTION PROTOTYPES
   129 // LOCAL FUNCTION PROTOTYPES
   130 static TRect ContactNameBoundingBox(
   130 static TRect ContactNameBoundingBox(
   131         const TRect& aItemRect, 
   131         const TRect& aItemRect, 
   132         const CFont* aContactNameFont, 
   132         const CFont* aContactNameFont, 
   133         TBool aArrowIconShown,
   133         TBool aArrowIconShown,
   134         TBool aFavOrSimIconShown, 
   134         TBool aIsFavourite, 
   135         TBool aThumbnailsShown );
   135         TBool aThumbnailsShown );
   136 static TRect CompanyNameBoundingBox(
   136 static TRect CompanyNameBoundingBox(
   137         const TRect& aItemRect, 
   137         const TRect& aItemRect, 
   138         const CFont* aCompanyNameFont, 
   138         const CFont* aCompanyNameFont, 
   139         TBool aIsCurrentItem,
   139         TBool aIsCurrentItem,
   140         TBool aThumbnailsShown );
   140         TBool aThumbnailsShown );
   141 static TRect FavouriteIconBoundingBox( const TRect& aContactNameBoundingBox );
   141 static TRect FavouriteIconBoundingBox( const TRect& aContactNameBoundingBox );
   142 static TRect SimIconBoundingBox( const TRect& aContactNameBoundingBox );
       
   143 static TRect MirrorLayoutBoundingBox(const TRect& aSourceRect, TRect& aBoundingBoxRect);
   142 static TRect MirrorLayoutBoundingBox(const TRect& aSourceRect, TRect& aBoundingBoxRect);
   144 static TInt BaseLineOffset( const TRect& aTextBoundingBox, const CFont* aFont );
   143 static TInt BaseLineOffset( const TRect& aTextBoundingBox, const CFont* aFont );
   145 static TBool ContainsRightToLeftText( const TDesC& aDesc );
   144 static TBool ContainsRightToLeftText( const TDesC& aDesc );
   146 static TInt HighlightSeparatorCount( const TDesC& aText );
   145 static TInt HighlightSeparatorCount( const TDesC& aText );
   147 static HBufC* ConvertToVisualAndClipLC( const TDesC& aText, const CFont& aFont, const TRect& aBoundingBox ); 
   146 static HBufC* ConvertToVisualAndClipLC( const TDesC& aText, const CFont& aFont, const TRect& aBoundingBox ); 
   250     delete iArrowPointingRight;
   249     delete iArrowPointingRight;
   251     delete iArrowPointingLeft;
   250     delete iArrowPointingLeft;
   252     delete iColorBitmap;
   251     delete iColorBitmap;
   253     delete iDummyThumbnail;
   252     delete iDummyThumbnail;
   254     delete iFavouriteIcon;
   253     delete iFavouriteIcon;
   255     delete iSimContactIcon;
       
   256     delete iSdnContactIcon;
       
   257     
   254     
   258     iContactDataManager = NULL;
   255     iContactDataManager = NULL;
   259     }
   256     }
   260 
   257 
   261 // -----------------------------------------------------------------------------
   258 // -----------------------------------------------------------------------------
   307 // -----------------------------------------------------------------------------
   304 // -----------------------------------------------------------------------------
   308 //
   305 //
   309 void CEasyDialingListBoxData::ConstructLD()
   306 void CEasyDialingListBoxData::ConstructLD()
   310     {
   307     {
   311     CFormattedCellListBoxData::ConstructLD();
   308     CFormattedCellListBoxData::ConstructLD();
   312     
       
   313     MAknsSkinInstance* skin = AknsUtils::SkinInstance();
       
   314     
   309     
   315     // EasyDialing bitmap file is attempted to be read from the same directory where the
   310     // EasyDialing bitmap file is attempted to be read from the same directory where the
   316     // executed binary is located
   311     // executed binary is located
   317     TFileName dllFileName;
   312     TFileName dllFileName;
   318     Dll::FileName( dllFileName );
   313     Dll::FileName( dllFileName );
   338             EMbmPhonebook2eceQgn_prop_pb_thumb_unknown, EMbmPhonebook2eceQgn_prop_pb_thumb_unknown_mask );
   333             EMbmPhonebook2eceQgn_prop_pb_thumb_unknown, EMbmPhonebook2eceQgn_prop_pb_thumb_unknown_mask );
   339     
   334     
   340     // Create the favourite icon bitmap and mask
   335     // Create the favourite icon bitmap and mask
   341     iFavouriteIcon = CreateIconL( KFavouriteIconBitmapFile, 
   336     iFavouriteIcon = CreateIconL( KFavouriteIconBitmapFile, 
   342             EMbmPhonebook2Qgn_prop_pb_topc, EMbmPhonebook2Qgn_prop_pb_topc_mask );
   337             EMbmPhonebook2Qgn_prop_pb_topc, EMbmPhonebook2Qgn_prop_pb_topc_mask );
   343 
       
   344     // Create SIM contact icon from the skin 
       
   345     iSimContactIcon = AknsUtils::CreateGulIconL( skin, KAknsIIDQgnPropNrtypSimContact, bitmapFileName,
       
   346             EMbmEasydialingQgn_prop_nrtyp_sim_contact, EMbmEasydialingQgn_prop_nrtyp_sim_contact_mask );
       
   347 
       
   348     // Create Service Dialing Number contact icon from the skin
       
   349     iSdnContactIcon = AknsUtils::CreateGulIconL( skin, KAknsIIDQgnPropNrtypSdn, bitmapFileName,
       
   350             EMbmEasydialingQgn_prop_nrtyp_sdn, EMbmEasydialingQgn_prop_nrtyp_sdn_mask );
       
   351     }
   338     }
   352 
   339 
   353 
   340 
   354 // -----------------------------------------------------------------------------
   341 // -----------------------------------------------------------------------------
   355 // DrawHighlight
   342 // DrawHighlight
   418         TBool aHighlight,
   405         TBool aHighlight,
   419         const TExtendedColors& aColors ) const
   406         const TExtendedColors& aColors ) const
   420     {
   407     {
   421     TPtrC cellText;
   408     TPtrC cellText;
   422 
   409 
   423     TInt error = TextUtils::ColumnText( cellText, 0, aText );
   410     TInt error = TextUtils::ColumnText( cellText , 0, aText );
   424     __ASSERT_DEBUG( error == KErrNone, EasyDialingPanic( EEasyDialingPanicInvalidListBoxModelString ) );
   411     __ASSERT_DEBUG( error == KErrNone, EasyDialingPanic( EEasyDialingPanicInvalidListBoxModelString ) );
   425     __ASSERT_DEBUG( iContactNameFont, EasyDialingPanic( EEasyDialingNoFontFound ) );
   412     __ASSERT_DEBUG( iContactNameFont, EasyDialingPanic( EEasyDialingNoFontFound ) );
   426     __ASSERT_DEBUG( iCompanyNameFont, EasyDialingPanic( EEasyDialingNoFontFound ) );
   413     __ASSERT_DEBUG( iCompanyNameFont, EasyDialingPanic( EEasyDialingNoFontFound ) );
   427     
   414     
   428     TInt contactDataIndex = iContactDataManager->IndexForId( cellText );
       
   429 
       
   430     MAknListBoxTfxInternal* transApi = CAknListLoader::TfxApiInternal( &aGc );
   415     MAknListBoxTfxInternal* transApi = CAknListLoader::TfxApiInternal( &aGc );
   431     if ( transApi )
   416     if ( transApi )
   432         {
   417         {
   433         transApi->StartDrawing( MAknListBoxTfxInternal::EListItem );
   418         transApi->StartDrawing( MAknListBoxTfxInternal::EListItem );
   434         if ( transApi->EffectsDisabled() )
   419         if ( transApi->EffectsDisabled() )
   441     if ( AknLayoutUtils::LayoutMirrored() )
   426     if ( AknLayoutUtils::LayoutMirrored() )
   442         {
   427         {
   443         boundingBox = MirrorLayoutBoundingBox( aItemRect, boundingBox );
   428         boundingBox = MirrorLayoutBoundingBox( aItemRect, boundingBox );
   444         }
   429         }
   445     
   430     
   446     //Draws the Contact Thumbnail Icon if exists, else draws the dummy contact thumbnail
       
   447     DrawContactThumbnail( aGc, boundingBox, contactDataIndex );
       
   448 
       
   449     // Arrow icon is drawn if the item is in focus and listbox has focus
   431     // Arrow icon is drawn if the item is in focus and listbox has focus
   450     // (and not only the temporary visual focus caused by touching a list item).
   432     // (and not only the temporary visual focus caused by touching a list item).
   451     TBool showArrowIcon = aHighlight && iControl->IsFocused();
   433     TBool showArrowIcon = aHighlight && iControl->IsFocused();
   452     if ( showArrowIcon )
   434     if ( showArrowIcon )
   453         {
   435         {
   457             arrowRect = MirrorLayoutBoundingBox( aItemRect, arrowRect );
   439             arrowRect = MirrorLayoutBoundingBox( aItemRect, arrowRect );
   458             }
   440             }
   459         DrawArrowIcon( aGc, arrowRect );
   441         DrawArrowIcon( aGc, arrowRect );
   460         }
   442         }
   461 
   443 
   462     TBool favOrSimContact = 
   444     //Draws the Contact Thumbnail Icon if exists, else draws the dummy contact thumbnail
   463             iContactDataManager->IsFav( contactDataIndex ) ||
   445     TBool fav = DrawContactThumbnail( aGc, boundingBox, cellText );
   464             iContactDataManager->IsSimContact( contactDataIndex ) ||
   446 
   465             iContactDataManager->IsSdnContact( contactDataIndex );
   447     error = TextUtils::ColumnText( cellText , 1, aText );
       
   448     __ASSERT_DEBUG( error == KErrNone, EasyDialingPanic( EEasyDialingPanicInvalidListBoxModelString ) );
       
   449 
   466     boundingBox = ContactNameBoundingBox( aItemRect,
   450     boundingBox = ContactNameBoundingBox( aItemRect,
   467                                           iContactNameFont,
   451                                           iContactNameFont,
   468                                           showArrowIcon,
   452                                           showArrowIcon,
   469                                           favOrSimContact,
   453                                           fav,
   470                                           iContactDataManager->GetContactThumbnailSetting() );
   454                                           iContactDataManager->GetContactThumbnailSetting() );
   471     
   455     TRect nameRectUnMirrored = boundingBox; // used for favourite star drawing
   472     // Draw favorite or sim icon if necessary. Only one of these can be drawn.
   456 
   473     TRect nameRectUnMirrored = boundingBox;
       
   474     if ( iContactDataManager->IsFav( contactDataIndex ) )
       
   475         {
       
   476         DrawFavouriteIcon( aGc, nameRectUnMirrored, aItemRect );
       
   477         }
       
   478     else if ( iContactDataManager->IsSimContact( contactDataIndex ) )
       
   479         {
       
   480         DrawSimIcon( *iSimContactIcon, aGc, nameRectUnMirrored, aItemRect );
       
   481         }
       
   482     else if ( iContactDataManager->IsSdnContact( contactDataIndex ) )
       
   483         {
       
   484         DrawSimIcon( *iSdnContactIcon, aGc, nameRectUnMirrored, aItemRect );
       
   485         }
       
   486     
       
   487     // Mirror the bounding box for text drawing if necessary.
       
   488     if ( AknLayoutUtils::LayoutMirrored() )
   457     if ( AknLayoutUtils::LayoutMirrored() )
   489         {
   458         {
   490         boundingBox = MirrorLayoutBoundingBox( aItemRect, boundingBox );
   459         boundingBox = MirrorLayoutBoundingBox( aItemRect, boundingBox );
   491         }
   460         }
   492 
   461 
   493     // Draw 1st row text
   462     // favourite icon size is set the same as contact name bounding box height.
   494     error = TextUtils::ColumnText( cellText , 1, aText );
   463     TInt favouriteIconSize = boundingBox.Height();
   495     __ASSERT_DEBUG( error == KErrNone, EasyDialingPanic( EEasyDialingPanicInvalidListBoxModelString ) );
   464     
   496 
       
   497     TInt err( KErrNone );
   465     TInt err( KErrNone );
   498     TRAP( err, DrawTextWithMatchHighlightL(
   466     TRAP( err, DrawTextWithMatchHighlightL(
   499             boundingBox, aGc, cellText, iContactNameFont, aColors, aHighlight ) );
   467             boundingBox, aGc, cellText, iContactNameFont, aColors, aHighlight ) );
   500 
   468 
   501     // Draw 2nd row text
       
   502     if ( !err && TextUtils::ColumnText( cellText , 2, aText ) == KErrNone ) 
   469     if ( !err && TextUtils::ColumnText( cellText , 2, aText ) == KErrNone ) 
   503         {
   470         {
   504         TRect companyNameBoundingBox = CompanyNameBoundingBox( 
   471         TRect companyNameBoundingBox = CompanyNameBoundingBox( 
   505                 aItemRect, iCompanyNameFont, aHighlight, iContactDataManager->GetContactThumbnailSetting() );
   472                 aItemRect, iCompanyNameFont, aHighlight, iContactDataManager->GetContactThumbnailSetting() );
   506         if ( AknLayoutUtils::LayoutMirrored() )
   473         if ( AknLayoutUtils::LayoutMirrored() )
   509             }
   476             }
   510         TRAP( err, DrawTextWithMatchHighlightL(
   477         TRAP( err, DrawTextWithMatchHighlightL(
   511                 companyNameBoundingBox, aGc, cellText, iCompanyNameFont, aColors, aHighlight ) );
   478                 companyNameBoundingBox, aGc, cellText, iCompanyNameFont, aColors, aHighlight ) );
   512         }
   479         }
   513 
   480 
       
   481     if ( !err && fav )
       
   482         {
       
   483         // Draws the Favourite Icon
       
   484         DrawFavouriteIcon( aGc, nameRectUnMirrored, aItemRect );
       
   485         }
       
   486     
   514     if ( transApi )
   487     if ( transApi )
   515         {
   488         {
   516         aGc.CancelClippingRect();
   489         aGc.CancelClippingRect();
   517         transApi->StopDrawing();
   490         transApi->StopDrawing();
   518         }
   491         }
   520 
   493 
   521 // -----------------------------------------------------------------------------
   494 // -----------------------------------------------------------------------------
   522 // DrawContactThumbnail
   495 // DrawContactThumbnail
   523 // 
   496 // 
   524 // Draws the Contact Thumbnail Icon if any, else draws the dummy contact thumbnail
   497 // Draws the Contact Thumbnail Icon if any, else draws the dummy contact thumbnail
   525 // -----------------------------------------------------------------------------
   498 // Also check if this is a favorite contact and return true if this is.
   526 //
   499 // -----------------------------------------------------------------------------
   527 void CEasyDialingListBoxData::DrawContactThumbnail(
   500 //
   528         CWindowGc& aGc, TRect aBoundingBox, TInt aContactIndex ) const
   501 TBool CEasyDialingListBoxData::DrawContactThumbnail(CWindowGc& aGc, TRect aBoundingBox, TPtrC aCellText) const
   529     {
   502     {
       
   503     TBool fav(EFalse);
   530     CFbsBitmap* thumbnail(NULL);
   504     CFbsBitmap* thumbnail(NULL);
   531     TBool isLoaded = iContactDataManager->GetThumbnail(aContactIndex, thumbnail);
   505     TBool isLoaded = iContactDataManager->GetThumbnailAndFav(aCellText, thumbnail, fav);
   532     if ( isLoaded && thumbnail )
   506     if ( isLoaded && thumbnail )
   533         {
   507         {
   534         // center the thumbnail in its rect
   508         // center the thumbnail in its rect
   535         TSize size(thumbnail->SizeInPixels());
   509         TSize size(thumbnail->SizeInPixels());
   536         TInt xOffset = (aBoundingBox.Width() - size.iWidth) / 2;
   510         TInt xOffset = (aBoundingBox.Width() - size.iWidth) / 2;
   541         }
   515         }
   542     else if ( isLoaded && iContactDataManager->GetContactThumbnailSetting() )
   516     else if ( isLoaded && iContactDataManager->GetContactThumbnailSetting() )
   543         {
   517         {
   544         // draw dummy thumnbnail, but only if we know that the contact doesn't
   518         // draw dummy thumnbnail, but only if we know that the contact doesn't
   545         // have a thumbnail, and thumbnail drawing is enabled.
   519         // have a thumbnail, and thumbnail drawing is enabled.
   546         AknIconUtils::SetSize( iDummyThumbnail->Bitmap(), aBoundingBox.Size() );
   520         AknIconUtils::SetSize(iDummyThumbnail->Bitmap(), aBoundingBox.Size());
   547         AknIconUtils::SetSize( iDummyThumbnail->Mask(), aBoundingBox.Size() );
   521         AknIconUtils::SetSize(iDummyThumbnail->Mask(), aBoundingBox.Size());
   548         aGc.BitBltMasked( aBoundingBox.iTl, iDummyThumbnail->Bitmap(),
   522         aGc.BitBltMasked( aBoundingBox.iTl, iDummyThumbnail->Bitmap(),
   549                 TRect( TPoint(0,0), aBoundingBox.Size() ), 
   523                 TRect( TPoint(0,0), aBoundingBox.Size() ), 
   550                 iDummyThumbnail->Mask(), ETrue );
   524                 iDummyThumbnail->Mask(), ETrue );
   551         }
   525         }
       
   526     return fav;
   552     }
   527     }
   553 
   528 
   554 
   529 
   555 // -----------------------------------------------------------------------------
   530 // -----------------------------------------------------------------------------
   556 // DrawArrowIcon
   531 // DrawArrowIcon
   614         AknIconUtils::SetSize( iFavouriteIcon->Mask(), favouriteIconBoundingBox.Size() );
   589         AknIconUtils::SetSize( iFavouriteIcon->Mask(), favouriteIconBoundingBox.Size() );
   615         aGc.BitBltMasked( favouriteIconBoundingBox.iTl, iFavouriteIcon->Bitmap(), 
   590         aGc.BitBltMasked( favouriteIconBoundingBox.iTl, iFavouriteIcon->Bitmap(), 
   616                 sourceRect, iFavouriteIcon->Mask(), ETrue );
   591                 sourceRect, iFavouriteIcon->Mask(), ETrue );
   617         }
   592         }
   618     }
   593     }
   619 
       
   620 // -----------------------------------------------------------------------------
       
   621 // DrawSimIcon
       
   622 // 
       
   623 // Draws the SIM or SDN contact icon
       
   624 // -----------------------------------------------------------------------------
       
   625 //
       
   626 void CEasyDialingListBoxData::DrawSimIcon(
       
   627         CGulIcon& aIcon,
       
   628         CWindowGc& aGc, 
       
   629         TRect aNameRectUnMirrored,
       
   630         TRect aEffectiveRect ) const
       
   631     {
       
   632     TRect simIconBoundingBox;
       
   633 
       
   634     simIconBoundingBox = SimIconBoundingBox( aNameRectUnMirrored );
       
   635 
       
   636     if ( AknLayoutUtils::LayoutMirrored() )
       
   637         {
       
   638         simIconBoundingBox = MirrorLayoutBoundingBox(aEffectiveRect, simIconBoundingBox);
       
   639         }
       
   640 
       
   641     aGc.SetBrushStyle( CGraphicsContext::ENullBrush );
       
   642     TRect sourceRect( TPoint(0,0), simIconBoundingBox.Size() );
       
   643 
       
   644     // Set size for the bitmap and mask
       
   645     AknIconUtils::SetSize( aIcon.Bitmap(), simIconBoundingBox.Size() );
       
   646     AknIconUtils::SetSize( aIcon.Mask(), simIconBoundingBox.Size() );
       
   647     aGc.BitBltMasked( simIconBoundingBox.iTl, aIcon.Bitmap(), 
       
   648             sourceRect, aIcon.Mask(), ETrue );
       
   649     }
       
   650 
       
   651 // -----------------------------------------------------------------------------
   594 // -----------------------------------------------------------------------------
   652 // SetContactDataManager
   595 // SetContactDataManager
   653 // 
   596 // 
   654 // -----------------------------------------------------------------------------
   597 // -----------------------------------------------------------------------------
   655 //
   598 //
   806 //
   749 //
   807 static TRect ContactNameBoundingBox(
   750 static TRect ContactNameBoundingBox(
   808         const TRect& aItemRect,
   751         const TRect& aItemRect,
   809         const CFont* aContactNameFont,
   752         const CFont* aContactNameFont,
   810         TBool aArrowIconShown,
   753         TBool aArrowIconShown,
   811         TBool aFavOrSimIconShown,
   754         TBool aIsFavourite,
   812         TBool aThumbnailsShown )
   755         TBool aThumbnailsShown )
   813     {
   756     {
   814     // Position X will contain the starting position of text from left side of item rect.
   757     // Position X will contain the starting position of text from left side of item rect.
   815     TInt positionX = aItemRect.Width() * KMarginXPercent / KCent;
   758     TInt positionX = aItemRect.Width() * KMarginXPercent / KCent;
   816     
   759     
   830     if ( aArrowIconShown )
   773     if ( aArrowIconShown )
   831         {
   774         {
   832         rightMargin += KArrowIconSizePercent * aItemRect.Height() / KCent;
   775         rightMargin += KArrowIconSizePercent * aItemRect.Height() / KCent;
   833         }
   776         }
   834     
   777     
   835     // If item is favourite or a SIM contact, reserve space for the icon. 
   778     // If item is favourite, reserve space for favourite icon. Icon dimensions are the same as bounding box height.
   836     // Icon dimensions are the same as bounding box height.
   779     if ( aIsFavourite )
   837     if ( aFavOrSimIconShown )
       
   838         {
   780         {
   839         rightMargin += height;
   781         rightMargin += height;
   840         }
   782         }
   841     
   783     
   842     return TRect(
   784     return TRect(
   927             aContactNameBoundingBox.iBr.iY);
   869             aContactNameBoundingBox.iBr.iY);
   928     rect.Shrink( shrinkMargin, shrinkMargin );
   870     rect.Shrink( shrinkMargin, shrinkMargin );
   929     return rect;
   871     return rect;
   930     }
   872     }
   931 
   873 
   932 
       
   933 // -----------------------------------------------------------------------------
       
   934 // SimIconBoundingBox
       
   935 // Calculates the area to which the sim/sdn icon is drawn.
       
   936 // -----------------------------------------------------------------------------
       
   937 //
       
   938 static TRect SimIconBoundingBox( const TRect& aContactNameBoundingBox )
       
   939     {
       
   940     // use the same bounding box as is used for the favourite icon
       
   941     return FavouriteIconBoundingBox( aContactNameBoundingBox );
       
   942     }
       
   943 
   874 
   944 
   875 
   945 // -----------------------------------------------------------------------------
   876 // -----------------------------------------------------------------------------
   946 // BaseLineOffset
   877 // BaseLineOffset
   947 //
   878 //