Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-10-05 09:21:48

0001 // Created on: 2012-11-12
0002 // Created by: Kirill GAVRILOV
0003 // Copyright (c) 2012-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 Cocoa_Window_HeaderFile
0017 #define Cocoa_Window_HeaderFile
0018 
0019 #if defined(__APPLE__)
0020   #import <TargetConditionals.h>
0021 #endif
0022 
0023 #if defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE
0024   #ifdef __OBJC__
0025 @class UIView;
0026 @class UIWindow;
0027   #else
0028 struct UIView;
0029 struct UIWindow;
0030   #endif
0031 #else
0032   #ifdef __OBJC__
0033 @class NSView;
0034 @class NSWindow;
0035   #else
0036 struct NSView;
0037 struct NSWindow;
0038   #endif
0039 #endif
0040 
0041 #include <Aspect_Window.hxx>
0042 
0043 #include <Standard.hxx>
0044 #include <Standard_Type.hxx>
0045 
0046 #include <Aspect_FillMethod.hxx>
0047 #include <Aspect_GradientFillMethod.hxx>
0048 #include <Aspect_Handle.hxx>
0049 #include <Aspect_TypeOfResize.hxx>
0050 #include <Aspect_VKey.hxx>
0051 #include <Quantity_NameOfColor.hxx>
0052 
0053 class Aspect_WindowDefinitionError;
0054 class Aspect_WindowError;
0055 class Aspect_Background;
0056 class Quantity_Color;
0057 class Aspect_GradientBackground;
0058 
0059 //! This class defines Cocoa window
0060 class Cocoa_Window : public Aspect_Window
0061 {
0062 public:
0063   //! Convert Carbon virtual key into Aspect_VKey.
0064   Standard_EXPORT static Aspect_VKey VirtualKeyFromNative(int theKey);
0065 
0066 public:
0067   //! Creates a NSWindow and NSView defined by his position and size in pixels
0068   Standard_EXPORT Cocoa_Window(const char* const theTitle,
0069                                const int         thePxLeft,
0070                                const int         thePxTop,
0071                                const int         thePxWidth,
0072                                const int         thePxHeight);
0073 
0074 #if defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE
0075   //! Creates a wrapper over existing UIView handle
0076   Standard_EXPORT Cocoa_Window(UIView* theViewUI);
0077 #else
0078   //! Creates a wrapper over existing NSView handle
0079   Standard_EXPORT Cocoa_Window(NSView* theViewNS);
0080 #endif
0081 
0082   //! Destroys the Window and all resources attached to it
0083   Standard_EXPORT ~Cocoa_Window();
0084 
0085   //! Opens the window <me>
0086   Standard_EXPORT virtual void Map() const override;
0087 
0088   //! Closes the window <me>
0089   Standard_EXPORT virtual void Unmap() const override;
0090 
0091   //! Applies the resizing to the window <me>
0092   Standard_EXPORT virtual Aspect_TypeOfResize DoResize() override;
0093 
0094   //! Apply the mapping change to the window <me>
0095   Standard_EXPORT virtual bool DoMapping() const override;
0096 
0097   //! Returns True if the window <me> is opened
0098   Standard_EXPORT virtual bool IsMapped() const override;
0099 
0100   //! Returns The Window RATIO equal to the physical WIDTH/HEIGHT dimensions
0101   Standard_EXPORT virtual double Ratio() const override;
0102 
0103   //! Returns The Window POSITION in PIXEL
0104   Standard_EXPORT virtual void Position(int& X1, int& Y1, int& X2, int& Y2) const override;
0105 
0106   //! Returns The Window SIZE in PIXEL
0107   Standard_EXPORT virtual void Size(int& theWidth, int& theHeight) const override;
0108 
0109 #if defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE
0110   //! @return associated UIView
0111   UIView* HView() const { return myHView; }
0112 
0113   //! Setup new UIView.
0114   Standard_EXPORT void SetHView(UIView* theView);
0115 #else
0116   //! @return associated NSView
0117   NSView* HView() const { return myHView; }
0118 
0119   //! Setup new NSView.
0120   Standard_EXPORT void SetHView(NSView* theView);
0121 #endif
0122 
0123   //! @return native Window handle
0124   virtual Aspect_Drawable NativeHandle() const override { return (Aspect_Drawable)HView(); }
0125 
0126   //! @return parent of native Window handle
0127   virtual Aspect_Drawable NativeParentHandle() const override { return 0; }
0128 
0129   //! Returns nothing on OS X
0130   virtual Aspect_FBConfig NativeFBConfig() const override { return nullptr; }
0131 
0132   //! Sets window title.
0133   Standard_EXPORT virtual void SetTitle(const TCollection_AsciiString& theTitle) override;
0134 
0135   //! Invalidate entire window content by setting NSView::setNeedsDisplay property.
0136   //! Call will be implicitly redirected to the main thread when called from non-GUI thread.
0137   Standard_EXPORT virtual void InvalidateContent(
0138     const occ::handle<Aspect_DisplayConnection>& theDisp = nullptr) override;
0139 
0140 protected:
0141 #if defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE
0142   UIView* myHView;
0143 #else
0144   NSWindow* myHWindow;
0145   NSView*   myHView;
0146 #endif
0147   int myXLeft;
0148   int myYTop;
0149   int myXRight;
0150   int myYBottom;
0151 
0152 public:
0153   DEFINE_STANDARD_RTTIEXT(Cocoa_Window, Aspect_Window)
0154 };
0155 
0156 #endif // _Cocoa_Window_H__