Documented and changed Graphics references to IDeviceContext references

pull/10/head
David Hall 2018-06-27 13:11:18 -06:00
parent 03b292eeba
commit 3a19f0135c
2 changed files with 35 additions and 14 deletions

View File

@ -11,6 +11,11 @@ namespace Vanara.Extensions
{
public static partial class VisualStylesRendererExtension
{
/// <summary>Retrieves the value of a <c>MARGINS</c> property.</summary>
/// <param name="rnd">The visual style to query.</param>
/// <param name="dc">A device context for any font selection. This value can be <see langword="null"/>.</param>
/// <param name="prop">The property to retrieve.</param>
/// <returns>The margins defined for the property.</returns>
public static Padding GetMargins2(this VisualStyleRenderer rnd, IDeviceContext dc = null, MarginProperty prop = MarginProperty.ContentMargins)
{
using (var hdc = new SafeDCHandle(dc))
@ -20,15 +25,23 @@ namespace Vanara.Extensions
}
}
/// <summary>Gets the duration of the specified transition.</summary>
/// <param name="rnd">The visual style to query.</param>
/// <param name="toState">State ID of the part after the transition.</param>
/// <param name="fromState">State ID of the part before the transition.</param>
/// <returns>The transition duration, in milliseconds.</returns>
public static uint GetTransitionDuration(this VisualStyleRenderer rnd, int toState, int fromState = 0)
{
GetThemeTransitionDuration(rnd.GetSafeHandle(), rnd.Part, fromState == 0 ? rnd.State : fromState, toState, (int)IntegerListProperty.TransitionDuration, out var dwDuration);
GetThemeTransitionDuration(rnd.GetSafeHandle(), rnd.Part, fromState == 0 ? rnd.State : fromState, toState, (int)ThemeProperty.TMT_TRANSITIONDURATIONS, out var dwDuration);
return dwDuration;
}
/// <summary>Gets the transition matrix for a visual style.</summary>
/// <param name="rnd">The visual style to query.</param>
/// <returns>A two dimensional array that represents the transition durations, in milliseconds, between any two parts.</returns>
public static int[,] GetTransitionMatrix(this VisualStyleRenderer rnd)
{
var res = GetThemeIntList(rnd.GetSafeHandle(), rnd.Part, rnd.State, (int)IntegerListProperty.TransitionDuration);
var res = GetThemeIntList(rnd.GetSafeHandle(), rnd.Part, rnd.State, (int)ThemeProperty.TMT_TRANSITIONDURATIONS);
if (res == null || res.Length == 0) return null;
var dim = res[0];
var ret = new int[dim, dim];
@ -38,7 +51,15 @@ namespace Vanara.Extensions
return ret;
}
public static bool IsPartDefined(this VisualStyleRenderer rnd, int part, int state) => IsThemePartDefined(rnd.GetSafeHandle(), part, state);
/// <summary>Determines whether a different part is defined for this visual theme.</summary>
/// <param name="rnd">The visual style to query.</param>
/// <param name="part">The part ID to consider.</param>
/// <returns><c>true</c> if the part is defined; otherwise, <c>false</c>.</returns>
public static bool IsPartDefined(this VisualStyleRenderer rnd, int part) => IsThemePartDefined(rnd.GetSafeHandle(), part, 0);
/// <summary>Prevents the application of visual styling for this specific window or control.</summary>
/// <param name="window">The window or control.</param>
public static void PreventVisualStyling(this IWin32Window window) => SetWindowTheme(window, " ", new[] { " " });
/// <summary>
/// Sets the state of the <see cref="VisualStyleRenderer"/>.
@ -47,9 +68,7 @@ namespace Vanara.Extensions
/// <param name="state">The state.</param>
public static void SetState(this VisualStyleRenderer rnd, int state) { rnd.SetParameters(rnd.Class, rnd.Part, state); }
/// <summary>
/// Sets the window theme.
/// </summary>
/// <summary>Sets the window theme.</summary>
/// <param name="win">The window on which to apply the theme.</param>
/// <param name="subAppName">Name of the sub application. This is the theme name (e.g. "Explorer").</param>
/// <param name="subIdList">The sub identifier list. This can be left <c>null</c>.</param>
@ -59,9 +78,7 @@ namespace Vanara.Extensions
try { UxTheme.SetWindowTheme(new HandleRef(win, win.Handle), subAppName, idl); } catch { }
}
/// <summary>
/// Sets attributes to control how visual styles are applied to a specified window.
/// </summary>
/// <summary>Sets attributes to control how visual styles are applied to a specified window.</summary>
/// <param name="window">The window.</param>
/// <param name="attr">The attributes to apply or disable.</param>
/// <param name="enable">if set to <c>true</c> enable the attribute, otherwise disable it.</param>

View File

@ -11,6 +11,10 @@ using static Vanara.PInvoke.UxTheme;
namespace Vanara.Extensions
{
/// <summary>
/// Extension methods for <see cref="VisualStyleRenderer"/> for glass effects and extended method functionality. Also provides GetFont2 and GetMargins2
/// methods that corrects base library's non-functioning methods.
/// </summary>
public static partial class VisualStylesRendererExtension
{
private static readonly Dictionary<long, Bitmap> bmpCache = new Dictionary<long, Bitmap>();
@ -25,7 +29,7 @@ namespace Vanara.Extensions
/// <param name="bounds">A <see cref="Rectangle"/> in which the background image is drawn.</param>
/// <param name="clipRectangle">A <see cref="Rectangle"/> that defines a clipping rectangle for the drawing operation.</param>
/// <param name="rightToLeft">If set to <c>true</c> flip the image for right to left layout.</param>
public static void DrawBackground(this VisualStyleRenderer rnd, Graphics dc, Rectangle bounds, Rectangle? clipRectangle = null, bool rightToLeft = false)
public static void DrawBackground(this VisualStyleRenderer rnd, IDeviceContext dc, Rectangle bounds, Rectangle? clipRectangle = null, bool rightToLeft = false)
{
/*var h = rnd.GetHashCode();
Bitmap bmp;
@ -82,14 +86,14 @@ namespace Vanara.Extensions
/// <param name="bounds">A <see cref="Rectangle"/> in which the image is drawn.</param>
/// <param name="imageList">An <see cref="ImageList"/> that contains the <see cref="Image"/> to draw.</param>
/// <param name="imageIndex">The index of the <see cref="Image"/> within <paramref name="imageList"/> to draw.</param>
public static void DrawGlassImage(this VisualStyleRenderer rnd, Graphics g, Rectangle bounds, ImageList imageList, int imageIndex)
public static void DrawGlassImage(this VisualStyleRenderer rnd, IDeviceContext g, Rectangle bounds, ImageList imageList, int imageIndex)
{
var ht = new SafeThemeHandle(rnd.Handle, false);
DrawWrapper(g, bounds,
memoryHdc =>
{
var rBounds = new RECT(bounds);
DrawThemeIcon(ht, memoryHdc, rnd.Part, rnd.State, ref rBounds, imageList.Handle, imageIndex);
DrawThemeIcon(ht, memoryHdc, rnd.Part, rnd.State, ref rBounds, new System.Runtime.InteropServices.HandleRef(imageList, imageList.Handle), imageIndex);
}
);
}
@ -102,7 +106,7 @@ namespace Vanara.Extensions
/// <param name="bounds">A <see cref="Rectangle" /> in which the image is drawn.</param>
/// <param name="image">An <see cref="ImageList" /> that contains the <see cref="Image" /> to draw.</param>
/// <param name="disabled">if set to <c>true</c> draws the image in a disabled state using the <see cref="ControlPaint.DrawImageDisabled"/> method.</param>
public static void DrawGlassImage(this VisualStyleRenderer rnd, Graphics g, Rectangle bounds, Image image, bool disabled = false)
public static void DrawGlassImage(this VisualStyleRenderer rnd, IDeviceContext g, Rectangle bounds, Image image, bool disabled = false)
{
DrawWrapper(g, bounds,
memoryHdc =>
@ -246,7 +250,7 @@ namespace Vanara.Extensions
using (var hdc = new SafeDCHandle(dc))
{
return 0 != GetThemeFont(new SafeThemeHandle(rnd.Handle, false), hdc, rnd.Part, rnd.State, 210, out LOGFONT f)
? defaultValue : f.ToFont();
? defaultValue : Font.FromLogFont(f);
}
}