1 // This file is part of VSTGUI. It is subject to the license terms
2 // in the LICENSE file found in the top-level directory of this
3 // distribution and at http://github.com/steinbergmedia/vstgui/LICENSE
4 
5 #pragma once
6 
7 #include "../../../vstguifwd.h"
8 
9 #if MAC_COCOA
10 
11 #include "../../platform_macos.h"
12 #include "../../../cview.h"
13 #include "../../../idatapackage.h"
14 #include "nsviewdraggingsession.h"
15 #include <list>
16 
17 #ifdef __OBJC__
18 #import <Cocoa/Cocoa.h>
19 #else
20 struct NSView;
21 struct NSRect;
22 struct NSDraggingSession;
23 #endif
24 
25 namespace VSTGUI {
26 class CocoaTooltipWindow;
27 struct NSViewDraggingSession;
28 
29 //-----------------------------------------------------------------------------
30 class NSViewFrame : public IPlatformFrame, public ICocoaPlatformFrame, public IPlatformFrameTouchBarExtension
31 {
32 public:
33 	NSViewFrame (IPlatformFrameCallback* frame, const CRect& size, NSView* parent, IPlatformFrameConfig* config);
34 	~NSViewFrame () noexcept override;
35 
getNSView()36 	NSView* getNSView () const override { return nsView; }
getFrame()37 	IPlatformFrameCallback* getFrame () const { return frame; }
38 	void* makeTouchBar () const;
getDraggingSession()39 	NSViewDraggingSession* getDraggingSession () const { return draggingSession; }
clearDraggingSession()40 	void clearDraggingSession () { draggingSession = nullptr; }
41 
42 #if VSTGUI_ENABLE_DEPRECATED_METHODS
setLastDragOperationResult(DragResult result)43 	void setLastDragOperationResult (DragResult result) { lastDragOperationResult = result; }
44 #endif
setIgnoreNextResignFirstResponder(bool state)45 	void setIgnoreNextResignFirstResponder (bool state) { ignoreNextResignFirstResponder = state; }
getIgnoreNextResignFirstResponder()46 	bool getIgnoreNextResignFirstResponder () const { return ignoreNextResignFirstResponder; }
47 
setDragDataPackage(SharedPointer<IDataPackage> && package)48 	void setDragDataPackage (SharedPointer<IDataPackage>&& package) { dragDataPackage = std::move (package); }
getDragDataPackage()49 	const SharedPointer<IDataPackage>& getDragDataPackage () const { return dragDataPackage; }
50 
51 	void initTrackingArea ();
52 	void scaleFactorChanged (double newScaleFactor);
53 	void cursorUpdate ();
54 	virtual void drawRect (NSRect* rect);
55 
56 	// IPlatformFrame
57 	bool getGlobalPosition (CPoint& pos) const override;
58 	bool setSize (const CRect& newSize) override;
59 	bool getSize (CRect& size) const override;
60 	bool getCurrentMousePosition (CPoint& mousePosition) const override;
61 	bool getCurrentMouseButtons (CButtonState& buttons) const override;
62 	bool setMouseCursor (CCursorType type) override;
63 	bool invalidRect (const CRect& rect) override;
64 	bool scrollRect (const CRect& src, const CPoint& distance) override;
65 	bool showTooltip (const CRect& rect, const char* utf8Text) override;
66 	bool hideTooltip () override;
getPlatformRepresentation()67 	void* getPlatformRepresentation () const override { return nsView; }
68 	SharedPointer<IPlatformTextEdit> createPlatformTextEdit (IPlatformTextEditCallback* textEdit) override;
69 	SharedPointer<IPlatformOptionMenu> createPlatformOptionMenu () override;
70 #if VSTGUI_OPENGL_SUPPORT
71 	SharedPointer<IPlatformOpenGLView> createPlatformOpenGLView () override;
72 #endif
73 	SharedPointer<IPlatformViewLayer> createPlatformViewLayer (IPlatformViewLayerDelegate* drawDelegate, IPlatformViewLayer* parentLayer = nullptr) override;
74 	SharedPointer<COffscreenContext> createOffscreenContext (CCoord width, CCoord height, double scaleFactor) override;
75 #if VSTGUI_ENABLE_DEPRECATED_METHODS
76 	DragResult doDrag (IDataPackage* source, const CPoint& offset, CBitmap* dragBitmap) override;
77 #endif
78 	bool doDrag (const DragDescription& dragDescription, const SharedPointer<IDragCallback>& callback) override;
79 
80 	void setClipboard (const SharedPointer<IDataPackage>& data) override;
81 	SharedPointer<IDataPackage> getClipboard () override;
getPlatformType()82 	PlatformType getPlatformType () const override { return PlatformType::kNSView; }
onFrameClosed()83 	void onFrameClosed () override {}
84 	Optional<UTF8String> convertCurrentKeyEventToText () override;
85 	bool setupGenericOptionMenu (bool use, GenericOptionMenuTheme* theme = nullptr) override;
86 
87 	// IPlatformFrameTouchBarExtension
88 	void setTouchBarCreator (const SharedPointer<ITouchBarCreator>& creator) override;
89 	void recreateTouchBar () override;
90 
91 //-----------------------------------------------------------------------------
92 protected:
93 	static void initClass ();
94 
95 	NSView* nsView;
96 	CocoaTooltipWindow* tooltipWindow;
97 	SharedPointer<IDataPackage> dragDataPackage;
98 	SharedPointer<ITouchBarCreator> touchBarCreator;
99 	SharedPointer<NSViewDraggingSession> draggingSession;
100 	std::unique_ptr<GenericOptionMenuTheme> genericOptionMenuTheme;
101 
102 #if VSTGUI_ENABLE_DEPRECATED_METHODS
103 	DragResult lastDragOperationResult;
104 #endif
105 	bool ignoreNextResignFirstResponder;
106 	bool trackingAreaInitialized;
107 	bool inDraw;
108 	CCursorType cursor;
109 };
110 
111 } // VSTGUI
112 
113 #endif // MAC_COCOA
114