| 21 |      1 | /*
 | 
|  |      2 | * Copyright (c) 2006-2006 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:  Implementation for Floating bubble
 | 
|  |     15 | *
 | 
|  |     16 | */
 | 
|  |     17 | 
 | 
|  |     18 | 
 | 
|  |     19 | #include <AknsDrawUtils.h> 
 | 
|  |     20 | #include <AknUtils.h>
 | 
|  |     21 | 
 | 
|  |     22 | #include "peninputfloatbubble.h"
 | 
|  |     23 | 
 | 
|  |     24 | const TInt KDefaultMarginSize = 10;
 | 
|  |     25 | 
 | 
|  |     26 | // ---------------------------------------------------------------------------
 | 
|  |     27 | // Symbian Constructor
 | 
|  |     28 | // ---------------------------------------------------------------------------
 | 
|  |     29 | //
 | 
|  |     30 | CPeninputFloatingBubble* CPeninputFloatingBubble::NewL()
 | 
|  |     31 |     {
 | 
|  |     32 |     CPeninputFloatingBubble* self = CPeninputFloatingBubble::NewLC();
 | 
|  |     33 |     CleanupStack::Pop(); // self;
 | 
|  |     34 |     return self;
 | 
|  |     35 |     }
 | 
|  |     36 | 
 | 
|  |     37 | // ---------------------------------------------------------------------------
 | 
|  |     38 | // Symbian Constructor
 | 
|  |     39 | // ---------------------------------------------------------------------------
 | 
|  |     40 | //
 | 
|  |     41 | CPeninputFloatingBubble* CPeninputFloatingBubble::NewLC()
 | 
|  |     42 |     {
 | 
|  |     43 |     CPeninputFloatingBubble* self = new ( ELeave ) CPeninputFloatingBubble();
 | 
|  |     44 |     CleanupStack::PushL( self );
 | 
|  |     45 |     self->ConstructL();
 | 
|  |     46 |     return self;
 | 
|  |     47 |     }
 | 
|  |     48 | 
 | 
|  |     49 | // ---------------------------------------------------------------------------
 | 
|  |     50 | // c++ destructor
 | 
|  |     51 | // ---------------------------------------------------------------------------
 | 
|  |     52 | //
 | 
|  |     53 | CPeninputFloatingBubble::~CPeninputFloatingBubble()
 | 
|  |     54 |     {
 | 
|  |     55 |     if ( iText ) 
 | 
|  |     56 |         {
 | 
|  |     57 |         delete iText;
 | 
|  |     58 |         }
 | 
|  |     59 |     
 | 
|  |     60 |     iText = NULL;    
 | 
|  |     61 |     iIconImage = NULL;
 | 
|  |     62 |     iIconMask = NULL;
 | 
|  |     63 |     }
 | 
|  |     64 | 
 | 
|  |     65 | // ---------------------------------------------------------------------------
 | 
|  |     66 | // Draw this control
 | 
|  |     67 | // ---------------------------------------------------------------------------
 | 
|  |     68 | //
 | 
|  |     69 | void CPeninputFloatingBubble::Draw( const TRect& aRect ) const
 | 
|  |     70 |     {
 | 
|  |     71 |     CWindowGc& gc = SystemGc();
 | 
|  |     72 |     TRect rect = Rect();
 | 
|  |     73 |     
 | 
|  |     74 |     if ( !SupportTransparent() )
 | 
|  |     75 |         {
 | 
|  |     76 |         gc.Clear( rect ); 
 | 
|  |     77 |         }
 | 
|  |     78 |     
 | 
|  |     79 |     //draw background
 | 
|  |     80 |     if ( iBkgndSkinId.iMajor )
 | 
|  |     81 |         {
 | 
|  |     82 |         TRect border = rect;
 | 
|  |     83 |         TRect inner = rect;
 | 
|  |     84 |         inner.Shrink( KDefaultMarginSize, KDefaultMarginSize );
 | 
|  |     85 |         AknsDrawUtils::DrawFrame( AknsUtils::SkinInstance(), 
 | 
|  |     86 |                                   gc,
 | 
|  |     87 |                                   border,
 | 
|  |     88 |                                   inner,
 | 
|  |     89 |                                   iBkgndSkinId,
 | 
|  |     90 |                                   KAknsIIDDefault );
 | 
|  |     91 |         }
 | 
|  |     92 |     else
 | 
|  |     93 |         {
 | 
|  |     94 |         gc.SetBrushStyle( CGraphicsContext::ESolidBrush );
 | 
|  |     95 |         gc.SetBrushColor( KRgbGray );
 | 
|  |     96 |         gc.SetPenStyle( CGraphicsContext::ESolidPen );
 | 
|  |     97 |         gc.SetPenColor( KRgbBlack );
 | 
|  |     98 |         gc.DrawRoundRect( rect, TSize( 2, 2 ) );        
 | 
|  |     99 |         }
 | 
|  |    100 |     
 | 
|  |    101 |     //draw icon
 | 
|  |    102 |     if ( iIconImage )
 | 
|  |    103 |         {
 | 
|  |    104 |         TSize size = iIconImage->SizeInPixels();
 | 
|  |    105 |         TInt x = rect.iTl.iX + ( rect.Width() - size.iWidth ) / 2;
 | 
|  |    106 |         TInt y = rect.iTl.iY + ( rect.Height() - size.iHeight ) / 2;
 | 
|  |    107 |         if ( iIconMask )
 | 
|  |    108 |             {
 | 
|  |    109 |             gc.BitBltMasked( TPoint( x, y ), iIconImage, 
 | 
|  |    110 |                              TRect( TPoint( 0, 0 ), size), iIconMask, 
 | 
|  |    111 |                              EFalse );
 | 
|  |    112 |             }
 | 
|  |    113 |         else
 | 
|  |    114 |             {
 | 
|  |    115 |             gc.BitBlt( TPoint( x, y ), iIconImage );
 | 
|  |    116 |             }
 | 
|  |    117 |         }
 | 
|  |    118 |     
 | 
|  |    119 |     //draw text
 | 
|  |    120 |     if ( iText )
 | 
|  |    121 |         {
 | 
|  |    122 |         gc.SetBrushStyle( CGraphicsContext::ENullBrush );
 | 
|  |    123 |         TAknLayoutText textLayout;
 | 
|  |    124 |         textLayout.LayoutText( rect, iTextFormat );
 | 
|  |    125 |         TRgb color( KRgbBlack );
 | 
|  |    126 |         if ( AknsUtils::AvkonSkinEnabled() )
 | 
|  |    127 |             {
 | 
|  |    128 |             AknsUtils::GetCachedColor( AknsUtils::SkinInstance(),
 | 
|  |    129 |                                        color, 
 | 
|  |    130 |                                        KAknsIIDQsnTextColors, 
 | 
|  |    131 |                                        EAknsCIQsnTextColorsCG60 );
 | 
|  |    132 |             }
 | 
|  |    133 |          textLayout.DrawText( gc, *iText, EFalse, color );
 | 
|  |    134 |         }
 | 
|  |    135 |     }
 | 
|  |    136 | 
 | 
|  |    137 | // ---------------------------------------------------------------------------
 | 
|  |    138 | // 
 | 
|  |    139 | // ---------------------------------------------------------------------------
 | 
|  |    140 | //
 | 
|  |    141 | void CPeninputFloatingBubble::SetBackgroundImage( TAknsItemID aBkgndImage )
 | 
|  |    142 |     {
 | 
|  |    143 |     iBkgndSkinId = aBkgndImage;
 | 
|  |    144 |     }
 | 
|  |    145 | 
 | 
|  |    146 | // ---------------------------------------------------------------------------
 | 
|  |    147 | // 
 | 
|  |    148 | // ---------------------------------------------------------------------------
 | 
|  |    149 | //
 | 
|  |    150 | void CPeninputFloatingBubble::SetText( const TDesC& aText )
 | 
|  |    151 |     {
 | 
|  |    152 |     if ( iText )
 | 
|  |    153 |         {
 | 
|  |    154 |         delete iText;
 | 
|  |    155 |         }
 | 
|  |    156 |     iText = NULL;
 | 
|  |    157 |     
 | 
|  |    158 |     iText = aText.Alloc();  
 | 
|  |    159 |     }
 | 
|  |    160 | 
 | 
|  |    161 | // ---------------------------------------------------------------------------
 | 
|  |    162 | // 
 | 
|  |    163 | // ---------------------------------------------------------------------------
 | 
|  |    164 | //
 | 
|  |    165 | void CPeninputFloatingBubble::SetTextFormat( TAknTextLineLayout aTextFormat )
 | 
|  |    166 |     {
 | 
|  |    167 |     iTextFormat = aTextFormat;
 | 
|  |    168 |     }
 | 
|  |    169 | 
 | 
|  |    170 | // ---------------------------------------------------------------------------
 | 
|  |    171 | // 
 | 
|  |    172 | // ---------------------------------------------------------------------------
 | 
|  |    173 | //
 | 
|  |    174 | void CPeninputFloatingBubble::SetIcon( CFbsBitmap* aIconImage, CFbsBitmap* aIconMask )
 | 
|  |    175 |     {
 | 
|  |    176 |     iIconImage = aIconImage;
 | 
|  |    177 |     iIconMask = aIconMask;
 | 
|  |    178 |     }
 | 
|  |    179 | 
 | 
|  |    180 | // ---------------------------------------------------------------------------
 | 
|  |    181 | // C++ constructor
 | 
|  |    182 | // ---------------------------------------------------------------------------
 | 
|  |    183 | //
 | 
|  |    184 | CPeninputFloatingBubble::CPeninputFloatingBubble()
 | 
|  |    185 |     : iBkgndSkinId( KAknsIIDNone )
 | 
|  |    186 |     {
 | 
|  |    187 |     // No implementation required
 | 
|  |    188 |     }
 | 
|  |    189 | 
 | 
|  |    190 | // ---------------------------------------------------------------------------
 | 
|  |    191 | // Symbian second-phase constructor
 | 
|  |    192 | // ---------------------------------------------------------------------------
 | 
|  |    193 | //
 | 
|  |    194 | void CPeninputFloatingBubble::ConstructL()
 | 
|  |    195 |     {
 | 
|  |    196 |     BaseConstructL();
 | 
|  |    197 |     }
 |