Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / wpf / src / Framework / System / Windows / Documents / SpellerHighlightLayer.cs / 1305600 / SpellerHighlightLayer.cs
//----------------------------------------------------------------------------
//
// File: SpellerHighlightLayer.cs
//
// Description: Highlight rendering for the Speller.
//
//---------------------------------------------------------------------------
using System;
using MS.Internal;
using System.Windows.Documents;
using System.Windows.Media;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
namespace System.Windows.Documents
{
// Highlight rendering for the Speller.
// The speller tags errors with red squigglies.
internal class SpellerHighlightLayer : HighlightLayer
{
//-----------------------------------------------------
//
// Constructors
//
//-----------------------------------------------------
#region Constructors
// Static constructor.
static SpellerHighlightLayer()
{
_errorTextDecorations = GetErrorTextDecorations();
}
// Constructor.
internal SpellerHighlightLayer(Speller speller)
{
_speller = speller;
}
#endregion Constructors
//------------------------------------------------------
//
// Internal Methods
//
//-----------------------------------------------------
#region Internal Methods
// Returns a TextDecorationCollection used to tag spelling errors,
// or DependencyProperty.UnsetValue if there's no error at the specified position.
internal override object GetHighlightValue(StaticTextPointer textPosition, LogicalDirection direction)
{
object value;
if (IsContentHighlighted(textPosition, direction))
{
value = _errorTextDecorations;
}
else
{
value = DependencyProperty.UnsetValue;
}
return value;
}
// Returns true iff the indicated content has scoping highlights.
internal override bool IsContentHighlighted(StaticTextPointer textPosition, LogicalDirection direction)
{
return _speller.StatusTable.IsRunType(textPosition, direction, SpellerStatusTable.RunType.Error);
}
// Returns the position of the next highlight start or end in an
// indicated direction, or null if there is no such position.
internal override StaticTextPointer GetNextChangePosition(StaticTextPointer textPosition, LogicalDirection direction)
{
return _speller.StatusTable.GetNextErrorTransition(textPosition, direction);
}
// Raises a Changed event for any listeners, covering the
// specified text.
internal void FireChangedEvent(ITextPointer start, ITextPointer end)
{
if (Changed != null)
{
Changed(this, new SpellerHighlightChangedEventArgs(start, end));
}
}
#endregion Internal Methods
//------------------------------------------------------
//
// Internal Properties
//
//------------------------------------------------------
#region Internal Properties
// Type identifying this layer for Highlights.GetHighlightValue calls.
internal override Type OwnerType
{
get
{
return typeof(SpellerHighlightLayer);
}
}
#endregion Internal Properties
//-----------------------------------------------------
//
// Internal Events
//
//------------------------------------------------------
#region Internal Events
///
/// Event raised when a highlight range is inserted, removed, moved, or
/// has a local property value change.
///
internal override event HighlightChangedEventHandler Changed;
#endregion Internal Events
//-----------------------------------------------------
//
// Private Methods
//
//-----------------------------------------------------
#region Private Methods
// Calculates TextDecorations for speller errors.
private static TextDecorationCollection GetErrorTextDecorations()
{
//
// Build a "squiggle" Brush.
//
// This works by hard-coding a 3 pixel high TextDecoration, and
// then tiling horizontally. (We can't scale the squiggle in
// the vertical direction, there's no support to limit tiling
// to just the horizontal from the MIL.)
//
DrawingGroup drawingGroup = new DrawingGroup();
DrawingContext drawingContext = drawingGroup.Open();
Pen pen = new Pen(Brushes.Red, 0.33);
// This is our tile:
//
// x x
// x x
// x
//
drawingContext.DrawLine(pen, new Point(0.0, 0.0), new Point(0.5, 1.0));
drawingContext.DrawLine(pen, new Point(0.5, 1.0), new Point(1.0, 0.0));
drawingContext.Close();
DrawingBrush brush = new DrawingBrush(drawingGroup);
brush.TileMode = TileMode.Tile;
brush.Viewport = new Rect(0, 0, 3, 3);
brush.ViewportUnits = BrushMappingMode.Absolute;
TextDecoration textDecoration = new TextDecoration(
TextDecorationLocation.Underline,
new Pen(brush, 3),
0,
TextDecorationUnit.FontRecommended,
TextDecorationUnit.Pixel);
TextDecorationCollection decorationCollection = new TextDecorationCollection();
decorationCollection.Add(textDecoration);
decorationCollection.Freeze();
return decorationCollection;
}
#endregion Private Methods
//-----------------------------------------------------
//
// Private Types
//
//------------------------------------------------------
#region Private Types
// Argument for the Changed event, encapsulates a highlight change.
private class SpellerHighlightChangedEventArgs : HighlightChangedEventArgs
{
// Constructor.
internal SpellerHighlightChangedEventArgs(ITextPointer start, ITextPointer end)
{
List list;
Invariant.Assert(start.CompareTo(end) < 0, "Bogus start/end combination!");
list = new List(1);
list.Add(new TextSegment(start, end));
_ranges = new ReadOnlyCollection(list);
}
// Collection of changed content ranges.
internal override IList Ranges
{
get
{
return _ranges;
}
}
// Type identifying the owner of the changed layer.
internal override Type OwnerType
{
get
{
return typeof(SpellerHighlightLayer);
}
}
// Collection of changed content ranges.
private readonly ReadOnlyCollection _ranges;
}
#endregion Private Types
//-----------------------------------------------------
//
// Private Fields
//
//------------------------------------------------------
#region Private Fields
// Assocated Speller.
private readonly Speller _speller;
// Decorations for text flagged with a spelling error.
private static readonly TextDecorationCollection _errorTextDecorations;
#endregion Private Fields
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
//----------------------------------------------------------------------------
//
// File: SpellerHighlightLayer.cs
//
// Description: Highlight rendering for the Speller.
//
//---------------------------------------------------------------------------
using System;
using MS.Internal;
using System.Windows.Documents;
using System.Windows.Media;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
namespace System.Windows.Documents
{
// Highlight rendering for the Speller.
// The speller tags errors with red squigglies.
internal class SpellerHighlightLayer : HighlightLayer
{
//-----------------------------------------------------
//
// Constructors
//
//-----------------------------------------------------
#region Constructors
// Static constructor.
static SpellerHighlightLayer()
{
_errorTextDecorations = GetErrorTextDecorations();
}
// Constructor.
internal SpellerHighlightLayer(Speller speller)
{
_speller = speller;
}
#endregion Constructors
//------------------------------------------------------
//
// Internal Methods
//
//-----------------------------------------------------
#region Internal Methods
// Returns a TextDecorationCollection used to tag spelling errors,
// or DependencyProperty.UnsetValue if there's no error at the specified position.
internal override object GetHighlightValue(StaticTextPointer textPosition, LogicalDirection direction)
{
object value;
if (IsContentHighlighted(textPosition, direction))
{
value = _errorTextDecorations;
}
else
{
value = DependencyProperty.UnsetValue;
}
return value;
}
// Returns true iff the indicated content has scoping highlights.
internal override bool IsContentHighlighted(StaticTextPointer textPosition, LogicalDirection direction)
{
return _speller.StatusTable.IsRunType(textPosition, direction, SpellerStatusTable.RunType.Error);
}
// Returns the position of the next highlight start or end in an
// indicated direction, or null if there is no such position.
internal override StaticTextPointer GetNextChangePosition(StaticTextPointer textPosition, LogicalDirection direction)
{
return _speller.StatusTable.GetNextErrorTransition(textPosition, direction);
}
// Raises a Changed event for any listeners, covering the
// specified text.
internal void FireChangedEvent(ITextPointer start, ITextPointer end)
{
if (Changed != null)
{
Changed(this, new SpellerHighlightChangedEventArgs(start, end));
}
}
#endregion Internal Methods
//------------------------------------------------------
//
// Internal Properties
//
//------------------------------------------------------
#region Internal Properties
// Type identifying this layer for Highlights.GetHighlightValue calls.
internal override Type OwnerType
{
get
{
return typeof(SpellerHighlightLayer);
}
}
#endregion Internal Properties
//-----------------------------------------------------
//
// Internal Events
//
//------------------------------------------------------
#region Internal Events
///
/// Event raised when a highlight range is inserted, removed, moved, or
/// has a local property value change.
///
internal override event HighlightChangedEventHandler Changed;
#endregion Internal Events
//-----------------------------------------------------
//
// Private Methods
//
//-----------------------------------------------------
#region Private Methods
// Calculates TextDecorations for speller errors.
private static TextDecorationCollection GetErrorTextDecorations()
{
//
// Build a "squiggle" Brush.
//
// This works by hard-coding a 3 pixel high TextDecoration, and
// then tiling horizontally. (We can't scale the squiggle in
// the vertical direction, there's no support to limit tiling
// to just the horizontal from the MIL.)
//
DrawingGroup drawingGroup = new DrawingGroup();
DrawingContext drawingContext = drawingGroup.Open();
Pen pen = new Pen(Brushes.Red, 0.33);
// This is our tile:
//
// x x
// x x
// x
//
drawingContext.DrawLine(pen, new Point(0.0, 0.0), new Point(0.5, 1.0));
drawingContext.DrawLine(pen, new Point(0.5, 1.0), new Point(1.0, 0.0));
drawingContext.Close();
DrawingBrush brush = new DrawingBrush(drawingGroup);
brush.TileMode = TileMode.Tile;
brush.Viewport = new Rect(0, 0, 3, 3);
brush.ViewportUnits = BrushMappingMode.Absolute;
TextDecoration textDecoration = new TextDecoration(
TextDecorationLocation.Underline,
new Pen(brush, 3),
0,
TextDecorationUnit.FontRecommended,
TextDecorationUnit.Pixel);
TextDecorationCollection decorationCollection = new TextDecorationCollection();
decorationCollection.Add(textDecoration);
decorationCollection.Freeze();
return decorationCollection;
}
#endregion Private Methods
//-----------------------------------------------------
//
// Private Types
//
//------------------------------------------------------
#region Private Types
// Argument for the Changed event, encapsulates a highlight change.
private class SpellerHighlightChangedEventArgs : HighlightChangedEventArgs
{
// Constructor.
internal SpellerHighlightChangedEventArgs(ITextPointer start, ITextPointer end)
{
List list;
Invariant.Assert(start.CompareTo(end) < 0, "Bogus start/end combination!");
list = new List(1);
list.Add(new TextSegment(start, end));
_ranges = new ReadOnlyCollection(list);
}
// Collection of changed content ranges.
internal override IList Ranges
{
get
{
return _ranges;
}
}
// Type identifying the owner of the changed layer.
internal override Type OwnerType
{
get
{
return typeof(SpellerHighlightLayer);
}
}
// Collection of changed content ranges.
private readonly ReadOnlyCollection _ranges;
}
#endregion Private Types
//-----------------------------------------------------
//
// Private Fields
//
//------------------------------------------------------
#region Private Fields
// Assocated Speller.
private readonly Speller _speller;
// Decorations for text flagged with a spelling error.
private static readonly TextDecorationCollection _errorTextDecorations;
#endregion Private Fields
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- SecurityUtils.cs
- TextProperties.cs
- RectangleHotSpot.cs
- UTF7Encoding.cs
- PeerCustomResolverElement.cs
- HMACMD5.cs
- FileDialog_Vista_Interop.cs
- Configuration.cs
- ToolboxDataAttribute.cs
- DbConnectionFactory.cs
- ProfileService.cs
- WebBrowserProgressChangedEventHandler.cs
- Utils.cs
- CaseInsensitiveComparer.cs
- SapiRecognizer.cs
- ProviderConnectionPointCollection.cs
- QilLiteral.cs
- PersianCalendar.cs
- TypeRestriction.cs
- CallbackWrapper.cs
- CqlParser.cs
- BaseValidatorDesigner.cs
- HostingEnvironmentWrapper.cs
- DataServiceExpressionVisitor.cs
- FixedTextBuilder.cs
- mda.cs
- ResourceReferenceExpression.cs
- SessionSwitchEventArgs.cs
- EventArgs.cs
- FuncCompletionCallbackWrapper.cs
- ImageSourceValueSerializer.cs
- Parameter.cs
- SQLDouble.cs
- processwaithandle.cs
- UserNamePasswordValidationMode.cs
- WrappingXamlSchemaContext.cs
- EntityDataSourceViewSchema.cs
- QueryableFilterRepeater.cs
- CreateUserErrorEventArgs.cs
- CodeObject.cs
- GiveFeedbackEvent.cs
- InfoCardRSAPKCS1SignatureFormatter.cs
- BitmapImage.cs
- DelegatingStream.cs
- TakeQueryOptionExpression.cs
- SqlBulkCopy.cs
- Metafile.cs
- OdbcConnectionHandle.cs
- MustUnderstandSoapException.cs
- VariableDesigner.xaml.cs
- FtpCachePolicyElement.cs
- ServiceMemoryGates.cs
- EdmComplexTypeAttribute.cs
- CapiSafeHandles.cs
- IPAddress.cs
- UserPersonalizationStateInfo.cs
- ScriptingWebServicesSectionGroup.cs
- MailAddressCollection.cs
- Int32Collection.cs
- ByteStorage.cs
- LineServices.cs
- ContextDataSourceContextData.cs
- DoubleCollectionConverter.cs
- ImageFormat.cs
- Trustee.cs
- HttpCapabilitiesSectionHandler.cs
- ClassImporter.cs
- ResXFileRef.cs
- GifBitmapEncoder.cs
- GlobalProxySelection.cs
- Token.cs
- TableSectionStyle.cs
- RSAPKCS1KeyExchangeDeformatter.cs
- Propagator.cs
- ChineseLunisolarCalendar.cs
- ExceptionHandlers.cs
- HandlerFactoryWrapper.cs
- HTTPAPI_VERSION.cs
- MetadataSource.cs
- TextParentUndoUnit.cs
- AccessorTable.cs
- BulletDecorator.cs
- SplayTreeNode.cs
- MessageSecurityOverMsmqElement.cs
- TemplateComponentConnector.cs
- Splitter.cs
- FrameworkElementAutomationPeer.cs
- CodeDOMUtility.cs
- InfoCardBaseException.cs
- Utility.cs
- SmtpNegotiateAuthenticationModule.cs
- Debugger.cs
- Size3DConverter.cs
- AmbientLight.cs
- SoapEnvelopeProcessingElement.cs
- ZipPackage.cs
- ListSourceHelper.cs
- PointAnimationUsingKeyFrames.cs
- AutomationPatternInfo.cs
- TextEditorLists.cs