Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / Orcas / NetFXw7 / wpf / src / Framework / MS / Internal / PtsHost / BackgroundFormatInfo.cs / 1 / BackgroundFormatInfo.cs
//----------------------------------------------------------------------------
//
//
// Copyright (C) Microsoft Corporation. All rights reserved.
//
//
//
// Description: Background format information
//
// History:
// 10/28/04 : ghermann - Created
//
//---------------------------------------------------------------------------
using System;
using MS.Internal.Documents; // FlowDocumentFormatter
using System.Windows.Threading; // DispatcherTimer
namespace MS.Internal.PtsHost
{
internal sealed class BackgroundFormatInfo
{
//-------------------------------------------------------------------
//
// Constructors
//
//-------------------------------------------------------------------
#region Constructors
///
/// Structural Cache contructor
///
internal BackgroundFormatInfo(StructuralCache structuralCache)
{
_structuralCache = structuralCache;
}
#endregion Constructors
//--------------------------------------------------------------------
//
// Internal Methods
//
//-------------------------------------------------------------------
#region Internal Methods
///
/// Updates background layout information from a structuralCache
///
internal void UpdateBackgroundFormatInfo()
{
_cpInterrupted = -1;
_lastCPUninterruptible = 0;
_doesFinalDTRCoverRestOfText = false;
_cchAllText = _structuralCache.TextContainer.SymbolCount;
if(_structuralCache.DtrList != null)
{
int positionsAdded = 0;
// Sum for all dtrs but the last
for(int dtrIndex = 0; dtrIndex < _structuralCache.DtrList.Length - 1; dtrIndex++)
{
positionsAdded += _structuralCache.DtrList[dtrIndex].PositionsAdded - _structuralCache.DtrList[dtrIndex].PositionsRemoved;
}
DirtyTextRange dtrLast = _structuralCache.DtrList[_structuralCache.DtrList.Length - 1];
if((dtrLast.StartIndex + positionsAdded + dtrLast.PositionsAdded) >= _cchAllText)
{
_doesFinalDTRCoverRestOfText = true;
_lastCPUninterruptible = dtrLast.StartIndex + positionsAdded;
}
}
else
{
_doesFinalDTRCoverRestOfText = true;
}
// And set a good stop time for formatting
_backgroundFormatStopTime = DateTime.UtcNow.AddMilliseconds(_stopTimeDelta);
}
///
/// This method is called after user input.
/// Temporarily disable background layout to cut down on ui latency.
///
internal void ThrottleBackgroundFormatting()
{
if (_throttleBackgroundTimer == null)
{
// Start up a timer. Until the timer fires, we'll disable
// all background layout. This leaves the control responsive
// to user input.
_throttleBackgroundTimer = new DispatcherTimer(DispatcherPriority.Background);
_throttleBackgroundTimer.Interval = new TimeSpan(0, 0, (int)_throttleBackgroundSeconds);
_throttleBackgroundTimer.Tick += new EventHandler(OnThrottleBackgroundTimeout);
}
else
{
// Reset the timer.
_throttleBackgroundTimer.Stop();
}
_throttleBackgroundTimer.Start();
}
///
/// Run one iteration of background formatting. Currently that simply requires
/// that we invalidate the content.
///
internal void BackgroundFormat(IFlowDocumentFormatter formatter, bool ignoreThrottle)
{
if (_throttleBackgroundTimer == null)
{
formatter.OnContentInvalidated(true);
}
else if (ignoreThrottle)
{
OnThrottleBackgroundTimeout(null, EventArgs.Empty);
}
else
{
// If we had recent user input, wait until the timeout passes
// to invalidate.
_pendingBackgroundFormatter = formatter;
}
}
#endregion Internal Methods
//--------------------------------------------------------------------
//
// Internal Properties
//
//--------------------------------------------------------------------
#region Internal Properties
///
/// Last CP Uninterruptible
///
internal int LastCPUninterruptible { get { return _lastCPUninterruptible; } }
///
/// Stop time for background formatting timeslice
///
internal DateTime BackgroundFormatStopTime { get { return _backgroundFormatStopTime; } }
///
/// Cch of all text in container
///
internal int CchAllText { get { return _cchAllText; } }
///
/// Whether background layout is globally enabled
///
static internal bool IsBackgroundFormatEnabled { get { return _isBackgroundFormatEnabled; } }
///
/// Does the final dtr extend through the sum of the text
///
internal bool DoesFinalDTRCoverRestOfText { get { return _doesFinalDTRCoverRestOfText; } }
///
/// Current last cp formatted
///
internal int CPInterrupted { get { return _cpInterrupted; } set { _cpInterrupted = value; } }
///
/// Height of the viewport
///
internal double ViewportHeight
{
get { return _viewportHeight; }
set { _viewportHeight = value; }
}
#endregion Internal Properties
//-------------------------------------------------------------------
//
// Private Methods
//
//--------------------------------------------------------------------
#region Private Methods
// Callback for the background layout throttle timer.
// Resumes backgound layout.
private void OnThrottleBackgroundTimeout(object sender, EventArgs e)
{
_throttleBackgroundTimer.Stop();
_throttleBackgroundTimer = null;
if (_pendingBackgroundFormatter != null)
{
BackgroundFormat(_pendingBackgroundFormatter, true /* ignoreThrottle */);
_pendingBackgroundFormatter = null;
}
}
#endregion Private Methods
//-------------------------------------------------------------------
//
// Private Fields
//
//-------------------------------------------------------------------
#region Private Fields
//-------------------------------------------------------------------
// Height of the viewport.
//--------------------------------------------------------------------
private double _viewportHeight;
//-------------------------------------------------------------------
// Does the final DTR cover the entirety of the range?
//--------------------------------------------------------------------
private bool _doesFinalDTRCoverRestOfText;
//--------------------------------------------------------------------
// What is the last uninterruptible cp ?
//-------------------------------------------------------------------
private int _lastCPUninterruptible;
//--------------------------------------------------------------------
// Stop time for background layout
// Used for background layout
//-------------------------------------------------------------------
private DateTime _backgroundFormatStopTime;
//-------------------------------------------------------------------
// Cch of all text in container
//-------------------------------------------------------------------
private int _cchAllText;
//--------------------------------------------------------------------
// Cp Interrupted
// Used for background layout
//-------------------------------------------------------------------
private int _cpInterrupted;
//--------------------------------------------------------------------
// Global enabling flag for whether background format is enabled.
//--------------------------------------------------------------------
private static bool _isBackgroundFormatEnabled = true;
//-------------------------------------------------------------------
// Structural cache
//--------------------------------------------------------------------
private StructuralCache _structuralCache;
//-------------------------------------------------------------------
// Time after a user input until which we use a minimal time slice
// to remain responsive to future input.
//-------------------------------------------------------------------
private DateTime _throttleTimeout = DateTime.UtcNow;
//-------------------------------------------------------------------
// Timer used to disable background layout during user interaction.
//--------------------------------------------------------------------
private DispatcherTimer _throttleBackgroundTimer;
//-------------------------------------------------------------------
// Holds the formatter to invalidate when _throttleBackgroundTimer
// fires.
//--------------------------------------------------------------------
IFlowDocumentFormatter _pendingBackgroundFormatter;
//--------------------------------------------------------------------
// Number of seconds to disable background layout after receiving
// user input.
//-------------------------------------------------------------------
private const uint _throttleBackgroundSeconds = 2;
//--------------------------------------------------------------------
// Max time slice (ms) for one background format iteration.
//-------------------------------------------------------------------
private const uint _stopTimeDelta = 200;
#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: Background format information
//
// History:
// 10/28/04 : ghermann - Created
//
//---------------------------------------------------------------------------
using System;
using MS.Internal.Documents; // FlowDocumentFormatter
using System.Windows.Threading; // DispatcherTimer
namespace MS.Internal.PtsHost
{
internal sealed class BackgroundFormatInfo
{
//-------------------------------------------------------------------
//
// Constructors
//
//-------------------------------------------------------------------
#region Constructors
///
/// Structural Cache contructor
///
internal BackgroundFormatInfo(StructuralCache structuralCache)
{
_structuralCache = structuralCache;
}
#endregion Constructors
//--------------------------------------------------------------------
//
// Internal Methods
//
//-------------------------------------------------------------------
#region Internal Methods
///
/// Updates background layout information from a structuralCache
///
internal void UpdateBackgroundFormatInfo()
{
_cpInterrupted = -1;
_lastCPUninterruptible = 0;
_doesFinalDTRCoverRestOfText = false;
_cchAllText = _structuralCache.TextContainer.SymbolCount;
if(_structuralCache.DtrList != null)
{
int positionsAdded = 0;
// Sum for all dtrs but the last
for(int dtrIndex = 0; dtrIndex < _structuralCache.DtrList.Length - 1; dtrIndex++)
{
positionsAdded += _structuralCache.DtrList[dtrIndex].PositionsAdded - _structuralCache.DtrList[dtrIndex].PositionsRemoved;
}
DirtyTextRange dtrLast = _structuralCache.DtrList[_structuralCache.DtrList.Length - 1];
if((dtrLast.StartIndex + positionsAdded + dtrLast.PositionsAdded) >= _cchAllText)
{
_doesFinalDTRCoverRestOfText = true;
_lastCPUninterruptible = dtrLast.StartIndex + positionsAdded;
}
}
else
{
_doesFinalDTRCoverRestOfText = true;
}
// And set a good stop time for formatting
_backgroundFormatStopTime = DateTime.UtcNow.AddMilliseconds(_stopTimeDelta);
}
///
/// This method is called after user input.
/// Temporarily disable background layout to cut down on ui latency.
///
internal void ThrottleBackgroundFormatting()
{
if (_throttleBackgroundTimer == null)
{
// Start up a timer. Until the timer fires, we'll disable
// all background layout. This leaves the control responsive
// to user input.
_throttleBackgroundTimer = new DispatcherTimer(DispatcherPriority.Background);
_throttleBackgroundTimer.Interval = new TimeSpan(0, 0, (int)_throttleBackgroundSeconds);
_throttleBackgroundTimer.Tick += new EventHandler(OnThrottleBackgroundTimeout);
}
else
{
// Reset the timer.
_throttleBackgroundTimer.Stop();
}
_throttleBackgroundTimer.Start();
}
///
/// Run one iteration of background formatting. Currently that simply requires
/// that we invalidate the content.
///
internal void BackgroundFormat(IFlowDocumentFormatter formatter, bool ignoreThrottle)
{
if (_throttleBackgroundTimer == null)
{
formatter.OnContentInvalidated(true);
}
else if (ignoreThrottle)
{
OnThrottleBackgroundTimeout(null, EventArgs.Empty);
}
else
{
// If we had recent user input, wait until the timeout passes
// to invalidate.
_pendingBackgroundFormatter = formatter;
}
}
#endregion Internal Methods
//--------------------------------------------------------------------
//
// Internal Properties
//
//--------------------------------------------------------------------
#region Internal Properties
///
/// Last CP Uninterruptible
///
internal int LastCPUninterruptible { get { return _lastCPUninterruptible; } }
///
/// Stop time for background formatting timeslice
///
internal DateTime BackgroundFormatStopTime { get { return _backgroundFormatStopTime; } }
///
/// Cch of all text in container
///
internal int CchAllText { get { return _cchAllText; } }
///
/// Whether background layout is globally enabled
///
static internal bool IsBackgroundFormatEnabled { get { return _isBackgroundFormatEnabled; } }
///
/// Does the final dtr extend through the sum of the text
///
internal bool DoesFinalDTRCoverRestOfText { get { return _doesFinalDTRCoverRestOfText; } }
///
/// Current last cp formatted
///
internal int CPInterrupted { get { return _cpInterrupted; } set { _cpInterrupted = value; } }
///
/// Height of the viewport
///
internal double ViewportHeight
{
get { return _viewportHeight; }
set { _viewportHeight = value; }
}
#endregion Internal Properties
//-------------------------------------------------------------------
//
// Private Methods
//
//--------------------------------------------------------------------
#region Private Methods
// Callback for the background layout throttle timer.
// Resumes backgound layout.
private void OnThrottleBackgroundTimeout(object sender, EventArgs e)
{
_throttleBackgroundTimer.Stop();
_throttleBackgroundTimer = null;
if (_pendingBackgroundFormatter != null)
{
BackgroundFormat(_pendingBackgroundFormatter, true /* ignoreThrottle */);
_pendingBackgroundFormatter = null;
}
}
#endregion Private Methods
//-------------------------------------------------------------------
//
// Private Fields
//
//-------------------------------------------------------------------
#region Private Fields
//-------------------------------------------------------------------
// Height of the viewport.
//--------------------------------------------------------------------
private double _viewportHeight;
//-------------------------------------------------------------------
// Does the final DTR cover the entirety of the range?
//--------------------------------------------------------------------
private bool _doesFinalDTRCoverRestOfText;
//--------------------------------------------------------------------
// What is the last uninterruptible cp ?
//-------------------------------------------------------------------
private int _lastCPUninterruptible;
//--------------------------------------------------------------------
// Stop time for background layout
// Used for background layout
//-------------------------------------------------------------------
private DateTime _backgroundFormatStopTime;
//-------------------------------------------------------------------
// Cch of all text in container
//-------------------------------------------------------------------
private int _cchAllText;
//--------------------------------------------------------------------
// Cp Interrupted
// Used for background layout
//-------------------------------------------------------------------
private int _cpInterrupted;
//--------------------------------------------------------------------
// Global enabling flag for whether background format is enabled.
//--------------------------------------------------------------------
private static bool _isBackgroundFormatEnabled = true;
//-------------------------------------------------------------------
// Structural cache
//--------------------------------------------------------------------
private StructuralCache _structuralCache;
//-------------------------------------------------------------------
// Time after a user input until which we use a minimal time slice
// to remain responsive to future input.
//-------------------------------------------------------------------
private DateTime _throttleTimeout = DateTime.UtcNow;
//-------------------------------------------------------------------
// Timer used to disable background layout during user interaction.
//--------------------------------------------------------------------
private DispatcherTimer _throttleBackgroundTimer;
//-------------------------------------------------------------------
// Holds the formatter to invalidate when _throttleBackgroundTimer
// fires.
//--------------------------------------------------------------------
IFlowDocumentFormatter _pendingBackgroundFormatter;
//--------------------------------------------------------------------
// Number of seconds to disable background layout after receiving
// user input.
//-------------------------------------------------------------------
private const uint _throttleBackgroundSeconds = 2;
//--------------------------------------------------------------------
// Max time slice (ms) for one background format iteration.
//-------------------------------------------------------------------
private const uint _stopTimeDelta = 200;
#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
- XmlChildNodes.cs
- PropertyChangedEventArgs.cs
- WebControl.cs
- DbParameterCollectionHelper.cs
- CardSpacePolicyElement.cs
- DbConnectionOptions.cs
- GeometryHitTestParameters.cs
- SplineKeyFrames.cs
- XmlUTF8TextWriter.cs
- RowUpdatedEventArgs.cs
- OnOperation.cs
- ReflectionHelper.cs
- XmlSchemaGroupRef.cs
- DataSetMappper.cs
- DataControlField.cs
- indexingfiltermarshaler.cs
- OleServicesContext.cs
- CursorConverter.cs
- HtmlInputRadioButton.cs
- XPathDescendantIterator.cs
- PaintValueEventArgs.cs
- DataGridColumnHeader.cs
- SqlFactory.cs
- TextRangeEdit.cs
- ControlUtil.cs
- TextEndOfParagraph.cs
- SystemSounds.cs
- ISO2022Encoding.cs
- Timeline.cs
- XmlSecureResolver.cs
- TiffBitmapDecoder.cs
- latinshape.cs
- PathTooLongException.cs
- TypeRefElement.cs
- _SslState.cs
- DataServiceRequestException.cs
- BinaryParser.cs
- X509SecurityTokenProvider.cs
- StreamUpgradeAcceptor.cs
- DrawingImage.cs
- Vertex.cs
- SortAction.cs
- FtpWebRequest.cs
- FirstMatchCodeGroup.cs
- HostingEnvironmentWrapper.cs
- EditorBrowsableAttribute.cs
- UpdateCompiler.cs
- TypedElement.cs
- UnlockInstanceAsyncResult.cs
- WebBrowserDocumentCompletedEventHandler.cs
- DoubleCollection.cs
- DataFormats.cs
- Trace.cs
- XmlElementList.cs
- EntityWithChangeTrackerStrategy.cs
- ToolBarButtonClickEvent.cs
- AnonymousIdentificationModule.cs
- PrintEvent.cs
- MenuCommand.cs
- IndicCharClassifier.cs
- ProtocolsConfiguration.cs
- DesignerDataStoredProcedure.cs
- XmlLangPropertyAttribute.cs
- TogglePattern.cs
- LinearKeyFrames.cs
- __Filters.cs
- ParseElementCollection.cs
- X509SubjectKeyIdentifierClause.cs
- TemplatedMailWebEventProvider.cs
- InputScope.cs
- ValidatingReaderNodeData.cs
- XmlKeywords.cs
- DesignerTextBoxAdapter.cs
- LongSumAggregationOperator.cs
- RawStylusInput.cs
- AutomationInteropProvider.cs
- LambdaCompiler.Binary.cs
- DataGridViewColumnStateChangedEventArgs.cs
- HideDisabledControlAdapter.cs
- ChangeBlockUndoRecord.cs
- TcpWorkerProcess.cs
- Guid.cs
- SizeChangedEventArgs.cs
- GZipDecoder.cs
- Animatable.cs
- CollectionDataContract.cs
- ExclusiveTcpListener.cs
- CompModSwitches.cs
- ListControl.cs
- MouseGesture.cs
- PrivateFontCollection.cs
- basecomparevalidator.cs
- NegationPusher.cs
- ListCollectionView.cs
- PopupRootAutomationPeer.cs
- PartialClassGenerationTask.cs
- GridViewCellAutomationPeer.cs
- MinMaxParagraphWidth.cs
- RegexCaptureCollection.cs
- BlockCollection.cs