uiacceltk/hitchcock/Client/src/alfenv.cpp
changeset 0 15bf7259bb7c
child 3 d8a3531bc6b8
equal deleted inserted replaced
-1:000000000000 0:15bf7259bb7c
       
     1 /*
       
     2 * Copyright (c) 2006 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:   Environment
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #include <coemain.h>
       
    21 #include <AknsConstants.h>
       
    22 #include <AknTaskList.h>
       
    23 #include <alf/ftokenclient.h>
       
    24 #include <aknappui.h>
       
    25 #include "alf/alfenv.h"
       
    26 #include "alfclient.h"
       
    27 #include "alf/alfdisplay.h"
       
    28 #include "alf/alfroster.h"
       
    29 #include "alf/alfcontrolgroup.h"
       
    30 #include "alf/alfevent.h"
       
    31 #include "alf/alftexturemanager.h"
       
    32 #include "alf/alftextstylemanager.h"
       
    33 #include "alfcommandscheduler.h"
       
    34 #include "alf/alfstatic.h"
       
    35 #include "alf/alflayoutmetrics.h"
       
    36 #include "alf/alfconstants.h"
       
    37 #include "alf/alfevent.h"
       
    38 #include "alf/alfcontrol.h"
       
    39 #include "alf/alfbatchbuffer.h"
       
    40 #include "alf/alfenvobject.h"
       
    41 #include "alfuids.h"
       
    42 #include "alfpanic.h"
       
    43 
       
    44 #include "uiacceltk/HuiUtil.h"
       
    45 #include "alflogger.h"
       
    46 // Literals and constants
       
    47 // This string is used with multiple ALF clients -panic. The panic conserns 
       
    48 // only ALF clients, NOT the server!
       
    49 _LIT( KUIAcceltkClientPanic, "UIAcceltkClient" );
       
    50 
       
    51 struct TSharedTextureManagerEntry 
       
    52     {
       
    53     public:
       
    54     	~TSharedTextureManagerEntry()
       
    55         {
       
    56         }
       
    57     	TSharedTextureManagerEntry()                      
       
    58                       : iRefCount(0), iTextureManager(NULL)
       
    59         {                            
       
    60         }
       
    61     	
       
    62     	TSharedTextureManagerEntry(CAlfTextureManager* aTextureManager)                      
       
    63                       : iRefCount(1), iTextureManager(aTextureManager)
       
    64         {
       
    65         }
       
    66 
       
    67     /** The texturemanager reference count */
       
    68     TInt iRefCount;
       
    69 
       
    70     /** The shared texture manager entry. */
       
    71     CAlfTextureManager* iTextureManager;
       
    72     };
       
    73 
       
    74 
       
    75 // Used flags.
       
    76 enum TAlfEnvFlags
       
    77     {
       
    78     EOwnClient =            0x01,
       
    79     ETokenClientConnected = 0x02 
       
    80     // ...add other flags...
       
    81     };
       
    82 
       
    83 
       
    84 // Deault max framerate
       
    85 const TInt KAlfDefaultMaxFrameRate = 33;
       
    86     
       
    87 // Default flags
       
    88 const TUint KAlfEnvDefaultFlags = 0x00;
       
    89 
       
    90 // Size of buffer towards client side.
       
    91 const TInt KAlfTextureInfoMonitorBufferSize = 128;
       
    92 
       
    93 // ---------------------------------------------------------------------------
       
    94 // Returns connected control with ID 
       
    95 // ---------------------------------------------------------------------------
       
    96 //
       
    97 CAlfControl* FindConnectedControl(CAlfControl& aControl, TInt aId, TBool aUserId)
       
    98     {
       
    99     CAlfControl* result = NULL;
       
   100     for ( TInt connectionIndex = 0 ; connectionIndex < aControl.ConnectionCount() && !result ; connectionIndex++ )
       
   101         {
       
   102         CAlfControl& connection = aControl.Connection( connectionIndex );
       
   103         if( (aUserId?
       
   104             connection.Id():
       
   105             connection.Identifier()) 
       
   106                 == aId)
       
   107             {
       
   108             result = &connection;
       
   109             }
       
   110         else
       
   111             {
       
   112             result = FindConnectedControl( connection, aId, aUserId );
       
   113             }
       
   114         }
       
   115     
       
   116     return result;
       
   117     }
       
   118 
       
   119 /**
       
   120  * Gets the pointer evetns from the server
       
   121  */
       
   122 NONSHARABLE_CLASS(CAlfPtrEventFetcher):public CActive
       
   123     {
       
   124     public:
       
   125     CAlfPtrEventFetcher(RAlfClient& aClient, CAlfEnv& aEnv)
       
   126         :CActive(CActive::EPriorityHigh),iClient(aClient),iEventAsDescriptor(iEvent),iEnv(aEnv)
       
   127         {
       
   128         CActiveScheduler::Add(this);
       
   129         }
       
   130 
       
   131     ~CAlfPtrEventFetcher()
       
   132         {
       
   133         Cancel();
       
   134         }
       
   135 
       
   136     void Start()
       
   137         {
       
   138         ASSERT(!IsActive());
       
   139         SetActive();
       
   140         iClient.RequestPointerEvents(iEventAsDescriptor, iStatus);
       
   141         }
       
   142 
       
   143     private:
       
   144     void DeliverPointerEventL();
       
   145     
       
   146     void RunL()
       
   147         {
       
   148         if(iStatus.Int() == KErrNone)    
       
   149         	{
       
   150         	DeliverPointerEventL();		
       
   151         	Start();
       
   152         	}
       
   153         else
       
   154         	{
       
   155         	__ALFLOGSTRING1( "~CAlfPtrEventFetcher::RunL error %d", iStatus.Int() )	
       
   156         	}
       
   157         
       
   158         }
       
   159         
       
   160     void DoCancel()
       
   161         {
       
   162         iClient.CancelPointerEvents();
       
   163         }
       
   164 
       
   165     TInt RunError(TInt /*aError*/)
       
   166         {
       
   167         //Nothing to worry, just restart
       
   168         Start();
       
   169         return KErrNone;
       
   170         }
       
   171 
       
   172     RAlfClient& iClient;
       
   173     TAlfTouchEvent iEvent;
       
   174     TPckg<TAlfTouchEvent> iEventAsDescriptor;
       
   175     CAlfEnv& iEnv;
       
   176     friend class CAlfEnv; // allow env to acces our event data
       
   177     };
       
   178 
       
   179 void CAlfPtrEventFetcher::DeliverPointerEventL()
       
   180     {
       
   181     TBool eventSent(EFalse);
       
   182     
       
   183     // search clients based on handles from server
       
   184     CAlfControl* ctrl = iEnv.FindControl(iEvent.iControls[0], EFalse);
       
   185     TInt visualIdentifier = iEvent.iVisuals[0];
       
   186     
       
   187     for(TInt ii = 1; ctrl ; ii++)
       
   188         {
       
   189         // Find the visual index
       
   190         CAlfVisual* visual = NULL;
       
   191         for ( TInt i = ctrl->VisualCount() - 1 ; i >= 0 && visualIdentifier ; i-- )
       
   192             {
       
   193             if ( ctrl->Visual( i ).Identifier() == visualIdentifier )
       
   194                 {
       
   195                 visual = &ctrl->Visual( i );
       
   196                 break;
       
   197                 }
       
   198             }
       
   199         
       
   200         // Todo: Do we allow ctrl to leave and still pass the event to other cntrls ??
       
   201         TBool consumed = EFalse;
       
   202         TAlfEvent event(*ctrl->Display(), iEvent.iEvent); 
       
   203         event.SetVisual( visual );
       
   204         eventSent = ETrue;
       
   205         /*TRAP_IGNORE(*/consumed = ctrl->OfferEventL(event)/*)*/;
       
   206         if (consumed)
       
   207             {
       
   208             break;
       
   209             }
       
   210             
       
   211         ctrl = iEnv.FindControl(iEvent.iControls[ii], EFalse);
       
   212         visualIdentifier = iEvent.iVisuals[ii];
       
   213         }
       
   214     
       
   215     if (!eventSent)
       
   216         {
       
   217         // ptr event hit visual having groupless control as an owner
       
   218         // we can't resolve destination in toolkit side, just post infromation about the event data to 
       
   219         // action observers and let the app implementation decide whether event is used or nor.
       
   220         iEnv.ReportAction(TAlfActionCommand(KAlfOrpheanPtrEventReceived));
       
   221         }
       
   222     }
       
   223 
       
   224 
       
   225 NONSHARABLE_CLASS(CAlfSystemEventFetcher):public CActive
       
   226     {
       
   227     public:
       
   228     CAlfSystemEventFetcher(RAlfClient& aClient, CAlfEnv& aEnv)
       
   229         :CActive(CActive::EPriorityHigh),iClient(aClient),iEventAsDescriptor(iEvent),iEnv(aEnv)
       
   230         {
       
   231         CActiveScheduler::Add(this);
       
   232         }
       
   233 
       
   234     ~CAlfSystemEventFetcher()
       
   235         {
       
   236         Cancel();
       
   237         }
       
   238 
       
   239     void Start()
       
   240         {
       
   241         ASSERT(!IsActive());
       
   242         SetActive();
       
   243         iClient.RequestSystemEvents(iEventAsDescriptor, iStatus);
       
   244         }
       
   245 
       
   246     private:
       
   247     void DeliverSystemEventL();
       
   248     
       
   249     void RunL()
       
   250         {
       
   251         if(iStatus.Int() != KErrNone)
       
   252             { // for now..
       
   253             USER_INVARIANT();
       
   254             }
       
   255             
       
   256         DeliverSystemEventL();
       
   257         Start();
       
   258         }
       
   259         
       
   260     void DoCancel()
       
   261         {
       
   262         iClient.CancelSystemEvents();
       
   263         }
       
   264 
       
   265     TInt RunError(TInt /*aError*/)
       
   266         {
       
   267         //Nothing to worry, just restart
       
   268         Start();
       
   269         return KErrNone;
       
   270         }
       
   271 
       
   272     RAlfClient& iClient;
       
   273     TInt iEvent;
       
   274     TPckg<TInt> iEventAsDescriptor;
       
   275     CAlfEnv& iEnv;
       
   276     };
       
   277 
       
   278 void CAlfSystemEventFetcher::DeliverSystemEventL()
       
   279     {
       
   280     if (iEvent == KAknsMessageSkinChange)
       
   281         {
       
   282         iEnv.SetSkinChangePending(ETrue);
       
   283         iEnv.ReportWsEventAsActionCommand(KAlfActionIdSkinChanged); 
       
   284         // Some action observer may have already called by themselves
       
   285         // NotifySkinChangedL, so check before we do it.
       
   286         if (iEnv.SkinChangePending())
       
   287             {
       
   288             iEnv.NotifySkinChangedL();            
       
   289             }        
       
   290         }
       
   291     }
       
   292        
       
   293 /**
       
   294  * Texture information monitor.
       
   295  */
       
   296 NONSHARABLE_CLASS( CAlfTextureInfoMonitor ) : public CActive
       
   297     {
       
   298 public:
       
   299     /**
       
   300      * Two-phased constructor.
       
   301      * @param aClient reference to client.
       
   302      */
       
   303     static CAlfTextureInfoMonitor* NewL( CAlfEnv& aEnv );
       
   304     
       
   305     /**
       
   306      * Destructor.
       
   307      */
       
   308     ~CAlfTextureInfoMonitor();
       
   309        
       
   310 private:
       
   311 
       
   312     /**
       
   313      * Constructor.
       
   314      * @param aClient reference to client.
       
   315      */
       
   316     CAlfTextureInfoMonitor( CAlfEnv& aEnv );
       
   317     
       
   318     /**
       
   319      * Symbian OS constructor.
       
   320      */
       
   321     void ConstructL();
       
   322 
       
   323     /**
       
   324      * Issues a request.
       
   325      */
       
   326     void IssueRequest();
       
   327     
       
   328     /**
       
   329      * Called by active object framework when request is completed.
       
   330      */
       
   331     virtual void RunL();
       
   332     
       
   333     /**
       
   334      * Cancels pending request.
       
   335      */
       
   336     virtual void DoCancel();
       
   337     
       
   338 private:
       
   339     
       
   340     /**
       
   341      * Reference to environment.
       
   342      */
       
   343     CAlfEnv& iEnv;    
       
   344     
       
   345     /**
       
   346      * Buffer containing texture info events.
       
   347      */
       
   348     TBuf8< KAlfTextureInfoMonitorBufferSize > iTextureEventBuffer;
       
   349     };
       
   350 
       
   351 CAlfTextureInfoMonitor* CAlfTextureInfoMonitor::NewL( CAlfEnv& aEnv )
       
   352     {
       
   353     CAlfTextureInfoMonitor* self = 
       
   354         new (ELeave) CAlfTextureInfoMonitor( aEnv );
       
   355 
       
   356     CleanupStack::PushL( self );
       
   357     self->ConstructL();
       
   358     CleanupStack::Pop( self );
       
   359     
       
   360     return self;    
       
   361     }
       
   362     
       
   363 CAlfTextureInfoMonitor::~CAlfTextureInfoMonitor()
       
   364     {
       
   365     Cancel();
       
   366     }
       
   367     
       
   368 CAlfTextureInfoMonitor::CAlfTextureInfoMonitor( CAlfEnv& aEnv )
       
   369     : CActive( CActive::EPriorityStandard ),
       
   370       iEnv( aEnv )
       
   371     {
       
   372     CActiveScheduler::Add( this );
       
   373     }
       
   374     
       
   375 void CAlfTextureInfoMonitor::ConstructL()
       
   376     {
       
   377     IssueRequest();
       
   378     }
       
   379 
       
   380 void CAlfTextureInfoMonitor::IssueRequest()
       
   381     {
       
   382     iEnv.Client().TextureNotifyInfo( iStatus, iTextureEventBuffer );
       
   383     SetActive();
       
   384     }
       
   385     
       
   386 void CAlfTextureInfoMonitor::RunL()
       
   387     {
       
   388     if ( iStatus.Int() == KErrNone )
       
   389         {
       
   390         iEnv.HandleTextureInfo( iTextureEventBuffer );
       
   391         IssueRequest();
       
   392         }
       
   393     }
       
   394     
       
   395 void CAlfTextureInfoMonitor::DoCancel()
       
   396     {
       
   397     iEnv.Client().TextureCancelNotifyInfo();
       
   398     }
       
   399 
       
   400 // Private data
       
   401 struct CAlfEnv::TPrivateData
       
   402     {
       
   403     // Structure used to hold owned objects in the extension array
       
   404     struct TObjectHolder
       
   405         {
       
   406         TInt iUid;
       
   407         MAlfEnvObject* iObject;
       
   408         };
       
   409     TPrivateData():iFlags(0),iClient(0),iSharedRoster(0),
       
   410                    iTextureManager(0),iTextStyleManager(0),iScheduler(0),
       
   411                    iMaxFrameRate(0),iRefreshMode(EAlfRefreshModeAutomatic),
       
   412                    iStatic(0),iLayoutMetricsUtility(0),iPointerEventAo(0),
       
   413                    iBatchBufferHandler(0){}
       
   414     TUint iFlags;                                   // Owned.
       
   415     RAlfClient* iClient;                            // Owned/not owned - see EOwnClient
       
   416     CAlfRoster* iSharedRoster;                      // Owned.
       
   417     RPointerArray<CAlfDisplay> iDisplays;           // Owned.
       
   418     RPointerArray<CAlfControlGroup> iLoadedGroups;  // Owned.
       
   419     CAlfTextureManager* iTextureManager;            // Owned.
       
   420     CAlfTextStyleManager* iTextStyleManager;        // Owned.
       
   421     RPointerArray<MAlfActionObserver> iActionObservers;   // Owned.
       
   422     RArray<TSharedTextureManagerEntry> iSharedTextureManagers; // Owned.
       
   423     CAlfCommandScheduler* iScheduler;               // Owned.
       
   424     TInt iMaxFrameRate;
       
   425     TAlfRefreshMode iRefreshMode;
       
   426     RFTokenClient   iTokenClient;                    // lazy bound, connected once first real request occurs
       
   427     CAlfStatic* iStatic;                              // Owned.
       
   428     CAlfLayoutMetricsUtility* iLayoutMetricsUtility;  // Owned.
       
   429     CAlfPtrEventFetcher* iPointerEventAo;             // Owned.
       
   430     CAlfSystemEventFetcher* iSystemEventAo;             // Owned.
       
   431     TVersion iApiVersion;
       
   432     CAlfBatchBuffer* iBatchBufferHandler;
       
   433         
       
   434     // Flags to avoid unnecessary skin & layout notify calls
       
   435     TBool iNotifySkinChangePending;  
       
   436     TBool iNotifyLayoutChangePending;  
       
   437     
       
   438     CAlfTextureInfoMonitor* iTextureInfoMonitor; // Owned.
       
   439     
       
   440     RArray<CAlfEnv::TPrivateData::TObjectHolder> iExtensionArray;
       
   441     };
       
   442 
       
   443 // ======== MEMBER FUNCTIONS ========
       
   444 
       
   445 // ---------------------------------------------------------------------------
       
   446 // Constructor
       
   447 // ---------------------------------------------------------------------------
       
   448 //
       
   449 CAlfEnv::CAlfEnv()
       
   450     {
       
   451     }
       
   452 
       
   453 
       
   454 // ---------------------------------------------------------------------------
       
   455 // ConstructL
       
   456 // ---------------------------------------------------------------------------
       
   457 //
       
   458 void CAlfEnv::ConstructL(TVersion aVersion)
       
   459     {
       
   460     /*  
       
   461     // AknEventMonitor can be used if we want to know the target control also
       
   462     // Otherwise CoeMonitor should be used for better compatibility between 
       
   463     // releases 
       
   464       
       
   465     CAknAppUi* appUi = iAvkonAppUi; // actually macro using coe static...
       
   466     if (appUi && appUi->EventMonitor())
       
   467         {
       
   468         appUi->EventMonitor()->AddObserverL(this);
       
   469         appUi->EventMonitor()->Enable();
       
   470         }
       
   471 */
       
   472 
       
   473     // Enforces single CAlfEnv policy. Panics ONLY the client, NOT the server!!
       
   474     __ASSERT_ALWAYS( !CAlfEnv::Static(), User::Panic( KUIAcceltkClientPanic, EAlfEnvPanicMultipleAlfEnvironments ) );
       
   475     
       
   476     CCoeEnv* coeStatic = CCoeEnv::Static();
       
   477     if ( coeStatic )
       
   478         {
       
   479         coeStatic->AddMessageMonitorObserverL(*this);
       
   480         }
       
   481 
       
   482     // Create private data
       
   483     iData = new (ELeave) TPrivateData;
       
   484 
       
   485     iData->iApiVersion = aVersion;
       
   486     
       
   487     // NULL member data before anything else may leave.
       
   488     iData->iClient = NULL;
       
   489     iData->iSharedRoster = NULL;
       
   490     iData->iTextureManager = NULL;
       
   491     iData->iTextStyleManager = NULL;
       
   492     iData->iScheduler = NULL;
       
   493     iData->iStatic = NULL;
       
   494     iData->iLayoutMetricsUtility = NULL;
       
   495     iData->iPointerEventAo = NULL;
       
   496     iData->iSystemEventAo = NULL;
       
   497     iData->iBatchBufferHandler = NULL;
       
   498     iData->iTextureInfoMonitor = NULL;
       
   499                 
       
   500     // Set flags
       
   501     iData->iFlags = KAlfEnvDefaultFlags;
       
   502     
       
   503     // Set client ( pekjokel: client can be passed from outside as well? )
       
   504     iData->iClient = new (ELeave) RAlfClient;
       
   505     iData->iFlags |= EOwnClient;
       
   506     iData->iClient->OpenL();
       
   507     
       
   508     if (coeStatic)
       
   509         {
       
   510         CAknTaskList* taskList = CAknTaskList::NewLC(coeStatic->WsSession());
       
   511         const RArray<RWsSession::TWindowGroupChainInfo>& chain = taskList->WgArray();
       
   512         const TInt chainCount = chain.Count();
       
   513 
       
   514         TInt parentId = 0;
       
   515 
       
   516         TInt wgId = coeStatic->RootWin().Identifier();
       
   517         for ( TInt ii = 0; ii < chainCount; ii++ )
       
   518             {
       
   519             const RWsSession::TWindowGroupChainInfo& info = chain[ ii ];
       
   520             if ( info.iId == wgId )
       
   521                 {
       
   522                 parentId = info.iParentId;
       
   523                 break;
       
   524                 }
       
   525             }
       
   526         
       
   527         if (parentId > 0)
       
   528             {
       
   529             iData->iClient->SetWgParent(parentId);
       
   530             }
       
   531   
       
   532         CleanupStack::PopAndDestroy();       
       
   533         }
       
   534         
       
   535      // Create a shared roster. This is used by all overlaid displays.
       
   536     iData->iSharedRoster = new (ELeave) CAlfRoster;
       
   537     iData->iSharedRoster->ConstructL(NULL);
       
   538     
       
   539     iData->iDisplays.Reset();
       
   540     iData->iLoadedGroups.Reset();
       
   541     
       
   542     iData->iMaxFrameRate = KAlfDefaultMaxFrameRate;
       
   543         
       
   544     // Create a texture manager.
       
   545     User::LeaveIfError( iData->iClient->TextureUpdateOwnerId() );
       
   546     iData->iTextureManager = CAlfTextureManager::NewL(*this, TUid::Uid(0));
       
   547     iData->iTextureManager->AddLoadObserverL(this);
       
   548     iData->iTextureManager->AddStateObserverL(this);
       
   549     iData->iSharedTextureManagers.Reset();
       
   550     
       
   551     // Create a text style manager.
       
   552     iData->iTextStyleManager = CAlfTextStyleManager::NewL(*this);
       
   553     
       
   554     // Command scheduler
       
   555     iData->iScheduler = CAlfCommandScheduler::NewL( *this ); 
       
   556     
       
   557     // Static data storage
       
   558     iData->iStatic = CAlfStatic::NewL(this);
       
   559         
       
   560     // Layout metrics utility
       
   561     iData->iLayoutMetricsUtility = CAlfLayoutMetricsUtility::NewL(*this);
       
   562     
       
   563     // Create one shared pointer event fetcher for all displays and start it
       
   564     // to listen to incoming pointer events.
       
   565     iData->iPointerEventAo = new (ELeave) CAlfPtrEventFetcher(Client(), *this); 
       
   566     iData->iPointerEventAo->Start();
       
   567 
       
   568     iData->iSystemEventAo = new (ELeave) CAlfSystemEventFetcher(Client(), *this); 
       
   569     iData->iSystemEventAo->Start();
       
   570     
       
   571     iData->iBatchBufferHandler = CAlfBatchBuffer::NewL( *this );
       
   572 
       
   573     iData->iNotifySkinChangePending = EFalse;
       
   574     iData->iNotifyLayoutChangePending = EFalse;
       
   575 
       
   576     iData->iTextureInfoMonitor = 
       
   577         CAlfTextureInfoMonitor::NewL( *this );
       
   578     
       
   579     }
       
   580 
       
   581 // ---------------------------------------------------------------------------
       
   582 // 2-phased contructor
       
   583 // ---------------------------------------------------------------------------
       
   584 //
       
   585 EXPORT_C CAlfEnv* CAlfEnv::NewL(TVersion aVersion)
       
   586     {
       
   587     CAlfEnv* self = CAlfEnv::NewLC(aVersion);
       
   588     CleanupStack::Pop( self );
       
   589     return self;
       
   590     }
       
   591 
       
   592 
       
   593 // ---------------------------------------------------------------------------
       
   594 // 2-phased contructor. Object stays on the stack.
       
   595 // ---------------------------------------------------------------------------
       
   596 //
       
   597 EXPORT_C CAlfEnv* CAlfEnv::NewLC(TVersion aVersion)
       
   598     {
       
   599     CAlfEnv* self = new( ELeave ) CAlfEnv;
       
   600     CleanupStack::PushL( self );    
       
   601     
       
   602     // Check client API compatibility. 
       
   603     if (aVersion.iMajor != self->Version().iMajor)
       
   604         {
       
   605         User::Leave(KErrNotSupported);    
       
   606         }
       
   607     
       
   608     self->ConstructL(aVersion);
       
   609     return self;
       
   610     }
       
   611 
       
   612 
       
   613 // ---------------------------------------------------------------------------
       
   614 // Destructor
       
   615 // ---------------------------------------------------------------------------
       
   616 //
       
   617 EXPORT_C CAlfEnv::~CAlfEnv()
       
   618     {
       
   619     // Delete struct items
       
   620     if ( iData )
       
   621         {
       
   622         delete iData->iBatchBufferHandler;
       
   623         iData->iBatchBufferHandler = NULL;
       
   624         
       
   625         // Destroy pointer event fetcher
       
   626         delete iData->iPointerEventAo;
       
   627         iData->iPointerEventAo = NULL;
       
   628 
       
   629         delete iData->iSystemEventAo;
       
   630         iData->iSystemEventAo = NULL;
       
   631                 
       
   632         iData->iLoadedGroups.ResetAndDestroy();
       
   633         iData->iDisplays.ResetAndDestroy();
       
   634         delete iData->iSharedRoster;
       
   635         iData->iSharedRoster = NULL;        
       
   636         
       
   637         delete iData->iScheduler;
       
   638         iData->iScheduler= NULL;
       
   639         
       
   640         // Delete extension objects in reverse order.
       
   641         // (Objects should be added with dependent objects after the object on which they depend)
       
   642         for (TInt extensionIndex = iData->iExtensionArray.Count()-1 ; 
       
   643             extensionIndex >= 0; 
       
   644             extensionIndex--)
       
   645             {
       
   646             MAlfEnvObject* obj =  iData->iExtensionArray[extensionIndex].iObject;
       
   647             if ( obj)
       
   648                 {
       
   649                 obj->Release();   
       
   650                 }
       
   651             }
       
   652         iData->iExtensionArray.Reset();
       
   653         iData->iExtensionArray.Close();
       
   654                 
       
   655         if (iData->iTextureManager)
       
   656             {
       
   657             iData->iTextureManager->RemoveLoadObserver(this);
       
   658             iData->iTextureManager->RemoveStateObserver(this);
       
   659             }
       
   660 
       
   661         delete iData->iTextureManager;
       
   662         iData->iTextureManager = NULL;
       
   663     
       
   664         delete iData->iTextStyleManager;
       
   665         iData->iTextStyleManager = NULL;
       
   666         
       
   667         // Remove shared texture managers if any exists
       
   668    	    RArray<TSharedTextureManagerEntry>& managers = (iData->iSharedTextureManagers);
       
   669        	TInt count = iData->iSharedTextureManagers.Count();
       
   670         for(TInt i = 0; i < count; i++)
       
   671           	{
       
   672           	TSharedTextureManagerEntry entry = managers[i];
       
   673             entry.iTextureManager->RemoveLoadObserver(this);
       
   674             entry.iTextureManager->RemoveStateObserver(this);          	
       
   675           	delete entry.iTextureManager;
       
   676       		managers.Remove(i);
       
   677         	}  								                       
       
   678 
       
   679         iData->iSharedTextureManagers.Close();	    
       
   680 
       
   681         delete iData->iTextureInfoMonitor;
       
   682         iData->iTextureInfoMonitor = NULL;
       
   683 
       
   684         // ... close, release, delete other member data...
       
   685         iData->iActionObservers.Close();
       
   686         
       
   687         // Disconnect and delete client if owned
       
   688         if ( (iData->iFlags&EOwnClient) && iData->iClient )
       
   689             {
       
   690             iData->iClient->Disconnect();
       
   691             delete iData->iClient;
       
   692             }
       
   693         iData->iClient = NULL;
       
   694         iData->iFlags &= ~EOwnClient;
       
   695         
       
   696         delete iData->iLayoutMetricsUtility;
       
   697         
       
   698       
       
   699 
       
   700         delete iData->iStatic;
       
   701         }
       
   702     
       
   703     // Delete struct
       
   704     delete iData;
       
   705     iData = NULL;
       
   706 
       
   707 /*  
       
   708     // AknEventMonitor can be used if we want to know the target control also
       
   709     // Otherwise CoeMonitor should be used for better compatibility between 
       
   710     // releases 
       
   711   
       
   712     CAknAppUi* appUi = iAvkonAppUi; // actually macro using coe static...
       
   713     if (appUi && appUi->EventMonitor())
       
   714         {
       
   715         appUi->EventMonitor()->RemoveObserver(this);
       
   716         appUi->EventMonitor()->Enable(EFalse);
       
   717         }
       
   718 */
       
   719 
       
   720     CCoeEnv* coeStatic = CCoeEnv::Static();
       
   721     if ( coeStatic )
       
   722         {
       
   723         coeStatic->RemoveMessageMonitorObserver(*this);
       
   724         }
       
   725     }
       
   726 
       
   727 
       
   728 // ---------------------------------------------------------------------------
       
   729 // Returns the client
       
   730 // ---------------------------------------------------------------------------
       
   731 //
       
   732 EXPORT_C RAlfClient& CAlfEnv::Client()
       
   733     {
       
   734     __ASSERT_ALWAYS( iData, USER_INVARIANT() );
       
   735     __ASSERT_ALWAYS( iData->iClient, USER_INVARIANT() );
       
   736     __ASSERT_ALWAYS( iData->iClient->Handle(), USER_INVARIANT() );
       
   737     
       
   738     iData->iClient->SetAlfEnv(*this);
       
   739     return *iData->iClient;
       
   740     }
       
   741 
       
   742 // ---------------------------------------------------------------------------
       
   743 // Creates new display
       
   744 // ---------------------------------------------------------------------------
       
   745 //    
       
   746 EXPORT_C CAlfDisplay& CAlfEnv::NewDisplayL(
       
   747     const TRect& aRect,
       
   748     TInt aFlags,
       
   749     TInt aDisplayType)
       
   750     {
       
   751     return NewDisplayL(aRect, aFlags, NULL, aDisplayType, KAlfUidBackBufferScreen0);    
       
   752     }  
       
   753     
       
   754 // ---------------------------------------------------------------------------
       
   755 // Creates new display
       
   756 // ---------------------------------------------------------------------------
       
   757 //    
       
   758 EXPORT_C CAlfDisplay& CAlfEnv::NewDisplayL( 
       
   759 	const TRect& aRect, 
       
   760 	TInt aFlags, 
       
   761 	CAlfDisplay* /*aRosterOwningDisplay*/, 
       
   762     TInt aDisplayType, 
       
   763     TUid aBackBufferUid )
       
   764     {
       
   765     CAlfRoster* roster = NULL;
       
   766     
       
   767     if(aFlags & ENewDisplayOverlaid)
       
   768         {
       
   769         roster = iData->iSharedRoster;
       
   770         }
       
   771     
       
   772     TBool asCoeControl = EFalse;
       
   773     if ( aFlags & ENewDisplayAsCoeControl )
       
   774         {
       
   775         asCoeControl = ETrue;
       
   776         }
       
   777            
       
   778     CAlfDisplay* display = new (ELeave) CAlfDisplay;
       
   779     CleanupStack::PushL(display);
       
   780     display->ConstructL(*this, asCoeControl,aRect, roster, aDisplayType, aBackBufferUid);
       
   781     CleanupStack::Pop(display);
       
   782     TInt err = iData->iDisplays.Append(display);
       
   783     if ( err != KErrNone )
       
   784         {
       
   785         delete display;
       
   786         User::Leave( err );
       
   787         }                
       
   788     return *display;
       
   789     }  
       
   790 // ---------------------------------------------------------------------------
       
   791 // Called when display is deleted.
       
   792 // ---------------------------------------------------------------------------
       
   793 // 
       
   794 void CAlfEnv::RemoveDisplay(CAlfDisplay& aDisplay)
       
   795     {
       
   796     // Actually this is "DestroyDisplay"
       
   797 
       
   798     /** @todo  Make a proper observer. */
       
   799     TInt index = iData->iDisplays.Find(&aDisplay);
       
   800     if(index >= 0)
       
   801         {
       
   802         iData->iDisplays.Remove(index);
       
   803         iData->iDisplays.Compress();
       
   804         }
       
   805     // @todo: remove from the server side
       
   806     }
       
   807 
       
   808 // ---------------------------------------------------------------------------
       
   809 // Creates new control group
       
   810 // ---------------------------------------------------------------------------
       
   811 //
       
   812 EXPORT_C CAlfControlGroup& CAlfEnv::NewControlGroupL( TInt aId )
       
   813     {
       
   814     if ( FindControlGroup( aId ) )
       
   815         {
       
   816         User::Leave( KErrAlreadyExists );
       
   817         }
       
   818     
       
   819     CAlfControlGroup* group = new (ELeave) CAlfControlGroup;
       
   820     CleanupStack::PushL( group );
       
   821     group->ConstructL( aId, *this );
       
   822     CleanupStack::Pop( group );
       
   823     TInt err = iData->iLoadedGroups.Append( group );
       
   824     if ( err != KErrNone )
       
   825         {
       
   826         delete group;
       
   827         User::Leave( err );
       
   828         }
       
   829     
       
   830     return *group;
       
   831     }
       
   832  
       
   833 // ---------------------------------------------------------------------------
       
   834 // Deletes control group
       
   835 // ---------------------------------------------------------------------------
       
   836 //   
       
   837 EXPORT_C TInt CAlfEnv::DeleteControlGroup(TInt aId)
       
   838     {
       
   839     TInt i;
       
   840 
       
   841     for(i = 0; i < iData->iLoadedGroups.Count(); ++i)
       
   842         {
       
   843         if(iData->iLoadedGroups[i]->ResourceId() == aId)
       
   844             {
       
   845             CAlfControlGroup* group = iData->iLoadedGroups[i];
       
   846 
       
   847             CancelCommands(group);
       
   848 
       
   849             for (TInt ii = iData->iDisplays.Count()-1; ii>=0; ii--)
       
   850                 {
       
   851                 CAlfRoster& r = iData->iDisplays[ii]->Roster();
       
   852                 TInt index = r.Find(*group);
       
   853                 if (index != KErrNotFound)
       
   854                     {
       
   855                     r.Hide(*group); // update server
       
   856                     r.Remove(group); // update client 
       
   857                     }
       
   858                 }
       
   859 
       
   860             // This is control group to delete.
       
   861             iData->iLoadedGroups.Remove(i);
       
   862             delete group;
       
   863             return KErrNone;
       
   864             }
       
   865         }
       
   866 
       
   867     return KErrNotFound;
       
   868     }
       
   869     
       
   870 // ---------------------------------------------------------------------------
       
   871 // Returns control group with ID
       
   872 // ---------------------------------------------------------------------------
       
   873 //
       
   874 EXPORT_C CAlfControlGroup& CAlfEnv::ControlGroup(TInt aResourceId)
       
   875     {
       
   876     for(TInt i = 0; i < iData->iLoadedGroups.Count(); ++i)
       
   877         {
       
   878         if(iData->iLoadedGroups[i]->ResourceId() == aResourceId)
       
   879             {
       
   880             return *iData->iLoadedGroups[i];
       
   881             }
       
   882         }
       
   883 
       
   884     // Group hasn't been loaded yet
       
   885     /** @todo load automatically? */
       
   886     __ASSERT_DEBUG( EFalse, USER_INVARIANT() );
       
   887     return *iData->iLoadedGroups[0];
       
   888     }
       
   889    
       
   890 // ---------------------------------------------------------------------------
       
   891 // Returns control group with ID or NULL if not found
       
   892 // ---------------------------------------------------------------------------
       
   893 // 
       
   894 EXPORT_C CAlfControlGroup* CAlfEnv::FindControlGroup(TInt aResourceId) const
       
   895     {
       
   896     for(TInt i = 0; i < iData->iLoadedGroups.Count(); ++i)
       
   897         {
       
   898         if(iData->iLoadedGroups[i]->ResourceId() == aResourceId)
       
   899             {
       
   900             return iData->iLoadedGroups[i];
       
   901             }
       
   902         }
       
   903 
       
   904     return NULL;
       
   905     }
       
   906 
       
   907 // ---------------------------------------------------------------------------
       
   908 // Returns control with ID
       
   909 // ---------------------------------------------------------------------------
       
   910 //
       
   911 EXPORT_C CAlfControl* CAlfEnv::FindControl(TInt aId, TBool aUserId) const
       
   912     {
       
   913     for(TInt i = 0; i < iData->iLoadedGroups.Count(); ++i)
       
   914         {
       
   915         CAlfControl* control = iData->iLoadedGroups[i]->FindControl(aId, aUserId);
       
   916         if(control)
       
   917             {
       
   918             return control;
       
   919             }
       
   920         }
       
   921         
       
   922     // If we cannot found it from any of the groups, check the connections
       
   923     for(TInt groupIndex = 0; groupIndex < iData->iLoadedGroups.Count(); ++groupIndex)
       
   924         {
       
   925         CAlfControlGroup* controlGroup = iData->iLoadedGroups[groupIndex];
       
   926         
       
   927         for ( TInt controlIndex = 0 ; controlIndex < controlGroup->Count() ; controlIndex++ )
       
   928             {
       
   929             CAlfControl* foundControl = FindConnectedControl(controlGroup->Control(controlIndex), aId, aUserId);
       
   930             if ( foundControl )
       
   931                 {
       
   932                 return foundControl;
       
   933                 }
       
   934             }
       
   935         } 
       
   936         
       
   937     // The control does not exist.
       
   938     return NULL;
       
   939     }
       
   940 
       
   941 // ---------------------------------------------------------------------------
       
   942 // Returns display count
       
   943 // ---------------------------------------------------------------------------
       
   944 //
       
   945 EXPORT_C TInt CAlfEnv::DisplayCount() const
       
   946     {
       
   947     return iData->iDisplays.Count();
       
   948     }
       
   949  
       
   950 // ---------------------------------------------------------------------------
       
   951 // Set refresh mode.
       
   952 // ---------------------------------------------------------------------------
       
   953 //   
       
   954 EXPORT_C void CAlfEnv::SetRefreshMode( TAlfRefreshMode aMode )
       
   955     {
       
   956     Client().EnvSetRefreshMode( aMode );
       
   957     iData->iRefreshMode = TAlfRefreshMode(aMode);
       
   958     }
       
   959     
       
   960 // ---------------------------------------------------------------------------
       
   961 // Set max frame rate.
       
   962 // ---------------------------------------------------------------------------
       
   963 // 
       
   964 EXPORT_C void CAlfEnv::SetMaxFrameRate( TReal32 aFrameRate ) __SOFTFP
       
   965     {
       
   966     Client().EnvSetMaxFrameRate( aFrameRate );
       
   967     iData->iMaxFrameRate = (TInt)aFrameRate;
       
   968     }
       
   969 
       
   970 // ---------------------------------------------------------------------------
       
   971 // Continues refresh
       
   972 // ---------------------------------------------------------------------------
       
   973 //    
       
   974 EXPORT_C void CAlfEnv::ContinueRefresh()
       
   975     {
       
   976     Client().EnvContinueRefresh();
       
   977     }
       
   978 
       
   979 // ---------------------------------------------------------------------------
       
   980 // Pauses refresh
       
   981 // ---------------------------------------------------------------------------
       
   982 //    
       
   983 EXPORT_C void CAlfEnv::PauseRefresh()
       
   984     {
       
   985     Client().EnvPauseRefresh();
       
   986     }
       
   987   
       
   988 // ---------------------------------------------------------------------------
       
   989 // Called when a redraw is wanted
       
   990 // ---------------------------------------------------------------------------
       
   991 //    
       
   992 EXPORT_C TInt CAlfEnv::RefreshCallBack(TAny* aInstance)
       
   993     {
       
   994     CAlfEnv* self = static_cast<CAlfEnv*>( aInstance );
       
   995     self->Client().EnvRefreshCallBack();
       
   996     return KErrNone;
       
   997     }
       
   998     
       
   999 // ---------------------------------------------------------------------------
       
  1000 // Returns the first display
       
  1001 // ---------------------------------------------------------------------------
       
  1002 //
       
  1003 EXPORT_C CAlfDisplay& CAlfEnv::PrimaryDisplay() const
       
  1004     {
       
  1005     return *iData->iDisplays[0];
       
  1006     }
       
  1007 
       
  1008 // ---------------------------------------------------------------------------
       
  1009 // 
       
  1010 // ---------------------------------------------------------------------------
       
  1011 //
       
  1012 EXPORT_C CAlfTextureManager& CAlfEnv::TextureManager() const
       
  1013     {
       
  1014     return *iData->iTextureManager;
       
  1015     }
       
  1016 
       
  1017 // ---------------------------------------------------------------------------
       
  1018 // 
       
  1019 // ---------------------------------------------------------------------------
       
  1020 //
       
  1021 EXPORT_C CAlfTextStyleManager& CAlfEnv::TextStyleManager() const
       
  1022     {
       
  1023     return *iData->iTextStyleManager;
       
  1024     }
       
  1025 
       
  1026 // ---------------------------------------------------------------------------
       
  1027 // From class MAknWsEventObserver
       
  1028 // Controls server based on raw ws events
       
  1029 // ---------------------------------------------------------------------------
       
  1030 //
       
  1031 void CAlfEnv::HandleWsEventL(const TWsEvent& aEvent, CCoeControl* /*aDestination*/)
       
  1032     {
       
  1033     __ASSERT_ALWAYS(iData, USER_INVARIANT());
       
  1034 
       
  1035 	TInt eventType = aEvent.Type();
       
  1036 	// block these two here to avoid any extra execution beneath avkon level
       
  1037     if (eventType == KAknFullOrPartialForegroundLost ||
       
  1038         eventType == KAknFullOrPartialForegroundGained )
       
  1039         {        
       
  1040         const TBool foreground = (eventType == KAknFullOrPartialForegroundGained);      
       
  1041          
       
  1042         iData->iClient->ApplicationIsForeground(foreground);
       
  1043         iData->iScheduler->AppicationOnForeground(foreground);
       
  1044 
       
  1045         if (foreground)
       
  1046             {
       
  1047             ReportWsEventAsActionCommand(KAlfActionIdForegroundGained); 
       
  1048             }
       
  1049         else
       
  1050             {            
       
  1051             ReportWsEventAsActionCommand(KAlfActionIdForegroundLost);    
       
  1052             }                                    
       
  1053         } 
       
  1054     else if (eventType == EEventFocusGained)
       
  1055         {
       
  1056         ReportWsEventAsActionCommand(KAlfActionIdFocusGained);            
       
  1057         }        
       
  1058     else if (eventType == EEventFocusLost)
       
  1059         {
       
  1060         ReportWsEventAsActionCommand(KAlfActionIdFocusLost);                        
       
  1061         }        
       
  1062     else if (eventType == KEikInputLanguageChange)
       
  1063         {
       
  1064         ReportWsEventAsActionCommand(KAlfActionIdInputLanguageChanged);    
       
  1065         }
       
  1066     else if (eventType == EEventUser)
       
  1067         {
       
  1068         TApaSystemEvent* systemEvent = (TApaSystemEvent*) aEvent.EventData();
       
  1069         if (*systemEvent == EApaSystemEventSecureShutdown)
       
  1070             {
       
  1071             ReportWsEventAsActionCommand(KAlfActionIdExitRequested);        
       
  1072             }
       
  1073         else if (CEikonEnv::Static())
       
  1074             {                                         
       
  1075             if (*systemEvent == EApaSystemEventShutdown && 
       
  1076                 !CEikonEnv::Static()->IsSystem())
       
  1077                 {
       
  1078                 ReportWsEventAsActionCommand(KAlfActionIdExitRequested);    
       
  1079                 }
       
  1080             }
       
  1081         }        
       
  1082     else
       
  1083         {
       
  1084         // for PC lint
       
  1085         }
       
  1086 
       
  1087 
       
  1088     // - Skin change events are handled from CAlfSystemEventFetcher
       
  1089     // - Layout change events are handled from CAlfDisplay
       
  1090     }
       
  1091 
       
  1092 // ---------------------------------------------------------------------------
       
  1093 // 
       
  1094 // ---------------------------------------------------------------------------
       
  1095 //
       
  1096 EXPORT_C void CAlfEnv::AddActionObserverL(MAlfActionObserver* aObserver)
       
  1097     {
       
  1098     if (iData->iActionObservers.Find(aObserver) == KErrNotFound)
       
  1099         {
       
  1100         iData->iActionObservers.AppendL(aObserver);        
       
  1101         }
       
  1102     }
       
  1103     
       
  1104 // ---------------------------------------------------------------------------
       
  1105 // 
       
  1106 // ---------------------------------------------------------------------------
       
  1107 //
       
  1108 EXPORT_C void CAlfEnv::RemoveActionObserver(MAlfActionObserver* aObserver)
       
  1109     {
       
  1110     TInt index = iData->iActionObservers.Find(aObserver); 
       
  1111     if (index != KErrNotFound )
       
  1112         {
       
  1113         iData->iActionObservers.Remove(index);            
       
  1114         }
       
  1115     }
       
  1116     
       
  1117 // ---------------------------------------------------------------------------
       
  1118 // 
       
  1119 // ---------------------------------------------------------------------------
       
  1120 //
       
  1121 void CAlfEnv::HandleActionL(const TAlfActionCommand& aActionCommand)
       
  1122     { // handle in reverse order as action observer may remove it self during handling of command
       
  1123     for (TInt ii = iData->iActionObservers.Count()-1; ii >= 0; ii-- )
       
  1124         {
       
  1125         iData->iActionObservers[ii]->HandleActionL(aActionCommand);
       
  1126         }
       
  1127     }
       
  1128     
       
  1129     
       
  1130 // ---------------------------------------------------------------------------
       
  1131 // 
       
  1132 // ---------------------------------------------------------------------------
       
  1133 //
       
  1134 EXPORT_C TInt CAlfEnv::Send(const TAlfCommand& aCommand, TInt aDelayMilliSeconds )
       
  1135     {
       
  1136     TRAPD( err , iData->iScheduler->ScheduleCommandL( aCommand, aDelayMilliSeconds ) );
       
  1137     return err;
       
  1138     }
       
  1139     
       
  1140 // ---------------------------------------------------------------------------
       
  1141 // 
       
  1142 // ---------------------------------------------------------------------------
       
  1143 //
       
  1144 EXPORT_C void CAlfEnv::CancelCommands( TAny* aObject )
       
  1145     {
       
  1146     if (iData->iScheduler)
       
  1147         {
       
  1148         iData->iScheduler->CancelCommands( aObject );
       
  1149         }
       
  1150     }
       
  1151     
       
  1152 // ---------------------------------------------------------------------------
       
  1153 // 
       
  1154 // ---------------------------------------------------------------------------
       
  1155 //
       
  1156 EXPORT_C void CAlfEnv::CancelCustomCommands(MAlfEventHandler* aObject)
       
  1157     {
       
  1158     if (iData->iScheduler)
       
  1159         {
       
  1160         iData->iScheduler->CancelCommands( aObject );
       
  1161         }
       
  1162     }
       
  1163 
       
  1164 // ---------------------------------------------------------------------------
       
  1165 // 
       
  1166 // ---------------------------------------------------------------------------
       
  1167 //
       
  1168 EXPORT_C void CAlfEnv::CancelCommands(TAny* aObject, TAlfOp aCommandOperation)
       
  1169     {
       
  1170     if (iData->iScheduler)
       
  1171         {
       
  1172         iData->iScheduler->CancelCommands( aObject , aCommandOperation );
       
  1173         }
       
  1174     }
       
  1175 
       
  1176 // ---------------------------------------------------------------------------
       
  1177 // 
       
  1178 // ---------------------------------------------------------------------------
       
  1179 //
       
  1180 EXPORT_C void CAlfEnv::CancelCommands( TAny* aObject, TAlfCommandType aCommandType )
       
  1181     {
       
  1182     // use overloaded CancelCustomCommands instead for custom commands
       
  1183     __ASSERT_DEBUG( aCommandType != EAlfCommandTypeCustomEvent, USER_INVARIANT() );
       
  1184     
       
  1185     if (iData->iScheduler)
       
  1186         {
       
  1187         iData->iScheduler->CancelCommands( aObject, aCommandType, 0 );
       
  1188         }
       
  1189     }
       
  1190 
       
  1191 // ---------------------------------------------------------------------------
       
  1192 // 
       
  1193 // ---------------------------------------------------------------------------
       
  1194 //    
       
  1195 EXPORT_C void CAlfEnv::CancelCustomCommands(MAlfEventHandler* aObject, TInt aCustomParam )
       
  1196     {
       
  1197     if (iData->iScheduler)
       
  1198         {
       
  1199         iData->iScheduler->CancelCommands( aObject, EAlfCommandTypeCustomEvent, aCustomParam );
       
  1200         }
       
  1201     }
       
  1202 // ---------------------------------------------------------------------------
       
  1203 // 
       
  1204 // ---------------------------------------------------------------------------
       
  1205 //
       
  1206 EXPORT_C TInt CAlfEnv::MilliSecondsUntilCommand( TAny* aObject )
       
  1207     {
       
  1208     return iData->iScheduler->MilliSecondsUntilCommand( aObject ); 
       
  1209     }
       
  1210     
       
  1211 // ---------------------------------------------------------------------------
       
  1212 // 
       
  1213 // ---------------------------------------------------------------------------
       
  1214 //
       
  1215 EXPORT_C TInt CAlfEnv::MilliSecondsUntilCustomCommand(MAlfEventHandler* aObject)
       
  1216     {
       
  1217     return iData->iScheduler->MilliSecondsUntilCommand( aObject ); 
       
  1218     }
       
  1219 
       
  1220 // ---------------------------------------------------------------------------
       
  1221 // 
       
  1222 // ---------------------------------------------------------------------------
       
  1223 //
       
  1224 EXPORT_C TInt CAlfEnv::MilliSecondsUntilCommand(TAny* aObject, TAlfOp aCommandOperation)
       
  1225     {
       
  1226     return iData->iScheduler->MilliSecondsUntilCommand( aObject , aCommandOperation ); 
       
  1227     }
       
  1228 
       
  1229 // ---------------------------------------------------------------------------
       
  1230 // 
       
  1231 // ---------------------------------------------------------------------------
       
  1232 //
       
  1233 EXPORT_C TInt CAlfEnv::MilliSecondsUntilCommand( TAny* aObject, TAlfCommandType aCommandType )
       
  1234     {
       
  1235     // use overloaded CancelCustomCommands instead for custom commands
       
  1236     __ASSERT_DEBUG( aCommandType != EAlfCommandTypeCustomEvent, USER_INVARIANT() );
       
  1237     
       
  1238     return iData->iScheduler->MilliSecondsUntilCommand( aObject, aCommandType, 0 ); 
       
  1239     }
       
  1240 
       
  1241 // ---------------------------------------------------------------------------
       
  1242 // 
       
  1243 // ---------------------------------------------------------------------------
       
  1244 //    
       
  1245 EXPORT_C TInt CAlfEnv::MilliSecondsUntilCustomCommand(MAlfEventHandler* aObject, TInt aCustomParam )
       
  1246     {
       
  1247     return iData->iScheduler->MilliSecondsUntilCommand( aObject, EAlfCommandTypeCustomEvent, aCustomParam ); 
       
  1248     }
       
  1249     
       
  1250 // ---------------------------------------------------------------------------
       
  1251 // 
       
  1252 // ---------------------------------------------------------------------------
       
  1253 //
       
  1254 EXPORT_C TKeyResponse CAlfEnv::HandleKeyEventL(const TKeyEvent& aKeyEvent, TEventCode aType,
       
  1255                                         CAlfDisplay* aAssocDisplay)
       
  1256     {
       
  1257     if(aAssocDisplay)
       
  1258         {
       
  1259         TAlfEvent event(*aAssocDisplay, aKeyEvent, aType);
       
  1260 
       
  1261         if(aAssocDisplay->Roster().HandleEventL(event))
       
  1262             {
       
  1263             return EKeyWasConsumed;
       
  1264             }
       
  1265         return EKeyWasNotConsumed;
       
  1266         }
       
  1267 
       
  1268     return EKeyWasNotConsumed;
       
  1269     }
       
  1270     
       
  1271 // ---------------------------------------------------------------------------
       
  1272 // 
       
  1273 // ---------------------------------------------------------------------------
       
  1274 //
       
  1275 void CAlfEnv::BroadcastEventL(const TAlfEvent& aEvent)
       
  1276     {
       
  1277     for(TInt i = 0; i < iData->iDisplays.Count(); ++i)
       
  1278         {
       
  1279         TAlfEvent event = aEvent;
       
  1280         event.SetDisplay( iData->iDisplays[i] );
       
  1281         /** @todo  Musn't access the roster directly. */
       
  1282         iData->iDisplays[i]->Roster().HandleEventL(event);
       
  1283         }
       
  1284     }
       
  1285 
       
  1286 // ---------------------------------------------------------------------------
       
  1287 // 
       
  1288 // ---------------------------------------------------------------------------
       
  1289 //
       
  1290 TInt CAlfEnv::ReportAction(const TAlfActionCommand& aCommand)
       
  1291     {
       
  1292     TInt resultError = KErrNone;
       
  1293 
       
  1294     for(TInt i = 0; i < iData->iActionObservers.Count(); ++i)
       
  1295         {
       
  1296         TRAPD(err, iData->iActionObservers[i]->HandleActionL(aCommand));
       
  1297         if(err != KErrNone && resultError == KErrNone)
       
  1298             {
       
  1299             // The first error code is returned.
       
  1300             resultError = err;
       
  1301             }
       
  1302         }
       
  1303     return resultError;
       
  1304     }
       
  1305 
       
  1306 // ---------------------------------------------------------------------------
       
  1307 // 
       
  1308 // ---------------------------------------------------------------------------
       
  1309 //
       
  1310 EXPORT_C CAlfTextureManager* CAlfEnv::CreateSharedTextureManagerL(TUid aUid)
       
  1311     {
       
  1312     CAlfTextureManager* retVal = NULL;
       
  1313     RArray<TSharedTextureManagerEntry>& managers = (iData->iSharedTextureManagers);
       
  1314     TInt count = managers.Count();
       
  1315     for(TInt i = 0; i < count; i++)
       
  1316       	{
       
  1317     	if (managers[i].iTextureManager->ManagerUid() == aUid)
       
  1318     		{
       
  1319     		managers[i].iRefCount++;    			
       
  1320     		retVal = managers[i].iTextureManager;
       
  1321     		}
       
  1322     	}
       
  1323     	
       
  1324     // Does not yet exist, create new one	
       
  1325     if (!retVal)
       
  1326         {
       
  1327        	CAlfTextureManager* manager = CAlfTextureManager::NewL(*this, aUid);	  								                       
       
  1328         TSharedTextureManagerEntry entry(manager);
       
  1329         managers.Append(entry);
       
  1330         retVal = manager;    	          
       
  1331         retVal->AddLoadObserverL(this);
       
  1332         retVal->AddStateObserverL(this);        
       
  1333         }                
       
  1334 
       
  1335     return retVal;    
       
  1336     }
       
  1337 
       
  1338 // ---------------------------------------------------------------------------
       
  1339 // 
       
  1340 // ---------------------------------------------------------------------------
       
  1341 //
       
  1342 EXPORT_C void CAlfEnv::DeleteSharedTextureManager(TUid aUid)
       
  1343     {
       
  1344     RArray<TSharedTextureManagerEntry>& managers = (iData->iSharedTextureManagers);
       
  1345     TInt count = managers.Count();
       
  1346     for(TInt i = 0; i < count; i++)
       
  1347       	{
       
  1348     	if (managers[i].iTextureManager->ManagerUid() == aUid)
       
  1349     		{
       
  1350     		if (managers[i].iRefCount <= 1)
       
  1351     		    {
       
  1352                 managers[i].iTextureManager->RemoveLoadObserver(this);
       
  1353                 managers[i].iTextureManager->RemoveStateObserver(this);
       
  1354     		    delete managers[i].iTextureManager;
       
  1355        			managers.Remove(i);
       
  1356        			managers.Compress();    			        
       
  1357     		    }
       
  1358     		else
       
  1359     		    {
       
  1360     		    managers[i].iRefCount--;        
       
  1361     		    }    			    
       
  1362     		break;
       
  1363     		}  								                       
       
  1364         }                
       
  1365     }
       
  1366 
       
  1367 // ---------------------------------------------------------------------------
       
  1368 // 
       
  1369 // ---------------------------------------------------------------------------
       
  1370 //
       
  1371 EXPORT_C CAlfTextureManager* CAlfEnv::SharedTextureManager(TUid aUid) const
       
  1372     {
       
  1373     CAlfTextureManager* retVal = NULL;
       
  1374 
       
  1375     RArray<TSharedTextureManagerEntry>& managers = (iData->iSharedTextureManagers);
       
  1376     TInt count = managers.Count();
       
  1377     for(TInt i = 0; i < count; i++)
       
  1378       	{
       
  1379     	if (managers[i].iTextureManager->ManagerUid() == aUid)
       
  1380     		{
       
  1381             retVal = managers[i].iTextureManager;
       
  1382          	break;
       
  1383     		}  								                       
       
  1384         }                
       
  1385         
       
  1386     return retVal;    
       
  1387     }
       
  1388 
       
  1389 // ---------------------------------------------------------------------------
       
  1390 // 
       
  1391 // ---------------------------------------------------------------------------
       
  1392 //
       
  1393 void CAlfEnv::TextureLoadingCompleted(CAlfTexture& /*aTexture*/,
       
  1394                                          TInt /*aTextureId*/,
       
  1395                                          TInt /*aErrorCode*/)
       
  1396     {
       
  1397     // This is not used at the moment, but in the future may be needed.            
       
  1398     }
       
  1399 
       
  1400 
       
  1401 // ---------------------------------------------------------------------------
       
  1402 // 
       
  1403 // ---------------------------------------------------------------------------
       
  1404 //
       
  1405 void CAlfEnv::TextureManagerStateChanged(const CAlfTextureManager& /*aManager*/)
       
  1406     {
       
  1407     // When texture manager is loading, reduce framerate little.
       
  1408 /*
       
  1409     if (aManager.State() == CAlfTextureManager::EIdle)
       
  1410         {
       
  1411         Client().EnvSetMaxFrameRate( iData->iMaxFrameRate );
       
  1412         }
       
  1413     else
       
  1414         {        
       
  1415         Client().EnvSetMaxFrameRate( iData->iMaxFrameRate/2 );            
       
  1416         }            
       
  1417 */
       
  1418     }
       
  1419 
       
  1420 // ---------------------------------------------------------------------------
       
  1421 // 
       
  1422 // ---------------------------------------------------------------------------
       
  1423 //
       
  1424 EXPORT_C TAlfRefreshMode CAlfEnv::RefreshMode()
       
  1425     {
       
  1426     return iData->iRefreshMode;    
       
  1427     }
       
  1428 
       
  1429 // ---------------------------------------------------------------------------
       
  1430 // 
       
  1431 // ---------------------------------------------------------------------------
       
  1432 //
       
  1433 EXPORT_C TAlfRenderer CAlfEnv::Renderer() const
       
  1434     {
       
  1435     return TAlfRenderer(iData->iClient->EnvRenderer());            
       
  1436     }
       
  1437 
       
  1438 // ---------------------------------------------------------------------------
       
  1439 // 
       
  1440 // ---------------------------------------------------------------------------
       
  1441 //
       
  1442 EXPORT_C void CAlfEnv::SetIdleThreshold(TInt aMilliSeconds)
       
  1443     {
       
  1444     Client().EnvSetIdleThreshold(aMilliSeconds);    
       
  1445     }
       
  1446     
       
  1447 // ---------------------------------------------------------------------------
       
  1448 // 
       
  1449 // ---------------------------------------------------------------------------
       
  1450 //
       
  1451 EXPORT_C void CAlfEnv::Release(TBool aReleaseSharedTextures)
       
  1452     {
       
  1453     iData->iTextStyleManager->ReleaseAllVisuals();
       
  1454     
       
  1455     iData->iTextureManager->Release();
       
  1456     if (aReleaseSharedTextures)
       
  1457         {
       
  1458         RArray<TSharedTextureManagerEntry>& managers = (iData->iSharedTextureManagers);
       
  1459         TInt count = managers.Count();
       
  1460         for(TInt i = 0; i < count; i++)
       
  1461           	{
       
  1462         	managers[i].iTextureManager->Release();    	  								                       
       
  1463             }                            
       
  1464         }        
       
  1465 
       
  1466     }
       
  1467    
       
  1468 // ---------------------------------------------------------------------------
       
  1469 // 
       
  1470 // ---------------------------------------------------------------------------
       
  1471 //
       
  1472 EXPORT_C void CAlfEnv::RestoreL()
       
  1473     {
       
  1474     iData->iTextureManager->RestoreL();
       
  1475     RArray<TSharedTextureManagerEntry>& managers = (iData->iSharedTextureManagers);
       
  1476     TInt count = managers.Count();
       
  1477     for(TInt i = 0; i < count; i++)
       
  1478       	{
       
  1479     	managers[i].iTextureManager->RestoreL();    	  								                       
       
  1480         }                            
       
  1481     iData->iTextStyleManager->RefreshAllVisuals();
       
  1482     }
       
  1483     
       
  1484 // ---------------------------------------------------------------------------
       
  1485 // 
       
  1486 // ---------------------------------------------------------------------------
       
  1487 //
       
  1488 EXPORT_C void CAlfEnv::SetFullScreenDrawing(TBool aEnable)
       
  1489     {
       
  1490     Client().SetFullScreenDrawing(aEnable);
       
  1491     }
       
  1492     
       
  1493 // ---------------------------------------------------------------------------
       
  1494 // 
       
  1495 // ---------------------------------------------------------------------------
       
  1496 //
       
  1497 EXPORT_C void CAlfEnv::NotifySkinChangedL()
       
  1498     {
       
  1499     SetSkinChangePending(EFalse);       
       
  1500     iData->iTextureManager->NotifySkinChangedL();
       
  1501     RArray<TSharedTextureManagerEntry>& managers = (iData->iSharedTextureManagers);
       
  1502     TInt count = managers.Count();
       
  1503     for(TInt i = 0; i < count; i++)
       
  1504       	{
       
  1505     	managers[i].iTextureManager->NotifySkinChangedL();    	  								                       
       
  1506         }                            
       
  1507     }
       
  1508 
       
  1509 // ---------------------------------------------------------------------------
       
  1510 // 
       
  1511 // ---------------------------------------------------------------------------
       
  1512 //
       
  1513 EXPORT_C void CAlfEnv::NotifyLayoutChangedL()
       
  1514     {
       
  1515     SetLayoutChangePending(EFalse); 
       
  1516     for(TInt i = 0; i < iData->iDisplays.Count(); ++i)
       
  1517         {
       
  1518         iData->iDisplays[i]->NotifyLayoutChangedL();
       
  1519         }        
       
  1520     }
       
  1521 
       
  1522 
       
  1523 // ---------------------------------------------------------------------------
       
  1524 // 
       
  1525 // ---------------------------------------------------------------------------
       
  1526 //
       
  1527 EXPORT_C RFTokenClient* CAlfEnv::TokenClient()
       
  1528     {
       
  1529     ASSERT(iData);
       
  1530     if (!(iData->iFlags&ETokenClientConnected))
       
  1531         {
       
  1532         TInt err = iData->iTokenClient.Connect();
       
  1533         if (!err)
       
  1534             {
       
  1535             iData->iFlags |= ETokenClientConnected;
       
  1536             }
       
  1537         }
       
  1538     
       
  1539     if (iData->iFlags&ETokenClientConnected)
       
  1540         {
       
  1541         return &iData->iTokenClient;
       
  1542         }
       
  1543     else 
       
  1544         {
       
  1545         return NULL;
       
  1546         }
       
  1547     }
       
  1548 
       
  1549 // ---------------------------------------------------------------------------
       
  1550 // for better compatibility with different S60 releases
       
  1551 // ---------------------------------------------------------------------------
       
  1552 //
       
  1553 void CAlfEnv::MonitorWsMessage(const TWsEvent& aEvent)
       
  1554     {
       
  1555     TRAP_IGNORE(CAlfEnv::HandleWsEventL(aEvent, 0))
       
  1556     }
       
  1557 
       
  1558 
       
  1559 // ---------------------------------------------------------------------------
       
  1560 // 
       
  1561 // ---------------------------------------------------------------------------
       
  1562 //
       
  1563 EXPORT_C CAlfLayoutMetricsUtility* CAlfEnv::LayoutMetricsUtility()
       
  1564     {
       
  1565     return iData->iLayoutMetricsUtility;    
       
  1566     }
       
  1567 
       
  1568 // ---------------------------------------------------------------------------
       
  1569 // DEPRECATED: Widget code removed!
       
  1570 // ---------------------------------------------------------------------------
       
  1571 //
       
  1572 EXPORT_C IAlfWidgetFactory& CAlfEnv::WidgetFactory()const
       
  1573     {
       
  1574     IAlfWidgetFactory* ret(NULL); 
       
  1575     return *ret;    
       
  1576     }
       
  1577 
       
  1578 // ---------------------------------------------------------------------------
       
  1579 // DEPRECATED: Widget code removed!
       
  1580 // ---------------------------------------------------------------------------
       
  1581 //
       
  1582 EXPORT_C void CAlfEnv::AppendWidgetL(IAlfWidget* /*aAlfWidget*/)
       
  1583     {
       
  1584     }
       
  1585 
       
  1586 // ---------------------------------------------------------------------------
       
  1587 // DEPRECATED: Widget code removed!
       
  1588 // ---------------------------------------------------------------------------
       
  1589 //
       
  1590 EXPORT_C TInt CAlfEnv::DestroyWidget(IAlfWidget* /*aAlfWidget*/)
       
  1591     {
       
  1592     return 0;    
       
  1593     }
       
  1594 
       
  1595 // ---------------------------------------------------------------------------
       
  1596 // DEPRECATED: Widget code removed!
       
  1597 // ---------------------------------------------------------------------------
       
  1598 //
       
  1599 EXPORT_C IAlfWidget* CAlfEnv::FindWidget(const char* /*aWidgetName*/) const
       
  1600     {
       
  1601     IAlfWidget* ret(NULL);
       
  1602     return ret;
       
  1603     }
       
  1604 
       
  1605 // ---------------------------------------------------------------------------
       
  1606 // Uses CAlfStatic directly. friend is needed to access dll static 
       
  1607 // ---------------------------------------------------------------------------
       
  1608 //
       
  1609 EXPORT_C CAlfEnv* CAlfEnv::Static()
       
  1610     {
       
  1611     if ( CAlfStatic::Data() )
       
  1612         {
       
  1613         return &CAlfStatic::Env();
       
  1614         }
       
  1615         
       
  1616     return 0;
       
  1617     }
       
  1618 
       
  1619 // ---------------------------------------------------------------------------
       
  1620 // Support for extreme usecases where there are several controls but they don't
       
  1621 // belong to ctrl groups (so env cannot deliver the event by it self, but 
       
  1622 // application needs to fetch events based on notifications from environment) 
       
  1623 // ---------------------------------------------------------------------------
       
  1624 //
       
  1625 EXPORT_C TPointerEvent* CAlfEnv::LastReceivedPtrEvent()
       
  1626     {
       
  1627     if (iData && iData->iPointerEventAo)
       
  1628         {
       
  1629         return &iData->iPointerEventAo->iEvent.iEvent;
       
  1630         }
       
  1631     return 0;
       
  1632     }
       
  1633 
       
  1634 // ---------------------------------------------------------------------------
       
  1635 // 
       
  1636 // ---------------------------------------------------------------------------
       
  1637 //
       
  1638 EXPORT_C TVersion CAlfEnv::Version() const
       
  1639     {
       
  1640     return TVersion(ALF_VERSION_MAJOR, ALF_VERSION_MINOR, ALF_VERSION_BUILD);    
       
  1641     }
       
  1642 
       
  1643 
       
  1644 // ---------------------------------------------------------------------------
       
  1645 // 
       
  1646 // ---------------------------------------------------------------------------
       
  1647 //
       
  1648 TVersion CAlfEnv::ApiVersion() const
       
  1649     {
       
  1650     return iData->iApiVersion;    
       
  1651     }
       
  1652     
       
  1653 // ---------------------------------------------------------------------------
       
  1654 // 
       
  1655 // ---------------------------------------------------------------------------
       
  1656 //
       
  1657 EXPORT_C CAlfBatchBuffer& CAlfEnv::BatchBufferHandler() const
       
  1658     {
       
  1659     return *iData->iBatchBufferHandler;
       
  1660     }
       
  1661 
       
  1662 void CAlfEnv::ReportWsEventAsActionCommand(TInt aActionCommandId)
       
  1663     {
       
  1664     if (aActionCommandId == KAlfActionIdDeviceLayoutChanged) 
       
  1665         {            
       
  1666         SetLayoutChangePending(ETrue); 
       
  1667         ReportAction(TAlfActionCommand(aActionCommandId));      
       
  1668         // If action obeserver did not call NotifyLayoutChangedL, we do it.
       
  1669         if (LayoutChangePending())
       
  1670             {
       
  1671             TRAP_IGNORE(NotifyLayoutChangedL());    
       
  1672             }
       
  1673         }
       
  1674     else
       
  1675         {
       
  1676         ReportAction(TAlfActionCommand(aActionCommandId));      
       
  1677         }            
       
  1678     }
       
  1679 
       
  1680 // ---------------------------------------------------------------------------
       
  1681 // 
       
  1682 // ---------------------------------------------------------------------------
       
  1683 //
       
  1684 TBool CAlfEnv::SkinChangePending() const
       
  1685     {
       
  1686     return iData->iNotifySkinChangePending;    
       
  1687     }
       
  1688 
       
  1689 // ---------------------------------------------------------------------------
       
  1690 // 
       
  1691 // ---------------------------------------------------------------------------
       
  1692 //
       
  1693 void CAlfEnv::SetSkinChangePending(TBool aPending)
       
  1694     {
       
  1695     iData->iNotifySkinChangePending = aPending;        
       
  1696     }
       
  1697 
       
  1698 // ---------------------------------------------------------------------------
       
  1699 // 
       
  1700 // ---------------------------------------------------------------------------
       
  1701 //
       
  1702 TBool CAlfEnv::LayoutChangePending() const
       
  1703     {
       
  1704     return iData->iNotifyLayoutChangePending;   
       
  1705     }
       
  1706 
       
  1707 // ---------------------------------------------------------------------------
       
  1708 // 
       
  1709 // ---------------------------------------------------------------------------
       
  1710 //
       
  1711 void CAlfEnv::SetLayoutChangePending(TBool aPending)
       
  1712     {
       
  1713     iData->iNotifyLayoutChangePending = aPending;    
       
  1714     }
       
  1715 
       
  1716 
       
  1717 // ---------------------------------------------------------------------------
       
  1718 // 
       
  1719 // ---------------------------------------------------------------------------
       
  1720 //
       
  1721 void CAlfEnv::HandleTextureInfo( const TDesC8& aEventData )
       
  1722     {
       
  1723     // Notify texture manager with new information.
       
  1724 
       
  1725     TAlfTextureInfoEvent eventData;
       
  1726     TPckg< TAlfTextureInfoEvent > eventBuf( eventData );
       
  1727     const TInt eventBufMaxLength = eventBuf.MaxLength();
       
  1728     TPtrC8 remainder( aEventData );
       
  1729     
       
  1730     while ( eventBufMaxLength <= remainder.Length() )
       
  1731         {
       
  1732         // Get event data - note that as data is copied to local buffer,
       
  1733         // there is no need to worry about padding issues.
       
  1734         eventBuf.Copy( remainder.Left( eventBufMaxLength ) );
       
  1735         remainder.Set( remainder.Mid( eventBufMaxLength ) );
       
  1736         
       
  1737         // Inform texture manager.
       
  1738         TRAP_IGNORE(iData->iTextureManager->ReportTextureInfoL( 
       
  1739             eventData.iTextureId, 
       
  1740             eventData.iTextureSize ));      
       
  1741         }
       
  1742             
       
  1743     // Note: texture information events are not delivered to shared texture
       
  1744     // managers (iData->iSharedTextureManagers) as this feature is not supported
       
  1745     // for those.    
       
  1746     }
       
  1747 
       
  1748 
       
  1749 
       
  1750 EXPORT_C MAlfEnvObject* CAlfEnv::Extension( TInt aUid) const
       
  1751     {
       
  1752     TPrivateData::TObjectHolder holder;
       
  1753     holder.iUid = aUid;
       
  1754     TInt index = iData->iExtensionArray.Find(holder);
       
  1755     if (index!=KErrNotFound)
       
  1756         {
       
  1757         return iData->iExtensionArray[index].iObject;
       
  1758         }
       
  1759     else
       
  1760         {
       
  1761         return NULL;
       
  1762         } 
       
  1763     }
       
  1764 
       
  1765 EXPORT_C TInt CAlfEnv::AddExtension( TInt aUid, MAlfEnvObject* aNewExtension)
       
  1766     {
       
  1767     TPrivateData::TObjectHolder holder;
       
  1768     holder.iUid = aUid;
       
  1769     holder.iObject = aNewExtension;
       
  1770     return iData->iExtensionArray.Append(holder);
       
  1771     }
       
  1772 
       
  1773 EXPORT_C void CAlfEnv::HandlePointerEventL(const TPointerEvent& aPointerEvent, 
       
  1774                                    CAlfDisplay& aAssocDisplay)
       
  1775     {
       
  1776     aAssocDisplay.HandlePointerEventL(aPointerEvent);
       
  1777     }
       
  1778 
       
  1779 // ---------------------------------------------------------------------------
       
  1780 // Returns index of the display
       
  1781 // ---------------------------------------------------------------------------
       
  1782 //
       
  1783 EXPORT_C TInt CAlfEnv::FindDisplayIndex(const CAlfDisplay& aDisplay) const
       
  1784     {
       
  1785     TInt index = iData->iDisplays.Find(&aDisplay);
       
  1786     return index;
       
  1787     }
       
  1788     
       
  1789 // ---------------------------------------------------------------------------
       
  1790 // Returns indexed display
       
  1791 // ---------------------------------------------------------------------------
       
  1792 //    
       
  1793 EXPORT_C CAlfDisplay& CAlfEnv::Display( TInt aIndex) const
       
  1794     {
       
  1795     return *iData->iDisplays[aIndex];
       
  1796     }
       
  1797