Browse Source

Warn in debug output when non-frozen brushes are used in AvalonEdit.

pull/14/head
Daniel Grunwald 15 years ago
parent
commit
03c220d8f4
  1. 4
      src/AddIns/BackendBindings/XamlBinding/XamlBinding/Extensions.cs
  2. 13
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Rendering/TextView.cs
  3. 5
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Rendering/VisualLineElementTextRunProperties.cs
  4. 11
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Utils/ExtensionMethods.cs

4
src/AddIns/BackendBindings/XamlBinding/XamlBinding/Extensions.cs

@ -362,7 +362,9 @@ namespace ICSharpCode.XamlBinding @@ -362,7 +362,9 @@ namespace ICSharpCode.XamlBinding
public static Brush ToBrush(this Color color)
{
return new SolidColorBrush(color);
var b = new SolidColorBrush(color);
b.Freeze();
return b;
}
}
}

13
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Rendering/TextView.cs

@ -778,12 +778,13 @@ namespace ICSharpCode.AvalonEdit.Rendering @@ -778,12 +778,13 @@ namespace ICSharpCode.AvalonEdit.Rendering
TextRunProperties CreateGlobalTextRunProperties()
{
return new GlobalTextRunProperties {
typeface = this.CreateTypeface(),
fontRenderingEmSize = FontSize,
foregroundBrush = (Brush)GetValue(Control.ForegroundProperty),
cultureInfo = CultureInfo.CurrentCulture
};
var p = new GlobalTextRunProperties();
p.typeface = this.CreateTypeface();
p.fontRenderingEmSize = FontSize;
p.foregroundBrush = (Brush)GetValue(Control.ForegroundProperty);
ExtensionMethods.CheckIsFrozen(p.foregroundBrush);
p.cultureInfo = CultureInfo.CurrentCulture;
return p;
}
VisualLineTextParagraphProperties CreateParagraphProperties(TextRunProperties defaultTextRunProperties)

5
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Rendering/VisualLineElementTextRunProperties.cs

@ -6,6 +6,7 @@ using System.Globalization; @@ -6,6 +6,7 @@ using System.Globalization;
using System.Windows;
using System.Windows.Media;
using System.Windows.Media.TextFormatting;
using ICSharpCode.AvalonEdit.Utils;
namespace ICSharpCode.AvalonEdit.Rendering
{
@ -76,6 +77,7 @@ namespace ICSharpCode.AvalonEdit.Rendering @@ -76,6 +77,7 @@ namespace ICSharpCode.AvalonEdit.Rendering
/// </summary>
public void SetBackgroundBrush(Brush value)
{
ExtensionMethods.CheckIsFrozen(value);
backgroundBrush = value;
}
@ -143,6 +145,7 @@ namespace ICSharpCode.AvalonEdit.Rendering @@ -143,6 +145,7 @@ namespace ICSharpCode.AvalonEdit.Rendering
/// </summary>
public void SetForegroundBrush(Brush value)
{
ExtensionMethods.CheckIsFrozen(value);
foregroundBrush = value;
}
@ -177,6 +180,7 @@ namespace ICSharpCode.AvalonEdit.Rendering @@ -177,6 +180,7 @@ namespace ICSharpCode.AvalonEdit.Rendering
/// </summary>
public void SetTextDecorations(TextDecorationCollection value)
{
ExtensionMethods.CheckIsFrozen(value);
textDecorations = value;
}
@ -196,6 +200,7 @@ namespace ICSharpCode.AvalonEdit.Rendering @@ -196,6 +200,7 @@ namespace ICSharpCode.AvalonEdit.Rendering
/// </summary>
public void SetTextEffects(TextEffectCollection value)
{
ExtensionMethods.CheckIsFrozen(value);
textEffects = value;
}
}

11
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Utils/ExtensionMethods.cs

@ -3,14 +3,12 @@ @@ -3,14 +3,12 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Threading;
using System.Xml;
using ICSharpCode.AvalonEdit.Document;
namespace ICSharpCode.AvalonEdit.Utils
{
static class ExtensionMethods
@ -187,5 +185,12 @@ namespace ICSharpCode.AvalonEdit.Utils @@ -187,5 +185,12 @@ namespace ICSharpCode.AvalonEdit.Utils
return new Rect(rect.Location.ToWpf(), rect.Size.ToWpf());
}
#endregion
[Conditional("DEBUG")]
public static void CheckIsFrozen(Freezable f)
{
if (f != null && !f.IsFrozen)
Debug.WriteLine("Performance warning: Not frozen: " + f.ToString());
}
}
}

Loading…
Cancel
Save