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