1 // Created on: 1996-01-26
2 // Created by: PLOTNIKOV Eugeny
3 // Copyright (c) 1996-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
17 #ifndef _WNT_Window_HeaderFile
18 #define _WNT_Window_HeaderFile
20 #include <Aspect_Window.hxx>
22 #if defined(_WIN32) && !defined(OCCT_UWP)
24 #include <Aspect_Drawable.hxx>
25 #include <Aspect_VKey.hxx>
26 #include <Aspect_Handle.hxx>
27 #include <WNT_Dword.hxx>
29 class Aspect_WindowInputListener;
31 typedef struct tagMSG MSG;
33 DEFINE_STANDARD_HANDLE(WNT_Window, Aspect_Window)
35 //! This class defines Windows NT window
36 class WNT_Window : public Aspect_Window
38 DEFINE_STANDARD_RTTIEXT(WNT_Window, Aspect_Window)
41 //! Convert WInAPI virtual key (VK_ enumeration) into Aspect_VKey.
42 Standard_EXPORT static Aspect_VKey VirtualKeyFromNative (Standard_Integer theKey);
44 //! Convert WPARAM from mouse event to key flags.
45 Standard_EXPORT static Aspect_VKeyFlags MouseKeyFlagsFromEvent (WPARAM theKeys);
47 //! Convert WPARAM from mouse event to mouse buttons bitmask.
48 Standard_EXPORT static Aspect_VKeyMouse MouseButtonsFromEvent (WPARAM theKeys);
50 //! Use GetAsyncKeyState() to fetch actual mouse key flags regardless of event loop.
51 Standard_EXPORT static Aspect_VKeyFlags MouseKeyFlagsAsync();
53 //! Use GetAsyncKeyState() to fetch actual mouse buttons state regardless of event loop.
54 Standard_EXPORT static Aspect_VKeyMouse MouseButtonsAsync();
58 //! Creates a Window defined by his position and size in pixels from the Parent Window.
59 //! Trigger: Raises WindowDefinitionError if the Position out of the Screen Space or the window creation failed.
60 Standard_EXPORT WNT_Window (const Standard_CString theTitle,
61 const Handle(WNT_WClass)& theClass,
62 const WNT_Dword& theStyle,
63 const Standard_Integer thePxLeft, const Standard_Integer thePxTop,
64 const Standard_Integer thePxWidth, const Standard_Integer thePxHeight,
65 const Quantity_NameOfColor theBackColor = Quantity_NOC_MATRAGRAY,
66 const Aspect_Handle theParent = 0,
67 const Aspect_Handle theMenu = 0,
68 const Standard_Address theClientStruct = 0);
70 //! Creates a Window based on the existing window handle.
71 Standard_EXPORT WNT_Window (const Aspect_Handle theHandle,
72 const Quantity_NameOfColor theBackColor = Quantity_NOC_MATRAGRAY);
74 //! Destroys the Window and all resources attached to it.
75 Standard_EXPORT virtual ~WNT_Window();
77 //! Sets cursor for ENTIRE WINDOW CLASS to which the Window belongs.
78 Standard_EXPORT void SetCursor (const Aspect_Handle theCursor) const;
80 //! Opens the window <me>.
81 Standard_EXPORT virtual void Map() const Standard_OVERRIDE;
83 //! Opens a window according to the map mode.
84 //! This method is specific to Windows NT.
85 //! @param theMapMode [in] can be one of SW_xxx constants defined in <windows.h>
86 Standard_EXPORT void Map (const Standard_Integer theMapMode) const;
88 //! Closes the window <me>.
89 Standard_EXPORT virtual void Unmap() const Standard_OVERRIDE;
91 //! Applies the resizing to the window <me>.
92 Standard_EXPORT virtual Aspect_TypeOfResize DoResize() Standard_OVERRIDE;
94 //! Does nothing on Windows.
95 virtual Standard_Boolean DoMapping() const Standard_OVERRIDE { return Standard_True; }
97 //! Changes variables due to window position.
98 Standard_EXPORT void SetPos (const Standard_Integer X, const Standard_Integer Y, const Standard_Integer X1, const Standard_Integer Y1);
100 //! Returns True if the window <me> is opened
101 //! and False if the window is closed.
102 Standard_EXPORT virtual Standard_Boolean IsMapped() const Standard_OVERRIDE;
104 //! Returns The Window RATIO equal to the physical
105 //! WIDTH/HEIGHT dimensions.
106 Standard_EXPORT virtual Standard_Real Ratio() const Standard_OVERRIDE;
108 //! Returns The Window POSITION in PIXEL
109 Standard_EXPORT virtual void Position (Standard_Integer& X1, Standard_Integer& Y1, Standard_Integer& X2, Standard_Integer& Y2) const Standard_OVERRIDE;
111 //! Returns The Window SIZE in PIXEL
112 Standard_EXPORT virtual void Size (Standard_Integer& Width, Standard_Integer& Height) const Standard_OVERRIDE;
114 //! Returns native Window handle (HWND)
115 virtual Aspect_Drawable NativeHandle() const Standard_OVERRIDE { return (Aspect_Drawable )myHWindow; }
117 //! Returns parent of native Window handle (HWND on Windows).
118 virtual Aspect_Drawable NativeParentHandle() const Standard_OVERRIDE { return (Aspect_Drawable )myHParentWindow; }
120 //! Returns nothing on Windows
121 virtual Aspect_FBConfig NativeFBConfig() const Standard_OVERRIDE { return NULL; }
123 //! Sets window title.
124 Standard_EXPORT virtual void SetTitle (const TCollection_AsciiString& theTitle) Standard_OVERRIDE;
126 //! Invalidate entire window content by calling InvalidateRect() WinAPI function, resulting in WM_PAINT event put into window message loop.
127 //! Method can be called from non-window thread, and system will also automatically aggregate multiple events into single one.
128 Standard_EXPORT virtual void InvalidateContent (const Handle(Aspect_DisplayConnection)& theDisp = Handle(Aspect_DisplayConnection)()) Standard_OVERRIDE;
132 //! Returns the Windows NT handle of the created window <me>.
133 Aspect_Handle HWindow() const { return myHWindow; }
135 //! Returns the Windows NT handle parent of the created window <me>.
136 Aspect_Handle HParentWindow() const { return myHParentWindow; }
141 RawInputMask_Mouse = 0x01, //!< HID_USAGE_GENERIC_MOUSE
142 RawInputMask_SpaceMouse = 0x02, //!< HID_USAGE_GENERIC_MULTI_AXIS_CONTROLLER
145 //! RegisterRawInputDevices() wrapper.
146 //! @param theRawDeviceMask [in] mask of RawInputMask flags
147 //! @return number of actually registered device types
148 Standard_EXPORT int RegisterRawInputDevices (unsigned int theRawDeviceMask);
150 //! Process a single window message.
151 //! @param theListener [in][out] listener to redirect message
152 //! @param theMsg [in][out] message to process
153 //! @return TRUE if message has been processed
154 Standard_EXPORT virtual bool ProcessMessage (Aspect_WindowInputListener& theListener,
159 Handle(WNT_WClass) myWClass;
160 Aspect_Handle myHWindow;
161 Aspect_Handle myHParentWindow;
162 Standard_Integer myXLeft;
163 Standard_Integer myYTop;
164 Standard_Integer myXRight;
165 Standard_Integer myYBottom;
166 Standard_Boolean myIsForeign;
171 #endif // _WNT_Window_HeaderFile