windowing/windowserver/nga/SERVER/CAPKEY.CPP
changeset 0 5d03bc08d59c
child 116 171fae344dd4
equal deleted inserted replaced
-1:000000000000 0:5d03bc08d59c
       
     1 // Copyright (c) 1995-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 // Capture key & hot key classes
       
    17 //
       
    18 #include <e32std.h>
       
    19 #include "server.h"
       
    20 #include "windowgroup.h"
       
    21 #include "EVENT.H"
       
    22 #include "inifile.h"
       
    23 
       
    24 _LIT(KWsProtectedKey, "PROTECTEDKEY");
       
    25 _LIT(KWsProtectedWindowName, "PROTECTEDKEYWINDOWNAME");
       
    26 
       
    27 TPriQue<CWsCaptureKeyUpsAndDowns> CWsCaptureKeyUpsAndDowns::iCaptureKeysUpsAndDowns(_FOFF(CWsCaptureKeyUpsAndDowns,iLink));
       
    28 TPriQue<CWsCaptureLongKey> CWsCaptureLongKey::iCaptureLongKeys(_FOFF(CWsCaptureLongKey,iLink));
       
    29 
       
    30 
       
    31 /*CWsCaptureKey*/
       
    32 
       
    33 CWsCaptureKey::CWsCaptureKey(CWsWindowGroup *aGroupWin) : CWsObject(aGroupWin?aGroupWin->WsOwner():NULL,WS_HANDLE_CAPTURE_KEY), iWindowGroup(aGroupWin)
       
    34 	{}
       
    35 
       
    36 CWsCaptureKey::~CWsCaptureKey()
       
    37 	{
       
    38 	TWindowServerEvent::CancelCaptureKey((TUint32)this);
       
    39 	}
       
    40 
       
    41 void CWsCaptureKey::CmdToParams(const TWsWinCmdCaptureKey &aCaptureKey, TCaptureKey &aParams)
       
    42 	{
       
    43 	aParams.iModifiers.iMask=aCaptureKey.modifierMask;
       
    44 	aParams.iModifiers.iValue=aCaptureKey.modifiers;
       
    45 	aParams.iKeyCodePattern.iKeyCode=(TInt16)aCaptureKey.key;
       
    46 	aParams.iKeyCodePattern.iPattern=EMatchKey;
       
    47 	aParams.iKeyCodePattern.iFiller=STATIC_CAST(TUint8,aCaptureKey.priority);
       
    48 	aParams.iApp=(TUint32)iWindowGroup;
       
    49 	aParams.iHandle=(TUint32)this;
       
    50 	}
       
    51 
       
    52 void CheckProtectedKeyL(CWsWindowGroup* aWindowGroup,const TWsWinCmdCaptureKey &aCaptureKey)
       
    53 	{
       
    54 	//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.
       
    56 	TInt protectedKey;
       
    57 	if(WsIniFile->FindVar(KWsProtectedKey,protectedKey))
       
    58 		{
       
    59 		if (aCaptureKey.key == (TUint)protectedKey)
       
    60 			{
       
    61 			if (aWindowGroup->GroupName()==NULL)
       
    62 				{
       
    63 				User::Leave(KErrPermissionDenied);
       
    64 				}
       
    65 				
       
    66 			TPtrC wsProtectedWindowName;
       
    67 			WsIniFile->FindVar(KWsProtectedWindowName,wsProtectedWindowName);
       
    68 			if (aWindowGroup->GroupName()->Find(wsProtectedWindowName)==KErrNotFound)
       
    69 				{
       
    70 				User::Leave(KErrPermissionDenied);
       
    71 				}
       
    72 			}
       
    73 		}
       
    74 	}
       
    75 
       
    76 void CWsCaptureKey::ConstructL(const TWsWinCmdCaptureKey &aCaptureKey)
       
    77 	{
       
    78 	CheckProtectedKeyL(iWindowGroup, aCaptureKey);
       
    79 	NewObjL();
       
    80 	TCaptureKey params;
       
    81 	CmdToParams(aCaptureKey, params);
       
    82 	TWindowServerEvent::AddCaptureKeyL(params);
       
    83 	}
       
    84 
       
    85 void CWsCaptureKey::SetL(const TWsWinCmdCaptureKey &aCaptureKey)
       
    86 	{
       
    87 	TCaptureKey params;
       
    88 	CmdToParams(aCaptureKey, params);
       
    89 	TWindowServerEvent::SetCaptureKey((TUint32)this, params);
       
    90 	}
       
    91 
       
    92 void CWsCaptureKey::CommandL(TInt , const TAny *)
       
    93 	{
       
    94 	}
       
    95 
       
    96 
       
    97 /*CWsCaptureKeyUpsAndDowns*/
       
    98 
       
    99 CWsCaptureKeyUpsAndDowns::CWsCaptureKeyUpsAndDowns(CWsWindowGroup *aGroupWin) : CWsObject(aGroupWin?aGroupWin->WsOwner():NULL,WS_HANDLE_CAPTURE_KEY_UPDOWNS), iWindowGroup(aGroupWin)
       
   100 	{}
       
   101 
       
   102 CWsCaptureKeyUpsAndDowns::~CWsCaptureKeyUpsAndDowns()
       
   103 	{
       
   104 	iLink.Deque();
       
   105 	}
       
   106 
       
   107 void CWsCaptureKeyUpsAndDowns::ConstructL(const TWsWinCmdCaptureKey &aCaptureKey)
       
   108 	{
       
   109 	CheckProtectedKeyL(iWindowGroup, aCaptureKey);
       
   110 	NewObjL();
       
   111 	iModifierMask=aCaptureKey.modifierMask;
       
   112 	iModifierValue=aCaptureKey.modifiers;
       
   113 	iScanCode=aCaptureKey.key;
       
   114 	iLink.iPriority=aCaptureKey.priority + 1;
       
   115 	iCaptureKeysUpsAndDowns.Add(*this);
       
   116 	--iLink.iPriority;
       
   117 	}
       
   118 
       
   119 void CWsCaptureKeyUpsAndDowns::CommandL(TInt , const TAny *)
       
   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;
       
   133 	}
       
   134 
       
   135 
       
   136 /*CWsCaptureLongKey*/
       
   137 
       
   138 CWsCaptureLongKey::CWsCaptureLongKey(CWsWindowGroup *aGroupWin) 
       
   139 	:CWsObject(aGroupWin?aGroupWin->WsOwner():NULL,WS_HANDLE_CAPTURE_LONG_KEY), iWindowGroup(aGroupWin)
       
   140 	{}
       
   141 
       
   142 CWsCaptureLongKey::~CWsCaptureLongKey()
       
   143 	{
       
   144 	iLink.Deque();
       
   145 	}
       
   146 
       
   147 void CWsCaptureLongKey::ConstructL(const TWsWinCmdCaptureLongKey &aCaptureKey)
       
   148 	{
       
   149 	NewObjL();
       
   150 	iData=aCaptureKey;
       
   151 	if (iData.delay.Int()<0)
       
   152 		{
       
   153 		TTimeIntervalMicroSeconds32 time;
       
   154 		CKeyboardRepeat::GetRepeatTime(iData.delay,time);
       
   155 		}
       
   156 	iLink.iPriority=iData.priority + 1;
       
   157 	iCaptureLongKeys.Add(*this);
       
   158 	--iLink.iPriority;
       
   159 	}
       
   160 
       
   161 void CWsCaptureLongKey::CommandL(TInt , const TAny *)
       
   162 	{
       
   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 	}