1 // Created on: 2013-04-06
2 // Created by: Kirill Gavrilov
3 // Copyright (c) 2013-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 #ifndef _Xw_Window_H__
17 #define _Xw_Window_H__
19 #if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX)) && !defined(__ANDROID__) && !defined(__QNX__) && !defined(__EMSCRIPTEN__)
21 #include <Aspect_Window.hxx>
23 #include <Aspect_VKey.hxx>
24 #include <Aspect_DisplayConnection.hxx>
25 #include <Aspect_FillMethod.hxx>
26 #include <Aspect_GradientFillMethod.hxx>
27 #include <Aspect_Handle.hxx>
28 #include <Aspect_TypeOfResize.hxx>
29 #include <Standard.hxx>
30 #include <Standard_Type.hxx>
31 #include <Quantity_NameOfColor.hxx>
33 class Aspect_WindowDefinitionError;
34 class Aspect_WindowError;
35 class Aspect_Background;
37 class Aspect_GradientBackground;
39 //! This class defines XLib window intended for creation of OpenGL context.
40 class Xw_Window : public Aspect_Window
44 //! Convert X11 virtual key (KeySym) into Aspect_VKey.
45 Standard_EXPORT static Aspect_VKey VirtualKeyFromNative (unsigned long theKey);
49 //! Creates a XLib window defined by his position and size in pixels.
50 //! Throws exception if window can not be created or Display do not support GLX extension.
51 Standard_EXPORT Xw_Window (const Handle(Aspect_DisplayConnection)& theXDisplay,
52 const Standard_CString theTitle,
53 const Standard_Integer thePxLeft,
54 const Standard_Integer thePxTop,
55 const Standard_Integer thePxWidth,
56 const Standard_Integer thePxHeight);
58 //! Creates a wrapper over existing Window handle
59 Standard_EXPORT Xw_Window (const Handle(Aspect_DisplayConnection)& theXDisplay,
61 const Aspect_FBConfig theFBConfig = NULL);
63 //! Destroys the Window and all resourses attached to it
64 Standard_EXPORT ~Xw_Window();
66 //! Opens the window <me>
67 Standard_EXPORT virtual void Map() const Standard_OVERRIDE;
69 //! Closes the window <me>
70 Standard_EXPORT virtual void Unmap() const Standard_OVERRIDE;
72 //! Applies the resizing to the window <me>
73 Standard_EXPORT virtual Aspect_TypeOfResize DoResize() Standard_OVERRIDE;
75 //! Apply the mapping change to the window <me>
76 Standard_EXPORT virtual Standard_Boolean DoMapping() const Standard_OVERRIDE;
78 //! Returns True if the window <me> is opened
79 Standard_EXPORT virtual Standard_Boolean IsMapped() const Standard_OVERRIDE;
81 //! Returns The Window RATIO equal to the physical WIDTH/HEIGHT dimensions
82 Standard_EXPORT virtual Standard_Real Ratio() const Standard_OVERRIDE;
84 //! Returns The Window POSITION in PIXEL
85 Standard_EXPORT virtual void Position (Standard_Integer& X1,
88 Standard_Integer& Y2) const Standard_OVERRIDE;
90 //! Returns The Window SIZE in PIXEL
91 Standard_EXPORT virtual void Size (Standard_Integer& theWidth,
92 Standard_Integer& theHeight) const Standard_OVERRIDE;
94 //! @return native Window handle
95 Standard_EXPORT Window XWindow() const;
97 //! @return connection to X Display
98 Standard_EXPORT const Handle(Aspect_DisplayConnection)& DisplayConnection() const;
100 //! @return native Window handle
101 virtual Aspect_Drawable NativeHandle() const Standard_OVERRIDE
103 return (Aspect_Drawable )XWindow();
106 //! @return parent of native Window handle
107 virtual Aspect_Drawable NativeParentHandle() const Standard_OVERRIDE
112 //! @return native Window FB config (GLXFBConfig on Xlib)
113 virtual Aspect_FBConfig NativeFBConfig() const Standard_OVERRIDE
118 //! Sets window title.
119 Standard_EXPORT virtual void SetTitle (const TCollection_AsciiString& theTitle) Standard_OVERRIDE;
121 //! Invalidate entire window content through generation of Expose event.
122 //! This method does not aggregate multiple calls into single event - dedicated event will be sent on each call.
123 //! When NULL display connection is specified, the connection specified on window creation will be used.
124 //! Sending exposure messages from non-window thread would require dedicated display connection opened specifically
125 //! for this working thread to avoid race conditions, since Xlib display connection is not thread-safe by default.
126 Standard_EXPORT virtual void InvalidateContent (const Handle(Aspect_DisplayConnection)& theDisp) Standard_OVERRIDE;
130 Handle(Aspect_DisplayConnection) myDisplay; //!< X Display connection
131 Window myXWindow; //!< XLib window handle
132 Aspect_FBConfig myFBConfig; //!< GLXFBConfig
133 Standard_Integer myXLeft; //!< left position in pixels
134 Standard_Integer myYTop; //!< top position in pixels
135 Standard_Integer myXRight; //!< right position in pixels
136 Standard_Integer myYBottom; //!< bottom position in pixels
137 Standard_Boolean myIsOwnWin; //!< flag to indicate own window handle (to be deallocated on destruction)
141 DEFINE_STANDARD_RTTIEXT(Xw_Window,Aspect_Window)
145 DEFINE_STANDARD_HANDLE(Xw_Window, Aspect_Window)
147 #endif // Win32 or Mac OS X
148 #endif // _Xw_Window_H__