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