os/boardsupport/emulator/emulatorbsp/specific/gui.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) 1995-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
// wins\specific\gui.cpp
sl@0
    15
// 
sl@0
    16
//
sl@0
    17
#define WINVER 0x0500
sl@0
    18
sl@0
    19
#include "gui.h"
sl@0
    20
#include <emulator.h>
sl@0
    21
#include <assp.h>
sl@0
    22
#include <kernel/kern_priv.h>
sl@0
    23
#include <kernel/kpower.h>
sl@0
    24
#include "variant.h"
sl@0
    25
#include "resource.h"
sl@0
    26
#include "winsgui.h"
sl@0
    27
#include "display_chan.h"
sl@0
    28
#include "pixelformats.h"
sl@0
    29
#include "multitouch.h"
sl@0
    30
sl@0
    31
#include "monitors.h"
sl@0
    32
sl@0
    33
//Define these so that emulator generates varying values for gce stride and offset.
sl@0
    34
//By default in emulator, stride is exactly right for display resolution and offset is zero
sl@0
    35
//Setting these will identify code which incorrectly calculates these factors instead of requesting them
sl@0
    36
//Note that multiples of 4 bytes are preferred for various reasons.
sl@0
    37
//[3/5/07 The Secure presentation burffer ignores stride extra because it uses a windows bitmap header to render.]
sl@0
    38
// #define TEST_GCE_VARIABLE_STRIDE_EXTRA	16		 	//This constant is added to each mode's scanline length in bytes. It may cause a break if enabled because the iDisplayBufferOffset is not being set
sl@0
    39
// #define TEST_GCE_VARIABLE_START_EXTRA	16			//A multiple of this is added to each mode's start address in bytes
sl@0
    40
// #define ASSYMETRIC_SQUARE_STRIDE						//If this is defined and the width==height the the stride will not be the same!
sl@0
    41
sl@0
    42
enum  
sl@0
    43
	{
sl@0
    44
		KMaskModeNum=0x0FFFFFFF,
sl@0
    45
		KMaskModeFlag8=0x80000000,
sl@0
    46
		KMaskModeFlag4=0x40000000,
sl@0
    47
		KMaskModeFlag2=0x20000000,
sl@0
    48
		KMaskModeFlag1=0x10000000,
sl@0
    49
		
sl@0
    50
		KModeFlagFlipped=KMaskModeFlag8,
sl@0
    51
		
sl@0
    52
	};
sl@0
    53
enum  
sl@0
    54
	{
sl@0
    55
		KMaskScreenNum=0x0FFF,
sl@0
    56
		KMaskScreenFlag8=0x8000,
sl@0
    57
		KMaskScreenFlag4=0x4000,
sl@0
    58
		KMaskScreenFlag2=0x2000,
sl@0
    59
		KMaskScreenFlag1=0x1000,
sl@0
    60
		
sl@0
    61
		KScreenFlagSecure=KMaskScreenFlag8,
sl@0
    62
		
sl@0
    63
	};
sl@0
    64
const TInt KMaxDisplayColors=16777216;
sl@0
    65
const TInt KMaxDisplayContrast=1;
sl@0
    66
sl@0
    67
static TEmulatorFlip* CurrentFlipState=NULL;
sl@0
    68
static TInt CurrentConfiguration = 0;
sl@0
    69
static TInt SavedFlipMessage = 0;
sl@0
    70
sl@0
    71
DWinsUi *systemIni=NULL;
sl@0
    72
DMasterIni* masterIni;
sl@0
    73
sl@0
    74
DMultiTouch* TheMultiTouch;
sl@0
    75
static HWND TheControlWin;
sl@0
    76
static HWND* TheChildWin=NULL;
sl@0
    77
static HWND* TheWin=NULL;
sl@0
    78
static HWND hwndStatus; // To display the X,Y,Z information of each mouse
sl@0
    79
static TInt VirtualKeyPressed = EStdKeyNull;
sl@0
    80
static HBITMAP* TheScreenBitmap=NULL;
sl@0
    81
static TUint LedMask;
sl@0
    82
static TBool WsSwitchOnScreen;
sl@0
    83
sl@0
    84
const char * DefaultWindowTitle = "Symbian OS Emulator";
sl@0
    85
sl@0
    86
#ifdef __VC32__
sl@0
    87
sl@0
    88
#ifdef _DEBUG
sl@0
    89
const char * VersionText = " - wins udeb";
sl@0
    90
#else
sl@0
    91
const char * VersionText = " - wins urel";
sl@0
    92
#endif
sl@0
    93
sl@0
    94
#else
sl@0
    95
#ifdef __CW32__
sl@0
    96
sl@0
    97
#ifdef _DEBUG
sl@0
    98
const char * VersionText = " - winscw udeb";
sl@0
    99
#else
sl@0
   100
const char * VersionText = " - winscw urel";
sl@0
   101
#endif
sl@0
   102
sl@0
   103
#else
sl@0
   104
//not winscw or wins!
sl@0
   105
#ifdef _DEBUG
sl@0
   106
const char * VersionText = " - unknown udeb";
sl@0
   107
#else
sl@0
   108
const char * VersionText = " - unknown urel");
sl@0
   109
#endif
sl@0
   110
sl@0
   111
#endif
sl@0
   112
#endif
sl@0
   113
sl@0
   114
void Inactive();
sl@0
   115
void Active();
sl@0
   116
void DrawLeds();
sl@0
   117
void UpdateModifiers(); 
sl@0
   118
TInt DisplayHalFunction(TAny*, TInt aFunction, TAny* a1, TAny* a2);
sl@0
   119
LOCAL_C TBool PaintWindowFromBuffer(HWND hWnd);
sl@0
   120
sl@0
   121
GLDEF_C const char* skipws(const char* aPtr)
sl@0
   122
	{
sl@0
   123
	while (isspace(*aPtr))
sl@0
   124
		++aPtr;
sl@0
   125
	return aPtr;
sl@0
   126
	}
sl@0
   127
sl@0
   128
GLDEF_C const char* skiptok(const char* aPtr)
sl@0
   129
	{
sl@0
   130
	while (isalnum(*aPtr))
sl@0
   131
		++aPtr;
sl@0
   132
	return aPtr;
sl@0
   133
	}
sl@0
   134
sl@0
   135
GLDEF_C TInt CompareI(const TDesC8& aLhs, const TDesC8& aRhs)
sl@0
   136
//
sl@0
   137
// Case insensitive comparison of descriptors
sl@0
   138
// (TDesC::CompareF not available to kernel side code)
sl@0
   139
//
sl@0
   140
	{
sl@0
   141
	TInt ll = aLhs.Length();
sl@0
   142
	TInt rl = aRhs.Length();
sl@0
   143
	TInt len = Min(ll, rl);
sl@0
   144
	TInt k = _strnicmp((const char*)aLhs.Ptr(), (const char*)aRhs.Ptr(), len);
sl@0
   145
	return k != 0 ? k : ll - rl;
sl@0
   146
	}
sl@0
   147
sl@0
   148
GLDEF_C TInt MultiProperty(TInt (*aHandler)(TAny* aObj, const char*), TAny* aPtr, const char* aProperty)
sl@0
   149
	{
sl@0
   150
	const char* value = Property::GetString(aProperty);
sl@0
   151
	if (!value)
sl@0
   152
		return KErrNone;
sl@0
   153
	for (;;)
sl@0
   154
		{
sl@0
   155
		TInt r = aHandler(aPtr, value);
sl@0
   156
		if (r != KErrNone)
sl@0
   157
			return r;
sl@0
   158
		const char* ev = strchr(value, ';');
sl@0
   159
		if (!ev)
sl@0
   160
			break;
sl@0
   161
		value = ev + 1;
sl@0
   162
		}
sl@0
   163
	return KErrNone;
sl@0
   164
	}
sl@0
   165
sl@0
   166
class DWinsGuiPowerHandler : public DPowerHandler
sl@0
   167
	{
sl@0
   168
public: // from DPowerHandler
sl@0
   169
	void PowerDown(TPowerState);
sl@0
   170
	void PowerUp();
sl@0
   171
public:
sl@0
   172
	static DWinsGuiPowerHandler* New();
sl@0
   173
	void ScreenOn();
sl@0
   174
	void ScreenOff();
sl@0
   175
	void ScreenOn(TInt aScreen);
sl@0
   176
	void ScreenOff(TInt aScreen);
sl@0
   177
public:
sl@0
   178
	DWinsGuiPowerHandler();
sl@0
   179
	TBool ProcessEvent(const TRawEvent* aEvent);
sl@0
   180
	TBool ProcessEventDfc(const TRawEvent* aEvent);
sl@0
   181
	TBool	iStandby;
sl@0
   182
	};
sl@0
   183
sl@0
   184
static DWinsGuiPowerHandler* WinsGuiPowerHandler;
sl@0
   185
sl@0
   186
_LIT(KWinsGuiName, "WinsGui");
sl@0
   187
sl@0
   188
DWinsGuiPowerHandler* DWinsGuiPowerHandler::New()
sl@0
   189
	{
sl@0
   190
	DWinsGuiPowerHandler* self = new DWinsGuiPowerHandler();
sl@0
   191
	if (!self)
sl@0
   192
		return NULL;
sl@0
   193
	self->Add();
sl@0
   194
sl@0
   195
	return self;
sl@0
   196
	}
sl@0
   197
sl@0
   198
DWinsGuiPowerHandler::DWinsGuiPowerHandler() : DPowerHandler(KWinsGuiName)
sl@0
   199
	{
sl@0
   200
	}
sl@0
   201
sl@0
   202
void DWinsGuiPowerHandler::ScreenOff()
sl@0
   203
	{
sl@0
   204
	for(TInt ix=0;ix<systemIni->iScreens.Count();ix++)
sl@0
   205
		ScreenOff(ix);
sl@0
   206
	}
sl@0
   207
sl@0
   208
void DWinsGuiPowerHandler::ScreenOn()
sl@0
   209
	{
sl@0
   210
	for(TInt ix=0;ix<systemIni->iScreens.Count();ix++)
sl@0
   211
		ScreenOn(ix);
sl@0
   212
	}
sl@0
   213
sl@0
   214
void DWinsGuiPowerHandler::ScreenOff(TInt aScreen)
sl@0
   215
	{
sl@0
   216
	PostMessageA(TheWin[aScreen], WM_EMUL_POWER_ON, FALSE, NULL);
sl@0
   217
	systemIni->iScreens[aScreen]->iScreenOff = ETrue;
sl@0
   218
	}
sl@0
   219
sl@0
   220
void DWinsGuiPowerHandler::ScreenOn(TInt aScreen)
sl@0
   221
	{
sl@0
   222
	PostMessageA(TheWin[aScreen], WM_EMUL_POWER_ON, TRUE, NULL);
sl@0
   223
	systemIni->iScreens[aScreen]->iScreenOff = EFalse;
sl@0
   224
	}
sl@0
   225
sl@0
   226
void DWinsGuiPowerHandler::PowerDown(TPowerState aState)
sl@0
   227
	{
sl@0
   228
	if (aState == EPwStandby)
sl@0
   229
		iStandby = ETrue;
sl@0
   230
	ScreenOff();
sl@0
   231
	PowerDownDone();
sl@0
   232
	}
sl@0
   233
sl@0
   234
sl@0
   235
void DWinsGuiPowerHandler::PowerUp()
sl@0
   236
	{
sl@0
   237
	iStandby = EFalse;
sl@0
   238
	ScreenOn();
sl@0
   239
	PowerUpDone();
sl@0
   240
	}
sl@0
   241
sl@0
   242
// called in the interrupt context
sl@0
   243
TBool DWinsGuiPowerHandler::ProcessEvent(const TRawEvent* aEvent)
sl@0
   244
	{
sl@0
   245
	if (!iStandby)
sl@0
   246
		// Pass through 
sl@0
   247
		return EFalse;
sl@0
   248
sl@0
   249
	if ((aEvent->Type() == TRawEvent::EKeyDown))
sl@0
   250
			{
sl@0
   251
			Wins::Self() -> AssertWakeupSignal();
sl@0
   252
			}
sl@0
   253
	
sl@0
   254
	// Ignore
sl@0
   255
	return ETrue;
sl@0
   256
	}
sl@0
   257
sl@0
   258
// called in DFC
sl@0
   259
TBool DWinsGuiPowerHandler::ProcessEventDfc(const TRawEvent* aEvent)
sl@0
   260
	{
sl@0
   261
	if (aEvent->Type() == TRawEvent::EKeyDown)
sl@0
   262
		{
sl@0
   263
		Wins::Self() -> WakeupEvent();
sl@0
   264
		if (aEvent->ScanCode() == EStdKeyF5)
sl@0
   265
			{
sl@0
   266
			// Simulate a media change interrupt (media removed)
sl@0
   267
			Wins::MediaChangeCallBack();
sl@0
   268
			*Wins::MediaDoorOpenPtr()=ETrue;
sl@0
   269
			// Ignore
sl@0
   270
			return ETrue;
sl@0
   271
			}
sl@0
   272
		if (aEvent->ScanCode() == EStdKeyF8)
sl@0
   273
			{
sl@0
   274
			TRawEvent v;
sl@0
   275
			v.Set(TRawEvent::ECaseClose);
sl@0
   276
			Kern::AddEvent(v);
sl@0
   277
			// Ignore
sl@0
   278
			return ETrue;
sl@0
   279
			}
sl@0
   280
		if (aEvent->ScanCode() == EStdKeyF8)
sl@0
   281
			{
sl@0
   282
			TRawEvent v;
sl@0
   283
			v.Set(TRawEvent::ECaseClose);
sl@0
   284
			Kern::AddEvent(v);
sl@0
   285
			// Ignore
sl@0
   286
			return ETrue;
sl@0
   287
			}
sl@0
   288
		if (aEvent->ScanCode() == EStdKeyOff)
sl@0
   289
			{
sl@0
   290
			// Pass through
sl@0
   291
			return EFalse;
sl@0
   292
			}
sl@0
   293
		if (aEvent->ScanCode() == EStdKeyF10)
sl@0
   294
			{
sl@0
   295
			TRawEvent v;
sl@0
   296
			v.Set(TRawEvent::ESwitchOff);
sl@0
   297
			Kern::AddEvent(v);
sl@0
   298
			// Ignore
sl@0
   299
			return ETrue;
sl@0
   300
			}
sl@0
   301
		if (aEvent->ScanCode() == EStdKeyF11)
sl@0
   302
			{
sl@0
   303
			TRawEvent v;
sl@0
   304
			v.Set(TRawEvent::ECaseOpen);
sl@0
   305
			Kern::AddEvent(v);
sl@0
   306
			// Ignore
sl@0
   307
			return ETrue;
sl@0
   308
			}
sl@0
   309
		}
sl@0
   310
	else if (aEvent->Type() == TRawEvent::EKeyUp)
sl@0
   311
		{
sl@0
   312
		if (aEvent->ScanCode() == EStdKeyF10)
sl@0
   313
			// Ignore
sl@0
   314
			return ETrue;
sl@0
   315
sl@0
   316
		if (aEvent->ScanCode() == EStdKeyF5)
sl@0
   317
			{
sl@0
   318
			// Simulate a media change interrupt (media Present)
sl@0
   319
			*Wins::MediaDoorOpenPtr()=EFalse;
sl@0
   320
			return ETrue;
sl@0
   321
			}
sl@0
   322
		}
sl@0
   323
sl@0
   324
	// Path through
sl@0
   325
	return EFalse;
sl@0
   326
	}
sl@0
   327
sl@0
   328
class EventQ
sl@0
   329
	{
sl@0
   330
	enum {ESize = 16};
sl@0
   331
public:
sl@0
   332
	EventQ();
sl@0
   333
	void Add(const TRawEvent& aEvent);
sl@0
   334
private:
sl@0
   335
	static void Dfc(TAny* aPtr);
sl@0
   336
	void Empty();
sl@0
   337
private:
sl@0
   338
	TDfc iDfc;
sl@0
   339
	TRawEvent* iTail;
sl@0
   340
	TRawEvent iQ[ESize];
sl@0
   341
	};
sl@0
   342
sl@0
   343
EventQ::EventQ()
sl@0
   344
	:iDfc(&EventQ::Dfc, this, Kern::DfcQue0(), 6), iTail(iQ)
sl@0
   345
	{}
sl@0
   346
sl@0
   347
sl@0
   348
void EventQ::Add(const TRawEvent& aEvent)
sl@0
   349
	{
sl@0
   350
	StartOfInterrupt();	
sl@0
   351
	if (WinsGuiPowerHandler->ProcessEvent(&aEvent)) 
sl@0
   352
		{
sl@0
   353
		EndOfInterrupt();
sl@0
   354
		return;
sl@0
   355
		}
sl@0
   356
sl@0
   357
	TRawEvent* pE = iTail;
sl@0
   358
	if (pE != &iQ[ESize])
sl@0
   359
		{
sl@0
   360
		*pE = aEvent;
sl@0
   361
		iTail = pE + 1;
sl@0
   362
		if (pE == iQ)
sl@0
   363
			iDfc.Add();
sl@0
   364
		}
sl@0
   365
	EndOfInterrupt();
sl@0
   366
	}
sl@0
   367
sl@0
   368
void EventQ::Dfc(TAny* aPtr)
sl@0
   369
	{
sl@0
   370
	static_cast<EventQ*>(aPtr)->Empty();
sl@0
   371
	}
sl@0
   372
sl@0
   373
void EventQ::Empty()
sl@0
   374
//
sl@0
   375
// Called in the DFC
sl@0
   376
//
sl@0
   377
	{
sl@0
   378
	TInt irq;
sl@0
   379
	TRawEvent* pE = iQ;
sl@0
   380
	for (;;)
sl@0
   381
		{
sl@0
   382
		if (!WinsGuiPowerHandler->ProcessEventDfc(pE)) 
sl@0
   383
			Kern::AddEvent(*pE);
sl@0
   384
		++pE;
sl@0
   385
		irq = NKern::DisableAllInterrupts();
sl@0
   386
		if (pE == iTail)
sl@0
   387
			break;
sl@0
   388
		NKern::RestoreInterrupts(irq);
sl@0
   389
		}
sl@0
   390
	iTail = iQ;
sl@0
   391
	NKern::RestoreInterrupts(irq);
sl@0
   392
	}
sl@0
   393
sl@0
   394
LOCAL_D EventQ TheEventQ;
sl@0
   395
sl@0
   396
// Virtual keys
sl@0
   397
sl@0
   398
sl@0
   399
VirtualKey::VirtualKey(const TInt aCommandData, const TEmulCommand aCommand) : iCommand(aCommand), iData(aCommandData)
sl@0
   400
	{
sl@0
   401
	}
sl@0
   402
sl@0
   403
TBool VKRect::Contains(TInt aX, TInt aY) const
sl@0
   404
	{
sl@0
   405
	return (aX >= iLeft && aX < iRight && aY >= iTop && aY < iBottom);
sl@0
   406
	}
sl@0
   407
sl@0
   408
VKRect::VKRect(const TInt aCommandData, const TEmulCommand aCommand, TInt aX, TInt aY, TInt aWidth, TInt aHeight) :
sl@0
   409
	VirtualKey(aCommandData, aCommand)
sl@0
   410
	{
sl@0
   411
	iLeft = aX;
sl@0
   412
	iTop = aY;
sl@0
   413
	iRight = aX + aWidth;
sl@0
   414
	iBottom = aY + aHeight;
sl@0
   415
	}
sl@0
   416
sl@0
   417
sl@0
   418
sl@0
   419
void VKRect::Draw(HDC aHdc,COLORREF aColor) const
sl@0
   420
	{
sl@0
   421
	HPEN pen;
sl@0
   422
	pen=CreatePen(PS_SOLID, 2, aColor);
sl@0
   423
	SelectObject(aHdc, pen);
sl@0
   424
	POINT point;
sl@0
   425
sl@0
   426
	MoveToEx(aHdc, (int)iLeft, (int)iTop, &point);
sl@0
   427
	LineTo(aHdc, (int)iLeft, (int)iBottom);
sl@0
   428
	LineTo(aHdc, (int)iRight, (int)iBottom);
sl@0
   429
	LineTo(aHdc, (int)iRight, (int)iTop);
sl@0
   430
	LineTo(aHdc, (int)iLeft, (int)iTop);
sl@0
   431
	}
sl@0
   432
sl@0
   433
sl@0
   434
KeyCombination::KeyCombination(const TInt aCommandData, TEmulCommand aCommand):
sl@0
   435
	iData(aCommandData),
sl@0
   436
	iCommand(aCommand)
sl@0
   437
{
sl@0
   438
	for (TInt i=0;i<KMaxHotKeyCombinationLength;i++) 
sl@0
   439
		{
sl@0
   440
		iCombination[i]=EStdKeyNull;
sl@0
   441
		}
sl@0
   442
}
sl@0
   443
sl@0
   444
TBool KeyCombination::CheckCombinationPressed()
sl@0
   445
{
sl@0
   446
	for (TInt j=0;(j<KMaxHotKeyCombinationLength && iCombination[j]!=0);j++)
sl@0
   447
		{
sl@0
   448
		if (GetAsyncKeyState(MapVirtualKey(iCombination[j],1))>=0)//if at least one key is not pressed, we return false
sl@0
   449
			return EFalse;				
sl@0
   450
		}
sl@0
   451
	return ETrue;	
sl@0
   452
}
sl@0
   453
sl@0
   454
TBool KeyCombination::AddKey(TStdScanCode aKey)
sl@0
   455
{
sl@0
   456
	TInt i;
sl@0
   457
	for (i=0;i<KMaxHotKeyCombinationLength;i++) 
sl@0
   458
		{
sl@0
   459
		if (iCombination[i]==EStdKeyNull) 
sl@0
   460
			break;
sl@0
   461
		}
sl@0
   462
	if (KMaxHotKeyCombinationLength==i)
sl@0
   463
		return EFalse;
sl@0
   464
	else		
sl@0
   465
		iCombination[i]=aKey;	
sl@0
   466
sl@0
   467
	return ETrue;
sl@0
   468
}
sl@0
   469
sl@0
   470
sl@0
   471
DScreenProperties::DScreenProperties()
sl@0
   472
	{
sl@0
   473
	memset(this,0,sizeof(DScreenProperties));
sl@0
   474
	iColorDepth=KDefaultColorDepth;
sl@0
   475
	
sl@0
   476
	iViewport = TViewport(this);
sl@0
   477
	}
sl@0
   478
sl@0
   479
sl@0
   480
LOCAL_C TInt MaskGceOnly(TInt aModeBits)
sl@0
   481
	{	   //All HAL modes are now reported. The GCE may refuse to register the surfaces.
sl@0
   482
	return aModeBits&KEmulModes;	//previous useful settings: //(KEmulPixPerLong2|KEmulPixPerLong1);	//|KEmulPixPerLong4;
sl@0
   483
	}
sl@0
   484
	
sl@0
   485
LOCAL_C TInt BitsForSingleMode(TInt aModeColor)
sl@0
   486
	{	//only 1 bit should be set in aModeColor
sl@0
   487
	switch (aModeColor)
sl@0
   488
		{
sl@0
   489
		case KEmulGray2:	return 1;	
sl@0
   490
		case KEmulGray4:	return 2;	
sl@0
   491
		case KEmulGray16:	return 4;
sl@0
   492
		case KEmulGray256:	return 8;
sl@0
   493
		case KEmulColor16:	return 4;
sl@0
   494
		case KEmulColor256:	return 8;
sl@0
   495
		case KEmulColor4K:	return 12;
sl@0
   496
		case KEmulColor64K:	return 16;
sl@0
   497
		case KEmulColor16M:	return 24;
sl@0
   498
		default:	return 32;
sl@0
   499
		}
sl@0
   500
	
sl@0
   501
	}
sl@0
   502
sl@0
   503
DScreenProperties::~DScreenProperties() 
sl@0
   504
	{
sl@0
   505
	}
sl@0
   506
sl@0
   507
TWindowState DScreenProperties::GetWindowState()
sl@0
   508
	{
sl@0
   509
	TWindowState state;
sl@0
   510
	state.iWinPlace = iWinPlace;
sl@0
   511
	state.iFlipstate = iScreenRotation;
sl@0
   512
	state.iXoffset = iViewport.GetViewportOffsetX();
sl@0
   513
	state.iYoffset = iViewport.GetViewportOffsetY();
sl@0
   514
	return state;
sl@0
   515
	}
sl@0
   516
	
sl@0
   517
TInt DScreenProperties::SetupProperties(TInt aConf, TInt aScreen)
sl@0
   518
	{
sl@0
   519
	char property[50];
sl@0
   520
sl@0
   521
	// Calculate maximum dimensions
sl@0
   522
	TInt configurations = Property::GetInt("ConfigCount", 0);
sl@0
   523
	if (configurations == 0)
sl@0
   524
		return KErrGeneral;
sl@0
   525
sl@0
   526
	TInt count, screenWidth, screenHeight, physicalScreenWidth, physicalScreenHeight;
sl@0
   527
	for (count = 0; count < configurations; ++count)
sl@0
   528
		{
sl@0
   529
		wsprintfA(property, "Configuration[%d][%d]ScreenWidth", count, aScreen);
sl@0
   530
		screenWidth = Property::GetInt(property, KScreenWidth);
sl@0
   531
		screenWidth = (screenWidth + 3) & ~3;
sl@0
   532
		if (screenWidth > iMaxScreenWidth)
sl@0
   533
			iMaxScreenWidth = screenWidth;
sl@0
   534
		wsprintfA(property, "Configuration[%d][%d]ScreenHeight", count, aScreen);
sl@0
   535
		screenHeight = Property::GetInt(property, KScreenHeight);
sl@0
   536
		screenHeight = (screenHeight + 3) & ~3;
sl@0
   537
		if (screenHeight > iMaxScreenHeight)
sl@0
   538
			iMaxScreenHeight = screenHeight;
sl@0
   539
//
sl@0
   540
		wsprintfA(property, "Configuration[%d][%d]PhysicalScreenWidth", count, aScreen);
sl@0
   541
		physicalScreenWidth = Property::GetInt(property);
sl@0
   542
		if (physicalScreenWidth > iMaxPhysicalScreenWidth)
sl@0
   543
			iMaxPhysicalScreenWidth = physicalScreenWidth;
sl@0
   544
		wsprintfA(property, "Configuration[%d][%d]PhysicalScreenHeight", count, aScreen);
sl@0
   545
		physicalScreenHeight = Property::GetInt(property);
sl@0
   546
		if (physicalScreenHeight > iMaxPhysicalScreenHeight)
sl@0
   547
			iMaxPhysicalScreenHeight = physicalScreenHeight;
sl@0
   548
		}
sl@0
   549
sl@0
   550
	// Read figures for current configuration
sl@0
   551
	TInt givenWidth, givenHeight;
sl@0
   552
	wsprintfA(property, "Configuration[%d][%d]ScreenWidth",aConf,aScreen);
sl@0
   553
	givenWidth = Property::GetInt(property, KScreenWidth);
sl@0
   554
	iScreenWidth = (givenWidth + 3) & ~3;
sl@0
   555
	wsprintfA(property, "Configuration[%d][%d]ScreenHeight",aConf,aScreen);
sl@0
   556
	givenHeight = Property::GetInt(property, KScreenHeight);
sl@0
   557
	iScreenHeight = (givenHeight + 3) & ~3;
sl@0
   558
	// Width of screen should be multiple number of 4 pixels.
sl@0
   559
	if (givenWidth & 3 || givenHeight & 3)
sl@0
   560
		{
sl@0
   561
		Kern::Printf("Width and Height of Screen should be multiple number of 4 pixels.\n"
sl@0
   562
				"\tWidth of screen[%d] set to: %d\n\tHeight of screen[%d] set to: %d", 
sl@0
   563
				aScreen, iScreenWidth, aScreen, iScreenHeight);
sl@0
   564
		}
sl@0
   565
sl@0
   566
//
sl@0
   567
	wsprintfA(property, "Configuration[%d][%d]PhysicalScreenWidth",aConf,aScreen);
sl@0
   568
	iPhysicalScreenWidth = Property::GetInt(property);
sl@0
   569
	wsprintfA(property, "Configuration[%d][%d]PhysicalScreenHeight",aConf,aScreen);
sl@0
   570
	iPhysicalScreenHeight = Property::GetInt(property);
sl@0
   571
//
sl@0
   572
	wsprintfA(property, "Configuration[%d][%d]ScreenOffsetX",aConf,aScreen);
sl@0
   573
	iScreenOffsetX = Property::GetInt(property, KScreenOffsetX);
sl@0
   574
	wsprintfA(property, "Configuration[%d][%d]ScreenOffsetY",aConf,aScreen);
sl@0
   575
	iScreenOffsetY = Property::GetInt(property, KScreenOffsetY);
sl@0
   576
	
sl@0
   577
	wsprintfA(property, "Configuration[%d][%d]CompositionBuffers",aConf,aScreen);
sl@0
   578
	iCompositionBuffers = Property::GetInt(property, KCompositionBuffers);
sl@0
   579
sl@0
   580
	wsprintfA(property, "Configuration[%d][%d]RefreshRateHz",aConf,aScreen);
sl@0
   581
	iRefreshRateHz = Property::GetInt(property, KRefreshRateHz);
sl@0
   582
sl@0
   583
sl@0
   584
	wsprintfA(property, "Configuration[%d][%d]ColorDepth",aConf,aScreen);
sl@0
   585
	const char* colors = Property::GetString(property);
sl@0
   586
	if (colors)
sl@0
   587
		{
sl@0
   588
		TUint colorDepth=0;
sl@0
   589
		const char* end = colors;
sl@0
   590
		for (;;)
sl@0
   591
			{
sl@0
   592
			const char* beg = skipws(end);
sl@0
   593
			if(*beg==';')
sl@0
   594
				break;
sl@0
   595
			if (!*beg)
sl@0
   596
				break;
sl@0
   597
			end	= skiptok(beg);
sl@0
   598
			if (_strnicmp("Gray2",beg,end-beg) == 0)
sl@0
   599
				{
sl@0
   600
				colorDepth|=KEmulGray2|KEmulIsBitMask;
sl@0
   601
				}
sl@0
   602
			else if (_strnicmp("Gray4",beg,end-beg) == 0)
sl@0
   603
				{
sl@0
   604
				colorDepth|=KEmulGray4|KEmulIsBitMask;
sl@0
   605
				}
sl@0
   606
			else if (_strnicmp("Gray16",beg,end-beg) == 0)
sl@0
   607
				{
sl@0
   608
				colorDepth|=KEmulGray16|KEmulIsBitMask;
sl@0
   609
				}
sl@0
   610
			else if (_strnicmp("Gray256",beg,end-beg) == 0)
sl@0
   611
				{
sl@0
   612
				colorDepth|=KEmulGray256|KEmulIsBitMask;
sl@0
   613
				}
sl@0
   614
			else if (_strnicmp("Color16",beg,end-beg) == 0)
sl@0
   615
				{
sl@0
   616
				colorDepth|=KEmulColor16|KEmulIsBitMask;
sl@0
   617
				}
sl@0
   618
			else if (_strnicmp("Color256",beg,end-beg) == 0)
sl@0
   619
				{
sl@0
   620
				colorDepth|=KEmulColor256|KEmulIsBitMask;
sl@0
   621
				}
sl@0
   622
			else if (_strnicmp("Color4K",beg,end-beg) == 0)
sl@0
   623
				{
sl@0
   624
				colorDepth|=KEmulColor4K|KEmulIsBitMask;
sl@0
   625
				}
sl@0
   626
			else if (_strnicmp("Color64K",beg,end-beg) == 0)
sl@0
   627
				{
sl@0
   628
				colorDepth|=KEmulColor64K|KEmulIsBitMask;
sl@0
   629
				}
sl@0
   630
			else if (_strnicmp("Color16M",beg,end-beg) == 0)
sl@0
   631
				{
sl@0
   632
				colorDepth|=KEmulColor16M|KEmulIsBitMask;
sl@0
   633
				}
sl@0
   634
			else
sl@0
   635
				return KErrArgument;
sl@0
   636
			}
sl@0
   637
		iColorDepth = colorDepth;
sl@0
   638
		
sl@0
   639
		}
sl@0
   640
	//multiple mode support is currently only for GCE. 
sl@0
   641
	//I fill this array in before knowing if GCE will be instanced.
sl@0
   642
	if (iColorDepth&KEmulIsBitMask)
sl@0
   643
		{
sl@0
   644
		//iModeDepths is only used by GCE
sl@0
   645
		TInt colorDepth=MaskGceOnly(iColorDepth);
sl@0
   646
		TInt setMode=0;
sl@0
   647
		for (TInt i=1;i!=KEmulIsBitMask;i+=i)
sl@0
   648
			if (colorDepth&i)
sl@0
   649
				iModeDepths[setMode++]=BitsForSingleMode(i);
sl@0
   650
		iMaxModes= setMode;	
sl@0
   651
		iModeDepths[setMode++]=0;	//a bit width of 0 is illegal	
sl@0
   652
		}
sl@0
   653
	else
sl@0
   654
		{
sl@0
   655
		iModeDepths[0]=iColorDepth;
sl@0
   656
		iMaxModes=1;
sl@0
   657
		iModeDepths[1]=0;	//a bit width of 0 is illegal
sl@0
   658
		}
sl@0
   659
sl@0
   660
	wsprintfA(property, "Configuration[%d][%d]FasciaBitmap",aConf,aScreen);
sl@0
   661
	const char* fascia = Property::GetString(property);
sl@0
   662
	if (fascia)
sl@0
   663
		{
sl@0
   664
		TInt len = strlen(fascia);
sl@0
   665
		//the path may have quotes at the start and end
sl@0
   666
		//need to work out if this is an absolute or relative path
sl@0
   667
		if (fascia[0] == '\"')
sl@0
   668
			{
sl@0
   669
			++fascia;
sl@0
   670
			--len;
sl@0
   671
			if (--len > 0 && fascia[len-1] == '\"')
sl@0
   672
				--len;
sl@0
   673
			}
sl@0
   674
		char* p = iFasciaFileName;
sl@0
   675
		if (fascia[0] != '\\' && (len < 3 || fascia[1] != ':'))
sl@0
   676
			{
sl@0
   677
			//relative path
sl@0
   678
			strcpy(p, Property::GetString("EmulatorDataPath"));
sl@0
   679
			p += strlen(p);
sl@0
   680
			}
sl@0
   681
		memcpy(p, fascia, len);
sl@0
   682
		p[len] = '\0';
sl@0
   683
		}
sl@0
   684
	else
sl@0
   685
		{
sl@0
   686
		// default to machine name
sl@0
   687
		strcpy(iFasciaFileName, Property::GetString("EmulatorDataPath"));
sl@0
   688
		strcat(iFasciaFileName, Property::GetString("MachineName"));
sl@0
   689
		strcat(iFasciaFileName, ".bmp");
sl@0
   690
		}
sl@0
   691
	return KErrNone;
sl@0
   692
	}
sl@0
   693
sl@0
   694
TViewport::TViewport() 
sl@0
   695
	:iScreenProps(NULL),iViewportWidth(0), iViewportHeight(0), iViewportOffsetX(0), iViewportOffsetY(0)
sl@0
   696
	{
sl@0
   697
	}
sl@0
   698
sl@0
   699
TViewport::TViewport(DScreenProperties* aScreenProps)
sl@0
   700
	:iScreenProps(aScreenProps),iViewportWidth(0), iViewportHeight(0), iViewportOffsetX(0), iViewportOffsetY(0)
sl@0
   701
	{	
sl@0
   702
	}	
sl@0
   703
TViewport::~TViewport()
sl@0
   704
	{
sl@0
   705
	}
sl@0
   706
	
sl@0
   707
sl@0
   708
/**
sl@0
   709
Changes the logical position of the viewport within the input area
sl@0
   710
of the emulator screen. The method may adjust the position so that
sl@0
   711
the viewport stays within the input area.
sl@0
   712
@param aPosition The new Y position of the top left hand corner of the viewport.
sl@0
   713
@param aHwnd The window associated with the viewport
sl@0
   714
*/
sl@0
   715
void TViewport::ScrollToY(TInt aPosition, HWND aHwnd)
sl@0
   716
	{
sl@0
   717
sl@0
   718
	SCROLLINFO scrollinfo;
sl@0
   719
	scrollinfo.cbSize=sizeof(scrollinfo);
sl@0
   720
sl@0
   721
	//save for later
sl@0
   722
	scrollinfo.fMask=SIF_POS;
sl@0
   723
	GetScrollInfo(aHwnd, SB_VERT, &scrollinfo);
sl@0
   724
	TInt oldY=scrollinfo.nPos;
sl@0
   725
sl@0
   726
	if(aPosition<0)
sl@0
   727
	{
sl@0
   728
		scrollinfo.nPos = 0;
sl@0
   729
	}
sl@0
   730
	else if( (aPosition+GetViewportHeight())>GetMaxHeight())
sl@0
   731
	{
sl@0
   732
		scrollinfo.nPos = max(0,GetMaxHeight() - GetViewportHeight() );
sl@0
   733
	}
sl@0
   734
	else
sl@0
   735
	{
sl@0
   736
		scrollinfo.nPos=aPosition;
sl@0
   737
	}
sl@0
   738
sl@0
   739
	SetViewportOffsetY(scrollinfo.nPos);
sl@0
   740
	scrollinfo.fMask=SIF_POS;
sl@0
   741
	SetScrollInfo(aHwnd,SB_VERT, &scrollinfo, TRUE );
sl@0
   742
	ScrollWindowEx(aHwnd, 0, oldY-scrollinfo.nPos, 0, 0, NULL, NULL, SW_INVALIDATE);
sl@0
   743
	
sl@0
   744
	UpdateChildPos(aHwnd);
sl@0
   745
	}
sl@0
   746
	
sl@0
   747
/**
sl@0
   748
As for ScrollToY but for the X direction
sl@0
   749
*/
sl@0
   750
void TViewport::ScrollToX(TInt aPosition, HWND aHwnd)
sl@0
   751
	{
sl@0
   752
	SCROLLINFO scrollinfo;
sl@0
   753
	scrollinfo.cbSize=sizeof(scrollinfo);
sl@0
   754
	
sl@0
   755
	//save for later
sl@0
   756
	scrollinfo.fMask=SIF_POS;
sl@0
   757
	GetScrollInfo(aHwnd, SB_HORZ, &scrollinfo);
sl@0
   758
	TInt oldX=scrollinfo.nPos;
sl@0
   759
sl@0
   760
	if(aPosition<0)
sl@0
   761
	{
sl@0
   762
		scrollinfo.nPos = 0;
sl@0
   763
	}
sl@0
   764
	else if( (aPosition+GetViewportWidth())>GetMaxWidth())
sl@0
   765
	{
sl@0
   766
		scrollinfo.nPos = max(0,GetMaxWidth() - GetViewportWidth() );
sl@0
   767
	}
sl@0
   768
	else
sl@0
   769
	{
sl@0
   770
		scrollinfo.nPos=aPosition;
sl@0
   771
	}
sl@0
   772
sl@0
   773
	SetViewportOffsetX(scrollinfo.nPos);
sl@0
   774
	scrollinfo.fMask=SIF_POS;
sl@0
   775
	SetScrollInfo(aHwnd,SB_HORZ, &scrollinfo, TRUE );
sl@0
   776
	ScrollWindowEx(aHwnd, oldX-scrollinfo.nPos, 0, 0, 0, NULL, NULL, SW_INVALIDATE);
sl@0
   777
sl@0
   778
	UpdateChildPos(aHwnd);
sl@0
   779
	}
sl@0
   780
	
sl@0
   781
//Forward declaration
sl@0
   782
LOCAL_C TInt ScreenFromHWND(HWND aHwnd,HWND* pWin);
sl@0
   783
sl@0
   784
/**
sl@0
   785
Move the child window to it's correct position.
sl@0
   786
sl@0
   787
@param aHwnd The HWND of the parent window
sl@0
   788
*/
sl@0
   789
void TViewport::UpdateChildPos(HWND aHwnd)
sl@0
   790
	{
sl@0
   791
	TInt screenNumber = ::ScreenFromHWND(aHwnd,TheWin);
sl@0
   792
	HWND childWin = TheChildWin[screenNumber];
sl@0
   793
sl@0
   794
	switch (iScreenProps->iScreenRotation)
sl@0
   795
		{
sl@0
   796
		case EEmulatorFlipRestore:
sl@0
   797
			MoveWindow(
sl@0
   798
				childWin,
sl@0
   799
				iScreenProps->iScreenOffsetX - GetViewportOffsetX(),
sl@0
   800
				iScreenProps->iScreenOffsetY - GetViewportOffsetY(),
sl@0
   801
				iScreenProps->iScreenWidth,
sl@0
   802
				iScreenProps->iScreenHeight,
sl@0
   803
				TRUE
sl@0
   804
				);
sl@0
   805
			break;
sl@0
   806
		case EEmulatorFlipInvert:
sl@0
   807
			MoveWindow(
sl@0
   808
				childWin,
sl@0
   809
				iScreenProps->iXYInputWidth-(iScreenProps->iScreenOffsetX+iScreenProps->iScreenWidth) - GetViewportOffsetX(),
sl@0
   810
				iScreenProps->iXYInputHeight-(iScreenProps->iScreenOffsetY+iScreenProps->iScreenHeight) - GetViewportOffsetY(),
sl@0
   811
				iScreenProps->iScreenWidth,
sl@0
   812
				iScreenProps->iScreenHeight,
sl@0
   813
				TRUE
sl@0
   814
				);
sl@0
   815
			break;
sl@0
   816
		case EEmulatorFlipLeft:
sl@0
   817
			MoveWindow(
sl@0
   818
				childWin,
sl@0
   819
				iScreenProps->iScreenOffsetY - GetViewportOffsetX(),
sl@0
   820
				iScreenProps->iXYInputWidth-(iScreenProps->iScreenOffsetX+iScreenProps->iScreenWidth)- GetViewportOffsetY(),
sl@0
   821
				iScreenProps->iScreenHeight,
sl@0
   822
				iScreenProps->iScreenWidth,
sl@0
   823
				TRUE
sl@0
   824
				);
sl@0
   825
			break;
sl@0
   826
		case EEmulatorFlipRight:
sl@0
   827
			MoveWindow(
sl@0
   828
				childWin,
sl@0
   829
				iScreenProps->iXYInputHeight-(iScreenProps->iScreenOffsetY+iScreenProps->iScreenHeight) - GetViewportOffsetX(),
sl@0
   830
				iScreenProps->iScreenOffsetX - GetViewportOffsetY(),
sl@0
   831
				iScreenProps->iScreenHeight,
sl@0
   832
				iScreenProps->iScreenWidth,
sl@0
   833
				TRUE
sl@0
   834
				);
sl@0
   835
			break;
sl@0
   836
		}
sl@0
   837
sl@0
   838
	}
sl@0
   839
	
sl@0
   840
/**
sl@0
   841
Update the range of the horizontal scrollbar,
sl@0
   842
to take account of the current viewport width.
sl@0
   843
sl@0
   844
@param aHwnd The window to be updated
sl@0
   845
*/
sl@0
   846
void TViewport::UpdateScrollBarH(HWND aHwnd)
sl@0
   847
	{
sl@0
   848
sl@0
   849
	SCROLLINFO scrollinfoHor;
sl@0
   850
	scrollinfoHor.cbSize=sizeof(scrollinfoHor);
sl@0
   851
	scrollinfoHor.fMask=SIF_RANGE|SIF_PAGE;
sl@0
   852
	scrollinfoHor.nMin=0;
sl@0
   853
	scrollinfoHor.nMax= GetMaxWidth()-1;
sl@0
   854
	
sl@0
   855
	
sl@0
   856
	TInt newPage = GetViewportWidth() ;
sl@0
   857
	TBool redraw=EFalse; //redraw window if a resize has caused a scrollbar to disappear and reveal image.
sl@0
   858
	if ( newPage>= scrollinfoHor.nMax -GetSystemMetrics(SM_CXVSCROLL)
sl@0
   859
		&& newPage < scrollinfoHor.nMax+1)
sl@0
   860
		{
sl@0
   861
		redraw=ETrue;
sl@0
   862
		newPage=GetMaxWidth();
sl@0
   863
sl@0
   864
		}
sl@0
   865
	scrollinfoHor.nPage= newPage;
sl@0
   866
sl@0
   867
	SetScrollInfo(aHwnd,SB_HORZ, &scrollinfoHor, TRUE );
sl@0
   868
	if(redraw)
sl@0
   869
		{
sl@0
   870
		ScrollToX(0, aHwnd); //in case egde of fascia was against edge of vertical scrollbar
sl@0
   871
		InvalidateRect(aHwnd, NULL, TRUE);
sl@0
   872
		}
sl@0
   873
	}
sl@0
   874
	
sl@0
   875
/**
sl@0
   876
Update the range of the vertical scrollbar,
sl@0
   877
to take account of the current viewport width.
sl@0
   878
sl@0
   879
@param aHwnd The window to be updated
sl@0
   880
*/	
sl@0
   881
void TViewport::UpdateScrollBarV(HWND aHwnd)
sl@0
   882
	{
sl@0
   883
	SCROLLINFO scrollinfoVer;
sl@0
   884
	scrollinfoVer.cbSize=sizeof(scrollinfoVer);
sl@0
   885
	scrollinfoVer.fMask=SIF_RANGE|SIF_PAGE;
sl@0
   886
	scrollinfoVer.nMin=0;
sl@0
   887
	scrollinfoVer.nMax= GetMaxHeight()-1;
sl@0
   888
	
sl@0
   889
	TInt newPage = GetViewportHeight() ;
sl@0
   890
	TBool redraw=EFalse; //redraw window if a resize has caused a scrollbar to disappear and reveal image.
sl@0
   891
	if ( newPage>= scrollinfoVer.nMax -GetSystemMetrics(SM_CYHSCROLL)
sl@0
   892
		&& newPage < scrollinfoVer.nMax+1)
sl@0
   893
		{
sl@0
   894
		redraw=ETrue;
sl@0
   895
		newPage=GetMaxHeight();
sl@0
   896
		}
sl@0
   897
	scrollinfoVer.nPage= newPage;
sl@0
   898
sl@0
   899
	SetScrollInfo(aHwnd,SB_VERT, &scrollinfoVer, TRUE );
sl@0
   900
	if(redraw)
sl@0
   901
		{
sl@0
   902
		ScrollToY(0, aHwnd); //in case egde of fascia was against edge of vertical scrollbar
sl@0
   903
		InvalidateRect(aHwnd, NULL, TRUE);
sl@0
   904
		}
sl@0
   905
	}
sl@0
   906
sl@0
   907
/**
sl@0
   908
Returns the max width for the viewport window (non-client area) so that it
sl@0
   909
may be bounded. Takes account of scrollbar.
sl@0
   910
sl@0
   911
@return Max width
sl@0
   912
*/	
sl@0
   913
TInt TViewport::GetMaxWindowWidth() const
sl@0
   914
	{
sl@0
   915
	
sl@0
   916
	RECT rect = {0,0,0,0};
sl@0
   917
	
sl@0
   918
	switch(iScreenProps->iScreenRotation)
sl@0
   919
		{
sl@0
   920
		case EEmulatorFlipRestore:
sl@0
   921
		case EEmulatorFlipInvert:
sl@0
   922
			{
sl@0
   923
			rect.right=iScreenProps->iXYInputWidth;
sl@0
   924
			rect.bottom=iScreenProps->iXYInputHeight;
sl@0
   925
			break;
sl@0
   926
			}
sl@0
   927
		case EEmulatorFlipLeft:
sl@0
   928
		case EEmulatorFlipRight:
sl@0
   929
			{
sl@0
   930
			rect.right=iScreenProps->iXYInputHeight;
sl@0
   931
			rect.bottom=iScreenProps->iXYInputWidth;
sl@0
   932
			break;
sl@0
   933
			}
sl@0
   934
		}
sl@0
   935
	AdjustWindowRect(//take account of window decorations
sl@0
   936
		&rect,
sl@0
   937
		KWinStyle,
sl@0
   938
		FALSE
sl@0
   939
		);
sl@0
   940
	
sl@0
   941
	
sl@0
   942
	return (rect.right-rect.left);
sl@0
   943
	}
sl@0
   944
	
sl@0
   945
/**
sl@0
   946
Returns the max height for the viewport window (non-client area) so that it
sl@0
   947
may be bounded. Takes account of scrollbar.
sl@0
   948
sl@0
   949
@return Max height
sl@0
   950
*/
sl@0
   951
TInt TViewport::GetMaxWindowHeight() const
sl@0
   952
	{
sl@0
   953
	
sl@0
   954
	RECT rect ={0,0,0,0};
sl@0
   955
sl@0
   956
	switch(iScreenProps->iScreenRotation)
sl@0
   957
		{
sl@0
   958
		case EEmulatorFlipRestore:
sl@0
   959
		case EEmulatorFlipInvert:
sl@0
   960
			{
sl@0
   961
			rect.right=iScreenProps->iXYInputWidth;
sl@0
   962
			rect.bottom=iScreenProps->iXYInputHeight;
sl@0
   963
			break;
sl@0
   964
			}
sl@0
   965
		case EEmulatorFlipLeft:
sl@0
   966
		case EEmulatorFlipRight:
sl@0
   967
			{
sl@0
   968
			rect.right=iScreenProps->iXYInputHeight;
sl@0
   969
			rect.bottom=iScreenProps->iXYInputWidth;
sl@0
   970
			break;
sl@0
   971
			}
sl@0
   972
		}
sl@0
   973
	AdjustWindowRect(//take account of window decorations
sl@0
   974
		&rect,
sl@0
   975
		KWinStyle,
sl@0
   976
		FALSE
sl@0
   977
		);
sl@0
   978
	return (rect.bottom-rect.top);
sl@0
   979
	}
sl@0
   980
sl@0
   981
/**
sl@0
   982
Returns the maximum width for the viewport (client area only).
sl@0
   983
Allowing for the orientation of the emulator.
sl@0
   984
sl@0
   985
@return Max width
sl@0
   986
*/
sl@0
   987
TInt TViewport::GetMaxWidth() const
sl@0
   988
	{
sl@0
   989
	TInt width=0;
sl@0
   990
	switch(iScreenProps->iScreenRotation)
sl@0
   991
		{
sl@0
   992
		case EEmulatorFlipRestore:
sl@0
   993
		case EEmulatorFlipInvert:
sl@0
   994
			{
sl@0
   995
			width = iScreenProps->iXYInputWidth;
sl@0
   996
			break;
sl@0
   997
			}
sl@0
   998
		case EEmulatorFlipLeft:
sl@0
   999
		case EEmulatorFlipRight:
sl@0
  1000
			{
sl@0
  1001
			width = iScreenProps->iXYInputHeight;
sl@0
  1002
			break;
sl@0
  1003
			}
sl@0
  1004
		}
sl@0
  1005
	
sl@0
  1006
	return width;
sl@0
  1007
	}
sl@0
  1008
sl@0
  1009
/**
sl@0
  1010
Returns the maximum height for the viewport (client area only).
sl@0
  1011
Allowing for the orientation of the emulator.
sl@0
  1012
sl@0
  1013
@return Max height
sl@0
  1014
*/
sl@0
  1015
TInt TViewport::GetMaxHeight() const
sl@0
  1016
	{
sl@0
  1017
	TInt height=0;
sl@0
  1018
	switch(iScreenProps->iScreenRotation)
sl@0
  1019
		{
sl@0
  1020
		case EEmulatorFlipRestore:
sl@0
  1021
		case EEmulatorFlipInvert:
sl@0
  1022
			{
sl@0
  1023
			height = iScreenProps->iXYInputHeight;
sl@0
  1024
			break;
sl@0
  1025
			}
sl@0
  1026
		case EEmulatorFlipLeft:
sl@0
  1027
		case EEmulatorFlipRight:
sl@0
  1028
			{
sl@0
  1029
			height =  iScreenProps->iXYInputWidth;
sl@0
  1030
			break;
sl@0
  1031
			}
sl@0
  1032
		}
sl@0
  1033
	
sl@0
  1034
	return height;
sl@0
  1035
	
sl@0
  1036
	}
sl@0
  1037
sl@0
  1038
/**
sl@0
  1039
Sets the X offset of the viewport from the edge of the input area
sl@0
  1040
@param aOffset The X offset
sl@0
  1041
*/
sl@0
  1042
void TViewport::SetViewportOffsetX(TInt aOffset)
sl@0
  1043
	{
sl@0
  1044
	iViewportOffsetX = aOffset;
sl@0
  1045
	}
sl@0
  1046
sl@0
  1047
/**
sl@0
  1048
Sets the Y offset of the viewport from the edge of the input area
sl@0
  1049
@param aOffset The Y offset
sl@0
  1050
*/
sl@0
  1051
void TViewport::SetViewportOffsetY(TInt aOffset)
sl@0
  1052
	{
sl@0
  1053
	iViewportOffsetY = aOffset;
sl@0
  1054
	}
sl@0
  1055
sl@0
  1056
TInt TViewport::GetViewportOffsetX() const
sl@0
  1057
	{
sl@0
  1058
	return iViewportOffsetX;	
sl@0
  1059
	}
sl@0
  1060
TInt TViewport::GetViewportOffsetY() const
sl@0
  1061
	{
sl@0
  1062
	return iViewportOffsetY;
sl@0
  1063
	}
sl@0
  1064
	
sl@0
  1065
/**
sl@0
  1066
Sets the viewport width, this is equal to the width
sl@0
  1067
of the window's client area
sl@0
  1068
@param aWidth The width
sl@0
  1069
*/
sl@0
  1070
void TViewport::SetViewportWidth(TInt aWidth)
sl@0
  1071
	{
sl@0
  1072
	iViewportWidth=aWidth;
sl@0
  1073
	}
sl@0
  1074
sl@0
  1075
/**
sl@0
  1076
Sets the viewport height, this is equal to the height
sl@0
  1077
of the window's client area
sl@0
  1078
@param aHeight The height
sl@0
  1079
*/
sl@0
  1080
void TViewport::SetViewportHeight(TInt aHeight)
sl@0
  1081
	{
sl@0
  1082
	iViewportHeight=aHeight;
sl@0
  1083
	}
sl@0
  1084
sl@0
  1085
TInt TViewport::GetViewportWidth() const
sl@0
  1086
	{
sl@0
  1087
	return iViewportWidth;
sl@0
  1088
	}
sl@0
  1089
TInt TViewport::GetViewportHeight() const
sl@0
  1090
	{
sl@0
  1091
	return iViewportHeight;
sl@0
  1092
	}
sl@0
  1093
sl@0
  1094
// the UI class
sl@0
  1095
sl@0
  1096
DWinsUi::DWinsUi()
sl@0
  1097
	:iVirtualKeys(10),
sl@0
  1098
	iControlHotKeys(10)
sl@0
  1099
	{}
sl@0
  1100
sl@0
  1101
/// Returns the current mode's depth. Remember current mode is never set!
sl@0
  1102
TUint DWinsUi::ColorDepth(TInt aScreenNumber)
sl@0
  1103
	{
sl@0
  1104
	TVideoInfoV01 info;
sl@0
  1105
	VideoInfo(aScreenNumber, info);
sl@0
  1106
	return info.iBitsPerPixel;
sl@0
  1107
	}
sl@0
  1108
sl@0
  1109
TInt DWinsUi::SetFlip(TEmulatorFlip aFlip, TInt aScreenNumber)
sl@0
  1110
	{
sl@0
  1111
	if(TUint(aScreenNumber)>=TUint(systemIni->iScreens.Count()))
sl@0
  1112
		return KErrArgument;
sl@0
  1113
	int r1 = PostMessageA(TheChildWin[aScreenNumber],WM_FLIP_MESSAGE,(TUint)aFlip,NULL);
sl@0
  1114
	return r1 ? KErrNone : KErrGeneral;
sl@0
  1115
	}
sl@0
  1116
sl@0
  1117
void DWinsUi::Info(TVariantInfoV01& aInfo)
sl@0
  1118
	{
sl@0
  1119
	aInfo.iLedCapabilities=0x3;
sl@0
  1120
	}
sl@0
  1121
sl@0
  1122
HWND DWinsUi::HWnd()
sl@0
  1123
	{
sl@0
  1124
	return TheControlWin;
sl@0
  1125
	}
sl@0
  1126
sl@0
  1127
TInt DWinsUi::SetupProperties(TInt aId)
sl@0
  1128
	
sl@0
  1129
//
sl@0
  1130
// load UI settings from the emulator properties
sl@0
  1131
//
sl@0
  1132
	{
sl@0
  1133
	//setup the screens
sl@0
  1134
	TInt screens = Property::GetInt("[screens]", 1);
sl@0
  1135
 
sl@0
  1136
 	for (TInt x = 0; x < screens; ++x)
sl@0
  1137
 		{
sl@0
  1138
 		DScreenProperties * pScr = new DScreenProperties();
sl@0
  1139
 		if (!pScr)
sl@0
  1140
 			return KErrNoMemory;
sl@0
  1141
 		
sl@0
  1142
 		TInt ret = pScr->SetupProperties(aId,x);
sl@0
  1143
 		if (KErrNone == ret)
sl@0
  1144
 			ret = iScreens.Append(pScr);
sl@0
  1145
 
sl@0
  1146
 		if (KErrNone != ret)
sl@0
  1147
 			{
sl@0
  1148
 			delete pScr;
sl@0
  1149
 			return ret;
sl@0
  1150
 			}
sl@0
  1151
 		}
sl@0
  1152
//
sl@0
  1153
	char property[50];
sl@0
  1154
	wsprintfA(property, "Configuration[%d]LedSize",aId);
sl@0
  1155
	iLedSize = Property::GetInt(property, KLedSize);
sl@0
  1156
	wsprintfA(property, "Configuration[%d]LedArrangeVertically",aId);
sl@0
  1157
	iLedVertical = Property::GetBool(property, KLedVertical);
sl@0
  1158
	wsprintfA(property, "Configuration[%d]LedArrangeHorizontally",aId);
sl@0
  1159
	if (Property::GetBool(property))
sl@0
  1160
		iLedVertical = EFalse;
sl@0
  1161
	wsprintfA(property, "Configuration[%d]LedOffsetX",aId);
sl@0
  1162
	iLedOffsetX = Property::GetInt(property, KLedLeft);
sl@0
  1163
	wsprintfA(property, "Configuration[%d]LedOffsetY",aId);
sl@0
  1164
	iLedOffsetY = Property::GetInt(property, KLedTop);
sl@0
  1165
	wsprintfA(property, "Configuration[%d]LedGap",aId);
sl@0
  1166
	iLedGap = Property::GetInt(property, KLedGap);
sl@0
  1167
//
sl@0
  1168
	wsprintfA(property, "Configuration[%d]PointerType",aId);
sl@0
  1169
	const char* pointer = Property::GetString(property, "Pen");
sl@0
  1170
	if (_stricmp(pointer, "None") == 0)
sl@0
  1171
		{
sl@0
  1172
		iPointerType=_S8("NONE");
sl@0
  1173
		iXYInputType=EXYInputNone;
sl@0
  1174
		}
sl@0
  1175
	else if (_stricmp(pointer,"Pen") == 0)
sl@0
  1176
		{
sl@0
  1177
		iPointerType=_S8("PEN");
sl@0
  1178
		iXYInputType=EXYInputPointer;
sl@0
  1179
		}
sl@0
  1180
	else if (_stricmp(pointer,"Mouse") == 0)
sl@0
  1181
		{
sl@0
  1182
		iPointerType=_S8("MOUSE");
sl@0
  1183
		iXYInputType=EXYInputMouse;
sl@0
  1184
		}
sl@0
  1185
	else if (_stricmp(pointer,"Delta-Mouse") == 0)
sl@0
  1186
		{
sl@0
  1187
		iPointerType=_S8("MOUSE");
sl@0
  1188
		iXYInputType=EXYInputDeltaMouse;
sl@0
  1189
		}
sl@0
  1190
	else
sl@0
  1191
		return KErrArgument;
sl@0
  1192
//
sl@0
  1193
	wsprintfA(property, "Configuration[%d]DigitizerOffsetX",aId);
sl@0
  1194
	iDigitizerOffsetX = Property::GetInt(property, -iScreens[0]->iScreenOffsetX);
sl@0
  1195
	wsprintfA(property, "Configuration[%d]DigitizerOffsetY",aId);
sl@0
  1196
	iDigitizerOffsetY = Property::GetInt(property, -iScreens[0]->iScreenOffsetY);
sl@0
  1197
	wsprintfA(property, "Configuration[%d]DigitizerWidth",aId);
sl@0
  1198
	iDigitizerWidth = Property::GetInt(property,-1);
sl@0
  1199
	wsprintfA(property, "Configuration[%d]DigitizerHeight",aId);
sl@0
  1200
	iDigitizerHeight = Property::GetInt(property,-1);
sl@0
  1201
	wsprintfA(property, "Configuration[%d]DisableDigitizer",aId);
sl@0
  1202
	iDigitizerEnabled = !Property::GetBool(property);
sl@0
  1203
//	To enable the multitouch 
sl@0
  1204
	wsprintfA(property, "EnableMultiTouch");
sl@0
  1205
	iMultiTouchEnabled = Property::GetBool(property,EFalse);
sl@0
  1206
	wsprintfA(property, "SYMBIAN_BASE_USE_GCE");
sl@0
  1207
	iGCEEnabled = Property::GetBool(property,EFalse);
sl@0
  1208
	wsprintfA(property, "MultiTouchProximityStep");
sl@0
  1209
	iMultiTouchProximityStep = Property::GetInt(property,-1);
sl@0
  1210
	wsprintfA(property, "MultiTouchPressureStep");
sl@0
  1211
	iMultiTouchPressureStep = Property::GetInt(property,-1);
sl@0
  1212
//
sl@0
  1213
	strcpy(iSysIniFileName, Property::GetString("EmulatorDataPath"));
sl@0
  1214
	strcat(iSysIniFileName, "emulator\\");
sl@0
  1215
	if (!Emulator::CreateAllDirectories(iSysIniFileName))
sl@0
  1216
		return Emulator::LastError();
sl@0
  1217
	strcat(iSysIniFileName, Property::GetString("MachineName"));
sl@0
  1218
	strcat(iSysIniFileName, ".sys.ini");
sl@0
  1219
//
sl@0
  1220
	TInt r = iKeyboard.Init(aId);
sl@0
  1221
	if (r != KErrNone)
sl@0
  1222
		return r;
sl@0
  1223
sl@0
  1224
	wsprintfA(property, "Configuration[%d]VirtualKey",aId);
sl@0
  1225
	r = MultiProperty(&DWinsUi::DoDefineVirtualKey, this, property);
sl@0
  1226
	if (r != KErrNone)
sl@0
  1227
		return r;
sl@0
  1228
//
sl@0
  1229
sl@0
  1230
	wsprintfA(property, "Configuration[%d]NoVersionInfo",aId);
sl@0
  1231
	iDisplayVersionInfo = !Property::GetBool(property);
sl@0
  1232
	
sl@0
  1233
	wsprintfA(property, "Configuration[%d]WindowTitle",aId);
sl@0
  1234
	const char * p = Property::GetString(property);
sl@0
  1235
	if (p && (strlen(p) <= KMaxNameSize))
sl@0
  1236
		strcpy(iWindowTitle, p);
sl@0
  1237
	else
sl@0
  1238
		strcpy(iWindowTitle, DefaultWindowTitle);
sl@0
  1239
sl@0
  1240
	if (iDisplayVersionInfo)
sl@0
  1241
		{
sl@0
  1242
		TInt wtLen = strlen(iWindowTitle);
sl@0
  1243
		TInt vtLen = strlen(VersionText);
sl@0
  1244
		if ((wtLen + vtLen) > KMaxNameSize)
sl@0
  1245
			iWindowTitle[KMaxNameSize-vtLen] = '\0';
sl@0
  1246
		strcat(iWindowTitle, VersionText);
sl@0
  1247
		}
sl@0
  1248
sl@0
  1249
	wsprintfA(property, "Configuration[%d]OnActivation",aId);
sl@0
  1250
	pointer = Property::GetString(property);	
sl@0
  1251
	//example	OnActivation 270 EKeyScreenDimension1
sl@0
  1252
	//params are rotation(int) and key(string)
sl@0
  1253
	if (pointer)
sl@0
  1254
		{
sl@0
  1255
		char * next;
sl@0
  1256
	
sl@0
  1257
		//skip any white space
sl@0
  1258
		const char* beg = skipws(pointer);
sl@0
  1259
		
sl@0
  1260
		//get the number
sl@0
  1261
		long rotation = strtol(beg, &next, 0);
sl@0
  1262
		if (next == beg)
sl@0
  1263
			return KErrArgument;
sl@0
  1264
sl@0
  1265
		switch (rotation)
sl@0
  1266
			{
sl@0
  1267
			case 0:
sl@0
  1268
				iScreens[0]->iScreenRotation = EEmulatorFlipRestore;
sl@0
  1269
				break;
sl@0
  1270
			case 90:
sl@0
  1271
				iScreens[0]->iScreenRotation = EEmulatorFlipRight;
sl@0
  1272
				break;
sl@0
  1273
			case 180:
sl@0
  1274
				iScreens[0]->iScreenRotation = EEmulatorFlipInvert;
sl@0
  1275
				break;
sl@0
  1276
			case 270:
sl@0
  1277
				iScreens[0]->iScreenRotation = EEmulatorFlipLeft;
sl@0
  1278
				break;
sl@0
  1279
			default:
sl@0
  1280
				r = KErrArgument;
sl@0
  1281
			}
sl@0
  1282
		if (r != KErrNone)
sl@0
  1283
			return r;
sl@0
  1284
		
sl@0
  1285
		beg = skipws(next);
sl@0
  1286
		
sl@0
  1287
		//beg should now point to the keycode
sl@0
  1288
		TInt key = iKeyboard.GetEPOCKeyCode(TPtrC8((const TUint8*)beg, strlen(beg)));
sl@0
  1289
		if (key == KErrNotFound)
sl@0
  1290
			return key;
sl@0
  1291
		iInitialFlipMsg = key;
sl@0
  1292
		}
sl@0
  1293
sl@0
  1294
	//EmulatorControl messages are a bit like virtual keys
sl@0
  1295
	wsprintfA(property, "Configuration[%d]EmulatorControl",aId);
sl@0
  1296
	r = MultiProperty(&DWinsUi::DoDefineEmulatorControl, this, property);
sl@0
  1297
	if (r != KErrNone)
sl@0
  1298
		return r;
sl@0
  1299
sl@0
  1300
	wsprintfA(property, "Configuration[%d]EmulatorControlHotKey",aId);
sl@0
  1301
	r = MultiProperty(&DWinsUi::DoDefineEmulatorControlHotKey, this, property);
sl@0
  1302
	if (r != KErrNone)
sl@0
  1303
		return r;
sl@0
  1304
	
sl@0
  1305
	return KErrNone;
sl@0
  1306
	}
sl@0
  1307
sl@0
  1308
TInt DWinsUi::NumberOfScreens()
sl@0
  1309
	{
sl@0
  1310
	return iScreens.Count();
sl@0
  1311
	}
sl@0
  1312
sl@0
  1313
/**
sl@0
  1314
Return the highest bit depth from an emulator mode mask.
sl@0
  1315
@param aModeMask	A bitwise combination of KEmul... display mode mask values.
sl@0
  1316
@return A color depth in bits per pixel.
sl@0
  1317
*/
sl@0
  1318
LOCAL_C TInt MaximumBitDepthFromMask(TInt aModeMask)
sl@0
  1319
	{
sl@0
  1320
	// Choose the highest bits per pixel based on the display mode mask.
sl@0
  1321
	if (aModeMask & KEmulColor16M)
sl@0
  1322
		{
sl@0
  1323
		return 24;
sl@0
  1324
		}
sl@0
  1325
	if (aModeMask & KEmulColor64K)
sl@0
  1326
		{
sl@0
  1327
		return 16;
sl@0
  1328
		}
sl@0
  1329
	if (aModeMask & KEmulColor4K)
sl@0
  1330
		{
sl@0
  1331
		return 12;
sl@0
  1332
		}
sl@0
  1333
sl@0
  1334
	// Lower bit depths are not supported, so use the default
sl@0
  1335
	return 24;
sl@0
  1336
	}
sl@0
  1337
sl@0
  1338
sl@0
  1339
/**
sl@0
  1340
Return the TDisplayRotation corresponding to the given TEmulatorFlip.
sl@0
  1341
@param aFlip	A screen rotation as a TEmulatorFlip.
sl@0
  1342
@return The screen rotation as a TDisplayRotation.
sl@0
  1343
*/
sl@0
  1344
LOCAL_C RDisplayChannel::TDisplayRotation FlipToDisplayRotation(TEmulatorFlip aFlip)
sl@0
  1345
	{
sl@0
  1346
	switch (aFlip)
sl@0
  1347
		{
sl@0
  1348
		case EEmulatorFlipLeft:
sl@0
  1349
			return RDisplayChannel::ERotation90CW;
sl@0
  1350
		case EEmulatorFlipInvert:
sl@0
  1351
			return RDisplayChannel::ERotation180;
sl@0
  1352
		case EEmulatorFlipRight:
sl@0
  1353
			return RDisplayChannel::ERotation270CW;
sl@0
  1354
		}
sl@0
  1355
	return RDisplayChannel::ERotationNormal;
sl@0
  1356
	}
sl@0
  1357
sl@0
  1358
sl@0
  1359
TInt DWinsUi::SetDisplayChannel(TInt aScreenNumber, DDisplayChannel* aDisplay)
sl@0
  1360
	{
sl@0
  1361
	return systemIni->SetDisplayChannelImpl(aScreenNumber,aDisplay);
sl@0
  1362
	}
sl@0
  1363
sl@0
  1364
sl@0
  1365
TInt DWinsUi::SetDisplayChannelImpl(TInt aScreenNumber, DDisplayChannel* aDisplay)
sl@0
  1366
	{
sl@0
  1367
	if (TUint(aScreenNumber) >= TUint(NumberOfScreens()))
sl@0
  1368
		{
sl@0
  1369
		// Screen number is either negative or too big.
sl@0
  1370
		return KErrArgument;
sl@0
  1371
		}
sl@0
  1372
sl@0
  1373
	TInt r = KErrNone;
sl@0
  1374
	HWND hWnd = TheChildWin[aScreenNumber];
sl@0
  1375
	TBufferSet& buffer = masterIni->iBufferSet[aScreenNumber];
sl@0
  1376
	
sl@0
  1377
	if (aDisplay)
sl@0
  1378
		{
sl@0
  1379
		// Display driver connecting
sl@0
  1380
		DScreenProperties* screen = iScreens[aScreenNumber];
sl@0
  1381
		RDisplayChannel::TDisplayInfo info;
sl@0
  1382
sl@0
  1383
		TInt pixelBytes = 2;
sl@0
  1384
		info.iBitsPerPixel = MaximumBitDepthFromMask(screen->iColorDepth);
sl@0
  1385
sl@0
  1386
		switch (info.iBitsPerPixel)
sl@0
  1387
			{
sl@0
  1388
			case 12:	// XRGB4444
sl@0
  1389
				info.iPixelFormat = EUidPixelFormatXRGB_4444;
sl@0
  1390
				break;
sl@0
  1391
			case 16:	// RGB565
sl@0
  1392
				info.iPixelFormat = EUidPixelFormatRGB_565;
sl@0
  1393
				break;
sl@0
  1394
			default:
sl@0
  1395
				// Force anything else to packed RGB888
sl@0
  1396
				pixelBytes = 4;
sl@0
  1397
				info.iBitsPerPixel = 24;
sl@0
  1398
				info.iPixelFormat = EUidPixelFormatXRGB_8888;
sl@0
  1399
				break;
sl@0
  1400
			}
sl@0
  1401
sl@0
  1402
		TInt width = screen->iMaxScreenWidth;
sl@0
  1403
		TInt height = screen->iMaxScreenHeight;
sl@0
  1404
sl@0
  1405
		info.iRefreshRateHz = screen->iRefreshRateHz;
sl@0
  1406
		info.iAvailableRotations = RDisplayChannel::ERotationNormal | RDisplayChannel::ERotation90CW |
sl@0
  1407
									RDisplayChannel::ERotation180 | RDisplayChannel::ERotation270CW;
sl@0
  1408
		info.iNormal.iWidth = width;
sl@0
  1409
		info.iNormal.iHeight = height;
sl@0
  1410
		// Windows requires rounding up to 4-bytes words
sl@0
  1411
		info.iNormal.iOffsetBetweenLines = _ALIGN_UP(width * pixelBytes, 4);
sl@0
  1412
		info.iFlipped.iWidth = height;
sl@0
  1413
		info.iFlipped.iHeight = width;
sl@0
  1414
		// Windows requires rounding up to 4-bytes words
sl@0
  1415
		info.iFlipped.iOffsetBetweenLines = _ALIGN_UP(height * pixelBytes, 4);
sl@0
  1416
	
sl@0
  1417
		TInt maxSize=0;	 
sl@0
  1418
		//ensure legacy buffer is large enough for all supported modes.
sl@0
  1419
		//It would be a very strange setup for the max size to not be the max bpp,
sl@0
  1420
		//but we don't know which mode is max bpp anyway!
sl@0
  1421
		TVideoInfoV01 videoInfo;
sl@0
  1422
		for (TInt mode=0,maxMode=screen->iMaxModes;mode<maxMode;mode++)
sl@0
  1423
			{
sl@0
  1424
			if (systemIni->VideoInfoForDisplayDriver(aScreenNumber,mode, videoInfo))	//can't actually fail currently
sl@0
  1425
				{
sl@0
  1426
				TInt dwSize=videoInfo.iOffsetToFirstPixel+videoInfo.iOffsetBetweenLines*videoInfo.iSizeInPixels.iHeight;
sl@0
  1427
				if (dwSize>maxSize)
sl@0
  1428
					maxSize=dwSize;
sl@0
  1429
				}
sl@0
  1430
			else
sl@0
  1431
				{
sl@0
  1432
				Fault(EGuiVideoInfoUnavailable);
sl@0
  1433
				}
sl@0
  1434
			//rotated mode may use more RAM?? Height may be >Width or may not be a multiple of stride quantum
sl@0
  1435
			if (systemIni->VideoInfoForDisplayDriver(aScreenNumber,mode|KModeFlagFlipped, videoInfo))	//can't actually fail currently
sl@0
  1436
				{
sl@0
  1437
				TInt dwSize=videoInfo.iOffsetToFirstPixel+videoInfo.iOffsetBetweenLines*videoInfo.iSizeInPixels.iWidth;
sl@0
  1438
				if (dwSize>maxSize)
sl@0
  1439
					{
sl@0
  1440
					maxSize=dwSize;
sl@0
  1441
					}
sl@0
  1442
				}
sl@0
  1443
			else
sl@0
  1444
				{
sl@0
  1445
				Fault(EGuiVideoInfoUnavailable);
sl@0
  1446
				}
sl@0
  1447
			}
sl@0
  1448
sl@0
  1449
		masterIni->iMaxSizeInBytes = maxSize;
sl@0
  1450
		if (__e32_atomic_add_ord32(&buffer.iDisplayDriverCount, 1) == 0)
sl@0
  1451
			{
sl@0
  1452
			// First driver to connect, allocate frame buffers.
sl@0
  1453
			// +1 frame buffer is ui legacy buffer at [0], so does need to take account of stride and offset
sl@0
  1454
			r = masterIni->AllocateFrameBuffers(aScreenNumber, screen->iCompositionBuffers + 1, maxSize);
sl@0
  1455
			}
sl@0
  1456
sl@0
  1457
		if (r == KErrNone)
sl@0
  1458
			{
sl@0
  1459
			buffer.iScreenBuffer.iDisplayBufferOffset = 0;
sl@0
  1460
			masterIni->iBufferSet[aScreenNumber].iDisplayChannel = aDisplay;
sl@0
  1461
			masterIni->InitBitmapHeader(*screen, &buffer.iInfo);
sl@0
  1462
			masterIni->InitBufferFormat(*screen, buffer.iBufferFormat);
sl@0
  1463
			if(systemIni->VideoInfoForDisplayDriver(aScreenNumber,screen->iCurrentMode, videoInfo, ETrue))
sl@0
  1464
				{
sl@0
  1465
					r = aDisplay->Initialize(info,
sl@0
  1466
											 FlipToDisplayRotation(screen->iScreenRotation),
sl@0
  1467
											 hWnd, buffer.iScreenBuffer.iFrameBuffers,
sl@0
  1468
											 buffer.iScreenBuffer.iMemChunks,
sl@0
  1469
											 buffer.iDsaBuffer,
sl@0
  1470
						                     videoInfo.iSizeInPixels,videoInfo.iSizeInTwips,
sl@0
  1471
						                     masterIni->iSupportedPixelFormatTable,
sl@0
  1472
						                     masterIni->iSupportedPixelFormatTableSize,
sl@0
  1473
						                     buffer.iBufferFormat);
sl@0
  1474
				}
sl@0
  1475
			else
sl@0
  1476
				{
sl@0
  1477
				Fault(EGuiVideoInfoUnavailable);
sl@0
  1478
				}
sl@0
  1479
			}
sl@0
  1480
sl@0
  1481
		if (r != KErrNone && __e32_atomic_tas_ord32(&buffer.iDisplayDriverCount, 1, -1, 0) == 1)
sl@0
  1482
			{
sl@0
  1483
			// Release any that were allocated
sl@0
  1484
			masterIni->ReleaseFrameBuffers(aScreenNumber);
sl@0
  1485
			}
sl@0
  1486
		}
sl@0
  1487
	else
sl@0
  1488
		{
sl@0
  1489
		// Display driver disconnected
sl@0
  1490
		if (__e32_atomic_tas_ord32(&buffer.iDisplayDriverCount, 1, -1, 0) == 1)
sl@0
  1491
			{
sl@0
  1492
			// All drivers disconnected, deallocate memory.
sl@0
  1493
			masterIni->ReleaseFrameBuffers(aScreenNumber);
sl@0
  1494
			}
sl@0
  1495
		}
sl@0
  1496
sl@0
  1497
	return r;
sl@0
  1498
	}
sl@0
  1499
sl@0
  1500
sl@0
  1501
void DWinsUi::SetVirtualKey(const TBool aProcessing, const TInt aCommandData, const TEmulCommand aCommand)
sl@0
  1502
	{
sl@0
  1503
	iProcessingVirtualKey = aProcessing;
sl@0
  1504
	iFakedVirtualKey = aCommandData;
sl@0
  1505
	iVirtualKeyCommand = aCommand;
sl@0
  1506
	}
sl@0
  1507
sl@0
  1508
TBool DWinsUi::WasVirtualKey(TInt& aCommandData, TEmulCommand& aCommand)
sl@0
  1509
	{
sl@0
  1510
	if (iProcessingVirtualKey)
sl@0
  1511
		{
sl@0
  1512
sl@0
  1513
		aCommandData = iFakedVirtualKey;
sl@0
  1514
		aCommand = iVirtualKeyCommand;
sl@0
  1515
		}
sl@0
  1516
	return iProcessingVirtualKey;
sl@0
  1517
	}
sl@0
  1518
sl@0
  1519
sl@0
  1520
TInt DWinsUi::DoDefineEmulatorControl(TAny* aPtr, const char* aValue)
sl@0
  1521
	{
sl@0
  1522
	return static_cast<DWinsUi*>(aPtr)->DefineEmulatorControl(aValue);
sl@0
  1523
	}
sl@0
  1524
sl@0
  1525
sl@0
  1526
TInt DWinsUi::DefineEmulatorControl(const char* aValue)
sl@0
  1527
	{
sl@0
  1528
sl@0
  1529
	//example EmulatorControl SelectConfig 2 rect 223,640 29,22
sl@0
  1530
	//example EmulatorControl NextConfig rect 223,640 29,22
sl@0
  1531
	const char* beg = skipws(aValue);
sl@0
  1532
	const char* end = skiptok(beg);
sl@0
  1533
	TInt err = KErrNone;
sl@0
  1534
	
sl@0
  1535
	TEmulCommand command = ENoCommand;
sl@0
  1536
	TInt data = 0;
sl@0
  1537
	if (_strnicmp(beg, "SelectConfig", end-beg) == 0)
sl@0
  1538
		{
sl@0
  1539
		//get the int param which is the config to switch to
sl@0
  1540
		beg = end;
sl@0
  1541
		char * e;
sl@0
  1542
		data = strtol(beg, &e,0);
sl@0
  1543
		if (beg == e)
sl@0
  1544
			err = KErrArgument;
sl@0
  1545
		end = e;
sl@0
  1546
		command = ESelectConfig;
sl@0
  1547
		}
sl@0
  1548
	else if(_strnicmp(beg, "NextConfig", end-beg) == 0)
sl@0
  1549
sl@0
  1550
		{
sl@0
  1551
		command = ENextConfig;
sl@0
  1552
		}
sl@0
  1553
	else
sl@0
  1554
		err = KErrArgument;
sl@0
  1555
sl@0
  1556
	if (err != KErrNone)
sl@0
  1557
		return err;
sl@0
  1558
	
sl@0
  1559
	//get the shape
sl@0
  1560
	beg = skipws(end);
sl@0
  1561
	end = skiptok(beg);
sl@0
  1562
	if (end - beg != 4 || _strnicmp(beg, "rect", 4) != 0)
sl@0
  1563
		return KErrArgument;
sl@0
  1564
		
sl@0
  1565
	// get the parameters
sl@0
  1566
	beg = skipws(end);
sl@0
  1567
	char* end2;
sl@0
  1568
	TInt x = strtol(beg, &end2, 10);
sl@0
  1569
	if (beg == end2 || *end2++ != ',')
sl@0
  1570
		return KErrArgument;
sl@0
  1571
	beg = end2;
sl@0
  1572
	TInt y = strtol(beg, &end2, 10);
sl@0
  1573
	if (beg == end2)
sl@0
  1574
		return KErrArgument;
sl@0
  1575
	beg = skipws(end2);
sl@0
  1576
	TInt w = strtol(beg, &end2, 10);
sl@0
  1577
	if (beg == end2 || *end2++ != ',')
sl@0
  1578
		return KErrArgument;
sl@0
  1579
	beg = end2;
sl@0
  1580
	TInt h = strtol(beg, &end2, 10);
sl@0
  1581
	if (beg == end2)
sl@0
  1582
		return KErrArgument;
sl@0
  1583
	
sl@0
  1584
	VKRect* pRect = new VKRect(data, command, x, y, w, h);
sl@0
  1585
	if (!pRect)
sl@0
  1586
		return KErrNoMemory;
sl@0
  1587
	return iVirtualKeys.Append(pRect);
sl@0
  1588
sl@0
  1589
	}
sl@0
  1590
sl@0
  1591
sl@0
  1592
TInt DWinsUi::DoDefineVirtualKey(TAny* aPtr, const char* aValue)
sl@0
  1593
	{
sl@0
  1594
	return static_cast<DWinsUi*>(aPtr)->DefineVirtualKey(aValue);
sl@0
  1595
	}
sl@0
  1596
sl@0
  1597
TInt DWinsUi::DefineVirtualKey(const char* aValue)
sl@0
  1598
	{
sl@0
  1599
	// Get the key to map
sl@0
  1600
	const char* beg = skipws(aValue);
sl@0
  1601
	const char* end = skiptok(beg);
sl@0
  1602
	TInt key = iKeyboard.GetEPOCKeyCode(TPtrC8((const TUint8*)beg, end-beg));
sl@0
  1603
	if (key == KErrNotFound)
sl@0
  1604
		return key;
sl@0
  1605
sl@0
  1606
	//get the shape
sl@0
  1607
	beg = skipws(end);
sl@0
  1608
	end = skiptok(beg);
sl@0
  1609
	if (end - beg != 4 || _strnicmp(beg, "rect", 4) != 0)
sl@0
  1610
		return KErrArgument;
sl@0
  1611
		
sl@0
  1612
	// get the parameters
sl@0
  1613
	beg = skipws(end);
sl@0
  1614
	char* end2;
sl@0
  1615
	TInt x = strtol(beg, &end2, 10);
sl@0
  1616
	if (beg == end2 || *end2++ != ',')
sl@0
  1617
		return KErrArgument;
sl@0
  1618
	beg = end2;
sl@0
  1619
	TInt y = strtol(beg, &end2, 10);
sl@0
  1620
	if (beg == end2)
sl@0
  1621
		return KErrArgument;
sl@0
  1622
	beg = skipws(end2);
sl@0
  1623
	TInt w = strtol(beg, &end2, 10);
sl@0
  1624
	if (beg == end2 || *end2++ != ',')
sl@0
  1625
		return KErrArgument;
sl@0
  1626
	beg = end2;
sl@0
  1627
	TInt h = strtol(beg, &end2, 10);
sl@0
  1628
	if (beg == end2)
sl@0
  1629
		return KErrArgument;
sl@0
  1630
	
sl@0
  1631
	VKRect* pRect = new VKRect(key, EKey, x, y, w, h);
sl@0
  1632
	if (!pRect)
sl@0
  1633
		return KErrNoMemory;
sl@0
  1634
	return iVirtualKeys.Append(pRect);
sl@0
  1635
	}
sl@0
  1636
sl@0
  1637
sl@0
  1638
LOCAL_C TInt readBitmapInfo(PBITMAPINFOHEADER aHeader, const char* aFileName)
sl@0
  1639
	{
sl@0
  1640
	PBITMAPFILEHEADER pbmfh=NULL;
sl@0
  1641
	PBITMAPINFOHEADER pbmih=NULL;
sl@0
  1642
	TInt bfOffBits;
sl@0
  1643
sl@0
  1644
	HANDLE fh=CreateFileA(aFileName,GENERIC_READ,NULL,NULL,OPEN_EXISTING,NULL,NULL);
sl@0
  1645
	if (!fh || fh==INVALID_HANDLE_VALUE)
sl@0
  1646
		return KErrNotFound;
sl@0
  1647
sl@0
  1648
	TInt r=KErrNone;
sl@0
  1649
sl@0
  1650
	// read in the bitmap file header.  save the offset to bits.
sl@0
  1651
	pbmfh = (PBITMAPFILEHEADER)LocalAlloc(LPTR, sizeof(BITMAPFILEHEADER));
sl@0
  1652
	if (pbmfh==NULL)
sl@0
  1653
		{
sl@0
  1654
		r=KErrNotFound;
sl@0
  1655
        goto exit;
sl@0
  1656
		}
sl@0
  1657
	DWORD bytesRead;
sl@0
  1658
	ReadFile(fh, (LPVOID)pbmfh, sizeof(BITMAPFILEHEADER), &bytesRead, NULL);
sl@0
  1659
	bfOffBits=pbmfh->bfOffBits;
sl@0
  1660
sl@0
  1661
	// read in the bitmap info header and the color table right after it.
sl@0
  1662
	pbmih = (PBITMAPINFOHEADER)LocalAlloc(LPTR, bfOffBits- sizeof(BITMAPFILEHEADER));
sl@0
  1663
	if (pbmih==NULL)
sl@0
  1664
		{
sl@0
  1665
		r=KErrNotFound;
sl@0
  1666
        goto exit;
sl@0
  1667
		}
sl@0
  1668
	ReadFile(fh, (LPVOID)pbmih, bfOffBits-sizeof(BITMAPFILEHEADER),&bytesRead,NULL);
sl@0
  1669
	*aHeader=*pbmih;
sl@0
  1670
exit:
sl@0
  1671
	LocalFree(LocalHandle ((LPSTR)pbmih));
sl@0
  1672
	LocalFree(LocalHandle ((LPSTR)pbmfh));
sl@0
  1673
	CloseHandle(fh);
sl@0
  1674
	return r;
sl@0
  1675
	}
sl@0
  1676
sl@0
  1677
HBITMAP readBitmap(HDC aHdc, const char* aFileName)
sl@0
  1678
//
sl@0
  1679
// reads a BMP file from disk and returns a HBITMAP
sl@0
  1680
//
sl@0
  1681
	{
sl@0
  1682
	HBITMAP hbm=NULL;
sl@0
  1683
	PBITMAPFILEHEADER pbmfh=NULL;
sl@0
  1684
	PBITMAPINFOHEADER pbmih=NULL;
sl@0
  1685
	TUint8 *pBits=NULL;
sl@0
  1686
	TInt bfOffBits;
sl@0
  1687
	TInt nbytes;
sl@0
  1688
sl@0
  1689
	HANDLE fh=CreateFileA(aFileName, GENERIC_READ, NULL, NULL, OPEN_EXISTING, NULL, NULL);
sl@0
  1690
	if (!fh || fh==INVALID_HANDLE_VALUE)
sl@0
  1691
		return NULL;
sl@0
  1692
sl@0
  1693
	nbytes=GetFileSize((HANDLE)fh, NULL);
sl@0
  1694
	// read in the bitmap file header.  save the offset to bits.
sl@0
  1695
	pbmfh = (PBITMAPFILEHEADER)LocalAlloc(LPTR, sizeof(BITMAPFILEHEADER));
sl@0
  1696
	if (pbmfh==NULL)
sl@0
  1697
        goto exit;
sl@0
  1698
	DWORD bytesRead;
sl@0
  1699
	ReadFile(fh, (LPVOID)pbmfh, sizeof(BITMAPFILEHEADER),&bytesRead,NULL);
sl@0
  1700
	bfOffBits=pbmfh->bfOffBits;
sl@0
  1701
sl@0
  1702
	// read in the bitmap info header and the color table right after it.
sl@0
  1703
	pbmih = (PBITMAPINFOHEADER)LocalAlloc(LPTR, bfOffBits- sizeof(BITMAPFILEHEADER));
sl@0
  1704
	if (pbmih==NULL)
sl@0
  1705
        goto exit;
sl@0
  1706
	ReadFile(fh, (LPVOID)pbmih, bfOffBits-sizeof(BITMAPFILEHEADER),&bytesRead,NULL);
sl@0
  1707
sl@0
  1708
	// finally read in the bit data.
sl@0
  1709
	pBits = (PBYTE)LocalAlloc (LPTR, (nbytes - bfOffBits));
sl@0
  1710
	if (pBits==NULL)
sl@0
  1711
        goto exit;
sl@0
  1712
	ReadFile(fh, (LPVOID)pBits, nbytes-bfOffBits,&bytesRead,NULL);
sl@0
  1713
		
sl@0
  1714
	hbm=CreateDIBitmap(aHdc, pbmih, CBM_INIT, pBits,(PBITMAPINFO) pbmih, DIB_RGB_COLORS);
sl@0
  1715
exit:
sl@0
  1716
	LocalFree(LocalHandle ((LPSTR)pBits));
sl@0
  1717
	LocalFree(LocalHandle ((LPSTR)pbmih));
sl@0
  1718
	LocalFree(LocalHandle ((LPSTR)pbmfh));
sl@0
  1719
	CloseHandle(fh);
sl@0
  1720
	return hbm;
sl@0
  1721
	}
sl@0
  1722
sl@0
  1723
void LoadFasciaBitmap(TInt aScreen)
sl@0
  1724
	{
sl@0
  1725
	HDC hdc=GetDC(TheWin[aScreen]);
sl@0
  1726
	RECT windowRect = {0};
sl@0
  1727
	windowRect.right=systemIni->iScreens[aScreen]->iXYInputWidth;
sl@0
  1728
	windowRect.bottom=systemIni->iScreens[aScreen]->iXYInputHeight;
sl@0
  1729
	HBITMAP screenBitmap=readBitmap(hdc, systemIni->iScreens[aScreen]->iFasciaFileName);
sl@0
  1730
	if (screenBitmap==NULL)
sl@0
  1731
		{
sl@0
  1732
		screenBitmap=CreateCompatibleBitmap(hdc, windowRect.right-windowRect.left, windowRect.bottom-windowRect.top);
sl@0
  1733
		HDC hdcMem=CreateCompatibleDC(hdc);
sl@0
  1734
		SelectObject(hdcMem, screenBitmap);
sl@0
  1735
		PatBlt(hdcMem, 0, 0, windowRect.right-windowRect.left, windowRect.bottom-windowRect.top, BLACKNESS);
sl@0
  1736
		DeleteDC(hdcMem);
sl@0
  1737
		}
sl@0
  1738
	__ASSERT_ALWAYS(screenBitmap!=NULL,Fault(EGuiCreateBitmap));
sl@0
  1739
	TheScreenBitmap[aScreen]=screenBitmap;
sl@0
  1740
sl@0
  1741
	DrawLeds();
sl@0
  1742
sl@0
  1743
	ReleaseDC(TheWin[aScreen], hdc);
sl@0
  1744
	}
sl@0
  1745
TBool DWinsUi::MultiTouchEnabled() const
sl@0
  1746
	{
sl@0
  1747
	return iMultiTouchEnabled;
sl@0
  1748
	}
sl@0
  1749
sl@0
  1750
TBool DWinsUi::GCEEnabled() const
sl@0
  1751
	{
sl@0
  1752
	return iGCEEnabled;
sl@0
  1753
	}
sl@0
  1754
sl@0
  1755
TInt DWinsUi::MultiTouchProximityStep() const
sl@0
  1756
	{
sl@0
  1757
	return iMultiTouchProximityStep;
sl@0
  1758
	}
sl@0
  1759
sl@0
  1760
TInt DWinsUi::MultiTouchPressureStep() const
sl@0
  1761
	{
sl@0
  1762
	return iMultiTouchPressureStep;
sl@0
  1763
	}
sl@0
  1764
sl@0
  1765
TBool DWinsUi::OnDigitizer(TInt aX, TInt aY) const
sl@0
  1766
	{
sl@0
  1767
	if (!iDigitizerEnabled)
sl@0
  1768
		return EFalse;
sl@0
  1769
	switch(CurrentFlipState[0])
sl@0
  1770
		{
sl@0
  1771
		case EEmulatorFlipRestore:
sl@0
  1772
			{
sl@0
  1773
			aX -= iDigitizerOffsetX;
sl@0
  1774
			aY -= iDigitizerOffsetY;
sl@0
  1775
			break;
sl@0
  1776
			}
sl@0
  1777
		case EEmulatorFlipInvert:
sl@0
  1778
			{
sl@0
  1779
			aX -= systemIni->iScreens[0]->iScreenWidth - iDigitizerOffsetX - iDigitizerWidth;
sl@0
  1780
			aY -= systemIni->iScreens[0]->iScreenHeight - iDigitizerOffsetY - iDigitizerHeight;
sl@0
  1781
			break;
sl@0
  1782
			}
sl@0
  1783
		case EEmulatorFlipRight:
sl@0
  1784
			{
sl@0
  1785
			TInt oldY = aY;
sl@0
  1786
			aY = aX - (systemIni->iScreens[0]->iScreenHeight - iDigitizerOffsetY - iDigitizerHeight);
sl@0
  1787
			aX = oldY - iDigitizerOffsetX;
sl@0
  1788
			break;
sl@0
  1789
			}
sl@0
  1790
		case EEmulatorFlipLeft:
sl@0
  1791
			{
sl@0
  1792
			TInt oldY = aY;
sl@0
  1793
			aY = aX - iDigitizerOffsetY;
sl@0
  1794
			aX = oldY - (systemIni->iScreens[0]->iScreenWidth - iDigitizerOffsetX - iDigitizerWidth);
sl@0
  1795
			break;
sl@0
  1796
			}
sl@0
  1797
		}
sl@0
  1798
	return (TUint(aX) < TUint(iDigitizerWidth) && TUint(aY) < TUint(iDigitizerHeight));
sl@0
  1799
	}
sl@0
  1800
sl@0
  1801
LOCAL_C void addMouseEvent(TRawEvent::TType aType,TInt aXpos,TInt aYpos)
sl@0
  1802
//
sl@0
  1803
// Add a mouse event.
sl@0
  1804
//
sl@0
  1805
	{
sl@0
  1806
	if (systemIni->OnDigitizer(aXpos, aYpos))
sl@0
  1807
		{
sl@0
  1808
		TRawEvent v;
sl@0
  1809
		v.Set(aType,aXpos,aYpos);
sl@0
  1810
		TheEventQ.Add(v);
sl@0
  1811
		}
sl@0
  1812
	}
sl@0
  1813
sl@0
  1814
LOCAL_C void addMouseEvent(TRawEvent::TType aType,TInt aXpos,TInt aYpos,TInt aZpos, TInt aPointerId=0)
sl@0
  1815
//
sl@0
  1816
// Add a multitouch mouse event.
sl@0
  1817
//
sl@0
  1818
	{
sl@0
  1819
	if (systemIni->OnDigitizer(aXpos, aYpos))
sl@0
  1820
		{
sl@0
  1821
		TRawEvent v;
sl@0
  1822
		v.Set(aType,aXpos,aYpos, aZpos);
sl@0
  1823
		v.SetPointerNumber(static_cast<const TUint8>(aPointerId));
sl@0
  1824
		TheEventQ.Add(v);
sl@0
  1825
		}
sl@0
  1826
	}
sl@0
  1827
LOCAL_C void addKeyEvent(TRawEvent::TType aType,TInt aKey)
sl@0
  1828
	{
sl@0
  1829
	TRawEvent v;
sl@0
  1830
	v.Set(aType, aKey);
sl@0
  1831
	TheEventQ.Add(v);
sl@0
  1832
	}
sl@0
  1833
sl@0
  1834
sl@0
  1835
LOCAL_C void SwitchConfiguration(TInt aData, TBool aSendFlipKey = ETrue)
sl@0
  1836
	{
sl@0
  1837
	if (aData < 0 || aData >= masterIni->iSystemInis.Count())
sl@0
  1838
		return;
sl@0
  1839
sl@0
  1840
	CurrentConfiguration = aData;
sl@0
  1841
	systemIni = masterIni->iSystemInis[aData];
sl@0
  1842
	
sl@0
  1843
	//get the correct fascia bitmaps
sl@0
  1844
	TInt screens=systemIni->iScreens.Count();
sl@0
  1845
	TInt i;
sl@0
  1846
	TUint disabledWinType=ENormalResolution;
sl@0
  1847
	for(i=0;i<screens;i++)
sl@0
  1848
		{
sl@0
  1849
		DeleteObject(TheScreenBitmap[i]);
sl@0
  1850
		LoadFasciaBitmap(i);
sl@0
  1851
		if (masterIni->iBufferSet[i].iDisplayState!=ENormalResolution)
sl@0
  1852
			{
sl@0
  1853
			disabledWinType=masterIni->iBufferSet[i].iDisplayState;
sl@0
  1854
			}
sl@0
  1855
		}
sl@0
  1856
	
sl@0
  1857
	//update the window title
sl@0
  1858
	if (disabledWinType!=ENormalResolution && disabledWinType < 4)	//hardwired 4 because the code below is hardwired
sl@0
  1859
		{	//string may be multi-part indexed by disable type, or it may not
sl@0
  1860
		CHAR* firstsemi=strchr(systemIni->iWindowTitle,';');
sl@0
  1861
		CHAR* secondsemi=NULL;
sl@0
  1862
		if (firstsemi)
sl@0
  1863
			{
sl@0
  1864
			secondsemi=strchr(firstsemi+1,';');
sl@0
  1865
			}
sl@0
  1866
		if (firstsemi&&secondsemi)
sl@0
  1867
			{
sl@0
  1868
			*firstsemi='\0';
sl@0
  1869
			*secondsemi='\0';
sl@0
  1870
			char* ptr[4]={0,systemIni->iWindowTitle,firstsemi+1,secondsemi+1};
sl@0
  1871
			SetWindowTextA(TheControlWin, ptr[disabledWinType]);
sl@0
  1872
			*firstsemi=';';
sl@0
  1873
			*secondsemi=';';
sl@0
  1874
			}
sl@0
  1875
		else
sl@0
  1876
			{
sl@0
  1877
			SetWindowTextA(TheControlWin, systemIni->iWindowTitle);
sl@0
  1878
			}
sl@0
  1879
		
sl@0
  1880
		}
sl@0
  1881
	else
sl@0
  1882
		{
sl@0
  1883
		SetWindowTextA(TheControlWin, systemIni->iWindowTitle);
sl@0
  1884
		}
sl@0
  1885
	//resize and repaint the current window anyway.
sl@0
  1886
	//the text window server doesn't respond to orientation messages
sl@0
  1887
	for(i=0;i<screens;i++)
sl@0
  1888
		{
sl@0
  1889
		InvalidateRect(TheWin[i], NULL, false);
sl@0
  1890
		SendMessage(TheWin[i], WM_FLIP_MESSAGE, systemIni->iScreens[i]->iScreenRotation,0);
sl@0
  1891
		}
sl@0
  1892
sl@0
  1893
	//pass on the orientation key to the windows server
sl@0
  1894
	if (aSendFlipKey)
sl@0
  1895
		{
sl@0
  1896
		if (!WinsGuiPowerHandler->iStandby)
sl@0
  1897
			{
sl@0
  1898
			addKeyEvent(TRawEvent::EKeyDown, systemIni->iInitialFlipMsg);
sl@0
  1899
			addKeyEvent(TRawEvent::EKeyUp, systemIni->iInitialFlipMsg);
sl@0
  1900
			}
sl@0
  1901
		else
sl@0
  1902
			{
sl@0
  1903
			//remember the flip message so we can send it to the window server when we come out of standby
sl@0
  1904
			SavedFlipMessage = systemIni->iInitialFlipMsg;
sl@0
  1905
			}
sl@0
  1906
		}
sl@0
  1907
	}
sl@0
  1908
/**
sl@0
  1909
Sets the specified screen to the given width and height, if available.
sl@0
  1910
sl@0
  1911
The configurations are searched to find a match, taking the display state into
sl@0
  1912
account. If no configuration is available, the request is ignored.
sl@0
  1913
sl@0
  1914
@param aScreenNumber	the screen index
sl@0
  1915
@param aWidth 			the desired width
sl@0
  1916
@param aHeight			the desired height
sl@0
  1917
**/
sl@0
  1918
void DMasterIni::SetDisplaySize(TInt aDisplayNumber, TInt aWidth, TInt aHeight)
sl@0
  1919
	{
sl@0
  1920
	TInt displayCount = iBufferSet.Count();
sl@0
  1921
sl@0
  1922
	if (aDisplayNumber < 0 || aDisplayNumber >= displayCount)
sl@0
  1923
		{
sl@0
  1924
		// Invalid screen number, discard.
sl@0
  1925
		return;
sl@0
  1926
		}
sl@0
  1927
sl@0
  1928
	if (iBufferSet[aDisplayNumber].iDisplayState != ENormalResolution)
sl@0
  1929
		{
sl@0
  1930
		// No (non-zero) resolutions available, discard.
sl@0
  1931
		return;
sl@0
  1932
		}
sl@0
  1933
sl@0
  1934
	TInt count = iSystemInis.Count();
sl@0
  1935
	TInt index;
sl@0
  1936
	for (index = 0; index < count; index++)
sl@0
  1937
		{
sl@0
  1938
		DWinsUi* newIni = masterIni->iSystemInis[index];
sl@0
  1939
		DScreenProperties* newProps = newIni->iScreens[aDisplayNumber];
sl@0
  1940
sl@0
  1941
		if (newProps->iScreenWidth == aWidth && newProps->iScreenHeight == aHeight)
sl@0
  1942
			{
sl@0
  1943
			// Found a potential match. Check other screens match their current size.
sl@0
  1944
			if (newIni == systemIni)
sl@0
  1945
				{
sl@0
  1946
				// Current configuration, already in use. Nothing to do.
sl@0
  1947
				break;
sl@0
  1948
				}
sl@0
  1949
			
sl@0
  1950
			TInt display;
sl@0
  1951
			for (display = 0; display < displayCount; display++)
sl@0
  1952
				{
sl@0
  1953
				if (display == aDisplayNumber)
sl@0
  1954
					{
sl@0
  1955
					// No need to check the display we are changing
sl@0
  1956
					continue;
sl@0
  1957
					}
sl@0
  1958
sl@0
  1959
				DScreenProperties* currentPropsN = systemIni->iScreens[display];
sl@0
  1960
				DScreenProperties* newPropsN = newIni->iScreens[display];
sl@0
  1961
				
sl@0
  1962
				if (newPropsN->iScreenWidth != currentPropsN->iScreenWidth ||
sl@0
  1963
						newPropsN->iScreenHeight != currentPropsN->iScreenHeight)
sl@0
  1964
					{
sl@0
  1965
					// Resolution mismatch, try next configuration.
sl@0
  1966
					break;
sl@0
  1967
					}
sl@0
  1968
				}
sl@0
  1969
			
sl@0
  1970
			if (display == displayCount)
sl@0
  1971
				{
sl@0
  1972
				// Match found, switch to this configuration and stop. Force
sl@0
  1973
				// rotation to the same as the current rotation.
sl@0
  1974
				newProps->iScreenRotation = systemIni->iScreens[aDisplayNumber]->iScreenRotation;
sl@0
  1975
				SwitchConfiguration(index);
sl@0
  1976
				break;
sl@0
  1977
				}
sl@0
  1978
			}
sl@0
  1979
		}
sl@0
  1980
	}
sl@0
  1981
sl@0
  1982
sl@0
  1983
void DMasterIni::SetBufferFormat(TInt aDisplayNumber, TUint aAggregateSize, RDisplayChannel::TPixelFormat aPixelFormat)
sl@0
  1984
	{
sl@0
  1985
	TInt displayCount = iBufferSet.Count();
sl@0
  1986
sl@0
  1987
	if (aDisplayNumber < 0 || aDisplayNumber >= displayCount)
sl@0
  1988
		{
sl@0
  1989
		// Invalid screen number, discard.
sl@0
  1990
		return;
sl@0
  1991
		}
sl@0
  1992
	
sl@0
  1993
	LPBITMAPV4HEADER info = &iBufferSet[aDisplayNumber].iInfo;
sl@0
  1994
	
sl@0
  1995
	// update the bitmap header taking in consideration the new pixel format
sl@0
  1996
	switch (aPixelFormat)
sl@0
  1997
		{
sl@0
  1998
		case EUidPixelFormatXRGB_4444:
sl@0
  1999
		case EUidPixelFormatARGB_4444:
sl@0
  2000
			info->bV4BitCount=16;
sl@0
  2001
			info->bV4V4Compression = BI_BITFIELDS;
sl@0
  2002
			info->bV4RedMask   = 0x0F00;
sl@0
  2003
			info->bV4GreenMask = 0x00F0;
sl@0
  2004
			info->bV4BlueMask  = 0x000F;
sl@0
  2005
			break;
sl@0
  2006
		case EUidPixelFormatRGB_565:
sl@0
  2007
			info->bV4BitCount=16;
sl@0
  2008
			info->bV4V4Compression = BI_BITFIELDS;
sl@0
  2009
			info->bV4RedMask   = 0xF800;
sl@0
  2010
			info->bV4GreenMask = 0x07E0;
sl@0
  2011
			info->bV4BlueMask  = 0x001F;
sl@0
  2012
			break;
sl@0
  2013
		case EUidPixelFormatXRGB_8888:	// Really 32bpp, but top 8 unused
sl@0
  2014
		case EUidPixelFormatARGB_8888:
sl@0
  2015
		case EUidPixelFormatARGB_8888_PRE:
sl@0
  2016
			info->bV4BitCount=32;
sl@0
  2017
			info->bV4V4Compression = BI_RGB;
sl@0
  2018
			// Mask is implicit for BI_RGB compression
sl@0
  2019
			break;
sl@0
  2020
		default:
sl@0
  2021
			// We got an error, it seems. Let's ignore the message
sl@0
  2022
			return;
sl@0
  2023
		}
sl@0
  2024
	iBufferSet[aDisplayNumber].iBufferFormat.iPixelFormat = aPixelFormat;
sl@0
  2025
	
sl@0
  2026
	// taking advantage of limiting the width and size to KMaxTInt16
sl@0
  2027
	TInt width = aAggregateSize & 0x0000ffff;
sl@0
  2028
	TInt height = (aAggregateSize >> 16) & 0x0000ffff;
sl@0
  2029
sl@0
  2030
	// let's deal with the new size just received
sl@0
  2031
	iBufferSet[aDisplayNumber].iBufferFormat.iSize.iWidth = width;
sl@0
  2032
	iBufferSet[aDisplayNumber].iBufferFormat.iSize.iHeight = height;
sl@0
  2033
	
sl@0
  2034
	// update the bitmap header, taking in consideration the rotation
sl@0
  2035
	switch (CurrentFlipState[aDisplayNumber])
sl@0
  2036
		{
sl@0
  2037
		case EEmulatorFlipRestore:
sl@0
  2038
		case EEmulatorFlipInvert:
sl@0
  2039
			info->bV4Width = width;
sl@0
  2040
			info->bV4Height = -height;
sl@0
  2041
			break;
sl@0
  2042
		case EEmulatorFlipLeft:
sl@0
  2043
		case EEmulatorFlipRight:
sl@0
  2044
			info->bV4Width = height;
sl@0
  2045
			info->bV4Height = -width;
sl@0
  2046
			break;
sl@0
  2047
		}
sl@0
  2048
	// finally, update the image size
sl@0
  2049
	SetImageSize(aDisplayNumber);
sl@0
  2050
	}
sl@0
  2051
sl@0
  2052
void DMasterIni::SetImageSize(TInt aScreenNumber)
sl@0
  2053
	{
sl@0
  2054
	TInt displayCount = iBufferSet.Count();
sl@0
  2055
sl@0
  2056
	if (aScreenNumber >= 0 && aScreenNumber < displayCount)
sl@0
  2057
		{
sl@0
  2058
		LPBITMAPV4HEADER info = &iBufferSet[aScreenNumber].iInfo;
sl@0
  2059
		TInt bpp = _ALIGN_UP(info->bV4BitCount, 16); //12 & 16 --> 16 ; 24 & 32 --> 32
sl@0
  2060
		TInt widthInBpp = info->bV4Width * bpp;
sl@0
  2061
		//rounding to 32 bits (4 octets) and converting, then, bits to octets;
sl@0
  2062
		TInt scanLineInBytes = _ALIGN_UP(widthInBpp, 32) >> 3;
sl@0
  2063
		// info->bV4Height is negative or zero
sl@0
  2064
		info->bV4SizeImage = -info->bV4Height * scanLineInBytes;
sl@0
  2065
		}
sl@0
  2066
	}
sl@0
  2067
sl@0
  2068
LOCAL_C void NextConfiguration()
sl@0
  2069
	{
sl@0
  2070
	TInt config = CurrentConfiguration;
sl@0
  2071
	if (++config == masterIni->iSystemInis.Count())
sl@0
  2072
		config = 0;
sl@0
  2073
	SwitchConfiguration(config);
sl@0
  2074
	}
sl@0
  2075
sl@0
  2076
sl@0
  2077
sl@0
  2078
LOCAL_C TBool ProcessedByEmulatorKey(TInt aScanCode, HWND hWnd,TUint message,TUint wParam,TUint lParam)
sl@0
  2079
	{
sl@0
  2080
sl@0
  2081
	TBool rVal = EFalse;
sl@0
  2082
	rVal = ETrue;
sl@0
  2083
	for (TInt i=0;i<systemIni->iControlHotKeys.Count();i++)//check key combinations
sl@0
  2084
		{
sl@0
  2085
		if (systemIni->iControlHotKeys[i]->CheckCombinationPressed()) 
sl@0
  2086
			{				
sl@0
  2087
			switch (systemIni->iControlHotKeys[i]->iCommand)
sl@0
  2088
				{
sl@0
  2089
				
sl@0
  2090
				case ENextConfig:
sl@0
  2091
					NextConfiguration();
sl@0
  2092
					break;
sl@0
  2093
		
sl@0
  2094
				case ESelectConfig:
sl@0
  2095
					SwitchConfiguration(systemIni->iControlHotKeys[i]->iData);
sl@0
  2096
					break;
sl@0
  2097
							
sl@0
  2098
				}
sl@0
  2099
			return ETrue;
sl@0
  2100
			}
sl@0
  2101
		}
sl@0
  2102
	switch (aScanCode)
sl@0
  2103
	{
sl@0
  2104
	
sl@0
  2105
	case EStdKeyF4:
sl@0
  2106
		{
sl@0
  2107
		// Simulate a change of media card
sl@0
  2108
		TInt irq = NKern::DisableAllInterrupts();
sl@0
  2109
		if (*Wins::MediaDoorOpenPtr())
sl@0
  2110
			{
sl@0
  2111
			*Wins::CurrentPBusDevicePtr() += 1;
sl@0
  2112
			if (*Wins::CurrentPBusDevicePtr() == 2)
sl@0
  2113
				{
sl@0
  2114
				*Wins::CurrentPBusDevicePtr() = -1;
sl@0
  2115
				}
sl@0
  2116
			}
sl@0
  2117
		NKern::RestoreInterrupts(irq);
sl@0
  2118
		
sl@0
  2119
		// pass on to the windows system so that if
sl@0
  2120
		// Alt-F4 is pressed the window will close
sl@0
  2121
		if (hWnd)
sl@0
  2122
			DefWindowProcA(hWnd,message,wParam,lParam);
sl@0
  2123
		break;
sl@0
  2124
		}
sl@0
  2125
sl@0
  2126
	default:
sl@0
  2127
		rVal = EFalse;
sl@0
  2128
		break;
sl@0
  2129
	}
sl@0
  2130
	return rVal;
sl@0
  2131
	}
sl@0
  2132
sl@0
  2133
LOCAL_C void MultiChildWndPointer(TUint aMessage,TInt aXpos,TInt aYpos, TInt aZ, TInt aPointerId)
sl@0
  2134
//
sl@0
  2135
// Handle a multi-touch pointer event in the Symbian OS screen window 
sl@0
  2136
//
sl@0
  2137
	{
sl@0
  2138
	TRawEvent::TType eventType=TRawEvent::ENone;
sl@0
  2139
	CHAR buf[50];
sl@0
  2140
	
sl@0
  2141
	if (aZ <= TheMultiTouch->iZMaxRange) //negative
sl@0
  2142
		{
sl@0
  2143
		eventType = TRawEvent::EPointer3DOutOfRange;
sl@0
  2144
		wsprintf((LPTSTR)buf, (LPCTSTR)TEXT("Out Of Range"));
sl@0
  2145
		SendMessage(hwndStatus, SB_SETTEXT, aPointerId , (LPARAM)(buf));					
sl@0
  2146
		}
sl@0
  2147
	else 
sl@0
  2148
		{
sl@0
  2149
		wsprintf((LPTSTR)buf, (LPCTSTR)TEXT("%d: %d,%d,%d"), aPointerId, aXpos,aYpos,aZ);
sl@0
  2150
		SendMessage(hwndStatus, SB_SETTEXT, aPointerId , (LPARAM)(buf));					
sl@0
  2151
		switch (aMessage)
sl@0
  2152
	    	{
sl@0
  2153
			case WM_MOUSEMOVE:
sl@0
  2154
				{
sl@0
  2155
				eventType=TRawEvent::EPointerMove;
sl@0
  2156
				break;
sl@0
  2157
				}
sl@0
  2158
			case WM_LBUTTONDOWN:
sl@0
  2159
				{
sl@0
  2160
				SetCapture(TheChildWin[0]);
sl@0
  2161
				eventType = TRawEvent::EButton1Down;
sl@0
  2162
				}
sl@0
  2163
				break;
sl@0
  2164
			case WM_LBUTTONUP:
sl@0
  2165
				{
sl@0
  2166
				ReleaseCapture();
sl@0
  2167
				eventType = TRawEvent::EButton1Up;
sl@0
  2168
				break;
sl@0
  2169
				}
sl@0
  2170
			case WM_RBUTTONDOWN:
sl@0
  2171
				{
sl@0
  2172
				eventType = TRawEvent::EButton3Down;
sl@0
  2173
				break;
sl@0
  2174
				}
sl@0
  2175
			case WM_RBUTTONUP:
sl@0
  2176
				{
sl@0
  2177
				eventType = TRawEvent::EButton3Up;
sl@0
  2178
				break;
sl@0
  2179
				}
sl@0
  2180
			case WM_MOUSEWHEEL:
sl@0
  2181
				{
sl@0
  2182
				eventType = TRawEvent::EPointerMove;
sl@0
  2183
				break;
sl@0
  2184
				}
sl@0
  2185
			default:
sl@0
  2186
				return;
sl@0
  2187
			}
sl@0
  2188
		}
sl@0
  2189
sl@0
  2190
	if (!WinsGuiPowerHandler->iStandby)
sl@0
  2191
		{
sl@0
  2192
		addMouseEvent(eventType, aXpos, aYpos, aZ, aPointerId);
sl@0
  2193
		}
sl@0
  2194
	}
sl@0
  2195
sl@0
  2196
LOCAL_C void ChildWndPointer(TUint message,TInt aXpos,TInt aYpos)
sl@0
  2197
//
sl@0
  2198
// Handle a pointer event in the Symbian OS screen window
sl@0
  2199
//
sl@0
  2200
	{
sl@0
  2201
	// Enable the multitouch if the cursor is inside the main client window
sl@0
  2202
	if (DMultiTouch::iMultiTouchCreated)
sl@0
  2203
		{
sl@0
  2204
		RECT client;
sl@0
  2205
		WINDOWINFO info;
sl@0
  2206
		GetWindowInfo(TheChildWin[0], &info);
sl@0
  2207
		POINT pt = {aXpos+(TInt)info.rcClient.left, aYpos+(TInt)info.rcClient.top};
sl@0
  2208
		if (GetWindowRect(TheChildWin[0], &client) &&
sl@0
  2209
				(PtInRect(&client,pt)!=NULL) && !DMultiTouch::iMultiTouchTempEnabled)	// within the window
sl@0
  2210
			{
sl@0
  2211
			if (systemIni->MultiTouchEnabled() && systemIni->GCEEnabled())
sl@0
  2212
				{
sl@0
  2213
				if(TheMultiTouch->Register())	// Register successfully
sl@0
  2214
					{
sl@0
  2215
					DMultiTouch::iMultiTouchTempEnabled = TRUE;
sl@0
  2216
					//Show the status bars at the bottom of the emulator
sl@0
  2217
					SetWindowPos(hwndStatus,0,0,0,0,0,SWP_SHOWWINDOW);
sl@0
  2218
					SetFocus(TheWin[0]);
sl@0
  2219
					SetCursor(LoadCursorA(NULL,MAKEINTRESOURCEA(32512)));
sl@0
  2220
					}
sl@0
  2221
				}
sl@0
  2222
			}
sl@0
  2223
		}
sl@0
  2224
	TRawEvent::TType eventType=TRawEvent::ENone;
sl@0
  2225
	switch (message)
sl@0
  2226
    	{
sl@0
  2227
	case WM_MOUSEMOVE:
sl@0
  2228
		eventType=TRawEvent::EPointerMove;
sl@0
  2229
		break;
sl@0
  2230
	case WM_LBUTTONDOWN:
sl@0
  2231
		{
sl@0
  2232
		SetCapture(TheChildWin[0]);
sl@0
  2233
		eventType=TRawEvent::EButton1Down;
sl@0
  2234
		}
sl@0
  2235
		break;
sl@0
  2236
	case WM_LBUTTONUP:
sl@0
  2237
		ReleaseCapture();
sl@0
  2238
		eventType=TRawEvent::EButton1Up;
sl@0
  2239
		break;
sl@0
  2240
	case WM_RBUTTONDOWN:
sl@0
  2241
		eventType=TRawEvent::EButton3Down;
sl@0
  2242
		break;
sl@0
  2243
	case WM_RBUTTONUP:
sl@0
  2244
		eventType=TRawEvent::EButton3Up;
sl@0
  2245
		break;
sl@0
  2246
	case WM_MBUTTONDOWN:
sl@0
  2247
		eventType=TRawEvent::EButton2Down;
sl@0
  2248
		break;
sl@0
  2249
	case WM_MBUTTONUP:
sl@0
  2250
		eventType=TRawEvent::EButton2Up;
sl@0
  2251
		break;
sl@0
  2252
		}
sl@0
  2253
	if (!WinsGuiPowerHandler->iStandby)
sl@0
  2254
		{
sl@0
  2255
		addMouseEvent(eventType, aXpos, aYpos);
sl@0
  2256
		}
sl@0
  2257
	}
sl@0
  2258
sl@0
  2259
LOCAL_C void FrameWndPointer(TUint message,TInt aXpos,TInt aYpos, TInt aScreenNumber, TInt aPointerId = 0)
sl@0
  2260
//
sl@0
  2261
// Handle a frame wnd pointer event.
sl@0
  2262
//
sl@0
  2263
	{
sl@0
  2264
	static bool	processingScreenOn=FALSE;
sl@0
  2265
	TEmulCommand command = ENoCommand;
sl@0
  2266
	TInt commandData = 0;
sl@0
  2267
	TBool mouseEvent = ETrue;
sl@0
  2268
	
sl@0
  2269
	TRawEvent::TType eventType=TRawEvent::ENone;
sl@0
  2270
	
sl@0
  2271
	TViewport& viewport = systemIni->iScreens[aScreenNumber]->iViewport;
sl@0
  2272
	aXpos += viewport.GetViewportOffsetX(); // make mouse-coords relative to fascia edge even if window is scrolled
sl@0
  2273
	aYpos += viewport.GetViewportOffsetY();
sl@0
  2274
	
sl@0
  2275
	switch (message)
sl@0
  2276
    	{
sl@0
  2277
	case WM_MOUSEMOVE:
sl@0
  2278
		{
sl@0
  2279
		TInt newX, newY;
sl@0
  2280
		systemIni->TranslateMouseCoords(CurrentFlipState[0], aXpos, aYpos, systemIni->iScreens[0]->iXYInputWidth, systemIni->iScreens[0]->iXYInputHeight, newX, newY);
sl@0
  2281
sl@0
  2282
		if (aPointerId == 0)
sl@0
  2283
			{ // only system pointer changes shape
sl@0
  2284
		if (systemIni->GetVirtualKey(command, newX, newY) >= 0)
sl@0
  2285
			{
sl@0
  2286
			HMODULE hmodule = GetModuleHandleA("winsgui.dll");
sl@0
  2287
			SetCursor(LoadCursorA((HINSTANCE)hmodule,MAKEINTRESOURCEA(OVERKEY)));		//hand cursor
sl@0
  2288
			}
sl@0
  2289
		else
sl@0
  2290
			SetCursor(LoadCursorA(NULL,MAKEINTRESOURCEA(32512))); //ICD_ARROW
sl@0
  2291
				}
sl@0
  2292
sl@0
  2293
		eventType=TRawEvent::EPointerMove;
sl@0
  2294
		
sl@0
  2295
		}
sl@0
  2296
		break;
sl@0
  2297
	case WM_LBUTTONDOWN:
sl@0
  2298
		{
sl@0
  2299
		SetCapture(TheWin[0]);
sl@0
  2300
		//check the configuration
sl@0
  2301
		TInt newX, newY;
sl@0
  2302
		
sl@0
  2303
		//if the emulator screen is rotated, rotate/flip the current mouse cursor position
sl@0
  2304
		//so it can be checked to see if it is in a key region.
sl@0
  2305
		systemIni->TranslateMouseCoords(CurrentFlipState[0], aXpos, aYpos, systemIni->iScreens[0]->iXYInputWidth, systemIni->iScreens[0]->iXYInputHeight, newX, newY);
sl@0
  2306
		commandData = systemIni->GetVirtualKey(command, newX, newY);
sl@0
  2307
		
sl@0
  2308
		if (commandData >= 0)
sl@0
  2309
			{
sl@0
  2310
			eventType=TRawEvent::EKeyDown;
sl@0
  2311
			mouseEvent = EFalse;
sl@0
  2312
			systemIni->SetVirtualKey(ETrue, commandData, command);
sl@0
  2313
			}
sl@0
  2314
		else
sl@0
  2315
			eventType=TRawEvent::EButton1Down;
sl@0
  2316
		}
sl@0
  2317
		break;
sl@0
  2318
	case WM_LBUTTONUP:
sl@0
  2319
		ReleaseCapture();
sl@0
  2320
		if (processingScreenOn)
sl@0
  2321
			{
sl@0
  2322
			// ignore button up - button down was switching things on
sl@0
  2323
			processingScreenOn=FALSE;
sl@0
  2324
			return;
sl@0
  2325
			}
sl@0
  2326
		if (systemIni->WasVirtualKey(commandData, command))
sl@0
  2327
			{
sl@0
  2328
			eventType=TRawEvent::EKeyUp;
sl@0
  2329
			mouseEvent = EFalse;
sl@0
  2330
			systemIni->SetVirtualKey(EFalse, EStdKeyNull, ENoCommand);
sl@0
  2331
			}
sl@0
  2332
		else
sl@0
  2333
			eventType=TRawEvent::EButton1Up;
sl@0
  2334
		break;
sl@0
  2335
	case WM_RBUTTONDOWN:
sl@0
  2336
		eventType=TRawEvent::EButton3Down;
sl@0
  2337
		break;
sl@0
  2338
	case WM_RBUTTONUP:
sl@0
  2339
		eventType=TRawEvent::EButton3Up;
sl@0
  2340
		break;
sl@0
  2341
	case WM_MBUTTONDOWN:
sl@0
  2342
		eventType=TRawEvent::EButton2Down;
sl@0
  2343
		break;
sl@0
  2344
	case WM_MBUTTONUP:
sl@0
  2345
		eventType=TRawEvent::EButton2Up;
sl@0
  2346
		break;
sl@0
  2347
		}
sl@0
  2348
	if (mouseEvent)
sl@0
  2349
		{
sl@0
  2350
		
sl@0
  2351
		if (!WinsGuiPowerHandler->iStandby)
sl@0
  2352
			{
sl@0
  2353
			/*
sl@0
  2354
			mouse events are relative to the child window position
sl@0
  2355
			and are clipped to the digitzer region in addMouseEvent
sl@0
  2356
			so all the mouse clicks are passed on here after being translated 
sl@0
  2357
			to the child window coordinate system (under the current rotation)
sl@0
  2358
			*/
sl@0
  2359
			TInt newX, newY;
sl@0
  2360
			switch (CurrentFlipState[0])
sl@0
  2361
				{
sl@0
  2362
				case EEmulatorFlipRestore:
sl@0
  2363
				default:
sl@0
  2364
					newX = aXpos - systemIni->iScreens[0]->iScreenOffsetX;
sl@0
  2365
					newY = aYpos - systemIni->iScreens[0]->iScreenOffsetY;
sl@0
  2366
					break;
sl@0
  2367
				case EEmulatorFlipInvert:
sl@0
  2368
					newX = aXpos - (systemIni->iScreens[0]->iXYInputWidth - systemIni->iScreens[0]->iScreenWidth - systemIni->iScreens[0]->iScreenOffsetX);
sl@0
  2369
					newY = aYpos - (systemIni->iScreens[0]->iXYInputHeight - systemIni->iScreens[0]->iScreenHeight - systemIni->iScreens[0]->iScreenOffsetY);
sl@0
  2370
					break;
sl@0
  2371
				case EEmulatorFlipLeft:
sl@0
  2372
					newX = aXpos - systemIni->iScreens[0]->iScreenOffsetY;
sl@0
  2373
					newY = aYpos - (systemIni->iScreens[0]->iXYInputWidth - systemIni->iScreens[0]->iScreenWidth - systemIni->iScreens[0]->iScreenOffsetX);
sl@0
  2374
					break;	
sl@0
  2375
				case EEmulatorFlipRight:
sl@0
  2376
					newX = aXpos - (systemIni->iScreens[0]->iXYInputHeight - systemIni->iScreens[0]->iScreenHeight - systemIni->iScreens[0]->iScreenOffsetY);
sl@0
  2377
					newY = aYpos - systemIni->iScreens[0]->iScreenOffsetX;
sl@0
  2378
					break;
sl@0
  2379
				}
sl@0
  2380
			addMouseEvent(eventType, newX, newY);
sl@0
  2381
			}
sl@0
  2382
		}
sl@0
  2383
	else if ((((message == WM_LBUTTONDOWN && command == EKey) && !ProcessedByEmulatorKey((TUint8)commandData,0,0,0,0)))
sl@0
  2384
			|| (message == WM_LBUTTONUP))
sl@0
  2385
		{
sl@0
  2386
			switch (command)
sl@0
  2387
			{
sl@0
  2388
			case EKey:
sl@0
  2389
				if (!WinsGuiPowerHandler->iStandby)
sl@0
  2390
					addKeyEvent(eventType, (TUint8)commandData);
sl@0
  2391
				break;
sl@0
  2392
sl@0
  2393
			case ENextConfig:
sl@0
  2394
				NextConfiguration();
sl@0
  2395
				break;
sl@0
  2396
			
sl@0
  2397
			case ESelectConfig:
sl@0
  2398
				SwitchConfiguration(commandData);
sl@0
  2399
				break;
sl@0
  2400
			}
sl@0
  2401
		}
sl@0
  2402
	}
sl@0
  2403
sl@0
  2404
LOCAL_C TInt ScreenFromHWND(HWND aHwnd,HWND* pWin)
sl@0
  2405
	{
sl@0
  2406
	TInt screens=systemIni->iScreens.Count();
sl@0
  2407
	TInt r=-1;
sl@0
  2408
	for(TInt i=0;i<screens;i++)
sl@0
  2409
		{
sl@0
  2410
		if(pWin[i]==aHwnd)
sl@0
  2411
			{
sl@0
  2412
			r=i;
sl@0
  2413
			break;
sl@0
  2414
			}
sl@0
  2415
		}
sl@0
  2416
	return r;
sl@0
  2417
	}
sl@0
  2418
void MultiTouchWndPointer(TUint message,TInt aXpos,TInt aYpos, TInt aZ, TInt aPointerId)
sl@0
  2419
	{
sl@0
  2420
	WINDOWINFO info;
sl@0
  2421
	info.cbSize = sizeof(WINDOWINFO);
sl@0
  2422
	if (GetWindowInfo(TheWin[0], &info))
sl@0
  2423
		{
sl@0
  2424
		POINT pt = {aXpos,aYpos};
sl@0
  2425
		if (PtInRect(&info.rcWindow,pt))
sl@0
  2426
			{
sl@0
  2427
			RECT client;
sl@0
  2428
			if (GetWindowRect(TheChildWin[0], &client) && PtInRect(&client,pt))	// within the window
sl@0
  2429
				{
sl@0
  2430
				MultiChildWndPointer(message, aXpos-client.left, aYpos-client.top, aZ, aPointerId);
sl@0
  2431
				}
sl@0
  2432
			else  
sl@0
  2433
				{		
sl@0
  2434
				//	Disable the multitouch if the cursor is outside the application window
sl@0
  2435
				if (DMultiTouch::iMultiTouchTempEnabled)	// within the window
sl@0
  2436
					{
sl@0
  2437
					DMultiTouch::iMultiTouchTempEnabled = FALSE;
sl@0
  2438
					if(TheMultiTouch->UnRegister())
sl@0
  2439
						{
sl@0
  2440
						SetWindowPos(hwndStatus,0,0,0,0,0,SWP_HIDEWINDOW);
sl@0
  2441
						}
sl@0
  2442
					}
sl@0
  2443
				FrameWndPointer(message, aXpos-info.rcClient.left, aYpos-info.rcClient.top, 0, aPointerId);	
sl@0
  2444
				}
sl@0
  2445
			}
sl@0
  2446
		}
sl@0
  2447
	}
sl@0
  2448
sl@0
  2449
LOCAL_C DScreenProperties* ScreenPropsFromHWND(HWND aHwnd, HWND* pWin)
sl@0
  2450
	{
sl@0
  2451
	TInt screenNumber =  ScreenFromHWND(aHwnd, pWin);
sl@0
  2452
	
sl@0
  2453
	if(screenNumber >=0)
sl@0
  2454
		{
sl@0
  2455
		return systemIni->iScreens[screenNumber];
sl@0
  2456
		}
sl@0
  2457
	return NULL;
sl@0
  2458
sl@0
  2459
	}
sl@0
  2460
sl@0
  2461
sl@0
  2462
TInt APIENTRY childWinProc(HWND hWnd,TUint message,TUint wParam,TUint lParam)
sl@0
  2463
//
sl@0
  2464
// The child window function.
sl@0
  2465
//
sl@0
  2466
	{
sl@0
  2467
	TInt screenNumber = 0;
sl@0
  2468
	TRawEvent v;
sl@0
  2469
    switch (message)
sl@0
  2470
    	{
sl@0
  2471
	case WM_FLIP_MESSAGE: // pass the flip message onto the parent window
sl@0
  2472
		{
sl@0
  2473
		screenNumber =ScreenFromHWND(hWnd,TheChildWin);
sl@0
  2474
		if(TUint(screenNumber) < TUint(systemIni->iScreens.Count()))
sl@0
  2475
			PostMessageA(TheWin[screenNumber],WM_FLIP_MESSAGE,wParam,NULL);
sl@0
  2476
		break;
sl@0
  2477
		}
sl@0
  2478
	case WM_LBUTTONDOWN:
sl@0
  2479
	case WM_LBUTTONUP:
sl@0
  2480
	case WM_MOUSEMOVE:
sl@0
  2481
	case WM_RBUTTONDOWN:
sl@0
  2482
	case WM_RBUTTONUP:
sl@0
  2483
	case WM_MBUTTONDOWN:
sl@0
  2484
	case WM_MBUTTONUP:
sl@0
  2485
		{
sl@0
  2486
		if (DMultiTouch::iMultiTouchTempEnabled)
sl@0
  2487
			{
sl@0
  2488
			DMultiTouch::iMultiTouchTempEnabled = FALSE;
sl@0
  2489
			}
sl@0
  2490
		screenNumber=ScreenFromHWND(hWnd,TheChildWin);
sl@0
  2491
		if(screenNumber==0)
sl@0
  2492
			{
sl@0
  2493
			ChildWndPointer(message,(TInt16)(lParam&0xFFFF),(TInt16)((lParam>>16)&0xFFFF));
sl@0
  2494
			}
sl@0
  2495
		break;
sl@0
  2496
		}
sl@0
  2497
    case WM_PAINT:
sl@0
  2498
		if (!PaintWindowFromBuffer(hWnd))
sl@0
  2499
			{
sl@0
  2500
			// Original behaviour
sl@0
  2501
			ValidateRect(hWnd,NULL);
sl@0
  2502
			v.Set(TRawEvent::ERedraw);
sl@0
  2503
			TheEventQ.Add(v);
sl@0
  2504
			}
sl@0
  2505
        break;
sl@0
  2506
    case WM_ACTIVATE:
sl@0
  2507
	case WM_SYSKEYDOWN:
sl@0
  2508
	case WM_KEYDOWN:
sl@0
  2509
	case WM_SYSKEYUP:
sl@0
  2510
	case WM_KEYUP:
sl@0
  2511
		Fault(EGuiChildWinProc);
sl@0
  2512
		break;
sl@0
  2513
    case WM_DESTROY:
sl@0
  2514
		break;
sl@0
  2515
sl@0
  2516
	case WM_CHAR:
sl@0
  2517
	case WM_SYSCHAR:
sl@0
  2518
	case WM_DEADCHAR:
sl@0
  2519
	case WM_SYSDEADCHAR:
sl@0
  2520
        break;
sl@0
  2521
sl@0
  2522
	case WMU_SET_DISPLAY_BUFFER:
sl@0
  2523
		screenNumber = ScreenFromHWND(hWnd, TheChildWin);
sl@0
  2524
		if (TUint(screenNumber) < TUint(systemIni->iScreens.Count()))
sl@0
  2525
			{
sl@0
  2526
			masterIni->iBufferSet[screenNumber].iDisplayBuffer = (LPVOID)lParam;
sl@0
  2527
			}
sl@0
  2528
		break;
sl@0
  2529
	case WMU_SET_DISPLAY_SIZE:
sl@0
  2530
		screenNumber = ScreenFromHWND(hWnd, TheChildWin);
sl@0
  2531
		masterIni->SetDisplaySize(screenNumber, wParam, lParam);
sl@0
  2532
		break;
sl@0
  2533
		
sl@0
  2534
	case WMU_SET_BUFFER_FORMAT:
sl@0
  2535
		screenNumber = ScreenFromHWND(hWnd, TheChildWin);
sl@0
  2536
		masterIni->SetBufferFormat(screenNumber, wParam, (RDisplayChannel::TPixelFormat) lParam);
sl@0
  2537
		break;
sl@0
  2538
		
sl@0
  2539
 	default:
sl@0
  2540
        return(DefWindowProcA(hWnd,message,wParam,lParam));
sl@0
  2541
	    }
sl@0
  2542
    return(FALSE);
sl@0
  2543
	}
sl@0
  2544
sl@0
  2545
sl@0
  2546
LOCAL_C TBool PaintWindowFromBuffer(HWND hWnd)
sl@0
  2547
	{
sl@0
  2548
	TInt screenNumber = ScreenFromHWND(hWnd,TheChildWin);
sl@0
  2549
	if (TUint(screenNumber) >= TUint(masterIni->iBufferSet.Count()))
sl@0
  2550
		{
sl@0
  2551
		return EFalse;
sl@0
  2552
		}
sl@0
  2553
sl@0
  2554
	LPVOID displayBuffer = masterIni->iBufferSet[screenNumber].iDisplayBuffer;
sl@0
  2555
	if (!displayBuffer)
sl@0
  2556
		{
sl@0
  2557
		return EFalse;
sl@0
  2558
		}
sl@0
  2559
sl@0
  2560
	TInt   frameOffset = masterIni->iBufferSet[screenNumber].iScreenBuffer.iDisplayBufferOffset;
sl@0
  2561
	displayBuffer=LPVOID(frameOffset+(char*)displayBuffer);
sl@0
  2562
sl@0
  2563
	PAINTSTRUCT ps;
sl@0
  2564
	BeginPaint(hWnd, &ps);
sl@0
  2565
sl@0
  2566
	// Paint directly from the buffer to the window
sl@0
  2567
	LPBITMAPINFO info = (LPBITMAPINFO)&masterIni->iBufferSet[screenNumber].iInfo;
sl@0
  2568
	WORD width = (WORD)info->bmiHeader.biWidth;
sl@0
  2569
	WORD height = (WORD)-info->bmiHeader.biHeight;	// stored -ve in info
sl@0
  2570
	SetDIBitsToDevice(ps.hdc,
sl@0
  2571
						0, 0, 	// Dst X, Y
sl@0
  2572
						width, height,	// Src W, H
sl@0
  2573
						0, 0,	// Src X, Y
sl@0
  2574
						0,		// Src offset to first line
sl@0
  2575
						height,	// Src lines available
sl@0
  2576
						displayBuffer,	// Src pointer to pixels
sl@0
  2577
						info,			// Src info
sl@0
  2578
						DIB_RGB_COLORS);
sl@0
  2579
sl@0
  2580
	EndPaint(hWnd, &ps);
sl@0
  2581
sl@0
  2582
	return TRUE;
sl@0
  2583
	}
sl@0
  2584
sl@0
  2585
sl@0
  2586
LOCAL_C void CalcTextPos(TInt aScreen, TInt& aX, TInt& aY)
sl@0
  2587
	{
sl@0
  2588
	switch (CurrentFlipState[aScreen])
sl@0
  2589
		{
sl@0
  2590
	case EEmulatorFlipInvert:
sl@0
  2591
		aX = systemIni->iScreens[aScreen]->iXYInputWidth-(systemIni->iScreens[aScreen]->iScreenOffsetX+systemIni->iScreens[aScreen]->iScreenWidth);
sl@0
  2592
		aY = systemIni->iScreens[aScreen]->iXYInputHeight-(systemIni->iScreens[aScreen]->iScreenOffsetY+systemIni->iScreens[aScreen]->iScreenHeight);
sl@0
  2593
		break;
sl@0
  2594
	case EEmulatorFlipLeft:
sl@0
  2595
		aX = systemIni->iScreens[aScreen]->iScreenOffsetY;
sl@0
  2596
		aY = systemIni->iScreens[aScreen]->iXYInputWidth-(systemIni->iScreens[aScreen]->iScreenOffsetX+systemIni->iScreens[aScreen]->iScreenWidth);
sl@0
  2597
		break;
sl@0
  2598
	case EEmulatorFlipRight:
sl@0
  2599
		aX = systemIni->iScreens[aScreen]->iXYInputHeight-(systemIni->iScreens[aScreen]->iScreenOffsetY+systemIni->iScreens[aScreen]->iScreenHeight);
sl@0
  2600
		aY = systemIni->iScreens[aScreen]->iScreenOffsetX;
sl@0
  2601
		break;
sl@0
  2602
	case EEmulatorFlipRestore:
sl@0
  2603
	default:
sl@0
  2604
		aX = systemIni->iScreens[aScreen]->iScreenOffsetX;
sl@0
  2605
		aY = systemIni->iScreens[aScreen]->iScreenOffsetY;
sl@0
  2606
	break;
sl@0
  2607
		}
sl@0
  2608
	//subtract viewport offset here
sl@0
  2609
	aX -= systemIni->iScreens[aScreen]->iViewport.GetViewportOffsetX();
sl@0
  2610
	aY -= systemIni->iScreens[aScreen]->iViewport.GetViewportOffsetY();
sl@0
  2611
	}
sl@0
  2612
sl@0
  2613
TInt APIENTRY ctrlwinProc(HWND hWnd,TUint message,TUint wParam,TUint lParam)
sl@0
  2614
//
sl@0
  2615
// The control window function
sl@0
  2616
//
sl@0
  2617
	{
sl@0
  2618
	switch(message)
sl@0
  2619
	{
sl@0
  2620
		case WM_SYSCOMMAND:
sl@0
  2621
			{
sl@0
  2622
				switch(wParam)
sl@0
  2623
				{
sl@0
  2624
					case 1:
sl@0
  2625
						{
sl@0
  2626
						NextConfiguration();
sl@0
  2627
						return 0;
sl@0
  2628
						}
sl@0
  2629
					case SC_MINIMIZE:
sl@0
  2630
					case SC_RESTORE:
sl@0
  2631
						{
sl@0
  2632
						if (wParam == SC_RESTORE) 
sl@0
  2633
							Active();
sl@0
  2634
						for(TInt ix=0;ix<systemIni->iScreens.Count();ix++)
sl@0
  2635
							{
sl@0
  2636
							SendMessage(TheWin[ix],message,wParam,lParam);
sl@0
  2637
							}
sl@0
  2638
						if (wParam == SC_MINIMIZE) 
sl@0
  2639
							Inactive();
sl@0
  2640
						}			
sl@0
  2641
				}
sl@0
  2642
				return(DefWindowProcA(hWnd,message,wParam,lParam));
sl@0
  2643
			}
sl@0
  2644
		case WM_CLOSE: // tell all emulator screen windows to close
sl@0
  2645
			{
sl@0
  2646
			for(TInt i=0;i<systemIni->iScreens.Count();i++)
sl@0
  2647
				{
sl@0
  2648
				DestroyWindow(TheWin[i]);
sl@0
  2649
				}
sl@0
  2650
			DestroyWindow(hWnd);
sl@0
  2651
			break;
sl@0
  2652
			}
sl@0
  2653
		case WM_DESTROY:
sl@0
  2654
			{
sl@0
  2655
			// save the main window position information
sl@0
  2656
			HANDLE hSysIni;
sl@0
  2657
			hSysIni = CreateFileA(systemIni->iSysIniFileName, GENERIC_WRITE, 0, 0, CREATE_ALWAYS, 0, 0);
sl@0
  2658
			DScreenProperties* screenProps;
sl@0
  2659
			if (hSysIni != INVALID_HANDLE_VALUE)
sl@0
  2660
				{
sl@0
  2661
				DWORD numWritten;
sl@0
  2662
				//write an identifier into file so that program can avoid loading old version
sl@0
  2663
				WriteFile(hSysIni, &KDatFileVersion, sizeof(TInt), &numWritten, 0);
sl@0
  2664
				
sl@0
  2665
				//record current configuration at start of file.
sl@0
  2666
				WriteFile(hSysIni, &CurrentConfiguration, sizeof(TInt), &numWritten, 0);
sl@0
  2667
				
sl@0
  2668
				//Write out the state for each window.
sl@0
  2669
				for(TInt i=0;i<systemIni->iScreens.Count();i++)
sl@0
  2670
					{
sl@0
  2671
					screenProps= systemIni->iScreens[i];
sl@0
  2672
					
sl@0
  2673
					TWindowState winState= screenProps->GetWindowState();
sl@0
  2674
					WriteFile(hSysIni, &winState, sizeof(TWindowState), &numWritten, 0);
sl@0
  2675
					
sl@0
  2676
					
sl@0
  2677
					}
sl@0
  2678
				}
sl@0
  2679
			CloseHandle(hSysIni);
sl@0
  2680
sl@0
  2681
			PostQuitMessage(KErrNone);
sl@0
  2682
			break;
sl@0
  2683
			}
sl@0
  2684
		case WM_INPUT:
sl@0
  2685
			{
sl@0
  2686
			if (!DMultiTouch::iMultiTouchTempEnabled)
sl@0
  2687
				{
sl@0
  2688
				for(TInt ix=0;ix<systemIni->iScreens.Count();ix++)
sl@0
  2689
					{
sl@0
  2690
					DMultiTouch::iMultiTouchTempEnabled = TRUE;
sl@0
  2691
sl@0
  2692
					SendMessage(TheWin[ix],message,wParam,lParam);
sl@0
  2693
					}
sl@0
  2694
				}
sl@0
  2695
			else if (systemIni->MultiTouchEnabled() && DMultiTouch::iMultiTouchSupported && systemIni->GCEEnabled())
sl@0
  2696
				{
sl@0
  2697
			   	TheMultiTouch->OnWmInput(hWnd, message, wParam, lParam,TheChildWin[0]);	
sl@0
  2698
				}
sl@0
  2699
			else
sl@0
  2700
				{
sl@0
  2701
				Fault(EGuiInvalidMultiTouch);
sl@0
  2702
				}
sl@0
  2703
		   	break;
sl@0
  2704
			}	
sl@0
  2705
		default:
sl@0
  2706
			return(DefWindowProcA(hWnd,message,wParam,lParam));
sl@0
  2707
	}
sl@0
  2708
	return(FALSE);
sl@0
  2709
	}
sl@0
  2710
sl@0
  2711
TInt APIENTRY winProc(HWND hWnd,TUint message,TUint wParam,TUint lParam)
sl@0
  2712
//
sl@0
  2713
// The border window function.
sl@0
  2714
//
sl@0
  2715
	{
sl@0
  2716
sl@0
  2717
	TRawEvent v;
sl@0
  2718
	
sl@0
  2719
	switch (message)
sl@0
  2720
    	{
sl@0
  2721
		case WM_GETMINMAXINFO:
sl@0
  2722
			{
sl@0
  2723
			DScreenProperties* screenProps = ScreenPropsFromHWND(hWnd, TheWin);
sl@0
  2724
			if(screenProps == NULL)
sl@0
  2725
				{
sl@0
  2726
				return DefWindowProcA(hWnd, message, wParam, lParam);
sl@0
  2727
				}
sl@0
  2728
						
sl@0
  2729
			MINMAXINFO* minMaxInfo = reinterpret_cast<MINMAXINFO*>(lParam);
sl@0
  2730
			minMaxInfo->ptMaxTrackSize.x = screenProps->iViewport.GetMaxWindowWidth();
sl@0
  2731
			minMaxInfo->ptMaxTrackSize.y = screenProps->iViewport.GetMaxWindowHeight();
sl@0
  2732
sl@0
  2733
			minMaxInfo->ptMaxSize.x = minMaxInfo->ptMaxTrackSize.x;
sl@0
  2734
			minMaxInfo->ptMaxSize.y = minMaxInfo->ptMaxTrackSize.y;
sl@0
  2735
			DefWindowProcA(hWnd, message, wParam, lParam);
sl@0
  2736
			
sl@0
  2737
			break;
sl@0
  2738
			}
sl@0
  2739
	   
sl@0
  2740
    	    		
sl@0
  2741
 	    	
sl@0
  2742
    	case WM_SIZE:
sl@0
  2743
    		{
sl@0
  2744
    		DScreenProperties* screenProps = ScreenPropsFromHWND(hWnd, TheWin);
sl@0
  2745
			if(screenProps == NULL)
sl@0
  2746
				{
sl@0
  2747
				return DefWindowProcA(hWnd, message, wParam, lParam);
sl@0
  2748
				}
sl@0
  2749
    		TViewport& viewport = screenProps->iViewport;
sl@0
  2750
    		//update size of viewport
sl@0
  2751
    		viewport.SetViewportWidth(LOWORD(lParam));
sl@0
  2752
    		viewport.SetViewportHeight(HIWORD(lParam));
sl@0
  2753
    		
sl@0
  2754
    		
sl@0
  2755
			//If resize goes beyond boundary of emulator then scroll to compensate
sl@0
  2756
			TInt ox = viewport.GetViewportOffsetX();
sl@0
  2757
    		TInt xs = ox + LOWORD(lParam) - viewport.GetMaxWidth();
sl@0
  2758
    		if (xs>0) 
sl@0
  2759
    			{    			
sl@0
  2760
    			viewport.ScrollToX(ox-xs, hWnd);
sl@0
  2761
    			}
sl@0
  2762
    		
sl@0
  2763
    		TInt oy = viewport.GetViewportOffsetY();
sl@0
  2764
    		TInt ys = oy + HIWORD(lParam) - viewport.GetMaxHeight();
sl@0
  2765
    		if (ys>0) 
sl@0
  2766
    			{    			
sl@0
  2767
    			viewport.ScrollToY(oy-ys, hWnd);
sl@0
  2768
    			}
sl@0
  2769
    	
sl@0
  2770
    		//Adjust ranges of scroll bars
sl@0
  2771
    	   	viewport.UpdateScrollBarH(hWnd);
sl@0
  2772
    		viewport.UpdateScrollBarV(hWnd);
sl@0
  2773
    		    		
sl@0
  2774
    		
sl@0
  2775
    		
sl@0
  2776
    		break;    		
sl@0
  2777
    		}
sl@0
  2778
    	case WM_HSCROLL:
sl@0
  2779
    		{
sl@0
  2780
    		DScreenProperties* screenProps = ScreenPropsFromHWND(hWnd, TheWin);
sl@0
  2781
			if(screenProps == NULL)
sl@0
  2782
				{
sl@0
  2783
				return DefWindowProcA(hWnd, message, wParam, lParam);
sl@0
  2784
				}
sl@0
  2785
    		TViewport& viewport = screenProps->iViewport;
sl@0
  2786
    		
sl@0
  2787
    		switch (LOWORD(wParam)) 
sl@0
  2788
    			{
sl@0
  2789
    			case SB_THUMBTRACK:
sl@0
  2790
    				{
sl@0
  2791
    				viewport.ScrollToX(HIWORD(wParam),hWnd);
sl@0
  2792
    				break;
sl@0
  2793
    				}
sl@0
  2794
				case SB_PAGELEFT:
sl@0
  2795
					{
sl@0
  2796
					viewport.ScrollToX(viewport.GetViewportOffsetX() - viewport.GetViewportWidth(), hWnd );
sl@0
  2797
					break;
sl@0
  2798
					}
sl@0
  2799
				case SB_PAGERIGHT:
sl@0
  2800
					{
sl@0
  2801
					viewport.ScrollToX(viewport.GetViewportOffsetX() + viewport.GetViewportWidth() , hWnd);
sl@0
  2802
					break;
sl@0
  2803
					}
sl@0
  2804
				case SB_LINEUP:
sl@0
  2805
					{
sl@0
  2806
					viewport.ScrollToX(viewport.GetViewportOffsetX() - 1, hWnd);
sl@0
  2807
					break;
sl@0
  2808
					}
sl@0
  2809
				case SB_LINEDOWN:
sl@0
  2810
					{
sl@0
  2811
					viewport.ScrollToX(viewport.GetViewportOffsetX() + 1, hWnd);
sl@0
  2812
					break;
sl@0
  2813
					}
sl@0
  2814
    			
sl@0
  2815
    			}
sl@0
  2816
    		   		
sl@0
  2817
   
sl@0
  2818
    		break;
sl@0
  2819
    		}
sl@0
  2820
    	
sl@0
  2821
    	case WM_VSCROLL:
sl@0
  2822
    		{
sl@0
  2823
    		DScreenProperties* screenProps = ScreenPropsFromHWND(hWnd, TheWin);
sl@0
  2824
			if(screenProps == NULL)
sl@0
  2825
				{
sl@0
  2826
				return DefWindowProcA(hWnd, message, wParam, lParam);
sl@0
  2827
				}
sl@0
  2828
    		TViewport& viewport = screenProps->iViewport;
sl@0
  2829
    		
sl@0
  2830
			
sl@0
  2831
			switch (LOWORD(wParam)) 
sl@0
  2832
    			{
sl@0
  2833
    			case SB_THUMBTRACK:
sl@0
  2834
    				{
sl@0
  2835
    				viewport.ScrollToY(HIWORD(wParam), hWnd);
sl@0
  2836
    				break;
sl@0
  2837
    				}
sl@0
  2838
				case SB_PAGELEFT:
sl@0
  2839
					{
sl@0
  2840
					viewport.ScrollToY(viewport.GetViewportOffsetY() - viewport.GetViewportHeight() , hWnd);
sl@0
  2841
					break;
sl@0
  2842
					}
sl@0
  2843
				case SB_PAGERIGHT:
sl@0
  2844
					{
sl@0
  2845
					viewport.ScrollToY(viewport.GetViewportOffsetY() + viewport.GetViewportHeight(), hWnd );
sl@0
  2846
					break;
sl@0
  2847
					}
sl@0
  2848
				case SB_LINEUP:
sl@0
  2849
					{
sl@0
  2850
					viewport.ScrollToY(viewport.GetViewportOffsetY() - 1, hWnd);
sl@0
  2851
					break;
sl@0
  2852
					}
sl@0
  2853
				case SB_LINEDOWN:
sl@0
  2854
					{
sl@0
  2855
					viewport.ScrollToY(viewport.GetViewportOffsetY() + 1, hWnd);
sl@0
  2856
					break;
sl@0
  2857
					}
sl@0
  2858
    			
sl@0
  2859
    			}
sl@0
  2860
    		
sl@0
  2861
    		break;
sl@0
  2862
    		
sl@0
  2863
    		}
sl@0
  2864
    	
sl@0
  2865
    	 		
sl@0
  2866
		case WM_FLIP_MESSAGE:
sl@0
  2867
			{
sl@0
  2868
			DScreenProperties* screenProps = ScreenPropsFromHWND(hWnd, TheWin);
sl@0
  2869
			if(screenProps == NULL)
sl@0
  2870
				{
sl@0
  2871
				return DefWindowProcA(hWnd, message, wParam, lParam);
sl@0
  2872
sl@0
  2873
				}
sl@0
  2874
			
sl@0
  2875
			TViewport& viewport = screenProps->iViewport;
sl@0
  2876
			RECT windowRect={0,0,0,0};
sl@0
  2877
			GetClientRect(hWnd, &windowRect);
sl@0
  2878
			
sl@0
  2879
			TInt screenNumber=ScreenFromHWND(hWnd,TheWin);
sl@0
  2880
			if(TUint(screenNumber) >= TUint(systemIni->iScreens.Count()))
sl@0
  2881
				break;
sl@0
  2882
			PBITMAPV4HEADER info = &masterIni->iBufferSet[screenNumber].iInfo;
sl@0
  2883
			CurrentFlipState[screenNumber]=(TEmulatorFlip)wParam;
sl@0
  2884
			TBufferSet* bufferSet = &masterIni->iBufferSet[screenNumber];
sl@0
  2885
			switch (CurrentFlipState[screenNumber])
sl@0
  2886
				{
sl@0
  2887
				case EEmulatorFlipRestore:
sl@0
  2888
				case EEmulatorFlipInvert:
sl@0
  2889
					windowRect.right=systemIni->iScreens[screenNumber]->iXYInputWidth;
sl@0
  2890
					windowRect.bottom=systemIni->iScreens[screenNumber]->iXYInputHeight;
sl@0
  2891
					info->bV4Width = bufferSet->iBufferFormat.iSize.iWidth;
sl@0
  2892
					info->bV4Height = -bufferSet->iBufferFormat.iSize.iHeight;
sl@0
  2893
					break;
sl@0
  2894
				case EEmulatorFlipLeft:
sl@0
  2895
				case EEmulatorFlipRight:
sl@0
  2896
					windowRect.right=systemIni->iScreens[screenNumber]->iXYInputHeight;
sl@0
  2897
					windowRect.bottom=systemIni->iScreens[screenNumber]->iXYInputWidth;
sl@0
  2898
					info->bV4Width = bufferSet->iBufferFormat.iSize.iHeight;
sl@0
  2899
					info->bV4Height = -bufferSet->iBufferFormat.iSize.iWidth;
sl@0
  2900
					break;
sl@0
  2901
				}
sl@0
  2902
			AdjustWindowRect(&windowRect,KWinStyle,FALSE);
sl@0
  2903
    		
sl@0
  2904
    		
sl@0
  2905
			viewport.ScrollToX(0, hWnd);
sl@0
  2906
			viewport.ScrollToY(0, hWnd);
sl@0
  2907
sl@0
  2908
			
sl@0
  2909
			screenProps->iScreenRotation = (TEmulatorFlip)wParam; 
sl@0
  2910
			
sl@0
  2911
						
sl@0
  2912
			RECT currentWindowRect;
sl@0
  2913
			GetWindowRect(hWnd,&currentWindowRect);
sl@0
  2914
			InvalidateRect(hWnd,NULL,FALSE);
sl@0
  2915
			MoveWindow(
sl@0
  2916
				TheWin[screenNumber],
sl@0
  2917
				max(currentWindowRect.left,0), // so the window doesn't disappear off the screen
sl@0
  2918
				max(currentWindowRect.top,0),
sl@0
  2919
				windowRect.right-windowRect.left,
sl@0
  2920
				windowRect.bottom-windowRect.top,
sl@0
  2921
				TRUE
sl@0
  2922
				);
sl@0
  2923
			// move the child window
sl@0
  2924
			screenProps->iViewport.UpdateChildPos(hWnd);
sl@0
  2925
			
sl@0
  2926
			viewport.UpdateScrollBarH(hWnd);
sl@0
  2927
    		viewport.UpdateScrollBarV(hWnd);
sl@0
  2928
sl@0
  2929
			InvalidateRect(hWnd,NULL,TRUE);
sl@0
  2930
			UpdateWindow(hWnd);
sl@0
  2931
			
sl@0
  2932
			break;
sl@0
  2933
			}
sl@0
  2934
		case WM_SYSKEYDOWN:
sl@0
  2935
		case WM_KEYDOWN:
sl@0
  2936
			if (!(HIWORD(lParam)&KF_REPEAT))
sl@0
  2937
				{
sl@0
  2938
				
sl@0
  2939
				
sl@0
  2940
				TUint scanCode=DWinsKeyboard::ScanCodeToStandardKey(HIWORD(lParam));
sl@0
  2941
				TUint newScanCode = systemIni->iKeyboard.ScanCodeToRemappedKey(HIWORD(lParam));
sl@0
  2942
				MSG msg={hWnd,message,wParam,lParam,GetMessageTime(),GetMessagePos()};
sl@0
  2943
				TranslateMessage(&msg);
sl@0
  2944
				TUint charCode=0;
sl@0
  2945
				// look in the message queue to get character associated with keypress
sl@0
  2946
				// so long as the control, shift and alt keys aren't depressed
sl@0
  2947
				if (!(HIBYTE(GetKeyState(VK_CONTROL)) && HIBYTE(GetKeyState(VK_MENU)) && HIBYTE(GetKeyState(VK_SHIFT))))
sl@0
  2948
					if (PeekMessageA(&msg,hWnd,WM_CHAR,WM_CHAR,PM_NOREMOVE) &&
sl@0
  2949
						scanCode == newScanCode) //no remapping
sl@0
  2950
						charCode=msg.wParam;
sl@0
  2951
				// Pass the character as the HIWORD of the Epoc scan code
sl@0
  2952
				
sl@0
  2953
				scanCode = newScanCode;
sl@0
  2954
				v.Set(TRawEvent::EKeyDown,(charCode<<16)|scanCode);
sl@0
  2955
				if (!ProcessedByEmulatorKey(scanCode,hWnd,message,wParam,lParam))
sl@0
  2956
   					TheEventQ.Add(v);
sl@0
  2957
				
sl@0
  2958
				}
sl@0
  2959
			break;
sl@0
  2960
		case WM_TIMER:
sl@0
  2961
			break;
sl@0
  2962
		case WM_EMUL_POWER_ON:
sl@0
  2963
			{
sl@0
  2964
			TInt screenNumber=ScreenFromHWND(hWnd,TheWin);
sl@0
  2965
			if(TUint(screenNumber) >= TUint(systemIni->iScreens.Count()))
sl@0
  2966
				break;
sl@0
  2967
//			HWND win = systemIni->iSecureDisplay ? TheSecureChildWin : TheChildWin;
sl@0
  2968
			HWND win = TheChildWin[screenNumber];
sl@0
  2969
			if (wParam==TRUE)
sl@0
  2970
				{
sl@0
  2971
				ShowWindow(win, SW_HIDE);
sl@0
  2972
				ShowWindow(win, SW_SHOWNORMAL);
sl@0
  2973
				if (SavedFlipMessage)
sl@0
  2974
					{
sl@0
  2975
					addKeyEvent(TRawEvent::EKeyDown, SavedFlipMessage);
sl@0
  2976
					addKeyEvent(TRawEvent::EKeyUp, SavedFlipMessage);
sl@0
  2977
					SavedFlipMessage = 0;
sl@0
  2978
					}
sl@0
  2979
				}
sl@0
  2980
			else
sl@0
  2981
				{
sl@0
  2982
				ShowWindow(win, SW_SHOWNORMAL);
sl@0
  2983
				ShowWindow(win, SW_HIDE);
sl@0
  2984
				}
sl@0
  2985
			}
sl@0
  2986
			break;
sl@0
  2987
		case WM_SYSKEYUP:
sl@0
  2988
		case WM_KEYUP:
sl@0
  2989
			{
sl@0
  2990
			//get the key code, this will pick up if it has been remapped or not.
sl@0
  2991
			TUint scanCode = systemIni->iKeyboard.ScanCodeToRemappedKey(HIWORD(lParam));
sl@0
  2992
	   /*
sl@0
  2993
		* We could do this to support generation of special characters using Alt+KeyPadNum
sl@0
  2994
		* combinations, but we would need to find a way to suppress the generation of
sl@0
  2995
		* home/end scancodes etc., so leave it for the moment.
sl@0
  2996
					MSG msg={hWnd,message,wParam,lParam,GetMessageTime(),GetMessagePos()};
sl@0
  2997
					TranslateMessage(&msg);
sl@0
  2998
					TUint charCode=0;
sl@0
  2999
					// look in the message queue to get character associated with keypress
sl@0
  3000
					if (PeekMessageU()(&msg,hWnd,WM_CHAR,WM_CHAR,PM_NOREMOVE))
sl@0
  3001
						charCode=msg.wParam;
sl@0
  3002
					// Pass the character as the HIWORD of the Epoc scan code
sl@0
  3003
					v.Set(TRawEvent::EKeyUp,(charCode<<16)|scanCode);
sl@0
  3004
		*/
sl@0
  3005
					v.Set(TRawEvent::EKeyUp,scanCode);
sl@0
  3006
	    			TheEventQ.Add(v);
sl@0
  3007
			break;
sl@0
  3008
			}
sl@0
  3009
		case WM_MOUSEMOVE:
sl@0
  3010
		case WM_LBUTTONDOWN:
sl@0
  3011
		case WM_LBUTTONUP:
sl@0
  3012
		case WM_RBUTTONDOWN:
sl@0
  3013
		case WM_RBUTTONUP:
sl@0
  3014
		case WM_MBUTTONDOWN:
sl@0
  3015
		case WM_MBUTTONUP:
sl@0
  3016
				{
sl@0
  3017
				//only handle mouse clicks on screen 0
sl@0
  3018
				TInt xpos=((TInt16)(lParam&0xffff));
sl@0
  3019
				TInt ypos = (TInt16)((lParam>>16)&0xFFFF);
sl@0
  3020
				if (DMultiTouch::iMultiTouchTempEnabled)
sl@0
  3021
					{
sl@0
  3022
					MultiChildWndPointer(message,xpos,ypos,0,0);
sl@0
  3023
					DMultiTouch::iMultiTouchTempEnabled = FALSE;				
sl@0
  3024
					}
sl@0
  3025
				else
sl@0
  3026
					{
sl@0
  3027
					TInt screenNumber=ScreenFromHWND(hWnd,TheWin);
sl@0
  3028
					if(screenNumber!=0)
sl@0
  3029
						break;
sl@0
  3030
					FrameWndPointer(message,xpos,ypos,screenNumber);
sl@0
  3031
					}
sl@0
  3032
				break;
sl@0
  3033
				}
sl@0
  3034
		case WM_PAINT:
sl@0
  3035
			{
sl@0
  3036
			DScreenProperties* screenProps = ScreenPropsFromHWND(hWnd, TheWin);
sl@0
  3037
			if(screenProps == NULL)
sl@0
  3038
				{
sl@0
  3039
				return DefWindowProcA(hWnd, message, wParam, lParam);
sl@0
  3040
				}
sl@0
  3041
    		TViewport& viewport = screenProps->iViewport;
sl@0
  3042
    		TInt screenNumber=ScreenFromHWND(hWnd,TheWin);
sl@0
  3043
sl@0
  3044
			PAINTSTRUCT p;
sl@0
  3045
sl@0
  3046
			BeginPaint(hWnd,&p);
sl@0
  3047
	   		HDC hdcBits;
sl@0
  3048
			BITMAP bm;
sl@0
  3049
    		hdcBits=CreateCompatibleDC(p.hdc);
sl@0
  3050
			GetObjectA(TheScreenBitmap[screenNumber],sizeof(BITMAP),&bm);
sl@0
  3051
    		SelectObject(hdcBits,TheScreenBitmap[screenNumber]);
sl@0
  3052
		
sl@0
  3053
			RECT windowRect;
sl@0
  3054
			GetClientRect(TheWin[screenNumber],&windowRect);
sl@0
  3055
			
sl@0
  3056
			viewport.SetViewportHeight(windowRect.bottom);
sl@0
  3057
			viewport.SetViewportWidth(windowRect.right);
sl@0
  3058
			
sl@0
  3059
			
sl@0
  3060
			switch (CurrentFlipState[screenNumber])
sl@0
  3061
				{
sl@0
  3062
				case EEmulatorFlipRestore:
sl@0
  3063
					{
sl@0
  3064
					BitBlt(p.hdc,0,0,windowRect.right,windowRect.bottom,hdcBits,
sl@0
  3065
						viewport.GetViewportOffsetX(),viewport.GetViewportOffsetY(),SRCCOPY);
sl@0
  3066
					break;
sl@0
  3067
					}
sl@0
  3068
				case EEmulatorFlipInvert:
sl@0
  3069
					{
sl@0
  3070
					TInt sourceX = screenProps->iXYInputWidth - viewport.GetViewportWidth() - viewport.GetViewportOffsetX();
sl@0
  3071
					if(sourceX<0)
sl@0
  3072
						sourceX=0;
sl@0
  3073
					TInt sourceY = screenProps->iXYInputHeight - viewport.GetViewportHeight() - viewport.GetViewportOffsetY();
sl@0
  3074
					if(sourceY<0)
sl@0
  3075
						sourceY=0;
sl@0
  3076
					TInt sourceWidth = viewport.GetMaxWidth()-sourceX - viewport.GetViewportOffsetX();
sl@0
  3077
					TInt sourceHeight = viewport.GetMaxHeight()-sourceY - viewport.GetViewportOffsetY();
sl@0
  3078
					
sl@0
  3079
					//when inverted it is necessary to translate the image by 1 pixel up and to the left,
sl@0
  3080
					//to avoid a glitch when scrolling using ScrollWindowEx()
sl@0
  3081
					POINT arrayPoints[3]={
sl@0
  3082
						{sourceWidth-1,sourceHeight-1},
sl@0
  3083
						{-1,sourceHeight-1},
sl@0
  3084
						{sourceWidth-1,-1}
sl@0
  3085
						};
sl@0
  3086
					PlgBlt(p.hdc,arrayPoints,hdcBits,sourceX,sourceY,sourceWidth,sourceHeight,NULL,NULL,NULL);
sl@0
  3087
					break;
sl@0
  3088
					}
sl@0
  3089
				case EEmulatorFlipLeft:
sl@0
  3090
					{
sl@0
  3091
					TInt offsetX = screenProps->iXYInputWidth- viewport.GetViewportHeight()  - viewport.GetViewportOffsetY(); 	
sl@0
  3092
					TInt offsetY = viewport.GetViewportOffsetX(); 	
sl@0
  3093
		
sl@0
  3094
					POINT arrayPoints[3]={{0,windowRect.bottom},{0,0},{windowRect.right,windowRect.bottom}};
sl@0
  3095
					PlgBlt(p.hdc,arrayPoints,hdcBits,offsetX,offsetY,viewport.GetViewportHeight(),viewport.GetViewportWidth(),NULL,NULL,NULL);
sl@0
  3096
					break;
sl@0
  3097
					}
sl@0
  3098
				case EEmulatorFlipRight:
sl@0
  3099
					{
sl@0
  3100
					TInt offsetX = viewport.GetViewportOffsetY(); 
sl@0
  3101
					TInt offsetY = screenProps->iXYInputHeight - viewport.GetViewportWidth() - viewport.GetViewportOffsetX(); 	
sl@0
  3102
									
sl@0
  3103
					POINT arrayPoints[3]={{windowRect.right,0},{windowRect.right,windowRect.bottom},{0,0}};
sl@0
  3104
					PlgBlt(p.hdc,arrayPoints,hdcBits,offsetX,offsetY,viewport.GetViewportHeight(),viewport.GetViewportWidth(),NULL,NULL,NULL);
sl@0
  3105
					break;
sl@0
  3106
					}
sl@0
  3107
				}
sl@0
  3108
sl@0
  3109
			
sl@0
  3110
			DeleteDC(hdcBits);
sl@0
  3111
			if (WinsGuiPowerHandler->iStandby)
sl@0
  3112
				{
sl@0
  3113
				TInt x,y;
sl@0
  3114
				CalcTextPos(screenNumber, x, y);
sl@0
  3115
				TextOutA(p.hdc, x, y, "Standby", 7);
sl@0
  3116
				}
sl@0
  3117
			else if (systemIni->iScreens[screenNumber]->iScreenOff)
sl@0
  3118
				{
sl@0
  3119
				TInt x,y;
sl@0
  3120
				CalcTextPos(screenNumber, x, y);
sl@0
  3121
				TextOutA(p.hdc, x, y, "Screen Off", 10);
sl@0
  3122
				}
sl@0
  3123
 			EndPaint(hWnd,&p);
sl@0
  3124
			break;
sl@0
  3125
			}
sl@0
  3126
		case WM_ACTIVATE:
sl@0
  3127
			//Added so that change in modifier keys can be detected without sending
sl@0
  3128
			//EActive/EInActive to wserv as it results in switching the timers
sl@0
  3129
   			if((wParam & 0xffff)!= WA_INACTIVE)
sl@0
  3130
   				UpdateModifiers();
sl@0
  3131
			break;
sl@0
  3132
		case WM_CHAR:
sl@0
  3133
		case WM_SYSCHAR:
sl@0
  3134
		case WM_DEADCHAR:
sl@0
  3135
		case WM_SYSDEADCHAR:
sl@0
  3136
			break;
sl@0
  3137
		case WM_CLOSE: //pass on message to control window, it will then destroy all e,ulator windows
sl@0
  3138
			SendMessage(TheControlWin,WM_CLOSE, NULL, NULL);
sl@0
  3139
			break;
sl@0
  3140
		case WM_DESTROY:
sl@0
  3141
			{
sl@0
  3142
			DScreenProperties* screenProps = ScreenPropsFromHWND(hWnd, TheWin);
sl@0
  3143
			if(screenProps == NULL)
sl@0
  3144
				{
sl@0
  3145
				return DefWindowProcA(hWnd, message, wParam, lParam);
sl@0
  3146
				}
sl@0
  3147
    					
sl@0
  3148
			// save window's position information
sl@0
  3149
			screenProps->iWinPlace.length = sizeof(WINDOWPLACEMENT);
sl@0
  3150
			GetWindowPlacement(hWnd, &screenProps->iWinPlace);
sl@0
  3151
			
sl@0
  3152
			break;
sl@0
  3153
			}
sl@0
  3154
		case WM_INPUT:
sl@0
  3155
			{
sl@0
  3156
			if (systemIni->MultiTouchEnabled() && DMultiTouch::iMultiTouchSupported && systemIni->GCEEnabled())
sl@0
  3157
				{
sl@0
  3158
				TInt screenNumber=ScreenFromHWND(hWnd,TheWin);
sl@0
  3159
				if(screenNumber==0)
sl@0
  3160
					{
sl@0
  3161
					TheMultiTouch->OnWmInput(hWnd, message, wParam, lParam,TheChildWin[screenNumber]);	
sl@0
  3162
					}
sl@0
  3163
				}
sl@0
  3164
			else
sl@0
  3165
				{
sl@0
  3166
				Fault(EGuiInvalidMultiTouch);
sl@0
  3167
				}
sl@0
  3168
		   	break;
sl@0
  3169
			}
sl@0
  3170
		default:
sl@0
  3171
	        return(DefWindowProcA(hWnd,message,wParam,lParam));
sl@0
  3172
	    }
sl@0
  3173
    return(FALSE);
sl@0
  3174
	
sl@0
  3175
	}
sl@0
  3176
sl@0
  3177
void SetStatusBarFont(HWND& aStatusBar)
sl@0
  3178
	{
sl@0
  3179
	int statwidths[] = {100,200,300,400,500,600,700,800};
sl@0
  3180
	SendMessage(aStatusBar, SB_SETPARTS, sizeof(statwidths)/sizeof(int), (LPARAM)statwidths);
sl@0
  3181
	HFONT hOrigFont = (HFONT) SendMessage(aStatusBar, WM_GETFONT, 0, 0);
sl@0
  3182
	SetProp(aStatusBar, TEXT("PROP_ORIGINAL_FONT"), (HANDLE) hOrigFont);
sl@0
  3183
	LOGFONT lf;
sl@0
  3184
	GetObject(hOrigFont, sizeof(lf), &lf);
sl@0
  3185
	lf.lfHeight = (long)(lf.lfHeight / 1.5);
sl@0
  3186
	lf.lfWeight = FW_NORMAL;
sl@0
  3187
	HFONT hFont = CreateFontIndirect(&lf);
sl@0
  3188
	SetProp(aStatusBar, TEXT("PROP_ITALIC_FONT"), (HANDLE) hFont);
sl@0
  3189
	hFont = (HFONT) GetProp(hwndStatus, TEXT("PROP_ITALIC_FONT"));
sl@0
  3190
	SendMessage(aStatusBar, WM_SETFONT, (WPARAM) hFont, FALSE);
sl@0
  3191
	}
sl@0
  3192
sl@0
  3193
DWORD WINAPI KernelWindowThread(LPVOID aArg)
sl@0
  3194
//
sl@0
  3195
// The kernel window thread.
sl@0
  3196
//
sl@0
  3197
	{
sl@0
  3198
	HMODULE hmodule = GetModuleHandleA("winsgui.dll");
sl@0
  3199
	__ASSERT_ALWAYS(hmodule!=NULL,Fault(EGuiGetModuleHandle));
sl@0
  3200
sl@0
  3201
	WNDCLASSA w;
sl@0
  3202
	memclr(&w, sizeof(WNDCLASSA));
sl@0
  3203
   	w.style=CS_OWNDC|CS_VREDRAW|CS_HREDRAW;
sl@0
  3204
   	w.lpfnWndProc=(WNDPROC)ctrlwinProc;
sl@0
  3205
   	w.hInstance=(HINSTANCE)aArg;
sl@0
  3206
   	w.hIcon=LoadIconA((HINSTANCE)hmodule,MAKEINTRESOURCEA(EPOC_ICON));
sl@0
  3207
   	w.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
sl@0
  3208
   	w.lpszClassName="E32KernelControlWindow";
sl@0
  3209
	
sl@0
  3210
	ATOM a=RegisterClassA(&w);
sl@0
  3211
	__ASSERT_ALWAYS(a!=0,Fault(EGuiRegisterWindow));
sl@0
  3212
sl@0
  3213
	RECT ctlrwindowRect={0,0,270,0};
sl@0
  3214
	AdjustWindowRect(&ctlrwindowRect,KControlWinStyle,FALSE);
sl@0
  3215
	TInt ctrlwindowWidth=ctlrwindowRect.right-ctlrwindowRect.left;
sl@0
  3216
	TInt ctrlwindowHeight=ctlrwindowRect.bottom-ctlrwindowRect.top;
sl@0
  3217
sl@0
  3218
    TheControlWin=CreateWindowA(
sl@0
  3219
		"E32KernelControlWindow",
sl@0
  3220
		systemIni->iWindowTitle,
sl@0
  3221
		KInvisibleControlWinStyle,
sl@0
  3222
		KWinPosX,
sl@0
  3223
		KWinPosY,
sl@0
  3224
		ctrlwindowWidth,
sl@0
  3225
		ctrlwindowHeight,
sl@0
  3226
		(HWND)NULL,
sl@0
  3227
		NULL,
sl@0
  3228
		(HINSTANCE)aArg,
sl@0
  3229
		(LPSTR)NULL
sl@0
  3230
		);
sl@0
  3231
	__ASSERT_ALWAYS(TheControlWin!=NULL,Fault(EGuiKernelWindowCreate));
sl@0
  3232
sl@0
  3233
	memclr(&w, sizeof(WNDCLASSA));
sl@0
  3234
   	w.style=CS_OWNDC;
sl@0
  3235
   	w.lpfnWndProc=(WNDPROC)winProc;
sl@0
  3236
   	w.hInstance=(HINSTANCE)aArg;
sl@0
  3237
   	w.hIcon=LoadIconA((HINSTANCE)hmodule,MAKEINTRESOURCEA(EPOC_ICON));
sl@0
  3238
   	w.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
sl@0
  3239
   	w.lpszClassName="E32KernelWindow";
sl@0
  3240
sl@0
  3241
	a=RegisterClassA(&w);
sl@0
  3242
	__ASSERT_ALWAYS(a!=0,Fault(EGuiRegisterWindow));
sl@0
  3243
sl@0
  3244
	memclr(&w, sizeof(WNDCLASSA));
sl@0
  3245
	w.style=CS_OWNDC;
sl@0
  3246
	w.lpfnWndProc=(WNDPROC)childWinProc;
sl@0
  3247
	w.hInstance=(HINSTANCE)aArg;
sl@0
  3248
	w.hCursor=LoadCursorA(NULL,MAKEINTRESOURCEA(32512)); //ICD_ARROW
sl@0
  3249
	w.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
sl@0
  3250
	w.lpszMenuName=NULL;
sl@0
  3251
	w.lpszClassName="E32KernelChildWindow";
sl@0
  3252
	a=RegisterClassA(&w);
sl@0
  3253
	__ASSERT_ALWAYS(a!=0,Fault(EGuiRegisterChildWindow));
sl@0
  3254
sl@0
  3255
	if (masterIni && masterIni->iSystemInis.Count() > 1)	
sl@0
  3256
		{
sl@0
  3257
		//add Configuration Items to the system menu if there's > 1 config
sl@0
  3258
		HMENU hMenu = GetSystemMenu(TheControlWin, FALSE);
sl@0
  3259
		InsertMenu(hMenu,5, MF_BYPOSITION|MF_SEPARATOR,0,NULL);
sl@0
  3260
		InsertMenuA(hMenu,6, MF_BYPOSITION|MF_STRING, 1, "Next Config...");
sl@0
  3261
		}
sl@0
  3262
	
sl@0
  3263
	ShowWindow(TheControlWin,SW_SHOWDEFAULT);
sl@0
  3264
	UpdateWindow(TheControlWin);
sl@0
  3265
sl@0
  3266
	//Create frame windows and child windows
sl@0
  3267
	for(TInt screen=0;screen<systemIni->iScreens.Count();screen++)
sl@0
  3268
		{
sl@0
  3269
	
sl@0
  3270
		RECT windowRect={0,0,systemIni->iScreens[screen]->iXYInputWidth,systemIni->iScreens[screen]->iXYInputHeight};
sl@0
  3271
		AdjustWindowRect(&windowRect,KWinStyle,FALSE);
sl@0
  3272
		TInt windowWidth=windowRect.right-windowRect.left;
sl@0
  3273
		TInt windowHeight=windowRect.bottom-windowRect.top;
sl@0
  3274
    
sl@0
  3275
		CHAR title[20];
sl@0
  3276
		wsprintfA(title, "Screen %d", screen);
sl@0
  3277
sl@0
  3278
		TheWin[screen]=CreateWindowA(
sl@0
  3279
			"E32KernelWindow",
sl@0
  3280
			title,
sl@0
  3281
			KInvisibleWinStyle,
sl@0
  3282
			KWinPosX,
sl@0
  3283
			KWinPosY,
sl@0
  3284
			windowWidth,
sl@0
  3285
			windowHeight,
sl@0
  3286
			(HWND)NULL,
sl@0
  3287
			NULL,
sl@0
  3288
			(HINSTANCE)aArg,
sl@0
  3289
			(LPSTR)NULL
sl@0
  3290
			);
sl@0
  3291
		__ASSERT_ALWAYS(TheWin[screen]!=NULL,Fault(EGuiKernelWindowCreate));
sl@0
  3292
		
sl@0
  3293
		LoadFasciaBitmap(screen);
sl@0
  3294
sl@0
  3295
		TheChildWin[screen]=CreateWindowA(
sl@0
  3296
			"E32KernelChildWindow",
sl@0
  3297
			"",
sl@0
  3298
			WS_CHILDWINDOW|WS_VISIBLE|WS_CLIPCHILDREN|WS_CLIPSIBLINGS,
sl@0
  3299
			systemIni->iScreens[screen]->iScreenOffsetX,
sl@0
  3300
			systemIni->iScreens[screen]->iScreenOffsetY,
sl@0
  3301
			systemIni->iScreens[screen]->iScreenWidth,
sl@0
  3302
			systemIni->iScreens[screen]->iScreenHeight,
sl@0
  3303
			TheWin[screen],
sl@0
  3304
			NULL,
sl@0
  3305
			(HINSTANCE)aArg,
sl@0
  3306
			(LPSTR)NULL
sl@0
  3307
			);
sl@0
  3308
		__ASSERT_ALWAYS(TheChildWin[screen]!=NULL,Fault(EGuiKernelChildWindowCreate));
sl@0
  3309
		
sl@0
  3310
		// Create status bars
sl@0
  3311
		if (systemIni->MultiTouchEnabled() && systemIni->GCEEnabled())
sl@0
  3312
			{
sl@0
  3313
			HMODULE hmodComCtl = LoadLibrary(TEXT("comctl32.dll"));
sl@0
  3314
			typedef int (WINAPI* FNINITCC)();
sl@0
  3315
			FNINITCC pfnInitCommonControls = GetProcAddress(hmodComCtl, "InitCommonControls");
sl@0
  3316
			pfnInitCommonControls();
sl@0
  3317
			hwndStatus = CreateWindowExA(0, STATUSCLASSNAMEA, NULL,
sl@0
  3318
								WS_CHILD | WS_VISIBLE | CCS_BOTTOM ,
sl@0
  3319
									0,0,0,0,
sl@0
  3320
									TheWin[0], NULL, GetModuleHandle(NULL), NULL);                 
sl@0
  3321
			SetStatusBarFont(hwndStatus);
sl@0
  3322
			SetWindowPos(hwndStatus,NULL, 0,0,0,0,SWP_HIDEWINDOW);
sl@0
  3323
			}
sl@0
  3324
		}
sl@0
  3325
	
sl@0
  3326
	//Restore window data from ini file if it exists. 
sl@0
  3327
	HANDLE hSysIni = CreateFileA(systemIni->iSysIniFileName, GENERIC_READ, 0, 0, OPEN_EXISTING, 0, 0);
sl@0
  3328
	TBool success=(hSysIni != INVALID_HANDLE_VALUE) ? ETrue : EFalse;
sl@0
  3329
	
sl@0
  3330
	DWORD numRead;
sl@0
  3331
	TInt fileVersion=0;
sl@0
  3332
	if(success) 
sl@0
  3333
		{
sl@0
  3334
		ReadFile(hSysIni, &fileVersion, sizeof(TInt), &numRead, 0);
sl@0
  3335
		}
sl@0
  3336
	
sl@0
  3337
	//Check we are using a dat file created by this version of the program.
sl@0
  3338
	if(success && (fileVersion==KDatFileVersion) )
sl@0
  3339
		{
sl@0
  3340
				
sl@0
  3341
		TInt savedConfiguration=0; //set this to default configuration
sl@0
  3342
				
sl@0
  3343
		if(ReadFile(hSysIni, &savedConfiguration, sizeof(TInt), &numRead, 0) && (numRead>0) )
sl@0
  3344
			{
sl@0
  3345
			//Don't restore the saved configuration, see INC114502.
sl@0
  3346
			//This could be reenabled in future as an optional operation
sl@0
  3347
			//dependent on an entry in the epoc.ini file.
sl@0
  3348
sl@0
  3349
			//SwitchConfiguration(savedConfiguration);
sl@0
  3350
			}
sl@0
  3351
	
sl@0
  3352
		//restore each window to saved state
sl@0
  3353
		for(TInt screen=0;screen<systemIni->iScreens.Count();screen++)
sl@0
  3354
			{
sl@0
  3355
		
sl@0
  3356
			//	If the .ini file was opened, get the saved settings for the windows position the last time
sl@0
  3357
			//	this emulator was run, if any, and move the window accordingly.
sl@0
  3358
			
sl@0
  3359
			TWindowState savedState;
sl@0
  3360
			
sl@0
  3361
			TBool stateLoaded = ReadFile(hSysIni, &savedState, sizeof(TWindowState), &numRead, 0) && (numRead>0);
sl@0
  3362
			 			
sl@0
  3363
			if (stateLoaded)
sl@0
  3364
				{				
sl@0
  3365
				//only allow window to be restored to 
sl@0
  3366
				//maximized or normal mode,
sl@0
  3367
				//this prevents it being restored in minimized mode
sl@0
  3368
				//or others.
sl@0
  3369
				if(savedState.iWinPlace.showCmd != SW_MAXIMIZE)
sl@0
  3370
						savedState.iWinPlace.showCmd= SW_NORMAL;
sl@0
  3371
				
sl@0
  3372
				//if starting in same configuration and/or rotation as last time emulator was run
sl@0
  3373
				//it makes sense to restore scroll offset, window position,
sl@0
  3374
				//and dimensions, if not, only restore position and window (ie. maximized/normal) state.
sl@0
  3375
				if(savedConfiguration == CurrentConfiguration &&
sl@0
  3376
					savedState.iFlipstate == CurrentFlipState[screen])
sl@0
  3377
					{
sl@0
  3378
					//Restore window placement
sl@0
  3379
					SetWindowPlacement(TheWin[screen], &savedState.iWinPlace);
sl@0
  3380
					
sl@0
  3381
					TViewport& viewport = systemIni->iScreens[screen]->iViewport;
sl@0
  3382
								
sl@0
  3383
					viewport.ScrollToX(savedState.iXoffset, TheWin[screen]);
sl@0
  3384
					viewport.ScrollToY(savedState.iYoffset, TheWin[screen]);
sl@0
  3385
					}
sl@0
  3386
				else
sl@0
  3387
					{
sl@0
  3388
					
sl@0
  3389
					RECT oldRect;
sl@0
  3390
					GetWindowRect(TheWin[screen], &oldRect);
sl@0
  3391
					//save default window dimensions
sl@0
  3392
					TInt width=oldRect.right-oldRect.left;
sl@0
  3393
					TInt height=oldRect.bottom - oldRect.top;
sl@0
  3394
sl@0
  3395
					//restore position and window state from file
sl@0
  3396
					SetWindowPlacement(TheWin[screen], &savedState.iWinPlace);
sl@0
  3397
					
sl@0
  3398
					RECT currentRect;
sl@0
  3399
					GetWindowRect(TheWin[screen], &currentRect);
sl@0
  3400
					//keep default size.
sl@0
  3401
					MoveWindow(TheWin[screen],currentRect.left, currentRect.top, width, height, TRUE);
sl@0
  3402
					
sl@0
  3403
					}
sl@0
  3404
sl@0
  3405
sl@0
  3406
				// Check that enough of the recorded window position is visible on the screen
sl@0
  3407
sl@0
  3408
				TBool enoughVisible = false;
sl@0
  3409
sl@0
  3410
				// vague values for ensuring we have enough of the window title bar to grab
sl@0
  3411
				// if the window is partly off screen 
sl@0
  3412
				const TInt KTitleBarGrabX=80;
sl@0
  3413
				const TInt KTitleBarGrabY=50;
sl@0
  3414
sl@0
  3415
				//inspect dimensions of the window to be restored.
sl@0
  3416
				RECT savedRect;
sl@0
  3417
				GetWindowRect(TheWin[screen], &savedRect);
sl@0
  3418
sl@0
  3419
				SystemMonitors monitors;
sl@0
  3420
sl@0
  3421
				if (monitors.Count() == 1)		/* Original algorithm */
sl@0
  3422
					{
sl@0
  3423
					RECT rcIntersect, rcScreen;
sl@0
  3424
sl@0
  3425
					SetRect(&rcScreen, KTitleBarGrabX, savedRect.bottom-savedRect.top,
sl@0
  3426
						GetSystemMetrics(SM_CXSCREEN)-KTitleBarGrabX, GetSystemMetrics(SM_CYSCREEN)-KTitleBarGrabY);
sl@0
  3427
sl@0
  3428
					enoughVisible = IntersectRect(&rcIntersect, &savedRect, &rcScreen);
sl@0
  3429
					}
sl@0
  3430
				else							/* > 1 monitor; do it differently */
sl@0
  3431
					{
sl@0
  3432
					RECT cornerBox1, cornerBox2;
sl@0
  3433
sl@0
  3434
					// The top-left corner box
sl@0
  3435
					SetRect(&cornerBox1, savedRect.left, savedRect.top,
sl@0
  3436
						savedRect.left + KTitleBarGrabX, savedRect.top + KTitleBarGrabY);
sl@0
  3437
sl@0
  3438
					// The top-right corner box
sl@0
  3439
					SetRect(&cornerBox2, savedRect.right - KTitleBarGrabX, savedRect.top,
sl@0
  3440
						savedRect.right, savedRect.top + KTitleBarGrabY);
sl@0
  3441
sl@0
  3442
					// Require one of these rectangles to be all on one monitor
sl@0
  3443
					enoughVisible = monitors.RectAllOnOne(cornerBox1) || monitors.RectAllOnOne(cornerBox2);
sl@0
  3444
					}
sl@0
  3445
sl@0
  3446
				if (!enoughVisible)
sl@0
  3447
					{
sl@0
  3448
					SetWindowPos(TheWin[screen], HWND_TOP, 0,0,0,0, SWP_NOSIZE);
sl@0
  3449
					}
sl@0
  3450
sl@0
  3451
				}
sl@0
  3452
			else //if there was no stored info for this screen
sl@0
  3453
				{
sl@0
  3454
				ShowWindow(TheWin[screen],SW_MAXIMIZE);
sl@0
  3455
				}
sl@0
  3456
			}
sl@0
  3457
		}
sl@0
  3458
	else
sl@0
  3459
		{
sl@0
  3460
		//use default configuration and make windows visible
sl@0
  3461
		SwitchConfiguration(CurrentConfiguration);
sl@0
  3462
		for(TInt screen=0;screen<systemIni->iScreens.Count();screen++)
sl@0
  3463
			{
sl@0
  3464
			ShowWindow(TheWin[screen],SW_MAXIMIZE);
sl@0
  3465
			UpdateWindow(TheWin[screen]);
sl@0
  3466
			}
sl@0
  3467
		}
sl@0
  3468
sl@0
  3469
	//close file if it was opened	
sl@0
  3470
	if(success) 
sl@0
  3471
		{
sl@0
  3472
		CloseHandle(hSysIni);
sl@0
  3473
		}
sl@0
  3474
		
sl@0
  3475
			
sl@0
  3476
	if (systemIni->iInitialFlipMsg != 0)
sl@0
  3477
		{
sl@0
  3478
		addKeyEvent(TRawEvent::EKeyDown,systemIni->iInitialFlipMsg);
sl@0
  3479
		addKeyEvent(TRawEvent::EKeyUp,systemIni->iInitialFlipMsg);
sl@0
  3480
		}
sl@0
  3481
sl@0
  3482
	SetFocus(TheWin[0]);
sl@0
  3483
sl@0
  3484
	MSG m;
sl@0
  3485
	while (GetMessageA(&m,NULL,0,0))
sl@0
  3486
    	{
sl@0
  3487
        DispatchMessageA(&m);
sl@0
  3488
	    }
sl@0
  3489
	
sl@0
  3490
	ExitProcess(m.wParam);
sl@0
  3491
	return 0;
sl@0
  3492
	}
sl@0
  3493
sl@0
  3494
SystemMonitors::SystemMonitors(void)
sl@0
  3495
	{
sl@0
  3496
	TInt n;
sl@0
  3497
sl@0
  3498
	iCount = 1;
sl@0
  3499
	iHaveMultiMonFunctions = false;
sl@0
  3500
sl@0
  3501
	if ((n = GetSystemMetrics(SM_CMONITORS)) <= 1)
sl@0
  3502
		{
sl@0
  3503
		return;
sl@0
  3504
		}
sl@0
  3505
sl@0
  3506
	HMODULE huser32 = GetModuleHandleA("user32.dll");
sl@0
  3507
sl@0
  3508
	// Get pointers to the APIs we want
sl@0
  3509
	if (huser32 == NULL ||
sl@0
  3510
		(ipMonitorFromRect =
sl@0
  3511
		(HMONITOR (WINAPI *)(LPCRECT lprcScreenCoords, UINT uFlags))
sl@0
  3512
		GetProcAddress(huser32, "MonitorFromRect")) == NULL ||
sl@0
  3513
		(ipGetMonitorInfo =
sl@0
  3514
		(BOOL (WINAPI *)(HMONITOR hMonitor, LPMONITORINFO lpMonitorInfo))
sl@0
  3515
		GetProcAddress(huser32, "GetMonitorInfoA")) == NULL)
sl@0
  3516
		{
sl@0
  3517
		return;
sl@0
  3518
		}
sl@0
  3519
sl@0
  3520
	iCount = n;
sl@0
  3521
	iHaveMultiMonFunctions = true;
sl@0
  3522
	}
sl@0
  3523
sl@0
  3524
TBool SystemMonitors::RectAllOnOne(RECT& rect)
sl@0
  3525
	{
sl@0
  3526
	HMONITOR monitor = MonitorFromRect(rect);
sl@0
  3527
	if (monitor == NULL)
sl@0
  3528
		{
sl@0
  3529
		return false;
sl@0
  3530
		}
sl@0
  3531
sl@0
  3532
	MONITORINFO monInfo;
sl@0
  3533
	monInfo.cbSize = sizeof(MONITORINFO);
sl@0
  3534
sl@0
  3535
	if (! GetMonitorInfo(monitor, &monInfo))
sl@0
  3536
		{
sl@0
  3537
		return false;
sl@0
  3538
		}
sl@0
  3539
sl@0
  3540
	RECT overlap;
sl@0
  3541
sl@0
  3542
	if (IntersectRect(&overlap, &rect, &monInfo.rcWork) &&
sl@0
  3543
		EqualRect(&overlap, &rect))
sl@0
  3544
		{
sl@0
  3545
		return true;
sl@0
  3546
		}
sl@0
  3547
sl@0
  3548
	return false;
sl@0
  3549
	}
sl@0
  3550
sl@0
  3551
HMONITOR SystemMonitors::MonitorFromRect(const RECT& rect, UINT flags)
sl@0
  3552
	{
sl@0
  3553
	if (! iHaveMultiMonFunctions)
sl@0
  3554
		{
sl@0
  3555
		return NULL;
sl@0
  3556
		}
sl@0
  3557
sl@0
  3558
	return (*ipMonitorFromRect)(&rect, flags);
sl@0
  3559
	}
sl@0
  3560
sl@0
  3561
TBool SystemMonitors::GetMonitorInfo(HMONITOR monitor, LPMONITORINFO pMonInfo)
sl@0
  3562
	{
sl@0
  3563
	if (! iHaveMultiMonFunctions)
sl@0
  3564
		{
sl@0
  3565
		return false;
sl@0
  3566
		}
sl@0
  3567
sl@0
  3568
	return (*ipGetMonitorInfo)(monitor, pMonInfo);
sl@0
  3569
	}
sl@0
  3570
sl@0
  3571
void DrawLeds()
sl@0
  3572
	{
sl@0
  3573
	HDC winDC = GetDC(TheWin[0]);
sl@0
  3574
	HDC hdcBits;
sl@0
  3575
	hdcBits=CreateCompatibleDC(winDC);
sl@0
  3576
	SelectObject(hdcBits,TheScreenBitmap[0]);
sl@0
  3577
	HPEN pen=CreatePen(PS_SOLID,0,RGB(0,0,0));
sl@0
  3578
	SelectObject(hdcBits,pen);
sl@0
  3579
	HBRUSH brush;
sl@0
  3580
	LOGBRUSH redbrush={BS_SOLID, RGB(0xff,0,0)};
sl@0
  3581
	LOGBRUSH greenbrush={BS_SOLID, RGB(0,0xff,0)};
sl@0
  3582
	LOGBRUSH blackbrush={BS_SOLID, RGB(0,0,0)};
sl@0
  3583
	// red
sl@0
  3584
	if (LedMask & KLedMaskRed1)
sl@0
  3585
		brush=CreateBrushIndirect(&redbrush);
sl@0
  3586
	else
sl@0
  3587
		brush=CreateBrushIndirect(&blackbrush);
sl@0
  3588
	SelectObject(hdcBits,brush);
sl@0
  3589
	DWinsUi *ini=systemIni;
sl@0
  3590
	Ellipse(hdcBits, ini->iLedOffsetX, ini->iLedOffsetY, ini->iLedOffsetX+ini->iLedSize, ini->iLedOffsetY+ini->iLedSize);
sl@0
  3591
	DeleteObject(brush);
sl@0
  3592
	// green
sl@0
  3593
	if (LedMask & KLedMaskGreen1)
sl@0
  3594
		brush=CreateBrushIndirect(&greenbrush);
sl@0
  3595
	else
sl@0
  3596
		brush=CreateBrushIndirect(&blackbrush);
sl@0
  3597
	SelectObject(hdcBits,brush);
sl@0
  3598
	if (ini->iLedVertical)
sl@0
  3599
		Ellipse(hdcBits, ini->iLedOffsetX, ini->iLedOffsetY+ini->iLedSize+ini->iLedGap,
sl@0
  3600
		ini->iLedOffsetX+ini->iLedSize, ini->iLedOffsetY+ini->iLedSize+ini->iLedGap+ini->iLedSize);
sl@0
  3601
	else
sl@0
  3602
		Ellipse(hdcBits, ini->iLedOffsetX+ini->iLedSize+ini->iLedGap, ini->iLedOffsetY,
sl@0
  3603
		ini->iLedOffsetX+ini->iLedSize+ini->iLedGap+ini->iLedSize, ini->iLedOffsetY+ini->iLedSize);
sl@0
  3604
	DeleteObject(brush);
sl@0
  3605
	DeleteObject(pen);
sl@0
  3606
	DeleteDC(hdcBits);
sl@0
  3607
	ReleaseDC(TheWin[0], winDC);
sl@0
  3608
	if (ini->iLedVertical)
sl@0
  3609
		{
sl@0
  3610
		RECT r={ini->iLedOffsetX,
sl@0
  3611
			ini->iLedOffsetY,
sl@0
  3612
			ini->iLedOffsetX+ini->iLedSize,
sl@0
  3613
			ini->iLedOffsetY+ini->iLedSize+ini->iLedGap+ini->iLedSize};
sl@0
  3614
		InvalidateRect(TheWin[0], &r, FALSE);
sl@0
  3615
		}
sl@0
  3616
	else
sl@0
  3617
		{
sl@0
  3618
		RECT r={ini->iLedOffsetX,
sl@0
  3619
			ini->iLedOffsetY,
sl@0
  3620
			ini->iLedOffsetX+ini->iLedSize+ini->iLedGap+ini->iLedSize,
sl@0
  3621
			ini->iLedOffsetY+ini->iLedSize};
sl@0
  3622
		InvalidateRect(TheWin[0], &r, FALSE);
sl@0
  3623
		}
sl@0
  3624
	}
sl@0
  3625
sl@0
  3626
void DWinsUi::ScreenInfo(TScreenInfoV01& aInfo)
sl@0
  3627
//
sl@0
  3628
// Return screen 0 info to the window server.
sl@0
  3629
//
sl@0
  3630
	{
sl@0
  3631
	aInfo.iWindowHandleValid=ETrue;
sl@0
  3632
	aInfo.iWindowHandle=TheChildWin[0];
sl@0
  3633
	aInfo.iScreenAddressValid=EFalse;
sl@0
  3634
	aInfo.iScreenAddress=NULL;
sl@0
  3635
	aInfo.iScreenSize.iWidth = iScreens[0]->iMaxScreenWidth;
sl@0
  3636
	aInfo.iScreenSize.iHeight = iScreens[0]->iMaxScreenHeight;
sl@0
  3637
	}
sl@0
  3638
	
sl@0
  3639
	
sl@0
  3640
TBool DWinsUi::VideoInfo(TInt aScreenNumber, TVideoInfoV01& aInfo)
sl@0
  3641
	{
sl@0
  3642
	return VideoInfo(aScreenNumber,iScreens[aScreenNumber&KMaskScreenNum]->iCurrentMode,aInfo);
sl@0
  3643
	}
sl@0
  3644
	
sl@0
  3645
/// Could fail if flip mode is not supported
sl@0
  3646
TBool DWinsUi::VideoInfo(TInt aScreenNumber,TInt aModeNumber, TVideoInfoV01& aInfo)
sl@0
  3647
	{
sl@0
  3648
	aScreenNumber &= KMaskScreenNum;
sl@0
  3649
	if (aScreenNumber>=iScreens.Count())
sl@0
  3650
		return EFalse;
sl@0
  3651
	if (masterIni->iBufferSet.Count() && masterIni->iBufferSet[aScreenNumber].iDisplayDriverCount > 0)
sl@0
  3652
		{
sl@0
  3653
			return VideoInfoForDisplayDriver(aScreenNumber,aModeNumber,aInfo);
sl@0
  3654
		}
sl@0
  3655
	else
sl@0
  3656
		{
sl@0
  3657
		if ((aModeNumber&KMaskModeNum)>=1)
sl@0
  3658
			return EFalse;	//non-gce emulator doesn't support changing the mode number.
sl@0
  3659
		DScreenProperties* screenProperties=iScreens[aScreenNumber];
sl@0
  3660
		aInfo.iSizeInPixels.iWidth = screenProperties->iMaxScreenWidth;
sl@0
  3661
		aInfo.iSizeInPixels.iHeight = screenProperties->iMaxScreenHeight;
sl@0
  3662
		aInfo.iSizeInTwips.iWidth = screenProperties->iMaxPhysicalScreenWidth ? screenProperties->iMaxPhysicalScreenWidth : TInt(screenProperties->iScreenWidth*KDefaultPixelsToTwipsX);
sl@0
  3663
		aInfo.iSizeInTwips.iHeight = screenProperties->iMaxPhysicalScreenHeight ? screenProperties->iMaxPhysicalScreenHeight : TInt(screenProperties->iScreenHeight*KDefaultPixelsToTwipsY);
sl@0
  3664
		aInfo.iIsMono = EFalse;
sl@0
  3665
		aInfo.iIsPalettized = EFalse;
sl@0
  3666
		aInfo.iDisplayMode=screenProperties->iCurrentMode;
sl@0
  3667
		aInfo.iIsPixelOrderRGB = ETrue;
sl@0
  3668
		aInfo.iIsPixelOrderLandscape=ETrue;
sl@0
  3669
sl@0
  3670
		aInfo.iVideoAddress =  (TInt)TheChildWin[aScreenNumber];
sl@0
  3671
		aInfo.iBitsPerPixel = screenProperties->iColorDepth;
sl@0
  3672
		aInfo.iOffsetToFirstPixel=0;
sl@0
  3673
		aInfo.iOffsetBetweenLines=0;
sl@0
  3674
		}
sl@0
  3675
	return ETrue;	
sl@0
  3676
	}
sl@0
  3677
sl@0
  3678
/** Could fail if flip mode is not supported.
sl@0
  3679
 Note that this method is inteneded to be called directly to parameterise the setting up of the display driver,
sl@0
  3680
 so it must survive absense of the display driver installation!
sl@0
  3681
**/
sl@0
  3682
 
sl@0
  3683
TBool DWinsUi::VideoInfoForDisplayDriver(TInt aScreenNumber,TInt aModeNumber, TVideoInfoV01& aInfo,  TBool aRealWidthAndHeight)
sl@0
  3684
	{
sl@0
  3685
	aScreenNumber &= KMaskScreenNum;
sl@0
  3686
	DScreenProperties* screenProperties = iScreens[aScreenNumber];
sl@0
  3687
	if ((aModeNumber&KMaskModeNum) >= screenProperties->iMaxModes)
sl@0
  3688
		{
sl@0
  3689
		return EFalse;
sl@0
  3690
		}
sl@0
  3691
		
sl@0
  3692
	aInfo.iSizeInPixels.iWidth = aRealWidthAndHeight ? screenProperties->iScreenWidth : screenProperties->iMaxScreenWidth;
sl@0
  3693
	aInfo.iSizeInPixels.iHeight = aRealWidthAndHeight ? screenProperties->iScreenHeight : screenProperties->iMaxScreenHeight;
sl@0
  3694
	
sl@0
  3695
	if (aRealWidthAndHeight==EFalse)
sl@0
  3696
		{
sl@0
  3697
		aInfo.iSizeInTwips.iWidth = screenProperties->iMaxPhysicalScreenWidth ?	screenProperties->iMaxPhysicalScreenWidth : TInt(screenProperties->iScreenWidth*KDefaultPixelsToTwipsX);
sl@0
  3698
		aInfo.iSizeInTwips.iHeight = screenProperties->iMaxPhysicalScreenHeight ? screenProperties->iMaxPhysicalScreenHeight : TInt(screenProperties->iScreenHeight*KDefaultPixelsToTwipsY);
sl@0
  3699
		}
sl@0
  3700
	else
sl@0
  3701
		{
sl@0
  3702
		aInfo.iSizeInTwips.iWidth = screenProperties->iPhysicalScreenWidth ? screenProperties->iPhysicalScreenWidth : TInt(screenProperties->iScreenWidth*KDefaultPixelsToTwipsX);
sl@0
  3703
		aInfo.iSizeInTwips.iHeight = screenProperties->iPhysicalScreenHeight ? screenProperties->iPhysicalScreenHeight : TInt(screenProperties->iScreenHeight*KDefaultPixelsToTwipsY);
sl@0
  3704
		}
sl@0
  3705
	
sl@0
  3706
	aInfo.iIsMono = EFalse;
sl@0
  3707
	aInfo.iIsPalettized = EFalse;
sl@0
  3708
	aInfo.iDisplayMode=screenProperties->iCurrentMode;
sl@0
  3709
	aInfo.iIsPixelOrderRGB = ETrue;
sl@0
  3710
	aInfo.iIsPixelOrderLandscape=ETrue;
sl@0
  3711
	
sl@0
  3712
	// Set memory to iVideoAddress to NULL to trigger the HAL code into querying the video address
sl@0
  3713
	// separately
sl@0
  3714
	aInfo.iVideoAddress = NULL;
sl@0
  3715
sl@0
  3716
	TInt bpp=screenProperties->iModeDepths[aModeNumber&KMaskModeNum];												
sl@0
  3717
	aInfo.iBitsPerPixel=bpp;
sl@0
  3718
	if (bpp>8)
sl@0
  3719
		{
sl@0
  3720
		bpp=(bpp+15)&-16;	//12 & 16 --> 16 ; 24 & 32 --> 32
sl@0
  3721
		}
sl@0
  3722
	
sl@0
  3723
	aInfo.iOffsetToFirstPixel=0;
sl@0
  3724
#ifdef TEST_GCE_VARIABLE_START_EXTRA
sl@0
  3725
	aInfo.iOffsetToFirstPixel+= TEST_GCE_VARIABLE_START_EXTRA*(1+aModeNumber&KMaskScreenModeNum);
sl@0
  3726
	if ((aModeNumber& KModeFlagFlipped)
sl@0
  3727
		{
sl@0
  3728
#ifndef ASSYMETRIC_SQUARE_STRIDE		
sl@0
  3729
		if (aInfo.iSizeInPixels.iWidth!=aInfo.iSizeInPixels.iHeight)
sl@0
  3730
#endif
sl@0
  3731
			aInfo.iOffsetToFirstPixel+= TEST_GCE_VARIABLE_START_EXTRA*KEmulMaxNumModes;	
sl@0
  3732
		}
sl@0
  3733
#endif
sl@0
  3734
	if (aModeNumber& KModeFlagFlipped)
sl@0
  3735
		{
sl@0
  3736
		// we calculate the number of bytes per scanline that MUST be a multiple of 32 bits word (alignment)
sl@0
  3737
		// screenProperties->iMaxScreenHeight * bpp represnts the number of bits per scanline
sl@0
  3738
		// +31 is the ceiling
sl@0
  3739
		// we shift right (>>3) because there are 8 bits/byte
sl@0
  3740
		// we mask with ~3 because we are intrested in the octet value
sl@0
  3741
		aInfo.iOffsetBetweenLines=((screenProperties->iMaxScreenHeight * bpp + 31) >> 3) & ~3;
sl@0
  3742
		}
sl@0
  3743
	else
sl@0
  3744
		{
sl@0
  3745
		// please see the comment above
sl@0
  3746
		aInfo.iOffsetBetweenLines=((screenProperties->iMaxScreenWidth * bpp + 31) >> 3) & ~3;
sl@0
  3747
		}
sl@0
  3748
#ifdef  TEST_GCE_VARIABLE_STRIDE_EXTRA
sl@0
  3749
	aInfo.iOffsetBetweenLines+=TEST_GCE_VARIABLE_STRIDE_EXTRA;
sl@0
  3750
#endif	
sl@0
  3751
sl@0
  3752
	return ETrue;	
sl@0
  3753
	}
sl@0
  3754
sl@0
  3755
TInt DMasterIni::DoHalFunction(TAny* aPtr, TInt aFunction, TAny* a1, TAny* a2)
sl@0
  3756
	{
sl@0
  3757
	return masterIni->HalFunction((TInt)aPtr,aFunction,a1,a2);
sl@0
  3758
	}
sl@0
  3759
sl@0
  3760
sl@0
  3761
TInt DMasterIni::HalFunction(TInt aDeviceNumber, TInt aFunction, TAny* a1, TAny* a2)
sl@0
  3762
	{
sl@0
  3763
	if (TUint(aDeviceNumber) >= TUint(systemIni->iScreens.Count()))
sl@0
  3764
		return KErrArgument;
sl@0
  3765
	
sl@0
  3766
	TInt mode;
sl@0
  3767
	TInt maxMode=1;
sl@0
  3768
	TInt r=KErrNone;
sl@0
  3769
	switch(aFunction)
sl@0
  3770
		{
sl@0
  3771
		case EDisplayHalScreenInfo:
sl@0
  3772
			{
sl@0
  3773
			TPckgBuf<TScreenInfoV01> vPckg;
sl@0
  3774
			systemIni->ScreenInfo(vPckg());
sl@0
  3775
			Kern::InfoCopy(*(TDes8*)a1,vPckg);
sl@0
  3776
			break;
sl@0
  3777
			}
sl@0
  3778
		case EDisplayHalWsRegisterSwitchOnScreenHandling:
sl@0
  3779
			WsSwitchOnScreen=(TBool)a1;
sl@0
  3780
			break;
sl@0
  3781
		case EDisplayHalSetState:
sl@0
  3782
			{
sl@0
  3783
			if(!Kern::CurrentThreadHasCapability(ECapabilityPowerMgmt,__PLATSEC_DIAGNOSTIC_STRING("Checked by Hal function EDisplayHalSetState")))
sl@0
  3784
				return KErrPermissionDenied;
sl@0
  3785
			if ((TBool)a1)
sl@0
  3786
				WinsGuiPowerHandler->ScreenOn(aDeviceNumber);
sl@0
  3787
			else
sl@0
  3788
				WinsGuiPowerHandler->ScreenOff(aDeviceNumber);
sl@0
  3789
			}
sl@0
  3790
			break;
sl@0
  3791
sl@0
  3792
		case EDisplayHalState:
sl@0
  3793
			*(TInt*)a1=!systemIni->iScreens[aDeviceNumber]->iScreenOff;
sl@0
  3794
			break;
sl@0
  3795
		case EDisplayHalWsSwitchOnScreen:
sl@0
  3796
			WinsGuiPowerHandler->ScreenOn();
sl@0
  3797
			break;
sl@0
  3798
		case EDisplayHalMaxDisplayContrast:
sl@0
  3799
			kumemput32(a1,&KMaxDisplayContrast,sizeof(KMaxDisplayContrast));
sl@0
  3800
			break;
sl@0
  3801
		case EDisplayHalDisplayContrast:
sl@0
  3802
			kumemput32(a1,&systemIni->iScreens[aDeviceNumber]->iDisplayContrast,sizeof(systemIni->iScreens[aDeviceNumber]->iDisplayContrast));
sl@0
  3803
			break;
sl@0
  3804
		case EDisplayHalSetDisplayContrast:
sl@0
  3805
			if(!Kern::CurrentThreadHasCapability(ECapabilityWriteDeviceData,__PLATSEC_DIAGNOSTIC_STRING("Checked by Hal function EDisplayHalSetDisplayContrast")))
sl@0
  3806
				return KErrPermissionDenied;
sl@0
  3807
			if (TUint(a1) <= TUint(KMaxDisplayContrast))
sl@0
  3808
				systemIni->iScreens[aDeviceNumber]->iDisplayContrast = TInt(a1);
sl@0
  3809
			else
sl@0
  3810
				r = KErrArgument;
sl@0
  3811
			break;
sl@0
  3812
		case EDisplayHalBacklightOn:
sl@0
  3813
			{
sl@0
  3814
			TBool c = EFalse;
sl@0
  3815
			kumemput32(a1,&c,sizeof(TBool));
sl@0
  3816
			}
sl@0
  3817
			break;
sl@0
  3818
		
sl@0
  3819
		case EDisplayHalCurrentModeInfo:
sl@0
  3820
			{
sl@0
  3821
			//a1 has ptr to buffer for results
sl@0
  3822
			TPckgBuf<TVideoInfoV01> vPckg;
sl@0
  3823
			if (systemIni->VideoInfo(aDeviceNumber, vPckg()))
sl@0
  3824
				Kern::InfoCopy(*(TDes8*)a1,vPckg);
sl@0
  3825
			else
sl@0
  3826
				r=KErrNotSupported;
sl@0
  3827
			}
sl@0
  3828
			break;
sl@0
  3829
sl@0
  3830
		case EDisplayHalSpecifiedModeInfo:
sl@0
  3831
			{
sl@0
  3832
			kumemget32(&mode, a1, sizeof(mode));
sl@0
  3833
			TPckgBuf<TVideoInfoV01> vPckg;
sl@0
  3834
			if (!systemIni->VideoInfo(aDeviceNumber, mode, vPckg()))
sl@0
  3835
				return KErrArgument;
sl@0
  3836
			Kern::InfoCopy(*(TDes8*)a2, vPckg);
sl@0
  3837
			}
sl@0
  3838
			break;
sl@0
  3839
sl@0
  3840
		case EDisplayHalSetMode:
sl@0
  3841
// 			if(!Kern::CurrentThreadHasCapability(ECapabilityMultimediaDD,__PLATSEC_DIAGNOSTIC_STRING("Checked by Hal function EDisplayHalSetMode")))
sl@0
  3842
// 				return KErrPermissionDenied;
sl@0
  3843
sl@0
  3844
			//Note that at present the HAL mode does not apparently get set when the CFbsScreenDevice requires a different mode.
sl@0
  3845
			//At least in the emulator and default h4 implementation...
sl@0
  3846
			
sl@0
  3847
			mode=KMaskModeNum&(TInt) a1;
sl@0
  3848
			maxMode=1;
sl@0
  3849
			//can't avoid this behaviour change test against gce loaded 
sl@0
  3850
			if (masterIni->iBufferSet.Count() &&  masterIni->iBufferSet[aDeviceNumber].iDisplayDriverCount > 0)
sl@0
  3851
				maxMode=systemIni->iScreens[aDeviceNumber]->iMaxModes;
sl@0
  3852
			if (mode >=maxMode || mode<0)
sl@0
  3853
				{
sl@0
  3854
				r = KErrArgument;
sl@0
  3855
				break;
sl@0
  3856
				}
sl@0
  3857
			//Harmless/Pointless in vanilla wins mode.
sl@0
  3858
			systemIni->iScreens[aDeviceNumber]->iCurrentMode=mode;
sl@0
  3859
			
sl@0
  3860
			break;
sl@0
  3861
		
sl@0
  3862
		case EDisplayHalMode:
sl@0
  3863
			{
sl@0
  3864
			//This is always 0 in non-gce emulator
sl@0
  3865
			kumemput32(a1,&systemIni->iScreens[aDeviceNumber]->iCurrentMode,sizeof(systemIni->iScreens[aDeviceNumber]->iCurrentMode));
sl@0
  3866
			}
sl@0
  3867
			break;
sl@0
  3868
sl@0
  3869
		case EDisplayHalModeCount:
sl@0
  3870
			{
sl@0
  3871
			//Need to actually count them here!
sl@0
  3872
			//GCE will ignore modes<=8
sl@0
  3873
			TInt encodedMode=1;
sl@0
  3874
			if (masterIni->iBufferSet.Count() &&  masterIni->iBufferSet[aDeviceNumber].iDisplayDriverCount > 0)
sl@0
  3875
				encodedMode=systemIni->iScreens[aDeviceNumber]->iMaxModes;
sl@0
  3876
			kumemput32(a1,&encodedMode,sizeof(encodedMode));
sl@0
  3877
			}
sl@0
  3878
			break;
sl@0
  3879
sl@0
  3880
		case EDisplayHalColors:
sl@0
  3881
			{
sl@0
  3882
			TInt deepestMode=0;
sl@0
  3883
			if (masterIni->iBufferSet.Count()==0 ||  masterIni->iBufferSet[aDeviceNumber].iDisplayDriverCount <= 0)
sl@0
  3884
				{
sl@0
  3885
				deepestMode = KMaxDisplayColors;  	//I could try and work it out, but this is what used to happen!
sl@0
  3886
				}
sl@0
  3887
			else
sl@0
  3888
				{
sl@0
  3889
				TInt maxBpp=0;
sl@0
  3890
				for (TInt i=0,maxI=systemIni->iScreens[aDeviceNumber]->iMaxModes;i<maxI;i++)	
sl@0
  3891
					if (systemIni->iScreens[aDeviceNumber]->iModeDepths[i]>maxBpp)
sl@0
  3892
						maxBpp=systemIni->iScreens[aDeviceNumber]->iModeDepths[i];
sl@0
  3893
				deepestMode= 1<<maxBpp;
sl@0
  3894
				}
sl@0
  3895
sl@0
  3896
			kumemput32(a1,&deepestMode,sizeof(deepestMode));
sl@0
  3897
			}
sl@0
  3898
			break;
sl@0
  3899
		case EDisplayHalGetDisplayMemoryHandle:
sl@0
  3900
			{
sl@0
  3901
			TInt val = 0;
sl@0
  3902
			TInt passedIn = 0;
sl@0
  3903
			kumemget32(&passedIn, a1, sizeof(TInt));
sl@0
  3904
			if (passedIn != -1)	//not from a getall
sl@0
  3905
				{
sl@0
  3906
				NKern::ThreadEnterCS();
sl@0
  3907
				if (!(masterIni->iBufferSet.Count() == 0 || masterIni->iBufferSet[aDeviceNumber].iDisplayDriverCount <= 0 ))
sl@0
  3908
					{
sl@0
  3909
						r = masterIni->DisplayMemoryHandle(aDeviceNumber, val); 
sl@0
  3910
					}
sl@0
  3911
				else
sl@0
  3912
					{
sl@0
  3913
					r = KErrArgument;
sl@0
  3914
					}
sl@0
  3915
				NKern::ThreadLeaveCS();
sl@0
  3916
				}
sl@0
  3917
			kumemput32(a1, &val, sizeof(TInt));
sl@0
  3918
sl@0
  3919
			}
sl@0
  3920
			break;
sl@0
  3921
sl@0
  3922
		case EDisplayHalGetDisplayMemoryAddress:
sl@0
  3923
			{
sl@0
  3924
			TInt val = 0;
sl@0
  3925
			TInt passedIn = 0;
sl@0
  3926
			kumemget32(&passedIn, a1, sizeof(TInt));
sl@0
  3927
			if (passedIn != -1)	//not from a getall
sl@0
  3928
				{
sl@0
  3929
				if (!(masterIni->iBufferSet.Count() == 0 || masterIni->iBufferSet[aDeviceNumber].iDisplayDriverCount <= 0 ))
sl@0
  3930
					{
sl@0
  3931
					r = masterIni->DisplayMemoryAddress(aDeviceNumber, val);
sl@0
  3932
					}
sl@0
  3933
				else
sl@0
  3934
					{
sl@0
  3935
					r = KErrArgument;
sl@0
  3936
					}
sl@0
  3937
				}
sl@0
  3938
			kumemput32(a1, &val, sizeof(TInt));
sl@0
  3939
			}
sl@0
  3940
			break;
sl@0
  3941
sl@0
  3942
		case EDisplayHalNumberOfResolutions:
sl@0
  3943
			{
sl@0
  3944
			r = NumberOfResolutions(aDeviceNumber, a1, a2);
sl@0
  3945
			}
sl@0
  3946
			break;
sl@0
  3947
		case EDisplayHalSpecificScreenInfo:
sl@0
  3948
			{
sl@0
  3949
			r = SpecificScreenInfo(aDeviceNumber, a1, a2);
sl@0
  3950
			}
sl@0
  3951
			break;
sl@0
  3952
		case EDisplayHalCurrentScreenInfo:
sl@0
  3953
			{
sl@0
  3954
			r = CurrentScreenInfo(aDeviceNumber, a1, a2);			
sl@0
  3955
			}
sl@0
  3956
			break;
sl@0
  3957
		case EDisplayHalSetDisplayState:
sl@0
  3958
			{
sl@0
  3959
			//increase the spinner at both beginning and end of resetting the display state
sl@0
  3960
			NKern::LockedInc(iBufferSet[aDeviceNumber].iStateChangeCount);
sl@0
  3961
			kumemget32(&iBufferSet[aDeviceNumber].iDisplayState, a1, sizeof(TInt));
sl@0
  3962
sl@0
  3963
			switch(iBufferSet[aDeviceNumber].iDisplayState)
sl@0
  3964
				{
sl@0
  3965
				case ENoResolution:
sl@0
  3966
				case EDisconnect:
sl@0
  3967
				case ESingleResolution:
sl@0
  3968
					// the fascia effect of 0x0 resolution
sl@0
  3969
					SetDisplaySize(aDeviceNumber, 0, 0);
sl@0
  3970
					break;
sl@0
  3971
				}
sl@0
  3972
sl@0
  3973
			NKern::LockedInc(iBufferSet[aDeviceNumber].iStateChangeCount);
sl@0
  3974
			}
sl@0
  3975
			break;
sl@0
  3976
		case EDisplayHalGetStateSpinner:
sl@0
  3977
			{
sl@0
  3978
			kumemput32(a1,&iBufferSet[aDeviceNumber].iStateChangeCount,
sl@0
  3979
					sizeof(iBufferSet[aDeviceNumber].iStateChangeCount));
sl@0
  3980
			}
sl@0
  3981
			break;
sl@0
  3982
		default:
sl@0
  3983
			r=KErrNotSupported;
sl@0
  3984
			break;
sl@0
  3985
		}
sl@0
  3986
	return r;
sl@0
  3987
	}
sl@0
  3988
sl@0
  3989
TInt DMasterIni::NumberOfResolutions(TInt aDeviceNumber, TAny* a1, TAny* a2)
sl@0
  3990
	{
sl@0
  3991
	TInt numberOfConfigs;
sl@0
  3992
	switch(iBufferSet[aDeviceNumber].iDisplayState)
sl@0
  3993
		{
sl@0
  3994
		case ENoResolution:
sl@0
  3995
			{
sl@0
  3996
			numberOfConfigs = 0;
sl@0
  3997
			}
sl@0
  3998
			break;
sl@0
  3999
		case EDisconnect:
sl@0
  4000
			{
sl@0
  4001
			return KErrDisconnected;
sl@0
  4002
			}
sl@0
  4003
			break;
sl@0
  4004
		case ESingleResolution:
sl@0
  4005
			{
sl@0
  4006
			numberOfConfigs = 1;
sl@0
  4007
			}
sl@0
  4008
			break;
sl@0
  4009
		case ENormalResolution:
sl@0
  4010
		default:
sl@0
  4011
			{
sl@0
  4012
			numberOfConfigs = iSystemInis.Count();
sl@0
  4013
			if (numberOfConfigs > 1)
sl@0
  4014
				{
sl@0
  4015
				TVideoInfoV01 info1;
sl@0
  4016
				TVideoInfoV01 info2;
sl@0
  4017
				iSystemInis[0]->VideoInfoForDisplayDriver(aDeviceNumber, 0, info1, ETrue);
sl@0
  4018
				iSystemInis[1]->VideoInfoForDisplayDriver(aDeviceNumber, 0, info2, ETrue);
sl@0
  4019
				if (info1.iSizeInPixels.iWidth == info2.iSizeInPixels.iWidth &&
sl@0
  4020
						info1.iSizeInPixels.iHeight == info2.iSizeInPixels.iHeight)
sl@0
  4021
					{
sl@0
  4022
					numberOfConfigs = 1;	//It looks like all resolutions for this device are the same
sl@0
  4023
					}
sl@0
  4024
				}
sl@0
  4025
			}
sl@0
  4026
		}
sl@0
  4027
	kumemput32(a1,&numberOfConfigs,sizeof(numberOfConfigs));
sl@0
  4028
	if(a2)
sl@0
  4029
		{
sl@0
  4030
		kumemput32(a2,&(iBufferSet[aDeviceNumber].iStateChangeCount),sizeof(iBufferSet[aDeviceNumber].iStateChangeCount));
sl@0
  4031
		}
sl@0
  4032
	return KErrNone;
sl@0
  4033
	}
sl@0
  4034
sl@0
  4035
TInt DMasterIni::SpecificScreenInfo(TInt aDeviceNumber, TAny* a1, TAny* a2)
sl@0
  4036
	{
sl@0
  4037
	TInt config;
sl@0
  4038
	switch(iBufferSet[aDeviceNumber].iDisplayState)
sl@0
  4039
		{
sl@0
  4040
		case ENoResolution: //Do Nothing
sl@0
  4041
			break;
sl@0
  4042
		case EDisconnect:
sl@0
  4043
			{
sl@0
  4044
			return KErrDisconnected;
sl@0
  4045
			}
sl@0
  4046
			break;
sl@0
  4047
		case ESingleResolution: //fill (0,0) as the only element in resolution array
sl@0
  4048
			{
sl@0
  4049
			if(*(TInt*)a1 == 0)
sl@0
  4050
				{
sl@0
  4051
				TVideoInfoV01 info;
sl@0
  4052
				info.iSizeInPixels.iHeight = 0;
sl@0
  4053
				info.iSizeInPixels.iWidth = 0;
sl@0
  4054
				info.iSizeInTwips.iHeight = 0;
sl@0
  4055
				info.iSizeInTwips.iWidth = 0;
sl@0
  4056
				TPtr8 infoPtr((TUint8*)&info, sizeof(info), sizeof(info));
sl@0
  4057
				Kern::InfoCopy(*(TDes8*)a2, infoPtr);
sl@0
  4058
				}
sl@0
  4059
			}
sl@0
  4060
			break;
sl@0
  4061
		case ENormalResolution:
sl@0
  4062
		default:
sl@0
  4063
			{
sl@0
  4064
			kumemget32(&config, a1, sizeof(config));
sl@0
  4065
			TPckgBuf<TVideoInfoV01> vPckg;
sl@0
  4066
			iSystemInis[config]->VideoInfoForDisplayDriver(aDeviceNumber, 0, vPckg(), ETrue);
sl@0
  4067
			Kern::InfoCopy(*(TDes8*)a2,vPckg);
sl@0
  4068
			}
sl@0
  4069
		}
sl@0
  4070
	return KErrNone;
sl@0
  4071
	}
sl@0
  4072
sl@0
  4073
TInt DMasterIni::CurrentScreenInfo(TInt aDeviceNumber, TAny* a1, TAny* /*a2*/)
sl@0
  4074
	{
sl@0
  4075
	switch(iBufferSet[aDeviceNumber].iDisplayState)
sl@0
  4076
		{
sl@0
  4077
		case ENoResolution: //Do Nothing
sl@0
  4078
			break;
sl@0
  4079
		case EDisconnect:
sl@0
  4080
			{
sl@0
  4081
			return KErrDisconnected;
sl@0
  4082
			}
sl@0
  4083
			break;
sl@0
  4084
		case ESingleResolution: //fill (0,0)
sl@0
  4085
			{
sl@0
  4086
			TVideoInfoV01 info;
sl@0
  4087
			info.iSizeInPixels.iHeight = 0;
sl@0
  4088
			info.iSizeInPixels.iWidth = 0;
sl@0
  4089
			info.iSizeInTwips.iHeight = 0;
sl@0
  4090
			info.iSizeInTwips.iWidth = 0;
sl@0
  4091
			TPtr8 infoPtr((TUint8*)&info, sizeof(info), sizeof(info));
sl@0
  4092
			Kern::InfoCopy(*(TDes8*)a1, infoPtr);
sl@0
  4093
			}
sl@0
  4094
			break;
sl@0
  4095
		case ENormalResolution:
sl@0
  4096
		default:
sl@0
  4097
			{
sl@0
  4098
			TPckgBuf<TVideoInfoV01> vPckg;
sl@0
  4099
			systemIni->VideoInfoForDisplayDriver(aDeviceNumber, 0, vPckg(), ETrue);
sl@0
  4100
			Kern::InfoCopy(*(TDes8*)a1,vPckg);
sl@0
  4101
			}
sl@0
  4102
		}
sl@0
  4103
	return KErrNone;
sl@0
  4104
	}
sl@0
  4105
sl@0
  4106
TInt DMasterIni::DoXYHalFunction(TAny* aThis, TInt aFunction, TAny* a1, TAny* a2)
sl@0
  4107
	{
sl@0
  4108
	return static_cast<DMasterIni*>(aThis)->XYHalFunction(aFunction,a1,a2);
sl@0
  4109
	}
sl@0
  4110
sl@0
  4111
TInt DMasterIni::XYHalFunction(TInt aFunction, TAny* a1, TAny* /*a2*/)
sl@0
  4112
	{
sl@0
  4113
	TInt r=KErrNone;
sl@0
  4114
	switch(aFunction)
sl@0
  4115
		{
sl@0
  4116
		case EDigitiserHalXYInfo:
sl@0
  4117
			{
sl@0
  4118
			if(systemIni->iXYInputType==EXYInputPointer)
sl@0
  4119
				{
sl@0
  4120
				TPckgBuf<TDigitiserInfoV01> vPckg;
sl@0
  4121
				TDigitiserInfoV01& xyinfo=vPckg();
sl@0
  4122
				xyinfo.iDigitiserSize.iWidth=max(systemIni->iScreens[0]->iXYInputWidth,systemIni->iScreens[0]->iMaxScreenWidth+systemIni->iScreens[0]->iScreenOffsetX);		
sl@0
  4123
				xyinfo.iDigitiserSize.iHeight=max(systemIni->iScreens[0]->iXYInputHeight,systemIni->iScreens[0]->iMaxScreenHeight+systemIni->iScreens[0]->iScreenOffsetY);
sl@0
  4124
				xyinfo.iOffsetToDisplay.iX=systemIni->iScreens[0]->iScreenOffsetX;
sl@0
  4125
				xyinfo.iOffsetToDisplay.iY=systemIni->iScreens[0]->iScreenOffsetY;
sl@0
  4126
				Kern::InfoCopy(*(TDes8*)a1,vPckg);
sl@0
  4127
				}
sl@0
  4128
			else
sl@0
  4129
				r=KErrNotSupported;
sl@0
  4130
			}
sl@0
  4131
			break;
sl@0
  4132
		default:
sl@0
  4133
			r=KErrNotSupported;
sl@0
  4134
			break;
sl@0
  4135
		}
sl@0
  4136
	return r;
sl@0
  4137
	}
sl@0
  4138
sl@0
  4139
TInt DMasterIni::DoMouseHalFunction(TAny* aThis, TInt aFunction, TAny* a1, TAny* a2)
sl@0
  4140
	{
sl@0
  4141
	return static_cast<DMasterIni*>(aThis)->MouseHalFunction(aFunction,a1,a2);
sl@0
  4142
	}
sl@0
  4143
sl@0
  4144
TInt DMasterIni::MouseHalFunction(TInt aFunction, TAny* a1, TAny* /*a2*/)
sl@0
  4145
	{
sl@0
  4146
	TInt r=KErrNone;
sl@0
  4147
	switch(aFunction)
sl@0
  4148
		{
sl@0
  4149
		case EMouseHalMouseInfo:
sl@0
  4150
			{
sl@0
  4151
			if(systemIni->iXYInputType==EXYInputMouse || systemIni->iXYInputType==EXYInputDeltaMouse)
sl@0
  4152
				{
sl@0
  4153
				TPckgBuf<TMouseInfoV01> vPckg;
sl@0
  4154
				TMouseInfoV01& xyinfo=vPckg();
sl@0
  4155
				xyinfo.iMouseButtons=2;
sl@0
  4156
				xyinfo.iMouseAreaSize.iWidth=max(systemIni->iScreens[0]->iXYInputWidth,systemIni->iScreens[0]->iMaxScreenWidth+systemIni->iScreens[0]->iScreenOffsetX);		
sl@0
  4157
				xyinfo.iMouseAreaSize.iHeight=max(systemIni->iScreens[0]->iXYInputHeight,systemIni->iScreens[0]->iMaxScreenHeight+systemIni->iScreens[0]->iScreenOffsetY);
sl@0
  4158
				xyinfo.iOffsetToDisplay.iX=systemIni->iScreens[0]->iScreenOffsetX;
sl@0
  4159
				xyinfo.iOffsetToDisplay.iY=systemIni->iScreens[0]->iScreenOffsetY;
sl@0
  4160
				Kern::InfoCopy(*(TDes8*)a1,vPckg);
sl@0
  4161
				}
sl@0
  4162
			else
sl@0
  4163
				r=KErrNotSupported;
sl@0
  4164
			}
sl@0
  4165
			break;
sl@0
  4166
		default:
sl@0
  4167
			r=KErrNotSupported;
sl@0
  4168
			break;
sl@0
  4169
		}
sl@0
  4170
	return r;
sl@0
  4171
	}
sl@0
  4172
sl@0
  4173
TInt DMasterIni::DoKbdHalFunction(TAny* /*aThis*/, TInt aFunction, TAny* /*a1*/, TAny* /*a2*/)
sl@0
  4174
	{
sl@0
  4175
	// don't actually do anything, just enough to report a Keyboard is present
sl@0
  4176
	TInt r=KErrNone;
sl@0
  4177
	if(aFunction!=EKeyboardHalKeyboardInfo)
sl@0
  4178
		r=KErrNotSupported;
sl@0
  4179
	return r;
sl@0
  4180
	}
sl@0
  4181
sl@0
  4182
void Inactive()
sl@0
  4183
//
sl@0
  4184
// Window has been minimised.
sl@0
  4185
//
sl@0
  4186
    {
sl@0
  4187
sl@0
  4188
	TRawEvent v;
sl@0
  4189
	v.Set(TRawEvent::EInactive);
sl@0
  4190
    TheEventQ.Add(v);
sl@0
  4191
    }
sl@0
  4192
sl@0
  4193
void UpdateModifiers()
sl@0
  4194
//Updates the modifier key states and sends an event to wserv about the 
sl@0
  4195
//change in state
sl@0
  4196
	{
sl@0
  4197
	TRawEvent v;
sl@0
  4198
	TInt modifiers=0;
sl@0
  4199
    if(GetKeyState(VK_SCROLL)&1)
sl@0
  4200
        modifiers|=EModifierScrollLock;
sl@0
  4201
    if(GetKeyState(VK_NUMLOCK)&1)
sl@0
  4202
        modifiers|=EModifierNumLock;
sl@0
  4203
    if(GetKeyState(VK_CAPITAL)&1)
sl@0
  4204
        modifiers|=EModifierCapsLock;
sl@0
  4205
    v.Set(TRawEvent::EUpdateModifiers,modifiers);
sl@0
  4206
    TheEventQ.Add(v);
sl@0
  4207
	}
sl@0
  4208
	
sl@0
  4209
void Active()
sl@0
  4210
//
sl@0
  4211
// Window has been restored.
sl@0
  4212
// Update the toggling modifiers, reset any others
sl@0
  4213
//
sl@0
  4214
    {
sl@0
  4215
	TRawEvent v;
sl@0
  4216
    UpdateModifiers();
sl@0
  4217
    v.Set(TRawEvent::EActive);
sl@0
  4218
    TheEventQ.Add(v);
sl@0
  4219
    }
sl@0
  4220
sl@0
  4221
sl@0
  4222
void ClearScreen()
sl@0
  4223
    {
sl@0
  4224
sl@0
  4225
    }
sl@0
  4226
sl@0
  4227
sl@0
  4228
TInt DWinsUi::GetVirtualKey(TEmulCommand& aCommand, TInt aX, TInt aY)
sl@0
  4229
	{
sl@0
  4230
	//if the point is in the list of shapes, set the key and return true
sl@0
  4231
	for (TInt keyCount = iVirtualKeys.Count(); --keyCount >= 0; )
sl@0
  4232
		{
sl@0
  4233
		const VirtualKey& vk = *iVirtualKeys[keyCount];
sl@0
  4234
		if (vk.Contains(aX, aY))
sl@0
  4235
			{
sl@0
  4236
			aCommand = vk.Command();
sl@0
  4237
			return vk.Value();
sl@0
  4238
			}
sl@0
  4239
		}
sl@0
  4240
	return -1;
sl@0
  4241
	}
sl@0
  4242
sl@0
  4243
void DWinsUi::TranslateMouseCoords(const TEmulatorFlip aFlipState, const TInt aX, const TInt aY, const TInt aRegionWidth, const TInt aRegionHeight, TInt& aNewX, TInt& aNewY)
sl@0
  4244
	{
sl@0
  4245
	switch (aFlipState)
sl@0
  4246
		{
sl@0
  4247
		case EEmulatorFlipRestore:
sl@0
  4248
			aNewX = aX;
sl@0
  4249
			aNewY = aY;
sl@0
  4250
			break;
sl@0
  4251
		
sl@0
  4252
		case EEmulatorFlipInvert:
sl@0
  4253
			aNewX = aRegionWidth - aX;
sl@0
  4254
			aNewY = aRegionHeight - aY;
sl@0
  4255
			break;
sl@0
  4256
		
sl@0
  4257
		case EEmulatorFlipLeft:
sl@0
  4258
			aNewX = aRegionWidth - aY;
sl@0
  4259
			aNewY = aX;
sl@0
  4260
			break;
sl@0
  4261
sl@0
  4262
		case EEmulatorFlipRight:
sl@0
  4263
			aNewX = aY;
sl@0
  4264
			aNewY = aRegionHeight - aX;
sl@0
  4265
			break;
sl@0
  4266
		}
sl@0
  4267
	}
sl@0
  4268
sl@0
  4269
sl@0
  4270
TBool DWinsUi::OnScreen(TInt aScreen, TInt ax, TInt ay) const
sl@0
  4271
//
sl@0
  4272
// Checks if a point within the Emulator window is on the screen
sl@0
  4273
//
sl@0
  4274
	{
sl@0
  4275
	return (TUint(ax) < TUint(systemIni->iScreens[aScreen]->iScreenWidth) && TUint(ay) < TUint(systemIni->iScreens[aScreen]->iScreenHeight));
sl@0
  4276
	}
sl@0
  4277
sl@0
  4278
TInt DWinsUi::Create(TInt aId)
sl@0
  4279
	{
sl@0
  4280
	TInt r = SetupProperties(aId);
sl@0
  4281
	if (r != KErrNone)
sl@0
  4282
		return r;
sl@0
  4283
	TInt screen;
sl@0
  4284
	DScreenProperties* currentScreen = NULL;
sl@0
  4285
	for(screen=0;screen<iScreens.Count();screen++)
sl@0
  4286
		{
sl@0
  4287
		BITMAPINFOHEADER bitmapinfo;
sl@0
  4288
		currentScreen = iScreens[screen];
sl@0
  4289
		if (readBitmapInfo(&bitmapinfo, currentScreen->iFasciaFileName) == KErrNone)
sl@0
  4290
			{
sl@0
  4291
			currentScreen->iXYInputWidth=bitmapinfo.biWidth;
sl@0
  4292
			currentScreen->iXYInputHeight=bitmapinfo.biHeight;
sl@0
  4293
			}
sl@0
  4294
		currentScreen->iXYInputWidth=max(currentScreen->iXYInputWidth,currentScreen->iScreenWidth+currentScreen->iScreenOffsetX);
sl@0
  4295
		currentScreen->iXYInputHeight=max(currentScreen->iXYInputHeight,currentScreen->iScreenHeight+currentScreen->iScreenOffsetY);
sl@0
  4296
		}
sl@0
  4297
sl@0
  4298
	currentScreen = iScreens[0];
sl@0
  4299
	//note digitizer offsets are relative to EPOC screen 0
sl@0
  4300
	if (-1 == iDigitizerWidth)
sl@0
  4301
		iDigitizerWidth = currentScreen->iXYInputWidth - 
sl@0
  4302
			(currentScreen->iScreenOffsetX + iDigitizerOffsetX);
sl@0
  4303
	else
sl@0
  4304
		currentScreen->iXYInputWidth=max(currentScreen->iXYInputWidth,iDigitizerWidth);
sl@0
  4305
sl@0
  4306
	if (-1 == iDigitizerHeight)
sl@0
  4307
		iDigitizerHeight = currentScreen->iXYInputHeight - 
sl@0
  4308
			(currentScreen->iScreenOffsetY + iDigitizerOffsetY);
sl@0
  4309
	else
sl@0
  4310
		currentScreen->iXYInputHeight=max(currentScreen->iXYInputHeight,iDigitizerHeight);
sl@0
  4311
sl@0
  4312
	return r;
sl@0
  4313
	}
sl@0
  4314
sl@0
  4315
const RDisplayChannel::TPixelFormat DMasterIni::iSupportedPixelFormatTable[] =
sl@0
  4316
	{
sl@0
  4317
		EUidPixelFormatXRGB_8888,
sl@0
  4318
		EUidPixelFormatARGB_8888,
sl@0
  4319
		EUidPixelFormatARGB_8888_PRE,
sl@0
  4320
		EUidPixelFormatXRGB_4444,
sl@0
  4321
		EUidPixelFormatARGB_4444,
sl@0
  4322
		EUidPixelFormatRGB_565 
sl@0
  4323
	};
sl@0
  4324
sl@0
  4325
const TInt DMasterIni::iSupportedPixelFormatTableSize = static_cast<TInt>(sizeof(iSupportedPixelFormatTable)/
sl@0
  4326
		                                                                  sizeof(iSupportedPixelFormatTable[0]));
sl@0
  4327
sl@0
  4328
void DMasterIni::InitBufferFormat(DScreenProperties& aScreenProperties, RDisplayChannel::TBufferFormat& aBufferFormat)
sl@0
  4329
	{
sl@0
  4330
	TUint bitsPerPixel = MaximumBitDepthFromMask(aScreenProperties.iColorDepth);
sl@0
  4331
	
sl@0
  4332
	aBufferFormat.iSize.iWidth = aScreenProperties.iMaxScreenWidth;
sl@0
  4333
	aBufferFormat.iSize.iHeight = aScreenProperties.iMaxScreenHeight;
sl@0
  4334
	switch (bitsPerPixel)
sl@0
  4335
		{
sl@0
  4336
	case 12:	// XRGB4444
sl@0
  4337
		aBufferFormat.iPixelFormat = EUidPixelFormatXRGB_4444;
sl@0
  4338
		break;
sl@0
  4339
	case 16:	// RGB565
sl@0
  4340
		aBufferFormat.iPixelFormat = EUidPixelFormatRGB_565;
sl@0
  4341
			break;
sl@0
  4342
	case 24:	// Really 32bpp, but top 8 unused
sl@0
  4343
	case 32:	// While 32bpp, top 8 will not be used
sl@0
  4344
	default:
sl@0
  4345
		aBufferFormat.iPixelFormat = EUidPixelFormatXRGB_8888;
sl@0
  4346
			break;
sl@0
  4347
		}
sl@0
  4348
	}
sl@0
  4349
sl@0
  4350
TInt DMasterIni::Create()
sl@0
  4351
	{
sl@0
  4352
	TInt configurations = Property::GetInt("ConfigCount", 0);
sl@0
  4353
	if (configurations == 0)
sl@0
  4354
		return KErrGeneral;
sl@0
  4355
sl@0
  4356
	// the pixel formats table is, at present, configuration independent
sl@0
  4357
	TInt count;
sl@0
  4358
	TInt r = KErrNone;
sl@0
  4359
	for (count = 0; count < configurations && r == KErrNone; ++count)
sl@0
  4360
		{
sl@0
  4361
		DWinsUi* dwi = new DWinsUi;
sl@0
  4362
		if (dwi)
sl@0
  4363
			r = dwi->Create(count);
sl@0
  4364
sl@0
  4365
		if (r == KErrNone)
sl@0
  4366
			iSystemInis.Append(dwi);
sl@0
  4367
		}
sl@0
  4368
	if (r != KErrNone)
sl@0
  4369
		return r;
sl@0
  4370
sl@0
  4371
	systemIni = masterIni->iSystemInis[0];
sl@0
  4372
sl@0
  4373
	WinsGuiPowerHandler = DWinsGuiPowerHandler::New();
sl@0
  4374
	if (!WinsGuiPowerHandler)
sl@0
  4375
		return KErrNoMemory;
sl@0
  4376
sl@0
  4377
	TheWin=new HWND[systemIni->iScreens.Count()];
sl@0
  4378
	TheChildWin=new HWND[systemIni->iScreens.Count()];
sl@0
  4379
	TheScreenBitmap=new HBITMAP[systemIni->iScreens.Count()];
sl@0
  4380
	CurrentFlipState=new TEmulatorFlip[systemIni->iScreens.Count()];
sl@0
  4381
sl@0
  4382
	if(!TheWin || !TheChildWin || !TheScreenBitmap || !CurrentFlipState)
sl@0
  4383
		return KErrNoMemory;
sl@0
  4384
	memset(CurrentFlipState,EEmulatorFlipRestore,systemIni->iScreens.Count());
sl@0
  4385
sl@0
  4386
	TBufferSet buffer;
sl@0
  4387
	buffer.iDisplayDriverCount = 0;
sl@0
  4388
	buffer.iDisplayState = ENormalResolution;
sl@0
  4389
	buffer.iDisplayBuffer = 0;
sl@0
  4390
	buffer.iDisplayChannel = NULL;
sl@0
  4391
sl@0
  4392
sl@0
  4393
	TInt i;
sl@0
  4394
	for(i=0;i<systemIni->iScreens.Count();i++)
sl@0
  4395
		{
sl@0
  4396
		DScreenProperties *pScr = systemIni->iScreens[i];
sl@0
  4397
sl@0
  4398
		masterIni->InitBitmapHeader(*pScr, &buffer.iInfo);
sl@0
  4399
		masterIni->InitBufferFormat(*pScr, buffer.iBufferFormat);
sl@0
  4400
sl@0
  4401
		r = masterIni->iBufferSet.Append(buffer);
sl@0
  4402
		if (r != KErrNone)
sl@0
  4403
			return r;
sl@0
  4404
		}
sl@0
  4405
sl@0
  4406
	if (CreateWin32Thread(EThreadEvent, &KernelWindowThread, NULL, ETrue) == NULL)
sl@0
  4407
		return KErrGeneral;
sl@0
  4408
sl@0
  4409
	for(i=0;i<systemIni->iScreens.Count();i++)
sl@0
  4410
		{
sl@0
  4411
		r = Kern::AddHalEntry(EHalGroupDisplay,&DoHalFunction,(TAny*)i,i);
sl@0
  4412
		if (r != KErrNone)
sl@0
  4413
			return r;
sl@0
  4414
		}
sl@0
  4415
sl@0
  4416
	// should really come from Keyboard driver, but not doing it now...
sl@0
  4417
	r = Kern::AddHalEntry(EHalGroupKeyboard,&DoKbdHalFunction,this);
sl@0
  4418
	if (r != KErrNone)
sl@0
  4419
		return r;
sl@0
  4420
sl@0
  4421
	if(systemIni->iXYInputType==EXYInputPointer)
sl@0
  4422
		{
sl@0
  4423
		r = Kern::AddHalEntry(EHalGroupDigitiser,&DoXYHalFunction,this);
sl@0
  4424
		if (r != KErrNone)
sl@0
  4425
			return r;
sl@0
  4426
		}
sl@0
  4427
	else if(systemIni->iXYInputType==EXYInputMouse || systemIni->iXYInputType==EXYInputDeltaMouse)
sl@0
  4428
		{
sl@0
  4429
		r = Kern::AddHalEntry(EHalGroupMouse,&DoMouseHalFunction,this);
sl@0
  4430
		if (r != KErrNone)
sl@0
  4431
			return r;
sl@0
  4432
		}
sl@0
  4433
sl@0
  4434
	return r;
sl@0
  4435
	}
sl@0
  4436
sl@0
  4437
void DMasterIni::InitBitmapHeader(DScreenProperties& aScreenProperties, LPBITMAPV4HEADER aInfo)
sl@0
  4438
	{
sl@0
  4439
	TInt width = aScreenProperties.iMaxScreenWidth; 
sl@0
  4440
	TInt height = aScreenProperties.iMaxScreenHeight;
sl@0
  4441
	TUint bitsPerPixel = MaximumBitDepthFromMask(aScreenProperties.iColorDepth);
sl@0
  4442
sl@0
  4443
	memset(aInfo, 0, sizeof(BITMAPV4HEADER));
sl@0
  4444
sl@0
  4445
	switch (bitsPerPixel)
sl@0
  4446
		{
sl@0
  4447
	case 12:	// XRGB4444
sl@0
  4448
			aInfo->bV4BitCount = 16;
sl@0
  4449
			aInfo->bV4V4Compression = BI_BITFIELDS;
sl@0
  4450
			aInfo->bV4RedMask   = 0x0F00;
sl@0
  4451
			aInfo->bV4GreenMask = 0x00F0;
sl@0
  4452
			aInfo->bV4BlueMask  = 0x000F;
sl@0
  4453
			break;
sl@0
  4454
	case 16:	// RGB565
sl@0
  4455
			aInfo->bV4BitCount = 16;
sl@0
  4456
			aInfo->bV4V4Compression = BI_BITFIELDS;
sl@0
  4457
			aInfo->bV4RedMask   = 0xF800;
sl@0
  4458
			aInfo->bV4GreenMask = 0x07E0;
sl@0
  4459
			aInfo->bV4BlueMask  = 0x001F;
sl@0
  4460
			break;
sl@0
  4461
	case 24:	// Really 32bpp, but top 8 unused
sl@0
  4462
	case 32:	// While 32bpp, top 8 will not be used
sl@0
  4463
	default:
sl@0
  4464
			aInfo->bV4BitCount = 32;
sl@0
  4465
			aInfo->bV4V4Compression = BI_RGB;
sl@0
  4466
			// Mask is implicit for BI_RGB compression
sl@0
  4467
			break;
sl@0
  4468
		}
sl@0
  4469
	
sl@0
  4470
	aInfo->bV4Size = sizeof(BITMAPV4HEADER);
sl@0
  4471
	aInfo->bV4Width = width;
sl@0
  4472
	aInfo->bV4Height = -height;	// Bitmap runs top to bottom
sl@0
  4473
	aInfo->bV4Planes = 1;
sl@0
  4474
	
sl@0
  4475
	TInt bpp = _ALIGN_UP(aInfo->bV4BitCount, 16); //12 & 16 --> 16 ; 24 & 32 --> 32
sl@0
  4476
	TInt widthInPixel = aInfo->bV4Width * bpp;
sl@0
  4477
	//rounding to 32 bits (4 octets) and converting, then, bits to octets;
sl@0
  4478
	TInt scanLineInBytes = _ALIGN_UP(widthInPixel, 32) >> 3; 
sl@0
  4479
	aInfo->bV4SizeImage = -aInfo->bV4Height * scanLineInBytes;
sl@0
  4480
sl@0
  4481
	// Set color space as uncalibrated. All other members are then ignored.
sl@0
  4482
#if defined(LCS_DEVICE_RGB)
sl@0
  4483
	aInfo->bV4CSType = LCS_DEVICE_RGB;
sl@0
  4484
#elif defined(LCS_sRGB)
sl@0
  4485
	aInfo->bV4CSType = LCS_sRGB;
sl@0
  4486
#endif
sl@0
  4487
	}
sl@0
  4488
sl@0
  4489
// Helper function that allocates a single frame buffer. 
sl@0
  4490
static TInt AllocateOneFrameBuffer(TInt aSize, TScreenBuffer &aScreenBuffer)
sl@0
  4491
	{
sl@0
  4492
    // Open shared chunk to the composition framebuffer
sl@0
  4493
	DChunk* chunk = 0;
sl@0
  4494
	// round to page size
sl@0
  4495
	if (aSize <= 0)
sl@0
  4496
		return KErrArgument;
sl@0
  4497
	TUint round = Kern::RoundToPageSize(aSize);
sl@0
  4498
	TLinAddr chunkKernelAddr = 0;
sl@0
  4499
	TUint32 physicalAddress = 0;
sl@0
  4500
	TUint32 chunkMapAttr = 0;
sl@0
  4501
sl@0
  4502
	// create shared chunk
sl@0
  4503
	NKern::ThreadEnterCS();
sl@0
  4504
sl@0
  4505
	TChunkCreateInfo info;
sl@0
  4506
	info.iType = TChunkCreateInfo::ESharedKernelMultiple;
sl@0
  4507
	info.iMaxSize = round;
sl@0
  4508
	info.iMapAttr = 0;
sl@0
  4509
	info.iOwnsMemory = ETrue;
sl@0
  4510
	info.iDestroyedDfc = 0;
sl@0
  4511
sl@0
  4512
	TInt r = Kern::ChunkCreate(info, chunk, chunkKernelAddr, chunkMapAttr);
sl@0
  4513
	if (r == KErrNone)
sl@0
  4514
		{
sl@0
  4515
		// map our chunk to specific 
sl@0
  4516
		r = Kern::ChunkCommitContiguous(chunk, 0, aSize, physicalAddress);
sl@0
  4517
		if (r != KErrNone)
sl@0
  4518
			{
sl@0
  4519
			Kern::ChunkClose(chunk);
sl@0
  4520
			}
sl@0
  4521
		}
sl@0
  4522
sl@0
  4523
	if (r == KErrNone)
sl@0
  4524
		{
sl@0
  4525
		TBufferAddressA* bufferAddress = new TBufferAddressA;
sl@0
  4526
		if (!bufferAddress)
sl@0
  4527
			{
sl@0
  4528
			r = KErrNoMemory;
sl@0
  4529
			}
sl@0
  4530
		else 
sl@0
  4531
			{
sl@0
  4532
			bufferAddress->iAddress = (TAny*)chunkKernelAddr;
sl@0
  4533
			bufferAddress->iChunk = chunk;
sl@0
  4534
sl@0
  4535
			if ((r = aScreenBuffer.iFrameBuffers.Append(bufferAddress->iAddress)) == KErrNone)
sl@0
  4536
				{
sl@0
  4537
				r = aScreenBuffer.iMemChunks.Append(bufferAddress);
sl@0
  4538
				}
sl@0
  4539
			}
sl@0
  4540
		}
sl@0
  4541
	if (r != KErrNone)
sl@0
  4542
		{
sl@0
  4543
		Kern::ChunkClose(chunk);
sl@0
  4544
		}
sl@0
  4545
	NKern::ThreadLeaveCS();
sl@0
  4546
	return KErrNone;
sl@0
  4547
	}
sl@0
  4548
sl@0
  4549
TInt DMasterIni::AllocateFrameBuffers(TInt aScreenNumber, TInt aCount, TInt aSize)
sl@0
  4550
	{
sl@0
  4551
	while (aCount--)
sl@0
  4552
		{
sl@0
  4553
		TInt r = AllocateOneFrameBuffer(aSize, masterIni->iBufferSet[aScreenNumber].iScreenBuffer);
sl@0
  4554
		if (r != KErrNone)
sl@0
  4555
			{
sl@0
  4556
			return r;
sl@0
  4557
			}
sl@0
  4558
		}
sl@0
  4559
	return KErrNone;
sl@0
  4560
	}
sl@0
  4561
sl@0
  4562
void DMasterIni::ReleaseFrameBuffers(TInt aScreenNumber)
sl@0
  4563
	{
sl@0
  4564
	RPointerArray<TAny>& frameBuffers = masterIni->iBufferSet[aScreenNumber].iScreenBuffer.iFrameBuffers;
sl@0
  4565
	RPointerArray<TBufferAddressA>& memChunks = masterIni->iBufferSet[aScreenNumber].iScreenBuffer.iMemChunks;
sl@0
  4566
	RPointerArray<TBufferAddressA>& dsaChunks = masterIni->iBufferSet[aScreenNumber].iDsaBuffer.iMemChunks;
sl@0
  4567
sl@0
  4568
   	NKern::ThreadEnterCS();
sl@0
  4569
	TInt index;
sl@0
  4570
	TInt count = memChunks.Count();
sl@0
  4571
	for (index = 0; index < count; index++)
sl@0
  4572
		{
sl@0
  4573
		Kern::ChunkClose(memChunks[index]->iChunk);
sl@0
  4574
		}
sl@0
  4575
	count = dsaChunks.Count();
sl@0
  4576
	for (index = 0; index < count; index++)
sl@0
  4577
		{
sl@0
  4578
		Kern::ChunkClose(dsaChunks[index]->iChunk);
sl@0
  4579
		}
sl@0
  4580
	NKern::ThreadLeaveCS();
sl@0
  4581
	
sl@0
  4582
	frameBuffers.Reset();
sl@0
  4583
	memChunks.Reset();
sl@0
  4584
	dsaChunks.Reset();
sl@0
  4585
	}
sl@0
  4586
sl@0
  4587
sl@0
  4588
TProcessAddrEntry::TProcessAddrEntry(DProcess *aProcess, TUint8* aAddress): 
sl@0
  4589
	iProcess(aProcess), iAddress(aAddress)
sl@0
  4590
	{
sl@0
  4591
	}
sl@0
  4592
sl@0
  4593
sl@0
  4594
/**
sl@0
  4595
Contruct a Shared Chunk cleanup object which will be used to clean up 
sl@0
  4596
after the process/address table entry. 
sl@0
  4597
*/
sl@0
  4598
TChunkCleanup::TChunkCleanup(DProcess* aProcess, TInt aScreenNumber)
sl@0
  4599
    : TDfc((TDfcFn)TChunkCleanup::ChunkDestroyed,this,Kern::SvMsgQue(),0)
sl@0
  4600
    , iProcess(aProcess)
sl@0
  4601
    , iScreenNumber(aScreenNumber)
sl@0
  4602
    , iIndex(-1)
sl@0
  4603
    {}
sl@0
  4604
sl@0
  4605
/**
sl@0
  4606
Cancel the action of the cleanup object.
sl@0
  4607
*/
sl@0
  4608
void TChunkCleanup::Cancel()
sl@0
  4609
    {
sl@0
  4610
    // Clear iProcess which means that when the DFC gets queued on chunk destruction
sl@0
  4611
    // our ChunkDestroyed method will do nothing other than cleanup itself.
sl@0
  4612
    iProcess = NULL;
sl@0
  4613
    }
sl@0
  4614
sl@0
  4615
/**
sl@0
  4616
Callback function called when the DFC runs, i.e. when a chunk is destroyed.
sl@0
  4617
*/
sl@0
  4618
void TChunkCleanup::ChunkDestroyed(TChunkCleanup* aSelf)
sl@0
  4619
    {
sl@0
  4620
    DProcess* process = aSelf->iProcess;
sl@0
  4621
    TInt screenNumber = aSelf->iScreenNumber;
sl@0
  4622
    TUint index = aSelf->iIndex;
sl@0
  4623
    // If we haven't been Cancelled...
sl@0
  4624
    if(process && index != -1)
sl@0
  4625
        {
sl@0
  4626
    	if (masterIni->iBufferSet[screenNumber].iProcAddrTable[index].iProcess == process)
sl@0
  4627
    		{
sl@0
  4628
    		masterIni->iBufferSet[screenNumber].iProcAddrTable[index].iProcess = 0;
sl@0
  4629
    		}
sl@0
  4630
    	else
sl@0
  4631
    		{
sl@0
  4632
    		__KTRACE_OPT(KEXTENSION,Kern::Printf("Oops! Someone has messed up our process index!"));
sl@0
  4633
    		}
sl@0
  4634
        }
sl@0
  4635
sl@0
  4636
    // We've finished so now delete ourself
sl@0
  4637
    delete aSelf;
sl@0
  4638
    }
sl@0
  4639
sl@0
  4640
sl@0
  4641
TInt DMasterIni::DisplayMemoryHandle(TInt aScreenNumber, TInt& aHandle)
sl@0
  4642
	{
sl@0
  4643
	if (iBufferSet[aScreenNumber].iDsaBuffer.iMemChunks.Count() == 0)
sl@0
  4644
		{	
sl@0
  4645
		int r;
sl@0
  4646
		r = AllocateOneFrameBuffer(iMaxSizeInBytes, iBufferSet[aScreenNumber].iDsaBuffer);
sl@0
  4647
		if (KErrNone != r)
sl@0
  4648
			{
sl@0
  4649
			return r;
sl@0
  4650
			}
sl@0
  4651
		__ASSERT_DEBUG(iBufferSet[aScreenNumber].iDisplayChannel, Fault(EGuiNoDisplayChannel));
sl@0
  4652
		iBufferSet[aScreenNumber].iDisplayChannel->SetLegacyBuffer(iBufferSet[aScreenNumber].iDsaBuffer.iFrameBuffers[0]);
sl@0
  4653
		}
sl@0
  4654
	
sl@0
  4655
	aHandle = Kern::MakeHandleAndOpen(&Kern::CurrentThread(), 
sl@0
  4656
			iBufferSet[aScreenNumber].iDsaBuffer.iMemChunks[0]->iChunk);
sl@0
  4657
	
sl@0
  4658
	if (aHandle < 0)
sl@0
  4659
		{
sl@0
  4660
		return aHandle;
sl@0
  4661
		}
sl@0
  4662
	
sl@0
  4663
	return KErrNone;
sl@0
  4664
	}
sl@0
  4665
sl@0
  4666
sl@0
  4667
sl@0
  4668
// Find the address of the display memory. 
sl@0
  4669
TInt DMasterIni::DisplayMemoryAddress(TInt aScreenNumber, TInt& aAddress)
sl@0
  4670
	{
sl@0
  4671
	TBufferSet &bufferSet = iBufferSet[aScreenNumber]; 
sl@0
  4672
	DProcess *process = &Kern::CurrentProcess();
sl@0
  4673
	TInt firstFree = -1;
sl@0
  4674
	NKern::FMWait(&iLock);
sl@0
  4675
	TUint count = bufferSet.iProcAddrTable.Count();
sl@0
  4676
	for(TUint i = 0; i < count; ++i)
sl@0
  4677
		{
sl@0
  4678
		DProcess *curProcess = bufferSet.iProcAddrTable[i].iProcess;
sl@0
  4679
		if (curProcess == process)
sl@0
  4680
			{
sl@0
  4681
			aAddress = reinterpret_cast<TInt>(bufferSet.iProcAddrTable[i].iAddress);
sl@0
  4682
			NKern::FMSignal(&iLock);
sl@0
  4683
			return KErrNone;
sl@0
  4684
			}
sl@0
  4685
		if (curProcess == 0 && firstFree == -1)
sl@0
  4686
			{
sl@0
  4687
			firstFree = i;
sl@0
  4688
			}
sl@0
  4689
		}
sl@0
  4690
	NKern::FMSignal(&iLock);
sl@0
  4691
	// If we get here, we couldn't find the process in the iProcAddrTable. 
sl@0
  4692
	// Create a new Process Address entry. 
sl@0
  4693
	// Step 1
sl@0
  4694
	// Create a dummy chunk so that we can detect when the process dies, 
sl@0
  4695
	// give a handle to the user [but don't actually let the process KNOW what the handle is
sl@0
  4696
	// so the user process can't do anything silly with the chunk]. Close our side of the
sl@0
  4697
	// chunk to make sure there is only one reference to it. 
sl@0
  4698
	DChunk* chunk = 0;
sl@0
  4699
	// find page size for one page. 
sl@0
  4700
	TUint round = Kern::RoundToPageSize(1);
sl@0
  4701
	TLinAddr chunkKernelAddr = 0;
sl@0
  4702
	TUint32 chunkMapAttr = 0;
sl@0
  4703
	
sl@0
  4704
	// create shared chunk
sl@0
  4705
	NKern::ThreadEnterCS();
sl@0
  4706
	// Cleanup object, used to issue a DFC when the chunk is closed (and 
sl@0
  4707
	// as the handle of the chunk is not given to the process, it can only
sl@0
  4708
	// be closed when the process terminates!)
sl@0
  4709
	TChunkCleanup *cleanup = new TChunkCleanup(process, aScreenNumber);
sl@0
  4710
	if (!cleanup)
sl@0
  4711
		{
sl@0
  4712
		NKern::ThreadLeaveCS();
sl@0
  4713
		return KErrNoMemory;
sl@0
  4714
		}
sl@0
  4715
sl@0
  4716
	TChunkCreateInfo info;
sl@0
  4717
	info.iType = TChunkCreateInfo::ESharedKernelMultiple;
sl@0
  4718
	info.iMaxSize = round;
sl@0
  4719
	info.iMapAttr = 0;
sl@0
  4720
	info.iOwnsMemory = ETrue;
sl@0
  4721
	info.iDestroyedDfc = cleanup;
sl@0
  4722
sl@0
  4723
	TInt r = Kern::ChunkCreate(info, chunk, chunkKernelAddr, chunkMapAttr);
sl@0
  4724
	
sl@0
  4725
	if (r != KErrNone)
sl@0
  4726
		{
sl@0
  4727
		delete cleanup;
sl@0
  4728
		NKern::ThreadLeaveCS();
sl@0
  4729
		return r;
sl@0
  4730
		}
sl@0
  4731
	
sl@0
  4732
	
sl@0
  4733
	// Create a new handle for the user thread. 
sl@0
  4734
    r = Kern::MakeHandleAndOpen(&Kern::CurrentThread(), chunk);
sl@0
  4735
	Kern::ChunkClose(chunk);
sl@0
  4736
	if (r <= 0)
sl@0
  4737
		{
sl@0
  4738
		NKern::ThreadLeaveCS();
sl@0
  4739
		return r;
sl@0
  4740
		}
sl@0
  4741
sl@0
  4742
	// Step 2
sl@0
  4743
	// Create a second handle for the chunk to the DSA buffer.
sl@0
  4744
	// First part: Make sure there is a DisplayMemoryHandle;
sl@0
  4745
	TInt handle = 0;
sl@0
  4746
	r = DisplayMemoryHandle(aScreenNumber, handle); 
sl@0
  4747
	if (r != KErrNone)
sl@0
  4748
		{
sl@0
  4749
		Kern::ChunkClose(chunk);
sl@0
  4750
		NKern::ThreadLeaveCS();
sl@0
  4751
		return r;
sl@0
  4752
		}
sl@0
  4753
	
sl@0
  4754
	DChunk *dsaChunk = bufferSet.iDsaBuffer.iMemChunks[0]->iChunk;
sl@0
  4755
	
sl@0
  4756
	// Step 3
sl@0
  4757
	// Get the base addrss and insert into table. 
sl@0
  4758
	TUint8* baseAddress = Kern::ChunkUserBase(dsaChunk, &Kern::CurrentThread());
sl@0
  4759
	NKern::FMWait(&iLock);
sl@0
  4760
	// Optimistically, the place we found earlier in the table is still free.
sl@0
  4761
	if (firstFree != -1 && bufferSet.iProcAddrTable[firstFree].iProcess != 0)
sl@0
  4762
		{
sl@0
  4763
		// If not, we go find another one.
sl@0
  4764
		firstFree = -1;
sl@0
  4765
		TUint count = bufferSet.iProcAddrTable.Count();
sl@0
  4766
		for(TUint i = 0; i < count; ++i)
sl@0
  4767
			{
sl@0
  4768
			if (bufferSet.iProcAddrTable[i].iProcess == 0)
sl@0
  4769
				{
sl@0
  4770
				firstFree = i;
sl@0
  4771
				break;
sl@0
  4772
				}
sl@0
  4773
			}
sl@0
  4774
		}
sl@0
  4775
	// Check if there is a free entry - if so, re-use it. 
sl@0
  4776
	if (firstFree != -1)
sl@0
  4777
		{
sl@0
  4778
		bufferSet.iProcAddrTable[firstFree].iProcess = process;
sl@0
  4779
		bufferSet.iProcAddrTable[firstFree].iAddress = baseAddress;
sl@0
  4780
		cleanup->SetIndex(firstFree);
sl@0
  4781
		NKern::FMSignal(&iLock);
sl@0
  4782
		}
sl@0
  4783
	else
sl@0
  4784
		{
sl@0
  4785
		// No free entry. Append it to the list. 
sl@0
  4786
		NKern::FMSignal(&iLock);
sl@0
  4787
		TProcessAddrEntry entry(process, baseAddress);
sl@0
  4788
		r = bufferSet.iProcAddrTable.Append(entry);
sl@0
  4789
		if (r != KErrNone)
sl@0
  4790
			{
sl@0
  4791
			Kern::ChunkClose(chunk);
sl@0
  4792
			NKern::ThreadLeaveCS();
sl@0
  4793
			return r;
sl@0
  4794
			}
sl@0
  4795
		// We added it at the end - so we start from the back and check for the 
sl@0
  4796
		// process, as some other process COULD have added one after us, so we 
sl@0
  4797
		// can't just use the count for index!
sl@0
  4798
		TUint index;
sl@0
  4799
		for(index = bufferSet.iProcAddrTable.Count()-1; index; --index)
sl@0
  4800
			{
sl@0
  4801
			if (bufferSet.iProcAddrTable[index].iProcess == process 
sl@0
  4802
					&& bufferSet.iProcAddrTable[index].iAddress != baseAddress)
sl@0
  4803
				{
sl@0
  4804
				break;
sl@0
  4805
				}
sl@0
  4806
			}
sl@0
  4807
		cleanup->SetIndex(index);
sl@0
  4808
		}
sl@0
  4809
	aAddress = reinterpret_cast<TInt>(baseAddress);
sl@0
  4810
sl@0
  4811
	NKern::ThreadLeaveCS();
sl@0
  4812
	return KErrNone;
sl@0
  4813
	}
sl@0
  4814
sl@0
  4815
EXPORT_C TInt WinsGui::CurrentConfiguration()
sl@0
  4816
	{
sl@0
  4817
	return ::CurrentConfiguration;
sl@0
  4818
	}
sl@0
  4819
sl@0
  4820
GLDEF_C void Fault(TGuiPanic aPanic)
sl@0
  4821
	{
sl@0
  4822
	Kern::Fault("WINS-UI",aPanic);
sl@0
  4823
	}
sl@0
  4824
sl@0
  4825
DECLARE_STANDARD_EXTENSION()
sl@0
  4826
	{
sl@0
  4827
	__KTRACE_OPT(KEXTENSION,Kern::Printf("Starting Emulator GUI"));
sl@0
  4828
sl@0
  4829
	// if NoGui property == true do nothing
sl@0
  4830
	if (Property::GetBool("NoGui",EFalse))
sl@0
  4831
		return KErrNone;
sl@0
  4832
sl@0
  4833
	// create keyboard driver
sl@0
  4834
	TInt r=KErrNoMemory;
sl@0
  4835
	masterIni = new DMasterIni;
sl@0
  4836
	if (masterIni)
sl@0
  4837
		{
sl@0
  4838
		r = masterIni->Create();
sl@0
  4839
		if (r!= KErrNone)
sl@0
  4840
			{
sl@0
  4841
			return r;
sl@0
  4842
			}
sl@0
  4843
		}
sl@0
  4844
	
sl@0
  4845
	DMultiTouch::iMultiTouchSupported = DMultiTouch::Init();
sl@0
  4846
sl@0
  4847
	// Create multitouch when necessary
sl@0
  4848
	if (systemIni->MultiTouchEnabled() && systemIni->GCEEnabled() && DMultiTouch::iMultiTouchSupported)
sl@0
  4849
		{
sl@0
  4850
		TheMultiTouch = new DMultiTouch(systemIni->MultiTouchProximityStep(),systemIni->MultiTouchPressureStep());
sl@0
  4851
		if(!TheMultiTouch)
sl@0
  4852
			{
sl@0
  4853
			r = KErrNoMemory;
sl@0
  4854
			__KTRACE_OPT(KEXTENSION,Kern::Printf("Returns %d",r));
sl@0
  4855
			return r;
sl@0
  4856
			}
sl@0
  4857
		DMultiTouch::iMultiTouchCreated = TRUE;
sl@0
  4858
		}
sl@0
  4859
sl@0
  4860
	__KTRACE_OPT(KEXTENSION,Kern::Printf("Returns %d",r));
sl@0
  4861
	return r;
sl@0
  4862
	}
sl@0
  4863
sl@0
  4864
TInt DWinsUi::DoDefineEmulatorControlHotKey(TAny* aPtr, const char* aValue)
sl@0
  4865
	{
sl@0
  4866
	return static_cast<DWinsUi*>(aPtr)->DefineEmulatorControlHotKey(aValue);
sl@0
  4867
	}
sl@0
  4868
sl@0
  4869
sl@0
  4870
TInt DWinsUi::DefineEmulatorControlHotKey(const char* aValue)
sl@0
  4871
	{
sl@0
  4872
	const char* beg = skipws(aValue);
sl@0
  4873
	const char* end = skiptok(beg);
sl@0
  4874
	TInt err = KErrNone;
sl@0
  4875
	
sl@0
  4876
	TEmulCommand command = ENoCommand;
sl@0
  4877
	TInt data = 0;
sl@0
  4878
	if (_strnicmp(beg, "SelectConfig", end-beg) == 0)
sl@0
  4879
		{
sl@0
  4880
		//get the int param which is the config to switch to
sl@0
  4881
		beg = end;
sl@0
  4882
		char * e;
sl@0
  4883
		data = strtol(beg, &e,0);
sl@0
  4884
		if (beg == e)
sl@0
  4885
			err = KErrArgument;
sl@0
  4886
		end = e;
sl@0
  4887
		command = ESelectConfig;
sl@0
  4888
		}
sl@0
  4889
	else if(_strnicmp(beg, "NextConfig", end-beg) == 0)
sl@0
  4890
		{
sl@0
  4891
		command = ENextConfig;
sl@0
  4892
		}
sl@0
  4893
	else
sl@0
  4894
		{
sl@0
  4895
		err = KErrArgument;
sl@0
  4896
		}
sl@0
  4897
	if (err != KErrNone)
sl@0
  4898
		return err;
sl@0
  4899
	
sl@0
  4900
	// get the keys	
sl@0
  4901
	KeyCombination* pCombination = new KeyCombination(data, command);
sl@0
  4902
	if (!pCombination)
sl@0
  4903
		return KErrNoMemory;	
sl@0
  4904
	
sl@0
  4905
	beg = skipws(end);
sl@0
  4906
	const char* end2;	
sl@0
  4907
	for (TInt i=0;i<KMaxHotKeyCombinationLength;i++)
sl@0
  4908
		{
sl@0
  4909
		TInt key=KErrNotFound;		
sl@0
  4910
		end2 = skiptok(beg);
sl@0
  4911
		TPtrC8 name((const TUint8*)beg, end2-beg);
sl@0
  4912
		if ((key=iKeyboard.GetScanCode(name))!=KErrNotFound)
sl@0
  4913
			pCombination->AddKey((TStdScanCode)key);
sl@0
  4914
		
sl@0
  4915
		if (beg == end2 || *end2++ != ',') 
sl@0
  4916
			break;		
sl@0
  4917
		beg = end2;
sl@0
  4918
		}
sl@0
  4919
	return iControlHotKeys.Append(pCombination);
sl@0
  4920
	}