textinput/peninputarc/src/peninputlayoutcontrol/peninputlayoutbubblectrl.cpp
changeset 0 eb1f2e154e89
child 5 a47de9135b21
equal deleted inserted replaced
-1:000000000000 0:eb1f2e154e89
       
     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 PeninputLayoutControl
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <AknIconUtils.h>
       
    20 #include <AknsUtils.h>
       
    21 #include <AknUtils.h>
       
    22 #include <AknsDrawUtils.h> 
       
    23 
       
    24 #include "peninputlayoutbubblectrl.h"
       
    25 #include "peninputlayout.h"
       
    26 #include <peninputpluginutils.h>
       
    27 
       
    28 const TInt KShrinkSize = 10;
       
    29 const TInt KDefaultTextColorIndex = EAknsCIQsnTextColorsCG60;
       
    30 // ======== MEMBER FUNCTIONS ========
       
    31 
       
    32 // Implementation of Class CBubbleCtrl
       
    33 
       
    34 // ---------------------------------------------------------------------------
       
    35 // CBubbleCtrl::NewL
       
    36 // Factory function
       
    37 // ---------------------------------------------------------------------------
       
    38 //
       
    39                
       
    40 EXPORT_C CBubbleCtrl* CBubbleCtrl::NewL(const TRect& aRect,
       
    41                                CFepUiLayout* aUiLayout,
       
    42                                TInt aCtrlId)
       
    43     {
       
    44     CBubbleCtrl* ctrl = new (ELeave)CBubbleCtrl(aRect,aUiLayout,aCtrlId);
       
    45     CleanupStack::PushL(ctrl);
       
    46     ctrl->BaseConstructL();
       
    47     CleanupStack::Pop(ctrl);
       
    48     return ctrl;
       
    49     }
       
    50 
       
    51 EXPORT_C CBubbleCtrl::CBubbleCtrl(const TRect& aRect,
       
    52                          CFepUiLayout* aUiLayout,
       
    53                          TInt aCtrlId)
       
    54     :CFepUiBaseCtrl(aRect,aUiLayout,aCtrlId),
       
    55      iForgroundBmp(NULL),
       
    56      iForgroundBmpMask(NULL),
       
    57      iShowing(EFalse),
       
    58      iTextColorIndex(KDefaultTextColorIndex)
       
    59     {
       
    60     SetControlType(ECtrlButton);
       
    61     SetHidenFlag(ETrue);
       
    62     }
       
    63         
       
    64 EXPORT_C CBubbleCtrl::~CBubbleCtrl()
       
    65     {
       
    66     if ( iText )
       
    67         delete iText;
       
    68     
       
    69     if( iForgroundBmp )
       
    70 		{
       
    71 		delete iForgroundBmp;
       
    72 		iForgroundBmp = NULL;
       
    73 		}
       
    74 	if( iForgroundBmpMask )
       
    75 		{
       
    76 		delete iForgroundBmpMask;
       
    77 		iForgroundBmpMask = NULL;
       
    78 		}    
       
    79     }
       
    80 
       
    81 EXPORT_C void CBubbleCtrl::SetBitmapParam(CFbsBitmap* aBmpId,
       
    82                                  CFbsBitmap* aMaskBmpId,
       
    83                                  TAknsItemID aBgSkinId)
       
    84     {
       
    85     if( iForgroundBmp )
       
    86 		{
       
    87 		delete iForgroundBmp;
       
    88 		iForgroundBmp = NULL;
       
    89 		}
       
    90 	if( iForgroundBmpMask )
       
    91 		{
       
    92 		delete iForgroundBmpMask;
       
    93 		iForgroundBmpMask = NULL;
       
    94 		}    
       
    95 		
       
    96     iForgroundBmp = aBmpId;
       
    97     iForgroundBmpMask = aMaskBmpId;
       
    98     iBgSkinId = aBgSkinId;    
       
    99     }
       
   100 
       
   101 EXPORT_C void CBubbleCtrl::Popup(const TRect& aRect)
       
   102     {
       
   103     SetRect(aRect);
       
   104 
       
   105     if(iFreeze)
       
   106         {
       
   107         iShowing = ETrue;              
       
   108         SetHidenFlag(EFalse);        
       
   109         return;
       
   110         }
       
   111     if(!iShowing || aRect != Rect() || iNeedRedraw)
       
   112         {
       
   113         iShowing = ETrue;  
       
   114         TRect rect = Rect();
       
   115         SetRect(aRect);
       
   116         SetHidenFlag(EFalse);        
       
   117         BringToTop();
       
   118         //redraw the control under bubble control
       
   119         if(aRect != rect)        
       
   120             RootControl()->ReDrawRect(rect);    
       
   121 
       
   122         Draw();
       
   123         
       
   124         rect.BoundingRect(aRect);
       
   125         UpdateAreaImmed(rect,ETrue);     
       
   126         
       
   127         iNeedRedraw = EFalse;
       
   128         }
       
   129     }
       
   130 EXPORT_C void CBubbleCtrl::SetBitmapParam(CFbsBitmap* aBmpId,
       
   131                                  CFbsBitmap* aMaskBmpId,
       
   132                                  TAknsItemID aFirstBmpId,
       
   133 		                         TAknsItemID aMiddleBmpId,
       
   134 		                         TAknsItemID aLastBmpId)
       
   135     {
       
   136     if( iForgroundBmp )
       
   137 		{
       
   138 		delete iForgroundBmp;
       
   139 		iForgroundBmp = NULL;
       
   140 		}
       
   141 	if( iForgroundBmpMask )
       
   142 		{
       
   143 		delete iForgroundBmpMask;
       
   144 		iForgroundBmpMask = NULL;
       
   145 		}    
       
   146 		
       
   147     iForgroundBmp = aBmpId;
       
   148     iForgroundBmpMask = aMaskBmpId;
       
   149     iFirstBmpId = aFirstBmpId;
       
   150     iMiddleBmpId =  aMiddleBmpId;
       
   151     iLastBmpId = aLastBmpId;    
       
   152     }
       
   153 
       
   154 EXPORT_C void CBubbleCtrl::Close()
       
   155     {
       
   156     TRect rect = Rect();
       
   157     
       
   158     iShowing = EFalse;  
       
   159     
       
   160     if( iFreeze )
       
   161         {
       
   162         if(iInvalidRect.IsEmpty() )
       
   163             {
       
   164             iInvalidRect = rect;
       
   165             }
       
   166         else
       
   167             {
       
   168             iInvalidRect.BoundingRect( rect );
       
   169             }            
       
   170         }
       
   171     else
       
   172         {
       
   173         Clear();
       
   174         SetHidenFlag(ETrue);    
       
   175         BringToBack();
       
   176 
       
   177         RootControl()->ReDrawRect(rect);
       
   178         UpdateAreaImmed(rect); 
       
   179         }
       
   180     }
       
   181 
       
   182 EXPORT_C void CBubbleCtrl::Hide(TBool aFlag)
       
   183     {
       
   184     if(aFlag) //hide bubble
       
   185         {
       
   186         Close();            
       
   187 
       
   188         }
       
   189     else
       
   190         {
       
   191         Popup(Rect());        
       
   192         }
       
   193     }
       
   194 
       
   195 
       
   196 EXPORT_C TBool CBubbleCtrl::IsShowing()
       
   197     {
       
   198     return iShowing;   
       
   199     }
       
   200             
       
   201 EXPORT_C void CBubbleCtrl::Draw()
       
   202     {
       
   203     if(!AbleToDraw() || iFreeze ) //|| !iShowing )
       
   204 	    {
       
   205 	    return;
       
   206 	    }
       
   207     
       
   208     CFbsBitGc* gc = static_cast<CFbsBitGc*>(BitGc());
       
   209     
       
   210     //mask bitmaps
       
   211   	DrawOpaqueMaskBackground();  
       
   212   	
       
   213     TRect rect = Rect();        
       
   214     TRect innerRect = rect;
       
   215     
       
   216     if ( ( iLeftDiff == 0 ) && ( iTopDiff == 0 )
       
   217          && ( iRightDiff == 0 ) && ( iBottomDiff == 0 ) )
       
   218         {
       
   219         innerRect.Shrink( KShrinkSize, 0 );
       
   220         }
       
   221     else
       
   222         {
       
   223         innerRect.iTl.iX = innerRect.iTl.iX + iLeftDiff;
       
   224         innerRect.iTl.iY = innerRect.iTl.iY + iTopDiff;
       
   225         innerRect.iBr.iX = innerRect.iBr.iX - iRightDiff;
       
   226         innerRect.iBr.iY = innerRect.iBr.iY - iBottomDiff;
       
   227         
       
   228         }
       
   229     
       
   230     // ----- draw bitmaps -----
       
   231     gc->Activate( BitmapDevice() );                
       
   232     //gc->Clear(rect);
       
   233     		
       
   234 	// Draw background
       
   235 	if ( iBgSkinId.iMajor )
       
   236 	    {
       
   237     	AknsDrawUtils::DrawFrame( AknsUtils::SkinInstance(), 
       
   238                          *gc,
       
   239                          rect,
       
   240                          innerRect,
       
   241                          iBgSkinId,
       
   242                          KAknsIIDDefault ); 	        
       
   243 	    }
       
   244 	else if( iFirstBmpId.iMajor && iMiddleBmpId.iMajor && iLastBmpId.iMajor )
       
   245 		{
       
   246 		AknPenInputDrawUtils::Draw3PiecesFrame( AknsUtils::SkinInstance(),
       
   247 						 *gc,
       
   248 						 rect,
       
   249 						 innerRect,
       
   250 						 iFirstBmpId,
       
   251 						 iMiddleBmpId,
       
   252 						 iLastBmpId);	
       
   253 		}
       
   254 	else
       
   255 	    {
       
   256 	    DrawBackground();    
       
   257 	    }
       
   258                      
       
   259     if ( iForgroundBmp )
       
   260         {
       
   261         if( iForgroundBmp->SizeInPixels() != innerRect.Size() )
       
   262         	{
       
   263         	AknIconUtils::SetSize( iForgroundBmp, innerRect.Size(), EAspectRatioNotPreserved );
       
   264         	}
       
   265         	
       
   266     	TRect srcRect( TPoint( 0, 0 ), iForgroundBmp->SizeInPixels() );
       
   267     	
       
   268     	if( iForgroundBmpMask )
       
   269     		{
       
   270             if( iForgroundBmpMask->SizeInPixels() != innerRect.Size() )
       
   271             	{
       
   272             	AknIconUtils::SetSize( iForgroundBmpMask, innerRect.Size(), EAspectRatioNotPreserved);
       
   273             	}
       
   274             	        
       
   275 
       
   276     		gc->BitBltMasked( innerRect.iTl, 
       
   277     						  iForgroundBmp, 
       
   278     						  srcRect,
       
   279     						  iForgroundBmpMask,
       
   280     						  EFalse);
       
   281     		}
       
   282         else
       
   283             {
       
   284     		gc->BitBlt( innerRect.iTl,
       
   285     					iForgroundBmp,
       
   286     					srcRect );
       
   287             }            
       
   288         }
       
   289         
       
   290     if ( iText )
       
   291         {
       
   292         gc->SetBrushStyle( CGraphicsContext::ENullBrush );
       
   293         TAknLayoutText textLayout;
       
   294         textLayout.LayoutText(Rect(), iTextFormat);
       
   295         TRgb color( KRgbBlack );  // sane default for nonskinned case
       
   296 	    if ( AknsUtils::AvkonSkinEnabled() )
       
   297 	        {
       
   298 	        AknsUtils::GetCachedColor( AknsUtils::SkinInstance(),
       
   299 	                               color, KAknsIIDQsnTextColors, iTextColorIndex );
       
   300 	        }
       
   301 	     textLayout.DrawText(*gc, *iText, EFalse, color);
       
   302         }
       
   303     }
       
   304            	
       
   305 EXPORT_C void CBubbleCtrl::SetTextFormat(TAknTextLineLayout aTextFormat)
       
   306     {
       
   307     iTextFormat = aTextFormat;                
       
   308     }
       
   309     
       
   310 EXPORT_C void CBubbleCtrl::SetTextL(const TDesC& aText)
       
   311     {
       
   312     delete iText;
       
   313     iText = NULL;
       
   314     iText = aText.AllocL();           
       
   315     iNeedRedraw = ETrue;
       
   316     }
       
   317 
       
   318 EXPORT_C void CBubbleCtrl::SetFrameDiff(TInt aLeftDiff, TInt aTopDiff,
       
   319                                         TInt aRightDiff,TInt aBottomDiff)
       
   320     {
       
   321     iLeftDiff = aLeftDiff;
       
   322     iTopDiff  = aTopDiff;
       
   323     iRightDiff = aRightDiff;
       
   324     iBottomDiff = aBottomDiff;      
       
   325     }
       
   326 
       
   327 void CBubbleCtrl::Freeze()
       
   328     {
       
   329     iFreeze = ETrue;
       
   330     iInvalidRect = TRect();
       
   331     }
       
   332 
       
   333 void CBubbleCtrl::UnFreeze( TBool aUpdate )
       
   334     {
       
   335     iFreeze = EFalse;
       
   336     if( aUpdate )
       
   337         {
       
   338         if( !iInvalidRect.IsEmpty() )
       
   339             {
       
   340             RootControl()->ReDrawRect( iInvalidRect );
       
   341             }
       
   342         Draw();
       
   343         
       
   344         if(iInvalidRect.IsEmpty() )
       
   345             {
       
   346             iInvalidRect = Rect();
       
   347             }
       
   348         else
       
   349             {
       
   350             iInvalidRect.BoundingRect( Rect() );
       
   351             }      
       
   352                   
       
   353         UpdateArea(iInvalidRect); 
       
   354         }
       
   355     
       
   356     iInvalidRect = TRect();
       
   357     }
       
   358 
       
   359 // ---------------------------------------------------------------------------
       
   360 // CTooltipBubbleCtrl::NewL
       
   361 // factory function
       
   362 // (other items were commented in a header).
       
   363 // ---------------------------------------------------------------------------
       
   364 //
       
   365 CTooltipBubbleCtrl* CTooltipBubbleCtrl::NewL( const TRect& aRect, 
       
   366 		                                            CFepUiLayout* aUiLayout, 
       
   367 		                                            TInt aCtrlId )
       
   368     {
       
   369     CTooltipBubbleCtrl* self = new (ELeave) CTooltipBubbleCtrl( aRect, 
       
   370     		                                                    aUiLayout, 
       
   371     		                                                    aCtrlId );
       
   372     CleanupStack::PushL( self );
       
   373     self->BaseConstructL();
       
   374     CleanupStack::Pop( self );
       
   375     return self;    
       
   376     }
       
   377     
       
   378 // ---------------------------------------------------------------------------
       
   379 // CTooltipBubbleCtrl::CTooltipBubbleCtrl
       
   380 // C++ default constructor
       
   381 // (other items were commented in a header).
       
   382 // ---------------------------------------------------------------------------
       
   383 //
       
   384 CTooltipBubbleCtrl::CTooltipBubbleCtrl( const TRect& aRect,
       
   385 		                                      CFepUiLayout* aUiLayout, 
       
   386 		                                      TInt aCtrlId )
       
   387     :CBubbleCtrl( aRect, aUiLayout, aCtrlId )
       
   388     {
       
   389 #ifdef RD_TACTILE_FEEDBACK
       
   390     if(IsKindOfControl(ECtrlTactileFeedback) && !Hiden() && UiLayout())
       
   391         {
       
   392 		SetTactileFeedbackType(ETouchFeedbackSensitiveInput);
       
   393         UiLayout()->RegisterFeedbackArea(reinterpret_cast<TInt>(this),aRect,ETouchFeedbackSensitiveInput);
       
   394         }  
       
   395 #endif // RD_TACTILE_FEEDBACK 
       
   396     }
       
   397 
       
   398 // ---------------------------------------------------------------------------
       
   399 // CTooltipBubbleCtrl::~CTooltipBubbleCtrl
       
   400 // Destructor
       
   401 // ---------------------------------------------------------------------------
       
   402 //
       
   403 CTooltipBubbleCtrl::~CTooltipBubbleCtrl()
       
   404     {  
       
   405     }
       
   406                  
       
   407 
       
   408 // ---------------------------------------------------------------------------
       
   409 // Handle pointer up event
       
   410 // ---------------------------------------------------------------------------
       
   411 //
       
   412 CFepUiBaseCtrl* CTooltipBubbleCtrl::HandlePointerUpEventL
       
   413                                                   ( const TPoint& /*aPoint*/ )
       
   414 	{
       
   415 	ReportEvent( EEventTooltipPointerUp );
       
   416 	return this;
       
   417 	}
       
   418 
       
   419 //end of implementation of class CVirtualKeyboard