idlehomescreen/xmluirendering/uiengine/src/xncomponentfactory.cpp
branchRCL_3
changeset 83 5456b4e8b3a8
equal deleted inserted replaced
82:5f0182e07bfb 83:5456b4e8b3a8
       
     1 /*
       
     2 * Copyright (c) 2002-2004 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:  Component factory interface
       
    15 *
       
    16 */
       
    17 
       
    18 // User includes
       
    19 #include "xnappuiadapter.h"
       
    20 #include "xnviewadapter.h"
       
    21 #include "xncomponentfactory.h"
       
    22 #include "xncomponent.h"
       
    23 #include "xnnodepluginif.h"
       
    24 #include "xncomponentnodeimpl.h"
       
    25 #include "xnviewnodeimpl.h"
       
    26 #include "xncontroladapter.h"
       
    27 #include "xnpanic.h"
       
    28 #include "xntype.h"
       
    29 
       
    30 // Constants
       
    31 _LIT8( KToolTip, "tooltip" );
       
    32 _LIT8( KView, "view" );
       
    33 
       
    34 // ============================= LOCAL FUNCTIONS ===============================
       
    35 
       
    36 // -----------------------------------------------------------------------------
       
    37 // FindParentAdapter
       
    38 // Find a parent control adapter up the node chain
       
    39 // -----------------------------------------------------------------------------
       
    40 //
       
    41 static CXnControlAdapter* FindParentAdapter( CXnNode& aNode )
       
    42     {
       
    43     CXnNode* parent( aNode.Parent() );
       
    44     
       
    45     for( ; parent; parent = parent->Parent() )
       
    46         {
       
    47         CXnControlAdapter* control( parent->Control() );
       
    48         
       
    49         if( control )
       
    50             {
       
    51             return control;
       
    52             }
       
    53         }
       
    54     
       
    55     return NULL;
       
    56     }
       
    57 
       
    58 // ============================ MEMBER FUNCTIONS ===============================
       
    59 
       
    60 // -----------------------------------------------------------------------------
       
    61 // MXnComponentFactory::MXnComponentFactory
       
    62 // C++ default constructor can NOT contain any code, that
       
    63 // might leave.
       
    64 // -----------------------------------------------------------------------------
       
    65 //
       
    66 EXPORT_C MXnComponentFactory::MXnComponentFactory()
       
    67     {
       
    68     }
       
    69 
       
    70 // -----------------------------------------------------------------------------
       
    71 // MXnComponentFactory::CreateXnComponentL
       
    72 // Creates a component
       
    73 // -----------------------------------------------------------------------------
       
    74 //
       
    75 EXPORT_C MXnComponentFactory::TXnComponentFactoryResponse MXnComponentFactory::CreateXnComponentL(
       
    76     CXnNodePluginIf& aNode,
       
    77     CXnComponent*& aTargetComponent )
       
    78     {
       
    79     const TDesC8& type( aNode.Type()->Type() );
       
    80     
       
    81     MXnComponentFactory::TXnComponentFactoryResponse response =
       
    82         MakeXnComponentL( aNode, aTargetComponent );
       
    83     
       
    84     CleanupStack::PushL( aTargetComponent );
       
    85     
       
    86     if ( response != EXnFactoryResponseComponentConstructed )
       
    87         {
       
    88         CleanupStack::PopAndDestroy( aTargetComponent );
       
    89         
       
    90         return response;
       
    91         }
       
    92     
       
    93     CXnControlAdapter* parentAdapter( FindParentAdapter( aNode.Node() ) );
       
    94     CXnControlAdapter* adapter( MakeXnControlAdapterL( aNode, parentAdapter ) );
       
    95         
       
    96     aTargetComponent->SetNode( aNode );
       
    97             
       
    98     if ( type == KView )
       
    99         {
       
   100         aNode.ViewNodeImpl()->SetComponent( aTargetComponent );
       
   101         }
       
   102     else
       
   103         {
       
   104         aNode.ComponentNodeImpl()->SetComponent( aTargetComponent );
       
   105         }
       
   106     
       
   107     if ( parentAdapter )
       
   108         {
       
   109         parentAdapter->AppendChildL( *adapter, aNode.Node() );
       
   110         }
       
   111       
       
   112     aTargetComponent->SetControlAdapter( adapter );
       
   113     
       
   114     if ( !adapter )
       
   115         {
       
   116         CleanupStack::Pop( aTargetComponent );
       
   117         
       
   118         return response;
       
   119         }
       
   120     
       
   121     adapter->SetComponent( aTargetComponent );
       
   122     adapter->SetComponentsToInheritVisibility( ETrue );
       
   123         
       
   124     if ( type != KToolTip )
       
   125         {
       
   126         // Don't activate tooltip yet
       
   127         adapter->ActivateL();
       
   128         }
       
   129       
       
   130     CleanupStack::Pop( aTargetComponent );
       
   131     
       
   132     return response;
       
   133     }
       
   134 
       
   135 // -----------------------------------------------------------------------------
       
   136 // MXnComponentFactory::DoesNodeNeedComponentImplL
       
   137 // Check whether a node needs a component node implementation
       
   138 // -----------------------------------------------------------------------------
       
   139 //
       
   140 EXPORT_C TBool MXnComponentFactory::DoesNodeNeedComponentImplL( 
       
   141     const TDesC8& /*aType*/ )
       
   142     {
       
   143     return ETrue;
       
   144     }
       
   145 
       
   146 // -----------------------------------------------------------------------------
       
   147 // MXnComponentFactory::MakeXnComponentL
       
   148 // Factory method to create component
       
   149 // -----------------------------------------------------------------------------
       
   150 //
       
   151 EXPORT_C MXnComponentFactory::TXnComponentFactoryResponse MXnComponentFactory::MakeXnComponentL(
       
   152     CXnNodePluginIf& /*aNode*/,
       
   153     CXnComponent*& /*aTargetComponent*/ )
       
   154     {
       
   155     return EXnFactoryResponseComponentNotSupported;
       
   156     }
       
   157 
       
   158 // -----------------------------------------------------------------------------
       
   159 // MXnComponentFactory::MakeXnComponentL
       
   160 // Factory method to create control adapter
       
   161 // -----------------------------------------------------------------------------
       
   162 //
       
   163 EXPORT_C CXnControlAdapter* MXnComponentFactory::MakeXnControlAdapterL(
       
   164     CXnNodePluginIf& /*aNode*/,
       
   165     CXnControlAdapter* /*aParent*/ )
       
   166     {
       
   167     return NULL;
       
   168     }
       
   169 
       
   170 // -----------------------------------------------------------------------------
       
   171 // Default destructor
       
   172 // -----------------------------------------------------------------------------
       
   173 //
       
   174 EXPORT_C  MXnComponentFactory::~MXnComponentFactory()
       
   175     {
       
   176     }