diff --git a/src/BindingHelpers.cs b/src/BindingHelpers.cs deleted file mode 100644 index 2deeebf81b36..000000000000 --- a/src/BindingHelpers.cs +++ /dev/null @@ -1,54 +0,0 @@ -#nullable enable - -namespace BindingHelpers -{ - internal static class BindingHelpers { - // this method is helpful for the getter for something like: - // unsafe PMPrinter* PMPrinter { get; } - // - // we can change this to: - // [Internal] - // [Export ("PMPrinter")] - // IntPtr _GetPMPrinter (); - // - // and then add this to the manual file: - // public PMPrinter? PMPrinter { - // get => BindingHelpers.GetPtrToStruct (_GetPMPrinter ()); - // } - public static T? GetPtrToStruct (IntPtr intPtr) where T : struct - { - if (intPtr == IntPtr.Zero) - return null; - return Marshal.PtrToStructure (intPtr); - } - - // this method is helpful for the setter for something like: - // unsafe MPSScaleTransform* ScaleTransform { get; set; } - // - // we can change this to: - // [Export ("setScaleTransform:")] - // [Internal] - // void _SetScaleTransform (IntPtr value); - // - // and then add this to the manual file: - // public MPSScaleTransform? ScaleTransform { - // ... - // set => BindingHelpers.SetPtrToStruct (value, (ptr) => _SetScaleTransform (ptr)); - // } - public static void SetPtrToStruct (object? value, Action setAction) where T : struct - { - if (value.HasValue) { - var size_of_scale_transform = Marshal.SizeOf (); - IntPtr ptr = Marshal.AllocHGlobal (size_of_scale_transform); - try { - Marshal.StructureToPtr (value.Value, ptr, false); - setAction (ptr); - } finally { - Marshal.FreeHGlobal (ptr); - } - } else { - setAction (IntPtr.Zero); - } - } - } -} \ No newline at end of file diff --git a/src/PrintCore/PDEPlugInCallbackProtocol.cs b/src/PrintCore/PDEPlugInCallbackProtocol.cs index 72899a7b290c..22ec5d44b1ce 100644 --- a/src/PrintCore/PDEPlugInCallbackProtocol.cs +++ b/src/PrintCore/PDEPlugInCallbackProtocol.cs @@ -6,33 +6,113 @@ using System.Runtime.InteropServices; using Foundation; using ObjCRuntime; -// TODO add reference to BindingHelpers -using BindingHelpers; +using ppd_file_s = System.IntPtr; + +#if !NET +using NativeHandle = System.IntPtr; +#endif namespace PrintCore { public partial class PDEPlugInCallbackProtocol { +#if NET + [SupportedOSPlatform ("macos13.0")] + [UnsupportedOSPlatform ("ios")] + [UnsupportedOSPlatform ("maccatalyst")] + [UnsupportedOSPlatform ("tvos")] +#endif public PMPrintSession? PrintSession { - get => BindingHelpers.GetPtrToStruct (_GetPrintSession ()); + get => GetPtrToStruct (_GetPrintSession ()); } +#if NET + [SupportedOSPlatform ("macos13.0")] + [UnsupportedOSPlatform ("ios")] + [UnsupportedOSPlatform ("maccatalyst")] + [UnsupportedOSPlatform ("tvos")] +#endif public PMPrintSession? PrintSettings { - get => BindingHelpers.GetPtrToStruct (_GetPrintSettings ()); + get => GetPtrToStruct (_GetPrintSettings ()); } - + +#if NET + [SupportedOSPlatform ("macos13.0")] + [UnsupportedOSPlatform ("ios")] + [UnsupportedOSPlatform ("maccatalyst")] + [UnsupportedOSPlatform ("tvos")] +#endif public PMPageFormat? PageFormat { - get => BindingHelpers.GetPtrToStruct (_GetPageFormat ()); + get => GetPtrToStruct (_GetPageFormat ()); } - + +#if NET + [SupportedOSPlatform ("macos13.0")] + [UnsupportedOSPlatform ("ios")] + [UnsupportedOSPlatform ("maccatalyst")] + [UnsupportedOSPlatform ("tvos")] +#endif public PMPrinter? PMPrinter { - get => BindingHelpers.GetPtrToStruct (_GetPMPrinter ()); + get => GetPtrToStruct (_GetPMPrinter ()); } - - // TODO Figure out how to make the ppd_file_s: https://gist.github.com/tj-devel709/ef051c6750fb304d826f58059d2c1acd#file-ppd-h-L286 - // public ppd_file_s? PpdFile { - // get => BindingHelpers.GetPtrToStruct (_GetPpdFile ()); + +#if NET + [SupportedOSPlatform ("macos13.0")] + [UnsupportedOSPlatform ("ios")] + [UnsupportedOSPlatform ("maccatalyst")] + [UnsupportedOSPlatform ("tvos")] +#endif + public ppd_file_s? PpdFile { + get => _GetPpdFile (); + } + + // this method is helpful for the getter for something like: + // unsafe PMPrinter* PMPrinter { get; } + // + // we can change this to: + // [Internal] + // [Export ("PMPrinter")] + // IntPtr _GetPMPrinter (); + // + // and then add this to the manual file: + // public PMPrinter? PMPrinter { + // get => BindingHelpers.GetPtrToStruct (_GetPMPrinter ()); // } + internal static T? GetPtrToStruct (IntPtr intPtr) where T : struct + { + if (intPtr == IntPtr.Zero) + return null; + return Marshal.PtrToStructure (intPtr); + } + + // this method is helpful for the setter for something like: + // unsafe MPSScaleTransform* ScaleTransform { get; set; } + // + // we can change this to: + // [Export ("setScaleTransform:")] + // [Internal] + // void _SetScaleTransform (IntPtr value); + // + // and then add this to the manual file: + // public MPSScaleTransform? ScaleTransform { + // ... + // set => BindingHelpers.SetPtrToStruct (value, (ptr) => _SetScaleTransform (ptr)); + // } + internal static void SetPtrToStruct (T? value, Action setAction) where T : struct + { + if (value.HasValue) { + var size_of_scale_transform = Marshal.SizeOf (); + IntPtr ptr = Marshal.AllocHGlobal (size_of_scale_transform); + try { + Marshal.StructureToPtr (value.Value, ptr, false); + setAction (ptr); + } finally { + Marshal.FreeHGlobal (ptr); + } + } else { + setAction (IntPtr.Zero); + } + } } } diff --git a/src/printcore.cs b/src/printcore.cs index 06e4d6561086..0219b1b5679e 100644 --- a/src/printcore.cs +++ b/src/printcore.cs @@ -16,7 +16,7 @@ namespace PrintCore { - [Mac (14,0)] + [Mac (13,0)] [Protocol] [BaseType (typeof (NSObject))] interface PDEPanel @@ -70,7 +70,7 @@ interface PDEPanel void PrintWindowWillClose (bool userCanceled); } - [Mac (14,0)] + [Mac (13,0)] [Protocol] [BaseType (typeof (NSObject))] interface PDEPlugIn @@ -86,7 +86,7 @@ interface PDEPlugIn interface IPDEPlugInCallbackProtocol { } - [Mac (14,0)] + [Mac (13,0)] [Protocol] interface PDEPlugInCallbackProtocol {