forked from xamarin/xamarin-macios
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
tj_devel709
committed
Oct 18, 2023
1 parent
c661ef5
commit b753413
Showing
2 changed files
with
110 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#nullable enable | ||
|
||
namespace BindingHelpers | ||
{ | ||
internal static class BindingHelpers { | ||
public static T? GetPtrToStruct<T> (IntPtr intPtr) where T : struct | ||
{ | ||
if (intPtr == IntPtr.Zero) | ||
return null; | ||
return Marshal.PtrToStructure<T> (intPtr); | ||
} | ||
|
||
public static void SetPtrToStruct<T> (object? 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); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
#nullable enable | ||
|
||
#if MONOMAC | ||
|
||
using System; | ||
using System.Runtime.InteropServices; | ||
using Foundation; | ||
using ObjCRuntime; | ||
|
||
namespace PrintCore { | ||
|
||
public partial class PDEPlugInCallbackProtocol { | ||
|
||
// public virtual MPSScaleTransform? ScaleTransform { | ||
// get { | ||
// var ptr = _GetScaleTransform (); | ||
// if (ptr == IntPtr.Zero) | ||
// return null; | ||
// return Marshal.PtrToStructure<MPSScaleTransform> (ptr); | ||
// } | ||
// set { | ||
// if (value.HasValue) { | ||
// IntPtr ptr = Marshal.AllocHGlobal (size_of_scale_transform); | ||
// try { | ||
// Marshal.StructureToPtr<MPSScaleTransform> (value.Value, ptr, false); | ||
// _SetScaleTransform (ptr); | ||
// } finally { | ||
// Marshal.FreeHGlobal (ptr); | ||
// } | ||
// } else { | ||
// _SetScaleTransform (IntPtr.Zero); | ||
// } | ||
// } | ||
// } | ||
|
||
public PMPrintSession? PrintSession { | ||
get => GetPtrToStruct<PMPrintSession> (_GetPrintSession ()); | ||
} | ||
|
||
public PMPrintSession? PrintSession { | ||
get => GetPtrToStruct<PMPrintSession> (_GetPrintSettings ()); | ||
} | ||
|
||
public PMPageFormat? PageFormat { | ||
get => GetPtrToStruct<PMPageFormat> (_GetPageFormat ()); | ||
} | ||
|
||
public PMPrinter? PMPrinter { | ||
get => GetPtrToStruct<PMPrinter> (_GetPMPrinter ()); | ||
} | ||
|
||
public ppd_file_s? PpdFile { | ||
get => GetPtrToStruct<ppd_file_s> (_GetPpdFile ()); | ||
} | ||
|
||
internal T? GetPtrToStruct<T> (IntPtr intPtr) where T : struct | ||
{ | ||
if (intPtr == IntPtr.Zero) | ||
return null; | ||
return Marshal.PtrToStructure<T> (intPtr); | ||
} | ||
|
||
internal void SetPtrToStruct<T> (object? 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); | ||
} | ||
} | ||
} | ||
} | ||
|
||
#endif |