9add87984aaffbd2bc865a2f7c8cbf8daed5ab19
[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_HeaderFile
17 #define Xw_Window_HeaderFile
18
19 #include <Aspect_Window.hxx>
20
21 #include <Aspect_VKey.hxx>
22
23 class Aspect_DisplayConnection;
24 class Aspect_WindowInputListener;
25
26 typedef union _XEvent XEvent;
27
28 //! This class defines XLib window intended for creation of OpenGL context.
29 class Xw_Window : public Aspect_Window
30 {
31   DEFINE_STANDARD_RTTIEXT(Xw_Window, Aspect_Window)
32 public:
33
34   //! Convert X11 virtual key (KeySym) into Aspect_VKey.
35   Standard_EXPORT static Aspect_VKey VirtualKeyFromNative (unsigned long theKey);
36
37 public:
38
39   //! Creates a XLib window defined by his position and size in pixels.
40   //! Throws exception if window can not be created or Display do not support GLX extension.
41   Standard_EXPORT Xw_Window (const Handle(Aspect_DisplayConnection)& theXDisplay,
42                              const Standard_CString theTitle,
43                              const Standard_Integer thePxLeft,
44                              const Standard_Integer thePxTop,
45                              const Standard_Integer thePxWidth,
46                              const Standard_Integer thePxHeight);
47
48   //! Creates a wrapper over existing Window handle
49   Standard_EXPORT Xw_Window (const Handle(Aspect_DisplayConnection)& theXDisplay,
50                              const Aspect_Drawable theXWin,
51                              const Aspect_FBConfig theFBConfig = NULL);
52
53   //! Destroys the Window and all resources attached to it
54   Standard_EXPORT ~Xw_Window();
55
56   //! Opens the window <me>
57   Standard_EXPORT virtual void Map() const Standard_OVERRIDE;
58
59   //! Closes the window <me>
60   Standard_EXPORT virtual void Unmap() const Standard_OVERRIDE;
61
62   //! Applies the resizing to the window <me>
63   Standard_EXPORT virtual Aspect_TypeOfResize DoResize() Standard_OVERRIDE;
64
65   //! Apply the mapping change to the window <me>
66   virtual Standard_Boolean DoMapping() const Standard_OVERRIDE
67   {
68     return Standard_True; // IsMapped()
69   }
70
71   //! Returns True if the window <me> is opened
72   Standard_EXPORT virtual Standard_Boolean IsMapped() const Standard_OVERRIDE;
73
74   //! Returns The Window RATIO equal to the physical WIDTH/HEIGHT dimensions
75   Standard_EXPORT virtual Standard_Real Ratio() const Standard_OVERRIDE;
76
77   //! Returns The Window POSITION in PIXEL
78   Standard_EXPORT virtual void Position (Standard_Integer& X1,
79                                          Standard_Integer& Y1,
80                                          Standard_Integer& X2,
81                                          Standard_Integer& Y2) const Standard_OVERRIDE;
82
83   //! Returns The Window SIZE in PIXEL
84   Standard_EXPORT virtual void Size (Standard_Integer& theWidth,
85                                      Standard_Integer& theHeight) const Standard_OVERRIDE;
86
87   //! @return native Window handle
88   Aspect_Drawable XWindow() const { return myXWindow; }
89
90   //! @return native Window handle
91   virtual Aspect_Drawable NativeHandle() const Standard_OVERRIDE
92   {
93     return myXWindow;
94   }
95
96   //! @return parent of native Window handle
97   virtual Aspect_Drawable NativeParentHandle() const Standard_OVERRIDE
98   {
99     return 0;
100   }
101
102   //! @return native Window FB config (GLXFBConfig on Xlib)
103   virtual Aspect_FBConfig NativeFBConfig() const Standard_OVERRIDE
104   {
105     return myFBConfig;
106   }
107
108   //! Sets window title.
109   Standard_EXPORT virtual void SetTitle (const TCollection_AsciiString& theTitle) Standard_OVERRIDE;
110
111   //! Invalidate entire window content through generation of Expose event.
112   //! This method does not aggregate multiple calls into single event - dedicated event will be sent on each call.
113   //! When NULL display connection is specified, the connection specified on window creation will be used.
114   //! Sending exposure messages from non-window thread would require dedicated display connection opened specifically
115   //! for this working thread to avoid race conditions, since Xlib display connection is not thread-safe by default.
116   Standard_EXPORT virtual void InvalidateContent (const Handle(Aspect_DisplayConnection)& theDisp) Standard_OVERRIDE;
117
118   //! Process a single window message.
119   //! @param theListener [in][out] listener to redirect message
120   //! @param theMsg [in][out] message to process
121   //! @return TRUE if message has been processed
122   Standard_EXPORT virtual bool ProcessMessage (Aspect_WindowInputListener& theListener,
123                                                XEvent& theMsg);
124
125 protected:
126
127   Aspect_Drawable  myXWindow;  //!< XLib window handle
128   Aspect_FBConfig  myFBConfig; //!< GLXFBConfig
129   Standard_Integer myXLeft;    //!< left   position in pixels
130   Standard_Integer myYTop;     //!< top    position in pixels
131   Standard_Integer myXRight;   //!< right  position in pixels
132   Standard_Integer myYBottom;  //!< bottom position in pixels
133   Standard_Boolean myIsOwnWin; //!< flag to indicate own window handle (to be deallocated on destruction)
134
135 };
136
137 DEFINE_STANDARD_HANDLE(Xw_Window, Aspect_Window)
138
139 #endif // _Xw_Window_H__