1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/boardsupport/emulator/emulatorbsp/specific/gui.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,4920 @@
1.4 +// Copyright (c) 1995-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +// wins\specific\gui.cpp
1.18 +//
1.19 +//
1.20 +#define WINVER 0x0500
1.21 +
1.22 +#include "gui.h"
1.23 +#include <emulator.h>
1.24 +#include <assp.h>
1.25 +#include <kernel/kern_priv.h>
1.26 +#include <kernel/kpower.h>
1.27 +#include "variant.h"
1.28 +#include "resource.h"
1.29 +#include "winsgui.h"
1.30 +#include "display_chan.h"
1.31 +#include "pixelformats.h"
1.32 +#include "multitouch.h"
1.33 +
1.34 +#include "monitors.h"
1.35 +
1.36 +//Define these so that emulator generates varying values for gce stride and offset.
1.37 +//By default in emulator, stride is exactly right for display resolution and offset is zero
1.38 +//Setting these will identify code which incorrectly calculates these factors instead of requesting them
1.39 +//Note that multiples of 4 bytes are preferred for various reasons.
1.40 +//[3/5/07 The Secure presentation burffer ignores stride extra because it uses a windows bitmap header to render.]
1.41 +// #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
1.42 +// #define TEST_GCE_VARIABLE_START_EXTRA 16 //A multiple of this is added to each mode's start address in bytes
1.43 +// #define ASSYMETRIC_SQUARE_STRIDE //If this is defined and the width==height the the stride will not be the same!
1.44 +
1.45 +enum
1.46 + {
1.47 + KMaskModeNum=0x0FFFFFFF,
1.48 + KMaskModeFlag8=0x80000000,
1.49 + KMaskModeFlag4=0x40000000,
1.50 + KMaskModeFlag2=0x20000000,
1.51 + KMaskModeFlag1=0x10000000,
1.52 +
1.53 + KModeFlagFlipped=KMaskModeFlag8,
1.54 +
1.55 + };
1.56 +enum
1.57 + {
1.58 + KMaskScreenNum=0x0FFF,
1.59 + KMaskScreenFlag8=0x8000,
1.60 + KMaskScreenFlag4=0x4000,
1.61 + KMaskScreenFlag2=0x2000,
1.62 + KMaskScreenFlag1=0x1000,
1.63 +
1.64 + KScreenFlagSecure=KMaskScreenFlag8,
1.65 +
1.66 + };
1.67 +const TInt KMaxDisplayColors=16777216;
1.68 +const TInt KMaxDisplayContrast=1;
1.69 +
1.70 +static TEmulatorFlip* CurrentFlipState=NULL;
1.71 +static TInt CurrentConfiguration = 0;
1.72 +static TInt SavedFlipMessage = 0;
1.73 +
1.74 +DWinsUi *systemIni=NULL;
1.75 +DMasterIni* masterIni;
1.76 +
1.77 +DMultiTouch* TheMultiTouch;
1.78 +static HWND TheControlWin;
1.79 +static HWND* TheChildWin=NULL;
1.80 +static HWND* TheWin=NULL;
1.81 +static HWND hwndStatus; // To display the X,Y,Z information of each mouse
1.82 +static TInt VirtualKeyPressed = EStdKeyNull;
1.83 +static HBITMAP* TheScreenBitmap=NULL;
1.84 +static TUint LedMask;
1.85 +static TBool WsSwitchOnScreen;
1.86 +
1.87 +const char * DefaultWindowTitle = "Symbian OS Emulator";
1.88 +
1.89 +#ifdef __VC32__
1.90 +
1.91 +#ifdef _DEBUG
1.92 +const char * VersionText = " - wins udeb";
1.93 +#else
1.94 +const char * VersionText = " - wins urel";
1.95 +#endif
1.96 +
1.97 +#else
1.98 +#ifdef __CW32__
1.99 +
1.100 +#ifdef _DEBUG
1.101 +const char * VersionText = " - winscw udeb";
1.102 +#else
1.103 +const char * VersionText = " - winscw urel";
1.104 +#endif
1.105 +
1.106 +#else
1.107 +//not winscw or wins!
1.108 +#ifdef _DEBUG
1.109 +const char * VersionText = " - unknown udeb";
1.110 +#else
1.111 +const char * VersionText = " - unknown urel");
1.112 +#endif
1.113 +
1.114 +#endif
1.115 +#endif
1.116 +
1.117 +void Inactive();
1.118 +void Active();
1.119 +void DrawLeds();
1.120 +void UpdateModifiers();
1.121 +TInt DisplayHalFunction(TAny*, TInt aFunction, TAny* a1, TAny* a2);
1.122 +LOCAL_C TBool PaintWindowFromBuffer(HWND hWnd);
1.123 +
1.124 +GLDEF_C const char* skipws(const char* aPtr)
1.125 + {
1.126 + while (isspace(*aPtr))
1.127 + ++aPtr;
1.128 + return aPtr;
1.129 + }
1.130 +
1.131 +GLDEF_C const char* skiptok(const char* aPtr)
1.132 + {
1.133 + while (isalnum(*aPtr))
1.134 + ++aPtr;
1.135 + return aPtr;
1.136 + }
1.137 +
1.138 +GLDEF_C TInt CompareI(const TDesC8& aLhs, const TDesC8& aRhs)
1.139 +//
1.140 +// Case insensitive comparison of descriptors
1.141 +// (TDesC::CompareF not available to kernel side code)
1.142 +//
1.143 + {
1.144 + TInt ll = aLhs.Length();
1.145 + TInt rl = aRhs.Length();
1.146 + TInt len = Min(ll, rl);
1.147 + TInt k = _strnicmp((const char*)aLhs.Ptr(), (const char*)aRhs.Ptr(), len);
1.148 + return k != 0 ? k : ll - rl;
1.149 + }
1.150 +
1.151 +GLDEF_C TInt MultiProperty(TInt (*aHandler)(TAny* aObj, const char*), TAny* aPtr, const char* aProperty)
1.152 + {
1.153 + const char* value = Property::GetString(aProperty);
1.154 + if (!value)
1.155 + return KErrNone;
1.156 + for (;;)
1.157 + {
1.158 + TInt r = aHandler(aPtr, value);
1.159 + if (r != KErrNone)
1.160 + return r;
1.161 + const char* ev = strchr(value, ';');
1.162 + if (!ev)
1.163 + break;
1.164 + value = ev + 1;
1.165 + }
1.166 + return KErrNone;
1.167 + }
1.168 +
1.169 +class DWinsGuiPowerHandler : public DPowerHandler
1.170 + {
1.171 +public: // from DPowerHandler
1.172 + void PowerDown(TPowerState);
1.173 + void PowerUp();
1.174 +public:
1.175 + static DWinsGuiPowerHandler* New();
1.176 + void ScreenOn();
1.177 + void ScreenOff();
1.178 + void ScreenOn(TInt aScreen);
1.179 + void ScreenOff(TInt aScreen);
1.180 +public:
1.181 + DWinsGuiPowerHandler();
1.182 + TBool ProcessEvent(const TRawEvent* aEvent);
1.183 + TBool ProcessEventDfc(const TRawEvent* aEvent);
1.184 + TBool iStandby;
1.185 + };
1.186 +
1.187 +static DWinsGuiPowerHandler* WinsGuiPowerHandler;
1.188 +
1.189 +_LIT(KWinsGuiName, "WinsGui");
1.190 +
1.191 +DWinsGuiPowerHandler* DWinsGuiPowerHandler::New()
1.192 + {
1.193 + DWinsGuiPowerHandler* self = new DWinsGuiPowerHandler();
1.194 + if (!self)
1.195 + return NULL;
1.196 + self->Add();
1.197 +
1.198 + return self;
1.199 + }
1.200 +
1.201 +DWinsGuiPowerHandler::DWinsGuiPowerHandler() : DPowerHandler(KWinsGuiName)
1.202 + {
1.203 + }
1.204 +
1.205 +void DWinsGuiPowerHandler::ScreenOff()
1.206 + {
1.207 + for(TInt ix=0;ix<systemIni->iScreens.Count();ix++)
1.208 + ScreenOff(ix);
1.209 + }
1.210 +
1.211 +void DWinsGuiPowerHandler::ScreenOn()
1.212 + {
1.213 + for(TInt ix=0;ix<systemIni->iScreens.Count();ix++)
1.214 + ScreenOn(ix);
1.215 + }
1.216 +
1.217 +void DWinsGuiPowerHandler::ScreenOff(TInt aScreen)
1.218 + {
1.219 + PostMessageA(TheWin[aScreen], WM_EMUL_POWER_ON, FALSE, NULL);
1.220 + systemIni->iScreens[aScreen]->iScreenOff = ETrue;
1.221 + }
1.222 +
1.223 +void DWinsGuiPowerHandler::ScreenOn(TInt aScreen)
1.224 + {
1.225 + PostMessageA(TheWin[aScreen], WM_EMUL_POWER_ON, TRUE, NULL);
1.226 + systemIni->iScreens[aScreen]->iScreenOff = EFalse;
1.227 + }
1.228 +
1.229 +void DWinsGuiPowerHandler::PowerDown(TPowerState aState)
1.230 + {
1.231 + if (aState == EPwStandby)
1.232 + iStandby = ETrue;
1.233 + ScreenOff();
1.234 + PowerDownDone();
1.235 + }
1.236 +
1.237 +
1.238 +void DWinsGuiPowerHandler::PowerUp()
1.239 + {
1.240 + iStandby = EFalse;
1.241 + ScreenOn();
1.242 + PowerUpDone();
1.243 + }
1.244 +
1.245 +// called in the interrupt context
1.246 +TBool DWinsGuiPowerHandler::ProcessEvent(const TRawEvent* aEvent)
1.247 + {
1.248 + if (!iStandby)
1.249 + // Pass through
1.250 + return EFalse;
1.251 +
1.252 + if ((aEvent->Type() == TRawEvent::EKeyDown))
1.253 + {
1.254 + Wins::Self() -> AssertWakeupSignal();
1.255 + }
1.256 +
1.257 + // Ignore
1.258 + return ETrue;
1.259 + }
1.260 +
1.261 +// called in DFC
1.262 +TBool DWinsGuiPowerHandler::ProcessEventDfc(const TRawEvent* aEvent)
1.263 + {
1.264 + if (aEvent->Type() == TRawEvent::EKeyDown)
1.265 + {
1.266 + Wins::Self() -> WakeupEvent();
1.267 + if (aEvent->ScanCode() == EStdKeyF5)
1.268 + {
1.269 + // Simulate a media change interrupt (media removed)
1.270 + Wins::MediaChangeCallBack();
1.271 + *Wins::MediaDoorOpenPtr()=ETrue;
1.272 + // Ignore
1.273 + return ETrue;
1.274 + }
1.275 + if (aEvent->ScanCode() == EStdKeyF8)
1.276 + {
1.277 + TRawEvent v;
1.278 + v.Set(TRawEvent::ECaseClose);
1.279 + Kern::AddEvent(v);
1.280 + // Ignore
1.281 + return ETrue;
1.282 + }
1.283 + if (aEvent->ScanCode() == EStdKeyF8)
1.284 + {
1.285 + TRawEvent v;
1.286 + v.Set(TRawEvent::ECaseClose);
1.287 + Kern::AddEvent(v);
1.288 + // Ignore
1.289 + return ETrue;
1.290 + }
1.291 + if (aEvent->ScanCode() == EStdKeyOff)
1.292 + {
1.293 + // Pass through
1.294 + return EFalse;
1.295 + }
1.296 + if (aEvent->ScanCode() == EStdKeyF10)
1.297 + {
1.298 + TRawEvent v;
1.299 + v.Set(TRawEvent::ESwitchOff);
1.300 + Kern::AddEvent(v);
1.301 + // Ignore
1.302 + return ETrue;
1.303 + }
1.304 + if (aEvent->ScanCode() == EStdKeyF11)
1.305 + {
1.306 + TRawEvent v;
1.307 + v.Set(TRawEvent::ECaseOpen);
1.308 + Kern::AddEvent(v);
1.309 + // Ignore
1.310 + return ETrue;
1.311 + }
1.312 + }
1.313 + else if (aEvent->Type() == TRawEvent::EKeyUp)
1.314 + {
1.315 + if (aEvent->ScanCode() == EStdKeyF10)
1.316 + // Ignore
1.317 + return ETrue;
1.318 +
1.319 + if (aEvent->ScanCode() == EStdKeyF5)
1.320 + {
1.321 + // Simulate a media change interrupt (media Present)
1.322 + *Wins::MediaDoorOpenPtr()=EFalse;
1.323 + return ETrue;
1.324 + }
1.325 + }
1.326 +
1.327 + // Path through
1.328 + return EFalse;
1.329 + }
1.330 +
1.331 +class EventQ
1.332 + {
1.333 + enum {ESize = 16};
1.334 +public:
1.335 + EventQ();
1.336 + void Add(const TRawEvent& aEvent);
1.337 +private:
1.338 + static void Dfc(TAny* aPtr);
1.339 + void Empty();
1.340 +private:
1.341 + TDfc iDfc;
1.342 + TRawEvent* iTail;
1.343 + TRawEvent iQ[ESize];
1.344 + };
1.345 +
1.346 +EventQ::EventQ()
1.347 + :iDfc(&EventQ::Dfc, this, Kern::DfcQue0(), 6), iTail(iQ)
1.348 + {}
1.349 +
1.350 +
1.351 +void EventQ::Add(const TRawEvent& aEvent)
1.352 + {
1.353 + StartOfInterrupt();
1.354 + if (WinsGuiPowerHandler->ProcessEvent(&aEvent))
1.355 + {
1.356 + EndOfInterrupt();
1.357 + return;
1.358 + }
1.359 +
1.360 + TRawEvent* pE = iTail;
1.361 + if (pE != &iQ[ESize])
1.362 + {
1.363 + *pE = aEvent;
1.364 + iTail = pE + 1;
1.365 + if (pE == iQ)
1.366 + iDfc.Add();
1.367 + }
1.368 + EndOfInterrupt();
1.369 + }
1.370 +
1.371 +void EventQ::Dfc(TAny* aPtr)
1.372 + {
1.373 + static_cast<EventQ*>(aPtr)->Empty();
1.374 + }
1.375 +
1.376 +void EventQ::Empty()
1.377 +//
1.378 +// Called in the DFC
1.379 +//
1.380 + {
1.381 + TInt irq;
1.382 + TRawEvent* pE = iQ;
1.383 + for (;;)
1.384 + {
1.385 + if (!WinsGuiPowerHandler->ProcessEventDfc(pE))
1.386 + Kern::AddEvent(*pE);
1.387 + ++pE;
1.388 + irq = NKern::DisableAllInterrupts();
1.389 + if (pE == iTail)
1.390 + break;
1.391 + NKern::RestoreInterrupts(irq);
1.392 + }
1.393 + iTail = iQ;
1.394 + NKern::RestoreInterrupts(irq);
1.395 + }
1.396 +
1.397 +LOCAL_D EventQ TheEventQ;
1.398 +
1.399 +// Virtual keys
1.400 +
1.401 +
1.402 +VirtualKey::VirtualKey(const TInt aCommandData, const TEmulCommand aCommand) : iCommand(aCommand), iData(aCommandData)
1.403 + {
1.404 + }
1.405 +
1.406 +TBool VKRect::Contains(TInt aX, TInt aY) const
1.407 + {
1.408 + return (aX >= iLeft && aX < iRight && aY >= iTop && aY < iBottom);
1.409 + }
1.410 +
1.411 +VKRect::VKRect(const TInt aCommandData, const TEmulCommand aCommand, TInt aX, TInt aY, TInt aWidth, TInt aHeight) :
1.412 + VirtualKey(aCommandData, aCommand)
1.413 + {
1.414 + iLeft = aX;
1.415 + iTop = aY;
1.416 + iRight = aX + aWidth;
1.417 + iBottom = aY + aHeight;
1.418 + }
1.419 +
1.420 +
1.421 +
1.422 +void VKRect::Draw(HDC aHdc,COLORREF aColor) const
1.423 + {
1.424 + HPEN pen;
1.425 + pen=CreatePen(PS_SOLID, 2, aColor);
1.426 + SelectObject(aHdc, pen);
1.427 + POINT point;
1.428 +
1.429 + MoveToEx(aHdc, (int)iLeft, (int)iTop, &point);
1.430 + LineTo(aHdc, (int)iLeft, (int)iBottom);
1.431 + LineTo(aHdc, (int)iRight, (int)iBottom);
1.432 + LineTo(aHdc, (int)iRight, (int)iTop);
1.433 + LineTo(aHdc, (int)iLeft, (int)iTop);
1.434 + }
1.435 +
1.436 +
1.437 +KeyCombination::KeyCombination(const TInt aCommandData, TEmulCommand aCommand):
1.438 + iData(aCommandData),
1.439 + iCommand(aCommand)
1.440 +{
1.441 + for (TInt i=0;i<KMaxHotKeyCombinationLength;i++)
1.442 + {
1.443 + iCombination[i]=EStdKeyNull;
1.444 + }
1.445 +}
1.446 +
1.447 +TBool KeyCombination::CheckCombinationPressed()
1.448 +{
1.449 + for (TInt j=0;(j<KMaxHotKeyCombinationLength && iCombination[j]!=0);j++)
1.450 + {
1.451 + if (GetAsyncKeyState(MapVirtualKey(iCombination[j],1))>=0)//if at least one key is not pressed, we return false
1.452 + return EFalse;
1.453 + }
1.454 + return ETrue;
1.455 +}
1.456 +
1.457 +TBool KeyCombination::AddKey(TStdScanCode aKey)
1.458 +{
1.459 + TInt i;
1.460 + for (i=0;i<KMaxHotKeyCombinationLength;i++)
1.461 + {
1.462 + if (iCombination[i]==EStdKeyNull)
1.463 + break;
1.464 + }
1.465 + if (KMaxHotKeyCombinationLength==i)
1.466 + return EFalse;
1.467 + else
1.468 + iCombination[i]=aKey;
1.469 +
1.470 + return ETrue;
1.471 +}
1.472 +
1.473 +
1.474 +DScreenProperties::DScreenProperties()
1.475 + {
1.476 + memset(this,0,sizeof(DScreenProperties));
1.477 + iColorDepth=KDefaultColorDepth;
1.478 +
1.479 + iViewport = TViewport(this);
1.480 + }
1.481 +
1.482 +
1.483 +LOCAL_C TInt MaskGceOnly(TInt aModeBits)
1.484 + { //All HAL modes are now reported. The GCE may refuse to register the surfaces.
1.485 + return aModeBits&KEmulModes; //previous useful settings: //(KEmulPixPerLong2|KEmulPixPerLong1); //|KEmulPixPerLong4;
1.486 + }
1.487 +
1.488 +LOCAL_C TInt BitsForSingleMode(TInt aModeColor)
1.489 + { //only 1 bit should be set in aModeColor
1.490 + switch (aModeColor)
1.491 + {
1.492 + case KEmulGray2: return 1;
1.493 + case KEmulGray4: return 2;
1.494 + case KEmulGray16: return 4;
1.495 + case KEmulGray256: return 8;
1.496 + case KEmulColor16: return 4;
1.497 + case KEmulColor256: return 8;
1.498 + case KEmulColor4K: return 12;
1.499 + case KEmulColor64K: return 16;
1.500 + case KEmulColor16M: return 24;
1.501 + default: return 32;
1.502 + }
1.503 +
1.504 + }
1.505 +
1.506 +DScreenProperties::~DScreenProperties()
1.507 + {
1.508 + }
1.509 +
1.510 +TWindowState DScreenProperties::GetWindowState()
1.511 + {
1.512 + TWindowState state;
1.513 + state.iWinPlace = iWinPlace;
1.514 + state.iFlipstate = iScreenRotation;
1.515 + state.iXoffset = iViewport.GetViewportOffsetX();
1.516 + state.iYoffset = iViewport.GetViewportOffsetY();
1.517 + return state;
1.518 + }
1.519 +
1.520 +TInt DScreenProperties::SetupProperties(TInt aConf, TInt aScreen)
1.521 + {
1.522 + char property[50];
1.523 +
1.524 + // Calculate maximum dimensions
1.525 + TInt configurations = Property::GetInt("ConfigCount", 0);
1.526 + if (configurations == 0)
1.527 + return KErrGeneral;
1.528 +
1.529 + TInt count, screenWidth, screenHeight, physicalScreenWidth, physicalScreenHeight;
1.530 + for (count = 0; count < configurations; ++count)
1.531 + {
1.532 + wsprintfA(property, "Configuration[%d][%d]ScreenWidth", count, aScreen);
1.533 + screenWidth = Property::GetInt(property, KScreenWidth);
1.534 + screenWidth = (screenWidth + 3) & ~3;
1.535 + if (screenWidth > iMaxScreenWidth)
1.536 + iMaxScreenWidth = screenWidth;
1.537 + wsprintfA(property, "Configuration[%d][%d]ScreenHeight", count, aScreen);
1.538 + screenHeight = Property::GetInt(property, KScreenHeight);
1.539 + screenHeight = (screenHeight + 3) & ~3;
1.540 + if (screenHeight > iMaxScreenHeight)
1.541 + iMaxScreenHeight = screenHeight;
1.542 +//
1.543 + wsprintfA(property, "Configuration[%d][%d]PhysicalScreenWidth", count, aScreen);
1.544 + physicalScreenWidth = Property::GetInt(property);
1.545 + if (physicalScreenWidth > iMaxPhysicalScreenWidth)
1.546 + iMaxPhysicalScreenWidth = physicalScreenWidth;
1.547 + wsprintfA(property, "Configuration[%d][%d]PhysicalScreenHeight", count, aScreen);
1.548 + physicalScreenHeight = Property::GetInt(property);
1.549 + if (physicalScreenHeight > iMaxPhysicalScreenHeight)
1.550 + iMaxPhysicalScreenHeight = physicalScreenHeight;
1.551 + }
1.552 +
1.553 + // Read figures for current configuration
1.554 + TInt givenWidth, givenHeight;
1.555 + wsprintfA(property, "Configuration[%d][%d]ScreenWidth",aConf,aScreen);
1.556 + givenWidth = Property::GetInt(property, KScreenWidth);
1.557 + iScreenWidth = (givenWidth + 3) & ~3;
1.558 + wsprintfA(property, "Configuration[%d][%d]ScreenHeight",aConf,aScreen);
1.559 + givenHeight = Property::GetInt(property, KScreenHeight);
1.560 + iScreenHeight = (givenHeight + 3) & ~3;
1.561 + // Width of screen should be multiple number of 4 pixels.
1.562 + if (givenWidth & 3 || givenHeight & 3)
1.563 + {
1.564 + Kern::Printf("Width and Height of Screen should be multiple number of 4 pixels.\n"
1.565 + "\tWidth of screen[%d] set to: %d\n\tHeight of screen[%d] set to: %d",
1.566 + aScreen, iScreenWidth, aScreen, iScreenHeight);
1.567 + }
1.568 +
1.569 +//
1.570 + wsprintfA(property, "Configuration[%d][%d]PhysicalScreenWidth",aConf,aScreen);
1.571 + iPhysicalScreenWidth = Property::GetInt(property);
1.572 + wsprintfA(property, "Configuration[%d][%d]PhysicalScreenHeight",aConf,aScreen);
1.573 + iPhysicalScreenHeight = Property::GetInt(property);
1.574 +//
1.575 + wsprintfA(property, "Configuration[%d][%d]ScreenOffsetX",aConf,aScreen);
1.576 + iScreenOffsetX = Property::GetInt(property, KScreenOffsetX);
1.577 + wsprintfA(property, "Configuration[%d][%d]ScreenOffsetY",aConf,aScreen);
1.578 + iScreenOffsetY = Property::GetInt(property, KScreenOffsetY);
1.579 +
1.580 + wsprintfA(property, "Configuration[%d][%d]CompositionBuffers",aConf,aScreen);
1.581 + iCompositionBuffers = Property::GetInt(property, KCompositionBuffers);
1.582 +
1.583 + wsprintfA(property, "Configuration[%d][%d]RefreshRateHz",aConf,aScreen);
1.584 + iRefreshRateHz = Property::GetInt(property, KRefreshRateHz);
1.585 +
1.586 +
1.587 + wsprintfA(property, "Configuration[%d][%d]ColorDepth",aConf,aScreen);
1.588 + const char* colors = Property::GetString(property);
1.589 + if (colors)
1.590 + {
1.591 + TUint colorDepth=0;
1.592 + const char* end = colors;
1.593 + for (;;)
1.594 + {
1.595 + const char* beg = skipws(end);
1.596 + if(*beg==';')
1.597 + break;
1.598 + if (!*beg)
1.599 + break;
1.600 + end = skiptok(beg);
1.601 + if (_strnicmp("Gray2",beg,end-beg) == 0)
1.602 + {
1.603 + colorDepth|=KEmulGray2|KEmulIsBitMask;
1.604 + }
1.605 + else if (_strnicmp("Gray4",beg,end-beg) == 0)
1.606 + {
1.607 + colorDepth|=KEmulGray4|KEmulIsBitMask;
1.608 + }
1.609 + else if (_strnicmp("Gray16",beg,end-beg) == 0)
1.610 + {
1.611 + colorDepth|=KEmulGray16|KEmulIsBitMask;
1.612 + }
1.613 + else if (_strnicmp("Gray256",beg,end-beg) == 0)
1.614 + {
1.615 + colorDepth|=KEmulGray256|KEmulIsBitMask;
1.616 + }
1.617 + else if (_strnicmp("Color16",beg,end-beg) == 0)
1.618 + {
1.619 + colorDepth|=KEmulColor16|KEmulIsBitMask;
1.620 + }
1.621 + else if (_strnicmp("Color256",beg,end-beg) == 0)
1.622 + {
1.623 + colorDepth|=KEmulColor256|KEmulIsBitMask;
1.624 + }
1.625 + else if (_strnicmp("Color4K",beg,end-beg) == 0)
1.626 + {
1.627 + colorDepth|=KEmulColor4K|KEmulIsBitMask;
1.628 + }
1.629 + else if (_strnicmp("Color64K",beg,end-beg) == 0)
1.630 + {
1.631 + colorDepth|=KEmulColor64K|KEmulIsBitMask;
1.632 + }
1.633 + else if (_strnicmp("Color16M",beg,end-beg) == 0)
1.634 + {
1.635 + colorDepth|=KEmulColor16M|KEmulIsBitMask;
1.636 + }
1.637 + else
1.638 + return KErrArgument;
1.639 + }
1.640 + iColorDepth = colorDepth;
1.641 +
1.642 + }
1.643 + //multiple mode support is currently only for GCE.
1.644 + //I fill this array in before knowing if GCE will be instanced.
1.645 + if (iColorDepth&KEmulIsBitMask)
1.646 + {
1.647 + //iModeDepths is only used by GCE
1.648 + TInt colorDepth=MaskGceOnly(iColorDepth);
1.649 + TInt setMode=0;
1.650 + for (TInt i=1;i!=KEmulIsBitMask;i+=i)
1.651 + if (colorDepth&i)
1.652 + iModeDepths[setMode++]=BitsForSingleMode(i);
1.653 + iMaxModes= setMode;
1.654 + iModeDepths[setMode++]=0; //a bit width of 0 is illegal
1.655 + }
1.656 + else
1.657 + {
1.658 + iModeDepths[0]=iColorDepth;
1.659 + iMaxModes=1;
1.660 + iModeDepths[1]=0; //a bit width of 0 is illegal
1.661 + }
1.662 +
1.663 + wsprintfA(property, "Configuration[%d][%d]FasciaBitmap",aConf,aScreen);
1.664 + const char* fascia = Property::GetString(property);
1.665 + if (fascia)
1.666 + {
1.667 + TInt len = strlen(fascia);
1.668 + //the path may have quotes at the start and end
1.669 + //need to work out if this is an absolute or relative path
1.670 + if (fascia[0] == '\"')
1.671 + {
1.672 + ++fascia;
1.673 + --len;
1.674 + if (--len > 0 && fascia[len-1] == '\"')
1.675 + --len;
1.676 + }
1.677 + char* p = iFasciaFileName;
1.678 + if (fascia[0] != '\\' && (len < 3 || fascia[1] != ':'))
1.679 + {
1.680 + //relative path
1.681 + strcpy(p, Property::GetString("EmulatorDataPath"));
1.682 + p += strlen(p);
1.683 + }
1.684 + memcpy(p, fascia, len);
1.685 + p[len] = '\0';
1.686 + }
1.687 + else
1.688 + {
1.689 + // default to machine name
1.690 + strcpy(iFasciaFileName, Property::GetString("EmulatorDataPath"));
1.691 + strcat(iFasciaFileName, Property::GetString("MachineName"));
1.692 + strcat(iFasciaFileName, ".bmp");
1.693 + }
1.694 + return KErrNone;
1.695 + }
1.696 +
1.697 +TViewport::TViewport()
1.698 + :iScreenProps(NULL),iViewportWidth(0), iViewportHeight(0), iViewportOffsetX(0), iViewportOffsetY(0)
1.699 + {
1.700 + }
1.701 +
1.702 +TViewport::TViewport(DScreenProperties* aScreenProps)
1.703 + :iScreenProps(aScreenProps),iViewportWidth(0), iViewportHeight(0), iViewportOffsetX(0), iViewportOffsetY(0)
1.704 + {
1.705 + }
1.706 +TViewport::~TViewport()
1.707 + {
1.708 + }
1.709 +
1.710 +
1.711 +/**
1.712 +Changes the logical position of the viewport within the input area
1.713 +of the emulator screen. The method may adjust the position so that
1.714 +the viewport stays within the input area.
1.715 +@param aPosition The new Y position of the top left hand corner of the viewport.
1.716 +@param aHwnd The window associated with the viewport
1.717 +*/
1.718 +void TViewport::ScrollToY(TInt aPosition, HWND aHwnd)
1.719 + {
1.720 +
1.721 + SCROLLINFO scrollinfo;
1.722 + scrollinfo.cbSize=sizeof(scrollinfo);
1.723 +
1.724 + //save for later
1.725 + scrollinfo.fMask=SIF_POS;
1.726 + GetScrollInfo(aHwnd, SB_VERT, &scrollinfo);
1.727 + TInt oldY=scrollinfo.nPos;
1.728 +
1.729 + if(aPosition<0)
1.730 + {
1.731 + scrollinfo.nPos = 0;
1.732 + }
1.733 + else if( (aPosition+GetViewportHeight())>GetMaxHeight())
1.734 + {
1.735 + scrollinfo.nPos = max(0,GetMaxHeight() - GetViewportHeight() );
1.736 + }
1.737 + else
1.738 + {
1.739 + scrollinfo.nPos=aPosition;
1.740 + }
1.741 +
1.742 + SetViewportOffsetY(scrollinfo.nPos);
1.743 + scrollinfo.fMask=SIF_POS;
1.744 + SetScrollInfo(aHwnd,SB_VERT, &scrollinfo, TRUE );
1.745 + ScrollWindowEx(aHwnd, 0, oldY-scrollinfo.nPos, 0, 0, NULL, NULL, SW_INVALIDATE);
1.746 +
1.747 + UpdateChildPos(aHwnd);
1.748 + }
1.749 +
1.750 +/**
1.751 +As for ScrollToY but for the X direction
1.752 +*/
1.753 +void TViewport::ScrollToX(TInt aPosition, HWND aHwnd)
1.754 + {
1.755 + SCROLLINFO scrollinfo;
1.756 + scrollinfo.cbSize=sizeof(scrollinfo);
1.757 +
1.758 + //save for later
1.759 + scrollinfo.fMask=SIF_POS;
1.760 + GetScrollInfo(aHwnd, SB_HORZ, &scrollinfo);
1.761 + TInt oldX=scrollinfo.nPos;
1.762 +
1.763 + if(aPosition<0)
1.764 + {
1.765 + scrollinfo.nPos = 0;
1.766 + }
1.767 + else if( (aPosition+GetViewportWidth())>GetMaxWidth())
1.768 + {
1.769 + scrollinfo.nPos = max(0,GetMaxWidth() - GetViewportWidth() );
1.770 + }
1.771 + else
1.772 + {
1.773 + scrollinfo.nPos=aPosition;
1.774 + }
1.775 +
1.776 + SetViewportOffsetX(scrollinfo.nPos);
1.777 + scrollinfo.fMask=SIF_POS;
1.778 + SetScrollInfo(aHwnd,SB_HORZ, &scrollinfo, TRUE );
1.779 + ScrollWindowEx(aHwnd, oldX-scrollinfo.nPos, 0, 0, 0, NULL, NULL, SW_INVALIDATE);
1.780 +
1.781 + UpdateChildPos(aHwnd);
1.782 + }
1.783 +
1.784 +//Forward declaration
1.785 +LOCAL_C TInt ScreenFromHWND(HWND aHwnd,HWND* pWin);
1.786 +
1.787 +/**
1.788 +Move the child window to it's correct position.
1.789 +
1.790 +@param aHwnd The HWND of the parent window
1.791 +*/
1.792 +void TViewport::UpdateChildPos(HWND aHwnd)
1.793 + {
1.794 + TInt screenNumber = ::ScreenFromHWND(aHwnd,TheWin);
1.795 + HWND childWin = TheChildWin[screenNumber];
1.796 +
1.797 + switch (iScreenProps->iScreenRotation)
1.798 + {
1.799 + case EEmulatorFlipRestore:
1.800 + MoveWindow(
1.801 + childWin,
1.802 + iScreenProps->iScreenOffsetX - GetViewportOffsetX(),
1.803 + iScreenProps->iScreenOffsetY - GetViewportOffsetY(),
1.804 + iScreenProps->iScreenWidth,
1.805 + iScreenProps->iScreenHeight,
1.806 + TRUE
1.807 + );
1.808 + break;
1.809 + case EEmulatorFlipInvert:
1.810 + MoveWindow(
1.811 + childWin,
1.812 + iScreenProps->iXYInputWidth-(iScreenProps->iScreenOffsetX+iScreenProps->iScreenWidth) - GetViewportOffsetX(),
1.813 + iScreenProps->iXYInputHeight-(iScreenProps->iScreenOffsetY+iScreenProps->iScreenHeight) - GetViewportOffsetY(),
1.814 + iScreenProps->iScreenWidth,
1.815 + iScreenProps->iScreenHeight,
1.816 + TRUE
1.817 + );
1.818 + break;
1.819 + case EEmulatorFlipLeft:
1.820 + MoveWindow(
1.821 + childWin,
1.822 + iScreenProps->iScreenOffsetY - GetViewportOffsetX(),
1.823 + iScreenProps->iXYInputWidth-(iScreenProps->iScreenOffsetX+iScreenProps->iScreenWidth)- GetViewportOffsetY(),
1.824 + iScreenProps->iScreenHeight,
1.825 + iScreenProps->iScreenWidth,
1.826 + TRUE
1.827 + );
1.828 + break;
1.829 + case EEmulatorFlipRight:
1.830 + MoveWindow(
1.831 + childWin,
1.832 + iScreenProps->iXYInputHeight-(iScreenProps->iScreenOffsetY+iScreenProps->iScreenHeight) - GetViewportOffsetX(),
1.833 + iScreenProps->iScreenOffsetX - GetViewportOffsetY(),
1.834 + iScreenProps->iScreenHeight,
1.835 + iScreenProps->iScreenWidth,
1.836 + TRUE
1.837 + );
1.838 + break;
1.839 + }
1.840 +
1.841 + }
1.842 +
1.843 +/**
1.844 +Update the range of the horizontal scrollbar,
1.845 +to take account of the current viewport width.
1.846 +
1.847 +@param aHwnd The window to be updated
1.848 +*/
1.849 +void TViewport::UpdateScrollBarH(HWND aHwnd)
1.850 + {
1.851 +
1.852 + SCROLLINFO scrollinfoHor;
1.853 + scrollinfoHor.cbSize=sizeof(scrollinfoHor);
1.854 + scrollinfoHor.fMask=SIF_RANGE|SIF_PAGE;
1.855 + scrollinfoHor.nMin=0;
1.856 + scrollinfoHor.nMax= GetMaxWidth()-1;
1.857 +
1.858 +
1.859 + TInt newPage = GetViewportWidth() ;
1.860 + TBool redraw=EFalse; //redraw window if a resize has caused a scrollbar to disappear and reveal image.
1.861 + if ( newPage>= scrollinfoHor.nMax -GetSystemMetrics(SM_CXVSCROLL)
1.862 + && newPage < scrollinfoHor.nMax+1)
1.863 + {
1.864 + redraw=ETrue;
1.865 + newPage=GetMaxWidth();
1.866 +
1.867 + }
1.868 + scrollinfoHor.nPage= newPage;
1.869 +
1.870 + SetScrollInfo(aHwnd,SB_HORZ, &scrollinfoHor, TRUE );
1.871 + if(redraw)
1.872 + {
1.873 + ScrollToX(0, aHwnd); //in case egde of fascia was against edge of vertical scrollbar
1.874 + InvalidateRect(aHwnd, NULL, TRUE);
1.875 + }
1.876 + }
1.877 +
1.878 +/**
1.879 +Update the range of the vertical scrollbar,
1.880 +to take account of the current viewport width.
1.881 +
1.882 +@param aHwnd The window to be updated
1.883 +*/
1.884 +void TViewport::UpdateScrollBarV(HWND aHwnd)
1.885 + {
1.886 + SCROLLINFO scrollinfoVer;
1.887 + scrollinfoVer.cbSize=sizeof(scrollinfoVer);
1.888 + scrollinfoVer.fMask=SIF_RANGE|SIF_PAGE;
1.889 + scrollinfoVer.nMin=0;
1.890 + scrollinfoVer.nMax= GetMaxHeight()-1;
1.891 +
1.892 + TInt newPage = GetViewportHeight() ;
1.893 + TBool redraw=EFalse; //redraw window if a resize has caused a scrollbar to disappear and reveal image.
1.894 + if ( newPage>= scrollinfoVer.nMax -GetSystemMetrics(SM_CYHSCROLL)
1.895 + && newPage < scrollinfoVer.nMax+1)
1.896 + {
1.897 + redraw=ETrue;
1.898 + newPage=GetMaxHeight();
1.899 + }
1.900 + scrollinfoVer.nPage= newPage;
1.901 +
1.902 + SetScrollInfo(aHwnd,SB_VERT, &scrollinfoVer, TRUE );
1.903 + if(redraw)
1.904 + {
1.905 + ScrollToY(0, aHwnd); //in case egde of fascia was against edge of vertical scrollbar
1.906 + InvalidateRect(aHwnd, NULL, TRUE);
1.907 + }
1.908 + }
1.909 +
1.910 +/**
1.911 +Returns the max width for the viewport window (non-client area) so that it
1.912 +may be bounded. Takes account of scrollbar.
1.913 +
1.914 +@return Max width
1.915 +*/
1.916 +TInt TViewport::GetMaxWindowWidth() const
1.917 + {
1.918 +
1.919 + RECT rect = {0,0,0,0};
1.920 +
1.921 + switch(iScreenProps->iScreenRotation)
1.922 + {
1.923 + case EEmulatorFlipRestore:
1.924 + case EEmulatorFlipInvert:
1.925 + {
1.926 + rect.right=iScreenProps->iXYInputWidth;
1.927 + rect.bottom=iScreenProps->iXYInputHeight;
1.928 + break;
1.929 + }
1.930 + case EEmulatorFlipLeft:
1.931 + case EEmulatorFlipRight:
1.932 + {
1.933 + rect.right=iScreenProps->iXYInputHeight;
1.934 + rect.bottom=iScreenProps->iXYInputWidth;
1.935 + break;
1.936 + }
1.937 + }
1.938 + AdjustWindowRect(//take account of window decorations
1.939 + &rect,
1.940 + KWinStyle,
1.941 + FALSE
1.942 + );
1.943 +
1.944 +
1.945 + return (rect.right-rect.left);
1.946 + }
1.947 +
1.948 +/**
1.949 +Returns the max height for the viewport window (non-client area) so that it
1.950 +may be bounded. Takes account of scrollbar.
1.951 +
1.952 +@return Max height
1.953 +*/
1.954 +TInt TViewport::GetMaxWindowHeight() const
1.955 + {
1.956 +
1.957 + RECT rect ={0,0,0,0};
1.958 +
1.959 + switch(iScreenProps->iScreenRotation)
1.960 + {
1.961 + case EEmulatorFlipRestore:
1.962 + case EEmulatorFlipInvert:
1.963 + {
1.964 + rect.right=iScreenProps->iXYInputWidth;
1.965 + rect.bottom=iScreenProps->iXYInputHeight;
1.966 + break;
1.967 + }
1.968 + case EEmulatorFlipLeft:
1.969 + case EEmulatorFlipRight:
1.970 + {
1.971 + rect.right=iScreenProps->iXYInputHeight;
1.972 + rect.bottom=iScreenProps->iXYInputWidth;
1.973 + break;
1.974 + }
1.975 + }
1.976 + AdjustWindowRect(//take account of window decorations
1.977 + &rect,
1.978 + KWinStyle,
1.979 + FALSE
1.980 + );
1.981 + return (rect.bottom-rect.top);
1.982 + }
1.983 +
1.984 +/**
1.985 +Returns the maximum width for the viewport (client area only).
1.986 +Allowing for the orientation of the emulator.
1.987 +
1.988 +@return Max width
1.989 +*/
1.990 +TInt TViewport::GetMaxWidth() const
1.991 + {
1.992 + TInt width=0;
1.993 + switch(iScreenProps->iScreenRotation)
1.994 + {
1.995 + case EEmulatorFlipRestore:
1.996 + case EEmulatorFlipInvert:
1.997 + {
1.998 + width = iScreenProps->iXYInputWidth;
1.999 + break;
1.1000 + }
1.1001 + case EEmulatorFlipLeft:
1.1002 + case EEmulatorFlipRight:
1.1003 + {
1.1004 + width = iScreenProps->iXYInputHeight;
1.1005 + break;
1.1006 + }
1.1007 + }
1.1008 +
1.1009 + return width;
1.1010 + }
1.1011 +
1.1012 +/**
1.1013 +Returns the maximum height for the viewport (client area only).
1.1014 +Allowing for the orientation of the emulator.
1.1015 +
1.1016 +@return Max height
1.1017 +*/
1.1018 +TInt TViewport::GetMaxHeight() const
1.1019 + {
1.1020 + TInt height=0;
1.1021 + switch(iScreenProps->iScreenRotation)
1.1022 + {
1.1023 + case EEmulatorFlipRestore:
1.1024 + case EEmulatorFlipInvert:
1.1025 + {
1.1026 + height = iScreenProps->iXYInputHeight;
1.1027 + break;
1.1028 + }
1.1029 + case EEmulatorFlipLeft:
1.1030 + case EEmulatorFlipRight:
1.1031 + {
1.1032 + height = iScreenProps->iXYInputWidth;
1.1033 + break;
1.1034 + }
1.1035 + }
1.1036 +
1.1037 + return height;
1.1038 +
1.1039 + }
1.1040 +
1.1041 +/**
1.1042 +Sets the X offset of the viewport from the edge of the input area
1.1043 +@param aOffset The X offset
1.1044 +*/
1.1045 +void TViewport::SetViewportOffsetX(TInt aOffset)
1.1046 + {
1.1047 + iViewportOffsetX = aOffset;
1.1048 + }
1.1049 +
1.1050 +/**
1.1051 +Sets the Y offset of the viewport from the edge of the input area
1.1052 +@param aOffset The Y offset
1.1053 +*/
1.1054 +void TViewport::SetViewportOffsetY(TInt aOffset)
1.1055 + {
1.1056 + iViewportOffsetY = aOffset;
1.1057 + }
1.1058 +
1.1059 +TInt TViewport::GetViewportOffsetX() const
1.1060 + {
1.1061 + return iViewportOffsetX;
1.1062 + }
1.1063 +TInt TViewport::GetViewportOffsetY() const
1.1064 + {
1.1065 + return iViewportOffsetY;
1.1066 + }
1.1067 +
1.1068 +/**
1.1069 +Sets the viewport width, this is equal to the width
1.1070 +of the window's client area
1.1071 +@param aWidth The width
1.1072 +*/
1.1073 +void TViewport::SetViewportWidth(TInt aWidth)
1.1074 + {
1.1075 + iViewportWidth=aWidth;
1.1076 + }
1.1077 +
1.1078 +/**
1.1079 +Sets the viewport height, this is equal to the height
1.1080 +of the window's client area
1.1081 +@param aHeight The height
1.1082 +*/
1.1083 +void TViewport::SetViewportHeight(TInt aHeight)
1.1084 + {
1.1085 + iViewportHeight=aHeight;
1.1086 + }
1.1087 +
1.1088 +TInt TViewport::GetViewportWidth() const
1.1089 + {
1.1090 + return iViewportWidth;
1.1091 + }
1.1092 +TInt TViewport::GetViewportHeight() const
1.1093 + {
1.1094 + return iViewportHeight;
1.1095 + }
1.1096 +
1.1097 +// the UI class
1.1098 +
1.1099 +DWinsUi::DWinsUi()
1.1100 + :iVirtualKeys(10),
1.1101 + iControlHotKeys(10)
1.1102 + {}
1.1103 +
1.1104 +/// Returns the current mode's depth. Remember current mode is never set!
1.1105 +TUint DWinsUi::ColorDepth(TInt aScreenNumber)
1.1106 + {
1.1107 + TVideoInfoV01 info;
1.1108 + VideoInfo(aScreenNumber, info);
1.1109 + return info.iBitsPerPixel;
1.1110 + }
1.1111 +
1.1112 +TInt DWinsUi::SetFlip(TEmulatorFlip aFlip, TInt aScreenNumber)
1.1113 + {
1.1114 + if(TUint(aScreenNumber)>=TUint(systemIni->iScreens.Count()))
1.1115 + return KErrArgument;
1.1116 + int r1 = PostMessageA(TheChildWin[aScreenNumber],WM_FLIP_MESSAGE,(TUint)aFlip,NULL);
1.1117 + return r1 ? KErrNone : KErrGeneral;
1.1118 + }
1.1119 +
1.1120 +void DWinsUi::Info(TVariantInfoV01& aInfo)
1.1121 + {
1.1122 + aInfo.iLedCapabilities=0x3;
1.1123 + }
1.1124 +
1.1125 +HWND DWinsUi::HWnd()
1.1126 + {
1.1127 + return TheControlWin;
1.1128 + }
1.1129 +
1.1130 +TInt DWinsUi::SetupProperties(TInt aId)
1.1131 +
1.1132 +//
1.1133 +// load UI settings from the emulator properties
1.1134 +//
1.1135 + {
1.1136 + //setup the screens
1.1137 + TInt screens = Property::GetInt("[screens]", 1);
1.1138 +
1.1139 + for (TInt x = 0; x < screens; ++x)
1.1140 + {
1.1141 + DScreenProperties * pScr = new DScreenProperties();
1.1142 + if (!pScr)
1.1143 + return KErrNoMemory;
1.1144 +
1.1145 + TInt ret = pScr->SetupProperties(aId,x);
1.1146 + if (KErrNone == ret)
1.1147 + ret = iScreens.Append(pScr);
1.1148 +
1.1149 + if (KErrNone != ret)
1.1150 + {
1.1151 + delete pScr;
1.1152 + return ret;
1.1153 + }
1.1154 + }
1.1155 +//
1.1156 + char property[50];
1.1157 + wsprintfA(property, "Configuration[%d]LedSize",aId);
1.1158 + iLedSize = Property::GetInt(property, KLedSize);
1.1159 + wsprintfA(property, "Configuration[%d]LedArrangeVertically",aId);
1.1160 + iLedVertical = Property::GetBool(property, KLedVertical);
1.1161 + wsprintfA(property, "Configuration[%d]LedArrangeHorizontally",aId);
1.1162 + if (Property::GetBool(property))
1.1163 + iLedVertical = EFalse;
1.1164 + wsprintfA(property, "Configuration[%d]LedOffsetX",aId);
1.1165 + iLedOffsetX = Property::GetInt(property, KLedLeft);
1.1166 + wsprintfA(property, "Configuration[%d]LedOffsetY",aId);
1.1167 + iLedOffsetY = Property::GetInt(property, KLedTop);
1.1168 + wsprintfA(property, "Configuration[%d]LedGap",aId);
1.1169 + iLedGap = Property::GetInt(property, KLedGap);
1.1170 +//
1.1171 + wsprintfA(property, "Configuration[%d]PointerType",aId);
1.1172 + const char* pointer = Property::GetString(property, "Pen");
1.1173 + if (_stricmp(pointer, "None") == 0)
1.1174 + {
1.1175 + iPointerType=_S8("NONE");
1.1176 + iXYInputType=EXYInputNone;
1.1177 + }
1.1178 + else if (_stricmp(pointer,"Pen") == 0)
1.1179 + {
1.1180 + iPointerType=_S8("PEN");
1.1181 + iXYInputType=EXYInputPointer;
1.1182 + }
1.1183 + else if (_stricmp(pointer,"Mouse") == 0)
1.1184 + {
1.1185 + iPointerType=_S8("MOUSE");
1.1186 + iXYInputType=EXYInputMouse;
1.1187 + }
1.1188 + else if (_stricmp(pointer,"Delta-Mouse") == 0)
1.1189 + {
1.1190 + iPointerType=_S8("MOUSE");
1.1191 + iXYInputType=EXYInputDeltaMouse;
1.1192 + }
1.1193 + else
1.1194 + return KErrArgument;
1.1195 +//
1.1196 + wsprintfA(property, "Configuration[%d]DigitizerOffsetX",aId);
1.1197 + iDigitizerOffsetX = Property::GetInt(property, -iScreens[0]->iScreenOffsetX);
1.1198 + wsprintfA(property, "Configuration[%d]DigitizerOffsetY",aId);
1.1199 + iDigitizerOffsetY = Property::GetInt(property, -iScreens[0]->iScreenOffsetY);
1.1200 + wsprintfA(property, "Configuration[%d]DigitizerWidth",aId);
1.1201 + iDigitizerWidth = Property::GetInt(property,-1);
1.1202 + wsprintfA(property, "Configuration[%d]DigitizerHeight",aId);
1.1203 + iDigitizerHeight = Property::GetInt(property,-1);
1.1204 + wsprintfA(property, "Configuration[%d]DisableDigitizer",aId);
1.1205 + iDigitizerEnabled = !Property::GetBool(property);
1.1206 +// To enable the multitouch
1.1207 + wsprintfA(property, "EnableMultiTouch");
1.1208 + iMultiTouchEnabled = Property::GetBool(property,EFalse);
1.1209 + wsprintfA(property, "SYMBIAN_BASE_USE_GCE");
1.1210 + iGCEEnabled = Property::GetBool(property,EFalse);
1.1211 + wsprintfA(property, "MultiTouchProximityStep");
1.1212 + iMultiTouchProximityStep = Property::GetInt(property,-1);
1.1213 + wsprintfA(property, "MultiTouchPressureStep");
1.1214 + iMultiTouchPressureStep = Property::GetInt(property,-1);
1.1215 +//
1.1216 + strcpy(iSysIniFileName, Property::GetString("EmulatorDataPath"));
1.1217 + strcat(iSysIniFileName, "emulator\\");
1.1218 + if (!Emulator::CreateAllDirectories(iSysIniFileName))
1.1219 + return Emulator::LastError();
1.1220 + strcat(iSysIniFileName, Property::GetString("MachineName"));
1.1221 + strcat(iSysIniFileName, ".sys.ini");
1.1222 +//
1.1223 + TInt r = iKeyboard.Init(aId);
1.1224 + if (r != KErrNone)
1.1225 + return r;
1.1226 +
1.1227 + wsprintfA(property, "Configuration[%d]VirtualKey",aId);
1.1228 + r = MultiProperty(&DWinsUi::DoDefineVirtualKey, this, property);
1.1229 + if (r != KErrNone)
1.1230 + return r;
1.1231 +//
1.1232 +
1.1233 + wsprintfA(property, "Configuration[%d]NoVersionInfo",aId);
1.1234 + iDisplayVersionInfo = !Property::GetBool(property);
1.1235 +
1.1236 + wsprintfA(property, "Configuration[%d]WindowTitle",aId);
1.1237 + const char * p = Property::GetString(property);
1.1238 + if (p && (strlen(p) <= KMaxNameSize))
1.1239 + strcpy(iWindowTitle, p);
1.1240 + else
1.1241 + strcpy(iWindowTitle, DefaultWindowTitle);
1.1242 +
1.1243 + if (iDisplayVersionInfo)
1.1244 + {
1.1245 + TInt wtLen = strlen(iWindowTitle);
1.1246 + TInt vtLen = strlen(VersionText);
1.1247 + if ((wtLen + vtLen) > KMaxNameSize)
1.1248 + iWindowTitle[KMaxNameSize-vtLen] = '\0';
1.1249 + strcat(iWindowTitle, VersionText);
1.1250 + }
1.1251 +
1.1252 + wsprintfA(property, "Configuration[%d]OnActivation",aId);
1.1253 + pointer = Property::GetString(property);
1.1254 + //example OnActivation 270 EKeyScreenDimension1
1.1255 + //params are rotation(int) and key(string)
1.1256 + if (pointer)
1.1257 + {
1.1258 + char * next;
1.1259 +
1.1260 + //skip any white space
1.1261 + const char* beg = skipws(pointer);
1.1262 +
1.1263 + //get the number
1.1264 + long rotation = strtol(beg, &next, 0);
1.1265 + if (next == beg)
1.1266 + return KErrArgument;
1.1267 +
1.1268 + switch (rotation)
1.1269 + {
1.1270 + case 0:
1.1271 + iScreens[0]->iScreenRotation = EEmulatorFlipRestore;
1.1272 + break;
1.1273 + case 90:
1.1274 + iScreens[0]->iScreenRotation = EEmulatorFlipRight;
1.1275 + break;
1.1276 + case 180:
1.1277 + iScreens[0]->iScreenRotation = EEmulatorFlipInvert;
1.1278 + break;
1.1279 + case 270:
1.1280 + iScreens[0]->iScreenRotation = EEmulatorFlipLeft;
1.1281 + break;
1.1282 + default:
1.1283 + r = KErrArgument;
1.1284 + }
1.1285 + if (r != KErrNone)
1.1286 + return r;
1.1287 +
1.1288 + beg = skipws(next);
1.1289 +
1.1290 + //beg should now point to the keycode
1.1291 + TInt key = iKeyboard.GetEPOCKeyCode(TPtrC8((const TUint8*)beg, strlen(beg)));
1.1292 + if (key == KErrNotFound)
1.1293 + return key;
1.1294 + iInitialFlipMsg = key;
1.1295 + }
1.1296 +
1.1297 + //EmulatorControl messages are a bit like virtual keys
1.1298 + wsprintfA(property, "Configuration[%d]EmulatorControl",aId);
1.1299 + r = MultiProperty(&DWinsUi::DoDefineEmulatorControl, this, property);
1.1300 + if (r != KErrNone)
1.1301 + return r;
1.1302 +
1.1303 + wsprintfA(property, "Configuration[%d]EmulatorControlHotKey",aId);
1.1304 + r = MultiProperty(&DWinsUi::DoDefineEmulatorControlHotKey, this, property);
1.1305 + if (r != KErrNone)
1.1306 + return r;
1.1307 +
1.1308 + return KErrNone;
1.1309 + }
1.1310 +
1.1311 +TInt DWinsUi::NumberOfScreens()
1.1312 + {
1.1313 + return iScreens.Count();
1.1314 + }
1.1315 +
1.1316 +/**
1.1317 +Return the highest bit depth from an emulator mode mask.
1.1318 +@param aModeMask A bitwise combination of KEmul... display mode mask values.
1.1319 +@return A color depth in bits per pixel.
1.1320 +*/
1.1321 +LOCAL_C TInt MaximumBitDepthFromMask(TInt aModeMask)
1.1322 + {
1.1323 + // Choose the highest bits per pixel based on the display mode mask.
1.1324 + if (aModeMask & KEmulColor16M)
1.1325 + {
1.1326 + return 24;
1.1327 + }
1.1328 + if (aModeMask & KEmulColor64K)
1.1329 + {
1.1330 + return 16;
1.1331 + }
1.1332 + if (aModeMask & KEmulColor4K)
1.1333 + {
1.1334 + return 12;
1.1335 + }
1.1336 +
1.1337 + // Lower bit depths are not supported, so use the default
1.1338 + return 24;
1.1339 + }
1.1340 +
1.1341 +
1.1342 +/**
1.1343 +Return the TDisplayRotation corresponding to the given TEmulatorFlip.
1.1344 +@param aFlip A screen rotation as a TEmulatorFlip.
1.1345 +@return The screen rotation as a TDisplayRotation.
1.1346 +*/
1.1347 +LOCAL_C RDisplayChannel::TDisplayRotation FlipToDisplayRotation(TEmulatorFlip aFlip)
1.1348 + {
1.1349 + switch (aFlip)
1.1350 + {
1.1351 + case EEmulatorFlipLeft:
1.1352 + return RDisplayChannel::ERotation90CW;
1.1353 + case EEmulatorFlipInvert:
1.1354 + return RDisplayChannel::ERotation180;
1.1355 + case EEmulatorFlipRight:
1.1356 + return RDisplayChannel::ERotation270CW;
1.1357 + }
1.1358 + return RDisplayChannel::ERotationNormal;
1.1359 + }
1.1360 +
1.1361 +
1.1362 +TInt DWinsUi::SetDisplayChannel(TInt aScreenNumber, DDisplayChannel* aDisplay)
1.1363 + {
1.1364 + return systemIni->SetDisplayChannelImpl(aScreenNumber,aDisplay);
1.1365 + }
1.1366 +
1.1367 +
1.1368 +TInt DWinsUi::SetDisplayChannelImpl(TInt aScreenNumber, DDisplayChannel* aDisplay)
1.1369 + {
1.1370 + if (TUint(aScreenNumber) >= TUint(NumberOfScreens()))
1.1371 + {
1.1372 + // Screen number is either negative or too big.
1.1373 + return KErrArgument;
1.1374 + }
1.1375 +
1.1376 + TInt r = KErrNone;
1.1377 + HWND hWnd = TheChildWin[aScreenNumber];
1.1378 + TBufferSet& buffer = masterIni->iBufferSet[aScreenNumber];
1.1379 +
1.1380 + if (aDisplay)
1.1381 + {
1.1382 + // Display driver connecting
1.1383 + DScreenProperties* screen = iScreens[aScreenNumber];
1.1384 + RDisplayChannel::TDisplayInfo info;
1.1385 +
1.1386 + TInt pixelBytes = 2;
1.1387 + info.iBitsPerPixel = MaximumBitDepthFromMask(screen->iColorDepth);
1.1388 +
1.1389 + switch (info.iBitsPerPixel)
1.1390 + {
1.1391 + case 12: // XRGB4444
1.1392 + info.iPixelFormat = EUidPixelFormatXRGB_4444;
1.1393 + break;
1.1394 + case 16: // RGB565
1.1395 + info.iPixelFormat = EUidPixelFormatRGB_565;
1.1396 + break;
1.1397 + default:
1.1398 + // Force anything else to packed RGB888
1.1399 + pixelBytes = 4;
1.1400 + info.iBitsPerPixel = 24;
1.1401 + info.iPixelFormat = EUidPixelFormatXRGB_8888;
1.1402 + break;
1.1403 + }
1.1404 +
1.1405 + TInt width = screen->iMaxScreenWidth;
1.1406 + TInt height = screen->iMaxScreenHeight;
1.1407 +
1.1408 + info.iRefreshRateHz = screen->iRefreshRateHz;
1.1409 + info.iAvailableRotations = RDisplayChannel::ERotationNormal | RDisplayChannel::ERotation90CW |
1.1410 + RDisplayChannel::ERotation180 | RDisplayChannel::ERotation270CW;
1.1411 + info.iNormal.iWidth = width;
1.1412 + info.iNormal.iHeight = height;
1.1413 + // Windows requires rounding up to 4-bytes words
1.1414 + info.iNormal.iOffsetBetweenLines = _ALIGN_UP(width * pixelBytes, 4);
1.1415 + info.iFlipped.iWidth = height;
1.1416 + info.iFlipped.iHeight = width;
1.1417 + // Windows requires rounding up to 4-bytes words
1.1418 + info.iFlipped.iOffsetBetweenLines = _ALIGN_UP(height * pixelBytes, 4);
1.1419 +
1.1420 + TInt maxSize=0;
1.1421 + //ensure legacy buffer is large enough for all supported modes.
1.1422 + //It would be a very strange setup for the max size to not be the max bpp,
1.1423 + //but we don't know which mode is max bpp anyway!
1.1424 + TVideoInfoV01 videoInfo;
1.1425 + for (TInt mode=0,maxMode=screen->iMaxModes;mode<maxMode;mode++)
1.1426 + {
1.1427 + if (systemIni->VideoInfoForDisplayDriver(aScreenNumber,mode, videoInfo)) //can't actually fail currently
1.1428 + {
1.1429 + TInt dwSize=videoInfo.iOffsetToFirstPixel+videoInfo.iOffsetBetweenLines*videoInfo.iSizeInPixels.iHeight;
1.1430 + if (dwSize>maxSize)
1.1431 + maxSize=dwSize;
1.1432 + }
1.1433 + else
1.1434 + {
1.1435 + Fault(EGuiVideoInfoUnavailable);
1.1436 + }
1.1437 + //rotated mode may use more RAM?? Height may be >Width or may not be a multiple of stride quantum
1.1438 + if (systemIni->VideoInfoForDisplayDriver(aScreenNumber,mode|KModeFlagFlipped, videoInfo)) //can't actually fail currently
1.1439 + {
1.1440 + TInt dwSize=videoInfo.iOffsetToFirstPixel+videoInfo.iOffsetBetweenLines*videoInfo.iSizeInPixels.iWidth;
1.1441 + if (dwSize>maxSize)
1.1442 + {
1.1443 + maxSize=dwSize;
1.1444 + }
1.1445 + }
1.1446 + else
1.1447 + {
1.1448 + Fault(EGuiVideoInfoUnavailable);
1.1449 + }
1.1450 + }
1.1451 +
1.1452 + masterIni->iMaxSizeInBytes = maxSize;
1.1453 + if (__e32_atomic_add_ord32(&buffer.iDisplayDriverCount, 1) == 0)
1.1454 + {
1.1455 + // First driver to connect, allocate frame buffers.
1.1456 + // +1 frame buffer is ui legacy buffer at [0], so does need to take account of stride and offset
1.1457 + r = masterIni->AllocateFrameBuffers(aScreenNumber, screen->iCompositionBuffers + 1, maxSize);
1.1458 + }
1.1459 +
1.1460 + if (r == KErrNone)
1.1461 + {
1.1462 + buffer.iScreenBuffer.iDisplayBufferOffset = 0;
1.1463 + masterIni->iBufferSet[aScreenNumber].iDisplayChannel = aDisplay;
1.1464 + masterIni->InitBitmapHeader(*screen, &buffer.iInfo);
1.1465 + masterIni->InitBufferFormat(*screen, buffer.iBufferFormat);
1.1466 + if(systemIni->VideoInfoForDisplayDriver(aScreenNumber,screen->iCurrentMode, videoInfo, ETrue))
1.1467 + {
1.1468 + r = aDisplay->Initialize(info,
1.1469 + FlipToDisplayRotation(screen->iScreenRotation),
1.1470 + hWnd, buffer.iScreenBuffer.iFrameBuffers,
1.1471 + buffer.iScreenBuffer.iMemChunks,
1.1472 + buffer.iDsaBuffer,
1.1473 + videoInfo.iSizeInPixels,videoInfo.iSizeInTwips,
1.1474 + masterIni->iSupportedPixelFormatTable,
1.1475 + masterIni->iSupportedPixelFormatTableSize,
1.1476 + buffer.iBufferFormat);
1.1477 + }
1.1478 + else
1.1479 + {
1.1480 + Fault(EGuiVideoInfoUnavailable);
1.1481 + }
1.1482 + }
1.1483 +
1.1484 + if (r != KErrNone && __e32_atomic_tas_ord32(&buffer.iDisplayDriverCount, 1, -1, 0) == 1)
1.1485 + {
1.1486 + // Release any that were allocated
1.1487 + masterIni->ReleaseFrameBuffers(aScreenNumber);
1.1488 + }
1.1489 + }
1.1490 + else
1.1491 + {
1.1492 + // Display driver disconnected
1.1493 + if (__e32_atomic_tas_ord32(&buffer.iDisplayDriverCount, 1, -1, 0) == 1)
1.1494 + {
1.1495 + // All drivers disconnected, deallocate memory.
1.1496 + masterIni->ReleaseFrameBuffers(aScreenNumber);
1.1497 + }
1.1498 + }
1.1499 +
1.1500 + return r;
1.1501 + }
1.1502 +
1.1503 +
1.1504 +void DWinsUi::SetVirtualKey(const TBool aProcessing, const TInt aCommandData, const TEmulCommand aCommand)
1.1505 + {
1.1506 + iProcessingVirtualKey = aProcessing;
1.1507 + iFakedVirtualKey = aCommandData;
1.1508 + iVirtualKeyCommand = aCommand;
1.1509 + }
1.1510 +
1.1511 +TBool DWinsUi::WasVirtualKey(TInt& aCommandData, TEmulCommand& aCommand)
1.1512 + {
1.1513 + if (iProcessingVirtualKey)
1.1514 + {
1.1515 +
1.1516 + aCommandData = iFakedVirtualKey;
1.1517 + aCommand = iVirtualKeyCommand;
1.1518 + }
1.1519 + return iProcessingVirtualKey;
1.1520 + }
1.1521 +
1.1522 +
1.1523 +TInt DWinsUi::DoDefineEmulatorControl(TAny* aPtr, const char* aValue)
1.1524 + {
1.1525 + return static_cast<DWinsUi*>(aPtr)->DefineEmulatorControl(aValue);
1.1526 + }
1.1527 +
1.1528 +
1.1529 +TInt DWinsUi::DefineEmulatorControl(const char* aValue)
1.1530 + {
1.1531 +
1.1532 + //example EmulatorControl SelectConfig 2 rect 223,640 29,22
1.1533 + //example EmulatorControl NextConfig rect 223,640 29,22
1.1534 + const char* beg = skipws(aValue);
1.1535 + const char* end = skiptok(beg);
1.1536 + TInt err = KErrNone;
1.1537 +
1.1538 + TEmulCommand command = ENoCommand;
1.1539 + TInt data = 0;
1.1540 + if (_strnicmp(beg, "SelectConfig", end-beg) == 0)
1.1541 + {
1.1542 + //get the int param which is the config to switch to
1.1543 + beg = end;
1.1544 + char * e;
1.1545 + data = strtol(beg, &e,0);
1.1546 + if (beg == e)
1.1547 + err = KErrArgument;
1.1548 + end = e;
1.1549 + command = ESelectConfig;
1.1550 + }
1.1551 + else if(_strnicmp(beg, "NextConfig", end-beg) == 0)
1.1552 +
1.1553 + {
1.1554 + command = ENextConfig;
1.1555 + }
1.1556 + else
1.1557 + err = KErrArgument;
1.1558 +
1.1559 + if (err != KErrNone)
1.1560 + return err;
1.1561 +
1.1562 + //get the shape
1.1563 + beg = skipws(end);
1.1564 + end = skiptok(beg);
1.1565 + if (end - beg != 4 || _strnicmp(beg, "rect", 4) != 0)
1.1566 + return KErrArgument;
1.1567 +
1.1568 + // get the parameters
1.1569 + beg = skipws(end);
1.1570 + char* end2;
1.1571 + TInt x = strtol(beg, &end2, 10);
1.1572 + if (beg == end2 || *end2++ != ',')
1.1573 + return KErrArgument;
1.1574 + beg = end2;
1.1575 + TInt y = strtol(beg, &end2, 10);
1.1576 + if (beg == end2)
1.1577 + return KErrArgument;
1.1578 + beg = skipws(end2);
1.1579 + TInt w = strtol(beg, &end2, 10);
1.1580 + if (beg == end2 || *end2++ != ',')
1.1581 + return KErrArgument;
1.1582 + beg = end2;
1.1583 + TInt h = strtol(beg, &end2, 10);
1.1584 + if (beg == end2)
1.1585 + return KErrArgument;
1.1586 +
1.1587 + VKRect* pRect = new VKRect(data, command, x, y, w, h);
1.1588 + if (!pRect)
1.1589 + return KErrNoMemory;
1.1590 + return iVirtualKeys.Append(pRect);
1.1591 +
1.1592 + }
1.1593 +
1.1594 +
1.1595 +TInt DWinsUi::DoDefineVirtualKey(TAny* aPtr, const char* aValue)
1.1596 + {
1.1597 + return static_cast<DWinsUi*>(aPtr)->DefineVirtualKey(aValue);
1.1598 + }
1.1599 +
1.1600 +TInt DWinsUi::DefineVirtualKey(const char* aValue)
1.1601 + {
1.1602 + // Get the key to map
1.1603 + const char* beg = skipws(aValue);
1.1604 + const char* end = skiptok(beg);
1.1605 + TInt key = iKeyboard.GetEPOCKeyCode(TPtrC8((const TUint8*)beg, end-beg));
1.1606 + if (key == KErrNotFound)
1.1607 + return key;
1.1608 +
1.1609 + //get the shape
1.1610 + beg = skipws(end);
1.1611 + end = skiptok(beg);
1.1612 + if (end - beg != 4 || _strnicmp(beg, "rect", 4) != 0)
1.1613 + return KErrArgument;
1.1614 +
1.1615 + // get the parameters
1.1616 + beg = skipws(end);
1.1617 + char* end2;
1.1618 + TInt x = strtol(beg, &end2, 10);
1.1619 + if (beg == end2 || *end2++ != ',')
1.1620 + return KErrArgument;
1.1621 + beg = end2;
1.1622 + TInt y = strtol(beg, &end2, 10);
1.1623 + if (beg == end2)
1.1624 + return KErrArgument;
1.1625 + beg = skipws(end2);
1.1626 + TInt w = strtol(beg, &end2, 10);
1.1627 + if (beg == end2 || *end2++ != ',')
1.1628 + return KErrArgument;
1.1629 + beg = end2;
1.1630 + TInt h = strtol(beg, &end2, 10);
1.1631 + if (beg == end2)
1.1632 + return KErrArgument;
1.1633 +
1.1634 + VKRect* pRect = new VKRect(key, EKey, x, y, w, h);
1.1635 + if (!pRect)
1.1636 + return KErrNoMemory;
1.1637 + return iVirtualKeys.Append(pRect);
1.1638 + }
1.1639 +
1.1640 +
1.1641 +LOCAL_C TInt readBitmapInfo(PBITMAPINFOHEADER aHeader, const char* aFileName)
1.1642 + {
1.1643 + PBITMAPFILEHEADER pbmfh=NULL;
1.1644 + PBITMAPINFOHEADER pbmih=NULL;
1.1645 + TInt bfOffBits;
1.1646 +
1.1647 + HANDLE fh=CreateFileA(aFileName,GENERIC_READ,NULL,NULL,OPEN_EXISTING,NULL,NULL);
1.1648 + if (!fh || fh==INVALID_HANDLE_VALUE)
1.1649 + return KErrNotFound;
1.1650 +
1.1651 + TInt r=KErrNone;
1.1652 +
1.1653 + // read in the bitmap file header. save the offset to bits.
1.1654 + pbmfh = (PBITMAPFILEHEADER)LocalAlloc(LPTR, sizeof(BITMAPFILEHEADER));
1.1655 + if (pbmfh==NULL)
1.1656 + {
1.1657 + r=KErrNotFound;
1.1658 + goto exit;
1.1659 + }
1.1660 + DWORD bytesRead;
1.1661 + ReadFile(fh, (LPVOID)pbmfh, sizeof(BITMAPFILEHEADER), &bytesRead, NULL);
1.1662 + bfOffBits=pbmfh->bfOffBits;
1.1663 +
1.1664 + // read in the bitmap info header and the color table right after it.
1.1665 + pbmih = (PBITMAPINFOHEADER)LocalAlloc(LPTR, bfOffBits- sizeof(BITMAPFILEHEADER));
1.1666 + if (pbmih==NULL)
1.1667 + {
1.1668 + r=KErrNotFound;
1.1669 + goto exit;
1.1670 + }
1.1671 + ReadFile(fh, (LPVOID)pbmih, bfOffBits-sizeof(BITMAPFILEHEADER),&bytesRead,NULL);
1.1672 + *aHeader=*pbmih;
1.1673 +exit:
1.1674 + LocalFree(LocalHandle ((LPSTR)pbmih));
1.1675 + LocalFree(LocalHandle ((LPSTR)pbmfh));
1.1676 + CloseHandle(fh);
1.1677 + return r;
1.1678 + }
1.1679 +
1.1680 +HBITMAP readBitmap(HDC aHdc, const char* aFileName)
1.1681 +//
1.1682 +// reads a BMP file from disk and returns a HBITMAP
1.1683 +//
1.1684 + {
1.1685 + HBITMAP hbm=NULL;
1.1686 + PBITMAPFILEHEADER pbmfh=NULL;
1.1687 + PBITMAPINFOHEADER pbmih=NULL;
1.1688 + TUint8 *pBits=NULL;
1.1689 + TInt bfOffBits;
1.1690 + TInt nbytes;
1.1691 +
1.1692 + HANDLE fh=CreateFileA(aFileName, GENERIC_READ, NULL, NULL, OPEN_EXISTING, NULL, NULL);
1.1693 + if (!fh || fh==INVALID_HANDLE_VALUE)
1.1694 + return NULL;
1.1695 +
1.1696 + nbytes=GetFileSize((HANDLE)fh, NULL);
1.1697 + // read in the bitmap file header. save the offset to bits.
1.1698 + pbmfh = (PBITMAPFILEHEADER)LocalAlloc(LPTR, sizeof(BITMAPFILEHEADER));
1.1699 + if (pbmfh==NULL)
1.1700 + goto exit;
1.1701 + DWORD bytesRead;
1.1702 + ReadFile(fh, (LPVOID)pbmfh, sizeof(BITMAPFILEHEADER),&bytesRead,NULL);
1.1703 + bfOffBits=pbmfh->bfOffBits;
1.1704 +
1.1705 + // read in the bitmap info header and the color table right after it.
1.1706 + pbmih = (PBITMAPINFOHEADER)LocalAlloc(LPTR, bfOffBits- sizeof(BITMAPFILEHEADER));
1.1707 + if (pbmih==NULL)
1.1708 + goto exit;
1.1709 + ReadFile(fh, (LPVOID)pbmih, bfOffBits-sizeof(BITMAPFILEHEADER),&bytesRead,NULL);
1.1710 +
1.1711 + // finally read in the bit data.
1.1712 + pBits = (PBYTE)LocalAlloc (LPTR, (nbytes - bfOffBits));
1.1713 + if (pBits==NULL)
1.1714 + goto exit;
1.1715 + ReadFile(fh, (LPVOID)pBits, nbytes-bfOffBits,&bytesRead,NULL);
1.1716 +
1.1717 + hbm=CreateDIBitmap(aHdc, pbmih, CBM_INIT, pBits,(PBITMAPINFO) pbmih, DIB_RGB_COLORS);
1.1718 +exit:
1.1719 + LocalFree(LocalHandle ((LPSTR)pBits));
1.1720 + LocalFree(LocalHandle ((LPSTR)pbmih));
1.1721 + LocalFree(LocalHandle ((LPSTR)pbmfh));
1.1722 + CloseHandle(fh);
1.1723 + return hbm;
1.1724 + }
1.1725 +
1.1726 +void LoadFasciaBitmap(TInt aScreen)
1.1727 + {
1.1728 + HDC hdc=GetDC(TheWin[aScreen]);
1.1729 + RECT windowRect = {0};
1.1730 + windowRect.right=systemIni->iScreens[aScreen]->iXYInputWidth;
1.1731 + windowRect.bottom=systemIni->iScreens[aScreen]->iXYInputHeight;
1.1732 + HBITMAP screenBitmap=readBitmap(hdc, systemIni->iScreens[aScreen]->iFasciaFileName);
1.1733 + if (screenBitmap==NULL)
1.1734 + {
1.1735 + screenBitmap=CreateCompatibleBitmap(hdc, windowRect.right-windowRect.left, windowRect.bottom-windowRect.top);
1.1736 + HDC hdcMem=CreateCompatibleDC(hdc);
1.1737 + SelectObject(hdcMem, screenBitmap);
1.1738 + PatBlt(hdcMem, 0, 0, windowRect.right-windowRect.left, windowRect.bottom-windowRect.top, BLACKNESS);
1.1739 + DeleteDC(hdcMem);
1.1740 + }
1.1741 + __ASSERT_ALWAYS(screenBitmap!=NULL,Fault(EGuiCreateBitmap));
1.1742 + TheScreenBitmap[aScreen]=screenBitmap;
1.1743 +
1.1744 + DrawLeds();
1.1745 +
1.1746 + ReleaseDC(TheWin[aScreen], hdc);
1.1747 + }
1.1748 +TBool DWinsUi::MultiTouchEnabled() const
1.1749 + {
1.1750 + return iMultiTouchEnabled;
1.1751 + }
1.1752 +
1.1753 +TBool DWinsUi::GCEEnabled() const
1.1754 + {
1.1755 + return iGCEEnabled;
1.1756 + }
1.1757 +
1.1758 +TInt DWinsUi::MultiTouchProximityStep() const
1.1759 + {
1.1760 + return iMultiTouchProximityStep;
1.1761 + }
1.1762 +
1.1763 +TInt DWinsUi::MultiTouchPressureStep() const
1.1764 + {
1.1765 + return iMultiTouchPressureStep;
1.1766 + }
1.1767 +
1.1768 +TBool DWinsUi::OnDigitizer(TInt aX, TInt aY) const
1.1769 + {
1.1770 + if (!iDigitizerEnabled)
1.1771 + return EFalse;
1.1772 + switch(CurrentFlipState[0])
1.1773 + {
1.1774 + case EEmulatorFlipRestore:
1.1775 + {
1.1776 + aX -= iDigitizerOffsetX;
1.1777 + aY -= iDigitizerOffsetY;
1.1778 + break;
1.1779 + }
1.1780 + case EEmulatorFlipInvert:
1.1781 + {
1.1782 + aX -= systemIni->iScreens[0]->iScreenWidth - iDigitizerOffsetX - iDigitizerWidth;
1.1783 + aY -= systemIni->iScreens[0]->iScreenHeight - iDigitizerOffsetY - iDigitizerHeight;
1.1784 + break;
1.1785 + }
1.1786 + case EEmulatorFlipRight:
1.1787 + {
1.1788 + TInt oldY = aY;
1.1789 + aY = aX - (systemIni->iScreens[0]->iScreenHeight - iDigitizerOffsetY - iDigitizerHeight);
1.1790 + aX = oldY - iDigitizerOffsetX;
1.1791 + break;
1.1792 + }
1.1793 + case EEmulatorFlipLeft:
1.1794 + {
1.1795 + TInt oldY = aY;
1.1796 + aY = aX - iDigitizerOffsetY;
1.1797 + aX = oldY - (systemIni->iScreens[0]->iScreenWidth - iDigitizerOffsetX - iDigitizerWidth);
1.1798 + break;
1.1799 + }
1.1800 + }
1.1801 + return (TUint(aX) < TUint(iDigitizerWidth) && TUint(aY) < TUint(iDigitizerHeight));
1.1802 + }
1.1803 +
1.1804 +LOCAL_C void addMouseEvent(TRawEvent::TType aType,TInt aXpos,TInt aYpos)
1.1805 +//
1.1806 +// Add a mouse event.
1.1807 +//
1.1808 + {
1.1809 + if (systemIni->OnDigitizer(aXpos, aYpos))
1.1810 + {
1.1811 + TRawEvent v;
1.1812 + v.Set(aType,aXpos,aYpos);
1.1813 + TheEventQ.Add(v);
1.1814 + }
1.1815 + }
1.1816 +
1.1817 +LOCAL_C void addMouseEvent(TRawEvent::TType aType,TInt aXpos,TInt aYpos,TInt aZpos, TInt aPointerId=0)
1.1818 +//
1.1819 +// Add a multitouch mouse event.
1.1820 +//
1.1821 + {
1.1822 + if (systemIni->OnDigitizer(aXpos, aYpos))
1.1823 + {
1.1824 + TRawEvent v;
1.1825 + v.Set(aType,aXpos,aYpos, aZpos);
1.1826 + v.SetPointerNumber(static_cast<const TUint8>(aPointerId));
1.1827 + TheEventQ.Add(v);
1.1828 + }
1.1829 + }
1.1830 +LOCAL_C void addKeyEvent(TRawEvent::TType aType,TInt aKey)
1.1831 + {
1.1832 + TRawEvent v;
1.1833 + v.Set(aType, aKey);
1.1834 + TheEventQ.Add(v);
1.1835 + }
1.1836 +
1.1837 +
1.1838 +LOCAL_C void SwitchConfiguration(TInt aData, TBool aSendFlipKey = ETrue)
1.1839 + {
1.1840 + if (aData < 0 || aData >= masterIni->iSystemInis.Count())
1.1841 + return;
1.1842 +
1.1843 + CurrentConfiguration = aData;
1.1844 + systemIni = masterIni->iSystemInis[aData];
1.1845 +
1.1846 + //get the correct fascia bitmaps
1.1847 + TInt screens=systemIni->iScreens.Count();
1.1848 + TInt i;
1.1849 + TUint disabledWinType=ENormalResolution;
1.1850 + for(i=0;i<screens;i++)
1.1851 + {
1.1852 + DeleteObject(TheScreenBitmap[i]);
1.1853 + LoadFasciaBitmap(i);
1.1854 + if (masterIni->iBufferSet[i].iDisplayState!=ENormalResolution)
1.1855 + {
1.1856 + disabledWinType=masterIni->iBufferSet[i].iDisplayState;
1.1857 + }
1.1858 + }
1.1859 +
1.1860 + //update the window title
1.1861 + if (disabledWinType!=ENormalResolution && disabledWinType < 4) //hardwired 4 because the code below is hardwired
1.1862 + { //string may be multi-part indexed by disable type, or it may not
1.1863 + CHAR* firstsemi=strchr(systemIni->iWindowTitle,';');
1.1864 + CHAR* secondsemi=NULL;
1.1865 + if (firstsemi)
1.1866 + {
1.1867 + secondsemi=strchr(firstsemi+1,';');
1.1868 + }
1.1869 + if (firstsemi&&secondsemi)
1.1870 + {
1.1871 + *firstsemi='\0';
1.1872 + *secondsemi='\0';
1.1873 + char* ptr[4]={0,systemIni->iWindowTitle,firstsemi+1,secondsemi+1};
1.1874 + SetWindowTextA(TheControlWin, ptr[disabledWinType]);
1.1875 + *firstsemi=';';
1.1876 + *secondsemi=';';
1.1877 + }
1.1878 + else
1.1879 + {
1.1880 + SetWindowTextA(TheControlWin, systemIni->iWindowTitle);
1.1881 + }
1.1882 +
1.1883 + }
1.1884 + else
1.1885 + {
1.1886 + SetWindowTextA(TheControlWin, systemIni->iWindowTitle);
1.1887 + }
1.1888 + //resize and repaint the current window anyway.
1.1889 + //the text window server doesn't respond to orientation messages
1.1890 + for(i=0;i<screens;i++)
1.1891 + {
1.1892 + InvalidateRect(TheWin[i], NULL, false);
1.1893 + SendMessage(TheWin[i], WM_FLIP_MESSAGE, systemIni->iScreens[i]->iScreenRotation,0);
1.1894 + }
1.1895 +
1.1896 + //pass on the orientation key to the windows server
1.1897 + if (aSendFlipKey)
1.1898 + {
1.1899 + if (!WinsGuiPowerHandler->iStandby)
1.1900 + {
1.1901 + addKeyEvent(TRawEvent::EKeyDown, systemIni->iInitialFlipMsg);
1.1902 + addKeyEvent(TRawEvent::EKeyUp, systemIni->iInitialFlipMsg);
1.1903 + }
1.1904 + else
1.1905 + {
1.1906 + //remember the flip message so we can send it to the window server when we come out of standby
1.1907 + SavedFlipMessage = systemIni->iInitialFlipMsg;
1.1908 + }
1.1909 + }
1.1910 + }
1.1911 +/**
1.1912 +Sets the specified screen to the given width and height, if available.
1.1913 +
1.1914 +The configurations are searched to find a match, taking the display state into
1.1915 +account. If no configuration is available, the request is ignored.
1.1916 +
1.1917 +@param aScreenNumber the screen index
1.1918 +@param aWidth the desired width
1.1919 +@param aHeight the desired height
1.1920 +**/
1.1921 +void DMasterIni::SetDisplaySize(TInt aDisplayNumber, TInt aWidth, TInt aHeight)
1.1922 + {
1.1923 + TInt displayCount = iBufferSet.Count();
1.1924 +
1.1925 + if (aDisplayNumber < 0 || aDisplayNumber >= displayCount)
1.1926 + {
1.1927 + // Invalid screen number, discard.
1.1928 + return;
1.1929 + }
1.1930 +
1.1931 + if (iBufferSet[aDisplayNumber].iDisplayState != ENormalResolution)
1.1932 + {
1.1933 + // No (non-zero) resolutions available, discard.
1.1934 + return;
1.1935 + }
1.1936 +
1.1937 + TInt count = iSystemInis.Count();
1.1938 + TInt index;
1.1939 + for (index = 0; index < count; index++)
1.1940 + {
1.1941 + DWinsUi* newIni = masterIni->iSystemInis[index];
1.1942 + DScreenProperties* newProps = newIni->iScreens[aDisplayNumber];
1.1943 +
1.1944 + if (newProps->iScreenWidth == aWidth && newProps->iScreenHeight == aHeight)
1.1945 + {
1.1946 + // Found a potential match. Check other screens match their current size.
1.1947 + if (newIni == systemIni)
1.1948 + {
1.1949 + // Current configuration, already in use. Nothing to do.
1.1950 + break;
1.1951 + }
1.1952 +
1.1953 + TInt display;
1.1954 + for (display = 0; display < displayCount; display++)
1.1955 + {
1.1956 + if (display == aDisplayNumber)
1.1957 + {
1.1958 + // No need to check the display we are changing
1.1959 + continue;
1.1960 + }
1.1961 +
1.1962 + DScreenProperties* currentPropsN = systemIni->iScreens[display];
1.1963 + DScreenProperties* newPropsN = newIni->iScreens[display];
1.1964 +
1.1965 + if (newPropsN->iScreenWidth != currentPropsN->iScreenWidth ||
1.1966 + newPropsN->iScreenHeight != currentPropsN->iScreenHeight)
1.1967 + {
1.1968 + // Resolution mismatch, try next configuration.
1.1969 + break;
1.1970 + }
1.1971 + }
1.1972 +
1.1973 + if (display == displayCount)
1.1974 + {
1.1975 + // Match found, switch to this configuration and stop. Force
1.1976 + // rotation to the same as the current rotation.
1.1977 + newProps->iScreenRotation = systemIni->iScreens[aDisplayNumber]->iScreenRotation;
1.1978 + SwitchConfiguration(index);
1.1979 + break;
1.1980 + }
1.1981 + }
1.1982 + }
1.1983 + }
1.1984 +
1.1985 +
1.1986 +void DMasterIni::SetBufferFormat(TInt aDisplayNumber, TUint aAggregateSize, RDisplayChannel::TPixelFormat aPixelFormat)
1.1987 + {
1.1988 + TInt displayCount = iBufferSet.Count();
1.1989 +
1.1990 + if (aDisplayNumber < 0 || aDisplayNumber >= displayCount)
1.1991 + {
1.1992 + // Invalid screen number, discard.
1.1993 + return;
1.1994 + }
1.1995 +
1.1996 + LPBITMAPV4HEADER info = &iBufferSet[aDisplayNumber].iInfo;
1.1997 +
1.1998 + // update the bitmap header taking in consideration the new pixel format
1.1999 + switch (aPixelFormat)
1.2000 + {
1.2001 + case EUidPixelFormatXRGB_4444:
1.2002 + case EUidPixelFormatARGB_4444:
1.2003 + info->bV4BitCount=16;
1.2004 + info->bV4V4Compression = BI_BITFIELDS;
1.2005 + info->bV4RedMask = 0x0F00;
1.2006 + info->bV4GreenMask = 0x00F0;
1.2007 + info->bV4BlueMask = 0x000F;
1.2008 + break;
1.2009 + case EUidPixelFormatRGB_565:
1.2010 + info->bV4BitCount=16;
1.2011 + info->bV4V4Compression = BI_BITFIELDS;
1.2012 + info->bV4RedMask = 0xF800;
1.2013 + info->bV4GreenMask = 0x07E0;
1.2014 + info->bV4BlueMask = 0x001F;
1.2015 + break;
1.2016 + case EUidPixelFormatXRGB_8888: // Really 32bpp, but top 8 unused
1.2017 + case EUidPixelFormatARGB_8888:
1.2018 + case EUidPixelFormatARGB_8888_PRE:
1.2019 + info->bV4BitCount=32;
1.2020 + info->bV4V4Compression = BI_RGB;
1.2021 + // Mask is implicit for BI_RGB compression
1.2022 + break;
1.2023 + default:
1.2024 + // We got an error, it seems. Let's ignore the message
1.2025 + return;
1.2026 + }
1.2027 + iBufferSet[aDisplayNumber].iBufferFormat.iPixelFormat = aPixelFormat;
1.2028 +
1.2029 + // taking advantage of limiting the width and size to KMaxTInt16
1.2030 + TInt width = aAggregateSize & 0x0000ffff;
1.2031 + TInt height = (aAggregateSize >> 16) & 0x0000ffff;
1.2032 +
1.2033 + // let's deal with the new size just received
1.2034 + iBufferSet[aDisplayNumber].iBufferFormat.iSize.iWidth = width;
1.2035 + iBufferSet[aDisplayNumber].iBufferFormat.iSize.iHeight = height;
1.2036 +
1.2037 + // update the bitmap header, taking in consideration the rotation
1.2038 + switch (CurrentFlipState[aDisplayNumber])
1.2039 + {
1.2040 + case EEmulatorFlipRestore:
1.2041 + case EEmulatorFlipInvert:
1.2042 + info->bV4Width = width;
1.2043 + info->bV4Height = -height;
1.2044 + break;
1.2045 + case EEmulatorFlipLeft:
1.2046 + case EEmulatorFlipRight:
1.2047 + info->bV4Width = height;
1.2048 + info->bV4Height = -width;
1.2049 + break;
1.2050 + }
1.2051 + // finally, update the image size
1.2052 + SetImageSize(aDisplayNumber);
1.2053 + }
1.2054 +
1.2055 +void DMasterIni::SetImageSize(TInt aScreenNumber)
1.2056 + {
1.2057 + TInt displayCount = iBufferSet.Count();
1.2058 +
1.2059 + if (aScreenNumber >= 0 && aScreenNumber < displayCount)
1.2060 + {
1.2061 + LPBITMAPV4HEADER info = &iBufferSet[aScreenNumber].iInfo;
1.2062 + TInt bpp = _ALIGN_UP(info->bV4BitCount, 16); //12 & 16 --> 16 ; 24 & 32 --> 32
1.2063 + TInt widthInBpp = info->bV4Width * bpp;
1.2064 + //rounding to 32 bits (4 octets) and converting, then, bits to octets;
1.2065 + TInt scanLineInBytes = _ALIGN_UP(widthInBpp, 32) >> 3;
1.2066 + // info->bV4Height is negative or zero
1.2067 + info->bV4SizeImage = -info->bV4Height * scanLineInBytes;
1.2068 + }
1.2069 + }
1.2070 +
1.2071 +LOCAL_C void NextConfiguration()
1.2072 + {
1.2073 + TInt config = CurrentConfiguration;
1.2074 + if (++config == masterIni->iSystemInis.Count())
1.2075 + config = 0;
1.2076 + SwitchConfiguration(config);
1.2077 + }
1.2078 +
1.2079 +
1.2080 +
1.2081 +LOCAL_C TBool ProcessedByEmulatorKey(TInt aScanCode, HWND hWnd,TUint message,TUint wParam,TUint lParam)
1.2082 + {
1.2083 +
1.2084 + TBool rVal = EFalse;
1.2085 + rVal = ETrue;
1.2086 + for (TInt i=0;i<systemIni->iControlHotKeys.Count();i++)//check key combinations
1.2087 + {
1.2088 + if (systemIni->iControlHotKeys[i]->CheckCombinationPressed())
1.2089 + {
1.2090 + switch (systemIni->iControlHotKeys[i]->iCommand)
1.2091 + {
1.2092 +
1.2093 + case ENextConfig:
1.2094 + NextConfiguration();
1.2095 + break;
1.2096 +
1.2097 + case ESelectConfig:
1.2098 + SwitchConfiguration(systemIni->iControlHotKeys[i]->iData);
1.2099 + break;
1.2100 +
1.2101 + }
1.2102 + return ETrue;
1.2103 + }
1.2104 + }
1.2105 + switch (aScanCode)
1.2106 + {
1.2107 +
1.2108 + case EStdKeyF4:
1.2109 + {
1.2110 + // Simulate a change of media card
1.2111 + TInt irq = NKern::DisableAllInterrupts();
1.2112 + if (*Wins::MediaDoorOpenPtr())
1.2113 + {
1.2114 + *Wins::CurrentPBusDevicePtr() += 1;
1.2115 + if (*Wins::CurrentPBusDevicePtr() == 2)
1.2116 + {
1.2117 + *Wins::CurrentPBusDevicePtr() = -1;
1.2118 + }
1.2119 + }
1.2120 + NKern::RestoreInterrupts(irq);
1.2121 +
1.2122 + // pass on to the windows system so that if
1.2123 + // Alt-F4 is pressed the window will close
1.2124 + if (hWnd)
1.2125 + DefWindowProcA(hWnd,message,wParam,lParam);
1.2126 + break;
1.2127 + }
1.2128 +
1.2129 + default:
1.2130 + rVal = EFalse;
1.2131 + break;
1.2132 + }
1.2133 + return rVal;
1.2134 + }
1.2135 +
1.2136 +LOCAL_C void MultiChildWndPointer(TUint aMessage,TInt aXpos,TInt aYpos, TInt aZ, TInt aPointerId)
1.2137 +//
1.2138 +// Handle a multi-touch pointer event in the Symbian OS screen window
1.2139 +//
1.2140 + {
1.2141 + TRawEvent::TType eventType=TRawEvent::ENone;
1.2142 + CHAR buf[50];
1.2143 +
1.2144 + if (aZ <= TheMultiTouch->iZMaxRange) //negative
1.2145 + {
1.2146 + eventType = TRawEvent::EPointer3DOutOfRange;
1.2147 + wsprintf((LPTSTR)buf, (LPCTSTR)TEXT("Out Of Range"));
1.2148 + SendMessage(hwndStatus, SB_SETTEXT, aPointerId , (LPARAM)(buf));
1.2149 + }
1.2150 + else
1.2151 + {
1.2152 + wsprintf((LPTSTR)buf, (LPCTSTR)TEXT("%d: %d,%d,%d"), aPointerId, aXpos,aYpos,aZ);
1.2153 + SendMessage(hwndStatus, SB_SETTEXT, aPointerId , (LPARAM)(buf));
1.2154 + switch (aMessage)
1.2155 + {
1.2156 + case WM_MOUSEMOVE:
1.2157 + {
1.2158 + eventType=TRawEvent::EPointerMove;
1.2159 + break;
1.2160 + }
1.2161 + case WM_LBUTTONDOWN:
1.2162 + {
1.2163 + SetCapture(TheChildWin[0]);
1.2164 + eventType = TRawEvent::EButton1Down;
1.2165 + }
1.2166 + break;
1.2167 + case WM_LBUTTONUP:
1.2168 + {
1.2169 + ReleaseCapture();
1.2170 + eventType = TRawEvent::EButton1Up;
1.2171 + break;
1.2172 + }
1.2173 + case WM_RBUTTONDOWN:
1.2174 + {
1.2175 + eventType = TRawEvent::EButton3Down;
1.2176 + break;
1.2177 + }
1.2178 + case WM_RBUTTONUP:
1.2179 + {
1.2180 + eventType = TRawEvent::EButton3Up;
1.2181 + break;
1.2182 + }
1.2183 + case WM_MOUSEWHEEL:
1.2184 + {
1.2185 + eventType = TRawEvent::EPointerMove;
1.2186 + break;
1.2187 + }
1.2188 + default:
1.2189 + return;
1.2190 + }
1.2191 + }
1.2192 +
1.2193 + if (!WinsGuiPowerHandler->iStandby)
1.2194 + {
1.2195 + addMouseEvent(eventType, aXpos, aYpos, aZ, aPointerId);
1.2196 + }
1.2197 + }
1.2198 +
1.2199 +LOCAL_C void ChildWndPointer(TUint message,TInt aXpos,TInt aYpos)
1.2200 +//
1.2201 +// Handle a pointer event in the Symbian OS screen window
1.2202 +//
1.2203 + {
1.2204 + // Enable the multitouch if the cursor is inside the main client window
1.2205 + if (DMultiTouch::iMultiTouchCreated)
1.2206 + {
1.2207 + RECT client;
1.2208 + WINDOWINFO info;
1.2209 + GetWindowInfo(TheChildWin[0], &info);
1.2210 + POINT pt = {aXpos+(TInt)info.rcClient.left, aYpos+(TInt)info.rcClient.top};
1.2211 + if (GetWindowRect(TheChildWin[0], &client) &&
1.2212 + (PtInRect(&client,pt)!=NULL) && !DMultiTouch::iMultiTouchTempEnabled) // within the window
1.2213 + {
1.2214 + if (systemIni->MultiTouchEnabled() && systemIni->GCEEnabled())
1.2215 + {
1.2216 + if(TheMultiTouch->Register()) // Register successfully
1.2217 + {
1.2218 + DMultiTouch::iMultiTouchTempEnabled = TRUE;
1.2219 + //Show the status bars at the bottom of the emulator
1.2220 + SetWindowPos(hwndStatus,0,0,0,0,0,SWP_SHOWWINDOW);
1.2221 + SetFocus(TheWin[0]);
1.2222 + SetCursor(LoadCursorA(NULL,MAKEINTRESOURCEA(32512)));
1.2223 + }
1.2224 + }
1.2225 + }
1.2226 + }
1.2227 + TRawEvent::TType eventType=TRawEvent::ENone;
1.2228 + switch (message)
1.2229 + {
1.2230 + case WM_MOUSEMOVE:
1.2231 + eventType=TRawEvent::EPointerMove;
1.2232 + break;
1.2233 + case WM_LBUTTONDOWN:
1.2234 + {
1.2235 + SetCapture(TheChildWin[0]);
1.2236 + eventType=TRawEvent::EButton1Down;
1.2237 + }
1.2238 + break;
1.2239 + case WM_LBUTTONUP:
1.2240 + ReleaseCapture();
1.2241 + eventType=TRawEvent::EButton1Up;
1.2242 + break;
1.2243 + case WM_RBUTTONDOWN:
1.2244 + eventType=TRawEvent::EButton3Down;
1.2245 + break;
1.2246 + case WM_RBUTTONUP:
1.2247 + eventType=TRawEvent::EButton3Up;
1.2248 + break;
1.2249 + case WM_MBUTTONDOWN:
1.2250 + eventType=TRawEvent::EButton2Down;
1.2251 + break;
1.2252 + case WM_MBUTTONUP:
1.2253 + eventType=TRawEvent::EButton2Up;
1.2254 + break;
1.2255 + }
1.2256 + if (!WinsGuiPowerHandler->iStandby)
1.2257 + {
1.2258 + addMouseEvent(eventType, aXpos, aYpos);
1.2259 + }
1.2260 + }
1.2261 +
1.2262 +LOCAL_C void FrameWndPointer(TUint message,TInt aXpos,TInt aYpos, TInt aScreenNumber, TInt aPointerId = 0)
1.2263 +//
1.2264 +// Handle a frame wnd pointer event.
1.2265 +//
1.2266 + {
1.2267 + static bool processingScreenOn=FALSE;
1.2268 + TEmulCommand command = ENoCommand;
1.2269 + TInt commandData = 0;
1.2270 + TBool mouseEvent = ETrue;
1.2271 +
1.2272 + TRawEvent::TType eventType=TRawEvent::ENone;
1.2273 +
1.2274 + TViewport& viewport = systemIni->iScreens[aScreenNumber]->iViewport;
1.2275 + aXpos += viewport.GetViewportOffsetX(); // make mouse-coords relative to fascia edge even if window is scrolled
1.2276 + aYpos += viewport.GetViewportOffsetY();
1.2277 +
1.2278 + switch (message)
1.2279 + {
1.2280 + case WM_MOUSEMOVE:
1.2281 + {
1.2282 + TInt newX, newY;
1.2283 + systemIni->TranslateMouseCoords(CurrentFlipState[0], aXpos, aYpos, systemIni->iScreens[0]->iXYInputWidth, systemIni->iScreens[0]->iXYInputHeight, newX, newY);
1.2284 +
1.2285 + if (aPointerId == 0)
1.2286 + { // only system pointer changes shape
1.2287 + if (systemIni->GetVirtualKey(command, newX, newY) >= 0)
1.2288 + {
1.2289 + HMODULE hmodule = GetModuleHandleA("winsgui.dll");
1.2290 + SetCursor(LoadCursorA((HINSTANCE)hmodule,MAKEINTRESOURCEA(OVERKEY))); //hand cursor
1.2291 + }
1.2292 + else
1.2293 + SetCursor(LoadCursorA(NULL,MAKEINTRESOURCEA(32512))); //ICD_ARROW
1.2294 + }
1.2295 +
1.2296 + eventType=TRawEvent::EPointerMove;
1.2297 +
1.2298 + }
1.2299 + break;
1.2300 + case WM_LBUTTONDOWN:
1.2301 + {
1.2302 + SetCapture(TheWin[0]);
1.2303 + //check the configuration
1.2304 + TInt newX, newY;
1.2305 +
1.2306 + //if the emulator screen is rotated, rotate/flip the current mouse cursor position
1.2307 + //so it can be checked to see if it is in a key region.
1.2308 + systemIni->TranslateMouseCoords(CurrentFlipState[0], aXpos, aYpos, systemIni->iScreens[0]->iXYInputWidth, systemIni->iScreens[0]->iXYInputHeight, newX, newY);
1.2309 + commandData = systemIni->GetVirtualKey(command, newX, newY);
1.2310 +
1.2311 + if (commandData >= 0)
1.2312 + {
1.2313 + eventType=TRawEvent::EKeyDown;
1.2314 + mouseEvent = EFalse;
1.2315 + systemIni->SetVirtualKey(ETrue, commandData, command);
1.2316 + }
1.2317 + else
1.2318 + eventType=TRawEvent::EButton1Down;
1.2319 + }
1.2320 + break;
1.2321 + case WM_LBUTTONUP:
1.2322 + ReleaseCapture();
1.2323 + if (processingScreenOn)
1.2324 + {
1.2325 + // ignore button up - button down was switching things on
1.2326 + processingScreenOn=FALSE;
1.2327 + return;
1.2328 + }
1.2329 + if (systemIni->WasVirtualKey(commandData, command))
1.2330 + {
1.2331 + eventType=TRawEvent::EKeyUp;
1.2332 + mouseEvent = EFalse;
1.2333 + systemIni->SetVirtualKey(EFalse, EStdKeyNull, ENoCommand);
1.2334 + }
1.2335 + else
1.2336 + eventType=TRawEvent::EButton1Up;
1.2337 + break;
1.2338 + case WM_RBUTTONDOWN:
1.2339 + eventType=TRawEvent::EButton3Down;
1.2340 + break;
1.2341 + case WM_RBUTTONUP:
1.2342 + eventType=TRawEvent::EButton3Up;
1.2343 + break;
1.2344 + case WM_MBUTTONDOWN:
1.2345 + eventType=TRawEvent::EButton2Down;
1.2346 + break;
1.2347 + case WM_MBUTTONUP:
1.2348 + eventType=TRawEvent::EButton2Up;
1.2349 + break;
1.2350 + }
1.2351 + if (mouseEvent)
1.2352 + {
1.2353 +
1.2354 + if (!WinsGuiPowerHandler->iStandby)
1.2355 + {
1.2356 + /*
1.2357 + mouse events are relative to the child window position
1.2358 + and are clipped to the digitzer region in addMouseEvent
1.2359 + so all the mouse clicks are passed on here after being translated
1.2360 + to the child window coordinate system (under the current rotation)
1.2361 + */
1.2362 + TInt newX, newY;
1.2363 + switch (CurrentFlipState[0])
1.2364 + {
1.2365 + case EEmulatorFlipRestore:
1.2366 + default:
1.2367 + newX = aXpos - systemIni->iScreens[0]->iScreenOffsetX;
1.2368 + newY = aYpos - systemIni->iScreens[0]->iScreenOffsetY;
1.2369 + break;
1.2370 + case EEmulatorFlipInvert:
1.2371 + newX = aXpos - (systemIni->iScreens[0]->iXYInputWidth - systemIni->iScreens[0]->iScreenWidth - systemIni->iScreens[0]->iScreenOffsetX);
1.2372 + newY = aYpos - (systemIni->iScreens[0]->iXYInputHeight - systemIni->iScreens[0]->iScreenHeight - systemIni->iScreens[0]->iScreenOffsetY);
1.2373 + break;
1.2374 + case EEmulatorFlipLeft:
1.2375 + newX = aXpos - systemIni->iScreens[0]->iScreenOffsetY;
1.2376 + newY = aYpos - (systemIni->iScreens[0]->iXYInputWidth - systemIni->iScreens[0]->iScreenWidth - systemIni->iScreens[0]->iScreenOffsetX);
1.2377 + break;
1.2378 + case EEmulatorFlipRight:
1.2379 + newX = aXpos - (systemIni->iScreens[0]->iXYInputHeight - systemIni->iScreens[0]->iScreenHeight - systemIni->iScreens[0]->iScreenOffsetY);
1.2380 + newY = aYpos - systemIni->iScreens[0]->iScreenOffsetX;
1.2381 + break;
1.2382 + }
1.2383 + addMouseEvent(eventType, newX, newY);
1.2384 + }
1.2385 + }
1.2386 + else if ((((message == WM_LBUTTONDOWN && command == EKey) && !ProcessedByEmulatorKey((TUint8)commandData,0,0,0,0)))
1.2387 + || (message == WM_LBUTTONUP))
1.2388 + {
1.2389 + switch (command)
1.2390 + {
1.2391 + case EKey:
1.2392 + if (!WinsGuiPowerHandler->iStandby)
1.2393 + addKeyEvent(eventType, (TUint8)commandData);
1.2394 + break;
1.2395 +
1.2396 + case ENextConfig:
1.2397 + NextConfiguration();
1.2398 + break;
1.2399 +
1.2400 + case ESelectConfig:
1.2401 + SwitchConfiguration(commandData);
1.2402 + break;
1.2403 + }
1.2404 + }
1.2405 + }
1.2406 +
1.2407 +LOCAL_C TInt ScreenFromHWND(HWND aHwnd,HWND* pWin)
1.2408 + {
1.2409 + TInt screens=systemIni->iScreens.Count();
1.2410 + TInt r=-1;
1.2411 + for(TInt i=0;i<screens;i++)
1.2412 + {
1.2413 + if(pWin[i]==aHwnd)
1.2414 + {
1.2415 + r=i;
1.2416 + break;
1.2417 + }
1.2418 + }
1.2419 + return r;
1.2420 + }
1.2421 +void MultiTouchWndPointer(TUint message,TInt aXpos,TInt aYpos, TInt aZ, TInt aPointerId)
1.2422 + {
1.2423 + WINDOWINFO info;
1.2424 + info.cbSize = sizeof(WINDOWINFO);
1.2425 + if (GetWindowInfo(TheWin[0], &info))
1.2426 + {
1.2427 + POINT pt = {aXpos,aYpos};
1.2428 + if (PtInRect(&info.rcWindow,pt))
1.2429 + {
1.2430 + RECT client;
1.2431 + if (GetWindowRect(TheChildWin[0], &client) && PtInRect(&client,pt)) // within the window
1.2432 + {
1.2433 + MultiChildWndPointer(message, aXpos-client.left, aYpos-client.top, aZ, aPointerId);
1.2434 + }
1.2435 + else
1.2436 + {
1.2437 + // Disable the multitouch if the cursor is outside the application window
1.2438 + if (DMultiTouch::iMultiTouchTempEnabled) // within the window
1.2439 + {
1.2440 + DMultiTouch::iMultiTouchTempEnabled = FALSE;
1.2441 + if(TheMultiTouch->UnRegister())
1.2442 + {
1.2443 + SetWindowPos(hwndStatus,0,0,0,0,0,SWP_HIDEWINDOW);
1.2444 + }
1.2445 + }
1.2446 + FrameWndPointer(message, aXpos-info.rcClient.left, aYpos-info.rcClient.top, 0, aPointerId);
1.2447 + }
1.2448 + }
1.2449 + }
1.2450 + }
1.2451 +
1.2452 +LOCAL_C DScreenProperties* ScreenPropsFromHWND(HWND aHwnd, HWND* pWin)
1.2453 + {
1.2454 + TInt screenNumber = ScreenFromHWND(aHwnd, pWin);
1.2455 +
1.2456 + if(screenNumber >=0)
1.2457 + {
1.2458 + return systemIni->iScreens[screenNumber];
1.2459 + }
1.2460 + return NULL;
1.2461 +
1.2462 + }
1.2463 +
1.2464 +
1.2465 +TInt APIENTRY childWinProc(HWND hWnd,TUint message,TUint wParam,TUint lParam)
1.2466 +//
1.2467 +// The child window function.
1.2468 +//
1.2469 + {
1.2470 + TInt screenNumber = 0;
1.2471 + TRawEvent v;
1.2472 + switch (message)
1.2473 + {
1.2474 + case WM_FLIP_MESSAGE: // pass the flip message onto the parent window
1.2475 + {
1.2476 + screenNumber =ScreenFromHWND(hWnd,TheChildWin);
1.2477 + if(TUint(screenNumber) < TUint(systemIni->iScreens.Count()))
1.2478 + PostMessageA(TheWin[screenNumber],WM_FLIP_MESSAGE,wParam,NULL);
1.2479 + break;
1.2480 + }
1.2481 + case WM_LBUTTONDOWN:
1.2482 + case WM_LBUTTONUP:
1.2483 + case WM_MOUSEMOVE:
1.2484 + case WM_RBUTTONDOWN:
1.2485 + case WM_RBUTTONUP:
1.2486 + case WM_MBUTTONDOWN:
1.2487 + case WM_MBUTTONUP:
1.2488 + {
1.2489 + if (DMultiTouch::iMultiTouchTempEnabled)
1.2490 + {
1.2491 + DMultiTouch::iMultiTouchTempEnabled = FALSE;
1.2492 + }
1.2493 + screenNumber=ScreenFromHWND(hWnd,TheChildWin);
1.2494 + if(screenNumber==0)
1.2495 + {
1.2496 + ChildWndPointer(message,(TInt16)(lParam&0xFFFF),(TInt16)((lParam>>16)&0xFFFF));
1.2497 + }
1.2498 + break;
1.2499 + }
1.2500 + case WM_PAINT:
1.2501 + if (!PaintWindowFromBuffer(hWnd))
1.2502 + {
1.2503 + // Original behaviour
1.2504 + ValidateRect(hWnd,NULL);
1.2505 + v.Set(TRawEvent::ERedraw);
1.2506 + TheEventQ.Add(v);
1.2507 + }
1.2508 + break;
1.2509 + case WM_ACTIVATE:
1.2510 + case WM_SYSKEYDOWN:
1.2511 + case WM_KEYDOWN:
1.2512 + case WM_SYSKEYUP:
1.2513 + case WM_KEYUP:
1.2514 + Fault(EGuiChildWinProc);
1.2515 + break;
1.2516 + case WM_DESTROY:
1.2517 + break;
1.2518 +
1.2519 + case WM_CHAR:
1.2520 + case WM_SYSCHAR:
1.2521 + case WM_DEADCHAR:
1.2522 + case WM_SYSDEADCHAR:
1.2523 + break;
1.2524 +
1.2525 + case WMU_SET_DISPLAY_BUFFER:
1.2526 + screenNumber = ScreenFromHWND(hWnd, TheChildWin);
1.2527 + if (TUint(screenNumber) < TUint(systemIni->iScreens.Count()))
1.2528 + {
1.2529 + masterIni->iBufferSet[screenNumber].iDisplayBuffer = (LPVOID)lParam;
1.2530 + }
1.2531 + break;
1.2532 + case WMU_SET_DISPLAY_SIZE:
1.2533 + screenNumber = ScreenFromHWND(hWnd, TheChildWin);
1.2534 + masterIni->SetDisplaySize(screenNumber, wParam, lParam);
1.2535 + break;
1.2536 +
1.2537 + case WMU_SET_BUFFER_FORMAT:
1.2538 + screenNumber = ScreenFromHWND(hWnd, TheChildWin);
1.2539 + masterIni->SetBufferFormat(screenNumber, wParam, (RDisplayChannel::TPixelFormat) lParam);
1.2540 + break;
1.2541 +
1.2542 + default:
1.2543 + return(DefWindowProcA(hWnd,message,wParam,lParam));
1.2544 + }
1.2545 + return(FALSE);
1.2546 + }
1.2547 +
1.2548 +
1.2549 +LOCAL_C TBool PaintWindowFromBuffer(HWND hWnd)
1.2550 + {
1.2551 + TInt screenNumber = ScreenFromHWND(hWnd,TheChildWin);
1.2552 + if (TUint(screenNumber) >= TUint(masterIni->iBufferSet.Count()))
1.2553 + {
1.2554 + return EFalse;
1.2555 + }
1.2556 +
1.2557 + LPVOID displayBuffer = masterIni->iBufferSet[screenNumber].iDisplayBuffer;
1.2558 + if (!displayBuffer)
1.2559 + {
1.2560 + return EFalse;
1.2561 + }
1.2562 +
1.2563 + TInt frameOffset = masterIni->iBufferSet[screenNumber].iScreenBuffer.iDisplayBufferOffset;
1.2564 + displayBuffer=LPVOID(frameOffset+(char*)displayBuffer);
1.2565 +
1.2566 + PAINTSTRUCT ps;
1.2567 + BeginPaint(hWnd, &ps);
1.2568 +
1.2569 + // Paint directly from the buffer to the window
1.2570 + LPBITMAPINFO info = (LPBITMAPINFO)&masterIni->iBufferSet[screenNumber].iInfo;
1.2571 + WORD width = (WORD)info->bmiHeader.biWidth;
1.2572 + WORD height = (WORD)-info->bmiHeader.biHeight; // stored -ve in info
1.2573 + SetDIBitsToDevice(ps.hdc,
1.2574 + 0, 0, // Dst X, Y
1.2575 + width, height, // Src W, H
1.2576 + 0, 0, // Src X, Y
1.2577 + 0, // Src offset to first line
1.2578 + height, // Src lines available
1.2579 + displayBuffer, // Src pointer to pixels
1.2580 + info, // Src info
1.2581 + DIB_RGB_COLORS);
1.2582 +
1.2583 + EndPaint(hWnd, &ps);
1.2584 +
1.2585 + return TRUE;
1.2586 + }
1.2587 +
1.2588 +
1.2589 +LOCAL_C void CalcTextPos(TInt aScreen, TInt& aX, TInt& aY)
1.2590 + {
1.2591 + switch (CurrentFlipState[aScreen])
1.2592 + {
1.2593 + case EEmulatorFlipInvert:
1.2594 + aX = systemIni->iScreens[aScreen]->iXYInputWidth-(systemIni->iScreens[aScreen]->iScreenOffsetX+systemIni->iScreens[aScreen]->iScreenWidth);
1.2595 + aY = systemIni->iScreens[aScreen]->iXYInputHeight-(systemIni->iScreens[aScreen]->iScreenOffsetY+systemIni->iScreens[aScreen]->iScreenHeight);
1.2596 + break;
1.2597 + case EEmulatorFlipLeft:
1.2598 + aX = systemIni->iScreens[aScreen]->iScreenOffsetY;
1.2599 + aY = systemIni->iScreens[aScreen]->iXYInputWidth-(systemIni->iScreens[aScreen]->iScreenOffsetX+systemIni->iScreens[aScreen]->iScreenWidth);
1.2600 + break;
1.2601 + case EEmulatorFlipRight:
1.2602 + aX = systemIni->iScreens[aScreen]->iXYInputHeight-(systemIni->iScreens[aScreen]->iScreenOffsetY+systemIni->iScreens[aScreen]->iScreenHeight);
1.2603 + aY = systemIni->iScreens[aScreen]->iScreenOffsetX;
1.2604 + break;
1.2605 + case EEmulatorFlipRestore:
1.2606 + default:
1.2607 + aX = systemIni->iScreens[aScreen]->iScreenOffsetX;
1.2608 + aY = systemIni->iScreens[aScreen]->iScreenOffsetY;
1.2609 + break;
1.2610 + }
1.2611 + //subtract viewport offset here
1.2612 + aX -= systemIni->iScreens[aScreen]->iViewport.GetViewportOffsetX();
1.2613 + aY -= systemIni->iScreens[aScreen]->iViewport.GetViewportOffsetY();
1.2614 + }
1.2615 +
1.2616 +TInt APIENTRY ctrlwinProc(HWND hWnd,TUint message,TUint wParam,TUint lParam)
1.2617 +//
1.2618 +// The control window function
1.2619 +//
1.2620 + {
1.2621 + switch(message)
1.2622 + {
1.2623 + case WM_SYSCOMMAND:
1.2624 + {
1.2625 + switch(wParam)
1.2626 + {
1.2627 + case 1:
1.2628 + {
1.2629 + NextConfiguration();
1.2630 + return 0;
1.2631 + }
1.2632 + case SC_MINIMIZE:
1.2633 + case SC_RESTORE:
1.2634 + {
1.2635 + if (wParam == SC_RESTORE)
1.2636 + Active();
1.2637 + for(TInt ix=0;ix<systemIni->iScreens.Count();ix++)
1.2638 + {
1.2639 + SendMessage(TheWin[ix],message,wParam,lParam);
1.2640 + }
1.2641 + if (wParam == SC_MINIMIZE)
1.2642 + Inactive();
1.2643 + }
1.2644 + }
1.2645 + return(DefWindowProcA(hWnd,message,wParam,lParam));
1.2646 + }
1.2647 + case WM_CLOSE: // tell all emulator screen windows to close
1.2648 + {
1.2649 + for(TInt i=0;i<systemIni->iScreens.Count();i++)
1.2650 + {
1.2651 + DestroyWindow(TheWin[i]);
1.2652 + }
1.2653 + DestroyWindow(hWnd);
1.2654 + break;
1.2655 + }
1.2656 + case WM_DESTROY:
1.2657 + {
1.2658 + // save the main window position information
1.2659 + HANDLE hSysIni;
1.2660 + hSysIni = CreateFileA(systemIni->iSysIniFileName, GENERIC_WRITE, 0, 0, CREATE_ALWAYS, 0, 0);
1.2661 + DScreenProperties* screenProps;
1.2662 + if (hSysIni != INVALID_HANDLE_VALUE)
1.2663 + {
1.2664 + DWORD numWritten;
1.2665 + //write an identifier into file so that program can avoid loading old version
1.2666 + WriteFile(hSysIni, &KDatFileVersion, sizeof(TInt), &numWritten, 0);
1.2667 +
1.2668 + //record current configuration at start of file.
1.2669 + WriteFile(hSysIni, &CurrentConfiguration, sizeof(TInt), &numWritten, 0);
1.2670 +
1.2671 + //Write out the state for each window.
1.2672 + for(TInt i=0;i<systemIni->iScreens.Count();i++)
1.2673 + {
1.2674 + screenProps= systemIni->iScreens[i];
1.2675 +
1.2676 + TWindowState winState= screenProps->GetWindowState();
1.2677 + WriteFile(hSysIni, &winState, sizeof(TWindowState), &numWritten, 0);
1.2678 +
1.2679 +
1.2680 + }
1.2681 + }
1.2682 + CloseHandle(hSysIni);
1.2683 +
1.2684 + PostQuitMessage(KErrNone);
1.2685 + break;
1.2686 + }
1.2687 + case WM_INPUT:
1.2688 + {
1.2689 + if (!DMultiTouch::iMultiTouchTempEnabled)
1.2690 + {
1.2691 + for(TInt ix=0;ix<systemIni->iScreens.Count();ix++)
1.2692 + {
1.2693 + DMultiTouch::iMultiTouchTempEnabled = TRUE;
1.2694 +
1.2695 + SendMessage(TheWin[ix],message,wParam,lParam);
1.2696 + }
1.2697 + }
1.2698 + else if (systemIni->MultiTouchEnabled() && DMultiTouch::iMultiTouchSupported && systemIni->GCEEnabled())
1.2699 + {
1.2700 + TheMultiTouch->OnWmInput(hWnd, message, wParam, lParam,TheChildWin[0]);
1.2701 + }
1.2702 + else
1.2703 + {
1.2704 + Fault(EGuiInvalidMultiTouch);
1.2705 + }
1.2706 + break;
1.2707 + }
1.2708 + default:
1.2709 + return(DefWindowProcA(hWnd,message,wParam,lParam));
1.2710 + }
1.2711 + return(FALSE);
1.2712 + }
1.2713 +
1.2714 +TInt APIENTRY winProc(HWND hWnd,TUint message,TUint wParam,TUint lParam)
1.2715 +//
1.2716 +// The border window function.
1.2717 +//
1.2718 + {
1.2719 +
1.2720 + TRawEvent v;
1.2721 +
1.2722 + switch (message)
1.2723 + {
1.2724 + case WM_GETMINMAXINFO:
1.2725 + {
1.2726 + DScreenProperties* screenProps = ScreenPropsFromHWND(hWnd, TheWin);
1.2727 + if(screenProps == NULL)
1.2728 + {
1.2729 + return DefWindowProcA(hWnd, message, wParam, lParam);
1.2730 + }
1.2731 +
1.2732 + MINMAXINFO* minMaxInfo = reinterpret_cast<MINMAXINFO*>(lParam);
1.2733 + minMaxInfo->ptMaxTrackSize.x = screenProps->iViewport.GetMaxWindowWidth();
1.2734 + minMaxInfo->ptMaxTrackSize.y = screenProps->iViewport.GetMaxWindowHeight();
1.2735 +
1.2736 + minMaxInfo->ptMaxSize.x = minMaxInfo->ptMaxTrackSize.x;
1.2737 + minMaxInfo->ptMaxSize.y = minMaxInfo->ptMaxTrackSize.y;
1.2738 + DefWindowProcA(hWnd, message, wParam, lParam);
1.2739 +
1.2740 + break;
1.2741 + }
1.2742 +
1.2743 +
1.2744 +
1.2745 + case WM_SIZE:
1.2746 + {
1.2747 + DScreenProperties* screenProps = ScreenPropsFromHWND(hWnd, TheWin);
1.2748 + if(screenProps == NULL)
1.2749 + {
1.2750 + return DefWindowProcA(hWnd, message, wParam, lParam);
1.2751 + }
1.2752 + TViewport& viewport = screenProps->iViewport;
1.2753 + //update size of viewport
1.2754 + viewport.SetViewportWidth(LOWORD(lParam));
1.2755 + viewport.SetViewportHeight(HIWORD(lParam));
1.2756 +
1.2757 +
1.2758 + //If resize goes beyond boundary of emulator then scroll to compensate
1.2759 + TInt ox = viewport.GetViewportOffsetX();
1.2760 + TInt xs = ox + LOWORD(lParam) - viewport.GetMaxWidth();
1.2761 + if (xs>0)
1.2762 + {
1.2763 + viewport.ScrollToX(ox-xs, hWnd);
1.2764 + }
1.2765 +
1.2766 + TInt oy = viewport.GetViewportOffsetY();
1.2767 + TInt ys = oy + HIWORD(lParam) - viewport.GetMaxHeight();
1.2768 + if (ys>0)
1.2769 + {
1.2770 + viewport.ScrollToY(oy-ys, hWnd);
1.2771 + }
1.2772 +
1.2773 + //Adjust ranges of scroll bars
1.2774 + viewport.UpdateScrollBarH(hWnd);
1.2775 + viewport.UpdateScrollBarV(hWnd);
1.2776 +
1.2777 +
1.2778 +
1.2779 + break;
1.2780 + }
1.2781 + case WM_HSCROLL:
1.2782 + {
1.2783 + DScreenProperties* screenProps = ScreenPropsFromHWND(hWnd, TheWin);
1.2784 + if(screenProps == NULL)
1.2785 + {
1.2786 + return DefWindowProcA(hWnd, message, wParam, lParam);
1.2787 + }
1.2788 + TViewport& viewport = screenProps->iViewport;
1.2789 +
1.2790 + switch (LOWORD(wParam))
1.2791 + {
1.2792 + case SB_THUMBTRACK:
1.2793 + {
1.2794 + viewport.ScrollToX(HIWORD(wParam),hWnd);
1.2795 + break;
1.2796 + }
1.2797 + case SB_PAGELEFT:
1.2798 + {
1.2799 + viewport.ScrollToX(viewport.GetViewportOffsetX() - viewport.GetViewportWidth(), hWnd );
1.2800 + break;
1.2801 + }
1.2802 + case SB_PAGERIGHT:
1.2803 + {
1.2804 + viewport.ScrollToX(viewport.GetViewportOffsetX() + viewport.GetViewportWidth() , hWnd);
1.2805 + break;
1.2806 + }
1.2807 + case SB_LINEUP:
1.2808 + {
1.2809 + viewport.ScrollToX(viewport.GetViewportOffsetX() - 1, hWnd);
1.2810 + break;
1.2811 + }
1.2812 + case SB_LINEDOWN:
1.2813 + {
1.2814 + viewport.ScrollToX(viewport.GetViewportOffsetX() + 1, hWnd);
1.2815 + break;
1.2816 + }
1.2817 +
1.2818 + }
1.2819 +
1.2820 +
1.2821 + break;
1.2822 + }
1.2823 +
1.2824 + case WM_VSCROLL:
1.2825 + {
1.2826 + DScreenProperties* screenProps = ScreenPropsFromHWND(hWnd, TheWin);
1.2827 + if(screenProps == NULL)
1.2828 + {
1.2829 + return DefWindowProcA(hWnd, message, wParam, lParam);
1.2830 + }
1.2831 + TViewport& viewport = screenProps->iViewport;
1.2832 +
1.2833 +
1.2834 + switch (LOWORD(wParam))
1.2835 + {
1.2836 + case SB_THUMBTRACK:
1.2837 + {
1.2838 + viewport.ScrollToY(HIWORD(wParam), hWnd);
1.2839 + break;
1.2840 + }
1.2841 + case SB_PAGELEFT:
1.2842 + {
1.2843 + viewport.ScrollToY(viewport.GetViewportOffsetY() - viewport.GetViewportHeight() , hWnd);
1.2844 + break;
1.2845 + }
1.2846 + case SB_PAGERIGHT:
1.2847 + {
1.2848 + viewport.ScrollToY(viewport.GetViewportOffsetY() + viewport.GetViewportHeight(), hWnd );
1.2849 + break;
1.2850 + }
1.2851 + case SB_LINEUP:
1.2852 + {
1.2853 + viewport.ScrollToY(viewport.GetViewportOffsetY() - 1, hWnd);
1.2854 + break;
1.2855 + }
1.2856 + case SB_LINEDOWN:
1.2857 + {
1.2858 + viewport.ScrollToY(viewport.GetViewportOffsetY() + 1, hWnd);
1.2859 + break;
1.2860 + }
1.2861 +
1.2862 + }
1.2863 +
1.2864 + break;
1.2865 +
1.2866 + }
1.2867 +
1.2868 +
1.2869 + case WM_FLIP_MESSAGE:
1.2870 + {
1.2871 + DScreenProperties* screenProps = ScreenPropsFromHWND(hWnd, TheWin);
1.2872 + if(screenProps == NULL)
1.2873 + {
1.2874 + return DefWindowProcA(hWnd, message, wParam, lParam);
1.2875 +
1.2876 + }
1.2877 +
1.2878 + TViewport& viewport = screenProps->iViewport;
1.2879 + RECT windowRect={0,0,0,0};
1.2880 + GetClientRect(hWnd, &windowRect);
1.2881 +
1.2882 + TInt screenNumber=ScreenFromHWND(hWnd,TheWin);
1.2883 + if(TUint(screenNumber) >= TUint(systemIni->iScreens.Count()))
1.2884 + break;
1.2885 + PBITMAPV4HEADER info = &masterIni->iBufferSet[screenNumber].iInfo;
1.2886 + CurrentFlipState[screenNumber]=(TEmulatorFlip)wParam;
1.2887 + TBufferSet* bufferSet = &masterIni->iBufferSet[screenNumber];
1.2888 + switch (CurrentFlipState[screenNumber])
1.2889 + {
1.2890 + case EEmulatorFlipRestore:
1.2891 + case EEmulatorFlipInvert:
1.2892 + windowRect.right=systemIni->iScreens[screenNumber]->iXYInputWidth;
1.2893 + windowRect.bottom=systemIni->iScreens[screenNumber]->iXYInputHeight;
1.2894 + info->bV4Width = bufferSet->iBufferFormat.iSize.iWidth;
1.2895 + info->bV4Height = -bufferSet->iBufferFormat.iSize.iHeight;
1.2896 + break;
1.2897 + case EEmulatorFlipLeft:
1.2898 + case EEmulatorFlipRight:
1.2899 + windowRect.right=systemIni->iScreens[screenNumber]->iXYInputHeight;
1.2900 + windowRect.bottom=systemIni->iScreens[screenNumber]->iXYInputWidth;
1.2901 + info->bV4Width = bufferSet->iBufferFormat.iSize.iHeight;
1.2902 + info->bV4Height = -bufferSet->iBufferFormat.iSize.iWidth;
1.2903 + break;
1.2904 + }
1.2905 + AdjustWindowRect(&windowRect,KWinStyle,FALSE);
1.2906 +
1.2907 +
1.2908 + viewport.ScrollToX(0, hWnd);
1.2909 + viewport.ScrollToY(0, hWnd);
1.2910 +
1.2911 +
1.2912 + screenProps->iScreenRotation = (TEmulatorFlip)wParam;
1.2913 +
1.2914 +
1.2915 + RECT currentWindowRect;
1.2916 + GetWindowRect(hWnd,¤tWindowRect);
1.2917 + InvalidateRect(hWnd,NULL,FALSE);
1.2918 + MoveWindow(
1.2919 + TheWin[screenNumber],
1.2920 + max(currentWindowRect.left,0), // so the window doesn't disappear off the screen
1.2921 + max(currentWindowRect.top,0),
1.2922 + windowRect.right-windowRect.left,
1.2923 + windowRect.bottom-windowRect.top,
1.2924 + TRUE
1.2925 + );
1.2926 + // move the child window
1.2927 + screenProps->iViewport.UpdateChildPos(hWnd);
1.2928 +
1.2929 + viewport.UpdateScrollBarH(hWnd);
1.2930 + viewport.UpdateScrollBarV(hWnd);
1.2931 +
1.2932 + InvalidateRect(hWnd,NULL,TRUE);
1.2933 + UpdateWindow(hWnd);
1.2934 +
1.2935 + break;
1.2936 + }
1.2937 + case WM_SYSKEYDOWN:
1.2938 + case WM_KEYDOWN:
1.2939 + if (!(HIWORD(lParam)&KF_REPEAT))
1.2940 + {
1.2941 +
1.2942 +
1.2943 + TUint scanCode=DWinsKeyboard::ScanCodeToStandardKey(HIWORD(lParam));
1.2944 + TUint newScanCode = systemIni->iKeyboard.ScanCodeToRemappedKey(HIWORD(lParam));
1.2945 + MSG msg={hWnd,message,wParam,lParam,GetMessageTime(),GetMessagePos()};
1.2946 + TranslateMessage(&msg);
1.2947 + TUint charCode=0;
1.2948 + // look in the message queue to get character associated with keypress
1.2949 + // so long as the control, shift and alt keys aren't depressed
1.2950 + if (!(HIBYTE(GetKeyState(VK_CONTROL)) && HIBYTE(GetKeyState(VK_MENU)) && HIBYTE(GetKeyState(VK_SHIFT))))
1.2951 + if (PeekMessageA(&msg,hWnd,WM_CHAR,WM_CHAR,PM_NOREMOVE) &&
1.2952 + scanCode == newScanCode) //no remapping
1.2953 + charCode=msg.wParam;
1.2954 + // Pass the character as the HIWORD of the Epoc scan code
1.2955 +
1.2956 + scanCode = newScanCode;
1.2957 + v.Set(TRawEvent::EKeyDown,(charCode<<16)|scanCode);
1.2958 + if (!ProcessedByEmulatorKey(scanCode,hWnd,message,wParam,lParam))
1.2959 + TheEventQ.Add(v);
1.2960 +
1.2961 + }
1.2962 + break;
1.2963 + case WM_TIMER:
1.2964 + break;
1.2965 + case WM_EMUL_POWER_ON:
1.2966 + {
1.2967 + TInt screenNumber=ScreenFromHWND(hWnd,TheWin);
1.2968 + if(TUint(screenNumber) >= TUint(systemIni->iScreens.Count()))
1.2969 + break;
1.2970 +// HWND win = systemIni->iSecureDisplay ? TheSecureChildWin : TheChildWin;
1.2971 + HWND win = TheChildWin[screenNumber];
1.2972 + if (wParam==TRUE)
1.2973 + {
1.2974 + ShowWindow(win, SW_HIDE);
1.2975 + ShowWindow(win, SW_SHOWNORMAL);
1.2976 + if (SavedFlipMessage)
1.2977 + {
1.2978 + addKeyEvent(TRawEvent::EKeyDown, SavedFlipMessage);
1.2979 + addKeyEvent(TRawEvent::EKeyUp, SavedFlipMessage);
1.2980 + SavedFlipMessage = 0;
1.2981 + }
1.2982 + }
1.2983 + else
1.2984 + {
1.2985 + ShowWindow(win, SW_SHOWNORMAL);
1.2986 + ShowWindow(win, SW_HIDE);
1.2987 + }
1.2988 + }
1.2989 + break;
1.2990 + case WM_SYSKEYUP:
1.2991 + case WM_KEYUP:
1.2992 + {
1.2993 + //get the key code, this will pick up if it has been remapped or not.
1.2994 + TUint scanCode = systemIni->iKeyboard.ScanCodeToRemappedKey(HIWORD(lParam));
1.2995 + /*
1.2996 + * We could do this to support generation of special characters using Alt+KeyPadNum
1.2997 + * combinations, but we would need to find a way to suppress the generation of
1.2998 + * home/end scancodes etc., so leave it for the moment.
1.2999 + MSG msg={hWnd,message,wParam,lParam,GetMessageTime(),GetMessagePos()};
1.3000 + TranslateMessage(&msg);
1.3001 + TUint charCode=0;
1.3002 + // look in the message queue to get character associated with keypress
1.3003 + if (PeekMessageU()(&msg,hWnd,WM_CHAR,WM_CHAR,PM_NOREMOVE))
1.3004 + charCode=msg.wParam;
1.3005 + // Pass the character as the HIWORD of the Epoc scan code
1.3006 + v.Set(TRawEvent::EKeyUp,(charCode<<16)|scanCode);
1.3007 + */
1.3008 + v.Set(TRawEvent::EKeyUp,scanCode);
1.3009 + TheEventQ.Add(v);
1.3010 + break;
1.3011 + }
1.3012 + case WM_MOUSEMOVE:
1.3013 + case WM_LBUTTONDOWN:
1.3014 + case WM_LBUTTONUP:
1.3015 + case WM_RBUTTONDOWN:
1.3016 + case WM_RBUTTONUP:
1.3017 + case WM_MBUTTONDOWN:
1.3018 + case WM_MBUTTONUP:
1.3019 + {
1.3020 + //only handle mouse clicks on screen 0
1.3021 + TInt xpos=((TInt16)(lParam&0xffff));
1.3022 + TInt ypos = (TInt16)((lParam>>16)&0xFFFF);
1.3023 + if (DMultiTouch::iMultiTouchTempEnabled)
1.3024 + {
1.3025 + MultiChildWndPointer(message,xpos,ypos,0,0);
1.3026 + DMultiTouch::iMultiTouchTempEnabled = FALSE;
1.3027 + }
1.3028 + else
1.3029 + {
1.3030 + TInt screenNumber=ScreenFromHWND(hWnd,TheWin);
1.3031 + if(screenNumber!=0)
1.3032 + break;
1.3033 + FrameWndPointer(message,xpos,ypos,screenNumber);
1.3034 + }
1.3035 + break;
1.3036 + }
1.3037 + case WM_PAINT:
1.3038 + {
1.3039 + DScreenProperties* screenProps = ScreenPropsFromHWND(hWnd, TheWin);
1.3040 + if(screenProps == NULL)
1.3041 + {
1.3042 + return DefWindowProcA(hWnd, message, wParam, lParam);
1.3043 + }
1.3044 + TViewport& viewport = screenProps->iViewport;
1.3045 + TInt screenNumber=ScreenFromHWND(hWnd,TheWin);
1.3046 +
1.3047 + PAINTSTRUCT p;
1.3048 +
1.3049 + BeginPaint(hWnd,&p);
1.3050 + HDC hdcBits;
1.3051 + BITMAP bm;
1.3052 + hdcBits=CreateCompatibleDC(p.hdc);
1.3053 + GetObjectA(TheScreenBitmap[screenNumber],sizeof(BITMAP),&bm);
1.3054 + SelectObject(hdcBits,TheScreenBitmap[screenNumber]);
1.3055 +
1.3056 + RECT windowRect;
1.3057 + GetClientRect(TheWin[screenNumber],&windowRect);
1.3058 +
1.3059 + viewport.SetViewportHeight(windowRect.bottom);
1.3060 + viewport.SetViewportWidth(windowRect.right);
1.3061 +
1.3062 +
1.3063 + switch (CurrentFlipState[screenNumber])
1.3064 + {
1.3065 + case EEmulatorFlipRestore:
1.3066 + {
1.3067 + BitBlt(p.hdc,0,0,windowRect.right,windowRect.bottom,hdcBits,
1.3068 + viewport.GetViewportOffsetX(),viewport.GetViewportOffsetY(),SRCCOPY);
1.3069 + break;
1.3070 + }
1.3071 + case EEmulatorFlipInvert:
1.3072 + {
1.3073 + TInt sourceX = screenProps->iXYInputWidth - viewport.GetViewportWidth() - viewport.GetViewportOffsetX();
1.3074 + if(sourceX<0)
1.3075 + sourceX=0;
1.3076 + TInt sourceY = screenProps->iXYInputHeight - viewport.GetViewportHeight() - viewport.GetViewportOffsetY();
1.3077 + if(sourceY<0)
1.3078 + sourceY=0;
1.3079 + TInt sourceWidth = viewport.GetMaxWidth()-sourceX - viewport.GetViewportOffsetX();
1.3080 + TInt sourceHeight = viewport.GetMaxHeight()-sourceY - viewport.GetViewportOffsetY();
1.3081 +
1.3082 + //when inverted it is necessary to translate the image by 1 pixel up and to the left,
1.3083 + //to avoid a glitch when scrolling using ScrollWindowEx()
1.3084 + POINT arrayPoints[3]={
1.3085 + {sourceWidth-1,sourceHeight-1},
1.3086 + {-1,sourceHeight-1},
1.3087 + {sourceWidth-1,-1}
1.3088 + };
1.3089 + PlgBlt(p.hdc,arrayPoints,hdcBits,sourceX,sourceY,sourceWidth,sourceHeight,NULL,NULL,NULL);
1.3090 + break;
1.3091 + }
1.3092 + case EEmulatorFlipLeft:
1.3093 + {
1.3094 + TInt offsetX = screenProps->iXYInputWidth- viewport.GetViewportHeight() - viewport.GetViewportOffsetY();
1.3095 + TInt offsetY = viewport.GetViewportOffsetX();
1.3096 +
1.3097 + POINT arrayPoints[3]={{0,windowRect.bottom},{0,0},{windowRect.right,windowRect.bottom}};
1.3098 + PlgBlt(p.hdc,arrayPoints,hdcBits,offsetX,offsetY,viewport.GetViewportHeight(),viewport.GetViewportWidth(),NULL,NULL,NULL);
1.3099 + break;
1.3100 + }
1.3101 + case EEmulatorFlipRight:
1.3102 + {
1.3103 + TInt offsetX = viewport.GetViewportOffsetY();
1.3104 + TInt offsetY = screenProps->iXYInputHeight - viewport.GetViewportWidth() - viewport.GetViewportOffsetX();
1.3105 +
1.3106 + POINT arrayPoints[3]={{windowRect.right,0},{windowRect.right,windowRect.bottom},{0,0}};
1.3107 + PlgBlt(p.hdc,arrayPoints,hdcBits,offsetX,offsetY,viewport.GetViewportHeight(),viewport.GetViewportWidth(),NULL,NULL,NULL);
1.3108 + break;
1.3109 + }
1.3110 + }
1.3111 +
1.3112 +
1.3113 + DeleteDC(hdcBits);
1.3114 + if (WinsGuiPowerHandler->iStandby)
1.3115 + {
1.3116 + TInt x,y;
1.3117 + CalcTextPos(screenNumber, x, y);
1.3118 + TextOutA(p.hdc, x, y, "Standby", 7);
1.3119 + }
1.3120 + else if (systemIni->iScreens[screenNumber]->iScreenOff)
1.3121 + {
1.3122 + TInt x,y;
1.3123 + CalcTextPos(screenNumber, x, y);
1.3124 + TextOutA(p.hdc, x, y, "Screen Off", 10);
1.3125 + }
1.3126 + EndPaint(hWnd,&p);
1.3127 + break;
1.3128 + }
1.3129 + case WM_ACTIVATE:
1.3130 + //Added so that change in modifier keys can be detected without sending
1.3131 + //EActive/EInActive to wserv as it results in switching the timers
1.3132 + if((wParam & 0xffff)!= WA_INACTIVE)
1.3133 + UpdateModifiers();
1.3134 + break;
1.3135 + case WM_CHAR:
1.3136 + case WM_SYSCHAR:
1.3137 + case WM_DEADCHAR:
1.3138 + case WM_SYSDEADCHAR:
1.3139 + break;
1.3140 + case WM_CLOSE: //pass on message to control window, it will then destroy all e,ulator windows
1.3141 + SendMessage(TheControlWin,WM_CLOSE, NULL, NULL);
1.3142 + break;
1.3143 + case WM_DESTROY:
1.3144 + {
1.3145 + DScreenProperties* screenProps = ScreenPropsFromHWND(hWnd, TheWin);
1.3146 + if(screenProps == NULL)
1.3147 + {
1.3148 + return DefWindowProcA(hWnd, message, wParam, lParam);
1.3149 + }
1.3150 +
1.3151 + // save window's position information
1.3152 + screenProps->iWinPlace.length = sizeof(WINDOWPLACEMENT);
1.3153 + GetWindowPlacement(hWnd, &screenProps->iWinPlace);
1.3154 +
1.3155 + break;
1.3156 + }
1.3157 + case WM_INPUT:
1.3158 + {
1.3159 + if (systemIni->MultiTouchEnabled() && DMultiTouch::iMultiTouchSupported && systemIni->GCEEnabled())
1.3160 + {
1.3161 + TInt screenNumber=ScreenFromHWND(hWnd,TheWin);
1.3162 + if(screenNumber==0)
1.3163 + {
1.3164 + TheMultiTouch->OnWmInput(hWnd, message, wParam, lParam,TheChildWin[screenNumber]);
1.3165 + }
1.3166 + }
1.3167 + else
1.3168 + {
1.3169 + Fault(EGuiInvalidMultiTouch);
1.3170 + }
1.3171 + break;
1.3172 + }
1.3173 + default:
1.3174 + return(DefWindowProcA(hWnd,message,wParam,lParam));
1.3175 + }
1.3176 + return(FALSE);
1.3177 +
1.3178 + }
1.3179 +
1.3180 +void SetStatusBarFont(HWND& aStatusBar)
1.3181 + {
1.3182 + int statwidths[] = {100,200,300,400,500,600,700,800};
1.3183 + SendMessage(aStatusBar, SB_SETPARTS, sizeof(statwidths)/sizeof(int), (LPARAM)statwidths);
1.3184 + HFONT hOrigFont = (HFONT) SendMessage(aStatusBar, WM_GETFONT, 0, 0);
1.3185 + SetProp(aStatusBar, TEXT("PROP_ORIGINAL_FONT"), (HANDLE) hOrigFont);
1.3186 + LOGFONT lf;
1.3187 + GetObject(hOrigFont, sizeof(lf), &lf);
1.3188 + lf.lfHeight = (long)(lf.lfHeight / 1.5);
1.3189 + lf.lfWeight = FW_NORMAL;
1.3190 + HFONT hFont = CreateFontIndirect(&lf);
1.3191 + SetProp(aStatusBar, TEXT("PROP_ITALIC_FONT"), (HANDLE) hFont);
1.3192 + hFont = (HFONT) GetProp(hwndStatus, TEXT("PROP_ITALIC_FONT"));
1.3193 + SendMessage(aStatusBar, WM_SETFONT, (WPARAM) hFont, FALSE);
1.3194 + }
1.3195 +
1.3196 +DWORD WINAPI KernelWindowThread(LPVOID aArg)
1.3197 +//
1.3198 +// The kernel window thread.
1.3199 +//
1.3200 + {
1.3201 + HMODULE hmodule = GetModuleHandleA("winsgui.dll");
1.3202 + __ASSERT_ALWAYS(hmodule!=NULL,Fault(EGuiGetModuleHandle));
1.3203 +
1.3204 + WNDCLASSA w;
1.3205 + memclr(&w, sizeof(WNDCLASSA));
1.3206 + w.style=CS_OWNDC|CS_VREDRAW|CS_HREDRAW;
1.3207 + w.lpfnWndProc=(WNDPROC)ctrlwinProc;
1.3208 + w.hInstance=(HINSTANCE)aArg;
1.3209 + w.hIcon=LoadIconA((HINSTANCE)hmodule,MAKEINTRESOURCEA(EPOC_ICON));
1.3210 + w.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
1.3211 + w.lpszClassName="E32KernelControlWindow";
1.3212 +
1.3213 + ATOM a=RegisterClassA(&w);
1.3214 + __ASSERT_ALWAYS(a!=0,Fault(EGuiRegisterWindow));
1.3215 +
1.3216 + RECT ctlrwindowRect={0,0,270,0};
1.3217 + AdjustWindowRect(&ctlrwindowRect,KControlWinStyle,FALSE);
1.3218 + TInt ctrlwindowWidth=ctlrwindowRect.right-ctlrwindowRect.left;
1.3219 + TInt ctrlwindowHeight=ctlrwindowRect.bottom-ctlrwindowRect.top;
1.3220 +
1.3221 + TheControlWin=CreateWindowA(
1.3222 + "E32KernelControlWindow",
1.3223 + systemIni->iWindowTitle,
1.3224 + KInvisibleControlWinStyle,
1.3225 + KWinPosX,
1.3226 + KWinPosY,
1.3227 + ctrlwindowWidth,
1.3228 + ctrlwindowHeight,
1.3229 + (HWND)NULL,
1.3230 + NULL,
1.3231 + (HINSTANCE)aArg,
1.3232 + (LPSTR)NULL
1.3233 + );
1.3234 + __ASSERT_ALWAYS(TheControlWin!=NULL,Fault(EGuiKernelWindowCreate));
1.3235 +
1.3236 + memclr(&w, sizeof(WNDCLASSA));
1.3237 + w.style=CS_OWNDC;
1.3238 + w.lpfnWndProc=(WNDPROC)winProc;
1.3239 + w.hInstance=(HINSTANCE)aArg;
1.3240 + w.hIcon=LoadIconA((HINSTANCE)hmodule,MAKEINTRESOURCEA(EPOC_ICON));
1.3241 + w.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
1.3242 + w.lpszClassName="E32KernelWindow";
1.3243 +
1.3244 + a=RegisterClassA(&w);
1.3245 + __ASSERT_ALWAYS(a!=0,Fault(EGuiRegisterWindow));
1.3246 +
1.3247 + memclr(&w, sizeof(WNDCLASSA));
1.3248 + w.style=CS_OWNDC;
1.3249 + w.lpfnWndProc=(WNDPROC)childWinProc;
1.3250 + w.hInstance=(HINSTANCE)aArg;
1.3251 + w.hCursor=LoadCursorA(NULL,MAKEINTRESOURCEA(32512)); //ICD_ARROW
1.3252 + w.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
1.3253 + w.lpszMenuName=NULL;
1.3254 + w.lpszClassName="E32KernelChildWindow";
1.3255 + a=RegisterClassA(&w);
1.3256 + __ASSERT_ALWAYS(a!=0,Fault(EGuiRegisterChildWindow));
1.3257 +
1.3258 + if (masterIni && masterIni->iSystemInis.Count() > 1)
1.3259 + {
1.3260 + //add Configuration Items to the system menu if there's > 1 config
1.3261 + HMENU hMenu = GetSystemMenu(TheControlWin, FALSE);
1.3262 + InsertMenu(hMenu,5, MF_BYPOSITION|MF_SEPARATOR,0,NULL);
1.3263 + InsertMenuA(hMenu,6, MF_BYPOSITION|MF_STRING, 1, "Next Config...");
1.3264 + }
1.3265 +
1.3266 + ShowWindow(TheControlWin,SW_SHOWDEFAULT);
1.3267 + UpdateWindow(TheControlWin);
1.3268 +
1.3269 + //Create frame windows and child windows
1.3270 + for(TInt screen=0;screen<systemIni->iScreens.Count();screen++)
1.3271 + {
1.3272 +
1.3273 + RECT windowRect={0,0,systemIni->iScreens[screen]->iXYInputWidth,systemIni->iScreens[screen]->iXYInputHeight};
1.3274 + AdjustWindowRect(&windowRect,KWinStyle,FALSE);
1.3275 + TInt windowWidth=windowRect.right-windowRect.left;
1.3276 + TInt windowHeight=windowRect.bottom-windowRect.top;
1.3277 +
1.3278 + CHAR title[20];
1.3279 + wsprintfA(title, "Screen %d", screen);
1.3280 +
1.3281 + TheWin[screen]=CreateWindowA(
1.3282 + "E32KernelWindow",
1.3283 + title,
1.3284 + KInvisibleWinStyle,
1.3285 + KWinPosX,
1.3286 + KWinPosY,
1.3287 + windowWidth,
1.3288 + windowHeight,
1.3289 + (HWND)NULL,
1.3290 + NULL,
1.3291 + (HINSTANCE)aArg,
1.3292 + (LPSTR)NULL
1.3293 + );
1.3294 + __ASSERT_ALWAYS(TheWin[screen]!=NULL,Fault(EGuiKernelWindowCreate));
1.3295 +
1.3296 + LoadFasciaBitmap(screen);
1.3297 +
1.3298 + TheChildWin[screen]=CreateWindowA(
1.3299 + "E32KernelChildWindow",
1.3300 + "",
1.3301 + WS_CHILDWINDOW|WS_VISIBLE|WS_CLIPCHILDREN|WS_CLIPSIBLINGS,
1.3302 + systemIni->iScreens[screen]->iScreenOffsetX,
1.3303 + systemIni->iScreens[screen]->iScreenOffsetY,
1.3304 + systemIni->iScreens[screen]->iScreenWidth,
1.3305 + systemIni->iScreens[screen]->iScreenHeight,
1.3306 + TheWin[screen],
1.3307 + NULL,
1.3308 + (HINSTANCE)aArg,
1.3309 + (LPSTR)NULL
1.3310 + );
1.3311 + __ASSERT_ALWAYS(TheChildWin[screen]!=NULL,Fault(EGuiKernelChildWindowCreate));
1.3312 +
1.3313 + // Create status bars
1.3314 + if (systemIni->MultiTouchEnabled() && systemIni->GCEEnabled())
1.3315 + {
1.3316 + HMODULE hmodComCtl = LoadLibrary(TEXT("comctl32.dll"));
1.3317 + typedef int (WINAPI* FNINITCC)();
1.3318 + FNINITCC pfnInitCommonControls = GetProcAddress(hmodComCtl, "InitCommonControls");
1.3319 + pfnInitCommonControls();
1.3320 + hwndStatus = CreateWindowExA(0, STATUSCLASSNAMEA, NULL,
1.3321 + WS_CHILD | WS_VISIBLE | CCS_BOTTOM ,
1.3322 + 0,0,0,0,
1.3323 + TheWin[0], NULL, GetModuleHandle(NULL), NULL);
1.3324 + SetStatusBarFont(hwndStatus);
1.3325 + SetWindowPos(hwndStatus,NULL, 0,0,0,0,SWP_HIDEWINDOW);
1.3326 + }
1.3327 + }
1.3328 +
1.3329 + //Restore window data from ini file if it exists.
1.3330 + HANDLE hSysIni = CreateFileA(systemIni->iSysIniFileName, GENERIC_READ, 0, 0, OPEN_EXISTING, 0, 0);
1.3331 + TBool success=(hSysIni != INVALID_HANDLE_VALUE) ? ETrue : EFalse;
1.3332 +
1.3333 + DWORD numRead;
1.3334 + TInt fileVersion=0;
1.3335 + if(success)
1.3336 + {
1.3337 + ReadFile(hSysIni, &fileVersion, sizeof(TInt), &numRead, 0);
1.3338 + }
1.3339 +
1.3340 + //Check we are using a dat file created by this version of the program.
1.3341 + if(success && (fileVersion==KDatFileVersion) )
1.3342 + {
1.3343 +
1.3344 + TInt savedConfiguration=0; //set this to default configuration
1.3345 +
1.3346 + if(ReadFile(hSysIni, &savedConfiguration, sizeof(TInt), &numRead, 0) && (numRead>0) )
1.3347 + {
1.3348 + //Don't restore the saved configuration, see INC114502.
1.3349 + //This could be reenabled in future as an optional operation
1.3350 + //dependent on an entry in the epoc.ini file.
1.3351 +
1.3352 + //SwitchConfiguration(savedConfiguration);
1.3353 + }
1.3354 +
1.3355 + //restore each window to saved state
1.3356 + for(TInt screen=0;screen<systemIni->iScreens.Count();screen++)
1.3357 + {
1.3358 +
1.3359 + // If the .ini file was opened, get the saved settings for the windows position the last time
1.3360 + // this emulator was run, if any, and move the window accordingly.
1.3361 +
1.3362 + TWindowState savedState;
1.3363 +
1.3364 + TBool stateLoaded = ReadFile(hSysIni, &savedState, sizeof(TWindowState), &numRead, 0) && (numRead>0);
1.3365 +
1.3366 + if (stateLoaded)
1.3367 + {
1.3368 + //only allow window to be restored to
1.3369 + //maximized or normal mode,
1.3370 + //this prevents it being restored in minimized mode
1.3371 + //or others.
1.3372 + if(savedState.iWinPlace.showCmd != SW_MAXIMIZE)
1.3373 + savedState.iWinPlace.showCmd= SW_NORMAL;
1.3374 +
1.3375 + //if starting in same configuration and/or rotation as last time emulator was run
1.3376 + //it makes sense to restore scroll offset, window position,
1.3377 + //and dimensions, if not, only restore position and window (ie. maximized/normal) state.
1.3378 + if(savedConfiguration == CurrentConfiguration &&
1.3379 + savedState.iFlipstate == CurrentFlipState[screen])
1.3380 + {
1.3381 + //Restore window placement
1.3382 + SetWindowPlacement(TheWin[screen], &savedState.iWinPlace);
1.3383 +
1.3384 + TViewport& viewport = systemIni->iScreens[screen]->iViewport;
1.3385 +
1.3386 + viewport.ScrollToX(savedState.iXoffset, TheWin[screen]);
1.3387 + viewport.ScrollToY(savedState.iYoffset, TheWin[screen]);
1.3388 + }
1.3389 + else
1.3390 + {
1.3391 +
1.3392 + RECT oldRect;
1.3393 + GetWindowRect(TheWin[screen], &oldRect);
1.3394 + //save default window dimensions
1.3395 + TInt width=oldRect.right-oldRect.left;
1.3396 + TInt height=oldRect.bottom - oldRect.top;
1.3397 +
1.3398 + //restore position and window state from file
1.3399 + SetWindowPlacement(TheWin[screen], &savedState.iWinPlace);
1.3400 +
1.3401 + RECT currentRect;
1.3402 + GetWindowRect(TheWin[screen], ¤tRect);
1.3403 + //keep default size.
1.3404 + MoveWindow(TheWin[screen],currentRect.left, currentRect.top, width, height, TRUE);
1.3405 +
1.3406 + }
1.3407 +
1.3408 +
1.3409 + // Check that enough of the recorded window position is visible on the screen
1.3410 +
1.3411 + TBool enoughVisible = false;
1.3412 +
1.3413 + // vague values for ensuring we have enough of the window title bar to grab
1.3414 + // if the window is partly off screen
1.3415 + const TInt KTitleBarGrabX=80;
1.3416 + const TInt KTitleBarGrabY=50;
1.3417 +
1.3418 + //inspect dimensions of the window to be restored.
1.3419 + RECT savedRect;
1.3420 + GetWindowRect(TheWin[screen], &savedRect);
1.3421 +
1.3422 + SystemMonitors monitors;
1.3423 +
1.3424 + if (monitors.Count() == 1) /* Original algorithm */
1.3425 + {
1.3426 + RECT rcIntersect, rcScreen;
1.3427 +
1.3428 + SetRect(&rcScreen, KTitleBarGrabX, savedRect.bottom-savedRect.top,
1.3429 + GetSystemMetrics(SM_CXSCREEN)-KTitleBarGrabX, GetSystemMetrics(SM_CYSCREEN)-KTitleBarGrabY);
1.3430 +
1.3431 + enoughVisible = IntersectRect(&rcIntersect, &savedRect, &rcScreen);
1.3432 + }
1.3433 + else /* > 1 monitor; do it differently */
1.3434 + {
1.3435 + RECT cornerBox1, cornerBox2;
1.3436 +
1.3437 + // The top-left corner box
1.3438 + SetRect(&cornerBox1, savedRect.left, savedRect.top,
1.3439 + savedRect.left + KTitleBarGrabX, savedRect.top + KTitleBarGrabY);
1.3440 +
1.3441 + // The top-right corner box
1.3442 + SetRect(&cornerBox2, savedRect.right - KTitleBarGrabX, savedRect.top,
1.3443 + savedRect.right, savedRect.top + KTitleBarGrabY);
1.3444 +
1.3445 + // Require one of these rectangles to be all on one monitor
1.3446 + enoughVisible = monitors.RectAllOnOne(cornerBox1) || monitors.RectAllOnOne(cornerBox2);
1.3447 + }
1.3448 +
1.3449 + if (!enoughVisible)
1.3450 + {
1.3451 + SetWindowPos(TheWin[screen], HWND_TOP, 0,0,0,0, SWP_NOSIZE);
1.3452 + }
1.3453 +
1.3454 + }
1.3455 + else //if there was no stored info for this screen
1.3456 + {
1.3457 + ShowWindow(TheWin[screen],SW_MAXIMIZE);
1.3458 + }
1.3459 + }
1.3460 + }
1.3461 + else
1.3462 + {
1.3463 + //use default configuration and make windows visible
1.3464 + SwitchConfiguration(CurrentConfiguration);
1.3465 + for(TInt screen=0;screen<systemIni->iScreens.Count();screen++)
1.3466 + {
1.3467 + ShowWindow(TheWin[screen],SW_MAXIMIZE);
1.3468 + UpdateWindow(TheWin[screen]);
1.3469 + }
1.3470 + }
1.3471 +
1.3472 + //close file if it was opened
1.3473 + if(success)
1.3474 + {
1.3475 + CloseHandle(hSysIni);
1.3476 + }
1.3477 +
1.3478 +
1.3479 + if (systemIni->iInitialFlipMsg != 0)
1.3480 + {
1.3481 + addKeyEvent(TRawEvent::EKeyDown,systemIni->iInitialFlipMsg);
1.3482 + addKeyEvent(TRawEvent::EKeyUp,systemIni->iInitialFlipMsg);
1.3483 + }
1.3484 +
1.3485 + SetFocus(TheWin[0]);
1.3486 +
1.3487 + MSG m;
1.3488 + while (GetMessageA(&m,NULL,0,0))
1.3489 + {
1.3490 + DispatchMessageA(&m);
1.3491 + }
1.3492 +
1.3493 + ExitProcess(m.wParam);
1.3494 + return 0;
1.3495 + }
1.3496 +
1.3497 +SystemMonitors::SystemMonitors(void)
1.3498 + {
1.3499 + TInt n;
1.3500 +
1.3501 + iCount = 1;
1.3502 + iHaveMultiMonFunctions = false;
1.3503 +
1.3504 + if ((n = GetSystemMetrics(SM_CMONITORS)) <= 1)
1.3505 + {
1.3506 + return;
1.3507 + }
1.3508 +
1.3509 + HMODULE huser32 = GetModuleHandleA("user32.dll");
1.3510 +
1.3511 + // Get pointers to the APIs we want
1.3512 + if (huser32 == NULL ||
1.3513 + (ipMonitorFromRect =
1.3514 + (HMONITOR (WINAPI *)(LPCRECT lprcScreenCoords, UINT uFlags))
1.3515 + GetProcAddress(huser32, "MonitorFromRect")) == NULL ||
1.3516 + (ipGetMonitorInfo =
1.3517 + (BOOL (WINAPI *)(HMONITOR hMonitor, LPMONITORINFO lpMonitorInfo))
1.3518 + GetProcAddress(huser32, "GetMonitorInfoA")) == NULL)
1.3519 + {
1.3520 + return;
1.3521 + }
1.3522 +
1.3523 + iCount = n;
1.3524 + iHaveMultiMonFunctions = true;
1.3525 + }
1.3526 +
1.3527 +TBool SystemMonitors::RectAllOnOne(RECT& rect)
1.3528 + {
1.3529 + HMONITOR monitor = MonitorFromRect(rect);
1.3530 + if (monitor == NULL)
1.3531 + {
1.3532 + return false;
1.3533 + }
1.3534 +
1.3535 + MONITORINFO monInfo;
1.3536 + monInfo.cbSize = sizeof(MONITORINFO);
1.3537 +
1.3538 + if (! GetMonitorInfo(monitor, &monInfo))
1.3539 + {
1.3540 + return false;
1.3541 + }
1.3542 +
1.3543 + RECT overlap;
1.3544 +
1.3545 + if (IntersectRect(&overlap, &rect, &monInfo.rcWork) &&
1.3546 + EqualRect(&overlap, &rect))
1.3547 + {
1.3548 + return true;
1.3549 + }
1.3550 +
1.3551 + return false;
1.3552 + }
1.3553 +
1.3554 +HMONITOR SystemMonitors::MonitorFromRect(const RECT& rect, UINT flags)
1.3555 + {
1.3556 + if (! iHaveMultiMonFunctions)
1.3557 + {
1.3558 + return NULL;
1.3559 + }
1.3560 +
1.3561 + return (*ipMonitorFromRect)(&rect, flags);
1.3562 + }
1.3563 +
1.3564 +TBool SystemMonitors::GetMonitorInfo(HMONITOR monitor, LPMONITORINFO pMonInfo)
1.3565 + {
1.3566 + if (! iHaveMultiMonFunctions)
1.3567 + {
1.3568 + return false;
1.3569 + }
1.3570 +
1.3571 + return (*ipGetMonitorInfo)(monitor, pMonInfo);
1.3572 + }
1.3573 +
1.3574 +void DrawLeds()
1.3575 + {
1.3576 + HDC winDC = GetDC(TheWin[0]);
1.3577 + HDC hdcBits;
1.3578 + hdcBits=CreateCompatibleDC(winDC);
1.3579 + SelectObject(hdcBits,TheScreenBitmap[0]);
1.3580 + HPEN pen=CreatePen(PS_SOLID,0,RGB(0,0,0));
1.3581 + SelectObject(hdcBits,pen);
1.3582 + HBRUSH brush;
1.3583 + LOGBRUSH redbrush={BS_SOLID, RGB(0xff,0,0)};
1.3584 + LOGBRUSH greenbrush={BS_SOLID, RGB(0,0xff,0)};
1.3585 + LOGBRUSH blackbrush={BS_SOLID, RGB(0,0,0)};
1.3586 + // red
1.3587 + if (LedMask & KLedMaskRed1)
1.3588 + brush=CreateBrushIndirect(&redbrush);
1.3589 + else
1.3590 + brush=CreateBrushIndirect(&blackbrush);
1.3591 + SelectObject(hdcBits,brush);
1.3592 + DWinsUi *ini=systemIni;
1.3593 + Ellipse(hdcBits, ini->iLedOffsetX, ini->iLedOffsetY, ini->iLedOffsetX+ini->iLedSize, ini->iLedOffsetY+ini->iLedSize);
1.3594 + DeleteObject(brush);
1.3595 + // green
1.3596 + if (LedMask & KLedMaskGreen1)
1.3597 + brush=CreateBrushIndirect(&greenbrush);
1.3598 + else
1.3599 + brush=CreateBrushIndirect(&blackbrush);
1.3600 + SelectObject(hdcBits,brush);
1.3601 + if (ini->iLedVertical)
1.3602 + Ellipse(hdcBits, ini->iLedOffsetX, ini->iLedOffsetY+ini->iLedSize+ini->iLedGap,
1.3603 + ini->iLedOffsetX+ini->iLedSize, ini->iLedOffsetY+ini->iLedSize+ini->iLedGap+ini->iLedSize);
1.3604 + else
1.3605 + Ellipse(hdcBits, ini->iLedOffsetX+ini->iLedSize+ini->iLedGap, ini->iLedOffsetY,
1.3606 + ini->iLedOffsetX+ini->iLedSize+ini->iLedGap+ini->iLedSize, ini->iLedOffsetY+ini->iLedSize);
1.3607 + DeleteObject(brush);
1.3608 + DeleteObject(pen);
1.3609 + DeleteDC(hdcBits);
1.3610 + ReleaseDC(TheWin[0], winDC);
1.3611 + if (ini->iLedVertical)
1.3612 + {
1.3613 + RECT r={ini->iLedOffsetX,
1.3614 + ini->iLedOffsetY,
1.3615 + ini->iLedOffsetX+ini->iLedSize,
1.3616 + ini->iLedOffsetY+ini->iLedSize+ini->iLedGap+ini->iLedSize};
1.3617 + InvalidateRect(TheWin[0], &r, FALSE);
1.3618 + }
1.3619 + else
1.3620 + {
1.3621 + RECT r={ini->iLedOffsetX,
1.3622 + ini->iLedOffsetY,
1.3623 + ini->iLedOffsetX+ini->iLedSize+ini->iLedGap+ini->iLedSize,
1.3624 + ini->iLedOffsetY+ini->iLedSize};
1.3625 + InvalidateRect(TheWin[0], &r, FALSE);
1.3626 + }
1.3627 + }
1.3628 +
1.3629 +void DWinsUi::ScreenInfo(TScreenInfoV01& aInfo)
1.3630 +//
1.3631 +// Return screen 0 info to the window server.
1.3632 +//
1.3633 + {
1.3634 + aInfo.iWindowHandleValid=ETrue;
1.3635 + aInfo.iWindowHandle=TheChildWin[0];
1.3636 + aInfo.iScreenAddressValid=EFalse;
1.3637 + aInfo.iScreenAddress=NULL;
1.3638 + aInfo.iScreenSize.iWidth = iScreens[0]->iMaxScreenWidth;
1.3639 + aInfo.iScreenSize.iHeight = iScreens[0]->iMaxScreenHeight;
1.3640 + }
1.3641 +
1.3642 +
1.3643 +TBool DWinsUi::VideoInfo(TInt aScreenNumber, TVideoInfoV01& aInfo)
1.3644 + {
1.3645 + return VideoInfo(aScreenNumber,iScreens[aScreenNumber&KMaskScreenNum]->iCurrentMode,aInfo);
1.3646 + }
1.3647 +
1.3648 +/// Could fail if flip mode is not supported
1.3649 +TBool DWinsUi::VideoInfo(TInt aScreenNumber,TInt aModeNumber, TVideoInfoV01& aInfo)
1.3650 + {
1.3651 + aScreenNumber &= KMaskScreenNum;
1.3652 + if (aScreenNumber>=iScreens.Count())
1.3653 + return EFalse;
1.3654 + if (masterIni->iBufferSet.Count() && masterIni->iBufferSet[aScreenNumber].iDisplayDriverCount > 0)
1.3655 + {
1.3656 + return VideoInfoForDisplayDriver(aScreenNumber,aModeNumber,aInfo);
1.3657 + }
1.3658 + else
1.3659 + {
1.3660 + if ((aModeNumber&KMaskModeNum)>=1)
1.3661 + return EFalse; //non-gce emulator doesn't support changing the mode number.
1.3662 + DScreenProperties* screenProperties=iScreens[aScreenNumber];
1.3663 + aInfo.iSizeInPixels.iWidth = screenProperties->iMaxScreenWidth;
1.3664 + aInfo.iSizeInPixels.iHeight = screenProperties->iMaxScreenHeight;
1.3665 + aInfo.iSizeInTwips.iWidth = screenProperties->iMaxPhysicalScreenWidth ? screenProperties->iMaxPhysicalScreenWidth : TInt(screenProperties->iScreenWidth*KDefaultPixelsToTwipsX);
1.3666 + aInfo.iSizeInTwips.iHeight = screenProperties->iMaxPhysicalScreenHeight ? screenProperties->iMaxPhysicalScreenHeight : TInt(screenProperties->iScreenHeight*KDefaultPixelsToTwipsY);
1.3667 + aInfo.iIsMono = EFalse;
1.3668 + aInfo.iIsPalettized = EFalse;
1.3669 + aInfo.iDisplayMode=screenProperties->iCurrentMode;
1.3670 + aInfo.iIsPixelOrderRGB = ETrue;
1.3671 + aInfo.iIsPixelOrderLandscape=ETrue;
1.3672 +
1.3673 + aInfo.iVideoAddress = (TInt)TheChildWin[aScreenNumber];
1.3674 + aInfo.iBitsPerPixel = screenProperties->iColorDepth;
1.3675 + aInfo.iOffsetToFirstPixel=0;
1.3676 + aInfo.iOffsetBetweenLines=0;
1.3677 + }
1.3678 + return ETrue;
1.3679 + }
1.3680 +
1.3681 +/** Could fail if flip mode is not supported.
1.3682 + Note that this method is inteneded to be called directly to parameterise the setting up of the display driver,
1.3683 + so it must survive absense of the display driver installation!
1.3684 +**/
1.3685 +
1.3686 +TBool DWinsUi::VideoInfoForDisplayDriver(TInt aScreenNumber,TInt aModeNumber, TVideoInfoV01& aInfo, TBool aRealWidthAndHeight)
1.3687 + {
1.3688 + aScreenNumber &= KMaskScreenNum;
1.3689 + DScreenProperties* screenProperties = iScreens[aScreenNumber];
1.3690 + if ((aModeNumber&KMaskModeNum) >= screenProperties->iMaxModes)
1.3691 + {
1.3692 + return EFalse;
1.3693 + }
1.3694 +
1.3695 + aInfo.iSizeInPixels.iWidth = aRealWidthAndHeight ? screenProperties->iScreenWidth : screenProperties->iMaxScreenWidth;
1.3696 + aInfo.iSizeInPixels.iHeight = aRealWidthAndHeight ? screenProperties->iScreenHeight : screenProperties->iMaxScreenHeight;
1.3697 +
1.3698 + if (aRealWidthAndHeight==EFalse)
1.3699 + {
1.3700 + aInfo.iSizeInTwips.iWidth = screenProperties->iMaxPhysicalScreenWidth ? screenProperties->iMaxPhysicalScreenWidth : TInt(screenProperties->iScreenWidth*KDefaultPixelsToTwipsX);
1.3701 + aInfo.iSizeInTwips.iHeight = screenProperties->iMaxPhysicalScreenHeight ? screenProperties->iMaxPhysicalScreenHeight : TInt(screenProperties->iScreenHeight*KDefaultPixelsToTwipsY);
1.3702 + }
1.3703 + else
1.3704 + {
1.3705 + aInfo.iSizeInTwips.iWidth = screenProperties->iPhysicalScreenWidth ? screenProperties->iPhysicalScreenWidth : TInt(screenProperties->iScreenWidth*KDefaultPixelsToTwipsX);
1.3706 + aInfo.iSizeInTwips.iHeight = screenProperties->iPhysicalScreenHeight ? screenProperties->iPhysicalScreenHeight : TInt(screenProperties->iScreenHeight*KDefaultPixelsToTwipsY);
1.3707 + }
1.3708 +
1.3709 + aInfo.iIsMono = EFalse;
1.3710 + aInfo.iIsPalettized = EFalse;
1.3711 + aInfo.iDisplayMode=screenProperties->iCurrentMode;
1.3712 + aInfo.iIsPixelOrderRGB = ETrue;
1.3713 + aInfo.iIsPixelOrderLandscape=ETrue;
1.3714 +
1.3715 + // Set memory to iVideoAddress to NULL to trigger the HAL code into querying the video address
1.3716 + // separately
1.3717 + aInfo.iVideoAddress = NULL;
1.3718 +
1.3719 + TInt bpp=screenProperties->iModeDepths[aModeNumber&KMaskModeNum];
1.3720 + aInfo.iBitsPerPixel=bpp;
1.3721 + if (bpp>8)
1.3722 + {
1.3723 + bpp=(bpp+15)&-16; //12 & 16 --> 16 ; 24 & 32 --> 32
1.3724 + }
1.3725 +
1.3726 + aInfo.iOffsetToFirstPixel=0;
1.3727 +#ifdef TEST_GCE_VARIABLE_START_EXTRA
1.3728 + aInfo.iOffsetToFirstPixel+= TEST_GCE_VARIABLE_START_EXTRA*(1+aModeNumber&KMaskScreenModeNum);
1.3729 + if ((aModeNumber& KModeFlagFlipped)
1.3730 + {
1.3731 +#ifndef ASSYMETRIC_SQUARE_STRIDE
1.3732 + if (aInfo.iSizeInPixels.iWidth!=aInfo.iSizeInPixels.iHeight)
1.3733 +#endif
1.3734 + aInfo.iOffsetToFirstPixel+= TEST_GCE_VARIABLE_START_EXTRA*KEmulMaxNumModes;
1.3735 + }
1.3736 +#endif
1.3737 + if (aModeNumber& KModeFlagFlipped)
1.3738 + {
1.3739 + // we calculate the number of bytes per scanline that MUST be a multiple of 32 bits word (alignment)
1.3740 + // screenProperties->iMaxScreenHeight * bpp represnts the number of bits per scanline
1.3741 + // +31 is the ceiling
1.3742 + // we shift right (>>3) because there are 8 bits/byte
1.3743 + // we mask with ~3 because we are intrested in the octet value
1.3744 + aInfo.iOffsetBetweenLines=((screenProperties->iMaxScreenHeight * bpp + 31) >> 3) & ~3;
1.3745 + }
1.3746 + else
1.3747 + {
1.3748 + // please see the comment above
1.3749 + aInfo.iOffsetBetweenLines=((screenProperties->iMaxScreenWidth * bpp + 31) >> 3) & ~3;
1.3750 + }
1.3751 +#ifdef TEST_GCE_VARIABLE_STRIDE_EXTRA
1.3752 + aInfo.iOffsetBetweenLines+=TEST_GCE_VARIABLE_STRIDE_EXTRA;
1.3753 +#endif
1.3754 +
1.3755 + return ETrue;
1.3756 + }
1.3757 +
1.3758 +TInt DMasterIni::DoHalFunction(TAny* aPtr, TInt aFunction, TAny* a1, TAny* a2)
1.3759 + {
1.3760 + return masterIni->HalFunction((TInt)aPtr,aFunction,a1,a2);
1.3761 + }
1.3762 +
1.3763 +
1.3764 +TInt DMasterIni::HalFunction(TInt aDeviceNumber, TInt aFunction, TAny* a1, TAny* a2)
1.3765 + {
1.3766 + if (TUint(aDeviceNumber) >= TUint(systemIni->iScreens.Count()))
1.3767 + return KErrArgument;
1.3768 +
1.3769 + TInt mode;
1.3770 + TInt maxMode=1;
1.3771 + TInt r=KErrNone;
1.3772 + switch(aFunction)
1.3773 + {
1.3774 + case EDisplayHalScreenInfo:
1.3775 + {
1.3776 + TPckgBuf<TScreenInfoV01> vPckg;
1.3777 + systemIni->ScreenInfo(vPckg());
1.3778 + Kern::InfoCopy(*(TDes8*)a1,vPckg);
1.3779 + break;
1.3780 + }
1.3781 + case EDisplayHalWsRegisterSwitchOnScreenHandling:
1.3782 + WsSwitchOnScreen=(TBool)a1;
1.3783 + break;
1.3784 + case EDisplayHalSetState:
1.3785 + {
1.3786 + if(!Kern::CurrentThreadHasCapability(ECapabilityPowerMgmt,__PLATSEC_DIAGNOSTIC_STRING("Checked by Hal function EDisplayHalSetState")))
1.3787 + return KErrPermissionDenied;
1.3788 + if ((TBool)a1)
1.3789 + WinsGuiPowerHandler->ScreenOn(aDeviceNumber);
1.3790 + else
1.3791 + WinsGuiPowerHandler->ScreenOff(aDeviceNumber);
1.3792 + }
1.3793 + break;
1.3794 +
1.3795 + case EDisplayHalState:
1.3796 + *(TInt*)a1=!systemIni->iScreens[aDeviceNumber]->iScreenOff;
1.3797 + break;
1.3798 + case EDisplayHalWsSwitchOnScreen:
1.3799 + WinsGuiPowerHandler->ScreenOn();
1.3800 + break;
1.3801 + case EDisplayHalMaxDisplayContrast:
1.3802 + kumemput32(a1,&KMaxDisplayContrast,sizeof(KMaxDisplayContrast));
1.3803 + break;
1.3804 + case EDisplayHalDisplayContrast:
1.3805 + kumemput32(a1,&systemIni->iScreens[aDeviceNumber]->iDisplayContrast,sizeof(systemIni->iScreens[aDeviceNumber]->iDisplayContrast));
1.3806 + break;
1.3807 + case EDisplayHalSetDisplayContrast:
1.3808 + if(!Kern::CurrentThreadHasCapability(ECapabilityWriteDeviceData,__PLATSEC_DIAGNOSTIC_STRING("Checked by Hal function EDisplayHalSetDisplayContrast")))
1.3809 + return KErrPermissionDenied;
1.3810 + if (TUint(a1) <= TUint(KMaxDisplayContrast))
1.3811 + systemIni->iScreens[aDeviceNumber]->iDisplayContrast = TInt(a1);
1.3812 + else
1.3813 + r = KErrArgument;
1.3814 + break;
1.3815 + case EDisplayHalBacklightOn:
1.3816 + {
1.3817 + TBool c = EFalse;
1.3818 + kumemput32(a1,&c,sizeof(TBool));
1.3819 + }
1.3820 + break;
1.3821 +
1.3822 + case EDisplayHalCurrentModeInfo:
1.3823 + {
1.3824 + //a1 has ptr to buffer for results
1.3825 + TPckgBuf<TVideoInfoV01> vPckg;
1.3826 + if (systemIni->VideoInfo(aDeviceNumber, vPckg()))
1.3827 + Kern::InfoCopy(*(TDes8*)a1,vPckg);
1.3828 + else
1.3829 + r=KErrNotSupported;
1.3830 + }
1.3831 + break;
1.3832 +
1.3833 + case EDisplayHalSpecifiedModeInfo:
1.3834 + {
1.3835 + kumemget32(&mode, a1, sizeof(mode));
1.3836 + TPckgBuf<TVideoInfoV01> vPckg;
1.3837 + if (!systemIni->VideoInfo(aDeviceNumber, mode, vPckg()))
1.3838 + return KErrArgument;
1.3839 + Kern::InfoCopy(*(TDes8*)a2, vPckg);
1.3840 + }
1.3841 + break;
1.3842 +
1.3843 + case EDisplayHalSetMode:
1.3844 +// if(!Kern::CurrentThreadHasCapability(ECapabilityMultimediaDD,__PLATSEC_DIAGNOSTIC_STRING("Checked by Hal function EDisplayHalSetMode")))
1.3845 +// return KErrPermissionDenied;
1.3846 +
1.3847 + //Note that at present the HAL mode does not apparently get set when the CFbsScreenDevice requires a different mode.
1.3848 + //At least in the emulator and default h4 implementation...
1.3849 +
1.3850 + mode=KMaskModeNum&(TInt) a1;
1.3851 + maxMode=1;
1.3852 + //can't avoid this behaviour change test against gce loaded
1.3853 + if (masterIni->iBufferSet.Count() && masterIni->iBufferSet[aDeviceNumber].iDisplayDriverCount > 0)
1.3854 + maxMode=systemIni->iScreens[aDeviceNumber]->iMaxModes;
1.3855 + if (mode >=maxMode || mode<0)
1.3856 + {
1.3857 + r = KErrArgument;
1.3858 + break;
1.3859 + }
1.3860 + //Harmless/Pointless in vanilla wins mode.
1.3861 + systemIni->iScreens[aDeviceNumber]->iCurrentMode=mode;
1.3862 +
1.3863 + break;
1.3864 +
1.3865 + case EDisplayHalMode:
1.3866 + {
1.3867 + //This is always 0 in non-gce emulator
1.3868 + kumemput32(a1,&systemIni->iScreens[aDeviceNumber]->iCurrentMode,sizeof(systemIni->iScreens[aDeviceNumber]->iCurrentMode));
1.3869 + }
1.3870 + break;
1.3871 +
1.3872 + case EDisplayHalModeCount:
1.3873 + {
1.3874 + //Need to actually count them here!
1.3875 + //GCE will ignore modes<=8
1.3876 + TInt encodedMode=1;
1.3877 + if (masterIni->iBufferSet.Count() && masterIni->iBufferSet[aDeviceNumber].iDisplayDriverCount > 0)
1.3878 + encodedMode=systemIni->iScreens[aDeviceNumber]->iMaxModes;
1.3879 + kumemput32(a1,&encodedMode,sizeof(encodedMode));
1.3880 + }
1.3881 + break;
1.3882 +
1.3883 + case EDisplayHalColors:
1.3884 + {
1.3885 + TInt deepestMode=0;
1.3886 + if (masterIni->iBufferSet.Count()==0 || masterIni->iBufferSet[aDeviceNumber].iDisplayDriverCount <= 0)
1.3887 + {
1.3888 + deepestMode = KMaxDisplayColors; //I could try and work it out, but this is what used to happen!
1.3889 + }
1.3890 + else
1.3891 + {
1.3892 + TInt maxBpp=0;
1.3893 + for (TInt i=0,maxI=systemIni->iScreens[aDeviceNumber]->iMaxModes;i<maxI;i++)
1.3894 + if (systemIni->iScreens[aDeviceNumber]->iModeDepths[i]>maxBpp)
1.3895 + maxBpp=systemIni->iScreens[aDeviceNumber]->iModeDepths[i];
1.3896 + deepestMode= 1<<maxBpp;
1.3897 + }
1.3898 +
1.3899 + kumemput32(a1,&deepestMode,sizeof(deepestMode));
1.3900 + }
1.3901 + break;
1.3902 + case EDisplayHalGetDisplayMemoryHandle:
1.3903 + {
1.3904 + TInt val = 0;
1.3905 + TInt passedIn = 0;
1.3906 + kumemget32(&passedIn, a1, sizeof(TInt));
1.3907 + if (passedIn != -1) //not from a getall
1.3908 + {
1.3909 + NKern::ThreadEnterCS();
1.3910 + if (!(masterIni->iBufferSet.Count() == 0 || masterIni->iBufferSet[aDeviceNumber].iDisplayDriverCount <= 0 ))
1.3911 + {
1.3912 + r = masterIni->DisplayMemoryHandle(aDeviceNumber, val);
1.3913 + }
1.3914 + else
1.3915 + {
1.3916 + r = KErrArgument;
1.3917 + }
1.3918 + NKern::ThreadLeaveCS();
1.3919 + }
1.3920 + kumemput32(a1, &val, sizeof(TInt));
1.3921 +
1.3922 + }
1.3923 + break;
1.3924 +
1.3925 + case EDisplayHalGetDisplayMemoryAddress:
1.3926 + {
1.3927 + TInt val = 0;
1.3928 + TInt passedIn = 0;
1.3929 + kumemget32(&passedIn, a1, sizeof(TInt));
1.3930 + if (passedIn != -1) //not from a getall
1.3931 + {
1.3932 + if (!(masterIni->iBufferSet.Count() == 0 || masterIni->iBufferSet[aDeviceNumber].iDisplayDriverCount <= 0 ))
1.3933 + {
1.3934 + r = masterIni->DisplayMemoryAddress(aDeviceNumber, val);
1.3935 + }
1.3936 + else
1.3937 + {
1.3938 + r = KErrArgument;
1.3939 + }
1.3940 + }
1.3941 + kumemput32(a1, &val, sizeof(TInt));
1.3942 + }
1.3943 + break;
1.3944 +
1.3945 + case EDisplayHalNumberOfResolutions:
1.3946 + {
1.3947 + r = NumberOfResolutions(aDeviceNumber, a1, a2);
1.3948 + }
1.3949 + break;
1.3950 + case EDisplayHalSpecificScreenInfo:
1.3951 + {
1.3952 + r = SpecificScreenInfo(aDeviceNumber, a1, a2);
1.3953 + }
1.3954 + break;
1.3955 + case EDisplayHalCurrentScreenInfo:
1.3956 + {
1.3957 + r = CurrentScreenInfo(aDeviceNumber, a1, a2);
1.3958 + }
1.3959 + break;
1.3960 + case EDisplayHalSetDisplayState:
1.3961 + {
1.3962 + //increase the spinner at both beginning and end of resetting the display state
1.3963 + NKern::LockedInc(iBufferSet[aDeviceNumber].iStateChangeCount);
1.3964 + kumemget32(&iBufferSet[aDeviceNumber].iDisplayState, a1, sizeof(TInt));
1.3965 +
1.3966 + switch(iBufferSet[aDeviceNumber].iDisplayState)
1.3967 + {
1.3968 + case ENoResolution:
1.3969 + case EDisconnect:
1.3970 + case ESingleResolution:
1.3971 + // the fascia effect of 0x0 resolution
1.3972 + SetDisplaySize(aDeviceNumber, 0, 0);
1.3973 + break;
1.3974 + }
1.3975 +
1.3976 + NKern::LockedInc(iBufferSet[aDeviceNumber].iStateChangeCount);
1.3977 + }
1.3978 + break;
1.3979 + case EDisplayHalGetStateSpinner:
1.3980 + {
1.3981 + kumemput32(a1,&iBufferSet[aDeviceNumber].iStateChangeCount,
1.3982 + sizeof(iBufferSet[aDeviceNumber].iStateChangeCount));
1.3983 + }
1.3984 + break;
1.3985 + default:
1.3986 + r=KErrNotSupported;
1.3987 + break;
1.3988 + }
1.3989 + return r;
1.3990 + }
1.3991 +
1.3992 +TInt DMasterIni::NumberOfResolutions(TInt aDeviceNumber, TAny* a1, TAny* a2)
1.3993 + {
1.3994 + TInt numberOfConfigs;
1.3995 + switch(iBufferSet[aDeviceNumber].iDisplayState)
1.3996 + {
1.3997 + case ENoResolution:
1.3998 + {
1.3999 + numberOfConfigs = 0;
1.4000 + }
1.4001 + break;
1.4002 + case EDisconnect:
1.4003 + {
1.4004 + return KErrDisconnected;
1.4005 + }
1.4006 + break;
1.4007 + case ESingleResolution:
1.4008 + {
1.4009 + numberOfConfigs = 1;
1.4010 + }
1.4011 + break;
1.4012 + case ENormalResolution:
1.4013 + default:
1.4014 + {
1.4015 + numberOfConfigs = iSystemInis.Count();
1.4016 + if (numberOfConfigs > 1)
1.4017 + {
1.4018 + TVideoInfoV01 info1;
1.4019 + TVideoInfoV01 info2;
1.4020 + iSystemInis[0]->VideoInfoForDisplayDriver(aDeviceNumber, 0, info1, ETrue);
1.4021 + iSystemInis[1]->VideoInfoForDisplayDriver(aDeviceNumber, 0, info2, ETrue);
1.4022 + if (info1.iSizeInPixels.iWidth == info2.iSizeInPixels.iWidth &&
1.4023 + info1.iSizeInPixels.iHeight == info2.iSizeInPixels.iHeight)
1.4024 + {
1.4025 + numberOfConfigs = 1; //It looks like all resolutions for this device are the same
1.4026 + }
1.4027 + }
1.4028 + }
1.4029 + }
1.4030 + kumemput32(a1,&numberOfConfigs,sizeof(numberOfConfigs));
1.4031 + if(a2)
1.4032 + {
1.4033 + kumemput32(a2,&(iBufferSet[aDeviceNumber].iStateChangeCount),sizeof(iBufferSet[aDeviceNumber].iStateChangeCount));
1.4034 + }
1.4035 + return KErrNone;
1.4036 + }
1.4037 +
1.4038 +TInt DMasterIni::SpecificScreenInfo(TInt aDeviceNumber, TAny* a1, TAny* a2)
1.4039 + {
1.4040 + TInt config;
1.4041 + switch(iBufferSet[aDeviceNumber].iDisplayState)
1.4042 + {
1.4043 + case ENoResolution: //Do Nothing
1.4044 + break;
1.4045 + case EDisconnect:
1.4046 + {
1.4047 + return KErrDisconnected;
1.4048 + }
1.4049 + break;
1.4050 + case ESingleResolution: //fill (0,0) as the only element in resolution array
1.4051 + {
1.4052 + if(*(TInt*)a1 == 0)
1.4053 + {
1.4054 + TVideoInfoV01 info;
1.4055 + info.iSizeInPixels.iHeight = 0;
1.4056 + info.iSizeInPixels.iWidth = 0;
1.4057 + info.iSizeInTwips.iHeight = 0;
1.4058 + info.iSizeInTwips.iWidth = 0;
1.4059 + TPtr8 infoPtr((TUint8*)&info, sizeof(info), sizeof(info));
1.4060 + Kern::InfoCopy(*(TDes8*)a2, infoPtr);
1.4061 + }
1.4062 + }
1.4063 + break;
1.4064 + case ENormalResolution:
1.4065 + default:
1.4066 + {
1.4067 + kumemget32(&config, a1, sizeof(config));
1.4068 + TPckgBuf<TVideoInfoV01> vPckg;
1.4069 + iSystemInis[config]->VideoInfoForDisplayDriver(aDeviceNumber, 0, vPckg(), ETrue);
1.4070 + Kern::InfoCopy(*(TDes8*)a2,vPckg);
1.4071 + }
1.4072 + }
1.4073 + return KErrNone;
1.4074 + }
1.4075 +
1.4076 +TInt DMasterIni::CurrentScreenInfo(TInt aDeviceNumber, TAny* a1, TAny* /*a2*/)
1.4077 + {
1.4078 + switch(iBufferSet[aDeviceNumber].iDisplayState)
1.4079 + {
1.4080 + case ENoResolution: //Do Nothing
1.4081 + break;
1.4082 + case EDisconnect:
1.4083 + {
1.4084 + return KErrDisconnected;
1.4085 + }
1.4086 + break;
1.4087 + case ESingleResolution: //fill (0,0)
1.4088 + {
1.4089 + TVideoInfoV01 info;
1.4090 + info.iSizeInPixels.iHeight = 0;
1.4091 + info.iSizeInPixels.iWidth = 0;
1.4092 + info.iSizeInTwips.iHeight = 0;
1.4093 + info.iSizeInTwips.iWidth = 0;
1.4094 + TPtr8 infoPtr((TUint8*)&info, sizeof(info), sizeof(info));
1.4095 + Kern::InfoCopy(*(TDes8*)a1, infoPtr);
1.4096 + }
1.4097 + break;
1.4098 + case ENormalResolution:
1.4099 + default:
1.4100 + {
1.4101 + TPckgBuf<TVideoInfoV01> vPckg;
1.4102 + systemIni->VideoInfoForDisplayDriver(aDeviceNumber, 0, vPckg(), ETrue);
1.4103 + Kern::InfoCopy(*(TDes8*)a1,vPckg);
1.4104 + }
1.4105 + }
1.4106 + return KErrNone;
1.4107 + }
1.4108 +
1.4109 +TInt DMasterIni::DoXYHalFunction(TAny* aThis, TInt aFunction, TAny* a1, TAny* a2)
1.4110 + {
1.4111 + return static_cast<DMasterIni*>(aThis)->XYHalFunction(aFunction,a1,a2);
1.4112 + }
1.4113 +
1.4114 +TInt DMasterIni::XYHalFunction(TInt aFunction, TAny* a1, TAny* /*a2*/)
1.4115 + {
1.4116 + TInt r=KErrNone;
1.4117 + switch(aFunction)
1.4118 + {
1.4119 + case EDigitiserHalXYInfo:
1.4120 + {
1.4121 + if(systemIni->iXYInputType==EXYInputPointer)
1.4122 + {
1.4123 + TPckgBuf<TDigitiserInfoV01> vPckg;
1.4124 + TDigitiserInfoV01& xyinfo=vPckg();
1.4125 + xyinfo.iDigitiserSize.iWidth=max(systemIni->iScreens[0]->iXYInputWidth,systemIni->iScreens[0]->iMaxScreenWidth+systemIni->iScreens[0]->iScreenOffsetX);
1.4126 + xyinfo.iDigitiserSize.iHeight=max(systemIni->iScreens[0]->iXYInputHeight,systemIni->iScreens[0]->iMaxScreenHeight+systemIni->iScreens[0]->iScreenOffsetY);
1.4127 + xyinfo.iOffsetToDisplay.iX=systemIni->iScreens[0]->iScreenOffsetX;
1.4128 + xyinfo.iOffsetToDisplay.iY=systemIni->iScreens[0]->iScreenOffsetY;
1.4129 + Kern::InfoCopy(*(TDes8*)a1,vPckg);
1.4130 + }
1.4131 + else
1.4132 + r=KErrNotSupported;
1.4133 + }
1.4134 + break;
1.4135 + default:
1.4136 + r=KErrNotSupported;
1.4137 + break;
1.4138 + }
1.4139 + return r;
1.4140 + }
1.4141 +
1.4142 +TInt DMasterIni::DoMouseHalFunction(TAny* aThis, TInt aFunction, TAny* a1, TAny* a2)
1.4143 + {
1.4144 + return static_cast<DMasterIni*>(aThis)->MouseHalFunction(aFunction,a1,a2);
1.4145 + }
1.4146 +
1.4147 +TInt DMasterIni::MouseHalFunction(TInt aFunction, TAny* a1, TAny* /*a2*/)
1.4148 + {
1.4149 + TInt r=KErrNone;
1.4150 + switch(aFunction)
1.4151 + {
1.4152 + case EMouseHalMouseInfo:
1.4153 + {
1.4154 + if(systemIni->iXYInputType==EXYInputMouse || systemIni->iXYInputType==EXYInputDeltaMouse)
1.4155 + {
1.4156 + TPckgBuf<TMouseInfoV01> vPckg;
1.4157 + TMouseInfoV01& xyinfo=vPckg();
1.4158 + xyinfo.iMouseButtons=2;
1.4159 + xyinfo.iMouseAreaSize.iWidth=max(systemIni->iScreens[0]->iXYInputWidth,systemIni->iScreens[0]->iMaxScreenWidth+systemIni->iScreens[0]->iScreenOffsetX);
1.4160 + xyinfo.iMouseAreaSize.iHeight=max(systemIni->iScreens[0]->iXYInputHeight,systemIni->iScreens[0]->iMaxScreenHeight+systemIni->iScreens[0]->iScreenOffsetY);
1.4161 + xyinfo.iOffsetToDisplay.iX=systemIni->iScreens[0]->iScreenOffsetX;
1.4162 + xyinfo.iOffsetToDisplay.iY=systemIni->iScreens[0]->iScreenOffsetY;
1.4163 + Kern::InfoCopy(*(TDes8*)a1,vPckg);
1.4164 + }
1.4165 + else
1.4166 + r=KErrNotSupported;
1.4167 + }
1.4168 + break;
1.4169 + default:
1.4170 + r=KErrNotSupported;
1.4171 + break;
1.4172 + }
1.4173 + return r;
1.4174 + }
1.4175 +
1.4176 +TInt DMasterIni::DoKbdHalFunction(TAny* /*aThis*/, TInt aFunction, TAny* /*a1*/, TAny* /*a2*/)
1.4177 + {
1.4178 + // don't actually do anything, just enough to report a Keyboard is present
1.4179 + TInt r=KErrNone;
1.4180 + if(aFunction!=EKeyboardHalKeyboardInfo)
1.4181 + r=KErrNotSupported;
1.4182 + return r;
1.4183 + }
1.4184 +
1.4185 +void Inactive()
1.4186 +//
1.4187 +// Window has been minimised.
1.4188 +//
1.4189 + {
1.4190 +
1.4191 + TRawEvent v;
1.4192 + v.Set(TRawEvent::EInactive);
1.4193 + TheEventQ.Add(v);
1.4194 + }
1.4195 +
1.4196 +void UpdateModifiers()
1.4197 +//Updates the modifier key states and sends an event to wserv about the
1.4198 +//change in state
1.4199 + {
1.4200 + TRawEvent v;
1.4201 + TInt modifiers=0;
1.4202 + if(GetKeyState(VK_SCROLL)&1)
1.4203 + modifiers|=EModifierScrollLock;
1.4204 + if(GetKeyState(VK_NUMLOCK)&1)
1.4205 + modifiers|=EModifierNumLock;
1.4206 + if(GetKeyState(VK_CAPITAL)&1)
1.4207 + modifiers|=EModifierCapsLock;
1.4208 + v.Set(TRawEvent::EUpdateModifiers,modifiers);
1.4209 + TheEventQ.Add(v);
1.4210 + }
1.4211 +
1.4212 +void Active()
1.4213 +//
1.4214 +// Window has been restored.
1.4215 +// Update the toggling modifiers, reset any others
1.4216 +//
1.4217 + {
1.4218 + TRawEvent v;
1.4219 + UpdateModifiers();
1.4220 + v.Set(TRawEvent::EActive);
1.4221 + TheEventQ.Add(v);
1.4222 + }
1.4223 +
1.4224 +
1.4225 +void ClearScreen()
1.4226 + {
1.4227 +
1.4228 + }
1.4229 +
1.4230 +
1.4231 +TInt DWinsUi::GetVirtualKey(TEmulCommand& aCommand, TInt aX, TInt aY)
1.4232 + {
1.4233 + //if the point is in the list of shapes, set the key and return true
1.4234 + for (TInt keyCount = iVirtualKeys.Count(); --keyCount >= 0; )
1.4235 + {
1.4236 + const VirtualKey& vk = *iVirtualKeys[keyCount];
1.4237 + if (vk.Contains(aX, aY))
1.4238 + {
1.4239 + aCommand = vk.Command();
1.4240 + return vk.Value();
1.4241 + }
1.4242 + }
1.4243 + return -1;
1.4244 + }
1.4245 +
1.4246 +void DWinsUi::TranslateMouseCoords(const TEmulatorFlip aFlipState, const TInt aX, const TInt aY, const TInt aRegionWidth, const TInt aRegionHeight, TInt& aNewX, TInt& aNewY)
1.4247 + {
1.4248 + switch (aFlipState)
1.4249 + {
1.4250 + case EEmulatorFlipRestore:
1.4251 + aNewX = aX;
1.4252 + aNewY = aY;
1.4253 + break;
1.4254 +
1.4255 + case EEmulatorFlipInvert:
1.4256 + aNewX = aRegionWidth - aX;
1.4257 + aNewY = aRegionHeight - aY;
1.4258 + break;
1.4259 +
1.4260 + case EEmulatorFlipLeft:
1.4261 + aNewX = aRegionWidth - aY;
1.4262 + aNewY = aX;
1.4263 + break;
1.4264 +
1.4265 + case EEmulatorFlipRight:
1.4266 + aNewX = aY;
1.4267 + aNewY = aRegionHeight - aX;
1.4268 + break;
1.4269 + }
1.4270 + }
1.4271 +
1.4272 +
1.4273 +TBool DWinsUi::OnScreen(TInt aScreen, TInt ax, TInt ay) const
1.4274 +//
1.4275 +// Checks if a point within the Emulator window is on the screen
1.4276 +//
1.4277 + {
1.4278 + return (TUint(ax) < TUint(systemIni->iScreens[aScreen]->iScreenWidth) && TUint(ay) < TUint(systemIni->iScreens[aScreen]->iScreenHeight));
1.4279 + }
1.4280 +
1.4281 +TInt DWinsUi::Create(TInt aId)
1.4282 + {
1.4283 + TInt r = SetupProperties(aId);
1.4284 + if (r != KErrNone)
1.4285 + return r;
1.4286 + TInt screen;
1.4287 + DScreenProperties* currentScreen = NULL;
1.4288 + for(screen=0;screen<iScreens.Count();screen++)
1.4289 + {
1.4290 + BITMAPINFOHEADER bitmapinfo;
1.4291 + currentScreen = iScreens[screen];
1.4292 + if (readBitmapInfo(&bitmapinfo, currentScreen->iFasciaFileName) == KErrNone)
1.4293 + {
1.4294 + currentScreen->iXYInputWidth=bitmapinfo.biWidth;
1.4295 + currentScreen->iXYInputHeight=bitmapinfo.biHeight;
1.4296 + }
1.4297 + currentScreen->iXYInputWidth=max(currentScreen->iXYInputWidth,currentScreen->iScreenWidth+currentScreen->iScreenOffsetX);
1.4298 + currentScreen->iXYInputHeight=max(currentScreen->iXYInputHeight,currentScreen->iScreenHeight+currentScreen->iScreenOffsetY);
1.4299 + }
1.4300 +
1.4301 + currentScreen = iScreens[0];
1.4302 + //note digitizer offsets are relative to EPOC screen 0
1.4303 + if (-1 == iDigitizerWidth)
1.4304 + iDigitizerWidth = currentScreen->iXYInputWidth -
1.4305 + (currentScreen->iScreenOffsetX + iDigitizerOffsetX);
1.4306 + else
1.4307 + currentScreen->iXYInputWidth=max(currentScreen->iXYInputWidth,iDigitizerWidth);
1.4308 +
1.4309 + if (-1 == iDigitizerHeight)
1.4310 + iDigitizerHeight = currentScreen->iXYInputHeight -
1.4311 + (currentScreen->iScreenOffsetY + iDigitizerOffsetY);
1.4312 + else
1.4313 + currentScreen->iXYInputHeight=max(currentScreen->iXYInputHeight,iDigitizerHeight);
1.4314 +
1.4315 + return r;
1.4316 + }
1.4317 +
1.4318 +const RDisplayChannel::TPixelFormat DMasterIni::iSupportedPixelFormatTable[] =
1.4319 + {
1.4320 + EUidPixelFormatXRGB_8888,
1.4321 + EUidPixelFormatARGB_8888,
1.4322 + EUidPixelFormatARGB_8888_PRE,
1.4323 + EUidPixelFormatXRGB_4444,
1.4324 + EUidPixelFormatARGB_4444,
1.4325 + EUidPixelFormatRGB_565
1.4326 + };
1.4327 +
1.4328 +const TInt DMasterIni::iSupportedPixelFormatTableSize = static_cast<TInt>(sizeof(iSupportedPixelFormatTable)/
1.4329 + sizeof(iSupportedPixelFormatTable[0]));
1.4330 +
1.4331 +void DMasterIni::InitBufferFormat(DScreenProperties& aScreenProperties, RDisplayChannel::TBufferFormat& aBufferFormat)
1.4332 + {
1.4333 + TUint bitsPerPixel = MaximumBitDepthFromMask(aScreenProperties.iColorDepth);
1.4334 +
1.4335 + aBufferFormat.iSize.iWidth = aScreenProperties.iMaxScreenWidth;
1.4336 + aBufferFormat.iSize.iHeight = aScreenProperties.iMaxScreenHeight;
1.4337 + switch (bitsPerPixel)
1.4338 + {
1.4339 + case 12: // XRGB4444
1.4340 + aBufferFormat.iPixelFormat = EUidPixelFormatXRGB_4444;
1.4341 + break;
1.4342 + case 16: // RGB565
1.4343 + aBufferFormat.iPixelFormat = EUidPixelFormatRGB_565;
1.4344 + break;
1.4345 + case 24: // Really 32bpp, but top 8 unused
1.4346 + case 32: // While 32bpp, top 8 will not be used
1.4347 + default:
1.4348 + aBufferFormat.iPixelFormat = EUidPixelFormatXRGB_8888;
1.4349 + break;
1.4350 + }
1.4351 + }
1.4352 +
1.4353 +TInt DMasterIni::Create()
1.4354 + {
1.4355 + TInt configurations = Property::GetInt("ConfigCount", 0);
1.4356 + if (configurations == 0)
1.4357 + return KErrGeneral;
1.4358 +
1.4359 + // the pixel formats table is, at present, configuration independent
1.4360 + TInt count;
1.4361 + TInt r = KErrNone;
1.4362 + for (count = 0; count < configurations && r == KErrNone; ++count)
1.4363 + {
1.4364 + DWinsUi* dwi = new DWinsUi;
1.4365 + if (dwi)
1.4366 + r = dwi->Create(count);
1.4367 +
1.4368 + if (r == KErrNone)
1.4369 + iSystemInis.Append(dwi);
1.4370 + }
1.4371 + if (r != KErrNone)
1.4372 + return r;
1.4373 +
1.4374 + systemIni = masterIni->iSystemInis[0];
1.4375 +
1.4376 + WinsGuiPowerHandler = DWinsGuiPowerHandler::New();
1.4377 + if (!WinsGuiPowerHandler)
1.4378 + return KErrNoMemory;
1.4379 +
1.4380 + TheWin=new HWND[systemIni->iScreens.Count()];
1.4381 + TheChildWin=new HWND[systemIni->iScreens.Count()];
1.4382 + TheScreenBitmap=new HBITMAP[systemIni->iScreens.Count()];
1.4383 + CurrentFlipState=new TEmulatorFlip[systemIni->iScreens.Count()];
1.4384 +
1.4385 + if(!TheWin || !TheChildWin || !TheScreenBitmap || !CurrentFlipState)
1.4386 + return KErrNoMemory;
1.4387 + memset(CurrentFlipState,EEmulatorFlipRestore,systemIni->iScreens.Count());
1.4388 +
1.4389 + TBufferSet buffer;
1.4390 + buffer.iDisplayDriverCount = 0;
1.4391 + buffer.iDisplayState = ENormalResolution;
1.4392 + buffer.iDisplayBuffer = 0;
1.4393 + buffer.iDisplayChannel = NULL;
1.4394 +
1.4395 +
1.4396 + TInt i;
1.4397 + for(i=0;i<systemIni->iScreens.Count();i++)
1.4398 + {
1.4399 + DScreenProperties *pScr = systemIni->iScreens[i];
1.4400 +
1.4401 + masterIni->InitBitmapHeader(*pScr, &buffer.iInfo);
1.4402 + masterIni->InitBufferFormat(*pScr, buffer.iBufferFormat);
1.4403 +
1.4404 + r = masterIni->iBufferSet.Append(buffer);
1.4405 + if (r != KErrNone)
1.4406 + return r;
1.4407 + }
1.4408 +
1.4409 + if (CreateWin32Thread(EThreadEvent, &KernelWindowThread, NULL, ETrue) == NULL)
1.4410 + return KErrGeneral;
1.4411 +
1.4412 + for(i=0;i<systemIni->iScreens.Count();i++)
1.4413 + {
1.4414 + r = Kern::AddHalEntry(EHalGroupDisplay,&DoHalFunction,(TAny*)i,i);
1.4415 + if (r != KErrNone)
1.4416 + return r;
1.4417 + }
1.4418 +
1.4419 + // should really come from Keyboard driver, but not doing it now...
1.4420 + r = Kern::AddHalEntry(EHalGroupKeyboard,&DoKbdHalFunction,this);
1.4421 + if (r != KErrNone)
1.4422 + return r;
1.4423 +
1.4424 + if(systemIni->iXYInputType==EXYInputPointer)
1.4425 + {
1.4426 + r = Kern::AddHalEntry(EHalGroupDigitiser,&DoXYHalFunction,this);
1.4427 + if (r != KErrNone)
1.4428 + return r;
1.4429 + }
1.4430 + else if(systemIni->iXYInputType==EXYInputMouse || systemIni->iXYInputType==EXYInputDeltaMouse)
1.4431 + {
1.4432 + r = Kern::AddHalEntry(EHalGroupMouse,&DoMouseHalFunction,this);
1.4433 + if (r != KErrNone)
1.4434 + return r;
1.4435 + }
1.4436 +
1.4437 + return r;
1.4438 + }
1.4439 +
1.4440 +void DMasterIni::InitBitmapHeader(DScreenProperties& aScreenProperties, LPBITMAPV4HEADER aInfo)
1.4441 + {
1.4442 + TInt width = aScreenProperties.iMaxScreenWidth;
1.4443 + TInt height = aScreenProperties.iMaxScreenHeight;
1.4444 + TUint bitsPerPixel = MaximumBitDepthFromMask(aScreenProperties.iColorDepth);
1.4445 +
1.4446 + memset(aInfo, 0, sizeof(BITMAPV4HEADER));
1.4447 +
1.4448 + switch (bitsPerPixel)
1.4449 + {
1.4450 + case 12: // XRGB4444
1.4451 + aInfo->bV4BitCount = 16;
1.4452 + aInfo->bV4V4Compression = BI_BITFIELDS;
1.4453 + aInfo->bV4RedMask = 0x0F00;
1.4454 + aInfo->bV4GreenMask = 0x00F0;
1.4455 + aInfo->bV4BlueMask = 0x000F;
1.4456 + break;
1.4457 + case 16: // RGB565
1.4458 + aInfo->bV4BitCount = 16;
1.4459 + aInfo->bV4V4Compression = BI_BITFIELDS;
1.4460 + aInfo->bV4RedMask = 0xF800;
1.4461 + aInfo->bV4GreenMask = 0x07E0;
1.4462 + aInfo->bV4BlueMask = 0x001F;
1.4463 + break;
1.4464 + case 24: // Really 32bpp, but top 8 unused
1.4465 + case 32: // While 32bpp, top 8 will not be used
1.4466 + default:
1.4467 + aInfo->bV4BitCount = 32;
1.4468 + aInfo->bV4V4Compression = BI_RGB;
1.4469 + // Mask is implicit for BI_RGB compression
1.4470 + break;
1.4471 + }
1.4472 +
1.4473 + aInfo->bV4Size = sizeof(BITMAPV4HEADER);
1.4474 + aInfo->bV4Width = width;
1.4475 + aInfo->bV4Height = -height; // Bitmap runs top to bottom
1.4476 + aInfo->bV4Planes = 1;
1.4477 +
1.4478 + TInt bpp = _ALIGN_UP(aInfo->bV4BitCount, 16); //12 & 16 --> 16 ; 24 & 32 --> 32
1.4479 + TInt widthInPixel = aInfo->bV4Width * bpp;
1.4480 + //rounding to 32 bits (4 octets) and converting, then, bits to octets;
1.4481 + TInt scanLineInBytes = _ALIGN_UP(widthInPixel, 32) >> 3;
1.4482 + aInfo->bV4SizeImage = -aInfo->bV4Height * scanLineInBytes;
1.4483 +
1.4484 + // Set color space as uncalibrated. All other members are then ignored.
1.4485 +#if defined(LCS_DEVICE_RGB)
1.4486 + aInfo->bV4CSType = LCS_DEVICE_RGB;
1.4487 +#elif defined(LCS_sRGB)
1.4488 + aInfo->bV4CSType = LCS_sRGB;
1.4489 +#endif
1.4490 + }
1.4491 +
1.4492 +// Helper function that allocates a single frame buffer.
1.4493 +static TInt AllocateOneFrameBuffer(TInt aSize, TScreenBuffer &aScreenBuffer)
1.4494 + {
1.4495 + // Open shared chunk to the composition framebuffer
1.4496 + DChunk* chunk = 0;
1.4497 + // round to page size
1.4498 + if (aSize <= 0)
1.4499 + return KErrArgument;
1.4500 + TUint round = Kern::RoundToPageSize(aSize);
1.4501 + TLinAddr chunkKernelAddr = 0;
1.4502 + TUint32 physicalAddress = 0;
1.4503 + TUint32 chunkMapAttr = 0;
1.4504 +
1.4505 + // create shared chunk
1.4506 + NKern::ThreadEnterCS();
1.4507 +
1.4508 + TChunkCreateInfo info;
1.4509 + info.iType = TChunkCreateInfo::ESharedKernelMultiple;
1.4510 + info.iMaxSize = round;
1.4511 + info.iMapAttr = 0;
1.4512 + info.iOwnsMemory = ETrue;
1.4513 + info.iDestroyedDfc = 0;
1.4514 +
1.4515 + TInt r = Kern::ChunkCreate(info, chunk, chunkKernelAddr, chunkMapAttr);
1.4516 + if (r == KErrNone)
1.4517 + {
1.4518 + // map our chunk to specific
1.4519 + r = Kern::ChunkCommitContiguous(chunk, 0, aSize, physicalAddress);
1.4520 + if (r != KErrNone)
1.4521 + {
1.4522 + Kern::ChunkClose(chunk);
1.4523 + }
1.4524 + }
1.4525 +
1.4526 + if (r == KErrNone)
1.4527 + {
1.4528 + TBufferAddressA* bufferAddress = new TBufferAddressA;
1.4529 + if (!bufferAddress)
1.4530 + {
1.4531 + r = KErrNoMemory;
1.4532 + }
1.4533 + else
1.4534 + {
1.4535 + bufferAddress->iAddress = (TAny*)chunkKernelAddr;
1.4536 + bufferAddress->iChunk = chunk;
1.4537 +
1.4538 + if ((r = aScreenBuffer.iFrameBuffers.Append(bufferAddress->iAddress)) == KErrNone)
1.4539 + {
1.4540 + r = aScreenBuffer.iMemChunks.Append(bufferAddress);
1.4541 + }
1.4542 + }
1.4543 + }
1.4544 + if (r != KErrNone)
1.4545 + {
1.4546 + Kern::ChunkClose(chunk);
1.4547 + }
1.4548 + NKern::ThreadLeaveCS();
1.4549 + return KErrNone;
1.4550 + }
1.4551 +
1.4552 +TInt DMasterIni::AllocateFrameBuffers(TInt aScreenNumber, TInt aCount, TInt aSize)
1.4553 + {
1.4554 + while (aCount--)
1.4555 + {
1.4556 + TInt r = AllocateOneFrameBuffer(aSize, masterIni->iBufferSet[aScreenNumber].iScreenBuffer);
1.4557 + if (r != KErrNone)
1.4558 + {
1.4559 + return r;
1.4560 + }
1.4561 + }
1.4562 + return KErrNone;
1.4563 + }
1.4564 +
1.4565 +void DMasterIni::ReleaseFrameBuffers(TInt aScreenNumber)
1.4566 + {
1.4567 + RPointerArray<TAny>& frameBuffers = masterIni->iBufferSet[aScreenNumber].iScreenBuffer.iFrameBuffers;
1.4568 + RPointerArray<TBufferAddressA>& memChunks = masterIni->iBufferSet[aScreenNumber].iScreenBuffer.iMemChunks;
1.4569 + RPointerArray<TBufferAddressA>& dsaChunks = masterIni->iBufferSet[aScreenNumber].iDsaBuffer.iMemChunks;
1.4570 +
1.4571 + NKern::ThreadEnterCS();
1.4572 + TInt index;
1.4573 + TInt count = memChunks.Count();
1.4574 + for (index = 0; index < count; index++)
1.4575 + {
1.4576 + Kern::ChunkClose(memChunks[index]->iChunk);
1.4577 + }
1.4578 + count = dsaChunks.Count();
1.4579 + for (index = 0; index < count; index++)
1.4580 + {
1.4581 + Kern::ChunkClose(dsaChunks[index]->iChunk);
1.4582 + }
1.4583 + NKern::ThreadLeaveCS();
1.4584 +
1.4585 + frameBuffers.Reset();
1.4586 + memChunks.Reset();
1.4587 + dsaChunks.Reset();
1.4588 + }
1.4589 +
1.4590 +
1.4591 +TProcessAddrEntry::TProcessAddrEntry(DProcess *aProcess, TUint8* aAddress):
1.4592 + iProcess(aProcess), iAddress(aAddress)
1.4593 + {
1.4594 + }
1.4595 +
1.4596 +
1.4597 +/**
1.4598 +Contruct a Shared Chunk cleanup object which will be used to clean up
1.4599 +after the process/address table entry.
1.4600 +*/
1.4601 +TChunkCleanup::TChunkCleanup(DProcess* aProcess, TInt aScreenNumber)
1.4602 + : TDfc((TDfcFn)TChunkCleanup::ChunkDestroyed,this,Kern::SvMsgQue(),0)
1.4603 + , iProcess(aProcess)
1.4604 + , iScreenNumber(aScreenNumber)
1.4605 + , iIndex(-1)
1.4606 + {}
1.4607 +
1.4608 +/**
1.4609 +Cancel the action of the cleanup object.
1.4610 +*/
1.4611 +void TChunkCleanup::Cancel()
1.4612 + {
1.4613 + // Clear iProcess which means that when the DFC gets queued on chunk destruction
1.4614 + // our ChunkDestroyed method will do nothing other than cleanup itself.
1.4615 + iProcess = NULL;
1.4616 + }
1.4617 +
1.4618 +/**
1.4619 +Callback function called when the DFC runs, i.e. when a chunk is destroyed.
1.4620 +*/
1.4621 +void TChunkCleanup::ChunkDestroyed(TChunkCleanup* aSelf)
1.4622 + {
1.4623 + DProcess* process = aSelf->iProcess;
1.4624 + TInt screenNumber = aSelf->iScreenNumber;
1.4625 + TUint index = aSelf->iIndex;
1.4626 + // If we haven't been Cancelled...
1.4627 + if(process && index != -1)
1.4628 + {
1.4629 + if (masterIni->iBufferSet[screenNumber].iProcAddrTable[index].iProcess == process)
1.4630 + {
1.4631 + masterIni->iBufferSet[screenNumber].iProcAddrTable[index].iProcess = 0;
1.4632 + }
1.4633 + else
1.4634 + {
1.4635 + __KTRACE_OPT(KEXTENSION,Kern::Printf("Oops! Someone has messed up our process index!"));
1.4636 + }
1.4637 + }
1.4638 +
1.4639 + // We've finished so now delete ourself
1.4640 + delete aSelf;
1.4641 + }
1.4642 +
1.4643 +
1.4644 +TInt DMasterIni::DisplayMemoryHandle(TInt aScreenNumber, TInt& aHandle)
1.4645 + {
1.4646 + if (iBufferSet[aScreenNumber].iDsaBuffer.iMemChunks.Count() == 0)
1.4647 + {
1.4648 + int r;
1.4649 + r = AllocateOneFrameBuffer(iMaxSizeInBytes, iBufferSet[aScreenNumber].iDsaBuffer);
1.4650 + if (KErrNone != r)
1.4651 + {
1.4652 + return r;
1.4653 + }
1.4654 + __ASSERT_DEBUG(iBufferSet[aScreenNumber].iDisplayChannel, Fault(EGuiNoDisplayChannel));
1.4655 + iBufferSet[aScreenNumber].iDisplayChannel->SetLegacyBuffer(iBufferSet[aScreenNumber].iDsaBuffer.iFrameBuffers[0]);
1.4656 + }
1.4657 +
1.4658 + aHandle = Kern::MakeHandleAndOpen(&Kern::CurrentThread(),
1.4659 + iBufferSet[aScreenNumber].iDsaBuffer.iMemChunks[0]->iChunk);
1.4660 +
1.4661 + if (aHandle < 0)
1.4662 + {
1.4663 + return aHandle;
1.4664 + }
1.4665 +
1.4666 + return KErrNone;
1.4667 + }
1.4668 +
1.4669 +
1.4670 +
1.4671 +// Find the address of the display memory.
1.4672 +TInt DMasterIni::DisplayMemoryAddress(TInt aScreenNumber, TInt& aAddress)
1.4673 + {
1.4674 + TBufferSet &bufferSet = iBufferSet[aScreenNumber];
1.4675 + DProcess *process = &Kern::CurrentProcess();
1.4676 + TInt firstFree = -1;
1.4677 + NKern::FMWait(&iLock);
1.4678 + TUint count = bufferSet.iProcAddrTable.Count();
1.4679 + for(TUint i = 0; i < count; ++i)
1.4680 + {
1.4681 + DProcess *curProcess = bufferSet.iProcAddrTable[i].iProcess;
1.4682 + if (curProcess == process)
1.4683 + {
1.4684 + aAddress = reinterpret_cast<TInt>(bufferSet.iProcAddrTable[i].iAddress);
1.4685 + NKern::FMSignal(&iLock);
1.4686 + return KErrNone;
1.4687 + }
1.4688 + if (curProcess == 0 && firstFree == -1)
1.4689 + {
1.4690 + firstFree = i;
1.4691 + }
1.4692 + }
1.4693 + NKern::FMSignal(&iLock);
1.4694 + // If we get here, we couldn't find the process in the iProcAddrTable.
1.4695 + // Create a new Process Address entry.
1.4696 + // Step 1
1.4697 + // Create a dummy chunk so that we can detect when the process dies,
1.4698 + // give a handle to the user [but don't actually let the process KNOW what the handle is
1.4699 + // so the user process can't do anything silly with the chunk]. Close our side of the
1.4700 + // chunk to make sure there is only one reference to it.
1.4701 + DChunk* chunk = 0;
1.4702 + // find page size for one page.
1.4703 + TUint round = Kern::RoundToPageSize(1);
1.4704 + TLinAddr chunkKernelAddr = 0;
1.4705 + TUint32 chunkMapAttr = 0;
1.4706 +
1.4707 + // create shared chunk
1.4708 + NKern::ThreadEnterCS();
1.4709 + // Cleanup object, used to issue a DFC when the chunk is closed (and
1.4710 + // as the handle of the chunk is not given to the process, it can only
1.4711 + // be closed when the process terminates!)
1.4712 + TChunkCleanup *cleanup = new TChunkCleanup(process, aScreenNumber);
1.4713 + if (!cleanup)
1.4714 + {
1.4715 + NKern::ThreadLeaveCS();
1.4716 + return KErrNoMemory;
1.4717 + }
1.4718 +
1.4719 + TChunkCreateInfo info;
1.4720 + info.iType = TChunkCreateInfo::ESharedKernelMultiple;
1.4721 + info.iMaxSize = round;
1.4722 + info.iMapAttr = 0;
1.4723 + info.iOwnsMemory = ETrue;
1.4724 + info.iDestroyedDfc = cleanup;
1.4725 +
1.4726 + TInt r = Kern::ChunkCreate(info, chunk, chunkKernelAddr, chunkMapAttr);
1.4727 +
1.4728 + if (r != KErrNone)
1.4729 + {
1.4730 + delete cleanup;
1.4731 + NKern::ThreadLeaveCS();
1.4732 + return r;
1.4733 + }
1.4734 +
1.4735 +
1.4736 + // Create a new handle for the user thread.
1.4737 + r = Kern::MakeHandleAndOpen(&Kern::CurrentThread(), chunk);
1.4738 + Kern::ChunkClose(chunk);
1.4739 + if (r <= 0)
1.4740 + {
1.4741 + NKern::ThreadLeaveCS();
1.4742 + return r;
1.4743 + }
1.4744 +
1.4745 + // Step 2
1.4746 + // Create a second handle for the chunk to the DSA buffer.
1.4747 + // First part: Make sure there is a DisplayMemoryHandle;
1.4748 + TInt handle = 0;
1.4749 + r = DisplayMemoryHandle(aScreenNumber, handle);
1.4750 + if (r != KErrNone)
1.4751 + {
1.4752 + Kern::ChunkClose(chunk);
1.4753 + NKern::ThreadLeaveCS();
1.4754 + return r;
1.4755 + }
1.4756 +
1.4757 + DChunk *dsaChunk = bufferSet.iDsaBuffer.iMemChunks[0]->iChunk;
1.4758 +
1.4759 + // Step 3
1.4760 + // Get the base addrss and insert into table.
1.4761 + TUint8* baseAddress = Kern::ChunkUserBase(dsaChunk, &Kern::CurrentThread());
1.4762 + NKern::FMWait(&iLock);
1.4763 + // Optimistically, the place we found earlier in the table is still free.
1.4764 + if (firstFree != -1 && bufferSet.iProcAddrTable[firstFree].iProcess != 0)
1.4765 + {
1.4766 + // If not, we go find another one.
1.4767 + firstFree = -1;
1.4768 + TUint count = bufferSet.iProcAddrTable.Count();
1.4769 + for(TUint i = 0; i < count; ++i)
1.4770 + {
1.4771 + if (bufferSet.iProcAddrTable[i].iProcess == 0)
1.4772 + {
1.4773 + firstFree = i;
1.4774 + break;
1.4775 + }
1.4776 + }
1.4777 + }
1.4778 + // Check if there is a free entry - if so, re-use it.
1.4779 + if (firstFree != -1)
1.4780 + {
1.4781 + bufferSet.iProcAddrTable[firstFree].iProcess = process;
1.4782 + bufferSet.iProcAddrTable[firstFree].iAddress = baseAddress;
1.4783 + cleanup->SetIndex(firstFree);
1.4784 + NKern::FMSignal(&iLock);
1.4785 + }
1.4786 + else
1.4787 + {
1.4788 + // No free entry. Append it to the list.
1.4789 + NKern::FMSignal(&iLock);
1.4790 + TProcessAddrEntry entry(process, baseAddress);
1.4791 + r = bufferSet.iProcAddrTable.Append(entry);
1.4792 + if (r != KErrNone)
1.4793 + {
1.4794 + Kern::ChunkClose(chunk);
1.4795 + NKern::ThreadLeaveCS();
1.4796 + return r;
1.4797 + }
1.4798 + // We added it at the end - so we start from the back and check for the
1.4799 + // process, as some other process COULD have added one after us, so we
1.4800 + // can't just use the count for index!
1.4801 + TUint index;
1.4802 + for(index = bufferSet.iProcAddrTable.Count()-1; index; --index)
1.4803 + {
1.4804 + if (bufferSet.iProcAddrTable[index].iProcess == process
1.4805 + && bufferSet.iProcAddrTable[index].iAddress != baseAddress)
1.4806 + {
1.4807 + break;
1.4808 + }
1.4809 + }
1.4810 + cleanup->SetIndex(index);
1.4811 + }
1.4812 + aAddress = reinterpret_cast<TInt>(baseAddress);
1.4813 +
1.4814 + NKern::ThreadLeaveCS();
1.4815 + return KErrNone;
1.4816 + }
1.4817 +
1.4818 +EXPORT_C TInt WinsGui::CurrentConfiguration()
1.4819 + {
1.4820 + return ::CurrentConfiguration;
1.4821 + }
1.4822 +
1.4823 +GLDEF_C void Fault(TGuiPanic aPanic)
1.4824 + {
1.4825 + Kern::Fault("WINS-UI",aPanic);
1.4826 + }
1.4827 +
1.4828 +DECLARE_STANDARD_EXTENSION()
1.4829 + {
1.4830 + __KTRACE_OPT(KEXTENSION,Kern::Printf("Starting Emulator GUI"));
1.4831 +
1.4832 + // if NoGui property == true do nothing
1.4833 + if (Property::GetBool("NoGui",EFalse))
1.4834 + return KErrNone;
1.4835 +
1.4836 + // create keyboard driver
1.4837 + TInt r=KErrNoMemory;
1.4838 + masterIni = new DMasterIni;
1.4839 + if (masterIni)
1.4840 + {
1.4841 + r = masterIni->Create();
1.4842 + if (r!= KErrNone)
1.4843 + {
1.4844 + return r;
1.4845 + }
1.4846 + }
1.4847 +
1.4848 + DMultiTouch::iMultiTouchSupported = DMultiTouch::Init();
1.4849 +
1.4850 + // Create multitouch when necessary
1.4851 + if (systemIni->MultiTouchEnabled() && systemIni->GCEEnabled() && DMultiTouch::iMultiTouchSupported)
1.4852 + {
1.4853 + TheMultiTouch = new DMultiTouch(systemIni->MultiTouchProximityStep(),systemIni->MultiTouchPressureStep());
1.4854 + if(!TheMultiTouch)
1.4855 + {
1.4856 + r = KErrNoMemory;
1.4857 + __KTRACE_OPT(KEXTENSION,Kern::Printf("Returns %d",r));
1.4858 + return r;
1.4859 + }
1.4860 + DMultiTouch::iMultiTouchCreated = TRUE;
1.4861 + }
1.4862 +
1.4863 + __KTRACE_OPT(KEXTENSION,Kern::Printf("Returns %d",r));
1.4864 + return r;
1.4865 + }
1.4866 +
1.4867 +TInt DWinsUi::DoDefineEmulatorControlHotKey(TAny* aPtr, const char* aValue)
1.4868 + {
1.4869 + return static_cast<DWinsUi*>(aPtr)->DefineEmulatorControlHotKey(aValue);
1.4870 + }
1.4871 +
1.4872 +
1.4873 +TInt DWinsUi::DefineEmulatorControlHotKey(const char* aValue)
1.4874 + {
1.4875 + const char* beg = skipws(aValue);
1.4876 + const char* end = skiptok(beg);
1.4877 + TInt err = KErrNone;
1.4878 +
1.4879 + TEmulCommand command = ENoCommand;
1.4880 + TInt data = 0;
1.4881 + if (_strnicmp(beg, "SelectConfig", end-beg) == 0)
1.4882 + {
1.4883 + //get the int param which is the config to switch to
1.4884 + beg = end;
1.4885 + char * e;
1.4886 + data = strtol(beg, &e,0);
1.4887 + if (beg == e)
1.4888 + err = KErrArgument;
1.4889 + end = e;
1.4890 + command = ESelectConfig;
1.4891 + }
1.4892 + else if(_strnicmp(beg, "NextConfig", end-beg) == 0)
1.4893 + {
1.4894 + command = ENextConfig;
1.4895 + }
1.4896 + else
1.4897 + {
1.4898 + err = KErrArgument;
1.4899 + }
1.4900 + if (err != KErrNone)
1.4901 + return err;
1.4902 +
1.4903 + // get the keys
1.4904 + KeyCombination* pCombination = new KeyCombination(data, command);
1.4905 + if (!pCombination)
1.4906 + return KErrNoMemory;
1.4907 +
1.4908 + beg = skipws(end);
1.4909 + const char* end2;
1.4910 + for (TInt i=0;i<KMaxHotKeyCombinationLength;i++)
1.4911 + {
1.4912 + TInt key=KErrNotFound;
1.4913 + end2 = skiptok(beg);
1.4914 + TPtrC8 name((const TUint8*)beg, end2-beg);
1.4915 + if ((key=iKeyboard.GetScanCode(name))!=KErrNotFound)
1.4916 + pCombination->AddKey((TStdScanCode)key);
1.4917 +
1.4918 + if (beg == end2 || *end2++ != ',')
1.4919 + break;
1.4920 + beg = end2;
1.4921 + }
1.4922 + return iControlHotKeys.Append(pCombination);
1.4923 + }