phoneuis/BubbleManager/bmcustomization/src/telbubblecallimage.cpp
changeset 0 5f000ab63145
child 44 3c221667e687
equal deleted inserted replaced
-1:000000000000 0:5f000ab63145
       
     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 image control.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <telbubblecallimage.h>
       
    20 #include <gdi.h>
       
    21 
       
    22 // ======== LOCAL FUNCTIONS ========
       
    23 
       
    24 // ---------------------------------------------------------------------------
       
    25 // Constructor
       
    26 // ---------------------------------------------------------------------------
       
    27 //
       
    28 EXPORT_C CTelBubbleCallImage::CTelBubbleCallImage()
       
    29     {
       
    30     }
       
    31 
       
    32 // ---------------------------------------------------------------------------
       
    33 // NewL
       
    34 // ---------------------------------------------------------------------------
       
    35 //
       
    36 EXPORT_C CTelBubbleCallImage* CTelBubbleCallImage::NewL()
       
    37     {
       
    38     CTelBubbleCallImage* self = new( ELeave )CTelBubbleCallImage();
       
    39     CleanupStack::PushL( self );
       
    40     self->ConstructL();
       
    41     CleanupStack::Pop( self );
       
    42     return self;
       
    43     }
       
    44 
       
    45 // ---------------------------------------------------------------------------
       
    46 // Destructor
       
    47 // ---------------------------------------------------------------------------
       
    48 //
       
    49 EXPORT_C CTelBubbleCallImage::~CTelBubbleCallImage()
       
    50     {
       
    51     if ( iImageOwnership )
       
    52         {
       
    53         delete iImage;
       
    54         }
       
    55     if ( iMaskOwnership )
       
    56         {
       
    57         delete iMask;
       
    58         }
       
    59     }
       
    60 
       
    61 // ---------------------------------------------------------------------------
       
    62 // CTelBubbleCallImage::ConstructL
       
    63 // ---------------------------------------------------------------------------
       
    64 //
       
    65 EXPORT_C void CTelBubbleCallImage::ConstructL()
       
    66     {
       
    67     }
       
    68 
       
    69 // ---------------------------------------------------------------------------
       
    70 // CTelBubbleCallImage::SetImage
       
    71 // ---------------------------------------------------------------------------
       
    72 //
       
    73 EXPORT_C void CTelBubbleCallImage::SetImage( 
       
    74     CFbsBitmap* aImage, 
       
    75     TBool aImageOwnership,
       
    76     CFbsBitmap* aMask,
       
    77     TBool aMaskOwnership )
       
    78     {
       
    79     if ( iImageOwnership )
       
    80         {
       
    81         delete iImage;
       
    82         }
       
    83     if ( iMaskOwnership )
       
    84         {
       
    85         delete iMask;
       
    86         }
       
    87     
       
    88     iImage = aImage;
       
    89     iMask = aMask;
       
    90     iImageOwnership = aImageOwnership;
       
    91     iMaskOwnership = aMaskOwnership;
       
    92     
       
    93     SizeChanged();
       
    94     ImageChanged();
       
    95     }
       
    96 
       
    97 // ---------------------------------------------------------------------------
       
    98 // CTelBubbleCallImage::ReleaseImage
       
    99 // ---------------------------------------------------------------------------
       
   100 //
       
   101 EXPORT_C void CTelBubbleCallImage::ImageChanged()
       
   102     {
       
   103     }
       
   104 
       
   105 // ---------------------------------------------------------------------------
       
   106 // CTelBubbleCallImage::ReleaseImage
       
   107 // ---------------------------------------------------------------------------
       
   108 //
       
   109 EXPORT_C void CTelBubbleCallImage::SetImagePlacingArea( TRect& aRect )
       
   110     {
       
   111     iImagePlacingArea = aRect;
       
   112     }
       
   113   
       
   114 // ---------------------------------------------------------------------------
       
   115 // CTelBubbleCallImage::ReleaseImage
       
   116 // ---------------------------------------------------------------------------
       
   117 //
       
   118 EXPORT_C const CFbsBitmap* CTelBubbleCallImage::Image() const
       
   119     {
       
   120     return iImage;
       
   121     }
       
   122 
       
   123 // ---------------------------------------------------------------------------
       
   124 // CTelBubbleCallImage::ReleaseImage
       
   125 // ---------------------------------------------------------------------------
       
   126 //
       
   127 EXPORT_C const CFbsBitmap* CTelBubbleCallImage::Mask() const
       
   128     {
       
   129     return iMask;
       
   130     }
       
   131 
       
   132 // ---------------------------------------------------------------------------
       
   133 // CTelBubbleCallImage::IsFullScreenImage
       
   134 // ---------------------------------------------------------------------------
       
   135 //
       
   136 EXPORT_C TBool CTelBubbleCallImage::IsFullScreenImage() const
       
   137     {
       
   138     TBool isFullScreen = ETrue;
       
   139     
       
   140     if ( iImage )
       
   141         {
       
   142         TSize imageSize = iImage->SizeInPixels();
       
   143         TSize thisSize( Rect().Size() );
       
   144         isFullScreen = ( imageSize.iWidth >= thisSize.iWidth ) ||
       
   145                        ( imageSize.iHeight >= thisSize.iHeight );
       
   146         }
       
   147         
       
   148     return isFullScreen;  
       
   149     }
       
   150 
       
   151 // ---------------------------------------------------------------------------
       
   152 // CTelBubbleCallImage::Offset
       
   153 // ---------------------------------------------------------------------------
       
   154 //
       
   155 EXPORT_C const TPoint& CTelBubbleCallImage::Offset() const
       
   156     {
       
   157     return iOffset;
       
   158     }
       
   159 
       
   160 // ---------------------------------------------------------------------------
       
   161 // CTelBubbleCallImage::SourceRect
       
   162 // ---------------------------------------------------------------------------
       
   163 //
       
   164 EXPORT_C const TRect& CTelBubbleCallImage::SourceRect() const
       
   165     {
       
   166     return iSourceRect;
       
   167     }
       
   168 
       
   169 // ---------------------------------------------------------------------------
       
   170 // CTelBubbleCallImage::ImagePlacingArea
       
   171 // ---------------------------------------------------------------------------
       
   172 //
       
   173 EXPORT_C const TRect& CTelBubbleCallImage::ImagePlacingArea() const
       
   174     {
       
   175     return iImagePlacingArea;
       
   176     }
       
   177 
       
   178 // ---------------------------------------------------------------------------
       
   179 // CTelBubbleCallImage::SizeChanged
       
   180 // ---------------------------------------------------------------------------
       
   181 //
       
   182 EXPORT_C void CTelBubbleCallImage::SizeChanged()
       
   183     {
       
   184     if ( !iImage )
       
   185         {
       
   186         return;                    
       
   187         }
       
   188     
       
   189     // If bitmap is bigger than drawing area then clip from center.
       
   190     TRect rect;
       
   191     if ( IsFullScreenImage() )
       
   192         {
       
   193         rect = Rect();
       
   194         }
       
   195     else
       
   196         {
       
   197         rect = ImagePlacingArea();
       
   198         }
       
   199     
       
   200     iSourceRect = iImage->SizeInPixels();
       
   201     
       
   202     TInt offsetX = ( iSourceRect.Width() > rect.Width() ) ? 
       
   203                    ((iSourceRect.Width() - rect.Width()) / 2) : 0;
       
   204     TInt offsetY = ( iSourceRect.Height() > rect.Height() ) ? 
       
   205                    ((iSourceRect.Height() - rect.Height()) / 2) : 0;
       
   206     iSourceRect.Shrink( offsetX, offsetY );    
       
   207     
       
   208     // If bitmap is smaller than drawing area then center it.
       
   209     iOffset.iX = ( iSourceRect.Width() < rect.Width() ) ? 
       
   210                 ((rect.Width() - iSourceRect.Width()) / 2) : 0;
       
   211     iOffset.iY = ( iSourceRect.Height() < rect.Height() ) ? 
       
   212                 ((rect.Height() - iSourceRect.Height()) / 2) : 0;
       
   213     }
       
   214 
       
   215 
       
   216 // ---------------------------------------------------------------------------
       
   217 // CTelBubbleCallImage::Draw
       
   218 // ---------------------------------------------------------------------------
       
   219 //
       
   220 EXPORT_C void CTelBubbleCallImage::Draw( const TRect& /*aRect*/ ) const
       
   221     {
       
   222     CWindowGc& gc = SystemGc();
       
   223     
       
   224     TPoint topLeft = IsFullScreenImage() ? Rect().iTl : iImagePlacingArea.iTl;
       
   225     
       
   226     
       
   227     if ( iImage && iMask )
       
   228         {
       
   229         gc.BitBltMasked( topLeft + iOffset,
       
   230                          iImage, 
       
   231                          iSourceRect, 
       
   232                          iMask, 
       
   233                          EFalse );
       
   234         }
       
   235     else if ( iImage )
       
   236         {
       
   237         gc.BitBlt( topLeft + iOffset, 
       
   238                    iImage,
       
   239                    iSourceRect );    
       
   240         }
       
   241     }
       
   242 
       
   243 // end of file