Code:
/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / NetFx40 / Tools / System.Activities.Core.Presentation / System / Activities / Core / Presentation / ConnectionPoint.cs / 1305376 / ConnectionPoint.cs
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------
namespace System.Activities.Core.Presentation
{
using System.Windows;
using System.Collections.Generic;
using System.Windows.Shapes;
using System.Diagnostics.CodeAnalysis;
using System.Runtime;
class ConnectionPoint : UIElement
{
//private UIElement visual;
public static readonly DependencyProperty LocationProperty = DependencyProperty.Register("Location", typeof(Point), typeof(ConnectionPoint));
private List attachedConnectors;
private Point location;
private UIElement parentDesigner;
private ConnectionPointType pointType;
// Size constants for the rectangle drawn
internal const double DrawingSmallSide = 4;
internal const double DrawingLargeSide = 10;
// Size constants for the hit test area.
internal const double HitTestSmallSide = 14;
internal const double HitTestLargeSide = 20;
public ConnectionPoint()
{
location = new Point(0, 0);
pointType = ConnectionPointType.Default;
attachedConnectors = new List();
this.parentDesigner = null;
}
public List AttachedConnectors
{
get
{
return this.attachedConnectors;
}
}
public Point Location
{
get { return (Point)GetValue(ConnectionPoint.LocationProperty); }
set { SetValue(ConnectionPoint.LocationProperty, value); }
}
// This is the vector from the point on the Edge to the topLeft of the rectangle being drawn.
public Vector DrawingOffset
{
get
{
return GetOffset(DrawingSmallSide, DrawingLargeSide);
}
}
// This is the vector from the point on the Edge to the topLeft of the rectangle being used for hit test.
public Vector HitTestOffset
{
get
{
return GetOffset(HitTestSmallSide, HitTestLargeSide);
}
}
// This is the size for the rectangle drawn (size is independent of coordinate system)
public Size DrawingSize
{
get
{
return this.GetSize(ConnectionPoint.DrawingSmallSide, ConnectionPoint.DrawingLargeSide);
}
}
// This is the size for the hit test area (size is independent of coordinate system)
public Size HitTestSize
{
get
{
return this.GetSize(ConnectionPoint.HitTestSmallSide, ConnectionPoint.HitTestLargeSide);
}
}
public UIElement ParentDesigner
{
get
{
return this.parentDesigner;
}
set
{
this.parentDesigner = value;
}
}
public ConnectionPointType PointType
{
get
{
return this.pointType;
}
set
{
this.pointType = value;
}
}
//Gets the list of Points representing the edge for the current ConnectionPoint with respect to the (0,0) of the FreeFormPanel.
public List Edge
{
get
{
FrameworkElement parent = this.ParentDesigner as FrameworkElement;
Fx.Assert(parent != null, "shape should be a FrameworkElement");
Point topLeft = FreeFormPanel.GetLocation(parent);
topLeft.Offset(parent.Margin.Left, parent.Margin.Top);
double parentWidth = parent.DesiredSize.Width - parent.Margin.Left - parent.Margin.Right;
double parentHeight = parent.DesiredSize.Height - parent.Margin.Top - parent.Margin.Bottom;
if (this.Location.X == topLeft.X)
{//Left Edge
return new List { topLeft, new Point(topLeft.X, topLeft.Y + parentHeight) };
}
else if (this.Location.X == topLeft.X + parentWidth)
{//Right edge
return new List { new Point(topLeft.X + parentWidth, topLeft.Y), new Point(topLeft.X + parentWidth, topLeft.Y + parentHeight) };
}
else if (this.Location.Y == topLeft.Y)
{//Top Edge
return new List { topLeft, new Point(topLeft.X + parentWidth, topLeft.Y) };
}
else if (this.Location.Y == topLeft.Y + parentHeight)
{//Bottom edge
return new List { new Point(topLeft.X, topLeft.Y + parentHeight), new Point(topLeft.X + parentWidth, topLeft.Y + parentHeight) };
}
return null;
}
}
public EdgeLocation EdgeLocation
{
get;
set;
}
// This is the vector from the point on the Edge to the topLeft of a rectangle with a particular (small, large) pair.
Vector GetOffset(double small, double large)
{
return this.EdgeToDrawnMidPointOffset() + this.MidPointToTopLeftOffset(small, large);
}
// This is the vector from the point on the Edge to the topLeft of the "drawn" rectangle.
Vector EdgeToDrawnMidPointOffset()
{
double small = ConnectionPoint.DrawingSmallSide;
switch (this.EdgeLocation)
{
case EdgeLocation.Left: return new Vector(-small / 2, 0);
case EdgeLocation.Right: return new Vector(small / 2, 0);
case EdgeLocation.Top: return new Vector(0, -small / 2);
case EdgeLocation.Bottom: return new Vector(0, small / 2);
}
Fx.Assert("There is no other possibilities for EdgeDirections");
// To please compiler
return new Vector();
}
// This is the vector from the midpoint of the rectangle to the topLeft of the rectangle with a particular (small, large) pair.
Vector MidPointToTopLeftOffset(double small, double large)
{
Size rectSize = GetSize(small, large);
return new Vector(-rectSize.Width / 2, -rectSize.Height / 2);
}
// This is the size for the rectangle with a particular (small, large) pair
Size GetSize(double small, double large)
{
if (this.EdgeLocation == EdgeLocation.Left || this.EdgeLocation == EdgeLocation.Right)
{
return new Size(small, large);
}
else
{
return new Size(large, small);
}
}
}
enum EdgeLocation
{
Left,
Right,
Top,
Bottom
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- CallContext.cs
- TextServicesPropertyRanges.cs
- ITextView.cs
- VScrollProperties.cs
- FormViewUpdateEventArgs.cs
- XmlDataLoader.cs
- NameValuePermission.cs
- ReadContentAsBinaryHelper.cs
- HttpWriter.cs
- NativeMethods.cs
- MulticastOption.cs
- PaintValueEventArgs.cs
- QueryOpeningEnumerator.cs
- DataSourceViewSchemaConverter.cs
- DictionaryMarkupSerializer.cs
- QilVisitor.cs
- AdornerPresentationContext.cs
- RelatedCurrencyManager.cs
- DESCryptoServiceProvider.cs
- MetabaseSettings.cs
- XmlValidatingReader.cs
- SwitchCase.cs
- DomNameTable.cs
- PointLight.cs
- PointAnimationUsingKeyFrames.cs
- ArrangedElementCollection.cs
- DispatcherProcessingDisabled.cs
- MediaContextNotificationWindow.cs
- DrawingAttributes.cs
- XmlDictionaryReader.cs
- serverconfig.cs
- Point.cs
- UndoEngine.cs
- _OSSOCK.cs
- BitArray.cs
- UpdatePanelTriggerCollection.cs
- WebBrowserHelper.cs
- DataServiceProviderWrapper.cs
- ObjectItemConventionAssemblyLoader.cs
- DiscoveryInnerClientAdhocCD1.cs
- DetailsViewPageEventArgs.cs
- WebDescriptionAttribute.cs
- ContainerParagraph.cs
- ContentWrapperAttribute.cs
- PeerNameResolver.cs
- PointLightBase.cs
- WsatConfiguration.cs
- PageCodeDomTreeGenerator.cs
- NetDispatcherFaultException.cs
- ValidatingPropertiesEventArgs.cs
- SystemDiagnosticsSection.cs
- ZipIOExtraFieldElement.cs
- CodeDelegateInvokeExpression.cs
- HttpAsyncResult.cs
- ModifierKeysValueSerializer.cs
- ConnectionManagementElement.cs
- ChangesetResponse.cs
- DatagramAdapter.cs
- DefaultValueTypeConverter.cs
- MenuEventArgs.cs
- TypeInfo.cs
- CustomPopupPlacement.cs
- FunctionGenerator.cs
- URLIdentityPermission.cs
- ValidationHelpers.cs
- EventLogEntry.cs
- MouseButtonEventArgs.cs
- WebZoneDesigner.cs
- VisualStyleRenderer.cs
- FastPropertyAccessor.cs
- Registry.cs
- ConfigurationManager.cs
- UInt32.cs
- ViewBase.cs
- PropertyMetadata.cs
- TimeSpanSecondsConverter.cs
- _SslState.cs
- ActivityDelegate.cs
- mda.cs
- FlowDocumentPaginator.cs
- basemetadatamappingvisitor.cs
- WebPartCatalogAddVerb.cs
- FixUp.cs
- SqlRecordBuffer.cs
- FormViewModeEventArgs.cs
- MemberPath.cs
- TripleDES.cs
- TransformDescriptor.cs
- XmlElement.cs
- PlanCompiler.cs
- CollectionsUtil.cs
- MimeMultiPart.cs
- EntityProviderFactory.cs
- Win32KeyboardDevice.cs
- Membership.cs
- UInt32Converter.cs
- EntityContainerRelationshipSet.cs
- CodeDomSerializerException.cs
- DataProviderNameConverter.cs
- FunctionDefinition.cs