os/graphics/windowing/windowserver/nga/SERVER/CAPKEY.CPP
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/graphics/windowing/windowserver/nga/SERVER/CAPKEY.CPP	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,213 @@
     1.4 +// Copyright (c) 1995-2010 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +//
    1.18 +
    1.19 +// Capture key & hot key classes
    1.20 +//
    1.21 +#include <e32std.h>
    1.22 +#include "server.h"
    1.23 +#include "windowgroup.h"
    1.24 +#include "EVENT.H"
    1.25 +#include "inifile.h"
    1.26 +
    1.27 +_LIT(KWsProtectedKey, "PROTECTEDKEY");
    1.28 +_LIT(KWsProtectedWindowName, "PROTECTEDKEYWINDOWNAME");
    1.29 +
    1.30 +
    1.31 +/*CWsCaptureKey*/
    1.32 +
    1.33 +CWsCaptureKey::CWsCaptureKey(CWsWindowGroup *aGroupWin) : CWsObject(aGroupWin?aGroupWin->WsOwner():NULL,WS_HANDLE_CAPTURE_KEY), iWindowGroup(aGroupWin)
    1.34 +	{}
    1.35 +
    1.36 +CWsCaptureKey::~CWsCaptureKey()
    1.37 +	{
    1.38 +	TWindowServerEvent::CancelCaptureKey(ECaptureTypeKey, this);
    1.39 +	}
    1.40 +
    1.41 +/**
    1.42 +Convert a window server key capture command to a capture request for the
    1.43 +key routing plug-in.
    1.44 +
    1.45 +@param	aCaptureKey		Input capture command
    1.46 +@param	aRequest		Output capture request
    1.47 +*/
    1.48 +void CWsCaptureKey::CmdToRequest(const TWsWinCmdCaptureKey &aCaptureKey, TKeyCaptureRequest &aRequest)
    1.49 +	{
    1.50 +	aRequest.iType = ECaptureTypeKey;
    1.51 +	aRequest.iModifierMask = aCaptureKey.modifierMask;
    1.52 +	aRequest.iModifiers = aCaptureKey.modifiers;
    1.53 +	aRequest.iInputCode = aCaptureKey.key;
    1.54 +	aRequest.iOutputCode = aCaptureKey.key;
    1.55 +	aRequest.iPriority = aCaptureKey.priority;
    1.56 +	aRequest.iWindowGroup = iWindowGroup;
    1.57 +	aRequest.iWindowGroupId = iWindowGroup ? iWindowGroup->Identifier() : 0;
    1.58 +	aRequest.iAppUid = iWsOwner ? TUid::Uid(iWsOwner->SecureId().iId) : KNullUid;
    1.59 +	aRequest.iHandle = this;
    1.60 +	}
    1.61 +
    1.62 +/**
    1.63 +Check for protected key in a capture command
    1.64 +
    1.65 +@param	aWindowGroup	Window Group of capture request
    1.66 +@param	aCaptureKey		Key capture command
    1.67 +
    1.68 +@leave KErrPermissionDenied		Capture key is protected
    1.69 +*/
    1.70 +void CheckProtectedKeyL(CWsWindowGroup* aWindowGroup,const TWsWinCmdCaptureKey &aCaptureKey)
    1.71 +	{
    1.72 +	//The key specified in the WSINI file with the keyword: PROTECTEDKEY can only be captured 
    1.73 +	//by a group window with name specified with the PROTECTEDKEYWINDOWNAME keyword.
    1.74 +	TInt protectedKey;
    1.75 +	if(WsIniFile->FindVar(KWsProtectedKey,protectedKey))
    1.76 +		{
    1.77 +		if (aCaptureKey.key == static_cast<TUint>(protectedKey))
    1.78 +			{
    1.79 +			if (aWindowGroup->GroupName()==NULL)
    1.80 +				{
    1.81 +				User::Leave(KErrPermissionDenied);
    1.82 +				}
    1.83 +				
    1.84 +			TPtrC wsProtectedWindowName;
    1.85 +			WsIniFile->FindVar(KWsProtectedWindowName,wsProtectedWindowName);
    1.86 +			if (aWindowGroup->GroupName()->Find(wsProtectedWindowName)==KErrNotFound)
    1.87 +				{
    1.88 +				User::Leave(KErrPermissionDenied);
    1.89 +				}
    1.90 +			}
    1.91 +		}
    1.92 +	}
    1.93 +
    1.94 +/**
    1.95 +Construct a capture object for normal key events and make a capture request
    1.96 +to the key routing plug-in.
    1.97 +
    1.98 +@param	aCaptureKey		Key capture command from RWindowGroup::CaptureKey(),
    1.99 +						RWsSession::SetHotKey() or default hot key settings.
   1.100 +*/
   1.101 +void CWsCaptureKey::ConstructL(const TWsWinCmdCaptureKey &aCaptureKey)
   1.102 +	{
   1.103 +	CheckProtectedKeyL(iWindowGroup, aCaptureKey);
   1.104 +	NewObjL();
   1.105 +
   1.106 +	TKeyCaptureRequest request;
   1.107 +	CmdToRequest(aCaptureKey, request);
   1.108 +	TWindowServerEvent::AddCaptureKeyL(request);
   1.109 +	}
   1.110 +
   1.111 +/**
   1.112 +Make a capture request update for normal key events to the key routing plug-in.
   1.113 +
   1.114 +@param	aCaptureKey		Key capture command from CWsHotKey::SetL()
   1.115 +
   1.116 +Note: this function is used only to disable hot key capture requests or to
   1.117 +reset them to their defaults.
   1.118 +*/
   1.119 +void CWsCaptureKey::SetL(const TWsWinCmdCaptureKey &aCaptureKey)
   1.120 +	{
   1.121 +	TKeyCaptureRequest request;
   1.122 +	CmdToRequest(aCaptureKey, request);
   1.123 +	TWindowServerEvent::UpdateCaptureKeyL(request);
   1.124 +	}
   1.125 +
   1.126 +void CWsCaptureKey::CommandL(TInt , const TAny *)
   1.127 +	{
   1.128 +	}
   1.129 +
   1.130 +
   1.131 +/*CWsCaptureKeyUpsAndDowns*/
   1.132 +
   1.133 +CWsCaptureKeyUpsAndDowns::CWsCaptureKeyUpsAndDowns(CWsWindowGroup *aGroupWin) : CWsObject(aGroupWin?aGroupWin->WsOwner():NULL,WS_HANDLE_CAPTURE_KEY_UPDOWNS), iWindowGroup(aGroupWin)
   1.134 +	{}
   1.135 +
   1.136 +CWsCaptureKeyUpsAndDowns::~CWsCaptureKeyUpsAndDowns()
   1.137 +	{
   1.138 +	TWindowServerEvent::CancelCaptureKey(ECaptureTypeKeyUpDown, this);
   1.139 +	}
   1.140 +
   1.141 +/**
   1.142 +Construct a capture object for up/down key events and make a capture request
   1.143 +to the key routing plug-in.
   1.144 +
   1.145 +@param	aCaptureKey		Key capture command from
   1.146 +						RWindowGroup::CaptureKeyUpAndDowns().
   1.147 +*/
   1.148 +void CWsCaptureKeyUpsAndDowns::ConstructL(const TWsWinCmdCaptureKey &aCaptureKey)
   1.149 +	{
   1.150 +	CheckProtectedKeyL(iWindowGroup, aCaptureKey);
   1.151 +	NewObjL();
   1.152 +
   1.153 +	TKeyCaptureRequest request;
   1.154 +	request.iType = ECaptureTypeKeyUpDown;
   1.155 +	request.iInputCode = aCaptureKey.key;
   1.156 +	request.iOutputCode = aCaptureKey.key;
   1.157 +	request.iModifiers = aCaptureKey.modifiers;
   1.158 +	request.iModifierMask = aCaptureKey.modifierMask;
   1.159 +	request.iPriority = aCaptureKey.priority;
   1.160 +	request.iWindowGroup = iWindowGroup;
   1.161 +	request.iWindowGroupId = iWindowGroup ? iWindowGroup->Identifier() : 0;
   1.162 +	request.iAppUid = iWsOwner ? TUid::Uid(iWsOwner->SecureId().iId) : KNullUid;
   1.163 +	request.iHandle = this;
   1.164 +	TWindowServerEvent::AddCaptureKeyL(request);
   1.165 +	}
   1.166 +
   1.167 +void CWsCaptureKeyUpsAndDowns::CommandL(TInt , const TAny *)
   1.168 +	{
   1.169 +	}
   1.170 +
   1.171 +
   1.172 +/*CWsCaptureLongKey*/
   1.173 +
   1.174 +CWsCaptureLongKey::CWsCaptureLongKey(CWsWindowGroup *aGroupWin) 
   1.175 +	:CWsObject(aGroupWin?aGroupWin->WsOwner():NULL,WS_HANDLE_CAPTURE_LONG_KEY), iWindowGroup(aGroupWin)
   1.176 +	{}
   1.177 +
   1.178 +CWsCaptureLongKey::~CWsCaptureLongKey()
   1.179 +	{
   1.180 +	TWindowServerEvent::CancelCaptureKey(ECaptureTypeLongKey, this);
   1.181 +	}
   1.182 +
   1.183 +/**
   1.184 +Construct a capture object for long key events and make a capture request
   1.185 +to the key routing plug-in.
   1.186 +
   1.187 +@param	aCaptureKey		Key capture command from RWindowGroup::CaptureLongKey()
   1.188 +*/
   1.189 +void CWsCaptureLongKey::ConstructL(const TWsWinCmdCaptureLongKey &aCaptureKey)
   1.190 +	{
   1.191 +	NewObjL();
   1.192 +	iFlags = aCaptureKey.flags;
   1.193 +	iDelay = aCaptureKey.delay;
   1.194 +	if (iDelay.Int() < 0)
   1.195 +		{
   1.196 +		TTimeIntervalMicroSeconds32 time;
   1.197 +		CKeyboardRepeat::GetRepeatTime(iDelay, time);
   1.198 +		}
   1.199 +
   1.200 +	TKeyCaptureRequest request;
   1.201 +	request.iType = ECaptureTypeLongKey;
   1.202 +	request.iInputCode = aCaptureKey.inputKey;
   1.203 +	request.iOutputCode = aCaptureKey.outputKey;
   1.204 +	request.iModifiers = aCaptureKey.modifiers;
   1.205 +	request.iModifierMask = aCaptureKey.modifierMask;
   1.206 +	request.iPriority = aCaptureKey.priority;
   1.207 +	request.iWindowGroup = iWindowGroup;
   1.208 +	request.iWindowGroupId = iWindowGroup ? iWindowGroup->Identifier() : 0;
   1.209 +	request.iAppUid = iWsOwner ? TUid::Uid(iWsOwner->SecureId().iId) : KNullUid;
   1.210 +	request.iHandle = this;
   1.211 +	TWindowServerEvent::AddCaptureKeyL(request);
   1.212 +	}
   1.213 +
   1.214 +void CWsCaptureLongKey::CommandL(TInt , const TAny *)
   1.215 +	{
   1.216 +	}