Code:
/ DotNET / DotNET / 8.0 / untmp / WIN_WINDOWS / lh_tools_devdiv_wpf / Windows / wcp / Print / Reach / Serialization / manager / ReachVisualSerializer.cs / 1 / ReachVisualSerializer.cs
/*++
Copyright (C) 2004- 2005 Microsoft Corporation
All rights reserved.
Module Name:
ReachVisualSerializer.cs
Abstract:
Author:
[....] ([....]) 1-December-2004
Revision History:
--*/
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Diagnostics;
using System.Reflection;
using System.Xml;
using System.IO;
using System.Security;
using System.Security.Permissions;
using System.ComponentModel.Design.Serialization;
using System.Windows.Xps.Packaging;
using System.Windows.Documents;
using System.Windows.Media;
using System.Windows.Media.Media3D;
using System.Windows.Markup;
namespace System.Windows.Xps.Serialization
{
///
///
///
internal class ReachVisualSerializer :
ReachSerializer
{
///
///
///
public
ReachVisualSerializer(
PackageSerializationManager manager
):
base(manager)
{
}
///
///
///
public
override
void
SerializeObject(
object serializedObject
)
{
Visual v = serializedObject as Visual;
if (v == null)
{
throw new ArgumentException(ReachSR.Get(ReachSRID.MustBeOfType, "serializedObject", typeof(Visual)));
}
XmlWriter pageWriter = ((XpsSerializationManager)SerializationManager).
PackagingPolicy.AcquireXmlWriterForPage();
XmlWriter resWriter = ((XpsSerializationManager)SerializationManager).
PackagingPolicy.AcquireXmlWriterForResourceDictionary();
SerializeTree(v, resWriter, pageWriter);
}
///
///
///
internal
override
void
SerializeObject(
SerializablePropertyContext serializedProperty
)
{
//
// Do nothing here.
// We do not support serializing visuals that come in as
// properties out of context of a FixedPage or a DocumentPage
//
}
private
void
SerializeTree(
Visual visual,
XmlWriter resWriter,
XmlWriter bodyWriter
)
{
Toolbox.StartEvent(Toolbox.DRXSERIALIZETREEGUID);
Size fixedPageSize = ((XpsSerializationManager)SerializationManager).FixedPageSize;
VisualTreeFlattener flattener = ((XpsSerializationManager)SerializationManager).
VisualSerializationService.AcquireVisualTreeFlattener(resWriter,
bodyWriter,
fixedPageSize);
Stack contextStack = new Stack();
if (flattener.StartVisual(visual))
{
contextStack.Push(new NodeContext(visual));
}
while (contextStack.Count > 0)
{
NodeContext ctx = contextStack.Peek();
Visual v = ctx.GetNextChild();
if (v != null)
{
if (flattener.StartVisual(v))
{
contextStack.Push(new NodeContext(v));
}
}
else
{
contextStack.Pop();
flattener.EndVisual();
}
}
Toolbox.EndEvent(Toolbox.DRXSERIALIZETREEGUID);
}
///
///
///
internal
override
void
PersistObjectData(
SerializableObjectContext serializableObjectContext
)
{
//
// Do nothing here
//
}
///
///
///
public
override
XmlWriter
XmlWriter
{
get
{
if(base.XmlWriter == null)
{
base.XmlWriter = SerializationManager.AcquireXmlWriter(typeof(FixedPage));
}
return base.XmlWriter;
}
set
{
base.XmlWriter = null;
SerializationManager.ReleaseXmlWriter(typeof(FixedPage));
}
}
#region Internal Methods
///
///
///
internal
bool
SerializeDisguisedVisual(
object serializedObject
)
{
Visual v = serializedObject as Visual;
if (v == null)
{
throw new ArgumentException(ReachSR.Get(ReachSRID.MustBeOfType, "serializedObject", typeof(Visual)));
}
XmlWriter pageWriter = ((XpsSerializationManager)SerializationManager).
PackagingPolicy.AcquireXmlWriterForPage();
XmlWriter resWriter = ((XpsSerializationManager)SerializationManager).
PackagingPolicy.AcquireXmlWriterForResourceDictionary();
Size fixedPageSize = ((XpsSerializationManager)SerializationManager).FixedPageSize;
VisualTreeFlattener flattener = ((XpsSerializationManager)SerializationManager).
VisualSerializationService.AcquireVisualTreeFlattener(resWriter,
pageWriter,
fixedPageSize);
return flattener.StartVisual(v);
}
#endregion Internal Methods
};
class NodeContext
{
#region Constructor
public NodeContext(Visual v)
{
nodeVisual = v;
index = 0;
}
#endregion Constructor
#region Public properties
public Visual NodeVisual
{
get
{
return nodeVisual;
}
}
#endregion Public properties
#region Public methods
public Visual GetNextChild()
{
Visual child = null;
if (index < VisualTreeHelper.GetChildrenCount(nodeVisual))
{
// VisualTreeFlattener will flatten Viewport3DVisual into an image. We shouldn't
// be attempting to walk Visual3D children.
child = (Visual) VisualTreeHelper.GetChild(nodeVisual, index);
index++;
}
return child;
}
#endregion Public methods
#region Private data
private Visual nodeVisual;
private int index;
#endregion Private data
}
}
// 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
- ClientSponsor.cs
- SyntaxCheck.cs
- ListenerElementsCollection.cs
- ObjectPersistData.cs
- EntityWithKeyStrategy.cs
- DBCSCodePageEncoding.cs
- ToolboxControl.cs
- DataGridItemEventArgs.cs
- TypePropertyEditor.cs
- BasePropertyDescriptor.cs
- AdRotator.cs
- HashCodeCombiner.cs
- validation.cs
- BitmapDownload.cs
- UITypeEditor.cs
- ProcessStartInfo.cs
- WorkerRequest.cs
- WebPartMenuStyle.cs
- Trace.cs
- DesignerTransactionCloseEvent.cs
- CalculatedColumn.cs
- SafeRightsManagementSessionHandle.cs
- ControlPaint.cs
- DoubleLinkListEnumerator.cs
- CDSsyncETWBCLProvider.cs
- OdbcParameterCollection.cs
- FacetChecker.cs
- Request.cs
- _NetRes.cs
- TogglePatternIdentifiers.cs
- CodeTypeOfExpression.cs
- HexParser.cs
- RawMouseInputReport.cs
- EntityFunctions.cs
- ConfigurationProperty.cs
- HttpMethodConstraint.cs
- SelectionHighlightInfo.cs
- BStrWrapper.cs
- PersonalizationStateQuery.cs
- DateTime.cs
- ProcessInfo.cs
- AsymmetricSecurityBindingElement.cs
- ReflectionHelper.cs
- ObjectDataSourceDisposingEventArgs.cs
- TableLayoutStyleCollection.cs
- TreeViewImageKeyConverter.cs
- UnsafeCollabNativeMethods.cs
- TTSEngineTypes.cs
- MenuItemBindingCollection.cs
- Activation.cs
- EntitySetRetriever.cs
- Expression.cs
- panel.cs
- WebPartActionVerb.cs
- DbXmlEnabledProviderManifest.cs
- ComboBoxRenderer.cs
- BitmapEffectOutputConnector.cs
- AttachmentCollection.cs
- CodeSnippetExpression.cs
- AssociationProvider.cs
- EnumBuilder.cs
- WSSecurityOneDotZeroSendSecurityHeader.cs
- ExtentCqlBlock.cs
- ModuleBuilder.cs
- ProgressiveCrcCalculatingStream.cs
- NonClientArea.cs
- CapabilitiesState.cs
- storagemappingitemcollection.viewdictionary.cs
- ObjectViewFactory.cs
- GlobalProxySelection.cs
- XmlValidatingReader.cs
- KeyEventArgs.cs
- TextElementCollectionHelper.cs
- ControlCachePolicy.cs
- ResourceAttributes.cs
- DrawingBrush.cs
- StrongNameMembershipCondition.cs
- IdentifierCreationService.cs
- WindowsFormsHost.cs
- SrgsOneOf.cs
- FontFamilyConverter.cs
- XamlFigureLengthSerializer.cs
- ScriptControlManager.cs
- DoubleSumAggregationOperator.cs
- FormsAuthenticationUserCollection.cs
- ClientTargetCollection.cs
- MailWebEventProvider.cs
- Int32AnimationBase.cs
- DataGridRowDetailsEventArgs.cs
- LinearGradientBrush.cs
- UIPermission.cs
- ListDictionary.cs
- DescendentsWalkerBase.cs
- CheckBoxRenderer.cs
- Hyperlink.cs
- PrintPreviewDialog.cs
- StructuredType.cs
- IHttpResponseInternal.cs
- DBSqlParser.cs
- ColumnPropertiesGroup.cs