mulwidgets/alfcontainerwidget/src/alfcontainerwidget.cpp
changeset 0 e83bab7cf002
equal deleted inserted replaced
-1:000000000000 0:e83bab7cf002
       
     1 /*
       
     2 * Copyright (c) 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:  Widget interface with utilities for container widget.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "alfcontainerwidget.h"
       
    20 #include "alfcontainercontrol.h"
       
    21 #include "alfcontainerwidgetexception.h"
       
    22 #include <libc/stdio.h>
       
    23 #include <libc/string.h>
       
    24 #include "alf/alfwidget.h"
       
    25 #include <alf/alfenv.h>
       
    26 #include <alf/alfmetric.h>
       
    27 #include <alf/alfgridlayoutmanager.h>
       
    28 #include <alf/ialfgridlayoutpolicy.h>
       
    29 
       
    30 #include "alf/attrproperty.h"
       
    31 
       
    32 namespace Alf
       
    33 {
       
    34 
       
    35 AlfContainerWidget::AlfContainerWidget(
       
    36 	const char* aWidgetName, 
       
    37 	IAlfContainerWidget& aContainer, 
       
    38 	CAlfEnv& aEnv, 
       
    39 	DuiNode* /*aNode*/,
       
    40 	const char* /*aFilePath*/)
       
    41 	: mWidget(0), 
       
    42 	mEnv(aEnv)
       
    43     {
       
    44     mWidget.reset(new (EMM) AlfWidget(aWidgetName, aContainer, aEnv));
       
    45             
       
    46        
       
    47     
       
    48         constructDefault();
       
    49         setDefaultLayoutManager();
       
    50         
       
    51     }
       
    52 
       
    53 AlfContainerWidget::~AlfContainerWidget()
       
    54     {
       
    55     }
       
    56 
       
    57 CAlfWidgetControl* AlfContainerWidget::control() const
       
    58     {
       
    59     return mWidget->control();
       
    60     }
       
    61     
       
    62 IAlfContainerWidget* AlfContainerWidget::parent() const
       
    63     {
       
    64     return mWidget->parent();
       
    65     }
       
    66 
       
    67 void AlfContainerWidget::setControl(CAlfWidgetControl* aControl, bool aDeletePreviousControl)
       
    68     {
       
    69     mWidget->setControl(aControl, aDeletePreviousControl);
       
    70     }
       
    71 
       
    72 IAlfModel* AlfContainerWidget::model()
       
    73     {
       
    74     return 0;
       
    75     }
       
    76 
       
    77 void AlfContainerWidget::setModel(IAlfModel* /*aModel*/, bool /*aTakeOwnership*/)
       
    78     {
       
    79     
       
    80     }
       
    81 
       
    82 const char* AlfContainerWidget::widgetName() const
       
    83     {
       
    84     return mWidget->widgetName();
       
    85     }
       
    86 
       
    87 void AlfContainerWidget::setChildFocus(bool /*aFocus*/)
       
    88     {
       
    89     
       
    90     }
       
    91 
       
    92 
       
    93 //---------------------------------------------------------------------------
       
    94 // Creates the presentation for the widget from XML. Destroys any existing
       
    95 // presentation.
       
    96 //---------------------------------------------------------------------------
       
    97 //    
       
    98 void AlfContainerWidget::setPresentation (const char* aFilePath)
       
    99     {
       
   100     if(mWidget.get())
       
   101     	{
       
   102         mWidget->setPresentation(aFilePath);    	
       
   103     	}
       
   104     }    
       
   105 
       
   106 int AlfContainerWidget::widgetCount() const
       
   107     {
       
   108     return mWidget->widgetCount();
       
   109     }
       
   110 
       
   111 void AlfContainerWidget::addWidget(IAlfWidget& aWidget)
       
   112     {
       
   113     mWidget->addWidget(aWidget);
       
   114     }
       
   115 
       
   116 IAlfWidget* AlfContainerWidget::getWidget(int aIndex) const
       
   117     {
       
   118     return mWidget->getWidget(aIndex);
       
   119     }
       
   120     
       
   121 int AlfContainerWidget::getWidgetIndex(IAlfWidget& aWidget) const
       
   122     {
       
   123     return mWidget->getWidgetIndex(aWidget);
       
   124     }
       
   125 
       
   126 void AlfContainerWidget::removeWidget(int aIndex)
       
   127     {
       
   128     mWidget->removeWidget(aIndex);
       
   129     }
       
   130 
       
   131 void AlfContainerWidget::applyLayout(IAlfLayoutManager& aLayout)
       
   132     {
       
   133     mWidget->applyLayout(aLayout);
       
   134     }
       
   135 
       
   136 IAlfInterfaceBase* AlfContainerWidget::makeInterface(const IfId& aType)
       
   137     {    
       
   138     // Type cast to IAlfWidget
       
   139     if(!strcmp(aType.mImplementationId, IAlfWidget::type().mImplementationId))
       
   140         {
       
   141         return static_cast<IAlfWidget*>(this);
       
   142         }
       
   143         
       
   144     // Type cast to IAlfContainerWidget        
       
   145     if(!strcmp(aType.mImplementationId, IAlfContainerWidget::type().mImplementationId))
       
   146         {
       
   147         return static_cast<IAlfContainerWidget*>(this); 
       
   148         } 
       
   149     
       
   150     return mWidget->makeInterface ( aType );
       
   151     }
       
   152 
       
   153 // ---------------------------------------------------------------------------
       
   154 // ---------------------------------------------------------------------------
       
   155 //    
       
   156 void AlfContainerWidget::constructDefault()
       
   157     {
       
   158     // Create control for the container widget
       
   159     auto_ptr<AlfContainerControl> control(new (EMM) AlfContainerControl(mEnv));    
       
   160     setControl(control.get());
       
   161     control.release();
       
   162    
       
   163     }
       
   164 
       
   165 // ---------------------------------------------------------------------------
       
   166 // ---------------------------------------------------------------------------
       
   167 //   
       
   168 void AlfContainerWidget::setDefaultLayoutManager()
       
   169 	{
       
   170 	 // Default layout manager provided by the container widget
       
   171     auto_ptr<AlfGridLayoutManager> layoutManager(new (EMM) AlfGridLayoutManager());
       
   172     this->applyLayout(*layoutManager.get());
       
   173     AlfGridLayoutManager* lm = layoutManager.release();
       
   174     
       
   175     IAlfGridLayoutPolicy* gridPolicy = IAlfInterfaceBase::makeInterface<IAlfGridLayoutPolicy>(lm);
       
   176     gridPolicy->fillWeights(IAlfGridLayoutPolicy::EGridDimensionColumn, 1, TAlfMetric(1, EAlfUnitWeight));
       
   177     gridPolicy->fillWeights(IAlfGridLayoutPolicy::EGridDimensionRow, 1, TAlfMetric(1, EAlfUnitWeight));
       
   178 	}
       
   179 
       
   180 // ---------------------------------------------------------------------------
       
   181 // ---------------------------------------------------------------------------
       
   182 //   
       
   183 void AlfContainerWidget::constructComponentsFromNode()
       
   184 	{
       
   185 	constructDefault();
       
   186     
       
   187     //check, if the layoutmanager is already set.
       
   188     IAlfLayoutManager* layoutManager = IAlfInterfaceBase::makeInterface<IAlfLayoutManager>(control());
       
   189     if (!layoutManager)
       
   190         {
       
   191         setDefaultLayoutManager();
       
   192         }
       
   193 	}
       
   194 // ---------------------------------------------------------------------------
       
   195 // ---------------------------------------------------------------------------
       
   196 //  
       
   197 void AlfContainerWidget::processTreeRecursively()
       
   198     {
       
   199     }
       
   200 
       
   201 //---------------------------------------------------------------------------
       
   202 //---------------------------------------------------------------------------
       
   203 //    
       
   204 void AlfContainerWidget::constructFromPresentationXML(const char* /*aFilePath*/ )
       
   205     {
       
   206     constructDefault();
       
   207     setDefaultLayoutManager();      
       
   208     }
       
   209 }