Increment OCCT version up to 7.4.0
[occt.git] / src / Aspect / Aspect_DisplayConnection.cxx
CommitLineData
d5f74e42 1// Copyright (c) 2013-2014 OPEN CASCADE SAS
dc3fe572 2//
973c2be1 3// This file is part of Open CASCADE Technology software library.
dc3fe572 4//
d5f74e42 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
973c2be1 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
dc3fe572 19
92efcf78 20IMPLEMENT_STANDARD_RTTIEXT(Aspect_DisplayConnection,Standard_Transient)
21
dc3fe572 22// =======================================================================
23// function : Aspect_DisplayConnection
24// purpose :
25// =======================================================================
26Aspect_DisplayConnection::Aspect_DisplayConnection()
27{
d8d01f6e 28#if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX)) && !defined(__ANDROID__) && !defined(__QNX__)
9c0787df 29 myDisplay = NULL;
30 myIsOwnDisplay = false;
dc3fe572 31 OSD_Environment anEnv ("DISPLAY");
32 myDisplayName = anEnv.Value();
9c0787df 33 Init (NULL);
dc3fe572 34#endif
35}
36
37// =======================================================================
38// function : ~Aspect_DisplayConnection
39// purpose :
40// =======================================================================
41Aspect_DisplayConnection::~Aspect_DisplayConnection()
42{
d8d01f6e 43#if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX)) && !defined(__ANDROID__) && !defined(__QNX__)
9c0787df 44 if (myDisplay != NULL
45 && myIsOwnDisplay)
dc3fe572 46 {
47 XCloseDisplay (myDisplay);
48 }
49#endif
50}
51
d8d01f6e 52#if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX)) && !defined(__ANDROID__) && !defined(__QNX__)
dc3fe572 53// =======================================================================
54// function : Aspect_DisplayConnection
55// purpose :
56// =======================================================================
57Aspect_DisplayConnection::Aspect_DisplayConnection (const TCollection_AsciiString& theDisplayName)
9c0787df 58: myDisplay (NULL),
59 myIsOwnDisplay (false)
dc3fe572 60{
61 myDisplayName = theDisplayName;
9c0787df 62 Init (NULL);
dc3fe572 63}
64
65// =======================================================================
9c0787df 66// function : Aspect_DisplayConnection
dc3fe572 67// purpose :
68// =======================================================================
9c0787df 69Aspect_DisplayConnection::Aspect_DisplayConnection (Display* theDisplay)
70: myDisplay (NULL),
71 myIsOwnDisplay (false)
dc3fe572 72{
9c0787df 73 Init (theDisplay);
dc3fe572 74}
75
76// =======================================================================
77// function : Init
78// purpose :
79// =======================================================================
9c0787df 80void Aspect_DisplayConnection::Init (Display* theDisplay)
dc3fe572 81{
9c0787df 82 if (myDisplay != NULL
83 && myIsOwnDisplay)
84 {
85 XCloseDisplay (myDisplay);
86 }
87 myIsOwnDisplay = false;
88 myAtoms.Clear();
89
90 myDisplay = theDisplay != NULL ? theDisplay : XOpenDisplay (myDisplayName.ToCString());
dc3fe572 91 if (myDisplay == NULL)
92 {
93 TCollection_AsciiString aMessage;
94 aMessage += "Can not connect to the server \"";
95 aMessage += myDisplayName + "\"";
9775fa61 96 throw Aspect_DisplayConnectionDefinitionError(aMessage.ToCString());
dc3fe572 97 }
9c0787df 98 else
99 {
100 myIsOwnDisplay = theDisplay == NULL;
101 myAtoms.Bind (Aspect_XA_DELETE_WINDOW, XInternAtom(myDisplay, "WM_DELETE_WINDOW", False));
102 }
dc3fe572 103}
18d715bd 104
105// =======================================================================
106// function : GetAtom
107// purpose :
108// =======================================================================
109Atom Aspect_DisplayConnection::GetAtom (const Aspect_XAtom theAtom) const
110{
111 Atom anAtom = myAtoms.Find(theAtom);
112 return anAtom;
113}
114
dc3fe572 115#endif