Browse Source

Replace raw pointer with ComObjectWeakPtr<T> (#18757)

release/11.3.0
Nikita Tsukanov 1 year ago
committed by Julien Lebosquain
parent
commit
21fe205612
  1. 2
      native/Avalonia.Native/src/OSX/AvnView.mm
  2. 3
      native/Avalonia.Native/src/OSX/PopupImpl.mm
  3. 2
      native/Avalonia.Native/src/OSX/WindowBaseImpl.h
  4. 9
      native/Avalonia.Native/src/OSX/WindowBaseImpl.mm
  5. 2
      native/Avalonia.Native/src/OSX/WindowImpl.mm

2
native/Avalonia.Native/src/OSX/AvnView.mm

@ -363,7 +363,7 @@ static void ConvertTilt(NSPoint tilt, float* xTilt, float* yTilt)
auto windowBase = _parent.tryGetWithCast<WindowBaseImpl>(); auto windowBase = _parent.tryGetWithCast<WindowBaseImpl>();
if(windowBase != nullptr){ if(windowBase != nullptr){
auto parent = windowBase->Parent; auto parent = windowBase->Parent.tryGet();
if(parent != nullptr){ if(parent != nullptr){
auto parentWindow = parent->Window; auto parentWindow = parent->Window;

3
native/Avalonia.Native/src/OSX/PopupImpl.mm

@ -45,8 +45,9 @@ public:
virtual bool ShouldTakeFocusOnShow() override virtual bool ShouldTakeFocusOnShow() override
{ {
auto parent = Parent.tryGet();
// Don't steal the focus from another windows if our parent is inactive // Don't steal the focus from another windows if our parent is inactive
if (Parent != nullptr && Parent->Window != nullptr && ![Parent->Window isKeyWindow]) if (parent != nullptr && parent->Window != nullptr && ![parent->Window isKeyWindow])
return false; return false;
return WindowBaseImpl::ShouldTakeFocusOnShow(); return WindowBaseImpl::ShouldTakeFocusOnShow();

2
native/Avalonia.Native/src/OSX/WindowBaseImpl.h

@ -108,7 +108,7 @@ protected:
std::list<WindowBaseImpl*> _children; std::list<WindowBaseImpl*> _children;
public: public:
WindowBaseImpl* Parent = nullptr; ComObjectWeakPtr<WindowBaseImpl> Parent = nullptr;
NSWindow * Window; NSWindow * Window;
ComPtr<IAvnWindowBaseEvents> BaseEvents; ComPtr<IAvnWindowBaseEvents> BaseEvents;
}; };

9
native/Avalonia.Native/src/OSX/WindowBaseImpl.mm

@ -503,16 +503,19 @@ HRESULT WindowBaseImpl::SetParent(IAvnWindowBase *parent) {
START_COM_CALL; START_COM_CALL;
@autoreleasepool { @autoreleasepool {
if(Parent != nullptr)
auto oldParent = Parent.tryGet();
if(oldParent != nullptr)
{ {
Parent->_children.remove(this); oldParent->_children.remove(this);
} }
auto cparent = dynamic_cast<WindowImpl *>(parent); auto cparent = dynamic_cast<WindowImpl *>(parent);
Parent = cparent; Parent = cparent;
if(Parent != nullptr && Window != nullptr){ if(cparent != nullptr && Window != nullptr){
// If one tries to show a child window with a minimized parent window, then the parent window will be // If one tries to show a child window with a minimized parent window, then the parent window will be
// restored but macOS isn't kind enough to *tell* us that, so the window will be left in a non-interactive // restored but macOS isn't kind enough to *tell* us that, so the window will be left in a non-interactive
// state. Detect this and explicitly restore the parent window ourselves to avoid this situation. // state. Detect this and explicitly restore the parent window ourselves to avoid this situation.

2
native/Avalonia.Native/src/OSX/WindowImpl.mm

@ -546,7 +546,7 @@ bool WindowImpl::IsModal() {
} }
bool WindowImpl::IsOwned() { bool WindowImpl::IsOwned() {
return Parent != nullptr; return Parent.tryGet() != nullptr;
} }
NSWindowStyleMask WindowImpl::CalculateStyleMask() { NSWindowStyleMask WindowImpl::CalculateStyleMask() {

Loading…
Cancel
Save