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 / Controls / InkCanvasFeedbackAdorner.cs / 1 / InkCanvasFeedbackAdorner.cs
//----------------------------------------------------------------------------
//
// File: InkCanvasFeedbackAdorner.cs
//
// Description:
// A class which is used as the feedback adorner of the InkCanvas selection
//
// Features:
//
// History:
// 1/27/2005 waynezen: Created
//
// Copyright (C) 2001 by Microsoft Corporation. All rights reserved.
//
//---------------------------------------------------------------------------
using MS.Internal;
using System;
using System.Diagnostics;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Media;
namespace MS.Internal.Controls
{
///
/// InkCanvasFeedbackAdorner
///
internal class InkCanvasFeedbackAdorner : Adorner
{
// No default constructor
private InkCanvasFeedbackAdorner() : base (null) { }
///
/// InkCanvasFeedbackAdorner Constructor
///
/// The adorned InkCanvas
internal InkCanvasFeedbackAdorner(InkCanvas inkCanvas)
: base(( inkCanvas != null ? inkCanvas.InnerCanvas : null ))
{
if ( inkCanvas == null )
throw new ArgumentNullException("inkCanvas");
// Initialize the internal data
_inkCanvas = inkCanvas;
_adornerBorderPen = new Pen(Brushes.Black, 1.0);
DoubleCollection dashes = new DoubleCollection( );
dashes.Add(4.5);
dashes.Add(4.5);
_adornerBorderPen.DashStyle = new DashStyle(dashes, 2.25);
_adornerBorderPen.DashCap = PenLineCap.Flat;
}
///
/// The overridden GetDesiredTransform method
///
public override GeneralTransform GetDesiredTransform(GeneralTransform transform)
{
if ( transform == null )
{
throw new ArgumentNullException("transform");
}
VerifyAccess();
GeneralTransformGroup desiredTransform = new GeneralTransformGroup();
desiredTransform.Children.Add(transform);
// Check if we need translate the adorner.
if ( !DoubleUtil.AreClose(_offsetX, 0) || !DoubleUtil.AreClose(_offsetY, 0) )
{
desiredTransform.Children.Add(new TranslateTransform(_offsetX, _offsetY));
}
return desiredTransform;
}
///
/// The OnBoundsUpdated method
///
///
private void OnBoundsUpdated(Rect rect)
{
VerifyAccess();
// Check if the rectangle has been changed.
if ( rect != _previousRect )
{
Size newSize;
double offsetX;
double offsetY;
bool invalidArrange = false;
if ( !rect.IsEmpty )
{
double offset = BorderMargin + CornerResizeHandleSize / 2;
Rect adornerRect = Rect.Inflate(rect, offset, offset);
newSize = new Size(adornerRect.Width, adornerRect.Height);
offsetX = adornerRect.Left;
offsetY = adornerRect.Top;
}
else
{
newSize = new Size(0, 0);
offsetX = 0;
offsetY = 0;
}
// Check if the size has been changed
if ( _frameSize != newSize )
{
_frameSize = newSize;
invalidArrange = true;
}
if ( !DoubleUtil.AreClose(_offsetX, offsetX) || !DoubleUtil.AreClose(_offsetY, offsetY) )
{
_offsetX = offsetX;
_offsetY = offsetY;
invalidArrange = true;
}
if ( invalidArrange )
{
InvalidateMeasure();
InvalidateVisual(); //ensure re-rendering
UIElement parent = ((UIElement)VisualTreeHelper.GetParent(this)) as UIElement;
if ( parent != null )
{
( (UIElement)VisualTreeHelper.GetParent(this) ).InvalidateArrange( );
}
}
_previousRect = rect;
}
}
///
/// The overridden MeasureOverride method
///
///
protected override Size MeasureOverride(Size constraint)
{
VerifyAccess();
// return the frame size.
return _frameSize;
}
///
/// The overridden OnRender method
///
///
protected override void OnRender(DrawingContext drawingContext)
{
// No need to invoke VerifyAccess since this method calls DrawingContext.DrawRectangle.
Debug.Assert(_frameSize != new Size(0, 0));
// Draw the wire frame.
drawingContext.DrawRectangle(null, _adornerBorderPen,
new Rect(CornerResizeHandleSize / 2, CornerResizeHandleSize / 2,
_frameSize.Width - CornerResizeHandleSize, _frameSize.Height - CornerResizeHandleSize));
}
///
/// The method is called by InkCanvasSelection.UpdateFeedbackRect
///
///
internal void UpdateBounds(Rect rect)
{
// Invoke OnBoundsUpdated.
OnBoundsUpdated(rect);
}
private InkCanvas _inkCanvas;
private Size _frameSize = new Size(0, 0);
private Rect _previousRect = Rect.Empty;
private double _offsetX = 0;
private double _offsetY = 0;
private Pen _adornerBorderPen;
private const int CornerResizeHandleSize = 8;
private const double BorderMargin = 8f;
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
//----------------------------------------------------------------------------
//
// File: InkCanvasFeedbackAdorner.cs
//
// Description:
// A class which is used as the feedback adorner of the InkCanvas selection
//
// Features:
//
// History:
// 1/27/2005 waynezen: Created
//
// Copyright (C) 2001 by Microsoft Corporation. All rights reserved.
//
//---------------------------------------------------------------------------
using MS.Internal;
using System;
using System.Diagnostics;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Media;
namespace MS.Internal.Controls
{
///
/// InkCanvasFeedbackAdorner
///
internal class InkCanvasFeedbackAdorner : Adorner
{
// No default constructor
private InkCanvasFeedbackAdorner() : base (null) { }
///
/// InkCanvasFeedbackAdorner Constructor
///
/// The adorned InkCanvas
internal InkCanvasFeedbackAdorner(InkCanvas inkCanvas)
: base(( inkCanvas != null ? inkCanvas.InnerCanvas : null ))
{
if ( inkCanvas == null )
throw new ArgumentNullException("inkCanvas");
// Initialize the internal data
_inkCanvas = inkCanvas;
_adornerBorderPen = new Pen(Brushes.Black, 1.0);
DoubleCollection dashes = new DoubleCollection( );
dashes.Add(4.5);
dashes.Add(4.5);
_adornerBorderPen.DashStyle = new DashStyle(dashes, 2.25);
_adornerBorderPen.DashCap = PenLineCap.Flat;
}
///
/// The overridden GetDesiredTransform method
///
public override GeneralTransform GetDesiredTransform(GeneralTransform transform)
{
if ( transform == null )
{
throw new ArgumentNullException("transform");
}
VerifyAccess();
GeneralTransformGroup desiredTransform = new GeneralTransformGroup();
desiredTransform.Children.Add(transform);
// Check if we need translate the adorner.
if ( !DoubleUtil.AreClose(_offsetX, 0) || !DoubleUtil.AreClose(_offsetY, 0) )
{
desiredTransform.Children.Add(new TranslateTransform(_offsetX, _offsetY));
}
return desiredTransform;
}
///
/// The OnBoundsUpdated method
///
///
private void OnBoundsUpdated(Rect rect)
{
VerifyAccess();
// Check if the rectangle has been changed.
if ( rect != _previousRect )
{
Size newSize;
double offsetX;
double offsetY;
bool invalidArrange = false;
if ( !rect.IsEmpty )
{
double offset = BorderMargin + CornerResizeHandleSize / 2;
Rect adornerRect = Rect.Inflate(rect, offset, offset);
newSize = new Size(adornerRect.Width, adornerRect.Height);
offsetX = adornerRect.Left;
offsetY = adornerRect.Top;
}
else
{
newSize = new Size(0, 0);
offsetX = 0;
offsetY = 0;
}
// Check if the size has been changed
if ( _frameSize != newSize )
{
_frameSize = newSize;
invalidArrange = true;
}
if ( !DoubleUtil.AreClose(_offsetX, offsetX) || !DoubleUtil.AreClose(_offsetY, offsetY) )
{
_offsetX = offsetX;
_offsetY = offsetY;
invalidArrange = true;
}
if ( invalidArrange )
{
InvalidateMeasure();
InvalidateVisual(); //ensure re-rendering
UIElement parent = ((UIElement)VisualTreeHelper.GetParent(this)) as UIElement;
if ( parent != null )
{
( (UIElement)VisualTreeHelper.GetParent(this) ).InvalidateArrange( );
}
}
_previousRect = rect;
}
}
///
/// The overridden MeasureOverride method
///
///
protected override Size MeasureOverride(Size constraint)
{
VerifyAccess();
// return the frame size.
return _frameSize;
}
///
/// The overridden OnRender method
///
///
protected override void OnRender(DrawingContext drawingContext)
{
// No need to invoke VerifyAccess since this method calls DrawingContext.DrawRectangle.
Debug.Assert(_frameSize != new Size(0, 0));
// Draw the wire frame.
drawingContext.DrawRectangle(null, _adornerBorderPen,
new Rect(CornerResizeHandleSize / 2, CornerResizeHandleSize / 2,
_frameSize.Width - CornerResizeHandleSize, _frameSize.Height - CornerResizeHandleSize));
}
///
/// The method is called by InkCanvasSelection.UpdateFeedbackRect
///
///
internal void UpdateBounds(Rect rect)
{
// Invoke OnBoundsUpdated.
OnBoundsUpdated(rect);
}
private InkCanvas _inkCanvas;
private Size _frameSize = new Size(0, 0);
private Rect _previousRect = Rect.Empty;
private double _offsetX = 0;
private double _offsetY = 0;
private Pen _adornerBorderPen;
private const int CornerResizeHandleSize = 8;
private const double BorderMargin = 8f;
}
}
// 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
- KeyProperty.cs
- RegistryPermission.cs
- Constants.cs
- Queue.cs
- ValidationRuleCollection.cs
- DBAsyncResult.cs
- DeploymentSection.cs
- NonBatchDirectoryCompiler.cs
- SpellerHighlightLayer.cs
- DataListItem.cs
- HttpResponse.cs
- HttpPostedFile.cs
- AsyncStreamReader.cs
- WebServiceClientProxyGenerator.cs
- basenumberconverter.cs
- CacheOutputQuery.cs
- ViewStateChangedEventArgs.cs
- Int16AnimationBase.cs
- OleDbInfoMessageEvent.cs
- SimpleHandlerBuildProvider.cs
- WaitHandleCannotBeOpenedException.cs
- ListDataBindEventArgs.cs
- Icon.cs
- FileFormatException.cs
- PackageRelationship.cs
- SqlExpander.cs
- PropertyDescriptor.cs
- ToolStripItemEventArgs.cs
- SoapReflectionImporter.cs
- PolicyConversionContext.cs
- InProcStateClientManager.cs
- log.cs
- MetabaseServerConfig.cs
- ConstraintManager.cs
- DelegateBodyWriter.cs
- ProfileSettings.cs
- _KerberosClient.cs
- TdsParserStaticMethods.cs
- _BaseOverlappedAsyncResult.cs
- LayoutEditorPart.cs
- Label.cs
- StringConverter.cs
- OleDbWrapper.cs
- DocumentsTrace.cs
- _ChunkParse.cs
- SearchForVirtualItemEventArgs.cs
- BitmapVisualManager.cs
- XmlDocumentFragment.cs
- ServerIdentity.cs
- ListCollectionView.cs
- RuntimeConfigurationRecord.cs
- XmlArrayItemAttribute.cs
- DataObjectFieldAttribute.cs
- TextEndOfSegment.cs
- TableItemProviderWrapper.cs
- XmlQueryOutput.cs
- ResourcesBuildProvider.cs
- TableItemPatternIdentifiers.cs
- util.cs
- DataSourceCacheDurationConverter.cs
- OutgoingWebResponseContext.cs
- AppLevelCompilationSectionCache.cs
- CachedBitmap.cs
- Int32AnimationBase.cs
- DesignerView.xaml.cs
- SecurityPolicySection.cs
- JavascriptXmlWriterWrapper.cs
- HttpDigestClientElement.cs
- SrgsSemanticInterpretationTag.cs
- ResetableIterator.cs
- RSAOAEPKeyExchangeFormatter.cs
- Expression.DebuggerProxy.cs
- BookmarkWorkItem.cs
- PageAsyncTaskManager.cs
- WinEventQueueItem.cs
- DataControlCommands.cs
- ControlBuilderAttribute.cs
- dataobject.cs
- MultipleViewPattern.cs
- Transform.cs
- CatalogZone.cs
- FixedSOMElement.cs
- GPRECTF.cs
- XslAst.cs
- followingsibling.cs
- Brushes.cs
- DesignerTransaction.cs
- ConfigurationLockCollection.cs
- TextRange.cs
- Int64Animation.cs
- DefinitionBase.cs
- autovalidator.cs
- DummyDataSource.cs
- HandlerMappingMemo.cs
- ParameterCollection.cs
- QilCloneVisitor.cs
- dbenumerator.cs
- XmlSerializerSection.cs
- Utils.cs
- DocumentXPathNavigator.cs