Imported Upstream version 4.0.0~alpha1

Former-commit-id: 806294f5ded97629b74c85c09952f2a74fe182d9
This commit is contained in:
Jo Shields
2015-04-07 09:35:12 +01:00
parent 283343f570
commit 3c1f479b9d
22469 changed files with 2931443 additions and 869343 deletions

View File

@@ -0,0 +1,10 @@
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------
namespace System.Workflow.ComponentModel.Design
{
using System.Workflow.ComponentModel;
internal delegate bool ActivityComparer<TActivity>(TActivity source, TActivity target) where TActivity : Activity;
}

View File

@@ -0,0 +1,216 @@
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------
namespace System.Workflow.ComponentModel.Design
{
using System;
using System.Collections.Generic;
using System.Text;
using System.Workflow.ComponentModel.Design;
using System.ComponentModel.Design;
using System.Drawing;
using System.ServiceModel;
// <summary>
// Helper class for visuaulizing the highlighted activity group
// </summary>
class ActivityDesignerHighlighter : IServiceProvider
{
private IDesignerGlyphProviderService glyphProviderService;
private HighlightGlyphProvider highlightProvider = null;
private ActivityDesigner owner;
private WorkflowView workflowView;
public ActivityDesignerHighlighter(ActivityDesigner owner)
{
this.owner = owner;
}
public object GetService(Type serviceType)
{
if (serviceType == null)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("serviceType");
}
if (owner.Activity != null && owner.Activity.Site != null)
{
return owner.Activity.Site.GetService(serviceType);
}
else
{
return null;
}
}
public void Highlight(List<ActivityDesigner> highlightedDesigners)
{
if (highlightedDesigners == null)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("hightlightedDesigners");
}
glyphProviderService = this.GetService(typeof(IDesignerGlyphProviderService)) as IDesignerGlyphProviderService;
workflowView = GetService(typeof(WorkflowView)) as WorkflowView;
RemoveCurrentHighlight();
IDesignerHost designerHost = this.GetService(typeof(IDesignerHost)) as IDesignerHost;
DesignerHighlighterMesageFilter messageFilter = new DesignerHighlighterMesageFilter();
highlightProvider = new HighlightGlyphProvider(designerHost.GetDesigner(designerHost.RootComponent) as ActivityDesigner, highlightedDesigners);
glyphProviderService.AddGlyphProvider(highlightProvider);
highlightProvider.MessageFilter = messageFilter;
messageFilter.MouseDown += new EventHandler<System.Windows.Forms.MouseEventArgs>(messageFilter_MouseDown);
messageFilter.KeyDown += new EventHandler<System.Windows.Forms.KeyEventArgs>(messageFilter_KeyDown);
workflowView.AddDesignerMessageFilter(messageFilter);
workflowView.FitToScreenSize();
}
public void RemoveCurrentHighlight()
{
HighlightGlyphProvider currentHightlightGlyhProvider = null;
foreach (IDesignerGlyphProvider glyphProvider in glyphProviderService.GlyphProviders)
{
if (glyphProvider is HighlightGlyphProvider)
{
currentHightlightGlyhProvider = (HighlightGlyphProvider) glyphProvider;
break;
}
}
if (currentHightlightGlyhProvider != null)
{
//remove associated designerMessageFilter before removing currentGlyphProvider.
workflowView.RemoveDesignerMessageFilter(currentHightlightGlyhProvider.MessageFilter);
glyphProviderService.RemoveGlyphProvider(currentHightlightGlyhProvider);
}
}
void messageFilter_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
{
glyphProviderService.RemoveGlyphProvider(highlightProvider);
if (workflowView != null)
{
workflowView.RemoveDesignerMessageFilter(sender as WorkflowDesignerMessageFilter);
Point scrollPosition = workflowView.ClientPointToLogical(owner.Location);
workflowView.FitToWorkflowSize();
// try to center the owner designer int the the workflowview
Size viewSize = workflowView.ClientSizeToLogical(workflowView.ViewPortSize);
if (scrollPosition.Y > viewSize.Height / 2)
{
scrollPosition.Y -= viewSize.Height / 2;
}
if (scrollPosition.X > viewSize.Width / 2)
{
scrollPosition.X -= viewSize.Width / 2;
}
workflowView.ScrollPosition = scrollPosition;
}
}
void messageFilter_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
glyphProviderService.RemoveGlyphProvider(highlightProvider);
if (workflowView != null)
{
workflowView.RemoveDesignerMessageFilter(sender as WorkflowDesignerMessageFilter);
Point scrollPosition = workflowView.ClientPointToLogical(e.Location);
workflowView.FitToWorkflowSize();
// try to center the clicked portion of the workflow in the workflowview
Size viewSize = workflowView.ClientSizeToLogical(workflowView.ViewPortSize);
if (scrollPosition.Y > viewSize.Height / 2)
{
scrollPosition.Y -= viewSize.Height / 2;
}
if (scrollPosition.X > viewSize.Width / 2)
{
scrollPosition.X -= viewSize.Width / 2;
}
workflowView.ScrollPosition = scrollPosition;
}
}
// this is the message filter inserted in the workflowview to escape back to the normal view
// from the highlighted view. since glyphs cant take mouse events, this is the only way to
// detect mouseclicks when in highlighted view.
internal sealed class DesignerHighlighterMesageFilter : WorkflowDesignerMessageFilter
{
public event EventHandler<System.Windows.Forms.KeyEventArgs> KeyDown;
public event EventHandler<System.Windows.Forms.MouseEventArgs> MouseDown;
protected override bool OnKeyDown(System.Windows.Forms.KeyEventArgs eventArgs)
{
if (KeyDown != null)
{
KeyDown(this, eventArgs);
}
// let event pass down to others. we dont want to mark it as handled
return false;
}
protected override bool OnMouseDown(System.Windows.Forms.MouseEventArgs eventArgs)
{
if (MouseDown != null)
{
MouseDown(this, eventArgs);
}
// let event pass down to others. we dont want to mark it as handled
return false;
}
}
internal sealed class HighlightGlyphProvider : IDesignerGlyphProvider
{
private List<ActivityDesigner> highlightedDesigners;
private DesignerHighlighterMesageFilter messageFilter;
private ActivityDesigner rootDesigner;
public HighlightGlyphProvider(ActivityDesigner rootDesigner, List<ActivityDesigner> highlightedDesigners)
{
this.RootDesigner = rootDesigner;
this.HighlightedDesigners = highlightedDesigners;
}
public List<ActivityDesigner> HighlightedDesigners
{
get { return highlightedDesigners; }
set { highlightedDesigners = value; }
}
public DesignerHighlighterMesageFilter MessageFilter
{
get { return messageFilter; }
set { messageFilter = value; }
}
public ActivityDesigner RootDesigner
{
get { return rootDesigner; }
set { rootDesigner = value; }
}
public ActivityDesignerGlyphCollection GetGlyphs(ActivityDesigner activityDesigner)
{
if (activityDesigner == null)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("activityDesigner");
}
if (!activityDesigner.IsRootDesigner)
{
return null;
}
ActivityDesignerGlyphCollection glyphs = new ActivityDesignerGlyphCollection();
glyphs.Add(new HighlightOverlayGlyph(activityDesigner.Bounds, HighlightedDesigners));
return glyphs;
}
}
}
}

View File

@@ -0,0 +1,130 @@
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------
namespace System.Workflow.ComponentModel.Design
{
using System;
using System.Collections.Generic;
using System.Text;
using System.Workflow.ComponentModel.Design;
using System.Windows.Forms;
using System.Reflection;
using System.Drawing;
using System.Diagnostics;
using System.ServiceModel;
// <summary>
// This is a helper class with static methods that dont fit anywhere but are useful in general
// </summary>
internal static class DesignerPainter
{
public static CompositeActivityDesigner GetRootDesigner(ActivityDesigner designer)
{
if (designer == null)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("designer");
}
CompositeActivityDesigner rootDesigner = designer.ParentDesigner;
while (!rootDesigner.IsRootDesigner && rootDesigner.ParentDesigner != null)
{
rootDesigner = rootDesigner.ParentDesigner;
}
return rootDesigner;
}
public static void PaintDesigner(ActivityDesigner activityDesigner, ActivityDesignerPaintEventArgs eventArgs)
{
if (activityDesigner == null)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("activityDesigner");
}
if (eventArgs == null)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("eventArgs");
}
ActivityDesigner parentDesigner = activityDesigner.ParentDesigner;
if (parentDesigner == null)
{
// This designer is no more on the design surface , dont paint this.
return;
}
if (!IsBranchVisible(activityDesigner))
{
return;
}
// special case designers contained inside activity preview designers ( only one of the contained designers is shown)
bool visible = false;
if (IsInsidePreviewDesignerBranch(activityDesigner, out visible))
{
if (visible)
{
PaintDesignerInternal(activityDesigner, eventArgs);
}
}
else
{
PaintDesignerInternal(activityDesigner, eventArgs);
}
}
private static bool IsBranchVisible(ActivityDesigner activityDesigner)
{
ActivityDesigner currentDesigner = activityDesigner;
ActivityDesigner parentDesigner = activityDesigner.ParentDesigner;
while (!currentDesigner.IsRootDesigner)
{
if (!((CompositeActivityDesigner) parentDesigner).ContainedDesigners.Contains(currentDesigner))
{
return false;
}
else
{
currentDesigner = parentDesigner;
parentDesigner = parentDesigner.ParentDesigner;
}
}
return true;
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1800:DoNotCastUnnecessarily")]
// The above suppression is required because, the parentDesigner object is changeing inside the loop and it is
// not possible to cache the result of the cast as suggested by FxCop
private static bool IsInsidePreviewDesignerBranch(ActivityDesigner activityDesigner, out bool visible)
{
visible = false;
ActivityDesigner currentDesigner = activityDesigner;
ActivityDesigner parentDesigner = activityDesigner.ParentDesigner;
while (!currentDesigner.IsRootDesigner)
{
if (parentDesigner is ActivityPreviewDesigner)
{
break;
}
else
{
currentDesigner = parentDesigner;
parentDesigner = parentDesigner.ParentDesigner;
}
}
if (parentDesigner is ActivityPreviewDesigner)
{
if (((ActivityPreviewDesigner) parentDesigner).IsContainedDesignerVisible(currentDesigner))
{
visible = true;
}
return true;
}
return false;
}
private static void PaintDesignerInternal(ActivityDesigner activityDesigner, ActivityDesignerPaintEventArgs eventArgs)
{
IWorkflowDesignerMessageSink sink = (IWorkflowDesignerMessageSink) activityDesigner;
sink.OnPaint(new PaintEventArgs(eventArgs.Graphics, eventArgs.ClipRectangle), eventArgs.ClipRectangle);
}
}
}

View File

@@ -0,0 +1,94 @@
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------
namespace System.Workflow.ComponentModel.Design
{
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Runtime;
using System.ServiceModel;
using System.Workflow.ComponentModel;
// <summary>
// This the the class that implements the Search by menu item displayed on the activityDesigner
// this is responsible for finding the matching activity designers and displaying them using
// the acticvitydesigner hightlighter.
// </summary>
internal class FindSimilarActivitiesVerb<TActivity> : ActivityDesignerVerb where TActivity : Activity
{
List<ActivityDesigner> matchingActivityDesigner;
ActivityComparer<TActivity> matchMaker;
ActivityDesigner owner;
public FindSimilarActivitiesVerb(ActivityDesigner designer, ActivityComparer<TActivity> matchMaker, string displayText)
: base(designer, DesignerVerbGroup.Misc, displayText, new EventHandler(OnInvoke))
{
Fx.Assert(designer != null,
"Received null for designer parameter to FindSimilarActivitiesVerb ctor.");
Fx.Assert(matchMaker != null,
"Received null for matchMaker parameter to FindSimilarActivitiesVerb ctor.");
this.owner = designer;
this.matchMaker = matchMaker;
}
private static void OnInvoke(object source, EventArgs e)
{
FindSimilarActivitiesVerb<TActivity> designerVerb = source as FindSimilarActivitiesVerb<TActivity>;
ActivityDesigner activityDesigner = designerVerb.owner;
List<ActivityDesigner> highlightedDesigners = designerVerb.GetMatchingActivityDesigners(activityDesigner);
ActivityDesignerHighlighter hightlighter = new ActivityDesignerHighlighter(activityDesigner);
hightlighter.Highlight(highlightedDesigners);
}
private ActivityDesigner GetDesigner(Activity activity)
{
IDesignerHost designerHost = this.GetService(typeof(IDesignerHost)) as IDesignerHost;
return designerHost.GetDesigner(activity as IComponent) as ActivityDesigner;
}
private List<ActivityDesigner> GetMatchingActivityDesigners(ActivityDesigner activityDesigner)
{
CompositeActivityDesigner rootDesigner = DesignerPainter.GetRootDesigner(activityDesigner);
matchingActivityDesigner = new List<ActivityDesigner>();
Walker activityTreeWalker = new Walker();
activityTreeWalker.FoundActivity += new WalkerEventHandler(OnWalkerFoundActivity);
activityTreeWalker.Walk(rootDesigner.Activity);
return matchingActivityDesigner;
}
private object GetService(Type serviceType)
{
if (serviceType == null)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("serviceType");
}
if (owner.Activity != null && owner.Activity.Site != null)
{
return owner.Activity.Site.GetService(serviceType);
}
else
{
return null;
}
}
private void OnWalkerFoundActivity(Walker walker, WalkerEventArgs eventArgs)
{
TActivity foundActivity = eventArgs.CurrentActivity as TActivity;
if (foundActivity != null)
{
if (this.matchMaker((TActivity) owner.Activity, foundActivity))
{
matchingActivityDesigner.Add(GetDesigner(eventArgs.CurrentActivity));
}
}
}
}
}

View File

@@ -0,0 +1,101 @@
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------
namespace System.Workflow.ComponentModel.Design
{
using System;
using System.Collections.Generic;
using System.Text;
using System.Workflow.ComponentModel.Design;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Runtime.InteropServices;
// <summary>
// This class provides the visualisation of the backdrop + hightlighted designer when
// in highlight view.
// </summary>
[ComVisible(false)]
internal class HighlightOverlayGlyph : DesignerGlyph
{
private Rectangle bounds;
private List<ActivityDesigner> highlightedDesigners;
public HighlightOverlayGlyph(Rectangle bounds, List<ActivityDesigner> highlightedDesigners)
{
this.HighlightedDesigners = highlightedDesigners;
this.Bounds = bounds;
}
public Rectangle Bounds
{
get { return bounds; }
set { bounds = value; }
}
public List<ActivityDesigner> HighlightedDesigners
{
get { return highlightedDesigners; }
set { highlightedDesigners = value; }
}
protected override void OnPaint(Graphics graphics, bool activated, AmbientTheme ambientTheme, ActivityDesigner designer)
{
Rectangle frameRect = Bounds;
Rectangle shadowRect = frameRect;
Color BaseColor = Color.FromArgb(150, 0, 0, 0); // dark semitransparent backdrop
Color LightingColor = Color.FromArgb(150, 0, 0, 0);
Brush frameBrush = new LinearGradientBrush(new Point(frameRect.Left, frameRect.Top), new Point(frameRect.Left, frameRect.Bottom), BaseColor, LightingColor);
shadowRect = DropRoundedRectangleShadow(shadowRect, graphics);
graphics.FillPath(frameBrush, RoundedRect(frameRect));
graphics.SmoothingMode = SmoothingMode.HighQuality;
graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
foreach (ActivityDesigner highlightedDesigner in HighlightedDesigners)
{
DesignerPainter.PaintDesigner(highlightedDesigner, new ActivityDesignerPaintEventArgs(graphics, designer.Bounds, designer.Bounds, null));
}
}
private Rectangle DropRoundedRectangleShadow(Rectangle shadowRect, Graphics outputGraphics)
{
int shadowIntensity = 1;
using (Pen shadowPen = new Pen(Color.FromArgb(shadowIntensity, 0, 0, 0)))
{
shadowPen.Width = 24;
for (int i = 0; i < 12; i++)
{
outputGraphics.DrawPath(shadowPen, RoundedRect(shadowRect));
shadowPen.Color = Color.FromArgb(shadowIntensity - 1, 0, 0, 0);
shadowIntensity += 2;
shadowPen.Width = shadowPen.Width - 2;;
}
return shadowRect;
}
}
private GraphicsPath RoundedRect(Rectangle frame)
{
GraphicsPath path = new GraphicsPath();
int radius = 1;
int diameter = radius * 2;
Rectangle arc = new Rectangle(frame.Left, frame.Top, diameter, diameter);
path.AddArc(arc, 180, 90);
arc.X = frame.Right - diameter;
path.AddArc(arc, 270, 90);
arc.Y = frame.Bottom - diameter;
path.AddArc(arc, 0, 90);
arc.X = frame.Left;
path.AddArc(arc, 90, 90);
path.CloseFigure();
return path;
}
}
}