Skip to content

Commit

Permalink
Merge pull request #895 from Krypton-Suite/alpha-fr#891
Browse files Browse the repository at this point in the history
* Resolves #891
  • Loading branch information
Smurf-IV authored Jan 15, 2023
2 parents e638170 + c610106 commit 73f44f8
Show file tree
Hide file tree
Showing 13 changed files with 249 additions and 40 deletions.
1 change: 1 addition & 0 deletions Documents/Help/Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
=======

## 2023-11-xx - Build 2311 - November 2023
* Resolved [#891](https://github.com/Krypton-Suite/Standard-Toolkit/issues/891), `LabelStyle` does not appear to have a default designer value
* Implemented [#887](https://github.com/Krypton-Suite/Standard-Toolkit/issues/887), A 'LinkLabel' version of the `KryptonWrapLabel`
* Fixed the display of the initial selected theme in the "ThemeSelection ComboBox"
* Resolved [#876](https://github.com/Krypton-Suite/Standard-Toolkit/issues/876), `Office 365 - Black` does not display text correctly
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ namespace Krypton.Toolkit
public class KryptonButton : VisualSimpleBase, IButtonControl, IContentValues
{
#region Instance Fields

private readonly ViewDrawButton _drawButton;
private ButtonStyle _style;
private readonly ButtonController _buttonController;
Expand All @@ -37,7 +38,14 @@ public class KryptonButton : VisualSimpleBase, IButtonControl, IContentValues
private readonly PaletteTripleOverride _overrideTracking;
private readonly PaletteTripleOverride _overridePressed;
private IKryptonCommand _command;
private bool _useAsDialogButton, _isDefault, _useMnemonic, _wasEnabled, _useAsUACElevationButton;
private bool _useAsDialogButton;
private bool _isDefault;
private bool _useMnemonic;
private bool _wasEnabled;
private bool _useAsUACElevationButton;
private Size _customUACShieldSize;
private UACShieldIconSize _uacShieldIconSize;

#endregion

#region Events
Expand Down Expand Up @@ -116,9 +124,13 @@ public KryptonButton()
ViewManager = new ViewManager(this, _drawButton);

_useAsDialogButton = false;

_useAsUACElevationButton = false;

_customUACShieldSize = new Size(16, 16);

_uacShieldIconSize = UACShieldIconSize.ExtraSmall;

// Set `CornerRoundingRadius' to 'GlobalStaticValues.PRIMARY_CORNER_ROUNDING_VALUE' (-1)
CornerRoundingRadius = GlobalStaticValues.PRIMARY_CORNER_ROUNDING_VALUE;
}
Expand Down Expand Up @@ -237,26 +249,32 @@ private void ResetButtonStyle()
ButtonStyle = ButtonStyle.Standalone;
}

[DefaultValue(false),
[DefaultValue(false),
Description(@"If set to true, the text will pair up with the equivalent KryptonManager's dialog button text result. (Note: You'll lose any previous text)")]
public bool UseAsADialogButton
{
get => _useAsDialogButton;
set => _useAsDialogButton = value;
public bool UseAsADialogButton
{
get => _useAsDialogButton;
set => _useAsDialogButton = value;
}

[DefaultValue(false),
[DefaultValue(false),
Description(@"Transforms the button into a UAC elevated button.")]
public bool UseAsUACElevationButton
{
get => _useAsUACElevationButton;
set
{
_useAsUACElevationButton = value;
ShowUACShield(value);
}
public bool UseAsUACElevationButton
{
get => _useAsUACElevationButton;
set
{
_useAsUACElevationButton = value;
ShowUACShield(value);
}
}

[DefaultValue(null), Description(@"")]
public Size CustomUACShieldSize { get => _customUACShieldSize; set { _customUACShieldSize = value; UpdateShieldCustomSize(value); } }

[DefaultValue(typeof(UACShieldIconSize), @"UACShieldIconSize.ExtraSmall"), Description(@"")]
public UACShieldIconSize UACShieldIconSize { get => _uacShieldIconSize; set { _uacShieldIconSize = value; UpdateShieldSize(value); } }

/// <summary>
/// Gets access to the button content.
/// </summary>
Expand All @@ -267,6 +285,11 @@ public bool UseAsUACElevationButton

private bool ShouldSerializeValues() => !Values.IsDefault;

//[Category(@"Visuals"), Description(@"UAC Shield Values"), DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
//public UACShieldValues UACShieldValues { get; }

//private bool ShouldSerializeUACShieldValues() => !UACShieldValues.IsDefault;

/// <summary>
/// Gets access to the common button appearance that other states can override.
/// </summary>
Expand Down Expand Up @@ -580,7 +603,7 @@ protected override void OnClick(EventArgs e)
{
owner.DialogResult = DialogResult;
}
catch (InvalidEnumArgumentException )
catch (InvalidEnumArgumentException)
{
// Is it https://github.com/Krypton-Suite/Standard-Toolkit/issues/728
if (owner is KryptonMessageBoxForm)
Expand Down Expand Up @@ -710,7 +733,7 @@ protected virtual void SetStyles(ButtonStyle buttonStyle)
/// </summary>
/// <returns>Set of button values.</returns>
/// <param name="needPaint">Delegate for notifying paint requests.</param>
protected virtual ButtonValues CreateButtonValues(NeedPaintHandler needPaint) => new (needPaint);
protected virtual ButtonValues CreateButtonValues(NeedPaintHandler needPaint) => new(needPaint);

/// <summary>
/// Raises the KryptonCommandChanged event.
Expand Down Expand Up @@ -794,6 +817,34 @@ private void ShowUACShield(bool showUACShield)
Values.Image = null;
}
}

private void UpdateShieldCustomSize(Size value) => UpdateShieldSize(UACShieldIconSize.Custom, value);

private void UpdateShieldSize(UACShieldIconSize value, Size? customSize = null)
{
switch (value)
{
case UACShieldIconSize.Custom:
Values.Image = GraphicsExtensions.ScaleImage(Values.Image, customSize);
break;
case UACShieldIconSize.ExtraSmall:
Values.Image = GraphicsExtensions.ScaleImage(Values.Image, new Size(16, 16));
break;
case UACShieldIconSize.Small:
Values.Image = GraphicsExtensions.ScaleImage(Values.Image, new Size(32, 32));
break;
case UACShieldIconSize.Medium:
Values.Image = GraphicsExtensions.ScaleImage(Values.Image, new Size(64, 64));
break;
case UACShieldIconSize.Large:
Values.Image = GraphicsExtensions.ScaleImage(Values.Image, new Size(128, 128));
break;
case UACShieldIconSize.ExtraLarge:
Values.Image = GraphicsExtensions.ScaleImage(Values.Image, new Size(255, 255));
break;
}
}

#endregion
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ public KryptonForm()

// Create the view manager instance
ViewManager = new ViewManager(this, _drawDocker);

// Set the CornerRoundingRadius to 'GlobalStaticValues.PRIMARY_CORNER_ROUNDING_VALUE', default value
CornerRoundingRadius = GlobalStaticValues.PRIMARY_CORNER_ROUNDING_VALUE;

Expand Down Expand Up @@ -1616,7 +1616,7 @@ private void OnShowToolTip(object sender, ToolTipEventArgs e)
PaletteBackStyle.ControlToolTip,
PaletteBorderStyle.ControlToolTip,
CommonHelper.ContentStyleFromLabelStyle(toolTipStyle),
shadow);
shadow);

_visualPopupToolTip.Disposed += OnVisualPopupToolTipDisposed;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ private void ResetOrientation()
/// </summary>
[Category(@"Visuals")]
[Description(@"Label style.")]
[DefaultValue(typeof(LabelStyle), "NormalPanel")]
[DefaultValue(typeof(LabelStyle), "LabelStyle.NormalPanel")]
public LabelStyle LabelStyle
{
get => _style;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ public override bool AutoSize
/// </summary>
[Category(@"Visuals")]
[Description(@"Label style.")]
[DefaultValue(typeof(LabelStyle), "NormalPanel")]
[DefaultValue(typeof(LabelStyle), "LabelStyle.NormalPanel")]
public LabelStyle LabelStyle
{
get => _labelStyle;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ public override bool AutoSize
/// </summary>
[Category(@"Visuals")]
[Description(@"Label style.")]
[DefaultValue(typeof(LabelStyle), "NormalPanel")]
[DefaultValue(typeof(LabelStyle), "LabelStyle.NormalPanel")]
public LabelStyle LabelStyle
{
get => _labelStyle;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,13 @@ public static Icon LoadIcon(IconType type, Size size)
/// <param name="sourceImage">The image to resize.</param>
/// <param name="imageSize">The size that you want to resize the image to.</param>
/// <returns>The resized image.</returns>
public static Bitmap ScaleImage(Image sourceImage, Size imageSize)
public static Bitmap ScaleImage(Image sourceImage, Size? imageSize)
{
var destRect = new Rectangle(0, 0, imageSize.Width, imageSize.Height);
Size tmpSize = imageSize ?? new Size(16, 16);

var destImage = new Bitmap(imageSize.Width, imageSize.Height);
var destRect = new Rectangle(0, 0, tmpSize.Width, tmpSize.Height);

var destImage = new Bitmap(tmpSize.Width, tmpSize.Height);

destImage.SetResolution(sourceImage.HorizontalResolution, sourceImage.VerticalResolution);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#region BSD License
/*
*
* New BSD 3-Clause License (https://github.com/Krypton-Suite/Standard-Toolkit/blob/master/LICENSE)
* Modifications by Peter Wagner(aka Wagnerp) & Simon Coghlan(aka Smurf-IV), et al. 2017 - 2023. All rights reserved.
*
*/
#endregion

namespace Krypton.Toolkit
{
/// <summary>Defines the UAC shield image size for a <see cref="KryptonButton"/>.</summary>
public enum UACShieldIconSize
{
/// <summary>A custom image size.</summary>
Custom = 0,
/// <summary>The extra small image size (16 x 16).</summary>
ExtraSmall = 1,
/// <summary>The small image size (32 x 32).</summary>
Small = 2,
/// <summary>The medium image size (64 x 64).</summary>
Medium = 3,
/// <summary>The large image size (128 x 128).</summary>
Large = 4,
/// <summary>The extra large image size (256 x 256).</summary>
ExtraLarge = 5
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ public void ResetExtraText()
/// Create the storage for the image states.
/// </summary>
/// <returns>Storage object.</returns>
protected virtual ButtonImageStates CreateImageStates() => new ();
protected virtual ButtonImageStates CreateImageStates() => new();

#endregion

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ namespace Krypton.Toolkit
public class ShadowValues : Storage
{
#region statics
private static readonly Point _defaultOffset = new(5,5);
private static readonly Point _defaultOffset = new(5, 5);
private double _blurDistance;
private bool _enableShadows;
private Point _offset;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#region BSD License
/*
*
* New BSD 3-Clause License (https://github.com/Krypton-Suite/Standard-Toolkit/blob/master/LICENSE)
* Modifications by Peter Wagner(aka Wagnerp) & Simon Coghlan(aka Smurf-IV), et al. 2017 - 2023. All rights reserved.
*
*/
#endregion

namespace Krypton.Toolkit
{
public class UACShieldValues : ButtonValues
{
#region Instance Fields

private bool _useAsUACShieldButton;

private bool _useOSStyleImage;

private UACShieldIconSize _iconSize;

private Size _customImageSize;

#endregion

public override bool IsDefault =>
(UseAsUACShieldButton == false) &&
(UseOSStyleImage == false) &&
(ShieldIconSize == UACShieldIconSize.ExtraSmall) &&
(CustomImageSize == null);

#region Identity

public UACShieldValues(NeedPaintHandler needPaint) : base(needPaint)
{
}

#endregion

#region Public

public bool UseAsUACShieldButton { get => _useAsUACShieldButton; set => _useAsUACShieldButton = value; }

public bool UseOSStyleImage { get => _useOSStyleImage; set => _useOSStyleImage = value; }

public UACShieldIconSize ShieldIconSize { get => _iconSize; set => _iconSize = value; }

public Size CustomImageSize { get => _customImageSize; set => _customImageSize = value; }

#endregion
}
}
Loading

0 comments on commit 73f44f8

Please sign in to comment.