os/graphics/windowing/windowserver/nga/SERVER/EVENT.CPP
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
// Copyright (c) 1994-2010 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
// Top level window server code
sl@0
    15
// 
sl@0
    16
//
sl@0
    17
sl@0
    18
#include "EVENT.H"
sl@0
    19
sl@0
    20
#include "W32STD.H"
sl@0
    21
#include <e32uid.h>
sl@0
    22
#include <hal.h>
sl@0
    23
#include <w32adll.h>
sl@0
    24
#include "W32CLICK.H"
sl@0
    25
#include "server.h"
sl@0
    26
#include "windowgroup.h"
sl@0
    27
#include "KEYCLICK.H"
sl@0
    28
#include "wstop.h"
sl@0
    29
#include "panics.h"
sl@0
    30
#include "screen.h"
sl@0
    31
#include "inifile.h"
sl@0
    32
#include "password.h"
sl@0
    33
#include "pointer.h"
sl@0
    34
#include "debugbar.h"
sl@0
    35
#include "advancedpointereventhelper.h"
sl@0
    36
#include "graphics/wsgraphicdrawerinternal.h"
sl@0
    37
#include "debughelper.h"
sl@0
    38
sl@0
    39
GLREF_D CDebugLogBase *wsDebugLog;
sl@0
    40
sl@0
    41
GLREF_C void StateDump();
sl@0
    42
GLREF_C void HeapDump();
sl@0
    43
sl@0
    44
_LIT(KDefaultKeyRouterPluginName, "keyrouter.dll");
sl@0
    45
_LIT(KWSERVIniFileVarKeyRouterPlugin, "KEYROUTERPLUGIN");
sl@0
    46
sl@0
    47
#define IMPOSSIBLE 0xFFFFFFFF
sl@0
    48
sl@0
    49
const TWsWinCmdCaptureKey ImpossibleKeyPress=
sl@0
    50
	{
sl@0
    51
	IMPOSSIBLE,	// Impossible to hit key combination, used for disabling Hot Keys
sl@0
    52
	IMPOSSIBLE,
sl@0
    53
	IMPOSSIBLE};
sl@0
    54
sl@0
    55
const TWsWinCmdCaptureKey DefaultHotKeys[TWindowServerEvent::ENumHotKeys]={
sl@0
    56
	{	// Enable logging
sl@0
    57
	EModifierFunc|EModifierCtrl|EModifierShift,
sl@0
    58
	EModifierFunc|EModifierCtrl|EModifierShift,
sl@0
    59
	5}, // E
sl@0
    60
	{	// Disable logging
sl@0
    61
	EModifierFunc|EModifierCtrl|EModifierShift,
sl@0
    62
	EModifierFunc|EModifierCtrl|EModifierShift,
sl@0
    63
	4}, // D
sl@0
    64
	{	// Window server internal dump to log
sl@0
    65
	EModifierFunc|EModifierCtrl|EModifierShift,
sl@0
    66
	EModifierFunc|EModifierCtrl|EModifierShift,
sl@0
    67
	23},// W
sl@0
    68
	{	// The key of death
sl@0
    69
	EModifierFunc|EModifierCtrl|EModifierShift,
sl@0
    70
	EModifierFunc|EModifierCtrl|EModifierShift,
sl@0
    71
	11},// K
sl@0
    72
	{	// Shutdown window server
sl@0
    73
#if defined(_DEBUG)
sl@0
    74
	EModifierFunc|EModifierCtrl|EModifierShift,
sl@0
    75
	EModifierFunc|EModifierCtrl|EModifierShift,
sl@0
    76
	24},// X
sl@0
    77
#else
sl@0
    78
	IMPOSSIBLE,	// Impossible to hit key combination, effectively disables shutdown key in release builds
sl@0
    79
	IMPOSSIBLE,
sl@0
    80
	IMPOSSIBLE},
sl@0
    81
#endif
sl@0
    82
	{	// Heap dump
sl@0
    83
	EModifierFunc|EModifierCtrl|EModifierShift,
sl@0
    84
	EModifierFunc|EModifierCtrl|EModifierShift,
sl@0
    85
	8}, // H
sl@0
    86
	{	// Inc Contrast
sl@0
    87
	0,
sl@0
    88
	0,
sl@0
    89
	EKeyIncContrast},
sl@0
    90
	{	// Dec Contrast
sl@0
    91
	0,
sl@0
    92
	0,
sl@0
    93
	EKeyDecContrast},
sl@0
    94
	{	// Off
sl@0
    95
	0,
sl@0
    96
	0,
sl@0
    97
	EKeyOff},
sl@0
    98
	{	// Backlight on 
sl@0
    99
	0,
sl@0
   100
	0,
sl@0
   101
	EKeyBacklightOn},
sl@0
   102
	{	// Backlight off
sl@0
   103
	0,
sl@0
   104
	0,
sl@0
   105
	EKeyBacklightOff},
sl@0
   106
	{	// Backlight toggle
sl@0
   107
	0,
sl@0
   108
	0,
sl@0
   109
	EKeyBacklightToggle},
sl@0
   110
	{	// Screen Dimension Change
sl@0
   111
	0,
sl@0
   112
	0,
sl@0
   113
	EKeyScreenDimension0},
sl@0
   114
	{
sl@0
   115
	0,
sl@0
   116
	0,
sl@0
   117
	EKeyScreenDimension1},
sl@0
   118
	{
sl@0
   119
	0,
sl@0
   120
	0,
sl@0
   121
	EKeyScreenDimension2},
sl@0
   122
	{
sl@0
   123
	0,
sl@0
   124
	0,
sl@0
   125
	EKeyScreenDimension3},
sl@0
   126
#if defined(_DEBUG)
sl@0
   127
	{	// Display mode cycle
sl@0
   128
	EModifierFunc|EModifierCtrl|EModifierShift,
sl@0
   129
	EModifierFunc|EModifierCtrl|EModifierShift,
sl@0
   130
	21},// U
sl@0
   131
	{	// Orientation cycle
sl@0
   132
	EModifierFunc|EModifierCtrl|EModifierShift,
sl@0
   133
	EModifierFunc|EModifierCtrl|EModifierShift,
sl@0
   134
	15},// O
sl@0
   135
#else
sl@0
   136
	{	// Display mode cycle
sl@0
   137
	IMPOSSIBLE,	// Impossible to hit key combination
sl@0
   138
	IMPOSSIBLE,
sl@0
   139
	IMPOSSIBLE},
sl@0
   140
	{	// Orientation cycle
sl@0
   141
	IMPOSSIBLE,	// Impossible to hit key combination
sl@0
   142
	IMPOSSIBLE,
sl@0
   143
	IMPOSSIBLE},
sl@0
   144
#endif
sl@0
   145
	{	// Inc Brightness
sl@0
   146
	0,
sl@0
   147
	0,
sl@0
   148
	EKeyIncBrightness},
sl@0
   149
	{	// Dec Brightness
sl@0
   150
	0,
sl@0
   151
	0,
sl@0
   152
	EKeyDecBrightness},
sl@0
   153
	{	// Cycle focus screen
sl@0
   154
	EModifierFunc|EModifierCtrl|EModifierShift,
sl@0
   155
	EModifierFunc|EModifierCtrl|EModifierShift,
sl@0
   156
	9}, // I
sl@0
   157
	};
sl@0
   158
sl@0
   159
CKeyTranslator *TWindowServerEvent::iKeyTranslator=NULL;
sl@0
   160
TEventRequestQueue TWindowServerEvent::iSwitchOnQueue;
sl@0
   161
TEventRequestQueue TWindowServerEvent::iErrorMessageQueue;
sl@0
   162
TEventRequestQueue TWindowServerEvent::iModifierChangedQueue;
sl@0
   163
TEventRequestQueue TWindowServerEvent::iGroupChangedQueue;
sl@0
   164
TEventRequestQueue TWindowServerEvent::iFocusChangedQueue;
sl@0
   165
TEventRequestQueue TWindowServerEvent::iGroupListChangedQueue;
sl@0
   166
TEventRequestQueue TWindowServerEvent::iScreenDeviceChangedQueue;
sl@0
   167
TTime TWindowServerEvent::iPrevOomMessageTime;
sl@0
   168
CCaptureKeys *TWindowServerEvent::iCaptureKeys;
sl@0
   169
CKeyEventRouter* TWindowServerEvent::iKeyEventRouter;
sl@0
   170
RLibrary TWindowServerEvent::iKeyEventRouterLibrary;
sl@0
   171
CWsHotKey *TWindowServerEvent::iHotKeys;
sl@0
   172
TInt TWindowServerEvent::iModifierState;
sl@0
   173
CRawEventReceiver *TWindowServerEvent::iEventReceiver;
sl@0
   174
RArray<TWindowServerEvent::TRawEventHandler> TWindowServerEvent::iEventHandlers;
sl@0
   175
CArrayFixFlat<SNotificationHandler> *TWindowServerEvent::iNotificationHandlers;
sl@0
   176
TInt TWindowServerEvent::iPotentialEventHandlers=0;
sl@0
   177
TUint32 TWindowServerEvent::iBinaryFlags=0x00;
sl@0
   178
RArray<TDrawerHandler>* TWindowServerEvent::iDrawerHandlers;
sl@0
   179
RArray<TWsEventHandler> TWindowServerEvent::iWsEventHandlers;
sl@0
   180
TInt TWindowServerEvent::iEventHandlerCount=0;
sl@0
   181
TRepeatKey CKeyboardRepeat::iCurrentRepeat;
sl@0
   182
TRepeatKey CKeyboardRepeat::iAlternateRepeat;
sl@0
   183
TRepeatKey CKeyboardRepeat::iLongRepeat;
sl@0
   184
TInt CKeyboardRepeat::iRepeatRollover=1;
sl@0
   185
CKeyboardRepeat::TRepeatType CKeyboardRepeat::iRepeating=ERepeatNone;
sl@0
   186
CKeyboardRepeat *CKeyboardRepeat::iThis=NULL;
sl@0
   187
TTimeIntervalMicroSeconds32 CKeyboardRepeat::iInitialTime;
sl@0
   188
TTimeIntervalMicroSeconds32 CKeyboardRepeat::iTime;
sl@0
   189
TBool CKeyboardRepeat::iAlternateRepeatExists=EFalse;
sl@0
   190
CWsCaptureLongKey* CKeyboardRepeat::iLongCapture=NULL;
sl@0
   191
sl@0
   192
sl@0
   193
void TWindowServerEvent::DeleteHotKeys()
sl@0
   194
	{
sl@0
   195
	CWsHotKey *hotKey=iHotKeys;
sl@0
   196
	while(hotKey)
sl@0
   197
		{
sl@0
   198
		CWsHotKey *next=hotKey->iNext;
sl@0
   199
		delete hotKey;
sl@0
   200
		hotKey=next;
sl@0
   201
		}
sl@0
   202
	iHotKeys=NULL;
sl@0
   203
	}
sl@0
   204
sl@0
   205
void TWindowServerEvent::DeleteStatics()
sl@0
   206
	{
sl@0
   207
	DeleteHotKeys();
sl@0
   208
	delete iCaptureKeys;
sl@0
   209
	delete iKeyEventRouter;
sl@0
   210
	iKeyEventRouterLibrary.Close();
sl@0
   211
	CKeyboardRepeat::Destroy();
sl@0
   212
	delete iKeyTranslator;
sl@0
   213
	delete iEventReceiver;
sl@0
   214
	iEventHandlers.Close();
sl@0
   215
	delete iNotificationHandlers;
sl@0
   216
	iDrawerHandlers->Close();
sl@0
   217
	delete iDrawerHandlers;
sl@0
   218
	iWsEventHandlers.Close();
sl@0
   219
	}
sl@0
   220
sl@0
   221
void TWindowServerEvent::InitStaticsL()
sl@0
   222
//
sl@0
   223
// Create the CEvent active object.
sl@0
   224
//
sl@0
   225
	{
sl@0
   226
#if defined(__WINS__)
sl@0
   227
	WS_ASSERT_DEBUG(TWindowServerEvent::ENumHotKeys==EHotKeyLastKeyType+1, EWsPanicUnknownCaptureKey);
sl@0
   228
#endif
sl@0
   229
	iEventReceiver=new(ELeave) CRawEventReceiver(EEventPriority);
sl@0
   230
	iEventReceiver->ConstructL();
sl@0
   231
	iKeyTranslator=CKeyTranslator::New();
sl@0
   232
	User::LeaveIfNull(iKeyTranslator);
sl@0
   233
    
sl@0
   234
//  Change keyboard mapping according to information the HAL
sl@0
   235
	TInt keyboardIndex;
sl@0
   236
	if (HAL::Get(HALData::EKeyboardIndex,keyboardIndex)==KErrNone)
sl@0
   237
		{
sl@0
   238
		_LIT(KLitKeyDataDllName,"EKDATA.%02d");
sl@0
   239
		TBuf<16> keyDataDllName;
sl@0
   240
		keyDataDllName.Format(KLitKeyDataDllName,keyboardIndex);
sl@0
   241
		iKeyTranslator->ChangeKeyData(keyDataDllName);
sl@0
   242
		}
sl@0
   243
sl@0
   244
	// CCaptureKeys is no longer used but a dummy object is required for
sl@0
   245
	// calls to CKeyTranslator::TranslateKey() until capture functionality
sl@0
   246
	// has been removed from ektran.dll.
sl@0
   247
	iCaptureKeys=new(ELeave) CCaptureKeys;
sl@0
   248
	iCaptureKeys->Construct();
sl@0
   249
sl@0
   250
	// Load the key event routing plug-in. The DLL name may be overridden
sl@0
   251
	// by setting the keyword KEYROUTERPLUGIN in wsini.ini.
sl@0
   252
	TPtrC pluginName(KDefaultKeyRouterPluginName);
sl@0
   253
	WsIniFile->FindVar(KWSERVIniFileVarKeyRouterPlugin, pluginName);
sl@0
   254
	const TUidType uidType(KDynamicLibraryUid, KKeyRouterPluginUid);
sl@0
   255
	TInt err = iKeyEventRouterLibrary.Load(pluginName, uidType);
sl@0
   256
sl@0
   257
	if (wsDebugLog)
sl@0
   258
		{
sl@0
   259
		TLogMessageText buf;
sl@0
   260
sl@0
   261
		if (err == KErrNone)
sl@0
   262
			{
sl@0
   263
			_LIT(KLogLoadOk, "Loaded plugin '%S' UID3 0x%x");
sl@0
   264
			const TFileName& pluginPathname = iKeyEventRouterLibrary.FileName();
sl@0
   265
			const TUid uid3 = iKeyEventRouterLibrary.Type()[2];
sl@0
   266
			buf.Format(KLogLoadOk, &pluginPathname, uid3.iUid);
sl@0
   267
			}
sl@0
   268
		else
sl@0
   269
			{
sl@0
   270
			_LIT(KLogLoadError, "Failed to load plugin '%S' (error %d)");
sl@0
   271
			buf.Format(KLogLoadError, &pluginName, err);
sl@0
   272
			}
sl@0
   273
sl@0
   274
		wsDebugLog->MiscMessage(CDebugLogBase::ELogImportant, buf);
sl@0
   275
		}
sl@0
   276
sl@0
   277
	if (err != KErrNone)
sl@0
   278
		{
sl@0
   279
#ifdef _DEBUG
sl@0
   280
		_LIT(KLoadError, "WServ: failed to load plugin '%S' (error %d)");
sl@0
   281
		RDebug::Print(KLoadError, &pluginName, err);
sl@0
   282
#endif
sl@0
   283
		User::Leave(err);
sl@0
   284
		}
sl@0
   285
sl@0
   286
	// Create the key event router
sl@0
   287
	typedef CKeyEventRouter* (*TCreateFunc)();
sl@0
   288
	TCreateFunc newL = reinterpret_cast<TCreateFunc>(iKeyEventRouterLibrary.Lookup(1));
sl@0
   289
	if (newL == NULL)
sl@0
   290
		{
sl@0
   291
		User::Leave(KErrNotFound);
sl@0
   292
		}
sl@0
   293
	iKeyEventRouter = (*newL)();
sl@0
   294
sl@0
   295
	for (TInt index=0;index<TWindowServerEvent::ENumHotKeys;index++)
sl@0
   296
		ConstructDefaultHotKeyL(index,DefaultHotKeys[index]);
sl@0
   297
	CKeyboardRepeat::NewL();
sl@0
   298
	CKeyboardRepeat::SetRepeatTime(EDefaultInitialRepeatTime, EDefaultRepeatTime);
sl@0
   299
	iEventHandlers=RArray<TRawEventHandler>(2);
sl@0
   300
	iNotificationHandlers=new(ELeave) CArrayFixFlat<SNotificationHandler>(2);
sl@0
   301
	iDrawerHandlers = new(ELeave) RArray<TDrawerHandler>(4);
sl@0
   302
	}
sl@0
   303
sl@0
   304
void TWindowServerEvent::LinkHotKey(CWsHotKey *aWsHotKey)
sl@0
   305
	{
sl@0
   306
	aWsHotKey->SetLink(iHotKeys);
sl@0
   307
	iHotKeys=aWsHotKey;
sl@0
   308
	}
sl@0
   309
sl@0
   310
void TWindowServerEvent::ConstructDefaultHotKeyL(TInt aHotKey, const TWsWinCmdCaptureKey &aSystemKey)
sl@0
   311
	{
sl@0
   312
	CWsHotKey* hotKey=new(ELeave) CWsHotKey(aHotKey, ETrue);
sl@0
   313
	// hotKey is pushed onto the cleanup stack in method ConstructLD.
sl@0
   314
	hotKey->ConstructLD(aSystemKey);
sl@0
   315
	LinkHotKey(hotKey);
sl@0
   316
	}
sl@0
   317
sl@0
   318
CWsHotKey* TWindowServerEvent::ClearHotKeysL(TInt aHotKey)
sl@0
   319
	{
sl@0
   320
	if (aHotKey>ENumHotKeys)
sl@0
   321
		{
sl@0
   322
		User::Leave(KErrArgument);
sl@0
   323
		}
sl@0
   324
	CWsHotKey** pHotKey= &iHotKeys;
sl@0
   325
	CWsHotKey* defaultHotKey=NULL;
sl@0
   326
	while(*pHotKey)
sl@0
   327
		{
sl@0
   328
		TBool unlinked=EFalse;
sl@0
   329
		if ((*pHotKey)->HotKeyType()==aHotKey)
sl@0
   330
			{
sl@0
   331
			CWsHotKey *free=*pHotKey;
sl@0
   332
			if (free->IsDefault())
sl@0
   333
				{
sl@0
   334
				free->SetL(ImpossibleKeyPress);
sl@0
   335
				defaultHotKey=free;
sl@0
   336
				}
sl@0
   337
			else
sl@0
   338
				{
sl@0
   339
				*pHotKey=(*pHotKey)->iNext;
sl@0
   340
				delete free;
sl@0
   341
				unlinked=ETrue;
sl@0
   342
				}
sl@0
   343
			}
sl@0
   344
		if (!unlinked)
sl@0
   345
			{
sl@0
   346
			pHotKey=&(*pHotKey)->iNext;
sl@0
   347
			}
sl@0
   348
		}
sl@0
   349
	return(defaultHotKey);
sl@0
   350
	}
sl@0
   351
sl@0
   352
void TWindowServerEvent::ResetDefaultHotKeyL(TInt aHotKey)
sl@0
   353
	{
sl@0
   354
	if ((aHotKey<0) || (aHotKey>=ENumHotKeys))
sl@0
   355
		{
sl@0
   356
		User::Leave(KErrArgument);
sl@0
   357
		}
sl@0
   358
	CWsHotKey* defaultHotKey=ClearHotKeysL(aHotKey);
sl@0
   359
	WS_ASSERT_DEBUG(defaultHotKey, EWsPanicDefaultHotKeyNotFound);
sl@0
   360
	defaultHotKey->SetL(DefaultHotKeys[aHotKey]);
sl@0
   361
	}
sl@0
   362
sl@0
   363
void TWindowServerEvent::SetHotKeyL(const TWsClCmdSetHotKey &aHotKey)
sl@0
   364
	{
sl@0
   365
	if (aHotKey.type>ENumHotKeys)
sl@0
   366
		User::Leave(KErrArgument);
sl@0
   367
//
sl@0
   368
	CWsHotKey *hotKey=new(ELeave) CWsHotKey(aHotKey.type, EFalse);
sl@0
   369
//
sl@0
   370
	TWsWinCmdCaptureKey captureKey;
sl@0
   371
	captureKey.modifiers=aHotKey.modifiers;
sl@0
   372
	captureKey.modifierMask=aHotKey.modifierMask;
sl@0
   373
	captureKey.key=aHotKey.keycode;
sl@0
   374
	captureKey.priority = 0;
sl@0
   375
	hotKey->ConstructLD(captureKey);
sl@0
   376
//
sl@0
   377
	LinkHotKey(hotKey);
sl@0
   378
	}
sl@0
   379
sl@0
   380
void TWindowServerEvent::AddEventHandler(MEventHandler *aEventHandler, TBool aAdvancedPointersEnabled)
sl@0
   381
	{
sl@0
   382
#if defined(_DEBUG)
sl@0
   383
	TRAPD(err,iEventHandlers.AppendL(TRawEventHandler(aEventHandler, aAdvancedPointersEnabled)));
sl@0
   384
	WS_ASSERT_DEBUG(err==KErrNone, EWsPanicEventHandlerInconsistency);
sl@0
   385
#else
sl@0
   386
	iEventHandlers.AppendL(TRawEventHandler(aEventHandler, aAdvancedPointersEnabled));	//Shouldn't leave
sl@0
   387
#endif
sl@0
   388
#ifdef LOG_WSERV_EVENTS
sl@0
   389
	RDebug::Printf("_WSEVENT_POINTER: TWindowServerEvent::AddEventHandler Added handler = %d AdvancedPointerEnabled = %d", iEventHandlers.Count(),aAdvancedPointersEnabled);
sl@0
   390
#endif
sl@0
   391
	}
sl@0
   392
sl@0
   393
void TWindowServerEvent::RemoveEventHandler(const MEventHandler *aEventHandler)
sl@0
   394
	{
sl@0
   395
	TInt count=iEventHandlers.Count();
sl@0
   396
	TInt ii;
sl@0
   397
	for(ii=0;ii<count;++ii)
sl@0
   398
		{
sl@0
   399
		if (iEventHandlers[ii].iEventHandler==aEventHandler)
sl@0
   400
			{
sl@0
   401
#ifdef LOG_WSERV_EVENTS
sl@0
   402
		    RDebug::Printf("_WSEVENT_POINTER: TWindowServerEvent::RemoveEventHandler Removed handler = %d",ii);
sl@0
   403
#endif
sl@0
   404
			if (iEventHandlerCount>0)  
sl@0
   405
				{
sl@0
   406
				iBinaryFlags |= ERemovedEventHandlerWhileProcessingRawEvents;
sl@0
   407
				iEventHandlers[ii].iEventHandler=NULL; // replace the Handler with null to keep size of the array
sl@0
   408
				}
sl@0
   409
			else 
sl@0
   410
				{
sl@0
   411
				iEventHandlers.Remove(ii);
sl@0
   412
				}
sl@0
   413
			return;
sl@0
   414
			}
sl@0
   415
		}
sl@0
   416
	}
sl@0
   417
sl@0
   418
void TWindowServerEvent::PotentialEventHandlerL(TInt aNum)
sl@0
   419
	{
sl@0
   420
	iPotentialEventHandlers+=aNum;
sl@0
   421
	WS_ASSERT_DEBUG(iPotentialEventHandlers>=iEventHandlers.Count(), EWsPanicEventHandlerInconsistency);
sl@0
   422
	TRAPD(err,iEventHandlers.Reserve(iPotentialEventHandlers));
sl@0
   423
	if (err!=KErrNone)
sl@0
   424
		{
sl@0
   425
		if (aNum>0)
sl@0
   426
			User::Leave(err);
sl@0
   427
		}
sl@0
   428
	else if (iPotentialEventHandlers==0)
sl@0
   429
		iEventHandlers.Compress();
sl@0
   430
	}
sl@0
   431
sl@0
   432
void SendSwitchOnEvent(TEventRequestItem *aQptr, TInt aEvent, TInt )
sl@0
   433
	{
sl@0
   434
	aQptr->iWindow->QueueEvent(aEvent);
sl@0
   435
	}
sl@0
   436
sl@0
   437
/*void SendSwitchOffEvent(TEventRequestItem *aQptr, TInt , TInt )
sl@0
   438
	{
sl@0
   439
	aQptr->iWindow->QueueEvent(EEventSwitchOff);
sl@0
   440
	}*/
sl@0
   441
sl@0
   442
void SendErrorMessage(TEventRequestItem *aQptr, TInt aCategory, TInt aError)
sl@0
   443
	{
sl@0
   444
	TWsEvent event;
sl@0
   445
	event.SetType(EEventErrorMessage);
sl@0
   446
	event.SetHandle(aQptr->iWindow->ClientHandle());
sl@0
   447
	event.ErrorMessage()->iErrorCategory=(TWsErrorMessage::TErrorCategory)aCategory;
sl@0
   448
	event.ErrorMessage()->iError=aError;
sl@0
   449
	event.SetTimeNow();
sl@0
   450
	aQptr->iWindow->EventQueue()->QueueEvent(event,EEventPriorityHigh);
sl@0
   451
	}
sl@0
   452
sl@0
   453
void SendModifierChangedEvent(TEventRequestItem *aQptr, TInt aChanged, TInt )
sl@0
   454
	{
sl@0
   455
	TInt tmpChanged=aChanged&aQptr->iParam;
sl@0
   456
	if (tmpChanged)
sl@0
   457
		{
sl@0
   458
		TWsEvent event;
sl@0
   459
		event.SetType(EEventModifiersChanged);
sl@0
   460
		event.SetHandle(aQptr->iWindow->ClientHandle());
sl@0
   461
		event.ModifiersChanged()->iChangedModifiers=tmpChanged;
sl@0
   462
		event.ModifiersChanged()->iModifiers=TWindowServerEvent::GetStoredModifierState();
sl@0
   463
		event.SetTimeNow();
sl@0
   464
		aQptr->iWindow->EventQueue()->QueueEvent(event,EEventPriorityHigh);
sl@0
   465
		}
sl@0
   466
	}
sl@0
   467
sl@0
   468
void TWindowServerEvent::ProcessEventQueue(TEventRequestQueue &aQueue, TSendEventFunc aFunc, TInt aParam1, TInt aParam2)
sl@0
   469
	{
sl@0
   470
	TSglQueIter<TEventRequestItem> iter(aQueue.Queue());
sl@0
   471
	TEventRequestItem *qPtr;
sl@0
   472
	CWsWindowGroup *focusWin=CWsTop::FocusWindowGroup();
sl@0
   473
	while((qPtr=iter++)!=NULL)
sl@0
   474
		{
sl@0
   475
		if (qPtr->iCircumstances==EEventControlAlways || 
sl@0
   476
			(qPtr->iCircumstances==EEventControlOnlyWithKeyboardFocus && qPtr->iWindow->WinGroup()==focusWin) ||
sl@0
   477
			(qPtr->iCircumstances==EEventControlOnlyWhenVisible && !qPtr->iWindow->TreeIsObscured()))
sl@0
   478
			aFunc(qPtr, aParam1, aParam2);
sl@0
   479
		}
sl@0
   480
	}
sl@0
   481
sl@0
   482
void TWindowServerEvent::NotifyOom()
sl@0
   483
	{
sl@0
   484
	TTime now;
sl@0
   485
	now.UniversalTime();
sl@0
   486
	TTimeIntervalSeconds interval;
sl@0
   487
	TInt err=now.SecondsFrom(iPrevOomMessageTime,interval);
sl@0
   488
	if (err!=KErrNone || interval.Int()<0 || interval.Int()>EOomEventSecondGap)
sl@0
   489
		{
sl@0
   490
		ProcessErrorMessages(TWsErrorMessage::EDrawingRegion,KErrNoMemory);
sl@0
   491
		iPrevOomMessageTime=now;
sl@0
   492
		}
sl@0
   493
	}
sl@0
   494
sl@0
   495
TBool TWindowServerEvent::ProcessErrorMessages(TWsErrorMessage::TErrorCategory aCategory, TInt aError)
sl@0
   496
	{
sl@0
   497
	if (aError!=KErrNone)
sl@0
   498
		{
sl@0
   499
		ProcessEventQueue(iErrorMessageQueue, SendErrorMessage, aCategory, aError);
sl@0
   500
		return ETrue;
sl@0
   501
		}
sl@0
   502
	return EFalse;
sl@0
   503
	}
sl@0
   504
sl@0
   505
void TWindowServerEvent::ProcessModifierChanges()
sl@0
   506
	{
sl@0
   507
	TInt newState=iKeyTranslator->GetModifierState();
sl@0
   508
	if (newState!=iModifierState)
sl@0
   509
		{
sl@0
   510
		TInt changed=iModifierState^newState;
sl@0
   511
		iModifierState=newState;
sl@0
   512
		ProcessEventQueue(iModifierChangedQueue, SendModifierChangedEvent, changed, 0);
sl@0
   513
		}
sl@0
   514
	}
sl@0
   515
sl@0
   516
TEventQueueWalkRet FindScreenDeviceChangedEvent(TAny *aHandlePtr, TWsEvent *aEvent)
sl@0
   517
	{
sl@0
   518
	if (aEvent->Type()==EEventScreenDeviceChanged && aEvent->Handle()==*(TUint *)aHandlePtr)
sl@0
   519
		*(TUint *)aHandlePtr=0;	// Indicates event found
sl@0
   520
	return(EEventQueueWalkOk);
sl@0
   521
	}
sl@0
   522
	
sl@0
   523
void TWindowServerEvent::SendScreenDeviceChangedEvents(CScreen* aScreen)
sl@0
   524
	{
sl@0
   525
	TSglQueIter<TEventRequestItem> iter(iScreenDeviceChangedQueue .Queue());
sl@0
   526
	TEventRequestItem *qPtr;
sl@0
   527
	while((qPtr=iter++)!=NULL)
sl@0
   528
		SendScreenDeviceChangedEvent(qPtr->iWindow);
sl@0
   529
	if(CClick::IsHandler())
sl@0
   530
		{
sl@0
   531
		TClickMakerData clickMakerData;
sl@0
   532
		clickMakerData.screenDeviceMode=aScreen->ScreenSizeMode();
sl@0
   533
		CClick::OtherEvent(EEventScreenDeviceChanged, &clickMakerData);
sl@0
   534
		}
sl@0
   535
	TWsEvent wsEvent;
sl@0
   536
	wsEvent.SetType(EEventScreenDeviceChanged);
sl@0
   537
	TWindowServerEvent::PublishNotification(wsEvent);
sl@0
   538
	TWservCrEvent crEvent(TWservCrEvent::EScreenSizeModeChanged,aScreen->ScreenSizeMode());
sl@0
   539
	TWindowServerEvent::NotifyDrawer(crEvent);
sl@0
   540
	}
sl@0
   541
sl@0
   542
void TWindowServerEvent::SendScreenDeviceChangedEvent(const CWsWindowBase *aWindow)
sl@0
   543
	{
sl@0
   544
	CEventQueue *queue=aWindow->EventQueue();
sl@0
   545
	TUint32 handle=aWindow->ClientHandle();
sl@0
   546
	queue->WalkEventQueue(&FindScreenDeviceChangedEvent,&handle);
sl@0
   547
	if (handle!=NULL)	// Indicates event not found
sl@0
   548
		queue->QueueEvent(handle, EEventScreenDeviceChanged);
sl@0
   549
	}
sl@0
   550
sl@0
   551
TEventQueueWalkRet FindGroupChangedEvent(TAny *aHandlePtr, TWsEvent *aEvent)
sl@0
   552
	{
sl@0
   553
	if (aEvent->Type()==EEventWindowGroupsChanged && aEvent->Handle()==*(TUint *)aHandlePtr)
sl@0
   554
		{
sl@0
   555
		*(TUint *)aHandlePtr=0;	// Indicates event found
sl@0
   556
		}
sl@0
   557
	return(EEventQueueWalkOk);
sl@0
   558
	}
sl@0
   559
	
sl@0
   560
void TWindowServerEvent::SendGroupChangedEvents()
sl@0
   561
	{
sl@0
   562
	TSglQueIter<TEventRequestItem> iter(iGroupChangedQueue.Queue());
sl@0
   563
	TEventRequestItem *qPtr;
sl@0
   564
	while((qPtr=iter++)!=NULL)
sl@0
   565
		{
sl@0
   566
		const CWsWindowBase *win=qPtr->iWindow;
sl@0
   567
		CEventQueue *queue=win->EventQueue();
sl@0
   568
		TUint32 handle=win->ClientHandle();
sl@0
   569
		queue->WalkEventQueue(&FindGroupChangedEvent,&handle);
sl@0
   570
		if (handle!=NULL)	// Indicates event not found
sl@0
   571
			{
sl@0
   572
			queue->QueueEvent(handle, EEventWindowGroupsChanged);
sl@0
   573
			}
sl@0
   574
		}
sl@0
   575
	}	
sl@0
   576
sl@0
   577
TEventQueueWalkRet FindFocusChangedEvent(TAny *aHandlePtr, TWsEvent *aEvent)
sl@0
   578
	{
sl@0
   579
	if (aEvent->Type()==EEventFocusGroupChanged && aEvent->Handle()==*(TUint *)aHandlePtr)
sl@0
   580
		{
sl@0
   581
		*(TUint *)aHandlePtr=0;	// Indicates event found
sl@0
   582
		}
sl@0
   583
	return(EEventQueueWalkOk);
sl@0
   584
	}
sl@0
   585
	
sl@0
   586
void TWindowServerEvent::SendFocusChangedEvents()
sl@0
   587
	{
sl@0
   588
	TInt identifier=0;	// Zero Identifier indicates, currently there is no focused window group
sl@0
   589
	CScreen* currentFocusScreen=CWsTop::CurrentFocusScreen();	
sl@0
   590
	TInt screenNumber=currentFocusScreen->ScreenNumber();
sl@0
   591
	CWsWindowGroup* currentFocusWG=currentFocusScreen->FocusWindowGroup();
sl@0
   592
	if(currentFocusWG)
sl@0
   593
		{
sl@0
   594
		identifier=currentFocusWG->Identifier();
sl@0
   595
		}
sl@0
   596
	TWindowServerEvent::NotifyDrawer(TWservCrEvent(TWservCrEvent::EWindowGroupChanged,
sl@0
   597
		screenNumber, reinterpret_cast<TAny*>(identifier)));
sl@0
   598
		 
sl@0
   599
	TSglQueIter<TEventRequestItem> iter(iFocusChangedQueue.Queue());
sl@0
   600
	TEventRequestItem *qPtr;
sl@0
   601
	while((qPtr=iter++)!=NULL)
sl@0
   602
		{
sl@0
   603
		const CWsWindowBase *win=qPtr->iWindow;
sl@0
   604
		CEventQueue *queue=win->EventQueue();
sl@0
   605
		TUint32 handle=win->ClientHandle();
sl@0
   606
		queue->WalkEventQueue(&FindFocusChangedEvent,&handle);
sl@0
   607
		if (handle!=NULL)	// Indicates event not found
sl@0
   608
			{
sl@0
   609
			queue->QueueEvent(handle, EEventFocusGroupChanged);
sl@0
   610
			}
sl@0
   611
		}
sl@0
   612
	}
sl@0
   613
sl@0
   614
TEventQueueWalkRet FindGroupListChangedEvent(TAny *aHandlePtr, TWsEvent *aEvent)
sl@0
   615
	{
sl@0
   616
	if (aEvent->Type()==EEventWindowGroupListChanged && aEvent->Handle()==*(TUint *)aHandlePtr)
sl@0
   617
		{
sl@0
   618
		*(TUint *)aHandlePtr=0;	// Indicates event found
sl@0
   619
		}
sl@0
   620
	return(EEventQueueWalkOk);
sl@0
   621
	}
sl@0
   622
	
sl@0
   623
void TWindowServerEvent::SendGroupListChangedEvents()
sl@0
   624
	{
sl@0
   625
	TSglQueIter<TEventRequestItem> iter(iGroupListChangedQueue.Queue());
sl@0
   626
	TEventRequestItem *qPtr;
sl@0
   627
	while((qPtr=iter++)!=NULL)
sl@0
   628
		{
sl@0
   629
		const CWsWindowBase *win=qPtr->iWindow;
sl@0
   630
		CEventQueue *queue=win->EventQueue();
sl@0
   631
		TUint32 handle=win->ClientHandle();
sl@0
   632
		queue->WalkEventQueue(&FindGroupListChangedEvent,&handle);
sl@0
   633
		if (handle!=NULL)	// Indicates event not found
sl@0
   634
			{
sl@0
   635
			queue->QueueEvent(handle, EEventWindowGroupListChanged);
sl@0
   636
			}
sl@0
   637
		}
sl@0
   638
	}	
sl@0
   639
sl@0
   640
TEventQueueWalkRet OverrideVisibilityChangedEvent(TAny *aNewEvent, TWsEvent *aOldEvent)
sl@0
   641
	{
sl@0
   642
	// This replaces the first visibility event it finds for the given window with the
sl@0
   643
	// one given.  This is fine, so long as the meaning of all visibility events remains
sl@0
   644
	// independent of the ones before.
sl@0
   645
	TWsEvent* newEvent = static_cast<TWsEvent*>(aNewEvent);
sl@0
   646
	if (aOldEvent->Type()==EEventWindowVisibilityChanged && aOldEvent->Handle()==newEvent->Handle())
sl@0
   647
		{
sl@0
   648
		aOldEvent->SetTimeNow();
sl@0
   649
		aOldEvent->VisibilityChanged()->iFlags = newEvent->VisibilityChanged()->iFlags;
sl@0
   650
		newEvent->SetHandle(NULL);
sl@0
   651
		}
sl@0
   652
	return EEventQueueWalkOk;
sl@0
   653
	}
sl@0
   654
sl@0
   655
void TWindowServerEvent::SendVisibilityChangedEvents(CWsWindowBase* aWin, TUint aFlags)
sl@0
   656
	{
sl@0
   657
	CEventQueue *queue=aWin->EventQueue();
sl@0
   658
	TWsEvent event;
sl@0
   659
	event.SetType(EEventWindowVisibilityChanged);
sl@0
   660
	event.SetHandle(aWin->ClientHandle());
sl@0
   661
	event.SetTimeNow();
sl@0
   662
	TWsVisibilityChangedEvent* visevent = event.VisibilityChanged();
sl@0
   663
	visevent->iFlags = aFlags;
sl@0
   664
	queue->WalkEventQueue(&OverrideVisibilityChangedEvent,&event);
sl@0
   665
	if (event.Handle()!=NULL)
sl@0
   666
		{
sl@0
   667
		queue->QueueEvent(event);
sl@0
   668
		}
sl@0
   669
	}
sl@0
   670
sl@0
   671
TEventQueueWalkRet OverrideDisplayChangedEvent(TAny *aNewEvent, TWsEvent *aOldEvent)
sl@0
   672
	{
sl@0
   673
	TWsEvent* newEvent = static_cast<TWsEvent*>(aNewEvent);
sl@0
   674
	if (aOldEvent->Type() == EEventDisplayChanged && 
sl@0
   675
			aOldEvent->DisplayChanged()->iDisplayNumber == newEvent->DisplayChanged()->iDisplayNumber)
sl@0
   676
		{
sl@0
   677
		aOldEvent->SetTimeNow();
sl@0
   678
		aOldEvent->DisplayChanged()->iConfigurationChangeId = newEvent->DisplayChanged()->iConfigurationChangeId;
sl@0
   679
		aOldEvent->DisplayChanged()->iResolutionListChangeId = newEvent->DisplayChanged()->iResolutionListChangeId;
sl@0
   680
		newEvent->DisplayChanged()->iDisplayNumber = KErrNotFound; //So the new event won't be placed on event queue again
sl@0
   681
		}
sl@0
   682
	return EEventQueueWalkOk;
sl@0
   683
	}
sl@0
   684
sl@0
   685
TBool TWindowServerEvent::SendDisplayChangedEvents(CWsClient* aWsClient, TInt aDisplayNumber, TInt aConfigurationChangeId, TInt aResolutionListChangeId)
sl@0
   686
	{
sl@0
   687
	CEventQueue *queue = aWsClient->EventQueue();
sl@0
   688
	TWsEvent event;
sl@0
   689
	event.SetType(EEventDisplayChanged);
sl@0
   690
	event.SetTimeNow();
sl@0
   691
	
sl@0
   692
    // fill in the handle otherwise CONE will discard the notification
sl@0
   693
    CWsObjectIx* clientObjList = aWsClient->ObjectIndex();
sl@0
   694
    const TWsObject* ptr=clientObjList->FirstObject();
sl@0
   695
    const TWsObject* end=ptr+clientObjList->Length();
sl@0
   696
    while(++ptr<end)    // first one should always have a NULL object
sl@0
   697
        {
sl@0
   698
        const CWsObject* obj=ptr->iObject;
sl@0
   699
        if (obj && obj->Type()==WS_HANDLE_GROUP_WINDOW)
sl@0
   700
            {
sl@0
   701
            event.SetHandle(ptr->iHandle);
sl@0
   702
            break;
sl@0
   703
            }
sl@0
   704
        }	
sl@0
   705
	
sl@0
   706
	TWsDisplayChangedEvent* dispEvent = event.DisplayChanged();
sl@0
   707
	dispEvent->iDisplayNumber = aDisplayNumber;
sl@0
   708
	dispEvent->iConfigurationChangeId = aConfigurationChangeId;
sl@0
   709
	dispEvent->iResolutionListChangeId = aResolutionListChangeId;
sl@0
   710
	queue->WalkEventQueue(&OverrideDisplayChangedEvent, &event);
sl@0
   711
	//place the new event on the queue only when its display number is valid (!=KErrNotFound)
sl@0
   712
	if(event.DisplayChanged()->iDisplayNumber >= 0)
sl@0
   713
		{
sl@0
   714
		return queue->QueueEvent(event);
sl@0
   715
		}
sl@0
   716
	return ETrue;
sl@0
   717
	}
sl@0
   718
sl@0
   719
void TWindowServerEvent::QueueKeyEvent(CWsWindowGroup *aWin, TWsEvent &aEvent, TWservEventPriorities aPriority)
sl@0
   720
	{
sl@0
   721
#ifdef LOG_WSERV_EVENTS
sl@0
   722
    RDebug::Print(_L("_WSEVENT_KEY: TWindowServerEvent::QueueKeyEvent, Queuing event name %S for application read, window handle: %d"), &WsEventName(aEvent), CWsTop::FocusWindowGroup()->ClientHandle());
sl@0
   723
#endif
sl@0
   724
	aEvent.SetTimeNow();
sl@0
   725
	aWin->EventQueue()->QueueEvent(aEvent, aPriority);
sl@0
   726
	}
sl@0
   727
sl@0
   728
/**
sl@0
   729
Process a key press event.
sl@0
   730
sl@0
   731
This function is called for every input key event and uses the Key Event
sl@0
   732
Routing plug-in to check for short and long key capture and determine the
sl@0
   733
destination window group for the queued event(s).
sl@0
   734
Window server hotkeys are also processed.
sl@0
   735
Note that the key repeat timer is started here but the key repeat events
sl@0
   736
generated by the timer go directly to QueueKeyPress().
sl@0
   737
sl@0
   738
@param	aKeyEvent		Input key event
sl@0
   739
@param	aCheckRepeat	Check for key repeat and long key capture
sl@0
   740
@param	aRepeats		Repeat count
sl@0
   741
*/
sl@0
   742
void TWindowServerEvent::ProcessKeyPress(const TKeyEvent& aKeyEvent, TBool aCheckRepeat, TInt aRepeats)
sl@0
   743
 	{
sl@0
   744
	CWsWindowGroup* focusWin = CWsTop::FocusWindowGroup();
sl@0
   745
	TUid focusAppUid = focusWin ? TUid::Uid(focusWin->Client()->SecureId().iId) : KNullUid;
sl@0
   746
sl@0
   747
	// Route the key event and check for short key capture.
sl@0
   748
	// Note that the Key Routing plugin may translate or block key events.
sl@0
   749
	TKeyEventRouterInput input(ECaptureTypeKey, aKeyEvent, focusWin, focusAppUid);
sl@0
   750
	TKeyEventRouterOutput output;
sl@0
   751
sl@0
   752
#ifdef _DEBUG
sl@0
   753
	// RouteKey() must not fail. Check for leaves in case the plug-in
sl@0
   754
	// is badly behaved.
sl@0
   755
	TRAPD(err, iKeyEventRouter->RouteKey(input, output));
sl@0
   756
	WS_ASSERT_DEBUG(err == KErrNone, EWsPanicKeyEventRouterLeave);
sl@0
   757
#else
sl@0
   758
	iKeyEventRouter->RouteKey(input, output);
sl@0
   759
#endif
sl@0
   760
sl@0
   761
	WS_ASSERT_DEBUG(output.iResult == ERouted || output.iResult == ECaptured || output.iResult == EConsumed, EWsPanicKeyEventRouterBadResult);
sl@0
   762
sl@0
   763
	if (output.iResult == EConsumed)
sl@0
   764
		{
sl@0
   765
		focusWin = NULL;
sl@0
   766
		}
sl@0
   767
	else
sl@0
   768
		{
sl@0
   769
		focusWin = static_cast<CWsWindowGroup*>(output.iWindowGroup);
sl@0
   770
		}
sl@0
   771
	WS_ASSERT_DEBUG((focusWin == NULL || focusWin->Type() == WS_HANDLE_GROUP_WINDOW) && (output.iResult != ERouted || focusWin == CWsTop::FocusWindowGroup()), EWsPanicKeyEventRouterBadWindowGroup);
sl@0
   772
sl@0
   773
	// Ensure that short event is not marked with EModifierLongKey
sl@0
   774
	output.iKeyEvent.iModifiers &= ~EModifierLongKey;
sl@0
   775
sl@0
   776
	// Generate key click unless the event is consumed. This is consistent
sl@0
   777
	// with the behaviour when CKeyTranslator::TranslateKey() yields no
sl@0
   778
	// translation for a particular scan code. (Click events for key up/down
sl@0
   779
	// will still be generated by QueueKeyUpDown()). Note however that a long
sl@0
   780
	// key press may still be captured even if the short event is consumed.
sl@0
   781
	if (CClick::IsHandler() && output.iResult != EConsumed)
sl@0
   782
		{
sl@0
   783
		output.iKeyEvent.iRepeats = aRepeats;
sl@0
   784
		CClick::KeyEvent(EEventKey, output.iKeyEvent);
sl@0
   785
		}
sl@0
   786
sl@0
   787
	if (output.iResult == ECaptured)
sl@0
   788
		{
sl@0
   789
		if (output.iWindowGroup == NULL)	// Captured by Wserv itself
sl@0
   790
			{
sl@0
   791
			_LIT(KWSERVDebugLogCapturedKey,"WSERV Captured Key");
sl@0
   792
			CScreen* focusScreen=CWsTop::CurrentFocusScreen();
sl@0
   793
			TInt screenNo=focusScreen->ScreenNumber();
sl@0
   794
			
sl@0
   795
			if (wsDebugLog)
sl@0
   796
				wsDebugLog->MiscMessage(CDebugLogBase::ELogEverything,KWSERVDebugLogCapturedKey);
sl@0
   797
			CWsHotKey *hotKey=iHotKeys;
sl@0
   798
			while(hotKey)
sl@0
   799
				{
sl@0
   800
				if (hotKey->KeyHandle() == reinterpret_cast<TInt>(output.iCaptureHandle))
sl@0
   801
					{
sl@0
   802
					switch(hotKey->HotKeyType())
sl@0
   803
						{
sl@0
   804
						case EHotKeyEnableLogging:
sl@0
   805
							CWsTop::EnableLogging();
sl@0
   806
							break;
sl@0
   807
						case EHotKeyDisableLogging:
sl@0
   808
							CWsTop::DisableLogging();
sl@0
   809
							break;
sl@0
   810
						case EHotKeyStateDump:
sl@0
   811
							StateDump();
sl@0
   812
							break;
sl@0
   813
						case EHotKeyHeapDump:
sl@0
   814
							HeapDump();
sl@0
   815
							break;
sl@0
   816
						case EHotKeyOfDeath:
sl@0
   817
							if (!CWsPassword::PasswordModeActive())
sl@0
   818
								{
sl@0
   819
								const TBool currentJustInTimeValue=User::JustInTime();
sl@0
   820
								if (currentJustInTimeValue)
sl@0
   821
									{
sl@0
   822
									User::SetJustInTime(EFalse);
sl@0
   823
									}
sl@0
   824
								CWsTop::KillForegroundSession();
sl@0
   825
								if (currentJustInTimeValue)
sl@0
   826
									{
sl@0
   827
									User::SetJustInTime(ETrue);
sl@0
   828
									}
sl@0
   829
								}
sl@0
   830
							break;
sl@0
   831
						case EHotKeyShutDown:
sl@0
   832
							CWsTop::Exit();
sl@0
   833
							break;
sl@0
   834
						case EHotKeyIncContrast:
sl@0
   835
							focusScreen->IncContrast();
sl@0
   836
							break;
sl@0
   837
						case EHotKeyDecContrast:
sl@0
   838
							focusScreen->DecContrast();
sl@0
   839
							break;
sl@0
   840
						case EHotKeyOff:
sl@0
   841
							CWsTop::HandleSwitchOff(EEventKeySwitchOff,ETrue);
sl@0
   842
							break;
sl@0
   843
						case EHotKeyBacklightToggle:
sl@0
   844
							{
sl@0
   845
							TInt state;
sl@0
   846
							if (!ProcessErrorMessages(TWsErrorMessage::EBackLight, HAL::Get(screenNo,HALData::EBacklightState,state)))
sl@0
   847
								ProcessErrorMessages(TWsErrorMessage::EBackLight, HAL::Set(screenNo,HALData::EBacklightState,!state));
sl@0
   848
							}
sl@0
   849
							break;
sl@0
   850
						case EHotKeyBacklightOn:
sl@0
   851
							ProcessErrorMessages(TWsErrorMessage::EBackLight, HAL::Set(screenNo,HALData::EBacklightState,ETrue));
sl@0
   852
							break;
sl@0
   853
						case EHotKeyBacklightOff:
sl@0
   854
							ProcessErrorMessages(TWsErrorMessage::EBackLight, HAL::Set(screenNo,HALData::EBacklightState,EFalse));
sl@0
   855
							break;
sl@0
   856
						case EHotKeyScreenDimension0:
sl@0
   857
						case EHotKeyScreenDimension1:
sl@0
   858
						case EHotKeyScreenDimension2:
sl@0
   859
						case EHotKeyScreenDimension3:
sl@0
   860
							focusScreen->doSetScreenMode(hotKey->HotKeyType()-EHotKeyScreenDimension0);
sl@0
   861
							break;
sl@0
   862
						case EHotKeyCycleDisplaySize:
sl@0
   863
							focusScreen->CycleDisplaySize();
sl@0
   864
							break;
sl@0
   865
						case EHotKeyCycleOrientation:
sl@0
   866
							focusScreen->CycleOrientation();
sl@0
   867
							break;
sl@0
   868
						case EHotKeyIncBrightness:
sl@0
   869
							focusScreen->IncBrightness();
sl@0
   870
							break;
sl@0
   871
						case EHotKeyDecBrightness:
sl@0
   872
							focusScreen->DecBrightness();
sl@0
   873
							break;
sl@0
   874
						case EHotKeyCycleFocusScreen:
sl@0
   875
							CWsTop::SetCurrentFocusScreen((CWsTop::CurrentFocusScreen()->ScreenNumber()+1)%CWsTop::NumberOfScreens());
sl@0
   876
							break;
sl@0
   877
						}
sl@0
   878
					return;
sl@0
   879
					}
sl@0
   880
				hotKey=hotKey->iNext;
sl@0
   881
				}
sl@0
   882
			WS_PANIC_ALWAYS(EWsPanicUnknownCaptureKey);
sl@0
   883
			return;
sl@0
   884
			}
sl@0
   885
sl@0
   886
		_LIT(KWSERVDebugLogKeyCapturedByApp,"Key captured by app %d");
sl@0
   887
		if (wsDebugLog)
sl@0
   888
			wsDebugLog->MiscMessage(CDebugLogBase::ELogEverything,KWSERVDebugLogKeyCapturedByApp,focusWin->Identifier());
sl@0
   889
		if (CWsPassword::PasswordModeActive() && focusWin!=CWsPassword::PasswordWindow()->WinGroup())
sl@0
   890
			return;
sl@0
   891
		}
sl@0
   892
sl@0
   893
	CWsCaptureLongKey* longCapture = NULL;
sl@0
   894
	TKeyEventRouterOutput longOutput;
sl@0
   895
	if (aCheckRepeat)
sl@0
   896
		{
sl@0
   897
		// Check for long key capture.
sl@0
   898
		// Note that a long key event can only result from capture, there is
sl@0
   899
		// no default detection or routing of long events.
sl@0
   900
		input.iType = ECaptureTypeLongKey;
sl@0
   901
#ifdef _DEBUG
sl@0
   902
		TRAPD(err, iKeyEventRouter->RouteKey(input, longOutput));
sl@0
   903
		WS_ASSERT_DEBUG(err == KErrNone, EWsPanicKeyEventRouterLeave);
sl@0
   904
#else
sl@0
   905
		iKeyEventRouter->RouteKey(input, longOutput);
sl@0
   906
#endif
sl@0
   907
sl@0
   908
		if (longOutput.iResult == ECaptured)
sl@0
   909
			{
sl@0
   910
			longCapture = static_cast<CWsCaptureLongKey*>(longOutput.iCaptureHandle);
sl@0
   911
sl@0
   912
			// Mark long key events with EModifierLongKey so that applications
sl@0
   913
			// can easily distinguish short and long events.
sl@0
   914
			longOutput.iKeyEvent.iModifiers |= EModifierLongKey;
sl@0
   915
sl@0
   916
			// Start timer to detect long key press
sl@0
   917
			CKeyboardRepeat::StartRepeat(aKeyEvent.iScanCode, output, &longOutput);
sl@0
   918
			}
sl@0
   919
		else if (output.iResult != EConsumed && output.iKeyEvent.iModifiers & EModifierAutorepeatable)
sl@0
   920
			{
sl@0
   921
			// Start timer for key repeat
sl@0
   922
			CKeyboardRepeat::StartRepeat(aKeyEvent.iScanCode, output, NULL);
sl@0
   923
			}
sl@0
   924
		}
sl@0
   925
sl@0
   926
	// Queue the short event
sl@0
   927
	if (!longCapture || longCapture->iFlags & ELongCaptureShortEventImmediately)
sl@0
   928
		{
sl@0
   929
		QueueKeyPress(output, EFalse, aRepeats);
sl@0
   930
		}
sl@0
   931
	}
sl@0
   932
sl@0
   933
/**
sl@0
   934
Queue a key press event.
sl@0
   935
sl@0
   936
This function is called for each key event produced by ProcessKeyPress(),
sl@0
   937
for every key repeat and long key event generated by the timer and also for
sl@0
   938
delayed short key events from KeyUp().
sl@0
   939
sl@0
   940
@param	aOutput			Output key event from routing plug-in
sl@0
   941
@param	aIsRepeat		Event is due to key repeat
sl@0
   942
@param	aRepeats		Repeat count
sl@0
   943
*/
sl@0
   944
void TWindowServerEvent::QueueKeyPress(const TKeyEventRouterOutput& aOutput, TBool aIsRepeat, TInt aRepeats)
sl@0
   945
 	{
sl@0
   946
	if (aOutput.iResult == EConsumed)
sl@0
   947
		{
sl@0
   948
		// Don't deliver this key
sl@0
   949
		return;
sl@0
   950
		}
sl@0
   951
sl@0
   952
	TWsEvent event;
sl@0
   953
	TKeyEvent& keyEvent = *event.Key();
sl@0
   954
	keyEvent = aOutput.iKeyEvent;
sl@0
   955
	keyEvent.iRepeats = aRepeats;
sl@0
   956
sl@0
   957
	CWsWindowGroup* focusWin = static_cast<CWsWindowGroup*>(aOutput.iWindowGroup);
sl@0
   958
	WS_ASSERT_DEBUG(focusWin == NULL || focusWin->Type() == WS_HANDLE_GROUP_WINDOW, EWsPanicKeyEventRouterBadWindowGroup);
sl@0
   959
sl@0
   960
	if (aIsRepeat && aOutput.iResult != ECaptured && focusWin != CWsTop::FocusWindowGroup())
sl@0
   961
		CKeyboardRepeat::CancelRepeat(NULL);		// Repeat is going to different window so cancel it and don't deliver this key
sl@0
   962
	else if (focusWin != NULL && focusWin->CheckForPriorityKey(keyEvent) == EFalse)
sl@0
   963
		{
sl@0
   964
		event.SetType(EEventKey);
sl@0
   965
		event.SetHandle(focusWin->ClientHandle());
sl@0
   966
		if (aRepeats!=0)
sl@0
   967
			{
sl@0
   968
			CEventQueue* queue=focusWin->EventQueue();
sl@0
   969
			queue->Wait();
sl@0
   970
			const TWsEvent* prev=queue->PeekLastEvent();
sl@0
   971
			if (prev != NULL && prev->Type() == EEventKey && prev->Key()->iRepeats > 0 && prev->Key()->iCode == keyEvent.iCode)
sl@0
   972
				{
sl@0
   973
				prev->Key()->iRepeats += aRepeats;
sl@0
   974
				queue->Signal();
sl@0
   975
				if (CClick::IsHandler())
sl@0
   976
					CClick::KeyEvent(EEventKeyRepeat, *prev->Key());
sl@0
   977
				return;
sl@0
   978
				}
sl@0
   979
			queue->Signal();
sl@0
   980
			if (CClick::IsHandler())
sl@0
   981
				CClick::KeyEvent(EEventKeyRepeat,keyEvent);
sl@0
   982
			}
sl@0
   983
		QueueKeyEvent(focusWin, event, EEventPriorityLow);
sl@0
   984
		}
sl@0
   985
	}
sl@0
   986
sl@0
   987
/**
sl@0
   988
Queue a key up/down event.
sl@0
   989
sl@0
   990
@param	aRawEvent		Raw event
sl@0
   991
*/
sl@0
   992
void TWindowServerEvent::QueueKeyUpDown(const TRawEvent &aRawEvent)
sl@0
   993
 	{
sl@0
   994
#ifdef LOG_WSERV_EVENTS
sl@0
   995
    RDebug::Print(_L("_WSEVENT_KEY: TWindowServerEvent::QueueKeyUpDown, Event Name: %S, Scan code: %d"), &RawEventName(aRawEvent), aRawEvent.ScanCode());
sl@0
   996
#endif
sl@0
   997
	TEventCode type = aRawEvent.Type() == TRawEvent::EKeyUp ? EEventKeyUp : EEventKeyDown;
sl@0
   998
sl@0
   999
	// Check for key up/down capture
sl@0
  1000
	TKeyEvent keyEvent;
sl@0
  1001
	keyEvent.iScanCode = aRawEvent.ScanCode() __REMOVE_WINS_CHARCODE;
sl@0
  1002
#if defined(__WINS__)
sl@0
  1003
	keyEvent.iCode = __WINS_CHARCODE(aRawEvent.ScanCode());
sl@0
  1004
#else
sl@0
  1005
	keyEvent.iCode = 0;
sl@0
  1006
#endif
sl@0
  1007
	keyEvent.iModifiers = iModifierState;
sl@0
  1008
	keyEvent.iRepeats = 0;
sl@0
  1009
sl@0
  1010
	CWsWindowGroup* focusWin = CWsTop::FocusWindowGroup();
sl@0
  1011
	TUid focusAppUid = focusWin ? TUid::Uid(focusWin->Client()->SecureId().iId) : KNullUid;
sl@0
  1012
sl@0
  1013
	TKeyEventRouterInput input(ECaptureTypeKeyUpDown, keyEvent, focusWin, focusAppUid);
sl@0
  1014
	TKeyEventRouterOutput output;
sl@0
  1015
#ifdef _DEBUG
sl@0
  1016
	TRAPD(err, iKeyEventRouter->RouteKey(input, output));
sl@0
  1017
	WS_ASSERT_DEBUG(err == KErrNone, EWsPanicKeyEventRouterLeave);
sl@0
  1018
#else
sl@0
  1019
	iKeyEventRouter->RouteKey(input, output);
sl@0
  1020
#endif
sl@0
  1021
sl@0
  1022
	if (output.iResult == EConsumed)
sl@0
  1023
		{
sl@0
  1024
		// Don't deliver this key. A key click is still generated for the
sl@0
  1025
		// input event.
sl@0
  1026
		if (CClick::IsHandler())
sl@0
  1027
			{
sl@0
  1028
			CClick::KeyEvent(type, keyEvent);
sl@0
  1029
			}
sl@0
  1030
		return;
sl@0
  1031
		}
sl@0
  1032
	WS_ASSERT_DEBUG(output.iResult == ERouted || output.iResult == ECaptured, EWsPanicKeyEventRouterBadResult);
sl@0
  1033
sl@0
  1034
	focusWin = static_cast<CWsWindowGroup*>(output.iWindowGroup);
sl@0
  1035
	WS_ASSERT_DEBUG((focusWin == NULL || focusWin->Type() == WS_HANDLE_GROUP_WINDOW) && (output.iResult != ERouted || focusWin == CWsTop::FocusWindowGroup()), EWsPanicKeyEventRouterBadWindowGroup);
sl@0
  1036
#if defined(__WINS__)
sl@0
  1037
	if (focusWin && !focusWin->WsOwner()->RemoveKeyCode())
sl@0
  1038
		{
sl@0
  1039
		// Restore WINS character code
sl@0
  1040
		output.iKeyEvent.iScanCode |= output.iKeyEvent.iCode;
sl@0
  1041
		}
sl@0
  1042
	output.iKeyEvent.iCode = 0;
sl@0
  1043
#endif
sl@0
  1044
sl@0
  1045
	output.iKeyEvent.iRepeats = 0;
sl@0
  1046
	if (CClick::IsHandler())
sl@0
  1047
		{
sl@0
  1048
		CClick::KeyEvent(type, output.iKeyEvent);
sl@0
  1049
		}
sl@0
  1050
sl@0
  1051
	TWsEvent event;
sl@0
  1052
	*event.Key() = output.iKeyEvent;
sl@0
  1053
	if (focusWin!=NULL)
sl@0
  1054
		{
sl@0
  1055
		event.SetType(type);
sl@0
  1056
		event.SetHandle(focusWin->ClientHandle());
sl@0
  1057
		QueueKeyEvent(focusWin, event, EEventPriorityHigh);
sl@0
  1058
		}
sl@0
  1059
	}
sl@0
  1060
sl@0
  1061
LOCAL_D void GetPointerEvent(TPointerEvent::TType& aType, const TRawEvent &aRawEvent, TBool& aHandled)
sl@0
  1062
	{
sl@0
  1063
	aHandled=ETrue;
sl@0
  1064
	switch(aRawEvent.Type())
sl@0
  1065
		{
sl@0
  1066
	case TRawEvent::EButton1Down:
sl@0
  1067
		aType=TPointerEvent::EButton1Down;
sl@0
  1068
		break;
sl@0
  1069
	case TRawEvent::EButton1Up:
sl@0
  1070
		aType=TPointerEvent::EButton1Up;
sl@0
  1071
		break;
sl@0
  1072
	case TRawEvent::EButton2Down:
sl@0
  1073
		aType=TPointerEvent::EButton2Down;
sl@0
  1074
		break;
sl@0
  1075
	case TRawEvent::EButton2Up:
sl@0
  1076
		aType=TPointerEvent::EButton2Up;
sl@0
  1077
		break;
sl@0
  1078
	case TRawEvent::EButton3Down:
sl@0
  1079
		aType=TPointerEvent::EButton3Down;
sl@0
  1080
		break;
sl@0
  1081
	case TRawEvent::EButton3Up:
sl@0
  1082
		aType=TPointerEvent::EButton3Up;
sl@0
  1083
		break;
sl@0
  1084
	case TRawEvent::EPointerMove:
sl@0
  1085
		aType=TPointerEvent::EMove;
sl@0
  1086
		break;
sl@0
  1087
	case TRawEvent::EPointerSwitchOn:
sl@0
  1088
		aType=TPointerEvent::ESwitchOn;
sl@0
  1089
		break;
sl@0
  1090
	case TRawEvent::EPointer3DOutOfRange:
sl@0
  1091
		aType=TPointerEvent::EOutOfRange;
sl@0
  1092
		break;
sl@0
  1093
	default:
sl@0
  1094
		aHandled=EFalse;
sl@0
  1095
		}
sl@0
  1096
	}
sl@0
  1097
sl@0
  1098
TBool TWindowServerEvent::MousePress(const TRawEvent &aRawEvent, const CWsWindowGroup *aGroupWin)
sl@0
  1099
	//
sl@0
  1100
	//Return EFalse if known not to be a Mouse Event
sl@0
  1101
	//
sl@0
  1102
	{
sl@0
  1103
	TBool handled=ETrue;
sl@0
  1104
	TPointerEvent::TType type;
sl@0
  1105
	GetPointerEvent(type, aRawEvent, handled);
sl@0
  1106
	if (handled)
sl@0
  1107
		{
sl@0
  1108
		TPoint3D point3D(0,0,0);
sl@0
  1109
		if (type != TPointerEvent::EOutOfRange)
sl@0
  1110
			{
sl@0
  1111
			point3D = aRawEvent.Pos3D();
sl@0
  1112
			}
sl@0
  1113
		TWsEvent event;
sl@0
  1114
		TAdvancedPointerEventHelper::InitAdvancedPointerEvent(event, type,iKeyTranslator->GetModifierState(),point3D,aRawEvent.PointerNumber());
sl@0
  1115
		TWsPointer::ProcessWsEvent(event, aGroupWin, ETrue);
sl@0
  1116
		}
sl@0
  1117
	return handled;
sl@0
  1118
	}
sl@0
  1119
sl@0
  1120
LOCAL_D void SendEventToKeyClick(const TRawEvent& aRawEvent)
sl@0
  1121
	{
sl@0
  1122
	switch(aRawEvent.Type())
sl@0
  1123
		{
sl@0
  1124
		case TRawEvent::EKeyDown:
sl@0
  1125
		case TRawEvent::EKeyUp:
sl@0
  1126
			{
sl@0
  1127
			TKeyEvent keyEvent;
sl@0
  1128
			keyEvent.iCode=0;
sl@0
  1129
			keyEvent.iScanCode=aRawEvent.ScanCode();
sl@0
  1130
			keyEvent.iModifiers=0;
sl@0
  1131
			keyEvent.iRepeats=0;
sl@0
  1132
			CClick::KeyEvent(EEventKey,keyEvent);
sl@0
  1133
			}
sl@0
  1134
			break;
sl@0
  1135
		case TRawEvent::EButton1Down:
sl@0
  1136
		case TRawEvent::EButton1Up:
sl@0
  1137
		case TRawEvent::EButton2Down:
sl@0
  1138
		case TRawEvent::EButton2Up:
sl@0
  1139
		case TRawEvent::EButton3Down:
sl@0
  1140
		case TRawEvent::EButton3Up:
sl@0
  1141
		case TRawEvent::EPointerMove:
sl@0
  1142
		case TRawEvent::EPointerSwitchOn:
sl@0
  1143
			{
sl@0
  1144
			TBool handled=ETrue;
sl@0
  1145
			TPointerEvent::TType type;
sl@0
  1146
			GetPointerEvent(type, aRawEvent, handled);
sl@0
  1147
			if (handled)
sl@0
  1148
				{
sl@0
  1149
				TWsEvent event;
sl@0
  1150
				TAdvancedPointerEventHelper::InitAdvancedPointerEvent(event, type, 0, aRawEvent.Pos3D(), TPoint(), aRawEvent.PointerNumber());
sl@0
  1151
				TAdvancedPointerEvent& pointerEvent = *event.Pointer();
sl@0
  1152
				CClick::PointerEvent(pointerEvent.iPosition,pointerEvent);
sl@0
  1153
				}
sl@0
  1154
			}
sl@0
  1155
			break;
sl@0
  1156
		default:
sl@0
  1157
			break;
sl@0
  1158
		}
sl@0
  1159
	}
sl@0
  1160
sl@0
  1161
/*
sl@0
  1162
Process a raw event
sl@0
  1163
sl@0
  1164
@param	aRawEvent	Raw event
sl@0
  1165
*/
sl@0
  1166
void TWindowServerEvent::ProcessRawEvent(const TRawEvent& aRawEvent)
sl@0
  1167
//
sl@0
  1168
// Event has completed.
sl@0
  1169
//
sl@0
  1170
	{
sl@0
  1171
	TRawEvent::TType eventType = aRawEvent.Type();
sl@0
  1172
	TBool isPointerEvent = TWsPointer::IsPointerEventType(eventType);
sl@0
  1173
	if (isPointerEvent)
sl@0
  1174
		{
sl@0
  1175
#ifdef LOG_WSERV_EVENTS
sl@0
  1176
        RDebug::Print(_L("_WSEVENT_POINTER: TWindowServerEvent::ProcessRawEvent EventName = %S PointerNumber = %d PrimaryPointerNumber = %d Coordinates = ( %d, %d )"), 
sl@0
  1177
                &RawEventName(aRawEvent),aRawEvent.PointerNumber(),TWsPointer::PrimaryPointer(),aRawEvent.Pos().iX,aRawEvent.Pos().iY); 
sl@0
  1178
#endif
sl@0
  1179
        TWsPointer::UpdatePrimaryPointer(aRawEvent);
sl@0
  1180
		}
sl@0
  1181
	TInt count=iEventHandlers.Count();
sl@0
  1182
	TInt ii;
sl@0
  1183
	TBool eventHandled = EFalse;
sl@0
  1184
	iEventHandlerCount++;
sl@0
  1185
	for(ii=0;ii<count;++ii)
sl@0
  1186
		{
sl@0
  1187
		TRawEventHandler &handler = iEventHandlers[ii];
sl@0
  1188
		if (handler.iEventHandler != NULL &&
sl@0
  1189
			(!isPointerEvent ||
sl@0
  1190
			 handler.iAdvancedPointersEnabled ||
sl@0
  1191
			 aRawEvent.PointerNumber() == TWsPointer::PrimaryPointer()) &&
sl@0
  1192
			handler.iEventHandler->OfferRawEvent(aRawEvent))
sl@0
  1193
			{
sl@0
  1194
			if (CClick::IsHandler())
sl@0
  1195
				{
sl@0
  1196
#ifdef LOG_WSERV_EVENTS
sl@0
  1197
				RDebug::Print(_L("_WSEVENT_KEY: Send event %S for Key Click"), &RawEventName(aRawEvent));
sl@0
  1198
#endif
sl@0
  1199
				SendEventToKeyClick(aRawEvent);
sl@0
  1200
				}
sl@0
  1201
			eventHandled = ETrue;
sl@0
  1202
#ifdef LOG_WSERV_EVENTS
sl@0
  1203
            RDebug::Printf("_WSEVENT_POINTER: TWindowServerEvent::ProcessRawEvent Event Consumed by ANIM.dll Handler No = %d Advanced Pointer Enabled = %d",ii,handler.iAdvancedPointersEnabled);
sl@0
  1204
#endif
sl@0
  1205
			break;
sl@0
  1206
			}
sl@0
  1207
		}
sl@0
  1208
	if (--iEventHandlerCount == 0)
sl@0
  1209
		{
sl@0
  1210
		if (ERemovedEventHandlerWhileProcessingRawEvents & iBinaryFlags) // Handler was deleted while previous loop
sl@0
  1211
			{ 
sl@0
  1212
			iBinaryFlags &= ~ERemovedEventHandlerWhileProcessingRawEvents;
sl@0
  1213
			for(ii=count-1;ii>=0;--ii)
sl@0
  1214
				{
sl@0
  1215
				if (iEventHandlers[ii].iEventHandler==NULL) iEventHandlers.Remove(ii);
sl@0
  1216
				}
sl@0
  1217
			}
sl@0
  1218
		}
sl@0
  1219
	if (eventHandled)
sl@0
  1220
		{
sl@0
  1221
#ifdef LOG_WSERV_EVENTS
sl@0
  1222
		RDebug::Printf("_WSEVENT: Event is already handled by anim dll not by window server");
sl@0
  1223
		// This is to determine when we press the power button which bring power dialog
sl@0
  1224
		// whether it is a pointer event or key event
sl@0
  1225
		// Also when we plugin the charging cable this is to determine whether it is a pointer event or key event
sl@0
  1226
		RDebug::Print(_L("_WSEVENT: RawEvent Name = %S"), &RawEventName(aRawEvent));
sl@0
  1227
#endif
sl@0
  1228
		if (isPointerEvent)
sl@0
  1229
			{
sl@0
  1230
#ifdef LOG_WSERV_EVENTS
sl@0
  1231
			RDebug::Printf("_WSEVENT_POINTER: TWindowServerEvent::ProcessRawEvent Pointer Number= %d  State = %x XY(%d,%d)",TWsPointer::iPointers[0].iNumber,TWsPointer::iPointers[0].iState,TWsPointer::iPointers[0].iPos.iX,TWsPointer::iPointers[0].iPos.iY);
sl@0
  1232
		    RDebug::Printf("_WSEVENT_POINTER: TWindowServerEvent::ProcessRawEvent Pointer Number= %d  State = %x XY(%d,%d)",TWsPointer::iPointers[1].iNumber,TWsPointer::iPointers[1].iState,TWsPointer::iPointers[1].iPos.iX,TWsPointer::iPointers[1].iPos.iY);
sl@0
  1233
#endif
sl@0
  1234
              //Prevention of the phone pointer event "dead lock". 
sl@0
  1235
              TPointerEvent::TType type;
sl@0
  1236
              TBool handled = ETrue;
sl@0
  1237
              GetPointerEvent(type, aRawEvent, handled);
sl@0
  1238
              switch(type)
sl@0
  1239
                  {
sl@0
  1240
                  case TPointerEvent::EButton1Down:
sl@0
  1241
                  case TPointerEvent::EButton2Down:
sl@0
  1242
                  case TPointerEvent::EButton3Down:
sl@0
  1243
                      TWsPointer::iPointers[aRawEvent.PointerNumber()].iState = TWsPointer::EPointerStateDown;
sl@0
  1244
                      break;
sl@0
  1245
                  case TPointerEvent::EButton1Up:
sl@0
  1246
                  case TPointerEvent::EButton2Up:
sl@0
  1247
                  case TPointerEvent::EButton3Up:
sl@0
  1248
                      TWsPointer::iPointers[aRawEvent.PointerNumber()].iState = TWsPointer::EPointerStateUp;
sl@0
  1249
                      break;
sl@0
  1250
                  case TPointerEvent::EOutOfRange:
sl@0
  1251
                      TWsPointer::iPointers[aRawEvent.PointerNumber()].iState = TWsPointer::EPointerStateOutOfRange;
sl@0
  1252
                      break;
sl@0
  1253
                      default:
sl@0
  1254
                      break;
sl@0
  1255
                  }
sl@0
  1256
			}
sl@0
  1257
		return;
sl@0
  1258
		}
sl@0
  1259
	
sl@0
  1260
	switch(eventType)
sl@0
  1261
		{
sl@0
  1262
		case TRawEvent::ERedraw:
sl@0
  1263
			CWsTop::RedrawScreens();
sl@0
  1264
			break;
sl@0
  1265
		case TRawEvent::ESwitchOn:
sl@0
  1266
		case TRawEvent::ECaseOpen:
sl@0
  1267
			{
sl@0
  1268
			TInt event=EEventCaseOpened;
sl@0
  1269
			CKeyboardRepeat::CancelRepeat(NULL);
sl@0
  1270
			CWsPassword::SwitchOn();
sl@0
  1271
			if (eventType==TRawEvent::ESwitchOn)
sl@0
  1272
				{
sl@0
  1273
				UserSvr::WsSwitchOnScreen();
sl@0
  1274
				HAL::Set(HALData::EDisplayState,1);
sl@0
  1275
				event=EEventSwitchOn;
sl@0
  1276
				}
sl@0
  1277
			ProcessEventQueue(iSwitchOnQueue, SendSwitchOnEvent, event, 0);
sl@0
  1278
			break;
sl@0
  1279
			}
sl@0
  1280
		case TRawEvent::ESwitchOff:
sl@0
  1281
		case TRawEvent::ECaseClose:
sl@0
  1282
			{
sl@0
  1283
			TBool switchOff=(eventType==TRawEvent::ESwitchOff);
sl@0
  1284
			CWsTop::HandleSwitchOff(switchOff? EEventSwitchOff:EEventCaseClosed,switchOff);
sl@0
  1285
			break;
sl@0
  1286
			}
sl@0
  1287
#ifdef SYMBIAN_PROCESS_MONITORING_AND_STARTUP			
sl@0
  1288
		case TRawEvent::ERestartSystem:
sl@0
  1289
			{ /* restart event being handled */
sl@0
  1290
			CWsTop::HandleSwitchOff(EEventRestartSystem,ETrue);
sl@0
  1291
			break;
sl@0
  1292
			}
sl@0
  1293
#endif			
sl@0
  1294
		case TRawEvent::EInactive:
sl@0
  1295
#ifndef __WINS__
sl@0
  1296
			CWsTop::WindowServer()->AnimationScheduler()->OnInactive();
sl@0
  1297
#endif
sl@0
  1298
			CKeyboardRepeat::CancelRepeat(NULL);
sl@0
  1299
			break;
sl@0
  1300
		case TRawEvent::EActive:
sl@0
  1301
#ifndef __WINS__
sl@0
  1302
			CWsTop::WindowServer()->AnimationScheduler()->OnActive();
sl@0
  1303
#endif
sl@0
  1304
			break;
sl@0
  1305
		case TRawEvent::EKeyDown:
sl@0
  1306
			{
sl@0
  1307
#ifdef LOG_WSERV_EVENTS
sl@0
  1308
			RDebug::Printf("_WSEVENT_KEY: TRawEvent::EKeyDown");
sl@0
  1309
#endif
sl@0
  1310
			_LIT(KWSERVDebugLogKeyDownArrival,"Key down arrives %d");
sl@0
  1311
			CScreen* screen = CWsTop::Screen();
sl@0
  1312
			WS_ASSERT_ALWAYS(screen, EWsPanicNoScreen);
sl@0
  1313
			if(CDebugBar* dbg = screen->DebugBar())
sl@0
  1314
				dbg->OnKeyEvent();
sl@0
  1315
			if (wsDebugLog)
sl@0
  1316
				wsDebugLog->MiscMessage(CDebugLogBase::ELogEverything,KWSERVDebugLogKeyDownArrival,aRawEvent.ScanCode());
sl@0
  1317
			CKeyboardRepeat::KeyDown();
sl@0
  1318
			TKeyData keyData;
sl@0
  1319
			// Note iCaptureKeys is needed as dummy arg only. Key capture is
sl@0
  1320
			// now handled in ProcessKeyPress().
sl@0
  1321
			TBool translated=iKeyTranslator->TranslateKey(aRawEvent.ScanCode(), EFalse,*iCaptureKeys,keyData);
sl@0
  1322
			ProcessModifierChanges();
sl@0
  1323
			QueueKeyUpDown(aRawEvent);
sl@0
  1324
			if (translated)
sl@0
  1325
				{
sl@0
  1326
				TKeyEvent keyEvent;
sl@0
  1327
				keyEvent.iScanCode = aRawEvent.ScanCode() __REMOVE_WINS_CHARCODE;
sl@0
  1328
				keyEvent.iCode = keyData.iKeyCode;
sl@0
  1329
				keyEvent.iModifiers = keyData.iModifiers;
sl@0
  1330
				ProcessKeyPress(keyEvent, ETrue, 0);
sl@0
  1331
				}
sl@0
  1332
			}
sl@0
  1333
			break;
sl@0
  1334
		case TRawEvent::EKeyUp:
sl@0
  1335
			{
sl@0
  1336
#ifdef LOG_WSERV_EVENTS
sl@0
  1337
			RDebug::Printf("_WSEVENT_KEY: TRawEvent::EKeyUp");
sl@0
  1338
#endif
sl@0
  1339
			_LIT(KWSERVDebugLogKeyUpArrival,"Key up arrives %d");
sl@0
  1340
			CScreen* screen = CWsTop::Screen();
sl@0
  1341
			WS_ASSERT_ALWAYS(screen, EWsPanicNoScreen);
sl@0
  1342
			if(CDebugBar* dbg = screen->DebugBar())
sl@0
  1343
				dbg->OnKeyEvent();
sl@0
  1344
			if (wsDebugLog)
sl@0
  1345
				wsDebugLog->MiscMessage(CDebugLogBase::ELogEverything,KWSERVDebugLogKeyUpArrival,aRawEvent.ScanCode());
sl@0
  1346
			TKeyData keyData;
sl@0
  1347
			CKeyboardRepeat::KeyUp(aRawEvent.ScanCode() __REMOVE_WINS_CHARCODE);
sl@0
  1348
			TBool translated=iKeyTranslator->TranslateKey(aRawEvent.ScanCode(), ETrue,*iCaptureKeys,keyData);
sl@0
  1349
			ProcessModifierChanges();
sl@0
  1350
			QueueKeyUpDown(aRawEvent);
sl@0
  1351
			if (translated)
sl@0
  1352
				{
sl@0
  1353
				CKeyboardRepeat::CancelRepeat(NULL);
sl@0
  1354
				TKeyEvent keyEvent;
sl@0
  1355
				keyEvent.iScanCode = aRawEvent.ScanCode() __REMOVE_WINS_CHARCODE;
sl@0
  1356
				keyEvent.iCode = keyData.iKeyCode;
sl@0
  1357
				keyEvent.iModifiers = keyData.iModifiers;
sl@0
  1358
				ProcessKeyPress(keyEvent, EFalse, 0);
sl@0
  1359
				}
sl@0
  1360
			}
sl@0
  1361
			break;
sl@0
  1362
		case TRawEvent::EButton1Down:
sl@0
  1363
		case TRawEvent::EButton2Down:
sl@0
  1364
		case TRawEvent::EButton3Down:
sl@0
  1365
		case TRawEvent::EPointerSwitchOn:
sl@0
  1366
#ifndef __WINS__
sl@0
  1367
			CWsTop::WindowServer()->AnimationScheduler()->OnActive();
sl@0
  1368
#endif
sl@0
  1369
			// fall through
sl@0
  1370
		case TRawEvent::EButton1Up:
sl@0
  1371
		case TRawEvent::EButton2Up:
sl@0
  1372
		case TRawEvent::EButton3Up:
sl@0
  1373
		case TRawEvent::EPointerMove:
sl@0
  1374
		case TRawEvent::EPointer3DOutOfRange:
sl@0
  1375
			#if defined(_DEBUG)
sl@0
  1376
				WS_ASSERT_DEBUG(MousePress(aRawEvent,NULL), EWsPanicEventType);
sl@0
  1377
			#else
sl@0
  1378
				MousePress(aRawEvent,NULL);
sl@0
  1379
			#endif
sl@0
  1380
			break;
sl@0
  1381
		case TRawEvent::EUpdateModifiers:
sl@0
  1382
			iKeyTranslator->UpdateModifiers(aRawEvent.Modifiers());
sl@0
  1383
			break;
sl@0
  1384
		case TRawEvent::EKeyRepeat:
sl@0
  1385
 			{
sl@0
  1386
 			_LIT(KWSERVDebugLogRepeatingKeyArrival,"Repeating key arrives %d");
sl@0
  1387
 			if (wsDebugLog)
sl@0
  1388
 				wsDebugLog->MiscMessage(CDebugLogBase::ELogEverything,KWSERVDebugLogRepeatingKeyArrival,aRawEvent.ScanCode());
sl@0
  1389
			TKeyEvent keyEvent;
sl@0
  1390
			keyEvent.iScanCode = aRawEvent.ScanCode() __REMOVE_WINS_CHARCODE;
sl@0
  1391
			keyEvent.iCode = aRawEvent.ScanCode();
sl@0
  1392
 			keyEvent.iModifiers = iKeyTranslator->GetModifierState();
sl@0
  1393
			ProcessKeyPress(keyEvent, EFalse, aRawEvent.Repeats());
sl@0
  1394
 			}
sl@0
  1395
 			break;
sl@0
  1396
		default:
sl@0
  1397
			break;
sl@0
  1398
		}
sl@0
  1399
#ifdef LOG_WSERV_EVENTS
sl@0
  1400
    RDebug::Printf("_WSEVENT_POINTER: TWindowServerEvent::ProcessRawEvent Number= %d  State = %x XY(%d,%d)",TWsPointer::iPointers[0].iNumber,TWsPointer::iPointers[0].iState,TWsPointer::iPointers[0].iPos.iX,TWsPointer::iPointers[0].iPos.iY);
sl@0
  1401
    RDebug::Printf("_WSEVENT_POINTER: TWindowServerEvent::ProcessRawEvent Number= %d  State = %x XY(%d,%d)",TWsPointer::iPointers[1].iNumber,TWsPointer::iPointers[1].iState,TWsPointer::iPointers[1].iPos.iX,TWsPointer::iPointers[1].iPos.iY);
sl@0
  1402
#endif
sl@0
  1403
	}
sl@0
  1404
sl@0
  1405
void TWindowServerEvent::ProcessKeyEvent(const TKeyEvent &aKeyEvent,TInt aRepeats)
sl@0
  1406
	{
sl@0
  1407
#ifdef LOG_WSERV_EVENTS
sl@0
  1408
    RDebug::Printf("_WSEVENT_KEY: TWindowServerEvent::ProcessKeyEvent, key code: %d, repeat: %d", aKeyEvent.iCode, aRepeats);
sl@0
  1409
#endif
sl@0
  1410
	TKeyData keyData;
sl@0
  1411
	keyData.iModifiers=aKeyEvent.iModifiers;
sl@0
  1412
	keyData.iApp=0;
sl@0
  1413
	keyData.iHandle=0;
sl@0
  1414
	keyData.iIsCaptureKey=EFalse;
sl@0
  1415
	keyData.iKeyCode=aKeyEvent.iCode;
sl@0
  1416
	if (CKeyboardRepeat::IsAreadyActive())
sl@0
  1417
		{
sl@0
  1418
		CKeyboardRepeat::CancelRepeat(NULL);
sl@0
  1419
		}
sl@0
  1420
	ProcessKeyPress(aKeyEvent, aRepeats == 0, aRepeats);
sl@0
  1421
	}
sl@0
  1422
sl@0
  1423
void TWindowServerEvent::AddCaptureKeyL(const TKeyCaptureRequest& aRequest)
sl@0
  1424
	{
sl@0
  1425
	iKeyEventRouter->AddCaptureKeyL(aRequest);
sl@0
  1426
	}
sl@0
  1427
sl@0
  1428
void TWindowServerEvent::UpdateCaptureKeyL(const TKeyCaptureRequest& aRequest)
sl@0
  1429
	{
sl@0
  1430
	iKeyEventRouter->UpdateCaptureKeyL(aRequest);
sl@0
  1431
	}
sl@0
  1432
sl@0
  1433
void TWindowServerEvent::CancelCaptureKey(TKeyCaptureType aType, TAny* aHandle)
sl@0
  1434
	{
sl@0
  1435
	iKeyEventRouter->CancelCaptureKey(aType, aHandle);
sl@0
  1436
	}
sl@0
  1437
sl@0
  1438
TInt TWindowServerEvent::GetModifierState()
sl@0
  1439
	{
sl@0
  1440
	return(iKeyTranslator->GetModifierState());
sl@0
  1441
	}
sl@0
  1442
sl@0
  1443
void TWindowServerEvent::SetModifierState(TEventModifier aModifier,TModifierState aState)
sl@0
  1444
	{
sl@0
  1445
	iKeyTranslator->SetModifierState(aModifier,aState);
sl@0
  1446
	}
sl@0
  1447
sl@0
  1448
TInt TWindowServerEvent::AddNotificationHandler(CAnim* aAnim, TUint32 aNotifications)
sl@0
  1449
	{
sl@0
  1450
	SNotificationHandler notif;
sl@0
  1451
	notif.iAnim = aAnim;
sl@0
  1452
	notif.iNotifications = aNotifications;
sl@0
  1453
sl@0
  1454
	// update the entry if the anim is already in the array
sl@0
  1455
	TInt count=iNotificationHandlers->Count();
sl@0
  1456
	TInt ii;
sl@0
  1457
	for(ii=0;ii<count;++ii)
sl@0
  1458
		{
sl@0
  1459
		if ((*iNotificationHandlers)[ii].iAnim==aAnim)
sl@0
  1460
			{
sl@0
  1461
			(*iNotificationHandlers)[ii]=notif;
sl@0
  1462
			return KErrNone;
sl@0
  1463
			}
sl@0
  1464
		}
sl@0
  1465
	
sl@0
  1466
	// otherwise add it to the array
sl@0
  1467
	TRAPD(err,iNotificationHandlers->AppendL(notif));
sl@0
  1468
	return err;
sl@0
  1469
	}
sl@0
  1470
sl@0
  1471
void TWindowServerEvent::RemoveNotificationHandler(CAnim* aAnim)
sl@0
  1472
	{
sl@0
  1473
	TInt count=iNotificationHandlers->Count();
sl@0
  1474
	TInt ii;
sl@0
  1475
	for(ii=0;ii<count;++ii)
sl@0
  1476
		{
sl@0
  1477
		if ((*iNotificationHandlers)[ii].iAnim==aAnim)
sl@0
  1478
			{
sl@0
  1479
			iNotificationHandlers->Delete(ii);
sl@0
  1480
			return;
sl@0
  1481
			}
sl@0
  1482
		}
sl@0
  1483
	}
sl@0
  1484
sl@0
  1485
void TWindowServerEvent::PublishNotification(const TWsEvent& aWsEvent)
sl@0
  1486
	{
sl@0
  1487
	TInt count=iNotificationHandlers->Count();
sl@0
  1488
	TInt ii;
sl@0
  1489
	for(ii=0;ii<count;++ii)
sl@0
  1490
		{
sl@0
  1491
		SNotificationHandler notif = (*iNotificationHandlers)[ii];
sl@0
  1492
		switch (aWsEvent.Type())
sl@0
  1493
			{
sl@0
  1494
		case EEventDirectScreenAccessBegin:
sl@0
  1495
		case EEventDirectScreenAccessEnd:
sl@0
  1496
			if (notif.iNotifications & EDirectScreenAccess)
sl@0
  1497
				{
sl@0
  1498
				notif.iAnim->HandleNotification(aWsEvent);
sl@0
  1499
				}
sl@0
  1500
			break;
sl@0
  1501
		case EEventHeartbeatTimerStateChange:
sl@0
  1502
			if (notif.iNotifications & EHeartbeatTimer)
sl@0
  1503
				{
sl@0
  1504
				notif.iAnim->HandleNotification(aWsEvent);
sl@0
  1505
				}
sl@0
  1506
			break;
sl@0
  1507
		case EEventScreenDeviceChanged:
sl@0
  1508
			if (notif.iNotifications & EScreenDeviceChange)
sl@0
  1509
				{
sl@0
  1510
				notif.iAnim->HandleNotification(aWsEvent);
sl@0
  1511
				}
sl@0
  1512
			break;
sl@0
  1513
		default:
sl@0
  1514
			break;
sl@0
  1515
			}
sl@0
  1516
		}
sl@0
  1517
sl@0
  1518
	}
sl@0
  1519
sl@0
  1520
TBool TWindowServerEvent::DrawerCompareFunc(const TDrawerHandler& lhs, const TDrawerHandler& rhs)
sl@0
  1521
	{
sl@0
  1522
	return lhs.iDrawer == rhs.iDrawer;	
sl@0
  1523
	}
sl@0
  1524
sl@0
  1525
TInt TWindowServerEvent::RegisterDrawerHandler(CWsGraphicDrawer* aDrawer, TUint32 aEvents)
sl@0
  1526
	{
sl@0
  1527
	TInt idx = iDrawerHandlers->Find(TDrawerHandler(aDrawer, aEvents),
sl@0
  1528
		TIdentityRelation<TDrawerHandler>(TWindowServerEvent::DrawerCompareFunc));
sl@0
  1529
	if (idx != KErrNotFound)
sl@0
  1530
		{
sl@0
  1531
		// replace event mask for this drawer
sl@0
  1532
		(*iDrawerHandlers)[idx].iEvents = aEvents;
sl@0
  1533
		idx = KErrNone;
sl@0
  1534
		}
sl@0
  1535
	else
sl@0
  1536
		idx = iDrawerHandlers->Append(TDrawerHandler(aDrawer,aEvents));
sl@0
  1537
	
sl@0
  1538
	return idx;
sl@0
  1539
	}
sl@0
  1540
sl@0
  1541
TInt TWindowServerEvent::UnregisterDrawerHandler(CWsGraphicDrawer* aDrawer)
sl@0
  1542
	{
sl@0
  1543
	TInt idx = iDrawerHandlers->Find(TDrawerHandler(aDrawer,0),
sl@0
  1544
		TIdentityRelation<TDrawerHandler>(TWindowServerEvent::DrawerCompareFunc));
sl@0
  1545
	if (idx == KErrNotFound)
sl@0
  1546
		return idx;
sl@0
  1547
	(*iDrawerHandlers)[idx].iDrawer = NULL;		//NotifyDrawer() will clean up the array
sl@0
  1548
	return KErrNone;
sl@0
  1549
	}
sl@0
  1550
sl@0
  1551
TInt TWindowServerEvent::RegisterWsEventHandler(MWsEventHandler * aHandler, TUint32 aEvents)
sl@0
  1552
	{
sl@0
  1553
	TWsEventHandler handler(aHandler, aEvents);
sl@0
  1554
	TInt idx = iWsEventHandlers.Find(handler, TIdentityRelation<TWsEventHandler>(TWsEventHandler::CompareHandler));
sl@0
  1555
	if (idx < 0)
sl@0
  1556
		{
sl@0
  1557
		TInt err = iWsEventHandlers.Append(handler);
sl@0
  1558
		return err;
sl@0
  1559
		}
sl@0
  1560
	else
sl@0
  1561
		{
sl@0
  1562
		iWsEventHandlers[idx].iEvents = aEvents;
sl@0
  1563
		return KErrNone;
sl@0
  1564
		}
sl@0
  1565
	}
sl@0
  1566
	
sl@0
  1567
TInt TWindowServerEvent::UnregisterWsEventHandler(MWsEventHandler * aHandler)
sl@0
  1568
	{
sl@0
  1569
	TWsEventHandler handler(aHandler, 0);
sl@0
  1570
	TInt idx = iWsEventHandlers.Find(handler, TIdentityRelation<TWsEventHandler>(TWsEventHandler::CompareHandler));
sl@0
  1571
	if (idx < 0)
sl@0
  1572
		return idx;
sl@0
  1573
	iWsEventHandlers[idx].iEvents = NULL;	//NotifyDrawer() will clean up the array
sl@0
  1574
	return KErrNone;
sl@0
  1575
	}
sl@0
  1576
sl@0
  1577
sl@0
  1578
void TWindowServerEvent::NotifyDrawer(const TWservCrEvent& aEvent)
sl@0
  1579
	{
sl@0
  1580
	TInt drawerCount = iDrawerHandlers->Count();
sl@0
  1581
	for (TInt idx = 0; idx < drawerCount; idx++)
sl@0
  1582
		{
sl@0
  1583
		TDrawerHandler hd = (*iDrawerHandlers)[idx]; 
sl@0
  1584
		if (!hd.iDrawer) 
sl@0
  1585
			{                					//If the handler has been removed 
sl@0
  1586
			iDrawerHandlers->Remove(idx);       //Remove from the array 
sl@0
  1587
			drawerCount -= 1;   				//Update the counters 
sl@0
  1588
			idx -= 1; 
sl@0
  1589
			} 
sl@0
  1590
		else 
sl@0
  1591
			{ 
sl@0
  1592
			if (hd.iEvents & aEvent.Type()) 
sl@0
  1593
				{ 
sl@0
  1594
			    hd.iDrawer->HandleEvent(aEvent); 
sl@0
  1595
			    } 
sl@0
  1596
			} 
sl@0
  1597
		}
sl@0
  1598
	
sl@0
  1599
	TInt eventHandlerCount = iWsEventHandlers.Count();
sl@0
  1600
	for (TInt idx = 0; idx < eventHandlerCount; ++idx)
sl@0
  1601
		{
sl@0
  1602
		TWsEventHandler* eh = &iWsEventHandlers[idx];
sl@0
  1603
		if (!eh->iEvents)
sl@0
  1604
			{								//If the handler has been removed
sl@0
  1605
			iWsEventHandlers.Remove(idx);	//Remove from the array
sl@0
  1606
			eventHandlerCount -= 1;			//Update the counters
sl@0
  1607
			idx -= 1;
sl@0
  1608
			}
sl@0
  1609
		else
sl@0
  1610
			{
sl@0
  1611
			if (eh->iEvents & aEvent.Type())
sl@0
  1612
				{
sl@0
  1613
				eh->iHandler->DoHandleEvent(aEvent);
sl@0
  1614
				}
sl@0
  1615
			}
sl@0
  1616
		}
sl@0
  1617
	}
sl@0
  1618
sl@0
  1619
void TWindowServerEvent::NotifyScreenDrawingEvent(const TRegion* aRegion)
sl@0
  1620
	{
sl@0
  1621
	if (aRegion && !aRegion->IsEmpty())
sl@0
  1622
		{
sl@0
  1623
		TWservCrEvent event(TWservCrEvent::EScreenDrawing,0,const_cast<TRegion*>(aRegion));
sl@0
  1624
		NotifyDrawer(event);
sl@0
  1625
		}
sl@0
  1626
	}
sl@0
  1627
sl@0
  1628
void TWindowServerEvent::NotifyScreenDrawingEvent(const TRect& aRect)
sl@0
  1629
	{
sl@0
  1630
	TRegionFix<1> reg(aRect);
sl@0
  1631
	TWservCrEvent event(TWservCrEvent::EScreenDrawing,0,&reg);
sl@0
  1632
	NotifyDrawer(event);
sl@0
  1633
	}
sl@0
  1634
sl@0
  1635
//
sl@0
  1636
// CRawEventReceiver //
sl@0
  1637
//
sl@0
  1638
sl@0
  1639
CRawEventReceiver::CRawEventReceiver(TInt aPriority) : CActive(aPriority)
sl@0
  1640
//
sl@0
  1641
// Constructor
sl@0
  1642
//
sl@0
  1643
	{
sl@0
  1644
	__DECLARE_NAME(_S("CRawEventReceiver"));
sl@0
  1645
	}
sl@0
  1646
sl@0
  1647
CRawEventReceiver::~CRawEventReceiver()
sl@0
  1648
	{
sl@0
  1649
	CActive::Cancel();
sl@0
  1650
	}
sl@0
  1651
sl@0
  1652
void CRawEventReceiver::ConstructL()
sl@0
  1653
	{
sl@0
  1654
	CActiveScheduler::Add(this);
sl@0
  1655
	UserSvr::CaptureEventHook();
sl@0
  1656
	Request();
sl@0
  1657
	}
sl@0
  1658
sl@0
  1659
void CRawEventReceiver::Request()
sl@0
  1660
//
sl@0
  1661
// Issue a request for the next event.
sl@0
  1662
//
sl@0
  1663
	{
sl@0
  1664
	UserSvr::RequestEvent(iEventBuf,iStatus);
sl@0
  1665
	SetActive();
sl@0
  1666
	}
sl@0
  1667
sl@0
  1668
void CRawEventReceiver::DoCancel()
sl@0
  1669
//
sl@0
  1670
// Cancel a pending event.
sl@0
  1671
//
sl@0
  1672
	{
sl@0
  1673
	UserSvr::RequestEventCancel();
sl@0
  1674
	}
sl@0
  1675
sl@0
  1676
void CRawEventReceiver::RunL()
sl@0
  1677
	{
sl@0
  1678
#ifdef LOG_WSERV_EVENTS
sl@0
  1679
    RDebug::Printf("_WSEVENT_KEY: CRawEventReceiver::RunL Entry point for event receiver");
sl@0
  1680
#endif
sl@0
  1681
//__PROFILE_START(11);
sl@0
  1682
	if (TWsPointer::PreProcessDriverEvent(iEventBuf.Event()
sl@0
  1683
#if defined(__WINS__)
sl@0
  1684
													,ETrue
sl@0
  1685
#endif
sl@0
  1686
														  ))
sl@0
  1687
		TWindowServerEvent::ProcessRawEvent(iEventBuf.Event());
sl@0
  1688
	Request();
sl@0
  1689
//__PROFILE_END(11);
sl@0
  1690
	}
sl@0
  1691
sl@0
  1692
//
sl@0
  1693
// TEventRequestQueue //
sl@0
  1694
//
sl@0
  1695
sl@0
  1696
TEventRequestQueue::TEventRequestQueue() : iQueue(_FOFF(TEventRequestItem,iQue))
sl@0
  1697
	{}
sl@0
  1698
sl@0
  1699
inline TSglQue<TEventRequestItem> &TEventRequestQueue::Queue()
sl@0
  1700
	{return(iQueue);}
sl@0
  1701
sl@0
  1702
TEventRequestItem *TEventRequestQueue::FindInEventRequestQueueList(const CWsWindowBase &aWindow)
sl@0
  1703
//
sl@0
  1704
// Return a pointer to the link in the queue for the window, or NULL if not in the queue
sl@0
  1705
//
sl@0
  1706
	{
sl@0
  1707
	TSglQueIter<TEventRequestItem> iter(iQueue);
sl@0
  1708
	TEventRequestItem *qPtr;
sl@0
  1709
	while((qPtr=iter++)!=NULL)
sl@0
  1710
		if (qPtr->iWindow==&aWindow)
sl@0
  1711
			break;
sl@0
  1712
	return(qPtr);
sl@0
  1713
	}
sl@0
  1714
sl@0
  1715
void TEventRequestQueue::AddToEventRequestListL(const CWsWindowBase &aWindow, TInt aParam, TEventControl aCircumstances)
sl@0
  1716
//
sl@0
  1717
// Add a link to the on event list
sl@0
  1718
//
sl@0
  1719
	{
sl@0
  1720
	TEventRequestItem *item=FindInEventRequestQueueList(aWindow);
sl@0
  1721
	if (!item)
sl@0
  1722
		{
sl@0
  1723
		item=new(ELeave) TEventRequestItem;
sl@0
  1724
		item->iWindow= &aWindow;
sl@0
  1725
		item->iParam=aParam;
sl@0
  1726
		item->iCircumstances=aCircumstances;
sl@0
  1727
		iQueue.AddFirst(*item);
sl@0
  1728
		}
sl@0
  1729
	item->iCircumstances=aCircumstances;
sl@0
  1730
	item->iParam=aParam;	// Just update the parameter if already exists
sl@0
  1731
	}
sl@0
  1732
sl@0
  1733
void TEventRequestQueue::RemoveFromEventRequestListL(const CWsWindowBase &aWindow)
sl@0
  1734
//
sl@0
  1735
// Remove a link from the on event list
sl@0
  1736
//
sl@0
  1737
	{
sl@0
  1738
	TEventRequestItem *qPtr=FindInEventRequestQueueList(aWindow);
sl@0
  1739
	if (qPtr)
sl@0
  1740
		{
sl@0
  1741
		iQueue.Remove(*qPtr);
sl@0
  1742
		delete qPtr;
sl@0
  1743
		}
sl@0
  1744
	}
sl@0
  1745
sl@0
  1746
//
sl@0
  1747
// Keyboard auto repeat class //
sl@0
  1748
//
sl@0
  1749
sl@0
  1750
CKeyboardRepeat::CKeyboardRepeat() : CTimer(EKeyRepeatPriority)
sl@0
  1751
	{}
sl@0
  1752
sl@0
  1753
void CKeyboardRepeat::NewL()
sl@0
  1754
	{
sl@0
  1755
	iThis=new(ELeave) CKeyboardRepeat();
sl@0
  1756
	iThis->ConstructL();
sl@0
  1757
	CActiveScheduler::Add(iThis);
sl@0
  1758
	_LIT(KWSERVIniFileVarRepeatRollover,"REPEATROLLOVER");
sl@0
  1759
	WsIniFile->FindVar(KWSERVIniFileVarRepeatRollover,iRepeatRollover);
sl@0
  1760
	}
sl@0
  1761
sl@0
  1762
void CKeyboardRepeat::Destroy()
sl@0
  1763
	{
sl@0
  1764
	delete iThis;
sl@0
  1765
	}
sl@0
  1766
sl@0
  1767
void CKeyboardRepeat::GetRepeatTime(TTimeIntervalMicroSeconds32 &aInitialTime, TTimeIntervalMicroSeconds32 &aTime)
sl@0
  1768
	{
sl@0
  1769
	aInitialTime=iInitialTime;
sl@0
  1770
	aTime=iTime;
sl@0
  1771
	}
sl@0
  1772
sl@0
  1773
void CKeyboardRepeat::SetRepeatTime(const TTimeIntervalMicroSeconds32 &aInitialTime, const TTimeIntervalMicroSeconds32 &aTime)
sl@0
  1774
	{
sl@0
  1775
	iInitialTime=aInitialTime;
sl@0
  1776
	iTime=aTime;
sl@0
  1777
	}
sl@0
  1778
sl@0
  1779
/**
sl@0
  1780
Process timer events.
sl@0
  1781
sl@0
  1782
Called when the key repeat timer expires, this function generates the
sl@0
  1783
appropriate long key or repeated key event. If the timer was started for
sl@0
  1784
normal key repeat or if the long key event was captured with the automatic
sl@0
  1785
repeat option specified then the timer is restarted.
sl@0
  1786
*/
sl@0
  1787
void CKeyboardRepeat::RunL()
sl@0
  1788
	{
sl@0
  1789
	User::ResetInactivityTime();
sl@0
  1790
	WS_ASSERT_DEBUG(iRepeating != ERepeatNone, EWsPanicKeyRepeat);
sl@0
  1791
	TBool timer=ETrue;
sl@0
  1792
	if (iRepeating>=ERepeatLong)
sl@0
  1793
		{
sl@0
  1794
		// Defensive programming - iLongCapture should never be NULL if iRepeating >= ERepeatLong
sl@0
  1795
		WS_ASSERT_DEBUG(iLongCapture != NULL, EWsPanicKeyRepeat);
sl@0
  1796
		if (iLongCapture)
sl@0
  1797
			{
sl@0
  1798
			iCurrentRepeat = iLongRepeat;
sl@0
  1799
			timer = iLongCapture->iFlags & ELongCaptureRepeatEvents;
sl@0
  1800
			iRepeating=ERepeatLongRepeated;
sl@0
  1801
			}
sl@0
  1802
		else
sl@0
  1803
			{
sl@0
  1804
			// Defensive programming - iLongCapture should never be NULL if iRepeating >= ERepeatLong
sl@0
  1805
			// Stop key repeat if this incorrect condition occurs
sl@0
  1806
			timer=EFalse; 
sl@0
  1807
			}		
sl@0
  1808
		}
sl@0
  1809
	if (timer)
sl@0
  1810
		After(iTime);
sl@0
  1811
	else
sl@0
  1812
		iRepeating=ERepeatNone;
sl@0
  1813
sl@0
  1814
	TWindowServerEvent::QueueKeyPress(iCurrentRepeat.iOutput, ETrue, 1);
sl@0
  1815
	}
sl@0
  1816
sl@0
  1817
/**
sl@0
  1818
Start key repeat and long key press timer
sl@0
  1819
sl@0
  1820
@param	aInputScanCode	Original scan code (before routing)
sl@0
  1821
@param	aShortEvent		Short key event (routing plug-in output)
sl@0
  1822
@param	aLongEvent		Pointer to long key event (routing plug-in output)
sl@0
  1823
						or NULL if none.
sl@0
  1824
sl@0
  1825
Note: When aLongEvent != NULL, iCurrentRepeat reflects the short key event
sl@0
  1826
until the timer has expired. This is necessary to allow a delayed short key
sl@0
  1827
event to be delivered by KeyUp(). CancelRepeat() must therefore examine
sl@0
  1828
iCurrentRepeat or iLongRepeat according to the repeat type in iRepeat.
sl@0
  1829
*/
sl@0
  1830
void CKeyboardRepeat::StartRepeat(TInt aInputScanCode, const TKeyEventRouterOutput& aShortEvent, const TKeyEventRouterOutput* aLongEvent)
sl@0
  1831
	{
sl@0
  1832
	TTimeIntervalMicroSeconds32 time;
sl@0
  1833
	iCurrentRepeat.iInputScanCode = aInputScanCode;
sl@0
  1834
	iCurrentRepeat.iOutput = aShortEvent;
sl@0
  1835
sl@0
  1836
	if (aLongEvent)
sl@0
  1837
		{
sl@0
  1838
		iRepeating = ERepeatLong;
sl@0
  1839
		iLongRepeat.iInputScanCode = aInputScanCode;
sl@0
  1840
		iLongRepeat.iOutput = *aLongEvent;
sl@0
  1841
		iLongCapture = static_cast<CWsCaptureLongKey*>(aLongEvent->iCaptureHandle);
sl@0
  1842
		time = iLongCapture->iDelay;
sl@0
  1843
		}
sl@0
  1844
	else
sl@0
  1845
		{
sl@0
  1846
		iLongCapture = NULL;
sl@0
  1847
		iRepeating=ERepeatNormal;
sl@0
  1848
		time=iInitialTime;
sl@0
  1849
		}
sl@0
  1850
	iThis->After(time);
sl@0
  1851
	}
sl@0
  1852
sl@0
  1853
/**
sl@0
  1854
Cancel key repeat processing
sl@0
  1855
*/
sl@0
  1856
void CKeyboardRepeat::doCancelRepeat()
sl@0
  1857
	{
sl@0
  1858
	iRepeating=ERepeatNone;
sl@0
  1859
	iThis->Cancel();
sl@0
  1860
	}
sl@0
  1861
sl@0
  1862
/**
sl@0
  1863
Cancel any key repeat associated with the specified window group
sl@0
  1864
sl@0
  1865
@param	aRepeatFocus	Destination window group or NULL for all
sl@0
  1866
*/
sl@0
  1867
void CKeyboardRepeat::CancelRepeat(CWsWindowGroup *aRepeatFocus)
sl@0
  1868
	{
sl@0
  1869
	if (iRepeating != ERepeatNone)
sl@0
  1870
		{
sl@0
  1871
		if (aRepeatFocus == NULL ||
sl@0
  1872
			(iRepeating == ERepeatNormal) && (aRepeatFocus == iCurrentRepeat.iOutput.iWindowGroup) ||
sl@0
  1873
			(iRepeating >= ERepeatLong) && (aRepeatFocus == iLongRepeat.iOutput.iWindowGroup))
sl@0
  1874
			{
sl@0
  1875
			doCancelRepeat();
sl@0
  1876
			iAlternateRepeatExists=EFalse;
sl@0
  1877
			}
sl@0
  1878
		}
sl@0
  1879
	}
sl@0
  1880
sl@0
  1881
/**
sl@0
  1882
Cancel any key repeat associated with the specified capture handle
sl@0
  1883
sl@0
  1884
@param	aCaptureHandle		Handle to capture request
sl@0
  1885
@param	aLongCaptureFlag	ETrue for long key capture, EFalse for normal key
sl@0
  1886
*/
sl@0
  1887
void CKeyboardRepeat::CancelRepeat(const TAny* aCaptureHandle, TBool aLongCaptureFlag)
sl@0
  1888
	{
sl@0
  1889
	if (aLongCaptureFlag)
sl@0
  1890
		{
sl@0
  1891
		// Cancel repeat for long capture key
sl@0
  1892
		if (iRepeating >= ERepeatLong && aCaptureHandle == iLongRepeat.iOutput.iCaptureHandle)
sl@0
  1893
			{
sl@0
  1894
			doCancelRepeat();
sl@0
  1895
			iAlternateRepeatExists=EFalse;
sl@0
  1896
			}
sl@0
  1897
		}
sl@0
  1898
	else
sl@0
  1899
		{
sl@0
  1900
		// Cancel repeat for normal capture key
sl@0
  1901
		if (iRepeating == ERepeatNormal && aCaptureHandle == iCurrentRepeat.iOutput.iCaptureHandle)
sl@0
  1902
			{
sl@0
  1903
			doCancelRepeat();
sl@0
  1904
			iAlternateRepeatExists=EFalse;
sl@0
  1905
			}
sl@0
  1906
		}
sl@0
  1907
	}
sl@0
  1908
	
sl@0
  1909
/**
sl@0
  1910
Process a key down event during key repeat.
sl@0
  1911
The current repeat data is saved for possible restoration after rollover.
sl@0
  1912
*/
sl@0
  1913
void CKeyboardRepeat::KeyDown()
sl@0
  1914
	{
sl@0
  1915
	if (iRepeating!=ERepeatNone)
sl@0
  1916
		{
sl@0
  1917
		if (iRepeating==ERepeatNormal && iRepeatRollover>0) // 1 Allow key repeat rollover
sl@0
  1918
			{
sl@0
  1919
			iAlternateRepeat=iCurrentRepeat;
sl@0
  1920
			iAlternateRepeatExists=ETrue;
sl@0
  1921
			}
sl@0
  1922
		doCancelRepeat();
sl@0
  1923
		}
sl@0
  1924
	}
sl@0
  1925
sl@0
  1926
/**
sl@0
  1927
Process a key up event during key repeat.
sl@0
  1928
Send delayed short key event if necessary for long key event processing.
sl@0
  1929
Switch to alternate repeat if rollover key was released.
sl@0
  1930
sl@0
  1931
@param	aScanCode	Scan code
sl@0
  1932
*/
sl@0
  1933
void CKeyboardRepeat::KeyUp(TInt aScanCode)
sl@0
  1934
	{
sl@0
  1935
	if (iAlternateRepeatExists && iAlternateRepeat.iInputScanCode == aScanCode)
sl@0
  1936
		iAlternateRepeatExists=EFalse;
sl@0
  1937
	if (iRepeating != ERepeatNone && iCurrentRepeat.iInputScanCode == aScanCode)
sl@0
  1938
		{
sl@0
  1939
		if (iRepeating==ERepeatLong)
sl@0
  1940
			{
sl@0
  1941
			// Defensive programming - iLongCapture should never be NULL if iRepeating >= ERepeatLong			
sl@0
  1942
			WS_ASSERT_DEBUG(iLongCapture != NULL, EWsPanicKeyRepeat);
sl@0
  1943
			if (iLongCapture && !(iLongCapture->iFlags & ELongCaptureShortEventImmediately))
sl@0
  1944
				{
sl@0
  1945
				TWindowServerEvent::QueueKeyPress(iCurrentRepeat.iOutput, EFalse, 0);
sl@0
  1946
				}
sl@0
  1947
			}			
sl@0
  1948
		if (iAlternateRepeatExists)
sl@0
  1949
			{
sl@0
  1950
			iAlternateRepeatExists=EFalse;
sl@0
  1951
			iCurrentRepeat=iAlternateRepeat;
sl@0
  1952
			iRepeating=ERepeatNormal;
sl@0
  1953
			}
sl@0
  1954
		else
sl@0
  1955
			doCancelRepeat();
sl@0
  1956
		}
sl@0
  1957
	}
sl@0
  1958
sl@0
  1959
//
sl@0
  1960
// CWsHotKey //
sl@0
  1961
//
sl@0
  1962
sl@0
  1963
CWsHotKey::CWsHotKey(TInt aHotKeyType, TBool aIsDefault) : 
sl@0
  1964
	iHotKeyType(aHotKeyType),
sl@0
  1965
	iIsDefault(aIsDefault)
sl@0
  1966
	{
sl@0
  1967
	}
sl@0
  1968
sl@0
  1969
CWsHotKey::~CWsHotKey()
sl@0
  1970
	{
sl@0
  1971
	delete iCaptureKey;
sl@0
  1972
	}
sl@0
  1973
sl@0
  1974
void CWsHotKey::ConstructLD(const TWsWinCmdCaptureKey &aCaptureKey)
sl@0
  1975
	{
sl@0
  1976
	CleanupStack::PushL(this);
sl@0
  1977
	iCaptureKey=new(ELeave) CWsCaptureKey(NULL);
sl@0
  1978
	iCaptureKey->ConstructL(aCaptureKey);
sl@0
  1979
	CleanupStack::Pop();
sl@0
  1980
	}
sl@0
  1981
sl@0
  1982
void CWsHotKey::SetL(const TWsWinCmdCaptureKey &aCaptureKey)
sl@0
  1983
	{
sl@0
  1984
	iCaptureKey->SetL(aCaptureKey);
sl@0
  1985
	}
sl@0
  1986
sl@0
  1987
//
sl@0
  1988
//CEventQueueRetry//
sl@0
  1989
//
sl@0
  1990
CEventQueueRetry* CEventQueueRetry::NewL()
sl@0
  1991
	{
sl@0
  1992
	CEventQueueRetry* self = new (ELeave) CEventQueueRetry;
sl@0
  1993
	CleanupStack::PushL(self);
sl@0
  1994
	self->ConstructL();
sl@0
  1995
	CleanupStack::Pop(self);
sl@0
  1996
	return self;
sl@0
  1997
	}
sl@0
  1998
      
sl@0
  1999
void CEventQueueRetry::ConstructL()
sl@0
  2000
	{
sl@0
  2001
	User::LeaveIfError(iTimer.CreateLocal());
sl@0
  2002
	CActiveScheduler::Add(this);
sl@0
  2003
	}
sl@0
  2004
 
sl@0
  2005
CEventQueueRetry::CEventQueueRetry() : CActive(EPriorityStandard), iRetrySpinner(1)
sl@0
  2006
	{
sl@0
  2007
	
sl@0
  2008
	}
sl@0
  2009
sl@0
  2010
CEventQueueRetry::~CEventQueueRetry()
sl@0
  2011
	{
sl@0
  2012
	Cancel();
sl@0
  2013
	iTimer.Close();
sl@0
  2014
	iClientArray.Close();
sl@0
  2015
	}
sl@0
  2016
sl@0
  2017
void CEventQueueRetry::DoCancel()
sl@0
  2018
	{
sl@0
  2019
	iTimer.Cancel();
sl@0
  2020
	iRetrySpinner = 0;
sl@0
  2021
	iClientArray.Reset();
sl@0
  2022
	}
sl@0
  2023
sl@0
  2024
void CEventQueueRetry::RunL()
sl@0
  2025
	{
sl@0
  2026
	//some clients may be no longer interested in listening
sl@0
  2027
	//so we need to refresh the client list each round of retry
sl@0
  2028
	iClientArray.Reset();
sl@0
  2029
	TInt err = iOwner->GetNotificationClients(iClientArray);
sl@0
  2030
	if(err != KErrNone)
sl@0
  2031
		{
sl@0
  2032
		iClientArray.Reset(); //so the retry won't kick off
sl@0
  2033
		}
sl@0
  2034
	if(iClientArray.Count() > 0)
sl@0
  2035
		{
sl@0
  2036
		TBool eventOnAllQueues = ETrue;
sl@0
  2037
		for(TInt i = 0; i < iClientArray.Count(); i++)
sl@0
  2038
			{
sl@0
  2039
			if(iClientArray[i]->RetryEvent(EEventDisplayChanged))
sl@0
  2040
				{
sl@0
  2041
				if(TWindowServerEvent::SendDisplayChangedEvents(iClientArray[i], iOwner->ScreenNumber(),
sl@0
  2042
						iOwner->ConfigSpinner(), iOwner->DisplaySpinner()))
sl@0
  2043
					{
sl@0
  2044
					iClientArray[i]->RemoveRetryFlag(EEventDisplayChanged);
sl@0
  2045
					}
sl@0
  2046
				else
sl@0
  2047
					{
sl@0
  2048
					eventOnAllQueues = EFalse;
sl@0
  2049
					}
sl@0
  2050
				}
sl@0
  2051
			}
sl@0
  2052
		
sl@0
  2053
		if(!eventOnAllQueues)
sl@0
  2054
			{//another retry needed, but with increased time interval
sl@0
  2055
			iRetrySpinner++;
sl@0
  2056
			Retry(KRetryInitialDelay*iRetrySpinner);
sl@0
  2057
			}
sl@0
  2058
		}
sl@0
  2059
	
sl@0
  2060
	}
sl@0
  2061
sl@0
  2062
void CEventQueueRetry::Retry(TInt aDelay)
sl@0
  2063
	{
sl@0
  2064
	//the retry might be infinite, with an increasing interval, as delivery of the event is garuanteed
sl@0
  2065
	//if aDelay is greater than max TInt, it will be negative number so we reset it to KRetryInitialDelay
sl@0
  2066
	if(aDelay < 0)
sl@0
  2067
		{
sl@0
  2068
		aDelay = KRetryInitialDelay;
sl@0
  2069
		}
sl@0
  2070
	iTimer.After(iStatus, aDelay);
sl@0
  2071
	SetActive();
sl@0
  2072
	}
sl@0
  2073
sl@0
  2074
void CEventQueueRetry::Init(CScreen *aOwner)
sl@0
  2075
	{
sl@0
  2076
	iOwner = aOwner;
sl@0
  2077
	iRetrySpinner = 0;
sl@0
  2078
	
sl@0
  2079
	}
sl@0
  2080
sl@0
  2081
void CEventQueueRetry::CancelRetry()
sl@0
  2082
	{
sl@0
  2083
	Cancel();
sl@0
  2084
	}