sl@0: // Copyright (c) 1995-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 "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: // sl@0: sl@0: // Capture key & hot key classes sl@0: // sl@0: #include sl@0: #include "server.h" sl@0: #include "windowgroup.h" sl@0: #include "EVENT.H" sl@0: #include "inifile.h" sl@0: sl@0: _LIT(KWsProtectedKey, "PROTECTEDKEY"); sl@0: _LIT(KWsProtectedWindowName, "PROTECTEDKEYWINDOWNAME"); sl@0: sl@0: TPriQue CWsCaptureKeyUpsAndDowns::iCaptureKeysUpsAndDowns(_FOFF(CWsCaptureKeyUpsAndDowns,iLink)); sl@0: TPriQue CWsCaptureLongKey::iCaptureLongKeys(_FOFF(CWsCaptureLongKey,iLink)); sl@0: sl@0: sl@0: /*CWsCaptureKey*/ sl@0: sl@0: CWsCaptureKey::CWsCaptureKey(CWsWindowGroup *aGroupWin) : CWsObject(aGroupWin?aGroupWin->WsOwner():NULL,WS_HANDLE_CAPTURE_KEY), iWindowGroup(aGroupWin) sl@0: {} sl@0: sl@0: CWsCaptureKey::~CWsCaptureKey() sl@0: { sl@0: TWindowServerEvent::CancelCaptureKey((TUint32)this); sl@0: } sl@0: sl@0: void CWsCaptureKey::CmdToParams(const TWsWinCmdCaptureKey &aCaptureKey, TCaptureKey &aParams) sl@0: { sl@0: aParams.iModifiers.iMask=aCaptureKey.modifierMask; sl@0: aParams.iModifiers.iValue=aCaptureKey.modifiers; sl@0: aParams.iKeyCodePattern.iKeyCode=(TInt16)aCaptureKey.key; sl@0: aParams.iKeyCodePattern.iPattern=EMatchKey; sl@0: aParams.iKeyCodePattern.iFiller=STATIC_CAST(TUint8,aCaptureKey.priority); sl@0: aParams.iApp=(TUint32)iWindowGroup; sl@0: aParams.iHandle=(TUint32)this; sl@0: } sl@0: sl@0: void CheckProtectedKeyL(CWsWindowGroup* aWindowGroup,const TWsWinCmdCaptureKey &aCaptureKey) sl@0: { sl@0: //The key specified in the WSINI file with the keyword: PROTECTEDKEY can only be captured sl@0: //by a group window with name specified with the PROTECTEDKEYWINDOWNAME keyword. sl@0: TInt protectedKey; sl@0: if(WsIniFile->FindVar(KWsProtectedKey,protectedKey)) sl@0: { sl@0: if (aCaptureKey.key == (TUint)protectedKey) sl@0: { sl@0: if (aWindowGroup->GroupName()==NULL) sl@0: { sl@0: User::Leave(KErrPermissionDenied); sl@0: } sl@0: sl@0: TPtrC wsProtectedWindowName; sl@0: WsIniFile->FindVar(KWsProtectedWindowName,wsProtectedWindowName); sl@0: if (aWindowGroup->GroupName()->Find(wsProtectedWindowName)==KErrNotFound) sl@0: { sl@0: User::Leave(KErrPermissionDenied); sl@0: } sl@0: } sl@0: } sl@0: } sl@0: sl@0: void CWsCaptureKey::ConstructL(const TWsWinCmdCaptureKey &aCaptureKey) sl@0: { sl@0: CheckProtectedKeyL(iWindowGroup, aCaptureKey); sl@0: NewObjL(); sl@0: TCaptureKey params; sl@0: CmdToParams(aCaptureKey, params); sl@0: TWindowServerEvent::AddCaptureKeyL(params); sl@0: } sl@0: sl@0: void CWsCaptureKey::SetL(const TWsWinCmdCaptureKey &aCaptureKey) sl@0: { sl@0: TCaptureKey params; sl@0: CmdToParams(aCaptureKey, params); sl@0: TWindowServerEvent::SetCaptureKey((TUint32)this, params); sl@0: } sl@0: sl@0: void CWsCaptureKey::CommandL(TInt , const TAny *) sl@0: { sl@0: } sl@0: sl@0: sl@0: /*CWsCaptureKeyUpsAndDowns*/ sl@0: sl@0: CWsCaptureKeyUpsAndDowns::CWsCaptureKeyUpsAndDowns(CWsWindowGroup *aGroupWin) : CWsObject(aGroupWin?aGroupWin->WsOwner():NULL,WS_HANDLE_CAPTURE_KEY_UPDOWNS), iWindowGroup(aGroupWin) sl@0: {} sl@0: sl@0: CWsCaptureKeyUpsAndDowns::~CWsCaptureKeyUpsAndDowns() sl@0: { sl@0: iLink.Deque(); sl@0: } sl@0: sl@0: void CWsCaptureKeyUpsAndDowns::ConstructL(const TWsWinCmdCaptureKey &aCaptureKey) sl@0: { sl@0: CheckProtectedKeyL(iWindowGroup, aCaptureKey); sl@0: NewObjL(); sl@0: iModifierMask=aCaptureKey.modifierMask; sl@0: iModifierValue=aCaptureKey.modifiers; sl@0: iScanCode=aCaptureKey.key; sl@0: iLink.iPriority=aCaptureKey.priority + 1; sl@0: iCaptureKeysUpsAndDowns.Add(*this); sl@0: --iLink.iPriority; sl@0: } sl@0: sl@0: void CWsCaptureKeyUpsAndDowns::CommandL(TInt , const TAny *) sl@0: { sl@0: } sl@0: sl@0: CWsWindowGroup *CWsCaptureKeyUpsAndDowns::CheckForCapture(TUint aScanCode, TUint aModifiers) sl@0: { sl@0: TDblQueIter iter(iCaptureKeysUpsAndDowns); sl@0: CWsCaptureKeyUpsAndDowns* cap; sl@0: while ((cap=iter++)!=NULL) sl@0: { sl@0: if (cap->iScanCode==aScanCode && (aModifiers&cap->iModifierMask)==cap->iModifierValue) sl@0: return(cap->iWindowGroup); sl@0: } sl@0: return NULL; sl@0: } sl@0: sl@0: sl@0: /*CWsCaptureLongKey*/ sl@0: sl@0: CWsCaptureLongKey::CWsCaptureLongKey(CWsWindowGroup *aGroupWin) sl@0: :CWsObject(aGroupWin?aGroupWin->WsOwner():NULL,WS_HANDLE_CAPTURE_LONG_KEY), iWindowGroup(aGroupWin) sl@0: {} sl@0: sl@0: CWsCaptureLongKey::~CWsCaptureLongKey() sl@0: { sl@0: iLink.Deque(); sl@0: } sl@0: sl@0: void CWsCaptureLongKey::ConstructL(const TWsWinCmdCaptureLongKey &aCaptureKey) sl@0: { sl@0: NewObjL(); sl@0: iData=aCaptureKey; sl@0: if (iData.delay.Int()<0) sl@0: { sl@0: TTimeIntervalMicroSeconds32 time; sl@0: CKeyboardRepeat::GetRepeatTime(iData.delay,time); sl@0: } sl@0: iLink.iPriority=iData.priority + 1; sl@0: iCaptureLongKeys.Add(*this); sl@0: --iLink.iPriority; sl@0: } sl@0: sl@0: void CWsCaptureLongKey::CommandL(TInt , const TAny *) sl@0: { sl@0: } sl@0: sl@0: CWsCaptureLongKey* CWsCaptureLongKey::CheckForCapture(TUint aKeyCode, TInt aModifiers) sl@0: { sl@0: TDblQueIter iter(iCaptureLongKeys); sl@0: CWsCaptureLongKey* longCapture; sl@0: while ((longCapture=iter++)!=NULL) sl@0: { sl@0: if (aKeyCode==longCapture->iData.inputKey && (aModifiers&longCapture->iData.modifierMask)==longCapture->iData.modifiers) sl@0: return longCapture; sl@0: } sl@0: return NULL; sl@0: }