windowing/windowserver/nonnga/SERVER/KEYBEMUL.CPP
changeset 0 5d03bc08d59c
equal deleted inserted replaced
-1:000000000000 0:5d03bc08d59c
       
     1 // Copyright (c) 1996-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 // Emulte key presses on pointer events
       
    15 // 
       
    16 //
       
    17 
       
    18 #include <e32std.h>
       
    19 #include <e32hal.h>
       
    20 #include "server.h"
       
    21 #include "EVENT.H"
       
    22 
       
    23 TInt WsKeyboardEmulator::iCurrentKeyDown;
       
    24 TBool WsKeyboardEmulator::iKeyIsDown=EFalse;
       
    25 
       
    26 void WsKeyboardEmulator::RawKeyEvent(TRawEvent::TType aType)
       
    27 	{
       
    28 	if (aType==TRawEvent::EKeyUp)
       
    29 		iKeyIsDown=EFalse;
       
    30 	else
       
    31 		iKeyIsDown=ETrue;
       
    32 	TRawEvent rawEvent;
       
    33 	rawEvent.Set(aType,iCurrentKeyDown);
       
    34 	TWindowServerEvent::ProcessRawEvent(rawEvent);
       
    35 	}
       
    36 
       
    37 TBool WsKeyboardEmulator::PointerEvent(TPointerEvent::TType aPointerEventType,const TPoint &aPoint, TDblQue<TPointerKeyList> *aKeyList)
       
    38 	{
       
    39 	if (iKeyIsDown && (aPointerEventType==TPointerEvent::EButton1Up))
       
    40 		RawKeyEvent(TRawEvent::EKeyUp);
       
    41 	else if (!aKeyList)
       
    42 		return(EFalse);
       
    43 	else
       
    44 		{
       
    45 		TPointerKeyList *pkl=NULL;
       
    46 		for(TDblQueIter<TPointerKeyList> iter(*aKeyList);(pkl=iter++)!=NULL;)
       
    47 			if (pkl->iRect.Contains(aPoint))
       
    48 				break;
       
    49 		if (iKeyIsDown && aPointerEventType==TPointerEvent::EDrag && (!pkl || iCurrentKeyDown!=pkl->iScanCode))
       
    50 			RawKeyEvent(TRawEvent::EKeyUp);
       
    51 		else if (pkl)
       
    52 			{
       
    53 			if (aPointerEventType==TPointerEvent::EButton1Down ||
       
    54 			    (aPointerEventType==TPointerEvent::ESwitchOn && pkl->iActivatedByPointerSwitchOn))
       
    55 				{
       
    56 				if (iKeyIsDown)
       
    57 					RawKeyEvent(TRawEvent::EKeyUp);
       
    58 				iCurrentKeyDown=pkl->iScanCode;
       
    59 				RawKeyEvent(TRawEvent::EKeyDown);
       
    60 				if (aPointerEventType==TPointerEvent::ESwitchOn)
       
    61 					RawKeyEvent(TRawEvent::EKeyUp);
       
    62 				}
       
    63 			}
       
    64 		else
       
    65 			return(EFalse);
       
    66 		}
       
    67 	return(ETrue);
       
    68 	}
       
    69