sl@0: // Copyright (c) 1996-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of the License "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // e32\ewsrv\ky_capt.cpp sl@0: // Provides the operations of setting and cancelling capture-keys sl@0: // sl@0: // sl@0: sl@0: #include sl@0: #include sl@0: sl@0: const TInt KCaptureKeyArrayGranularity=5; sl@0: sl@0: EXPORT_C CCaptureKeys::CCaptureKeys() sl@0: : iCKarray(KCaptureKeyArrayGranularity, _FOFF(TCaptureKey,iHandle)) sl@0: { sl@0: } sl@0: sl@0: EXPORT_C void CCaptureKeys::Construct() sl@0: // sl@0: // sl@0: // sl@0: { sl@0: } sl@0: sl@0: EXPORT_C CCaptureKeys::~CCaptureKeys() sl@0: // sl@0: // Destructor sl@0: // sl@0: { sl@0: iCKarray.Close(); sl@0: } sl@0: sl@0: void CCaptureKeys::CheckCaptureKey(const TCaptureKey& aCaptureKey) sl@0: { sl@0: sl@0: if ((aCaptureKey.iModifiers.iValue&~aCaptureKey.iModifiers.iMask)!=0) sl@0: User::Leave(KErrArgument); sl@0: } sl@0: sl@0: EXPORT_C void CCaptureKeys::AddCaptureKeyL(const TCaptureKey& aCaptureKey) sl@0: // sl@0: // Adds the specified capture-key to the list sl@0: // sl@0: { sl@0: sl@0: AddCaptureKeyL(aCaptureKey,0); sl@0: } sl@0: sl@0: EXPORT_C void CCaptureKeys::AddCaptureKeyL(const TCaptureKey& aCaptureKey, TUint8 aPriority) sl@0: // sl@0: // Adds the specified capture-key to the beginning of the list sl@0: // sl@0: { sl@0: sl@0: TCaptureKey captureKey(aCaptureKey); sl@0: captureKey.iKeyCodePattern.iFiller = aPriority;// Priority is stored in spare data member 'iFiller' sl@0: CheckCaptureKey(captureKey); sl@0: User::LeaveIfError(iCKarray.Insert(captureKey,0)); sl@0: } sl@0: sl@0: EXPORT_C void CCaptureKeys::SetCaptureKey(TUint32 aHandle, const TCaptureKey& aCaptureKey) sl@0: // sl@0: // Finds the first capture-key from the list that matches the handle and sets sl@0: // it to the new value. sl@0: // sl@0: { sl@0: sl@0: SetCaptureKey(aHandle,aCaptureKey,0); sl@0: } sl@0: sl@0: EXPORT_C void CCaptureKeys::SetCaptureKey(TUint32 aHandle, const TCaptureKey& aCaptureKey, TUint8 aPriority) sl@0: // sl@0: // Finds the first capture-key from the list that matches the handle and sets sl@0: // it to the new value. sl@0: // sl@0: { sl@0: sl@0: TCaptureKey captureKey(aCaptureKey); sl@0: captureKey.iKeyCodePattern.iFiller = aPriority;// Priority is stored in spare data member 'iFiller' sl@0: CheckCaptureKey(captureKey); sl@0: TCaptureKey ck; sl@0: ck.iHandle=aHandle; sl@0: TInt r=iCKarray.Find(ck); sl@0: if (r>=0) sl@0: iCKarray[r]=captureKey; sl@0: } sl@0: sl@0: void CCaptureKeys::removeCaptureKey(TUint aIndex) sl@0: // sl@0: // Removes the capture-key at the given aIndex from the list sl@0: // sl@0: { sl@0: sl@0: iCKarray.Remove(aIndex); sl@0: } sl@0: sl@0: EXPORT_C void CCaptureKeys::CancelCaptureKey(TUint32 aHandle) sl@0: // sl@0: // Removes the first capture-key from the list that matches the handle; sl@0: // sl@0: { sl@0: sl@0: TCaptureKey ck; sl@0: ck.iHandle=aHandle; sl@0: TInt r=iCKarray.Find(ck); sl@0: if (r>=0) sl@0: iCKarray.Remove(r); sl@0: } sl@0: sl@0: EXPORT_C void CCaptureKeys::CancelAllCaptureKeys(TUint32 aApp) sl@0: // sl@0: // Removes all capture-keys from the list that match the given application handle sl@0: // sl@0: { sl@0: sl@0: TInt i=iCKarray.Count(); sl@0: while(--i>=0) sl@0: { sl@0: if (iCKarray[i].iApp==aApp) sl@0: iCKarray.Remove(i); sl@0: } sl@0: } sl@0: sl@0: EXPORT_C void CCaptureKeys::ProcessCaptureKeys(TKeyData& aKeyData) const sl@0: // sl@0: // Sets aKeyData.iIsCaptureKey to true if the given aKeyCode match a capture-key in the list sl@0: // and sets aKeyData.iApp to the handle of the last application that set it; sl@0: // otherwise sets aKeyData.iIsCaptureKey to false and aKeyData.iApp to 0. sl@0: // sl@0: { sl@0: sl@0: TCharExtended ch=aKeyData.iKeyCode; sl@0: aKeyData.iIsCaptureKey=EFalse; sl@0: aKeyData.iApp = 0x0; sl@0: TInt c=iCKarray.Count(); sl@0: TInt i; sl@0: TInt priority=KMinTInt; sl@0: for (i=0; ipriority) sl@0: { sl@0: priority=ck.iKeyCodePattern.iFiller; sl@0: aKeyData.iApp=ck.iApp; sl@0: aKeyData.iHandle=ck.iHandle; sl@0: aKeyData.iIsCaptureKey=ETrue; sl@0: } sl@0: } sl@0: } sl@0: } sl@0: