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
	}