windowing/windowserver/nga/SERVER/EVENT.CPP
changeset 0 5d03bc08d59c
child 4 15986eb6c500
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 "W32STD.H"
       
    21 #include <hal.h>
       
    22 #include <w32adll.h>
       
    23 #include "W32CLICK.H"
       
    24 #include "server.h"
       
    25 #include "windowgroup.h"
       
    26 #include "KEYCLICK.H"
       
    27 #include "wstop.h"
       
    28 #include "panics.h"
       
    29 #include "screen.h"
       
    30 #include "inifile.h"
       
    31 #include "password.h"
       
    32 #include "pointer.h"
       
    33 #include "debugbar.h"
       
    34 #include "advancedpointereventhelper.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 RArray<TWindowServerEvent::TRawEventHandler> 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 	iEventHandlers.Close();
       
   205 	delete iNotificationHandlers;
       
   206 	iDrawerHandlers->Close();
       
   207 	delete iDrawerHandlers;
       
   208 	iWsEventHandlers.Close();
       
   209 	}
       
   210 
       
   211 void TWindowServerEvent::InitStaticsL()
       
   212 //
       
   213 // Create the CEvent active object.
       
   214 //
       
   215 	{
       
   216 #if defined(__WINS__)
       
   217 	WS_ASSERT_DEBUG(TWindowServerEvent::ENumHotKeys==EHotKeyLastKeyType+1, EWsPanicUnknownCaptureKey);
       
   218 #endif
       
   219 	iEventReceiver=new(ELeave) CRawEventReceiver(EEventPriority);
       
   220 	iEventReceiver->ConstructL();
       
   221 	iKeyTranslator=CKeyTranslator::New();
       
   222 	User::LeaveIfNull(iKeyTranslator);
       
   223     
       
   224 //  Change keyboard mapping according to information the HAL
       
   225 	TInt keyboardIndex;
       
   226 	if (HAL::Get(HALData::EKeyboardIndex,keyboardIndex)==KErrNone)
       
   227 		{
       
   228 		_LIT(KLitKeyDataDllName,"EKDATA.%02d");
       
   229 		TBuf<16> keyDataDllName;
       
   230 		keyDataDllName.Format(KLitKeyDataDllName,keyboardIndex);
       
   231 		iKeyTranslator->ChangeKeyData(keyDataDllName);
       
   232 		}
       
   233 
       
   234 	iCaptureKeys=new(ELeave) CCaptureKeys;
       
   235 	iCaptureKeys->Construct();
       
   236 	for (TInt index=0;index<TWindowServerEvent::ENumHotKeys;index++)
       
   237 		ConstructDefaultHotKeyL(index,DefaultHotKeys[index]);
       
   238 	CKeyboardRepeat::NewL();
       
   239 	CKeyboardRepeat::SetRepeatTime(EDefaultInitialRepeatTime, EDefaultRepeatTime);
       
   240 	iEventHandlers=RArray<TRawEventHandler>(2);
       
   241 	iNotificationHandlers=new(ELeave) CArrayFixFlat<SNotificationHandler>(2);
       
   242 	iDrawerHandlers = new(ELeave) RArray<TDrawerHandler>(4);
       
   243 	}
       
   244 
       
   245 void TWindowServerEvent::LinkHotKey(CWsHotKey *aWsHotKey)
       
   246 	{
       
   247 	aWsHotKey->SetLink(iHotKeys);
       
   248 	iHotKeys=aWsHotKey;
       
   249 	}
       
   250 
       
   251 void TWindowServerEvent::ConstructDefaultHotKeyL(TInt aHotKey, const TWsWinCmdCaptureKey &aSystemKey)
       
   252 	{
       
   253 	CWsHotKey* hotKey=new(ELeave) CWsHotKey(aHotKey, ETrue);
       
   254 	// hotKey is pushed onto the cleanup stack in method ConstructLD.
       
   255 	hotKey->ConstructLD(aSystemKey);
       
   256 	LinkHotKey(hotKey);
       
   257 	}
       
   258 
       
   259 CWsHotKey* TWindowServerEvent::ClearHotKeysL(TInt aHotKey)
       
   260 	{
       
   261 	if (aHotKey>ENumHotKeys)
       
   262 		{
       
   263 		User::Leave(KErrArgument);
       
   264 		}
       
   265 	CWsHotKey** pHotKey= &iHotKeys;
       
   266 	CWsHotKey* defaultHotKey=NULL;
       
   267 	while(*pHotKey)
       
   268 		{
       
   269 		TBool unlinked=EFalse;
       
   270 		if ((*pHotKey)->HotKeyType()==aHotKey)
       
   271 			{
       
   272 			CWsHotKey *free=*pHotKey;
       
   273 			if (free->IsDefault())
       
   274 				{
       
   275 				free->SetL(ImpossibleKeyPress);
       
   276 				defaultHotKey=free;
       
   277 				}
       
   278 			else
       
   279 				{
       
   280 				*pHotKey=(*pHotKey)->iNext;
       
   281 				delete free;
       
   282 				unlinked=ETrue;
       
   283 				}
       
   284 			}
       
   285 		if (!unlinked)
       
   286 			{
       
   287 			pHotKey=&(*pHotKey)->iNext;
       
   288 			}
       
   289 		}
       
   290 	return(defaultHotKey);
       
   291 	}
       
   292 
       
   293 void TWindowServerEvent::ResetDefaultHotKeyL(TInt aHotKey)
       
   294 	{
       
   295 	if ((aHotKey<0) || (aHotKey>=ENumHotKeys))
       
   296 		{
       
   297 		User::Leave(KErrArgument);
       
   298 		}
       
   299 	CWsHotKey* defaultHotKey=ClearHotKeysL(aHotKey);
       
   300 	WS_ASSERT_DEBUG(defaultHotKey, EWsPanicDefaultHotKeyNotFound);
       
   301 	defaultHotKey->SetL(DefaultHotKeys[aHotKey]);
       
   302 	}
       
   303 
       
   304 void TWindowServerEvent::SetHotKeyL(const TWsClCmdSetHotKey &aHotKey)
       
   305 	{
       
   306 	if (aHotKey.type>ENumHotKeys)
       
   307 		User::Leave(KErrArgument);
       
   308 //
       
   309 	CWsHotKey *hotKey=new(ELeave) CWsHotKey(aHotKey.type, EFalse);
       
   310 //
       
   311 	TWsWinCmdCaptureKey captureKey;
       
   312 	captureKey.modifiers=aHotKey.modifiers;
       
   313 	captureKey.modifierMask=aHotKey.modifierMask;
       
   314 	captureKey.key=aHotKey.keycode;
       
   315 	hotKey->ConstructLD(captureKey);
       
   316 //
       
   317 	LinkHotKey(hotKey);
       
   318 	}
       
   319 
       
   320 void TWindowServerEvent::AddEventHandler(MEventHandler *aEventHandler, TBool aAdvancedPointersEnabled)
       
   321 	{
       
   322 #if defined(_DEBUG)
       
   323 	TRAPD(err,iEventHandlers.AppendL(TRawEventHandler(aEventHandler, aAdvancedPointersEnabled)));
       
   324 	WS_ASSERT_DEBUG(err==KErrNone, EWsPanicEventHandlerInconsistency);
       
   325 #else
       
   326 	iEventHandlers.AppendL(TRawEventHandler(aEventHandler, aAdvancedPointersEnabled));	//Shouldn't leave
       
   327 #endif
       
   328 	}
       
   329 
       
   330 void TWindowServerEvent::RemoveEventHandler(const MEventHandler *aEventHandler)
       
   331 	{
       
   332 	TInt count=iEventHandlers.Count();
       
   333 	TInt ii;
       
   334 	for(ii=0;ii<count;++ii)
       
   335 		{
       
   336 		if (iEventHandlers[ii].iEventHandler==aEventHandler)
       
   337 			{
       
   338 			if (iEventHandlerCount>0)  
       
   339 				{
       
   340 				iBinaryFlags |= ERemovedEventHandlerWhileProcessingRawEvents;
       
   341 				iEventHandlers[ii].iEventHandler=NULL; // replace the Handler with null to keep size of the array
       
   342 				}
       
   343 			else 
       
   344 				{
       
   345 				iEventHandlers.Remove(ii);
       
   346 				}
       
   347 			return;
       
   348 			}
       
   349 		}
       
   350 	}
       
   351 
       
   352 void TWindowServerEvent::PotentialEventHandlerL(TInt aNum)
       
   353 	{
       
   354 	iPotentialEventHandlers+=aNum;
       
   355 	WS_ASSERT_DEBUG(iPotentialEventHandlers>=iEventHandlers.Count(), EWsPanicEventHandlerInconsistency);
       
   356 	TRAPD(err,iEventHandlers.Reserve(iPotentialEventHandlers));
       
   357 	if (err!=KErrNone)
       
   358 		{
       
   359 		if (aNum>0)
       
   360 			User::Leave(err);
       
   361 		}
       
   362 	else if (iPotentialEventHandlers==0)
       
   363 		iEventHandlers.Compress();
       
   364 	}
       
   365 
       
   366 void SendSwitchOnEvent(TEventRequestItem *aQptr, TInt aEvent, TInt )
       
   367 	{
       
   368 	aQptr->iWindow->QueueEvent(aEvent);
       
   369 	}
       
   370 
       
   371 /*void SendSwitchOffEvent(TEventRequestItem *aQptr, TInt , TInt )
       
   372 	{
       
   373 	aQptr->iWindow->QueueEvent(EEventSwitchOff);
       
   374 	}*/
       
   375 
       
   376 void SendErrorMessage(TEventRequestItem *aQptr, TInt aCategory, TInt aError)
       
   377 	{
       
   378 	TWsEvent event;
       
   379 	event.SetType(EEventErrorMessage);
       
   380 	event.SetHandle(aQptr->iWindow->ClientHandle());
       
   381 	event.ErrorMessage()->iErrorCategory=(TWsErrorMessage::TErrorCategory)aCategory;
       
   382 	event.ErrorMessage()->iError=aError;
       
   383 	event.SetTimeNow();
       
   384 	aQptr->iWindow->EventQueue()->QueueEvent(event,EEventPriorityHigh);
       
   385 	}
       
   386 
       
   387 void SendModifierChangedEvent(TEventRequestItem *aQptr, TInt aChanged, TInt )
       
   388 	{
       
   389 	TInt tmpChanged=aChanged&aQptr->iParam;
       
   390 	if (tmpChanged)
       
   391 		{
       
   392 		TWsEvent event;
       
   393 		event.SetType(EEventModifiersChanged);
       
   394 		event.SetHandle(aQptr->iWindow->ClientHandle());
       
   395 		event.ModifiersChanged()->iChangedModifiers=tmpChanged;
       
   396 		event.ModifiersChanged()->iModifiers=TWindowServerEvent::GetStoredModifierState();
       
   397 		event.SetTimeNow();
       
   398 		aQptr->iWindow->EventQueue()->QueueEvent(event,EEventPriorityHigh);
       
   399 		}
       
   400 	}
       
   401 
       
   402 void TWindowServerEvent::ProcessEventQueue(TEventRequestQueue &aQueue, TSendEventFunc aFunc, TInt aParam1, TInt aParam2)
       
   403 	{
       
   404 	TSglQueIter<TEventRequestItem> iter(aQueue.Queue());
       
   405 	TEventRequestItem *qPtr;
       
   406 	CWsWindowGroup *focusWin=CWsTop::FocusWindowGroup();
       
   407 	while((qPtr=iter++)!=NULL)
       
   408 		{
       
   409 		if (qPtr->iCircumstances==EEventControlAlways || 
       
   410 			(qPtr->iCircumstances==EEventControlOnlyWithKeyboardFocus && qPtr->iWindow->WinGroup()==focusWin) ||
       
   411 			(qPtr->iCircumstances==EEventControlOnlyWhenVisible && !qPtr->iWindow->TreeIsObscured()))
       
   412 			aFunc(qPtr, aParam1, aParam2);
       
   413 		}
       
   414 	}
       
   415 
       
   416 void TWindowServerEvent::NotifyOom()
       
   417 	{
       
   418 	TTime now;
       
   419 	now.UniversalTime();
       
   420 	TTimeIntervalSeconds interval;
       
   421 	TInt err=now.SecondsFrom(iPrevOomMessageTime,interval);
       
   422 	if (err!=KErrNone || interval.Int()<0 || interval.Int()>EOomEventSecondGap)
       
   423 		{
       
   424 		ProcessErrorMessages(TWsErrorMessage::EDrawingRegion,KErrNoMemory);
       
   425 		iPrevOomMessageTime=now;
       
   426 		}
       
   427 	}
       
   428 
       
   429 TBool TWindowServerEvent::ProcessErrorMessages(TWsErrorMessage::TErrorCategory aCategory, TInt aError)
       
   430 	{
       
   431 	if (aError!=KErrNone)
       
   432 		{
       
   433 		ProcessEventQueue(iErrorMessageQueue, SendErrorMessage, aCategory, aError);
       
   434 		return ETrue;
       
   435 		}
       
   436 	return EFalse;
       
   437 	}
       
   438 
       
   439 void TWindowServerEvent::ProcessModifierChanges()
       
   440 	{
       
   441 	TInt newState=iKeyTranslator->GetModifierState();
       
   442 	if (newState!=iModifierState)
       
   443 		{
       
   444 		TInt changed=iModifierState^newState;
       
   445 		iModifierState=newState;
       
   446 		ProcessEventQueue(iModifierChangedQueue, SendModifierChangedEvent, changed, 0);
       
   447 		}
       
   448 	}
       
   449 
       
   450 TEventQueueWalkRet FindScreenDeviceChangedEvent(TAny *aHandlePtr, TWsEvent *aEvent)
       
   451 	{
       
   452 	if (aEvent->Type()==EEventScreenDeviceChanged && aEvent->Handle()==*(TUint *)aHandlePtr)
       
   453 		*(TUint *)aHandlePtr=0;	// Indicates event found
       
   454 	return(EEventQueueWalkOk);
       
   455 	}
       
   456 	
       
   457 void TWindowServerEvent::SendScreenDeviceChangedEvents(CScreen* aScreen)
       
   458 	{
       
   459 	TSglQueIter<TEventRequestItem> iter(iScreenDeviceChangedQueue .Queue());
       
   460 	TEventRequestItem *qPtr;
       
   461 	while((qPtr=iter++)!=NULL)
       
   462 		SendScreenDeviceChangedEvent(qPtr->iWindow);
       
   463 	if(CClick::IsHandler())
       
   464 		{
       
   465 		TClickMakerData clickMakerData;
       
   466 		clickMakerData.screenDeviceMode=aScreen->ScreenSizeMode();
       
   467 		CClick::OtherEvent(EEventScreenDeviceChanged, &clickMakerData);
       
   468 		}
       
   469 	TWsEvent wsEvent;
       
   470 	wsEvent.SetType(EEventScreenDeviceChanged);
       
   471 	TWindowServerEvent::PublishNotification(wsEvent);
       
   472 	TWservCrEvent crEvent(TWservCrEvent::EScreenSizeModeChanged,aScreen->ScreenSizeMode());
       
   473 	TWindowServerEvent::NotifyDrawer(crEvent);
       
   474 	}
       
   475 
       
   476 void TWindowServerEvent::SendScreenDeviceChangedEvent(const CWsWindowBase *aWindow)
       
   477 	{
       
   478 	CEventQueue *queue=aWindow->EventQueue();
       
   479 	TUint32 handle=aWindow->ClientHandle();
       
   480 	queue->WalkEventQueue(&FindScreenDeviceChangedEvent,&handle);
       
   481 	if (handle!=NULL)	// Indicates event not found
       
   482 		queue->QueueEvent(handle, EEventScreenDeviceChanged);
       
   483 	}
       
   484 
       
   485 TEventQueueWalkRet FindGroupChangedEvent(TAny *aHandlePtr, TWsEvent *aEvent)
       
   486 	{
       
   487 	if (aEvent->Type()==EEventWindowGroupsChanged && aEvent->Handle()==*(TUint *)aHandlePtr)
       
   488 		{
       
   489 		*(TUint *)aHandlePtr=0;	// Indicates event found
       
   490 		}
       
   491 	return(EEventQueueWalkOk);
       
   492 	}
       
   493 	
       
   494 void TWindowServerEvent::SendGroupChangedEvents()
       
   495 	{
       
   496 	TSglQueIter<TEventRequestItem> iter(iGroupChangedQueue.Queue());
       
   497 	TEventRequestItem *qPtr;
       
   498 	while((qPtr=iter++)!=NULL)
       
   499 		{
       
   500 		const CWsWindowBase *win=qPtr->iWindow;
       
   501 		CEventQueue *queue=win->EventQueue();
       
   502 		TUint32 handle=win->ClientHandle();
       
   503 		queue->WalkEventQueue(&FindGroupChangedEvent,&handle);
       
   504 		if (handle!=NULL)	// Indicates event not found
       
   505 			{
       
   506 			queue->QueueEvent(handle, EEventWindowGroupsChanged);
       
   507 			}
       
   508 		}
       
   509 	}	
       
   510 
       
   511 TEventQueueWalkRet FindFocusChangedEvent(TAny *aHandlePtr, TWsEvent *aEvent)
       
   512 	{
       
   513 	if (aEvent->Type()==EEventFocusGroupChanged && aEvent->Handle()==*(TUint *)aHandlePtr)
       
   514 		{
       
   515 		*(TUint *)aHandlePtr=0;	// Indicates event found
       
   516 		}
       
   517 	return(EEventQueueWalkOk);
       
   518 	}
       
   519 	
       
   520 void TWindowServerEvent::SendFocusChangedEvents()
       
   521 	{
       
   522 	TInt identifier=0;	// Zero Identifier indicates, currently there is no focused window group
       
   523 	CScreen* currentFocusScreen=CWsTop::CurrentFocusScreen();	
       
   524 	TInt screenNumber=currentFocusScreen->ScreenNumber();
       
   525 	CWsWindowGroup* currentFocusWG=currentFocusScreen->FocusWindowGroup();
       
   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 TEventQueueWalkRet OverrideDisplayChangedEvent(TAny *aNewEvent, TWsEvent *aOldEvent)
       
   606 	{
       
   607 	TWsEvent* newEvent = static_cast<TWsEvent*>(aNewEvent);
       
   608 	if (aOldEvent->Type() == EEventDisplayChanged && 
       
   609 			aOldEvent->DisplayChanged()->iDisplayNumber == newEvent->DisplayChanged()->iDisplayNumber)
       
   610 		{
       
   611 		aOldEvent->SetTimeNow();
       
   612 		aOldEvent->DisplayChanged()->iConfigurationChangeId = newEvent->DisplayChanged()->iConfigurationChangeId;
       
   613 		aOldEvent->DisplayChanged()->iResolutionListChangeId = newEvent->DisplayChanged()->iResolutionListChangeId;
       
   614 		newEvent->DisplayChanged()->iDisplayNumber = KErrNotFound; //So the new event won't be placed on event queue again
       
   615 		}
       
   616 	return EEventQueueWalkOk;
       
   617 	}
       
   618 
       
   619 TBool TWindowServerEvent::SendDisplayChangedEvents(CWsClient* aWsClient, TInt aDisplayNumber, TInt aConfigurationChangeId, TInt aResolutionListChangeId)
       
   620 	{
       
   621 	CEventQueue *queue = aWsClient->EventQueue();
       
   622 	TWsEvent event;
       
   623 	event.SetType(EEventDisplayChanged);
       
   624 	event.SetTimeNow();
       
   625 	TWsDisplayChangedEvent* dispEvent = event.DisplayChanged();
       
   626 	dispEvent->iDisplayNumber = aDisplayNumber;
       
   627 	dispEvent->iConfigurationChangeId = aConfigurationChangeId;
       
   628 	dispEvent->iResolutionListChangeId = aResolutionListChangeId;
       
   629 	queue->WalkEventQueue(&OverrideDisplayChangedEvent, &event);
       
   630 	//place the new event on the queue only when its display number is valid (!=KErrNotFound)
       
   631 	if(event.DisplayChanged()->iDisplayNumber >= 0)
       
   632 		{
       
   633 		return queue->QueueEvent(event);
       
   634 		}
       
   635 	return ETrue;
       
   636 	}
       
   637 
       
   638 void TWindowServerEvent::QueueKeyEvent(CWsWindowGroup *aWin, TWsEvent &aEvent, TWservEventPriorities aPriority)
       
   639 	{
       
   640 	aEvent.SetTimeNow();
       
   641 	aWin->EventQueue()->QueueEvent(aEvent, aPriority);
       
   642 	}
       
   643 
       
   644 void TWindowServerEvent::QueueKeyPress(const TKeyData& aKey, TInt aScanCode, CWsWindowGroup* aRepeatFocus, TBool aCheckRepeat,TInt aRepeats)
       
   645  	{
       
   646 	CWsWindowGroup* focusWin=CWsTop::FocusWindowGroup();
       
   647 	TWsEvent event;
       
   648 	TKeyEvent& keyEvent=*event.Key();
       
   649 	keyEvent.iCode=aKey.iKeyCode;
       
   650 	keyEvent.iScanCode=aScanCode;
       
   651 	keyEvent.iModifiers=aKey.iModifiers;
       
   652 	keyEvent.iRepeats=aRepeats;
       
   653 	if (!aRepeatFocus && CClick::IsHandler())
       
   654 		CClick::KeyEvent(EEventKey,keyEvent);
       
   655 	CWsCaptureLongKey* longCapture=NULL;
       
   656 	if (aCheckRepeat)
       
   657 		longCapture=CWsCaptureLongKey::CheckForCapture(aKey.iKeyCode, aKey.iModifiers);
       
   658 	if (aKey.iIsCaptureKey)
       
   659 		{
       
   660 		if (aKey.iApp==NULL)	// Captured by Wserv itself
       
   661 			{
       
   662 			_LIT(KWSERVDebugLogCapturedKey,"WSERV Captured Key");
       
   663 			CScreen* focusScreen=CWsTop::CurrentFocusScreen();
       
   664 			TInt screenNo=focusScreen->ScreenNumber();
       
   665 			
       
   666 			if (wsDebugLog)
       
   667 				wsDebugLog->MiscMessage(CDebugLogBase::ELogEverything,KWSERVDebugLogCapturedKey);
       
   668 			CWsHotKey *hotKey=iHotKeys;
       
   669 			while(hotKey)
       
   670 				{
       
   671 				if (hotKey->KeyHandle()==aKey.iHandle)
       
   672 					{
       
   673 					switch(hotKey->HotKeyType())
       
   674 						{
       
   675 						case EHotKeyEnableLogging:
       
   676 							CWsTop::EnableLogging();
       
   677 							break;
       
   678 						case EHotKeyDisableLogging:
       
   679 							CWsTop::DisableLogging();
       
   680 							break;
       
   681 						case EHotKeyStateDump:
       
   682 							StateDump();
       
   683 							break;
       
   684 						case EHotKeyHeapDump:
       
   685 							HeapDump();
       
   686 							break;
       
   687 						case EHotKeyOfDeath:
       
   688 							if (!CWsPassword::PasswordModeActive())
       
   689 								{
       
   690 								const TBool currentJustInTimeValue=User::JustInTime();
       
   691 								if (currentJustInTimeValue)
       
   692 									{
       
   693 									User::SetJustInTime(EFalse);
       
   694 									}
       
   695 								CWsTop::KillForegroundSession();
       
   696 								if (currentJustInTimeValue)
       
   697 									{
       
   698 									User::SetJustInTime(ETrue);
       
   699 									}
       
   700 								}
       
   701 							break;
       
   702 						case EHotKeyShutDown:
       
   703 							CWsTop::Exit();
       
   704 							break;
       
   705 						case EHotKeyIncContrast:
       
   706 							focusScreen->IncContrast();
       
   707 							break;
       
   708 						case EHotKeyDecContrast:
       
   709 							focusScreen->DecContrast();
       
   710 							break;
       
   711 						case EHotKeyOff:
       
   712 							CWsTop::HandleSwitchOff(EEventKeySwitchOff,ETrue);
       
   713 							break;
       
   714 						case EHotKeyBacklightToggle:
       
   715 							{
       
   716 							TInt state;
       
   717 							if (!ProcessErrorMessages(TWsErrorMessage::EBackLight, HAL::Get(screenNo,HALData::EBacklightState,state)))
       
   718 								ProcessErrorMessages(TWsErrorMessage::EBackLight, HAL::Set(screenNo,HALData::EBacklightState,!state));
       
   719 							}
       
   720 							break;
       
   721 						case EHotKeyBacklightOn:
       
   722 							ProcessErrorMessages(TWsErrorMessage::EBackLight, HAL::Set(screenNo,HALData::EBacklightState,ETrue));
       
   723 							break;
       
   724 						case EHotKeyBacklightOff:
       
   725 							ProcessErrorMessages(TWsErrorMessage::EBackLight, HAL::Set(screenNo,HALData::EBacklightState,EFalse));
       
   726 							break;
       
   727 						case EHotKeyScreenDimension0:
       
   728 						case EHotKeyScreenDimension1:
       
   729 						case EHotKeyScreenDimension2:
       
   730 						case EHotKeyScreenDimension3:
       
   731 							focusScreen->doSetScreenMode(hotKey->HotKeyType()-EHotKeyScreenDimension0);
       
   732 							break;
       
   733 						case EHotKeyCycleDisplaySize:
       
   734 							focusScreen->CycleDisplaySize();
       
   735 							break;
       
   736 						case EHotKeyCycleOrientation:
       
   737 							focusScreen->CycleOrientation();
       
   738 							break;
       
   739 						case EHotKeyIncBrightness:
       
   740 							focusScreen->IncBrightness();
       
   741 							break;
       
   742 						case EHotKeyDecBrightness:
       
   743 							focusScreen->DecBrightness();
       
   744 							break;
       
   745 						case EHotKeyCycleFocusScreen:
       
   746 							CWsTop::SetCurrentFocusScreen((CWsTop::CurrentFocusScreen()->ScreenNumber()+1)%CWsTop::NumberOfScreens());
       
   747 							break;
       
   748 						}
       
   749 					return;
       
   750 					}
       
   751 				hotKey=hotKey->iNext;
       
   752 				}
       
   753 			WS_PANIC_ALWAYS(EWsPanicUnknownCaptureKey);
       
   754 			return;
       
   755 			}
       
   756 		focusWin=((CWsWindowGroup *)aKey.iApp);
       
   757 		_LIT(KWSERVDebugLogKeyCapturedByApp,"Key captured by app %d");
       
   758 		if (wsDebugLog)
       
   759 			wsDebugLog->MiscMessage(CDebugLogBase::ELogEverything,KWSERVDebugLogKeyCapturedByApp,focusWin->Identifier());
       
   760 		if (CWsPassword::PasswordModeActive() && focusWin!=CWsPassword::PasswordWindow()->WinGroup())
       
   761 			return;
       
   762 		}
       
   763 	if (aRepeatFocus && aRepeatFocus!=focusWin)
       
   764 		CKeyboardRepeat::CancelRepeat(NULL);		// Repeat is going to different window so cancel it and don't deliver this key
       
   765 	else if (focusWin!=NULL && focusWin->CheckForPriorityKey(aKey,aScanCode)==EFalse)
       
   766 		{
       
   767 		if (longCapture || (aCheckRepeat && !aRepeatFocus && aKey.iModifiers&EModifierAutorepeatable))
       
   768 			{
       
   769 			if (CKeyboardRepeat::StartRepeat(aKey,aScanCode,focusWin,longCapture))
       
   770 				return;
       
   771 			}
       
   772 		event.SetType(EEventKey);
       
   773 		event.SetHandle(focusWin->ClientHandle());
       
   774 		if (aRepeats!=0)
       
   775 			{
       
   776 			CEventQueue* queue=focusWin->EventQueue();
       
   777 			queue->Wait();
       
   778 			const TWsEvent* prev=queue->PeekLastEvent();
       
   779 			if (prev!=NULL && prev->Type()==EEventKey && prev->Key()->iRepeats>0)
       
   780 				{
       
   781 				event= *prev;
       
   782 				event.Key()->iRepeats+=aRepeats;
       
   783 				queue->UpdateLastEvent(event);
       
   784 				queue->Signal();
       
   785 				if (CClick::IsHandler())
       
   786 					CClick::KeyEvent(EEventKeyRepeat,*event.Key());
       
   787 				return;
       
   788 				}
       
   789 			queue->Signal();
       
   790 			event.Key()->iRepeats=aRepeats;
       
   791 			if (CClick::IsHandler())
       
   792 				CClick::KeyEvent(EEventKeyRepeat,keyEvent);
       
   793 			}
       
   794 		QueueKeyEvent(focusWin, event, EEventPriorityLow);
       
   795 		}
       
   796 	}
       
   797 
       
   798 void TWindowServerEvent::QueueKeyUpDown(const TRawEvent &aRawEvent)
       
   799  	{
       
   800 	CWsWindowGroup *focusWin=CWsCaptureKeyUpsAndDowns::CheckForCapture(aRawEvent.ScanCode() __REMOVE_WINS_CHARCODE, iModifierState);
       
   801 	if (!focusWin)	// If not captured
       
   802 		focusWin=CWsTop::FocusWindowGroup();
       
   803 	TWsEvent event;
       
   804 	TEventCode type=aRawEvent.Type()==TRawEvent::EKeyUp ? EEventKeyUp : EEventKeyDown;
       
   805 	event.Key()->iCode=0;
       
   806 #if defined(__WINS__)
       
   807 	if (focusWin && !focusWin->WsOwner()->RemoveKeyCode())
       
   808 		event.Key()->iScanCode=aRawEvent.ScanCode();
       
   809 	else
       
   810 #endif
       
   811 	event.Key()->iScanCode=aRawEvent.ScanCode() __REMOVE_WINS_CHARCODE;
       
   812 	event.Key()->iModifiers=iModifierState;
       
   813 	event.Key()->iRepeats=0;
       
   814 	if (CClick::IsHandler())
       
   815 		CClick::KeyEvent(type,*event.Key());
       
   816 	if (focusWin!=NULL)
       
   817 		{
       
   818 		event.SetType(type);
       
   819 		event.SetHandle(focusWin->ClientHandle());
       
   820 		QueueKeyEvent(focusWin, event, EEventPriorityHigh);
       
   821 		}
       
   822 	}
       
   823 
       
   824 LOCAL_D void GetPointerEvent(TPointerEvent::TType& aType, const TRawEvent &aRawEvent, TBool& aHandled)
       
   825 	{
       
   826 	aHandled=ETrue;
       
   827 	switch(aRawEvent.Type())
       
   828 		{
       
   829 	case TRawEvent::EButton1Down:
       
   830 		aType=TPointerEvent::EButton1Down;
       
   831 		break;
       
   832 	case TRawEvent::EButton1Up:
       
   833 		aType=TPointerEvent::EButton1Up;
       
   834 		break;
       
   835 	case TRawEvent::EButton2Down:
       
   836 		aType=TPointerEvent::EButton2Down;
       
   837 		break;
       
   838 	case TRawEvent::EButton2Up:
       
   839 		aType=TPointerEvent::EButton2Up;
       
   840 		break;
       
   841 	case TRawEvent::EButton3Down:
       
   842 		aType=TPointerEvent::EButton3Down;
       
   843 		break;
       
   844 	case TRawEvent::EButton3Up:
       
   845 		aType=TPointerEvent::EButton3Up;
       
   846 		break;
       
   847 	case TRawEvent::EPointerMove:
       
   848 		aType=TPointerEvent::EMove;
       
   849 		break;
       
   850 	case TRawEvent::EPointerSwitchOn:
       
   851 		aType=TPointerEvent::ESwitchOn;
       
   852 		break;
       
   853 	case TRawEvent::EPointer3DOutOfRange:
       
   854 		aType=TPointerEvent::EOutOfRange;
       
   855 		break;
       
   856 	default:
       
   857 		aHandled=EFalse;
       
   858 		}
       
   859 	}
       
   860 
       
   861 TBool TWindowServerEvent::MousePress(const TRawEvent &aRawEvent, const CWsWindowGroup *aGroupWin)
       
   862 	//
       
   863 	//Return EFalse if known not to be a Mouse Event
       
   864 	//
       
   865 	{
       
   866 	TBool handled=ETrue;
       
   867 	TPointerEvent::TType type;
       
   868 	GetPointerEvent(type, aRawEvent, handled);
       
   869 	if (handled)
       
   870 		{
       
   871 		TPoint3D point3D(0,0,0);
       
   872 		if (type != TPointerEvent::EOutOfRange)
       
   873 			{
       
   874 			point3D = aRawEvent.Pos3D();
       
   875 			}
       
   876 		TWsEvent event;
       
   877 		TAdvancedPointerEventHelper::InitAdvancedPointerEvent(event, type,iKeyTranslator->GetModifierState(),point3D,aRawEvent.PointerNumber());
       
   878 		TWsPointer::ProcessWsEvent(event, aGroupWin, ETrue);
       
   879 		}
       
   880 	return handled;
       
   881 	}
       
   882 
       
   883 LOCAL_D void SendEventToKeyClick(const TRawEvent& aRawEvent)
       
   884 	{
       
   885 	switch(aRawEvent.Type())
       
   886 		{
       
   887 		case TRawEvent::EKeyDown:
       
   888 		case TRawEvent::EKeyUp:
       
   889 			{
       
   890 			TKeyEvent keyEvent;
       
   891 			keyEvent.iCode=0;
       
   892 			keyEvent.iScanCode=aRawEvent.ScanCode();
       
   893 			keyEvent.iModifiers=0;
       
   894 			keyEvent.iRepeats=0;
       
   895 			CClick::KeyEvent(EEventKey,keyEvent);
       
   896 			}
       
   897 			break;
       
   898 		case TRawEvent::EButton1Down:
       
   899 		case TRawEvent::EButton1Up:
       
   900 		case TRawEvent::EButton2Down:
       
   901 		case TRawEvent::EButton2Up:
       
   902 		case TRawEvent::EButton3Down:
       
   903 		case TRawEvent::EButton3Up:
       
   904 		case TRawEvent::EPointerMove:
       
   905 		case TRawEvent::EPointerSwitchOn:
       
   906 			{
       
   907 			TBool handled=ETrue;
       
   908 			TPointerEvent::TType type;
       
   909 			GetPointerEvent(type, aRawEvent, handled);
       
   910 			if (handled)
       
   911 				{
       
   912 				TWsEvent event;
       
   913 				TAdvancedPointerEventHelper::InitAdvancedPointerEvent(event, type, 0, aRawEvent.Pos3D(), TPoint(), aRawEvent.PointerNumber());
       
   914 				TAdvancedPointerEvent& pointerEvent = *event.Pointer();
       
   915 				CClick::PointerEvent(pointerEvent.iPosition,pointerEvent);
       
   916 				}
       
   917 			}
       
   918 			break;
       
   919 		default:
       
   920 			break;
       
   921 		}
       
   922 	}
       
   923 
       
   924 void TWindowServerEvent::ProcessRawEvent(const TRawEvent& aRawEvent)
       
   925 //
       
   926 // Event has completed.
       
   927 //
       
   928 	{
       
   929 	TRawEvent::TType eventType = aRawEvent.Type();
       
   930 	TBool isPointerEvent = TWsPointer::IsPointerEventType(eventType);
       
   931 	if (isPointerEvent)
       
   932 		{
       
   933 		TWsPointer::UpdatePrimaryPointer(aRawEvent);
       
   934 		}
       
   935 	TInt count=iEventHandlers.Count();
       
   936 	TInt ii;
       
   937 	TBool eventHandled = EFalse;
       
   938 	iEventHandlerCount++;
       
   939 	for(ii=0;ii<count;++ii)
       
   940 		{
       
   941 		TRawEventHandler &handler = iEventHandlers[ii];
       
   942 		if (handler.iEventHandler != NULL &&
       
   943 			(!isPointerEvent ||
       
   944 			 handler.iAdvancedPointersEnabled ||
       
   945 			 aRawEvent.PointerNumber() == TWsPointer::PrimaryPointer()) &&
       
   946 			handler.iEventHandler->OfferRawEvent(aRawEvent))
       
   947 			{
       
   948 			if (CClick::IsHandler())
       
   949 				{
       
   950 				SendEventToKeyClick(aRawEvent);
       
   951 				}
       
   952 			eventHandled = ETrue;
       
   953 			break;
       
   954 			}
       
   955 		}
       
   956 	if (--iEventHandlerCount == 0)
       
   957 		{
       
   958 		if (ERemovedEventHandlerWhileProcessingRawEvents & iBinaryFlags) // Handler was deleted while previous loop
       
   959 			{ 
       
   960 			iBinaryFlags &= ~ERemovedEventHandlerWhileProcessingRawEvents;
       
   961 			for(ii=count-1;ii>=0;--ii)
       
   962 				{
       
   963 				if (iEventHandlers[ii].iEventHandler==NULL) iEventHandlers.Remove(ii);
       
   964 				}
       
   965 			}
       
   966 		}
       
   967 	if (eventHandled)
       
   968 		{
       
   969 		if (isPointerEvent)
       
   970 			{
       
   971 			TWsPointer::RollbackPrimaryPointer();
       
   972 			}
       
   973 		return;
       
   974 		}
       
   975 	switch(eventType)
       
   976 		{
       
   977 		case TRawEvent::ERedraw:
       
   978 			CWsTop::RedrawScreens();
       
   979 			break;
       
   980 		case TRawEvent::ESwitchOn:
       
   981 		case TRawEvent::ECaseOpen:
       
   982 			{
       
   983 			TInt event=EEventCaseOpened;
       
   984 			CKeyboardRepeat::CancelRepeat(NULL);
       
   985 			CWsPassword::SwitchOn();
       
   986 			if (eventType==TRawEvent::ESwitchOn)
       
   987 				{
       
   988 				UserSvr::WsSwitchOnScreen();
       
   989 				HAL::Set(HALData::EDisplayState,1);
       
   990 				event=EEventSwitchOn;
       
   991 				}
       
   992 			ProcessEventQueue(iSwitchOnQueue, SendSwitchOnEvent, event, 0);
       
   993 			break;
       
   994 			}
       
   995 		case TRawEvent::ESwitchOff:
       
   996 		case TRawEvent::ECaseClose:
       
   997 			{
       
   998 			TBool switchOff=(eventType==TRawEvent::ESwitchOff);
       
   999 			CWsTop::HandleSwitchOff(switchOff? EEventSwitchOff:EEventCaseClosed,switchOff);
       
  1000 			break;
       
  1001 			}
       
  1002 #ifdef SYMBIAN_PROCESS_MONITORING_AND_STARTUP			
       
  1003 		case TRawEvent::ERestartSystem:
       
  1004 			{ /* restart event being handled */
       
  1005 			CWsTop::HandleSwitchOff(EEventRestartSystem,ETrue);
       
  1006 			break;
       
  1007 			}
       
  1008 #endif			
       
  1009 		case TRawEvent::EInactive:
       
  1010 #ifndef __WINS__
       
  1011 			CWsTop::WindowServer()->AnimationScheduler()->OnInactive();
       
  1012 #endif
       
  1013 			CKeyboardRepeat::CancelRepeat(NULL);
       
  1014 			break;
       
  1015 		case TRawEvent::EActive:
       
  1016 #ifndef __WINS__
       
  1017 			CWsTop::WindowServer()->AnimationScheduler()->OnActive();
       
  1018 #endif
       
  1019 			break;
       
  1020 		case TRawEvent::EKeyDown:
       
  1021 			{
       
  1022 			_LIT(KWSERVDebugLogKeyDownArrival,"Key down arrives %d");
       
  1023 			if(CDebugBar* dbg = CWsTop::Screen()->DebugBar())
       
  1024 				dbg->OnKeyEvent();
       
  1025 			if (wsDebugLog)
       
  1026 				wsDebugLog->MiscMessage(CDebugLogBase::ELogEverything,KWSERVDebugLogKeyDownArrival,aRawEvent.ScanCode());
       
  1027 			CKeyboardRepeat::KeyDown();
       
  1028 			TKeyData keyData;
       
  1029 			TBool translated=iKeyTranslator->TranslateKey(aRawEvent.ScanCode(), EFalse,*iCaptureKeys,keyData);
       
  1030 			ProcessModifierChanges();
       
  1031 			QueueKeyUpDown(aRawEvent);
       
  1032 			if (translated)
       
  1033 				QueueKeyPress(keyData,aRawEvent.ScanCode() __REMOVE_WINS_CHARCODE,NULL,ETrue,0);
       
  1034 			}
       
  1035 			break;
       
  1036 		case TRawEvent::EKeyUp:
       
  1037 			{
       
  1038 			_LIT(KWSERVDebugLogKeyUpArrival,"Key up arrives %d");
       
  1039 			if(CDebugBar* dbg = CWsTop::Screen()->DebugBar())
       
  1040 				dbg->OnKeyEvent();
       
  1041 			if (wsDebugLog)
       
  1042 				wsDebugLog->MiscMessage(CDebugLogBase::ELogEverything,KWSERVDebugLogKeyUpArrival,aRawEvent.ScanCode());
       
  1043 			TKeyData keyData;
       
  1044 			CKeyboardRepeat::KeyUp(aRawEvent.ScanCode() __REMOVE_WINS_CHARCODE);
       
  1045 			TBool translated=iKeyTranslator->TranslateKey(aRawEvent.ScanCode(), ETrue,*iCaptureKeys,keyData);
       
  1046 			ProcessModifierChanges();
       
  1047 			QueueKeyUpDown(aRawEvent);
       
  1048 			if (translated)
       
  1049 				{
       
  1050 				CKeyboardRepeat::CancelRepeat(NULL);
       
  1051 				QueueKeyPress(keyData,aRawEvent.ScanCode() __REMOVE_WINS_CHARCODE,NULL,EFalse,0);
       
  1052 				}
       
  1053 			}
       
  1054 			break;
       
  1055 		case TRawEvent::EButton1Down:
       
  1056 		case TRawEvent::EButton2Down:
       
  1057 		case TRawEvent::EButton3Down:
       
  1058 		case TRawEvent::EPointerSwitchOn:
       
  1059 #ifndef __WINS__
       
  1060 			CWsTop::WindowServer()->AnimationScheduler()->OnActive();
       
  1061 #endif
       
  1062 			// fall through
       
  1063 		case TRawEvent::EButton1Up:
       
  1064 		case TRawEvent::EButton2Up:
       
  1065 		case TRawEvent::EButton3Up:
       
  1066 		case TRawEvent::EPointerMove:
       
  1067 		case TRawEvent::EPointer3DOutOfRange:
       
  1068 			#if defined(_DEBUG)
       
  1069 				WS_ASSERT_DEBUG(MousePress(aRawEvent,NULL), EWsPanicEventType);
       
  1070 			#else
       
  1071 				MousePress(aRawEvent,NULL);
       
  1072 			#endif
       
  1073 			break;
       
  1074 		case TRawEvent::EUpdateModifiers:
       
  1075 			iKeyTranslator->UpdateModifiers(aRawEvent.Modifiers());
       
  1076 			break;
       
  1077 		case TRawEvent::EKeyRepeat:
       
  1078  			{
       
  1079  			_LIT(KWSERVDebugLogRepeatingKeyArrival,"Repeating key arrives %d");
       
  1080  			if (wsDebugLog)
       
  1081  				wsDebugLog->MiscMessage(CDebugLogBase::ELogEverything,KWSERVDebugLogRepeatingKeyArrival,aRawEvent.ScanCode());
       
  1082  			TKeyData keyData;
       
  1083  			keyData.iModifiers=iKeyTranslator->GetModifierState();
       
  1084 			keyData.iApp=0;
       
  1085 			keyData.iHandle=0;
       
  1086 			keyData.iIsCaptureKey=EFalse;
       
  1087 			keyData.iKeyCode=aRawEvent.ScanCode(); 
       
  1088 			iCaptureKeys->ProcessCaptureKeys(keyData);
       
  1089 			QueueKeyPress(keyData, aRawEvent.ScanCode() __REMOVE_WINS_CHARCODE,NULL,EFalse,aRawEvent.Repeats());
       
  1090  			}
       
  1091  			break;
       
  1092 		default:
       
  1093 			break;
       
  1094 		}
       
  1095 	}
       
  1096 
       
  1097 void TWindowServerEvent::ProcessKeyEvent(const TKeyEvent &aKeyEvent,TInt aRepeats)
       
  1098 	{
       
  1099 	TKeyData keyData;
       
  1100 	keyData.iModifiers=aKeyEvent.iModifiers;
       
  1101 	keyData.iApp=0;
       
  1102 	keyData.iHandle=0;
       
  1103 	keyData.iIsCaptureKey=EFalse;
       
  1104 	keyData.iKeyCode=aKeyEvent.iCode;
       
  1105 	if (CKeyboardRepeat::IsAreadyActive())
       
  1106 		{
       
  1107 		CKeyboardRepeat::CancelRepeat(NULL);
       
  1108 		}
       
  1109 	iCaptureKeys->ProcessCaptureKeys(keyData);
       
  1110 	QueueKeyPress(keyData,aKeyEvent.iScanCode,NULL,aRepeats==0,aRepeats);
       
  1111 	}
       
  1112 
       
  1113 void TWindowServerEvent::AddCaptureKeyL(const TCaptureKey &aCaptureKey)
       
  1114 	{
       
  1115 	iCaptureKeys->AddCaptureKeyL(aCaptureKey,aCaptureKey.iKeyCodePattern.iFiller);
       
  1116 	}
       
  1117 
       
  1118 void TWindowServerEvent::SetCaptureKey(TUint32 aHandle, const TCaptureKey &aCaptureKey)
       
  1119 	{
       
  1120 	iCaptureKeys->SetCaptureKey(aHandle, aCaptureKey,aCaptureKey.iKeyCodePattern.iFiller);
       
  1121 	}
       
  1122 
       
  1123 void TWindowServerEvent::CancelCaptureKey(TUint32 aHandle)
       
  1124 	{
       
  1125 	iCaptureKeys->CancelCaptureKey(aHandle);
       
  1126 	}
       
  1127 
       
  1128 TInt TWindowServerEvent::GetModifierState()
       
  1129 	{
       
  1130 	return(iKeyTranslator->GetModifierState());
       
  1131 	}
       
  1132 
       
  1133 void TWindowServerEvent::SetModifierState(TEventModifier aModifier,TModifierState aState)
       
  1134 	{
       
  1135 	iKeyTranslator->SetModifierState(aModifier,aState);
       
  1136 	}
       
  1137 
       
  1138 TInt TWindowServerEvent::AddNotificationHandler(CAnim* aAnim, TUint32 aNotifications)
       
  1139 	{
       
  1140 	SNotificationHandler notif;
       
  1141 	notif.iAnim = aAnim;
       
  1142 	notif.iNotifications = aNotifications;
       
  1143 
       
  1144 	// update the entry if the anim is already in the array
       
  1145 	TInt count=iNotificationHandlers->Count();
       
  1146 	TInt ii;
       
  1147 	for(ii=0;ii<count;++ii)
       
  1148 		{
       
  1149 		if ((*iNotificationHandlers)[ii].iAnim==aAnim)
       
  1150 			{
       
  1151 			(*iNotificationHandlers)[ii]=notif;
       
  1152 			return KErrNone;
       
  1153 			}
       
  1154 		}
       
  1155 	
       
  1156 	// otherwise add it to the array
       
  1157 	TRAPD(err,iNotificationHandlers->AppendL(notif));
       
  1158 	return err;
       
  1159 	}
       
  1160 
       
  1161 void TWindowServerEvent::RemoveNotificationHandler(CAnim* aAnim)
       
  1162 	{
       
  1163 	TInt count=iNotificationHandlers->Count();
       
  1164 	TInt ii;
       
  1165 	for(ii=0;ii<count;++ii)
       
  1166 		{
       
  1167 		if ((*iNotificationHandlers)[ii].iAnim==aAnim)
       
  1168 			{
       
  1169 			iNotificationHandlers->Delete(ii);
       
  1170 			return;
       
  1171 			}
       
  1172 		}
       
  1173 	}
       
  1174 
       
  1175 void TWindowServerEvent::PublishNotification(const TWsEvent& aWsEvent)
       
  1176 	{
       
  1177 	TInt count=iNotificationHandlers->Count();
       
  1178 	TInt ii;
       
  1179 	for(ii=0;ii<count;++ii)
       
  1180 		{
       
  1181 		SNotificationHandler notif = (*iNotificationHandlers)[ii];
       
  1182 		switch (aWsEvent.Type())
       
  1183 			{
       
  1184 		case EEventDirectScreenAccessBegin:
       
  1185 		case EEventDirectScreenAccessEnd:
       
  1186 			if (notif.iNotifications & EDirectScreenAccess)
       
  1187 				{
       
  1188 				notif.iAnim->HandleNotification(aWsEvent);
       
  1189 				}
       
  1190 			break;
       
  1191 		case EEventHeartbeatTimerStateChange:
       
  1192 			if (notif.iNotifications & EHeartbeatTimer)
       
  1193 				{
       
  1194 				notif.iAnim->HandleNotification(aWsEvent);
       
  1195 				}
       
  1196 			break;
       
  1197 		case EEventScreenDeviceChanged:
       
  1198 			if (notif.iNotifications & EScreenDeviceChange)
       
  1199 				{
       
  1200 				notif.iAnim->HandleNotification(aWsEvent);
       
  1201 				}
       
  1202 			break;
       
  1203 		default:
       
  1204 			break;
       
  1205 			}
       
  1206 		}
       
  1207 
       
  1208 	}
       
  1209 
       
  1210 TBool TWindowServerEvent::DrawerCompareFunc(const TDrawerHandler& lhs, const TDrawerHandler& rhs)
       
  1211 	{
       
  1212 	return lhs.iDrawer == rhs.iDrawer;	
       
  1213 	}
       
  1214 
       
  1215 TInt TWindowServerEvent::RegisterDrawerHandler(CWsGraphicDrawer* aDrawer, TUint32 aEvents)
       
  1216 	{
       
  1217 	TInt idx = iDrawerHandlers->Find(TDrawerHandler(aDrawer, aEvents),
       
  1218 		TIdentityRelation<TDrawerHandler>(TWindowServerEvent::DrawerCompareFunc));
       
  1219 	if (idx != KErrNotFound)
       
  1220 		{
       
  1221 		// replace event mask for this drawer
       
  1222 		(*iDrawerHandlers)[idx].iEvents = aEvents;
       
  1223 		idx = KErrNone;
       
  1224 		}
       
  1225 	else
       
  1226 		idx = iDrawerHandlers->Append(TDrawerHandler(aDrawer,aEvents));
       
  1227 	
       
  1228 	return idx;
       
  1229 	}
       
  1230 
       
  1231 TInt TWindowServerEvent::UnregisterDrawerHandler(CWsGraphicDrawer* aDrawer)
       
  1232 	{
       
  1233 	TInt idx = iDrawerHandlers->Find(TDrawerHandler(aDrawer,0),
       
  1234 		TIdentityRelation<TDrawerHandler>(TWindowServerEvent::DrawerCompareFunc));
       
  1235 	if (idx == KErrNotFound)
       
  1236 		return idx;
       
  1237 	(*iDrawerHandlers)[idx].iDrawer = NULL;		//NotifyDrawer() will clean up the array
       
  1238 	return KErrNone;
       
  1239 	}
       
  1240 
       
  1241 TInt TWindowServerEvent::RegisterWsEventHandler(MWsEventHandler * aHandler, TUint32 aEvents)
       
  1242 	{
       
  1243 	TWsEventHandler handler(aHandler, aEvents);
       
  1244 	TInt idx = iWsEventHandlers.Find(handler, TIdentityRelation<TWsEventHandler>(TWsEventHandler::CompareHandler));
       
  1245 	if (idx < 0)
       
  1246 		{
       
  1247 		TInt err = iWsEventHandlers.Append(handler);
       
  1248 		return err;
       
  1249 		}
       
  1250 	else
       
  1251 		{
       
  1252 		iWsEventHandlers[idx].iEvents = aEvents;
       
  1253 		return KErrNone;
       
  1254 		}
       
  1255 	}
       
  1256 	
       
  1257 TInt TWindowServerEvent::UnregisterWsEventHandler(MWsEventHandler * aHandler)
       
  1258 	{
       
  1259 	TWsEventHandler handler(aHandler, 0);
       
  1260 	TInt idx = iWsEventHandlers.Find(handler, TIdentityRelation<TWsEventHandler>(TWsEventHandler::CompareHandler));
       
  1261 	if (idx < 0)
       
  1262 		return idx;
       
  1263 	iWsEventHandlers[idx].iEvents = NULL;	//NotifyDrawer() will clean up the array
       
  1264 	return KErrNone;
       
  1265 	}
       
  1266 
       
  1267 
       
  1268 void TWindowServerEvent::NotifyDrawer(const TWservCrEvent& aEvent)
       
  1269 	{
       
  1270 	TInt drawerCount = iDrawerHandlers->Count();
       
  1271 	for (TInt idx = 0; idx < drawerCount; idx++)
       
  1272 		{
       
  1273 		TDrawerHandler hd = (*iDrawerHandlers)[idx]; 
       
  1274 		if (!hd.iDrawer) 
       
  1275 			{                					//If the handler has been removed 
       
  1276 			iDrawerHandlers->Remove(idx);       //Remove from the array 
       
  1277 			drawerCount -= 1;   				//Update the counters 
       
  1278 			idx -= 1; 
       
  1279 			} 
       
  1280 		else 
       
  1281 			{ 
       
  1282 			if (hd.iEvents & aEvent.Type()) 
       
  1283 				{ 
       
  1284 			    hd.iDrawer->HandleEvent(aEvent); 
       
  1285 			    } 
       
  1286 			} 
       
  1287 		}
       
  1288 	
       
  1289 	TInt eventHandlerCount = iWsEventHandlers.Count();
       
  1290 	for (TInt idx = 0; idx < eventHandlerCount; ++idx)
       
  1291 		{
       
  1292 		TWsEventHandler* eh = &iWsEventHandlers[idx];
       
  1293 		if (!eh->iEvents)
       
  1294 			{								//If the handler has been removed
       
  1295 			iWsEventHandlers.Remove(idx);	//Remove from the array
       
  1296 			eventHandlerCount -= 1;			//Update the counters
       
  1297 			idx -= 1;
       
  1298 			}
       
  1299 		else
       
  1300 			{
       
  1301 			if (eh->iEvents & aEvent.Type())
       
  1302 				{
       
  1303 				eh->iHandler->DoHandleEvent(aEvent);
       
  1304 				}
       
  1305 			}
       
  1306 		}
       
  1307 	}
       
  1308 
       
  1309 void TWindowServerEvent::NotifyScreenDrawingEvent(const TRegion* aRegion)
       
  1310 	{
       
  1311 	if (aRegion && !aRegion->IsEmpty())
       
  1312 		{
       
  1313 		TWservCrEvent event(TWservCrEvent::EScreenDrawing,0,const_cast<TRegion*>(aRegion));
       
  1314 		NotifyDrawer(event);
       
  1315 		}
       
  1316 	}
       
  1317 
       
  1318 void TWindowServerEvent::NotifyScreenDrawingEvent(const TRect& aRect)
       
  1319 	{
       
  1320 	TRegionFix<1> reg(aRect);
       
  1321 	TWservCrEvent event(TWservCrEvent::EScreenDrawing,0,&reg);
       
  1322 	NotifyDrawer(event);
       
  1323 	}
       
  1324 
       
  1325 //
       
  1326 // CRawEventReceiver //
       
  1327 //
       
  1328 
       
  1329 CRawEventReceiver::CRawEventReceiver(TInt aPriority) : CActive(aPriority)
       
  1330 //
       
  1331 // Constructor
       
  1332 //
       
  1333 	{
       
  1334 	__DECLARE_NAME(_S("CRawEventReceiver"));
       
  1335 	}
       
  1336 
       
  1337 CRawEventReceiver::~CRawEventReceiver()
       
  1338 	{
       
  1339 	CActive::Cancel();
       
  1340 	}
       
  1341 
       
  1342 void CRawEventReceiver::ConstructL()
       
  1343 	{
       
  1344 	CActiveScheduler::Add(this);
       
  1345 	UserSvr::CaptureEventHook();
       
  1346 	Request();
       
  1347 	}
       
  1348 
       
  1349 void CRawEventReceiver::Request()
       
  1350 //
       
  1351 // Issue a request for the next event.
       
  1352 //
       
  1353 	{
       
  1354 	UserSvr::RequestEvent(iEventBuf,iStatus);
       
  1355 	SetActive();
       
  1356 	}
       
  1357 
       
  1358 void CRawEventReceiver::DoCancel()
       
  1359 //
       
  1360 // Cancel a pending event.
       
  1361 //
       
  1362 	{
       
  1363 	UserSvr::RequestEventCancel();
       
  1364 	}
       
  1365 
       
  1366 void CRawEventReceiver::RunL()
       
  1367 	{
       
  1368 //__PROFILE_START(11);
       
  1369 	if (TWsPointer::PreProcessDriverEvent(iEventBuf.Event()
       
  1370 #if defined(__WINS__)
       
  1371 													,ETrue
       
  1372 #endif
       
  1373 														  ))
       
  1374 		TWindowServerEvent::ProcessRawEvent(iEventBuf.Event());
       
  1375 	Request();
       
  1376 //__PROFILE_END(11);
       
  1377 	}
       
  1378 
       
  1379 //
       
  1380 // TEventRequestQueue //
       
  1381 //
       
  1382 
       
  1383 TEventRequestQueue::TEventRequestQueue() : iQueue(_FOFF(TEventRequestItem,iQue))
       
  1384 	{}
       
  1385 
       
  1386 inline TSglQue<TEventRequestItem> &TEventRequestQueue::Queue()
       
  1387 	{return(iQueue);}
       
  1388 
       
  1389 TEventRequestItem *TEventRequestQueue::FindInEventRequestQueueList(const CWsWindowBase &aWindow)
       
  1390 //
       
  1391 // Return a pointer to the link in the queue for the window, or NULL if not in the queue
       
  1392 //
       
  1393 	{
       
  1394 	TSglQueIter<TEventRequestItem> iter(iQueue);
       
  1395 	TEventRequestItem *qPtr;
       
  1396 	while((qPtr=iter++)!=NULL)
       
  1397 		if (qPtr->iWindow==&aWindow)
       
  1398 			break;
       
  1399 	return(qPtr);
       
  1400 	}
       
  1401 
       
  1402 void TEventRequestQueue::AddToEventRequestListL(const CWsWindowBase &aWindow, TInt aParam, TEventControl aCircumstances)
       
  1403 //
       
  1404 // Add a link to the on event list
       
  1405 //
       
  1406 	{
       
  1407 	TEventRequestItem *item=FindInEventRequestQueueList(aWindow);
       
  1408 	if (!item)
       
  1409 		{
       
  1410 		item=new(ELeave) TEventRequestItem;
       
  1411 		item->iWindow= &aWindow;
       
  1412 		item->iParam=aParam;
       
  1413 		item->iCircumstances=aCircumstances;
       
  1414 		iQueue.AddFirst(*item);
       
  1415 		}
       
  1416 	item->iCircumstances=aCircumstances;
       
  1417 	item->iParam=aParam;	// Just update the parameter if already exists
       
  1418 	}
       
  1419 
       
  1420 void TEventRequestQueue::RemoveFromEventRequestListL(const CWsWindowBase &aWindow)
       
  1421 //
       
  1422 // Remove a link from the on event list
       
  1423 //
       
  1424 	{
       
  1425 	TEventRequestItem *qPtr=FindInEventRequestQueueList(aWindow);
       
  1426 	if (qPtr)
       
  1427 		{
       
  1428 		iQueue.Remove(*qPtr);
       
  1429 		delete qPtr;
       
  1430 		}
       
  1431 	}
       
  1432 
       
  1433 //
       
  1434 // Keyboard auto repeat class //
       
  1435 //
       
  1436 
       
  1437 CKeyboardRepeat::CKeyboardRepeat() : CTimer(EKeyRepeatPriority)
       
  1438 	{}
       
  1439 
       
  1440 void CKeyboardRepeat::NewL()
       
  1441 	{
       
  1442 	iThis=new(ELeave) CKeyboardRepeat();
       
  1443 	iThis->ConstructL();
       
  1444 	CActiveScheduler::Add(iThis);
       
  1445 	_LIT(KWSERVIniFileVarRepeatRollover,"REPEATROLLOVER");
       
  1446 	WsIniFile->FindVar(KWSERVIniFileVarRepeatRollover,iRepeatRollover);
       
  1447 	}
       
  1448 
       
  1449 void CKeyboardRepeat::Destroy()
       
  1450 	{
       
  1451 	delete iThis;
       
  1452 	}
       
  1453 
       
  1454 void CKeyboardRepeat::GetRepeatTime(TTimeIntervalMicroSeconds32 &aInitialTime, TTimeIntervalMicroSeconds32 &aTime)
       
  1455 	{
       
  1456 	aInitialTime=iInitialTime;
       
  1457 	aTime=iTime;
       
  1458 	}
       
  1459 
       
  1460 void CKeyboardRepeat::SetRepeatTime(const TTimeIntervalMicroSeconds32 &aInitialTime, const TTimeIntervalMicroSeconds32 &aTime)
       
  1461 	{
       
  1462 	iInitialTime=aInitialTime;
       
  1463 	iTime=aTime;
       
  1464 	}
       
  1465 
       
  1466 void CKeyboardRepeat::RunL()
       
  1467 	{
       
  1468 	User::ResetInactivityTime();
       
  1469 	//WS_ASSERT_DEBUG(iRepeating!=ERepeatNone, EWsPanicTemp);
       
  1470 	TBool timer=ETrue;
       
  1471 	if (iRepeating>=ERepeatLong)
       
  1472 		{
       
  1473 		// Defensive programming - iLongCapture should never be NULL if iRepeating >= ERepeatLong
       
  1474 		if (iLongCapture)
       
  1475 			{
       
  1476 			iCurrentRepeat.iKey.iApp=REINTERPRET_CAST(TUint32,iLongCapture->iWindowGroup);
       
  1477 			iCurrentRepeat.iKey.iHandle=0;
       
  1478 			iCurrentRepeat.iKey.iIsCaptureKey=ETrue;
       
  1479 			iCurrentRepeat.iKey.iKeyCode=iLongCapture->iData.outputKey;
       
  1480 			timer=iLongCapture->iData.flags&ELongCaptureRepeatEvents;
       
  1481 			iRepeating=ERepeatLongRepeated;
       
  1482 			}
       
  1483 		else
       
  1484 			{
       
  1485 			// Defensive programming - iLongCapture should never be NULL if iRepeating >= ERepeatLong
       
  1486 			// Stop key repeat if this incorrect condition occurs
       
  1487 			timer=EFalse; 
       
  1488 			}		
       
  1489 		}
       
  1490 	if (timer)
       
  1491 		After(iTime);
       
  1492 	else
       
  1493 		iRepeating=ERepeatNone;
       
  1494 	TWindowServerEvent::QueueKeyPress(iCurrentRepeat.iKey,iCurrentRepeat.iScanCode,iFocus,EFalse,1);
       
  1495 	}
       
  1496 
       
  1497 TBool CKeyboardRepeat::StartRepeat(const TKeyData &aKey, TInt aScanCode, CWsWindowGroup *aRepeatFocus, CWsCaptureLongKey* aLongCapture)
       
  1498 	{
       
  1499 	TTimeIntervalMicroSeconds32 time;
       
  1500 	TBool ret=EFalse;
       
  1501 	iCurrentRepeat.iScanCode=aScanCode;
       
  1502 	iCurrentRepeat.iKey=aKey;
       
  1503 
       
  1504 	if (aLongCapture)
       
  1505 		{
       
  1506 		iLongCapture=aLongCapture;
       
  1507 		iRepeating=ERepeatLong;
       
  1508 		time=aLongCapture->iData.delay;
       
  1509 		ret=!(aLongCapture->iData.flags&ELongCaptureShortEventImmediately);
       
  1510 		//need window group from long capture key or even better delete it altogether.
       
  1511 		iFocus=aLongCapture->WindowGroup();
       
  1512 		}
       
  1513 	else
       
  1514 		{
       
  1515 		iFocus=aRepeatFocus;
       
  1516 		iRepeating=ERepeatNormal;
       
  1517 		time=iInitialTime;
       
  1518 		}
       
  1519 	iThis->After(time);
       
  1520 	return ret;
       
  1521 	}
       
  1522 
       
  1523 void CKeyboardRepeat::doCancelRepeat()
       
  1524 	{
       
  1525 	iRepeating=ERepeatNone;
       
  1526 	iThis->Cancel();
       
  1527 	}
       
  1528 
       
  1529 void CKeyboardRepeat::CancelRepeat(CWsWindowGroup *aRepeatFocus)
       
  1530 	{
       
  1531 	if (aRepeatFocus==NULL || aRepeatFocus==iFocus)
       
  1532 		{
       
  1533 		if (iRepeating)
       
  1534 			doCancelRepeat();
       
  1535 		iAlternateRepeatExists=EFalse;
       
  1536 		}
       
  1537 	else if (iRepeating >= ERepeatLong)
       
  1538 		{
       
  1539 		// Defensive programming - iLongCapture should never be NULL if iRepeating >= ERepeatLong
       
  1540 		if (iLongCapture && iLongCapture->iWindowGroup == aRepeatFocus)
       
  1541 			{
       
  1542 			doCancelRepeat();
       
  1543 			iAlternateRepeatExists=EFalse;
       
  1544 			}
       
  1545 		}
       
  1546 	}
       
  1547 
       
  1548 void CKeyboardRepeat::CancelRepeat(CWsWindowGroup *aRepeatFocus,TUint aScanCode,TBool aLongCaptureFlag,TUint aModifiers)
       
  1549 	{
       
  1550 	if (aLongCaptureFlag)
       
  1551 		{
       
  1552 		// long capture key is cancelled
       
  1553 		if (iRepeating >= ERepeatLong && iCurrentRepeat.iScanCode==aScanCode)			
       
  1554 				{
       
  1555 				// Defensive programming - iLongCapture should never be NULL if iRepeating >= ERepeatLong
       
  1556 				if (iLongCapture && aRepeatFocus == iLongCapture->iWindowGroup &&
       
  1557 					(aModifiers & iLongCapture->iData.modifierMask) == iLongCapture->iData.modifiers)
       
  1558 					{
       
  1559 					doCancelRepeat();
       
  1560 					iAlternateRepeatExists=EFalse;
       
  1561 					}
       
  1562 				}
       
  1563 		}
       
  1564 	else
       
  1565 		{
       
  1566 		// normal capture key is cancelled
       
  1567 		if (aRepeatFocus==iFocus)
       
  1568 			{
       
  1569 			if (iRepeating>=ERepeatNormal && iCurrentRepeat.iScanCode==aScanCode)
       
  1570 				{
       
  1571 				doCancelRepeat();
       
  1572 				}
       
  1573 			iAlternateRepeatExists=EFalse;
       
  1574 			}
       
  1575 		}
       
  1576 	}
       
  1577 	
       
  1578 void CKeyboardRepeat::KeyDown()
       
  1579 	{
       
  1580 	if (iRepeating!=ERepeatNone)
       
  1581 		{
       
  1582 		if (iRepeating==ERepeatNormal && iRepeatRollover>0) // 1 Allow key repeat rollover
       
  1583 			{
       
  1584 			iAlternateRepeat=iCurrentRepeat;
       
  1585 			iAlternateRepeatExists=ETrue;
       
  1586 			}
       
  1587 		doCancelRepeat();
       
  1588 		}
       
  1589 	}
       
  1590 
       
  1591 void CKeyboardRepeat::KeyUp(TInt aScanCode)
       
  1592 	{
       
  1593 	if (iAlternateRepeatExists && iAlternateRepeat.iScanCode==aScanCode)
       
  1594 		iAlternateRepeatExists=EFalse;
       
  1595 	if (iRepeating!=ERepeatNone && iCurrentRepeat.iScanCode==aScanCode)
       
  1596 		{
       
  1597 		if (iRepeating==ERepeatLong)
       
  1598 			{
       
  1599 			// Defensive programming - iLongCapture should never be NULL if iRepeating >= ERepeatLong			
       
  1600 			if (iLongCapture && !(iLongCapture->iData.flags&ELongCaptureShortEventImmediately))
       
  1601 				{
       
  1602 				TWindowServerEvent::QueueKeyPress(iCurrentRepeat.iKey,iCurrentRepeat.iScanCode,NULL,EFalse,0);	
       
  1603 				}
       
  1604 			}			
       
  1605 		if (iAlternateRepeatExists)
       
  1606 			{
       
  1607 			iAlternateRepeatExists=EFalse;
       
  1608 			iCurrentRepeat=iAlternateRepeat;
       
  1609 			iRepeating=ERepeatNormal;
       
  1610 			}
       
  1611 		else
       
  1612 			doCancelRepeat();
       
  1613 		}
       
  1614 	}
       
  1615 
       
  1616 //
       
  1617 // CWsHotKey //
       
  1618 //
       
  1619 
       
  1620 CWsHotKey::CWsHotKey(TInt aHotKeyType, TBool aIsDefault) : 
       
  1621 	iHotKeyType(aHotKeyType),
       
  1622 	iIsDefault(aIsDefault)
       
  1623 	{
       
  1624 	}
       
  1625 
       
  1626 CWsHotKey::~CWsHotKey()
       
  1627 	{
       
  1628 	delete iCaptureKey;
       
  1629 	}
       
  1630 
       
  1631 void CWsHotKey::ConstructLD(const TWsWinCmdCaptureKey &aCaptureKey)
       
  1632 	{
       
  1633 	CleanupStack::PushL(this);
       
  1634 	iCaptureKey=new(ELeave) CWsCaptureKey(NULL);
       
  1635 	iCaptureKey->ConstructL(aCaptureKey);
       
  1636 	CleanupStack::Pop();
       
  1637 	}
       
  1638 
       
  1639 void CWsHotKey::SetL(const TWsWinCmdCaptureKey &aCaptureKey)
       
  1640 	{
       
  1641 	iCaptureKey->SetL(aCaptureKey);
       
  1642 	}
       
  1643 
       
  1644 //
       
  1645 //CEventQueueRetry//
       
  1646 //
       
  1647 CEventQueueRetry* CEventQueueRetry::NewL()
       
  1648 	{
       
  1649 	CEventQueueRetry* self = new (ELeave) CEventQueueRetry;
       
  1650 	CleanupStack::PushL(self);
       
  1651 	self->ConstructL();
       
  1652 	CleanupStack::Pop(self);
       
  1653 	return self;
       
  1654 	}
       
  1655       
       
  1656 void CEventQueueRetry::ConstructL()
       
  1657 	{
       
  1658 	User::LeaveIfError(iTimer.CreateLocal());
       
  1659 	CActiveScheduler::Add(this);
       
  1660 	}
       
  1661  
       
  1662 CEventQueueRetry::CEventQueueRetry() : CActive(EPriorityStandard), iRetrySpinner(1)
       
  1663 	{
       
  1664 	
       
  1665 	}
       
  1666 
       
  1667 CEventQueueRetry::~CEventQueueRetry()
       
  1668 	{
       
  1669 	Cancel();
       
  1670 	iTimer.Close();
       
  1671 	iClientArray.Close();
       
  1672 	}
       
  1673 
       
  1674 void CEventQueueRetry::DoCancel()
       
  1675 	{
       
  1676 	iTimer.Cancel();
       
  1677 	iRetrySpinner = 0;
       
  1678 	iClientArray.Reset();
       
  1679 	}
       
  1680 
       
  1681 void CEventQueueRetry::RunL()
       
  1682 	{
       
  1683 	//some clients may be no longer interested in listening
       
  1684 	//so we need to refresh the client list each round of retry
       
  1685 	iClientArray.Reset();
       
  1686 	TInt err = iOwner->GetNotificationClients(iClientArray);
       
  1687 	if(err != KErrNone)
       
  1688 		{
       
  1689 		iClientArray.Reset(); //so the retry won't kick off
       
  1690 		}
       
  1691 	if(iClientArray.Count() > 0)
       
  1692 		{
       
  1693 		TBool eventOnAllQueues = ETrue;
       
  1694 		for(TInt i = 0; i < iClientArray.Count(); i++)
       
  1695 			{
       
  1696 			if(iClientArray[i]->RetryEvent(EEventDisplayChanged))
       
  1697 				{
       
  1698 				if(TWindowServerEvent::SendDisplayChangedEvents(iClientArray[i], iOwner->ScreenNumber(),
       
  1699 						iOwner->ConfigSpinner(), iOwner->DisplaySpinner()))
       
  1700 					{
       
  1701 					iClientArray[i]->RemoveRetryFlag(EEventDisplayChanged);
       
  1702 					}
       
  1703 				else
       
  1704 					{
       
  1705 					eventOnAllQueues = EFalse;
       
  1706 					}
       
  1707 				}
       
  1708 			}
       
  1709 		
       
  1710 		if(!eventOnAllQueues)
       
  1711 			{//another retry needed, but with increased time interval
       
  1712 			iRetrySpinner++;
       
  1713 			Retry(KRetryInitialDelay*iRetrySpinner);
       
  1714 			}
       
  1715 		}
       
  1716 	
       
  1717 	}
       
  1718 
       
  1719 void CEventQueueRetry::Retry(TInt aDelay)
       
  1720 	{
       
  1721 	//the retry might be infinite, with an increasing interval, as delivery of the event is garuanteed
       
  1722 	//if aDelay is greater than max TInt, it will be negative number so we reset it to KRetryInitialDelay
       
  1723 	if(aDelay < 0)
       
  1724 		{
       
  1725 		aDelay = KRetryInitialDelay;
       
  1726 		}
       
  1727 	iTimer.After(iStatus, aDelay);
       
  1728 	SetActive();
       
  1729 	}
       
  1730 
       
  1731 void CEventQueueRetry::Init(CScreen *aOwner)
       
  1732 	{
       
  1733 	iOwner = aOwner;
       
  1734 	iRetrySpinner = 0;
       
  1735 	
       
  1736 	}
       
  1737 
       
  1738 void CEventQueueRetry::CancelRetry()
       
  1739 	{
       
  1740 	Cancel();
       
  1741 	}