mirror of
https://github.com/netbirdio/IronRDP.git
synced 2026-05-22 18:43:12 -07:00
feat(ffi): expose InclusiveRectangle attributes (#480)
This commit is contained in:
@@ -46,11 +46,11 @@ public struct DiplomatWriteable : IDisposable
|
||||
|
||||
IntPtr flushFuncPtr = Marshal.GetFunctionPointerForDelegate(flushFunc);
|
||||
IntPtr growFuncPtr = Marshal.GetFunctionPointerForDelegate(growFunc);
|
||||
|
||||
|
||||
// flushFunc and growFunc are managed objects and might be disposed of by the garbage collector.
|
||||
// To prevent this, we make the context hold the references and protect the context itself
|
||||
// for automatic disposal by moving it behind a GCHandle.
|
||||
DiplomatWriteableContext ctx = new DiplomatWriteableContext();
|
||||
DiplomatWriteableContext ctx = new DiplomatWriteableContext();
|
||||
ctx.flushFunc = flushFunc;
|
||||
ctx.growFunc = growFunc;
|
||||
GCHandle ctxHandle = GCHandle.Alloc(ctx);
|
||||
@@ -81,7 +81,7 @@ public struct DiplomatWriteable : IDisposable
|
||||
{
|
||||
throw new IndexOutOfRangeException("DiplomatWriteable buffer is too big");
|
||||
}
|
||||
return Marshal.PtrToStringUTF8(buf, (int)len);
|
||||
return Marshal.PtrToStringUTF8(buf, (int) len);
|
||||
#else
|
||||
byte[] utf8 = ToUtf8Bytes();
|
||||
return DiplomatUtils.Utf8ToString(utf8);
|
||||
|
||||
@@ -15,6 +15,54 @@ public partial class InclusiveRectangle: IDisposable
|
||||
{
|
||||
private unsafe Raw.InclusiveRectangle* _inner;
|
||||
|
||||
public ushort Bottom
|
||||
{
|
||||
get
|
||||
{
|
||||
return GetBottom();
|
||||
}
|
||||
}
|
||||
|
||||
public ushort Height
|
||||
{
|
||||
get
|
||||
{
|
||||
return GetHeight();
|
||||
}
|
||||
}
|
||||
|
||||
public ushort Left
|
||||
{
|
||||
get
|
||||
{
|
||||
return GetLeft();
|
||||
}
|
||||
}
|
||||
|
||||
public ushort Right
|
||||
{
|
||||
get
|
||||
{
|
||||
return GetRight();
|
||||
}
|
||||
}
|
||||
|
||||
public ushort Top
|
||||
{
|
||||
get
|
||||
{
|
||||
return GetTop();
|
||||
}
|
||||
}
|
||||
|
||||
public ushort Width
|
||||
{
|
||||
get
|
||||
{
|
||||
return GetWidth();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a managed <c>InclusiveRectangle</c> from a raw handle.
|
||||
/// </summary>
|
||||
@@ -29,6 +77,84 @@ public partial class InclusiveRectangle: IDisposable
|
||||
_inner = handle;
|
||||
}
|
||||
|
||||
public ushort GetLeft()
|
||||
{
|
||||
unsafe
|
||||
{
|
||||
if (_inner == null)
|
||||
{
|
||||
throw new ObjectDisposedException("InclusiveRectangle");
|
||||
}
|
||||
ushort retVal = Raw.InclusiveRectangle.GetLeft(_inner);
|
||||
return retVal;
|
||||
}
|
||||
}
|
||||
|
||||
public ushort GetTop()
|
||||
{
|
||||
unsafe
|
||||
{
|
||||
if (_inner == null)
|
||||
{
|
||||
throw new ObjectDisposedException("InclusiveRectangle");
|
||||
}
|
||||
ushort retVal = Raw.InclusiveRectangle.GetTop(_inner);
|
||||
return retVal;
|
||||
}
|
||||
}
|
||||
|
||||
public ushort GetRight()
|
||||
{
|
||||
unsafe
|
||||
{
|
||||
if (_inner == null)
|
||||
{
|
||||
throw new ObjectDisposedException("InclusiveRectangle");
|
||||
}
|
||||
ushort retVal = Raw.InclusiveRectangle.GetRight(_inner);
|
||||
return retVal;
|
||||
}
|
||||
}
|
||||
|
||||
public ushort GetBottom()
|
||||
{
|
||||
unsafe
|
||||
{
|
||||
if (_inner == null)
|
||||
{
|
||||
throw new ObjectDisposedException("InclusiveRectangle");
|
||||
}
|
||||
ushort retVal = Raw.InclusiveRectangle.GetBottom(_inner);
|
||||
return retVal;
|
||||
}
|
||||
}
|
||||
|
||||
public ushort GetWidth()
|
||||
{
|
||||
unsafe
|
||||
{
|
||||
if (_inner == null)
|
||||
{
|
||||
throw new ObjectDisposedException("InclusiveRectangle");
|
||||
}
|
||||
ushort retVal = Raw.InclusiveRectangle.GetWidth(_inner);
|
||||
return retVal;
|
||||
}
|
||||
}
|
||||
|
||||
public ushort GetHeight()
|
||||
{
|
||||
unsafe
|
||||
{
|
||||
if (_inner == null)
|
||||
{
|
||||
throw new ObjectDisposedException("InclusiveRectangle");
|
||||
}
|
||||
ushort retVal = Raw.InclusiveRectangle.GetHeight(_inner);
|
||||
return retVal;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the underlying raw handle.
|
||||
/// </summary>
|
||||
|
||||
@@ -16,6 +16,24 @@ public partial struct InclusiveRectangle
|
||||
{
|
||||
private const string NativeLib = "DevolutionsIronRdp";
|
||||
|
||||
[DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "InclusiveRectangle_get_left", ExactSpelling = true)]
|
||||
public static unsafe extern ushort GetLeft(InclusiveRectangle* self);
|
||||
|
||||
[DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "InclusiveRectangle_get_top", ExactSpelling = true)]
|
||||
public static unsafe extern ushort GetTop(InclusiveRectangle* self);
|
||||
|
||||
[DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "InclusiveRectangle_get_right", ExactSpelling = true)]
|
||||
public static unsafe extern ushort GetRight(InclusiveRectangle* self);
|
||||
|
||||
[DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "InclusiveRectangle_get_bottom", ExactSpelling = true)]
|
||||
public static unsafe extern ushort GetBottom(InclusiveRectangle* self);
|
||||
|
||||
[DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "InclusiveRectangle_get_width", ExactSpelling = true)]
|
||||
public static unsafe extern ushort GetWidth(InclusiveRectangle* self);
|
||||
|
||||
[DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "InclusiveRectangle_get_height", ExactSpelling = true)]
|
||||
public static unsafe extern ushort GetHeight(InclusiveRectangle* self);
|
||||
|
||||
[DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "InclusiveRectangle_destroy", ExactSpelling = true)]
|
||||
public static unsafe extern void Destroy(InclusiveRectangle* self);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
#[diplomat::bridge]
|
||||
pub mod ffi {
|
||||
|
||||
use ironrdp::pdu::geometry::Rectangle;
|
||||
|
||||
use crate::{error::ffi::IronRdpError, utils::ffi::VecU8};
|
||||
|
||||
#[diplomat::opaque]
|
||||
@@ -34,6 +36,32 @@ pub mod ffi {
|
||||
#[diplomat::opaque]
|
||||
pub struct InclusiveRectangle(pub ironrdp::pdu::geometry::InclusiveRectangle);
|
||||
|
||||
impl InclusiveRectangle {
|
||||
pub fn get_left(&self) -> u16 {
|
||||
self.0.left
|
||||
}
|
||||
|
||||
pub fn get_top(&self) -> u16 {
|
||||
self.0.top
|
||||
}
|
||||
|
||||
pub fn get_right(&self) -> u16 {
|
||||
self.0.right
|
||||
}
|
||||
|
||||
pub fn get_bottom(&self) -> u16 {
|
||||
self.0.bottom
|
||||
}
|
||||
|
||||
pub fn get_width(&self) -> u16 {
|
||||
self.0.width()
|
||||
}
|
||||
|
||||
pub fn get_height(&self) -> u16 {
|
||||
self.0.height()
|
||||
}
|
||||
}
|
||||
|
||||
#[diplomat::opaque]
|
||||
pub struct IronRdpPdu; // A struct representing the ironrdp_pdu crate
|
||||
|
||||
|
||||
Reference in New Issue
Block a user