Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-20 08:18:24

0001 // Created on: 2013-04-06
0002 // Created by: Kirill Gavrilov
0003 // Copyright (c) 2013-2014 OPEN CASCADE SAS
0004 //
0005 // This file is part of Open CASCADE Technology software library.
0006 //
0007 // This library is free software; you can redistribute it and/or modify it under
0008 // the terms of the GNU Lesser General Public License version 2.1 as published
0009 // by the Free Software Foundation, with special exception defined in the file
0010 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0011 // distribution for complete text of the license and disclaimer of any warranty.
0012 //
0013 // Alternatively, this file may be used under the terms of Open CASCADE
0014 // commercial license or contractual agreement.
0015 
0016 #ifndef Xw_Window_HeaderFile
0017 #define Xw_Window_HeaderFile
0018 
0019 #include <Aspect_Window.hxx>
0020 
0021 #include <Aspect_VKey.hxx>
0022 
0023 class Aspect_DisplayConnection;
0024 class Aspect_WindowInputListener;
0025 
0026 typedef union _XEvent XEvent;
0027 
0028 //! This class defines XLib window intended for creation of OpenGL context.
0029 class Xw_Window : public Aspect_Window
0030 {
0031   DEFINE_STANDARD_RTTIEXT(Xw_Window, Aspect_Window)
0032 public:
0033   //! Convert X11 virtual key (KeySym) into Aspect_VKey.
0034   Standard_EXPORT static Aspect_VKey VirtualKeyFromNative(unsigned long theKey);
0035 
0036 public:
0037   //! Creates a XLib window defined by his position and size in pixels.
0038   //! Throws exception if window can not be created or Display do not support GLX extension.
0039   Standard_EXPORT Xw_Window(const Handle(Aspect_DisplayConnection)& theXDisplay,
0040                             const Standard_CString                  theTitle,
0041                             const Standard_Integer                  thePxLeft,
0042                             const Standard_Integer                  thePxTop,
0043                             const Standard_Integer                  thePxWidth,
0044                             const Standard_Integer                  thePxHeight);
0045 
0046   //! Creates a wrapper over existing Window handle
0047   Standard_EXPORT Xw_Window(const Handle(Aspect_DisplayConnection)& theXDisplay,
0048                             const Aspect_Drawable                   theXWin,
0049                             const Aspect_FBConfig                   theFBConfig = NULL);
0050 
0051   //! Destroys the Window and all resources attached to it
0052   Standard_EXPORT ~Xw_Window();
0053 
0054   //! Opens the window <me>
0055   Standard_EXPORT virtual void Map() const Standard_OVERRIDE;
0056 
0057   //! Closes the window <me>
0058   Standard_EXPORT virtual void Unmap() const Standard_OVERRIDE;
0059 
0060   //! Applies the resizing to the window <me>
0061   Standard_EXPORT virtual Aspect_TypeOfResize DoResize() Standard_OVERRIDE;
0062 
0063   //! Apply the mapping change to the window <me>
0064   virtual Standard_Boolean DoMapping() const Standard_OVERRIDE
0065   {
0066     return Standard_True; // IsMapped()
0067   }
0068 
0069   //! Returns True if the window <me> is opened
0070   Standard_EXPORT virtual Standard_Boolean IsMapped() const Standard_OVERRIDE;
0071 
0072   //! Returns The Window RATIO equal to the physical WIDTH/HEIGHT dimensions
0073   Standard_EXPORT virtual Standard_Real Ratio() const Standard_OVERRIDE;
0074 
0075   //! Returns The Window POSITION in PIXEL
0076   Standard_EXPORT virtual void Position(Standard_Integer& X1,
0077                                         Standard_Integer& Y1,
0078                                         Standard_Integer& X2,
0079                                         Standard_Integer& Y2) const Standard_OVERRIDE;
0080 
0081   //! Returns The Window SIZE in PIXEL
0082   Standard_EXPORT virtual void Size(Standard_Integer& theWidth,
0083                                     Standard_Integer& theHeight) const Standard_OVERRIDE;
0084 
0085   //! @return native Window handle
0086   Aspect_Drawable XWindow() const { return myXWindow; }
0087 
0088   //! @return native Window handle
0089   virtual Aspect_Drawable NativeHandle() const Standard_OVERRIDE { return myXWindow; }
0090 
0091   //! @return parent of native Window handle
0092   virtual Aspect_Drawable NativeParentHandle() const Standard_OVERRIDE { return 0; }
0093 
0094   //! @return native Window FB config (GLXFBConfig on Xlib)
0095   virtual Aspect_FBConfig NativeFBConfig() const Standard_OVERRIDE { return myFBConfig; }
0096 
0097   //! Sets window title.
0098   Standard_EXPORT virtual void SetTitle(const TCollection_AsciiString& theTitle) Standard_OVERRIDE;
0099 
0100   //! Invalidate entire window content through generation of Expose event.
0101   //! This method does not aggregate multiple calls into single event - dedicated event will be sent
0102   //! on each call. When NULL display connection is specified, the connection specified on window
0103   //! creation will be used. Sending exposure messages from non-window thread would require
0104   //! dedicated display connection opened specifically for this working thread to avoid race
0105   //! conditions, since Xlib display connection is not thread-safe by default.
0106   Standard_EXPORT virtual void InvalidateContent(const Handle(Aspect_DisplayConnection)& theDisp)
0107     Standard_OVERRIDE;
0108 
0109   //! Process a single window message.
0110   //! @param[in][out] theListener  listener to redirect message
0111   //! @param[in][out] theMsg message to process
0112   //! @return TRUE if message has been processed
0113   Standard_EXPORT virtual bool ProcessMessage(Aspect_WindowInputListener& theListener,
0114                                               XEvent&                     theMsg);
0115 
0116 protected:
0117   Aspect_Drawable  myXWindow;  //!< XLib window handle
0118   Aspect_FBConfig  myFBConfig; //!< GLXFBConfig
0119   Standard_Integer myXLeft;    //!< left   position in pixels
0120   Standard_Integer myYTop;     //!< top    position in pixels
0121   Standard_Integer myXRight;   //!< right  position in pixels
0122   Standard_Integer myYBottom;  //!< bottom position in pixels
0123   // clang-format off
0124   Standard_Boolean myIsOwnWin; //!< flag to indicate own window handle (to be deallocated on destruction)
0125   // clang-format on
0126 };
0127 
0128 DEFINE_STANDARD_HANDLE(Xw_Window, Aspect_Window)
0129 
0130 #endif // _Xw_Window_H__