textinput/peninputarc/src/peninputlayoutcontrol/peninputfloatbubble.cpp
branchRCL_3
changeset 7 a47de9135b21
child 18 c8fb4cf7b3ae
equal deleted inserted replaced
3:f5a1e66df979 7:a47de9135b21
       
     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     gc.Clear( rect ); 
       
    74     
       
    75     //draw background
       
    76     if ( iBkgndSkinId.iMajor )
       
    77         {
       
    78         TRect border = rect;
       
    79         TRect inner = rect;
       
    80         inner.Shrink( KDefaultMarginSize, KDefaultMarginSize );
       
    81         AknsDrawUtils::DrawFrame( AknsUtils::SkinInstance(), 
       
    82                                   gc,
       
    83                                   border,
       
    84                                   inner,
       
    85                                   iBkgndSkinId,
       
    86                                   KAknsIIDDefault );
       
    87         }
       
    88     else
       
    89         {
       
    90         gc.SetBrushStyle( CGraphicsContext::ESolidBrush );
       
    91         gc.SetBrushColor( KRgbGray );
       
    92         gc.SetPenStyle( CGraphicsContext::ESolidPen );
       
    93         gc.SetPenColor( KRgbBlack );
       
    94         gc.DrawRoundRect( rect, TSize( 2, 2 ) );        
       
    95         }
       
    96     
       
    97     //draw icon
       
    98     if ( iIconImage )
       
    99         {
       
   100         TSize size = iIconImage->SizeInPixels();
       
   101         TInt x = rect.iTl.iX + ( rect.Width() - size.iWidth ) / 2;
       
   102         TInt y = rect.iTl.iY + ( rect.Height() - size.iHeight ) / 2;
       
   103         if ( iIconMask )
       
   104             {
       
   105             gc.BitBltMasked( TPoint( x, y ), iIconImage, 
       
   106                              TRect( TPoint( 0, 0 ), size), iIconMask, 
       
   107                              EFalse );
       
   108             }
       
   109         else
       
   110             {
       
   111             gc.BitBlt( TPoint( x, y ), iIconImage );
       
   112             }
       
   113         }
       
   114     
       
   115     //draw text
       
   116     if ( iText )
       
   117         {
       
   118         gc.SetBrushStyle( CGraphicsContext::ENullBrush );
       
   119         TAknLayoutText textLayout;
       
   120         textLayout.LayoutText( rect, iTextFormat );
       
   121         TRgb color( KRgbBlack );
       
   122         if ( AknsUtils::AvkonSkinEnabled() )
       
   123             {
       
   124             AknsUtils::GetCachedColor( AknsUtils::SkinInstance(),
       
   125                                        color, 
       
   126                                        KAknsIIDQsnTextColors, 
       
   127                                        EAknsCIQsnTextColorsCG60 );
       
   128             }
       
   129          textLayout.DrawText( gc, *iText, EFalse, color );
       
   130         }
       
   131     }
       
   132 
       
   133 // ---------------------------------------------------------------------------
       
   134 // 
       
   135 // ---------------------------------------------------------------------------
       
   136 //
       
   137 void CPeninputFloatingBubble::SetBackgroundImage( TAknsItemID aBkgndImage )
       
   138     {
       
   139     iBkgndSkinId = aBkgndImage;
       
   140     }
       
   141 
       
   142 // ---------------------------------------------------------------------------
       
   143 // 
       
   144 // ---------------------------------------------------------------------------
       
   145 //
       
   146 void CPeninputFloatingBubble::SetText( const TDesC& aText )
       
   147     {
       
   148     if ( iText )
       
   149         {
       
   150         delete iText;
       
   151         }
       
   152     iText = NULL;
       
   153     
       
   154     iText = aText.Alloc();  
       
   155     }
       
   156 
       
   157 // ---------------------------------------------------------------------------
       
   158 // 
       
   159 // ---------------------------------------------------------------------------
       
   160 //
       
   161 void CPeninputFloatingBubble::SetTextFormat( TAknTextLineLayout aTextFormat )
       
   162     {
       
   163     iTextFormat = aTextFormat;
       
   164     }
       
   165 
       
   166 // ---------------------------------------------------------------------------
       
   167 // 
       
   168 // ---------------------------------------------------------------------------
       
   169 //
       
   170 void CPeninputFloatingBubble::SetIcon( CFbsBitmap* aIconImage, CFbsBitmap* aIconMask )
       
   171     {
       
   172     iIconImage = aIconImage;
       
   173     iIconMask = aIconMask;
       
   174     }
       
   175 
       
   176 // ---------------------------------------------------------------------------
       
   177 // C++ constructor
       
   178 // ---------------------------------------------------------------------------
       
   179 //
       
   180 CPeninputFloatingBubble::CPeninputFloatingBubble()
       
   181     : iBkgndSkinId( KAknsIIDNone )
       
   182     {
       
   183     // No implementation required
       
   184     }
       
   185 
       
   186 // ---------------------------------------------------------------------------
       
   187 // Symbian second-phase constructor
       
   188 // ---------------------------------------------------------------------------
       
   189 //
       
   190 void CPeninputFloatingBubble::ConstructL()
       
   191     {
       
   192     BaseConstructL();
       
   193     }