0025973: Visualization, TKOpenGl - support EAGLContext as alternative to NSOpenGLContext
[occt.git] / src / Cocoa / Cocoa_Window.hxx
CommitLineData
6aca4d39 1// Created on: 2012-11-12
4fe56619 2// Created by: Kirill GAVRILOV
6aca4d39 3// Copyright (c) 2012-2014 OPEN CASCADE SAS
4fe56619 4//
973c2be1 5// This file is part of Open CASCADE Technology software library.
4fe56619 6//
d5f74e42 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
973c2be1 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.
4fe56619 12//
973c2be1 13// Alternatively, this file may be used under the terms of Open CASCADE
14// commercial license or contractual agreement.
4fe56619 15
16#ifndef _Cocoa_Window_H__
17#define _Cocoa_Window_H__
18
a2e4f780 19#if defined(__APPLE__)
20 #import <TargetConditionals.h>
21#endif
22
23#if defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE
24 #ifdef __OBJC__
25 @class UIView;
26 @class UIWindow;
27 #else
28 struct UIView;
29 struct UIWindow;
30 #endif
4fe56619 31#else
a2e4f780 32 #ifdef __OBJC__
33 @class NSView;
34 @class NSWindow;
35 #else
36 struct NSView;
37 struct NSWindow;
38 #endif
4fe56619 39#endif
40
41#include <Aspect_Window.hxx>
42
43#include <Standard.hxx>
44#include <Standard_DefineHandle.hxx>
45
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>
51#include <Quantity_Parameter.hxx>
52#include <Quantity_Ratio.hxx>
53
54class Aspect_WindowDefinitionError;
55class Aspect_WindowError;
56class Aspect_Background;
57class Quantity_Color;
58class Aspect_GradientBackground;
59
60//! This class defines Cocoa window
61class Cocoa_Window : public Aspect_Window
62{
63
64public:
65
66 //! Creates a NSWindow and NSView defined by his position and size in pixels
67 Standard_EXPORT Cocoa_Window (const Standard_CString theTitle,
68 const Standard_Integer thePxLeft,
69 const Standard_Integer thePxTop,
70 const Standard_Integer thePxWidth,
71 const Standard_Integer thePxHeight);
72
a2e4f780 73#if defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE
74 //! Creates a wrapper over existing UIView handle
75 Standard_EXPORT Cocoa_Window (UIView* theViewUI);
76#else
4fe56619 77 //! Creates a wrapper over existing NSView handle
78 Standard_EXPORT Cocoa_Window (NSView* theViewNS);
a2e4f780 79#endif
4fe56619 80
81 //! Destroies the Window and all resourses attached to it
82 Standard_EXPORT virtual void Destroy();
83
84 ~Cocoa_Window()
85 {
86 Destroy();
87 }
88
4fe56619 89 //! Opens the window <me>
90 Standard_EXPORT virtual void Map() const;
91
92 //! Closes the window <me>
93 Standard_EXPORT virtual void Unmap() const;
94
95 //! Applies the resizing to the window <me>
96 Standard_EXPORT virtual Aspect_TypeOfResize DoResize() const;
97
98 //! Apply the mapping change to the window <me>
99 Standard_EXPORT virtual Standard_Boolean DoMapping() const;
100
4fe56619 101 //! Returns True if the window <me> is opened
102 Standard_EXPORT virtual Standard_Boolean IsMapped() const;
103
104 //! Returns The Window RATIO equal to the physical WIDTH/HEIGHT dimensions
105 Standard_EXPORT virtual Quantity_Ratio Ratio() const;
106
4fe56619 107 //! Returns The Window POSITION in PIXEL
108 Standard_EXPORT virtual void Position (Standard_Integer& X1,
109 Standard_Integer& Y1,
110 Standard_Integer& X2,
111 Standard_Integer& Y2) const;
112
4fe56619 113 //! Returns The Window SIZE in PIXEL
114 Standard_EXPORT virtual void Size (Standard_Integer& theWidth,
115 Standard_Integer& theHeight) const;
116
a2e4f780 117#if defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE
118 //! @return associated UIView
119 UIView* HView() const { return myHView; }
120
121 //! Setup new UIView.
122 Standard_EXPORT void SetHView (UIView* theView);
123#else
4fe56619 124 //! @return associated NSView
a2e4f780 125 NSView* HView() const { return myHView; }
4fe56619 126
127 //! Setup new NSView.
128 Standard_EXPORT void SetHView (NSView* theView);
a2e4f780 129#endif
4fe56619 130
25b97fac 131 //! @return native Window handle
132 virtual Aspect_Drawable NativeHandle() const
133 {
134 return (Aspect_Drawable )HView();
135 }
136
137 //! @return parent of native Window handle
138 virtual Aspect_Drawable NativeParentHandle() const
139 {
140 return 0;
141 }
142
4fe56619 143protected:
144
a2e4f780 145#if defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE
146 UIView* myHView;
147#else
4fe56619 148 NSWindow* myHWindow;
149 NSView* myHView;
a2e4f780 150#endif
4fe56619 151 Standard_Integer myXLeft;
152 Standard_Integer myYTop;
153 Standard_Integer myXRight;
154 Standard_Integer myYBottom;
155
156public:
157
158 DEFINE_STANDARD_RTTI(Cocoa_Window)
159
160};
161
162DEFINE_STANDARD_HANDLE(Cocoa_Window, Aspect_Window)
163
164#endif // _Cocoa_Window_H__