Code:
/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / Orcas / QFE / wpf / src / Framework / MS / Internal / PtsHost / PageVisual.cs / 1 / PageVisual.cs
//----------------------------------------------------------------------------
//
// Copyright (C) Microsoft Corporation. All rights reserved.
//
// File: PageVisual.cs
//
// Description: Visual representing a PTS page.
//
// History:
// 11/11/2003 : grzegorz - created.
//
//---------------------------------------------------------------------------
using System;
using System.Diagnostics;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Threading;
namespace MS.Internal.PtsHost
{
// ---------------------------------------------------------------------
// Visual representing a PTS page.
// ---------------------------------------------------------------------
internal class PageVisual : DrawingVisual, IContentHost
{
// ------------------------------------------------------------------
// Create a visual representing a PTS page.
// -----------------------------------------------------------------
internal PageVisual(FlowDocumentPage owner)
{
_owner = new WeakReference(owner);
}
// ------------------------------------------------------------------
// Set information about background that is necessary for rendering
// process.
//
// backgroundBrush - The background brush used for background.
// renderBounds - Render bounds of the visual.
// ------------------------------------------------------------------
internal void DrawBackground(Brush backgroundBrush, Rect renderBounds)
{
if (_backgroundBrush != backgroundBrush || _renderBounds != renderBounds)
{
_backgroundBrush = backgroundBrush;
_renderBounds = renderBounds;
// Open DrawingContext and draw background.
// If background is not set, Open will clean the render data, but it
// will preserve visual children.
using (DrawingContext dc = RenderOpen())
{
if (_backgroundBrush != null)
{
dc.DrawRectangle(_backgroundBrush, null, _renderBounds);
}
else
{
dc.DrawRectangle(Brushes.Transparent, null, _renderBounds);
}
}
}
}
// -----------------------------------------------------------------
// Get/Set visual child.
// ------------------------------------------------------------------
internal Visual Child
{
get
{
VisualCollection vc = this.Children;
Debug.Assert(vc.Count <= 1);
return (vc.Count == 0) ? null : vc[0];
}
set
{
VisualCollection vc = this.Children;
Debug.Assert(vc.Count <= 1);
if (vc.Count == 0)
{
vc.Add(value);
}
else if (vc[0] != value)
{
vc[0] = value;
}
// else Visual child is the same as already stored; do nothing.
}
}
// -----------------------------------------------------------------
// Clear its DrawingContext
// Opening and closing a DrawingContext, clears it.
// -----------------------------------------------------------------
internal void ClearDrawingContext()
{
DrawingContext ctx = this.RenderOpen();
if(ctx != null)
ctx.Close();
}
//-------------------------------------------------------------------
//
// IContentHost Members
//
//--------------------------------------------------------------------
#region IContentHost Members
///
///
///
IInputElement IContentHost.InputHitTest(Point point)
{
IContentHost host = _owner.Target as IContentHost;
if (host != null)
{
return host.InputHitTest(point);
}
return null;
}
///
///
///
ReadOnlyCollection IContentHost.GetRectangles(ContentElement child)
{
IContentHost host = _owner.Target as IContentHost;
if (host != null)
{
return host.GetRectangles(child);
}
return new ReadOnlyCollection(new List(0));
}
///
///
///
IEnumerator IContentHost.HostedElements
{
get
{
IContentHost host = _owner.Target as IContentHost;
if (host != null)
{
return host.HostedElements;
}
return null;
}
}
///
///
///
void IContentHost.OnChildDesiredSizeChanged(UIElement child)
{
IContentHost host = _owner.Target as IContentHost;
if (host != null)
{
host.OnChildDesiredSizeChanged(child);
}
}
#endregion IContentHost Members
// -----------------------------------------------------------------
// Reference to DocumentPage that owns this visual.
// ------------------------------------------------------------------
private readonly WeakReference _owner;
// ------------------------------------------------------------------
// Brush used for background rendering.
// -----------------------------------------------------------------
private Brush _backgroundBrush;
// ------------------------------------------------------------------
// Render bounds.
// -----------------------------------------------------------------
private Rect _renderBounds;
}
}
// 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: PageVisual.cs
//
// Description: Visual representing a PTS page.
//
// History:
// 11/11/2003 : grzegorz - created.
//
//---------------------------------------------------------------------------
using System;
using System.Diagnostics;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Threading;
namespace MS.Internal.PtsHost
{
// ---------------------------------------------------------------------
// Visual representing a PTS page.
// ---------------------------------------------------------------------
internal class PageVisual : DrawingVisual, IContentHost
{
// ------------------------------------------------------------------
// Create a visual representing a PTS page.
// -----------------------------------------------------------------
internal PageVisual(FlowDocumentPage owner)
{
_owner = new WeakReference(owner);
}
// ------------------------------------------------------------------
// Set information about background that is necessary for rendering
// process.
//
// backgroundBrush - The background brush used for background.
// renderBounds - Render bounds of the visual.
// ------------------------------------------------------------------
internal void DrawBackground(Brush backgroundBrush, Rect renderBounds)
{
if (_backgroundBrush != backgroundBrush || _renderBounds != renderBounds)
{
_backgroundBrush = backgroundBrush;
_renderBounds = renderBounds;
// Open DrawingContext and draw background.
// If background is not set, Open will clean the render data, but it
// will preserve visual children.
using (DrawingContext dc = RenderOpen())
{
if (_backgroundBrush != null)
{
dc.DrawRectangle(_backgroundBrush, null, _renderBounds);
}
else
{
dc.DrawRectangle(Brushes.Transparent, null, _renderBounds);
}
}
}
}
// -----------------------------------------------------------------
// Get/Set visual child.
// ------------------------------------------------------------------
internal Visual Child
{
get
{
VisualCollection vc = this.Children;
Debug.Assert(vc.Count <= 1);
return (vc.Count == 0) ? null : vc[0];
}
set
{
VisualCollection vc = this.Children;
Debug.Assert(vc.Count <= 1);
if (vc.Count == 0)
{
vc.Add(value);
}
else if (vc[0] != value)
{
vc[0] = value;
}
// else Visual child is the same as already stored; do nothing.
}
}
// -----------------------------------------------------------------
// Clear its DrawingContext
// Opening and closing a DrawingContext, clears it.
// -----------------------------------------------------------------
internal void ClearDrawingContext()
{
DrawingContext ctx = this.RenderOpen();
if(ctx != null)
ctx.Close();
}
//-------------------------------------------------------------------
//
// IContentHost Members
//
//--------------------------------------------------------------------
#region IContentHost Members
///
///
///
IInputElement IContentHost.InputHitTest(Point point)
{
IContentHost host = _owner.Target as IContentHost;
if (host != null)
{
return host.InputHitTest(point);
}
return null;
}
///
///
///
ReadOnlyCollection IContentHost.GetRectangles(ContentElement child)
{
IContentHost host = _owner.Target as IContentHost;
if (host != null)
{
return host.GetRectangles(child);
}
return new ReadOnlyCollection(new List(0));
}
///
///
///
IEnumerator IContentHost.HostedElements
{
get
{
IContentHost host = _owner.Target as IContentHost;
if (host != null)
{
return host.HostedElements;
}
return null;
}
}
///
///
///
void IContentHost.OnChildDesiredSizeChanged(UIElement child)
{
IContentHost host = _owner.Target as IContentHost;
if (host != null)
{
host.OnChildDesiredSizeChanged(child);
}
}
#endregion IContentHost Members
// -----------------------------------------------------------------
// Reference to DocumentPage that owns this visual.
// ------------------------------------------------------------------
private readonly WeakReference _owner;
// ------------------------------------------------------------------
// Brush used for background rendering.
// -----------------------------------------------------------------
private Brush _backgroundBrush;
// ------------------------------------------------------------------
// Render bounds.
// -----------------------------------------------------------------
private Rect _renderBounds;
}
}
// 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
- ActivationServices.cs
- StringDictionaryEditor.cs
- InputReferenceExpression.cs
- TableLayoutStyle.cs
- HitTestResult.cs
- CommentGlyph.cs
- OdbcPermission.cs
- NonParentingControl.cs
- AssemblyAttributes.cs
- TextBox.cs
- ShortcutKeysEditor.cs
- SessionPageStateSection.cs
- RouteValueDictionary.cs
- CommandID.cs
- PermissionToken.cs
- CannotUnloadAppDomainException.cs
- EdmComplexTypeAttribute.cs
- StreamFormatter.cs
- VirtualPathProvider.cs
- LineProperties.cs
- RichTextBox.cs
- TitleStyle.cs
- JournalEntry.cs
- DataGridViewButtonColumn.cs
- SqlConnectionPoolGroupProviderInfo.cs
- Vector3DCollectionConverter.cs
- AuthenticatingEventArgs.cs
- Roles.cs
- SolidBrush.cs
- WebPartAddingEventArgs.cs
- SafeNativeMethods.cs
- JavaScriptObjectDeserializer.cs
- SoapInteropTypes.cs
- FixedBufferAttribute.cs
- ProviderIncompatibleException.cs
- GridViewUpdatedEventArgs.cs
- SocketElement.cs
- XmlSchemaSimpleTypeUnion.cs
- Policy.cs
- CompModSwitches.cs
- DependencyPropertyConverter.cs
- ServiceModelConfigurationSection.cs
- SerializationEventsCache.cs
- CalendarKeyboardHelper.cs
- DataServiceRequestOfT.cs
- WindowsUserNameSecurityTokenAuthenticator.cs
- ListControlStringCollectionEditor.cs
- DataObjectCopyingEventArgs.cs
- BaseParser.cs
- AnnouncementInnerClient11.cs
- DataGridViewTextBoxEditingControl.cs
- ReachFixedPageSerializer.cs
- SpecialFolderEnumConverter.cs
- HWStack.cs
- ClientApiGenerator.cs
- ApplicationTrust.cs
- FormViewPageEventArgs.cs
- ConnectionConsumerAttribute.cs
- ManagedCodeMarkers.cs
- parserscommon.cs
- ApplicationProxyInternal.cs
- SchemaConstraints.cs
- DataContractSet.cs
- RuntimeHelpers.cs
- FilterableAttribute.cs
- UndoUnit.cs
- SplineKeyFrames.cs
- OutOfMemoryException.cs
- InstanceDataCollection.cs
- arabicshape.cs
- Utils.cs
- FrameworkContentElement.cs
- XmlComment.cs
- DNS.cs
- HtmlInputText.cs
- SystemException.cs
- WindowsListViewItemCheckBox.cs
- WebBrowserContainer.cs
- SimpleBitVector32.cs
- LogicalExpressionEditor.cs
- RuntimeWrappedException.cs
- SchemaImporterExtensionElement.cs
- ContentPosition.cs
- AnnotationHelper.cs
- FacetDescription.cs
- DirtyTextRange.cs
- DesignerAttribute.cs
- SelectedDatesCollection.cs
- ConstantSlot.cs
- MenuItemStyleCollection.cs
- COM2ICategorizePropertiesHandler.cs
- ToolStripItemTextRenderEventArgs.cs
- FixedNode.cs
- ImageMap.cs
- _SslState.cs
- FormsAuthenticationTicket.cs
- CompiledIdentityConstraint.cs
- IncomingWebResponseContext.cs
- ObjectSet.cs
- DecoderExceptionFallback.cs