widgetmodel/alfwidgetmodel/src/alfgridlayoutpolicyimpl.cpp
changeset 17 3eca7e70b1b8
parent 3 4526337fb576
equal deleted inserted replaced
3:4526337fb576 17:3eca7e70b1b8
     1 /*
       
     2 * Copyright (c) 2008 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:  layoutmanager implementation class with focus handling in 1D (next/previous)
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <alf/ialfwidgetcontrol.h>
       
    20 #include <alf/alfvisual.h>
       
    21 #include <alf/alfgridlayout.h>
       
    22 #include "alf/alfwidget.h"
       
    23 #include <alf/alfvisualfactory.h>
       
    24 #include <alf/alfexceptions.h>
       
    25 #include <alf/ialflayoutpreferences.h>
       
    26 #include <osn/osnnew.h>
       
    27 
       
    28 //stl
       
    29 #include <algorithm> //for min & max
       
    30 
       
    31 #include "alfgridlayoutpolicyimpl.h"
       
    32 
       
    33 using namespace Alf;
       
    34 
       
    35 namespace Alf
       
    36     {
       
    37 //ifdef to prevent compiler warning: className not used.
       
    38 #ifdef ALF_DEBUG_EXCEPTIONS
       
    39 static const char* const className = "AlfGridLayoutPolicyImpl";
       
    40 #endif
       
    41     
       
    42     
       
    43 // ======== MEMBER FUNCTIONS ========
       
    44     
       
    45 // ---------------------------------------------------------------------------
       
    46 // layoutmanagerimpl constructor
       
    47 // ---------------------------------------------------------------------------
       
    48 //    
       
    49 AlfGridLayoutPolicyImpl::AlfGridLayoutPolicyImpl(
       
    50     AlfGridLayoutManager& aGridLayoutManager) : 
       
    51     mGridLayoutManager(aGridLayoutManager)
       
    52     {
       
    53     }
       
    54     
       
    55 // ---------------------------------------------------------------------------
       
    56 // creates the layout used by the layoutmanager.
       
    57 // ---------------------------------------------------------------------------
       
    58 //    
       
    59 AlfGridLayoutPolicyImpl::~AlfGridLayoutPolicyImpl()
       
    60     {
       
    61     }
       
    62 
       
    63 // ---------------------------------------------------------------------------
       
    64 // from IAlfGridLayoutPolicy
       
    65 // Sets the number and weights of blocks in this grid layout in the direction of the specified
       
    66 // dimension. 
       
    67 // ---------------------------------------------------------------------------
       
    68 void AlfGridLayoutPolicyImpl::fillWeights(gridLayoutDimension aDim, int aCount, const TAlfMetric& aWeight)
       
    69     {
       
    70     CAlfGridLayout& gridLayout = layout();
       
    71     TAlfGridDimension dim = (TAlfGridDimension)aDim;
       
    72     TRAPD(err, gridLayout.FillWeightsL(dim, aCount, aWeight));
       
    73     if(err != KErrNone)
       
    74         {
       
    75         ALF_THROW(AlfVisualException, err, className);
       
    76         }
       
    77     }
       
    78 
       
    79 // ---------------------------------------------------------------------------
       
    80 // from IAlfGridLayoutPolicy
       
    81 // Add a new line of blocks to this grid layout at the last position in the direction of the 
       
    82 // specified dimension. 
       
    83 // ---------------------------------------------------------------------------
       
    84 void AlfGridLayoutPolicyImpl::appendWeight(gridLayoutDimension aDim, const TAlfMetric& aWeight)
       
    85     {
       
    86     CAlfGridLayout& gridLayout = layout();
       
    87     TAlfGridDimension dim = (TAlfGridDimension)aDim;
       
    88     TRAPD(err, gridLayout.AppendWeightL(dim, aWeight));
       
    89     if(err != KErrNone)
       
    90         {
       
    91         ALF_THROW(AlfVisualException, err, className);
       
    92         }
       
    93     }
       
    94 
       
    95 // ---------------------------------------------------------------------------
       
    96 // from IAlfGridLayoutPolicy
       
    97 // Add a new line of blocks to this grid layout at the specified position in the direciton of 
       
    98 // the specified dimension. 
       
    99 // ---------------------------------------------------------------------------
       
   100 void AlfGridLayoutPolicyImpl::insertWeight(gridLayoutDimension aDim, const TAlfMetric& aWeight, int aPos)
       
   101     {
       
   102     CAlfGridLayout& gridLayout = layout();
       
   103     TAlfGridDimension dim = (TAlfGridDimension)aDim;
       
   104     TRAPD(err, gridLayout.InsertWeightL(dim, aWeight, aPos));
       
   105     if(err != KErrNone)
       
   106         {
       
   107         ALF_THROW(AlfVisualException, err, className);
       
   108         }
       
   109     }
       
   110 
       
   111 // ---------------------------------------------------------------------------
       
   112 // from IAlfGridLayoutPolicy
       
   113 // Sets the weight of a specific line of blocks in this grid layout, in the direction of the supplied dimension.
       
   114 // ---------------------------------------------------------------------------
       
   115 void AlfGridLayoutPolicyImpl::replaceWeight(gridLayoutDimension aDim, const TAlfMetric& aWeight, int aPos)
       
   116     {
       
   117     CAlfGridLayout& gridLayout = layout();
       
   118     TAlfGridDimension dim = (TAlfGridDimension)aDim;
       
   119     TRAPD(err, gridLayout.ReplaceWeightL(dim, aWeight, aPos));
       
   120     if(err != KErrNone)
       
   121         {
       
   122         ALF_THROW(AlfVisualException, err, className);
       
   123         }
       
   124     }
       
   125 
       
   126 // ---------------------------------------------------------------------------
       
   127 // from IAlfGridLayoutPolicy
       
   128 // Remove a line of blocks from this grid layout at the specified position in the 
       
   129 // specified dimension. 
       
   130 // ---------------------------------------------------------------------------
       
   131 void AlfGridLayoutPolicyImpl::removeWeight(gridLayoutDimension aDim, int aPos)
       
   132     {
       
   133     CAlfGridLayout& gridLayout = layout();
       
   134     TAlfGridDimension dim = (TAlfGridDimension)aDim;
       
   135     TRAPD(err, gridLayout.RemoveWeightL(dim, aPos));
       
   136     if(err != KErrNone)
       
   137         {
       
   138         ALF_THROW(AlfVisualException, err, className);
       
   139         }
       
   140     }
       
   141 
       
   142 
       
   143 // ---------------------------------------------------------------------------
       
   144 // from IAlfGridLayoutPolicy
       
   145 // Returns the weight of a specific line of blocks in this grid layout, in the
       
   146 // specified dimension. 
       
   147 // ---------------------------------------------------------------------------
       
   148 TAlfMetric AlfGridLayoutPolicyImpl::weight(gridLayoutDimension aDim, int aPos) const
       
   149     {
       
   150     CAlfGridLayout& gridLayout = layout();
       
   151     TAlfGridDimension dim = (TAlfGridDimension)aDim;
       
   152     TAlfMetric result;
       
   153     TRAPD(err, result = gridLayout.Weight(dim, aPos));
       
   154     if(err != KErrNone)
       
   155         {
       
   156         ALF_THROW(AlfVisualException, err, className);
       
   157         }
       
   158     return result;
       
   159     }
       
   160 
       
   161     
       
   162 // ---------------------------------------------------------------------------
       
   163 // from IAlfGridLayoutPolicy
       
   164 // Return the number of lines of blocks in this grid, along the specified dimension
       
   165 // ---------------------------------------------------------------------------
       
   166 int AlfGridLayoutPolicyImpl::count(gridLayoutDimension aDim) const
       
   167     {
       
   168     CAlfGridLayout& gridLayout = layout();
       
   169     TAlfGridDimension dim = (TAlfGridDimension)aDim;
       
   170     int result(0);
       
   171     TRAPD(err, result = gridLayout.DimensionCount(dim));
       
   172     if(err != KErrNone)
       
   173         {
       
   174         ALF_THROW(AlfVisualException, err, className);
       
   175         }
       
   176     return result;
       
   177     }
       
   178 
       
   179 
       
   180 
       
   181 // ---------------------------------------------------------------------------
       
   182 // From class IAlfInterfaceBase.
       
   183 // Getter for interfaces provided by the element.
       
   184 // ---------------------------------------------------------------------------
       
   185 //
       
   186 IAlfInterfaceBase* AlfGridLayoutPolicyImpl::makeInterface(const IfId& aType)
       
   187     {
       
   188     UString param(aType.mImplementationId);
       
   189     if (param == IAlfGridLayoutPolicy::type().mImplementationId)
       
   190         {
       
   191         return this;
       
   192         }      
       
   193     
       
   194     return NULL;
       
   195     }
       
   196     
       
   197 // ---------------------------------------------------------------------------
       
   198 // returns the gridlayout used by the layoutmanager
       
   199 // ---------------------------------------------------------------------------
       
   200 //
       
   201 CAlfGridLayout& AlfGridLayoutPolicyImpl::layout() const
       
   202     {
       
   203     return dynamic_cast<CAlfGridLayout&>(mGridLayoutManager.getLayout());
       
   204     }
       
   205 
       
   206  } // Alf