0024428: Implementation of LGPL license
[occt.git] / src / Aspect / Aspect_DisplayConnection.cxx
CommitLineData
dc3fe572 1// Copyright (c) 2013 OPEN CASCADE SAS
2//
973c2be1 3// This file is part of Open CASCADE Technology software library.
dc3fe572 4//
973c2be1 5// This library is free software; you can redistribute it and / or modify it
6// under the terms of the GNU Lesser General Public 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.
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#include <Aspect_DisplayConnection.hxx>
15
16#include <Aspect_DisplayConnectionDefinitionError.hxx>
17#include <OSD_Environment.hxx>
18
19IMPLEMENT_STANDARD_HANDLE (Aspect_DisplayConnection, Standard_Transient)
20IMPLEMENT_STANDARD_RTTIEXT(Aspect_DisplayConnection, Standard_Transient)
21
22// =======================================================================
23// function : Aspect_DisplayConnection
24// purpose :
25// =======================================================================
26Aspect_DisplayConnection::Aspect_DisplayConnection()
27{
28#if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
29 OSD_Environment anEnv ("DISPLAY");
30 myDisplayName = anEnv.Value();
31 Init();
32#endif
33}
34
35// =======================================================================
36// function : ~Aspect_DisplayConnection
37// purpose :
38// =======================================================================
39Aspect_DisplayConnection::~Aspect_DisplayConnection()
40{
41#if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
42 if (myDisplay != NULL)
43 {
44 XCloseDisplay (myDisplay);
45 }
46#endif
47}
48
49#if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
50// =======================================================================
51// function : Aspect_DisplayConnection
52// purpose :
53// =======================================================================
54Aspect_DisplayConnection::Aspect_DisplayConnection (const TCollection_AsciiString& theDisplayName)
55{
56 myDisplayName = theDisplayName;
57 Init();
58}
59
60// =======================================================================
61// function : GetDisplay
62// purpose :
63// =======================================================================
64Display* Aspect_DisplayConnection::GetDisplay()
65{
66 return myDisplay;
67}
68
69// =======================================================================
70// function : GetDisplayName
71// purpose :
72// =======================================================================
73TCollection_AsciiString Aspect_DisplayConnection::GetDisplayName()
74{
75 return myDisplayName;
76}
77
78// =======================================================================
79// function : Init
80// purpose :
81// =======================================================================
82void Aspect_DisplayConnection::Init()
83{
84 myDisplay = XOpenDisplay (myDisplayName.ToCString());
18d715bd 85 myAtoms.Bind (Aspect_XA_DELETE_WINDOW, XInternAtom(myDisplay, "WM_DELETE_WINDOW", False));
dc3fe572 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}
18d715bd 95
96// =======================================================================
97// function : GetAtom
98// purpose :
99// =======================================================================
100Atom Aspect_DisplayConnection::GetAtom (const Aspect_XAtom theAtom) const
101{
102 Atom anAtom = myAtoms.Find(theAtom);
103 return anAtom;
104}
105
dc3fe572 106#endif