Update contrib.
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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
21 #define _CRTIMP // we want to use the win32 static runtime library
24 #include <kernel/win32/property.h>
29 #include <videodriver.h>
30 #include <dispchannel.h>
32 GLREF_C const char* skipws(const char* aPtr);
33 GLREF_C const char* skiptok(const char* aPtr);
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;
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;};
63 TEmulCommand iCommand;
67 typedef TStdScanCode KeyArray[KMaxHotKeyCombinationLength];
71 KeyCombination(const TInt aCommandData, TEmulCommand aCommand);
72 TBool AddKey(TStdScanCode);
73 TBool CheckCombinationPressed();
75 TEmulCommand iCommand;
78 KeyArray iCombination;
81 class VKRect : public VirtualKey
84 VKRect(const TInt aCommandData, TEmulCommand aCommand, TInt aX, TInt aY, TInt aWidth, TInt aHeight);
86 TBool Contains(TInt aX, TInt aY) const;
87 virtual void Draw(HDC aHdc,COLORREF aColor) const;
89 TInt iLeft,iTop,iRight,iBottom;
100 TInt Add(const TDesC8& aAlias, const TDesC8& aName);
101 const TDesC8* operator[](const TDesC8& aAlias);
108 static TBool Compare(const SEntry& aLhs, const SEntry& aRhs);
115 const TInt KPowerTimerId=1;
117 const TInt KRomMajorVersionNumber=1;
118 const TInt KRomMinorVersionNumber=0;
119 const TInt KRomBuildVersionNumber=1;
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;
128 const TInt KCompositionBuffers=2; // Default to double-buffering
129 const TInt KRefreshRateHz=30; // Default to 30fps
131 const TInt KMaxNameSize=80; //size of window title string
135 const DWORD KInvisibleControlWinStyle=WS_CAPTION|WS_CLIPCHILDREN|WS_MINIMIZEBOX|WS_OVERLAPPED|WS_SYSMENU;
136 const DWORD KControlWinStyle=KInvisibleControlWinStyle|WS_VISIBLE;
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;
142 // Scaling factors to use if PhysicalScreenWidth or Height are not specified
143 const TReal KDefaultPixelsToTwipsX=11.90625;
144 const TReal KDefaultPixelsToTwipsY=11.9083333334;
146 const TInt KHeapSize=0x2000;
147 const TInt KWindowServerHeapSize=0x40000;
148 const TInt KKeyDown=0x80;
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;
156 GLREF_C TInt MultiProperty(TInt (*aHandler)(TAny* aObj, const char*), TAny* aPtr, const char* aProperty);
158 const TInt KSecureLedColor = 0xFFFF;
160 class DWinsKeyboard : public DBase
166 TInt ScanCodeToRemappedKey(TInt aScanCode);
167 static TInt ScanCodeToStandardKey(TInt aScanCode);
169 TInt GetEPOCKeyCode(const TDesC8& aStr);
170 TInt GetScanCode(const TDesC8& aStr);
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);
178 TUint8 iStandardKeyMap[KStandardKeyMapSize];
179 TUint8 iExtendedKeyMap[KExtendedKeyMapSize];
180 TUint8 iAltStandardKeyMap[KStandardKeyMapSize];
181 TUint8 iAltExtendedKeyMap[KExtendedKeyMapSize];
182 TUint8 iCtrlStandardKeyMap[KStandardKeyMapSize];
183 TUint8 iCtrlExtendedKeyMap[KExtendedKeyMapSize];
190 WINDOWPLACEMENT iWinPlace;
193 TEmulatorFlip iFlipstate;
196 class DScreenProperties;
201 TViewport(DScreenProperties* aScreenProps);
204 void UpdateScrollBarH(HWND aHwnd);
205 void UpdateScrollBarV(HWND aHwnd);
207 TInt GetMaxWindowWidth() const;
208 TInt GetMaxWindowHeight() const;
209 TInt GetMaxWidth() const;
210 TInt GetMaxHeight() const;
212 TInt GetViewportOffsetX() const;
213 TInt GetViewportOffsetY() const;
215 void SetViewportWidth(TInt aWidth);
216 void SetViewportHeight(TInt aHeight);
217 TInt GetViewportWidth() const;
218 TInt GetViewportHeight() const;
220 void ScrollToY(TInt aPosition,HWND aHwnd);
221 void ScrollToX(TInt aPosition, HWND aHwnd);
223 void UpdateChildPos(HWND aHwnd);
227 void SetViewportOffsetX(TInt aOffset);
228 void SetViewportOffsetY(TInt aOffset);
231 The DScreenProperties object which owns this viewport
233 DScreenProperties* iScreenProps;
236 Width in pixels of the client area of the window through which the emulator is being viewed
240 Height in pixels of the client area of the window through which the emulator is being viewed
242 TInt iViewportHeight;
244 X Offset of viewport edge from emulator image ie. How far viewport is translated
246 TInt iViewportOffsetX;
248 Y Offset of viewport edge from emulator image ie. How far viewport is translated
250 TInt iViewportOffsetY;
254 class DScreenProperties
256 friend class TViewport;
259 ~DScreenProperties();
260 TInt SetupProperties(TInt aConf, TInt aScreen);
261 TWindowState GetWindowState();
265 TInt iMaxScreenWidth;
266 TInt iMaxScreenHeight;
269 TInt iPhysicalScreenWidth;
270 TInt iPhysicalScreenHeight;
271 TInt iMaxPhysicalScreenWidth;
272 TInt iMaxPhysicalScreenHeight;
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];
280 WINDOWPLACEMENT iWinPlace; ///<Used to store the window's WINDOWPLACEMENT struct.
283 TInt iCurrentMode; ///<Indicates the current mode when multiple modes are supported
285 TInt iModeDepths[KEmulMaxNumModes];
286 TInt iCompositionBuffers;
289 The viewport owned by the screen
296 class DDisplayChannel;
298 class DWinsUi : public DWinsUiBase
302 TInt Create(TInt aId);
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);
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;
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);
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);
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);
335 void SwitchDisplay(TBool aSecure);
336 TInt NumberOfScreens();
337 virtual TInt SetDisplayChannel(TInt aScreenNumber, DDisplayChannel* aDisplay);
338 TInt SetDisplayChannelImpl(TInt aScreenNumber, DDisplayChannel* aDisplay);
340 DWinsKeyboard iKeyboard;
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;
367 TBool iMultiTouchEnabled;
369 TInt iMultiTouchProximityStep;
370 TInt iMultiTouchPressureStep;
373 struct TBufferAddressA
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!
388 // Chunk cleanup object - used to clean up the process/addr table when the process goes away.
389 class TChunkCleanup : public TDfc
392 TChunkCleanup(DProcess* aProcess, TInt aScreenNumber);
394 inline void SetIndex(TUint aIndex) { iIndex = aIndex; }
396 static void ChunkDestroyed(TChunkCleanup* aSelf);
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
411 TProcessAddrEntry(DProcess *aProcess, TUint8* aAddress);
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;
429 TInt iStateChangeCount;
430 RDisplayChannel::TBufferFormat iBufferFormat;
431 DDisplayChannel* iDisplayChannel;
434 class DMasterIni : public DBase
437 TInt SetupProperties();
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);
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);
453 TInt DisplayMemoryAddress(TInt aScreenNumber, TInt& aAddress);
454 TInt DisplayMemoryHandle(TInt aScreenNumber, TInt& aHandle);
456 void ProcessDeletedDFC();
458 void SetDisplaySize(TInt aDisplayNumber, TInt aWidth, TInt aHeight);
459 void SetBufferFormat(TInt aDisplayNumber, TUint aAgregatSize, RDisplayChannel::TPixelFormat aPixelFormat);
460 void SetImageSize(TInt aScreenNumber);
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
469 TUint iMaxSizeInBytes;
470 static const RDisplayChannel::TPixelFormat iSupportedPixelFormatTable[];
471 static const TInt iSupportedPixelFormatTableSize;
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);
479 GLREF_C TInt CompareI(const TDesC8& aLhs, const TDesC8& aRhs);
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
487 //redraw client window from the internal buffer
488 #define WM_REDRAW_WINDOW (WM_USER + 1)
490 // Set the display frame buffer for this window to lParam
491 #define WMU_SET_DISPLAY_BUFFER (WM_USER + 2)
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)
498 //modifies the header of the bitmap that is getting painted, updating the size
499 #define WMU_SET_BUFFER_FORMAT (WM_USER + 4)
503 EGuiGetModuleHandle=21,
504 EGuiRegisterWindow=22,
505 EGuiKernelWindowCreate=23,
506 EGuiRegisterChildWindow=24,
507 EGuiKernelChildWindowCreate=25,
512 EGuiStandbyWhilstOff=30,
513 EGuiResetPowerEvent=31,
514 EGuiSetPowerEvent=32,
515 EGuiWaitPowerOnFailed=33,
516 EGuiNoDisplayChannel=34,
517 EGuiVideoInfoUnavailable=35,
518 EGuiInvalidMultiTouch=36
521 GLREF_C void Fault(TGuiPanic aPanic);