windowing/windowserver/nga/SERVER/CAPKEY.CPP
changeset 116 171fae344dd4
parent 0 5d03bc08d59c
child 164 25ffed67c7ef
equal deleted inserted replaced
103:2717213c588a 116:171fae344dd4
     1 // Copyright (c) 1995-2009 Nokia Corporation and/or its subsidiary(-ies).
     1 // Copyright (c) 1995-2010 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 
       
    30 
    27 
    31 /*CWsCaptureKey*/
    28 /*CWsCaptureKey*/
    32 
    29 
    33 CWsCaptureKey::CWsCaptureKey(CWsWindowGroup *aGroupWin) : CWsObject(aGroupWin?aGroupWin->WsOwner():NULL,WS_HANDLE_CAPTURE_KEY), iWindowGroup(aGroupWin)
    30 CWsCaptureKey::CWsCaptureKey(CWsWindowGroup *aGroupWin) : CWsObject(aGroupWin?aGroupWin->WsOwner():NULL,WS_HANDLE_CAPTURE_KEY), iWindowGroup(aGroupWin)
    34 	{}
    31 	{}
    35 
    32 
    36 CWsCaptureKey::~CWsCaptureKey()
    33 CWsCaptureKey::~CWsCaptureKey()
    37 	{
    34 	{
    38 	TWindowServerEvent::CancelCaptureKey((TUint32)this);
    35 	TWindowServerEvent::CancelCaptureKey(ECaptureTypeKey, this);
    39 	}
    36 	}
    40 
    37 
    41 void CWsCaptureKey::CmdToParams(const TWsWinCmdCaptureKey &aCaptureKey, TCaptureKey &aParams)
    38 /**
    42 	{
    39 Convert a window server key capture command to a capture request for the
    43 	aParams.iModifiers.iMask=aCaptureKey.modifierMask;
    40 key routing plug-in.
    44 	aParams.iModifiers.iValue=aCaptureKey.modifiers;
    41 
    45 	aParams.iKeyCodePattern.iKeyCode=(TInt16)aCaptureKey.key;
    42 @param	aCaptureKey		Input capture command
    46 	aParams.iKeyCodePattern.iPattern=EMatchKey;
    43 @param	aRequest		Output capture request
    47 	aParams.iKeyCodePattern.iFiller=STATIC_CAST(TUint8,aCaptureKey.priority);
    44 */
    48 	aParams.iApp=(TUint32)iWindowGroup;
    45 void CWsCaptureKey::CmdToRequest(const TWsWinCmdCaptureKey &aCaptureKey, TKeyCaptureRequest &aRequest)
    49 	aParams.iHandle=(TUint32)this;
    46 	{
    50 	}
    47 	aRequest.iType = ECaptureTypeKey;
    51 
    48 	aRequest.iModifierMask = aCaptureKey.modifierMask;
       
    49 	aRequest.iModifiers = aCaptureKey.modifiers;
       
    50 	aRequest.iInputCode = aCaptureKey.key;
       
    51 	aRequest.iOutputCode = aCaptureKey.key;
       
    52 	aRequest.iPriority = aCaptureKey.priority;
       
    53 	aRequest.iWindowGroup = iWindowGroup;
       
    54 	aRequest.iWindowGroupId = iWindowGroup ? iWindowGroup->Identifier() : 0;
       
    55 	aRequest.iAppUid = iWsOwner ? TUid::Uid(iWsOwner->SecureId().iId) : KNullUid;
       
    56 	aRequest.iHandle = this;
       
    57 	}
       
    58 
       
    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 */
    52 void CheckProtectedKeyL(CWsWindowGroup* aWindowGroup,const TWsWinCmdCaptureKey &aCaptureKey)
    67 void CheckProtectedKeyL(CWsWindowGroup* aWindowGroup,const TWsWinCmdCaptureKey &aCaptureKey)
    53 	{
    68 	{
    54 	//The key specified in the WSINI file with the keyword: PROTECTEDKEY can only be captured 
    69 	//The key specified in the WSINI file with the keyword: PROTECTEDKEY can only be captured 
    55 	//by a group window with name specified with the PROTECTEDKEYWINDOWNAME keyword.
    70 	//by a group window with name specified with the PROTECTEDKEYWINDOWNAME keyword.
    56 	TInt protectedKey;
    71 	TInt protectedKey;
    57 	if(WsIniFile->FindVar(KWsProtectedKey,protectedKey))
    72 	if(WsIniFile->FindVar(KWsProtectedKey,protectedKey))
    58 		{
    73 		{
    59 		if (aCaptureKey.key == (TUint)protectedKey)
    74 		if (aCaptureKey.key == static_cast<TUint>(protectedKey))
    60 			{
    75 			{
    61 			if (aWindowGroup->GroupName()==NULL)
    76 			if (aWindowGroup->GroupName()==NULL)
    62 				{
    77 				{
    63 				User::Leave(KErrPermissionDenied);
    78 				User::Leave(KErrPermissionDenied);
    64 				}
    79 				}
    71 				}
    86 				}
    72 			}
    87 			}
    73 		}
    88 		}
    74 	}
    89 	}
    75 
    90 
       
    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 */
    76 void CWsCaptureKey::ConstructL(const TWsWinCmdCaptureKey &aCaptureKey)
    98 void CWsCaptureKey::ConstructL(const TWsWinCmdCaptureKey &aCaptureKey)
    77 	{
    99 	{
    78 	CheckProtectedKeyL(iWindowGroup, aCaptureKey);
   100 	CheckProtectedKeyL(iWindowGroup, aCaptureKey);
    79 	NewObjL();
   101 	NewObjL();
    80 	TCaptureKey params;
   102 
    81 	CmdToParams(aCaptureKey, params);
   103 	TKeyCaptureRequest request;
    82 	TWindowServerEvent::AddCaptureKeyL(params);
   104 	CmdToRequest(aCaptureKey, request);
    83 	}
   105 	TWindowServerEvent::AddCaptureKeyL(request);
    84 
   106 	}
       
   107 
       
   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 */
    85 void CWsCaptureKey::SetL(const TWsWinCmdCaptureKey &aCaptureKey)
   116 void CWsCaptureKey::SetL(const TWsWinCmdCaptureKey &aCaptureKey)
    86 	{
   117 	{
    87 	TCaptureKey params;
   118 	TKeyCaptureRequest request;
    88 	CmdToParams(aCaptureKey, params);
   119 	CmdToRequest(aCaptureKey, request);
    89 	TWindowServerEvent::SetCaptureKey((TUint32)this, params);
   120 	TWindowServerEvent::UpdateCaptureKeyL(request);
    90 	}
   121 	}
    91 
   122 
    92 void CWsCaptureKey::CommandL(TInt , const TAny *)
   123 void CWsCaptureKey::CommandL(TInt , const TAny *)
    93 	{
   124 	{
    94 	}
   125 	}
    99 CWsCaptureKeyUpsAndDowns::CWsCaptureKeyUpsAndDowns(CWsWindowGroup *aGroupWin) : CWsObject(aGroupWin?aGroupWin->WsOwner():NULL,WS_HANDLE_CAPTURE_KEY_UPDOWNS), iWindowGroup(aGroupWin)
   130 CWsCaptureKeyUpsAndDowns::CWsCaptureKeyUpsAndDowns(CWsWindowGroup *aGroupWin) : CWsObject(aGroupWin?aGroupWin->WsOwner():NULL,WS_HANDLE_CAPTURE_KEY_UPDOWNS), iWindowGroup(aGroupWin)
   100 	{}
   131 	{}
   101 
   132 
   102 CWsCaptureKeyUpsAndDowns::~CWsCaptureKeyUpsAndDowns()
   133 CWsCaptureKeyUpsAndDowns::~CWsCaptureKeyUpsAndDowns()
   103 	{
   134 	{
   104 	iLink.Deque();
   135 	TWindowServerEvent::CancelCaptureKey(ECaptureTypeKeyUpDown, this);
   105 	}
   136 	}
   106 
   137 
       
   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 */
   107 void CWsCaptureKeyUpsAndDowns::ConstructL(const TWsWinCmdCaptureKey &aCaptureKey)
   145 void CWsCaptureKeyUpsAndDowns::ConstructL(const TWsWinCmdCaptureKey &aCaptureKey)
   108 	{
   146 	{
   109 	CheckProtectedKeyL(iWindowGroup, aCaptureKey);
   147 	CheckProtectedKeyL(iWindowGroup, aCaptureKey);
   110 	NewObjL();
   148 	NewObjL();
   111 	iModifierMask=aCaptureKey.modifierMask;
   149 
   112 	iModifierValue=aCaptureKey.modifiers;
   150 	TKeyCaptureRequest request;
   113 	iScanCode=aCaptureKey.key;
   151 	request.iType = ECaptureTypeKeyUpDown;
   114 	iLink.iPriority=aCaptureKey.priority + 1;
   152 	request.iInputCode = aCaptureKey.key;
   115 	iCaptureKeysUpsAndDowns.Add(*this);
   153 	request.iOutputCode = aCaptureKey.key;
   116 	--iLink.iPriority;
   154 	request.iModifiers = aCaptureKey.modifiers;
       
   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);
   117 	}
   162 	}
   118 
   163 
   119 void CWsCaptureKeyUpsAndDowns::CommandL(TInt , const TAny *)
   164 void CWsCaptureKeyUpsAndDowns::CommandL(TInt , const TAny *)
   120 	{
   165 	{
   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;
       
   133 	}
   166 	}
   134 
   167 
   135 
   168 
   136 /*CWsCaptureLongKey*/
   169 /*CWsCaptureLongKey*/
   137 
   170 
   139 	:CWsObject(aGroupWin?aGroupWin->WsOwner():NULL,WS_HANDLE_CAPTURE_LONG_KEY), iWindowGroup(aGroupWin)
   172 	:CWsObject(aGroupWin?aGroupWin->WsOwner():NULL,WS_HANDLE_CAPTURE_LONG_KEY), iWindowGroup(aGroupWin)
   140 	{}
   173 	{}
   141 
   174 
   142 CWsCaptureLongKey::~CWsCaptureLongKey()
   175 CWsCaptureLongKey::~CWsCaptureLongKey()
   143 	{
   176 	{
   144 	iLink.Deque();
   177 	TWindowServerEvent::CancelCaptureKey(ECaptureTypeLongKey, this);
   145 	}
   178 	}
   146 
   179 
       
   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 */
   147 void CWsCaptureLongKey::ConstructL(const TWsWinCmdCaptureLongKey &aCaptureKey)
   186 void CWsCaptureLongKey::ConstructL(const TWsWinCmdCaptureLongKey &aCaptureKey)
   148 	{
   187 	{
   149 	NewObjL();
   188 	NewObjL();
   150 	iData=aCaptureKey;
   189 	iFlags = aCaptureKey.flags;
   151 	if (iData.delay.Int()<0)
   190 	iDelay = aCaptureKey.delay;
       
   191 	if (iDelay.Int() < 0)
   152 		{
   192 		{
   153 		TTimeIntervalMicroSeconds32 time;
   193 		TTimeIntervalMicroSeconds32 time;
   154 		CKeyboardRepeat::GetRepeatTime(iData.delay,time);
   194 		CKeyboardRepeat::GetRepeatTime(iDelay, time);
   155 		}
   195 		}
   156 	iLink.iPriority=iData.priority + 1;
   196 
   157 	iCaptureLongKeys.Add(*this);
   197 	TKeyCaptureRequest request;
   158 	--iLink.iPriority;
   198 	request.iType = ECaptureTypeLongKey;
       
   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);
   159 	}
   209 	}
   160 
   210 
   161 void CWsCaptureLongKey::CommandL(TInt , const TAny *)
   211 void CWsCaptureLongKey::CommandL(TInt , const TAny *)
   162 	{
   212 	{
   163 	}
   213 	}
   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 	}