os/graphics/windowing/windowserver/nga/SERVER/KEYCLICK.CPP
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
// Copyright (c) 2001-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
// Definition of the class that manages the keyclick plugin
sl@0
    15
// 
sl@0
    16
//
sl@0
    17
sl@0
    18
#include "KEYCLICK.H"
sl@0
    19
sl@0
    20
#include "server.h"
sl@0
    21
#include "W32CLICK.H"
sl@0
    22
#include "panics.h"
sl@0
    23
#include "inifile.h"
sl@0
    24
#include "advancedpointereventhelper.h"
sl@0
    25
sl@0
    26
CClickMaker* CClick::iHandler=NULL;
sl@0
    27
TBool CClick::iIsChangeable=ETrue;
sl@0
    28
TBool CClick::iKeyClickOveride=EFalse;
sl@0
    29
TBool CClick::iKeyClickEnabled=ETrue;
sl@0
    30
TBool CClick::iPenClickEnabled=ETrue;
sl@0
    31
RLibrary CClick::iPlugIn;
sl@0
    32
TBool CClick::iIsLoaded=EFalse;
sl@0
    33
sl@0
    34
const TUid KClickPlugInDllUid={0x10004F63};
sl@0
    35
static _LIT_SECURITY_POLICY_C1(KSecurityPolicy_WriteDeviceData,ECapabilityWriteDeviceData);
sl@0
    36
sl@0
    37
sl@0
    38
/*static part*/
sl@0
    39
sl@0
    40
void CClick::InitStaticsL()
sl@0
    41
	{
sl@0
    42
	_LIT(KClickPlugin,"KEYCLICKPLUGIN");
sl@0
    43
	TPtrC plugInName;
sl@0
    44
	if (WsIniFile->FindVar(KClickPlugin,plugInName))
sl@0
    45
		LoadNewLibraryL(plugInName);
sl@0
    46
	_LIT(KClickFixed,"KEYCLICKPLUGINFIXED");
sl@0
    47
	iIsChangeable=!WsIniFile->FindVar(KClickFixed);
sl@0
    48
	}
sl@0
    49
sl@0
    50
void CClick::DeleteStatics()
sl@0
    51
	{
sl@0
    52
	if (iIsLoaded)
sl@0
    53
		{
sl@0
    54
		delete iHandler;
sl@0
    55
		iHandler=NULL;
sl@0
    56
		iPlugIn.Close();
sl@0
    57
		}
sl@0
    58
	}
sl@0
    59
sl@0
    60
void CClick::KeyEvent(TEventCode aType,const TKeyEvent& aEvent)
sl@0
    61
	{
sl@0
    62
	WS_ASSERT_DEBUG(iHandler, EWsPanicClickPluginNotLoaded);
sl@0
    63
	if (iKeyClickEnabled && !iKeyClickOveride)
sl@0
    64
		{
sl@0
    65
		TRAP_IGNORE(iHandler->KeyEvent(aType,aEvent)); // TRAP leaves in case the plugin is badly behaved
sl@0
    66
		}
sl@0
    67
	}
sl@0
    68
sl@0
    69
void CClick::PointerEvent(const TPoint& aScreenPos,const TAdvancedPointerEvent& aEvent)
sl@0
    70
	{
sl@0
    71
	WS_ASSERT_DEBUG(iHandler, EWsPanicClickPluginNotLoaded);
sl@0
    72
	if (iPenClickEnabled)
sl@0
    73
		{
sl@0
    74
		TAdvancedPointerEvent event;
sl@0
    75
		TAdvancedPointerEventHelper::Copy(aEvent,event);
sl@0
    76
		event.iParentPosition=aScreenPos;
sl@0
    77
		TRAP_IGNORE(iHandler->PointerEvent(event)); // TRAP leaves in case the plugin is badly behaved
sl@0
    78
		}
sl@0
    79
	}
sl@0
    80
sl@0
    81
void CClick::OtherEvent(TInt aType,TAny* aParam)
sl@0
    82
	{
sl@0
    83
	WS_ASSERT_DEBUG(iHandler, EWsPanicClickPluginNotLoaded);
sl@0
    84
	if (aType!=EEventPointer || iPenClickEnabled)
sl@0
    85
		TRAP_IGNORE(iHandler->OtherEvent(aType,aParam)); // TRAP leaves in case the plugin is badly behaved
sl@0
    86
	}
sl@0
    87
sl@0
    88
void CClick::LoadNewLibraryL(const TDesC &aDllName)
sl@0
    89
	{
sl@0
    90
	WS_ASSERT_DEBUG(iIsChangeable, EWsPanicChangeClickPlugin);
sl@0
    91
	const TUidType uidType(KDllUid,KClickPlugInDllUid);
sl@0
    92
	RLibrary plugIn;
sl@0
    93
	User::LeaveIfError(plugIn.Load(aDllName,uidType));
sl@0
    94
	CleanupClosePushL(plugIn);
sl@0
    95
	CreateCClickHandler function;
sl@0
    96
	CClickMaker* handler;
sl@0
    97
	function=(CreateCClickHandler)User::LeaveIfNull((TAny*)plugIn.Lookup(1));	//Can only cast function pointer with C-style casts
sl@0
    98
	handler=(*function)();
sl@0
    99
	if (handler)
sl@0
   100
		{
sl@0
   101
		Unload();
sl@0
   102
		CleanupStack::Pop(&plugIn);
sl@0
   103
		iPlugIn=plugIn;
sl@0
   104
		iHandler=handler;
sl@0
   105
		iIsLoaded=ETrue;
sl@0
   106
		}
sl@0
   107
	else
sl@0
   108
		CleanupStack::PopAndDestroy(&plugIn);
sl@0
   109
	}
sl@0
   110
sl@0
   111
/*object part*/
sl@0
   112
sl@0
   113
void CClick::ConstructL(const TUid& aUid)
sl@0
   114
	{
sl@0
   115
	NewObjL();
sl@0
   116
	iThirdUid=aUid;
sl@0
   117
	}
sl@0
   118
sl@0
   119
void CClick::CommandL(TInt aOpcode,const TAny* aCmdData)
sl@0
   120
	{
sl@0
   121
	TWsClickCmdUnion pData;
sl@0
   122
	pData.any=aCmdData;
sl@0
   123
	switch(aOpcode)
sl@0
   124
		{
sl@0
   125
		case EWsClickOpFree:
sl@0
   126
			delete this;
sl@0
   127
			break;
sl@0
   128
		case EWsClickOpIsLoaded:
sl@0
   129
			{
sl@0
   130
			TUint reply=0;
sl@0
   131
			if (IsHandler())
sl@0
   132
				reply|=EClickLoaded;
sl@0
   133
			if (iIsChangeable)
sl@0
   134
				reply|=EClickLoadable;
sl@0
   135
			SetReply(reply);
sl@0
   136
			}
sl@0
   137
			break;
sl@0
   138
		case EWsClickOpUnLoad:
sl@0
   139
			{
sl@0
   140
			if(!KSecurityPolicy_WriteDeviceData().CheckPolicy(iWsOwner->ClientMessage(),__PLATSEC_DIAGNOSTIC_STRING("Capability check failed for RSoundPlugIn::UnLoad API")))
sl@0
   141
				{
sl@0
   142
				User::Leave(KErrPermissionDenied);
sl@0
   143
				}
sl@0
   144
			if (iIsChangeable)
sl@0
   145
				Unload();
sl@0
   146
			else
sl@0
   147
				SetReply(KErrNotSupported);
sl@0
   148
			}
sl@0
   149
			break;
sl@0
   150
		case EWsClickOpLoad:
sl@0
   151
			{
sl@0
   152
			if(!KSecurityPolicy_WriteDeviceData().CheckPolicy(iWsOwner->ClientMessage(),__PLATSEC_DIAGNOSTIC_STRING("Capability check failed for RSoundPlugIn::Load API")))
sl@0
   153
				{
sl@0
   154
				User::Leave(KErrPermissionDenied);
sl@0
   155
				}
sl@0
   156
			if (iIsChangeable)
sl@0
   157
				LoadNewLibraryL(iWsOwner->BufferTPtr((TText*)(pData.Int+1),*pData.Int));
sl@0
   158
			else 
sl@0
   159
				SetReply(KErrNotSupported);
sl@0
   160
			}
sl@0
   161
			break;
sl@0
   162
		case EWsClickOpSetKeyClick:
sl@0
   163
			{
sl@0
   164
			if(KSecurityPolicy_WriteDeviceData().CheckPolicy(iWsOwner->ClientMessage(),__PLATSEC_DIAGNOSTIC_STRING("Capability check failed for RSoundPlugIn::SetKeyClick API")))
sl@0
   165
				{
sl@0
   166
				iKeyClickEnabled=*pData.Bool;
sl@0
   167
				}
sl@0
   168
			}
sl@0
   169
			break;
sl@0
   170
		case EWsClickOpSetPenClick:
sl@0
   171
			{
sl@0
   172
			if(KSecurityPolicy_WriteDeviceData().CheckPolicy(iWsOwner->ClientMessage(),__PLATSEC_DIAGNOSTIC_STRING("Capability check failed for RSoundPlugIn::SetPenClick API")))
sl@0
   173
				{
sl@0
   174
				iPenClickEnabled=*pData.Bool;
sl@0
   175
				}
sl@0
   176
			}
sl@0
   177
			break;
sl@0
   178
		case EWsClickOpKeyClickEnabled:
sl@0
   179
			SetReply(iKeyClickEnabled);
sl@0
   180
			break;
sl@0
   181
		case EWsClickOpPenClickEnabled:
sl@0
   182
			SetReply(iPenClickEnabled);
sl@0
   183
			break;
sl@0
   184
		case EWsClickOpCommandReply:
sl@0
   185
			{
sl@0
   186
			TInt reply=RSoundPlugIn::ESoundWrongPlugIn;
sl@0
   187
			if (iHandler && iThirdUid==ThirdUid() && iThirdUid!=TUid::Null())
sl@0
   188
				TRAP(reply, reply = iHandler->CommandReplyL(*pData.Int,(TAny*)(pData.Int+1)));
sl@0
   189
			SetReply(reply);
sl@0
   190
			}
sl@0
   191
			break;
sl@0
   192
		default:
sl@0
   193
			OwnerPanic(EWservPanicOpcode);
sl@0
   194
			break;
sl@0
   195
		}
sl@0
   196
	}