Skip to content

Commit

Permalink
point of confusion
Browse files Browse the repository at this point in the history
  • Loading branch information
tj_devel709 committed Oct 20, 2023
1 parent 5bdc17a commit 71405c6
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 69 deletions.
54 changes: 0 additions & 54 deletions src/BindingHelpers.cs

This file was deleted.

104 changes: 92 additions & 12 deletions src/PrintCore/PDEPlugInCallbackProtocol.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<PMPrintSession> (_GetPrintSession ());
get => GetPtrToStruct<PMPrintSession> (_GetPrintSession ());
}

#if NET
[SupportedOSPlatform ("macos13.0")]
[UnsupportedOSPlatform ("ios")]
[UnsupportedOSPlatform ("maccatalyst")]
[UnsupportedOSPlatform ("tvos")]
#endif
public PMPrintSession? PrintSettings {
get => BindingHelpers.GetPtrToStruct<PMPrintSession> (_GetPrintSettings ());
get => GetPtrToStruct<PMPrintSession> (_GetPrintSettings ());
}


#if NET
[SupportedOSPlatform ("macos13.0")]
[UnsupportedOSPlatform ("ios")]
[UnsupportedOSPlatform ("maccatalyst")]
[UnsupportedOSPlatform ("tvos")]
#endif
public PMPageFormat? PageFormat {
get => BindingHelpers.GetPtrToStruct<PMPageFormat> (_GetPageFormat ());
get => GetPtrToStruct<PMPageFormat> (_GetPageFormat ());
}


#if NET
[SupportedOSPlatform ("macos13.0")]
[UnsupportedOSPlatform ("ios")]
[UnsupportedOSPlatform ("maccatalyst")]
[UnsupportedOSPlatform ("tvos")]
#endif
public PMPrinter? PMPrinter {
get => BindingHelpers.GetPtrToStruct<PMPrinter> (_GetPMPrinter ());
get => GetPtrToStruct<PMPrinter> (_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<ppd_file_s> (_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<PMPrinter> (_GetPMPrinter ());
// }
internal static T? GetPtrToStruct<T> (IntPtr intPtr) where T : struct
{
if (intPtr == IntPtr.Zero)
return null;
return Marshal.PtrToStructure<T> (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<MPSScaleTransform> (value, (ptr) => _SetScaleTransform (ptr));
// }
internal static void SetPtrToStruct<T> (T? value, Action<IntPtr> setAction) where T : struct
{
if (value.HasValue) {
var size_of_scale_transform = Marshal.SizeOf<T> ();
IntPtr ptr = Marshal.AllocHGlobal (size_of_scale_transform);
try {
Marshal.StructureToPtr<T> (value.Value, ptr, false);
setAction (ptr);
} finally {
Marshal.FreeHGlobal (ptr);
}
} else {
setAction (IntPtr.Zero);
}
}
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/printcore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

namespace PrintCore {

[Mac (14,0)]
[Mac (13,0)]
[Protocol]
[BaseType (typeof (NSObject))]
interface PDEPanel
Expand Down Expand Up @@ -70,7 +70,7 @@ interface PDEPanel
void PrintWindowWillClose (bool userCanceled);
}

[Mac (14,0)]
[Mac (13,0)]
[Protocol]
[BaseType (typeof (NSObject))]
interface PDEPlugIn
Expand All @@ -86,7 +86,7 @@ interface PDEPlugIn

interface IPDEPlugInCallbackProtocol { }

[Mac (14,0)]
[Mac (13,0)]
[Protocol]
interface PDEPlugInCallbackProtocol
{
Expand Down

0 comments on commit 71405c6

Please sign in to comment.