0031067: Visualization - Aspect_Window::DoResize() should be a non-const method
[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>
ec357c5c 44#include <Standard_Type.hxx>
4fe56619 45
46#include <Aspect_FillMethod.hxx>
47#include <Aspect_GradientFillMethod.hxx>
48#include <Aspect_Handle.hxx>
49#include <Aspect_TypeOfResize.hxx>
49582f9d 50#include <Aspect_VKey.hxx>
4fe56619 51#include <Quantity_NameOfColor.hxx>
4fe56619 52
53class Aspect_WindowDefinitionError;
54class Aspect_WindowError;
55class Aspect_Background;
56class Quantity_Color;
57class Aspect_GradientBackground;
58
59//! This class defines Cocoa window
60class Cocoa_Window : public Aspect_Window
61{
49582f9d 62public:
63
64 //! Convert Carbon virtual key into Aspect_VKey.
65 Standard_EXPORT static Aspect_VKey VirtualKeyFromNative (Standard_Integer theKey);
4fe56619 66
67public:
68
69 //! Creates a NSWindow and NSView defined by his position and size in pixels
70 Standard_EXPORT Cocoa_Window (const Standard_CString theTitle,
71 const Standard_Integer thePxLeft,
72 const Standard_Integer thePxTop,
73 const Standard_Integer thePxWidth,
74 const Standard_Integer thePxHeight);
75
a2e4f780 76#if defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE
77 //! Creates a wrapper over existing UIView handle
78 Standard_EXPORT Cocoa_Window (UIView* theViewUI);
79#else
4fe56619 80 //! Creates a wrapper over existing NSView handle
81 Standard_EXPORT Cocoa_Window (NSView* theViewNS);
a2e4f780 82#endif
4fe56619 83
e6f550da 84 //! Destroys the Window and all resourses attached to it
85 Standard_EXPORT ~Cocoa_Window();
4fe56619 86
4fe56619 87 //! Opens the window <me>
b6bf4ec1 88 Standard_EXPORT virtual void Map() const Standard_OVERRIDE;
4fe56619 89
90 //! Closes the window <me>
b6bf4ec1 91 Standard_EXPORT virtual void Unmap() const Standard_OVERRIDE;
4fe56619 92
93 //! Applies the resizing to the window <me>
1a5007a9 94 Standard_EXPORT virtual Aspect_TypeOfResize DoResize() Standard_OVERRIDE;
4fe56619 95
96 //! Apply the mapping change to the window <me>
b6bf4ec1 97 Standard_EXPORT virtual Standard_Boolean DoMapping() const Standard_OVERRIDE;
4fe56619 98
4fe56619 99 //! Returns True if the window <me> is opened
b6bf4ec1 100 Standard_EXPORT virtual Standard_Boolean IsMapped() const Standard_OVERRIDE;
4fe56619 101
102 //! Returns The Window RATIO equal to the physical WIDTH/HEIGHT dimensions
ee2be2a8 103 Standard_EXPORT virtual Standard_Real Ratio() const Standard_OVERRIDE;
4fe56619 104
4fe56619 105 //! Returns The Window POSITION in PIXEL
106 Standard_EXPORT virtual void Position (Standard_Integer& X1,
107 Standard_Integer& Y1,
108 Standard_Integer& X2,
b6bf4ec1 109 Standard_Integer& Y2) const Standard_OVERRIDE;
4fe56619 110
4fe56619 111 //! Returns The Window SIZE in PIXEL
112 Standard_EXPORT virtual void Size (Standard_Integer& theWidth,
b6bf4ec1 113 Standard_Integer& theHeight) const Standard_OVERRIDE;
4fe56619 114
a2e4f780 115#if defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE
116 //! @return associated UIView
117 UIView* HView() const { return myHView; }
118
119 //! Setup new UIView.
120 Standard_EXPORT void SetHView (UIView* theView);
121#else
4fe56619 122 //! @return associated NSView
a2e4f780 123 NSView* HView() const { return myHView; }
4fe56619 124
125 //! Setup new NSView.
126 Standard_EXPORT void SetHView (NSView* theView);
a2e4f780 127#endif
4fe56619 128
25b97fac 129 //! @return native Window handle
b6bf4ec1 130 virtual Aspect_Drawable NativeHandle() const Standard_OVERRIDE
25b97fac 131 {
132 return (Aspect_Drawable )HView();
133 }
134
135 //! @return parent of native Window handle
b6bf4ec1 136 virtual Aspect_Drawable NativeParentHandle() const Standard_OVERRIDE
25b97fac 137 {
138 return 0;
139 }
140
b6bf4ec1 141 //! Returns nothing on OS X
142 virtual Aspect_FBConfig NativeFBConfig() const Standard_OVERRIDE { return NULL; }
143
49582f9d 144 //! Sets window title.
145 Standard_EXPORT virtual void SetTitle (const TCollection_AsciiString& theTitle) Standard_OVERRIDE;
146
8693dfd0 147 //! Invalidate entire window content by setting NSView::setNeedsDisplay property.
148 //! Call will be implicitly redirected to the main thread when called from non-GUI thread.
149 Standard_EXPORT virtual void InvalidateContent (const Handle(Aspect_DisplayConnection)& theDisp = NULL) Standard_OVERRIDE;
150
4fe56619 151protected:
152
a2e4f780 153#if defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE
154 UIView* myHView;
155#else
4fe56619 156 NSWindow* myHWindow;
157 NSView* myHView;
a2e4f780 158#endif
4fe56619 159 Standard_Integer myXLeft;
160 Standard_Integer myYTop;
161 Standard_Integer myXRight;
162 Standard_Integer myYBottom;
163
164public:
165
f5f4ebd0 166 DEFINE_STANDARD_RTTIEXT(Cocoa_Window,Aspect_Window)
4fe56619 167
168};
169
170DEFINE_STANDARD_HANDLE(Cocoa_Window, Aspect_Window)
171
172#endif // _Cocoa_Window_H__