textinput/peninputarc/src/peninputcrp/peninputcrp.cpp
changeset 0 eb1f2e154e89
equal deleted inserted replaced
-1:000000000000 0:eb1f2e154e89
       
     1 /*
       
     2 * Copyright (c) 2009 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:
       
    15 *
       
    16 */
       
    17 
       
    18 #include "peninputcrp.h"
       
    19 #include "peninputcrpmsg.h"
       
    20 #include <ecom/implementationproxy.h>
       
    21 #include <s32mem.h> //RDesReadStream
       
    22 
       
    23 //const TInt KDefaultScreen(0);
       
    24 const TInt KImpId(0x2000B5E7);
       
    25 
       
    26 #define INVERTLANDSCAPE
       
    27 
       
    28 const TInt KMonitoredEvents = TWservCrEvent::EDsaDrawingBegin|TWservCrEvent::EDsaDrawingEnd ;
       
    29 
       
    30 	
       
    31 class CAknWsService : public CBase, public MWsEventHandler
       
    32 	{
       
    33 	public:
       
    34 		static void CreateL(MWsGraphicDrawerEnvironment& aEnv, CAknWsServiceCRP* aSrv);
       
    35 		static void Delete(CAknWsServiceCRP* aSrv);
       
    36 		static inline CAknWsService* Service();
       
    37 		~CAknWsService();
       
    38 		
       
    39 	private:
       
    40 		void DoHandleEvent(const TWservCrEvent& aEvent);
       
    41 		void ConstructL();
       
    42 		CAknWsService(MWsGraphicDrawerEnvironment& aEnv);
       
    43 			    
       
    44 	private:
       
    45 		MWsGraphicDrawerEnvironment* iEnv;
       
    46 		CAknWsServiceCRP* iService;		
       
    47 	};
       
    48 
       
    49 
       
    50 inline CAknWsService* CAknWsService::Service()
       
    51 	{
       
    52 	return static_cast<CAknWsService*> (Dll::Tls());
       
    53 	}
       
    54 
       
    55 CAknWsService::CAknWsService(MWsGraphicDrawerEnvironment& aEnv) :
       
    56 iEnv(&aEnv)
       
    57 	{
       
    58 	}
       
    59 
       
    60 void CAknWsService::ConstructL()	
       
    61 	{
       
    62 	}
       
    63 
       
    64 void CAknWsService::CreateL(MWsGraphicDrawerEnvironment& aEnv, CAknWsServiceCRP* aSrv)
       
    65 	{
       
    66 	CAknWsService* srv = Service();
       
    67 	if(srv == NULL)
       
    68 		{
       
    69 		srv = new (ELeave) CAknWsService(aEnv);
       
    70 		CleanupStack::PushL(srv);
       
    71 		srv->ConstructL();
       
    72 		CleanupStack::Pop();
       
    73 		Dll::SetTls(srv);
       
    74 		}
       
    75 	else
       
    76 		{
       
    77 		CAknWsServiceCRP* s = srv->iService;
       
    78 		if(s != NULL)
       
    79 			{
       
    80 			while(s->iNext != NULL)
       
    81 				s = s->iNext;
       
    82 			s->iNext = aSrv;
       
    83 			return;
       
    84 			}
       
    85 		}
       
    86 	srv->iService = aSrv;
       
    87 	aEnv.RegisterEventHandler(aSrv, srv, KMonitoredEvents);	
       
    88 	}
       
    89 	
       
    90 void CAknWsService::Delete(CAknWsServiceCRP* aSrv) 
       
    91 	{
       
    92 	CAknWsService* srv = Service();
       
    93 	if(srv != NULL)
       
    94 		{
       
    95 		if(aSrv == srv->iService)
       
    96 			{
       
    97 			srv->iEnv->UnregisterEventHandler(aSrv);
       
    98 			if(aSrv->iNext != NULL)
       
    99 				{
       
   100 				srv->iEnv->RegisterEventHandler(aSrv->iNext, srv, KMonitoredEvents);
       
   101 				}
       
   102 			else  
       
   103 				{
       
   104 				srv->iService = NULL;	
       
   105 				delete srv;
       
   106 				Dll::SetTls(NULL);
       
   107 				return;
       
   108 				}
       
   109 			}
       
   110 			
       
   111 		CAknWsServiceCRP* s = srv->iService;
       
   112 		while(s->iNext != aSrv)
       
   113 			{
       
   114 			s = s->iNext;
       
   115 			ASSERT(s != NULL);
       
   116 			}
       
   117 		s->iNext = aSrv->iNext;	
       
   118 		}
       
   119 	}
       
   120 	
       
   121 CAknWsService::~CAknWsService()
       
   122 	{
       
   123 	RDebug::Print(_L("QQQ destructor"));
       
   124 	
       
   125 	}
       
   126 	
       
   127 		
       
   128 void CAknWsService::DoHandleEvent(const TWservCrEvent& aEvent)
       
   129 	{
       
   130 	
       
   131     //TInt data = 0;
       
   132     if(aEvent.Type() == TWservCrEvent::EDsaDrawingBegin)
       
   133         {
       
   134         // DSA is active 
       
   135        	iService->SetDsaActive(ETrue);
       
   136         }
       
   137         
       
   138     if(aEvent.Type() == TWservCrEvent::EDsaDrawingEnd)
       
   139         {
       
   140         // DSA is inactive
       
   141         iService->SetDsaActive(EFalse);
       
   142         }
       
   143 	
       
   144 	}
       
   145 		
       
   146 
       
   147 //////////////////////////////////////////////////////////////////////////////////////////////////////
       
   148 //////////////////////////////////////////////////////////////////////////////////////////////////////
       
   149 
       
   150 
       
   151 CWsGraphicDrawer* CAknWsServiceCRP::CreateL()
       
   152 	{
       
   153 	CAknWsServiceCRP* crp = new (ELeave) CAknWsServiceCRP();
       
   154 	return crp;
       
   155 	}
       
   156 	
       
   157 
       
   158 	
       
   159 CAknWsServiceCRP::~CAknWsServiceCRP()	
       
   160 	{
       
   161 	CAknWsService::Delete(this);
       
   162     iDsaGrpList.Close();
       
   163 	}
       
   164 
       
   165 void CAknWsServiceCRP::DoDraw(MWsGc& /*aGc*/, const TRect& /*aRect*/, const TDesC8& /*aData*/) const
       
   166 	{
       
   167 	//draws nothing
       
   168 	}
       
   169 	
       
   170 void CAknWsServiceCRP::HandleMessage(const TDesC8& aData)
       
   171 	{
       
   172 	TRAP_IGNORE(DoHandleMessageL(aData));
       
   173 	}
       
   174 	
       
   175 TBool CAknWsServiceCRP::IsDsaApp(TInt aId)
       
   176     {
       
   177     return iDsaGrpList.Find(aId) != KErrNotFound;
       
   178     }
       
   179 
       
   180 void CAknWsServiceCRP::RemoveDsaApp(TInt aId)
       
   181     {
       
   182     TInt idx = iDsaGrpList.Find(aId);
       
   183     if(KErrNotFound != idx)
       
   184         iDsaGrpList.Remove(idx);
       
   185     }
       
   186 TInt CAknWsServiceCRP::HandleSynchronMessage(const TDesC8& aData)
       
   187 	{
       
   188 	RDesReadStream in(aData);
       
   189 	TInt cmd = 0;
       
   190 	TRAP_IGNORE( cmd = in.ReadInt32L()); 
       
   191 //	RDebug::Printf("QQQ HandleSynchronMessage %d", cmd);
       
   192 	switch(cmd)
       
   193 		{
       
   194 	    case NPenInputCRPServiceMsg::EIsDsaApp:
       
   195 	        {
       
   196             return iIsDsaActive;	        
       
   197 	        }
       
   198 	    default:
       
   199 	        break;
       
   200 		}
       
   201 	return 0;
       
   202 	}
       
   203 	
       
   204 void CAknWsServiceCRP::DoHandleMessageL(const TDesC8& aData)
       
   205 	{
       
   206 	RDesReadStream in(aData);
       
   207 	const TInt cmd = in.ReadInt32L(); 
       
   208 //	RDebug::Printf("QQQ DoHandleMessageL %d", cmd);
       
   209 	switch(cmd)
       
   210 		{
       
   211 	    case NPenInputCRPServiceMsg::ERemoveDsaApp:
       
   212             {
       
   213             TInt id = in.ReadInt32L(); 
       
   214             RemoveDsaApp(id);
       
   215             }
       
   216 	        break;
       
   217         default:		        
       
   218 			break;
       
   219 		} 	
       
   220 	}
       
   221 	
       
   222 	
       
   223 void CAknWsServiceCRP::ConstructL(MWsGraphicDrawerEnvironment& aEnv,
       
   224  const TGraphicDrawerId& aId, MWsClient& aOwner, const TDesC8& /*aData*/)
       
   225 	{
       
   226 	BaseConstructL(aEnv, aId, aOwner);
       
   227 	CAknWsService::CreateL(aEnv, this);
       
   228 	}
       
   229 	
       
   230 	
       
   231 
       
   232 void CAknWsServiceCRP::AddDsaGrp(TInt aId)
       
   233     {
       
   234     if(KErrNotFound == iDsaGrpList.Find(aId))
       
   235         {
       
   236         iDsaGrpList.Append(aId);
       
   237         }
       
   238     }
       
   239     
       
   240 void CAknWsServiceCRP::SetDsaActive( TBool aIsActive )
       
   241 	{
       
   242 	iIsDsaActive = aIsActive;
       
   243 	}
       
   244     
       
   245 TAny* CAknWsServiceCRP::ResolveObjectInterface(TUint aTypeId)
       
   246 	{
       
   247 	if(aTypeId == KWsGraphicHandleSynchronMessageId)
       
   248 		{
       
   249 		TAny* interface = NULL;
       
   250 		interface = static_cast<MWsGraphicHandleSynchronMessage*>(this);
       
   251 		return interface;
       
   252 		}
       
   253 	return CWsGraphicDrawer::ResolveObjectInterface(aTypeId);
       
   254 	}	
       
   255     
       
   256     
       
   257 LOCAL_C const TImplementationProxy KImplementationTable[] = 
       
   258 	{
       
   259 	IMPLEMENTATION_PROXY_ENTRY(KImpId, CAknWsServiceCRP::CreateL)
       
   260 	};
       
   261 	
       
   262 EXPORT_C const TImplementationProxy* ImplementationGroupProxy(TInt& aTableCount)
       
   263 	{
       
   264 	aTableCount = (sizeof(KImplementationTable) / sizeof(TImplementationProxy));
       
   265 	return KImplementationTable;
       
   266 	}
       
   267