0032306: Draw Harness, ViewerTest - move window message processing to TKService
[occt.git] / src / WNT / WNT_Window.hxx
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
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
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.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17 #ifndef _WNT_Window_HeaderFile
18 #define _WNT_Window_HeaderFile
19
20 #include <Aspect_Window.hxx>
21
22 #if defined(_WIN32) && !defined(OCCT_UWP)
23
24 #include <Aspect_Drawable.hxx>
25 #include <Aspect_VKey.hxx>
26 #include <Aspect_Handle.hxx>
27 #include <WNT_Dword.hxx>
28
29 class Aspect_WindowInputListener;
30 class WNT_WClass;
31 typedef struct tagMSG MSG;
32
33 DEFINE_STANDARD_HANDLE(WNT_Window, Aspect_Window)
34
35 //! This class defines Windows NT window
36 class WNT_Window : public Aspect_Window
37 {
38   DEFINE_STANDARD_RTTIEXT(WNT_Window, Aspect_Window)
39 public:
40
41   //! Convert WInAPI virtual key (VK_ enumeration) into Aspect_VKey.
42   Standard_EXPORT static Aspect_VKey VirtualKeyFromNative (Standard_Integer theKey);
43
44   //! Convert WPARAM from mouse event to key flags.
45   Standard_EXPORT static Aspect_VKeyFlags MouseKeyFlagsFromEvent (WPARAM theKeys);
46
47   //! Convert WPARAM from mouse event to mouse buttons bitmask.
48   Standard_EXPORT static Aspect_VKeyMouse MouseButtonsFromEvent (WPARAM theKeys);
49
50   //! Use GetAsyncKeyState() to fetch actual mouse key flags regardless of event loop.
51   Standard_EXPORT static Aspect_VKeyFlags MouseKeyFlagsAsync();
52
53   //! Use GetAsyncKeyState() to fetch actual mouse buttons state regardless of event loop.
54   Standard_EXPORT static Aspect_VKeyMouse MouseButtonsAsync();
55
56 public:
57
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);
69
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);
73
74   //! Destroys the Window and all resources attached to it.
75   Standard_EXPORT virtual ~WNT_Window();
76
77   //! Sets cursor for ENTIRE WINDOW CLASS to which the Window belongs.
78   Standard_EXPORT void SetCursor (const Aspect_Handle theCursor) const;
79
80   //! Opens the window <me>.
81   Standard_EXPORT virtual void Map() const Standard_OVERRIDE;
82   
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;
87
88   //! Closes the window <me>.
89   Standard_EXPORT virtual void Unmap() const Standard_OVERRIDE;
90   
91   //! Applies the resizing to the window <me>.
92   Standard_EXPORT virtual Aspect_TypeOfResize DoResize() Standard_OVERRIDE;
93   
94   //! Does nothing on Windows.
95   virtual Standard_Boolean DoMapping() const Standard_OVERRIDE { return Standard_True; }
96
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);
99   
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;
103   
104   //! Returns The Window RATIO equal to the physical
105   //! WIDTH/HEIGHT dimensions.
106   Standard_EXPORT virtual Standard_Real Ratio() const Standard_OVERRIDE;
107   
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;
110   
111   //! Returns The Window SIZE in PIXEL
112   Standard_EXPORT virtual void Size (Standard_Integer& Width, Standard_Integer& Height) const Standard_OVERRIDE;
113   
114   //! Returns native Window handle (HWND)
115   virtual Aspect_Drawable NativeHandle() const Standard_OVERRIDE { return (Aspect_Drawable )myHWindow; }
116   
117   //! Returns parent of native Window handle (HWND on Windows).
118   virtual Aspect_Drawable NativeParentHandle() const Standard_OVERRIDE { return (Aspect_Drawable )myHParentWindow; }
119
120   //! Returns nothing on Windows
121   virtual Aspect_FBConfig NativeFBConfig() const Standard_OVERRIDE { return NULL; }
122
123   //! Sets window title.
124   Standard_EXPORT virtual void SetTitle (const TCollection_AsciiString& theTitle) Standard_OVERRIDE;
125
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;
129
130 public:
131
132   //! Returns the Windows NT handle of the created window <me>.
133   Aspect_Handle HWindow() const { return myHWindow; }
134
135   //! Returns the Windows NT handle parent of the created window <me>.
136   Aspect_Handle HParentWindow() const { return myHParentWindow; }
137
138   //! Raw input flags.
139   enum RawInputMask
140   {
141     RawInputMask_Mouse      = 0x01, //!< HID_USAGE_GENERIC_MOUSE
142     RawInputMask_SpaceMouse = 0x02, //!< HID_USAGE_GENERIC_MULTI_AXIS_CONTROLLER
143   };
144
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);
149
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,
155                                                MSG& theMsg);
156
157 protected:
158
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;
167
168 };
169
170 #endif // _WIN32
171 #endif // _WNT_Window_HeaderFile