From 0ce5d7452cb9273ab9e82f53c472631759974abe Mon Sep 17 00:00:00 2001 From: Simon Coghlan Date: Mon, 16 Dec 2024 14:22:16 +0000 Subject: [PATCH 1/2] - Use `DeviceDpi` to scale images - And Some Warnings #565 #559 --- Documents/Help/Changelog.md | 2 ++ .../ButtonSpecs/ButtonSpecNavFixed.cs | 2 +- .../ButtonSpecs/ButtonSpecNavRemap.cs | 2 +- .../Controller/DragViewController.cs | 2 +- .../Dragging/DragFeedback.cs | 2 +- .../General/PageToToolTipMapping.cs | 2 +- .../Palette/HeaderGroupMappingBase.cs | 8 +++-- .../Palette/HeaderGroupMappingPrimary.cs | 7 +++-- .../Palette/HeaderGroupMappingSecondary.cs | 7 +++-- .../Krypton.Navigator/Palette/NavigatorBar.cs | 2 +- .../Palette/NavigatorHeader.cs | 12 ++++++-- .../Group Contents/KryptonRibbonGroupItem.cs | 13 +++++++-- .../View Layout/ViewLayoutRibbonTabsArea.cs | 11 ++++++- .../ContextMenu/KryptonContextMenuItemBase.cs | 10 ++++++- .../Controls Toolkit/KryptonForm.cs | 9 +++++- .../Controls Toolkit/KryptonGroupBox.cs | 11 +++++-- .../Controls Toolkit/KryptonHeader.cs | 7 ++++- .../Controls Toolkit/KryptonHeaderGroup.cs | 11 +++++-- .../Controls Visuals/VisualControlBase.cs | 7 ++++- .../Krypton.Toolkit/Values/CaptionValues.cs | 6 ++-- .../Values/HeaderGroupValuesPrimary.cs | 6 ++-- .../Values/HeaderGroupValuesSecondary.cs | 6 ++-- .../Krypton.Toolkit/Values/HeaderValues.cs | 6 ++-- .../Values/HeaderValuesBase.cs | 29 +++++++++++++++---- .../Krypton.Toolkit/Values/ToolTipValues.cs | 5 ++-- .../View Layout/ViewLayoutMonths.cs | 9 +++++- 26 files changed, 151 insertions(+), 43 deletions(-) diff --git a/Documents/Help/Changelog.md b/Documents/Help/Changelog.md index e291fb7de..320140078 100644 --- a/Documents/Help/Changelog.md +++ b/Documents/Help/Changelog.md @@ -3,6 +3,8 @@ ======= # 2025-02-01 - Build 2502 (Patch 5) - February 2025 +* Resolved [#565](https://github.com/Krypton-Suite/Standard-Toolkit/issues/565), GroupBox icons are not scaled for dpi awareness +* Resolved [#559](https://github.com/Krypton-Suite/Standard-Toolkit/issues/559), Header group icon is not scaled for dpi awareness * Resolved [#1946](https://github.com/Krypton-Suite/Standard-Toolkit/issues/1946), ButtonSpecs do not scale anymore! * Resolved [#1890](https://github.com/Krypton-Suite/Standard-Toolkit/issues/1890), V85 codebase: Exception thrown for colouring a ribbon * Resolved [#1905](https://github.com/Krypton-Suite/Standard-Toolkit/issues/1905), `Sparkle` Themes have an issue with the Background diff --git a/Source/Krypton Components/Krypton.Navigator/ButtonSpecs/ButtonSpecNavFixed.cs b/Source/Krypton Components/Krypton.Navigator/ButtonSpecs/ButtonSpecNavFixed.cs index 9895250a4..7a4d81dda 100644 --- a/Source/Krypton Components/Krypton.Navigator/ButtonSpecs/ButtonSpecNavFixed.cs +++ b/Source/Krypton Components/Krypton.Navigator/ButtonSpecs/ButtonSpecNavFixed.cs @@ -35,7 +35,7 @@ protected ButtonSpecNavFixed([DisallowNull] KryptonNavigator navigator, Debug.Assert(navigator != null); // Remember back reference to owning navigator. - Navigator = navigator; + Navigator = navigator!; // Fix the type ProtectedType = fixedStyle; diff --git a/Source/Krypton Components/Krypton.Navigator/ButtonSpecs/ButtonSpecNavRemap.cs b/Source/Krypton Components/Krypton.Navigator/ButtonSpecs/ButtonSpecNavRemap.cs index f06ed1843..a087ce971 100644 --- a/Source/Krypton Components/Krypton.Navigator/ButtonSpecs/ButtonSpecNavRemap.cs +++ b/Source/Krypton Components/Krypton.Navigator/ButtonSpecs/ButtonSpecNavRemap.cs @@ -134,7 +134,7 @@ public ButtonSpecNavRemap(PaletteBase? target, { Debug.Assert(buttonSpec != null); - _buttonSpec = buttonSpec; + _buttonSpec = buttonSpec!; _remapTarget = remapTarget; } #endregion diff --git a/Source/Krypton Components/Krypton.Navigator/Controller/DragViewController.cs b/Source/Krypton Components/Krypton.Navigator/Controller/DragViewController.cs index 0b610fca9..656d78ae7 100644 --- a/Source/Krypton Components/Krypton.Navigator/Controller/DragViewController.cs +++ b/Source/Krypton Components/Krypton.Navigator/Controller/DragViewController.cs @@ -77,7 +77,7 @@ public DragViewController([DisallowNull] ViewBase target) MousePoint = CommonHelper.NullPoint; AllowDragging = true; _dragging = false; - Target = target; + Target = target!; _lastClick = DateTime.Now.AddDays(-1); } #endregion diff --git a/Source/Krypton Components/Krypton.Navigator/Dragging/DragFeedback.cs b/Source/Krypton Components/Krypton.Navigator/Dragging/DragFeedback.cs index f95992647..f110591be 100644 --- a/Source/Krypton Components/Krypton.Navigator/Dragging/DragFeedback.cs +++ b/Source/Krypton Components/Krypton.Navigator/Dragging/DragFeedback.cs @@ -87,7 +87,7 @@ public virtual void Start([DisallowNull] IPaletteDragDrop paletteDragDrop, Debug.Assert(pageDragEndData != null); Debug.Assert(dragTargets != null); - PaletteDragDrop = paletteDragDrop; + PaletteDragDrop = paletteDragDrop!; Renderer = renderer; PageDragEndData = pageDragEndData; DragTargets = dragTargets; diff --git a/Source/Krypton Components/Krypton.Navigator/General/PageToToolTipMapping.cs b/Source/Krypton Components/Krypton.Navigator/General/PageToToolTipMapping.cs index d8452e07f..cba50d6bd 100644 --- a/Source/Krypton Components/Krypton.Navigator/General/PageToToolTipMapping.cs +++ b/Source/Krypton Components/Krypton.Navigator/General/PageToToolTipMapping.cs @@ -39,7 +39,7 @@ public PageToToolTipMapping([DisallowNull] KryptonPage page, { Debug.Assert(page != null); - _page = page; + _page = page!; _mapImage = mapImage; _mapText = mapText; _mapExtraText = mapExtraText; diff --git a/Source/Krypton Components/Krypton.Navigator/Palette/HeaderGroupMappingBase.cs b/Source/Krypton Components/Krypton.Navigator/Palette/HeaderGroupMappingBase.cs index 62525080d..97d3f1840 100644 --- a/Source/Krypton Components/Krypton.Navigator/Palette/HeaderGroupMappingBase.cs +++ b/Source/Krypton Components/Krypton.Navigator/Palette/HeaderGroupMappingBase.cs @@ -26,17 +26,18 @@ public abstract class HeaderGroupMappingBase : HeaderValuesBase #endregion #region Identity + /// /// Initialize a new instance of the HeaderGroupMappingBase class. /// /// Reference to owning navigator instance. /// Delegate for notifying paint requests. + /// protected HeaderGroupMappingBase([DisallowNull] KryptonNavigator navigator, - NeedPaintHandler needPaint) - : base(needPaint) + NeedPaintHandler needPaint, GetDpiFactor getDpiFactor) + : base(needPaint, getDpiFactor) { Debug.Assert(navigator != null); - // Remember back reference to owning control _navigator = navigator; @@ -45,6 +46,7 @@ protected HeaderGroupMappingBase([DisallowNull] KryptonNavigator navigator, _mapHeading = GetMapHeadingDefault(); _mapDescription = GetMapDescriptionDefault(); } + #endregion #region Default Values diff --git a/Source/Krypton Components/Krypton.Navigator/Palette/HeaderGroupMappingPrimary.cs b/Source/Krypton Components/Krypton.Navigator/Palette/HeaderGroupMappingPrimary.cs index 3b870075b..b8c81f70e 100644 --- a/Source/Krypton Components/Krypton.Navigator/Palette/HeaderGroupMappingPrimary.cs +++ b/Source/Krypton Components/Krypton.Navigator/Palette/HeaderGroupMappingPrimary.cs @@ -22,14 +22,17 @@ public class HeaderGroupMappingPrimary : HeaderGroupMappingBase #endregion #region Identity + /// /// Initialize a new instance of the HeaderGroupMappingPrimary class. /// /// Reference to owning navigator instance. /// Delegate for notifying paint requests. + /// public HeaderGroupMappingPrimary(KryptonNavigator navigator, - NeedPaintHandler needPaint) - : base(navigator, needPaint) + NeedPaintHandler needPaint, + GetDpiFactor getDpiFactor) + : base(navigator, needPaint, getDpiFactor) { } #endregion diff --git a/Source/Krypton Components/Krypton.Navigator/Palette/HeaderGroupMappingSecondary.cs b/Source/Krypton Components/Krypton.Navigator/Palette/HeaderGroupMappingSecondary.cs index 053576874..d754600e4 100644 --- a/Source/Krypton Components/Krypton.Navigator/Palette/HeaderGroupMappingSecondary.cs +++ b/Source/Krypton Components/Krypton.Navigator/Palette/HeaderGroupMappingSecondary.cs @@ -22,14 +22,17 @@ public class HeaderGroupMappingSecondary : HeaderGroupMappingBase #endregion #region Identity + /// /// Initialize a new instance of the HeaderGroupMappingSecondary class. /// /// Reference to owning navigator instance. /// Delegate for notifying paint requests. + /// public HeaderGroupMappingSecondary(KryptonNavigator navigator, - NeedPaintHandler needPaint) - : base(navigator, needPaint) + NeedPaintHandler needPaint, + GetDpiFactor getDpiFactor) + : base(navigator, needPaint, getDpiFactor) { } #endregion diff --git a/Source/Krypton Components/Krypton.Navigator/Palette/NavigatorBar.cs b/Source/Krypton Components/Krypton.Navigator/Palette/NavigatorBar.cs index 11bc2fd27..66f83a93b 100644 --- a/Source/Krypton Components/Krypton.Navigator/Palette/NavigatorBar.cs +++ b/Source/Krypton Components/Krypton.Navigator/Palette/NavigatorBar.cs @@ -59,7 +59,7 @@ public NavigatorBar([DisallowNull] KryptonNavigator navigator, Debug.Assert(navigator != null); // Remember back reference - _navigator = navigator; + _navigator = navigator!; // Store the provided paint notification delegate NeedPaint = needPaint; diff --git a/Source/Krypton Components/Krypton.Navigator/Palette/NavigatorHeader.cs b/Source/Krypton Components/Krypton.Navigator/Palette/NavigatorHeader.cs index 8e9498347..caeae7080 100644 --- a/Source/Krypton Components/Krypton.Navigator/Palette/NavigatorHeader.cs +++ b/Source/Krypton Components/Krypton.Navigator/Palette/NavigatorHeader.cs @@ -11,6 +11,8 @@ #endregion // ReSharper disable VirtualMemberCallInConstructor +using static Krypton.Toolkit.HeaderValuesBase; + namespace Krypton.Navigator { /// @@ -59,9 +61,15 @@ public NavigatorHeader([DisallowNull] KryptonNavigator navigator, _headerVisiblePrimary = true; _headerVisibleSecondary = true; _headerVisibleBar = true; - HeaderValuesPrimary = new HeaderGroupMappingPrimary(_navigator, needPaint); - HeaderValuesSecondary = new HeaderGroupMappingSecondary(_navigator, needPaint); + HeaderValuesPrimary = new HeaderGroupMappingPrimary(_navigator, needPaint, GetDpiFactor); + HeaderValuesSecondary = new HeaderGroupMappingSecondary(_navigator, needPaint, GetDpiFactor); } + + private float GetDpiFactor() + { + return _navigator.DeviceDpi / 96F; + } + #endregion #region IsDefault diff --git a/Source/Krypton Components/Krypton.Ribbon/Group Contents/KryptonRibbonGroupItem.cs b/Source/Krypton Components/Krypton.Ribbon/Group Contents/KryptonRibbonGroupItem.cs index 5e75d99fe..0d154973a 100644 --- a/Source/Krypton Components/Krypton.Ribbon/Group Contents/KryptonRibbonGroupItem.cs +++ b/Source/Krypton Components/Krypton.Ribbon/Group Contents/KryptonRibbonGroupItem.cs @@ -12,6 +12,8 @@ */ #endregion +using static Krypton.Toolkit.HeaderValuesBase; + namespace Krypton.Ribbon { /// @@ -40,8 +42,15 @@ public abstract class KryptonRibbonGroupItem : Component, /// Initialise a new instance of the KryptonRibbonGroupItem class. /// protected KryptonRibbonGroupItem() => - // Do the Tooltip Magic - _toolTipValues = new ToolTipValues(null/*NeedPaintDelegate*/); // Must be replaced by appropriate call + // Do the Tooltip Magic + _toolTipValues = new ToolTipValues(null/*NeedPaintDelegate*/, GetDpiFactor); // Must be replaced by appropriate call + + private float GetDpiFactor() + { + return (Ribbon != null) + ? Ribbon.DeviceDpi / 96F + : 1.0f; + } #endregion Identity diff --git a/Source/Krypton Components/Krypton.Ribbon/View Layout/ViewLayoutRibbonTabsArea.cs b/Source/Krypton Components/Krypton.Ribbon/View Layout/ViewLayoutRibbonTabsArea.cs index 963dffebb..b188a3c15 100644 --- a/Source/Krypton Components/Krypton.Ribbon/View Layout/ViewLayoutRibbonTabsArea.cs +++ b/Source/Krypton Components/Krypton.Ribbon/View Layout/ViewLayoutRibbonTabsArea.cs @@ -12,6 +12,8 @@ */ #endregion +using static Krypton.Toolkit.HeaderValuesBase; + namespace Krypton.Ribbon { /// @@ -537,12 +539,19 @@ private void CreateViewElements(PaletteRedirect? redirect) NeedPaintDelegate); // Create the manager for handling tooltips - ToolTipManager = new ToolTipManager(new ToolTipValues(null)); // use default, as each button "could" have different values ??!!?? + ToolTipManager = new ToolTipManager(new ToolTipValues(null, GetDpiFactor)); // use default, as each button "could" have different values ??!!?? ToolTipManager.ShowToolTip += OnShowToolTip; ToolTipManager.CancelToolTip += OnCancelToolTip; ButtonSpecManager.ToolTipManager = ToolTipManager; } + private float GetDpiFactor() + { + return (_visualPopupToolTip != null) + ? _visualPopupToolTip.DeviceDpi / 96F + : 1F; + } + private void SetupParentMonitoring() { // We have to know when the parent of the ribbon changes so we can then hook diff --git a/Source/Krypton Components/Krypton.Toolkit/ContextMenu/KryptonContextMenuItemBase.cs b/Source/Krypton Components/Krypton.Toolkit/ContextMenu/KryptonContextMenuItemBase.cs index 1b9675bab..c7d88ef60 100644 --- a/Source/Krypton Components/Krypton.Toolkit/ContextMenu/KryptonContextMenuItemBase.cs +++ b/Source/Krypton Components/Krypton.Toolkit/ContextMenu/KryptonContextMenuItemBase.cs @@ -21,7 +21,7 @@ public abstract class KryptonContextMenuItemBase : Component, INotifyPropertyCha #region Instance Fields private bool _visible; - private ToolTipValues _toolTipValues = new ToolTipValues(null); + private ToolTipValues _toolTipValues; private VisualPopupToolTip? _visualPopupToolTip; private IContextMenuProvider _provider; #endregion @@ -49,11 +49,19 @@ public abstract class KryptonContextMenuItemBase : Component, INotifyPropertyCha protected KryptonContextMenuItemBase() { _visible = true; + _toolTipValues = new ToolTipValues(null, GetDpiFactor); ToolTipManager = new ToolTipManager(_toolTipValues); ToolTipManager.ShowToolTip += OnShowToolTip; ToolTipManager.CancelToolTip += OnCancelToolTip; } + private float GetDpiFactor() + { + return (_visualPopupToolTip != null) + ? _visualPopupToolTip.DeviceDpi / 96F + : 1F; + } + #endregion #region Public diff --git a/Source/Krypton Components/Krypton.Toolkit/Controls Toolkit/KryptonForm.cs b/Source/Krypton Components/Krypton.Toolkit/Controls Toolkit/KryptonForm.cs index bcca89211..eb8b56e69 100644 --- a/Source/Krypton Components/Krypton.Toolkit/Controls Toolkit/KryptonForm.cs +++ b/Source/Krypton Components/Krypton.Toolkit/Controls Toolkit/KryptonForm.cs @@ -178,7 +178,7 @@ public KryptonForm() OnButtonManagerNeedPaint!); // Create the manager for handling tooltips - ToolTipManager = new ToolTipManager(new ToolTipValues(null)); // use default, as each button "could" have different values ??!!?? + ToolTipManager = new ToolTipManager(new ToolTipValues(null, GetDpiFactor)); // use default, as each button "could" have different values ??!!?? ToolTipManager.ShowToolTip += OnShowToolTip; ToolTipManager.CancelToolTip += OnCancelToolTip; _buttonManager.ToolTipManager = ToolTipManager; @@ -201,6 +201,13 @@ public KryptonForm() #pragma warning restore CS0618 } + private float GetDpiFactor() + { + return (_visualPopupToolTip != null) + ? _visualPopupToolTip.DeviceDpi / 96F + : 1F; + } + /// /// Releases all resources used by the Control. /// diff --git a/Source/Krypton Components/Krypton.Toolkit/Controls Toolkit/KryptonGroupBox.cs b/Source/Krypton Components/Krypton.Toolkit/Controls Toolkit/KryptonGroupBox.cs index 7878c5c2d..ad3f7e70f 100644 --- a/Source/Krypton Components/Krypton.Toolkit/Controls Toolkit/KryptonGroupBox.cs +++ b/Source/Krypton Components/Krypton.Toolkit/Controls Toolkit/KryptonGroupBox.cs @@ -56,7 +56,7 @@ public KryptonGroupBox() _captionVisible = true; // Create storage objects - Values = new CaptionValues(NeedPaintDelegate); + Values = new CaptionValues(NeedPaintDelegate, GetDpiFactor); Values.TextChanged += OnValuesTextChanged; // Create the palette storage @@ -67,11 +67,9 @@ public KryptonGroupBox() // Create the internal panel used for containing content Panel = new KryptonGroupBoxPanel(this, StateCommon, StateDisabled, StateNormal, OnGroupPanelPaint!) { - // Make sure the panel back style always mimics our back style PanelBackStyle = PaletteBackStyle.ControlGroupBox }; - _drawContent = new ViewDrawContent(StateNormal.Content, Values, VisualOrientation.Top); // Create view for the control border and background @@ -108,6 +106,13 @@ public KryptonGroupBox() _cornerRoundingRadius = GlobalStaticValues.PRIMARY_CORNER_ROUNDING_VALUE; } + private float GetDpiFactor() + { + return (Panel != null) + ? Panel.DeviceDpi / 96F + : 1f; + } + /// /// Clean up any resources being used. /// diff --git a/Source/Krypton Components/Krypton.Toolkit/Controls Toolkit/KryptonHeader.cs b/Source/Krypton Components/Krypton.Toolkit/Controls Toolkit/KryptonHeader.cs index fb0b983ba..28c28c1cb 100644 --- a/Source/Krypton Components/Krypton.Toolkit/Controls Toolkit/KryptonHeader.cs +++ b/Source/Krypton Components/Krypton.Toolkit/Controls Toolkit/KryptonHeader.cs @@ -71,7 +71,7 @@ public KryptonHeader() AllowButtonSpecToolTipPriority = false; // Create storage objects - Values = new HeaderValues(NeedPaintDelegate); + Values = new HeaderValues(NeedPaintDelegate, GetDpiFactor); Values.TextChanged += OnHeaderTextChanged; ButtonSpecs = new HeaderButtonSpecCollection(this); @@ -110,6 +110,11 @@ public KryptonHeader() _cornerRoundingRadius = GlobalStaticValues.PRIMARY_CORNER_ROUNDING_VALUE; } + private float GetDpiFactor() + { + return DeviceDpi / 96F; + } + /// /// Clean up any resources being used. /// diff --git a/Source/Krypton Components/Krypton.Toolkit/Controls Toolkit/KryptonHeaderGroup.cs b/Source/Krypton Components/Krypton.Toolkit/Controls Toolkit/KryptonHeaderGroup.cs index fe5634f1c..b6a21e05f 100644 --- a/Source/Krypton Components/Krypton.Toolkit/Controls Toolkit/KryptonHeaderGroup.cs +++ b/Source/Krypton Components/Krypton.Toolkit/Controls Toolkit/KryptonHeaderGroup.cs @@ -102,9 +102,9 @@ public KryptonHeaderGroup() _visibleSecondary = true; // Create storage objects - ValuesPrimary = new HeaderGroupValuesPrimary(NeedPaintDelegate); + ValuesPrimary = new HeaderGroupValuesPrimary(NeedPaintDelegate, GetDpiFactor); ValuesPrimary.TextChanged += OnHeaderGroupTextChanged; - ValuesSecondary = new HeaderGroupValuesSecondary(NeedPaintDelegate); + ValuesSecondary = new HeaderGroupValuesSecondary(NeedPaintDelegate, GetDpiFactor); ButtonSpecs = new HeaderGroupButtonSpecCollection(this); // We need to monitor button spec click events @@ -208,6 +208,13 @@ public KryptonHeaderGroup() _headerSecondaryCornerRoundingRadius = GlobalStaticValues.SECONDARY_CORNER_ROUNDING_VALUE; } + private float GetDpiFactor() + { + return (Panel != null) + ? Panel.DeviceDpi / 96F + : 1f; + } + /// /// Clean up any resources being used. /// diff --git a/Source/Krypton Components/Krypton.Toolkit/Controls Visuals/VisualControlBase.cs b/Source/Krypton Components/Krypton.Toolkit/Controls Visuals/VisualControlBase.cs index a765e4d93..7aa6a2e1d 100644 --- a/Source/Krypton Components/Krypton.Toolkit/Controls Visuals/VisualControlBase.cs +++ b/Source/Krypton Components/Krypton.Toolkit/Controls Visuals/VisualControlBase.cs @@ -118,7 +118,7 @@ protected VisualControlBase() AttachGlobalEvents(); // Do the Tooltip Magic - ToolTipValues = new ToolTipValues(NeedPaintDelegate); + ToolTipValues = new ToolTipValues(NeedPaintDelegate, GetDpiFactor); // Create the manager for handling tooltips // ReSharper disable once UseObjectOrCollectionInitializer _toolTipManager = new ToolTipManager(ToolTipValues); @@ -126,6 +126,11 @@ protected VisualControlBase() _toolTipManager.CancelToolTip += OnCancelToolTip; } + private float GetDpiFactor() + { + return DeviceDpi / 96F; + } + /// /// Clean up any resources being used. /// diff --git a/Source/Krypton Components/Krypton.Toolkit/Values/CaptionValues.cs b/Source/Krypton Components/Krypton.Toolkit/Values/CaptionValues.cs index 5f1fa05b0..4deac329b 100644 --- a/Source/Krypton Components/Krypton.Toolkit/Values/CaptionValues.cs +++ b/Source/Krypton Components/Krypton.Toolkit/Values/CaptionValues.cs @@ -22,12 +22,14 @@ public class CaptionValues : HeaderValuesBase #endregion #region Identity + /// /// Initialize a new instance of the CaptionValues class. /// /// Delegate for notifying paint requests. - public CaptionValues(NeedPaintHandler needPaint) - : base(needPaint) + /// + public CaptionValues(NeedPaintHandler needPaint, GetDpiFactor getDpiFactor) + : base(needPaint, getDpiFactor) { } #endregion diff --git a/Source/Krypton Components/Krypton.Toolkit/Values/HeaderGroupValuesPrimary.cs b/Source/Krypton Components/Krypton.Toolkit/Values/HeaderGroupValuesPrimary.cs index f93bb77c7..e2ce78dea 100644 --- a/Source/Krypton Components/Krypton.Toolkit/Values/HeaderGroupValuesPrimary.cs +++ b/Source/Krypton Components/Krypton.Toolkit/Values/HeaderGroupValuesPrimary.cs @@ -22,12 +22,14 @@ public class HeaderGroupValuesPrimary : HeaderValuesBase #endregion #region Identity + /// /// Initialize a new instance of the HeaderGroupValuesPrimary class. /// /// Delegate for notifying paint requests. - public HeaderGroupValuesPrimary(NeedPaintHandler needPaint) - : base(needPaint) + /// + public HeaderGroupValuesPrimary(NeedPaintHandler needPaint, GetDpiFactor getDpiFactor) + : base(needPaint, getDpiFactor) { } #endregion diff --git a/Source/Krypton Components/Krypton.Toolkit/Values/HeaderGroupValuesSecondary.cs b/Source/Krypton Components/Krypton.Toolkit/Values/HeaderGroupValuesSecondary.cs index 00e19a0bc..6dc605181 100644 --- a/Source/Krypton Components/Krypton.Toolkit/Values/HeaderGroupValuesSecondary.cs +++ b/Source/Krypton Components/Krypton.Toolkit/Values/HeaderGroupValuesSecondary.cs @@ -22,12 +22,14 @@ public class HeaderGroupValuesSecondary : HeaderValuesBase #endregion #region Identity + /// /// Initialize a new instance of the HeaderGroupValuesSecondary class. /// /// Delegate for notifying paint requests. - public HeaderGroupValuesSecondary(NeedPaintHandler needPaint) - : base(needPaint) + /// + public HeaderGroupValuesSecondary(NeedPaintHandler needPaint, GetDpiFactor getDpiFactor) + : base(needPaint, getDpiFactor) { } #endregion diff --git a/Source/Krypton Components/Krypton.Toolkit/Values/HeaderValues.cs b/Source/Krypton Components/Krypton.Toolkit/Values/HeaderValues.cs index e60f86e0e..caacba047 100644 --- a/Source/Krypton Components/Krypton.Toolkit/Values/HeaderValues.cs +++ b/Source/Krypton Components/Krypton.Toolkit/Values/HeaderValues.cs @@ -23,12 +23,14 @@ public class HeaderValues : HeaderValuesBase #endregion #region Identity + /// /// Initialize a new instance of the HeaderValues class. /// /// Delegate for notifying paint requests. - public HeaderValues(NeedPaintHandler? needPaint) - : base(needPaint) + /// + public HeaderValues(NeedPaintHandler? needPaint, GetDpiFactor getDpiFactor) + : base(needPaint, getDpiFactor) { } #endregion diff --git a/Source/Krypton Components/Krypton.Toolkit/Values/HeaderValuesBase.cs b/Source/Krypton Components/Krypton.Toolkit/Values/HeaderValuesBase.cs index 25e3e7e80..ab94d9994 100644 --- a/Source/Krypton Components/Krypton.Toolkit/Values/HeaderValuesBase.cs +++ b/Source/Krypton Components/Krypton.Toolkit/Values/HeaderValuesBase.cs @@ -18,6 +18,8 @@ namespace Krypton.Toolkit public abstract class HeaderValuesBase : Storage, IContentValues { + private readonly GetDpiFactor _getDpiFactor; + #region Static Fields private static readonly Image _defaultImage = GenericImageResources.KryptonLogoGeneric; #endregion @@ -35,14 +37,24 @@ public abstract class HeaderValuesBase : Storage, /// public event EventHandler? TextChanged; #endregion - + + #region Delegates + /// + /// Signature of method that is called when Image scaling is required. + /// + public delegate float GetDpiFactor(); + #endregion + #region Identity + /// /// Initialize a new instance of the HeaderValuesBase class. /// /// Delegate for notifying paint requests. - protected HeaderValuesBase(NeedPaintHandler? needPaint) + /// + protected HeaderValuesBase(NeedPaintHandler? needPaint, GetDpiFactor getDpiFactor) { + _getDpiFactor = getDpiFactor; // Store the provided paint notification delegate NeedPaint = needPaint; @@ -108,19 +120,26 @@ public Image? Image } } - private bool ShouldSerializeImage() => Image != GetImageDefault(); + private bool ShouldSerializeImage() => _image != GetImageDefault(); /// /// Resets the Image property to its default value. /// - public void ResetImage() => Image = GetImageDefault(); + public void ResetImage() => _image = GetImageDefault(); /// /// Gets the content image. /// /// The state for which the image is needed. /// Image value. - public virtual Image? GetImage(PaletteState state) => Image; + public virtual Image? GetImage(PaletteState state) + { + float dpiFactor = _getDpiFactor(); + return (_image != null) + ? CommonHelper.ScaleImageForSizedDisplay(_image, _image.Width * dpiFactor, + _image.Height * dpiFactor) + : null; + } #endregion diff --git a/Source/Krypton Components/Krypton.Toolkit/Values/ToolTipValues.cs b/Source/Krypton Components/Krypton.Toolkit/Values/ToolTipValues.cs index 800c39cac..0db5f7f75 100644 --- a/Source/Krypton Components/Krypton.Toolkit/Values/ToolTipValues.cs +++ b/Source/Krypton Components/Krypton.Toolkit/Values/ToolTipValues.cs @@ -27,8 +27,9 @@ public class ToolTipValues : HeaderValues /// /// /// - public ToolTipValues(NeedPaintHandler? needPaint) - : base(needPaint) + /// + public ToolTipValues(NeedPaintHandler? needPaint, GetDpiFactor getDpiFactor) + : base(needPaint, getDpiFactor) { ResetToolTipStyle(); ToolTipPosition = new PopupPositionValues(); diff --git a/Source/Krypton Components/Krypton.Toolkit/View Layout/ViewLayoutMonths.cs b/Source/Krypton Components/Krypton.Toolkit/View Layout/ViewLayoutMonths.cs index bc5ce73e6..245688e05 100644 --- a/Source/Krypton Components/Krypton.Toolkit/View Layout/ViewLayoutMonths.cs +++ b/Source/Krypton Components/Krypton.Toolkit/View Layout/ViewLayoutMonths.cs @@ -104,7 +104,7 @@ public ViewLayoutMonths(IContextMenuProvider provider, Calendar.GetToolStripDelegate, _needPaintDelegate); // Create the manager for handling tooltips - _toolTipManager = new ToolTipManager(new ToolTipValues(null)); // use default, as each button "could" have different values ??!!?? + _toolTipManager = new ToolTipManager(new ToolTipValues(null, GetDpiFactor)); // use default, as each button "could" have different values ??!!?? _toolTipManager.ShowToolTip += OnShowToolTip; _toolTipManager.CancelToolTip += OnCancelToolTip; ButtonManager.ToolTipManager = _toolTipManager; @@ -125,6 +125,13 @@ public ViewLayoutMonths(IContextMenuProvider provider, _drawHeader.Add(_drawToday, ViewDockStyle.Left); } + private float GetDpiFactor() + { + return (_visualPopupToolTip != null) + ? _visualPopupToolTip.DeviceDpi / 96F + : 1F; + } + /// /// Obtains the String representation of this instance. /// From dc37ad4025793eafef31062d9da2c1cacf36913f Mon Sep 17 00:00:00 2001 From: Simon Coghlan Date: Mon, 16 Dec 2024 15:20:08 +0000 Subject: [PATCH 2/2] - Make it Net4.62 compliant --- .../Krypton.Navigator/Palette/NavigatorHeader.cs | 4 ++++ .../Group Contents/KryptonRibbonGroupItem.cs | 4 ++++ .../View Layout/ViewLayoutRibbonTabsArea.cs | 4 ++++ .../ButtonSpec/ButtonSpecRemapByContentBase.cs | 2 +- .../ContextMenu/KryptonContextMenuItemBase.cs | 4 ++++ .../Krypton.Toolkit/Controls Toolkit/KryptonForm.cs | 4 ++++ .../Krypton.Toolkit/Controls Toolkit/KryptonGroupBox.cs | 4 ++++ .../Krypton.Toolkit/Controls Toolkit/KryptonHeader.cs | 4 ++++ .../Controls Toolkit/KryptonHeaderGroup.cs | 4 ++++ .../Krypton.Toolkit/Controls Visuals/VisualControlBase.cs | 4 ++++ .../Krypton.Toolkit/General/PlatformInvoke.cs | 4 ++++ .../Krypton.Toolkit/ShellDialogs/ShellDialogWrapper.cs | 5 ++--- .../Krypton.Toolkit/View Layout/ViewLayoutMonths.cs | 8 ++++++-- 13 files changed, 49 insertions(+), 6 deletions(-) diff --git a/Source/Krypton Components/Krypton.Navigator/Palette/NavigatorHeader.cs b/Source/Krypton Components/Krypton.Navigator/Palette/NavigatorHeader.cs index caeae7080..4d00b0b45 100644 --- a/Source/Krypton Components/Krypton.Navigator/Palette/NavigatorHeader.cs +++ b/Source/Krypton Components/Krypton.Navigator/Palette/NavigatorHeader.cs @@ -67,7 +67,11 @@ public NavigatorHeader([DisallowNull] KryptonNavigator navigator, private float GetDpiFactor() { +#if NET462 + return PI.GetDpiForWindow(_navigator.Handle) / 96F; +#else return _navigator.DeviceDpi / 96F; +#endif } #endregion diff --git a/Source/Krypton Components/Krypton.Ribbon/Group Contents/KryptonRibbonGroupItem.cs b/Source/Krypton Components/Krypton.Ribbon/Group Contents/KryptonRibbonGroupItem.cs index 0d154973a..267c6826a 100644 --- a/Source/Krypton Components/Krypton.Ribbon/Group Contents/KryptonRibbonGroupItem.cs +++ b/Source/Krypton Components/Krypton.Ribbon/Group Contents/KryptonRibbonGroupItem.cs @@ -48,7 +48,11 @@ protected KryptonRibbonGroupItem() => private float GetDpiFactor() { return (Ribbon != null) +#if NET462 + ? PI.GetDpiForWindow(Ribbon.Handle) / 96F +#else ? Ribbon.DeviceDpi / 96F +#endif : 1.0f; } diff --git a/Source/Krypton Components/Krypton.Ribbon/View Layout/ViewLayoutRibbonTabsArea.cs b/Source/Krypton Components/Krypton.Ribbon/View Layout/ViewLayoutRibbonTabsArea.cs index b188a3c15..6640a21fd 100644 --- a/Source/Krypton Components/Krypton.Ribbon/View Layout/ViewLayoutRibbonTabsArea.cs +++ b/Source/Krypton Components/Krypton.Ribbon/View Layout/ViewLayoutRibbonTabsArea.cs @@ -548,7 +548,11 @@ private void CreateViewElements(PaletteRedirect? redirect) private float GetDpiFactor() { return (_visualPopupToolTip != null) +#if NET462 + ? PI.GetDpiForWindow(_visualPopupToolTip.Handle) / 96F +#else ? _visualPopupToolTip.DeviceDpi / 96F +#endif : 1F; } diff --git a/Source/Krypton Components/Krypton.Toolkit/ButtonSpec/ButtonSpecRemapByContentBase.cs b/Source/Krypton Components/Krypton.Toolkit/ButtonSpec/ButtonSpecRemapByContentBase.cs index 1c0d66f9e..2e7a7ef5a 100644 --- a/Source/Krypton Components/Krypton.Toolkit/ButtonSpec/ButtonSpecRemapByContentBase.cs +++ b/Source/Krypton Components/Krypton.Toolkit/ButtonSpec/ButtonSpecRemapByContentBase.cs @@ -32,7 +32,7 @@ protected ButtonSpecRemapByContentBase(PaletteBase? target, : base(target) { Debug.Assert(buttonSpec != null); - _buttonSpec = buttonSpec; + _buttonSpec = buttonSpec!; } #endregion diff --git a/Source/Krypton Components/Krypton.Toolkit/ContextMenu/KryptonContextMenuItemBase.cs b/Source/Krypton Components/Krypton.Toolkit/ContextMenu/KryptonContextMenuItemBase.cs index c7d88ef60..ddb7f5f14 100644 --- a/Source/Krypton Components/Krypton.Toolkit/ContextMenu/KryptonContextMenuItemBase.cs +++ b/Source/Krypton Components/Krypton.Toolkit/ContextMenu/KryptonContextMenuItemBase.cs @@ -58,7 +58,11 @@ protected KryptonContextMenuItemBase() private float GetDpiFactor() { return (_visualPopupToolTip != null) +#if NET462 + ? PI.GetDpiForWindow(_visualPopupToolTip.Handle) / 96F +#else ? _visualPopupToolTip.DeviceDpi / 96F +#endif : 1F; } diff --git a/Source/Krypton Components/Krypton.Toolkit/Controls Toolkit/KryptonForm.cs b/Source/Krypton Components/Krypton.Toolkit/Controls Toolkit/KryptonForm.cs index eb8b56e69..4c559f0be 100644 --- a/Source/Krypton Components/Krypton.Toolkit/Controls Toolkit/KryptonForm.cs +++ b/Source/Krypton Components/Krypton.Toolkit/Controls Toolkit/KryptonForm.cs @@ -204,7 +204,11 @@ public KryptonForm() private float GetDpiFactor() { return (_visualPopupToolTip != null) +#if NET462 + ? PI.GetDpiForWindow(_visualPopupToolTip.Handle) / 96F +#else ? _visualPopupToolTip.DeviceDpi / 96F +#endif : 1F; } diff --git a/Source/Krypton Components/Krypton.Toolkit/Controls Toolkit/KryptonGroupBox.cs b/Source/Krypton Components/Krypton.Toolkit/Controls Toolkit/KryptonGroupBox.cs index ad3f7e70f..7d14f1621 100644 --- a/Source/Krypton Components/Krypton.Toolkit/Controls Toolkit/KryptonGroupBox.cs +++ b/Source/Krypton Components/Krypton.Toolkit/Controls Toolkit/KryptonGroupBox.cs @@ -109,7 +109,11 @@ public KryptonGroupBox() private float GetDpiFactor() { return (Panel != null) +#if NET462 + ? PI.GetDpiForWindow(Panel.Handle) / 96F +#else ? Panel.DeviceDpi / 96F +#endif : 1f; } diff --git a/Source/Krypton Components/Krypton.Toolkit/Controls Toolkit/KryptonHeader.cs b/Source/Krypton Components/Krypton.Toolkit/Controls Toolkit/KryptonHeader.cs index 28c28c1cb..6030da753 100644 --- a/Source/Krypton Components/Krypton.Toolkit/Controls Toolkit/KryptonHeader.cs +++ b/Source/Krypton Components/Krypton.Toolkit/Controls Toolkit/KryptonHeader.cs @@ -112,7 +112,11 @@ public KryptonHeader() private float GetDpiFactor() { +#if NET462 + return PI.GetDpiForWindow(Handle) / 96F; +#else return DeviceDpi / 96F; +#endif } /// diff --git a/Source/Krypton Components/Krypton.Toolkit/Controls Toolkit/KryptonHeaderGroup.cs b/Source/Krypton Components/Krypton.Toolkit/Controls Toolkit/KryptonHeaderGroup.cs index b6a21e05f..ff6e5245a 100644 --- a/Source/Krypton Components/Krypton.Toolkit/Controls Toolkit/KryptonHeaderGroup.cs +++ b/Source/Krypton Components/Krypton.Toolkit/Controls Toolkit/KryptonHeaderGroup.cs @@ -211,7 +211,11 @@ public KryptonHeaderGroup() private float GetDpiFactor() { return (Panel != null) +#if NET462 + ? PI.GetDpiForWindow(Panel.Handle) / 96F +#else ? Panel.DeviceDpi / 96F +#endif : 1f; } diff --git a/Source/Krypton Components/Krypton.Toolkit/Controls Visuals/VisualControlBase.cs b/Source/Krypton Components/Krypton.Toolkit/Controls Visuals/VisualControlBase.cs index 7aa6a2e1d..52f420b35 100644 --- a/Source/Krypton Components/Krypton.Toolkit/Controls Visuals/VisualControlBase.cs +++ b/Source/Krypton Components/Krypton.Toolkit/Controls Visuals/VisualControlBase.cs @@ -128,7 +128,11 @@ protected VisualControlBase() private float GetDpiFactor() { +#if NET462 + return PI.GetDpiForWindow(Handle) / 96F; +#else return DeviceDpi / 96F; +#endif } /// diff --git a/Source/Krypton Components/Krypton.Toolkit/General/PlatformInvoke.cs b/Source/Krypton Components/Krypton.Toolkit/General/PlatformInvoke.cs index 70d45353f..b7db30330 100644 --- a/Source/Krypton Components/Krypton.Toolkit/General/PlatformInvoke.cs +++ b/Source/Krypton Components/Krypton.Toolkit/General/PlatformInvoke.cs @@ -2839,6 +2839,10 @@ private static KEY_ GetKeyState(Keys key) #endregion #region Static User32 + [DllImport(Libraries.User32)] + [DefaultDllImportSearchPaths(DllImportSearchPath.System32)] + internal static extern uint GetDpiForWindow(IntPtr hWnd); + [DllImport(Libraries.User32)] [DefaultDllImportSearchPaths(DllImportSearchPath.System32)] internal static extern BOOL EndDialog(IntPtr hDlg, IntPtr nResult); diff --git a/Source/Krypton Components/Krypton.Toolkit/ShellDialogs/ShellDialogWrapper.cs b/Source/Krypton Components/Krypton.Toolkit/ShellDialogs/ShellDialogWrapper.cs index b356a6fdf..b87f1ddc0 100644 --- a/Source/Krypton Components/Krypton.Toolkit/ShellDialogs/ShellDialogWrapper.cs +++ b/Source/Krypton Components/Krypton.Toolkit/ShellDialogs/ShellDialogWrapper.cs @@ -88,8 +88,7 @@ private protected virtual void WndMessage(object sender, CWPRETSTRUCT e, out boo if (e.message == PI.WM_.INITDIALOG) { #if NET462 - using var g = _commonDialogHandler._wrapperForm.CreateGraphics(); - _scaleFactor = g.DpiX / 96.0f; + _scaleFactor = PI.GetDpiForWindow(_commonDialogHandler._wrapperForm.Handle) / 96F; #else _scaleFactor = _commonDialogHandler._wrapperForm.DeviceDpi / 96.0f; #endif @@ -178,7 +177,7 @@ private protected virtual bool WndActivated(object sender, CbtEventArgs e) return true; } - #endregion Do_CBT +#endregion Do_CBT /// /// Runs a common dialog box, parented to the given IWin32Window. diff --git a/Source/Krypton Components/Krypton.Toolkit/View Layout/ViewLayoutMonths.cs b/Source/Krypton Components/Krypton.Toolkit/View Layout/ViewLayoutMonths.cs index 245688e05..2b7f36f6e 100644 --- a/Source/Krypton Components/Krypton.Toolkit/View Layout/ViewLayoutMonths.cs +++ b/Source/Krypton Components/Krypton.Toolkit/View Layout/ViewLayoutMonths.cs @@ -128,7 +128,11 @@ public ViewLayoutMonths(IContextMenuProvider provider, private float GetDpiFactor() { return (_visualPopupToolTip != null) +#if NET462 + ? PI.GetDpiForWindow(_visualPopupToolTip.Handle) / 96F +#else ? _visualPopupToolTip.DeviceDpi / 96F +#endif : 1F; } @@ -480,10 +484,10 @@ public Size GetSingleMonthSize([DisallowNull] ViewLayoutContext context) { Debug.Assert(context != null); - SyncData(context); + SyncData(context!); SyncMonths(); - return this[1].GetPreferredSize(context); + return this[1].GetPreferredSize(context!); } ///