Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-11-16 10:23:44

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 occ::handle<Aspect_DisplayConnection>& theXDisplay,
0040                             const char* const                            theTitle,
0041                             const int                                    thePxLeft,
0042                             const int                                    thePxTop,
0043                             const int                                    thePxWidth,
0044                             const int                                    thePxHeight);
0045 
0046   //! Creates a wrapper over existing Window handle
0047   Standard_EXPORT Xw_Window(const occ::handle<Aspect_DisplayConnection>& theXDisplay,
0048                             const Aspect_Drawable                        theXWin,
0049                             const Aspect_FBConfig                        theFBConfig = nullptr);
0050 
0051   //! Destroys the Window and all resources attached to it
0052   Standard_EXPORT ~Xw_Window() override;
0053 
0054   //! Opens the window <me>
0055   Standard_EXPORT void Map() const override;
0056 
0057   //! Closes the window <me>
0058   Standard_EXPORT void Unmap() const override;
0059 
0060   //! Applies the resizing to the window <me>
0061   Standard_EXPORT Aspect_TypeOfResize DoResize() override;
0062 
0063   //! Apply the mapping change to the window <me>
0064   bool DoMapping() const override
0065   {
0066     return true; // IsMapped()
0067   }
0068 
0069   //! Returns True if the window <me> is opened
0070   Standard_EXPORT bool IsMapped() const override;
0071 
0072   //! Returns The Window RATIO equal to the physical WIDTH/HEIGHT dimensions
0073   Standard_EXPORT double Ratio() const override;
0074 
0075   //! Returns The Window POSITION in PIXEL
0076   Standard_EXPORT void Position(int& X1, int& Y1, int& X2, int& Y2) const override;
0077 
0078   //! Returns The Window SIZE in PIXEL
0079   Standard_EXPORT void Size(int& theWidth, int& theHeight) const override;
0080 
0081   //! @return native Window handle
0082   Aspect_Drawable XWindow() const { return myXWindow; }
0083 
0084   //! @return native Window handle
0085   Aspect_Drawable NativeHandle() const override { return myXWindow; }
0086 
0087   //! @return parent of native Window handle
0088   Aspect_Drawable NativeParentHandle() const override { return 0; }
0089 
0090   //! @return native Window FB config (GLXFBConfig on Xlib)
0091   Aspect_FBConfig NativeFBConfig() const override { return myFBConfig; }
0092 
0093   //! Sets window title.
0094   Standard_EXPORT void SetTitle(const TCollection_AsciiString& theTitle) override;
0095 
0096   //! Invalidate entire window content through generation of Expose event.
0097   //! This method does not aggregate multiple calls into single event - dedicated event will be sent
0098   //! on each call. When NULL display connection is specified, the connection specified on window
0099   //! creation will be used. Sending exposure messages from non-window thread would require
0100   //! dedicated display connection opened specifically for this working thread to avoid race
0101   //! conditions, since Xlib display connection is not thread-safe by default.
0102   Standard_EXPORT void InvalidateContent(
0103     const occ::handle<Aspect_DisplayConnection>& theDisp) override;
0104 
0105   //! Process a single window message.
0106   //! @param[in][out] theListener  listener to redirect message
0107   //! @param[in][out] theMsg message to process
0108   //! @return TRUE if message has been processed
0109   Standard_EXPORT virtual bool ProcessMessage(Aspect_WindowInputListener& theListener,
0110                                               XEvent&                     theMsg);
0111 
0112 protected:
0113   Aspect_Drawable myXWindow;  //!< XLib window handle
0114   Aspect_FBConfig myFBConfig; //!< GLXFBConfig
0115   int             myXLeft;    //!< left   position in pixels
0116   int             myYTop;     //!< top    position in pixels
0117   int             myXRight;   //!< right  position in pixels
0118   int             myYBottom;  //!< bottom position in pixels
0119   // clang-format off
0120   bool myIsOwnWin; //!< flag to indicate own window handle (to be deallocated on destruction)
0121   // clang-format on
0122 };
0123 
0124 #endif // _Xw_Window_H__