textinput/peninputarc/src/peninputlayoutcontrol/peninputpopupbubble.cpp
branchRCL_3
changeset 50 5a1685599b76
equal deleted inserted replaced
46:bd83ceabce89 50:5a1685599b76
       
     1 /*
       
     2 * Copyright (c) 2005-2007 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 CPopupBubbleCtrl
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <AknIconUtils.h>
       
    20 #include <AknsUtils.h>
       
    21 #include <AknUtils.h>
       
    22 #include <AknsDrawUtils.h> 
       
    23 
       
    24 #include "peninputpopupbubble.h"
       
    25 #include "peninputlayout.h"
       
    26 #include <peninputpluginutils.h>
       
    27 #include <imageconversion.h> 
       
    28 #include "peninputcmd.h"
       
    29 
       
    30 const TInt KShrinkSize = 10;
       
    31 const TInt KDefaultTextColorIndex = EAknsCIQsnTextColorsCG60;
       
    32 const TInt KAlpha = 200;
       
    33 
       
    34 // ======== MEMBER FUNCTIONS ========
       
    35 
       
    36 /*****************************************************************************/
       
    37 // Implementation of Class CPopupBubbleWnd
       
    38 
       
    39 // ---------------------------------------------------------------------------
       
    40 // c++ constructor
       
    41 // ---------------------------------------------------------------------------
       
    42 //
       
    43 CPopupBubbleWnd::CPopupBubbleWnd(CPopupBubbleCtrl& aParent)
       
    44 : iParent(aParent),
       
    45 iSupportTransparent(EFalse)
       
    46     {
       
    47     }
       
    48 
       
    49 // ---------------------------------------------------------------------------
       
    50 // c++ destructor
       
    51 // ---------------------------------------------------------------------------
       
    52 //
       
    53 CPopupBubbleWnd::~CPopupBubbleWnd()
       
    54     {
       
    55     //delete bitmaps    
       
    56     iBitGc.ResetAndDestroy();
       
    57     iDevice.ResetAndDestroy();
       
    58     iBitmap.ResetAndDestroy();       
       
    59     }
       
    60 
       
    61 // ---------------------------------------------------------------------------
       
    62 // Symbian constructor
       
    63 // ---------------------------------------------------------------------------
       
    64 //
       
    65 CPopupBubbleWnd* CPopupBubbleWnd::NewL(const TRect& aRect, CPopupBubbleCtrl& aParent)
       
    66     {
       
    67     CPopupBubbleWnd* self = CPopupBubbleWnd::NewLC(aRect, aParent);
       
    68     CleanupStack::Pop(); // self;
       
    69     return self;
       
    70     }
       
    71 
       
    72 // ---------------------------------------------------------------------------
       
    73 // Symbian constructor
       
    74 // ---------------------------------------------------------------------------
       
    75 //
       
    76 CPopupBubbleWnd* CPopupBubbleWnd::NewLC(const TRect& aRect, CPopupBubbleCtrl& aParent)
       
    77     {
       
    78     CPopupBubbleWnd* self = new ( ELeave ) CPopupBubbleWnd(aParent);
       
    79     CleanupStack::PushL( self );
       
    80     self->ConstructL(aRect);
       
    81     return self;
       
    82     }
       
    83 
       
    84 // ---------------------------------------------------------------------------
       
    85 // Symbian second-phase constructor
       
    86 // ---------------------------------------------------------------------------
       
    87 //
       
    88 void CPopupBubbleWnd::ConstructL(const TRect& aRect)
       
    89     {
       
    90     RWindowGroup& wg = CCoeEnv::Static()->RootWin();
       
    91     CreateWindowL( wg );
       
    92     SetComponentsToInheritVisibility();
       
    93     Window().SetRequiredDisplayMode( EColor16MA );
       
    94     TInt err = Window().SetTransparencyAlphaChannel();
       
    95     iSupportTransparent = ( KErrNone == err );
       
    96     Window().SetBackgroundColor( TRgb(0,0,0,0) );
       
    97 
       
    98     //create bitmaps
       
    99     for(TInt i = 0; i<ELastItem; i++)
       
   100         {
       
   101         CFbsBitmap* bitmap = new (ELeave) CFbsBitmap(); // Bitmap
       
   102         CleanupStack::PushL(bitmap);
       
   103         iBitmap.AppendL(bitmap); //take ownership
       
   104         CleanupStack::Pop(bitmap);
       
   105         iBitmap[i]->Create(aRect.Size(), EColor16MA);
       
   106         
       
   107         CFbsBitmapDevice* device = CFbsBitmapDevice::NewL(iBitmap[i]); //BitmapDevice
       
   108         CleanupStack::PushL(device);
       
   109         iDevice.AppendL(device); //take ownership
       
   110         CleanupStack::Pop(device);
       
   111         
       
   112         CFbsBitGc* bitgc = CFbsBitGc::NewL(); // GraphicsContext
       
   113         CleanupStack::PushL(bitgc);
       
   114         iBitGc.AppendL(bitgc); //take ownership
       
   115         CleanupStack::Pop(bitgc);
       
   116         }
       
   117     
       
   118     MakeVisible( ETrue );    
       
   119     SetRect(aRect);
       
   120     ActivateL();
       
   121     }
       
   122 
       
   123 // ---------------------------------------------------------------------------
       
   124 // Draw this control
       
   125 // ---------------------------------------------------------------------------
       
   126 //
       
   127 void CPopupBubbleWnd::Draw(const TRect& aRect) const
       
   128     {    
       
   129     if ( !iParent.AbleToDraw() )
       
   130         {
       
   131         return;
       
   132         }
       
   133     
       
   134     CWindowGc& gc = SystemGc();
       
   135 
       
   136     if ( !SupportTransparent() )
       
   137         {
       
   138         gc.Clear( aRect ); 
       
   139         }    
       
   140     
       
   141     DrawTransparentBackground( aRect );
       
   142 
       
   143     if ( iParent.iForgroundBmp )
       
   144         {
       
   145         TRect innerRect = aRect;
       
   146         innerRect.Shrink( KShrinkSize, 0 );
       
   147         
       
   148         TRect iconRect;
       
   149         iconRect.iTl = TPoint( innerRect.iTl.iX + iParent.iIconOffset.iWidth, 
       
   150                 innerRect.iTl.iY + iParent.iIconOffset.iHeight );
       
   151         iconRect.SetWidth( iParent.iIconSize.iWidth );
       
   152         iconRect.SetHeight( iParent.iIconSize.iHeight );
       
   153         
       
   154         if( iParent.iForgroundBmp->SizeInPixels() != iconRect.Size() )
       
   155             {
       
   156             AknIconUtils::SetSize( iParent.iForgroundBmp, iconRect.Size(), EAspectRatioNotPreserved );
       
   157             }
       
   158             
       
   159         TRect srcRect( TPoint( 0, 0 ), iParent.iForgroundBmp->SizeInPixels() );
       
   160         
       
   161         if( iParent.iForgroundBmpMask )
       
   162             {
       
   163             if( iParent.iForgroundBmpMask->SizeInPixels() != iconRect.Size() )
       
   164                 {
       
   165                 AknIconUtils::SetSize( iParent.iForgroundBmpMask, iconRect.Size(), EAspectRatioNotPreserved);
       
   166                 }
       
   167                         
       
   168             gc.SetBrushStyle( CGraphicsContext::ENullBrush );
       
   169             gc.BitBltMasked( iconRect.iTl, 
       
   170                               iParent.iForgroundBmp, 
       
   171                               srcRect,
       
   172                               iParent.iForgroundBmpMask,
       
   173                               EFalse);
       
   174             }
       
   175         else
       
   176             {
       
   177             gc.BitBlt( iconRect.iTl,
       
   178                         iParent.iForgroundBmp,
       
   179                         srcRect );
       
   180             }            
       
   181         }
       
   182     
       
   183     if ( iParent.iText && iParent.iText->Length() > 0 )
       
   184         {
       
   185         gc.SetBrushStyle( CGraphicsContext::ENullBrush );
       
   186         TAknLayoutText textLayout;
       
   187         textLayout.LayoutText(Rect(), iParent.iTextFormat);
       
   188         TRgb color( KRgbBlack );  // sane default for nonskinned case
       
   189         if ( AknsUtils::AvkonSkinEnabled() )
       
   190             {
       
   191             AknsUtils::GetCachedColor( AknsUtils::SkinInstance(),
       
   192                                    color, KAknsIIDQsnTextColors, iParent.iTextColorIndex );
       
   193             }
       
   194          textLayout.DrawText(gc, *(iParent.iText), ETrue, color);
       
   195         }    
       
   196     }
       
   197 
       
   198 // ---------------------------------------------------------------------------
       
   199 // Resize this control
       
   200 // ---------------------------------------------------------------------------
       
   201 //
       
   202 void CPopupBubbleWnd::SizeChanged()
       
   203     {
       
   204     TRect rect = Rect();        
       
   205     
       
   206     iRect[EMiddleItem] = rect;    
       
   207     
       
   208     iRect[EMiddleItem].Shrink( KShrinkSize, 0 );
       
   209       
       
   210     // horizon
       
   211     if( rect.iTl.iY == iRect[EMiddleItem].iTl.iY && rect.iBr.iY == iRect[EMiddleItem].iBr.iY )
       
   212         {
       
   213         iRect[ELeftItem] = TRect( rect.iTl, TPoint( iRect[EMiddleItem].iTl.iX, iRect[EMiddleItem].iBr.iY ) );
       
   214         iRect[ERightItem] = TRect( TPoint( iRect[EMiddleItem].iBr.iX, iRect[EMiddleItem].iTl.iY), rect.iBr );    
       
   215         }
       
   216     else if( rect.iTl.iX == iRect[EMiddleItem].iTl.iX &&  rect.iBr.iX == iRect[EMiddleItem].iBr.iX )
       
   217         {
       
   218         iRect[ELeftItem] = TRect( rect.iTl, TPoint( iRect[EMiddleItem].iBr.iX, iRect[EMiddleItem].iTl.iY ) );
       
   219         iRect[ERightItem] = TRect( TPoint( iRect[EMiddleItem].iTl.iX, iRect[EMiddleItem].iBr.iY), rect.iBr );            
       
   220         }     
       
   221     
       
   222     SizeImage( iParent.iFirstBmpId, iRect[ELeftItem], iBitmap[ELeftItem], iDevice[ELeftItem], iBitGc[ELeftItem] );
       
   223     SizeImage( iParent.iMiddleBmpId, iRect[EMiddleItem], iBitmap[EMiddleItem], iDevice[EMiddleItem], iBitGc[EMiddleItem] );
       
   224     SizeImage( iParent.iLastBmpId, iRect[ERightItem], iBitmap[ERightItem], iDevice[ERightItem], iBitGc[ERightItem] );
       
   225     }
       
   226 
       
   227 // ---------------------------------------------------------------------------
       
   228 // Handle resource change
       
   229 // ---------------------------------------------------------------------------
       
   230 //
       
   231 void CPopupBubbleWnd::HandleResourceChange( TInt aType )
       
   232     {
       
   233     if ( aType == KAknsMessageSkinChange )
       
   234         {
       
   235         // When skin changes, we need to update local bitmaps
       
   236         SizeChanged();
       
   237         }
       
   238     }
       
   239 
       
   240 // ---------------------------------------------------------------------------
       
   241 // Size images used for drawing
       
   242 // ---------------------------------------------------------------------------
       
   243 //
       
   244 void CPopupBubbleWnd::SizeImage( TAknsItemID aId, TRect aRect, CFbsBitmap* aBitmap, CFbsBitmapDevice* aDevice, CFbsBitGc* aBitGc )
       
   245     {     
       
   246     MAknsSkinInstance* instance = AknsUtils::SkinInstance();
       
   247     TAknsItemType type = instance->GetCachedItemData( aId )->Type();
       
   248     if ( type == EAknsITMaskedBitmap )
       
   249         {
       
   250         CAknsMaskedBitmapItemData* itemData =
       
   251                 static_cast<CAknsMaskedBitmapItemData*> ( instance->GetCachedItemData( aId ) );
       
   252 
       
   253         AknIconUtils::SetSize( itemData->Bitmap(), aRect.Size(), EAspectRatioNotPreserved );
       
   254         AknIconUtils::SetSize( itemData->Mask(), aRect.Size(), EAspectRatioNotPreserved );
       
   255 
       
   256         TDisplayMode bitmapmode = itemData->Bitmap()->DisplayMode();
       
   257         TDisplayMode maskmode = itemData->Mask()->DisplayMode();
       
   258 
       
   259         aBitmap->Resize( aRect.Size() );
       
   260         aDevice->Resize( aRect.Size() );
       
   261         aBitGc->Activate( aDevice );
       
   262 
       
   263         TRect entireImage( TPoint(0, 0), itemData->Bitmap()->SizeInPixels() );
       
   264         if (itemData->Mask())
       
   265             {
       
   266             aBitGc->BitBltMasked( TPoint(0, 0), itemData->Bitmap(), entireImage,
       
   267                     itemData->Mask(), ETrue );
       
   268             }
       
   269         else
       
   270             {
       
   271             aBitGc->BitBlt( TPoint(0, 0), itemData->Bitmap() );
       
   272             }
       
   273 
       
   274         TInt size = aBitmap->DataSize();
       
   275         TUint32* data = aBitmap->DataAddress();
       
   276         TDisplayMode mode = aBitmap->DisplayMode();
       
   277 
       
   278         iBitmap[ETempItem]->Resize( aRect.Size() );
       
   279         iDevice[ETempItem]->Resize( aRect.Size() );
       
   280         iBitGc[ETempItem]->Activate( iDevice[ETempItem] );
       
   281         iBitGc[ETempItem]->BitBlt( TPoint(0, 0), itemData->Mask() );
       
   282         
       
   283         TUint32* mask_data = iBitmap[ETempItem]->DataAddress(); 
       
   284          
       
   285          if (mode == EColor16MA)
       
   286              {
       
   287              for (TInt i = 0; i < size/sizeof( TUint32 ); i++)
       
   288                  {
       
   289                  TRgb colour;
       
   290                  colour.SetInternal( *(mask_data + i) );
       
   291                  if (colour != TRgb( 0x00, 0x00, 0x00, 0xFF ))
       
   292                      {
       
   293                      colour.SetInternal( *(data + i) );
       
   294                      colour.SetAlpha( KAlpha ); //semi transparent
       
   295                      *(data + i) = colour.Internal();
       
   296                      }
       
   297                  else
       
   298                      {
       
   299                      colour.SetInternal( *(data + i) );
       
   300                      colour.SetAlpha( 0x00 ); //fully transparent
       
   301                      *(data + i) = colour.Internal();                   
       
   302                      }
       
   303                  }           
       
   304              }
       
   305         }
       
   306     } 
       
   307 
       
   308 // ---------------------------------------------------------------------------
       
   309 // Draw transparent background
       
   310 // ---------------------------------------------------------------------------
       
   311 //
       
   312 
       
   313 void CPopupBubbleWnd::DrawTransparentBackground( const TRect& aRect ) const
       
   314 {
       
   315     CWindowGc& gc = SystemGc();
       
   316 
       
   317     for( TInt i=0; i<ELastItem; i++ )
       
   318         {
       
   319         if ( i == ETempItem )//skip temporary bitmap
       
   320             {
       
   321             continue;
       
   322             }
       
   323         if ( iBitmap[i] )//draw other bitmaps
       
   324             {
       
   325             gc.BitBlt( iRect[i].iTl, iBitmap[i] );
       
   326             }
       
   327         }
       
   328 }
       
   329 
       
   330 /*****************************************************************************/
       
   331 // Implementation of Class CPopupBubbleCtrl
       
   332 
       
   333 // ---------------------------------------------------------------------------
       
   334 // CPopupBubbleCtrl::NewL
       
   335 // Symbian constructor
       
   336 // (other items were commented in a header).
       
   337 // ---------------------------------------------------------------------------
       
   338 //               
       
   339 EXPORT_C CPopupBubbleCtrl* CPopupBubbleCtrl::NewL( const TRect& aRect,
       
   340                                CFepUiLayout* aUiLayout,
       
   341                                TInt aCtrlId )
       
   342     {
       
   343     CPopupBubbleCtrl* ctrl = new (ELeave)CPopupBubbleCtrl( aRect,aUiLayout,aCtrlId );
       
   344     CleanupStack::PushL( ctrl );
       
   345     ctrl->BaseConstructL();
       
   346     
       
   347     CleanupStack::Pop( ctrl );
       
   348     return ctrl;
       
   349     }
       
   350 
       
   351 // ---------------------------------------------------------------------------
       
   352 // CPopupBubbleCtrl::CPopupBubbleCtrl
       
   353 // C++  constructor
       
   354 // (other items were commented in a header).
       
   355 // ---------------------------------------------------------------------------
       
   356 //
       
   357 EXPORT_C CPopupBubbleCtrl::CPopupBubbleCtrl( const TRect& aRect,
       
   358                          CFepUiLayout* aUiLayout,
       
   359                          TInt aCtrlId )
       
   360     :CFepUiBaseCtrl( aRect,aUiLayout,aCtrlId ),
       
   361      iTextColorIndex( KDefaultTextColorIndex )
       
   362     {
       
   363     SetControlType( ECtrlButton );
       
   364     SetHidenFlag( ETrue );
       
   365     }
       
   366 
       
   367 // ---------------------------------------------------------------------------
       
   368 // CPopupBubbleCtrl::CPopupBubbleCtrl
       
   369 // C++  destructor
       
   370 // ---------------------------------------------------------------------------
       
   371 //
       
   372 EXPORT_C CPopupBubbleCtrl::~CPopupBubbleCtrl()
       
   373     {
       
   374     if ( iText )
       
   375         {
       
   376         delete iText;
       
   377         iText = NULL;
       
   378         }      
       
   379     if( iForgroundBmp )
       
   380         {
       
   381         delete iForgroundBmp;
       
   382         iForgroundBmp = NULL;
       
   383         }
       
   384     if( iForgroundBmpMask )
       
   385         {
       
   386         delete iForgroundBmpMask;
       
   387         iForgroundBmpMask = NULL;
       
   388         }        
       
   389     }
       
   390 
       
   391 // ---------------------------------------------------------------------------
       
   392 // CPopupBubbleCtrl::SetBitmapParamL
       
   393 // Set bitmap parameters used fot this bubble
       
   394 // (other items were commented in a header).
       
   395 // ---------------------------------------------------------------------------
       
   396 //
       
   397 EXPORT_C void CPopupBubbleCtrl::SetBitmapParamL(
       
   398                                     CFbsBitmap* aBmpId,
       
   399                                     CFbsBitmap* aMaskBmpId,     
       
   400                                  TAknsItemID aFirstBmpId,
       
   401                                  TAknsItemID aMiddleBmpId,
       
   402                                  TAknsItemID aLastBmpId)
       
   403     {
       
   404     if( iForgroundBmp )
       
   405         {
       
   406         delete iForgroundBmp;
       
   407         iForgroundBmp = NULL;
       
   408         }
       
   409     if( iForgroundBmpMask )
       
   410         {
       
   411         delete iForgroundBmpMask;
       
   412         iForgroundBmpMask = NULL;
       
   413         }    
       
   414         
       
   415     iForgroundBmp = aBmpId;
       
   416     iForgroundBmpMask = aMaskBmpId;
       
   417     
       
   418     iFirstBmpId = aFirstBmpId;
       
   419     iMiddleBmpId =  aMiddleBmpId;
       
   420     iLastBmpId = aLastBmpId;
       
   421     
       
   422     delete iWndControl;
       
   423     iWndControl = NULL;
       
   424     iWndControl = CPopupBubbleWnd::NewL( Rect(), *this );
       
   425     }
       
   426 
       
   427 // ---------------------------------------------------------------------------
       
   428 // CPopupBubbleCtrl::Hide
       
   429 // Hide bubble control
       
   430 // (other items were commented in a header).
       
   431 // ---------------------------------------------------------------------------
       
   432 //
       
   433 EXPORT_C void CPopupBubbleCtrl::Hide( TBool aFlag )
       
   434     {
       
   435     if ( iWndControl )
       
   436         {
       
   437         iWndControl->MakeVisible( !aFlag );
       
   438         }
       
   439     CFepUiBaseCtrl::Hide( aFlag );    
       
   440     }
       
   441 
       
   442 // ---------------------------------------------------------------------------
       
   443 // CPopupBubbleCtrl::Draw
       
   444 // Draw bubble control
       
   445 // ---------------------------------------------------------------------------
       
   446 //
       
   447 EXPORT_C void CPopupBubbleCtrl::Draw()
       
   448     {
       
   449     if( !AbleToDraw() )
       
   450         {
       
   451         return;
       
   452         }    
       
   453     
       
   454     if( iWndControl )
       
   455         {
       
   456         iWndControl->DrawDeferred();
       
   457         }
       
   458     }
       
   459 
       
   460 // ---------------------------------------------------------------------------
       
   461 // CPopupBubbleCtrl::Move
       
   462 // Move bubble control
       
   463 // ---------------------------------------------------------------------------
       
   464 //
       
   465 EXPORT_C void CPopupBubbleCtrl::Move( const TPoint& aOffset )
       
   466     {
       
   467     //leave empty
       
   468     }
       
   469 
       
   470 // ---------------------------------------------------------------------------
       
   471 // CPopupBubbleCtrl::SetTextFormat
       
   472 // Set text format used for text drawing
       
   473 // (other items were commented in a header).
       
   474 // ---------------------------------------------------------------------------
       
   475 //
       
   476 EXPORT_C void CPopupBubbleCtrl::SetTextFormat( TAknTextLineLayout aTextFormat )
       
   477     {
       
   478     iTextFormat = aTextFormat;                
       
   479     }
       
   480 
       
   481 // ---------------------------------------------------------------------------
       
   482 // CPopupBubbleCtrl::SetTextL
       
   483 // Set bubble text
       
   484 // (other items were commented in a header).
       
   485 // ---------------------------------------------------------------------------
       
   486 //
       
   487 EXPORT_C void CPopupBubbleCtrl::SetTextL( const TDesC& aText )
       
   488     {
       
   489     delete iText;
       
   490     iText = NULL;
       
   491     iText = aText.AllocL();
       
   492     }