Skip to content

Commit

Permalink
Update CommandLinkImageValues.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
PWagner1 committed Dec 2, 2023
1 parent ed4c828 commit 2bfc63c
Showing 1 changed file with 160 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,52 @@ public class CommandLinkImageValues : Storage, IContentValues

#region Instance Fields

private bool _displayUACShield;

private Color _transparencyKey;

private Image _image;
private Image? _image;

private UACShieldIconSize _uacShieldIconSize;

#endregion

#region Public

//public bool ShowUACShield { get; set; }
public bool DisplayUACShield
{
get => _displayUACShield;

set
{
if (_displayUACShield != value)
{
_displayUACShield = value;

switch (_uacShieldIconSize)
{
case UACShieldIconSize.ExtraSmall:
ShowUACShieldImage(value, UACShieldIconSize.ExtraSmall);
break;
case UACShieldIconSize.Small:
ShowUACShieldImage(value, UACShieldIconSize.Small);
break;
case UACShieldIconSize.Medium:
ShowUACShieldImage(value, UACShieldIconSize.Medium);
break;
case UACShieldIconSize.Large:
ShowUACShieldImage(value, UACShieldIconSize.Large);
break;
case UACShieldIconSize.ExtraLarge:
ShowUACShieldImage(value, UACShieldIconSize.ExtraLarge);
break;
default:
ShowUACShieldImage(value, UACShieldIconSize.ExtraSmall);
break;
}
}
}
}

/// <summary>Gets and sets the heading image transparent color.</summary>
[Localizable(true)]
Expand Down Expand Up @@ -60,7 +97,7 @@ public Color ImageTransparentColor
[Category("Visuals")]
[Description("The image.")]
[RefreshProperties(RefreshProperties.All)]
public Image Image
public Image? Image
{
get => _image;
set
Expand All @@ -78,6 +115,19 @@ public Image Image

public void ResetImage() => Image = DEFAULT_IMAGE;

[DefaultValue(UACShieldIconSize.ExtraSmall), Description(@"")]
public UACShieldIconSize UACShieldIconSize
{
get => _uacShieldIconSize;

set
{
_uacShieldIconSize = value;

ShowUACShieldImage(_displayUACShield, value);
}
}

#endregion

#region Identity
Expand All @@ -88,9 +138,17 @@ public CommandLinkImageValues(NeedPaintHandler needPaint)
{
NeedPaint = needPaint;

ResetImage();
_displayUACShield = false;

_uacShieldIconSize = UACShieldIconSize.Medium;

ResetImageTransparentColor();
_image = DEFAULT_IMAGE;

_transparencyKey = Color.Empty;

//ResetImage();

//ResetImageTransparentColor();
}

#endregion
Expand All @@ -99,8 +157,10 @@ public CommandLinkImageValues(NeedPaintHandler needPaint)

/// <inheritdoc />
[Browsable(false)]
public override bool IsDefault => ((Image == DEFAULT_IMAGE) &&
(ImageTransparentColor == Color.Empty));
public override bool IsDefault => (DisplayUACShield.Equals(false) &&
Image!.Equals(DEFAULT_IMAGE) &&
ImageTransparentColor.Equals(Color.Empty) &&
UACShieldIconSize.Equals(UACShieldIconSize.Medium));

#endregion

Expand All @@ -118,6 +178,99 @@ public CommandLinkImageValues(NeedPaintHandler needPaint)
/// <inheritdoc />
public string GetLongText() => string.Empty;

/// <summary>Shows the uac shield.</summary>
/// <param name="showUACShield">if set to <c>true</c> [show uac shield].</param>
/// <param name="shieldIconSize">Size of the shield icon.</param>
/// <param name="width">The width.</param>
/// <param name="height">The height.</param>
private void ShowUACShieldImage(bool showUACShield, UACShieldIconSize? shieldIconSize = null, int? width = null, int? height = null)
{
if (showUACShield)
{
int h = height ?? 16, w = width ?? 16;

Image shield = SystemIcons.Shield.ToBitmap();

switch (shieldIconSize)
{
//case UACShieldIconSize.Custom:
// Values.Image = GraphicsExtensions.ScaleImage(shield, w, h);
// break;
case UACShieldIconSize.ExtraSmall:
Image = GraphicsExtensions.ScaleImage(shield, 16, 16);
break;
case UACShieldIconSize.Small:
Image = GraphicsExtensions.ScaleImage(shield, 32, 32);
break;
case UACShieldIconSize.Medium:
Image = GraphicsExtensions.ScaleImage(shield, 64, 64);
break;
case UACShieldIconSize.Large:
Image = GraphicsExtensions.ScaleImage(shield, 128, 128);
break;
case UACShieldIconSize.ExtraLarge:
Image = GraphicsExtensions.ScaleImage(shield, 256, 256);
break;
case null:
Image = GraphicsExtensions.ScaleImage(shield, 16, 16);
break;
}

// Force a repaint
PerformNeedPaint(true);
}
else
{
Image = null;
}
}

/// <summary>Updates the UAC shield icon.</summary>
/// <param name="iconSize">Size of the icon.</param>
/// <param name="customSize">Size of the custom.</param>
private void UpdateOSUACShieldIcon(UACShieldIconSize? iconSize = null, Size? customSize = null)
{
//if (OSUtilities.IsWindowsEleven)
//{
// Image windowsElevenUacShieldImage = UACShieldIconResources.UACShieldWindows11;

// if (iconSize == UACShieldIconSize.Custom)
// {
// UpdateShieldSize(UACShieldIconSize.Custom, customSize, windowsElevenUacShieldImage);
// }
// else
// {
// UpdateShieldSize(iconSize, null, windowsElevenUacShieldImage);
// }
//}
//else if (OSUtilities.IsWindowsTen)
//{
// Image windowsTenUacShieldImage = UACShieldIconResources.UACShieldWindows10;

// if (iconSize == UACShieldIconSize.Custom)
// {
// UpdateShieldSize(UACShieldIconSize.Custom, customSize, windowsTenUacShieldImage);
// }
// else
// {
// UpdateShieldSize(iconSize, null, windowsTenUacShieldImage);
// }
//}
//else if (OSUtilities.IsWindowsEightPointOne || OSUtilities.IsWindowsEight || OSUtilities.IsWindowsSeven)
//{
// Image windowsEightUacShieldImage = UACShieldIconResources.UACShieldWindows7881;

// if (iconSize == UACShieldIconSize.Custom)
// {
// UpdateShieldSize(UACShieldIconSize.Custom, customSize, windowsEightUacShieldImage);
// }
// else
// {
// UpdateShieldSize(iconSize, null, windowsEightUacShieldImage);
// }
//}
}

#endregion
}
}

0 comments on commit 2bfc63c

Please sign in to comment.