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