xcfw/src/gecodefaultobjectfactory.cpp
changeset 0 79c6a41cd166
equal deleted inserted replaced
-1:000000000000 0:79c6a41cd166
       
     1 /*
       
     2 * Copyright (c) 2002-2005 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 of GECODefaultObjectFactory
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include    "gecodefaultobjectfactory.h"
       
    22 #include    "gecodefaultobject.h"
       
    23 
       
    24 // ============================ MEMBER FUNCTIONS ===============================
       
    25 
       
    26 // -----------------------------------------------------------------------------
       
    27 // CGECOObjectFactory::CGECOObjectFactory
       
    28 // C++ default constructor can NOT contain any code, that
       
    29 // might leave.
       
    30 // -----------------------------------------------------------------------------
       
    31 //
       
    32 EXPORT_C CGECODefaultObjectFactory::CGECODefaultObjectFactory()
       
    33     {
       
    34     }
       
    35 
       
    36     
       
    37 // Destructor
       
    38 EXPORT_C CGECODefaultObjectFactory::~CGECODefaultObjectFactory()
       
    39     {
       
    40     //Null context reference
       
    41     iContext = NULL;
       
    42     }
       
    43 
       
    44 
       
    45 // -----------------------------------------------------------------------------
       
    46 // CGECOObjectFactory::NewL
       
    47 // Two-phased constructor.
       
    48 // -----------------------------------------------------------------------------
       
    49 //
       
    50 EXPORT_C CGECODefaultObjectFactory* CGECODefaultObjectFactory::NewL()
       
    51     {
       
    52     CGECODefaultObjectFactory* self = new( ELeave ) CGECODefaultObjectFactory();
       
    53     
       
    54     CleanupStack::PushL( self );
       
    55     self->ConstructL();
       
    56     CleanupStack::Pop( self );
       
    57 
       
    58     return self;    
       
    59     }
       
    60 
       
    61 
       
    62 // -----------------------------------------------------------------------------
       
    63 // CGECOObjectFactory::ConstructL
       
    64 // -----------------------------------------------------------------------------
       
    65 //
       
    66 void CGECODefaultObjectFactory::ConstructL()
       
    67     {
       
    68     }
       
    69 
       
    70 
       
    71 // -----------------------------------------------------------------------------
       
    72 // CGECOObjectFactory::GetContentObjectAndSetContextL
       
    73 // Function instantiates a new default content object, sets context and
       
    74 // returns the object.
       
    75 // -----------------------------------------------------------------------------
       
    76 //
       
    77 EXPORT_C CGECOObjectBase* 
       
    78     CGECODefaultObjectFactory::GetContentObjectAndSetContextL(
       
    79     const TDesC& aIdentifier )
       
    80     {
       
    81     CGECODefaultObject* myObject = CGECODefaultObject::NewL( aIdentifier );
       
    82     iContext = myObject;
       
    83     return myObject;
       
    84     }
       
    85 
       
    86 
       
    87 
       
    88 // -----------------------------------------------------------------------------
       
    89 // CGECOObjectFactory::InitializeL
       
    90 // Base class implementation reads attributes to default object arrays.
       
    91 // -----------------------------------------------------------------------------
       
    92 //
       
    93 EXPORT_C void CGECODefaultObjectFactory::InitializeObjectL(
       
    94     MGECOAttributeProvider& aAttributeProvider )
       
    95     {
       
    96     if ( iContext )
       
    97         {
       
    98         //Cast context to GECODefaultObject
       
    99         CGECODefaultObject* temp = 
       
   100             reinterpret_cast<CGECODefaultObject*>( iContext );
       
   101 
       
   102         TInt counter = aAttributeProvider.NumAttributes() - 1;
       
   103         TPtrC name;
       
   104         TPtrC value;
       
   105         TBool islocalized = EFalse;
       
   106         while ( counter >= 0 )
       
   107             {
       
   108             aAttributeProvider.AttributeDetailsL( counter,name,value );
       
   109             temp->SetAttributeL( name, value, islocalized );
       
   110             counter--;            
       
   111             }
       
   112 
       
   113         if ( aAttributeProvider.HasTextData() )
       
   114             {
       
   115             aAttributeProvider.TextDetailsL( value, islocalized );
       
   116             temp->SetTextL( value, islocalized );
       
   117             }
       
   118 
       
   119         temp = NULL;
       
   120         }
       
   121 
       
   122     }
       
   123 
       
   124 
       
   125 // -----------------------------------------------------------------------------
       
   126 // CGECOObjectFactory::SetContext
       
   127 // Sets internal context pointer. Deriving class may return an error if 
       
   128 // it does not know the context by context's type identifier.
       
   129 // -----------------------------------------------------------------------------
       
   130 //
       
   131 EXPORT_C TInt CGECODefaultObjectFactory::SetContext( 
       
   132     CGECOObjectBase* aContext )
       
   133     {
       
   134     iContext = aContext;
       
   135     return KErrNone;        
       
   136     }
       
   137 
       
   138 
       
   139 // -----------------------------------------------------------------------------
       
   140 // CGECOObjectFactory::HasTextData
       
   141 // Returns ETrue if object has text data
       
   142 // -----------------------------------------------------------------------------
       
   143 //
       
   144 EXPORT_C TBool CGECODefaultObjectFactory::HasTextData()
       
   145     {
       
   146     TBool ret = EFalse;
       
   147     if ( iContext )
       
   148         {
       
   149         CGECODefaultObject* temp = 
       
   150             ((CGECODefaultObject*)iContext);
       
   151         ret = temp->HasTextData( );        
       
   152         }
       
   153     return ret;
       
   154     }
       
   155 
       
   156 // -----------------------------------------------------------------------------
       
   157 // CGECOObjectFactory::TextDetails
       
   158 // Returns text data details for this object
       
   159 // -----------------------------------------------------------------------------
       
   160 //
       
   161 EXPORT_C void CGECODefaultObjectFactory::TextDetailsL(
       
   162     TPtrC& aText,
       
   163     TBool& aIsLocalized )
       
   164     {
       
   165     if ( iContext )
       
   166         {
       
   167         CGECODefaultObject* temp = 
       
   168             ((CGECODefaultObject*)iContext);
       
   169             temp->TextDetailsL( aText, aIsLocalized );        
       
   170         }
       
   171     }
       
   172 
       
   173 // -----------------------------------------------------------------------------
       
   174 // CGECOObjectFactory::NumAttributes
       
   175 // Returns number of attributes for the current context
       
   176 // -----------------------------------------------------------------------------
       
   177 //
       
   178 EXPORT_C TInt CGECODefaultObjectFactory::NumAttributes()
       
   179     {
       
   180     TInt count = 0;
       
   181 
       
   182     if ( iContext )
       
   183         {
       
   184         count = ((CGECODefaultObject*)iContext)->NumAttributes();
       
   185         }
       
   186 
       
   187     return count;
       
   188     }
       
   189 
       
   190 // -----------------------------------------------------------------------------
       
   191 // CGECODefaultObjectFactory::AttributeDetailsL
       
   192 // Returns attribute details for the current context
       
   193 // -----------------------------------------------------------------------------
       
   194 //
       
   195 EXPORT_C void CGECODefaultObjectFactory::AttributeDetailsL(
       
   196     const TInt aIndex, 
       
   197     TPtrC& aAttrName, 
       
   198     TPtrC& aAttrValue, 
       
   199     TBool& aIsLocalized )
       
   200     {
       
   201     
       
   202     if ( iContext )
       
   203         {
       
   204         CGECODefaultObject* temp = ((CGECODefaultObject*)iContext);
       
   205         temp->AttributeDetailsL( aIndex, aAttrName, aAttrValue, aIsLocalized );
       
   206         temp = NULL;
       
   207         }
       
   208 
       
   209 
       
   210     }
       
   211 
       
   212 // -----------------------------------------------------------------------------
       
   213 // CGECODefaultObjectFactory::AttributeDetailsL
       
   214 // Returns attribute details for the current context
       
   215 // -----------------------------------------------------------------------------
       
   216 //
       
   217 EXPORT_C void CGECODefaultObjectFactory::AttributeDetailsL(
       
   218     const TInt aIndex, 
       
   219     TPtrC& aAttrName, 
       
   220     TPtrC& aAttrValue)
       
   221     {
       
   222     
       
   223     if ( iContext )
       
   224         {
       
   225         CGECODefaultObject* temp = ((CGECODefaultObject*)iContext);
       
   226         temp->AttributeDetailsL( aIndex, aAttrName, aAttrValue);
       
   227         temp = NULL;
       
   228         }
       
   229 
       
   230 
       
   231     }
       
   232 
       
   233 //  End of File