Browse Source

Added CheckDisposed logic to FormattedText

pull/261/head
Nikita Tsukanov 11 years ago
parent
commit
303f473ffe
  1. 1
      src/Perspex.Base/Perspex.Base.csproj
  2. 27
      src/Perspex.Base/PerspexDisposable.cs
  3. 22
      src/Perspex.SceneGraph/Media/FormattedText.cs

1
src/Perspex.Base/Perspex.Base.csproj

@ -46,6 +46,7 @@
<Compile Include="Diagnostics\PerspexObjectExtensions.cs" />
<Compile Include="IObservablePropertyBag.cs" />
<Compile Include="IPropertyBag.cs" />
<Compile Include="PerspexDisposable.cs" />
<Compile Include="PerspexLocator.cs" />
<Compile Include="Metadata\XmlnsDefinitionAttribute.cs" />
<Compile Include="PerspexObjectExtensions.cs" />

27
src/Perspex.Base/PerspexDisposable.cs

@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Perspex
{
public abstract class PerspexDisposable : IDisposable
{
public bool IsDisposed { get; private set; }
public void Dispose()
{
IsDisposed = true;
DoDispose();
}
protected void CheckDisposed()
{
if (IsDisposed)
throw new ObjectDisposedException(GetType().FullName);
}
protected abstract void DoDispose();
}
}

22
src/Perspex.SceneGraph/Media/FormattedText.cs

@ -10,7 +10,7 @@ namespace Perspex.Media
/// <summary>
/// Represents a piece of text with formatting.
/// </summary>
public class FormattedText : IDisposable
public class FormattedText : PerspexDisposable
{
/// <summary>
/// Initializes a new instance of the <see cref="FormattedText"/> class.
@ -56,8 +56,16 @@ namespace Perspex.Media
/// </summary>
public Size Constraint
{
get { return PlatformImpl.Constraint; }
set { PlatformImpl.Constraint = value; }
get
{
CheckDisposed();
return PlatformImpl.Constraint;
}
set
{
CheckDisposed();
PlatformImpl.Constraint = value;
}
}
/// <summary>
@ -124,7 +132,7 @@ namespace Perspex.Media
/// <summary>
/// Disposes of unmanaged resources associated with the formatted text.
/// </summary>
public void Dispose()
protected override void DoDispose()
{
PlatformImpl.Dispose();
}
@ -137,6 +145,7 @@ namespace Perspex.Media
/// </returns>
public IEnumerable<FormattedTextLine> GetLines()
{
CheckDisposed();
return PlatformImpl.GetLines();
}
@ -149,6 +158,7 @@ namespace Perspex.Media
/// </returns>
public TextHitTestResult HitTestPoint(Point point)
{
CheckDisposed();
return PlatformImpl.HitTestPoint(point);
}
@ -159,6 +169,7 @@ namespace Perspex.Media
/// <returns>The character bounds.</returns>
public Rect HitTestTextPosition(int index)
{
CheckDisposed();
return PlatformImpl.HitTestTextPosition(index);
}
@ -170,6 +181,7 @@ namespace Perspex.Media
/// <returns>The character bounds.</returns>
public IEnumerable<Rect> HitTestTextRange(int index, int length)
{
CheckDisposed();
return PlatformImpl.HitTestTextRange(index, length);
}
@ -179,6 +191,7 @@ namespace Perspex.Media
/// <returns>The bounds box of the text.</returns>
public Size Measure()
{
CheckDisposed();
return PlatformImpl.Measure();
}
@ -190,6 +203,7 @@ namespace Perspex.Media
/// <param name="length">The length of the text range.</param>
public void SetForegroundBrush(Brush brush, int startIndex, int length)
{
CheckDisposed();
PlatformImpl.SetForegroundBrush(brush, startIndex, length);
}
}

Loading…
Cancel
Save