0033661: Data Exchange, Step Import - Tessellated GDTs are not imported
[occt.git] / src / WNT / WNT_Window.cxx
old mode 100755 (executable)
new mode 100644 (file)
index 134e1e6..fff0080
 // Copyright (c) 1998-1999 Matra Datavision
-// Copyright (c) 1999-2012 OPEN CASCADE SAS
+// Copyright (c) 1999-2014 OPEN CASCADE SAS
 //
-// The content of this file is subject to the Open CASCADE Technology Public
-// License Version 6.5 (the "License"). You may not use the content of this file
-// except in compliance with the License. Please obtain a copy of the License
-// at http://www.opencascade.org and read it completely before using this file.
+// This file is part of Open CASCADE Technology software library.
 //
-// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
-// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
+// This library is free software; you can redistribute it and/or modify it under
+// the terms of the GNU Lesser General Public License version 2.1 as published
+// by the Free Software Foundation, with special exception defined in the file
+// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
+// distribution for complete text of the license and disclaimer of any warranty.
 //
-// The Original Code and all software distributed under the License is
-// distributed on an "AS IS" basis, without warranty of any kind, and the
-// Initial Developer hereby disclaims all such warranties, including without
-// limitation, any warranties of merchantability, fitness for a particular
-// purpose or non-infringement. Please see the License for the specific terms
-// and conditions governing the rights and limitations under the License.
-
-// Modifications: PLOTNIKOV Eugeny at July 1998 (BUC60286)
-//                TCL              at October 2000 (G002)
-//                new method SetBackground(CString aName)
-
-// include windows.h first to have all definitions available
-#include <windows.h>
-
-//                GG 07/03/00 Add MMSize() method
-
-#include <WNT_Window.ixx>
-
-#include <Image_AlienPixMap.hxx>
-#include <Aspect_Convert.hxx>
-
-#include <stdio.h>
-extern "C" void _debug_break ( char* );
-//************************************************************************//
-//***//
-// callback function to manage window's background
-extern LRESULT CALLBACK WNT_WndProc (
-                         HWND, UINT, WPARAM, LPARAM
-                        );
-//***//
-#define SELECT_PALETTE(hDC)                                  \
- HPALETTE hOldPal;                                           \
-                                                             \
-  if ( myExtraData.hPal  ) {                                 \
-                                                             \
-   hOldPal = SelectPalette ( hDC, myExtraData.hPal, FALSE ); \
-                                                             \
-   if (  RealizePalette ( hDC )  )                           \
-                                                             \
-    UpdateColors ( hDC );                                    \
-                                                             \
-  }  // end if
-//***//
-#define UNSELECT_PALETTE(hDC)            \
- if ( myExtraData.hPal )                 \
-                                         \
-  SelectPalette ( hDC, hOldPal, FALSE );
-
-HBITMAP LoadImageFromFile (  Handle( WNT_GraphicDevice )&, char*, HDC = NULL  );
-
-//***//
-//************************* Constructor **********************************//
-//***//
-// TODO - Here is enough of duplicated code in 1st and second constructors!
-WNT_Window::WNT_Window (const Handle(WNT_GraphicDevice)& theDevice,
-                        const Standard_CString           theTitle,
-                        const Handle(WNT_WClass)&        theClass,
-                        const WNT_Dword&                 theStyle,
-                        const Quantity_Parameter         theXc,
-                        const Quantity_Parameter         theYc,
-                        const Quantity_Parameter         theWidth,
-                        const Quantity_Parameter         theHeight,
-                        const Quantity_NameOfColor       theBackColor,
-                        const Aspect_Handle              theParent,
-                        const Aspect_Handle              theMenu,
-                        const Standard_Address           theClientStruct)
-: Aspect_Window (theDevice),
-  myWClass (theClass)
-{
-  ZeroMemory (&myExtraData, sizeof (WNT_WindowData));
-  DWORD dwStyle = theStyle;
-  const Handle(WNT_GraphicDevice)& aDev = Handle(WNT_GraphicDevice)::DownCast (MyGraphicDevice);
+// Alternatively, this file may be used under the terms of Open CASCADE
+// commercial license or contractual agreement.
 
-  if (theXc < 0.0 || theXc > 1.0 || theYc < 0.0 || theYc > 1.0 ||
-      theWidth <= 0.0 || theHeight <= 0.0)
-  {
-    Aspect_WindowDefinitionError::Raise ("Coordinate(s) out of range");
-  }
+#if defined(_WIN32)
+  // include windows.h first to have all definitions available
+  #include <windows.h>
+#endif
 
-  Standard_Integer aParentSizeX, aParentSizeY;
-  if (theParent)
-  {
-    RECT aRect;
-    GetClientRect ((HWND )theParent, &aRect);
-    aParentSizeX = aRect.right;
-    aParentSizeY = aRect.bottom;
-  }
-  else
-  {
-    aDev->DisplaySize (aParentSizeX, aParentSizeY);
-  }
+#include <WNT_Window.hxx>
 
-  Standard_Integer aPxWidth, aPxHeight;
-  Aspect_Convert::ConvertCoordinates (aParentSizeX, aParentSizeY,
-                                      theXc, theYc, theWidth, theHeight,
-                                      aXLeft, aYTop, aPxWidth, aPxHeight);
-  Aspect_Convert::FitIn (aParentSizeX, aParentSizeY,
-                         aXLeft, aYTop, aPxWidth, aPxHeight);
-  aXRight  = aXLeft + aPxWidth;
-  aYBottom = aYTop + aPxHeight;
+#if defined(_WIN32) && !defined(OCCT_UWP)
 
-  if (theParent && !(theStyle & WS_CHILD))
-  {
-    dwStyle |= WS_CHILD | WS_CLIPSIBLINGS;
-  }
-  else if (!theParent && !(theStyle & WS_CLIPCHILDREN))
-  {
-    dwStyle |= WS_CLIPCHILDREN;
-  }
+#include <Aspect_ScrollDelta.hxx>
+#include <Aspect_WindowDefinitionError.hxx>
+#include <Aspect_WindowInputListener.hxx>
+#include <Message.hxx>
+#include <NCollection_LocalArray.hxx>
+#include <TCollection_ExtendedString.hxx>
+#include <WNT_WClass.hxx>
+#include <WNT_HIDSpaceMouse.hxx>
 
-  if (dwStyle & WS_OVERLAPPEDWINDOW)
-  {
-    // include decorations in the window dimensions
-    // to reproduce same behaviour of Xw_Window.
-    aXLeft   -= GetSystemMetrics(SM_CXSIZEFRAME);
-    aYTop    -= GetSystemMetrics(SM_CYSIZEFRAME) + GetSystemMetrics(SM_CYCAPTION);
-    aXRight  += GetSystemMetrics(SM_CXSIZEFRAME);
-    aYBottom += GetSystemMetrics(SM_CYSIZEFRAME);
-  }
+IMPLEMENT_STANDARD_RTTIEXT(WNT_Window, Aspect_Window)
 
-  myHWindow = CreateWindow (
-              myWClass->Name(),                 // window's class name
-              theTitle,                         // window's name
-              dwStyle,                          // window's style
-              aXLeft, aYTop,                    // window's coordinates
-              (aXRight - aXLeft), (aYBottom - aYTop),
-              (HWND )theParent,                 // window's parent
-              (HMENU )theMenu,                    // window's menu
-              (HINSTANCE )myWClass->Instance(), // application's instance
-              theClientStruct);                 // pointer to CLIENTCREATESTRUCT
-  if (!myHWindow)
+#ifndef MOUSEEVENTF_FROMTOUCH
+#define MOUSEEVENTF_FROMTOUCH 0xFF515700
+#endif
+
+//! Auxiliary tool for handling WM_TOUCH events.
+//! Dynamically loads functions from User32 available since Win7 and later.
+class WNT_Window::TouchInputHelper : public Standard_Transient
+{
+public:
+  typedef BOOL (WINAPI *RegisterTouchWindow_t)(HWND hwnd, ULONG ulFlags);
+  typedef BOOL (WINAPI *UnregisterTouchWindow_t)(HWND hwnd);
+  typedef BOOL (WINAPI *GetTouchInputInfo_t)(HTOUCHINPUT hTouchInput,
+                                             UINT cInputs,
+                                             PTOUCHINPUT pInputs,
+                                             int         cbSize);
+  typedef BOOL (WINAPI *CloseTouchInputHandle_t)(HTOUCHINPUT hTouchInput);
+
+  typedef NCollection_LocalArray<TOUCHINPUT, 16> InnerTouchArray;
+
+public:
+
+  //! Main constructor.
+  TouchInputHelper()
+  : myRegisterTouchWindow (NULL),
+    myUnregisterTouchWindow (NULL),
+    myGetTouchInputInfo (NULL),
+    myCloseTouchInputHandle (NULL),
+    myIsRegistered (false)
   {
-    Aspect_WindowDefinitionError::Raise ("Unable to create window");
+    HMODULE aUser32Module = GetModuleHandleW (L"User32");
+    if (aUser32Module != NULL)
+    {
+      // User32 should be already loaded
+      myRegisterTouchWindow   = (RegisterTouchWindow_t   )GetProcAddress (aUser32Module, "RegisterTouchWindow");
+      myUnregisterTouchWindow = (UnregisterTouchWindow_t )GetProcAddress (aUser32Module, "UnregisterTouchWindow");
+      myGetTouchInputInfo     = (GetTouchInputInfo_t     )GetProcAddress (aUser32Module, "GetTouchInputInfo");
+      myCloseTouchInputHandle = (CloseTouchInputHandle_t )GetProcAddress (aUser32Module, "CloseTouchInputHandle");
+    }
   }
 
-  myDoubleBuffer  = Standard_False;
-  myHPixmap       = 0;
-  myHParentWindow = theParent;
-  myWndProc       = myWClass->WndProc();
-  SetBackground (theBackColor);
-  SetWindowLongPtr ((HWND )myHWindow, GWLP_WNDPROC, (LONG_PTR )WNT_WndProc);
-  myUsrData = (Standard_Address )SetWindowLongPtr ((HWND )myHWindow, GWLP_USERDATA, (LONG_PTR )&myExtraData);
+  //! Return TRUE if window has been registered.
+  bool IsRegistered() const { return myIsRegistered; }
 
-  myExtraData.WNT_Window_Ptr = (void* )this;
-  myExtraData.hPal           = (HPALETTE )aDev->HPalette();
-
-  myImages = new WNT_ImageManager (this);
-  myFormat = WNT_TOI_XWD;
-
-       SetFlags(WDF_NOERASEBKGRND);
-}
+  //! Register window to receive WM_TOUCH events.
+  bool Register (HWND theWin)
+  {
+    if (myRegisterTouchWindow == NULL)
+    {
+      return false;
+    }
+
+    if (myRegisterTouchWindow (theWin, TWF_FINETOUCH))
+    {
+      myIsRegistered = true;
+      return true;
+    }
+    //Message::SendTrace() << "RegisterTouchWindow() FAILED";
+    return false;
+  }
 
-WNT_Window::WNT_Window (const Handle(WNT_GraphicDevice)& theDevice,
-                        const Standard_CString           theTitle,
+  //! Array of touches retrieved from HTOUCHINPUT.
+  class TouchInputInfo : public InnerTouchArray
+  {
+  public:
+    //! Main constructor.
+    TouchInputInfo (const TouchInputHelper& theHelper,
+                    const MSG& theMsg)
+    : InnerTouchArray (0),
+      myHelper (&theHelper),
+      myHInput ((HTOUCHINPUT )theMsg.lParam)
+    {
+      const int aNbTouches = LOWORD(theMsg.wParam);
+      if (aNbTouches > 0
+       && theHelper.myGetTouchInputInfo != NULL)
+      {
+        InnerTouchArray::Allocate (aNbTouches);
+        TOUCHINPUT* aTouches = InnerTouchArray::operator TOUCHINPUT*();
+        if (!theHelper.myGetTouchInputInfo (myHInput, aNbTouches, aTouches, sizeof(TOUCHINPUT)))
+        {
+          InnerTouchArray::Deallocate();
+        }
+      }
+    }
+
+    //! Destructor.
+    ~TouchInputInfo()
+    {
+      if (myHelper->myCloseTouchInputHandle != NULL)
+      {
+        myHelper->myCloseTouchInputHandle (myHInput);
+      }
+    }
+
+  private:
+    const TouchInputHelper* myHelper;
+    HTOUCHINPUT myHInput;
+  };
+
+private:
+
+  RegisterTouchWindow_t   myRegisterTouchWindow;
+  UnregisterTouchWindow_t myUnregisterTouchWindow;
+  GetTouchInputInfo_t     myGetTouchInputInfo;
+  CloseTouchInputHandle_t myCloseTouchInputHandle;
+  bool                    myIsRegistered;
+
+};
+
+// =======================================================================
+// function : WNT_Window
+// purpose  :
+// =======================================================================
+WNT_Window::WNT_Window (const Standard_CString           theTitle,
                         const Handle(WNT_WClass)&        theClass,
                         const WNT_Dword&                 theStyle,
                         const Standard_Integer           thePxLeft,
@@ -173,1084 +155,913 @@ WNT_Window::WNT_Window (const Handle(WNT_GraphicDevice)& theDevice,
                         const Aspect_Handle              theParent,
                         const Aspect_Handle              theMenu,
                         const Standard_Address           theClientStruct)
-: Aspect_Window (theDevice),
-  aXLeft (thePxLeft),
-  aYTop (thePxTop),
-  aXRight (thePxLeft + thePxWidth),
-  aYBottom (thePxTop + thePxHeight),
-  myWClass (theClass)
+: Aspect_Window(),
+  myWClass (theClass),
+  myHWindow (NULL),
+  myHParentWindow (NULL),
+  myXLeft (thePxLeft),
+  myYTop  (thePxTop),
+  myXRight (thePxLeft + thePxWidth),
+  myYBottom (thePxTop + thePxHeight),
+  myIsForeign (Standard_False)
 {
-  ZeroMemory (&myExtraData, sizeof (WNT_WindowData));
-  DWORD dwStyle = theStyle;
-  const Handle(WNT_GraphicDevice)& aDev = Handle(WNT_GraphicDevice)::DownCast (MyGraphicDevice);
-
   if (thePxWidth <= 0 || thePxHeight <= 0)
   {
-    Aspect_WindowDefinitionError::Raise ("Coordinate(s) out of range");
+    throw Aspect_WindowDefinitionError("Coordinate(s) out of range");
   }
 
+  DWORD aStyle = theStyle;
   if (theParent && !(theStyle & WS_CHILD))
   {
-    dwStyle |= WS_CHILD | WS_CLIPSIBLINGS;
+    aStyle |= WS_CHILD | WS_CLIPSIBLINGS;
   }
   else if (!theParent && !(theStyle & WS_CLIPCHILDREN))
   {
-    dwStyle |= WS_CLIPCHILDREN;
-  }
-
-  if (dwStyle & WS_OVERLAPPEDWINDOW)
-  {
-    // include decorations in the window dimensions
-    // to reproduce same behaviour of Xw_Window.
-    aXLeft   -= GetSystemMetrics(SM_CXSIZEFRAME);
-    aYTop    -= GetSystemMetrics(SM_CYSIZEFRAME) + GetSystemMetrics(SM_CYCAPTION);
-    aXRight  += GetSystemMetrics(SM_CXSIZEFRAME);
-    aYBottom += GetSystemMetrics(SM_CYSIZEFRAME);
+    aStyle |= WS_CLIPCHILDREN;
   }
 
-  myHWindow = CreateWindow (
-              myWClass->Name(),                 // window's class name
-              theTitle,                         // window's name
-              dwStyle,                          // window's style
-              aXLeft, aYTop,                    // window's coordinates
-              (aXRight - aXLeft), (aYBottom - aYTop),
-              (HWND )theParent,                 // window's parent
-              (HMENU )theMenu,                  // window's menu
-              (HINSTANCE )myWClass->Instance(), // application's instance
-              theClientStruct);                 // pointer to CLIENTCREATESTRUCT
+  // include decorations in the window dimensions to reproduce same behavior of Xw_Window
+  RECT aRect;
+  aRect.top    = myYTop;
+  aRect.bottom = myYBottom;
+  aRect.left   = myXLeft;
+  aRect.right  = myXRight;
+  AdjustWindowRect (&aRect, aStyle, theMenu != NULL ? TRUE : FALSE);
+  myXLeft   = aRect.left;
+  myYTop    = aRect.top;
+  myXRight  = aRect.right;
+  myYBottom = aRect.bottom;
+
+  const TCollection_ExtendedString aTitleW (theTitle);
+  const TCollection_ExtendedString aClassNameW (myWClass->Name());
+  myHWindow = CreateWindowW (aClassNameW.ToWideString(), aTitleW.ToWideString(),
+                             aStyle,
+                             myXLeft, myYTop,
+                             (myXRight - myXLeft), (myYBottom - myYTop),
+                             (HWND )theParent,
+                             (HMENU )theMenu,
+                             (HINSTANCE )myWClass->Instance(),
+                             theClientStruct);
   if (!myHWindow)
   {
-    Aspect_WindowDefinitionError::Raise ("Unable to create window");
+    throw Aspect_WindowDefinitionError("Unable to create window");
   }
 
-  myDoubleBuffer  = Standard_False;
-  myHPixmap       = 0;
   myHParentWindow = theParent;
-  myWndProc       = myWClass->WndProc();
   SetBackground (theBackColor);
-  SetWindowLongPtr ((HWND )myHWindow, GWLP_WNDPROC, (LONG_PTR )WNT_WndProc);
-  myUsrData = (Standard_Address )SetWindowLongPtr ((HWND )myHWindow, GWLP_USERDATA, (LONG_PTR )&myExtraData);
-
-  myExtraData.WNT_Window_Ptr = (void* )this;
-  myExtraData.hPal = (HPALETTE )aDev->HPalette();
-
-  myImages = new WNT_ImageManager (this);
-  myFormat = WNT_TOI_XWD;
-
-       SetFlags (WDF_NOERASEBKGRND);
 }
 
-//***//
-//************************* Constructor **********************************//
-//***//
-WNT_Window :: WNT_Window (
-               const Handle( WNT_GraphicDevice )& aDevice,
-               const Aspect_Handle                aHandle,
-               const Quantity_NameOfColor         aBackColor
-              ) : Aspect_Window ( aDevice ) {
-
- doCreate ( aDevice, aHandle, aBackColor );
-
-       /* Bug OCC20596 */
-       SetFlags(WDF_NOERASEBKGRND);
+// =======================================================================
+// function : WNT_Window
+// purpose  :
+// =======================================================================
+WNT_Window::WNT_Window (const Aspect_Handle        theHandle,
+                        const Quantity_NameOfColor theBackColor)
+: myHWindow (theHandle),
+  myHParentWindow (GetParent ((HWND )theHandle)),
+  myXLeft (0),
+  myYTop  (0),
+  myXRight (0),
+  myYBottom (0),
+  myIsForeign (Standard_True)
+{
+  SetBackground (theBackColor);
 
-}  // end constructor
-//***//
-//************************* Constructor **********************************//
-//***//
-WNT_Window :: WNT_Window (
-               const Handle( WNT_GraphicDevice )& aDevice,
-               const Standard_Integer             aPart1,
-               const Standard_Integer             aPart2,
-               const Quantity_NameOfColor         aBackColor
-              ) : Aspect_Window ( aDevice ) {
+  WINDOWPLACEMENT aPlace = {};
+  aPlace.length = sizeof(WINDOWPLACEMENT);
+  ::GetWindowPlacement ((HWND )myHWindow, &aPlace);
 
- Aspect_Handle aHandle = ( Aspect_Handle )(  ( aPart1 << 16 ) + aPart2  );
+  myXLeft   = aPlace.rcNormalPosition.left;
+  myYTop    = aPlace.rcNormalPosition.top;
+  myXRight  = aPlace.rcNormalPosition.right;
+  myYBottom = aPlace.rcNormalPosition.bottom;
+}
 
- doCreate ( aDevice, aHandle, aBackColor );
+// =======================================================================
+// function : ~WNT_Window
+// purpose  :
+// =======================================================================
+WNT_Window::~WNT_Window()
+{
+  if (myHWindow == NULL
+   || myIsForeign)
+  {
+    return;
+  }
 
-       /* Bug OCC20596 */
-       SetFlags(WDF_NOERASEBKGRND);
+  DestroyWindow ((HWND )myHWindow);
+  myIsForeign = Standard_False;
+}
 
-}  // end constructor
-//***//
-//***************************** Destroy **********************************//
-//***//
-void WNT_Window :: Destroy () {
+// =======================================================================
+// function : SetCursor
+// purpose  :
+// =======================================================================
+void WNT_Window::SetCursor (const Aspect_Handle theCursor) const
+{
+  ::SetClassLongPtrW ((HWND )myHWindow, GCLP_HCURSOR, (LONG_PTR )theCursor);
+}
 
- if ( MyHBackground ) DeleteObject ( MyHBackground );  // delete background brush
- if ( myHPixmap     ) DeleteObject ( myHPixmap     );  // . . . and double buffer pixmap if exists
+// =======================================================================
+// function : IsMapped
+// purpose  :
+// =======================================================================
+Standard_Boolean WNT_Window::IsMapped() const
+{
+  if (IsVirtual())
+  {
+    return Standard_True;
+  }
 
- if ( myHWindow ) {
+  WINDOWPLACEMENT aPlace = {};
+  aPlace.length = sizeof(WINDOWPLACEMENT);
+  ::GetWindowPlacement ((HWND )myHWindow, &aPlace);
+  return !(aPlace.showCmd == SW_HIDE
+        || aPlace.showCmd == SW_MINIMIZE);
+}
 
-  if (myUsrData != Standard_Address(-1))
+// =======================================================================
+// function : Map
+// purpose  :
+// =======================================================================
+void WNT_Window::Map() const
+{
+  if (!IsVirtual())
   {
-    SetWindowLongPtr ((HWND )myHWindow, GWLP_USERDATA, (LONG_PTR )myUsrData);
+    Map (SW_SHOW);
   }
+}
 
-  if (myWndProc != NULL)
+// =======================================================================
+// function : Map
+// purpose  :
+// =======================================================================
+void WNT_Window::Map (const Standard_Integer theMapMode) const
+{
+  if (IsVirtual())
   {
-   SetWindowLongPtr ((HWND )myHWindow, GWLP_WNDPROC, (LONG_PTR )myWndProc);
+    return;
   }
 
-  if (  !( myExtraData.dwFlags & WDF_FOREIGN )  )
-
-   DestroyWindow (  ( HWND )myHWindow  );
-
- }  // end if
-
-}  // end WNT_Window :: Destroy
-//***//
-//************************ SetBackground (1) *****************************//
-//***//
-void WNT_Window :: SetBackground ( const Aspect_Background& Background ) {
-
- SetBackground (  Background.Color ().Name ()  );
-
-}  // end WNT_Window :: SetBackground
-//***//
-//************************ SetBackground (2) *****************************//
-//***//
-void WNT_Window :: SetBackground ( const Quantity_NameOfColor BackColor ) {
-
- const Handle( WNT_GraphicDevice )& dev = Handle( WNT_GraphicDevice ) ::
-                                           DownCast ( MyGraphicDevice );
-
- if ( MyHBackground )
-   DeleteObject ( MyHBackground );
-
- MyBackground.SetColor ( BackColor );
- MyHBackground = CreateSolidBrush (
-                  dev -> SetColor (  MyBackground.Color ()  )
-                 );
-
-}  // end WNT_Window :: SetBackground
-//***//
-//************************ SetBackground (3) *****************************//
-//***//
-void WNT_Window :: SetBackground ( const Aspect_Handle aBackPixmap ) {
-
- Aspect_Handle bitmap = CreatePatternBrush (  ( HBITMAP )aBackPixmap  );
-
- if( bitmap ) {
-   if ( MyHBackground ) DeleteObject ( MyHBackground );
-   MyHBackground = bitmap;
-   MyBackgroundImage.Clear();
-   MyBackgroundFillMethod = Aspect_FM_NONE;
- }
-
-}  // end WNT_Window :: SetBackground
-//***//
-//************************ SetBackground (4) *****************************//
-//***//
-Standard_Boolean WNT_Window::SetBackground( const Standard_CString aName,
-                                const Aspect_FillMethod aMethod ) {
- Standard_Boolean status = Standard_False;
-
- if( !aName ) return Standard_False;
-
- Handle( WNT_GraphicDevice ) gdev =
-     *( ( Handle_WNT_GraphicDevice * )& MyGraphicDevice );
- if ( MyHBackground )
-   DeleteObject( MyHBackground );
- MyHBackground = 0;
-
- HBITMAP hBmp = LoadImageFromFile( gdev, (Standard_PCharacter)aName );
-
- if( hBmp ) {
-   status = Standard_True;
-   MyBackgroundImage = aName;
-   MyBackgroundFillMethod = aMethod;
-   MyHBackground = CreatePatternBrush(  hBmp  );
- }
-
- return status;
-}  // end WNT_Window :: SetBackground
-    //***//
-//************************ SetBackground (5) *****************************//
-//***//
-void WNT_Window::SetBackground( const Quantity_Color& color ) {
-
- const Handle( WNT_GraphicDevice )& dev =
-   Handle( WNT_GraphicDevice )::DownCast ( MyGraphicDevice );
-
- if ( MyHBackground )
-   DeleteObject( MyHBackground );
-
- MyBackground.SetColor( color );
- MyHBackground = CreateSolidBrush( dev->SetColor( color ) );
-
-}  // end WNT_Window :: SetBackground
-
-//************************ SetBackground (6) *****************************//
-//***//
-void WNT_Window::SetBackground (const Aspect_GradientBackground& GrBackground) {
-
-  Quantity_Color Color1, Color2;
-  GrBackground.Colors(Color1,Color2);
-  SetBackground(Color1,Color2, GrBackground.BgGradientFillMethod());
-
-} // end WNT_Window :: SetBackground
-
-//************************ SetBackground (7) *****************************//
-//***//
-void WNT_Window::SetBackground( const Quantity_Color& color1,
-                                const Quantity_Color& color2,
-                                const Aspect_GradientFillMethod aMethod){
-
-  Standard_Integer bcolor = Standard_Integer( color1.Name() ) + Standard_Integer( color2.Name() );
-  if(  ( bcolor >= 0 ) )
-    MyGradientBackground.SetColors( color1, color2, aMethod ) ;
-}  // end WNT_Window :: SetBackground
-
-//**************************** SetCursor *********************************//
-//***//
-void WNT_Window :: SetCursor ( const Aspect_Handle aCursor ) const {
-
-#ifndef _WIN64
- SetClassLong (  ( HWND )myHWindow, GCL_HCURSOR, ( LONG )aCursor  );
-#else
- SetClassLong (  ( HWND )myHWindow, GCLP_HCURSOR, ( LONG )aCursor  );
-#endif
-
-}  // end WNT_Window :: SetCursor
-//***//
-//**************************** SetIcon ***********************************//
-//***//
-void WNT_Window :: SetIcon (
-                    const Aspect_Handle    anIcon,
-                    const Standard_CString aName
-                   ) {
-
- if (  !myIcon.IsNull ()  )
-
-  myIcon.Nullify ();
-
- myIcon = new WNT_Icon ( aName, anIcon, 0 );
-
-}  // end WNT_Window :: SetIcon
-//***//
-//**************************** SetIconName *******************************//
-//***//
-void WNT_Window :: SetIconName ( const Standard_CString aName ) {
-
- myIcon -> SetName ( aName );
-
-}  // end WNT_Window :: SetIconName
-//***//
-//************************** SetDoubleBuffer *****************************//
-//***//
-void WNT_Window :: SetDoubleBuffer ( const Standard_Boolean DBmode ) {
-
- if ( DBmode )
-
-  if (  !BackingStore ()  )
-
-   Aspect_WindowError :: Raise ( "Unable to set double buffer" );
-
-  else {
-
-   myDoubleBuffer   = Standard_True;
-   myExtraData.hBmp     = ( HBITMAP )myHPixmap;
-
-  }  // end else
-
- else {
-
-  myDoubleBuffer   = Standard_False;
-  myExtraData.hBmp = NULL;
+  ::ShowWindow   ((HWND )myHWindow, theMapMode);
+  ::UpdateWindow ((HWND )myHWindow);
+}
 
- }  // end else
+// =======================================================================
+// function : Unmap
+// purpose  :
+// =======================================================================
+void WNT_Window::Unmap() const
+{
+  Map (SW_HIDE);
+}
 
-}  // end WNT_Window :: SetDoubleBuffer
-//***//
-//***************************** Flush ************************************//
-//***//
-void WNT_Window :: Flush () const {
+// =======================================================================
+// function : DoResize
+// purpose  :
+// =======================================================================
+Aspect_TypeOfResize WNT_Window::DoResize()
+{
+  if (IsVirtual())
+  {
+    return Aspect_TOR_UNKNOWN;
+  }
 
- if ( myDoubleBuffer ) Restore ();
+  WINDOWPLACEMENT aPlace = {};
+  aPlace.length = sizeof(WINDOWPLACEMENT);
+  GetWindowPlacement ((HWND )myHWindow, &aPlace);
+  if (aPlace.showCmd == SW_SHOWMINIMIZED)
+  {
+    return Aspect_TOR_UNKNOWN;
+  }
 
-}  // end WNT_Window :: Flush
-//***//
-//***************************** IsMapped *********************************//
-//***//
-Standard_Boolean WNT_Window :: IsMapped () const {
-  if (IsVirtual()) {
-    return Standard_True;
+  int aMask = 0;
+  if (Abs ((int )aPlace.rcNormalPosition.left   - myXLeft  ) > 2) { aMask |= 1; }
+  if (Abs ((int )aPlace.rcNormalPosition.right  - myXRight ) > 2) { aMask |= 2; }
+  if (Abs ((int )aPlace.rcNormalPosition.top    - myYTop   ) > 2) { aMask |= 4; }
+  if (Abs ((int )aPlace.rcNormalPosition.bottom - myYBottom) > 2) { aMask |= 8; }
+
+  myXLeft   = aPlace.rcNormalPosition.left;
+  myXRight  = aPlace.rcNormalPosition.right;
+  myYTop    = aPlace.rcNormalPosition.top;
+  myYBottom = aPlace.rcNormalPosition.bottom;
+  switch (aMask)
+  {
+    case 0:  return Aspect_TOR_NO_BORDER;
+    case 1:  return Aspect_TOR_LEFT_BORDER;
+    case 2:  return Aspect_TOR_RIGHT_BORDER;
+    case 4:  return Aspect_TOR_TOP_BORDER;
+    case 5:  return Aspect_TOR_LEFT_AND_TOP_BORDER;
+    case 6:  return Aspect_TOR_TOP_AND_RIGHT_BORDER;
+    case 8:  return Aspect_TOR_BOTTOM_BORDER;
+    case 9:  return Aspect_TOR_BOTTOM_AND_LEFT_BORDER;
+    case 10: return Aspect_TOR_RIGHT_AND_BOTTOM_BORDER;
   }
+  return Aspect_TOR_UNKNOWN;
+}
 
-  WINDOWPLACEMENT wp;
+// =======================================================================
+// function : Ratio
+// purpose  :
+// =======================================================================
+Standard_Real WNT_Window::Ratio() const
+{
+  if (IsVirtual())
+  {
+    return Standard_Real(myXRight - myXLeft)/ Standard_Real(myYBottom - myYTop);
+  }
 
-  wp.length = sizeof ( WINDOWPLACEMENT );
-  GetWindowPlacement (  ( HWND )myHWindow, &wp  );
+  RECT aRect = {};
+  GetClientRect ((HWND )myHWindow, &aRect);
+  return Standard_Real(aRect.right - aRect.left) / Standard_Real(aRect.bottom - aRect.top);
+}
 
-  return !(  wp.showCmd == SW_HIDE || wp.showCmd == SW_MINIMIZE );
-}  // WNT_Window :: IsMapped
-//***//
-//***************************** Map (1) **********************************//
-//***//
-void WNT_Window :: Map () const {
-  if (IsVirtual()) {
-    return;
-  }
-  Map ( SW_SHOW );
-}  // end WNT_Window :: Map
-//***//
-//***************************** Map (2) **********************************//
-//***//
-void WNT_Window :: Map ( const Standard_Integer aMapMode ) const {
-  if (IsVirtual()) {
+// =======================================================================
+// function : Position
+// purpose  :
+// =======================================================================
+void WNT_Window::Position (Standard_Integer& theX1, Standard_Integer& theY1,
+                           Standard_Integer& theX2, Standard_Integer& theY2) const
+{
+  if (IsVirtual())
+  {
+    theX1  = myXLeft;
+    theX2  = myXRight;
+    theY1  = myYTop;
+    theY2  = myYBottom;
     return;
   }
-  ShowWindow (  ( HWND )myHWindow, aMapMode  );
-  UpdateWindow (  ( HWND )myHWindow  );
-
-}  // end WNT_Window :: Map
-//***//
-//**************************** Unmap *************************************//
-//***//
-void WNT_Window :: Unmap () const {
-
- Map ( SW_HIDE );
-
-}  // end WNT_Window :: Unmap
-//***//
-//**************************** DoResize **********************************//
-//***//
-Aspect_TypeOfResize WNT_Window :: DoResize () const {
-
- int                 mask = 0;
- Aspect_TypeOfResize mode = Aspect_TOR_UNKNOWN;
- WINDOWPLACEMENT     wp;
-
- wp.length = sizeof ( WINDOWPLACEMENT );
- GetWindowPlacement (  ( HWND )myHWindow, &wp  );
-
- if ( wp.showCmd != SW_SHOWMINIMIZED ) {
 
-  if (  Abs ( wp.rcNormalPosition.left   - aXLeft   ) > 2  ) mask |= 1;
-  if (  Abs ( wp.rcNormalPosition.right  - aXRight  ) > 2  ) mask |= 2;
-  if (  Abs ( wp.rcNormalPosition.top    - aYTop    ) > 2  ) mask |= 4;
-  if (  Abs ( wp.rcNormalPosition.bottom - aYBottom ) > 2  ) mask |= 8;
+  RECT aRect = {};
+  ::GetClientRect ((HWND )myHWindow, &aRect);
 
-  switch ( mask ) {
+  POINT aPntLeft, aPntRight;
+  aPntLeft.x = aPntLeft.y = 0;
+  ::ClientToScreen ((HWND )myHWindow, &aPntLeft);
+  aPntRight.x = aRect.right;
+  aPntRight.y = aRect.bottom;
+  ::ClientToScreen ((HWND )myHWindow, &aPntRight);
 
-   case 0:
-
-     mode = Aspect_TOR_NO_BORDER;
-
-    break;
-
-   case 1:
-
-     mode = Aspect_TOR_LEFT_BORDER;
-
-    break;
-
-   case 2:
-
-     mode = Aspect_TOR_RIGHT_BORDER;
-
-    break;
-
-   case 4:
-
-     mode = Aspect_TOR_TOP_BORDER;
-
-    break;
-
-   case 5:
-
-     mode = Aspect_TOR_LEFT_AND_TOP_BORDER;
-
-    break;
-
-   case 6:
-
-     mode = Aspect_TOR_TOP_AND_RIGHT_BORDER;
-
-    break;
-
-   case 8:
-
-     mode = Aspect_TOR_BOTTOM_BORDER;
-
-    break;
-
-   case 9:
-
-     mode = Aspect_TOR_BOTTOM_AND_LEFT_BORDER;
-
-    break;
-
-   case 10:
-
-     mode = Aspect_TOR_RIGHT_AND_BOTTOM_BORDER;
-
-    break;
-
-   default:
-
-    break;
-
-  }  // end switch
-
-  *(  ( Standard_Integer* )&aXLeft   ) = wp.rcNormalPosition.left;
-  *(  ( Standard_Integer* )&aXRight  ) = wp.rcNormalPosition.right;
-  *(  ( Standard_Integer* )&aYTop    ) = wp.rcNormalPosition.top;
-  *(  ( Standard_Integer* )&aYBottom ) = wp.rcNormalPosition.bottom;
-
-  if (  myDoubleBuffer  ) {
-
-   DeleteObject ( myHPixmap );
-   *(  ( Aspect_Handle* )&myHPixmap  ) = 0;
-
-   if (  !BackingStore ()  )
-
-    Aspect_WindowError :: Raise ( "WNT_Window::DoResize (): Unable to set double buffer" );
-
-  }  // end if
-
- }  // end if
-
- return mode;
-
-}  // end WNT_Window :: DoResize
+  if (myHParentWindow != NULL)
+  {
+    ::ScreenToClient ((HWND )myHParentWindow, &aPntLeft);
+    ::ScreenToClient ((HWND )myHParentWindow, &aPntRight);
+  }
 
-//***//
-//**************************** DoMapping **********************************//
-//***//
-Standard_Boolean WNT_Window :: DoMapping () const {
-// DO nothing on WNT.
-  return Standard_True;
+  theX1 = aPntLeft.x;
+  theX2 = aPntRight.x;
+  theY1 = aPntLeft.y;
+  theY2 = aPntRight.y;
 }
 
-//***//
-//**************************** Clear *************************************//
-//***//
-void WNT_Window :: Clear () const {
-
- RECT r;
-
- GetClientRect (  ( HWND )myHWindow, &r  );
- ClearArea ( r.right / 2, r.bottom / 2, r.right, r.bottom );
-
-}  // end WNT_Window :: Clear
-//***//
-//**************************** ClearArea *********************************//
-//***//
-void WNT_Window :: ClearArea (
-                    const Standard_Integer Xc,
-                    const Standard_Integer Yc,
-                    const Standard_Integer Width,
-                    const Standard_Integer Height
-                   ) const {
-
- RECT r;
- HDC  hDC = GetDC (  ( HWND )myHWindow  );
-
-  r.left   = Xc - Width / 2;
-  r.right  = r.left + Width;
-  r.top    = Yc - Height / 2;
-  r.bottom = r.top + Height;
-
-  if ( myDoubleBuffer && myHPixmap ) {
-
-   HDC hDCmem = CreateCompatibleDC ( hDC );
-
-    SELECT_PALETTE( hDCmem );
-
-     SelectObject ( hDCmem, myHPixmap );
-     FillRect (  hDCmem, &r, ( HBRUSH )MyHBackground  );
-
-        UNSELECT_PALETTE( hDCmem );
-
-   DeleteDC ( hDCmem );
-
-  } else {
-
-   SELECT_PALETTE( hDC );
-
-    FillRect (  hDC, &r, ( HBRUSH )MyHBackground  );
-
-   UNSELECT_PALETTE( hDC );
-
-  }  // end else
-
- ReleaseDC (  ( HWND )myHWindow, hDC  );
-
-}  // end WNT_Window :: ClearArea
-//***//
-//**************************** Restore ***********************************//
-//***//
-void WNT_Window :: Restore () const {
-
- RECT r;
-
- if ( myHPixmap ) {
-
-  GetClientRect (  ( HWND )myHWindow, &r  );
-  RestoreArea (
-   r.right / 2, r.bottom - r.bottom / 2, r.right, r.bottom
-  );
-
- }  // end if
-
-}  // end WNT_Window :: Restore
-//***//
-//************************* Restore Area *********************************//
-//***//
-void WNT_Window :: RestoreArea (
-                    const Standard_Integer Xc,
-                    const Standard_Integer Yc,
-                    const Standard_Integer Width,
-                    const Standard_Integer Height
-                   ) const {
-
- HDC hDC, hDCmem;
- int x, y;
-
- if ( myHPixmap ) {
-
-  hDC     = GetDC (  ( HWND )myHWindow  );
-   hDCmem = CreateCompatibleDC ( hDC );
+// =======================================================================
+// function : Size
+// purpose  :
+// =======================================================================
+void WNT_Window::Size (Standard_Integer& theWidth,
+                       Standard_Integer& theHeight) const
+{
+  if (IsVirtual())
+  {
+    theWidth  = myXRight - myXLeft;
+    theHeight = myYBottom - myYTop;
+    return;
+  }
 
-    x = Xc - Width / 2;
-    y = Yc - Height / 2;
+  RECT aRect = {};
+  ::GetClientRect ((HWND )myHWindow, &aRect);
+  theWidth  = aRect.right;
+  theHeight = aRect.bottom;
+}
 
-    SelectObject ( hDCmem, myHPixmap );
-    BitBlt ( hDC, x, y, Width, Height, hDCmem, x, y, SRCCOPY );
+// =======================================================================
+// function : SetPos
+// purpose  :
+// =======================================================================
+void WNT_Window::SetPos (const Standard_Integer theX,  const Standard_Integer theY,
+                         const Standard_Integer theX1, const Standard_Integer theY1)
+{
+  myXLeft   = theX;
+  myYTop    = theY;
+  myXRight  = theX1;
+  myYBottom = theY1;
+}
 
-   DeleteDC ( hDCmem );
-  ReleaseDC (  ( HWND )myHWindow, hDC  );
+// =======================================================================
+// function : SetTitle
+// purpose  :
+// =======================================================================
+void WNT_Window::SetTitle (const TCollection_AsciiString& theTitle)
+{
+  const TCollection_ExtendedString aTitleW (theTitle);
+  SetWindowTextW ((HWND )myHWindow, aTitleW.ToWideString());
+}
 
- }  // end if
+// =======================================================================
+// function : InvalidateContent
+// purpose  :
+// =======================================================================
+void WNT_Window::InvalidateContent (const Handle(Aspect_DisplayConnection)& )
+{
+  if (myHWindow != NULL)
+  {
+    ::InvalidateRect ((HWND )myHWindow, NULL, TRUE);
+  }
+}
 
-}  // end WNT_Window :: RestoreArea
-//***//
-//****************************** Dump ************************************//
-//***//
-Standard_Boolean WNT_Window::Dump (const Standard_CString theFilename,
-                                   const Standard_Real theGammaValue) const
+// =======================================================================
+// function : VirtualKeyFromNative
+// purpose  :
+// =======================================================================
+Aspect_VKey WNT_Window::VirtualKeyFromNative (Standard_Integer theKey)
 {
-  Image_AlienPixMap anImg;
-  if (!ToPixMap (anImg) || anImg.IsEmpty())
+  if (theKey >= Standard_Integer('0')
+   && theKey <= Standard_Integer('9'))
   {
-    return Standard_False;
+    return Aspect_VKey((theKey - Standard_Integer('0')) + Aspect_VKey_0);
   }
-  if (Abs (theGammaValue - 1.0) > 0.001)
+  if (theKey >= Standard_Integer('A')
+   && theKey <= Standard_Integer('Z'))
   {
-    anImg.AdjustGamma (theGammaValue);
+    // main latin alphabet keys
+    return Aspect_VKey((theKey - Standard_Integer('A')) + Aspect_VKey_A);
   }
-  return anImg.Save (theFilename);
-}  // end WNT_Window :: Dump
-//***//
-//*************************** DumpArea ***********************************//
-//***//
-Standard_Boolean WNT_Window::DumpArea (const Standard_CString theFilename,
-                                       const Standard_Integer Xc, const Standard_Integer Yc,
-                                       const Standard_Integer Width, const Standard_Integer Height,
-                                       const Standard_Real aGammaValue) const
-{
-// *** Gamma correction must be implemented also under WNT ...
- Standard_Integer x = Xc - Width  / 2;
- Standard_Integer y = Yc - Height / 2;
- return (myDoubleBuffer) ?
-         myImages->SaveBuffer (theFilename, x, y, Width, Height) :
-         myImages->Save       (theFilename, x, y, Width, Height);
-
-}  // end WNT_Window :: DumpArea
-//***//
-
-static Standard_Boolean ConvertBitmap (HBITMAP       theHBitmap,
-                                       Image_PixMap& thePixMap)
-{
-  // Get informations about the bitmap
-  BITMAP aBitmap;
-  if (GetObject (theHBitmap, sizeof(BITMAP), (LPSTR )&aBitmap) == 0)
+  if (theKey >= VK_F1
+   && theKey <= VK_F24)
   {
-    return Standard_False;
+    // special keys
+    if (theKey <= VK_F12)
+    {
+      return Aspect_VKey((theKey - VK_F1) + Aspect_VKey_F1);
+    }
+    return Aspect_VKey_UNKNOWN;
+  }
+  if (theKey >= VK_NUMPAD0
+   && theKey <= VK_NUMPAD9)
+  {
+    // numpad keys
+    return Aspect_VKey((theKey - VK_NUMPAD0) + Aspect_VKey_Numpad0);
   }
 
-  const Standard_Size aSizeRowBytes = Standard_Size(aBitmap.bmWidth) * 4;
-  if (!thePixMap.InitTrash (Image_PixMap::ImgBGR32, Standard_Size(aBitmap.bmWidth), Standard_Size(aBitmap.bmHeight), aSizeRowBytes))
+  switch (theKey)
   {
-    return Standard_False;
+    case VK_LBUTTON:
+    case VK_RBUTTON:
+    case VK_CANCEL:
+    case VK_MBUTTON:
+    case VK_XBUTTON1:
+    case VK_XBUTTON2:
+      return Aspect_VKey_UNKNOWN;
+    case VK_BACK:
+      return Aspect_VKey_Backspace;
+    case VK_TAB:
+      return Aspect_VKey_Tab;
+    case VK_CLEAR:
+      return Aspect_VKey_UNKNOWN;
+    case VK_RETURN:
+      return Aspect_VKey_Enter;
+    case VK_SHIFT:
+      return Aspect_VKey_Shift;
+    case VK_CONTROL:
+      return Aspect_VKey_Control;
+    case VK_MENU:
+      return Aspect_VKey_Alt; //Aspect_VKey_Menu;
+    case VK_PAUSE:
+    case VK_CAPITAL:
+      return Aspect_VKey_UNKNOWN;
+    case VK_ESCAPE:
+      return Aspect_VKey_Escape;
+    case VK_CONVERT:
+    case VK_NONCONVERT:
+    case VK_ACCEPT:
+    case VK_MODECHANGE:
+      return Aspect_VKey_UNKNOWN;
+    case VK_SPACE:
+      return Aspect_VKey_Space;
+    case VK_PRIOR:
+      return Aspect_VKey_PageUp;
+    case VK_NEXT:
+      return Aspect_VKey_PageDown;
+    case VK_END:
+      return Aspect_VKey_End;
+    case VK_HOME:
+      return Aspect_VKey_Home;
+    case VK_LEFT:
+      return Aspect_VKey_Left;
+    case VK_UP:
+      return Aspect_VKey_Up;
+    case VK_DOWN:
+      return Aspect_VKey_Down;
+    case VK_RIGHT:
+      return Aspect_VKey_Right;
+    case VK_SELECT:
+    case VK_PRINT:
+    case VK_EXECUTE:
+    case VK_SNAPSHOT:
+      return Aspect_VKey_UNKNOWN;
+    case VK_INSERT:
+      return Aspect_VKey_UNKNOWN; // Aspect_VKey_Insert
+    case VK_DELETE:
+      return Aspect_VKey_Delete;
+    case VK_HELP:
+    case VK_LWIN:
+    case VK_RWIN:
+    case VK_APPS:
+    case VK_SLEEP:
+      return Aspect_VKey_UNKNOWN;
+    case VK_MULTIPLY:
+      return Aspect_VKey_NumpadMultiply;
+    case VK_ADD:
+      return Aspect_VKey_NumpadAdd;
+    case VK_SEPARATOR:
+    case VK_DECIMAL:
+      return Aspect_VKey_UNKNOWN;
+    case VK_SUBTRACT:
+      return Aspect_VKey_NumpadSubtract;
+    case VK_DIVIDE:
+      return Aspect_VKey_NumpadDivide;
+    case VK_NUMLOCK:
+      return Aspect_VKey_Numlock;
+    case VK_SCROLL:
+      return Aspect_VKey_Scroll;
+    case VK_LSHIFT:
+    case VK_RSHIFT:
+    case VK_LCONTROL:
+    case VK_RCONTROL:
+    case VK_LMENU:
+    case VK_RMENU:
+      return Aspect_VKey_UNKNOWN;
+    case VK_BROWSER_BACK:
+      return Aspect_VKey_BrowserBack;
+    case VK_BROWSER_FORWARD:
+      return Aspect_VKey_BrowserForward;
+    case VK_BROWSER_REFRESH:
+      return Aspect_VKey_BrowserRefresh;
+    case VK_BROWSER_STOP:
+      return Aspect_VKey_BrowserStop;
+    case VK_BROWSER_SEARCH:
+      return Aspect_VKey_BrowserSearch;
+    case VK_BROWSER_FAVORITES:
+      return Aspect_VKey_BrowserFavorites;
+    case VK_BROWSER_HOME:
+      return Aspect_VKey_BrowserHome;
+    case VK_VOLUME_MUTE:
+      return Aspect_VKey_VolumeMute;
+    case VK_VOLUME_DOWN:
+      return Aspect_VKey_VolumeDown;
+    case VK_VOLUME_UP:
+      return Aspect_VKey_VolumeUp;
+    case VK_MEDIA_NEXT_TRACK:
+      return Aspect_VKey_MediaNextTrack;
+    case VK_MEDIA_PREV_TRACK:
+      return Aspect_VKey_MediaPreviousTrack;
+    case VK_MEDIA_STOP:
+      return Aspect_VKey_MediaStop;
+    case VK_MEDIA_PLAY_PAUSE:
+      return Aspect_VKey_MediaPlayPause;
+    case VK_OEM_1:
+      return Aspect_VKey_Semicolon;
+    case VK_OEM_PLUS:
+      return Aspect_VKey_Plus;
+    case VK_OEM_COMMA:
+      return Aspect_VKey_Comma;
+    case VK_OEM_MINUS:
+      return Aspect_VKey_Minus;
+    case VK_OEM_PERIOD:
+      return Aspect_VKey_Period;
+    case VK_OEM_2:
+      return Aspect_VKey_Slash;
+    case VK_OEM_3:
+      return Aspect_VKey_Tilde;
+    case VK_OEM_4:
+      return Aspect_VKey_BracketLeft;
+    case VK_OEM_5:
+      return Aspect_VKey_Backslash;
+    case VK_OEM_6:
+      return Aspect_VKey_BracketRight;
+    case VK_OEM_7:
+      return Aspect_VKey_Apostrophe;
   }
-  thePixMap.SetTopDown (false);
-
-  // Setup image data
-  BITMAPINFOHEADER aBitmapInfo;
-  memset (&aBitmapInfo, 0, sizeof(BITMAPINFOHEADER));
-  aBitmapInfo.biSize        = sizeof(BITMAPINFOHEADER);
-  aBitmapInfo.biWidth       = aBitmap.bmWidth;
-  aBitmapInfo.biHeight      = aBitmap.bmHeight; // positive means bottom-up!
-  aBitmapInfo.biPlanes      = 1;
-  aBitmapInfo.biBitCount    = 32; // use 32bit for automatic word-alignment per row
-  aBitmapInfo.biCompression = BI_RGB;
-
-  // Copy the pixels
-  HDC aDC = GetDC (NULL);
-  Standard_Boolean isSuccess = GetDIBits (aDC, theHBitmap,
-                                          0,                           // first scan line to set
-                                          aBitmap.bmHeight,            // number of scan lines to copy
-                                          thePixMap.ChangeData(),      // array for bitmap bits
-                                          (LPBITMAPINFO )&aBitmapInfo, // bitmap data info
-                                          DIB_RGB_COLORS) != 0;
-  ReleaseDC (NULL, aDC);
-  return isSuccess;
+  return Aspect_VKey_UNKNOWN;
 }
 
-Standard_Boolean WNT_Window::ToPixMap (Image_PixMap& thePixMap) const
+// =======================================================================
+// function : MouseKeyFlagsFromEvent
+// purpose  :
+// =======================================================================
+Aspect_VKeyFlags WNT_Window::MouseKeyFlagsFromEvent (WPARAM theKeys)
 {
-  if (myDoubleBuffer && myHPixmap)
+  Aspect_VKeyFlags aFlags = Aspect_VKeyFlags_NONE;
+  if ((theKeys & MK_CONTROL) != 0)
   {
-    return ConvertBitmap ((HBITMAP )myHPixmap, thePixMap);
+    aFlags |= Aspect_VKeyFlags_CTRL;
   }
-
-  RECT aRect;
-  GetClientRect ((HWND )myHWindow, &aRect);
-  int aWidth  = aRect.right  - aRect.left;
-  int aHeight = aRect.bottom - aRect.top;
-
-  // Prepare the DCs
-  HDC aDstDC = GetDC (NULL);
-  HDC aSrcDC = GetDC ((HWND )myHWindow); // we copy only client area
-  HDC aMemDC = CreateCompatibleDC (aDstDC);
-
-  // Copy the screen to the bitmap
-  HBITMAP anHBitmapDump = CreateCompatibleBitmap (aDstDC, aWidth, aHeight);
-  HBITMAP anHBitmapOld = (HBITMAP )SelectObject (aMemDC, anHBitmapDump);
-  BitBlt (aMemDC, 0, 0, aWidth, aHeight, aSrcDC, 0, 0, SRCCOPY);
-
-  Standard_Boolean isSuccess = ConvertBitmap (anHBitmapDump, thePixMap);
-
-  // Free objects
-  DeleteObject (SelectObject (aMemDC, anHBitmapOld));
-  DeleteDC (aMemDC);
-
-  return isSuccess;
+  if ((theKeys & MK_SHIFT) != 0)
+  {
+    aFlags |= Aspect_VKeyFlags_SHIFT;
+  }
+  if (GetKeyState (VK_MENU) < 0)
+  {
+    aFlags |= Aspect_VKeyFlags_ALT;
+  }
+  return aFlags;
 }
 
-//****************************** Load ************************************//
-//***//
-Standard_Boolean WNT_Window :: Load ( const Standard_CString aFilename ) const {
-
- RECT r;
-
- GetClientRect (  ( HWND )myHWindow, &r  );
-
- return LoadArea ( aFilename, r.right / 2, r.bottom / 2, r.right, r.bottom );
-
-}  // end WNT_Window :: Load
-//***//
-//*************************** LoadArea ***********************************//
-//***//
-Standard_Boolean WNT_Window :: LoadArea (
-                                const Standard_CString aFilename,
-                                const Standard_Integer Xc,
-                                const Standard_Integer Yc,
-                                const Standard_Integer Width,
-                                const Standard_Integer Height
-                               ) const {
-
- Standard_Integer idx;
- Standard_Boolean status;
-
- status = (  idx = myImages -> Load ( aFilename )  ) ? Standard_True : Standard_False;
-
- if ( status ) myImages -> Draw ( idx, Xc, Yc, Width, Height );
-
- return status;
-
-}  // end WNT_Window :: LoadArea
-//***//
-//*************************** BackingStore *******************************//
-//***//
-Standard_Boolean WNT_Window :: BackingStore () const {
-
- Standard_Boolean retVal = Standard_False;;
- HDC              hDC;
- RECT             r;
-
- if ( myHPixmap )
-
-  retVal = Standard_True;
-
- else {
-
-  hDC = GetDC (  ( HWND )myHWindow  );
-
-   GetClientRect (  ( HWND )myHWindow, &r  );
-   *(  ( Aspect_Handle* )&myHPixmap  ) = CreateCompatibleBitmap ( hDC, r.right, r.bottom );
-
-   if ( myHPixmap ) {
-
-    HDC hDCmem;
-
-         hDCmem = CreateCompatibleDC ( hDC );
-
-       SELECT_PALETTE( hDCmem );
-
-            SelectObject ( hDCmem, myHPixmap );
-        FillRect (  hDCmem, &r, ( HBRUSH )MyHBackground  );
-
-       UNSELECT_PALETTE( hDCmem );
-
-         DeleteDC ( hDCmem );
-
-    retVal = Standard_True;
-
-   }  // end if
-
-  ReleaseDC (  ( HWND )myHWindow, hDC  );
-
- }  // end else
-
- return retVal;
-
-}  // end WNT_Window :: BackingStore
-//***//
-//******************************* Ratio **********************************//
-//***//
-Quantity_Ratio WNT_Window :: Ratio () const {
-
- RECT r;
-
- GetClientRect (  ( HWND )myHWindow, &r  );
-
- return ( Quantity_Ratio )(  ( Quantity_Ratio )r.right / ( Quantity_Ratio )r.bottom  );
-
-}  // end WNT_Window :: Ratio
-//***//
-//**************************** Position (1) ******************************//
-//***//
-void WNT_Window :: Position (
-                    Quantity_Parameter& X1, Quantity_Parameter& Y1,
-                    Quantity_Parameter& X2, Quantity_Parameter& Y2
-                   ) const {
-
- POINT ptl, ptr;
- RECT  pr, cr;
- const Handle( WNT_GraphicDevice )& dev = Handle( WNT_GraphicDevice ) ::
-                                           DownCast ( MyGraphicDevice );
-
- if ( myHParentWindow )
-
-  GetClientRect (  ( HWND )myHParentWindow, &pr  );
-
- else {
-
-  int w, h;
-
-  dev -> DisplaySize ( w, h );
-
-  pr.right  = w;
-  pr.bottom = h;
-
- }  // end else
-
- GetClientRect (  ( HWND )myHWindow, &cr  );
-
- ptl.x = ptl.y = 0;
- ClientToScreen (  ( HWND )myHWindow, &ptl  );
- cr.left = ptl.x;
- cr.top  = ptl.y;
-
- ptr.x = cr.right;
- ptr.y = cr.bottom;
- ClientToScreen (  ( HWND )myHWindow, &ptr  );
- cr.right  = ptr.x;
- cr.bottom = ptr.y;
-
- if ( myHParentWindow ) {
-
-  ScreenToClient (      ( HWND )myHParentWindow, &ptl  );
-  ScreenToClient (  ( HWND )myHParentWindow, &ptr  );
-  cr.left   = ptl.x;
-  cr.top    = ptl.y;
-  cr.right  = ptr.x;
-  cr.bottom     = ptr.y;
-
- }  // end if
-
- X1 = ( Quantity_Parameter )cr.left   / ( Quantity_Parameter )pr.right;
- X2 = ( Quantity_Parameter )cr.right  / ( Quantity_Parameter )pr.right;
- Y1 = 1. - ( Quantity_Parameter )cr.top    / ( Quantity_Parameter )pr.bottom;
- Y2 = 1. - ( Quantity_Parameter )cr.bottom / ( Quantity_Parameter )pr.bottom;
-
-}  // end WNT_Window :: Position
-//***//
-//**************************** Position (2) ******************************//
-//***//
-void WNT_Window :: Position (
-                    Standard_Integer& X1, Standard_Integer& Y1,
-                    Standard_Integer& X2, Standard_Integer& Y2
-                   ) const {
-
- POINT ptl, ptr;
- RECT  r;
-
- GetClientRect (  ( HWND )myHWindow, &r  );
-
- ptl.x = ptl.y = 0;
- ClientToScreen (  ( HWND )myHWindow, &ptl  );
- ptr.x = r.right;
- ptr.y = r.bottom;
- ClientToScreen (  ( HWND )myHWindow, &ptr  );
-
- if ( myHParentWindow ) {
-
-  ScreenToClient (      ( HWND )myHParentWindow, &ptl  );
-  ScreenToClient (  ( HWND )myHParentWindow, &ptr  );
-
- }  // end if
-
- X1 = ptl.x;
- X2 = ptr.x;
- Y1 = ptl.y;
- Y2 = ptr.y;
-
-}  // end WNT_Window :: Position
-//***//
-//******************************* Size (1) *******************************//
-//***//
-void WNT_Window :: Size (
-                    Quantity_Parameter& Width, Quantity_Parameter& Height
-                   ) const {
-
- RECT pr, wr;
- const Handle( WNT_GraphicDevice )& dev = Handle( WNT_GraphicDevice ) ::
-                                           DownCast ( MyGraphicDevice );
-
- if ( myHParentWindow )
-
-  GetClientRect (  ( HWND )myHParentWindow, &pr  );
-
- else {
-
-  int w, h;
-
-  dev -> DisplaySize ( w, h );
-
-  pr.right  = w;
-  pr.bottom     = h;
-
- }  // end else
-
- GetClientRect (  ( HWND )myHWindow, &wr  );
-
- Width  = ( Quantity_Parameter )wr.right  / ( Quantity_Parameter )pr.right;
- Height = ( Quantity_Parameter )wr.bottom / ( Quantity_Parameter )pr.bottom;
-
-}  // end WNT_Window :: Size
-//***//
-//******************************* Size (2) *******************************//
-//***//
-void WNT_Window :: Size (
-                    Standard_Integer& Width, Standard_Integer& Height
-                   ) const {
-
- RECT r;
-
- GetClientRect (  ( HWND )myHWindow, &r  );
-
- Width  = r.right;
- Height = r.bottom;
-
-}  // end WNT_Window :: Size
-//***//
-//******************************* MMSize (1) *******************************//
-//***//
-void WNT_Window :: MMSize (
-                    Standard_Real& Width, Standard_Real& Height
-                   ) const {
-
- const Handle( WNT_GraphicDevice )& dev = Handle( WNT_GraphicDevice ) ::
-                                           DownCast ( MyGraphicDevice );
-
- int w, h;
- dev -> DisplaySize ( w, h );
- Standard_Real mmw,mmh;
- dev -> DisplaySize ( mmw, mmh );
- Standard_Real mmratio = (mmw/w + mmh/h)/2.;
-
- RECT wr;
- GetClientRect (  ( HWND )myHWindow, &wr  );
-
- Width  = mmratio * wr.right;
- Height = mmratio * wr.bottom;
-
-}  // end WNT_Window :: MMSize
-//***//
-//**************************** Convert (1) *******************************//
-//***//
-Quantity_Parameter WNT_Window :: Convert (
-                                  const Standard_Integer PV
-                                 ) const {
-
- int w, h;
- const Handle( WNT_GraphicDevice )& dev = Handle( WNT_GraphicDevice ) ::
-                                           DownCast ( MyGraphicDevice );
-
- dev -> DisplaySize ( w, h );
-
- return ( Quantity_Parameter )(  PV / Min ( w, h )  );
-
-}  // end WNT_Window :: Convert
-//***//
-//**************************** Convert (2) *******************************//
-//***//
-Standard_Integer WNT_Window :: Convert (
-                                const Quantity_Parameter DV
-                               ) const {
-
- int w, h;
- const Handle( WNT_GraphicDevice )& dev = Handle( WNT_GraphicDevice ) ::
-                                           DownCast ( MyGraphicDevice );
-
- dev -> DisplaySize ( w, h );
-
- return ( Standard_Integer )(  DV * Min ( w, h )  );
-
-}  // end WNT_Window :: Convert
-//***//
-//**************************** Convert (3) *******************************//
-//***//
-
-void WNT_Window :: Convert (
-                    const Standard_Integer PX, const Standard_Integer PY,
-                    Quantity_Parameter& DX, Quantity_Parameter& DY
-                   ) const {
-
- int w, h;
- const Handle( WNT_GraphicDevice )& dev = Handle( WNT_GraphicDevice ) ::
-                                           DownCast ( MyGraphicDevice );
+// =======================================================================
+// function : MouseKeyFlagsAsync
+// purpose  :
+// =======================================================================
+Aspect_VKeyFlags WNT_Window::MouseKeyFlagsAsync()
+{
+  Aspect_VKeyFlags aFlags = Aspect_VKeyFlags_NONE;
+  if ((GetAsyncKeyState (VK_CONTROL) & 0x8000) != 0)
+  {
+    aFlags |= Aspect_VKeyFlags_CTRL;
+  }
+  if ((GetAsyncKeyState (VK_SHIFT) & 0x8000) != 0)
+  {
+    aFlags |= Aspect_VKeyFlags_SHIFT;
+  }
+  if ((GetAsyncKeyState (VK_MENU) & 0x8000) != 0)
+  {
+    aFlags |= Aspect_VKeyFlags_ALT;
+  }
+  return aFlags;
+}
 
- dev -> DisplaySize ( w, h );
+// =======================================================================
+// function : MouseButtonsFromEvent
+// purpose  :
+// =======================================================================
+Aspect_VKeyMouse WNT_Window::MouseButtonsFromEvent (WPARAM theKeys)
+{
+  Aspect_VKeyMouse aButtons = Aspect_VKeyMouse_NONE;
+  if ((theKeys & MK_LBUTTON) != 0)
+  {
+    aButtons |= Aspect_VKeyMouse_LeftButton;
+  }
+  if ((theKeys & MK_MBUTTON) != 0)
+  {
+    aButtons |= Aspect_VKeyMouse_MiddleButton;
+  }
+  if ((theKeys & MK_RBUTTON) != 0)
+  {
+    aButtons |= Aspect_VKeyMouse_RightButton;
+  }
+  return aButtons;
+}
 
- DX = ( Quantity_Parameter )PX / ( Quantity_Parameter )w;
- DY = 1. - ( Quantity_Parameter )PY / ( Quantity_Parameter )h;
-
-}  // end WNT_Window :: Convert
-//***//
-//**************************** Convert (4) *******************************//
-//***//
-void WNT_Window :: Convert (
-                    const Quantity_Parameter DX, const Quantity_Parameter DY,
-                    Standard_Integer& PX, Standard_Integer& PY
-                   ) const {
-
- int w, h;
- const Handle( WNT_GraphicDevice )& dev = Handle( WNT_GraphicDevice ) ::
-                                           DownCast ( MyGraphicDevice );
-
- dev -> DisplaySize ( w, h );
-
- PX = ( Standard_Integer )(  DX * ( Quantity_Parameter )w           );
- PY = ( Standard_Integer )(  ( 1. - DY ) * ( Quantity_Parameter )h  );
-
-}  // end WNT_Window :: Convert
-//***//
-//******************************* SetPos *********************************//
-//***//
-void WNT_Window :: SetPos (
-                    const Standard_Integer X,  const Standard_Integer Y,
-                    const Standard_Integer X1, const Standard_Integer Y1
-                   ) {
-
- aXLeft   = X;
- aYTop    = Y;
- aXRight  = X1;
- aYBottom = Y1;
-
-}  // end WNT_Window :: SetPos
-//***//
-//*************************** SetOutputFormat ****************************//
-//***//
-void WNT_Window :: SetOutputFormat ( const WNT_TypeOfImage aFormat ) {
-
- myFormat = aFormat;
- myImages -> SetFormat ( aFormat );
-
-}  // end WNT_Window :: SetOutputFormat
-//***//
-//**************************** SetFlags **********************************//
-//***//
-void WNT_Window :: SetFlags ( const Standard_Integer aFlags ) {
-
- myExtraData.dwFlags |= aFlags;
-
-}  // end WNT_Window :: SetFlags
-//***//
-//*************************** ResetFlags *********************************//
-//***//
-void WNT_Window :: ResetFlags ( const Standard_Integer aFlags ) {
-
- myExtraData.dwFlags &= ~aFlags;
+// =======================================================================
+// function : MouseButtonsAsync
+// purpose  :
+// =======================================================================
+Aspect_VKeyMouse WNT_Window::MouseButtonsAsync()
+{
+  Aspect_VKeyMouse aButtons = Aspect_VKeyMouse_NONE;
+  const bool isSwapped = GetSystemMetrics (SM_SWAPBUTTON) != 0;
 
-}  // end WNT_Window :: ResetFlags
-//***//
-//*************************** doCreate **********************************//
-//***//
-void WNT_Window :: doCreate (
-                    const Handle( WNT_GraphicDevice )& aDevice,
-                    const Aspect_Handle                aHandle,
-                    const Quantity_NameOfColor         aBackColor
-                   ) {
-
- LONG            uData;
- WNDPROC         wProc;
- WINDOWPLACEMENT wp;
-
- const Handle( WNT_GraphicDevice )& dev = Handle( WNT_GraphicDevice ) ::
-                                           DownCast ( MyGraphicDevice );
-
- ZeroMemory (  &myExtraData, sizeof ( WNT_WindowData )  );
-
- myHWindow        = aHandle;
- myHParentWindow  = GetParent (  ( HWND )aHandle  );
- myDoubleBuffer   = Standard_False;
- myHPixmap        = NULL;
- wProc            = (WNDPROC )GetWindowLongPtr ((HWND )aHandle, GWLP_WNDPROC);
- uData            = GetWindowLongPtr ((HWND )aHandle, GWLP_USERDATA);
- myUsrData        = Standard_Address(-1);
- myWndProc        = NULL;
-
- if ( wProc != &WNT_WndProc ) {
-
-  myWndProc = wProc;
-
-  SetBackground ( aBackColor );
-
-  myExtraData.WNT_Window_Ptr = ( void* )this;
-  myExtraData.hPal           = ( HPALETTE )dev -> HPalette ();
-
-  if (  uData != ( LONG )&myExtraData  )
+  if ((GetAsyncKeyState (!isSwapped ? VK_LBUTTON : VK_RBUTTON) & 0x8000) != 0)
+  {
+    aButtons |= Aspect_VKeyMouse_LeftButton;
+  }
+  if ((GetAsyncKeyState (VK_MBUTTON) & 0x8000) != 0)
   {
-    myUsrData = (Standard_Address )SetWindowLongPtr ((HWND )myHWindow, GWLP_USERDATA, (LONG_PTR )&myExtraData);
+    aButtons |= Aspect_VKeyMouse_MiddleButton;
   }
+  if ((GetAsyncKeyState (!isSwapped ? VK_RBUTTON : VK_LBUTTON) & 0x8000) != 0)
+  {
+    aButtons |= Aspect_VKeyMouse_RightButton;
+  }
+  return aButtons;
+}
 
-  if (myWndProc != NULL)
+// =======================================================================
+// function : RegisterRawInputDevices
+// purpose  :
+// =======================================================================
+int WNT_Window::RegisterRawInputDevices (unsigned int theRawDeviceMask)
+{
+  if (IsVirtual()
+   || myHWindow == NULL)
   {
-    SetWindowLongPtr ((HWND )myHWindow, GWLP_WNDPROC, (LONG_PTR )WNT_WndProc);
+    return 0;
   }
 
- }  // end if
+  // hidusage.h
+  enum HidUsagePage { THE_HID_USAGE_PAGE_GENERIC = 0x01 }; // HID_USAGE_PAGE_GENERIC
+  enum HidUsage
+  {
+    THE_HID_USAGE_GENERIC_MOUSE                 = 0x02, // HID_USAGE_GENERIC_MOUSE
+    THE_HID_USAGE_GENERIC_MULTI_AXIS_CONTROLLER = 0x08, // HID_USAGE_GENERIC_MULTI_AXIS_CONTROLLER
+  };
 
- myExtraData.dwFlags = WDF_FOREIGN;
+  int aNbDevices = 0;
+  RAWINPUTDEVICE aRawInDevList[2];
+  if ((theRawDeviceMask & RawInputMask_Mouse) != 0)
+  {
+    // mouse
+    RAWINPUTDEVICE& aRawMouse = aRawInDevList[aNbDevices++];
+    aRawMouse.usUsagePage = THE_HID_USAGE_PAGE_GENERIC;
+    aRawMouse.usUsage     = THE_HID_USAGE_GENERIC_MOUSE;
+    aRawMouse.dwFlags     = RIDEV_INPUTSINK;
+    aRawMouse.hwndTarget  = (HWND )myHWindow;
+  }
+  if ((theRawDeviceMask & RawInputMask_SpaceMouse) != 0)
+  {
+    // space mouse
+    RAWINPUTDEVICE& aRawSpace = aRawInDevList[aNbDevices++];
+    aRawSpace.usUsagePage = THE_HID_USAGE_PAGE_GENERIC;
+    aRawSpace.usUsage     = THE_HID_USAGE_GENERIC_MULTI_AXIS_CONTROLLER;
+    aRawSpace.dwFlags     = 0; // RIDEV_DEVNOTIFY
+    aRawSpace.hwndTarget  = (HWND )myHWindow;
+  }
 
- myImages = new WNT_ImageManager ( this );
- myFormat = WNT_TOI_XWD;
+  for (int aTryIter = aNbDevices; aTryIter > 0; --aTryIter)
+  {
+    if (::RegisterRawInputDevices (aRawInDevList, aTryIter, sizeof(aRawInDevList[0])))
+    {
+      return aTryIter;
+    }
+
+    Message::SendTrace (aRawInDevList[aTryIter - 1].usUsage == THE_HID_USAGE_GENERIC_MULTI_AXIS_CONTROLLER
+                      ? "Warning: RegisterRawInputDevices() failed to register RAW multi-axis controller input"
+                      : "Warning: RegisterRawInputDevices() failed to register RAW mouse input");
+  }
+  return 0;
+}
 
- wp.length = sizeof ( WINDOWPLACEMENT );
- GetWindowPlacement (  ( HWND )myHWindow, &wp  );
+// =======================================================================
+// function : ProcessMessage
+// purpose  :
+// =======================================================================
+bool WNT_Window::ProcessMessage (Aspect_WindowInputListener& theListener,
+                                 MSG& theMsg)
+{
+  if (myTouchInputHelper.IsNull())
+  {
+    myTouchInputHelper = new TouchInputHelper();
+    myTouchInputHelper->Register ((HWND )myHWindow);
+  }
 
- aXLeft   = wp.rcNormalPosition.left;
- aYTop    = wp.rcNormalPosition.top;
- aXRight  = wp.rcNormalPosition.right;
- aYBottom = wp.rcNormalPosition.bottom;
+  switch (theMsg.message)
+  {
+    case WM_CLOSE:
+    {
+      if (theMsg.hwnd == (HWND )myHWindow)
+      {
+        theListener.ProcessClose();
+        return true;
+      }
+      return false;
+    }
+    case WM_SETFOCUS:
+    case WM_KILLFOCUS:
+    {
+      if (theMsg.hwnd == (HWND )myHWindow)
+      {
+        theListener.ProcessFocus (theMsg.message == WM_SETFOCUS);
+        return true;
+      }
+      return false;
+    }
+    case WM_PAINT:
+    {
+      PAINTSTRUCT aPaint;
+      BeginPaint(theMsg.hwnd, &aPaint);
+      EndPaint  (theMsg.hwnd, &aPaint);
+      theListener.ProcessExpose();
+      return true;
+    }
+    case WM_SIZE:
+    case WM_MOVE:
+    case WM_MOVING:
+    case WM_SIZING:
+    {
+      theListener.ProcessConfigure (theMsg.message == WM_SIZE);
+      return true;
+    }
+    case WM_KEYUP:
+    case WM_KEYDOWN:
+    {
+      const Aspect_VKey aVKey = WNT_Window::VirtualKeyFromNative ((Standard_Integer )theMsg.wParam);
+      if (aVKey != Aspect_VKey_UNKNOWN)
+      {
+        const double aTimeStamp = theListener.EventTime();
+        if (theMsg.message == WM_KEYDOWN)
+        {
+          theListener.KeyDown (aVKey, aTimeStamp);
+        }
+        else
+        {
+          theListener.KeyUp (aVKey, aTimeStamp);
+        }
+        theListener.ProcessInput();
+      }
+      return true;
+    }
+    case WM_LBUTTONUP:
+    case WM_MBUTTONUP:
+    case WM_RBUTTONUP:
+    case WM_LBUTTONDOWN:
+    case WM_MBUTTONDOWN:
+    case WM_RBUTTONDOWN:
+    {
+      const LPARAM anExtraInfo = GetMessageExtraInfo();
+      bool isEmulated = false;
+      if ((anExtraInfo & MOUSEEVENTF_FROMTOUCH) == MOUSEEVENTF_FROMTOUCH)
+      {
+        isEmulated = true;
+        if (!myTouchInputHelper.IsNull()
+          && myTouchInputHelper->IsRegistered())
+        {
+          //Message::SendTrace ("Skipping mouse message emulated from touches...");
+          break;
+        }
+      }
+
+      const Graphic3d_Vec2i aPos (LOWORD(theMsg.lParam), HIWORD(theMsg.lParam));
+      const Aspect_VKeyFlags aFlags = WNT_Window::MouseKeyFlagsFromEvent (theMsg.wParam);
+      Aspect_VKeyMouse aButton = Aspect_VKeyMouse_NONE;
+      switch (theMsg.message)
+      {
+        case WM_LBUTTONUP:
+        case WM_LBUTTONDOWN:
+          aButton = Aspect_VKeyMouse_LeftButton;
+          break;
+        case WM_MBUTTONUP:
+        case WM_MBUTTONDOWN:
+          aButton = Aspect_VKeyMouse_MiddleButton;
+          break;
+        case WM_RBUTTONUP:
+        case WM_RBUTTONDOWN:
+          aButton = Aspect_VKeyMouse_RightButton;
+          break;
+      }
+      if (theMsg.message == WM_LBUTTONDOWN
+       || theMsg.message == WM_MBUTTONDOWN
+       || theMsg.message == WM_RBUTTONDOWN)
+      {
+        SetFocus  (theMsg.hwnd);
+        SetCapture(theMsg.hwnd);
+        theListener.PressMouseButton (aPos, aButton, aFlags, isEmulated);
+      }
+      else
+      {
+        ReleaseCapture();
+        theListener.ReleaseMouseButton (aPos, aButton, aFlags, isEmulated);
+      }
+      theListener.ProcessInput();
+      return true;
+    }
+    case WM_MOUSEWHEEL:
+    {
+      const int aDelta = GET_WHEEL_DELTA_WPARAM (theMsg.wParam);
+      const Standard_Real aDeltaF = Standard_Real(aDelta) / Standard_Real(WHEEL_DELTA);
+      const Aspect_VKeyFlags aFlags = WNT_Window::MouseKeyFlagsFromEvent (theMsg.wParam);
+      Graphic3d_Vec2i aPos (int(short(LOWORD(theMsg.lParam))), int(short(HIWORD(theMsg.lParam))));
+      POINT aCursorPnt = { aPos.x(), aPos.y() };
+      if (ScreenToClient (theMsg.hwnd, &aCursorPnt))
+      {
+        aPos.SetValues (aCursorPnt.x, aCursorPnt.y);
+      }
+
+      if (theMsg.hwnd != (HWND )myHWindow)
+      {
+        return false;
+      }
+
+      theListener.UpdateMouseScroll (Aspect_ScrollDelta (aPos, aDeltaF, aFlags));
+      theListener.ProcessInput();
+      return true;
+    }
+    case WM_MOUSEMOVE:
+    {
+      Graphic3d_Vec2i aPos (LOWORD(theMsg.lParam), HIWORD(theMsg.lParam));
+      Aspect_VKeyMouse aButtons = WNT_Window::MouseButtonsFromEvent (theMsg.wParam);
+      Aspect_VKeyFlags aFlags   = WNT_Window::MouseKeyFlagsFromEvent(theMsg.wParam);
+
+      // don't make a slide-show from input events - fetch the actual mouse cursor position
+      CURSORINFO aCursor;
+      aCursor.cbSize = sizeof(aCursor);
+      if (::GetCursorInfo (&aCursor) != FALSE)
+      {
+        POINT aCursorPnt = { aCursor.ptScreenPos.x, aCursor.ptScreenPos.y };
+        if (ScreenToClient (theMsg.hwnd, &aCursorPnt))
+        {
+          // as we override mouse position, we need overriding also mouse state
+          aPos.SetValues (aCursorPnt.x, aCursorPnt.y);
+          aButtons = WNT_Window::MouseButtonsAsync();
+          aFlags   = WNT_Window::MouseKeyFlagsAsync();
+        }
+      }
+
+      if (theMsg.hwnd != (HWND )myHWindow)
+      {
+        // mouse move events come also for inactive windows
+        return false;
+      }
+
+      theListener.UpdateMousePosition (aPos, aButtons, aFlags, false);
+      theListener.ProcessInput();
+      return true;
+    }
+    case WM_INPUT:
+    {
+      UINT aSize = 0;
+      ::GetRawInputData ((HRAWINPUT )theMsg.lParam, RID_INPUT, NULL, &aSize, sizeof(RAWINPUTHEADER));
+      NCollection_LocalArray<BYTE> aRawData (aSize);
+      if (aSize == 0 || ::GetRawInputData ((HRAWINPUT )theMsg.lParam, RID_INPUT, aRawData, &aSize, sizeof(RAWINPUTHEADER)) != aSize)
+      {
+        return true;
+      }
+
+      const RAWINPUT* aRawInput = (RAWINPUT* )(BYTE* )aRawData;
+      if (aRawInput->header.dwType != RIM_TYPEHID)
+      {
+        return true;
+      }
+
+      RID_DEVICE_INFO aDevInfo;
+      aDevInfo.cbSize = sizeof(RID_DEVICE_INFO);
+      UINT aDevInfoSize = sizeof(RID_DEVICE_INFO);
+      if (::GetRawInputDeviceInfoW (aRawInput->header.hDevice, RIDI_DEVICEINFO, &aDevInfo, &aDevInfoSize) != sizeof(RID_DEVICE_INFO)
+       || (aDevInfo.hid.dwVendorId != WNT_HIDSpaceMouse::VENDOR_ID_LOGITECH
+        && aDevInfo.hid.dwVendorId != WNT_HIDSpaceMouse::VENDOR_ID_3DCONNEXION))
+      {
+        return true;
+      }
+
+      WNT_HIDSpaceMouse aSpaceData (aDevInfo.hid.dwProductId, aRawInput->data.hid.bRawData, aRawInput->data.hid.dwSizeHid);
+      if (theListener.Update3dMouse (aSpaceData))
+      {
+        InvalidateContent (Handle(Aspect_DisplayConnection)());
+      }
+      return true;
+    }
+    case WM_TOUCH:
+    {
+      if (theMsg.hwnd != (HWND )myHWindow
+       || myTouchInputHelper.IsNull())
+      {
+        return false;
+      }
+
+      TouchInputHelper::TouchInputInfo aSrcTouches (*myTouchInputHelper, theMsg);
+      if (aSrcTouches.Size() < 1)
+      {
+        break;
+      }
+
+      Graphic3d_Vec2i aWinTopLeft, aWinBotRight;
+      Position (aWinTopLeft.x(),  aWinTopLeft.y(),
+                aWinBotRight.x(), aWinBotRight.y());
+
+      bool hasUpdates = false;
+      for (size_t aTouchIter = 0; aTouchIter < aSrcTouches.Size(); ++aTouchIter)
+      {
+        const TOUCHINPUT& aTouchSrc = aSrcTouches[aTouchIter];
+        const Standard_Size aTouchId = (Standard_Size )aTouchSrc.dwID;
+        //const Standard_Size aDeviceId = (Standard_Size )aTouchSrc.hSource;
+
+        const Graphic3d_Vec2i aSize = aWinBotRight - aWinTopLeft;
+        const Graphic3d_Vec2d aNewPos2d = Graphic3d_Vec2d (double(aTouchSrc.x), double(aTouchSrc.y)) * 0.01
+                                        - Graphic3d_Vec2d (aWinTopLeft);
+        const Graphic3d_Vec2i aNewPos2i = Graphic3d_Vec2i (aNewPos2d + Graphic3d_Vec2d (0.5));
+        if ((aTouchSrc.dwFlags & TOUCHEVENTF_DOWN) == TOUCHEVENTF_DOWN)
+        {
+          if (aNewPos2i.x() >= 0 && aNewPos2i.x() < aSize.x()
+           && aNewPos2i.y() >= 0 && aNewPos2i.y() < aSize.y())
+          {
+            hasUpdates = true;
+            theListener.AddTouchPoint (aTouchId, aNewPos2d);
+          }
+        }
+        else if ((aTouchSrc.dwFlags & TOUCHEVENTF_MOVE) == TOUCHEVENTF_MOVE)
+        {
+          const int anOldIndex = theListener.TouchPoints().FindIndex (aTouchId);
+          if (anOldIndex != 0)
+          {
+            hasUpdates = true;
+            theListener.UpdateTouchPoint (aTouchId, aNewPos2d);
+          }
+        }
+        else if ((aTouchSrc.dwFlags & TOUCHEVENTF_UP) == TOUCHEVENTF_UP)
+        {
+          if (theListener.RemoveTouchPoint (aTouchId))
+          {
+            hasUpdates = true;
+          }
+        }
+      }
+
+      if (hasUpdates)
+      {
+        InvalidateContent (Handle(Aspect_DisplayConnection)());
+      }
+      return true;
+    }
+  }
+  return false;
+}
 
-}  // end WNT_Window :: doCreate
-//***//
-//************************************************************************//
+#endif // _WIN32