phoneuis/BubbleManager/Src/BMMainPaneControl.cpp
branchRCL_3
changeset 62 5266b1f337bd
child 81 c26cc2a7c548
equal deleted inserted replaced
61:41a7f70b3818 62:5266b1f337bd
       
     1 /*
       
     2 * Copyright (c) 2008 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:  Call status indicator
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "BMBubbleManager.h"
       
    20 #include "BMMainPaneControl.h"
       
    21 #include "BMCustomManager.h"
       
    22 #include "BMBubbleHeader.h"
       
    23 #include "BMUtils.h"
       
    24 #include "BMCallObjectManager.h"
       
    25 #include "BMBubbleImageManager.h"
       
    26 
       
    27 #include <telbubblecallimage.h>
       
    28 #include <AknIconUtils.h>
       
    29 #include <layoutmetadata.cdl.h>
       
    30 
       
    31 #define SCALE_FACTOR 1.5
       
    32 
       
    33 // ---------------------------------------------------------------------------
       
    34 // C++ constructor
       
    35 // ---------------------------------------------------------------------------
       
    36 //
       
    37 CBubbleMainPaneControl::CBubbleMainPaneControl( 
       
    38     CBubbleManager& aBubbleManager,  
       
    39     CBubbleCallObjectManager& aCallObjectManager ) : 
       
    40     iBubbleManager( aBubbleManager ), 
       
    41     iCallObjectManager ( aCallObjectManager ),
       
    42     iScaler( NULL ),
       
    43     iScaledImage( NULL )
       
    44     {
       
    45     }
       
    46 
       
    47 // ---------------------------------------------------------------------------
       
    48 // ConstructL
       
    49 // ---------------------------------------------------------------------------
       
    50 //
       
    51 void CBubbleMainPaneControl::ConstructL()
       
    52     {
       
    53     iScaler = CTelBubbleImageScaler::NewL( *this );
       
    54     }
       
    55 
       
    56 // ---------------------------------------------------------------------------
       
    57 // NewL
       
    58 // ---------------------------------------------------------------------------
       
    59 //
       
    60 CBubbleMainPaneControl* CBubbleMainPaneControl::NewL(
       
    61     CBubbleManager& aBubbleManager,
       
    62     CBubbleCallObjectManager& aCallObjectManager )
       
    63     {
       
    64     CBubbleMainPaneControl* self = 
       
    65         new( ELeave ) CBubbleMainPaneControl( aBubbleManager, 
       
    66                                                aCallObjectManager );
       
    67     CleanupStack::PushL( self );
       
    68     self->ConstructL();
       
    69     CleanupStack::Pop( self );
       
    70     return self;
       
    71     }
       
    72 
       
    73 
       
    74 // ---------------------------------------------------------------------------
       
    75 // Destructor
       
    76 // ---------------------------------------------------------------------------
       
    77 //
       
    78 CBubbleMainPaneControl::~CBubbleMainPaneControl()
       
    79     {
       
    80     delete iScaler;
       
    81     iScaler = NULL;
       
    82     
       
    83     delete iScaledImage;
       
    84     iScaledImage = NULL;	
       
    85     }
       
    86 
       
    87 // ---------------------------------------------------------------------------
       
    88 // ReadBubbleHeader
       
    89 // ---------------------------------------------------------------------------
       
    90 //
       
    91 void CBubbleMainPaneControl::ReadBubbleHeader( 
       
    92     const CBubbleHeader& aHeader )
       
    93     {
       
    94     iBubble = aHeader.BubbleId();
       
    95     TBool thumbnail( EFalse );
       
    96     TBool noScaling( EFalse );
       
    97     
       
    98     if ( aHeader.CallObjectImage() )
       
    99         {
       
   100         iBitmap = aHeader.CallObjectImage();
       
   101         iMask = aHeader.CallObjectImageMask();
       
   102         }
       
   103     else if ( aHeader.TnBitmap() )
       
   104         {
       
   105         iBitmap = aHeader.TnBitmap();
       
   106         iMask = aHeader.TnBitmapMask();
       
   107         thumbnail = ETrue;
       
   108         }
       
   109     else
       
   110         {
       
   111         iBitmap = NULL;
       
   112         }
       
   113     
       
   114     iThreeLinedBubble = ( aHeader.CNAP().Length() > 0 );
       
   115     
       
   116     // PrepareBitmapsL() needs to know if a brand new thumbnail is about to get prepared.
       
   117     if ( thumbnail && (iOldBitmap != NULL) && (iOldBitmap == iBitmap) && (iScaler->GetState() != CTelBubbleImageScaler::EScalingStarted) )
       
   118         {
       
   119         noScaling = ETrue;
       
   120         }
       
   121     
       
   122     if ( iBitmap )
       
   123         {
       
   124         iOldBitmap = iBitmap;
       
   125         
       
   126         CFbsBitmap* bitmap( NULL );
       
   127         CFbsBitmap* mask( NULL );
       
   128         TBool bitmapOwnership( EFalse );
       
   129         TBool maskOwnership( EFalse );
       
   130         
       
   131         TRAPD(err, PrepareBitmapsL( bitmap, 
       
   132                                     bitmapOwnership, 
       
   133                                     mask, 
       
   134                                     maskOwnership,
       
   135                                     aHeader.CallObjectImageType() == 
       
   136                                     CBubbleHeader::EThemeImage,
       
   137                                     noScaling ));
       
   138         
       
   139         if ( err )
       
   140             {
       
   141             return;
       
   142             }
       
   143 
       
   144         iCallImage = iBubbleManager.CustomManager().ReserveCustomElement(
       
   145                 aHeader, CTelBubbleCustomElement::ECallImage );
       
   146         SizeChanged();
       
   147         
       
   148         if ( iCallImage->ControlType() == 
       
   149              CTelBubbleCustomElement::EBubbleCallImage )
       
   150             {
       
   151             CTelBubbleCallImage* image = 
       
   152                 static_cast<CTelBubbleCallImage*> ( iCallImage->Control() );
       
   153             image->SetImage( bitmap, EFalse, mask, maskOwnership );
       
   154             } 
       
   155         
       
   156         iIsUsed = ETrue;
       
   157         MakeVisible( ETrue );
       
   158         
       
   159         // upscale thumbnails if loading it for the first time.
       
   160         if ( thumbnail && !noScaling && ( iScaler->GetState() != CTelBubbleImageScaler::EScalingStarted ) )
       
   161             {
       
   162             StartScaling( iBitmap );
       
   163             }
       
   164         }
       
   165     }
       
   166 
       
   167 // ---------------------------------------------------------------------------
       
   168 // PrepareBitmapsL
       
   169 // ---------------------------------------------------------------------------
       
   170 //
       
   171 void CBubbleMainPaneControl::PrepareBitmapsL( 
       
   172     CFbsBitmap*& aBitmap,
       
   173     TBool& aBitmapOwnership, 
       
   174     CFbsBitmap*& aMask,
       
   175     TBool& aMaskOwnership,
       
   176     TBool aIsScalable,
       
   177     TBool aThumbnail )
       
   178     {
       
   179     if ( aThumbnail )
       
   180         {
       
   181         aBitmap = iScaledImage;
       
   182         }
       
   183     else
       
   184         {
       
   185         aBitmap = iBitmap;
       
   186         }
       
   187 
       
   188     aMask = iMask;
       
   189     aBitmapOwnership = EFalse;
       
   190     aMaskOwnership = EFalse;
       
   191     
       
   192     if ( aIsScalable )
       
   193         {
       
   194         // Switch to preloaded image when available
       
   195         if ( iCallObjectManager.CallThemeImageIcon() )
       
   196             {
       
   197             aBitmap = iCallObjectManager.CallThemeImageIcon()->Bitmap();
       
   198             aMask = iCallObjectManager.CallThemeImageIcon()->Mask();
       
   199             }
       
   200     
       
   201         // Secure that SVG image is initialized
       
   202         User::LeaveIfError( AknIconUtils::SetSize( aBitmap,
       
   203              iBubbleManager.MainPaneImageRect().Size(),
       
   204              EAspectRatioPreservedSlice ) != KErrNone );
       
   205         }
       
   206     
       
   207     TSize imageSize = aBitmap->SizeInPixels();
       
   208     TSize tinyImageSize( iBubbleManager.MainPaneImageRect( ETrue ).Size() );
       
   209     TBool fullScreen = !( ( imageSize.iWidth <= tinyImageSize.iWidth ) &&
       
   210                           ( imageSize.iHeight <= tinyImageSize.iHeight ) );  
       
   211     
       
   212     if ( iBubbleManager.IsTouchCallHandling() &&
       
   213          fullScreen )
       
   214         {
       
   215         // Attach display mask to image.
       
   216         CEikImage* displayMask = new( ELeave ) CEikImage;
       
   217         CleanupStack::PushL( displayMask ); 
       
   218     
       
   219         TBMIcons maskId = 
       
   220             Layout_Meta_Data::IsLandscapeOrientation() ?
       
   221             EQgn_indi_call4_image_mask_lsc :
       
   222             EQgn_indi_call4_image_mask_prt;
       
   223     
       
   224         iBubbleManager.ImageManager().SetBitmapToImage( 
       
   225             displayMask,
       
   226             maskId );
       
   227     
       
   228         User::LeaveIfError( AknIconUtils::SetSize( 
       
   229             const_cast<CFbsBitmap*> (displayMask->Bitmap()),
       
   230             imageSize,
       
   231             EAspectRatioNotPreserved ) );
       
   232             
       
   233         if ( aMask )
       
   234             {
       
   235             // Combine display mask and image mask.
       
   236             CFbsBitmap* combinedMask = 
       
   237                 BubbleUtils::CreateCombinedMaskL(
       
   238                     displayMask->Bitmap(),
       
   239                     aMask );        
       
   240             aMask = combinedMask;
       
   241             }
       
   242         else
       
   243             {
       
   244             aMask = 
       
   245                 const_cast<CFbsBitmap*> ( displayMask->Bitmap());
       
   246             displayMask->SetPictureOwnedExternally( ETrue );
       
   247             }                        
       
   248             
       
   249         aMaskOwnership = ETrue;    
       
   250         CleanupStack::PopAndDestroy( displayMask );
       
   251         }    
       
   252     }
       
   253 
       
   254 // ---------------------------------------------------------------------------
       
   255 // Reset
       
   256 // ---------------------------------------------------------------------------
       
   257 //
       
   258 void CBubbleMainPaneControl::Reset()
       
   259     {
       
   260     if ( iIsUsed )
       
   261         {
       
   262         iIsUsed = EFalse;
       
   263         MakeVisible( EFalse );
       
   264         iBubble = KErrNotFound;
       
   265         
       
   266         if ( iCallImage && 
       
   267              iCallImage->ControlType() == 
       
   268              CTelBubbleCustomElement::EBubbleCallImage )
       
   269             {
       
   270             CTelBubbleCallImage* image = 
       
   271                 static_cast<CTelBubbleCallImage*> ( iCallImage->Control() );
       
   272             image->SetImage( NULL, EFalse, NULL, EFalse );
       
   273             }
       
   274         
       
   275         iBubbleManager.CustomManager().ReleaseCustomElement( iCallImage );
       
   276         }
       
   277     }
       
   278 
       
   279 // ---------------------------------------------------------------------------
       
   280 // DrawBitmaps
       
   281 // ---------------------------------------------------------------------------
       
   282 //
       
   283 void CBubbleMainPaneControl::DrawBitmaps( const TRect& aRect ) const
       
   284     {
       
   285     if ( iCallImage )
       
   286         {
       
   287         // ToDo: propagate to components
       
   288         iCallImage->Control()->DrawForeground( aRect );
       
   289         }
       
   290     }
       
   291 
       
   292 // ---------------------------------------------------------------------------
       
   293 // BubbleId
       
   294 // ---------------------------------------------------------------------------
       
   295 //
       
   296 CBubbleManager::TBubbleId CBubbleMainPaneControl::BubbleId() const
       
   297     {
       
   298     return iBubble;
       
   299     }
       
   300 
       
   301 // ---------------------------------------------------------------------------
       
   302 // IsUsed
       
   303 // ---------------------------------------------------------------------------
       
   304 //
       
   305 TBool CBubbleMainPaneControl::IsUsed() const
       
   306     {
       
   307     return iIsUsed;
       
   308     }
       
   309 
       
   310 // ---------------------------------------------------------------------------
       
   311 // SizeChanged
       
   312 // ---------------------------------------------------------------------------
       
   313 //
       
   314 void CBubbleMainPaneControl::SizeChanged()
       
   315     {
       
   316     if ( iCallImage )
       
   317         {
       
   318         iCallImage->Control()->SetRect( Rect() );
       
   319         if ( iCallImage->ControlType() == 
       
   320              CTelBubbleCustomElement::EBubbleCallImage )
       
   321             {
       
   322             CTelBubbleCallImage* image = 
       
   323                 static_cast<CTelBubbleCallImage*> ( iCallImage->Control() );
       
   324             TRect imageArea( iBubbleManager.MainPaneImageRect( 
       
   325                                  ETrue, iThreeLinedBubble ) );
       
   326             
       
   327             image->SetImagePlacingArea( imageArea );
       
   328             }
       
   329         }
       
   330     }
       
   331 
       
   332 // ---------------------------------------------------------------------------
       
   333 // CTelBubbleCallImage::ImageScalingComplete
       
   334 //
       
   335 // ---------------------------------------------------------------------------
       
   336 //
       
   337 void CBubbleMainPaneControl::ImageScalingComplete( TInt aError,
       
   338         CFbsBitmap* aBitmap )
       
   339     {
       
   340     if ( aError == KErrNone )
       
   341         {
       
   342         // Draw the scaled image
       
   343         iScaledImage = aBitmap;
       
   344         iScaler->SetState( CTelBubbleImageScaler::EScalingDone );
       
   345         
       
   346         CFbsBitmap* bitmap( NULL );
       
   347         CFbsBitmap* mask( NULL );
       
   348         TBool bitmapOwnership( EFalse );
       
   349         TBool maskOwnership( EFalse );
       
   350       
       
   351         TRAPD(err, PrepareBitmapsL( bitmap, 
       
   352                                     bitmapOwnership, 
       
   353                                     mask, 
       
   354                                     maskOwnership,
       
   355                                     EFalse,
       
   356                                     ETrue ) );
       
   357         
       
   358         if ( err )
       
   359             {
       
   360             return;
       
   361             }
       
   362                 
       
   363         if ( iCallImage->ControlType() == 
       
   364              CTelBubbleCustomElement::EBubbleCallImage )
       
   365             {
       
   366             CTelBubbleCallImage* image = 
       
   367                 static_cast<CTelBubbleCallImage*> ( iCallImage->Control() );
       
   368             image->SetImage( bitmap, EFalse, mask, maskOwnership );
       
   369             } 
       
   370 
       
   371         SizeChanged();
       
   372         
       
   373         iIsUsed = ETrue;
       
   374         MakeVisible( ETrue );
       
   375         
       
   376         Parent()->DrawNow(); // refreshing view with scaled image
       
   377         }
       
   378     else if ( aError == KErrCancel )
       
   379         {
       
   380         // error is ignored
       
   381         // This error is returned when a previous scaling is cancelled
       
   382         // while new scaling request is given to active object
       
   383         }
       
   384     else
       
   385         {
       
   386         // draw the unscaled image in error cases
       
   387     
       
   388         delete iScaledImage;
       
   389         iScaledImage = NULL;
       
   390         }
       
   391     
       
   392     iScaler->SetState( CTelBubbleImageScaler::EScalingDone );
       
   393     }
       
   394 
       
   395 // ---------------------------------------------------------------------------
       
   396 // CTelBubbleCallImage::StartScaling
       
   397 //
       
   398 // ---------------------------------------------------------------------------
       
   399 //
       
   400 void CBubbleMainPaneControl::StartScaling( CFbsBitmap *aSourceBitmap )
       
   401     {
       
   402     if ( !iScaler )
       
   403         {
       
   404         return;
       
   405         }
       
   406     
       
   407     iScaler->Cancel(); // cancels any outstanding scaling requests
       
   408     
       
   409     delete iScaledImage;
       
   410     iScaledImage = NULL;
       
   411 
       
   412     // create a bitmap for scaled size
       
   413     TRAPD( err, iScaledImage = new (ELeave) CFbsBitmap );
       
   414     if ( err != KErrNone )
       
   415         {
       
   416         // no scaling in error cases
       
   417         iScaler->SetState( CTelBubbleImageScaler::EScalingIdle );
       
   418         return;
       
   419         }
       
   420 
       
   421     TSize size = aSourceBitmap->SizeInPixels();
       
   422     TRect scaledRect( 0, 0, size.iWidth * SCALE_FACTOR, size.iHeight * SCALE_FACTOR );
       
   423     
       
   424     TRAP( err, iScaledImage->Create( scaledRect.Size(), aSourceBitmap->DisplayMode() ) );
       
   425     if ( err != KErrNone )
       
   426         {
       
   427         delete iScaledImage;
       
   428         iScaledImage = NULL;
       
   429         iScaler->SetState( CTelBubbleImageScaler::EScalingIdle );
       
   430         }
       
   431     else
       
   432         {
       
   433         //start scaling
       
   434         TRAPD( err, iScaler->StartScaleL( aSourceBitmap, iScaledImage ) );
       
   435         if (err != KErrNone)
       
   436             {
       
   437             iScaler->SetState( CTelBubbleImageScaler::EScalingIdle );
       
   438             delete iScaledImage;
       
   439             iScaledImage = NULL;
       
   440             }
       
   441         }
       
   442     }
       
   443 	
       
   444 // END OF FILE
       
   445