0024947: Redesign OCCT legacy type system -- automatic
[occt.git] / src / Aspect / Aspect_DisplayConnection.hxx
1 // Copyright (c) 2013-2014 OPEN CASCADE SAS
2 //
3 // This file is part of Open CASCADE Technology software library.
4 //
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
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.
10 //
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
13
14 #ifndef _Aspect_DisplayConnection_H__
15 #define _Aspect_DisplayConnection_H__
16
17 #include <Standard_Transient.hxx>
18 #include <Aspect_XAtom.hxx>
19
20 #include <TCollection_AsciiString.hxx>
21 #include <NCollection_DataMap.hxx>
22
23 #if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX)) && !defined(__ANDROID__)
24   #include <InterfaceGraphic.hxx>
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
32 class Aspect_DisplayConnection : public Standard_Transient
33 {
34 public:
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
42 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX)) && !defined(__ANDROID__)
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
50   //! @return pointer to Display structure that serves as the connection to the X server.
51   Display* GetDisplay();
52   
53   //! @return identifier(atom) for custom named property associated with windows that use current connection to X server.
54   Atom GetAtom (const Aspect_XAtom theAtom) const;
55
56   //! @return display name for this connection.
57   TCollection_AsciiString GetDisplayName();
58
59 private:
60
61   //! Open connection with display specified in myDisplayName class field.
62   void Init();
63
64 private:
65
66   Display*                 myDisplay;
67   NCollection_DataMap<Aspect_XAtom, Atom> myAtoms;
68   TCollection_AsciiString  myDisplayName;
69 #endif
70
71 private:
72
73   //! To protect the connection from closing copying allowed only through the handles.
74   Aspect_DisplayConnection            (const Aspect_DisplayConnection& );
75   Aspect_DisplayConnection& operator= (const Aspect_DisplayConnection& );
76
77 public:
78
79   DEFINE_STANDARD_RTTI(Aspect_DisplayConnection, Standard_Transient) // Type definition
80
81 };
82
83 DEFINE_STANDARD_HANDLE (Aspect_DisplayConnection, Standard_Transient)
84
85 #endif // _Aspect_DisplayConnection_H__