cbd6a8f8de33fcc73349e708bc156fd4caa7c8a6
[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 <Standard_Type.hxx>
28 #include <WNT_Dword.hxx>
29
30 class WNT_WClass;
31
32 DEFINE_STANDARD_HANDLE(WNT_Window, Aspect_Window)
33
34 //! This class defines Windows NT window
35 class WNT_Window : public Aspect_Window
36 {
37 public:
38
39   //! Convert WInAPI virtual key (VK_ enumeration) into Aspect_VKey.
40   Standard_EXPORT static Aspect_VKey VirtualKeyFromNative (Standard_Integer theKey);
41
42   //! Convert WPARAM from mouse event to key flags.
43   Standard_EXPORT static Aspect_VKeyFlags MouseKeyFlagsFromEvent (WPARAM theKeys);
44
45   //! Convert WPARAM from mouse event to mouse buttons bitmask.
46   Standard_EXPORT static Aspect_VKeyMouse MouseButtonsFromEvent (WPARAM theKeys);
47
48   //! Use GetAsyncKeyState() to fetch actual mouse key flags regardless of event loop.
49   Standard_EXPORT static Aspect_VKeyFlags MouseKeyFlagsAsync();
50
51   //! Use GetAsyncKeyState() to fetch actual mouse buttons state regardless of event loop.
52   Standard_EXPORT static Aspect_VKeyMouse MouseButtonsAsync();
53
54 public:
55
56   //! Creates a Window defined by his position and size
57   //! in pixles from the Parent Window.
58   //! Trigger: Raises WindowDefinitionError if the Position out of the
59   //! Screen Space or the window creation failed.
60   Standard_EXPORT WNT_Window(const Standard_CString theTitle, const Handle(WNT_WClass)& theClass, const WNT_Dword& theStyle, const Standard_Integer thePxLeft, const Standard_Integer thePxTop, const Standard_Integer thePxWidth, const Standard_Integer thePxHeight, const Quantity_NameOfColor theBackColor = Quantity_NOC_MATRAGRAY, const Aspect_Handle theParent = 0, const Aspect_Handle theMenu = 0, const Standard_Address theClientStruct = 0);
61   
62   //! Creates a Window based on the existing window handle.
63   //! This handle equals ( aPart1 << 16 ) + aPart2.
64   Standard_EXPORT WNT_Window(const Aspect_Handle aHandle, const Quantity_NameOfColor aBackColor = Quantity_NOC_MATRAGRAY);
65   
66   //! Destroys the Window and all resourses attached to it.
67   Standard_EXPORT ~WNT_Window();
68   
69   //! Sets cursor <aCursor> for ENTIRE WINDOW CLASS to which
70   //! the Window belongs.
71   Standard_EXPORT void SetCursor (const Aspect_Handle aCursor) const;
72   
73   //! Opens the window <me>.
74   Standard_EXPORT virtual void Map() const Standard_OVERRIDE;
75   
76   //! Opens a window <me> according to <aMapMode>.
77   //! This method is specific to Windows NT.
78   //! <aMapMode> can be one of SW_xxx constants defined
79   //! in <windows.h>. See documentation.
80   Standard_EXPORT void Map (const Standard_Integer aMapMode) const;
81   
82   //! Closes the window <me>.
83   Standard_EXPORT virtual void Unmap() const Standard_OVERRIDE;
84   
85   //! Applies the resizing to the window <me>.
86   Standard_EXPORT virtual Aspect_TypeOfResize DoResize() const Standard_OVERRIDE;
87   
88   //! Apply the mapping change to the window <me>
89   //! and returns TRUE if the window is mapped at screen.
90   virtual Standard_Boolean DoMapping() const Standard_OVERRIDE;
91   
92   //! Changes variables due to window position.
93   Standard_EXPORT void SetPos (const Standard_Integer X, const Standard_Integer Y, const Standard_Integer X1, const Standard_Integer Y1);
94   
95   //! Returns True if the window <me> is opened
96   //! and False if the window is closed.
97   Standard_EXPORT virtual Standard_Boolean IsMapped() const Standard_OVERRIDE;
98   
99   //! Returns The Window RATIO equal to the physical
100   //! WIDTH/HEIGHT dimensions.
101   Standard_EXPORT virtual Standard_Real Ratio() const Standard_OVERRIDE;
102   
103   //! Returns The Window POSITION in PIXEL
104   Standard_EXPORT virtual void Position (Standard_Integer& X1, Standard_Integer& Y1, Standard_Integer& X2, Standard_Integer& Y2) const Standard_OVERRIDE;
105   
106   //! Returns The Window SIZE in PIXEL
107   Standard_EXPORT virtual void Size (Standard_Integer& Width, Standard_Integer& Height) const Standard_OVERRIDE;
108   
109   //! Returns the Windows NT handle of the created window <me>.
110   Aspect_Handle HWindow() const;
111   
112   //! Returns the Windows NT handle parent of the created window <me>.
113   Aspect_Handle HParentWindow() const;
114   
115   //! Returns native Window handle (HWND)
116   virtual Aspect_Drawable NativeHandle() const Standard_OVERRIDE;
117   
118   //! Returns parent of native Window handle (HWND on Windows, Window with Xlib, and so on)
119   virtual Aspect_Drawable NativeParentHandle() const Standard_OVERRIDE;
120
121   //! Returns nothing on Windows
122   virtual Aspect_FBConfig NativeFBConfig() const Standard_OVERRIDE { return NULL; }
123
124   //! Sets window title.
125   Standard_EXPORT virtual void SetTitle (const TCollection_AsciiString& theTitle) Standard_OVERRIDE;
126
127   //! Invalidate entire window content by calling InvalidateRect() WinAPI function, resulting in WM_PAINT event put into window message loop.
128   //! Method can be called from non-window thread, and system will also automatically aggregate multiple events into single one.
129   Standard_EXPORT virtual void InvalidateContent (const Handle(Aspect_DisplayConnection)& theDisp = NULL) Standard_OVERRIDE;
130
131   DEFINE_STANDARD_RTTIEXT(WNT_Window,Aspect_Window)
132
133 protected:
134
135   Standard_Integer aXLeft;
136   Standard_Integer aYTop;
137   Standard_Integer aXRight;
138   Standard_Integer aYBottom;
139   Handle(WNT_WClass) myWClass;
140   Aspect_Handle myHWindow;
141   Aspect_Handle myHParentWindow;
142   Standard_Boolean myIsForeign;
143
144 };
145
146 #include <WNT_Window.lxx>
147
148 #endif // _WIN32
149 #endif // _WNT_Window_HeaderFile