uifw/AvKon/src/AknWsEventObserver.cpp
changeset 0 2f259fa3e83a
equal deleted inserted replaced
-1:000000000000 0:2f259fa3e83a
       
     1 /*
       
     2 * Copyright (c) 2001 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 classes derived from MAknWsEventObserver  
       
    15 *  Support for the observation of events prior to their normal handling in the the
       
    16 *  App Ui.
       
    17 *
       
    18 *
       
    19 */
       
    20 
       
    21 
       
    22 
       
    23 // INCLUDES
       
    24 #include "AknWsEventObserver.h"
       
    25 
       
    26 
       
    27 // LOCAL FUNCTIONS
       
    28 
       
    29 GLDEF_C void Panic(TAknWsEventObserverPanic aPanic)
       
    30 	{
       
    31 	_LIT(KPanicCat,"Avkon Ws Event Observer");
       
    32 	User::Panic(KPanicCat, aPanic);
       
    33 	}
       
    34 
       
    35 // IMPLEMENTATIONS
       
    36 
       
    37 CAknWsEventMonitor* CAknWsEventMonitor::NewL()
       
    38 	{
       
    39 	CAknWsEventMonitor* self=new(ELeave)CAknWsEventMonitor();
       
    40 	CleanupStack::PushL(self);
       
    41 	self->ConstructL();
       
    42 	CleanupStack::Pop();
       
    43 	return self;
       
    44 	}
       
    45 
       
    46 CAknWsEventMonitor::~CAknWsEventMonitor()
       
    47 	{
       
    48 	if (iEventObservers)
       
    49 	    iEventObservers->Close();
       
    50 	delete iEventObservers;
       
    51 	}
       
    52 
       
    53 void CAknWsEventMonitor::ConstructL()
       
    54 	{
       
    55 	iEventObservers = new (ELeave) RPointerArray<MAknWsEventObserver>(4);
       
    56 	}
       
    57 
       
    58 EXPORT_C void CAknWsEventMonitor::AddObserverL( MAknWsEventObserver* aEventObserver)
       
    59 	{
       
    60     TInt index = iEventObservers->Find(aEventObserver);
       
    61     if (index == KErrNotFound)
       
    62         {
       
    63         iEventObservers->AppendL(aEventObserver);
       
    64         }
       
    65 	}
       
    66 
       
    67 EXPORT_C void CAknWsEventMonitor::RemoveObserver(const MAknWsEventObserver* aEventObserver)
       
    68 	{
       
    69 	// Remove the pointer, as the object may want to disappear...
       
    70     TInt index = iEventObservers->Find(aEventObserver);
       
    71     if (index != KErrNotFound)
       
    72         {
       
    73         iEventObservers->Remove(index);
       
    74         }
       
    75 	}
       
    76 
       
    77 EXPORT_C void CAknWsEventMonitor::HandleWsEventL(const TWsEvent& aEvent, CCoeControl* aDestination )
       
    78     {
       
    79     // make a quickshot for current Observers.
       
    80     TInt count = iEventObservers->Count();
       
    81     if ( count == 0 )
       
    82         {
       
    83         return;
       
    84         }
       
    85     
       
    86     // not own
       
    87     RArray<MAknWsEventObserver*> snapShot( 4 );
       
    88     CleanupClosePushL( snapShot );
       
    89     
       
    90     for ( TInt i = 0; i < count; i++ )
       
    91         {
       
    92         snapShot.AppendL( (*iEventObservers)[i] );
       
    93         }
       
    94     
       
    95     for ( TInt i = 0; i < count; i++ )
       
    96         {
       
    97         MAknWsEventObserver* eventObserver = snapShot[i];
       
    98         if ( eventObserver && iEventObservers->Find( eventObserver ) != KErrNotFound )
       
    99             {
       
   100             eventObserver->HandleWsEventL(aEvent, aDestination);
       
   101             }
       
   102         }
       
   103    
       
   104     CleanupStack::PopAndDestroy(); // CleanupClosePushL( quichShort );
       
   105     }
       
   106 
       
   107 EXPORT_C void CAknWsEventMonitor::Enable(TBool aEnable)
       
   108     {
       
   109     iEnabled = aEnable;
       
   110     }
       
   111 	
       
   112 TBool CAknWsEventMonitor::IsEnabled()
       
   113     {
       
   114     return iEnabled;
       
   115     }
       
   116 
       
   117 EXPORT_C void CAknWsEventMonitor::Reserved_1()
       
   118 	{
       
   119 	}
       
   120 
       
   121