windowing/windowserver/nga/SERVER/CAPKEY.CPP
branchRCL_3
changeset 164 25ffed67c7ef
parent 163 bbf46f59e123
equal deleted inserted replaced
163:bbf46f59e123 164:25ffed67c7ef
     1 // Copyright (c) 1995-2010 Nokia Corporation and/or its subsidiary(-ies).
     1 // Copyright (c) 1995-2009 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     3 // This component and the accompanying materials are made available
     4 // under the terms of "Eclipse Public License v1.0"
     4 // under the terms of "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
    22 #include "inifile.h"
    22 #include "inifile.h"
    23 
    23 
    24 _LIT(KWsProtectedKey, "PROTECTEDKEY");
    24 _LIT(KWsProtectedKey, "PROTECTEDKEY");
    25 _LIT(KWsProtectedWindowName, "PROTECTEDKEYWINDOWNAME");
    25 _LIT(KWsProtectedWindowName, "PROTECTEDKEYWINDOWNAME");
    26 
    26 
       
    27 TPriQue<CWsCaptureKeyUpsAndDowns> CWsCaptureKeyUpsAndDowns::iCaptureKeysUpsAndDowns(_FOFF(CWsCaptureKeyUpsAndDowns,iLink));
       
    28 TPriQue<CWsCaptureLongKey> CWsCaptureLongKey::iCaptureLongKeys(_FOFF(CWsCaptureLongKey,iLink));
       
    29 
    27 
    30 
    28 /*CWsCaptureKey*/
    31 /*CWsCaptureKey*/
    29 
    32 
    30 CWsCaptureKey::CWsCaptureKey(CWsWindowGroup *aGroupWin) : CWsObject(aGroupWin?aGroupWin->WsOwner():NULL,WS_HANDLE_CAPTURE_KEY), iWindowGroup(aGroupWin)
    33 CWsCaptureKey::CWsCaptureKey(CWsWindowGroup *aGroupWin) : CWsObject(aGroupWin?aGroupWin->WsOwner():NULL,WS_HANDLE_CAPTURE_KEY), iWindowGroup(aGroupWin)
    31 	{}
    34 	{}
    32 
    35 
    33 CWsCaptureKey::~CWsCaptureKey()
    36 CWsCaptureKey::~CWsCaptureKey()
    34 	{
    37 	{
    35 	TWindowServerEvent::CancelCaptureKey(ECaptureTypeKey, this);
    38 	TWindowServerEvent::CancelCaptureKey((TUint32)this);
    36 	}
    39 	}
    37 
    40 
    38 /**
    41 void CWsCaptureKey::CmdToParams(const TWsWinCmdCaptureKey &aCaptureKey, TCaptureKey &aParams)
    39 Convert a window server key capture command to a capture request for the
       
    40 key routing plug-in.
       
    41 
       
    42 @param	aCaptureKey		Input capture command
       
    43 @param	aRequest		Output capture request
       
    44 */
       
    45 void CWsCaptureKey::CmdToRequest(const TWsWinCmdCaptureKey &aCaptureKey, TKeyCaptureRequest &aRequest)
       
    46 	{
    42 	{
    47 	aRequest.iType = ECaptureTypeKey;
    43 	aParams.iModifiers.iMask=aCaptureKey.modifierMask;
    48 	aRequest.iModifierMask = aCaptureKey.modifierMask;
    44 	aParams.iModifiers.iValue=aCaptureKey.modifiers;
    49 	aRequest.iModifiers = aCaptureKey.modifiers;
    45 	aParams.iKeyCodePattern.iKeyCode=(TInt16)aCaptureKey.key;
    50 	aRequest.iInputCode = aCaptureKey.key;
    46 	aParams.iKeyCodePattern.iPattern=EMatchKey;
    51 	aRequest.iOutputCode = aCaptureKey.key;
    47 	aParams.iKeyCodePattern.iFiller=STATIC_CAST(TUint8,aCaptureKey.priority);
    52 	aRequest.iPriority = aCaptureKey.priority;
    48 	aParams.iApp=(TUint32)iWindowGroup;
    53 	aRequest.iWindowGroup = iWindowGroup;
    49 	aParams.iHandle=(TUint32)this;
    54 	aRequest.iWindowGroupId = iWindowGroup ? iWindowGroup->Identifier() : 0;
       
    55 	aRequest.iAppUid = iWsOwner ? TUid::Uid(iWsOwner->SecureId().iId) : KNullUid;
       
    56 	aRequest.iHandle = this;
       
    57 	}
    50 	}
    58 
    51 
    59 /**
       
    60 Check for protected key in a capture command
       
    61 
       
    62 @param	aWindowGroup	Window Group of capture request
       
    63 @param	aCaptureKey		Key capture command
       
    64 
       
    65 @leave KErrPermissionDenied		Capture key is protected
       
    66 */
       
    67 void CheckProtectedKeyL(CWsWindowGroup* aWindowGroup,const TWsWinCmdCaptureKey &aCaptureKey)
    52 void CheckProtectedKeyL(CWsWindowGroup* aWindowGroup,const TWsWinCmdCaptureKey &aCaptureKey)
    68 	{
    53 	{
    69 	//The key specified in the WSINI file with the keyword: PROTECTEDKEY can only be captured 
    54 	//The key specified in the WSINI file with the keyword: PROTECTEDKEY can only be captured 
    70 	//by a group window with name specified with the PROTECTEDKEYWINDOWNAME keyword.
    55 	//by a group window with name specified with the PROTECTEDKEYWINDOWNAME keyword.
    71 	TInt protectedKey;
    56 	TInt protectedKey;
    72 	if(WsIniFile->FindVar(KWsProtectedKey,protectedKey))
    57 	if(WsIniFile->FindVar(KWsProtectedKey,protectedKey))
    73 		{
    58 		{
    74 		if (aCaptureKey.key == static_cast<TUint>(protectedKey))
    59 		if (aCaptureKey.key == (TUint)protectedKey)
    75 			{
    60 			{
    76 			if (aWindowGroup->GroupName()==NULL)
    61 			if (aWindowGroup->GroupName()==NULL)
    77 				{
    62 				{
    78 				User::Leave(KErrPermissionDenied);
    63 				User::Leave(KErrPermissionDenied);
    79 				}
    64 				}
    86 				}
    71 				}
    87 			}
    72 			}
    88 		}
    73 		}
    89 	}
    74 	}
    90 
    75 
    91 /**
       
    92 Construct a capture object for normal key events and make a capture request
       
    93 to the key routing plug-in.
       
    94 
       
    95 @param	aCaptureKey		Key capture command from RWindowGroup::CaptureKey(),
       
    96 						RWsSession::SetHotKey() or default hot key settings.
       
    97 */
       
    98 void CWsCaptureKey::ConstructL(const TWsWinCmdCaptureKey &aCaptureKey)
    76 void CWsCaptureKey::ConstructL(const TWsWinCmdCaptureKey &aCaptureKey)
    99 	{
    77 	{
   100 	CheckProtectedKeyL(iWindowGroup, aCaptureKey);
    78 	CheckProtectedKeyL(iWindowGroup, aCaptureKey);
   101 	NewObjL();
    79 	NewObjL();
   102 
    80 	TCaptureKey params;
   103 	TKeyCaptureRequest request;
    81 	CmdToParams(aCaptureKey, params);
   104 	CmdToRequest(aCaptureKey, request);
    82 	TWindowServerEvent::AddCaptureKeyL(params);
   105 	TWindowServerEvent::AddCaptureKeyL(request);
       
   106 	}
    83 	}
   107 
    84 
   108 /**
       
   109 Make a capture request update for normal key events to the key routing plug-in.
       
   110 
       
   111 @param	aCaptureKey		Key capture command from CWsHotKey::SetL()
       
   112 
       
   113 Note: this function is used only to disable hot key capture requests or to
       
   114 reset them to their defaults.
       
   115 */
       
   116 void CWsCaptureKey::SetL(const TWsWinCmdCaptureKey &aCaptureKey)
    85 void CWsCaptureKey::SetL(const TWsWinCmdCaptureKey &aCaptureKey)
   117 	{
    86 	{
   118 	TKeyCaptureRequest request;
    87 	TCaptureKey params;
   119 	CmdToRequest(aCaptureKey, request);
    88 	CmdToParams(aCaptureKey, params);
   120 	TWindowServerEvent::UpdateCaptureKeyL(request);
    89 	TWindowServerEvent::SetCaptureKey((TUint32)this, params);
   121 	}
    90 	}
   122 
    91 
   123 void CWsCaptureKey::CommandL(TInt , const TAny *)
    92 void CWsCaptureKey::CommandL(TInt , const TAny *)
   124 	{
    93 	{
   125 	}
    94 	}
   130 CWsCaptureKeyUpsAndDowns::CWsCaptureKeyUpsAndDowns(CWsWindowGroup *aGroupWin) : CWsObject(aGroupWin?aGroupWin->WsOwner():NULL,WS_HANDLE_CAPTURE_KEY_UPDOWNS), iWindowGroup(aGroupWin)
    99 CWsCaptureKeyUpsAndDowns::CWsCaptureKeyUpsAndDowns(CWsWindowGroup *aGroupWin) : CWsObject(aGroupWin?aGroupWin->WsOwner():NULL,WS_HANDLE_CAPTURE_KEY_UPDOWNS), iWindowGroup(aGroupWin)
   131 	{}
   100 	{}
   132 
   101 
   133 CWsCaptureKeyUpsAndDowns::~CWsCaptureKeyUpsAndDowns()
   102 CWsCaptureKeyUpsAndDowns::~CWsCaptureKeyUpsAndDowns()
   134 	{
   103 	{
   135 	TWindowServerEvent::CancelCaptureKey(ECaptureTypeKeyUpDown, this);
   104 	iLink.Deque();
   136 	}
   105 	}
   137 
   106 
   138 /**
       
   139 Construct a capture object for up/down key events and make a capture request
       
   140 to the key routing plug-in.
       
   141 
       
   142 @param	aCaptureKey		Key capture command from
       
   143 						RWindowGroup::CaptureKeyUpAndDowns().
       
   144 */
       
   145 void CWsCaptureKeyUpsAndDowns::ConstructL(const TWsWinCmdCaptureKey &aCaptureKey)
   107 void CWsCaptureKeyUpsAndDowns::ConstructL(const TWsWinCmdCaptureKey &aCaptureKey)
   146 	{
   108 	{
   147 	CheckProtectedKeyL(iWindowGroup, aCaptureKey);
   109 	CheckProtectedKeyL(iWindowGroup, aCaptureKey);
   148 	NewObjL();
   110 	NewObjL();
   149 
   111 	iModifierMask=aCaptureKey.modifierMask;
   150 	TKeyCaptureRequest request;
   112 	iModifierValue=aCaptureKey.modifiers;
   151 	request.iType = ECaptureTypeKeyUpDown;
   113 	iScanCode=aCaptureKey.key;
   152 	request.iInputCode = aCaptureKey.key;
   114 	iLink.iPriority=aCaptureKey.priority + 1;
   153 	request.iOutputCode = aCaptureKey.key;
   115 	iCaptureKeysUpsAndDowns.Add(*this);
   154 	request.iModifiers = aCaptureKey.modifiers;
   116 	--iLink.iPriority;
   155 	request.iModifierMask = aCaptureKey.modifierMask;
       
   156 	request.iPriority = aCaptureKey.priority;
       
   157 	request.iWindowGroup = iWindowGroup;
       
   158 	request.iWindowGroupId = iWindowGroup ? iWindowGroup->Identifier() : 0;
       
   159 	request.iAppUid = iWsOwner ? TUid::Uid(iWsOwner->SecureId().iId) : KNullUid;
       
   160 	request.iHandle = this;
       
   161 	TWindowServerEvent::AddCaptureKeyL(request);
       
   162 	}
   117 	}
   163 
   118 
   164 void CWsCaptureKeyUpsAndDowns::CommandL(TInt , const TAny *)
   119 void CWsCaptureKeyUpsAndDowns::CommandL(TInt , const TAny *)
   165 	{
   120 	{
       
   121 	}
       
   122 
       
   123 CWsWindowGroup *CWsCaptureKeyUpsAndDowns::CheckForCapture(TUint aScanCode, TUint aModifiers)
       
   124 	{
       
   125 	TDblQueIter<CWsCaptureKeyUpsAndDowns> iter(iCaptureKeysUpsAndDowns);
       
   126 	CWsCaptureKeyUpsAndDowns* cap;
       
   127 	while ((cap=iter++)!=NULL)
       
   128 		{
       
   129 		if (cap->iScanCode==aScanCode && (aModifiers&cap->iModifierMask)==cap->iModifierValue)
       
   130 			return(cap->iWindowGroup);
       
   131 		}
       
   132 	return NULL;
   166 	}
   133 	}
   167 
   134 
   168 
   135 
   169 /*CWsCaptureLongKey*/
   136 /*CWsCaptureLongKey*/
   170 
   137 
   172 	:CWsObject(aGroupWin?aGroupWin->WsOwner():NULL,WS_HANDLE_CAPTURE_LONG_KEY), iWindowGroup(aGroupWin)
   139 	:CWsObject(aGroupWin?aGroupWin->WsOwner():NULL,WS_HANDLE_CAPTURE_LONG_KEY), iWindowGroup(aGroupWin)
   173 	{}
   140 	{}
   174 
   141 
   175 CWsCaptureLongKey::~CWsCaptureLongKey()
   142 CWsCaptureLongKey::~CWsCaptureLongKey()
   176 	{
   143 	{
   177 	TWindowServerEvent::CancelCaptureKey(ECaptureTypeLongKey, this);
   144 	iLink.Deque();
   178 	}
   145 	}
   179 
   146 
   180 /**
       
   181 Construct a capture object for long key events and make a capture request
       
   182 to the key routing plug-in.
       
   183 
       
   184 @param	aCaptureKey		Key capture command from RWindowGroup::CaptureLongKey()
       
   185 */
       
   186 void CWsCaptureLongKey::ConstructL(const TWsWinCmdCaptureLongKey &aCaptureKey)
   147 void CWsCaptureLongKey::ConstructL(const TWsWinCmdCaptureLongKey &aCaptureKey)
   187 	{
   148 	{
   188 	NewObjL();
   149 	NewObjL();
   189 	iFlags = aCaptureKey.flags;
   150 	iData=aCaptureKey;
   190 	iDelay = aCaptureKey.delay;
   151 	if (iData.delay.Int()<0)
   191 	if (iDelay.Int() < 0)
       
   192 		{
   152 		{
   193 		TTimeIntervalMicroSeconds32 time;
   153 		TTimeIntervalMicroSeconds32 time;
   194 		CKeyboardRepeat::GetRepeatTime(iDelay, time);
   154 		CKeyboardRepeat::GetRepeatTime(iData.delay,time);
   195 		}
   155 		}
   196 
   156 	iLink.iPriority=iData.priority + 1;
   197 	TKeyCaptureRequest request;
   157 	iCaptureLongKeys.Add(*this);
   198 	request.iType = ECaptureTypeLongKey;
   158 	--iLink.iPriority;
   199 	request.iInputCode = aCaptureKey.inputKey;
       
   200 	request.iOutputCode = aCaptureKey.outputKey;
       
   201 	request.iModifiers = aCaptureKey.modifiers;
       
   202 	request.iModifierMask = aCaptureKey.modifierMask;
       
   203 	request.iPriority = aCaptureKey.priority;
       
   204 	request.iWindowGroup = iWindowGroup;
       
   205 	request.iWindowGroupId = iWindowGroup ? iWindowGroup->Identifier() : 0;
       
   206 	request.iAppUid = iWsOwner ? TUid::Uid(iWsOwner->SecureId().iId) : KNullUid;
       
   207 	request.iHandle = this;
       
   208 	TWindowServerEvent::AddCaptureKeyL(request);
       
   209 	}
   159 	}
   210 
   160 
   211 void CWsCaptureLongKey::CommandL(TInt , const TAny *)
   161 void CWsCaptureLongKey::CommandL(TInt , const TAny *)
   212 	{
   162 	{
   213 	}
   163 	}
       
   164 
       
   165 CWsCaptureLongKey* CWsCaptureLongKey::CheckForCapture(TUint aKeyCode, TInt aModifiers)
       
   166 	{
       
   167 	TDblQueIter<CWsCaptureLongKey> iter(iCaptureLongKeys);
       
   168 	CWsCaptureLongKey* longCapture;
       
   169 	while ((longCapture=iter++)!=NULL)
       
   170 		{
       
   171 		if (aKeyCode==longCapture->iData.inputKey && (aModifiers&longCapture->iData.modifierMask)==longCapture->iData.modifiers)
       
   172 			return longCapture;
       
   173 		}
       
   174 	return NULL;
       
   175 	}