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