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

[AppKit] Create a better binding for [NSEvent eventWithGCEvent:]. #20362

Merged
merged 1 commit into from
Mar 25, 2024
Merged
Show file tree
Hide file tree
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
9 changes: 9 additions & 0 deletions src/AppKit/NSEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@ namespace AppKit {
[DebuggerTypeProxy (typeof (NSEvent.NSEventDebuggerProxy))]
public partial class NSEvent {

/// <summary>Create a new <see cref="AppKit.NSEvent" /> using the specified <see cref="CoreGraphics.CGEvent" />.</summary>
/// <param name="event">The <see cref="CoreGraphics.CGEvent" /> that will be wrapped.</param>
/// <returns>The newly created <see cref="AppKit.NSEvent" />.</returns>
/// <remarks>This method will return null if there's no corresponding Cocoa event.</remarks>
public static NSEvent? Create (CGEvent @event)
{
return EventWithCGEvent (@event.GetNonNullHandle (nameof (@event)));
}

class NSEventDebuggerProxy {
NSEvent target;

Expand Down
4 changes: 4 additions & 0 deletions src/appkit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7956,6 +7956,10 @@ interface NSEvent : NSCoding, NSCopying {

[Static]
[Export ("eventWithCGEvent:")]
[Obsolete ("Use 'Create (CGEvent)' instead.")]
#if XAMCORE_5_0
[Internal]
#endif
NSEvent EventWithCGEvent (IntPtr cgEventPtr);

[Export ("magnification")]
Expand Down
23 changes: 23 additions & 0 deletions tests/monotouch-test/AppKit/NSEvent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#if __MACOS__
using NUnit.Framework;
using System;

using AppKit;
using CoreGraphics;
using Foundation;
using ObjCRuntime;

namespace Xamarin.Mac.Tests {
[TestFixture]
[Preserve (AllMembers = true)]
public class NSEventTests {
[Test]
public void Create ()
{
using var cgevent = new CGEvent (null, (ushort) 1, true);
using var nsevent = NSEvent.Create (cgevent);
Assert.AreEqual ((int) cgevent.EventType, (int) nsevent.Type, "[Event]Type");
}
}
}
#endif // __MACOS__
Loading