widgetmodel/alfwidgetmodel/src/alfreferencetovisual.cpp
changeset 17 3eca7e70b1b8
parent 3 4526337fb576
equal deleted inserted replaced
3:4526337fb576 17:3eca7e70b1b8
     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:  Visual class for alfred widget model.
       
    15       This class queries the visual by name and ID.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 
       
    21 
       
    22 //INCLUDES
       
    23 
       
    24 #include "alf/alfreferencetovisual.h"
       
    25 #include <alf/alfwidgetcontrol.h>
       
    26 #include <alf/alfvisual.h>
       
    27 #include "alf/alfelement.h"
       
    28 #include <osn/ustring.h>
       
    29 #include <osn/osnnew.h>
       
    30 #include <alf/alfexceptions.h>
       
    31 
       
    32 //using namespace osncore;
       
    33 
       
    34 namespace Alf
       
    35     {
       
    36 ////////////////////// CAlfReferenceToVisual //////////////////////
       
    37 
       
    38 
       
    39 // ============================ MEMBER FUNCTIONS ===============================
       
    40 
       
    41 OSN_EXPORT AlfReferenceToVisual* AlfReferenceToVisual::create(
       
    42     const char *aElementName,
       
    43     const char *aVisualName,
       
    44     bool aUseDataID)
       
    45     {
       
    46     return new( EMM ) AlfReferenceToVisual( aElementName, aVisualName, aUseDataID );
       
    47     }
       
    48 
       
    49 // ---------------------------------------------------------------------------
       
    50 // Description : Constructor
       
    51 // ---------------------------------------------------------------------------
       
    52 //
       
    53 AlfReferenceToVisual::AlfReferenceToVisual(const char *aElementName,
       
    54         const char *aVisualName, bool aUseDataID)
       
    55     {
       
    56     mUseDataID = aUseDataID;
       
    57     mElementName = UString(aElementName);
       
    58     mVisualName = UString(aVisualName);
       
    59     }
       
    60 
       
    61 // ---------------------------------------------------------------------------
       
    62 // Description : Class Destructor
       
    63 // ---------------------------------------------------------------------------
       
    64 //
       
    65 OSN_EXPORT AlfReferenceToVisual::~AlfReferenceToVisual()
       
    66     {
       
    67 
       
    68     }
       
    69 
       
    70 // ---------------------------------------------------------------------------
       
    71 // Description :Find the referenced visual according to the given data ID.
       
    72 // ---------------------------------------------------------------------------
       
    73 //
       
    74 OSN_EXPORT CAlfVisual *AlfReferenceToVisual::resolve(CAlfWidgetControl &aControl, unsigned int aDataID)
       
    75     {
       
    76     // Find the element.
       
    77     CAlfVisual* visual = NULL;
       
    78     IAlfElement *element = aControl.findElement(mElementName.getUtf8());
       
    79     if (element)
       
    80         {
       
    81         unsigned int dataID = aDataID;
       
    82 
       
    83         // Find the visual.
       
    84         visual = element->findVisual(mVisualName.getUtf8(), dataID);
       
    85         if (!visual)
       
    86             {
       
    87             // maybe global visual.
       
    88             visual = element->findVisual(mVisualName.getUtf8(), 0);
       
    89             }
       
    90         }
       
    91     return visual;
       
    92     }
       
    93 
       
    94 // ---------------------------------------------------------------------------
       
    95 // Description :Finds the referenced visual according to the given pointer.
       
    96 // ---------------------------------------------------------------------------
       
    97 //
       
    98 OSN_EXPORT CAlfVisual *AlfReferenceToVisual::resolve(CAlfWidgetControl &aControl, CAlfVisual* aSourceVisual)
       
    99     {
       
   100     // Find the element.
       
   101     CAlfVisual* visual = NULL;
       
   102     //Get the element with the name stored herein
       
   103     IAlfElement *element = aControl.findElement(mElementName.getUtf8());
       
   104     if (element)
       
   105         {
       
   106         //is passed visual part of the element
       
   107         if (element->contains(*aSourceVisual))
       
   108             {
       
   109             HBufC8 *buf8 = NULL;
       
   110             TRAPD(error,buf8 = aSourceVisual->Tag().AllocL());
       
   111             if (error != KErrNone)
       
   112             	{
       
   113             	ALF_THROW(AlfVisualException,ECommonError,"AlfReferenceToVisual")
       
   114             	}
       
   115 
       
   116             UString sourceTag((const char*)buf8->Des().PtrZ());
       
   117             if (mVisualName.compare(sourceTag)==0) //Is this visual same as what was stored herein?
       
   118            		{
       
   119            		visual = aSourceVisual;
       
   120            		}
       
   121             delete buf8;
       
   122             }
       
   123         }
       
   124     return visual;
       
   125     }
       
   126 
       
   127     } // namespace Alf