1 // Created on: 2012-11-12
2 // Created by: Kirill GAVRILOV
3 // Copyright (c) 2012-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 #ifndef _Cocoa_Window_H__
17 #define _Cocoa_Window_H__
19 #if defined(__APPLE__)
20 #import <TargetConditionals.h>
23 #if defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE
41 #include <Aspect_Window.hxx>
43 #include <Standard.hxx>
44 #include <Standard_Type.hxx>
46 #include <Aspect_FillMethod.hxx>
47 #include <Aspect_GradientFillMethod.hxx>
48 #include <Aspect_Handle.hxx>
49 #include <Aspect_TypeOfResize.hxx>
50 #include <Quantity_NameOfColor.hxx>
52 class Aspect_WindowDefinitionError;
53 class Aspect_WindowError;
54 class Aspect_Background;
56 class Aspect_GradientBackground;
58 //! This class defines Cocoa window
59 class Cocoa_Window : public Aspect_Window
64 //! Creates a NSWindow and NSView defined by his position and size in pixels
65 Standard_EXPORT Cocoa_Window (const Standard_CString theTitle,
66 const Standard_Integer thePxLeft,
67 const Standard_Integer thePxTop,
68 const Standard_Integer thePxWidth,
69 const Standard_Integer thePxHeight);
71 #if defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE
72 //! Creates a wrapper over existing UIView handle
73 Standard_EXPORT Cocoa_Window (UIView* theViewUI);
75 //! Creates a wrapper over existing NSView handle
76 Standard_EXPORT Cocoa_Window (NSView* theViewNS);
79 //! Destroys the Window and all resourses attached to it
80 Standard_EXPORT ~Cocoa_Window();
82 //! Opens the window <me>
83 Standard_EXPORT virtual void Map() const Standard_OVERRIDE;
85 //! Closes the window <me>
86 Standard_EXPORT virtual void Unmap() const Standard_OVERRIDE;
88 //! Applies the resizing to the window <me>
89 Standard_EXPORT virtual Aspect_TypeOfResize DoResize() const Standard_OVERRIDE;
91 //! Apply the mapping change to the window <me>
92 Standard_EXPORT virtual Standard_Boolean DoMapping() const Standard_OVERRIDE;
94 //! Returns True if the window <me> is opened
95 Standard_EXPORT virtual Standard_Boolean IsMapped() const Standard_OVERRIDE;
97 //! Returns The Window RATIO equal to the physical WIDTH/HEIGHT dimensions
98 Standard_EXPORT virtual Standard_Real Ratio() const Standard_OVERRIDE;
100 //! Returns The Window POSITION in PIXEL
101 Standard_EXPORT virtual void Position (Standard_Integer& X1,
102 Standard_Integer& Y1,
103 Standard_Integer& X2,
104 Standard_Integer& Y2) const Standard_OVERRIDE;
106 //! Returns The Window SIZE in PIXEL
107 Standard_EXPORT virtual void Size (Standard_Integer& theWidth,
108 Standard_Integer& theHeight) const Standard_OVERRIDE;
110 #if defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE
111 //! @return associated UIView
112 UIView* HView() const { return myHView; }
114 //! Setup new UIView.
115 Standard_EXPORT void SetHView (UIView* theView);
117 //! @return associated NSView
118 NSView* HView() const { return myHView; }
120 //! Setup new NSView.
121 Standard_EXPORT void SetHView (NSView* theView);
124 //! @return native Window handle
125 virtual Aspect_Drawable NativeHandle() const Standard_OVERRIDE
127 return (Aspect_Drawable )HView();
130 //! @return parent of native Window handle
131 virtual Aspect_Drawable NativeParentHandle() const Standard_OVERRIDE
136 //! Returns nothing on OS X
137 virtual Aspect_FBConfig NativeFBConfig() const Standard_OVERRIDE { return NULL; }
139 //! Invalidate entire window content by setting NSView::setNeedsDisplay property.
140 //! Call will be implicitly redirected to the main thread when called from non-GUI thread.
141 Standard_EXPORT virtual void InvalidateContent (const Handle(Aspect_DisplayConnection)& theDisp = NULL) Standard_OVERRIDE;
145 #if defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE
151 Standard_Integer myXLeft;
152 Standard_Integer myYTop;
153 Standard_Integer myXRight;
154 Standard_Integer myYBottom;
158 DEFINE_STANDARD_RTTIEXT(Cocoa_Window,Aspect_Window)
162 DEFINE_STANDARD_HANDLE(Cocoa_Window, Aspect_Window)
164 #endif // _Cocoa_Window_H__