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

Loading…
Cancel
Save