windowing/windowserver/nonnga/SERVER/EVENT.CPP
changeset 0 5d03bc08d59c
child 26 15986eb6c500
child 80 823021ef148e
equal deleted inserted replaced
-1:000000000000 0:5d03bc08d59c
       
     1 // Copyright (c) 1994-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 // Top level window server code
       
    15 // 
       
    16 //
       
    17 
       
    18 #include "EVENT.H"
       
    19 
       
    20 #include <hal.h>
       
    21 #include <w32adll.h>
       
    22 #include <w32click.h>
       
    23 #include "server.h"
       
    24 #include "windowgroup.h"
       
    25 #include "KEYCLICK.H"
       
    26 #include "wstop.h"
       
    27 #include "panics.h"
       
    28 #include "screen.h"
       
    29 #include "inifile.h"
       
    30 #include "password.h"
       
    31 #include <w32std.h>
       
    32 #include "pointer.h"
       
    33 #include "debugbar.h"
       
    34 #include "wstraces.h"
       
    35 
       
    36 GLREF_D CDebugLogBase *wsDebugLog;
       
    37 
       
    38 GLREF_C void StateDump();
       
    39 GLREF_C void HeapDump();
       
    40 
       
    41 #define IMPOSSIBLE 0xFFFFFFFF
       
    42 
       
    43 const TWsWinCmdCaptureKey ImpossibleKeyPress=
       
    44 	{
       
    45 	IMPOSSIBLE,	// Impossible to hit key combination, used for disabling Hot Keys
       
    46 	IMPOSSIBLE,
       
    47 	IMPOSSIBLE};
       
    48 
       
    49 const TWsWinCmdCaptureKey DefaultHotKeys[TWindowServerEvent::ENumHotKeys]={
       
    50 	{	// Enable logging
       
    51 	EModifierFunc|EModifierCtrl|EModifierShift,
       
    52 	EModifierFunc|EModifierCtrl|EModifierShift,
       
    53 	5}, // E
       
    54 	{	// Disable logging
       
    55 	EModifierFunc|EModifierCtrl|EModifierShift,
       
    56 	EModifierFunc|EModifierCtrl|EModifierShift,
       
    57 	4}, // D
       
    58 	{	// Window server internal dump to log
       
    59 	EModifierFunc|EModifierCtrl|EModifierShift,
       
    60 	EModifierFunc|EModifierCtrl|EModifierShift,
       
    61 	23},// W
       
    62 	{	// The key of death
       
    63 	EModifierFunc|EModifierCtrl|EModifierShift,
       
    64 	EModifierFunc|EModifierCtrl|EModifierShift,
       
    65 	11},// K
       
    66 	{	// Shutdown window server
       
    67 #if defined(_DEBUG)
       
    68 	EModifierFunc|EModifierCtrl|EModifierShift,
       
    69 	EModifierFunc|EModifierCtrl|EModifierShift,
       
    70 	24},// X
       
    71 #else
       
    72 	IMPOSSIBLE,	// Impossible to hit key combination, effectively disables shutdown key in release builds
       
    73 	IMPOSSIBLE,
       
    74 	IMPOSSIBLE},
       
    75 #endif
       
    76 	{	// Heap dump
       
    77 	EModifierFunc|EModifierCtrl|EModifierShift,
       
    78 	EModifierFunc|EModifierCtrl|EModifierShift,
       
    79 	8}, // H
       
    80 	{	// Inc Contrast
       
    81 	0,
       
    82 	0,
       
    83 	EKeyIncContrast},
       
    84 	{	// Dec Contrast
       
    85 	0,
       
    86 	0,
       
    87 	EKeyDecContrast},
       
    88 	{	// Off
       
    89 	0,
       
    90 	0,
       
    91 	EKeyOff},
       
    92 	{	// Backlight on 
       
    93 	0,
       
    94 	0,
       
    95 	EKeyBacklightOn},
       
    96 	{	// Backlight off
       
    97 	0,
       
    98 	0,
       
    99 	EKeyBacklightOff},
       
   100 	{	// Backlight toggle
       
   101 	0,
       
   102 	0,
       
   103 	EKeyBacklightToggle},
       
   104 	{	// Screen Dimension Change
       
   105 	0,
       
   106 	0,
       
   107 	EKeyScreenDimension0},
       
   108 	{
       
   109 	0,
       
   110 	0,
       
   111 	EKeyScreenDimension1},
       
   112 	{
       
   113 	0,
       
   114 	0,
       
   115 	EKeyScreenDimension2},
       
   116 	{
       
   117 	0,
       
   118 	0,
       
   119 	EKeyScreenDimension3},
       
   120 #if defined(_DEBUG)
       
   121 	{	// Display mode cycle
       
   122 	EModifierFunc|EModifierCtrl|EModifierShift,
       
   123 	EModifierFunc|EModifierCtrl|EModifierShift,
       
   124 	21},// U
       
   125 	{	// Orientation cycle
       
   126 	EModifierFunc|EModifierCtrl|EModifierShift,
       
   127 	EModifierFunc|EModifierCtrl|EModifierShift,
       
   128 	15},// O
       
   129 #else
       
   130 	{	// Display mode cycle
       
   131 	IMPOSSIBLE,	// Impossible to hit key combination
       
   132 	IMPOSSIBLE,
       
   133 	IMPOSSIBLE},
       
   134 	{	// Orientation cycle
       
   135 	IMPOSSIBLE,	// Impossible to hit key combination
       
   136 	IMPOSSIBLE,
       
   137 	IMPOSSIBLE},
       
   138 #endif
       
   139 	{	// Inc Brightness
       
   140 	0,
       
   141 	0,
       
   142 	EKeyIncBrightness},
       
   143 	{	// Dec Brightness
       
   144 	0,
       
   145 	0,
       
   146 	EKeyDecBrightness},
       
   147 	{	// Cycle focus screen
       
   148 	EModifierFunc|EModifierCtrl|EModifierShift,
       
   149 	EModifierFunc|EModifierCtrl|EModifierShift,
       
   150 	9}, // I
       
   151 	};
       
   152 
       
   153 CKeyTranslator *TWindowServerEvent::iKeyTranslator=NULL;
       
   154 TEventRequestQueue TWindowServerEvent::iSwitchOnQueue;
       
   155 TEventRequestQueue TWindowServerEvent::iErrorMessageQueue;
       
   156 TEventRequestQueue TWindowServerEvent::iModifierChangedQueue;
       
   157 TEventRequestQueue TWindowServerEvent::iGroupChangedQueue;
       
   158 TEventRequestQueue TWindowServerEvent::iFocusChangedQueue;
       
   159 TEventRequestQueue TWindowServerEvent::iGroupListChangedQueue;
       
   160 TEventRequestQueue TWindowServerEvent::iScreenDeviceChangedQueue;
       
   161 TTime TWindowServerEvent::iPrevOomMessageTime;
       
   162 CCaptureKeys *TWindowServerEvent::iCaptureKeys;
       
   163 CWsHotKey *TWindowServerEvent::iHotKeys;
       
   164 TInt TWindowServerEvent::iModifierState;
       
   165 CRawEventReceiver *TWindowServerEvent::iEventReceiver;
       
   166 CArrayPtrFlat<MEventHandler> *TWindowServerEvent::iEventHandlers;
       
   167 CArrayFixFlat<SNotificationHandler> *TWindowServerEvent::iNotificationHandlers;
       
   168 TInt TWindowServerEvent::iPotentialEventHandlers=0;
       
   169 TUint32 TWindowServerEvent::iBinaryFlags=0x00;
       
   170 RArray<TDrawerHandler>* TWindowServerEvent::iDrawerHandlers;
       
   171 RArray<TWsEventHandler> TWindowServerEvent::iWsEventHandlers;
       
   172 TInt TWindowServerEvent::iEventHandlerCount=0;
       
   173 TRepeatKey CKeyboardRepeat::iCurrentRepeat;
       
   174 TRepeatKey CKeyboardRepeat::iAlternateRepeat;
       
   175 TInt CKeyboardRepeat::iRepeatRollover=1;
       
   176 CKeyboardRepeat::TRepeatType CKeyboardRepeat::iRepeating=ERepeatNone;
       
   177 CKeyboardRepeat *CKeyboardRepeat::iThis=NULL;
       
   178 TTimeIntervalMicroSeconds32 CKeyboardRepeat::iInitialTime;
       
   179 TTimeIntervalMicroSeconds32 CKeyboardRepeat::iTime;
       
   180 CWsWindowGroup *CKeyboardRepeat::iFocus=NULL;
       
   181 TBool CKeyboardRepeat::iAlternateRepeatExists=EFalse;
       
   182 CWsCaptureLongKey* CKeyboardRepeat::iLongCapture=NULL;
       
   183 
       
   184 
       
   185 void TWindowServerEvent::DeleteHotKeys()
       
   186 	{
       
   187 	CWsHotKey *hotKey=iHotKeys;
       
   188 	while(hotKey)
       
   189 		{
       
   190 		CWsHotKey *next=hotKey->iNext;
       
   191 		delete hotKey;
       
   192 		hotKey=next;
       
   193 		}
       
   194 	iHotKeys=NULL;
       
   195 	}
       
   196 
       
   197 void TWindowServerEvent::DeleteStatics()
       
   198 	{
       
   199 	DeleteHotKeys();
       
   200 	delete iCaptureKeys;
       
   201 	CKeyboardRepeat::Destroy();
       
   202 	delete iKeyTranslator;
       
   203 	delete iEventReceiver;
       
   204 	delete iEventHandlers;
       
   205 	delete iNotificationHandlers;
       
   206 	iDrawerHandlers->Close();
       
   207 	delete iDrawerHandlers;
       
   208 	}
       
   209 
       
   210 void TWindowServerEvent::InitStaticsL()
       
   211 //
       
   212 // Create the CEvent active object.
       
   213 //
       
   214 	{
       
   215 #if defined(__WINS__)
       
   216 	WS_ASSERT_DEBUG(TWindowServerEvent::ENumHotKeys==EHotKeyLastKeyType+1, EWsPanicUnknownCaptureKey);
       
   217 #endif
       
   218 	iEventReceiver=new(ELeave) CRawEventReceiver(EEventPriority);
       
   219 	iEventReceiver->ConstructL();
       
   220 	iKeyTranslator=CKeyTranslator::New();
       
   221 	User::LeaveIfNull(iKeyTranslator);
       
   222 
       
   223 //  Change keyboard mapping according to information the HAL
       
   224 	TInt keyboardIndex;
       
   225 	if (HAL::Get(HALData::EKeyboardIndex,keyboardIndex)==KErrNone)
       
   226 		{
       
   227 		_LIT(KLitKeyDataDllName,"EKDATA.%02d");
       
   228 		TBuf<16> keyDataDllName;
       
   229 		keyDataDllName.Format(KLitKeyDataDllName,keyboardIndex);
       
   230 		iKeyTranslator->ChangeKeyData(keyDataDllName);
       
   231 		}
       
   232 
       
   233 	iCaptureKeys=new(ELeave) CCaptureKeys;
       
   234 	iCaptureKeys->Construct();
       
   235 	for (TInt index=0;index<TWindowServerEvent::ENumHotKeys;index++)
       
   236 		ConstructDefaultHotKeyL(index,DefaultHotKeys[index]);
       
   237 	CKeyboardRepeat::NewL();
       
   238 	CKeyboardRepeat::SetRepeatTime(EDefaultInitialRepeatTime, EDefaultRepeatTime);
       
   239 	iEventHandlers=new(ELeave) CArrayPtrFlat<MEventHandler>(2);
       
   240 	iNotificationHandlers=new(ELeave) CArrayFixFlat<SNotificationHandler>(2);
       
   241 	iDrawerHandlers = new(ELeave) RArray<TDrawerHandler>(4);
       
   242 	}
       
   243 
       
   244 void TWindowServerEvent::LinkHotKey(CWsHotKey *aWsHotKey)
       
   245 	{
       
   246 	aWsHotKey->SetLink(iHotKeys);
       
   247 	iHotKeys=aWsHotKey;
       
   248 	}
       
   249 
       
   250 void TWindowServerEvent::ConstructDefaultHotKeyL(TInt aHotKey, const TWsWinCmdCaptureKey &aSystemKey)
       
   251 	{
       
   252 	CWsHotKey* hotKey=new(ELeave) CWsHotKey(aHotKey, ETrue);
       
   253 	// hotKey is pushed onto the cleanup stack in method ConstructLD.
       
   254 	hotKey->ConstructLD(aSystemKey);
       
   255 	LinkHotKey(hotKey);
       
   256 	}
       
   257 
       
   258 CWsHotKey* TWindowServerEvent::ClearHotKeysL(TInt aHotKey)
       
   259 	{
       
   260 	if (aHotKey>ENumHotKeys)
       
   261 		{
       
   262 		User::Leave(KErrArgument);
       
   263 		}
       
   264 	CWsHotKey** pHotKey= &iHotKeys;
       
   265 	CWsHotKey* defaultHotKey=NULL;
       
   266 	while(*pHotKey)
       
   267 		{
       
   268 		TBool unlinked=EFalse;
       
   269 		if ((*pHotKey)->HotKeyType()==aHotKey)
       
   270 			{
       
   271 			CWsHotKey *free=*pHotKey;
       
   272 			if (free->IsDefault())
       
   273 				{
       
   274 				free->SetL(ImpossibleKeyPress);
       
   275 				defaultHotKey=free;
       
   276 				}
       
   277 			else
       
   278 				{
       
   279 				*pHotKey=(*pHotKey)->iNext;
       
   280 				delete free;
       
   281 				unlinked=ETrue;
       
   282 				}
       
   283 			}
       
   284 		if (!unlinked)
       
   285 			{
       
   286 			pHotKey=&(*pHotKey)->iNext;
       
   287 			}
       
   288 		}
       
   289 	return(defaultHotKey);
       
   290 	}
       
   291 
       
   292 void TWindowServerEvent::ResetDefaultHotKeyL(TInt aHotKey)
       
   293 	{
       
   294 	if ((aHotKey<0) || (aHotKey>=ENumHotKeys))
       
   295 		{
       
   296 		User::Leave(KErrArgument);
       
   297 		}
       
   298 	CWsHotKey* defaultHotKey=ClearHotKeysL(aHotKey);
       
   299 	WS_ASSERT_DEBUG(defaultHotKey, EWsPanicDefaultHotKeyNotFound);
       
   300 	defaultHotKey->SetL(DefaultHotKeys[aHotKey]);
       
   301 	}
       
   302 
       
   303 void TWindowServerEvent::SetHotKeyL(const TWsClCmdSetHotKey &aHotKey)
       
   304 	{
       
   305 	if (aHotKey.type>ENumHotKeys)
       
   306 		User::Leave(KErrArgument);
       
   307 //
       
   308 	CWsHotKey *hotKey=new(ELeave) CWsHotKey(aHotKey.type, EFalse);
       
   309 //
       
   310 	TWsWinCmdCaptureKey captureKey;
       
   311 	captureKey.modifiers=aHotKey.modifiers;
       
   312 	captureKey.modifierMask=aHotKey.modifierMask;
       
   313 	captureKey.key=aHotKey.keycode;
       
   314 	hotKey->ConstructLD(captureKey);
       
   315 //
       
   316 	LinkHotKey(hotKey);
       
   317 	}
       
   318 
       
   319 void TWindowServerEvent::AddEventHandler(MEventHandler *aEventHandler)
       
   320 	{
       
   321 #if defined(_DEBUG)
       
   322 	TRAPD(err,iEventHandlers->AppendL(aEventHandler));
       
   323 	WS_ASSERT_DEBUG(err==KErrNone, EWsPanicEventHandlerInconsistency);
       
   324 #else
       
   325 	iEventHandlers->AppendL(aEventHandler);		//Shouldn't leave
       
   326 #endif
       
   327 	}
       
   328 
       
   329 void TWindowServerEvent::RemoveEventHandler(const MEventHandler *aEventHandler)
       
   330 	{
       
   331 	TInt count=iEventHandlers->Count();
       
   332 	TInt ii;
       
   333 	for(ii=0;ii<count;++ii)
       
   334 		{
       
   335 		if ((*iEventHandlers)[ii]==aEventHandler)
       
   336 			{
       
   337 			if (iEventHandlerCount>0)  
       
   338 				{
       
   339 				iBinaryFlags |= ERemovedEventHandlerWhileProcessingRawEvents;
       
   340 				(*iEventHandlers)[ii]=NULL; // replace the Handler with null to keep size of the array
       
   341 				}
       
   342 			else 
       
   343 				{
       
   344 				iEventHandlers->Delete(ii);
       
   345 				}
       
   346 			return;
       
   347 			}
       
   348 		}
       
   349 	}
       
   350 
       
   351 void TWindowServerEvent::PotentialEventHandlerL(TInt aNum)
       
   352 	{
       
   353 	iPotentialEventHandlers+=aNum;
       
   354 	WS_ASSERT_DEBUG(iPotentialEventHandlers>=iEventHandlers->Count(), EWsPanicEventHandlerInconsistency);
       
   355 	TRAPD(err,iEventHandlers->SetReserveL(iPotentialEventHandlers));
       
   356 	if (err!=KErrNone)
       
   357 		{
       
   358 		if (aNum>0)
       
   359 			User::Leave(err);
       
   360 		}
       
   361 	else if (iPotentialEventHandlers==0)
       
   362 		iEventHandlers->Compress();
       
   363 	}
       
   364 
       
   365 void SendSwitchOnEvent(TEventRequestItem *aQptr, TInt aEvent, TInt )
       
   366 	{
       
   367 	aQptr->iWindow->QueueEvent(aEvent);
       
   368 	}
       
   369 
       
   370 /*void SendSwitchOffEvent(TEventRequestItem *aQptr, TInt , TInt )
       
   371 	{
       
   372 	aQptr->iWindow->QueueEvent(EEventSwitchOff);
       
   373 	}*/
       
   374 
       
   375 void SendErrorMessage(TEventRequestItem *aQptr, TInt aCategory, TInt aError)
       
   376 	{
       
   377 	TWsEvent event;
       
   378 	event.SetType(EEventErrorMessage);
       
   379 	event.SetHandle(aQptr->iWindow->ClientHandle());
       
   380 	event.ErrorMessage()->iErrorCategory=(TWsErrorMessage::TErrorCategory)aCategory;
       
   381 	event.ErrorMessage()->iError=aError;
       
   382 	event.SetTimeNow();
       
   383 	aQptr->iWindow->EventQueue()->QueueEvent(event,EEventPriorityHigh);
       
   384 	}
       
   385 
       
   386 void SendModifierChangedEvent(TEventRequestItem *aQptr, TInt aChanged, TInt )
       
   387 	{
       
   388 	TInt tmpChanged=aChanged&aQptr->iParam;
       
   389 	if (tmpChanged)
       
   390 		{
       
   391 		TWsEvent event;
       
   392 		event.SetType(EEventModifiersChanged);
       
   393 		event.SetHandle(aQptr->iWindow->ClientHandle());
       
   394 		event.ModifiersChanged()->iChangedModifiers=tmpChanged;
       
   395 		event.ModifiersChanged()->iModifiers=TWindowServerEvent::GetStoredModifierState();
       
   396 		event.SetTimeNow();
       
   397 		aQptr->iWindow->EventQueue()->QueueEvent(event,EEventPriorityHigh);
       
   398 		}
       
   399 	}
       
   400 
       
   401 void TWindowServerEvent::ProcessEventQueue(TEventRequestQueue &aQueue, TSendEventFunc aFunc, TInt aParam1, TInt aParam2)
       
   402 	{
       
   403 	TSglQueIter<TEventRequestItem> iter(aQueue.Queue());
       
   404 	TEventRequestItem *qPtr;
       
   405 	CWsWindowGroup *focusWin=CWsTop::FocusWindowGroup();
       
   406 	while((qPtr=iter++)!=NULL)
       
   407 		{
       
   408 		if (qPtr->iCircumstances==EEventControlAlways || 
       
   409 			(qPtr->iCircumstances==EEventControlOnlyWithKeyboardFocus && qPtr->iWindow->WinGroup()==focusWin) ||
       
   410 			(qPtr->iCircumstances==EEventControlOnlyWhenVisible && !qPtr->iWindow->TreeIsObscured()))
       
   411 			aFunc(qPtr, aParam1, aParam2);
       
   412 		}
       
   413 	}
       
   414 
       
   415 void TWindowServerEvent::NotifyOom()
       
   416 	{
       
   417 	TTime now;
       
   418 	now.UniversalTime();
       
   419 	TTimeIntervalSeconds interval;
       
   420 	TInt err=now.SecondsFrom(iPrevOomMessageTime,interval);
       
   421 	if (err!=KErrNone || interval.Int()<0 || interval.Int()>EOomEventSecondGap)
       
   422 		{
       
   423 		ProcessErrorMessages(TWsErrorMessage::EDrawingRegion,KErrNoMemory);
       
   424 		iPrevOomMessageTime=now;
       
   425 		}
       
   426 	}
       
   427 
       
   428 TBool TWindowServerEvent::ProcessErrorMessages(TWsErrorMessage::TErrorCategory aCategory, TInt aError)
       
   429 	{
       
   430 	if (aError!=KErrNone)
       
   431 		{
       
   432 		ProcessEventQueue(iErrorMessageQueue, SendErrorMessage, aCategory, aError);
       
   433 		return ETrue;
       
   434 		}
       
   435 	return EFalse;
       
   436 	}
       
   437 
       
   438 void TWindowServerEvent::ProcessModifierChanges()
       
   439 	{
       
   440 	TInt newState=iKeyTranslator->GetModifierState();
       
   441 	if (newState!=iModifierState)
       
   442 		{
       
   443 		TInt changed=iModifierState^newState;
       
   444 		iModifierState=newState;
       
   445 		ProcessEventQueue(iModifierChangedQueue, SendModifierChangedEvent, changed, 0);
       
   446 		}
       
   447 	}
       
   448 
       
   449 TEventQueueWalkRet FindScreenDeviceChangedEvent(TAny *aHandlePtr, TWsEvent *aEvent)
       
   450 	{
       
   451 	if (aEvent->Type()==EEventScreenDeviceChanged && aEvent->Handle()==*(TUint *)aHandlePtr)
       
   452 		*(TUint *)aHandlePtr=0;	// Indicates event found
       
   453 	return(EEventQueueWalkOk);
       
   454 	}
       
   455 	
       
   456 void TWindowServerEvent::SendScreenDeviceChangedEvents(CScreen* aScreen)
       
   457 	{
       
   458 	TSglQueIter<TEventRequestItem> iter(iScreenDeviceChangedQueue .Queue());
       
   459 	TEventRequestItem *qPtr;
       
   460 	while((qPtr=iter++)!=NULL)
       
   461 		SendScreenDeviceChangedEvent(qPtr->iWindow);
       
   462 	if(CClick::IsHandler())
       
   463 		{
       
   464 		TClickMakerData clickMakerData;
       
   465 		clickMakerData.screenDeviceMode=aScreen->ScreenSizeMode();
       
   466 		CClick::OtherEvent(EEventScreenDeviceChanged, &clickMakerData);
       
   467 		}
       
   468 	TWsEvent wsEvent;
       
   469 	wsEvent.SetType(EEventScreenDeviceChanged);
       
   470 	TWindowServerEvent::PublishNotification(wsEvent);
       
   471 	TWservCrEvent crEvent(TWservCrEvent::EScreenSizeModeChanged,aScreen->ScreenSizeMode());
       
   472 	TWindowServerEvent::NotifyDrawer(crEvent);
       
   473 	}
       
   474 
       
   475 void TWindowServerEvent::SendScreenDeviceChangedEvent(const CWsWindowBase *aWindow)
       
   476 	{
       
   477 	CEventQueue *queue=aWindow->EventQueue();
       
   478 	TUint32 handle=aWindow->ClientHandle();
       
   479 	queue->WalkEventQueue(&FindScreenDeviceChangedEvent,&handle);
       
   480 	if (handle!=NULL)	// Indicates event not found
       
   481 		queue->QueueEvent(handle, EEventScreenDeviceChanged);
       
   482 	}
       
   483 
       
   484 TEventQueueWalkRet FindGroupChangedEvent(TAny *aHandlePtr, TWsEvent *aEvent)
       
   485 	{
       
   486 	if (aEvent->Type()==EEventWindowGroupsChanged && aEvent->Handle()==*(TUint *)aHandlePtr)
       
   487 		{
       
   488 		*(TUint *)aHandlePtr=0;	// Indicates event found
       
   489 		}
       
   490 	return(EEventQueueWalkOk);
       
   491 	}
       
   492 	
       
   493 void TWindowServerEvent::SendGroupChangedEvents()
       
   494 	{
       
   495 	TSglQueIter<TEventRequestItem> iter(iGroupChangedQueue.Queue());
       
   496 	TEventRequestItem *qPtr;
       
   497 	while((qPtr=iter++)!=NULL)
       
   498 		{
       
   499 		const CWsWindowBase *win=qPtr->iWindow;
       
   500 		CEventQueue *queue=win->EventQueue();
       
   501 		TUint32 handle=win->ClientHandle();
       
   502 		queue->WalkEventQueue(&FindGroupChangedEvent,&handle);
       
   503 		if (handle!=NULL)	// Indicates event not found
       
   504 			{
       
   505 			queue->QueueEvent(handle, EEventWindowGroupsChanged);
       
   506 			}
       
   507 		}
       
   508 	}	
       
   509 
       
   510 TEventQueueWalkRet FindFocusChangedEvent(TAny *aHandlePtr, TWsEvent *aEvent)
       
   511 	{
       
   512 	if (aEvent->Type()==EEventFocusGroupChanged && aEvent->Handle()==*(TUint *)aHandlePtr)
       
   513 		{
       
   514 		*(TUint *)aHandlePtr=0;	// Indicates event found
       
   515 		}
       
   516 	return(EEventQueueWalkOk);
       
   517 	}
       
   518 	
       
   519 void TWindowServerEvent::SendFocusChangedEvents()
       
   520 	{
       
   521 	TInt identifier=0;	// Zero Identifier indicates, currently there is no focused window group
       
   522 	CScreen* currentFocusScreen=CWsTop::CurrentFocusScreen();	
       
   523 	TInt screenNumber=currentFocusScreen->ScreenNumber();
       
   524 	CWsWindowGroup* currentFocusWG=currentFocusScreen->FocusWindowGroup();
       
   525 	WS_ASSERT_DEBUG(currentFocusWG, EWsPanicNoScreen);
       
   526 	if(currentFocusWG)
       
   527 		{
       
   528 		identifier=currentFocusWG->Identifier();
       
   529 		}
       
   530 	TWindowServerEvent::NotifyDrawer(TWservCrEvent(TWservCrEvent::EWindowGroupChanged,
       
   531 		screenNumber, reinterpret_cast<TAny*>(identifier)));
       
   532 		 
       
   533 	TSglQueIter<TEventRequestItem> iter(iFocusChangedQueue.Queue());
       
   534 	TEventRequestItem *qPtr;
       
   535 	while((qPtr=iter++)!=NULL)
       
   536 		{
       
   537 		const CWsWindowBase *win=qPtr->iWindow;
       
   538 		CEventQueue *queue=win->EventQueue();
       
   539 		TUint32 handle=win->ClientHandle();
       
   540 		queue->WalkEventQueue(&FindFocusChangedEvent,&handle);
       
   541 		if (handle!=NULL)	// Indicates event not found
       
   542 			{
       
   543 			queue->QueueEvent(handle, EEventFocusGroupChanged);
       
   544 			}
       
   545 		}
       
   546 	}
       
   547 
       
   548 TEventQueueWalkRet FindGroupListChangedEvent(TAny *aHandlePtr, TWsEvent *aEvent)
       
   549 	{
       
   550 	if (aEvent->Type()==EEventWindowGroupListChanged && aEvent->Handle()==*(TUint *)aHandlePtr)
       
   551 		{
       
   552 		*(TUint *)aHandlePtr=0;	// Indicates event found
       
   553 		}
       
   554 	return(EEventQueueWalkOk);
       
   555 	}
       
   556 	
       
   557 void TWindowServerEvent::SendGroupListChangedEvents()
       
   558 	{
       
   559 	TSglQueIter<TEventRequestItem> iter(iGroupListChangedQueue.Queue());
       
   560 	TEventRequestItem *qPtr;
       
   561 	while((qPtr=iter++)!=NULL)
       
   562 		{
       
   563 		const CWsWindowBase *win=qPtr->iWindow;
       
   564 		CEventQueue *queue=win->EventQueue();
       
   565 		TUint32 handle=win->ClientHandle();
       
   566 		queue->WalkEventQueue(&FindGroupListChangedEvent,&handle);
       
   567 		if (handle!=NULL)	// Indicates event not found
       
   568 			{
       
   569 			queue->QueueEvent(handle, EEventWindowGroupListChanged);
       
   570 			}
       
   571 		}
       
   572 	}	
       
   573 
       
   574 TEventQueueWalkRet OverrideVisibilityChangedEvent(TAny *aNewEvent, TWsEvent *aOldEvent)
       
   575 	{
       
   576 	// This replaces the first visibility event it finds for the given window with the
       
   577 	// one given.  This is fine, so long as the meaning of all visibility events remains
       
   578 	// independent of the ones before.
       
   579 	TWsEvent* newEvent = static_cast<TWsEvent*>(aNewEvent);
       
   580 	if (aOldEvent->Type()==EEventWindowVisibilityChanged && aOldEvent->Handle()==newEvent->Handle())
       
   581 		{
       
   582 		aOldEvent->SetTimeNow();
       
   583 		aOldEvent->VisibilityChanged()->iFlags = newEvent->VisibilityChanged()->iFlags;
       
   584 		newEvent->SetHandle(NULL);
       
   585 		}
       
   586 	return EEventQueueWalkOk;
       
   587 	}
       
   588 
       
   589 void TWindowServerEvent::SendVisibilityChangedEvents(CWsWindowBase* aWin, TUint aFlags)
       
   590 	{
       
   591 	CEventQueue *queue=aWin->EventQueue();
       
   592 	TWsEvent event;
       
   593 	event.SetType(EEventWindowVisibilityChanged);
       
   594 	event.SetHandle(aWin->ClientHandle());
       
   595 	event.SetTimeNow();
       
   596 	TWsVisibilityChangedEvent* visevent = event.VisibilityChanged();
       
   597 	visevent->iFlags = aFlags;
       
   598 	queue->WalkEventQueue(&OverrideVisibilityChangedEvent,&event);
       
   599 	if (event.Handle()!=NULL)
       
   600 		{
       
   601 		queue->QueueEvent(event);
       
   602 		}
       
   603 	}
       
   604 
       
   605 void TWindowServerEvent::QueueKeyEvent(CWsWindowGroup *aWin, TWsEvent &aEvent, TWservEventPriorities aPriority)
       
   606 	{
       
   607 	aEvent.SetTimeNow();
       
   608 	aWin->EventQueue()->QueueEvent(aEvent, aPriority);
       
   609 	}
       
   610 
       
   611 void TWindowServerEvent::QueueKeyPress(const TKeyData& aKey, TInt aScanCode, CWsWindowGroup* aRepeatFocus, TBool aCheckRepeat,TInt aRepeats)
       
   612  	{
       
   613 	CWsWindowGroup* focusWin=CWsTop::FocusWindowGroup();
       
   614 	TWsEvent event;
       
   615 	TKeyEvent& keyEvent=*event.Key();
       
   616 	keyEvent.iCode=aKey.iKeyCode;
       
   617 	keyEvent.iScanCode=aScanCode;
       
   618 	keyEvent.iModifiers=aKey.iModifiers;
       
   619 	keyEvent.iRepeats=aRepeats;
       
   620 	if (!aRepeatFocus && CClick::IsHandler())
       
   621 		CClick::KeyEvent(EEventKey,keyEvent);
       
   622 	CWsCaptureLongKey* longCapture=NULL;
       
   623 	if (aCheckRepeat)
       
   624 		longCapture=CWsCaptureLongKey::CheckForCapture(aKey.iKeyCode, aKey.iModifiers);
       
   625 	if (aKey.iIsCaptureKey)
       
   626 		{
       
   627 		if (aKey.iApp==NULL)	// Captured by Wserv itself
       
   628 			{
       
   629 			_LIT(KWSERVDebugLogCapturedKey,"WSERV Captured Key");
       
   630 			CScreen* focusScreen=CWsTop::CurrentFocusScreen();
       
   631 			TInt screenNo=focusScreen->ScreenNumber();
       
   632 			
       
   633 			if (wsDebugLog)
       
   634 				wsDebugLog->MiscMessage(CDebugLogBase::ELogEverything,KWSERVDebugLogCapturedKey);
       
   635 			CWsHotKey *hotKey=iHotKeys;
       
   636 			while(hotKey)
       
   637 				{
       
   638 				if (hotKey->KeyHandle()==aKey.iHandle)
       
   639 					{
       
   640 					switch(hotKey->HotKeyType())
       
   641 						{
       
   642 						case EHotKeyEnableLogging:
       
   643 							CWsTop::EnableLogging();
       
   644 							break;
       
   645 						case EHotKeyDisableLogging:
       
   646 							CWsTop::DisableLogging();
       
   647 							break;
       
   648 						case EHotKeyStateDump:
       
   649 							StateDump();
       
   650 							break;
       
   651 						case EHotKeyHeapDump:
       
   652 							HeapDump();
       
   653 							break;
       
   654 						case EHotKeyOfDeath:
       
   655 							if (!CWsPassword::PasswordModeActive())
       
   656 								{
       
   657 								const TBool currentJustInTimeValue=User::JustInTime();
       
   658 								if (currentJustInTimeValue)
       
   659 									{
       
   660 									User::SetJustInTime(EFalse);
       
   661 									}
       
   662 								CWsTop::KillForegroundSession();
       
   663 								if (currentJustInTimeValue)
       
   664 									{
       
   665 									User::SetJustInTime(ETrue);
       
   666 									}
       
   667 								}
       
   668 							break;
       
   669 						case EHotKeyShutDown:
       
   670 							CWsTop::Exit();
       
   671 							break;
       
   672 						case EHotKeyIncContrast:
       
   673 							focusScreen->IncContrast();
       
   674 							break;
       
   675 						case EHotKeyDecContrast:
       
   676 							focusScreen->DecContrast();
       
   677 							break;
       
   678 						case EHotKeyOff:
       
   679 							CWsTop::HandleSwitchOff(EEventKeySwitchOff,ETrue);
       
   680 							break;
       
   681 						case EHotKeyBacklightToggle:
       
   682 							{
       
   683 							TInt state;
       
   684 							if (!ProcessErrorMessages(TWsErrorMessage::EBackLight, HAL::Get(screenNo,HALData::EBacklightState,state)))
       
   685 								ProcessErrorMessages(TWsErrorMessage::EBackLight, HAL::Set(screenNo,HALData::EBacklightState,!state));
       
   686 							}
       
   687 							break;
       
   688 						case EHotKeyBacklightOn:
       
   689 							ProcessErrorMessages(TWsErrorMessage::EBackLight, HAL::Set(screenNo,HALData::EBacklightState,ETrue));
       
   690 							break;
       
   691 						case EHotKeyBacklightOff:
       
   692 							ProcessErrorMessages(TWsErrorMessage::EBackLight, HAL::Set(screenNo,HALData::EBacklightState,EFalse));
       
   693 							break;
       
   694 						case EHotKeyScreenDimension0:
       
   695 						case EHotKeyScreenDimension1:
       
   696 						case EHotKeyScreenDimension2:
       
   697 						case EHotKeyScreenDimension3:
       
   698 							focusScreen->doSetScreenMode(hotKey->HotKeyType()-EHotKeyScreenDimension0);
       
   699 							break;
       
   700 						case EHotKeyCycleDisplaySize:
       
   701 							focusScreen->CycleDisplaySize();
       
   702 							break;
       
   703 						case EHotKeyCycleOrientation:
       
   704 							focusScreen->CycleOrientation();
       
   705 							break;
       
   706 						case EHotKeyIncBrightness:
       
   707 							focusScreen->IncBrightness();
       
   708 							break;
       
   709 						case EHotKeyDecBrightness:
       
   710 							focusScreen->DecBrightness();
       
   711 							break;
       
   712 						case EHotKeyCycleFocusScreen:
       
   713 							CWsTop::SetCurrentFocusScreen((CWsTop::CurrentFocusScreen()->ScreenNumber()+1)%CWsTop::NumberOfScreens());
       
   714 							break;
       
   715 						}
       
   716 					return;
       
   717 					}
       
   718 				hotKey=hotKey->iNext;
       
   719 				}
       
   720 			WS_PANIC_ALWAYS(EWsPanicUnknownCaptureKey);
       
   721 			return;
       
   722 			}
       
   723 		focusWin=((CWsWindowGroup *)aKey.iApp);
       
   724 		_LIT(KWSERVDebugLogKeyCapturedByApp,"Key captured by app %d");
       
   725 		if (wsDebugLog)
       
   726 			wsDebugLog->MiscMessage(CDebugLogBase::ELogEverything,KWSERVDebugLogKeyCapturedByApp,focusWin->Identifier());
       
   727 		if (CWsPassword::PasswordModeActive() && focusWin!=CWsPassword::PasswordWindow()->WinGroup())
       
   728 			return;
       
   729 		}
       
   730 	if (aRepeatFocus && aRepeatFocus!=focusWin)
       
   731 		CKeyboardRepeat::CancelRepeat(NULL);		// Repeat is going to different window so cancel it and don't deliver this key
       
   732 	else if (focusWin!=NULL && focusWin->CheckForPriorityKey(aKey,aScanCode)==EFalse)
       
   733 		{
       
   734 		if (longCapture || (aCheckRepeat && !aRepeatFocus && aKey.iModifiers&EModifierAutorepeatable))
       
   735 			{
       
   736 			if (CKeyboardRepeat::StartRepeat(aKey,aScanCode,focusWin,longCapture))
       
   737 				return;
       
   738 			}
       
   739 		event.SetType(EEventKey);
       
   740 		event.SetHandle(focusWin->ClientHandle());
       
   741 		if (aRepeats!=0)
       
   742 			{
       
   743 			CEventQueue* queue=focusWin->EventQueue();
       
   744 			queue->Wait();
       
   745 			const TWsEvent* prev=queue->PeekLastEvent();
       
   746 			if (prev!=NULL && prev->Type()==EEventKey && prev->Key()->iRepeats>0)
       
   747 				{
       
   748 			//WS_ASSERT_DEBUG(prev->Key()->iScanCode==aScanCode, EWsPanicKeyRepeat); //This ASSERT can be triggered by using new functionality, need to find a way to make it tell the difference.
       
   749 				event= *prev;
       
   750 				event.Key()->iRepeats+=aRepeats;
       
   751 				queue->UpdateLastEvent(event);
       
   752 				if (CClick::IsHandler())
       
   753 					CClick::KeyEvent(EEventKeyRepeat,*event.Key());
       
   754 				return;
       
   755 				}
       
   756 			queue->Signal();
       
   757 			event.Key()->iRepeats=aRepeats;
       
   758 			if (CClick::IsHandler())
       
   759 				CClick::KeyEvent(EEventKeyRepeat,keyEvent);
       
   760 			}
       
   761 		QueueKeyEvent(focusWin, event, EEventPriorityLow);
       
   762 		}
       
   763 	}
       
   764 
       
   765 void TWindowServerEvent::QueueKeyUpDown(const TRawEvent &aRawEvent)
       
   766  	{
       
   767 	CWsWindowGroup *focusWin=CWsCaptureKeyUpsAndDowns::CheckForCapture(aRawEvent.ScanCode() __REMOVE_WINS_CHARCODE, iModifierState);
       
   768 	if (!focusWin)	// If not captured
       
   769 		focusWin=CWsTop::FocusWindowGroup();
       
   770 	TWsEvent event;
       
   771 	TEventCode type=aRawEvent.Type()==TRawEvent::EKeyUp ? EEventKeyUp : EEventKeyDown;
       
   772 	event.Key()->iCode=0;
       
   773 #if defined(__WINS__)
       
   774 	if (focusWin && !focusWin->WsOwner()->RemoveKeyCode())
       
   775 		event.Key()->iScanCode=aRawEvent.ScanCode();
       
   776 	else
       
   777 #endif
       
   778 	event.Key()->iScanCode=aRawEvent.ScanCode() __REMOVE_WINS_CHARCODE;
       
   779 	event.Key()->iModifiers=iModifierState;
       
   780 	event.Key()->iRepeats=0;
       
   781 	if (CClick::IsHandler())
       
   782 		CClick::KeyEvent(type,*event.Key());
       
   783 	if (focusWin!=NULL)
       
   784 		{
       
   785 		event.SetType(type);
       
   786 		event.SetHandle(focusWin->ClientHandle());
       
   787 		QueueKeyEvent(focusWin, event, EEventPriorityHigh);
       
   788 		}
       
   789 	}
       
   790 
       
   791 LOCAL_D void GetPointerEvent(TPointerEvent::TType& aType, const TRawEvent &aRawEvent, TBool& aHandled)
       
   792 	{
       
   793 	aHandled=ETrue;
       
   794 	switch(aRawEvent.Type())
       
   795 		{
       
   796 	case TRawEvent::EButton1Down:
       
   797 		aType=TPointerEvent::EButton1Down;
       
   798 		break;
       
   799 	case TRawEvent::EButton1Up:
       
   800 		aType=TPointerEvent::EButton1Up;
       
   801 		break;
       
   802 	case TRawEvent::EButton2Down:
       
   803 		aType=TPointerEvent::EButton2Down;
       
   804 		break;
       
   805 	case TRawEvent::EButton2Up:
       
   806 		aType=TPointerEvent::EButton2Up;
       
   807 		break;
       
   808 	case TRawEvent::EButton3Down:
       
   809 		aType=TPointerEvent::EButton3Down;
       
   810 		break;
       
   811 	case TRawEvent::EButton3Up:
       
   812 		aType=TPointerEvent::EButton3Up;
       
   813 		break;
       
   814 	case TRawEvent::EPointerMove:
       
   815 		aType=TPointerEvent::EMove;
       
   816 		break;
       
   817 	case TRawEvent::EPointerSwitchOn:
       
   818 		aType=TPointerEvent::ESwitchOn;
       
   819 		break;
       
   820 	default:
       
   821 		aHandled=EFalse;
       
   822 		}
       
   823 	}
       
   824 
       
   825 TBool TWindowServerEvent::MousePress(const TRawEvent &aRawEvent, const CWsWindowGroup *aGroupWin)
       
   826 	//
       
   827 	//Return EFalse if known not to be a Mouse Event
       
   828 	//
       
   829 	{
       
   830 	TBool handled=ETrue;
       
   831 	TPointerEvent::TType type;
       
   832 	GetPointerEvent(type, aRawEvent, handled);
       
   833 	if (handled)
       
   834 		{
       
   835 		TPoint xy(aRawEvent.Pos());
       
   836 		WsPointer::ProcessEvent(type, xy, iKeyTranslator->GetModifierState(), aGroupWin, ETrue);
       
   837 		}
       
   838 	return handled;
       
   839 	}
       
   840 
       
   841 LOCAL_D void SendEventToKeyClick(const TRawEvent& aRawEvent)
       
   842 	{
       
   843 	switch(aRawEvent.Type())
       
   844 		{
       
   845 		case TRawEvent::EKeyDown:
       
   846 		case TRawEvent::EKeyUp:
       
   847 			{
       
   848 			TKeyEvent keyEvent;
       
   849 			keyEvent.iCode=0;
       
   850 			keyEvent.iScanCode=aRawEvent.ScanCode();
       
   851 			keyEvent.iModifiers=0;
       
   852 			keyEvent.iRepeats=0;
       
   853 			CClick::KeyEvent(EEventKey,keyEvent);
       
   854 			}
       
   855 			break;
       
   856 		case TRawEvent::EButton1Down:
       
   857 		case TRawEvent::EButton1Up:
       
   858 		case TRawEvent::EButton2Down:
       
   859 		case TRawEvent::EButton2Up:
       
   860 		case TRawEvent::EButton3Down:
       
   861 		case TRawEvent::EButton3Up:
       
   862 		case TRawEvent::EPointerMove:
       
   863 		case TRawEvent::EPointerSwitchOn:
       
   864 			{
       
   865 			TBool handled=ETrue;
       
   866 			TPointerEvent::TType type;
       
   867 			GetPointerEvent(type, aRawEvent, handled);
       
   868 			if (handled)
       
   869 				{
       
   870 				TPointerEvent pointerEvent;
       
   871 				pointerEvent.iType=type;
       
   872 				pointerEvent.iModifiers=0;
       
   873 				pointerEvent.iPosition=aRawEvent.Pos();
       
   874 				pointerEvent.iParentPosition=TPoint(KMinTInt32,KMinTInt32);
       
   875 				CClick::PointerEvent(pointerEvent.iPosition,pointerEvent);
       
   876 				}
       
   877 			}
       
   878 			break;
       
   879 		default:
       
   880 			break;
       
   881 		}
       
   882 	}
       
   883 
       
   884 void TWindowServerEvent::ProcessRawEvent(const TRawEvent& aRawEvent)
       
   885 //
       
   886 // Event has completed.
       
   887 //
       
   888 	{
       
   889 	WS_TRACE_SERVER_PROCESSRAWEVENT();
       
   890 	TInt count=iEventHandlers->Count();
       
   891 	TInt ii;
       
   892 	TBool eventHandled = EFalse;
       
   893 	iEventHandlerCount++;
       
   894 	for(ii=0;ii<count;++ii)
       
   895 		{
       
   896 		if ((*iEventHandlers)[ii] != NULL && (*iEventHandlers)[ii]->OfferRawEvent(aRawEvent))
       
   897 			{
       
   898 			if (CClick::IsHandler())
       
   899 				{
       
   900 				SendEventToKeyClick(aRawEvent);
       
   901 				}
       
   902 			eventHandled = ETrue;
       
   903 			break;
       
   904 			}
       
   905 		}
       
   906 	if (--iEventHandlerCount == 0)
       
   907 		{
       
   908 		if (ERemovedEventHandlerWhileProcessingRawEvents & iBinaryFlags) // Handler was deleted while previous loop
       
   909 			{ 
       
   910 			iBinaryFlags &= ~ERemovedEventHandlerWhileProcessingRawEvents;
       
   911 			for(ii=count-1;ii>=0;--ii)
       
   912 				{
       
   913 				if ((*iEventHandlers)[ii]==NULL) iEventHandlers->Delete(ii);
       
   914 				}
       
   915 			}
       
   916 		}
       
   917 	if (eventHandled)
       
   918 		{
       
   919 		return;
       
   920 		}
       
   921 	switch(aRawEvent.Type())
       
   922 		{
       
   923 		case TRawEvent::ERedraw:
       
   924 			CWsTop::RedrawScreens();
       
   925 			break;
       
   926 		case TRawEvent::ESwitchOn:
       
   927 		case TRawEvent::ECaseOpen:
       
   928 			{
       
   929 			TInt event=EEventCaseOpened;
       
   930 			CKeyboardRepeat::CancelRepeat(NULL);
       
   931 			CWsPassword::SwitchOn();
       
   932 			if (aRawEvent.Type()==TRawEvent::ESwitchOn)
       
   933 				{
       
   934 				UserSvr::WsSwitchOnScreen();
       
   935 				HAL::Set(HALData::EDisplayState,1);
       
   936 				event=EEventSwitchOn;
       
   937 				}
       
   938 			ProcessEventQueue(iSwitchOnQueue, SendSwitchOnEvent, event, 0);
       
   939 			break;
       
   940 			}
       
   941 		case TRawEvent::ESwitchOff:
       
   942 		case TRawEvent::ECaseClose:
       
   943 			{
       
   944 			TBool switchOff=(aRawEvent.Type()==TRawEvent::ESwitchOff);
       
   945 			CWsTop::HandleSwitchOff(switchOff? EEventSwitchOff:EEventCaseClosed,switchOff);
       
   946 			break;
       
   947 			}
       
   948 #ifdef SYMBIAN_PROCESS_MONITORING_AND_STARTUP			
       
   949 		case TRawEvent::ERestartSystem:
       
   950 			{ /* restart event being handled */
       
   951 			CWsTop::HandleSwitchOff(EEventRestartSystem,ETrue);
       
   952 			break;
       
   953 			}
       
   954 #endif			
       
   955 		case TRawEvent::EInactive:
       
   956 #ifndef __WINS__
       
   957 			CWsTop::WindowServer()->AnimationScheduler()->OnInactive();
       
   958 #endif
       
   959 			CKeyboardRepeat::CancelRepeat(NULL);
       
   960 			break;
       
   961 		case TRawEvent::EActive:
       
   962 #ifndef __WINS__
       
   963 			CWsTop::WindowServer()->AnimationScheduler()->OnActive();
       
   964 #endif
       
   965 			break;
       
   966 		case TRawEvent::EKeyDown:
       
   967 			{
       
   968 			_LIT(KWSERVDebugLogKeyDownArrival,"Key down arrives %d");
       
   969 			if(CDebugBar* dbg = CWsTop::Screen()->DebugBar())
       
   970 				dbg->OnKeyEvent();
       
   971 			if (wsDebugLog)
       
   972 				wsDebugLog->MiscMessage(CDebugLogBase::ELogEverything,KWSERVDebugLogKeyDownArrival,aRawEvent.ScanCode());
       
   973 			CKeyboardRepeat::KeyDown();
       
   974 			TKeyData keyData;
       
   975 			TBool translated=iKeyTranslator->TranslateKey(aRawEvent.ScanCode(), EFalse,*iCaptureKeys,keyData);
       
   976 			ProcessModifierChanges();
       
   977 			QueueKeyUpDown(aRawEvent);
       
   978 			if (translated)
       
   979 				QueueKeyPress(keyData,aRawEvent.ScanCode() __REMOVE_WINS_CHARCODE,NULL,ETrue,0);
       
   980 			}
       
   981 			break;
       
   982 		case TRawEvent::EKeyUp:
       
   983 			{
       
   984 			_LIT(KWSERVDebugLogKeyUpArrival,"Key up arrives %d");
       
   985 			if(CDebugBar* dbg = CWsTop::Screen()->DebugBar())
       
   986 				dbg->OnKeyEvent();
       
   987 			if (wsDebugLog)
       
   988 				wsDebugLog->MiscMessage(CDebugLogBase::ELogEverything,KWSERVDebugLogKeyUpArrival,aRawEvent.ScanCode());
       
   989 			TKeyData keyData;
       
   990 			CKeyboardRepeat::KeyUp(aRawEvent.ScanCode() __REMOVE_WINS_CHARCODE);
       
   991 			TBool translated=iKeyTranslator->TranslateKey(aRawEvent.ScanCode(), ETrue,*iCaptureKeys,keyData);
       
   992 			ProcessModifierChanges();
       
   993 			QueueKeyUpDown(aRawEvent);
       
   994 			if (translated)
       
   995 				{
       
   996 				CKeyboardRepeat::CancelRepeat(NULL);
       
   997 				QueueKeyPress(keyData,aRawEvent.ScanCode() __REMOVE_WINS_CHARCODE,NULL,EFalse,0);
       
   998 				}
       
   999 			}
       
  1000 			break;
       
  1001 		case TRawEvent::EButton1Down:
       
  1002 		case TRawEvent::EButton2Down:
       
  1003 		case TRawEvent::EButton3Down:
       
  1004 		case TRawEvent::EPointerSwitchOn:
       
  1005 #ifndef __WINS__
       
  1006 			CWsTop::WindowServer()->AnimationScheduler()->OnActive();
       
  1007 #endif
       
  1008 			// fall through
       
  1009 		case TRawEvent::EButton1Up:
       
  1010 		case TRawEvent::EButton2Up:
       
  1011 		case TRawEvent::EButton3Up:
       
  1012 		case TRawEvent::EPointerMove:
       
  1013 			#if defined(_DEBUG)
       
  1014 				WS_ASSERT_DEBUG(MousePress(aRawEvent,NULL), EWsPanicEventType);
       
  1015 			#else
       
  1016 				MousePress(aRawEvent,NULL);
       
  1017 			#endif
       
  1018 			break;
       
  1019 		case TRawEvent::EUpdateModifiers:
       
  1020 			iKeyTranslator->UpdateModifiers(aRawEvent.Modifiers());
       
  1021 			break;
       
  1022 		case TRawEvent::EKeyRepeat:
       
  1023  			{
       
  1024  			_LIT(KWSERVDebugLogRepeatingKeyArrival,"Repeating key arrives %d");
       
  1025  			if (wsDebugLog)
       
  1026  				wsDebugLog->MiscMessage(CDebugLogBase::ELogEverything,KWSERVDebugLogRepeatingKeyArrival,aRawEvent.ScanCode());
       
  1027  			TKeyData keyData;
       
  1028  			keyData.iModifiers=iKeyTranslator->GetModifierState();
       
  1029 			keyData.iApp=0;
       
  1030 			keyData.iHandle=0;
       
  1031 			keyData.iIsCaptureKey=EFalse;
       
  1032 			keyData.iKeyCode=aRawEvent.ScanCode(); 
       
  1033 			iCaptureKeys->ProcessCaptureKeys(keyData);
       
  1034 			QueueKeyPress(keyData, aRawEvent.ScanCode() __REMOVE_WINS_CHARCODE,NULL,EFalse,aRawEvent.Repeats());
       
  1035  			}
       
  1036  			break;
       
  1037 		default:
       
  1038 			break;
       
  1039 		}
       
  1040 	}
       
  1041 
       
  1042 void TWindowServerEvent::ProcessKeyEvent(const TKeyEvent &aKeyEvent,TInt aRepeats)
       
  1043 	{
       
  1044 	TKeyData keyData;
       
  1045 	keyData.iModifiers=aKeyEvent.iModifiers;
       
  1046 	keyData.iApp=0;
       
  1047 	keyData.iHandle=0;
       
  1048 	keyData.iIsCaptureKey=EFalse;
       
  1049 	keyData.iKeyCode=aKeyEvent.iCode;
       
  1050 	if (CKeyboardRepeat::IsAreadyActive())
       
  1051 		{
       
  1052 		CKeyboardRepeat::CancelRepeat(NULL);
       
  1053 		}
       
  1054 	iCaptureKeys->ProcessCaptureKeys(keyData);
       
  1055 	QueueKeyPress(keyData,aKeyEvent.iScanCode,NULL,aRepeats==0,aRepeats);
       
  1056 	}
       
  1057 
       
  1058 void TWindowServerEvent::AddCaptureKeyL(const TCaptureKey &aCaptureKey)
       
  1059 	{
       
  1060 	iCaptureKeys->AddCaptureKeyL(aCaptureKey,aCaptureKey.iKeyCodePattern.iFiller);
       
  1061 	}
       
  1062 
       
  1063 void TWindowServerEvent::SetCaptureKey(TUint32 aHandle, const TCaptureKey &aCaptureKey)
       
  1064 	{
       
  1065 	iCaptureKeys->SetCaptureKey(aHandle, aCaptureKey,aCaptureKey.iKeyCodePattern.iFiller);
       
  1066 	}
       
  1067 
       
  1068 void TWindowServerEvent::CancelCaptureKey(TUint32 aHandle)
       
  1069 	{
       
  1070 	iCaptureKeys->CancelCaptureKey(aHandle);
       
  1071 	}
       
  1072 
       
  1073 TInt TWindowServerEvent::GetModifierState()
       
  1074 	{
       
  1075 	return(iKeyTranslator->GetModifierState());
       
  1076 	}
       
  1077 
       
  1078 void TWindowServerEvent::SetModifierState(TEventModifier aModifier,TModifierState aState)
       
  1079 	{
       
  1080 	iKeyTranslator->SetModifierState(aModifier,aState);
       
  1081 	}
       
  1082 
       
  1083 TInt TWindowServerEvent::AddNotificationHandler(CAnim* aAnim, TUint32 aNotifications)
       
  1084 	{
       
  1085 	SNotificationHandler notif;
       
  1086 	notif.iAnim = aAnim;
       
  1087 	notif.iNotifications = aNotifications;
       
  1088 
       
  1089 	// update the entry if the anim is already in the array
       
  1090 	TInt count=iNotificationHandlers->Count();
       
  1091 	TInt ii;
       
  1092 	for(ii=0;ii<count;++ii)
       
  1093 		{
       
  1094 		if ((*iNotificationHandlers)[ii].iAnim==aAnim)
       
  1095 			{
       
  1096 			(*iNotificationHandlers)[ii]=notif;
       
  1097 			return KErrNone;
       
  1098 			}
       
  1099 		}
       
  1100 	
       
  1101 	// otherwise add it to the array
       
  1102 	TRAPD(err,iNotificationHandlers->AppendL(notif));
       
  1103 	return err;
       
  1104 	}
       
  1105 
       
  1106 void TWindowServerEvent::RemoveNotificationHandler(CAnim* aAnim)
       
  1107 	{
       
  1108 	TInt count=iNotificationHandlers->Count();
       
  1109 	TInt ii;
       
  1110 	for(ii=0;ii<count;++ii)
       
  1111 		{
       
  1112 		if ((*iNotificationHandlers)[ii].iAnim==aAnim)
       
  1113 			{
       
  1114 			iNotificationHandlers->Delete(ii);
       
  1115 			return;
       
  1116 			}
       
  1117 		}
       
  1118 	}
       
  1119 
       
  1120 void TWindowServerEvent::PublishNotification(const TWsEvent& aWsEvent)
       
  1121 	{
       
  1122 	TInt count=iNotificationHandlers->Count();
       
  1123 	TInt ii;
       
  1124 	for(ii=0;ii<count;++ii)
       
  1125 		{
       
  1126 		SNotificationHandler notif = (*iNotificationHandlers)[ii];
       
  1127 		switch (aWsEvent.Type())
       
  1128 			{
       
  1129 		case EEventDirectScreenAccessBegin:
       
  1130 		case EEventDirectScreenAccessEnd:
       
  1131 			if (notif.iNotifications & EDirectScreenAccess)
       
  1132 				{
       
  1133 				notif.iAnim->HandleNotification(aWsEvent);
       
  1134 				}
       
  1135 			break;
       
  1136 		case EEventHeartbeatTimerStateChange:
       
  1137 			if (notif.iNotifications & EHeartbeatTimer)
       
  1138 				{
       
  1139 				notif.iAnim->HandleNotification(aWsEvent);
       
  1140 				}
       
  1141 			break;
       
  1142 		case EEventScreenDeviceChanged:
       
  1143 			if (notif.iNotifications & EScreenDeviceChange)
       
  1144 				{
       
  1145 				notif.iAnim->HandleNotification(aWsEvent);
       
  1146 				}
       
  1147 			break;
       
  1148 		default:
       
  1149 			break;
       
  1150 			}
       
  1151 		}
       
  1152 
       
  1153 	}
       
  1154 
       
  1155 TBool TWindowServerEvent::DrawerCompareFunc(const TDrawerHandler& lhs, const TDrawerHandler& rhs)
       
  1156 	{
       
  1157 	return lhs.iDrawer == rhs.iDrawer;	
       
  1158 	}
       
  1159 
       
  1160 TInt TWindowServerEvent::RegisterDrawerHandler(CWsGraphicDrawer* aDrawer, TUint32 aEvents)
       
  1161 	{
       
  1162 	TInt idx = iDrawerHandlers->Find(TDrawerHandler(aDrawer, aEvents),
       
  1163 		TIdentityRelation<TDrawerHandler>(TWindowServerEvent::DrawerCompareFunc));
       
  1164 	if (idx != KErrNotFound)
       
  1165 		{
       
  1166 		// replace event mask for this drawer
       
  1167 		(*iDrawerHandlers)[idx].iEvents = aEvents;
       
  1168 		idx = KErrNone;
       
  1169 		}
       
  1170 	else
       
  1171 		idx = iDrawerHandlers->Append(TDrawerHandler(aDrawer,aEvents));
       
  1172 	
       
  1173 	return idx;
       
  1174 	}
       
  1175 
       
  1176 TInt TWindowServerEvent::UnregisterDrawerHandler(CWsGraphicDrawer* aDrawer)
       
  1177 	{
       
  1178 	TInt idx = iDrawerHandlers->Find(TDrawerHandler(aDrawer,0),
       
  1179 		TIdentityRelation<TDrawerHandler>(TWindowServerEvent::DrawerCompareFunc));
       
  1180 	if (idx == KErrNotFound)
       
  1181 		return idx;
       
  1182 	(*iDrawerHandlers)[idx].iDrawer = NULL;		//NotifyDrawer() will clean up the array
       
  1183 	return KErrNone;
       
  1184 	}
       
  1185 
       
  1186 TInt TWindowServerEvent::RegisterWsEventHandler(MWsEventHandler * aHandler, TUint32 aEvents)
       
  1187 	{
       
  1188 	TWsEventHandler handler(aHandler, aEvents);
       
  1189 	TInt idx = iWsEventHandlers.Find(handler, TIdentityRelation<TWsEventHandler>(TWsEventHandler::CompareHandler));
       
  1190 	if (idx < 0)
       
  1191 		{
       
  1192 		TInt err = iWsEventHandlers.Append(handler);
       
  1193 		return err;
       
  1194 		}
       
  1195 	else
       
  1196 		{
       
  1197 		iWsEventHandlers[idx].iEvents = aEvents;
       
  1198 		return KErrNone;
       
  1199 		}
       
  1200 	}
       
  1201 	
       
  1202 TInt TWindowServerEvent::UnregisterWsEventHandler(MWsEventHandler * aHandler)
       
  1203 	{
       
  1204 	TWsEventHandler handler(aHandler, 0);
       
  1205 	TInt idx = iWsEventHandlers.Find(handler, TIdentityRelation<TWsEventHandler>(TWsEventHandler::CompareHandler));
       
  1206 	if (idx < 0)
       
  1207 		return idx;
       
  1208 	iWsEventHandlers[idx].iEvents = NULL;	//NotifyDrawer() will clean up the array
       
  1209 	return KErrNone;
       
  1210 	}
       
  1211 
       
  1212 
       
  1213 void TWindowServerEvent::NotifyDrawer(const TWservCrEvent& aEvent)
       
  1214 	{
       
  1215 	TInt drawerCount = iDrawerHandlers->Count();
       
  1216 	for (TInt idx = 0; idx < drawerCount; idx++)
       
  1217 		{
       
  1218 		TDrawerHandler hd = (*iDrawerHandlers)[idx]; 
       
  1219 		if (!hd.iDrawer) 
       
  1220 			{                					//If the handler has been removed 
       
  1221 			iDrawerHandlers->Remove(idx);       //Remove from the array 
       
  1222 			drawerCount -= 1;   				//Update the counters 
       
  1223 			idx -= 1; 
       
  1224 			} 
       
  1225 		else 
       
  1226 			{ 
       
  1227 			if (hd.iEvents & aEvent.Type()) 
       
  1228 				{ 
       
  1229 			    hd.iDrawer->HandleEvent(aEvent); 
       
  1230 			    } 
       
  1231 			} 
       
  1232 		}
       
  1233 	
       
  1234 	TInt eventHandlerCount = iWsEventHandlers.Count();
       
  1235 	for (TInt idx = 0; idx < eventHandlerCount; ++idx)
       
  1236 		{
       
  1237 		TWsEventHandler* eh = &iWsEventHandlers[idx];
       
  1238 		if (!eh->iEvents)
       
  1239 			{								//If the handler has been removed
       
  1240 			iWsEventHandlers.Remove(idx);	//Remove from the array
       
  1241 			drawerCount -= 1;				//Update the counters
       
  1242 			idx -= 1;
       
  1243 			}
       
  1244 		else
       
  1245 			{
       
  1246 			if (eh->iEvents & aEvent.Type())
       
  1247 				{
       
  1248 				eh->iHandler->DoHandleEvent(aEvent);
       
  1249 				}
       
  1250 			}
       
  1251 		}
       
  1252 	}
       
  1253 
       
  1254 void TWindowServerEvent::NotifyScreenDrawingEvent(const TRegion* aRegion)
       
  1255 	{
       
  1256 	if (aRegion && !aRegion->IsEmpty())
       
  1257 		{
       
  1258 		TWservCrEvent event(TWservCrEvent::EScreenDrawing,0,const_cast<TRegion*>(aRegion));
       
  1259 		NotifyDrawer(event);
       
  1260 		}
       
  1261 	}
       
  1262 
       
  1263 void TWindowServerEvent::NotifyScreenDrawingEvent(const TRect& aRect)
       
  1264 	{
       
  1265 	TRegionFix<1> reg(aRect);
       
  1266 	TWservCrEvent event(TWservCrEvent::EScreenDrawing,0,&reg);
       
  1267 	NotifyDrawer(event);
       
  1268 	}
       
  1269 
       
  1270 //
       
  1271 // CRawEventReceiver //
       
  1272 //
       
  1273 
       
  1274 CRawEventReceiver::CRawEventReceiver(TInt aPriority) : CActive(aPriority)
       
  1275 //
       
  1276 // Constructor
       
  1277 //
       
  1278 	{
       
  1279 	__DECLARE_NAME(_S("CRawEventReceiver"));
       
  1280 	}
       
  1281 
       
  1282 CRawEventReceiver::~CRawEventReceiver()
       
  1283 	{
       
  1284 	CActive::Cancel();
       
  1285 	}
       
  1286 
       
  1287 void CRawEventReceiver::ConstructL()
       
  1288 	{
       
  1289 	CActiveScheduler::Add(this);
       
  1290 	UserSvr::CaptureEventHook();
       
  1291 	Request();
       
  1292 	}
       
  1293 
       
  1294 void CRawEventReceiver::Request()
       
  1295 //
       
  1296 // Issue a request for the next event.
       
  1297 //
       
  1298 	{
       
  1299 	UserSvr::RequestEvent(iEventBuf,iStatus);
       
  1300 	SetActive();
       
  1301 	}
       
  1302 
       
  1303 void CRawEventReceiver::DoCancel()
       
  1304 //
       
  1305 // Cancel a pending event.
       
  1306 //
       
  1307 	{
       
  1308 	UserSvr::RequestEventCancel();
       
  1309 	}
       
  1310 
       
  1311 void CRawEventReceiver::RunL()
       
  1312 	{
       
  1313 //__PROFILE_START(11);
       
  1314 	if (WsPointer::PreProcessEvent(iEventBuf.Event()
       
  1315 #if defined(__WINS__)
       
  1316 													,ETrue
       
  1317 #endif
       
  1318 														  ))
       
  1319 		TWindowServerEvent::ProcessRawEvent(iEventBuf.Event());
       
  1320 	Request();
       
  1321 //__PROFILE_END(11);
       
  1322 	}
       
  1323 
       
  1324 //
       
  1325 // TEventRequestQueue //
       
  1326 //
       
  1327 
       
  1328 TEventRequestQueue::TEventRequestQueue() : iQueue(_FOFF(TEventRequestItem,iQue))
       
  1329 	{}
       
  1330 
       
  1331 inline TSglQue<TEventRequestItem> &TEventRequestQueue::Queue()
       
  1332 	{return(iQueue);}
       
  1333 
       
  1334 TEventRequestItem *TEventRequestQueue::FindInEventRequestQueueList(const CWsWindowBase &aWindow)
       
  1335 //
       
  1336 // Return a pointer to the link in the queue for the window, or NULL if not in the queue
       
  1337 //
       
  1338 	{
       
  1339 	TSglQueIter<TEventRequestItem> iter(iQueue);
       
  1340 	TEventRequestItem *qPtr;
       
  1341 	while((qPtr=iter++)!=NULL)
       
  1342 		if (qPtr->iWindow==&aWindow)
       
  1343 			break;
       
  1344 	return(qPtr);
       
  1345 	}
       
  1346 
       
  1347 void TEventRequestQueue::AddToEventRequestListL(const CWsWindowBase &aWindow, TInt aParam, TEventControl aCircumstances)
       
  1348 //
       
  1349 // Add a link to the on event list
       
  1350 //
       
  1351 	{
       
  1352 	TEventRequestItem *item=FindInEventRequestQueueList(aWindow);
       
  1353 	if (!item)
       
  1354 		{
       
  1355 		item=new(ELeave) TEventRequestItem;
       
  1356 		item->iWindow= &aWindow;
       
  1357 		item->iParam=aParam;
       
  1358 		item->iCircumstances=aCircumstances;
       
  1359 		iQueue.AddFirst(*item);
       
  1360 		}
       
  1361 	item->iCircumstances=aCircumstances;
       
  1362 	item->iParam=aParam;	// Just update the parameter if already exists
       
  1363 	}
       
  1364 
       
  1365 void TEventRequestQueue::RemoveFromEventRequestListL(const CWsWindowBase &aWindow)
       
  1366 //
       
  1367 // Remove a link from the on event list
       
  1368 //
       
  1369 	{
       
  1370 	TEventRequestItem *qPtr=FindInEventRequestQueueList(aWindow);
       
  1371 	if (qPtr)
       
  1372 		{
       
  1373 		iQueue.Remove(*qPtr);
       
  1374 		delete qPtr;
       
  1375 		}
       
  1376 	}
       
  1377 
       
  1378 //
       
  1379 // Keyboard auto repeat class //
       
  1380 //
       
  1381 
       
  1382 CKeyboardRepeat::CKeyboardRepeat() : CTimer(EKeyRepeatPriority)
       
  1383 	{}
       
  1384 
       
  1385 void CKeyboardRepeat::NewL()
       
  1386 	{
       
  1387 	iThis=new(ELeave) CKeyboardRepeat();
       
  1388 	iThis->ConstructL();
       
  1389 	CActiveScheduler::Add(iThis);
       
  1390 	_LIT(KWSERVIniFileVarRepeatRollover,"REPEATROLLOVER");
       
  1391 	WsIniFile->FindVar(KWSERVIniFileVarRepeatRollover,iRepeatRollover);
       
  1392 	}
       
  1393 
       
  1394 void CKeyboardRepeat::Destroy()
       
  1395 	{
       
  1396 	delete iThis;
       
  1397 	}
       
  1398 
       
  1399 void CKeyboardRepeat::GetRepeatTime(TTimeIntervalMicroSeconds32 &aInitialTime, TTimeIntervalMicroSeconds32 &aTime)
       
  1400 	{
       
  1401 	aInitialTime=iInitialTime;
       
  1402 	aTime=iTime;
       
  1403 	}
       
  1404 
       
  1405 void CKeyboardRepeat::SetRepeatTime(const TTimeIntervalMicroSeconds32 &aInitialTime, const TTimeIntervalMicroSeconds32 &aTime)
       
  1406 	{
       
  1407 	iInitialTime=aInitialTime;
       
  1408 	iTime=aTime;
       
  1409 	}
       
  1410 
       
  1411 void CKeyboardRepeat::RunL()
       
  1412 	{
       
  1413 	User::ResetInactivityTime();
       
  1414 	//WS_ASSERT_DEBUG(iRepeating!=ERepeatNone, EWsPanicTemp);
       
  1415 	TBool timer=ETrue;
       
  1416 	if (iRepeating>=ERepeatLong)
       
  1417 		{
       
  1418 		// Defensive programming - iLongCapture should never be NULL if iRepeating >= ERepeatLong
       
  1419 		if (iLongCapture)
       
  1420 			{
       
  1421 			iCurrentRepeat.iKey.iApp=REINTERPRET_CAST(TUint32,iLongCapture->iWindowGroup);
       
  1422 			iCurrentRepeat.iKey.iHandle=0;
       
  1423 			iCurrentRepeat.iKey.iIsCaptureKey=ETrue;
       
  1424 			iCurrentRepeat.iKey.iKeyCode=iLongCapture->iData.outputKey;
       
  1425 			timer=iLongCapture->iData.flags&ELongCaptureRepeatEvents;
       
  1426 			iRepeating=ERepeatLongRepeated;
       
  1427 			}
       
  1428 		else
       
  1429 			{
       
  1430 			// Defensive programming - iLongCapture should never be NULL if iRepeating >= ERepeatLong
       
  1431 			// Stop key repeat if this incorrect condition occurs
       
  1432 			timer=EFalse; 
       
  1433 			}		
       
  1434 		}
       
  1435 	if (timer)
       
  1436 		After(iTime);
       
  1437 	else
       
  1438 		iRepeating=ERepeatNone;
       
  1439 	TWindowServerEvent::QueueKeyPress(iCurrentRepeat.iKey,iCurrentRepeat.iScanCode,iFocus,EFalse,1);
       
  1440 	}
       
  1441 
       
  1442 TBool CKeyboardRepeat::StartRepeat(const TKeyData &aKey, TInt aScanCode, CWsWindowGroup *aRepeatFocus, CWsCaptureLongKey* aLongCapture)
       
  1443 	{
       
  1444 	TTimeIntervalMicroSeconds32 time;
       
  1445 	TBool ret=EFalse;
       
  1446 	iCurrentRepeat.iScanCode=aScanCode;
       
  1447 	iCurrentRepeat.iKey=aKey;
       
  1448 	iFocus=aRepeatFocus;
       
  1449 	if (aLongCapture)
       
  1450 		{
       
  1451 		iLongCapture=aLongCapture;
       
  1452 		iRepeating=ERepeatLong;
       
  1453 		time=aLongCapture->iData.delay;
       
  1454 		ret=!(aLongCapture->iData.flags&ELongCaptureShortEventImmediately);
       
  1455 		}
       
  1456 	else
       
  1457 		{
       
  1458 		iRepeating=ERepeatNormal;
       
  1459 		time=iInitialTime;
       
  1460 		}
       
  1461 	iThis->After(time);
       
  1462 	return ret;
       
  1463 	}
       
  1464 
       
  1465 void CKeyboardRepeat::doCancelRepeat()
       
  1466 	{
       
  1467 	iRepeating=ERepeatNone;
       
  1468 	iThis->Cancel();
       
  1469 	}
       
  1470 
       
  1471 void CKeyboardRepeat::CancelRepeat(CWsWindowGroup *aRepeatFocus)
       
  1472 	{
       
  1473 	if (aRepeatFocus==NULL || aRepeatFocus==iFocus)
       
  1474 		{
       
  1475 		if (iRepeating)
       
  1476 			doCancelRepeat();
       
  1477 		iAlternateRepeatExists=EFalse;
       
  1478 		}
       
  1479 	else if (iRepeating >= ERepeatLong)
       
  1480 		{
       
  1481 		// Defensive programming - iLongCapture should never be NULL if iRepeating >= ERepeatLong
       
  1482 		if (iLongCapture && iLongCapture->iWindowGroup == aRepeatFocus)
       
  1483 			{
       
  1484 			doCancelRepeat();
       
  1485 			iAlternateRepeatExists=EFalse;
       
  1486 			}
       
  1487 		}
       
  1488 	}
       
  1489 
       
  1490 void CKeyboardRepeat::CancelRepeat(CWsWindowGroup *aRepeatFocus,TUint aScanCode,TBool aLongCaptureFlag,TUint aModifiers)
       
  1491 	{
       
  1492 	// aLongCaptureFlag indicates if CancelRepeat caused by call to CancelCaptureLongKey()
       
  1493 	if (aLongCaptureFlag)
       
  1494 		{
       
  1495 		// long capture key is cancelled
       
  1496 		if (iRepeating >= ERepeatLong && iCurrentRepeat.iScanCode==aScanCode)			
       
  1497 				{
       
  1498 				// Defensive programming - iLongCapture should never be NULL if iRepeating >= ERepeatLong
       
  1499 				if (iLongCapture && aRepeatFocus == iLongCapture->iWindowGroup &&
       
  1500 					(aModifiers & iLongCapture->iData.modifierMask) == iLongCapture->iData.modifiers)
       
  1501 					{
       
  1502 					doCancelRepeat();
       
  1503 					iAlternateRepeatExists=EFalse;
       
  1504 					}
       
  1505 				}
       
  1506 		}
       
  1507 	else
       
  1508 		{
       
  1509 		// normal capture key is cancelled
       
  1510 		if (aRepeatFocus==iFocus)
       
  1511 			{
       
  1512 			if (iRepeating>=ERepeatNormal && iCurrentRepeat.iScanCode==aScanCode)
       
  1513 				{
       
  1514 				doCancelRepeat();
       
  1515 				}
       
  1516 			iAlternateRepeatExists=EFalse;
       
  1517 			}
       
  1518 		}
       
  1519 	}
       
  1520 	
       
  1521 void CKeyboardRepeat::KeyDown()
       
  1522 	{
       
  1523 	if (iRepeating!=ERepeatNone)
       
  1524 		{
       
  1525 		if (iRepeating==ERepeatNormal && iRepeatRollover>0) // 1 Allow key repeat rollover
       
  1526 			{
       
  1527 			iAlternateRepeat=iCurrentRepeat;
       
  1528 			iAlternateRepeatExists=ETrue;
       
  1529 			}
       
  1530 		doCancelRepeat();
       
  1531 		}
       
  1532 	}
       
  1533 
       
  1534 void CKeyboardRepeat::KeyUp(TInt aScanCode)
       
  1535 	{
       
  1536 	if (iAlternateRepeatExists && iAlternateRepeat.iScanCode==aScanCode)
       
  1537 		iAlternateRepeatExists=EFalse;
       
  1538 	if (iRepeating!=ERepeatNone && iCurrentRepeat.iScanCode==aScanCode)
       
  1539 		{
       
  1540 		if (iRepeating==ERepeatLong)
       
  1541 			{
       
  1542 			// Defensive programming - iLongCapture should never be NULL if iRepeating >= ERepeatLong		
       
  1543 			if (iLongCapture && !(iLongCapture->iData.flags&ELongCaptureShortEventImmediately))
       
  1544 				{
       
  1545 				TWindowServerEvent::QueueKeyPress(iCurrentRepeat.iKey,iCurrentRepeat.iScanCode,NULL,EFalse,0);
       
  1546 				}
       
  1547 			}
       
  1548 		if (iAlternateRepeatExists)
       
  1549 			{
       
  1550 			iAlternateRepeatExists=EFalse;
       
  1551 			iCurrentRepeat=iAlternateRepeat;
       
  1552 			iRepeating=ERepeatNormal;
       
  1553 			}
       
  1554 		else
       
  1555 			doCancelRepeat();
       
  1556 		}
       
  1557 	}
       
  1558 
       
  1559 //
       
  1560 // CWsHotKey //
       
  1561 //
       
  1562 
       
  1563 CWsHotKey::CWsHotKey(TInt aHotKeyType, TBool aIsDefault) : 
       
  1564 	iHotKeyType(aHotKeyType),
       
  1565 	iIsDefault(aIsDefault)
       
  1566 	{
       
  1567 	}
       
  1568 
       
  1569 CWsHotKey::~CWsHotKey()
       
  1570 	{
       
  1571 	delete iCaptureKey;
       
  1572 	}
       
  1573 
       
  1574 void CWsHotKey::ConstructLD(const TWsWinCmdCaptureKey &aCaptureKey)
       
  1575 	{
       
  1576 	CleanupStack::PushL(this);
       
  1577 	iCaptureKey=new(ELeave) CWsCaptureKey(NULL);
       
  1578 	iCaptureKey->ConstructL(aCaptureKey);
       
  1579 	CleanupStack::Pop();
       
  1580 	}
       
  1581 
       
  1582 void CWsHotKey::SetL(const TWsWinCmdCaptureKey &aCaptureKey)
       
  1583 	{
       
  1584 	iCaptureKey->SetL(aCaptureKey);
       
  1585 	}
       
  1586 
       
  1587