Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add additional null checks to Avalonia.Native.WindowBaseImpl. #7299

Merged
merged 1 commit into from
Jan 3, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions src/Avalonia.Native/WindowImplBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,18 @@ public MacOSTopLevelWindowHandle(IAvnWindowBase native)

public string HandleDescriptor => "NSWindow";

public IntPtr NSView => _native.ObtainNSViewHandle();
public IntPtr NSView => _native?.ObtainNSViewHandle() ?? IntPtr.Zero;

public IntPtr NSWindow => _native.ObtainNSWindowHandle();
public IntPtr NSWindow => _native?.ObtainNSWindowHandle() ?? IntPtr.Zero;

public IntPtr GetNSViewRetained()
{
return _native.ObtainNSViewHandleRetained();
return _native?.ObtainNSViewHandleRetained() ?? IntPtr.Zero;
}

public IntPtr GetNSWindowRetained()
{
return _native.ObtainNSWindowHandleRetained();
return _native?.ObtainNSWindowHandleRetained() ?? IntPtr.Zero;
}
}

Expand Down Expand Up @@ -260,7 +260,7 @@ public AvnDragDropEffects DragEvent(AvnDragEventType type, AvnPoint position,

public void Activate()
{
_native.Activate();
_native?.Activate();
}

public bool RawTextInputEvent(uint timeStamp, string text)
Expand Down Expand Up @@ -322,7 +322,7 @@ public void RawMouseEvent(AvnRawMouseEventType type, uint timeStamp, AvnInputMod

public void Resize(Size clientSize, PlatformResizeReason reason)
{
_native.Resize(clientSize.Width, clientSize.Height, (AvnPlatformResizeReason)reason);
_native?.Resize(clientSize.Width, clientSize.Height, (AvnPlatformResizeReason)reason);
}

public IRenderer CreateRenderer(IRenderRoot root)
Expand Down Expand Up @@ -367,14 +367,14 @@ public void SetInputRoot(IInputRoot inputRoot)

public virtual void Show(bool activate, bool isDialog)
{
_native.Show(activate.AsComBool(), isDialog.AsComBool());
_native?.Show(activate.AsComBool(), isDialog.AsComBool());
}


public PixelPoint Position
{
get => _native.Position.ToAvaloniaPixelPoint();
set => _native.SetPosition(value.ToAvnPoint());
get => _native?.Position.ToAvaloniaPixelPoint() ?? default;
set => _native?.SetPosition(value.ToAvnPoint());
}

public Point PointToClient(PixelPoint point)
Expand All @@ -389,20 +389,20 @@ public PixelPoint PointToScreen(Point point)

public void Hide()
{
_native.Hide();
_native?.Hide();
}

public void BeginMoveDrag(PointerPressedEventArgs e)
{
_native.BeginMoveDrag();
_native?.BeginMoveDrag();
}

public Size MaxAutoSizeHint => Screen.AllScreens.Select(s => s.Bounds.Size.ToSize(1))
.OrderByDescending(x => x.Width + x.Height).FirstOrDefault();

public void SetTopmost(bool value)
{
_native.SetTopMost(value.AsComBool());
_native?.SetTopMost(value.AsComBool());
}

public double RenderScaling => _native?.Scaling ?? 1;
Expand Down Expand Up @@ -438,7 +438,7 @@ public void SetCursor(ICursorImpl cursor)

public void SetMinMaxSize(Size minSize, Size maxSize)
{
_native.SetMinMaxSize(minSize.ToAvnSize(), maxSize.ToAvnSize());
_native?.SetMinMaxSize(minSize.ToAvnSize(), maxSize.ToAvnSize());
}

public void BeginResizeDrag(WindowEdge edge, PointerPressedEventArgs e)
Expand All @@ -449,7 +449,7 @@ public void BeginResizeDrag(WindowEdge edge, PointerPressedEventArgs e)
internal void BeginDraggingSession(AvnDragDropEffects effects, AvnPoint point, IAvnClipboard clipboard,
IAvnDndResultCallback callback, IntPtr sourceHandle)
{
_native.BeginDragAndDropOperation(effects, point, clipboard, callback, sourceHandle);
_native?.BeginDragAndDropOperation(effects, point, clipboard, callback, sourceHandle);
}

public void SetTransparencyLevelHint(WindowTransparencyLevel transparencyLevel)
Expand Down