Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / Orcas / NetFXw7 / wpf / src / Framework / System / Windows / Documents / TextParentUndoUnit.cs / 1 / TextParentUndoUnit.cs
//---------------------------------------------------------------------------- //--------------------------------------------------------------------------- // //// Copyright (C) Microsoft Corporation. All rights reserved. // // // Description: // // See spec at http://avalon/uis/Stock%20Services/Undo%20spec.htm // // History: // 03/23/2004 : eveselov - created // //--------------------------------------------------------------------------- using System; using MS.Internal; using System.Windows.Input; using System.Windows.Controls; using System.Windows.Documents.Internal; using System.Windows.Threading; using System.ComponentModel; using System.Windows.Media; using System.Windows.Markup; using System.Text; using MS.Utility; using MS.Internal.Documents; namespace System.Windows.Documents { ////// TextParentUndoUnit /// internal class TextParentUndoUnit : ParentUndoUnit { //----------------------------------------------------- // // Constructors // //------------------------------------------------------ #region Constructors ////// Constructor /// /// /// TextSelection before executing the operation. /// internal TextParentUndoUnit(ITextSelection selection) : this(selection, selection.AnchorPosition, selection.MovingPosition) { } internal TextParentUndoUnit(ITextSelection selection, ITextPointer anchorPosition, ITextPointer movingPosition) : base(String.Empty) { _selection = selection; _undoAnchorPositionOffset = anchorPosition.Offset; _undoAnchorPositionDirection = anchorPosition.LogicalDirection; _undoMovingPositionOffset = movingPosition.Offset; _undoMovingPositionDirection = movingPosition.LogicalDirection; // Bug 1706768: we are seeing unitialized values when the undo // undo is pulled off the undo stack. _redoAnchorPositionOffset // and _redoMovingPositionOffset are supposed to be initialized // with calls to RecordRedoSelectionState before that happens. // // This code path is being left enabled in DEBUG to help track down // the underlying bug post V1. #if DEBUG _redoAnchorPositionOffset = -1; _redoMovingPositionOffset = -1; #else _redoAnchorPositionOffset = 0; _redoMovingPositionOffset = 0; #endif } ////// Creates a redo unit from an undo unit. /// protected TextParentUndoUnit(TextParentUndoUnit undoUnit) : base(String.Empty) { _selection = undoUnit._selection; _undoAnchorPositionOffset = undoUnit._redoAnchorPositionOffset; _undoAnchorPositionDirection = undoUnit._redoAnchorPositionDirection; _undoMovingPositionOffset = undoUnit._redoMovingPositionOffset; _undoMovingPositionDirection = undoUnit._redoMovingPositionDirection; // Bug 1706768: we are seeing unitialized values when the undo // undo is pulled off the undo stack. _redoAnchorPositionOffset // and _redoMovingPositionOffset are supposed to be initialized // with calls to RecordRedoSelectionState before that happens. // // This code path is being left enabled in DEBUG to help track down // the underlying bug post V1. #if DEBUG _redoAnchorPositionOffset = -1; _redoMovingPositionOffset = -1; #else _redoAnchorPositionOffset = 0; _redoMovingPositionOffset = 0; #endif } #endregion Constructors //----------------------------------------------------- // // Public Methods // //------------------------------------------------------ #region Public Methods ////// Implements IUndoUnit::Do(). For IParentUndoUnit, this means iterating through /// all contained units and calling their Do(). /// public override void Do() { base.Do(); // Note: TextParentUndoUnit will be created here by our callback CreateParentUndoUnitForSelf. ITextContainer textContainer = _selection.Start.TextContainer; ITextPointer anchorPosition = textContainer.CreatePointerAtOffset(_undoAnchorPositionOffset, _undoAnchorPositionDirection); ITextPointer movingPosition = textContainer.CreatePointerAtOffset(_undoMovingPositionOffset, _undoMovingPositionDirection); _selection.Select(anchorPosition, movingPosition); _redoUnit.RecordRedoSelectionState(); } #endregion Public Methods //------------------------------------------------------ // // Protected Methods // //----------------------------------------------------- #region Protected Methods ////// Implements a callback called from base.Do method for /// creating appropriate ParentUndoUnit for redo. /// ///protected override IParentUndoUnit CreateParentUndoUnitForSelf() { _redoUnit = CreateRedoUnit(); return _redoUnit; } protected virtual TextParentUndoUnit CreateRedoUnit() { return new TextParentUndoUnit(this); } protected void MergeRedoSelectionState(TextParentUndoUnit undoUnit) { _redoAnchorPositionOffset = undoUnit._redoAnchorPositionOffset; _redoAnchorPositionDirection = undoUnit._redoAnchorPositionDirection; _redoMovingPositionOffset = undoUnit._redoMovingPositionOffset; _redoMovingPositionDirection = undoUnit._redoMovingPositionDirection; } #endregion Protected Methods //------------------------------------------------------ // // Internal Methods // //----------------------------------------------------- #region Internal Methods /// /// This method should be called just before the undo unit is closed. It will capture /// the current selectionStart and selectionEnd offsets for use later when this undo unit /// gets Redone. /// internal void RecordRedoSelectionState() { RecordRedoSelectionState(_selection.AnchorPosition, _selection.MovingPosition); } ////// This method should be called just before the undo unit is closed. It will capture /// the current selectionStart and selectionEnd offsets for use later when this undo unit /// gets Redone. /// internal void RecordRedoSelectionState(ITextPointer anchorPosition, ITextPointer movingPosition) { _redoAnchorPositionOffset = anchorPosition.Offset; _redoAnchorPositionDirection = anchorPosition.LogicalDirection; _redoMovingPositionOffset = movingPosition.Offset; _redoMovingPositionDirection = movingPosition.LogicalDirection; } #endregion Internal Methods //----------------------------------------------------- // // Private Fields // //----------------------------------------------------- #region Private Fields private readonly ITextSelection _selection; private readonly int _undoAnchorPositionOffset; private readonly LogicalDirection _undoAnchorPositionDirection; private readonly int _undoMovingPositionOffset; private readonly LogicalDirection _undoMovingPositionDirection; private int _redoAnchorPositionOffset; private LogicalDirection _redoAnchorPositionDirection; private int _redoMovingPositionOffset; private LogicalDirection _redoMovingPositionDirection; private TextParentUndoUnit _redoUnit; #if DEBUG // Debug-only unique identifier for this instance. private readonly int _debugId = _debugIdCounter++; // Debug-only id counter. private static int _debugIdCounter; #endif #endregion Private Fields } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved. //---------------------------------------------------------------------------- //--------------------------------------------------------------------------- // //// Copyright (C) Microsoft Corporation. All rights reserved. // // // Description: // // See spec at http://avalon/uis/Stock%20Services/Undo%20spec.htm // // History: // 03/23/2004 : eveselov - created // //--------------------------------------------------------------------------- using System; using MS.Internal; using System.Windows.Input; using System.Windows.Controls; using System.Windows.Documents.Internal; using System.Windows.Threading; using System.ComponentModel; using System.Windows.Media; using System.Windows.Markup; using System.Text; using MS.Utility; using MS.Internal.Documents; namespace System.Windows.Documents { ////// TextParentUndoUnit /// internal class TextParentUndoUnit : ParentUndoUnit { //----------------------------------------------------- // // Constructors // //------------------------------------------------------ #region Constructors ////// Constructor /// /// /// TextSelection before executing the operation. /// internal TextParentUndoUnit(ITextSelection selection) : this(selection, selection.AnchorPosition, selection.MovingPosition) { } internal TextParentUndoUnit(ITextSelection selection, ITextPointer anchorPosition, ITextPointer movingPosition) : base(String.Empty) { _selection = selection; _undoAnchorPositionOffset = anchorPosition.Offset; _undoAnchorPositionDirection = anchorPosition.LogicalDirection; _undoMovingPositionOffset = movingPosition.Offset; _undoMovingPositionDirection = movingPosition.LogicalDirection; // Bug 1706768: we are seeing unitialized values when the undo // undo is pulled off the undo stack. _redoAnchorPositionOffset // and _redoMovingPositionOffset are supposed to be initialized // with calls to RecordRedoSelectionState before that happens. // // This code path is being left enabled in DEBUG to help track down // the underlying bug post V1. #if DEBUG _redoAnchorPositionOffset = -1; _redoMovingPositionOffset = -1; #else _redoAnchorPositionOffset = 0; _redoMovingPositionOffset = 0; #endif } ////// Creates a redo unit from an undo unit. /// protected TextParentUndoUnit(TextParentUndoUnit undoUnit) : base(String.Empty) { _selection = undoUnit._selection; _undoAnchorPositionOffset = undoUnit._redoAnchorPositionOffset; _undoAnchorPositionDirection = undoUnit._redoAnchorPositionDirection; _undoMovingPositionOffset = undoUnit._redoMovingPositionOffset; _undoMovingPositionDirection = undoUnit._redoMovingPositionDirection; // Bug 1706768: we are seeing unitialized values when the undo // undo is pulled off the undo stack. _redoAnchorPositionOffset // and _redoMovingPositionOffset are supposed to be initialized // with calls to RecordRedoSelectionState before that happens. // // This code path is being left enabled in DEBUG to help track down // the underlying bug post V1. #if DEBUG _redoAnchorPositionOffset = -1; _redoMovingPositionOffset = -1; #else _redoAnchorPositionOffset = 0; _redoMovingPositionOffset = 0; #endif } #endregion Constructors //----------------------------------------------------- // // Public Methods // //------------------------------------------------------ #region Public Methods ////// Implements IUndoUnit::Do(). For IParentUndoUnit, this means iterating through /// all contained units and calling their Do(). /// public override void Do() { base.Do(); // Note: TextParentUndoUnit will be created here by our callback CreateParentUndoUnitForSelf. ITextContainer textContainer = _selection.Start.TextContainer; ITextPointer anchorPosition = textContainer.CreatePointerAtOffset(_undoAnchorPositionOffset, _undoAnchorPositionDirection); ITextPointer movingPosition = textContainer.CreatePointerAtOffset(_undoMovingPositionOffset, _undoMovingPositionDirection); _selection.Select(anchorPosition, movingPosition); _redoUnit.RecordRedoSelectionState(); } #endregion Public Methods //------------------------------------------------------ // // Protected Methods // //----------------------------------------------------- #region Protected Methods ////// Implements a callback called from base.Do method for /// creating appropriate ParentUndoUnit for redo. /// ///protected override IParentUndoUnit CreateParentUndoUnitForSelf() { _redoUnit = CreateRedoUnit(); return _redoUnit; } protected virtual TextParentUndoUnit CreateRedoUnit() { return new TextParentUndoUnit(this); } protected void MergeRedoSelectionState(TextParentUndoUnit undoUnit) { _redoAnchorPositionOffset = undoUnit._redoAnchorPositionOffset; _redoAnchorPositionDirection = undoUnit._redoAnchorPositionDirection; _redoMovingPositionOffset = undoUnit._redoMovingPositionOffset; _redoMovingPositionDirection = undoUnit._redoMovingPositionDirection; } #endregion Protected Methods //------------------------------------------------------ // // Internal Methods // //----------------------------------------------------- #region Internal Methods /// /// This method should be called just before the undo unit is closed. It will capture /// the current selectionStart and selectionEnd offsets for use later when this undo unit /// gets Redone. /// internal void RecordRedoSelectionState() { RecordRedoSelectionState(_selection.AnchorPosition, _selection.MovingPosition); } ////// This method should be called just before the undo unit is closed. It will capture /// the current selectionStart and selectionEnd offsets for use later when this undo unit /// gets Redone. /// internal void RecordRedoSelectionState(ITextPointer anchorPosition, ITextPointer movingPosition) { _redoAnchorPositionOffset = anchorPosition.Offset; _redoAnchorPositionDirection = anchorPosition.LogicalDirection; _redoMovingPositionOffset = movingPosition.Offset; _redoMovingPositionDirection = movingPosition.LogicalDirection; } #endregion Internal Methods //----------------------------------------------------- // // Private Fields // //----------------------------------------------------- #region Private Fields private readonly ITextSelection _selection; private readonly int _undoAnchorPositionOffset; private readonly LogicalDirection _undoAnchorPositionDirection; private readonly int _undoMovingPositionOffset; private readonly LogicalDirection _undoMovingPositionDirection; private int _redoAnchorPositionOffset; private LogicalDirection _redoAnchorPositionDirection; private int _redoMovingPositionOffset; private LogicalDirection _redoMovingPositionDirection; private TextParentUndoUnit _redoUnit; #if DEBUG // Debug-only unique identifier for this instance. private readonly int _debugId = _debugIdCounter++; // Debug-only id counter. private static int _debugIdCounter; #endif #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
- IxmlLineInfo.cs
- WsdlInspector.cs
- StringKeyFrameCollection.cs
- PrintPreviewDialog.cs
- MaskedTextBoxDesigner.cs
- TrustManagerPromptUI.cs
- CanonicalXml.cs
- MappingModelBuildProvider.cs
- ButtonBase.cs
- UnionExpr.cs
- AttributeQuery.cs
- HttpStreamXmlDictionaryReader.cs
- Validator.cs
- SmtpTransport.cs
- HttpGetServerProtocol.cs
- SystemParameters.cs
- MaskedTextBoxDesigner.cs
- SqlDelegatedTransaction.cs
- DynamicILGenerator.cs
- XmlSerializableServices.cs
- MSG.cs
- ExpressionEditorAttribute.cs
- OrderByBuilder.cs
- Crypto.cs
- ErrorInfoXmlDocument.cs
- TreeNodeStyle.cs
- DataGridViewCell.cs
- SecuritySessionServerSettings.cs
- DbConnectionPoolOptions.cs
- XmlSchemaSet.cs
- DependencyObject.cs
- SourceFileBuildProvider.cs
- Listbox.cs
- InkPresenter.cs
- HyperLinkField.cs
- AlgoModule.cs
- NativeMethods.cs
- DataControlField.cs
- Point3DCollection.cs
- SrgsDocumentParser.cs
- SolidColorBrush.cs
- HttpAsyncResult.cs
- Comparer.cs
- FormView.cs
- DesignerRegionCollection.cs
- FacetEnabledSchemaElement.cs
- CompModSwitches.cs
- CachedFontFace.cs
- DataObjectMethodAttribute.cs
- CodeMemberProperty.cs
- BitSet.cs
- FirewallWrapper.cs
- TextSpan.cs
- CompoundFileStreamReference.cs
- ExpressionEditorAttribute.cs
- XmlReflectionImporter.cs
- XmlSchemaComplexContentRestriction.cs
- BitmapEffectDrawingContextWalker.cs
- Track.cs
- DBDataPermission.cs
- MessageQueuePermissionEntry.cs
- PageBreakRecord.cs
- JournalEntryListConverter.cs
- CreateRefExpr.cs
- ManagedFilter.cs
- PersonalizationStateInfoCollection.cs
- Thickness.cs
- Timeline.cs
- FlowDocumentView.cs
- DefaultSerializationProviderAttribute.cs
- WebBrowser.cs
- VirtualizingPanel.cs
- SelectionItemPattern.cs
- ApplicationSecurityManager.cs
- GridViewRowCollection.cs
- LinqDataView.cs
- XsdDuration.cs
- TextHidden.cs
- StateBag.cs
- DocumentViewerBase.cs
- WCFModelStrings.Designer.cs
- ExpressionContext.cs
- DataControlPagerLinkButton.cs
- AttributeEmitter.cs
- SqlFunctionAttribute.cs
- XmlValidatingReader.cs
- AdapterUtil.cs
- CommentEmitter.cs
- SystemResources.cs
- SystemFonts.cs
- RoutedEventArgs.cs
- EdmToObjectNamespaceMap.cs
- PenLineJoinValidation.cs
- StrokeIntersection.cs
- WebHttpSecurity.cs
- CharUnicodeInfo.cs
- SortKey.cs
- DataServiceQueryProvider.cs
- DocumentApplication.cs
- MenuAutoFormat.cs