os/kernelhwsrv/kernel/eka/ewsrv/ky_capt.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/kernelhwsrv/kernel/eka/ewsrv/ky_capt.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,164 @@
     1.4 +// Copyright (c) 1996-2009 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 the License "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 +// e32\ewsrv\ky_capt.cpp
    1.18 +// Provides the operations of setting and cancelling capture-keys
    1.19 +// 
    1.20 +//
    1.21 +
    1.22 +#include <e32svr.h>
    1.23 +#include <k32keys.h>
    1.24 +
    1.25 +const TInt KCaptureKeyArrayGranularity=5;
    1.26 +
    1.27 +EXPORT_C CCaptureKeys::CCaptureKeys()
    1.28 +	: iCKarray(KCaptureKeyArrayGranularity, _FOFF(TCaptureKey,iHandle))
    1.29 +	{
    1.30 +	}
    1.31 +
    1.32 +EXPORT_C void CCaptureKeys::Construct()
    1.33 +//
    1.34 +//
    1.35 +//
    1.36 +	{
    1.37 +	}
    1.38 +
    1.39 +EXPORT_C CCaptureKeys::~CCaptureKeys()
    1.40 +//
    1.41 +// Destructor
    1.42 +//
    1.43 +	{
    1.44 +	iCKarray.Close();
    1.45 +	}
    1.46 +
    1.47 +void CCaptureKeys::CheckCaptureKey(const TCaptureKey& aCaptureKey)
    1.48 +	{
    1.49 +
    1.50 +	if ((aCaptureKey.iModifiers.iValue&~aCaptureKey.iModifiers.iMask)!=0)
    1.51 +		User::Leave(KErrArgument);
    1.52 +	}
    1.53 +
    1.54 +EXPORT_C void CCaptureKeys::AddCaptureKeyL(const TCaptureKey& aCaptureKey)
    1.55 +//
    1.56 +// Adds the specified capture-key to the list
    1.57 +//
    1.58 +	{
    1.59 +
    1.60 +	AddCaptureKeyL(aCaptureKey,0);
    1.61 +	}
    1.62 +
    1.63 +EXPORT_C void CCaptureKeys::AddCaptureKeyL(const TCaptureKey& aCaptureKey, TUint8 aPriority)
    1.64 +//
    1.65 +// Adds the specified capture-key to the beginning of the list
    1.66 +//
    1.67 +	{
    1.68 +
    1.69 +	TCaptureKey captureKey(aCaptureKey);
    1.70 +	captureKey.iKeyCodePattern.iFiller = aPriority;// Priority is stored in spare data member 'iFiller'
    1.71 +	CheckCaptureKey(captureKey);
    1.72 +	User::LeaveIfError(iCKarray.Insert(captureKey,0));
    1.73 +	}
    1.74 +
    1.75 +EXPORT_C void CCaptureKeys::SetCaptureKey(TUint32 aHandle, const TCaptureKey& aCaptureKey)
    1.76 +//
    1.77 +// Finds the first capture-key from the list that matches the handle and sets
    1.78 +// it to the new value.
    1.79 +//
    1.80 +	{
    1.81 +
    1.82 +	SetCaptureKey(aHandle,aCaptureKey,0);
    1.83 +	}
    1.84 +
    1.85 +EXPORT_C void CCaptureKeys::SetCaptureKey(TUint32 aHandle, const TCaptureKey& aCaptureKey, TUint8 aPriority)
    1.86 +//
    1.87 +// Finds the first capture-key from the list that matches the handle and sets
    1.88 +// it to the new value.
    1.89 +//
    1.90 +	{
    1.91 +
    1.92 +	TCaptureKey captureKey(aCaptureKey);
    1.93 +	captureKey.iKeyCodePattern.iFiller = aPriority;// Priority is stored in spare data member 'iFiller'
    1.94 +	CheckCaptureKey(captureKey);
    1.95 +	TCaptureKey ck;
    1.96 +	ck.iHandle=aHandle;
    1.97 +	TInt r=iCKarray.Find(ck);
    1.98 +	if (r>=0)
    1.99 +		iCKarray[r]=captureKey;
   1.100 +	}
   1.101 +
   1.102 +void CCaptureKeys::removeCaptureKey(TUint aIndex)
   1.103 +//
   1.104 +// Removes the capture-key at the given aIndex from the list
   1.105 +//
   1.106 +	{
   1.107 +
   1.108 +	iCKarray.Remove(aIndex);
   1.109 +	}
   1.110 +
   1.111 +EXPORT_C void CCaptureKeys::CancelCaptureKey(TUint32 aHandle)
   1.112 +//
   1.113 +// Removes the first capture-key from the list that matches the handle;
   1.114 +//
   1.115 +	{
   1.116 +
   1.117 +	TCaptureKey ck;
   1.118 +	ck.iHandle=aHandle;
   1.119 +	TInt r=iCKarray.Find(ck);
   1.120 +	if (r>=0)
   1.121 +		iCKarray.Remove(r);
   1.122 +	}
   1.123 +
   1.124 +EXPORT_C void CCaptureKeys::CancelAllCaptureKeys(TUint32 aApp)
   1.125 +//
   1.126 +// Removes all capture-keys from the list that match the given application handle
   1.127 +//
   1.128 +	{
   1.129 +
   1.130 +	TInt i=iCKarray.Count();
   1.131 +	while(--i>=0)
   1.132 +		{
   1.133 +		if (iCKarray[i].iApp==aApp)
   1.134 +			iCKarray.Remove(i);
   1.135 +		}
   1.136 +	}
   1.137 +
   1.138 +EXPORT_C void CCaptureKeys::ProcessCaptureKeys(TKeyData& aKeyData) const
   1.139 +//
   1.140 +// Sets aKeyData.iIsCaptureKey to true if the given aKeyCode match a capture-key in the list
   1.141 +// and sets aKeyData.iApp to the handle of the last application that set it; 
   1.142 +// otherwise sets aKeyData.iIsCaptureKey to false and aKeyData.iApp to 0.
   1.143 +//
   1.144 +	{
   1.145 +
   1.146 +	TCharExtended ch=aKeyData.iKeyCode;
   1.147 +	aKeyData.iIsCaptureKey=EFalse;
   1.148 +	aKeyData.iApp = 0x0;
   1.149 +	TInt c=iCKarray.Count();
   1.150 +	TInt i;
   1.151 +	TInt priority=KMinTInt;
   1.152 +	for (i=0; i<c; i++)
   1.153 +		{
   1.154 +		const TCaptureKey& ck=iCKarray[i];
   1.155 +		if	( ch.MatchesPattern(ck.iKeyCodePattern) && MatchesMaskedValue(aKeyData.iModifiers, ck.iModifiers) )
   1.156 +			{
   1.157 +			if(ck.iKeyCodePattern.iFiller>priority)
   1.158 +				{
   1.159 +				priority=ck.iKeyCodePattern.iFiller;
   1.160 +				aKeyData.iApp=ck.iApp;
   1.161 +				aKeyData.iHandle=ck.iHandle;
   1.162 +				aKeyData.iIsCaptureKey=ETrue;
   1.163 +				}
   1.164 +			}
   1.165 +		}
   1.166 +	}
   1.167 +