os/boardsupport/emulator/emulatorbsp/inc/gui.h
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
     1 // Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     4 // under the terms of "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 //
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
    10 //
    11 // Contributors:
    12 //
    13 // Description:
    14 // wins\inc\gui.h
    15 // 
    16 //
    17 
    18 #ifndef __EX_GUI_H__
    19 #define __EX_GUI_H__
    20 
    21 #define _CRTIMP			// we want to use the win32 static runtime library
    22 
    23 #include "platform.h"
    24 #include <kernel/win32/property.h>
    25 #include "nk_priv.h"
    26 #include "vwins.h"
    27 #include <e32keys.h>
    28 #include <stdlib.h>
    29 #include <videodriver.h>
    30 #include <dispchannel.h>
    31 
    32 GLREF_C const char* skipws(const char* aPtr);
    33 GLREF_C const char* skiptok(const char* aPtr);
    34 
    35 // keyboard mapping
    36 
    37 const TUint KKeyExtendedBit=0x100;
    38 const TUint KKeyNormalBits=0xFF;
    39 const TInt KMaxExtendedKey=0x5d;
    40 const TInt KExtendedKeyBase=0x1c;
    41 const TInt KStandardKeyMapSize = 89;
    42 const TInt KExtendedKeyMapSize = KMaxExtendedKey + 1 - KExtendedKeyBase;
    43 const TUint KMaxHotKeyCombinationLength=10;
    44 const TInt KDatFileVersion= 1000;
    45 
    46 enum TEmulCommand
    47 	{
    48 	ENoCommand,
    49 	EKey,
    50 	ENextConfig,
    51 	ESelectConfig,
    52 	};
    53 
    54 class VirtualKey
    55 	{
    56 public:
    57 	VirtualKey(const TInt aCommandData, TEmulCommand aCommand);
    58 	virtual TBool Contains(TInt aX, TInt aY) const = 0;
    59 	virtual void Draw(HDC aHdc,COLORREF aColor) const =0;
    60 	inline TInt Value() const {return iData;};
    61 	inline TEmulCommand Command() const {return iCommand;};
    62 private:
    63 	TEmulCommand iCommand;
    64 	TInt iData;
    65 	};
    66 
    67 typedef TStdScanCode KeyArray[KMaxHotKeyCombinationLength];
    68 class KeyCombination
    69 	{
    70 public:
    71 	KeyCombination(const TInt aCommandData, TEmulCommand aCommand);
    72 	TBool AddKey(TStdScanCode);
    73 	TBool CheckCombinationPressed();
    74 
    75 	TEmulCommand iCommand;
    76 	TInt iData;
    77 private:
    78 	KeyArray iCombination;
    79 	};
    80 
    81 class VKRect : public VirtualKey
    82 	{
    83 public:
    84 	VKRect(const TInt aCommandData, TEmulCommand aCommand, TInt aX, TInt aY, TInt aWidth, TInt aHeight);
    85 	// From VirtualKey
    86 	TBool Contains(TInt aX, TInt aY) const;
    87 	virtual void Draw(HDC aHdc,COLORREF aColor) const;
    88 private:
    89 	TInt iLeft,iTop,iRight,iBottom;
    90 	VKRect();
    91 	};
    92 
    93 
    94 
    95 class Alias
    96 	{
    97 public:
    98 	Alias();
    99 //
   100 	TInt Add(const TDesC8& aAlias, const TDesC8& aName);
   101 	const TDesC8* operator[](const TDesC8& aAlias);
   102 private:
   103 	struct SEntry
   104 		{
   105 		TDesC8* iAlias;
   106 		TDesC8* iName;
   107 		};
   108 	static TBool Compare(const SEntry& aLhs, const SEntry& aRhs);
   109 private:
   110 	RArray<SEntry> iMap;
   111 	};
   112 
   113 // GUI settings
   114 
   115 const TInt KPowerTimerId=1;
   116 
   117 const TInt KRomMajorVersionNumber=1;
   118 const TInt KRomMinorVersionNumber=0;
   119 const TInt KRomBuildVersionNumber=1;
   120 //
   121 const TInt KScreenOffsetX=90;
   122 const TInt KScreenOffsetY=51;
   123 const TInt KScreenWidth=640;
   124 const TInt KScreenHeight=240;
   125 const TInt KWinPosX=10;
   126 const TInt KWinPosY=10;
   127 
   128 const TInt KCompositionBuffers=2;	// Default to double-buffering
   129 const TInt KRefreshRateHz=30;	// Default to 30fps
   130 
   131 const TInt KMaxNameSize=80;	//size of window title string
   132 
   133 //
   134 // window style
   135 const DWORD KInvisibleControlWinStyle=WS_CAPTION|WS_CLIPCHILDREN|WS_MINIMIZEBOX|WS_OVERLAPPED|WS_SYSMENU;
   136 const DWORD KControlWinStyle=KInvisibleControlWinStyle|WS_VISIBLE;
   137 
   138 const DWORD KInvisibleWinStyle=WS_CAPTION|WS_CLIPCHILDREN|WS_OVERLAPPED|WS_HSCROLL|WS_VSCROLL|WS_SIZEBOX|
   139 	WS_MAXIMIZEBOX|WS_MINIMIZEBOX|WS_SYSMENU;
   140 const DWORD KWinStyle=KInvisibleWinStyle|WS_VISIBLE;
   141 //
   142 // Scaling factors to use if PhysicalScreenWidth or Height are not specified
   143 const TReal KDefaultPixelsToTwipsX=11.90625;
   144 const TReal KDefaultPixelsToTwipsY=11.9083333334;
   145 //
   146 const TInt KHeapSize=0x2000;
   147 const TInt KWindowServerHeapSize=0x40000;
   148 const TInt KKeyDown=0x80;
   149 //
   150 const TInt KLedTop=45;
   151 const TInt KLedLeft=36;
   152 const TInt KLedSize=14;
   153 const TInt KLedGap=5;
   154 const TBool KLedVertical=ETrue;
   155 
   156 GLREF_C TInt MultiProperty(TInt (*aHandler)(TAny* aObj, const char*), TAny* aPtr, const char* aProperty);
   157 
   158 const TInt KSecureLedColor = 0xFFFF;
   159 
   160 class DWinsKeyboard : public DBase
   161 	{
   162 public:
   163 	DWinsKeyboard();
   164 	TInt Init(TInt aId);
   165 //
   166 	TInt ScanCodeToRemappedKey(TInt aScanCode);
   167 	static TInt ScanCodeToStandardKey(TInt aScanCode);
   168 //
   169 	TInt GetEPOCKeyCode(const TDesC8& aStr);
   170 	TInt GetScanCode(const TDesC8& aStr);
   171 private:
   172 	static TInt ScanCodeToKey(TInt aScanCode, const TUint8* aStandardMap, const TUint8* aExtendedMap);
   173 	TInt DefineAlias(const char* aValue);
   174 	static TInt DoDefineAlias(TAny* aObj, const char* aValue);
   175 	TInt MapKey(const char* aValue);
   176 	static TInt DoMapKey(TAny* aObj, const char* aValue);
   177 private:
   178 	TUint8 iStandardKeyMap[KStandardKeyMapSize];
   179 	TUint8 iExtendedKeyMap[KExtendedKeyMapSize];
   180 	TUint8 iAltStandardKeyMap[KStandardKeyMapSize];
   181 	TUint8 iAltExtendedKeyMap[KExtendedKeyMapSize];
   182 	TUint8 iCtrlStandardKeyMap[KStandardKeyMapSize];
   183 	TUint8 iCtrlExtendedKeyMap[KExtendedKeyMapSize];
   184 	Alias iAliasedKeys;
   185 	};
   186 
   187 struct TWindowState
   188 	{
   189 public:
   190 	WINDOWPLACEMENT iWinPlace;
   191 	TInt iXoffset;
   192 	TInt iYoffset;
   193 	TEmulatorFlip iFlipstate;
   194 	};
   195 
   196 class DScreenProperties;
   197 class TViewport 
   198 	{
   199 public:
   200 	TViewport();
   201 	TViewport(DScreenProperties* aScreenProps);
   202 	~TViewport();
   203 		
   204 	void UpdateScrollBarH(HWND aHwnd);
   205 	void UpdateScrollBarV(HWND aHwnd);
   206 	
   207 	TInt GetMaxWindowWidth() const;
   208 	TInt GetMaxWindowHeight() const;
   209 	TInt GetMaxWidth() const;
   210 	TInt GetMaxHeight() const;
   211 	
   212 	TInt GetViewportOffsetX() const;
   213 	TInt GetViewportOffsetY() const;
   214 		
   215 	void SetViewportWidth(TInt aWidth);
   216 	void SetViewportHeight(TInt aHeight);
   217 	TInt GetViewportWidth() const;
   218 	TInt GetViewportHeight() const;
   219 	
   220 	void ScrollToY(TInt aPosition,HWND aHwnd);
   221 	void ScrollToX(TInt aPosition, HWND aHwnd);
   222 	
   223 	void UpdateChildPos(HWND aHwnd);
   224 		
   225 private:
   226 	
   227 	void SetViewportOffsetX(TInt aOffset);
   228 	void SetViewportOffsetY(TInt aOffset);
   229 	
   230 	/**
   231 	The DScreenProperties object which owns this viewport
   232 	*/
   233 	DScreenProperties* iScreenProps;
   234 	
   235 	/**
   236 	Width in pixels of the client area of the window through which the emulator is being viewed
   237 	*/
   238 	TInt iViewportWidth;
   239 	/**
   240 	Height in pixels of the client area of the window through which the emulator is being viewed
   241 	*/
   242 	TInt iViewportHeight;
   243 	/**
   244 	X Offset of viewport edge from emulator image ie. How far viewport is translated
   245 	*/
   246 	TInt iViewportOffsetX;
   247 	/**
   248 	Y Offset of viewport edge from emulator image ie. How far viewport is translated
   249 	*/
   250 	TInt iViewportOffsetY;
   251 	
   252 	};
   253 
   254 class DScreenProperties
   255 	{
   256 friend class TViewport;
   257 public:
   258 	DScreenProperties();
   259 	~DScreenProperties();
   260 	TInt SetupProperties(TInt aConf, TInt aScreen);
   261 	TWindowState GetWindowState();
   262 public:
   263 	TInt iScreenWidth;
   264 	TInt iScreenHeight;
   265 	TInt iMaxScreenWidth;
   266 	TInt iMaxScreenHeight;
   267     TInt iXYInputWidth;
   268     TInt iXYInputHeight;
   269 	TInt iPhysicalScreenWidth;
   270 	TInt iPhysicalScreenHeight;
   271 	TInt iMaxPhysicalScreenWidth;
   272 	TInt iMaxPhysicalScreenHeight;
   273 	TInt iScreenOffsetX; 
   274 	TInt iScreenOffsetY;
   275 	TUint iColorDepth; 			///<In emulator this is a bitfield of the available modes. All other aspects of each mode are identical.
   276 	TInt iDisplayContrast;
   277 	TEmulatorFlip iScreenRotation;
   278 	CHAR iFasciaFileName[MAX_PATH];
   279 	HWND iWindowHandle;
   280 	WINDOWPLACEMENT iWinPlace; ///<Used to store the window's WINDOWPLACEMENT struct.
   281 	RECT iWinRect;
   282 	TBool iScreenOff;
   283 	TInt  iCurrentMode;		   ///<Indicates the current mode when multiple modes are supported
   284 	TInt  iMaxModes;
   285 	TInt  iModeDepths[KEmulMaxNumModes];
   286 	TInt iCompositionBuffers;
   287 	TInt iRefreshRateHz;
   288 	/**
   289 	The viewport owned by the screen
   290 	*/
   291 	TViewport iViewport;
   292 
   293 	};
   294 	
   295 
   296 class DDisplayChannel;
   297 
   298 class DWinsUi : public DWinsUiBase
   299 	{
   300 public:
   301 	DWinsUi();
   302 	TInt Create(TInt aId);
   303 //
   304 	TInt GetVirtualKey(TEmulCommand& aCommand, TInt aX, TInt aY);
   305 	void SetVirtualKey(const TBool aProcessing, const TInt aCommandData, const TEmulCommand aCommand);
   306 	TBool WasVirtualKey(TInt& aCommandData, TEmulCommand& aCommand);
   307 	void TranslateMouseCoords(const TEmulatorFlip aFlipState, const TInt aX, const TInt aY, const TInt aRegionWidth, const TInt aRegionHeight, TInt& aNewX, TInt& aNewY);
   308 
   309 	//
   310 	TBool OnScreen(TInt aScreen, TInt aX, TInt aY) const;
   311 	TBool OnDigitizer(TInt aX, TInt aY) const;
   312 	TBool MultiTouchEnabled() const;
   313 	TBool GCEEnabled() const;
   314 	TInt MultiTouchPressureStep() const;
   315 	TInt MultiTouchProximityStep() const;
   316 //private:
   317 	void ScreenInfo(TScreenInfoV01& aInfo);
   318 	TBool VideoInfo(TInt aDeviceNumber, TVideoInfoV01& aInfo);
   319 	TBool VideoInfo(TInt aDeviceNumber,TInt aModeNumber, TVideoInfoV01& aInfo);
   320 	TBool VideoInfoForDisplayDriver(TInt aDeviceNumber,TInt aModeNumber, TVideoInfoV01& aInfo, TBool aRealWidthAndHeight = EFalse);
   321 //
   322 	TInt SetupProperties(TInt aId);
   323 	TInt DefineVirtualKey(const char* aValue);
   324 	static TInt DoDefineVirtualKey(TAny* aObj, const char* aValue);
   325 	TInt DefineEmulatorControl(const char* aValue);
   326 	static TInt DoDefineEmulatorControl(TAny* aObj, const char* aValue);
   327 
   328 	static TInt DoDefineEmulatorControlHotKey(TAny* aPtr, const char* aValue);
   329 	TInt DefineEmulatorControlHotKey(const char* aValue);
   330 //	implementing DWinsUiBase
   331 	TUint ColorDepth(TInt aScreenNumber);
   332 	TInt SetFlip(TEmulatorFlip aFlip, TInt aScreenNumber);
   333 	void Info(TVariantInfoV01& aInfo);
   334 	HWND HWnd();
   335 	void SwitchDisplay(TBool aSecure);
   336 	TInt NumberOfScreens();
   337 	virtual TInt SetDisplayChannel(TInt aScreenNumber, DDisplayChannel* aDisplay);
   338 	TInt SetDisplayChannelImpl(TInt aScreenNumber, DDisplayChannel* aDisplay);
   339 public:
   340 	DWinsKeyboard iKeyboard;
   341 //
   342 	TInt iLedSize;
   343 	TInt iLedGap;
   344 	TInt iLedOffsetX;
   345 	TInt iLedOffsetY;
   346 	TBool iLedVertical;
   347 	TBuf8<0x10> iPointerType;
   348 	TXYInputType iXYInputType;
   349 	CHAR iSysIniFileName[MAX_PATH];
   350 	WINDOWPLACEMENT iWinPlace;
   351     RPointerArray<VirtualKey> iVirtualKeys;
   352 	RPointerArray<KeyCombination> iControlHotKeys;
   353 	TInt iDigitizerWidth;
   354 	TInt iDigitizerHeight;
   355 	TInt iDigitizerOffsetX;	//offset from the epoc screen 0!
   356 	TInt iDigitizerOffsetY;//offset from the epoc screen 0!
   357 	TBool iDigitizerEnabled;
   358 	CHAR iWindowTitle[KMaxNameSize+1];
   359 	TBool iDisplayVersionInfo;
   360 	TInt aId;			//configuration number;
   361 	TInt iInitialFlipMsg;
   362 	TBool iProcessingVirtualKey;
   363 	TUint iFakedVirtualKey;
   364 	TEmulCommand iVirtualKeyCommand;
   365 	RPointerArray<DScreenProperties> iScreens;
   366 private:
   367 	TBool iMultiTouchEnabled;
   368 	TBool iGCEEnabled;
   369 	TInt iMultiTouchProximityStep;
   370 	TInt iMultiTouchPressureStep;
   371 	};
   372 
   373 struct TBufferAddressA
   374 	{
   375 	DChunk* iChunk;
   376 	TAny* iAddress;
   377 	};
   378 	
   379 class TScreenBuffer
   380 	{
   381 public:	
   382 	RPointerArray<TAny> iFrameBuffers;
   383 	RPointerArray<TBufferAddressA> iMemChunks;
   384 	TInt 	iDisplayBufferOffset;    //offset to pixel data in current mode for display buffer. Mode of display buffer doesn't change we presume!
   385 	};
   386 
   387 
   388 // Chunk cleanup object - used to clean up the process/addr table when the process goes away.
   389 class TChunkCleanup : public TDfc
   390     {
   391 public:
   392     TChunkCleanup(DProcess* aProcess, TInt aScreenNumber);
   393     void Cancel();
   394     inline void SetIndex(TUint aIndex) { iIndex = aIndex; }
   395 private:
   396     static void ChunkDestroyed(TChunkCleanup* aSelf);
   397 private:
   398     DProcess* iProcess;
   399     TInt      iScreenNumber;
   400     TInt	  iIndex;
   401     };
   402 
   403 
   404 // Entry to hold the process/disp.memory address, as we need to find the address of the display
   405 // memory when requested. A new entry would be added when a process first requests the address of display
   406 // memory. When the process dies, we remove the process entry (by way of a DFC for a chunk that is 
   407 // created on behalf of that process).
   408 class TProcessAddrEntry 
   409     {
   410 public:
   411 	TProcessAddrEntry(DProcess *aProcess, TUint8* aAddress);
   412 public:
   413 	DProcess* iProcess;
   414 	TUint8* iAddress;
   415 	};
   416 
   417 
   418 
   419 class TBufferSet
   420 	{
   421 public:
   422 	TAny* iDisplayBuffer;		//current display buffer
   423 	BITMAPV4HEADER iInfo;		// This can be cast to a BITMAPINFOHEADER
   424 	TInt           iDisplayDriverCount;
   425 	TScreenBuffer  iScreenBuffer;
   426 	TScreenBuffer  iDsaBuffer;
   427 	RArray<TProcessAddrEntry> iProcAddrTable;
   428 	TInt iDisplayState;
   429 	TInt iStateChangeCount;
   430 	RDisplayChannel::TBufferFormat iBufferFormat;
   431 	DDisplayChannel* iDisplayChannel;
   432 	};
   433 
   434 class DMasterIni : public DBase
   435 	{
   436 public:
   437 	TInt SetupProperties();
   438 	TInt Create();
   439 	static TInt DoHalFunction(TAny* aPtr, TInt aFunction, TAny* a1, TAny* a2);
   440 	TInt HalFunction(TInt aDeviceNumber, TInt aFunction, TAny* a1, TAny* a2);
   441 	static TInt DoXYHalFunction(TAny* aThis, TInt aFunction, TAny* a1, TAny* a2);
   442 	TInt XYHalFunction(TInt aFunction, TAny* a1, TAny* a2);
   443 	static TInt DoMouseHalFunction(TAny* aThis, TInt aFunction, TAny* a1, TAny* a2);
   444 	TInt MouseHalFunction(TInt aFunction, TAny* a1, TAny* a2);
   445 	static TInt DoKbdHalFunction(TAny* aThis, TInt aFunction, TAny* a1, TAny* a2);
   446 
   447 	void InitBitmapHeader(DScreenProperties& aScreenProperties, LPBITMAPV4HEADER aInfo);
   448 	void InitBufferFormat(DScreenProperties& aScreenProperties, RDisplayChannel::TBufferFormat& aBufferFormat);
   449 	TInt AllocateFrameBuffers(TInt aScreenNumber, TInt aCount, TInt aSize);
   450 	void ReleaseFrameBuffers(TInt aScreenNumber);
   451 
   452 	
   453 	TInt DisplayMemoryAddress(TInt aScreenNumber, TInt& aAddress);
   454 	TInt DisplayMemoryHandle(TInt aScreenNumber, TInt& aHandle);
   455 	
   456 	void ProcessDeletedDFC();
   457 
   458 	void SetDisplaySize(TInt aDisplayNumber, TInt aWidth, TInt aHeight);
   459 	void SetBufferFormat(TInt aDisplayNumber, TUint aAgregatSize, RDisplayChannel::TPixelFormat aPixelFormat);
   460 	void SetImageSize(TInt aScreenNumber);
   461 
   462 public:
   463 	//not set or used: TInt iConfigurationCount;
   464 	RPointerArray<DWinsUi> iSystemInis;	//Indexed by config
   465 	RArray<TBufferSet>     iBufferSet;
   466 	// Fast mutex used to control access to the process/address table in the 
   467 	// TBufferSet. 
   468 	NFastMutex iLock;
   469 	TUint iMaxSizeInBytes;
   470 	static const RDisplayChannel::TPixelFormat iSupportedPixelFormatTable[];
   471 	static const TInt iSupportedPixelFormatTableSize;
   472 private:
   473 	TInt NumberOfResolutions(TInt aDeviceNumber, TAny* a1, TAny* a2);
   474 	TInt SpecificScreenInfo(TInt aDeviceNumber, TAny* a1, TAny* a2);
   475 	TInt CurrentScreenInfo(TInt aDeviceNumber, TAny* a1, TAny* a2);
   476 };
   477 
   478 
   479 GLREF_C TInt CompareI(const TDesC8& aLhs, const TDesC8& aRhs);
   480 
   481 // user-defined messages ...
   482 // flip the emulator window
   483 #define WM_FLIP_MESSAGE 0x7FFF
   484 // emulator window power state
   485 #define WM_EMUL_POWER_ON 0x7FFE
   486 
   487 //redraw client window from the internal buffer
   488 #define WM_REDRAW_WINDOW 	(WM_USER + 1)
   489 
   490 // Set the display frame buffer for this window to lParam
   491 #define WMU_SET_DISPLAY_BUFFER	(WM_USER + 2)
   492 
   493 // Set the display size for this window to (wParam,lParam)
   494 // Rotation (flip) is ignored. Current display state is used.
   495 // Configurations are searched to find a match, message is ignored if none found.
   496 #define WMU_SET_DISPLAY_SIZE	(WM_USER + 3)
   497 
   498 //modifies the header of the bitmap that is getting painted, updating the size
   499 #define WMU_SET_BUFFER_FORMAT	(WM_USER + 4)
   500 
   501 enum TGuiPanic
   502 	{
   503 	EGuiGetModuleHandle=21,
   504 	EGuiRegisterWindow=22,
   505 	EGuiKernelWindowCreate=23,
   506 	EGuiRegisterChildWindow=24,
   507 	EGuiKernelChildWindowCreate=25,
   508 	EGuiCreateBitmap=26,
   509 	EGuiChildWinProc=27,
   510 	EGuiEnterCS=28,
   511 	EGuiLeaveCS=29,
   512 	EGuiStandbyWhilstOff=30,
   513 	EGuiResetPowerEvent=31,
   514 	EGuiSetPowerEvent=32,
   515 	EGuiWaitPowerOnFailed=33,
   516 	EGuiNoDisplayChannel=34,
   517 	EGuiVideoInfoUnavailable=35,
   518 	EGuiInvalidMultiTouch=36
   519 	};
   520 
   521 GLREF_C void Fault(TGuiPanic aPanic);
   522 
   523 #endif