diff --git a/Source/Krypton Components/Krypton.Toolkit/Values/CommandLinkImageValues.cs b/Source/Krypton Components/Krypton.Toolkit/Values/CommandLinkImageValues.cs index 1a843d531..6f1bdb533 100644 --- a/Source/Krypton Components/Krypton.Toolkit/Values/CommandLinkImageValues.cs +++ b/Source/Krypton Components/Krypton.Toolkit/Values/CommandLinkImageValues.cs @@ -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; + } + } + } + } /// Gets and sets the heading image transparent color. [Localizable(true)] @@ -60,7 +97,7 @@ public Color ImageTransparentColor [Category("Visuals")] [Description("The image.")] [RefreshProperties(RefreshProperties.All)] - public Image Image + public Image? Image { get => _image; set @@ -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 @@ -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 @@ -99,8 +157,10 @@ public CommandLinkImageValues(NeedPaintHandler needPaint) /// [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 @@ -118,6 +178,99 @@ public CommandLinkImageValues(NeedPaintHandler needPaint) /// public string GetLongText() => string.Empty; + /// Shows the uac shield. + /// if set to true [show uac shield]. + /// Size of the shield icon. + /// The width. + /// The height. + 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; + } + } + + /// Updates the UAC shield icon. + /// Size of the icon. + /// Size of the custom. + 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 } } \ No newline at end of file