0030429: Samples - add simple glfw 3D Viewer sample
[occt.git] / src / Aspect / Aspect_DisplayConnection.hxx
CommitLineData
d5f74e42 1// Copyright (c) 2013-2014 OPEN CASCADE SAS
dc3fe572 2//
973c2be1 3// This file is part of Open CASCADE Technology software library.
dc3fe572 4//
d5f74e42 5// This library is free software; you can redistribute it and/or modify it under
6// the terms of the GNU Lesser General Public License version 2.1 as published
973c2be1 7// by the Free Software Foundation, with special exception defined in the file
8// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
9// distribution for complete text of the license and disclaimer of any warranty.
dc3fe572 10//
973c2be1 11// Alternatively, this file may be used under the terms of Open CASCADE
12// commercial license or contractual agreement.
dc3fe572 13
14#ifndef _Aspect_DisplayConnection_H__
15#define _Aspect_DisplayConnection_H__
16
17#include <Standard_Transient.hxx>
18d715bd 18#include <Aspect_XAtom.hxx>
dc3fe572 19
20#include <TCollection_AsciiString.hxx>
18d715bd 21#include <NCollection_DataMap.hxx>
dc3fe572 22
d8d01f6e 23#if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX)) && !defined(__ANDROID__) && !defined(__QNX__)
2905ff17 24 #include <InterfaceGraphic.hxx>
dc3fe572 25#endif
26
27//! This class creates and provides connection with X server.
28//! Raises exception if can not connect to X server.
29//! On Windows and Mac OS X (in case when Cocoa used) platforms this class do nothing.
30//! WARRNING: Do not close display connection manualy!
31
32class Aspect_DisplayConnection : public Standard_Transient
33{
34public:
35
36 //! Default constructor. Creates connection with display name taken from "DISPLAY" environment variable
37 Standard_EXPORT Aspect_DisplayConnection();
38
39 //! Destructor. Close opened connection.
40 Standard_EXPORT ~Aspect_DisplayConnection();
41
d8d01f6e 42#if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX)) && !defined(__ANDROID__) && !defined(__QNX__)
dc3fe572 43 //! Constructor. Creates connection with display specified in theDisplayName.
44 //! Display name should be in format "hostname:number" or "hostname:number.screen_number", where:
45 //! hostname - Specifies the name of the host machine on which the display is physically attached.
46 //! number - Specifies the number of the display server on that host machine.
47 //! screen_number - Specifies the screen to be used on that server. Optional variable.
48 Aspect_DisplayConnection (const TCollection_AsciiString& theDisplayName);
49
9c0787df 50 //! Constructor wrapping existing Display instance.
51 //! WARNING! it is a responsibility of application to keep this pointer
52 //! valid while Aspect_DisplayConnection is alive and to close Display when it is no more needed.
53 Aspect_DisplayConnection (Display* theDisplay);
54
dc3fe572 55 //! @return pointer to Display structure that serves as the connection to the X server.
9c0787df 56 Display* GetDisplay() { return myDisplay; }
57
58 //! @return TRUE if X Display has been allocated by this class
59 Standard_Boolean IsOwnDisplay() const { return myIsOwnDisplay; }
60
18d715bd 61 //! @return identifier(atom) for custom named property associated with windows that use current connection to X server.
62 Atom GetAtom (const Aspect_XAtom theAtom) const;
dc3fe572 63
64 //! @return display name for this connection.
9c0787df 65 const TCollection_AsciiString& GetDisplayName() { return myDisplayName; }
dc3fe572 66
9c0787df 67 //! Open connection with display specified in myDisplayName class field
68 //! or takes theDisplay parameter when it is not NULL.
69 //! WARNING! When external Display is specified, it is a responsibility of application
70 //! to keep this pointer valid while Aspect_DisplayConnection is alive
71 //! and to close Display when it is no more needed.
72 //! @param theDisplay external pointer to allocated Display, or NULL if new connection should be created
73 void Init (Display* theDisplay);
dc3fe572 74
75private:
76
18d715bd 77 Display* myDisplay;
78 NCollection_DataMap<Aspect_XAtom, Atom> myAtoms;
79 TCollection_AsciiString myDisplayName;
9c0787df 80 Standard_Boolean myIsOwnDisplay;
dc3fe572 81#endif
82
83private:
84
85 //! To protect the connection from closing copying allowed only through the handles.
86 Aspect_DisplayConnection (const Aspect_DisplayConnection& );
87 Aspect_DisplayConnection& operator= (const Aspect_DisplayConnection& );
88
89public:
90
92efcf78 91 DEFINE_STANDARD_RTTIEXT(Aspect_DisplayConnection,Standard_Transient) // Type definition
dc3fe572 92
93};
94
494782f6 95DEFINE_STANDARD_HANDLE (Aspect_DisplayConnection, Standard_Transient)
96
dc3fe572 97#endif // _Aspect_DisplayConnection_H__