0026936: Drawbacks of inlining in new type system in OCCT 7.0 -- automatic
[occt.git] / src / Aspect / Aspect_DisplayConnection.cxx
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 #include <Aspect_DisplayConnection.hxx>
15
16 #include <Aspect_DisplayConnectionDefinitionError.hxx>
17 #include <OSD_Environment.hxx>
18
19
20 IMPLEMENT_STANDARD_RTTIEXT(Aspect_DisplayConnection,Standard_Transient)
21
22 // =======================================================================
23 // function : Aspect_DisplayConnection
24 // purpose  :
25 // =======================================================================
26 Aspect_DisplayConnection::Aspect_DisplayConnection()
27 {
28 #if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX)) && !defined(__ANDROID__) && !defined(__QNX__)
29   OSD_Environment anEnv ("DISPLAY");
30   myDisplayName = anEnv.Value();
31   Init();
32 #endif
33 }
34
35 // =======================================================================
36 // function : ~Aspect_DisplayConnection
37 // purpose  :
38 // =======================================================================
39 Aspect_DisplayConnection::~Aspect_DisplayConnection()
40 {
41 #if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX)) && !defined(__ANDROID__) && !defined(__QNX__)
42   if (myDisplay != NULL)
43   {
44     XCloseDisplay (myDisplay);
45   }
46 #endif
47 }
48
49 #if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX)) && !defined(__ANDROID__) && !defined(__QNX__)
50 // =======================================================================
51 // function : Aspect_DisplayConnection
52 // purpose  :
53 // =======================================================================
54 Aspect_DisplayConnection::Aspect_DisplayConnection (const TCollection_AsciiString& theDisplayName)
55 {
56   myDisplayName = theDisplayName;
57   Init();
58 }
59
60 // =======================================================================
61 // function : GetDisplay
62 // purpose  :
63 // =======================================================================
64 Display* Aspect_DisplayConnection::GetDisplay()
65 {
66   return myDisplay;
67 }
68
69 // =======================================================================
70 // function : GetDisplayName
71 // purpose  :
72 // =======================================================================
73 TCollection_AsciiString Aspect_DisplayConnection::GetDisplayName()
74 {
75   return myDisplayName;
76 }
77
78 // =======================================================================
79 // function : Init
80 // purpose  :
81 // =======================================================================
82 void Aspect_DisplayConnection::Init()
83 {
84   myDisplay = XOpenDisplay (myDisplayName.ToCString());
85   myAtoms.Bind (Aspect_XA_DELETE_WINDOW, XInternAtom(myDisplay, "WM_DELETE_WINDOW", False));
86   
87   if (myDisplay == NULL)
88   {
89     TCollection_AsciiString aMessage;
90     aMessage += "Can not connect to the server \"";
91     aMessage += myDisplayName + "\"";
92     Aspect_DisplayConnectionDefinitionError::Raise (aMessage.ToCString());
93   }
94 }
95
96 // =======================================================================
97 // function : GetAtom
98 // purpose  :
99 // =======================================================================
100 Atom Aspect_DisplayConnection::GetAtom (const Aspect_XAtom theAtom) const
101 {
102   Atom anAtom = myAtoms.Find(theAtom);
103   return anAtom;
104 }
105
106 #endif