uiacceltk/hitchcock/coretoolkit/src/HuiFlowLayout.cpp
changeset 0 15bf7259bb7c
equal deleted inserted replaced
-1:000000000000 0:15bf7259bb7c
       
     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:   ?Description
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19  
       
    20 #include <AknUtils.h>
       
    21 
       
    22 #include "uiacceltk/HuiFlowLayout.h"  // Class definition
       
    23 #include "uiacceltk/HuiControl.h"
       
    24 
       
    25 
       
    26 EXPORT_C CHuiFlowLayout* CHuiFlowLayout::AddNewL(CHuiControl& aOwnerControl, 
       
    27                                                  TFlowDirection aDirection,
       
    28                                                  CHuiLayout* aParentLayout)
       
    29     {
       
    30     CHuiFlowLayout* flow = STATIC_CAST(CHuiFlowLayout*,
       
    31         aOwnerControl.AppendLayoutL(EHuiLayoutTypeFlow, aParentLayout));
       
    32     flow->SetFlowDirection(aDirection);       
       
    33     return flow;
       
    34     }
       
    35 
       
    36 
       
    37 CHuiFlowLayout::CHuiFlowLayout(MHuiVisualOwner& aOwner)
       
    38         : CHuiLayout(aOwner), iMode(EFlowHorizontal)
       
    39     {
       
    40     }
       
    41 
       
    42 
       
    43 void CHuiFlowLayout::ConstructL()
       
    44     {    
       
    45     CHuiLayout::ConstructL();
       
    46     }
       
    47 
       
    48 	
       
    49 EXPORT_C CHuiFlowLayout::~CHuiFlowLayout()
       
    50     {    
       
    51     }
       
    52 
       
    53 
       
    54 EXPORT_C void CHuiFlowLayout::SetSize(const THuiRealSize& aSize, 
       
    55                                       TInt aTransitionTime)
       
    56     {
       
    57     CHuiLayout::SetSize(aSize, aTransitionTime);
       
    58     UpdateChildrenLayout(aTransitionTime);    
       
    59     }
       
    60 
       
    61 
       
    62 EXPORT_C TBool CHuiFlowLayout::ChildSize(TInt aOrdinal, TSize& aSize)
       
    63     {    
       
    64     TBool result(EFalse);
       
    65     THuiRealRect rect;
       
    66     TInt childRectStatus(THuiLayoutChildRectUpdateNotNeeded);
       
    67     childRectStatus = ChildRect(aOrdinal, rect);
       
    68     if(childRectStatus != THuiLayoutChildRectNotImplemented)
       
    69         {
       
    70         result = (childRectStatus & THuiLayoutChildRectSizeUpdateNeeded);
       
    71         if(result)
       
    72             {
       
    73             THuiRealPoint size(rect.Width(), rect.Height());
       
    74             aSize = LocalPointInPixels(size).AsSize();
       
    75             }
       
    76         }
       
    77     return result;        
       
    78     }
       
    79     
       
    80     
       
    81 EXPORT_C TBool CHuiFlowLayout::ChildPos(TInt aOrdinal, TPoint& aPos)
       
    82     {
       
    83     TBool result(EFalse);
       
    84     THuiRealRect rect;
       
    85     TInt childRectStatus(THuiLayoutChildRectUpdateNotNeeded);
       
    86     childRectStatus = ChildRect(aOrdinal, rect);
       
    87     if(childRectStatus != THuiLayoutChildRectNotImplemented)
       
    88         {
       
    89         result = (childRectStatus & THuiLayoutChildRectPosUpdateNeeded);
       
    90         if(result)
       
    91             {
       
    92             aPos = LocalPointInPixels(rect.iTl);
       
    93             }
       
    94         }
       
    95     return result;   
       
    96     }
       
    97 
       
    98 EXPORT_C TInt CHuiFlowLayout::ChildRect(TInt aOrdinal, THuiRealRect& aRect)
       
    99     {    
       
   100     THuiRealPoint childTopLeft;    
       
   101     THuiRealSize childSize = Visual(aOrdinal).Size().RealTarget().AsSize();
       
   102     THuiRealSize parentSize = InnerSize();
       
   103     TReal32 horizDirection = 1.0;
       
   104     
       
   105     // By default, flow layout modifies only positions of the children
       
   106     TInt ret = THuiLayoutChildRectPosUpdateNeeded;
       
   107     
       
   108     // Adjust the child size if perpendicular fit is specified
       
   109     if(iMode & EModeFitPerpendicular)
       
   110         {
       
   111         // Expand the child's size to fit the layout rectangle along
       
   112         // the minor axis.        
       
   113         if(iDirection == EFlowVertical)
       
   114             {
       
   115             childSize.iWidth = parentSize.iWidth;
       
   116             }
       
   117         else
       
   118             {
       
   119             childSize.iHeight = parentSize.iHeight;
       
   120             }                                
       
   121         // Modify also the size of the child.        
       
   122         ret |= THuiLayoutChildRectSizeUpdateNeeded;
       
   123         }      
       
   124     
       
   125     // Center the child perpendicular to the flow direction
       
   126     if(iMode & EModeCenterPerpendicular)
       
   127         {
       
   128         if(iDirection == EFlowHorizontal)
       
   129             {            
       
   130             childTopLeft.iY = parentSize.iHeight/2 - childSize.iHeight/2;
       
   131             }
       
   132         else
       
   133             {
       
   134             childTopLeft.iX = parentSize.iWidth/2 - childSize.iWidth/2;
       
   135             }
       
   136         }
       
   137         
       
   138     // Apply parent padding
       
   139     THuiRealPoint topLeft = InnerTopLeft();
       
   140     childTopLeft += topLeft;
       
   141 
       
   142     // Iterate through previous children and add their width or height along with
       
   143     // inner padding to the position.
       
   144     THuiRealPoint innerPadding = InnerPaddingInBaseUnits();
       
   145     for(TInt i = 0; i < aOrdinal; ++i)
       
   146         {
       
   147         if(!(Visual(i).Flags() & EHuiVisualFlagManualPosition))
       
   148             {
       
   149             // Take child visual into calculations unless it is manually positioned.
       
   150             THuiRealSize size = Visual(i).Size().RealTarget().AsSize();
       
   151             
       
   152             if(iDirection == EFlowHorizontal)
       
   153                 {
       
   154                 size.iWidth += innerPadding.iX;
       
   155                 childTopLeft.iX += horizDirection * size.iWidth;
       
   156                 }
       
   157             else
       
   158                 {
       
   159                 size.iHeight += innerPadding.iY;
       
   160                 childTopLeft.iY += size.iHeight;
       
   161                 }            
       
   162             }
       
   163         }      
       
   164     
       
   165     // Compose the final child rectangle    
       
   166     aRect = THuiRealRect(childTopLeft, childSize);
       
   167     
       
   168     // Return the bitmask of modified components
       
   169     return ret;
       
   170     }
       
   171 
       
   172 
       
   173 EXPORT_C void CHuiFlowLayout::SetFlowDirection(TFlowDirection aDirection)
       
   174     {
       
   175     if(iDirection != aDirection)
       
   176         {
       
   177         iDirection = aDirection;
       
   178         SetChanged();        
       
   179         }
       
   180     }
       
   181 
       
   182 
       
   183 EXPORT_C void CHuiFlowLayout::SetCentering(TBool aCentering)
       
   184     {
       
   185     if(aCentering)
       
   186         {
       
   187         iMode |= EModeCenterPerpendicular;
       
   188         }
       
   189     else
       
   190         {
       
   191         iMode &= ~EModeCenterPerpendicular;
       
   192         }
       
   193     SetChanged();        
       
   194     }
       
   195 
       
   196 
       
   197 EXPORT_C void CHuiFlowLayout::SetMode(TInt aMode)
       
   198     {
       
   199     iMode = aMode;
       
   200     SetChanged();
       
   201     }
       
   202 
       
   203 
       
   204 EXPORT_C TInt CHuiFlowLayout::Mode() const
       
   205     {
       
   206     return iMode;
       
   207     }