Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
/ corefx Public archive

Commit

Permalink
Cleanup GDI interop in System.Drawing.Common (#39727)
Browse files Browse the repository at this point in the history
* Cleanup GDI object Interop

* Cleanup GDI region interop

* Cleanup GDI font interop

* Cleanup GDI DC interop

* Address PR feedback
  • Loading branch information
hughbe authored and safern committed Nov 1, 2019
1 parent 273d46a commit f807df6
Show file tree
Hide file tree
Showing 56 changed files with 875 additions and 570 deletions.
32 changes: 32 additions & 0 deletions src/Common/src/Interop/Windows/Gdi32/Interop.CombineRgn.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
using System.Diagnostics;
using System.Runtime.InteropServices;

internal static partial class Interop
{
internal static partial class Gdi32
{
public enum CombineMode : int
{
RGN_AND = 1,
RGN_XOR = 3,
RGN_DIFF = 4,
}

[DllImport(Libraries.Gdi32, SetLastError = true, ExactSpelling = true)]
public static extern RegionType CombineRgn(IntPtr hrgnDst, IntPtr hrgnSrc1, IntPtr hrgnSrc2, CombineMode iMode);

public static RegionType CombineRgn(HandleRef hrgnDst, HandleRef hrgnSrc1, HandleRef hrgnSrc2, CombineMode iMode)
{
RegionType result = CombineRgn(hrgnDst.Handle, hrgnSrc1.Handle, hrgnSrc2.Handle, iMode);
GC.KeepAlive(hrgnDst.Wrapper);
GC.KeepAlive(hrgnSrc1.Wrapper);
GC.KeepAlive(hrgnSrc2.Wrapper);
return result;
}
}
}
15 changes: 15 additions & 0 deletions src/Common/src/Interop/Windows/Gdi32/Interop.CreateCompatibleDC.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
using System.Runtime.InteropServices;

internal static partial class Interop
{
internal static partial class Gdi32
{
[DllImport(Libraries.Gdi32, ExactSpelling = true)]
public static extern IntPtr CreateCompatibleDC(IntPtr hdc);
}
}
15 changes: 15 additions & 0 deletions src/Common/src/Interop/Windows/Gdi32/Interop.CreateDC.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
using System.Runtime.InteropServices;

internal static partial class Interop
{
internal static partial class Gdi32
{
[DllImport(Libraries.Gdi32, ExactSpelling = true, CharSet = CharSet.Unicode)]
public static extern IntPtr CreateDCW(string pwszDriver, string pwszDevice, string pszPort, IntPtr pdm);
}
}
15 changes: 15 additions & 0 deletions src/Common/src/Interop/Windows/Gdi32/Interop.CreateFontIndirect.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
using System.Runtime.InteropServices;

internal static partial class Interop
{
internal static partial class Gdi32
{
[DllImport(Libraries.Gdi32, ExactSpelling = true, CharSet = CharSet.Unicode)]
public static extern IntPtr CreateFontIndirectW(ref User32.LOGFONT lplf);
}
}
15 changes: 15 additions & 0 deletions src/Common/src/Interop/Windows/Gdi32/Interop.CreateIC.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
using System.Runtime.InteropServices;

internal static partial class Interop
{
internal static partial class Gdi32
{
[DllImport(Libraries.Gdi32, ExactSpelling = true, CharSet = CharSet.Unicode)]
public static extern IntPtr CreateICW(string pszDriver, string pszDevice, string pszPort, IntPtr pdm);
}
}
15 changes: 15 additions & 0 deletions src/Common/src/Interop/Windows/Gdi32/Interop.CreateRectRgn.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
using System.Runtime.InteropServices;

internal static partial class Interop
{
internal static partial class Gdi32
{
[DllImport(Libraries.Gdi32, ExactSpelling = true)]
public static extern IntPtr CreateRectRgn(int x1, int y1, int x2, int y2);
}
}
22 changes: 22 additions & 0 deletions src/Common/src/Interop/Windows/Gdi32/Interop.DeleteDC.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
using System.Runtime.InteropServices;

internal static partial class Interop
{
internal static partial class Gdi32
{
[DllImport(Libraries.Gdi32, ExactSpelling = true)]
public static extern bool DeleteDC(IntPtr hdc);

public static bool DeleteDC(HandleRef hdc)
{
bool result = DeleteDC(hdc.Handle);
GC.KeepAlive(hdc.Wrapper);
return result;
}
}
}
22 changes: 22 additions & 0 deletions src/Common/src/Interop/Windows/Gdi32/Interop.DeleteObject.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
using System.Runtime.InteropServices;

internal static partial class Interop
{
internal static partial class Gdi32
{
[DllImport(Libraries.Gdi32, ExactSpelling = true)]
public static extern bool DeleteObject(IntPtr ho);

public static bool DeleteObject(HandleRef ho)
{
bool result = DeleteObject(ho.Handle);
GC.KeepAlive(ho.Wrapper);
return result;
}
}
}
31 changes: 31 additions & 0 deletions src/Common/src/Interop/Windows/Gdi32/Interop.GetClipRgn.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
using System.Diagnostics;
using System.Runtime.InteropServices;

internal static partial class Interop
{
internal static partial class Gdi32
{
[DllImport(Libraries.Gdi32, ExactSpelling = true)]
public static extern int GetClipRgn(IntPtr hdc, IntPtr hrgn);

public static int GetClipRgn(HandleRef hdc, IntPtr hrgn)
{
int result = GetClipRgn(hdc.Handle, hrgn);
GC.KeepAlive(hdc.Wrapper);
return result;
}

public static int GetClipRgn(HandleRef hdc, HandleRef hrgn)
{
int result = GetClipRgn(hdc.Handle, hrgn.Handle);
GC.KeepAlive(hdc.Wrapper);
GC.KeepAlive(hrgn.Wrapper);
return result;
}
}
}
22 changes: 22 additions & 0 deletions src/Common/src/Interop/Windows/Gdi32/Interop.GetCurrentObject.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
using System.Runtime.InteropServices;

internal static partial class Interop
{
internal static partial class Gdi32
{
[DllImport(Libraries.Gdi32, ExactSpelling = true)]
public static extern IntPtr GetCurrentObject(IntPtr hdc, ObjectType type);

public static IntPtr GetCurrentObject(HandleRef hdc, ObjectType type)
{
IntPtr result = GetCurrentObject(hdc.Handle, type);
GC.KeepAlive(hdc.Wrapper);
return result;
}
}
}
44 changes: 44 additions & 0 deletions src/Common/src/Interop/Windows/Gdi32/Interop.GetDeviceCaps.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
using System.Diagnostics;
using System.Runtime.InteropServices;

internal static partial class Interop
{
internal static partial class Gdi32
{
public enum DeviceCapability : int
{
TECHNOLOGY = 2,
VERTRES = 10,
HORZRES = 8,
BITSPIXEL = 12,
PLANES = 14,
LOGPIXELSX = 88,
LOGPIXELSY = 90,
PHYSICALWIDTH = 110,
PHYSICALHEIGHT = 111,
PHYSICALOFFSETX = 112,
PHYSICALOFFSETY = 113
}

public static class DeviceTechnology
{
public const int DT_PLOTTER = 0;
public const int DT_RASPRINTER = 2;
}

[DllImport(Libraries.Gdi32, ExactSpelling = true)]
public static extern int GetDeviceCaps(IntPtr hdc, DeviceCapability index);

public static int GetDeviceCaps(HandleRef hdc, DeviceCapability index)
{
int caps = GetDeviceCaps(hdc.Handle, index);
GC.KeepAlive(hdc.Wrapper);
return caps;
}
}
}
15 changes: 15 additions & 0 deletions src/Common/src/Interop/Windows/Gdi32/Interop.GetObjectType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
using System.Runtime.InteropServices;

internal static partial class Interop
{
internal static partial class Gdi32
{
[DllImport(Libraries.Gdi32, ExactSpelling = true)]
public static extern ObjectType GetObjectType(IntPtr h);
}
}
22 changes: 22 additions & 0 deletions src/Common/src/Interop/Windows/Gdi32/Interop.GetRgnBox.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
using System.Runtime.InteropServices;

internal static partial class Interop
{
internal static partial class Gdi32
{
[DllImport(Libraries.Gdi32, ExactSpelling = true)]
public static extern RegionType GetRgnBox(IntPtr hrgn, ref RECT lprc);

public static RegionType GetRgnBox(HandleRef hrgn, ref RECT lprc)
{
RegionType result = GetRgnBox(hrgn.Handle, ref lprc);
GC.KeepAlive(hrgn.Wrapper);
return result;
}
}
}
20 changes: 20 additions & 0 deletions src/Common/src/Interop/Windows/Gdi32/Interop.GetStockObject.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
using System.Runtime.InteropServices;

internal static partial class Interop
{
internal static partial class Gdi32
{
public enum StockObject : int
{
DEFAULT_GUI_FONT = 17
}

[DllImport(Libraries.Gdi32, ExactSpelling = true)]
public static extern IntPtr GetStockObject(StockObject i);
}
}
27 changes: 27 additions & 0 deletions src/Common/src/Interop/Windows/Gdi32/Interop.ObjectType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

internal static partial class Interop
{
internal static partial class Gdi32
{
public enum ObjectType : int
{
OBJ_PEN = 1,
OBJ_BRUSH = 2,
OBJ_DC = 3,
OBJ_METADC = 4,
OBJ_PAL = 5,
OBJ_FONT = 6,
OBJ_BITMAP = 7,
OBJ_REGION = 8,
OBJ_METAFILE = 9,
OBJ_MEMDC = 10,
OBJ_EXTPEN = 11,
OBJ_ENHMETADC = 12,
OBJ_ENHMETAFILE = 13,
OBJ_COLORSPACE = 14
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
using System.Drawing;
using System.Runtime.InteropServices;

internal static partial class Interop
{
internal static partial class Gdi32
{
[DllImport(Libraries.Gdi32, ExactSpelling = true)]
public static extern bool OffsetViewportOrgEx(IntPtr hdc, int x, int y, ref Point lppt);

public static bool OffsetViewportOrgEx(HandleRef hdc, int x, int y, ref Point lppt)
{
bool result = OffsetViewportOrgEx(hdc.Handle, x, y, ref lppt);
GC.KeepAlive(hdc.Wrapper);
return result;
}
}
}
23 changes: 23 additions & 0 deletions src/Common/src/Interop/Windows/Gdi32/Interop.RECT.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System.Drawing;
using System.Runtime.InteropServices;

internal static partial class Interop
{
internal static partial class Gdi32
{
[StructLayout(LayoutKind.Sequential)]
public struct RECT
{
public int left;
public int top;
public int right;
public int bottom;

public Size Size => new Size(right - left, bottom - top);
}
}
}
Loading

0 comments on commit f807df6

Please sign in to comment.