Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:02:58

0001 // Copyright (c) 2013-2014 OPEN CASCADE SAS
0002 //
0003 // This file is part of Open CASCADE Technology software library.
0004 //
0005 // This library is free software; you can redistribute it and/or modify it under
0006 // the terms of the GNU Lesser General Public License version 2.1 as published
0007 // by the Free Software Foundation, with special exception defined in the file
0008 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0009 // distribution for complete text of the license and disclaimer of any warranty.
0010 //
0011 // Alternatively, this file may be used under the terms of Open CASCADE
0012 // commercial license or contractual agreement.
0013 
0014 #ifndef Aspect_DisplayConnection_HeaderFile
0015 #define Aspect_DisplayConnection_HeaderFile
0016 
0017 #include <Standard_Transient.hxx>
0018 #include <Aspect_XAtom.hxx>
0019 #include <Aspect_FBConfig.hxx>
0020 
0021 #include <TCollection_AsciiString.hxx>
0022 #include <NCollection_DataMap.hxx>
0023 
0024 struct Aspect_XDisplay;
0025 struct Aspect_XVisualInfo;
0026 
0027 //! This class creates and provides connection with X server.
0028 //! Raises exception if can not connect to X server.
0029 //! On Windows and Mac OS X (in case when Cocoa used) platforms this class does nothing.
0030 //! WARRNING: Do not close display connection manually!
0031 class Aspect_DisplayConnection : public Standard_Transient
0032 {
0033   DEFINE_STANDARD_RTTIEXT(Aspect_DisplayConnection, Standard_Transient)
0034 public:
0035 
0036   //! Default constructor. Creates connection with display name taken from "DISPLAY" environment variable
0037   Standard_EXPORT Aspect_DisplayConnection();
0038 
0039   //! Destructor. Close opened connection.
0040   Standard_EXPORT virtual ~Aspect_DisplayConnection();
0041 
0042   //! Constructor. Creates connection with display specified in theDisplayName.
0043   //! Display name should be in format "hostname:number" or "hostname:number.screen_number", where:
0044   //! hostname      - Specifies the name of the host machine on which the display is physically attached.
0045   //! number        - Specifies the number of the display server on that host machine.
0046   //! screen_number - Specifies the screen to be used on that server. Optional variable.
0047   Standard_EXPORT Aspect_DisplayConnection (const TCollection_AsciiString& theDisplayName);
0048 
0049   //! Constructor wrapping existing Display instance.
0050   //! WARNING! it is a responsibility of application to keep this pointer
0051   //! valid while Aspect_DisplayConnection is alive and to close Display when it is no more needed.
0052   Standard_EXPORT Aspect_DisplayConnection (Aspect_XDisplay* theDisplay);
0053 
0054   //! @return pointer to Display structure that serves as the connection to the X server.
0055   Aspect_XDisplay* GetDisplayAspect() { return myDisplay; }
0056 
0057   //! @return TRUE if X Display has been allocated by this class
0058   Standard_Boolean IsOwnDisplay() const { return myIsOwnDisplay; }
0059 
0060   //! @return identifier(atom) for custom named property associated with windows that use current connection to X server.
0061   uint64_t GetAtom (const Aspect_XAtom theAtom) const
0062   {
0063     return myAtoms.Find (theAtom);
0064   }
0065 
0066   //! @return display name for this connection.
0067   const TCollection_AsciiString& GetDisplayName() { return myDisplayName; }
0068 
0069   //! Open connection with display specified in myDisplayName class field
0070   //! or takes theDisplay parameter when it is not NULL.
0071   //! WARNING! When external Display is specified, it is a responsibility of application
0072   //! to keep this pointer valid while Aspect_DisplayConnection is alive
0073   //! and to close Display when it is no more needed.
0074   //! @param theDisplay external pointer to allocated Display, or NULL if new connection should be created
0075   Standard_EXPORT void Init (Aspect_XDisplay* theDisplay);
0076 
0077   //! Return default window visual or NULL when undefined.
0078   Aspect_XVisualInfo* GetDefaultVisualInfo() const { return myDefVisualInfo; }
0079 
0080   //! @return native Window FB config (GLXFBConfig on Xlib)
0081   Aspect_FBConfig GetDefaultFBConfig() const { return myDefFBConfig; }
0082 
0083   //! Set default window visual; the visual will be deallocated using XFree().
0084   Standard_EXPORT void SetDefaultVisualInfo (Aspect_XVisualInfo* theVisual,
0085                                              Aspect_FBConfig theFBConfig);
0086 
0087 #ifdef X_PROTOCOL
0088   //! Constructor wrapping existing Display instance.
0089   //! WARNING! it is a responsibility of application to keep this pointer
0090   //! valid while Aspect_DisplayConnection is alive and to close Display when it is no more needed.
0091   Aspect_DisplayConnection (Display* theDisplay)
0092   : Aspect_DisplayConnection ((Aspect_XDisplay* )theDisplay) {}
0093 
0094   //! @return pointer to Display structure that serves as the connection to the X server.
0095   Display* GetDisplay() { return (Display* )myDisplay; }
0096 
0097   //! Return default window visual or NULL when undefined.
0098   XVisualInfo* GetDefaultVisualInfoX() const { return (XVisualInfo* )myDefVisualInfo; }
0099 
0100   //! Set default window visual; the visual will be deallocated using XFree().
0101   void SetDefaultVisualInfo (XVisualInfo* theVisual,
0102                              Aspect_FBConfig theFBConfig)
0103   {
0104     SetDefaultVisualInfo ((Aspect_XVisualInfo* )theVisual, theFBConfig);
0105   }
0106 
0107   //! @return identifier(atom) for custom named property associated with windows that use current connection to X server.
0108   Atom GetAtomX (const Aspect_XAtom theAtom) const
0109   {
0110     return (Atom )GetAtom (theAtom);
0111   }
0112 
0113   //! Open connection with display specified in myDisplayName class field
0114   //! or takes theDisplay parameter when it is not NULL.
0115   void Init (Display* theDisplay)
0116   {
0117     Init ((Aspect_XDisplay* )theDisplay);
0118   }
0119 #endif
0120 
0121 private:
0122 
0123   Aspect_XDisplay*         myDisplay;
0124   Aspect_XVisualInfo*      myDefVisualInfo;
0125   Aspect_FBConfig          myDefFBConfig;
0126   NCollection_DataMap<Aspect_XAtom, uint64_t> myAtoms;
0127   TCollection_AsciiString  myDisplayName;
0128   Standard_Boolean         myIsOwnDisplay;
0129 
0130 private:
0131 
0132   //! To protect the connection from closing copying allowed only through the handles.
0133   Aspect_DisplayConnection            (const Aspect_DisplayConnection& );
0134   Aspect_DisplayConnection& operator= (const Aspect_DisplayConnection& );
0135 
0136 };
0137 
0138 DEFINE_STANDARD_HANDLE (Aspect_DisplayConnection, Standard_Transient)
0139 
0140 #endif // _Aspect_DisplayConnection_H__