0026732: Visualization, TKOpenGl - add option to request Core profile 3.2+ using GLX
[occt.git] / src / Xw / Xw_Window.hxx
1 // Created on: 2013-04-06
2 // Created by: Kirill Gavrilov
3 // Copyright (c) 2013-2014 OPEN CASCADE SAS
4 //
5 // This file is part of Open CASCADE Technology software library.
6 //
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.
12 //
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
15
16 #ifndef _Xw_Window_H__
17 #define _Xw_Window_H__
18
19 #if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX)) && !defined(__ANDROID__)
20
21 #include <Aspect_Window.hxx>
22
23 #include <Aspect_DisplayConnection.hxx>
24 #include <Aspect_FillMethod.hxx>
25 #include <Aspect_GradientFillMethod.hxx>
26 #include <Aspect_Handle.hxx>
27 #include <Aspect_TypeOfResize.hxx>
28 #include <Standard.hxx>
29 #include <Standard_Type.hxx>
30 #include <Quantity_NameOfColor.hxx>
31 #include <Quantity_Parameter.hxx>
32 #include <Quantity_Ratio.hxx>
33
34 class Aspect_WindowDefinitionError;
35 class Aspect_WindowError;
36 class Aspect_Background;
37 class Quantity_Color;
38 class Aspect_GradientBackground;
39
40 //! This class defines XLib window intended for creation of OpenGL context.
41 class Xw_Window : public Aspect_Window
42 {
43
44 public:
45
46   //! Creates a XLib window defined by his position and size in pixels.
47   //! Throws exception if window can not be created or Display do not support GLX extension.
48   Standard_EXPORT Xw_Window (const Handle(Aspect_DisplayConnection)& theXDisplay,
49                              const Standard_CString theTitle,
50                              const Standard_Integer thePxLeft,
51                              const Standard_Integer thePxTop,
52                              const Standard_Integer thePxWidth,
53                              const Standard_Integer thePxHeight,
54                              const Aspect_FBConfig  theFBConfig = NULL);
55
56   //! Creates a wrapper over existing Window handle
57   Standard_EXPORT Xw_Window (const Handle(Aspect_DisplayConnection)& theXDisplay,
58                              const Window theXWin,
59                              const Aspect_FBConfig theFBConfig = NULL);
60
61   //! Destroies the Window and all resourses attached to it
62   Standard_EXPORT virtual void Destroy();
63
64   ~Xw_Window()
65   {
66     Destroy();
67   }
68
69   //! Opens the window <me>
70   Standard_EXPORT virtual void Map() const Standard_OVERRIDE;
71
72   //! Closes the window <me>
73   Standard_EXPORT virtual void Unmap() const Standard_OVERRIDE;
74
75   //! Applies the resizing to the window <me>
76   Standard_EXPORT virtual Aspect_TypeOfResize DoResize() const Standard_OVERRIDE;
77
78   //! Apply the mapping change to the window <me>
79   Standard_EXPORT virtual Standard_Boolean DoMapping() const Standard_OVERRIDE;
80
81   //! Returns True if the window <me> is opened
82   Standard_EXPORT virtual Standard_Boolean IsMapped() const Standard_OVERRIDE;
83
84   //! Returns The Window RATIO equal to the physical WIDTH/HEIGHT dimensions
85   Standard_EXPORT virtual Quantity_Ratio Ratio() const Standard_OVERRIDE;
86
87   //! Returns The Window POSITION in PIXEL
88   Standard_EXPORT virtual void Position (Standard_Integer& X1,
89                                          Standard_Integer& Y1,
90                                          Standard_Integer& X2,
91                                          Standard_Integer& Y2) const Standard_OVERRIDE;
92
93   //! Returns The Window SIZE in PIXEL
94   Standard_EXPORT virtual void Size (Standard_Integer& theWidth,
95                                      Standard_Integer& theHeight) const Standard_OVERRIDE;
96
97   //! @return native Window handle
98   Standard_EXPORT Window XWindow() const;
99
100   //! @return connection to X Display
101   Standard_EXPORT const Handle(Aspect_DisplayConnection)& DisplayConnection() const;
102
103   //! @return native Window handle
104   virtual Aspect_Drawable NativeHandle() const Standard_OVERRIDE
105   {
106     return (Aspect_Drawable )XWindow();
107   }
108
109   //! @return parent of native Window handle
110   virtual Aspect_Drawable NativeParentHandle() const Standard_OVERRIDE
111   {
112     return 0;
113   }
114
115   //! @return native Window FB config (GLXFBConfig on Xlib)
116   virtual Aspect_FBConfig NativeFBConfig() const Standard_OVERRIDE
117   {
118     return myFBConfig;
119   }
120
121 protected:
122
123   Handle(Aspect_DisplayConnection) myDisplay; //!< X Display connection
124   Window           myXWindow;  //!< XLib window handle
125   Aspect_FBConfig  myFBConfig; //!< GLXFBConfig
126   Standard_Integer myXLeft;    //!< left   position in pixels
127   Standard_Integer myYTop;     //!< top    position in pixels
128   Standard_Integer myXRight;   //!< right  position in pixels
129   Standard_Integer myYBottom;  //!< bottom position in pixels
130   Standard_Boolean myIsOwnWin; //!< flag to indicate own window handle (to be deallocated on destruction)
131
132 public:
133
134   DEFINE_STANDARD_RTTI(Xw_Window, Aspect_Window)
135
136 };
137
138 DEFINE_STANDARD_HANDLE(Xw_Window, Aspect_Window)
139
140 #endif //  Win32 or Mac OS X
141 #endif // _Xw_Window_H__