0023712: Remove dependency on Aspect_GraphicDevice from Aspect_Window
[occt.git] / src / Aspect / Aspect_DisplayConnection.cxx
CommitLineData
dc3fe572 1// Copyright (c) 2013 OPEN CASCADE SAS
2//
3// The content of this file is subject to the Open CASCADE Technology Public
4// License Version 6.5 (the "License"). You may not use the content of this file
5// except in compliance with the License. Please obtain a copy of the License
6// at http://www.opencascade.org and read it completely before using this file.
7//
8// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
9// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
10//
11// The Original Code and all software distributed under the License is
12// distributed on an "AS IS" basis, without warranty of any kind, and the
13// Initial Developer hereby disclaims all such warranties, including without
14// limitation, any warranties of merchantability, fitness for a particular
15// purpose or non-infringement. Please see the License for the specific terms
16// and conditions governing the rights and limitations under the License.
17
18#include <Aspect_DisplayConnection.hxx>
19
20#include <Aspect_DisplayConnectionDefinitionError.hxx>
21#include <OSD_Environment.hxx>
22
23IMPLEMENT_STANDARD_HANDLE (Aspect_DisplayConnection, Standard_Transient)
24IMPLEMENT_STANDARD_RTTIEXT(Aspect_DisplayConnection, Standard_Transient)
25
26// =======================================================================
27// function : Aspect_DisplayConnection
28// purpose :
29// =======================================================================
30Aspect_DisplayConnection::Aspect_DisplayConnection()
31{
32#if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
33 OSD_Environment anEnv ("DISPLAY");
34 myDisplayName = anEnv.Value();
35 Init();
36#endif
37}
38
39// =======================================================================
40// function : ~Aspect_DisplayConnection
41// purpose :
42// =======================================================================
43Aspect_DisplayConnection::~Aspect_DisplayConnection()
44{
45#if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
46 if (myDisplay != NULL)
47 {
48 XCloseDisplay (myDisplay);
49 }
50#endif
51}
52
53#if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
54// =======================================================================
55// function : Aspect_DisplayConnection
56// purpose :
57// =======================================================================
58Aspect_DisplayConnection::Aspect_DisplayConnection (const TCollection_AsciiString& theDisplayName)
59{
60 myDisplayName = theDisplayName;
61 Init();
62}
63
64// =======================================================================
65// function : GetDisplay
66// purpose :
67// =======================================================================
68Display* Aspect_DisplayConnection::GetDisplay()
69{
70 return myDisplay;
71}
72
73// =======================================================================
74// function : GetDisplayName
75// purpose :
76// =======================================================================
77TCollection_AsciiString Aspect_DisplayConnection::GetDisplayName()
78{
79 return myDisplayName;
80}
81
82// =======================================================================
83// function : Init
84// purpose :
85// =======================================================================
86void Aspect_DisplayConnection::Init()
87{
88 myDisplay = XOpenDisplay (myDisplayName.ToCString());
89
90 if (myDisplay == NULL)
91 {
92 TCollection_AsciiString aMessage;
93 aMessage += "Can not connect to the server \"";
94 aMessage += myDisplayName + "\"";
95 Aspect_DisplayConnectionDefinitionError::Raise (aMessage.ToCString());
96 }
97}
98#endif