textinput/peninputarc/src/peninputlayoutcontrol/peninputlayoutbutton.cpp
changeset 0 eb1f2e154e89
child 3 f5a1e66df979
equal deleted inserted replaced
-1:000000000000 0:eb1f2e154e89
       
     1 /*
       
     2 * Copyright (c) 2006-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 button base and dragbar
       
    15 *
       
    16 */
       
    17 
       
    18 #include <aknfepglobalenums.h>
       
    19 #include "peninputlayoutbutton.h"
       
    20 #include "peninputlayouttimer.h"
       
    21 #include "peninputlayout.h"
       
    22 
       
    23 #ifdef __WINS__
       
    24 const TInt KSpriteMoveDrawInterval    = 10000; // 1/100 second
       
    25 #else
       
    26 const TInt KSpriteMoveDrawInterval    = 1000; // 1/1000 second
       
    27 #endif
       
    28 
       
    29 #define __USING_MOVING_FRAME__	//flag to use the moving frame when dragging the layout
       
    30 // ============================ MEMBER FUNCTIONS ===============================
       
    31 
       
    32 
       
    33 /******************** start of CButtonBase **********************************/
       
    34 
       
    35 // ---------------------------------------------------------------------------
       
    36 // CButtonBase::NewL
       
    37 // factory function
       
    38 // (other items were commented in a header).
       
    39 // ---------------------------------------------------------------------------
       
    40 //
       
    41 EXPORT_C CButtonBase* CButtonBase::NewL(const TRect& aRect,
       
    42                                         CFepUiLayout* aUiLayout,TInt aCtrlId)
       
    43     {
       
    44     CButtonBase* btn=new (ELeave)CButtonBase(aRect,aUiLayout,aCtrlId);
       
    45     CleanupStack::PushL(btn);
       
    46     btn->BaseConstructL();
       
    47     CleanupStack::Pop(btn);
       
    48     return btn;    
       
    49     }
       
    50     
       
    51 // ---------------------------------------------------------------------------
       
    52 // CButtonBase::CButtonBase
       
    53 // C++ default constructor
       
    54 // (other items were commented in a header).
       
    55 // ---------------------------------------------------------------------------
       
    56 //
       
    57 EXPORT_C CButtonBase::CButtonBase(const TRect& aRect,CFepUiLayout* aUiLayout,
       
    58                                                                 TInt aCtrlId)
       
    59                         :CFepUiBaseCtrl(aRect,aUiLayout,aCtrlId),
       
    60                          iPressed(EFalse),
       
    61                          iStretchable(ETrue),
       
    62                          iBaseline(-1),
       
    63                          iCaptionColor(KRgbWhite), //white caption
       
    64                          iCaptionShadowColor(KRgbBlack) //black caption shadow
       
    65     {
       
    66     SetControlType(ECtrlButton | ECtrlTactileFeedback);
       
    67     iDimmed = EFalse;
       
    68 #ifdef __ALPHA_TRANCEPARENCY__
       
    69     const TRgb KDefaultButtonBackCol = TRgb(30,30,30);
       
    70 #else
       
    71     const TRgb KDefaultButtonBackCol = TRgb(230,230,230);
       
    72 #endif
       
    73     
       
    74     SetBkColor(KDefaultButtonBackCol);
       
    75 
       
    76 #ifdef RD_TACTILE_FEEDBACK     
       
    77     //Advanced Tactile feedback REQ417-47932
       
    78     if(aUiLayout)
       
    79     	{
       
    80     	if (aUiLayout->PenInputType() == EPluginInputModeFSQ||
       
    81     		aUiLayout->PenInputType() == EPluginInputModeVkb)
       
    82     		{
       
    83     		SetTactileFeedbackType(ETouchFeedbackBasicButton);
       
    84     		aUiLayout->RegisterFeedbackArea(reinterpret_cast<TInt>(this),aRect,ETouchFeedbackBasicButton);
       
    85     		}
       
    86     	else
       
    87     		{
       
    88     		SetTactileFeedbackType(ETouchFeedbackSensitiveInput);
       
    89     		aUiLayout->RegisterFeedbackArea(reinterpret_cast<TInt>(this),aRect,ETouchFeedbackSensitiveInput);
       
    90     		}
       
    91     	}       
       
    92 #endif //RD_TACTILE_FEEDBACK     
       
    93     }
       
    94 
       
    95 // ---------------------------------------------------------------------------
       
    96 // CButtonBase::~CButtonBase
       
    97 // Destructor
       
    98 // ---------------------------------------------------------------------------
       
    99 //
       
   100 EXPORT_C CButtonBase::~CButtonBase()
       
   101     {  
       
   102     delete iCaption;
       
   103     
       
   104     //only free the bitmaps in the pool
       
   105     iBmpPool.ResetAndDestroy();    
       
   106     
       
   107     //must reset the background bmp otherwise CFepUiBaseCtrl will re-delete it.    
       
   108     SetBackgroundBmp(NULL);
       
   109     SetBackgroundMaskBmp(NULL);    
       
   110     //font
       
   111     if(iFontOwnership && iFont)
       
   112         {
       
   113         BitmapDevice()->ReleaseFont(iFont);
       
   114         iFont = NULL;    
       
   115         }        
       
   116     delete iNoUsedBkbmp;
       
   117     delete iNoUsedMaskBkbmp;      
       
   118 
       
   119 #ifdef RD_TACTILE_FEEDBACK     
       
   120     //de-register the area for tactile feedback
       
   121     //if(aUiLayout) //there must be aUiLayout
       
   122     UiLayout()->DeRegisterFeedbackArea(reinterpret_cast<TInt>(this),Rect());          
       
   123 #endif // RD_TACTILE_FEEDBACK     
       
   124     }
       
   125 
       
   126 // ---------------------------------------------------------------------------
       
   127 // CButtonBase::Draw
       
   128 // Draw the control
       
   129 // (other items were commented in a header).
       
   130 // ---------------------------------------------------------------------------
       
   131 //    
       
   132 EXPORT_C void CButtonBase::Draw()
       
   133     {
       
   134     if(!AbleToDraw())
       
   135     	return;    
       
   136         
       
   137     if(iWndControl)
       
   138         {
       
   139         CFepUiBaseCtrl::Draw();
       
   140         return;
       
   141         }
       
   142     CFbsBitGc* gc = static_cast<CFbsBitGc*>(BitGc());        
       
   143 	DrawOpaqueMaskBackground(iStretchable);
       
   144         
       
   145         //mask bitmaps
       
   146 		DrawBackground();            
       
   147         //draw caption if there is
       
   148     //gc->SetClippingRegion(&ValidClipRegion());  //this cause crash in generic vkb
       
   149         if(iCaption && iFont)
       
   150             {
       
   151             //use font
       
   152             gc->UseFont(iFont);
       
   153             gc->SetBrushStyle( CGraphicsContext::ENullBrush ); 
       
   154             gc->SetPenStyle(CGraphicsContext::ESolidPen);                        
       
   155             
       
   156            
       
   157             TRect rect(iRect);
       
   158             
       
   159             //draw text shadow first
       
   160             rect.Move(1,1);
       
   161             
       
   162             TInt baseLine = iBaseline > 0 ? iBaseline : 
       
   163                                 rect.Height()*KDEFAULTBASELINERATIO;      
       
   164             //set pen color for text shadow
       
   165             gc->SetPenColor(iCaptionShadowColor);                                      
       
   166             gc->DrawText(*iCaption,rect,baseLine,CGraphicsContext::ECenter );
       
   167 
       
   168             //Now draw caption on top of the shadow
       
   169             //re-cal the baseline
       
   170             baseLine = iBaseline > 0 ? iBaseline : 
       
   171                                 iRect.Height()*KDEFAULTBASELINERATIO;
       
   172             gc->SetPenColor(iCaptionColor);              
       
   173             gc->DrawText(*iCaption,iRect,baseLine,CGraphicsContext::ECenter );
       
   174             
       
   175         gc->DiscardFont();
       
   176         }
       
   177     gc->CancelClipping();
       
   178     }
       
   179 
       
   180 // ---------------------------------------------------------------------------
       
   181 // CButtonBase::HandleButtonDown
       
   182 // Handle button down event
       
   183 // (other items were commented in a header).
       
   184 // ---------------------------------------------------------------------------
       
   185 //    
       
   186 EXPORT_C CFepUiBaseCtrl* CButtonBase::HandlePointerDownEventL(const TPoint& aPt)
       
   187     {    
       
   188     
       
   189     if(iDimmed)
       
   190         return NULL;
       
   191     
       
   192     CFepUiBaseCtrl::HandlePointerDownEventL(aPt);
       
   193     if(IsActive())
       
   194         {
       
   195         SetBackgroundBmp(iActiveBmpPressed);
       
   196         SetBackgroundMaskBmp(iActiveMaskBmpPressed);
       
   197         }        
       
   198     else
       
   199         {
       
   200         SetBackgroundBmp(iNonActiveBkBmpPressed);
       
   201         SetBackgroundMaskBmp(iNonActiveBkMaskBmpPressed);
       
   202         }        
       
   203 
       
   204     Draw();
       
   205     UpdateArea(Rect(), EFalse);
       
   206     ReportEvent(EEventButtonDown);
       
   207     return this;
       
   208     }
       
   209     
       
   210 // ---------------------------------------------------------------------------
       
   211 // CButtonBase::HandlePointerLeave
       
   212 // Handle pointer leave event
       
   213 // ---------------------------------------------------------------------------
       
   214 //           
       
   215 EXPORT_C void CButtonBase::HandlePointerLeave(const TPoint& aPt)
       
   216     {
       
   217     if(iDimmed)
       
   218         return;
       
   219     if(IsActive())
       
   220         {
       
   221         SetBackgroundBmp(iActiveBmp);
       
   222         SetBackgroundMaskBmp(iActiveMaskBmp);
       
   223         }
       
   224         
       
   225     else
       
   226         {
       
   227         SetBackgroundBmp(iNonActiveBkBmp);
       
   228         SetBackgroundMaskBmp(iNonActiveBkMaskBmp);
       
   229         }
       
   230     Draw();
       
   231     UpdateArea(Rect(), EFalse);   
       
   232     CFepUiBaseCtrl::HandlePointerLeave(aPt);
       
   233     return ;
       
   234     }
       
   235     
       
   236 // ---------------------------------------------------------------------------
       
   237 // CButtonBase::HandlePointerEnter
       
   238 // Handle pointer enter event
       
   239 // ---------------------------------------------------------------------------
       
   240 //           
       
   241 EXPORT_C void CButtonBase::HandlePointerEnter(const TPoint& aPt)
       
   242     {
       
   243     if(iDimmed)
       
   244         return;
       
   245     if(IsActive())
       
   246         {
       
   247         SetBackgroundBmp(iActiveBmpPressed);
       
   248         SetBackgroundMaskBmp(iActiveMaskBmpPressed);
       
   249         }        
       
   250         
       
   251     else
       
   252         {
       
   253         SetBackgroundBmp(iNonActiveBkBmpPressed);
       
   254         SetBackgroundMaskBmp(iNonActiveBkMaskBmpPressed);
       
   255         }
       
   256     Draw();
       
   257     UpdateArea(Rect(), EFalse);   
       
   258     CFepUiBaseCtrl::HandlePointerEnter(aPt);
       
   259     }
       
   260 
       
   261     
       
   262     
       
   263 // ---------------------------------------------------------------------------
       
   264 // CButtonBase::HandleButtonUpEventL
       
   265 // Handle button up event
       
   266 // (other items were commented in a header).
       
   267 // ---------------------------------------------------------------------------
       
   268 //        
       
   269 EXPORT_C CFepUiBaseCtrl* CButtonBase::HandlePointerUpEventL(const TPoint& /*aPt*/)        
       
   270     {
       
   271     if(iDimmed)
       
   272         return NULL;
       
   273     if(IsActive())
       
   274         {
       
   275         SetBackgroundBmp(iActiveBmp);
       
   276         SetBackgroundMaskBmp(iActiveMaskBmp);
       
   277         }        
       
   278     else
       
   279         {
       
   280         SetBackgroundBmp(iNonActiveBkBmp);
       
   281         SetBackgroundMaskBmp(iNonActiveBkMaskBmp);
       
   282         }
       
   283     SetActive(ETrue);
       
   284     Draw();
       
   285     UpdateArea(Rect(), EFalse);    
       
   286     
       
   287     ReportEvent(EEventButtonUp);
       
   288     return this;
       
   289     }
       
   290 
       
   291 
       
   292 // ---------------------------------------------------------------------------
       
   293 // CButtonBase::HandleButtonMoveEventL
       
   294 // Handle button move event
       
   295 // (other items were commented in a header).
       
   296 // ---------------------------------------------------------------------------
       
   297 //
       
   298 EXPORT_C CFepUiBaseCtrl* CButtonBase::HandlePointerMoveEventL(const TPoint& /*aPt*/)
       
   299     {
       
   300     //do nothing
       
   301     return this;
       
   302     }
       
   303 
       
   304 // ---------------------------------------------------------------------------
       
   305 // CButtonBase::SetActive
       
   306 // Set button active
       
   307 // (other items were commented in a header).
       
   308 // ---------------------------------------------------------------------------
       
   309 //
       
   310 EXPORT_C void CButtonBase::SetActive(TBool aActiveFlag)
       
   311     {
       
   312     if(iDimmed)
       
   313         return;
       
   314     if(IsActive() != aActiveFlag)
       
   315         {
       
   316         CFepUiBaseCtrl::SetActive(aActiveFlag);
       
   317         if(aActiveFlag)
       
   318             {               
       
   319             SetBackgroundBmp(iActiveBmp);
       
   320             SetBackgroundMaskBmp(iActiveMaskBmp);
       
   321             }
       
   322         else
       
   323             {
       
   324             SetBackgroundBmp(iNonActiveBkBmp);
       
   325             SetBackgroundMaskBmp(iNonActiveBkMaskBmp);
       
   326             }
       
   327         if(BitGc())
       
   328             {       
       
   329             Draw();
       
   330             UpdateArea(Rect(),EFalse);
       
   331             }
       
   332         }
       
   333     }
       
   334 
       
   335 // ---------------------------------------------------------------------------
       
   336 // CButtonBase::SetDimmed
       
   337 // Dim button
       
   338 // (other items were commented in a header).
       
   339 // ---------------------------------------------------------------------------
       
   340 //
       
   341 EXPORT_C void CButtonBase::SetDimmed(TBool aDimFlag)
       
   342     {
       
   343     //Remove its active flag if dim an active button.
       
   344     if(aDimFlag && IsActive())
       
   345         SetActive(EFalse);
       
   346     iDimmed = aDimFlag;
       
   347     if(iDimmed)
       
   348         {        
       
   349         SetBackgroundBmp(iDimmedBmp);
       
   350         SetBackgroundMaskBmp(iDimmedMaskBmp);
       
   351         }
       
   352     else
       
   353         {        
       
   354         // set the bmp according to current status
       
   355         if(IsActive())
       
   356             {               
       
   357             SetBackgroundBmp(iActiveBmp);
       
   358             SetBackgroundMaskBmp(iActiveMaskBmp);
       
   359             }
       
   360         else
       
   361             {
       
   362             SetBackgroundBmp(iNonActiveBkBmp);
       
   363             SetBackgroundMaskBmp(iNonActiveBkMaskBmp);
       
   364             }        
       
   365         }
       
   366     
       
   367     if(BitGc())
       
   368         {       
       
   369         Draw();
       
   370         UpdateArea(Rect(), EFalse);
       
   371         }
       
   372 
       
   373 #ifdef RD_TACTILE_FEEDBACK 
       
   374     if(IsKindOfControl(ECtrlTactileFeedback))
       
   375         {        
       
   376         //if(aDimFlag)
       
   377             UiLayout()->DeRegisterFeedbackArea(reinterpret_cast<TInt>(this),Rect());
       
   378         if(!aDimFlag && !Hiden())
       
   379             UiLayout()->RegisterFeedbackArea(reinterpret_cast<TInt>(this),Rect(),TactileFeedbackType());            
       
   380         }
       
   381 #endif        
       
   382     }
       
   383   
       
   384 
       
   385 
       
   386 // ---------------------------------------------------------------------------
       
   387 // CButtonBase::SetBitmapL
       
   388 // Set bitmap for given status
       
   389 // (other items were commented in a header).
       
   390 // ---------------------------------------------------------------------------
       
   391 //    
       
   392 EXPORT_C void CButtonBase::SetBitmapL(CFbsBitmap* aBitmap, TButtonBmpType aType)
       
   393     {
       
   394     CFbsBitmap* bmp = aBitmap;
       
   395     
       
   396     if(!aBitmap)
       
   397         return;   
       
   398     AddBmpToPool(aBitmap);
       
   399     
       
   400     switch(aType)
       
   401         {
       
   402         case EBtnBmpNonActive :
       
   403             {            
       
   404             iNonActiveBkBmp = bmp;        
       
   405             if(!IsActive())
       
   406                 SetBackgroundBmp(iNonActiveBkBmp);
       
   407             }
       
   408             break;
       
   409         case EBtnBmpNonActivePressed :
       
   410             iNonActiveBkBmpPressed = bmp;
       
   411             break;
       
   412         case EBtnBmpActive :
       
   413             iActiveBmp = bmp;    
       
   414             if(IsActive())
       
   415                 SetBackgroundBmp(iActiveBmp);
       
   416 
       
   417             break;
       
   418         case EBtnBmpActivePressed :
       
   419             iActiveBmpPressed = bmp;        
       
   420             break;
       
   421         case EBtnBmpDimmed :
       
   422             iDimmedBmp = bmp;
       
   423             break;
       
   424         default:
       
   425             break;
       
   426 
       
   427         }
       
   428     }  
       
   429    
       
   430 // ---------------------------------------------------------------------------
       
   431 // CButtonBase::Bitmap
       
   432 // get bitmap for given type
       
   433 // (other items were commented in a header).
       
   434 // ---------------------------------------------------------------------------
       
   435 //    
       
   436 EXPORT_C CFbsBitmap* CButtonBase::Bitmap(TButtonBmpType aType, TBool aMaskFlag)
       
   437     {
       
   438     CFbsBitmap* bmp = NULL;
       
   439     if(!aMaskFlag)
       
   440         {
       
   441         
       
   442         switch(aType)
       
   443             {
       
   444             case EBtnBmpNonActive :
       
   445                 {            
       
   446                 bmp = iNonActiveBkBmp;
       
   447                 }
       
   448                 break;
       
   449             case EBtnBmpNonActivePressed :
       
   450                 bmp = iNonActiveBkBmpPressed;
       
   451                 break;
       
   452             case EBtnBmpActive :
       
   453                 bmp = iActiveBmp ;
       
   454                 break;
       
   455             case EBtnBmpActivePressed :
       
   456                 bmp = iActiveBmpPressed;
       
   457                 break;
       
   458             case EBtnBmpDimmed :
       
   459                 bmp = iDimmedBmp;
       
   460                 break;
       
   461             default:
       
   462                 break;
       
   463             }
       
   464         }
       
   465     else //get mask bitmap
       
   466         {
       
   467         switch(aType)
       
   468             {
       
   469             case EBtnBmpNonActive :
       
   470                 bmp = iNonActiveBkMaskBmp;
       
   471                 break;
       
   472             case EBtnBmpNonActivePressed :
       
   473                 bmp = iNonActiveBkMaskBmpPressed;
       
   474                 break;
       
   475             case EBtnBmpActive :
       
   476                 bmp = iActiveMaskBmp;
       
   477                 break;
       
   478             case EBtnBmpActivePressed :
       
   479                 bmp = iActiveMaskBmpPressed;
       
   480                 break;
       
   481             case EBtnBmpDimmed :
       
   482                 bmp = iDimmedMaskBmp;
       
   483                 break;
       
   484             default:
       
   485                 break;
       
   486             }        
       
   487         }
       
   488     return bmp;
       
   489     }  
       
   490 // ---------------------------------------------------------------------------
       
   491 // CButtonBase::SetMaskBitmapL
       
   492 // Set mask bitmap for given status
       
   493 // (other items were commented in a header).
       
   494 // ---------------------------------------------------------------------------
       
   495 //    
       
   496 EXPORT_C void CButtonBase::SetMaskBitmapL(CFbsBitmap* aBmp, TButtonBmpType aType)
       
   497     {   
       
   498     if (!aBmp)
       
   499         return;
       
   500     
       
   501     AddBmpToPool(aBmp);
       
   502 
       
   503     switch(aType)
       
   504         {
       
   505         case EBtnBmpNonActive :
       
   506             iNonActiveBkMaskBmp = aBmp;        
       
   507             if(BkMaskBmp())
       
   508                 SetBackgroundMaskBmp(iNonActiveBkMaskBmp);  
       
   509             break;
       
   510         case EBtnBmpNonActivePressed :
       
   511             iNonActiveBkMaskBmpPressed = aBmp;
       
   512             break;
       
   513         case EBtnBmpActive :
       
   514             iActiveMaskBmp = aBmp;    
       
   515             break;
       
   516         case EBtnBmpActivePressed :
       
   517             iActiveMaskBmpPressed = aBmp;        
       
   518             break;
       
   519         case EBtnBmpDimmed :
       
   520             iDimmedMaskBmp = aBmp;
       
   521             break;
       
   522         default:
       
   523             break;
       
   524         }
       
   525     }
       
   526    
       
   527    
       
   528 // ---------------------------------------------------------------------------
       
   529 // CButtonBase::SetCaptionL
       
   530 // Set mask bitmap for given status
       
   531 // (other items were commented in a header).
       
   532 // ---------------------------------------------------------------------------
       
   533 //      
       
   534 EXPORT_C void CButtonBase::SetCaptionL(const TDesC& aText)
       
   535     {
       
   536     TBool bRedraw(EFalse);
       
   537     if(iCaption)
       
   538         {        
       
   539         delete iCaption;
       
   540         //already has a caption, redraw may be needed.
       
   541         bRedraw = ETrue;
       
   542         iCaption = NULL;        
       
   543         }
       
   544     iCaption = aText.AllocL();
       
   545     if(bRedraw)
       
   546         {
       
   547         Draw();
       
   548         UpdateArea(iRect, EFalse);
       
   549         }
       
   550     }
       
   551     
       
   552     
       
   553 // ---------------------------------------------------------------------------
       
   554 // CButtonBase::SetFont
       
   555 // Set caption font
       
   556 // (other items were commented in a header).
       
   557 // ---------------------------------------------------------------------------
       
   558 //        
       
   559 EXPORT_C void CButtonBase::SetFont(const TFontSpec& aFontSpec)
       
   560     {
       
   561     iFontSpec = aFontSpec;
       
   562     //release old font
       
   563     if(iFontOwnership && iFont)
       
   564         {
       
   565         BitmapDevice()->ReleaseFont(iFont);
       
   566         iFont = NULL;    
       
   567         }    
       
   568     iFontOwnership = ETrue;    
       
   569     if(BitmapDevice())
       
   570         {
       
   571         if (KErrNone != BitmapDevice()->GetNearestFontInPixels(iFont,iFontSpec))
       
   572             iFont = NULL;
       
   573         }      
       
   574     }        
       
   575     
       
   576 // ---------------------------------------------------------------------------
       
   577 // CButtonBase::SetFont
       
   578 // Set caption font
       
   579 // (other items were commented in a header).
       
   580 // ---------------------------------------------------------------------------
       
   581 //        
       
   582 EXPORT_C void CButtonBase::SetFont(const CFont* aFont)
       
   583     {
       
   584     if(iFontOwnership && iFont)
       
   585         {
       
   586         BitmapDevice()->ReleaseFont(iFont);
       
   587         }    
       
   588     iFontOwnership = EFalse;    
       
   589     iFont = const_cast<CFont*>(aFont);
       
   590     if(iFont)
       
   591         iFontSpec = iFont->FontSpecInTwips();
       
   592     }        
       
   593 
       
   594 // ---------------------------------------------------------------------------
       
   595 // CButtonBase::ResetBmpPool
       
   596 // Rest bitmap pool
       
   597 // (other items were commented in a header).
       
   598 // ---------------------------------------------------------------------------
       
   599 //        
       
   600 EXPORT_C void CButtonBase::ResetBmpPool()
       
   601     {
       
   602     iBmpPool.ResetAndDestroy();        
       
   603     //must reset the background bmp otherwise CFepUiBaseCtrl will re-delete it.    
       
   604     SetBackgroundBmp(NULL);
       
   605     SetBackgroundMaskBmp(NULL);        
       
   606     }
       
   607     
       
   608     
       
   609 // ---------------------------------------------------------------------------
       
   610 // CButtonBase::SetBackgroundBitmapL
       
   611 // Set back ground bitmap
       
   612 // (other items were commented in a header).
       
   613 // ---------------------------------------------------------------------------
       
   614 //       
       
   615 EXPORT_C void CButtonBase::SetBackgroundBitmapL(CFbsBitmap* aBmp)
       
   616     {
       
   617     if(!aBmp)
       
   618         return;
       
   619     AddBmpToPool(aBmp);
       
   620     SetBackgroundBmp(aBmp);    
       
   621     }
       
   622 
       
   623 // ---------------------------------------------------------------------------
       
   624 // CButtonBase::SetBackgroundMaskBitmapL
       
   625 // Set back ground mask bitmap
       
   626 // (other items were commented in a header).
       
   627 // ---------------------------------------------------------------------------
       
   628 //           
       
   629 EXPORT_C void CButtonBase::SetBackgroundMaskBitmapL(CFbsBitmap* aBmp)
       
   630     {
       
   631     if(!aBmp)
       
   632         return;   
       
   633     AddBmpToPool(aBmp);
       
   634     SetBackgroundMaskBmp(aBmp);          
       
   635     }
       
   636     
       
   637 EXPORT_C void CButtonBase::Hide(TBool aFlag)
       
   638 	{
       
   639 	CFepUiBaseCtrl::Hide(aFlag);
       
   640 #ifdef RD_TACTILE_FEEDBACK   
       
   641     if(IsKindOfControl(ECtrlTactileFeedback))
       
   642         {        
       
   643         if(aFlag || iDimmed)
       
   644             UiLayout()->DeRegisterFeedbackArea(reinterpret_cast<TInt>(this),Rect());
       
   645         }
       
   646 #endif    
       
   647 	}
       
   648     
       
   649 // ---------------------------------------------------------------------------
       
   650 // CButtonBase::AddBmpToPool
       
   651 // add a bitmap to pool
       
   652 // (other items were commented in a header).
       
   653 // ---------------------------------------------------------------------------
       
   654 //               
       
   655 void CButtonBase::AddBmpToPool(CFbsBitmap* aBmp)
       
   656     {
       
   657     //do we already has the bitmap?
       
   658     if(KErrNotFound == iBmpPool.Find(aBmp))
       
   659         {
       
   660         TRAP_IGNORE(iBmpPool.AppendL(aBmp));
       
   661         }        
       
   662     }    
       
   663     
       
   664 /**********************    end of CButtonBase     ****************************/
       
   665 
       
   666 
       
   667 /********************   Implementation of CDragBar   ************************/
       
   668 
       
   669 // ---------------------------------------------------------------------------
       
   670 // CDragBar::NewL
       
   671 // factory function
       
   672 // (other items were commented in a header).
       
   673 // ---------------------------------------------------------------------------
       
   674 //    
       
   675 EXPORT_C CDragBar* CDragBar::NewL(const TRect& aRect,CFepUiLayout* aUiLayout,
       
   676                                                                  TInt aCtrlId)
       
   677     {
       
   678     CDragBar* btn = new (ELeave)CDragBar(aRect,aUiLayout,aCtrlId);
       
   679     CleanupStack::PushL(btn);
       
   680     btn->ConstructL ();
       
   681     CleanupStack::Pop(btn);
       
   682     return btn;    
       
   683     }
       
   684 
       
   685 // ---------------------------------------------------------------------------
       
   686 // CDragBar::~CDragBar
       
   687 // Destructor
       
   688 // (other items were commented in a header).
       
   689 // ---------------------------------------------------------------------------
       
   690 //    
       
   691 EXPORT_C CDragBar::~CDragBar()
       
   692     {
       
   693     iPosObserverList.Close();       
       
   694     delete iLongPressTimer;
       
   695     delete iMoveTimer;    
       
   696     iLongPressTimer = NULL;
       
   697     iDraggingCtrlList.Close();
       
   698     }
       
   699  
       
   700 // ---------------------------------------------------------------------------
       
   701 // CDragBar::CDragBar
       
   702 // Constructor
       
   703 // (other items were commented in a header).
       
   704 // ---------------------------------------------------------------------------
       
   705 // 
       
   706 EXPORT_C CDragBar::CDragBar(const TRect& aRect,CFepUiLayout* aUiLayout,
       
   707                                                                  TInt aCtrlId)
       
   708                 :CButtonBase(aRect,aUiLayout,aCtrlId),
       
   709                  iIsDragging(EFalse),iMoved(EFalse),
       
   710                  iLayoutBeingDraged(EFalse),iNeedLongtimePress(EFalse),
       
   711                  iDraggingEnabled(ETrue),iDrawInterval(KSpriteMoveDrawInterval)
       
   712     {    
       
   713     SetControlType(ECtrlDragBar);
       
   714     iDragFrameRect = Rect();
       
   715     SetPenSize(TSize(KDefaultFrameWidth,KDefaultFrameWidth));
       
   716     iMovingIndicatorPos = aRect.iTl + PenSize();
       
   717     }
       
   718 
       
   719 // ---------------------------------------------------------------------------
       
   720 // CDragBar::ConstructL
       
   721 // Second phase constructor
       
   722 // (other items were commented in a header).
       
   723 // ---------------------------------------------------------------------------
       
   724 //
       
   725 EXPORT_C void CDragBar::ConstructL()
       
   726     {
       
   727     BaseConstructL();
       
   728     iLongPressTimer = CLayoutTimer::NewL(this,CLayoutTimer::ELongPressTimer);
       
   729     iMoveTimer = CLayoutTimer::NewL(this,CLayoutTimer::EDragbarMoveTimer,ETrue);
       
   730     iMoveTimer->SetPriority(CActive::EPriorityHigh);
       
   731     AddPositionObserver(this);//add itself to be an position change observer        
       
   732     }
       
   733 
       
   734 // ---------------------------------------------------------------------------
       
   735 // CDragBar::HandleButtonDownEventL
       
   736 // Handle pen down event in dragbar
       
   737 // (other items were commented in a header).
       
   738 // ---------------------------------------------------------------------------
       
   739 //
       
   740 EXPORT_C CFepUiBaseCtrl* CDragBar::HandlePointerDownEventL(const TPoint& aPt)
       
   741     {    
       
   742     if(!iDraggingEnabled) //not support dragging
       
   743         {
       
   744         CButtonBase::HandlePointerDownEventL(aPt);
       
   745         return this;
       
   746         }
       
   747     //call base class to set state
       
   748     CFepUiBaseCtrl::HandlePointerDownEventL(aPt);        
       
   749     //init status
       
   750     iLongPressed = EFalse;    
       
   751     iMoved = EFalse;
       
   752     iMoveOffset = TPoint(0,0);    
       
   753     
       
   754     iDraggingStartPt = aPt;
       
   755     if(iLayoutBeingDraged)
       
   756         {
       
   757         //change draging start point to absolute point in layout dragging
       
   758         iDraggingStartPt += UiLayout()->Position();
       
   759         }
       
   760         
       
   761     
       
   762     iCurrentPointerPos = aPt;       
       
   763     CapturePointer();
       
   764     if(iNeedLongtimePress)
       
   765         {
       
   766         iIsDragging = EFalse;
       
   767         iLongPressTimer->SetTimer(iLongtimePressTimeout);        
       
   768         }
       
   769     else
       
   770         {
       
   771         //report event first, so other controls can prepare for dragging
       
   772         ReportEvent(EEventDraggingStart);                
       
   773         
       
   774         iIsDragging = ETrue;
       
   775         PrepareDragging();
       
   776 #ifdef __USING_MOVING_FRAME__        
       
   777         DrawFrame(iDragFrameRect);
       
   778         ShowMovingIndicator();
       
   779         RootControl()->UpdateArea(iDragFrameRect, EFalse);        
       
   780 #endif        
       
   781         iMoveTimer->SetTimer(iDrawInterval);        
       
   782         }
       
   783         
       
   784     return this;
       
   785     }
       
   786 
       
   787 // ---------------------------------------------------------------------------
       
   788 // CDragBar::HandleButtonUpEventL
       
   789 // Handle pen up event in dragbar
       
   790 // (other items were commented in a header).
       
   791 // ---------------------------------------------------------------------------
       
   792 //
       
   793 EXPORT_C CFepUiBaseCtrl* CDragBar::HandlePointerUpEventL(const TPoint& aPt)
       
   794     {
       
   795     CapturePointer(EFalse);
       
   796     if(!PointerDown())
       
   797         return this;
       
   798 
       
   799     if(!iDraggingEnabled)
       
   800         {
       
   801         return CButtonBase::HandlePointerUpEventL(aPt);        
       
   802         }    
       
   803     
       
   804     SetPointerDown(EFalse);
       
   805     if(iNeedLongtimePress)
       
   806         {
       
   807         iLongPressTimer->Cancel();    
       
   808         iLongPressed = EFalse;        
       
   809         }
       
   810     
       
   811     if(iIsDragging)
       
   812        {
       
   813        
       
   814        iIsDragging=EFalse;       
       
   815        iMoveTimer->Cancel();
       
   816        
       
   817        AfterDragging();
       
   818        ReportEvent(EEventDraggingEnd);       
       
   819        //Clear the frame of the last drawing
       
   820        TRect rect;
       
   821 #ifdef __USING_MOVING_FRAME__       
       
   822        rect = DrawFrame(iDragFrameRect,EFalse);
       
   823        rect.BoundingRect(rect);
       
   824 #endif       
       
   825 
       
   826        
       
   827        for(TInt i = iPosObserverList.Count()-1; i >= 0; i--)
       
   828             {
       
   829             if(iPosObserverList[i]->HandlePositionChange(iMoveOffset))
       
   830                 break;    
       
   831             }
       
   832 #ifdef __USING_MOVING_FRAME__            
       
   833        if(iLayoutBeingDraged) //special handling when layout is Dragging            
       
   834             {
       
   835              RootControl()->Draw();
       
   836             }
       
   837        else
       
   838            {
       
   839            //redraw the component.
       
   840             RootControl()->DrawRect(rect,EFalse); //not draw the frame
       
   841             UpdateArea(rect, EFalse);
       
   842            }
       
   843 
       
   844        RootControl()->UpdateValidRegion(NULL,EFalse);
       
   845 #endif       
       
   846        iMoveOffset = TPoint(0,0);    
       
   847        }
       
   848     else
       
   849         {
       
   850         if(iNeedLongtimePress) 
       
   851             {            
       
   852             ReportEvent(EEventButtonUp);            
       
   853             }                           
       
   854         }
       
   855         
       
   856     return this;
       
   857     }
       
   858     
       
   859 // ---------------------------------------------------------------------------
       
   860 // CDragBar::HandleButtonMoveEventL
       
   861 // Handle dragbar move event
       
   862 // (other items were commented in a header).
       
   863 // ---------------------------------------------------------------------------
       
   864 //
       
   865 EXPORT_C CFepUiBaseCtrl* CDragBar::HandlePointerMoveEventL(const TPoint& aPt)       
       
   866     {
       
   867     if(!iDraggingEnabled) //dragging not allowed
       
   868         {
       
   869         CButtonBase::HandlePointerMoveEventL(aPt);
       
   870         return this;
       
   871         }
       
   872     
       
   873     if(!iIsDragging)
       
   874         {
       
   875         if(PointerDown())
       
   876             {
       
   877             iCurrentPointerPos = aPt;   
       
   878             }
       
   879         }        
       
   880     else    // being dragging
       
   881         {            
       
   882         TBool verticalMove(EFalse);
       
   883         TBool horizontalMove(EFalse);
       
   884         if(iLayoutBeingDraged) //special handling when layout is Dragging
       
   885             {            
       
   886             TRect dragRect(Rect());
       
   887             
       
   888             //convert to screen coordinate
       
   889             dragRect.Move(UiLayout()->Position());
       
   890             TPoint pt = aPt + UiLayout()->Position();            
       
   891             
       
   892             TPoint offset = pt-iDraggingStartPt;
       
   893             
       
   894             dragRect.Move(offset + iMoveOffset);
       
   895             
       
   896             //check whether dragRect is a valid position
       
   897             if(!UiLayout()->IsValidDestination(dragRect,this,verticalMove,
       
   898                                                 horizontalMove,ETrue))
       
   899                 {
       
   900                 // Not valid, then check H and V direction separately
       
   901                 if(verticalMove) //V is valid then H is not.
       
   902                     {
       
   903                     //set x offset to 0
       
   904                     offset.iX = 0;
       
   905                     }
       
   906                 else
       
   907                     {
       
   908                     if(horizontalMove)//H is valid then V is not.
       
   909                         {
       
   910                         // set y offset to 0
       
   911                         offset.iY = 0;
       
   912                         }
       
   913                     else
       
   914                         {                        
       
   915                         offset = TPoint(0,0);//return this; 
       
   916                         //not valid in both direction. Can't move
       
   917                         }
       
   918                     }                
       
   919                 }
       
   920             
       
   921             iDraggingStartPt += offset;                
       
   922             iMoveOffset += offset;                        
       
   923             ReportEvent(EEventDragging);
       
   924             return  this;
       
   925             }
       
   926         else    //component moving inside layout area
       
   927             {            
       
   928             if(IsValidDestination(aPt,verticalMove,horizontalMove))
       
   929                 {
       
   930                 iCurrentPointerPos = aPt;
       
   931                 ReportEvent(EEventDragging);
       
   932                 }
       
   933             else
       
   934                 {
       
   935                 // Not valid, then check H and V direction separately
       
   936                 if(verticalMove)
       
   937                     {
       
   938                     //vertical move is allowed
       
   939                     iCurrentPointerPos.iY = aPt.iY;
       
   940                     }
       
   941                 else
       
   942                     {
       
   943                     if(horizontalMove)
       
   944                         {
       
   945                         //horizontal move is allowed
       
   946                         iCurrentPointerPos.iX = aPt.iX;
       
   947                         }
       
   948                     }
       
   949                 }
       
   950             }
       
   951         }
       
   952     //When Dragging, eats the move event even it's not a valid destination
       
   953     return this;
       
   954     }
       
   955 
       
   956 // ---------------------------------------------------------------------------
       
   957 // CDragBar::IsValidDestination
       
   958 // Test whether the destination is valid for dragbar
       
   959 // (other items were commented in a header).
       
   960 // ---------------------------------------------------------------------------
       
   961 //    
       
   962 EXPORT_C TBool CDragBar::IsValidDestination(const TPoint& aPt,TBool& aVInfo,
       
   963                                                                TBool& aHInfo)
       
   964     {
       
   965     TRect rect(iDragFrameRect);
       
   966     TPoint offset(aPt-iDraggingStartPt);
       
   967     
       
   968     rect.Move(offset);
       
   969     
       
   970     return UiLayout()->IsValidDestination(rect,this,aVInfo,aHInfo,
       
   971                                                           iLayoutBeingDraged);
       
   972     }
       
   973 
       
   974 // ---------------------------------------------------------------------------
       
   975 // CDragBar::Move
       
   976 // Move control
       
   977 // (other items were commented in a header).
       
   978 // ---------------------------------------------------------------------------
       
   979 //            
       
   980 EXPORT_C void CDragBar::Move(const TPoint& aOffset)
       
   981     {
       
   982     CFepUiBaseCtrl::Move(aOffset);
       
   983     iMovingIndicatorPos += aOffset;
       
   984     iMoved = ETrue;
       
   985     
       
   986     } 
       
   987 
       
   988 // ---------------------------------------------------------------------------
       
   989 // CDragBar::AddPositionObserver
       
   990 // Add position change observer
       
   991 // (other items were commented in a header).
       
   992 // ---------------------------------------------------------------------------
       
   993 //            
       
   994 EXPORT_C void CDragBar::AddPositionObserver(MPositionObserver* aObserver)
       
   995     {
       
   996     if(!aObserver)
       
   997         return;    
       
   998     
       
   999      //is it already an observer?
       
  1000     if(KErrNotFound != iPosObserverList.Find(aObserver))
       
  1001         {
       
  1002         return; // do nothing
       
  1003         }
       
  1004     
       
  1005     if(aObserver == static_cast<MPositionObserver*>(RootControl()) )
       
  1006         {        
       
  1007         iLayoutBeingDraged = ETrue;        
       
  1008         }
       
  1009     
       
  1010     iPosObserverList.Append(aObserver);
       
  1011     
       
  1012     iDragFrameRect.BoundingRect(aObserver->MovingArea());    
       
  1013     
       
  1014     if(aObserver->IsFepBaseControl())
       
  1015         {
       
  1016         CFepUiBaseCtrl* ctrl=static_cast<CFepUiBaseCtrl*>(aObserver);
       
  1017         ctrl->AddEventObserver(this);                 
       
  1018         }
       
  1019     }
       
  1020 
       
  1021 // ---------------------------------------------------------------------------
       
  1022 // CDragBar::AddToDraggingCtrlList
       
  1023 // Add a control to dragging list
       
  1024 // (other items were commented in a header).
       
  1025 // ---------------------------------------------------------------------------
       
  1026 //            
       
  1027 void CDragBar::AddToDraggingCtrlList(CFepUiBaseCtrl* aCtrl)
       
  1028     {
       
  1029     if(!aCtrl->Ready())
       
  1030         return;
       
  1031     
       
  1032     if(aCtrl->IsKindOfControl(ECtrlControlGroup))
       
  1033         {
       
  1034         CControlGroup* group = reinterpret_cast<CControlGroup*>(aCtrl);
       
  1035         RPointerArray<CFepUiBaseCtrl> ctrlList = group->ControlList();
       
  1036         for(TInt i = 0; i < ctrlList.Count(); i++)
       
  1037             {
       
  1038             if(ctrlList[i]->Ready())
       
  1039                 AddToDraggingCtrlList(ctrlList[i]);
       
  1040             }
       
  1041         }
       
  1042     else
       
  1043         {
       
  1044         if(aCtrl->Ready()) //root control is not included
       
  1045             iDraggingCtrlList.Append(aCtrl);
       
  1046         }
       
  1047     }
       
  1048 
       
  1049 
       
  1050 // ---------------------------------------------------------------------------
       
  1051 // CDragBar::PrepareDragging
       
  1052 // Change dragging control's state before dragging
       
  1053 // (other items were commented in a header).
       
  1054 // ---------------------------------------------------------------------------
       
  1055 //            
       
  1056 void CDragBar::PrepareDragging()
       
  1057     {
       
  1058     TInt i;
       
  1059     //re-calculate the dragging area
       
  1060     ReCalculateDragArea();
       
  1061     
       
  1062     iDraggingCtrlList.Reset();
       
  1063     for( i = 0; i < iPosObserverList.Count(); i++)
       
  1064         {
       
  1065         if(iPosObserverList[i]->IsFepBaseControl())
       
  1066             {
       
  1067             CFepUiBaseCtrl* ctrl=static_cast<CFepUiBaseCtrl*>(
       
  1068                                                         iPosObserverList[i]);
       
  1069             if(ctrl != RootControl())
       
  1070                 {
       
  1071                 AddToDraggingCtrlList(ctrl);
       
  1072                 }
       
  1073             }
       
  1074         }
       
  1075         
       
  1076     for(i = 0; i < iDraggingCtrlList.Count(); i++)
       
  1077         {
       
  1078         iDraggingCtrlList[i]->SetReady(EFalse);
       
  1079         }
       
  1080     }
       
  1081 
       
  1082 // ---------------------------------------------------------------------------
       
  1083 // CDragBar::AfterDragging
       
  1084 // Change dragging control's state after dragging 
       
  1085 // (other items were commented in a header).
       
  1086 // ---------------------------------------------------------------------------
       
  1087 //            
       
  1088 void CDragBar::AfterDragging()
       
  1089     {
       
  1090     TInt i;        
       
  1091     for(i = 0; i < iDraggingCtrlList.Count(); i++)
       
  1092         {
       
  1093         iDraggingCtrlList[i]->SetReady(ETrue);
       
  1094         }
       
  1095     }
       
  1096 
       
  1097 // ---------------------------------------------------------------------------
       
  1098 // CDragBar::RemovePositionObserver
       
  1099 // Remove position change observer
       
  1100 // (other items were commented in a header).
       
  1101 // ---------------------------------------------------------------------------
       
  1102 //            
       
  1103 EXPORT_C void CDragBar::RemovePositionObserver(MPositionObserver* aObserver)
       
  1104     {
       
  1105     TInt index = iPosObserverList.Find(aObserver);
       
  1106     if(KErrNotFound != index)
       
  1107         {       
       
  1108         if(aObserver == RootControl())
       
  1109             iLayoutBeingDraged = EFalse;
       
  1110     
       
  1111         iPosObserverList.Remove(index);
       
  1112         //re-calculate the moving rect
       
  1113         iDragFrameRect = Rect();
       
  1114         for(TInt i = 0; i < iPosObserverList.Count(); i++)
       
  1115             iDragFrameRect.BoundingRect(iPosObserverList[i]->MovingArea());        
       
  1116         }            
       
  1117     }
       
  1118 
       
  1119 // ---------------------------------------------------------------------------
       
  1120 // CDragBar::SetLongpressTimer
       
  1121 // Set long time press time out
       
  1122 // (other items were commented in a header).
       
  1123 // ---------------------------------------------------------------------------
       
  1124 //            
       
  1125 EXPORT_C void CDragBar::SetLongpressTimer(TTimeIntervalMicroSeconds32 aTime)
       
  1126     {
       
  1127     if(aTime.Int() <= 0)
       
  1128         iNeedLongtimePress = EFalse;
       
  1129     else
       
  1130         {
       
  1131         iNeedLongtimePress = ETrue;
       
  1132         iLongtimePressTimeout = aTime;
       
  1133         }
       
  1134     }
       
  1135 
       
  1136 // ---------------------------------------------------------------------------
       
  1137 // CDragBar::HandleTimerOut
       
  1138 // Handle long press time out event
       
  1139 // (other items were commented in a header).
       
  1140 // ---------------------------------------------------------------------------
       
  1141 //                
       
  1142 EXPORT_C void CDragBar::HandleTimerOut(TInt aTimeType)
       
  1143     {
       
  1144     switch(aTimeType)
       
  1145         {
       
  1146         //long press timeout        
       
  1147         case CLayoutTimer::ELongPressTimer:
       
  1148             if(PointerDown() && Contains(iCurrentPointerPos))
       
  1149                 {
       
  1150                 //report event
       
  1151                 ReportEvent(EEventButtonLongPress);
       
  1152                 
       
  1153                 //report event first                
       
  1154                 ReportEvent(EEventDraggingStart);                        
       
  1155                 
       
  1156                 iLongPressed = ETrue;
       
  1157                 iIsDragging = ETrue;            
       
  1158                 //need redraw to show that moving starts
       
  1159                 PrepareDragging();
       
  1160 #ifdef __USING_MOVING_FRAME__                
       
  1161                 TRect dirtyRect = DrawFrame(iDragFrameRect);
       
  1162                 ShowMovingIndicator();
       
  1163 
       
  1164                 UpdateArea(dirtyRect, EFalse);        
       
  1165 #endif                
       
  1166                 iMoveTimer->SetTimer(iDrawInterval);                        
       
  1167                 }
       
  1168             break;
       
  1169         case CLayoutTimer::EDragbarMoveTimer:
       
  1170             if(iLayoutBeingDraged)
       
  1171                 {                        
       
  1172                 
       
  1173                 static_cast<MPositionObserver*>(RootControl())->
       
  1174                                             HandlePositionChange(iMoveOffset);
       
  1175                 iMoveOffset = TPoint(0,0);
       
  1176                 }
       
  1177             else
       
  1178                 {                
       
  1179                 //clear previous frame rect
       
  1180                 TRect rect = DrawFrame(iDragFrameRect,EFalse);          
       
  1181                 TPoint offset = iCurrentPointerPos - iDraggingStartPt;
       
  1182                 iMoveOffset += offset;        
       
  1183                 
       
  1184                 iDragFrameRect.Move(offset);      
       
  1185                 
       
  1186 #ifdef __USING_MOVING_FRAME__                
       
  1187                 TRect dirtyRect = DrawFrame(iDragFrameRect);        
       
  1188                 ShowMovingIndicator();
       
  1189                 rect.BoundingRect(dirtyRect);
       
  1190 #else
       
  1191                 rect = iDragFrameRect;                
       
  1192 #endif                
       
  1193                 iDraggingStartPt = iCurrentPointerPos;
       
  1194                 
       
  1195                 UpdateArea(rect, EFalse);
       
  1196                 
       
  1197                 }
       
  1198             break;
       
  1199         default:
       
  1200             break;
       
  1201         }
       
  1202     }
       
  1203 
       
  1204 // ---------------------------------------------------------------------------
       
  1205 // CDragBar::ReCalculateDragArea
       
  1206 // Update moving area. 
       
  1207 // (other items were commented in a header).
       
  1208 // ---------------------------------------------------------------------------
       
  1209 //                 
       
  1210 void CDragBar::ReCalculateDragArea()
       
  1211     {
       
  1212     iDragFrameRect = Rect();
       
  1213     for(TInt i = 0; i < iPosObserverList.Count(); i++)
       
  1214         {
       
  1215         iDragFrameRect.BoundingRect(
       
  1216                         iPosObserverList[i]->MovingArea());
       
  1217         }                                        
       
  1218     }
       
  1219 // ---------------------------------------------------------------------------
       
  1220 // CDragBar::HandleControlEvent
       
  1221 // Handle event from control which being observed
       
  1222 // (other items were commented in a header).
       
  1223 // ---------------------------------------------------------------------------
       
  1224 //                
       
  1225 EXPORT_C void CDragBar::HandleControlEvent(TInt aEventType, CFepUiBaseCtrl* aCtrl,
       
  1226                                                     const TDesC& /*aEventData*/)
       
  1227     {
       
  1228     //only handle control size event change
       
  1229     switch(aEventType)
       
  1230         {
       
  1231         case EEventSizeChanged:
       
  1232             {
       
  1233             if(aCtrl && !aCtrl->Hiden())
       
  1234                 {
       
  1235 /*                TInt index = iPosObserverList.Find(aCtrl);
       
  1236                 if(KErrNotFound != index)
       
  1237                     {
       
  1238                     //recaculate the bounding rect
       
  1239                     ReCalculateDragArea();    
       
  1240                     }              */
       
  1241                 if(aCtrl == this)
       
  1242                     {
       
  1243                     iMovingIndicatorPos = Rect().iTl + PenSize();
       
  1244                     }
       
  1245                 }
       
  1246             }
       
  1247             break;
       
  1248         default:
       
  1249             break;
       
  1250         }
       
  1251     }
       
  1252     
       
  1253 // ---------------------------------------------------------------------------
       
  1254 // CDragBar::SetBitmapL
       
  1255 // Set bitmap for given status
       
  1256 // (other items were commented in a header).
       
  1257 // ---------------------------------------------------------------------------
       
  1258 //    
       
  1259 EXPORT_C void CDragBar::SetBitmapL(CFbsBitmap* aBitmap, TButtonBmpType aType)
       
  1260     {
       
  1261     CFbsBitmap* bmp = aBitmap;
       
  1262     
       
  1263     if(!aBitmap)
       
  1264         return;
       
  1265     
       
  1266     if(EBtnBmpMovingIndicator == aType)
       
  1267         {            
       
  1268         iMovingIndicatorBmp = bmp;
       
  1269 
       
  1270         iMovingIndicatorPos = Rect().iTl + PenSize();            
       
  1271         }
       
  1272 
       
  1273     CButtonBase::SetBitmapL(bmp,aType);
       
  1274     }  
       
  1275 
       
  1276 // ---------------------------------------------------------------------------
       
  1277 // CDragBar::ShowMovingIndicator
       
  1278 // Show dragging indicator
       
  1279 // (other items were commented in a header).
       
  1280 // ---------------------------------------------------------------------------
       
  1281 //    
       
  1282 void CDragBar::ShowMovingIndicator(TBool aDrawFlag)
       
  1283     {
       
  1284     if(iMovingIndicatorBmp && aDrawFlag)
       
  1285         {
       
  1286         
       
  1287         CFbsBitGc* gc = static_cast<CFbsBitGc*>(BitGc());                     
       
  1288         
       
  1289         TSize bmpSize = iMovingIndicatorBmp->SizeInPixels();
       
  1290         bmpSize -= PenSize();
       
  1291         TRect bmpRect(TPoint(0,0),bmpSize);
       
  1292         TPoint bmpPos = iMovingIndicatorPos + iMoveOffset;
       
  1293         
       
  1294       
       
  1295         gc->Activate( MaskBitmapDevice() );
       
  1296         
       
  1297         gc->SetBrushStyle( CGraphicsContext::ESolidBrush );
       
  1298         gc->SetBrushColor( TRgb(KOpaqueColor) );
       
  1299         TRect rect = bmpRect;
       
  1300         rect.Move(bmpPos);
       
  1301         gc->DrawRect(rect);
       
  1302     
       
  1303         //mask will not be used if no bmp
       
  1304         if(iMovingIndicatorMaskBmp) 
       
  1305             {            
       
  1306             gc->BitBlt(bmpPos,iMovingIndicatorMaskBmp,bmpRect);            
       
  1307             }        
       
  1308         
       
  1309         gc->Activate( BitmapDevice() );            
       
  1310         gc->SetBrushColor( KRgbWhite );        
       
  1311         gc->BitBlt(bmpPos,iMovingIndicatorBmp,bmpRect);       
       
  1312         }
       
  1313        
       
  1314     }
       
  1315 
       
  1316 // ---------------------------------------------------------------------------
       
  1317 // CDragBar::DrawFrame
       
  1318 // Draw moving frame
       
  1319 // (other items were commented in a header).
       
  1320 // ---------------------------------------------------------------------------
       
  1321 //    
       
  1322 TRect CDragBar::DrawFrame(const TRect& aFrameRect, TBool aDrawFlag)
       
  1323     {   
       
  1324     return RootControl()->DrawFrame(aFrameRect,aDrawFlag);     
       
  1325     }
       
  1326 
       
  1327 
       
  1328 
       
  1329 // ---------------------------------------------------------------------------
       
  1330 // CDragBar::SetMaskBitmapL
       
  1331 // Set bitmap for given status
       
  1332 // (other items were commented in a header).
       
  1333 // ---------------------------------------------------------------------------
       
  1334 //    
       
  1335 EXPORT_C void CDragBar::SetMaskBitmapL(CFbsBitmap* aBitmap, TButtonBmpType aType)
       
  1336     {   
       
  1337     if(!aBitmap)
       
  1338         return;
       
  1339     
       
  1340     switch(aType)
       
  1341         {
       
  1342         case EBtnBmpMovingIndicator:
       
  1343             iMovingIndicatorMaskBmp = aBitmap;
       
  1344             break;
       
  1345         default:
       
  1346             CButtonBase::SetBitmapL(aBitmap,aType);
       
  1347             break;
       
  1348         }
       
  1349     }  
       
  1350    
       
  1351 // ---------------------------------------------------------------------------
       
  1352 // CDragBar::IsDraggingComponent
       
  1353 // Test whether this control belongs to a dragbar
       
  1354 // (other items were commented in a header).
       
  1355 // ---------------------------------------------------------------------------
       
  1356 //        
       
  1357 EXPORT_C TBool CDragBar::IsDraggingComponent(CFepUiBaseCtrl* aControl)
       
  1358     {
       
  1359     for(TInt i = 0; i < iPosObserverList.Count(); i++)
       
  1360         {
       
  1361         if(aControl == iPosObserverList[i])
       
  1362             return ETrue;
       
  1363         }
       
  1364     return EFalse;
       
  1365     }
       
  1366 
       
  1367 // ---------------------------------------------------------------------------
       
  1368 // CDragBar::OnDeActivate
       
  1369 // Response to layout de activation event
       
  1370 // (other items were commented in a header).
       
  1371 // ---------------------------------------------------------------------------
       
  1372 //     
       
  1373 EXPORT_C void CDragBar::OnDeActivate()
       
  1374     {
       
  1375     //simulates a pointer up event to end the draging.
       
  1376     TRAP_IGNORE(HandlePointerUpEventL(TPoint(0,0)));
       
  1377     CFepUiBaseCtrl::OnDeActivate();        
       
  1378     }
       
  1379     
       
  1380 // ---------------------------------------------------------------------------
       
  1381 // CDragBar::CancelPointerDownL
       
  1382 // Cancel pointer down event
       
  1383 // (other items were commented in a header).
       
  1384 // ---------------------------------------------------------------------------
       
  1385 //    
       
  1386 EXPORT_C void CDragBar::CancelPointerDownL()
       
  1387     {
       
  1388     HandlePointerUpEventL(TPoint(0,0));
       
  1389     }
       
  1390         
       
  1391 //end of CDragBar