textinput/peninputarc/src/peninputlayoutcontrol/peninputlayoutcontrolgroup.cpp
changeset 0 eb1f2e154e89
child 7 6defe5d1bd39
equal deleted inserted replaced
-1:000000000000 0:eb1f2e154e89
       
     1 /*
       
     2 * Copyright (c) 2005-2006 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0""
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Implementation for control group
       
    15 *
       
    16 */
       
    17 
       
    18 #include "peninputlayoutbutton.h"
       
    19 #include "peninputlayoutctrlgroup.h"
       
    20 #include "peninputlayoutrootctrl.h"
       
    21 #include "peninputlayout.h"
       
    22 #include "coecntrl.h"
       
    23 // ============================ MEMBER FUNCTIONS ===============================
       
    24 
       
    25 /******************************************************************************/
       
    26 // Implementation to Class CControlGroup
       
    27 //
       
    28 /******************************************************************************/
       
    29 
       
    30 // -----------------------------------------------------------------------------
       
    31 // CControlGroup::NewL
       
    32 // Factory function
       
    33 // (other items were commented in a header).
       
    34 // -----------------------------------------------------------------------------
       
    35 //    
       
    36 EXPORT_C CControlGroup* CControlGroup::NewL(CFepUiLayout* aUiLayout,
       
    37 										    TInt aControlId,
       
    38 										    TBool aRedrawBg /*= ETrue*/)
       
    39     {
       
    40     CControlGroup* ctrlGroup=new (ELeave)CControlGroup(aUiLayout,aControlId, aRedrawBg);   
       
    41     CleanupStack::PushL(ctrlGroup);
       
    42     ctrlGroup->ConstructL();
       
    43     CleanupStack::Pop(ctrlGroup);
       
    44     return ctrlGroup;
       
    45     }
       
    46 
       
    47 // -----------------------------------------------------------------------------
       
    48 // CControlGroup::NewL
       
    49 // Factory function
       
    50 // (other items were commented in a header).
       
    51 // -----------------------------------------------------------------------------
       
    52 //    
       
    53 CControlGroup* CControlGroup::NewL(CFepUiLayout* aUiLayout,CCoeControl* aControl)
       
    54     {
       
    55     if(!aControl)
       
    56         return NULL;
       
    57     CControlGroup* ctrlGroup=new (ELeave)CControlGroup(aUiLayout,
       
    58                                                       aControl->UniqueHandle());
       
    59     
       
    60     ctrlGroup->iWndControl = aControl;
       
    61     CleanupStack::PushL(ctrlGroup);
       
    62     ctrlGroup->ConstructL();
       
    63     ctrlGroup->SetRect(aControl->Rect());    
       
    64     CleanupStack::Pop(ctrlGroup);
       
    65     return ctrlGroup;
       
    66     }
       
    67     
       
    68 // -----------------------------------------------------------------------------
       
    69 // CControlGroup::CControlGroup
       
    70 // C++ default constructor
       
    71 // (other items were commented in a header).
       
    72 // -----------------------------------------------------------------------------
       
    73 //        
       
    74 EXPORT_C CControlGroup::CControlGroup(CFepUiLayout* aUiLayout,TInt aCtrlId)
       
    75                 :CFepUiBaseCtrl(TRect(0,0,0,0),aUiLayout,aCtrlId)
       
    76     {
       
    77     iNeedRedrawBg = (TInt)ETrue;
       
    78     SetControlType(ECtrlControlGroup);
       
    79     }
       
    80 
       
    81 // -----------------------------------------------------------------------------
       
    82 // CControlGroup::CControlGroup
       
    83 // C++ default constructor
       
    84 // (other items were commented in a header).
       
    85 // -----------------------------------------------------------------------------
       
    86 //        
       
    87 EXPORT_C CControlGroup::CControlGroup(CFepUiLayout* aUiLayout,
       
    88 									  TInt aCtrlId,
       
    89 									  TBool aRedrawBg)
       
    90                 :CFepUiBaseCtrl(TRect(0,0,0,0),aUiLayout,aCtrlId)
       
    91     {
       
    92     iNeedRedrawBg = aRedrawBg;
       
    93     SetControlType(ECtrlControlGroup);
       
    94     }
       
    95 
       
    96 // -----------------------------------------------------------------------------
       
    97 // CControlGroup::ConstructL
       
    98 // Second phrase constructor
       
    99 // (other items were commented in a header).
       
   100 // -----------------------------------------------------------------------------
       
   101 //            
       
   102 EXPORT_C void CControlGroup::ConstructL()
       
   103     {
       
   104     //do CFepUiBaseCtrl's base construction
       
   105     BaseConstructL();
       
   106     }
       
   107 
       
   108 // -----------------------------------------------------------------------------
       
   109 // CControlGroup::~CControlGroup
       
   110 // Destructor
       
   111 // (other items were commented in a header).
       
   112 // -----------------------------------------------------------------------------
       
   113 //            
       
   114 EXPORT_C CControlGroup::~CControlGroup()
       
   115     {
       
   116     CFepUiBaseCtrl* ctrl;
       
   117     for(TInt i = iOwnedCtrlList.Count()-1;i >= 0;i--)
       
   118         {
       
   119         ctrl = iOwnedCtrlList[i];
       
   120         delete ctrl;
       
   121         }
       
   122     iOwnedCtrlList.Close();
       
   123     
       
   124     iCtrlList.Close();
       
   125     iPopCtrlList.Close();
       
   126     iNonHwrStartPtRegion.Close();    
       
   127     /*for(TInt i = 0 ; i < iSubRegionArea.Count(); ++i)
       
   128         {
       
   129          delete iSubRegionArea[i];
       
   130         }*/
       
   131     iSubRegionArea.ResetAndDestroy();    
       
   132     iSubRegionArea.Close();
       
   133     iSubCtrlShowStateBeforeHiden.Close();
       
   134     }
       
   135     
       
   136 // -----------------------------------------------------------------------------
       
   137 // CControlGroup::AddControlL
       
   138 // Add control to group
       
   139 // (other items were commented in a header).
       
   140 // -----------------------------------------------------------------------------
       
   141 //        
       
   142 EXPORT_C void CControlGroup::AddControlL(CFepUiBaseCtrl* aControl, TBool aOwnerFlag)
       
   143     {
       
   144     //do nothing if we already has the control.
       
   145     if(!aControl || KErrNotFound != iCtrlList.Find(aControl))
       
   146         return;
       
   147     CalculateClipRegion(aControl);
       
   148     
       
   149     if(aOwnerFlag)
       
   150         iOwnedCtrlList.AppendL(aControl);
       
   151 
       
   152     iCtrlList.AppendL(aControl);   
       
   153     
       
   154     aControl->SetParent(this);
       
   155     if(!aControl->Hiden() && !aControl->IsKindOfControl(ECtrlPopupWindow))
       
   156         {        
       
   157         //TRect rect = Rect();
       
   158         
       
   159         if(iCtrlList.Count() > 1)
       
   160             {
       
   161             iRect.BoundingRect(aControl->Rect());       
       
   162             }
       
   163         else
       
   164             iRect = aControl->Rect();
       
   165         
       
   166         //iRect = rect;
       
   167 
       
   168         /*RRegion region(8);
       
   169         region.Copy(Region());   
       
   170 
       
   171         region.AddRect(aControl->Rect());
       
   172         SetRegion(region);*/
       
   173         UpdateValidRegion(aControl,EFalse);
       
   174         }
       
   175     //since control may be added dynamically, we need draw it
       
   176 //        aControl->Draw();
       
   177 //        aControl->UpdateArea(aControl->Rect(),ETrue);
       
   178     TSubCtrlShownState state = {aControl,aControl->Hiden()};    
       
   179     iSubCtrlShowStateBeforeHiden.AppendL(state);
       
   180     }
       
   181 
       
   182 
       
   183 // -----------------------------------------------------------------------------
       
   184 // CControlGroup::Find
       
   185 // Find the control in a control group
       
   186 // (other items were commented in a header).
       
   187 // -----------------------------------------------------------------------------
       
   188 //        
       
   189 CFepUiBaseCtrl* CControlGroup::Find(CCoeControl* aCtrl)
       
   190     {
       
   191     if(!IsKindOfControl(ECtrlWndBasedCtrl))
       
   192         return NULL;
       
   193     
       
   194     if(aCtrl == iWndControl)
       
   195         return this;
       
   196     
       
   197     for(TInt i = 0; i < iCtrlList.Count(); i++)
       
   198         {
       
   199         CFepUiBaseCtrl* ctrl = iCtrlList[i];
       
   200         if(!ctrl->IsKindOfControl(ECtrlControlGroup))
       
   201             {
       
   202             if(aCtrl == ctrl->WndBasedControl())
       
   203                 return ctrl;
       
   204             }
       
   205         else
       
   206             {
       
   207             /*
       
   208             bFound = static_cast<CControlGroup*>(ctrl)->Find(aCtrl);
       
   209             if(bFound)
       
   210                 return bFound;
       
   211                 */
       
   212             CControlGroup* ctrlGroup = static_cast<CControlGroup*>(ctrl);
       
   213             CFepUiBaseCtrl* foundedCtrl = ctrlGroup->Find(aCtrl);
       
   214             if(foundedCtrl)
       
   215                 return foundedCtrl;
       
   216             }
       
   217         }
       
   218     
       
   219     return NULL;    
       
   220     }
       
   221     
       
   222     
       
   223 // -----------------------------------------------------------------------------
       
   224 // CControlGroup::AddControlL
       
   225 // Add control to group
       
   226 // (other items were commented in a header).
       
   227 // -----------------------------------------------------------------------------
       
   228 //        
       
   229 EXPORT_C CFepUiBaseCtrl* CControlGroup::AddControlL(CCoeControl* aControl)
       
   230     {
       
   231     //do nothing if we already has the control.
       
   232     if(!IsKindOfControl(ECtrlWndBasedCtrl) || !aControl)
       
   233         return NULL;
       
   234     
       
   235     CFepUiBaseCtrl* ctrl = Find(aControl);
       
   236     if(ctrl)
       
   237         return ctrl;   
       
   238 
       
   239     //if it's a compound control, we need find out its sub-control one by one
       
   240     if(aControl->CountComponentControls())
       
   241         {
       
   242         //create a control group
       
   243         CControlGroup* group = CControlGroup::NewL(UiLayout(),aControl);
       
   244         ctrl = group;
       
   245         CleanupStack::PushL(ctrl);
       
   246         for(TInt i = 0; i < aControl->CountComponentControls(); i++)
       
   247             {
       
   248             group->AddControlL(aControl->ComponentControl(i));
       
   249             }        
       
   250         group->SetControlType(ECtrlWndBasedCtrl|ECtrlControlGroup);                
       
   251         }
       
   252     else
       
   253         {
       
   254         ctrl = new(ELeave) CFepUiBaseCtrl(aControl,UiLayout());
       
   255         ctrl->SetControlType(ECtrlWndBasedCtrl|ECtrlBaseCtrl);
       
   256         CleanupStack::PushL(ctrl);
       
   257         ctrl->BaseConstructL();
       
   258         }   
       
   259     AddControlL(ctrl,ETrue);
       
   260     CleanupStack::Pop(ctrl);            
       
   261     UpdateValidRegion(ctrl,EFalse);    
       
   262     return ctrl;
       
   263     }
       
   264 
       
   265 // ---------------------------------------------------------------------------
       
   266 // CControlGroup::RemoveOwnedControl
       
   267 // Remove a control from group's owned control list
       
   268 // ---------------------------------------------------------------------------
       
   269 //
       
   270 TBool CControlGroup::RemoveOwnedControl(CFepUiBaseCtrl* aControl)
       
   271     {
       
   272     TInt index = iOwnedCtrlList.Find(aControl);
       
   273     if(KErrNotFound != index)
       
   274         {
       
   275         iOwnedCtrlList.Remove(index);
       
   276         delete aControl;
       
   277         }
       
   278     return KErrNotFound != index;
       
   279     }
       
   280 
       
   281 // ---------------------------------------------------------------------------
       
   282 // CControlGroup::RemoveControl
       
   283 // Remove a control from group
       
   284 // ---------------------------------------------------------------------------
       
   285 //
       
   286 EXPORT_C TBool CControlGroup::RemoveControl(CFepUiBaseCtrl* aControl)
       
   287     {
       
   288     TInt i;
       
   289     TBool bFound = EFalse;
       
   290     //CControlGroup* parent = this;
       
   291     
       
   292     if(!aControl || iCtrlList.Count() <= 0)
       
   293         return EFalse;
       
   294     
       
   295     if(aControl == iActiveCtrl)
       
   296         iActiveCtrl = NULL;
       
   297     
       
   298     //iRect = iCtrlList[0]->Rect();    
       
   299     
       
   300     //find and remove the control
       
   301     for(i = 0 ; i < iCtrlList.Count() && !bFound; ++i)
       
   302         {
       
   303         if(iCtrlList[i] == aControl)
       
   304             {
       
   305             iCtrlList.Remove(i);            
       
   306             RemoveOwnedControl(aControl);
       
   307             bFound = ETrue;            
       
   308             }
       
   309         }
       
   310         
       
   311     if(bFound && !aControl->Hiden())
       
   312         {
       
   313         //change iRect
       
   314         if(iCtrlList.Count())
       
   315             {
       
   316             iRect = iCtrlList[0]->Rect();
       
   317             }
       
   318         else
       
   319             iRect = TRect(0,0,0,0);
       
   320         
       
   321         for( i = 1; i < iCtrlList.Count(); ++i)
       
   322             {            
       
   323             iRect.BoundingRect(iCtrlList[i]->Rect());            
       
   324             }
       
   325         }
       
   326     else
       
   327         return EFalse;
       
   328     
       
   329     RemoveCtrlFromSubCtrlInfoList(aControl);
       
   330     UpdateValidRegion(aControl,ETrue);
       
   331     
       
   332     CalculateClipRegion();
       
   333     return bFound;
       
   334     }
       
   335 
       
   336 void CControlGroup::CalculateClipRegion(CFepUiBaseCtrl* aControl)
       
   337     {
       
   338     for(TInt i = 0 ; i < iCtrlList.Count(); ++i)
       
   339         {
       
   340         if(!aControl->Hiden())
       
   341             iCtrlList[i]->iClipRegion.SubRect(aControl->Rect());        
       
   342         }
       
   343     }
       
   344     
       
   345 void CControlGroup::CalculateClipRegion()
       
   346     {
       
   347     //restore each control's rect first.
       
   348     for(TInt i = 0; i < iCtrlList.Count(); ++i)
       
   349         {
       
   350         CFepUiBaseCtrl* ctrl = iCtrlList[i];
       
   351         if(ctrl->IsKindOfControl(ECtrlControlGroup))
       
   352             static_cast<CControlGroup*>(ctrl)->CalculateClipRegion();
       
   353         ctrl->iClipRegion.Clear();
       
   354         ctrl->iClipRegion.AddRect(ctrl->Rect());
       
   355         }
       
   356     //re calulate clip region
       
   357     
       
   358     for(TInt curCtrlIdx = iCtrlList.Count() - 1 ; curCtrlIdx >= 0 ; --curCtrlIdx)
       
   359         {
       
   360         CFepUiBaseCtrl* curCtrl = iCtrlList[curCtrlIdx];
       
   361         for(TInt upperCtrlIdx = curCtrlIdx + 1 ;  upperCtrlIdx < iCtrlList.Count(); ++upperCtrlIdx)
       
   362             {
       
   363             if(!iCtrlList[upperCtrlIdx]->Hiden())
       
   364                 curCtrl->iClipRegion.SubRect(iCtrlList[upperCtrlIdx]->Rect());
       
   365             }
       
   366         }
       
   367     }
       
   368 // -----------------------------------------------------------------------------
       
   369 // CControlGroup::At
       
   370 // Return control in given position
       
   371 // (other items were commented in a header).
       
   372 // -----------------------------------------------------------------------------
       
   373 //
       
   374 EXPORT_C CFepUiBaseCtrl* CControlGroup::At(TInt aIndex)
       
   375     {
       
   376     if(aIndex >=0 && aIndex < iCtrlList.Count())
       
   377         return iCtrlList[aIndex];
       
   378     else
       
   379         return NULL;
       
   380     }
       
   381 
       
   382 // -----------------------------------------------------------------------------
       
   383 // CControlGroup::ControlForPoints()
       
   384 // Find the control which contains the point
       
   385 // (other items were commented in a header).
       
   386 // -----------------------------------------------------------------------------
       
   387 //    
       
   388 CFepUiBaseCtrl* CControlGroup::ControlForPoints(const TPoint& aPt)
       
   389     {
       
   390     CFepUiBaseCtrl* ctrl = NULL;
       
   391 
       
   392     if(iActiveCtrl && !iActiveCtrl->Hiden() && iActiveCtrl->Contains(aPt))
       
   393         {
       
   394         return iActiveCtrl;        
       
   395         }
       
   396         
       
   397     for ( TInt i = iCtrlList.Count() - 1 ; i > -1 ; i-- )
       
   398         {
       
   399         ctrl = iCtrlList[i];
       
   400         if(!ctrl->Hiden() && ctrl->Contains(aPt))
       
   401             {
       
   402             return ctrl;
       
   403             }
       
   404         }
       
   405     return NULL;
       
   406     }
       
   407 
       
   408 
       
   409 // -----------------------------------------------------------------------------
       
   410 // CControlGroup::HandlePointerUpEventL()
       
   411 // Handle pointer up event
       
   412 // (other items were commented in a header).
       
   413 // -----------------------------------------------------------------------------
       
   414 //    
       
   415 EXPORT_C CFepUiBaseCtrl* CControlGroup::HandlePointerUpEventL(const TPoint& aPt)
       
   416     {
       
   417     if(iWndControl)
       
   418         {
       
   419         return CFepUiBaseCtrl::HandlePointerUpEventL(aPt);
       
   420         }
       
   421     CFepUiBaseCtrl* ctrl = ControlForPoints(aPt);
       
   422     if(!ctrl && !iRect.Contains(aPt)) // not belong our group
       
   423         return NULL;
       
   424     
       
   425     if(!PointerDown())
       
   426         {    
       
   427         return this;
       
   428         }
       
   429         
       
   430     SetPointerDown(EFalse);    
       
   431     
       
   432     if(ctrl != iCtrlWithPointerDown)
       
   433         {
       
   434         if(iCtrlWithPointerDown)
       
   435             iCtrlWithPointerDown->CancelPointerDownL();
       
   436         }
       
   437     else
       
   438         {        
       
   439         if(ctrl)
       
   440             {          // modify by vv for temp  
       
   441             if(ctrl->HandlePointerUpEventL(aPt))
       
   442                 {
       
   443                 if( !ctrl->Hiden() && ctrl->Ready() )
       
   444                     {
       
   445                     SetActiveCtrl(ctrl);
       
   446                     }
       
   447                 }
       
   448             ctrl->SetPointerDown(EFalse);
       
   449             }
       
   450         }
       
   451     iCtrlWithPointerDown = NULL;
       
   452     return this;
       
   453     }
       
   454 
       
   455 
       
   456 // -----------------------------------------------------------------------------
       
   457 // CControlGroup::HandlePointerDownEventL()
       
   458 // Handle pointer down event
       
   459 // (other items were commented in a header).
       
   460 // -----------------------------------------------------------------------------
       
   461 //    
       
   462 EXPORT_C CFepUiBaseCtrl* CControlGroup::HandlePointerDownEventL(const TPoint& aPt)
       
   463     {
       
   464     if(iWndControl)
       
   465         {
       
   466         return CFepUiBaseCtrl::HandlePointerDownEventL(aPt);
       
   467         }
       
   468         
       
   469     CFepUiBaseCtrl* ctrl = ControlForPoints(aPt);
       
   470     iCtrlWithPointerDown = ctrl;
       
   471     
       
   472     if(ctrl)
       
   473         {
       
   474         SetPointerDown(ETrue);
       
   475         
       
   476         iPointerLeft = EFalse;
       
   477         iTempActiveCtrl = iActiveCtrl;
       
   478         SetTempActiveCtrl(ctrl);
       
   479         ctrl->HandlePointerDownEventL(aPt);
       
   480         return this;
       
   481         }
       
   482     return NULL;
       
   483     }
       
   484 
       
   485 
       
   486 // -----------------------------------------------------------------------------
       
   487 // CControlGroup::HandlePointerMoveEvent()
       
   488 // Handle pointer move event
       
   489 // (other items were commented in a header).
       
   490 // -----------------------------------------------------------------------------
       
   491 //    
       
   492 EXPORT_C CFepUiBaseCtrl* CControlGroup::HandlePointerMoveEventL(const TPoint& aPt)
       
   493     {
       
   494     if(iWndControl)
       
   495         {
       
   496         return CFepUiBaseCtrl::HandlePointerMoveEventL(aPt);
       
   497         }
       
   498     CFepUiBaseCtrl* ctrl = ControlForPoints(aPt);
       
   499 
       
   500     if(!ctrl && !iRect.Contains(aPt)) // not belong our group
       
   501         return NULL; // Check: This will not happen!
       
   502     
       
   503     if(!iCtrlWithPointerDown) // does not's process move event if no pointer down
       
   504         return this;
       
   505     
       
   506     if(ctrl != iCtrlWithPointerDown) 
       
   507     //pointer just move out the control for the first time
       
   508         {
       
   509         //Inform the control that pointer is out for first time
       
   510         if(!iPointerLeft)
       
   511             {
       
   512             iPointerLeft = ETrue;            
       
   513             iCtrlWithPointerDown->HandlePointerLeave(aPt);
       
   514             }
       
   515         }
       
   516     else
       
   517         {
       
   518         //Inform the control that pointer is in
       
   519         if(iPointerLeft)
       
   520             {                                    
       
   521             iCtrlWithPointerDown->HandlePointerEnter(aPt);
       
   522             iPointerLeft = EFalse; //reset the flag
       
   523             }
       
   524         }
       
   525     
       
   526     
       
   527     if(ctrl)
       
   528         ctrl->HandlePointerMoveEventL(aPt);
       
   529     else
       
   530         return NULL;
       
   531     return this;
       
   532     }
       
   533 
       
   534 
       
   535 // -----------------------------------------------------------------------------
       
   536 // CControlGroup::Draw
       
   537 // Draw the control
       
   538 // (other items were commented in a header).
       
   539 // -----------------------------------------------------------------------------
       
   540 //    
       
   541 EXPORT_C void CControlGroup::Draw()
       
   542     {
       
   543 	if(!AbleToDraw() || WholeHiden())
       
   544         return;
       
   545     
       
   546     if(iWndControl)
       
   547         {
       
   548         CFepUiBaseCtrl::Draw();
       
   549         return;
       
   550         }
       
   551     //Clear();
       
   552         
       
   553     for(TInt i=0; i<iCtrlList.Count();i++)        
       
   554         {
       
   555         CFepUiBaseCtrl* ctrl = iCtrlList[i];
       
   556         //not draw hiden control and pop up window. Active control is drawn later
       
   557         if(!ctrl->Hiden() && !ctrl->IsKindOfControl(ECtrlPopupWindow)
       
   558             && ctrl != iActiveCtrl) 
       
   559             ctrl->Draw();        
       
   560         }
       
   561     //draw active controls
       
   562     if(iActiveCtrl)
       
   563         iActiveCtrl->Draw();
       
   564     
       
   565     //draw pop control
       
   566      for(TInt i=0; i<iPopCtrlList.Count();i++)        
       
   567         {
       
   568         CFepUiBaseCtrl* ctrl = iPopCtrlList[i];
       
   569         if(!ctrl->Hiden()) 
       
   570             ctrl->Draw();        
       
   571         }
       
   572     }
       
   573 
       
   574 void DoRedrawInCtrlList(const TRect& aRect, CFepUiBaseCtrl* aCtrl,
       
   575                         RPointerArray<CFepUiBaseCtrl>& aList)
       
   576     {
       
   577     for(TInt i = 0 ; i < aList.Count(); ++i)
       
   578         {
       
   579         if(aList[i] == aCtrl)
       
   580             continue;
       
   581         if(!aList[i]->Hiden() && 
       
   582             aList[i]->IsOnTopOf(aCtrl) && 
       
   583             aRect.Intersects(aList[i]->Rect()))
       
   584             {
       
   585             TRect r = aRect;
       
   586             r.Intersection(aList[i]->Rect());
       
   587             aList[i]->ReDrawRect(r);
       
   588             }
       
   589         }
       
   590     }
       
   591 
       
   592 // -----------------------------------------------------------------------------
       
   593 // CControlGroup::RedrawRectIfNeeded
       
   594 // ReDraw the affected control in the rect if needed
       
   595 // (other items were commented in a header).
       
   596 // -----------------------------------------------------------------------------
       
   597 //    
       
   598 void CControlGroup::RedrawRectIfNeeded(const TRect& aRect, CFepUiBaseCtrl* aCtrl)
       
   599     {
       
   600     if( aCtrl->Hiden() )
       
   601         {
       
   602         return;
       
   603         }
       
   604 	if(!AbleToDraw() || WholeHiden())
       
   605         return;
       
   606     
       
   607     if(aRect.IsEmpty())
       
   608         return;
       
   609     
       
   610     //check all sub controls
       
   611     DoRedrawInCtrlList(aRect,aCtrl,iCtrlList);    
       
   612     //check pop list
       
   613     //check all sub controls
       
   614     DoRedrawInCtrlList(aRect,aCtrl,iPopCtrlList);    
       
   615     }
       
   616     
       
   617     
       
   618 // -----------------------------------------------------------------------------
       
   619 // CControlGroup::ReDrawRect
       
   620 // ReDraw the control in the rect
       
   621 // (other items were commented in a header).
       
   622 // -----------------------------------------------------------------------------
       
   623 //    
       
   624 EXPORT_C void CControlGroup::ReDrawRect(const TRect& aRect)
       
   625     {   
       
   626 	if(!AbleToDraw() || WholeHiden())
       
   627         return;
       
   628     
       
   629     if(aRect.IsEmpty())
       
   630         return;
       
   631     if(aRect == Rect())
       
   632         {
       
   633         Draw();    
       
   634         }
       
   635     else
       
   636         {        
       
   637         //find out the controls within the rect
       
   638         if( iNeedRedrawBg )
       
   639         	DrawBackground( aRect );            
       
   640         //DrawControlGroupBackground( aRect );
       
   641         TBool needDrawActiveCtrl = EFalse;
       
   642         for(TInt i=0;i<iCtrlList.Count();i++)
       
   643             {
       
   644             CFepUiBaseCtrl* ctrl=iCtrlList[i];
       
   645             if(!ctrl->Hiden() && aRect.Intersects(ctrl->Rect()))
       
   646                 {
       
   647                 if(iActiveCtrl == ctrl)
       
   648                     {
       
   649                     needDrawActiveCtrl = ETrue;
       
   650                     continue;
       
   651                     }
       
   652                 TRect r = aRect;
       
   653                 r.Intersection(ctrl->Rect());
       
   654                 
       
   655                 ctrl->ReDrawRect(r);
       
   656                 }
       
   657                 
       
   658             }
       
   659         if(needDrawActiveCtrl)
       
   660             {
       
   661             TRect r = aRect;
       
   662             r.Intersection(iActiveCtrl->Rect());
       
   663             
       
   664             iActiveCtrl->ReDrawRect(r);            
       
   665             }
       
   666         }        
       
   667             
       
   668     }    
       
   669     
       
   670 
       
   671 // -----------------------------------------------------------------------------
       
   672 // CControlGroup::SetTempActiveCtrl
       
   673 // Set temparary active control in button down state
       
   674 // (other items were commented in a header).
       
   675 // -----------------------------------------------------------------------------
       
   676 //
       
   677 CFepUiBaseCtrl* CControlGroup::SetTempActiveCtrl(CFepUiBaseCtrl* aCtrl)
       
   678     {
       
   679     if( aCtrl && 
       
   680     	aCtrl != iTempActiveCtrl && 
       
   681         !(aCtrl->ControlType() & ECtrlBackgroundCtrl) )
       
   682         {             
       
   683         //iPrevActiveCtrl = iActiveCtrl;   
       
   684         CFepUiBaseCtrl* previous = iTempActiveCtrl;
       
   685         iTempActiveCtrl = aCtrl;
       
   686         iTempActiveCtrl->SetActive(ETrue);
       
   687         //We need to check whether the control news status is successfully set.   
       
   688         if( iTempActiveCtrl->IsActive() )
       
   689             {
       
   690             if(previous)
       
   691                 previous->SetActive(EFalse);
       
   692             }
       
   693         else
       
   694             {
       
   695             return previous;
       
   696             }
       
   697         }
       
   698     return iTempActiveCtrl;
       
   699     }
       
   700     
       
   701 // -----------------------------------------------------------------------------
       
   702 // CControlGroup::SetActiveCtrl
       
   703 // Set active control
       
   704 // (other items were commented in a header).
       
   705 // -----------------------------------------------------------------------------
       
   706 //
       
   707 EXPORT_C CFepUiBaseCtrl* CControlGroup::SetActiveCtrl(CFepUiBaseCtrl* aCtrl)
       
   708     {
       
   709     if( aCtrl &&
       
   710     	aCtrl != iActiveCtrl &&
       
   711     	!(aCtrl->ControlType() & ECtrlBackgroundCtrl) )
       
   712         {                
       
   713         CFepUiBaseCtrl* previous = iActiveCtrl;
       
   714         iActiveCtrl = aCtrl;
       
   715         //Change the previous control first, then current control
       
   716         if(previous)
       
   717             previous->SetActive(EFalse);
       
   718 
       
   719         iActiveCtrl->SetActive(ETrue);
       
   720         }        
       
   721     return iActiveCtrl;
       
   722     }
       
   723     
       
   724 // -----------------------------------------------------------------------------
       
   725 // CControlGroup::SetActiveCtrl
       
   726 // Set active control
       
   727 // (other items were commented in a header).
       
   728 // -----------------------------------------------------------------------------
       
   729 //    
       
   730 EXPORT_C CFepUiBaseCtrl* CControlGroup::SetActiveCtrl(TInt aIndex)
       
   731     {
       
   732     if(aIndex < 0 || aIndex >= iCtrlList.Count())
       
   733         return NULL;
       
   734     return SetActiveCtrl(iCtrlList[aIndex]);        
       
   735     }
       
   736   
       
   737 // -----------------------------------------------------------------------------
       
   738 // CControlGroup::ActiveControl
       
   739 // Get active control
       
   740 // (other items were commented in a header).
       
   741 // -----------------------------------------------------------------------------
       
   742 //    
       
   743 EXPORT_C CFepUiBaseCtrl* CControlGroup::ActiveControl()
       
   744     {
       
   745         return iActiveCtrl;
       
   746     }
       
   747 
       
   748 // -----------------------------------------------------------------------------
       
   749 // CControlGroup::NumOfControlss
       
   750 // get control numbers
       
   751 // (other items were commented in a header).
       
   752 // -----------------------------------------------------------------------------
       
   753 //    
       
   754 EXPORT_C TInt CControlGroup::NumOfControls()
       
   755     {
       
   756     return iCtrlList.Count();
       
   757     }
       
   758     
       
   759 
       
   760 // -----------------------------------------------------------------------------
       
   761 // CControlGroup::HideControl
       
   762 // Hide control
       
   763 // (other items were commented in a header).
       
   764 // -----------------------------------------------------------------------------
       
   765 //       
       
   766 EXPORT_C void CControlGroup::HideControl(TInt aIndex,TBool aFlag)
       
   767     {
       
   768     if(aIndex >=0 && aIndex < iCtrlList.Count())
       
   769         {
       
   770         HideControl(iCtrlList[aIndex],aFlag);
       
   771         }
       
   772     }
       
   773     
       
   774 // -----------------------------------------------------------------------------
       
   775 // CControlGroup::HideControl
       
   776 // Hide control
       
   777 // (other items were commented in a header).
       
   778 // -----------------------------------------------------------------------------
       
   779 //           
       
   780 EXPORT_C void CControlGroup::HideControl(CFepUiBaseCtrl* aControl,TBool aFlag)
       
   781     {
       
   782     if(!aControl  || aControl->Hiden() == aFlag)    
       
   783         return;
       
   784     
       
   785     aControl->Hide(aFlag);
       
   786 
       
   787     //recalculate the control group rect
       
   788     if(aFlag) //hide
       
   789         {        
       
   790         iRect.SetRect(0,0,0,0);
       
   791         for(TInt j = 0; j < iCtrlList.Count(); j++)
       
   792             {
       
   793             if(aControl != iCtrlList[j] && ! iCtrlList[j]->Hiden())
       
   794                 {
       
   795                 if(iRect.IsEmpty())
       
   796                     {
       
   797                     iRect = iCtrlList[j]->Rect();
       
   798                     }
       
   799                 else
       
   800                     {
       
   801                     iRect.BoundingRect(iCtrlList[j]->Rect());
       
   802                     }
       
   803                 }
       
   804             }
       
   805         }
       
   806     else	//show
       
   807         {
       
   808         if(iRect.IsEmpty())
       
   809             {
       
   810             iRect = aControl->Rect();
       
   811             }
       
   812         else 
       
   813             {                                   
       
   814             iRect.BoundingRect(aControl->Rect());
       
   815             }
       
   816         }
       
   817 
       
   818     UpdateValidRegion(aControl,ETrue);
       
   819         
       
   820     /*
       
   821     SetRect(rect);
       
   822     RRegion region(8);
       
   823     region.Copy(Region());   
       
   824 
       
   825     if(aFlag) //hide control
       
   826         region.SubRect(aControl->Rect());
       
   827     else
       
   828         region.AddRect(aControl->Rect());
       
   829     SetRegion(region);
       
   830     RootControl()->UpdateValidRegion(NULL,EFalse);
       
   831     */
       
   832     }
       
   833 
       
   834 
       
   835 // -----------------------------------------------------------------------------
       
   836 // CControlGroup::Hide
       
   837 // Hide the control group and all it's controls
       
   838 // (other items were commented in a header).
       
   839 // -----------------------------------------------------------------------------
       
   840 //    
       
   841 EXPORT_C void CControlGroup::Hide(TBool aFlag)
       
   842     {
       
   843     if(Hiden() == aFlag)
       
   844         return;
       
   845   /*  if(aFlag) //hide
       
   846         {
       
   847         SaveSubCtrlShownState();
       
   848         }*/
       
   849     DisableRegionUpdating(); //disable updating caused by sub controls           
       
   850     /*for (TInt i = 0; i < iCtrlList.Count(); ++i)
       
   851         {
       
   852         CFepUiBaseCtrl* ctrl = iCtrlList[i];
       
   853         TBool hideFlag = aFlag;
       
   854         if( i < iSubCtrlShowStateBeforeHiden.Count() && 
       
   855                     iSubCtrlShowStateBeforeHiden[i].iSubCtrl == ctrl)
       
   856             {            
       
   857             hideFlag = hideFlag || iSubCtrlShowStateBeforeHiden[i].iHiden;
       
   858             }
       
   859         ctrl->Hide(hideFlag); //loop sub controls        
       
   860         }*/
       
   861     EnableRegionUpdating();            
       
   862     CFepUiBaseCtrl::Hide(aFlag); //hide myself               
       
   863     /*if(!aFlag)
       
   864         iSubCtrlShowStateBeforeHiden.Reset();
       
   865 */
       
   866         }
       
   867 
       
   868 // -----------------------------------------------------------------------------
       
   869 // CControlGroup::Move
       
   870 // Move control and component's rect
       
   871 // (other items were commented in a header).
       
   872 // -----------------------------------------------------------------------------
       
   873 //        
       
   874 EXPORT_C void CControlGroup::Move(const TPoint& aOffset)
       
   875     {
       
   876     //disable region update and re-calculate it after all sub-control moved.
       
   877     DisableRegionUpdating();    
       
   878     CFepUiBaseCtrl::Move(aOffset);
       
   879     //move components
       
   880     for(TInt j = 0; j < iCtrlList.Count(); j++)
       
   881         {
       
   882         iCtrlList[j]->Move(aOffset);
       
   883         }    
       
   884     EnableRegionUpdating();
       
   885     UpdateValidRegion(NULL,ETrue); //recalculate valid region
       
   886     }
       
   887     
       
   888 // -----------------------------------------------------------------------------
       
   889 // CControlGroup::ControlById
       
   890 // Get the sub control for given control Id. 
       
   891 // (other items were commented in a header).
       
   892 // -----------------------------------------------------------------------------
       
   893 //            
       
   894 EXPORT_C CFepUiBaseCtrl* CControlGroup::ControlById(TInt aCtrlId)
       
   895     {
       
   896     CFepUiBaseCtrl* ctrl = NULL;
       
   897     
       
   898     for(TInt i = 0; i < iCtrlList.Count(); i++)
       
   899         {
       
   900         ctrl = iCtrlList[i];
       
   901         if(ctrl->ControlId() == aCtrlId)
       
   902             {
       
   903                 return ctrl;
       
   904             }
       
   905         else
       
   906             {
       
   907             if(ctrl->IsKindOfControl(ECtrlControlGroup))
       
   908                 {
       
   909                 CFepUiBaseCtrl* subCtrl = static_cast<CControlGroup*>(ctrl)->
       
   910                                             ControlById(aCtrlId);
       
   911                 if(subCtrl)
       
   912                     return subCtrl; 
       
   913                 }
       
   914             }
       
   915         }
       
   916 
       
   917     return NULL;
       
   918     
       
   919     }
       
   920     
       
   921 // ---------------------------------------------------------------------------
       
   922 // CControlGroup::CancelPointerDownL
       
   923 // Cancel pointer down event
       
   924 // (other items were commented in a header).
       
   925 // ---------------------------------------------------------------------------
       
   926 //    
       
   927 EXPORT_C void CControlGroup::CancelPointerDownL()
       
   928     {
       
   929     //let the pointer downed control do the canceling
       
   930     if(iCtrlWithPointerDown)
       
   931         {
       
   932         if (iCtrlWithPointerDown != iActiveCtrl)
       
   933         	{
       
   934 			iCtrlWithPointerDown->SetActive(EFalse);
       
   935 			if (iActiveCtrl)
       
   936 				{
       
   937 				iActiveCtrl->SetActive(ETrue);        		
       
   938 				}
       
   939         	}
       
   940         iCtrlWithPointerDown->CancelPointerDownL();
       
   941         iCtrlWithPointerDown = NULL;
       
   942         ReportEvent(EEventButtonDownCanceled);
       
   943         }    
       
   944     }
       
   945 
       
   946 // ---------------------------------------------------------------------------
       
   947 // CControlGroup::HandlePointerLeave
       
   948 // Handle pointer leave event
       
   949 // ---------------------------------------------------------------------------
       
   950 //           
       
   951 EXPORT_C void CControlGroup::HandlePointerLeave(const TPoint& aPt)
       
   952     {
       
   953     SetPointerDown( EFalse );
       
   954     iPointerLeft = ETrue;
       
   955 
       
   956     if(iCtrlWithPointerDown)
       
   957         {
       
   958         if(iCtrlWithPointerDown != iActiveCtrl)
       
   959             {
       
   960             SetTempActiveCtrl(iActiveCtrl);
       
   961             }
       
   962         iCtrlWithPointerDown->HandlePointerLeave(aPt);        
       
   963         }
       
   964     }
       
   965     
       
   966 // ---------------------------------------------------------------------------
       
   967 // CControlGroup::HandlePointerEnter
       
   968 // Handle pointer enter event
       
   969 // ---------------------------------------------------------------------------
       
   970 //           
       
   971 EXPORT_C void CControlGroup::HandlePointerEnter(const TPoint& aPt)
       
   972     {
       
   973     SetPointerDown( ETrue );
       
   974     iPointerLeft = EFalse;
       
   975     if(iCtrlWithPointerDown)
       
   976         {
       
   977         //does the pointer really enter this control?
       
   978         if(iCtrlWithPointerDown->Contains(aPt))
       
   979             {
       
   980             SetTempActiveCtrl(iCtrlWithPointerDown);
       
   981             iCtrlWithPointerDown->HandlePointerEnter(aPt);        
       
   982             }
       
   983         }
       
   984     }
       
   985 
       
   986 // ---------------------------------------------------------------------------
       
   987 // CControlGroup::ControlByType
       
   988 // Get a control by type and index
       
   989 // ---------------------------------------------------------------------------
       
   990 //
       
   991 EXPORT_C CFepUiBaseCtrl* CControlGroup::ControlByType(TControlType aType,TInt aIndex)
       
   992     {
       
   993     if(aIndex < 0)
       
   994         return NULL;
       
   995     
       
   996     CFepUiBaseCtrl* ctrl = NULL;
       
   997     TInt ctrlIdx = 0;
       
   998     for(TInt i = 0;i < iCtrlList.Count();i++)
       
   999         {
       
  1000         if(iCtrlList[i]->ControlType() == aType)
       
  1001             {
       
  1002             if(ctrlIdx == aIndex)
       
  1003                 return iCtrlList[i];
       
  1004             else
       
  1005                 ctrlIdx++;
       
  1006             }
       
  1007         else
       
  1008             {
       
  1009             //If sub control is a control group, loop inside the control group
       
  1010             if(iCtrlList[i]->IsKindOfControl(ECtrlControlGroup))
       
  1011                 {
       
  1012                 CControlGroup* ctrlGroup = static_cast<CControlGroup*>(iCtrlList[i]);
       
  1013                 ctrl = ctrlGroup->ControlByType(aType,aIndex - ctrlIdx);
       
  1014                 if(ctrl)
       
  1015                     return ctrl;
       
  1016                 }
       
  1017             }
       
  1018         }
       
  1019 
       
  1020     return ctrl;
       
  1021     }
       
  1022 
       
  1023 // ---------------------------------------------------------------------------
       
  1024 // CControlGroup::ControlHasType
       
  1025 // Get a control by type and index
       
  1026 // ---------------------------------------------------------------------------
       
  1027 //
       
  1028 EXPORT_C CFepUiBaseCtrl* CControlGroup::ControlForKindOfType(
       
  1029                                         TStockBaseCtrlType aType,TInt aIndex)
       
  1030     {
       
  1031     
       
  1032     if(aIndex < 0 || aIndex >= iCtrlList.Count())
       
  1033         return NULL;
       
  1034     
       
  1035     CFepUiBaseCtrl* ctrl = NULL;
       
  1036     TInt ctrlIdx = 0;
       
  1037     for(TInt i = 0;i < iCtrlList.Count();i++)
       
  1038         {
       
  1039         if(iCtrlList[i]->IsKindOfControl(aType))
       
  1040             {
       
  1041             if(ctrlIdx == aIndex)
       
  1042                 return iCtrlList[i];
       
  1043             else
       
  1044                 ctrlIdx++;
       
  1045             }
       
  1046         else
       
  1047             {
       
  1048             //If sub control is a control group, loop inside the control group
       
  1049             if(iCtrlList[i]->IsKindOfControl(ECtrlControlGroup))
       
  1050                 {
       
  1051                 CControlGroup* ctrlGroup = static_cast<CControlGroup*>(iCtrlList[i]);
       
  1052                 ctrl = ctrlGroup->ControlForKindOfType(aType,aIndex - ctrlIdx);
       
  1053                 if(ctrl)
       
  1054                     return ctrl;
       
  1055                 }
       
  1056             }
       
  1057         }
       
  1058 
       
  1059     return ctrl;
       
  1060     }
       
  1061 
       
  1062 
       
  1063 // ---------------------------------------------------------------------------
       
  1064 // CControlGroup::OnDeActivate
       
  1065 // Response to layout de activation event
       
  1066 // (other items were commented in a header).
       
  1067 // ---------------------------------------------------------------------------
       
  1068 //     
       
  1069 EXPORT_C void CControlGroup::OnDeActivate()
       
  1070     {
       
  1071     TRAP_IGNORE(OnDeActivateL());
       
  1072     }
       
  1073 
       
  1074 void CControlGroup::OnDeActivateL()
       
  1075     {
       
  1076     if(iCtrlWithPointerDown)
       
  1077         {
       
  1078         TRAP_IGNORE(iCtrlWithPointerDown->CancelPointerDownL());
       
  1079         iCtrlWithPointerDown = NULL;
       
  1080         }
       
  1081     CFepUiBaseCtrl::OnDeActivate();
       
  1082     for(TInt i = 0;i < iCtrlList.Count();i++)
       
  1083         {
       
  1084         CFepUiBaseCtrl* ctrl = iCtrlList[i];
       
  1085         
       
  1086         __ASSERT_DEBUG(ctrl,User::Leave(-1));    
       
  1087         
       
  1088         iCtrlList[i]->OnDeActivate();
       
  1089         }
       
  1090     }
       
  1091 
       
  1092 // ---------------------------------------------------------------------------
       
  1093 // CControlGroup::OnDctivate
       
  1094 // Response to layout activation event
       
  1095 // (other items were commented in a header).
       
  1096 // ---------------------------------------------------------------------------
       
  1097 //     
       
  1098 EXPORT_C void CControlGroup::OnActivate()
       
  1099     {
       
  1100     CFepUiBaseCtrl::OnActivate();
       
  1101     for(TInt i = 0;i < iCtrlList.Count();i++)
       
  1102         {
       
  1103         iCtrlList[i]->OnActivate();
       
  1104         }
       
  1105     }
       
  1106 
       
  1107 // ---------------------------------------------------------------------------
       
  1108 // CControlGroup::OnLayoutDraggingStart
       
  1109 // Response to layout dragging start event
       
  1110 // (other items were commented in a header).
       
  1111 // ---------------------------------------------------------------------------
       
  1112 //     
       
  1113 EXPORT_C void CControlGroup::OnLayoutDraggingStart()
       
  1114     {
       
  1115     //notify child controls
       
  1116     for(TInt i = 0; i < iCtrlList.Count(); i++)
       
  1117         {
       
  1118         iCtrlList[i]->OnLayoutDraggingStart();
       
  1119         }
       
  1120     }
       
  1121     
       
  1122 // ---------------------------------------------------------------------------
       
  1123 // CControlGroup::OnLayoutDraggingEnd
       
  1124 // Response to layout dragging end event
       
  1125 // (other items were commented in a header).
       
  1126 // ---------------------------------------------------------------------------
       
  1127 //     
       
  1128 EXPORT_C void CControlGroup::OnLayoutDraggingEnd()
       
  1129     {
       
  1130     //notify child controls    
       
  1131     for(TInt i = 0; i < iCtrlList.Count(); i++)
       
  1132         {
       
  1133         iCtrlList[i]->OnLayoutDraggingEnd();
       
  1134         }    
       
  1135     }    
       
  1136 
       
  1137 // ---------------------------------------------------------------------------
       
  1138 // CControlGroup::ConstructFromResourceL
       
  1139 // Handle resource change
       
  1140 // (other items were commented in a header).
       
  1141 // ---------------------------------------------------------------------------
       
  1142 //     
       
  1143 EXPORT_C void CControlGroup::ConstructFromResourceL()
       
  1144     {
       
  1145     //let child control hanlde resource change.
       
  1146     for(TInt i = 0; i < iCtrlList.Count(); i++)
       
  1147         {
       
  1148         iCtrlList[i]->ConstructFromResourceL();
       
  1149         }    
       
  1150     }
       
  1151     
       
  1152 const RRegion& CControlGroup::CalculateNonHwrStartPtArea()
       
  1153     {
       
  1154     RRegion r;
       
  1155     iNonHwrStartPtRegion.Clear();
       
  1156     for(TInt i = 0; i < iCtrlList.Count(); ++i)
       
  1157         {						 
       
  1158         CFepUiBaseCtrl* ctrl = iCtrlList[i];
       
  1159         if(ctrl->Hiden() || !ctrl->Ready())
       
  1160             continue;
       
  1161         if(ctrl->IsKindOfControl(ECtrlControlGroup))
       
  1162             {
       
  1163             iNonHwrStartPtRegion.Union(static_cast<CControlGroup*>(ctrl)->
       
  1164                             CalculateNonHwrStartPtArea());
       
  1165             continue;
       
  1166             }
       
  1167         if(ctrl->IsKindOfControl(ECtrlTransparentHwrWnd))
       
  1168             {            
       
  1169             r.Copy(ctrl->Region());
       
  1170             continue;		          
       
  1171             }
       
  1172         
       
  1173         iNonHwrStartPtRegion.AddRect(ctrl->Rect());
       
  1174         }
       
  1175     r.Sort();
       
  1176     
       
  1177     RRegion r2;
       
  1178     r2.AddRect(UiLayout()->Rect());
       
  1179     r2.SubRegion(iNonHwrStartPtRegion);
       
  1180     r2.Sort();
       
  1181     r2.Close();
       
  1182     r.Close();
       
  1183     return iNonHwrStartPtRegion;    
       
  1184     }    
       
  1185     
       
  1186 // ---------------------------------------------------------------------------
       
  1187 // CControlGroup::UpdateValidRegion
       
  1188 // Update control's valid region when other control show or hide.
       
  1189 // (other items were commented in a header).
       
  1190 // ---------------------------------------------------------------------------
       
  1191 //
       
  1192 EXPORT_C void CControlGroup::UpdateValidRegion(CFepUiBaseCtrl* aCtrl,TBool aRemoveFlag)
       
  1193     {
       
  1194     if(!iUpdateFlagEnabled) //do nothing if disabled.
       
  1195         return;
       
  1196     
       
  1197     if(aCtrl) //update due to this control
       
  1198         {        
       
  1199         TInt idx = FindSubRegion(aCtrl);
       
  1200         if(aRemoveFlag)
       
  1201             {
       
  1202             if(idx == KErrNotFound)
       
  1203                 return;
       
  1204             RemoveSubRegion(idx);            
       
  1205             
       
  1206             delete iSubRegionArea[idx];
       
  1207             iSubRegionArea.Remove(idx);        
       
  1208             CalculateClipRegion();        
       
  1209             }
       
  1210         else
       
  1211             {
       
  1212             if(idx == KErrNotFound) //new one
       
  1213                 {            
       
  1214                 //no need to check whether the control is hide as updating is done when 
       
  1215                 //control is hiden.
       
  1216                 //CSubRegionArea area(aCtrl,aCtrl->Region());
       
  1217                 //iSubRegionArea.Append(area);
       
  1218                 TRAP_IGNORE(AddSubRegionL(aCtrl));
       
  1219                 CalculateClipRegion(aCtrl);
       
  1220                 }
       
  1221             else //replace the old one   
       
  1222                 {            
       
  1223                 RemoveSubRegion(idx);                                            
       
  1224                 iSubRegionArea[idx]->iSubRegion.Copy(aCtrl->Region());
       
  1225                 CalculateClipRegion();
       
  1226                 }
       
  1227             iValidRegion.Union(aCtrl->Region());                
       
  1228             }   
       
  1229         }
       
  1230     else //recalculate valid region
       
  1231         {
       
  1232         iSubRegionArea.ResetAndDestroy();
       
  1233         iValidRegion.Clear();
       
  1234         for(TInt i = 0 ; i < iCtrlList.Count(); ++i)
       
  1235             {		
       
  1236             iValidRegion.Union(iCtrlList[i]->Region()); 
       
  1237             //CSubRegionArea area(aCtrl,aCtrl->Region());
       
  1238             //iSubRegionArea.Append(area);
       
  1239             TRAP_IGNORE(AddSubRegionL(iCtrlList[i]));
       
  1240             }
       
  1241             
       
  1242         CalculateClipRegion();
       
  1243         }
       
  1244         
       
  1245     if(iParentCtrl)
       
  1246         iParentCtrl->UpdateValidRegion(this,EFalse);    
       
  1247     }
       
  1248 
       
  1249 TInt CControlGroup::FindSubRegion(CFepUiBaseCtrl* aCtrl)
       
  1250     {
       
  1251     for(TInt i = 0; i < iSubRegionArea.Count(); ++i)
       
  1252         {
       
  1253         if(aCtrl == iSubRegionArea[i]->iSubCtrl)
       
  1254             return i;
       
  1255         }
       
  1256         
       
  1257     return KErrNotFound;
       
  1258     }
       
  1259 
       
  1260 void CControlGroup::RemoveCtrlFromSubCtrlInfoList(CFepUiBaseCtrl* aControl)
       
  1261     {
       
  1262     for(TInt i = 0 ; i < iSubCtrlShowStateBeforeHiden.Count(); ++i)
       
  1263         {
       
  1264         if(iSubCtrlShowStateBeforeHiden[i].iSubCtrl == aControl)
       
  1265             {
       
  1266             iSubCtrlShowStateBeforeHiden.Remove(i);
       
  1267             break;
       
  1268             }
       
  1269         }
       
  1270     }
       
  1271 
       
  1272 //record each sub control's current hide/show state
       
  1273 void CControlGroup::SaveSubCtrlShownState()
       
  1274     {   
       
  1275     iSubCtrlShowStateBeforeHiden.Reset(); 
       
  1276     for (TInt i = 0; i < iCtrlList.Count(); ++i)
       
  1277         {
       
  1278         TSubCtrlShownState state = {iCtrlList[i],iCtrlList[i]->Hiden()};
       
  1279             
       
  1280         TRAP_IGNORE(iSubCtrlShowStateBeforeHiden.AppendL(state));
       
  1281         }                
       
  1282     }
       
  1283 
       
  1284 void CControlGroup::AddSubRegionL(CFepUiBaseCtrl* aCtrl)
       
  1285     {
       
  1286     //no need to check aCtrl    
       
  1287     CSubRegionArea* area = new (ELeave) CSubRegionArea(aCtrl,aCtrl->Region());
       
  1288     CleanupStack::PushL(area);
       
  1289     iSubRegionArea.AppendL(area);
       
  1290     CleanupStack::Pop(area);    
       
  1291     }
       
  1292     
       
  1293 void CControlGroup::RemoveSubRegion(TInt aIdx)
       
  1294     {    
       
  1295     //check whether this region is clipped with other region
       
  1296     RRegion overlappedReg;    
       
  1297     for(TInt i = 0 ; i < iSubRegionArea.Count(); ++i)
       
  1298         {
       
  1299         if(i == aIdx)
       
  1300             continue;
       
  1301         
       
  1302         RRegion r;
       
  1303         r.Intersection(iSubRegionArea[aIdx]->iSubRegion,
       
  1304                                         iSubRegionArea[i]->iSubRegion);
       
  1305         overlappedReg.Union(r);
       
  1306         r.Close();           
       
  1307         }						   
       
  1308     iValidRegion.SubRegion(iSubRegionArea[aIdx]->iSubRegion);
       
  1309     iValidRegion.Union(overlappedReg);
       
  1310     overlappedReg.Close();
       
  1311     
       
  1312     }
       
  1313 
       
  1314 // -----------------------------------------------------------------------------
       
  1315 // CControlGroup::BringToTop
       
  1316 // Bring and show a control in current group
       
  1317 // (other items were commented in a header).
       
  1318 // -----------------------------------------------------------------------------
       
  1319 //     
       
  1320 TBool CControlGroup::MoveSubCtrlToTop(CFepUiBaseCtrl* aCtrl,RPointerArray<CFepUiBaseCtrl>& aList)
       
  1321     {
       
  1322     TInt index = aList.Find(aCtrl); 
       
  1323     if(KErrNotFound == index)
       
  1324         return EFalse;
       
  1325     //move the control to the end of the list
       
  1326     for(; index < aList.Count() -1; ++index)
       
  1327         {
       
  1328         aList[index] = aList[index + 1];
       
  1329         }
       
  1330     aList[index] = aCtrl;
       
  1331     return ETrue;    
       
  1332     }
       
  1333 
       
  1334 TBool CControlGroup::MoveSubCtrlToBack(CFepUiBaseCtrl* aCtrl,RPointerArray<CFepUiBaseCtrl>& aList)
       
  1335     {
       
  1336     TInt index = aList.Find(aCtrl); 
       
  1337     if(KErrNotFound == index)
       
  1338         return EFalse;
       
  1339     //move the control to the start of the list
       
  1340     for(; index > 0; --index)
       
  1341         {
       
  1342         //stop if found background control
       
  1343         if( iCtrlList[index-1]->IsKindOfControl(ECtrlBackgroundCtrl) ||
       
  1344             iCtrlList[index-1]->IsKindOfControl(ECtrlTransparentHwrWnd) )
       
  1345             {
       
  1346             break;
       
  1347             }
       
  1348         
       
  1349         aList[index] = aList[index -1];
       
  1350         }
       
  1351     aList[index] = aCtrl;
       
  1352     return ETrue;    
       
  1353     }
       
  1354 
       
  1355 EXPORT_C void CControlGroup::BringToTopInGroup(CFepUiBaseCtrl* aCtrl)
       
  1356     {
       
  1357     if(MoveSubCtrlToTop(aCtrl,iCtrlList)) //check in iCtrlList first
       
  1358         {
       
  1359         aCtrl->iClipRegion.Clear();
       
  1360         aCtrl->iClipRegion.AddRect(aCtrl->Rect());
       
  1361         UpdateValidRegion(aCtrl,EFalse);
       
  1362         //other control should update its valid/clip region    
       
  1363         }
       
  1364     }
       
  1365 
       
  1366 EXPORT_C void CControlGroup::BringToBackInGroup(CFepUiBaseCtrl* aCtrl)
       
  1367     {
       
  1368     if(MoveSubCtrlToBack(aCtrl,iCtrlList)) //check in iCtrlList first
       
  1369         {
       
  1370         aCtrl->iClipRegion.Clear();
       
  1371         aCtrl->iClipRegion.AddRect(aCtrl->Rect());
       
  1372         
       
  1373         UpdateValidRegion(aCtrl,EFalse);
       
  1374         //other control should update its valid/clip region    
       
  1375         }
       
  1376     }
       
  1377 
       
  1378 // -----------------------------------------------------------------------------
       
  1379 // CControlGroup::OnResourceChange
       
  1380 // Handle system resource change 
       
  1381 // (other items were commented in a header).
       
  1382 // -----------------------------------------------------------------------------
       
  1383 //     
       
  1384 EXPORT_C void CControlGroup::HandleResourceChange(TInt aType)
       
  1385     {
       
  1386     //let child control handle the resource change
       
  1387     for(TInt i = 0 ; i < iCtrlList.Count(); ++i)
       
  1388         {
       
  1389         iCtrlList[i]->HandleResourceChange(aType);
       
  1390         }
       
  1391     CFepUiBaseCtrl::HandleResourceChange(aType);
       
  1392     }
       
  1393 // -----------------------------------------------------------------------------
       
  1394 // CControlGroup::GraphicDeviceSizeChanged
       
  1395 // Handle graphic device size change event
       
  1396 // (other items were commented in a header).
       
  1397 // -----------------------------------------------------------------------------
       
  1398 //     
       
  1399 EXPORT_C void CControlGroup::GraphicDeviceSizeChanged()
       
  1400     {
       
  1401     //let child control handle the resource change
       
  1402     for(TInt i = 0 ; i < iCtrlList.Count(); ++i)
       
  1403         {
       
  1404         iCtrlList[i]->GraphicDeviceSizeChanged();
       
  1405         }
       
  1406     CFepUiBaseCtrl::GraphicDeviceSizeChanged();     
       
  1407     }
       
  1408 
       
  1409 
       
  1410 // ---------------------------------------------------------------------------
       
  1411 // CControlGroup::UpdateArea
       
  1412 // Update layout area
       
  1413 // (other items were commented in a header).
       
  1414 // ---------------------------------------------------------------------------
       
  1415 //       
       
  1416 void CControlGroup::UpdateAreaInGrp(CFepUiBaseCtrl* aControl,const TRect& aRect,TBool aUpdateFlag)
       
  1417     {
       
  1418     RedrawRectInGrp( aControl, aRect );
       
  1419     UpdateArea(aRect,aUpdateFlag);
       
  1420     }    
       
  1421     
       
  1422 //implementation for class CControlGroup::CSubRegionArea::CSubRegionArea
       
  1423 CControlGroup::CSubRegionArea::CSubRegionArea(const CFepUiBaseCtrl* aCtrl,const RRegion &aRegion)
       
  1424                                 : iSubCtrl(aCtrl) //,iSubRegion(aRegion) 
       
  1425     {
       
  1426     iSubRegion.Copy(aRegion);
       
  1427     //RRegion's copy constructor will make two region point to same data. !!!
       
  1428     }
       
  1429 CControlGroup::CSubRegionArea::~CSubRegionArea()
       
  1430     {
       
  1431     iSubRegion.Close();
       
  1432     }
       
  1433 
       
  1434 TInt CControlGroup::GetNestedLevel()    
       
  1435     {
       
  1436     TInt level = 1;
       
  1437     CFepUiBaseCtrl* parent = ParentCtrl();
       
  1438     if(!parent)
       
  1439         return 0; //This is the root control
       
  1440  
       
  1441     while(parent && parent != RootControl())
       
  1442         {
       
  1443         parent = ParentCtrl();
       
  1444         level++;
       
  1445         }
       
  1446     return level;
       
  1447     }
       
  1448 
       
  1449 
       
  1450 TInt CControlGroup::GetIdx(const CFepUiBaseCtrl* aCtrl)
       
  1451     {
       
  1452     for(TInt i = 0; i < iCtrlList.Count(); i++)
       
  1453         {
       
  1454         if(iCtrlList[i] == aCtrl)
       
  1455             {
       
  1456             return i;            
       
  1457             }
       
  1458         } 
       
  1459     return KErrNotFound;   
       
  1460     }
       
  1461 
       
  1462 // ---------------------------------------------------------------------------
       
  1463 // CControlGroup::DrawControlGroupBackground
       
  1464 // Draw ControlGroup Background
       
  1465 // (other items were commented in a header).
       
  1466 // ---------------------------------------------------------------------------
       
  1467 //  
       
  1468 EXPORT_C void CControlGroup::DrawControlGroupBackground( const TRect& aUpdateRegion )
       
  1469 	{
       
  1470 	DrawBackground( aUpdateRegion );
       
  1471 	}
       
  1472 	
       
  1473 void CControlGroup::AdjustBkCtrlPos()
       
  1474     {
       
  1475     //No need to check the first control
       
  1476     TInt firstBkCtrlPos = 1;
       
  1477     for(TInt i = 1 ; i < iCtrlList.Count(); ++i)
       
  1478         {
       
  1479         if(iCtrlList[i]->IsKindOfControl(ECtrlBackgroundCtrl)) 
       
  1480             {
       
  1481             //move to first
       
  1482             CFepUiBaseCtrl* ctrl = iCtrlList[firstBkCtrlPos];
       
  1483             iCtrlList[firstBkCtrlPos++] = iCtrlList[i];
       
  1484 
       
  1485             for(TInt j = i ; j < firstBkCtrlPos ; --j)
       
  1486                 {
       
  1487                 iCtrlList[j] = iCtrlList[j-1];
       
  1488                 }
       
  1489             iCtrlList[firstBkCtrlPos] = ctrl;
       
  1490             }
       
  1491         else
       
  1492             {
       
  1493             if(iCtrlList[i]->IsKindOfControl(ECtrlControlGroup))
       
  1494                 {
       
  1495                 CControlGroup* ctrlGroup = static_cast<CControlGroup*>(iCtrlList[i]);
       
  1496                 ctrlGroup->AdjustBkCtrlPos();
       
  1497                 }
       
  1498             }
       
  1499         }
       
  1500     } 	
       
  1501     
       
  1502 // ---------------------------------------------------------------------------
       
  1503 // CControlGroup::UpdateAreaInGrpImmed
       
  1504 // Update layout area
       
  1505 // (other items were commented in a header).
       
  1506 // ---------------------------------------------------------------------------
       
  1507 //  
       
  1508 void CControlGroup::UpdateAreaInGrpImmed(CFepUiBaseCtrl* aControl,const TRect& aRect,TBool aUpdateFlag)
       
  1509     {
       
  1510     RedrawRectInGrp( aControl, aRect );
       
  1511     UpdateAreaImmed(aRect,aUpdateFlag);
       
  1512     }    
       
  1513 
       
  1514 
       
  1515 // ---------------------------------------------------------------------------
       
  1516 // CControlGroup::RedrawRectInGrp
       
  1517 // Redraw rect
       
  1518 // (other items were commented in a header).
       
  1519 // ---------------------------------------------------------------------------
       
  1520 //    
       
  1521 void CControlGroup::RedrawRectInGrp( CFepUiBaseCtrl* aControl,const TRect& aRect )
       
  1522     {
       
  1523     //check in ctrl list
       
  1524     TInt idx = 0;
       
  1525     for(; idx < iCtrlList.Count(); ++idx)
       
  1526         {
       
  1527         if(aControl == iCtrlList[idx])
       
  1528             {
       
  1529             ++idx;
       
  1530             break;
       
  1531             }
       
  1532         }
       
  1533        
       
  1534     for(; idx < iCtrlList.Count(); ++idx)
       
  1535         {
       
  1536         if(aRect.Intersects(iCtrlList[idx]->Rect()) &&
       
  1537                                         !iCtrlList[idx]->Hiden())
       
  1538             {
       
  1539             iCtrlList[idx]->ReDrawRect(aRect);
       
  1540             }
       
  1541         }
       
  1542     //check the pop up list
       
  1543     for(idx = 0 ; idx < iPopCtrlList.Count(); ++idx)
       
  1544         {
       
  1545         if(aRect.Intersects(iPopCtrlList[idx]->Rect()) && 
       
  1546                                         !iPopCtrlList[idx]->Hiden())
       
  1547             {
       
  1548             if(aControl != iPopCtrlList[idx]) //not the same one
       
  1549                 iPopCtrlList[idx]->ReDrawRect(aRect);
       
  1550             }
       
  1551         }
       
  1552     }    
       
  1553 //end of file