Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / wpf / src / Framework / System / Windows / Automation / Peers / FlowDocumentReaderAutomationPeer.cs / 1305600 / FlowDocumentReaderAutomationPeer.cs
//----------------------------------------------------------------------------
//
// Copyright (C) Microsoft Corporation. All rights reserved.
//
// File: FlowDocumentReaderAutomationPeer.cs
//
// Description: AutomationPeer associated with FlowDocumentReader.
//
//---------------------------------------------------------------------------
using System.Collections.Generic; // List
using System.Windows.Automation.Provider; // IMultipleViewProvider
using System.Windows.Controls; // FlowDocumentReader
using System.Windows.Documents; // FlowDocument
using MS.Internal; // Invariant
namespace System.Windows.Automation.Peers
{
///
/// AutomationPeer associated with FlowDocumentScrollViewer.
///
public class FlowDocumentReaderAutomationPeer : FrameworkElementAutomationPeer, IMultipleViewProvider
{
///
/// Constructor.
///
/// Owner of the AutomationPeer.
public FlowDocumentReaderAutomationPeer(FlowDocumentReader owner)
: base(owner)
{ }
///
///
///
public override object GetPattern(PatternInterface patternInterface)
{
object returnValue = null;
if (patternInterface == PatternInterface.MultipleView)
{
returnValue = this;
}
else
{
returnValue = base.GetPattern(patternInterface);
}
return returnValue;
}
///
///
///
///
/// AutomationPeer associated with FlowDocumentScrollViewer returns an AutomationPeer
/// for hosted Document and for elements in the style.
///
protected override List GetChildrenCore()
{
// Get children for all elements in the style.
List children = base.GetChildrenCore();
// Add AutomationPeer associated with the document.
// Make it the first child of the collection.
FlowDocument document = ((FlowDocumentReader)Owner).Document;
if (document != null)
{
AutomationPeer documentPeer = ContentElementAutomationPeer.CreatePeerForElement(document);
if (_documentPeer != documentPeer)
{
if (_documentPeer != null)
{
_documentPeer.OnDisconnected();
}
_documentPeer = documentPeer as DocumentAutomationPeer;
}
if (documentPeer != null)
{
if (children == null)
{
children = new List();
}
children.Add(documentPeer);
}
}
return children;
}
///
///
///
protected override string GetClassNameCore()
{
return "FlowDocumentReader";
}
///
/// This helper synchronously fires automation PropertyChange event
/// in responce to current view mode change.
///
//
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
internal void RaiseCurrentViewChangedEvent(FlowDocumentReaderViewingMode newMode, FlowDocumentReaderViewingMode oldMode)
{
if (newMode != oldMode)
{
RaisePropertyChangedEvent(MultipleViewPatternIdentifiers.CurrentViewProperty,
ConvertModeToViewId(newMode), ConvertModeToViewId(oldMode));
}
}
///
/// This helper synchronously fires automation PropertyChange event
/// in responce to supported views change.
///
//
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
internal void RaiseSupportedViewsChangedEvent(DependencyPropertyChangedEventArgs e)
{
bool newSingle, oldSingle, newFacing, oldFacing, newScroll, oldScroll;
if (e.Property == FlowDocumentReader.IsPageViewEnabledProperty)
{
newSingle = (bool)e.NewValue;
oldSingle = (bool)e.OldValue;
newFacing = oldFacing = FlowDocumentReader.IsTwoPageViewEnabled;
newScroll = oldScroll = FlowDocumentReader.IsScrollViewEnabled;
}
else if (e.Property == FlowDocumentReader.IsTwoPageViewEnabledProperty)
{
newSingle = oldSingle = FlowDocumentReader.IsPageViewEnabled;
newFacing = (bool)e.NewValue;
oldFacing = (bool)e.OldValue;
newScroll = oldScroll = FlowDocumentReader.IsScrollViewEnabled;
}
else// if (e.Property == FlowDocumentReader.IsScrollViewEnabledProperty)
{
newSingle = oldSingle = FlowDocumentReader.IsPageViewEnabled;
newFacing = oldFacing = FlowDocumentReader.IsTwoPageViewEnabled;
newScroll = (bool)e.NewValue;
oldScroll = (bool)e.OldValue;
}
if (newSingle != oldSingle || newFacing != oldFacing || newScroll != oldScroll)
{
int[] newViews = GetSupportedViews(newSingle, newFacing, newScroll);
int[] oldViews = GetSupportedViews(oldSingle, oldFacing, oldScroll);
RaisePropertyChangedEvent(MultipleViewPatternIdentifiers.SupportedViewsProperty, newViews, oldViews);
}
}
//-------------------------------------------------------------------
//
// Private Members
//
//-------------------------------------------------------------------
#region Private Members
private int[] GetSupportedViews(bool single, bool facing, bool scroll)
{
int count = 0;
if (single) { count++; }
if (facing) { count++; }
if (scroll) { count++; }
int[] views = count > 0 ? new int[count] : null;
count = 0;
if (single) { views[count++] = ConvertModeToViewId(FlowDocumentReaderViewingMode.Page); }
if (facing) { views[count++] = ConvertModeToViewId(FlowDocumentReaderViewingMode.TwoPage); }
if (scroll) { views[count++] = ConvertModeToViewId(FlowDocumentReaderViewingMode.Scroll); }
return views;
}
///
/// Converts viewing mode to view id.
///
private int ConvertModeToViewId(FlowDocumentReaderViewingMode mode)
{
return (int)mode;
}
///
/// Converts view id to viewing mode.
///
private FlowDocumentReaderViewingMode ConvertViewIdToMode(int viewId)
{
Invariant.Assert(viewId >= 0 && viewId <= 2);
return (FlowDocumentReaderViewingMode)viewId;
}
///
/// FlowDocumentReader associated with the peer.
///
private FlowDocumentReader FlowDocumentReader
{
get { return (FlowDocumentReader)Owner; }
}
private DocumentAutomationPeer _documentPeer;
#endregion Private Members
//--------------------------------------------------------------------
//
// IMultipleViewProvider Members
//
//-------------------------------------------------------------------
#region IMultipleViewProvider Members
///
///
///
string IMultipleViewProvider.GetViewName(int viewId)
{
string name = string.Empty;
if (viewId >= 0 && viewId <= 2)
{
FlowDocumentReaderViewingMode mode = ConvertViewIdToMode(viewId);
if (mode == FlowDocumentReaderViewingMode.Page)
{
name = SR.Get(SRID.FlowDocumentReader_MultipleViewProvider_PageViewName);
}
else if (mode == FlowDocumentReaderViewingMode.TwoPage)
{
name = SR.Get(SRID.FlowDocumentReader_MultipleViewProvider_TwoPageViewName);
}
else if (mode == FlowDocumentReaderViewingMode.Scroll)
{
name = SR.Get(SRID.FlowDocumentReader_MultipleViewProvider_ScrollViewName);
}
}
return name;
}
///
///
///
void IMultipleViewProvider.SetCurrentView(int viewId)
{
if (viewId >= 0 && viewId <= 2)
{
FlowDocumentReader.ViewingMode = ConvertViewIdToMode(viewId);
}
}
///
///
///
int IMultipleViewProvider.CurrentView
{
get { return ConvertModeToViewId(FlowDocumentReader.ViewingMode); }
}
///
///
///
int[] IMultipleViewProvider.GetSupportedViews()
{
return GetSupportedViews(
FlowDocumentReader.IsPageViewEnabled,
FlowDocumentReader.IsTwoPageViewEnabled,
FlowDocumentReader.IsScrollViewEnabled);
}
#endregion IMultipleViewProvider Members
}
}
// 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.
//
// File: FlowDocumentReaderAutomationPeer.cs
//
// Description: AutomationPeer associated with FlowDocumentReader.
//
//---------------------------------------------------------------------------
using System.Collections.Generic; // List
using System.Windows.Automation.Provider; // IMultipleViewProvider
using System.Windows.Controls; // FlowDocumentReader
using System.Windows.Documents; // FlowDocument
using MS.Internal; // Invariant
namespace System.Windows.Automation.Peers
{
///
/// AutomationPeer associated with FlowDocumentScrollViewer.
///
public class FlowDocumentReaderAutomationPeer : FrameworkElementAutomationPeer, IMultipleViewProvider
{
///
/// Constructor.
///
/// Owner of the AutomationPeer.
public FlowDocumentReaderAutomationPeer(FlowDocumentReader owner)
: base(owner)
{ }
///
///
///
public override object GetPattern(PatternInterface patternInterface)
{
object returnValue = null;
if (patternInterface == PatternInterface.MultipleView)
{
returnValue = this;
}
else
{
returnValue = base.GetPattern(patternInterface);
}
return returnValue;
}
///
///
///
///
/// AutomationPeer associated with FlowDocumentScrollViewer returns an AutomationPeer
/// for hosted Document and for elements in the style.
///
protected override List GetChildrenCore()
{
// Get children for all elements in the style.
List children = base.GetChildrenCore();
// Add AutomationPeer associated with the document.
// Make it the first child of the collection.
FlowDocument document = ((FlowDocumentReader)Owner).Document;
if (document != null)
{
AutomationPeer documentPeer = ContentElementAutomationPeer.CreatePeerForElement(document);
if (_documentPeer != documentPeer)
{
if (_documentPeer != null)
{
_documentPeer.OnDisconnected();
}
_documentPeer = documentPeer as DocumentAutomationPeer;
}
if (documentPeer != null)
{
if (children == null)
{
children = new List();
}
children.Add(documentPeer);
}
}
return children;
}
///
///
///
protected override string GetClassNameCore()
{
return "FlowDocumentReader";
}
///
/// This helper synchronously fires automation PropertyChange event
/// in responce to current view mode change.
///
//
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
internal void RaiseCurrentViewChangedEvent(FlowDocumentReaderViewingMode newMode, FlowDocumentReaderViewingMode oldMode)
{
if (newMode != oldMode)
{
RaisePropertyChangedEvent(MultipleViewPatternIdentifiers.CurrentViewProperty,
ConvertModeToViewId(newMode), ConvertModeToViewId(oldMode));
}
}
///
/// This helper synchronously fires automation PropertyChange event
/// in responce to supported views change.
///
//
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
internal void RaiseSupportedViewsChangedEvent(DependencyPropertyChangedEventArgs e)
{
bool newSingle, oldSingle, newFacing, oldFacing, newScroll, oldScroll;
if (e.Property == FlowDocumentReader.IsPageViewEnabledProperty)
{
newSingle = (bool)e.NewValue;
oldSingle = (bool)e.OldValue;
newFacing = oldFacing = FlowDocumentReader.IsTwoPageViewEnabled;
newScroll = oldScroll = FlowDocumentReader.IsScrollViewEnabled;
}
else if (e.Property == FlowDocumentReader.IsTwoPageViewEnabledProperty)
{
newSingle = oldSingle = FlowDocumentReader.IsPageViewEnabled;
newFacing = (bool)e.NewValue;
oldFacing = (bool)e.OldValue;
newScroll = oldScroll = FlowDocumentReader.IsScrollViewEnabled;
}
else// if (e.Property == FlowDocumentReader.IsScrollViewEnabledProperty)
{
newSingle = oldSingle = FlowDocumentReader.IsPageViewEnabled;
newFacing = oldFacing = FlowDocumentReader.IsTwoPageViewEnabled;
newScroll = (bool)e.NewValue;
oldScroll = (bool)e.OldValue;
}
if (newSingle != oldSingle || newFacing != oldFacing || newScroll != oldScroll)
{
int[] newViews = GetSupportedViews(newSingle, newFacing, newScroll);
int[] oldViews = GetSupportedViews(oldSingle, oldFacing, oldScroll);
RaisePropertyChangedEvent(MultipleViewPatternIdentifiers.SupportedViewsProperty, newViews, oldViews);
}
}
//-------------------------------------------------------------------
//
// Private Members
//
//-------------------------------------------------------------------
#region Private Members
private int[] GetSupportedViews(bool single, bool facing, bool scroll)
{
int count = 0;
if (single) { count++; }
if (facing) { count++; }
if (scroll) { count++; }
int[] views = count > 0 ? new int[count] : null;
count = 0;
if (single) { views[count++] = ConvertModeToViewId(FlowDocumentReaderViewingMode.Page); }
if (facing) { views[count++] = ConvertModeToViewId(FlowDocumentReaderViewingMode.TwoPage); }
if (scroll) { views[count++] = ConvertModeToViewId(FlowDocumentReaderViewingMode.Scroll); }
return views;
}
///
/// Converts viewing mode to view id.
///
private int ConvertModeToViewId(FlowDocumentReaderViewingMode mode)
{
return (int)mode;
}
///
/// Converts view id to viewing mode.
///
private FlowDocumentReaderViewingMode ConvertViewIdToMode(int viewId)
{
Invariant.Assert(viewId >= 0 && viewId <= 2);
return (FlowDocumentReaderViewingMode)viewId;
}
///
/// FlowDocumentReader associated with the peer.
///
private FlowDocumentReader FlowDocumentReader
{
get { return (FlowDocumentReader)Owner; }
}
private DocumentAutomationPeer _documentPeer;
#endregion Private Members
//--------------------------------------------------------------------
//
// IMultipleViewProvider Members
//
//-------------------------------------------------------------------
#region IMultipleViewProvider Members
///
///
///
string IMultipleViewProvider.GetViewName(int viewId)
{
string name = string.Empty;
if (viewId >= 0 && viewId <= 2)
{
FlowDocumentReaderViewingMode mode = ConvertViewIdToMode(viewId);
if (mode == FlowDocumentReaderViewingMode.Page)
{
name = SR.Get(SRID.FlowDocumentReader_MultipleViewProvider_PageViewName);
}
else if (mode == FlowDocumentReaderViewingMode.TwoPage)
{
name = SR.Get(SRID.FlowDocumentReader_MultipleViewProvider_TwoPageViewName);
}
else if (mode == FlowDocumentReaderViewingMode.Scroll)
{
name = SR.Get(SRID.FlowDocumentReader_MultipleViewProvider_ScrollViewName);
}
}
return name;
}
///
///
///
void IMultipleViewProvider.SetCurrentView(int viewId)
{
if (viewId >= 0 && viewId <= 2)
{
FlowDocumentReader.ViewingMode = ConvertViewIdToMode(viewId);
}
}
///
///
///
int IMultipleViewProvider.CurrentView
{
get { return ConvertModeToViewId(FlowDocumentReader.ViewingMode); }
}
///
///
///
int[] IMultipleViewProvider.GetSupportedViews()
{
return GetSupportedViews(
FlowDocumentReader.IsPageViewEnabled,
FlowDocumentReader.IsTwoPageViewEnabled,
FlowDocumentReader.IsScrollViewEnabled);
}
#endregion IMultipleViewProvider Members
}
}
// 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
- ColumnTypeConverter.cs
- Storyboard.cs
- TextProperties.cs
- WindowsProgressbar.cs
- IndexedGlyphRun.cs
- SessionStateModule.cs
- Unit.cs
- AffineTransform3D.cs
- CaseExpr.cs
- NamespaceInfo.cs
- XAMLParseException.cs
- XmlTypeAttribute.cs
- SqlUDTStorage.cs
- SchemaInfo.cs
- CacheAxisQuery.cs
- FutureFactory.cs
- HostVisual.cs
- WebBaseEventKeyComparer.cs
- CompositeTypefaceMetrics.cs
- ReadWriteObjectLock.cs
- ChildDocumentBlock.cs
- JoinSymbol.cs
- HttpPostedFile.cs
- DataColumn.cs
- OleDbPermission.cs
- FunctionNode.cs
- ContentControl.cs
- DesignerFrame.cs
- OracleConnectionFactory.cs
- WindowsScrollBarBits.cs
- ButtonFieldBase.cs
- DLinqColumnProvider.cs
- MissingMemberException.cs
- EventToken.cs
- ZipPackagePart.cs
- Attributes.cs
- NotifyParentPropertyAttribute.cs
- DuplicateWaitObjectException.cs
- Utils.cs
- SoapReflectionImporter.cs
- HttpPostProtocolReflector.cs
- PersistenceTypeAttribute.cs
- OdbcConnectionStringbuilder.cs
- safex509handles.cs
- MethodToken.cs
- StatusCommandUI.cs
- DesigntimeLicenseContextSerializer.cs
- ObjectCache.cs
- WebPartVerb.cs
- TargetControlTypeCache.cs
- SiteMapPath.cs
- CoreSwitches.cs
- ObjectResult.cs
- Substitution.cs
- GacUtil.cs
- ToolStripDropDownItem.cs
- StrokeCollectionConverter.cs
- SBCSCodePageEncoding.cs
- DebugControllerThread.cs
- CounterSetInstance.cs
- QueryAccessibilityHelpEvent.cs
- DataSourceListEditor.cs
- AssemblyUtil.cs
- PaintValueEventArgs.cs
- SqlBulkCopy.cs
- MissingFieldException.cs
- InternalEnumValidatorAttribute.cs
- ProfileBuildProvider.cs
- DataViewSettingCollection.cs
- OrthographicCamera.cs
- StickyNote.cs
- ToolStripSplitStackLayout.cs
- ArgumentOutOfRangeException.cs
- InkCanvas.cs
- CollectionChangeEventArgs.cs
- DoubleLinkList.cs
- QueryExpr.cs
- PropertyIDSet.cs
- GetPageNumberCompletedEventArgs.cs
- CheckBoxField.cs
- TrustLevelCollection.cs
- ADMembershipProvider.cs
- SplitContainerDesigner.cs
- ColorPalette.cs
- ImageMap.cs
- ClusterRegistryConfigurationProvider.cs
- CollectionDataContract.cs
- FontStyle.cs
- ConfigurationManagerHelper.cs
- GregorianCalendar.cs
- SimpleRecyclingCache.cs
- MimeMapping.cs
- ConfigurationElementCollection.cs
- _ShellExpression.cs
- BitmapVisualManager.cs
- KeyConstraint.cs
- XPathParser.cs
- sqlcontext.cs
- EntityDataSourceEntityTypeFilterConverter.cs
- DataContractJsonSerializerOperationBehavior.cs