0031668: Visualization - WebGL sample doesn't work on Emscripten 1.39
[occt.git] / src / WNT / WNT_Window.cxx
old mode 100755 (executable)
new mode 100644 (file)
index 11cab24..6408620
@@ -1,40 +1,40 @@
 // 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.
+// Alternatively, this file may be used under the terms of Open CASCADE
+// commercial license or contractual agreement.
 
-// include windows.h first to have all definitions available
-#include <windows.h>
+#if defined(_WIN32)
+  // include windows.h first to have all definitions available
+  #include <windows.h>
+#endif
 
-//                GG 07/03/00 Add MMSize() method
+#include <WNT_Window.hxx>
 
-#include <WNT_Window.ixx>
+#if defined(_WIN32) && !defined(OCCT_UWP)
 
-#include <Image_AlienPixMap.hxx>
 #include <Aspect_Convert.hxx>
-
-#include <stdio.h>
-
-//************************************************************************//
-//***//
-// callback function to manage window's background
-extern LRESULT CALLBACK WNT_WndProc (
-                         HWND, UINT, WPARAM, LPARAM
-                        );
-
+#include <Aspect_WindowDefinitionError.hxx>
+#include <Aspect_WindowError.hxx>
+#include <Message.hxx>
+#include <Standard_Type.hxx>
+#include <TCollection_ExtendedString.hxx>
+#include <WNT_WClass.hxx>
+
+IMPLEMENT_STANDARD_RTTIEXT(WNT_Window, Aspect_Window)
+
+// =======================================================================
+// function : WNT_Window
+// purpose  :
+// =======================================================================
 WNT_Window::WNT_Window (const Standard_CString           theTitle,
                         const Handle(WNT_WClass)&        theClass,
                         const WNT_Dword&                 theStyle,
@@ -51,177 +51,168 @@ WNT_Window::WNT_Window (const Standard_CString           theTitle,
   aYTop (thePxTop),
   aXRight (thePxLeft + thePxWidth),
   aYBottom (thePxTop + thePxHeight),
-  myWClass (theClass)
+  myWClass (theClass),
+  myIsForeign (Standard_False)
 {
-  ZeroMemory (&myExtraData, sizeof (WNT_WindowData));
-  DWORD dwStyle = theStyle;
-
   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;
+    aStyle |= WS_CLIPCHILDREN;
   }
 
-  // include decorations in the window dimensions
-  // to reproduce same behaviour of Xw_Window.
+  // include decorations in the window dimensions to reproduce same behavior of Xw_Window
   RECT aRect;
   aRect.top    = aYTop;
   aRect.bottom = aYBottom;
   aRect.left   = aXLeft;
   aRect.right  = aXRight;
-  AdjustWindowRect (&aRect, dwStyle, theMenu != NULL ? TRUE : FALSE);
+  AdjustWindowRect (&aRect, aStyle, theMenu != NULL ? TRUE : FALSE);
   aXLeft   = aRect.left;
   aYTop    = aRect.top;
   aXRight  = aRect.right;
   aYBottom = aRect.bottom;
 
-  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
+  const TCollection_ExtendedString aTitleW (theTitle);
+  const TCollection_ExtendedString aClassNameW (myWClass->Name());
+  myHWindow = CreateWindowW (aClassNameW.ToWideString(), aTitleW.ToWideString(),
+                             aStyle,
+                             aXLeft, aYTop,
+                             (aXRight - aXLeft), (aYBottom - aYTop),
+                             (HWND )theParent,
+                             (HMENU )theMenu,
+                             (HINSTANCE )myWClass->Instance(),
+                             theClientStruct);
   if (!myHWindow)
   {
-    Aspect_WindowDefinitionError::Raise ("Unable to create window");
+    throw Aspect_WindowDefinitionError("Unable to create window");
   }
 
   myHParentWindow = theParent;
   SetBackground (theBackColor);
-
-  myUsrData = (Standard_Address )SetWindowLongPtr ((HWND )myHWindow, GWLP_USERDATA, (LONG_PTR )&myExtraData);
-
-  myExtraData.WNT_Window_Ptr = (void* )this;
-
-  SetFlags (WDF_NOERASEBKGRND);
 }
 
-//***//
-//************************* Constructor **********************************//
-//***//
-WNT_Window :: WNT_Window (
-               const Aspect_Handle                aHandle,
-               const Quantity_NameOfColor         aBackColor
-              ) : Aspect_Window()
-{
-  doCreate (aHandle, aBackColor);
-
-  /* Bug OCC20596 */
-  SetFlags(WDF_NOERASEBKGRND);
-
-}  // end constructor
-//***//
-//************************* Constructor **********************************//
-//***//
-WNT_Window :: WNT_Window (
-               const Standard_Integer             aPart1,
-               const Standard_Integer             aPart2,
-               const Quantity_NameOfColor         aBackColor
-              ) : Aspect_Window()
+// =======================================================================
+// function : WNT_Window
+// purpose  :
+// =======================================================================
+WNT_Window::WNT_Window (const Aspect_Handle        theHandle,
+                        const Quantity_NameOfColor theBackColor)
+: myIsForeign (Standard_True)
 {
-  Aspect_Handle aHandle = ( Aspect_Handle )(  ( aPart1 << 16 ) + aPart2  );
+  myHWindow        = theHandle;
+  myHParentWindow  = GetParent ((HWND )theHandle);
 
-  doCreate (aHandle, aBackColor);
+  SetBackground (theBackColor);
+
+  WINDOWPLACEMENT aPlace;
+  aPlace.length = sizeof (WINDOWPLACEMENT);
+  ::GetWindowPlacement ((HWND )myHWindow, &aPlace);
 
-  /* Bug OCC20596 */
-  SetFlags(WDF_NOERASEBKGRND);
+  aXLeft   = aPlace.rcNormalPosition.left;
+  aYTop    = aPlace.rcNormalPosition.top;
+  aXRight  = aPlace.rcNormalPosition.right;
+  aYBottom = aPlace.rcNormalPosition.bottom;
+}
 
-}  // end constructor
-//***//
-//***************************** Destroy **********************************//
-//***//
-void WNT_Window :: Destroy ()
+// =======================================================================
+// function : ~WNT_Window
+// purpose  :
+// =======================================================================
+WNT_Window::~WNT_Window()
 {
-  if (myHWindow)
+  if (myHWindow == NULL
+   || myIsForeign)
   {
-    if (myUsrData != Standard_Address(-1))
-    {
-      SetWindowLongPtr ((HWND )myHWindow, GWLP_USERDATA, (LONG_PTR )myUsrData);
-    }
-
-    if (!( myExtraData.dwFlags & WDF_FOREIGN))
-    {
-      DestroyWindow ((HWND )myHWindow);
-    }
-  }  // end if
-}  // end WNT_Window :: Destroy
-
-//**************************** SetCursor *********************************//
-//***//
-void WNT_Window :: SetCursor ( const Aspect_Handle aCursor ) const {
+    return;
+  }
 
-#ifndef _WIN64
- SetClassLong (  ( HWND )myHWindow, GCL_HCURSOR, ( LONG )aCursor  );
-#else
- SetClassLong (  ( HWND )myHWindow, GCLP_HCURSOR, ( LONG )aCursor  );
-#endif
+  DestroyWindow ((HWND )myHWindow);
+  myIsForeign = Standard_False;
+}
 
-}  // end WNT_Window :: SetCursor
+// =======================================================================
+// function : SetCursor
+// purpose  :
+// =======================================================================
+void WNT_Window::SetCursor (const Aspect_Handle theCursor) const
+{
+  ::SetClassLongPtrW ((HWND )myHWindow, GCLP_HCURSOR, (LONG_PTR )theCursor);
+}
 
-//***//
-//***************************** IsMapped *********************************//
-//***//
-Standard_Boolean WNT_Window :: IsMapped () const {
-  if (IsVirtual()) {
+// =======================================================================
+// function : IsMapped
+// purpose  :
+// =======================================================================
+Standard_Boolean WNT_Window::IsMapped() const
+{
+  if (IsVirtual())
+  {
     return Standard_True;
   }
 
-  WINDOWPLACEMENT wp;
-
-  wp.length = sizeof ( WINDOWPLACEMENT );
-  GetWindowPlacement (  ( HWND )myHWindow, &wp  );
-
-  return !(  wp.showCmd == SW_HIDE || wp.showCmd == SW_MINIMIZE );
-}  // WNT_Window :: IsMapped
+  WINDOWPLACEMENT aPlace;
+  aPlace.length = sizeof (WINDOWPLACEMENT);
+  ::GetWindowPlacement ((HWND )myHWindow, &aPlace);
+  return !(aPlace.showCmd == SW_HIDE
+        || aPlace.showCmd == SW_MINIMIZE);
+}
 
-//***//
-//***************************** Map (1) **********************************//
-//***//
-void WNT_Window :: Map () const {
-  if (IsVirtual()) {
-    return;
+// =======================================================================
+// function : Map
+// purpose  :
+// =======================================================================
+void WNT_Window::Map() const
+{
+  if (!IsVirtual())
+  {
+    Map (SW_SHOW);
   }
-  Map ( SW_SHOW );
-}  // end WNT_Window :: Map
+}
 
-//***//
-//***************************** Map (2) **********************************//
-//***//
-void WNT_Window :: Map ( const Standard_Integer aMapMode ) const {
-  if (IsVirtual()) {
+// =======================================================================
+// function : Map
+// purpose  :
+// =======================================================================
+void WNT_Window::Map (const Standard_Integer theMapMode) const
+{
+  if (IsVirtual())
+  {
     return;
   }
-  ShowWindow (  ( HWND )myHWindow, aMapMode  );
-  UpdateWindow (  ( HWND )myHWindow  );
-
-}  // end WNT_Window :: Map
 
-//***//
-//**************************** Unmap *************************************//
-//***//
-void WNT_Window :: Unmap () const {
-
- Map ( SW_HIDE );
+  ::ShowWindow   ((HWND )myHWindow, theMapMode);
+  ::UpdateWindow ((HWND )myHWindow);
+}
 
-}  // end WNT_Window :: Unmap
+// =======================================================================
+// function : Unmap
+// purpose  :
+// =======================================================================
+void WNT_Window::Unmap() const
+{
+  Map (SW_HIDE);
+}
 
-//***//
-//**************************** DoResize **********************************//
-//***//
-Aspect_TypeOfResize WNT_Window :: DoResize () const
+// =======================================================================
+// function : DoResize
+// purpose  :
+// =======================================================================
+Aspect_TypeOfResize WNT_Window::DoResize()
 {
+  if (IsVirtual())
+  {
+    return Aspect_TOR_UNKNOWN;
+  }
+
   int                 mask = 0;
   Aspect_TypeOfResize mode = Aspect_TOR_UNKNOWN;
   WINDOWPLACEMENT     wp;
@@ -231,10 +222,10 @@ Aspect_TypeOfResize WNT_Window :: DoResize () const
 
   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;
+    if (Abs ((int )wp.rcNormalPosition.left   - aXLeft  ) > 2) mask |= 1;
+    if (Abs ((int )wp.rcNormalPosition.right  - aXRight ) > 2) mask |= 2;
+    if (Abs ((int )wp.rcNormalPosition.top    - aYTop   ) > 2) mask |= 4;
+    if (Abs ((int )wp.rcNormalPosition.bottom - aYBottom) > 2) mask |= 8;
 
     switch (mask)
     {
@@ -269,151 +260,443 @@ Aspect_TypeOfResize WNT_Window :: DoResize () const
         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;
+    aXLeft   = wp.rcNormalPosition.left;
+    aXRight  = wp.rcNormalPosition.right;
+    aYTop    = wp.rcNormalPosition.top;
+    aYBottom = wp.rcNormalPosition.bottom;
   }
 
   return mode;
-
-}  // end WNT_Window :: DoResize
-
-//***//
-//**************************** DoMapping **********************************//
-//***//
-Standard_Boolean WNT_Window :: DoMapping () const {
-// DO nothing on WNT.
-  return Standard_True;
 }
 
-//***//
-//******************************* 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 (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
+// =======================================================================
+// function : Ratio
+// purpose  :
+// =======================================================================
+Standard_Real WNT_Window::Ratio() const
+{
+  if (IsVirtual())
+  {
+    return Standard_Real(aXRight - aXLeft)/ Standard_Real(aYBottom - aYTop);
+  }
 
X1 = ptl.x;
X2 = ptr.x;
Y1 = ptl.y;
- Y2 = ptr.y;
 RECT aRect;
 GetClientRect ((HWND )myHWindow, &aRect);
 return Standard_Real(aRect.right - aRect.left) / Standard_Real(aRect.bottom - aRect.top);
+}
 
-}  // end WNT_Window :: Position
+// =======================================================================
+// function : Position
+// purpose  :
+// =======================================================================
+void WNT_Window::Position (Standard_Integer& theX1, Standard_Integer& theY1,
+                           Standard_Integer& theX2, Standard_Integer& theY2) const
+{
+  if (IsVirtual())
+  {
+    theX1  = aXLeft;
+    theX2  = aXRight;
+    theY1  = aYTop;
+    theY2  = aYBottom;
+    return;
+  }
 
-//***//
-//******************************* Size (2) *******************************//
-//***//
-void WNT_Window :: Size (
-                    Standard_Integer& Width, Standard_Integer& Height
-                   ) const {
+  RECT  aRect;
+  ::GetClientRect ((HWND )myHWindow, &aRect);
 
- RECT r;
+  POINT aPntLeft, aPntRight;
+  aPntLeft.x = aPntLeft.y = 0;
+  ::ClientToScreen ((HWND )myHWindow, &aPntLeft);
+  aPntRight.x = aRect.right;
+  aPntRight.y = aRect.bottom;
+  ::ClientToScreen ((HWND )myHWindow, &aPntRight);
 
- GetClientRect (  ( HWND )myHWindow, &r  );
+  if (myHParentWindow != NULL)
+  {
+    ::ScreenToClient ((HWND )myHParentWindow, &aPntLeft);
+    ::ScreenToClient ((HWND )myHParentWindow, &aPntRight);
+  }
 
- Width  = r.right;
- Height = r.bottom;
+  theX1 = aPntLeft.x;
+  theX2 = aPntRight.x;
+  theY1 = aPntLeft.y;
+  theY2 = aPntRight.y;
+}
 
-}  // end WNT_Window :: Size
+// =======================================================================
+// function : Size
+// purpose  :
+// =======================================================================
+void WNT_Window::Size (Standard_Integer& theWidth,
+                       Standard_Integer& theHeight) const
+{
+  if (IsVirtual())
+  {
+    theWidth  = aXRight - aXLeft;
+    theHeight = aYBottom - aYTop;
+    return;
+  }
 
-//***//
-//******************************* SetPos *********************************//
-//***//
-void WNT_Window :: SetPos (
-                    const Standard_Integer X,  const Standard_Integer Y,
-                    const Standard_Integer X1, const Standard_Integer Y1
-                   ) {
+  RECT aRect;
+  ::GetClientRect ((HWND )myHWindow, &aRect);
+  theWidth  = aRect.right;
+  theHeight = aRect.bottom;
+}
 
- aXLeft   = X;
- aYTop    = Y;
- aXRight  = X1;
- aYBottom = Y1;
+// =======================================================================
+// function : SetPos
+// purpose  :
+// =======================================================================
+void WNT_Window::SetPos (const Standard_Integer theX,  const Standard_Integer theY,
+                         const Standard_Integer theX1, const Standard_Integer theY1)
+{
+  aXLeft   = theX;
+  aYTop    = theY;
+  aXRight  = theX1;
+  aYBottom = theY1;
+}
 
-}  // end WNT_Window :: SetPos
+// =======================================================================
+// function : SetTitle
+// purpose  :
+// =======================================================================
+void WNT_Window::SetTitle (const TCollection_AsciiString& theTitle)
+{
+  const TCollection_ExtendedString aTitleW (theTitle);
+  SetWindowTextW ((HWND )myHWindow, aTitleW.ToWideString());
+}
 
-//***//
-//**************************** SetFlags **********************************//
-//***//
-void WNT_Window :: SetFlags ( const Standard_Integer aFlags ) {
+// =======================================================================
+// function : InvalidateContent
+// purpose  :
+// =======================================================================
+void WNT_Window::InvalidateContent (const Handle(Aspect_DisplayConnection)& )
+{
+  if (myHWindow != NULL)
+  {
+    ::InvalidateRect ((HWND )myHWindow, NULL, TRUE);
+  }
+}
 
- myExtraData.dwFlags |= aFlags;
+// =======================================================================
+// function : VirtualKeyFromNative
+// purpose  :
+// =======================================================================
+Aspect_VKey WNT_Window::VirtualKeyFromNative (Standard_Integer theKey)
+{
+  if (theKey >= Standard_Integer('0')
+   && theKey <= Standard_Integer('9'))
+  {
+    return Aspect_VKey((theKey - Standard_Integer('0')) + Aspect_VKey_0);
+  }
+  if (theKey >= Standard_Integer('A')
+   && theKey <= Standard_Integer('Z'))
+  {
+    // main latin alphabet keys
+    return Aspect_VKey((theKey - Standard_Integer('A')) + Aspect_VKey_A);
+  }
+  if (theKey >= VK_F1
+   && theKey <= VK_F24)
+  {
+    // 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);
+  }
 
-}  // end WNT_Window :: SetFlags
+  switch (theKey)
+  {
+    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;
+  }
+  return Aspect_VKey_UNKNOWN;
+}
 
-//***//
-//*************************** ResetFlags *********************************//
-//***//
-void WNT_Window :: ResetFlags ( const Standard_Integer aFlags ) {
+// =======================================================================
+// function : MouseKeyFlagsFromEvent
+// purpose  :
+// =======================================================================
+Aspect_VKeyFlags WNT_Window::MouseKeyFlagsFromEvent (WPARAM theKeys)
+{
+  Aspect_VKeyFlags aFlags = Aspect_VKeyFlags_NONE;
+  if ((theKeys & MK_CONTROL) != 0)
+  {
+    aFlags |= Aspect_VKeyFlags_CTRL;
+  }
+  if ((theKeys & MK_SHIFT) != 0)
+  {
+    aFlags |= Aspect_VKeyFlags_SHIFT;
+  }
+  if (GetKeyState (VK_MENU) < 0)
+  {
+    aFlags |= Aspect_VKeyFlags_ALT;
+  }
+  return aFlags;
+}
 
- myExtraData.dwFlags &= ~aFlags;
+// =======================================================================
+// 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;
+}
 
-}  // end WNT_Window :: ResetFlags
+// =======================================================================
+// 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;
+}
 
-//***//
-//*************************** doCreate **********************************//
-//***//
-void WNT_Window :: doCreate (
-                    const Aspect_Handle                aHandle,
-                    const Quantity_NameOfColor         aBackColor
-                   )
+// =======================================================================
+// function : MouseButtonsAsync
+// purpose  :
+// =======================================================================
+Aspect_VKeyMouse WNT_Window::MouseButtonsAsync()
 {
-  ZeroMemory (&myExtraData, sizeof (WNT_WindowData));
+  Aspect_VKeyMouse aButtons = Aspect_VKeyMouse_NONE;
+  const bool isSwapped = GetSystemMetrics (SM_SWAPBUTTON) != 0;
 
-  myHWindow        = aHandle;
-  myHParentWindow  = GetParent ((HWND )aHandle);
-  LONG_PTR uData   = GetWindowLongPtr ((HWND )aHandle, GWLP_USERDATA);
-  myUsrData        = Standard_Address(-1);
+  if ((GetAsyncKeyState (!isSwapped ? VK_LBUTTON : VK_RBUTTON) & 0x8000) != 0)
+  {
+    aButtons |= Aspect_VKeyMouse_LeftButton;
+  }
+  if ((GetAsyncKeyState (VK_MBUTTON) & 0x8000) != 0)
+  {
+    aButtons |= Aspect_VKeyMouse_MiddleButton;
+  }
+  if ((GetAsyncKeyState (!isSwapped ? VK_RBUTTON : VK_LBUTTON) & 0x8000) != 0)
+  {
+    aButtons |= Aspect_VKeyMouse_RightButton;
+  }
+  return aButtons;
+}
 
-  SetBackground (aBackColor);
+// =======================================================================
+// function : RegisterRawInputDevices
+// purpose  :
+// =======================================================================
+int WNT_Window::RegisterRawInputDevices (unsigned int theRawDeviceMask)
+{
+  if (IsVirtual()
+   || myHWindow == NULL)
+  {
+    return 0;
+  }
 
-  myExtraData.WNT_Window_Ptr = (void* )this;
+  // 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
+  };
 
-  if (uData != (LONG_PTR )&myExtraData)
+  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)
   {
-    myUsrData = (Standard_Address )SetWindowLongPtr ((HWND )myHWindow, GWLP_USERDATA, (LONG_PTR )&myExtraData);
+    // 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;
   }
 
-  myExtraData.dwFlags = WDF_FOREIGN;
+  for (int aTryIter = aNbDevices; aTryIter > 0; --aTryIter)
+  {
+    if (::RegisterRawInputDevices (aRawInDevList, aTryIter, sizeof(aRawInDevList[0])))
+    {
+      return aTryIter;
+    }
 
-  WINDOWPLACEMENT wp;
-  wp.length = sizeof (WINDOWPLACEMENT);
-  GetWindowPlacement ((HWND )myHWindow, &wp);
+    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;
+}
 
-  aXLeft   = wp.rcNormalPosition.left;
-  aYTop    = wp.rcNormalPosition.top;
-  aXRight  = wp.rcNormalPosition.right;
-  aYBottom = wp.rcNormalPosition.bottom;
-}  // end WNT_Window :: doCreate
+#endif // _WIN32