diff --git a/CHANGELOG.md b/CHANGELOG.md index a0cb7ea..13f6a67 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,20 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/). +### Ribbon V2.13.0, RibbonTools V1.5.0 + +#### Changed (Ribbon) + +- Bugfix RibbonDropDownColorPicker.StandardColors. +- Free unmanaged memory as soon as possible. +- Support for .NET7 + +#### Changed (RibbonTools) + +- Correct usage of TActions +- delete unnecessary namespace in CodeBuilder for RibbonItems + + ### Ribbon V2.12.0, RibbonTools V1.4.0 #### Changed (Ribbon) diff --git a/Ribbon/Controls/Properties/ColorPickerPropertiesProvider.cs b/Ribbon/Controls/Properties/ColorPickerPropertiesProvider.cs index 3261107..aac09a3 100644 --- a/Ribbon/Controls/Properties/ColorPickerPropertiesProvider.cs +++ b/Ribbon/Controls/Properties/ColorPickerPropertiesProvider.cs @@ -235,7 +235,9 @@ public string AutomaticColorLabel HRESULT hr = _ribbon.Framework.GetUICommandProperty(_commandID, ref RibbonProperties.AutomaticColorLabel, out automaticColorLabel); if (NativeMethods.Succeeded(hr)) { - return (string)automaticColorLabel.Value; + string result = (string)automaticColorLabel.Value; + PropVariant.Clear(ref automaticColorLabel); + return result; } } @@ -256,6 +258,7 @@ public string AutomaticColorLabel automaticColorLabel = PropVariant.FromObject(_automaticColorLabel); } HRESULT hr = _ribbon.Framework.SetUICommandProperty(_commandID, ref RibbonProperties.AutomaticColorLabel, ref automaticColorLabel); + PropVariant.Clear(ref automaticColorLabel); } } } @@ -333,7 +336,9 @@ public string MoreColorsLabel HRESULT hr = _ribbon.Framework.GetUICommandProperty(_commandID, ref RibbonProperties.MoreColorsLabel, out moreColorsLabel); if (NativeMethods.Succeeded(hr)) { - return (string)moreColorsLabel.Value; + string result = (string)moreColorsLabel.Value; + PropVariant.Clear(ref moreColorsLabel); + return result; } } @@ -354,6 +359,7 @@ public string MoreColorsLabel moreColorsLabel = PropVariant.FromObject(_moreColorsLabel); } HRESULT hr = _ribbon.Framework.SetUICommandProperty(_commandID, ref RibbonProperties.MoreColorsLabel, ref moreColorsLabel); + PropVariant.Clear(ref moreColorsLabel); } } } @@ -371,7 +377,9 @@ public string NoColorLabel HRESULT hr = _ribbon.Framework.GetUICommandProperty(_commandID, ref RibbonProperties.NoColorLabel, out noColorLabel); if (NativeMethods.Succeeded(hr)) { - return (string)noColorLabel.Value; + string result = (string)noColorLabel.Value; + PropVariant.Clear(ref noColorLabel); + return result; } } @@ -392,6 +400,7 @@ public string NoColorLabel noColorLabel = PropVariant.FromObject(_noColorLabel); } HRESULT hr = _ribbon.Framework.SetUICommandProperty(_commandID, ref RibbonProperties.NoColorLabel, ref noColorLabel); + PropVariant.Clear(ref noColorLabel); } } } @@ -409,7 +418,9 @@ public string RecentColorsCategoryLabel HRESULT hr = _ribbon.Framework.GetUICommandProperty(_commandID, ref RibbonProperties.RecentColorsCategoryLabel, out recentColorsCategoryLabel); if (NativeMethods.Succeeded(hr)) { - return (string)recentColorsCategoryLabel.Value; + string result = (string)recentColorsCategoryLabel.Value; + PropVariant.Clear(ref recentColorsCategoryLabel); + return result; } } @@ -430,6 +441,7 @@ public string RecentColorsCategoryLabel recentColorsCategoryLabel = PropVariant.FromObject(_recentColorsCategoryLabel); } HRESULT hr = _ribbon.Framework.SetUICommandProperty(_commandID, ref RibbonProperties.RecentColorsCategoryLabel, ref recentColorsCategoryLabel); + PropVariant.Clear(ref recentColorsCategoryLabel); } } } @@ -450,6 +462,7 @@ public Color[] StandardColors uint[] uintStandardColors = (uint[])standardColors.Value; int[] intStandardColors = Array.ConvertAll(uintStandardColors, new Converter(Convert.ToInt32)); Color[] colorStandardColors = Array.ConvertAll(intStandardColors, new Converter(ColorTranslator.FromWin32)); + PropVariant.Clear(ref standardColors); return colorStandardColors; } } @@ -466,6 +479,7 @@ public Color[] StandardColors PropVariant standardColors = PropVariant.FromObject(uintStandardColors); HRESULT hr = _ribbon.Framework.SetUICommandProperty(_commandID, ref RibbonProperties.StandardColors, ref standardColors); + PropVariant.Clear(ref standardColors); } } } @@ -483,7 +497,9 @@ public string StandardColorsCategoryLabel HRESULT hr = _ribbon.Framework.GetUICommandProperty(_commandID, ref RibbonProperties.StandardColorsCategoryLabel, out standardColorsCategoryLabel); if (NativeMethods.Succeeded(hr)) { - return (string)standardColorsCategoryLabel.Value; + string result = (string)standardColorsCategoryLabel.Value; + PropVariant.Clear(ref standardColorsCategoryLabel); + return result; } } @@ -504,6 +520,7 @@ public string StandardColorsCategoryLabel standardColorsCategoryLabel = PropVariant.FromObject(_standardColorsCategoryLabel); } HRESULT hr = _ribbon.Framework.SetUICommandProperty(_commandID, ref RibbonProperties.StandardColorsCategoryLabel, ref standardColorsCategoryLabel); + PropVariant.Clear(ref standardColorsCategoryLabel); } } } @@ -521,7 +538,9 @@ public string[] StandardColorsTooltips HRESULT hr = _ribbon.Framework.GetUICommandProperty(_commandID, ref RibbonProperties.StandardColorsTooltips, out standardColorsTooltips); if (NativeMethods.Succeeded(hr)) { - return (string[])standardColorsTooltips.Value; + string[] result = (string[])standardColorsTooltips.Value; + PropVariant.Clear(ref standardColorsTooltips); + return result; } } @@ -534,6 +553,7 @@ public string[] StandardColorsTooltips { PropVariant standardColorsTooltips = PropVariant.FromObject(value); HRESULT hr = _ribbon.Framework.SetUICommandProperty(_commandID, ref RibbonProperties.StandardColorsTooltips, ref standardColorsTooltips); + PropVariant.Clear(ref standardColorsTooltips); } } } @@ -554,6 +574,7 @@ public Color[] ThemeColors uint[] uintThemeColors = (uint[])themeColors.Value; int[] intThemeColors = Array.ConvertAll(uintThemeColors, new Converter(Convert.ToInt32)); Color[] colorThemeColors = Array.ConvertAll(intThemeColors, new Converter(ColorTranslator.FromWin32)); + PropVariant.Clear(ref themeColors); return colorThemeColors; } } @@ -570,6 +591,7 @@ public Color[] ThemeColors PropVariant themeColors = PropVariant.FromObject(uintThemeColors); HRESULT hr = _ribbon.Framework.SetUICommandProperty(_commandID, ref RibbonProperties.ThemeColors, ref themeColors); + PropVariant.Clear(ref themeColors); } } } @@ -587,7 +609,9 @@ public string ThemeColorsCategoryLabel HRESULT hr = _ribbon.Framework.GetUICommandProperty(_commandID, ref RibbonProperties.ThemeColorsCategoryLabel, out themeColorsCategoryLabel); if (NativeMethods.Succeeded(hr)) { - return (string)themeColorsCategoryLabel.Value; + string result = (string)themeColorsCategoryLabel.Value; + PropVariant.Clear(ref themeColorsCategoryLabel); + return result; } } @@ -608,6 +632,7 @@ public string ThemeColorsCategoryLabel themeColorsCategoryLabel = PropVariant.FromObject(_themeColorsCategoryLabel); } HRESULT hr = _ribbon.Framework.SetUICommandProperty(_commandID, ref RibbonProperties.ThemeColorsCategoryLabel, ref themeColorsCategoryLabel); + PropVariant.Clear(ref themeColorsCategoryLabel); } } } @@ -625,7 +650,9 @@ public string[] ThemeColorsTooltips HRESULT hr = _ribbon.Framework.GetUICommandProperty(_commandID, ref RibbonProperties.ThemeColorsTooltips, out themeColorsTooltips); if (NativeMethods.Succeeded(hr)) { - return (string[])themeColorsTooltips.Value; + string[] result = (string[])themeColorsTooltips.Value; + PropVariant.Clear(ref themeColorsTooltips); + return result; } } @@ -638,6 +665,7 @@ public string[] ThemeColorsTooltips { PropVariant themeColorsTooltips = PropVariant.FromObject(value); HRESULT hr = _ribbon.Framework.SetUICommandProperty(_commandID, ref RibbonProperties.ThemeColorsTooltips, ref themeColorsTooltips); + PropVariant.Clear(ref themeColorsTooltips); } } } diff --git a/Ribbon/Controls/Properties/FontControlPropertiesProvider.cs b/Ribbon/Controls/Properties/FontControlPropertiesProvider.cs index d9dce40..e1e87ab 100644 --- a/Ribbon/Controls/Properties/FontControlPropertiesProvider.cs +++ b/Ribbon/Controls/Properties/FontControlPropertiesProvider.cs @@ -118,6 +118,7 @@ public override HRESULT UpdateProperty(ref PropertyKey key, PropVariantRef curre { PropVariant propFamily = PropVariant.FromObject(_family); fontProperties.SetValue(ref RibbonProperties.FontProperties_Family, ref propFamily); + PropVariant.Clear(ref propFamily); } // set size @@ -233,7 +234,9 @@ public string Family IPropertyStore propertyStore = FontProperties; PropVariant propFamily; HRESULT hr = propertyStore.GetValue(ref RibbonProperties.FontProperties_Family, out propFamily); - return (string)propFamily.Value; + string result = (string)propFamily.Value; + PropVariant.Clear(ref propFamily); + return result; } return _family; diff --git a/Ribbon/Controls/Properties/StringValueProperiesProvider.cs b/Ribbon/Controls/Properties/StringValueProperiesProvider.cs index a56bfde..9b68881 100644 --- a/Ribbon/Controls/Properties/StringValueProperiesProvider.cs +++ b/Ribbon/Controls/Properties/StringValueProperiesProvider.cs @@ -75,7 +75,9 @@ public string StringValue HRESULT hr = _ribbon.Framework.GetUICommandProperty(_commandID, ref RibbonProperties.StringValue, out stringValue); if (NativeMethods.Succeeded(hr)) { - return (string)stringValue.Value; + string result = (string)stringValue.Value; + PropVariant.Clear(ref stringValue); + return result; } } @@ -97,6 +99,7 @@ public string StringValue stringValue = PropVariant.FromObject(_stringValue); } HRESULT hr = _ribbon.Framework.SetUICommandProperty(_commandID, ref RibbonProperties.StringValue, ref stringValue); + PropVariant.Clear(ref stringValue); } } } diff --git a/Ribbon/Interop/PropVariant.cs b/Ribbon/Interop/PropVariant.cs index 6a379fc..b5a8d5f 100644 --- a/Ribbon/Interop/PropVariant.cs +++ b/Ribbon/Interop/PropVariant.cs @@ -382,6 +382,27 @@ public void Clear() valueDataExt = 0; } + /// + /// Called to clear the PropVariant's referenced and local memory. + /// + /// + /// You must call Clear to avoid memory leaks. + /// + /// The PropVariant. + public static void Clear(ref PropVariant var) + { + UnsafeNativeMethods.PropVariantClear(ref var); + } + + /// + /// Set all values to zero. + /// + /// The PropVariant. + public static void PropVariantInit(ref PropVariant var) + { + var = default(PropVariant); + } + /// /// Clone a PropVariant /// @@ -403,7 +424,7 @@ public PropVariant Clone() /// The new value to set. public void SetUInt(UInt32 value) { - if (!this.IsNull()) this.Clear(); + if (!this.IsNull()) PropVariantInit(ref this); valueType = (ushort)VarEnum.VT_UI4; valueData = (IntPtr)((int)value); @@ -415,7 +436,7 @@ public void SetUInt(UInt32 value) /// The new value to set. public void SetBool(bool value) { - if (!this.IsNull()) this.Clear(); + if (!this.IsNull()) PropVariantInit(ref this); valueType = (ushort)VarEnum.VT_BOOL; valueData = ((value == true) ? (IntPtr)65535 : (IntPtr)0); @@ -427,12 +448,12 @@ public void SetBool(bool value) /// The new value to set. public void SetDateTime(DateTime value) { - if (!this.IsNull()) this.Clear(); + if (!this.IsNull()) PropVariantInit(ref this); valueType = (ushort)VarEnum.VT_FILETIME; PropVariant propVar; - System.Runtime.InteropServices.ComTypes.FILETIME ft = DateTimeTotFileTime(value); + System.Runtime.InteropServices.ComTypes.FILETIME ft = DateTimeToFileTime(value); UnsafeNativeMethods.InitPropVariantFromFileTime(ref ft, out propVar); CopyData(propVar); } @@ -443,7 +464,7 @@ public void SetDateTime(DateTime value) /// The new value to set. public void SetString(string value) { - if (!this.IsNull()) this.Clear(); + if (!this.IsNull()) PropVariantInit(ref this); valueType = (ushort)VarEnum.VT_LPWSTR; valueData = Marshal.StringToCoTaskMemUni(value); @@ -455,7 +476,7 @@ public void SetString(string value) /// The new value to set. public void SetIUnknown(object value) { - if (!this.IsNull()) this.Clear(); + if (!this.IsNull()) PropVariantInit(ref this); valueType = (ushort)VarEnum.VT_UNKNOWN; valueData = Marshal.GetIUnknownForObject(value); @@ -467,12 +488,11 @@ public void SetIUnknown(object value) /// The new value to set. public void SetSafeArray(Array array) { - if (!this.IsNull()) this.Clear(); + if (!this.IsNull()) PropVariantInit(ref this); if (array == null) return; - const ushort vtUnknown = 13; - IntPtr psa = UnsafeNativeMethods.SafeArrayCreateVector(vtUnknown, 0, (uint)array.Length); + IntPtr psa = UnsafeNativeMethods.SafeArrayCreateVector((ushort)VarEnum.VT_UNKNOWN, 0, (uint)array.Length); IntPtr pvData = UnsafeNativeMethods.SafeArrayAccessData(psa); try // to remember to release lock on data @@ -499,7 +519,7 @@ public void SetSafeArray(Array array) /// The new value to set. public void SetByte(byte value) { - if (!this.IsNull()) this.Clear(); + if (!this.IsNull()) PropVariantInit(ref this); valueType = (ushort)VarEnum.VT_UI1; valueData = (IntPtr)value; @@ -511,7 +531,7 @@ public void SetByte(byte value) /// The new value to set. public void SetSByte(sbyte value) { - if (!this.IsNull()) this.Clear(); + if (!this.IsNull()) PropVariantInit(ref this); valueType = (ushort)VarEnum.VT_I1; valueData = (IntPtr)value; @@ -523,7 +543,7 @@ public void SetSByte(sbyte value) /// The new value to set. public void SetShort(short value) { - if (!this.IsNull()) this.Clear(); + if (!this.IsNull()) PropVariantInit(ref this); valueType = (ushort)VarEnum.VT_I2; valueData = (IntPtr)value; @@ -535,7 +555,7 @@ public void SetShort(short value) /// The new value to set. public void SetUShort(ushort value) { - if (!this.IsNull()) this.Clear(); + if (!this.IsNull()) PropVariantInit(ref this); valueType = (ushort)VarEnum.VT_UI2; valueData = (IntPtr)value; @@ -547,7 +567,7 @@ public void SetUShort(ushort value) /// The new value to set. public void SetInt(int value) { - if (!this.IsNull()) this.Clear(); + if (!this.IsNull()) PropVariantInit(ref this); valueType = (ushort)VarEnum.VT_I4; valueData = (IntPtr)value; @@ -703,7 +723,7 @@ public void SetDateTimeVector(DateTime[] array) for (int i = 0; i < array.Length; i++) { - fileTimeArr[i] = DateTimeTotFileTime(array[i]); + fileTimeArr[i] = DateTimeToFileTime(array[i]); } PropVariant propVar; @@ -717,7 +737,7 @@ public void SetDateTimeVector(DateTime[] array) /// The new value to set. public void SetDecimal(decimal value) { - if (!this.IsNull()) this.Clear(); + if (!this.IsNull()) PropVariantInit(ref this); PVDecimalOuterUnion union = new PVDecimalOuterUnion(); union.decVal = value; @@ -734,7 +754,7 @@ public void SetDecimal(decimal value) /// The new value to set. public void SetLong(long value) { - if (!this.IsNull()) this.Clear(); + if (!this.IsNull()) PropVariantInit(ref this); long[] valueArr = new long[] { value }; @@ -750,7 +770,7 @@ public void SetLong(long value) /// The new value to set. public void SetULong(ulong value) { - if (!this.IsNull()) this.Clear(); + if (!this.IsNull()) PropVariantInit(ref this); PropVariant propVar; ulong[] valueArr = new ulong[] { value }; @@ -765,7 +785,7 @@ public void SetULong(ulong value) /// The new value to set. public void SetDouble(double value) { - if (!this.IsNull()) this.Clear(); + if (!this.IsNull()) PropVariantInit(ref this); double[] valueArr = new double[] { value }; @@ -949,7 +969,7 @@ private static long FileTimeToDateTime(ref System.Runtime.InteropServices.ComTyp return (((long)val.dwHighDateTime) << 32) + val.dwLowDateTime; } - private static System.Runtime.InteropServices.ComTypes.FILETIME DateTimeTotFileTime(DateTime value) + private static System.Runtime.InteropServices.ComTypes.FILETIME DateTimeToFileTime(DateTime value) { long hFT = value.ToFileTime(); System.Runtime.InteropServices.ComTypes.FILETIME ft = diff --git a/Ribbon/Interop/RibbonProperties.cs b/Ribbon/Interop/RibbonProperties.cs index 5ea9438..bba5de9 100644 --- a/Ribbon/Interop/RibbonProperties.cs +++ b/Ribbon/Interop/RibbonProperties.cs @@ -83,7 +83,7 @@ public static class RibbonProperties public static PropertyKey NoColorLabel = CreateRibbonPropertyKey(407, VarEnum.VT_LPWSTR); public static PropertyKey MoreColorsLabel = CreateRibbonPropertyKey(408, VarEnum.VT_LPWSTR); public static PropertyKey ThemeColors = CreateRibbonPropertyKey(409, (VarEnum.VT_VECTOR | VarEnum.VT_UI4)); - public static PropertyKey StandardColors = CreateRibbonPropertyKey(400, (VarEnum.VT_VECTOR | VarEnum.VT_UI4)); + public static PropertyKey StandardColors = CreateRibbonPropertyKey(410, (VarEnum.VT_VECTOR | VarEnum.VT_UI4)); public static PropertyKey ThemeColorsTooltips = CreateRibbonPropertyKey(411, (VarEnum.VT_VECTOR | VarEnum.VT_LPWSTR)); public static PropertyKey StandardColorsTooltips = CreateRibbonPropertyKey(412, (VarEnum.VT_VECTOR | VarEnum.VT_LPWSTR)); diff --git a/Ribbon/Properties/AssemblyInfo.cs b/Ribbon/Properties/AssemblyInfo.cs index 598a9c8..e7fcd5c 100644 --- a/Ribbon/Properties/AssemblyInfo.cs +++ b/Ribbon/Properties/AssemblyInfo.cs @@ -37,5 +37,5 @@ #else [assembly: AssemblyVersion("1.0.0.0")] #endif -[assembly: AssemblyFileVersion("2.12.0.0")] +[assembly: AssemblyFileVersion("2.13.0.0")] diff --git a/Ribbon/RibbonCore.csproj b/Ribbon/RibbonCore.csproj index b4f3339..986f2a5 100644 --- a/Ribbon/RibbonCore.csproj +++ b/Ribbon/RibbonCore.csproj @@ -2,7 +2,8 @@ Library - net6.0-windows;net5.0-windows;netcoreapp3.1;net40 + net7.0-windows;net6.0-windows;net5.0-windows;netcoreapp3.1;net40 + true true @@ -19,7 +20,7 @@ WindowsRibbon Windows Ribbon Control - 2.12.0 + 2.13.0 Hartmut Borkenhagen RibbonLib Ribbon64.png @@ -36,7 +37,7 @@ false - + DEBUG;Core @@ -44,6 +45,11 @@ DEBUG + + TRACE;Core + .\bin\Release\net7.0-windows\Ribbon.xml + + TRACE;Core .\bin\Release\net6.0-windows\Ribbon.xml diff --git a/RibbonTools/Properties/AssemblyInfo.cs b/RibbonTools/Properties/AssemblyInfo.cs index e8e6980..076b652 100644 --- a/RibbonTools/Properties/AssemblyInfo.cs +++ b/RibbonTools/Properties/AssemblyInfo.cs @@ -33,4 +33,4 @@ // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] [assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.4.0.0")] +[assembly: AssemblyFileVersion("1.5.0.0")] diff --git a/Setup/Ribbon.wxs b/Setup/Ribbon.wxs index 677daa6..8f4e40f 100644 --- a/Setup/Ribbon.wxs +++ b/Setup/Ribbon.wxs @@ -9,7 +9,7 @@ - + diff --git a/Setup/RibbonTools.wxs b/Setup/RibbonTools.wxs index a89b4b4..82a19fc 100644 --- a/Setup/RibbonTools.wxs +++ b/Setup/RibbonTools.wxs @@ -9,7 +9,7 @@ - +