Skip to content

Commit

Permalink
Merge pull request #8078 from AvaloniaUI/osx-nswindow-refactor
Browse files Browse the repository at this point in the history
Osx nswindow refactor: Part 1
# Conflicts:
#	native/Avalonia.Native/src/OSX/Avalonia.Native.OSX.xcodeproj/project.pbxproj
#	native/Avalonia.Native/src/OSX/automation.h
#	native/Avalonia.Native/src/OSX/automation.mm
#	native/Avalonia.Native/src/OSX/window.h
#	native/Avalonia.Native/src/OSX/window.mm
  • Loading branch information
danwalmsley committed May 10, 2022
1 parent 81e5fe8 commit 991d9d8
Show file tree
Hide file tree
Showing 19 changed files with 1,434 additions and 1,385 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@
objects = {

/* Begin PBXBuildFile section */
18391068E48EF96E3DB5FDAB /* ResizeScope.mm in Sources */ = {isa = PBXBuildFile; fileRef = 18391E45702740FE9DD69695 /* ResizeScope.mm */; };
1839125F057B0A4EB1760058 /* WindowImpl.mm in Sources */ = {isa = PBXBuildFile; fileRef = 183919BF108EB72A029F7671 /* WindowImpl.mm */; };
183916173528EC2737DBE5E1 /* WindowBaseImpl.h in Headers */ = {isa = PBXBuildFile; fileRef = 183915BFF0E234CD3604A7CD /* WindowBaseImpl.h */; };
1839171DCC651B0638603AC4 /* INSWindowHolder.h in Headers */ = {isa = PBXBuildFile; fileRef = 18391BBB7782C296D424071F /* INSWindowHolder.h */; };
1839179A55FC1421BEE83330 /* WindowBaseImpl.mm in Sources */ = {isa = PBXBuildFile; fileRef = 18391676ECF0E983F4964357 /* WindowBaseImpl.mm */; };
183919D91DB9AAB5D700C2EA /* WindowImpl.h in Headers */ = {isa = PBXBuildFile; fileRef = 18391CD090AA776E7E841AC9 /* WindowImpl.h */; };
18391C28BF1823B5464FDD36 /* ResizeScope.h in Headers */ = {isa = PBXBuildFile; fileRef = 1839171D898F9BFC1373631A /* ResizeScope.h */; };
18391CF07316F819E76B617C /* IWindowStateChanged.h in Headers */ = {isa = PBXBuildFile; fileRef = 183913C6BFD6856BD42D19FD /* IWindowStateChanged.h */; };
1A002B9E232135EE00021753 /* app.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1A002B9D232135EE00021753 /* app.mm */; };
1A1852DC23E05814008F0DED /* deadlock.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1A1852DB23E05814008F0DED /* deadlock.mm */; };
1A3E5EA823E9E83B00EDE661 /* rendertarget.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1A3E5EA723E9E83B00EDE661 /* rendertarget.mm */; };
Expand All @@ -33,6 +41,14 @@
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
183913C6BFD6856BD42D19FD /* IWindowStateChanged.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IWindowStateChanged.h; sourceTree = "<group>"; };
183915BFF0E234CD3604A7CD /* WindowBaseImpl.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WindowBaseImpl.h; sourceTree = "<group>"; };
18391676ECF0E983F4964357 /* WindowBaseImpl.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WindowBaseImpl.mm; sourceTree = "<group>"; };
1839171D898F9BFC1373631A /* ResizeScope.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ResizeScope.h; sourceTree = "<group>"; };
183919BF108EB72A029F7671 /* WindowImpl.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WindowImpl.mm; sourceTree = "<group>"; };
18391BBB7782C296D424071F /* INSWindowHolder.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = INSWindowHolder.h; sourceTree = "<group>"; };
18391CD090AA776E7E841AC9 /* WindowImpl.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WindowImpl.h; sourceTree = "<group>"; };
18391E45702740FE9DD69695 /* ResizeScope.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ResizeScope.mm; sourceTree = "<group>"; };
1A002B9D232135EE00021753 /* app.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = app.mm; sourceTree = "<group>"; };
1A1852DB23E05814008F0DED /* deadlock.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = deadlock.mm; sourceTree = "<group>"; };
1A3E5EA723E9E83B00EDE661 /* rendertarget.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = rendertarget.mm; sourceTree = "<group>"; };
Expand Down Expand Up @@ -124,6 +140,14 @@
37C09D8721580FE4006A6758 /* SystemDialogs.mm */,
AB7A61F02147C815003C5833 /* Products */,
AB661C1C2148230E00291242 /* Frameworks */,
18391676ECF0E983F4964357 /* WindowBaseImpl.mm */,
183915BFF0E234CD3604A7CD /* WindowBaseImpl.h */,
18391BBB7782C296D424071F /* INSWindowHolder.h */,
183919BF108EB72A029F7671 /* WindowImpl.mm */,
18391CD090AA776E7E841AC9 /* WindowImpl.h */,
183913C6BFD6856BD42D19FD /* IWindowStateChanged.h */,
18391E45702740FE9DD69695 /* ResizeScope.mm */,
1839171D898F9BFC1373631A /* ResizeScope.h */,
);
sourceTree = "<group>";
};
Expand All @@ -143,6 +167,11 @@
buildActionMask = 2147483647;
files = (
37155CE4233C00EB0034DCE9 /* menu.h in Headers */,
183916173528EC2737DBE5E1 /* WindowBaseImpl.h in Headers */,
1839171DCC651B0638603AC4 /* INSWindowHolder.h in Headers */,
183919D91DB9AAB5D700C2EA /* WindowImpl.h in Headers */,
18391CF07316F819E76B617C /* IWindowStateChanged.h in Headers */,
18391C28BF1823B5464FDD36 /* ResizeScope.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -221,6 +250,9 @@
AB00E4F72147CA920032A60A /* main.mm in Sources */,
37C09D8821580FE4006A6758 /* SystemDialogs.mm in Sources */,
AB661C202148286E00291242 /* window.mm in Sources */,
1839179A55FC1421BEE83330 /* WindowBaseImpl.mm in Sources */,
1839125F057B0A4EB1760058 /* WindowImpl.mm in Sources */,
18391068E48EF96E3DB5FDAB /* ResizeScope.mm in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
15 changes: 15 additions & 0 deletions native/Avalonia.Native/src/OSX/INSWindowHolder.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//
// Created by Dan Walmsley on 04/05/2022.
// Copyright (c) 2022 Avalonia. All rights reserved.
//

#ifndef AVALONIA_NATIVE_OSX_INSWINDOWHOLDER_H
#define AVALONIA_NATIVE_OSX_INSWINDOWHOLDER_H

struct INSWindowHolder
{
virtual AvnWindow* _Nonnull GetNSWindow () = 0;
virtual AvnView* _Nonnull GetNSView () = 0;
};

#endif //AVALONIA_NATIVE_OSX_INSWINDOWHOLDER_H
18 changes: 18 additions & 0 deletions native/Avalonia.Native/src/OSX/IWindowStateChanged.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//
// Created by Dan Walmsley on 04/05/2022.
// Copyright (c) 2022 Avalonia. All rights reserved.
//

#ifndef AVALONIA_NATIVE_OSX_IWINDOWSTATECHANGED_H
#define AVALONIA_NATIVE_OSX_IWINDOWSTATECHANGED_H

struct IWindowStateChanged
{
virtual void WindowStateChanged () = 0;
virtual void StartStateTransition () = 0;
virtual void EndStateTransition () = 0;
virtual SystemDecorations Decorations () = 0;
virtual AvnWindowState WindowState () = 0;
};

#endif //AVALONIA_NATIVE_OSX_IWINDOWSTATECHANGED_H
23 changes: 23 additions & 0 deletions native/Avalonia.Native/src/OSX/ResizeScope.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//
// Created by Dan Walmsley on 04/05/2022.
// Copyright (c) 2022 Avalonia. All rights reserved.
//

#ifndef AVALONIA_NATIVE_OSX_RESIZESCOPE_H
#define AVALONIA_NATIVE_OSX_RESIZESCOPE_H

#include "window.h"
#include "avalonia-native.h"

class ResizeScope
{
public:
ResizeScope(AvnView* _Nonnull view, AvnPlatformResizeReason reason);

~ResizeScope();
private:
AvnView* _Nonnull _view;
AvnPlatformResizeReason _restore;
};

#endif //AVALONIA_NATIVE_OSX_RESIZESCOPE_H
17 changes: 17 additions & 0 deletions native/Avalonia.Native/src/OSX/ResizeScope.mm
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//
// Created by Dan Walmsley on 04/05/2022.
// Copyright (c) 2022 Avalonia. All rights reserved.
//

#import <AppKit/AppKit.h>
#include "ResizeScope.h"

ResizeScope::ResizeScope(AvnView *view, AvnPlatformResizeReason reason) {
_view = view;
_restore = [view getResizeReason];
[view setResizeReason:reason];
}

ResizeScope::~ResizeScope() {
[_view setResizeReason:_restore];
}
1 change: 1 addition & 0 deletions native/Avalonia.Native/src/OSX/SystemDialogs.mm
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "common.h"
#include "window.h"
#include "INSWindowHolder.h"

class SystemDialogs : public ComSingleObject<IAvnSystemDialogs, &IID_IAvnSystemDialogs>
{
Expand Down
119 changes: 119 additions & 0 deletions native/Avalonia.Native/src/OSX/WindowBaseImpl.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
//
// Created by Dan Walmsley on 04/05/2022.
// Copyright (c) 2022 Avalonia. All rights reserved.
//

#ifndef AVALONIA_NATIVE_OSX_WINDOWBASEIMPL_H
#define AVALONIA_NATIVE_OSX_WINDOWBASEIMPL_H

#import "rendertarget.h"
#include "INSWindowHolder.h"

class WindowBaseImpl : public virtual ComObject,
public virtual IAvnWindowBase,
public INSWindowHolder {
private:
NSCursor *cursor;

public:
FORWARD_IUNKNOWN()

BEGIN_INTERFACE_MAP()
INTERFACE_MAP_ENTRY(IAvnWindowBase, IID_IAvnWindowBase)
END_INTERFACE_MAP()

virtual ~WindowBaseImpl() {
View = NULL;
Window = NULL;
}

AutoFitContentView *StandardContainer;
AvnView *View;
AvnWindow *Window;
ComPtr<IAvnWindowBaseEvents> BaseEvents;
ComPtr<IAvnGlContext> _glContext;
NSObject <IRenderTarget> *renderTarget;
AvnPoint lastPositionSet;
NSString *_lastTitle;

bool _shown;
bool _inResize;

WindowBaseImpl(IAvnWindowBaseEvents *events, IAvnGlContext *gl);

virtual HRESULT ObtainNSWindowHandle(void **ret) override;

virtual HRESULT ObtainNSWindowHandleRetained(void **ret) override;

virtual HRESULT ObtainNSViewHandle(void **ret) override;

virtual HRESULT ObtainNSViewHandleRetained(void **ret) override;

virtual AvnWindow *GetNSWindow() override;

virtual AvnView *GetNSView() override;

virtual HRESULT Show(bool activate, bool isDialog) override;

virtual bool ShouldTakeFocusOnShow();

virtual HRESULT Hide() override;

virtual HRESULT Activate() override;

virtual HRESULT SetTopMost(bool value) override;

virtual HRESULT Close() override;

virtual HRESULT GetClientSize(AvnSize *ret) override;

virtual HRESULT GetFrameSize(AvnSize *ret) override;

virtual HRESULT GetScaling(double *ret) override;

virtual HRESULT SetMinMaxSize(AvnSize minSize, AvnSize maxSize) override;

virtual HRESULT Resize(double x, double y, AvnPlatformResizeReason reason) override;

virtual HRESULT Invalidate(__attribute__((unused)) AvnRect rect) override;

virtual HRESULT SetMainMenu(IAvnMenu *menu) override;

virtual HRESULT BeginMoveDrag() override;

virtual HRESULT BeginResizeDrag(__attribute__((unused)) AvnWindowEdge edge) override;

virtual HRESULT GetPosition(AvnPoint *ret) override;

virtual HRESULT SetPosition(AvnPoint point) override;

virtual HRESULT PointToClient(AvnPoint point, AvnPoint *ret) override;

virtual HRESULT PointToScreen(AvnPoint point, AvnPoint *ret) override;

virtual HRESULT ThreadSafeSetSwRenderedFrame(AvnFramebuffer *fb, IUnknown *dispose) override;

virtual HRESULT SetCursor(IAvnCursor *cursor) override;

virtual void UpdateCursor();

virtual HRESULT CreateGlRenderTarget(IAvnGlSurfaceRenderTarget **ppv) override;

virtual HRESULT CreateNativeControlHost(IAvnNativeControlHost **retOut) override;

virtual HRESULT SetBlurEnabled(bool enable) override;

virtual HRESULT BeginDragAndDropOperation(AvnDragDropEffects effects, AvnPoint point,
IAvnClipboard *clipboard, IAvnDndResultCallback *cb,
void *sourceHandle) override;

virtual bool IsDialog();

protected:
virtual NSWindowStyleMask GetStyle();

void UpdateStyle();

};

#endif //AVALONIA_NATIVE_OSX_WINDOWBASEIMPL_H
Loading

0 comments on commit 991d9d8

Please sign in to comment.