void CreateStartSymbol()
        {
            //Instantiate the start symbol
            StartSymbol start = System.Activities.Core.Presentation.StartSymbol.CreateStartSymbol(this.Context);

            start.Text     = "Start";
            this.flowStart = start.ModelItem;
            DragDropHelper.SetCompositeView(start, this);
            modelElement.Add(flowStart, start);
            start.SizeChanged += new SizeChangedEventHandler(ChildSizeChanged);
            this.StartSymbol   = start;
            PopulateConnectionPoints(this.StartSymbol, null);
            this.StartSymbol.MouseEnter += new MouseEventHandler(ChildElement_MouseEnter);
            this.StartSymbol.MouseLeave += new MouseEventHandler(ChildElement_MouseLeave);

            //Getting the View state information.
            object locationOfShape = this.ViewStateService.RetrieveViewState(this.ModelItem, shapeLocation);
            object sizeOfShape     = this.ViewStateService.RetrieveViewState(this.ModelItem, shapeSize);

            if (locationOfShape != null)
            {
                Point locationPt = (Point)locationOfShape;
                FreeFormPanel.SetLocation(this.StartSymbol, locationPt);
            }
            else
            {
                //Set the location of the start symbol.
                this.StartSymbol.Measure(new Size(Double.PositiveInfinity, Double.PositiveInfinity));
                double startHeight   = this.StartSymbol.DesiredSize.Height;
                double startWidth    = this.StartSymbol.DesiredSize.Width;
                Point  startPoint    = new Point(panel.MinWidth / 2, startSymbolTopMargin + startHeight / 2);
                Point  startLocation = SnapVisualToGrid(this.StartSymbol, startPoint, new Point(-1, -1), false);
                FreeFormPanel.SetLocation(this.StartSymbol, startLocation);
                this.internalViewStateChange = true;
                this.StoreShapeViewState(this.ModelItem, startLocation);
                this.internalViewStateChange = false;
            }
            if (sizeOfShape != null)
            {
                FreeFormPanel.SetChildSize(this.StartSymbol, (Size)sizeOfShape);
            }
        }
예제 #2
0
        void OnViewStateChanged(object sender, ViewStateChangedEventArgs e)
        {
            Debug.Assert(e.ParentModelItem != null, "ViewState should be associated with some modelItem");

            if (!this.internalViewStateChange)
            {
                if (e.ParentModelItem == this.ModelItem)
                {
                    if (string.Equals(e.Key, StateContainerWidthViewStateKey, StringComparison.Ordinal))
                    {
                        double defaultWidth   = ((this.ModelItem.ItemType == typeof(State)) ? DefaultStateWidth : DefaultStateMachineWidth);
                        object widthViewState = this.ViewStateService.RetrieveViewState(this.ModelItem, StateContainerWidthViewStateKey);
                        this.StateContainerWidth = (widthViewState != null) ? (double)widthViewState : defaultWidth;
                    }
                    else if (string.Equals(e.Key, StateContainerHeightViewStateKey, StringComparison.Ordinal))
                    {
                        double defaultHeight   = ((this.ModelItem.ItemType == typeof(State)) ? DefaultStateHeight : DefaultStateMachineHeight);
                        object heightViewState = this.ViewStateService.RetrieveViewState(this.ModelItem, StateContainerHeightViewStateKey);
                        this.StateContainerHeight = (heightViewState != null) ? (double)heightViewState : defaultHeight;
                    }
                }

                if (e.ParentModelItem.ItemType == typeof(State) && e.Key.Equals(ShapeLocationViewStateKey))
                {
                    if (this.modelItemToUIElement.ContainsKey(e.ParentModelItem))
                    {
                        if (e.NewValue != null)
                        {
                            FreeFormPanel.SetLocation(this.modelItemToUIElement[e.ParentModelItem], (Point)e.NewValue);
                            this.panel.InvalidateMeasure();
                            if (e.OldValue != null)
                            {
                                this.shapeLocations.Remove((Point)e.OldValue);
                            }
                            this.shapeLocations.Add((Point)e.NewValue);
                            // To reroute the links
                            this.InvalidateMeasureForOutmostPanel();
                        }
                    }
                }

                else if (e.ParentModelItem.ItemType == typeof(State) && e.Key.Equals(ShapeSizeViewStateKey))
                {
                    // To reroute the links
                    this.InvalidateMeasureForOutmostPanel();
                }

                // Only the outmost editor should respond to connector changes because all connectors are
                // only added to the outmost editor
                else if (e.Key.Equals(ConnectorLocationViewStateKey) && this.IsOutmostStateContainerEditor())
                {
                    Connector changedConnector = this.GetConnectorOnOutmostEditor(e.ParentModelItem);
                    if (changedConnector != null)
                    {
                        if (e.NewValue != null)
                        {
                            Debug.Assert(e.NewValue is PointCollection, "e.NewValue is not PointCollection");
                            changedConnector.Points = e.NewValue as PointCollection;
                            this.panel.RemoveConnectorEditor();
                            this.InvalidateMeasureForOutmostPanel();
                            if (IsConnectorFromInitialNode(changedConnector))
                            {
                                this.initialStateChanged = true;
                            }
                        }
                    }
                }
            }
        }
        void OnViewStateChanged(object sender, ViewStateChangedEventArgs e)
        {
            Fx.Assert(this.panel != null, "This code should not be hit if panel is null");
            Fx.Assert(e.ParentModelItem != null, "ViewState should be associated with some modelItem");
            Connector changedConnector = null;

            if (e.ParentModelItem == this.ModelItem)
            {
                if (string.Equals(e.Key, FlowchartSizeFeature.WidthPropertyName, StringComparison.Ordinal))
                {
                    this.FlowchartWidth = (double)TypeDescriptor.GetProperties(this.ModelItem)[FlowchartSizeFeature.WidthPropertyName].GetValue(this.ModelItem);
                }
                else if (string.Equals(e.Key, FlowchartSizeFeature.HeightPropertyName, StringComparison.Ordinal))
                {
                    this.FlowchartHeight = (double)TypeDescriptor.GetProperties(this.ModelItem)[FlowchartSizeFeature.HeightPropertyName].GetValue(this.ModelItem);
                }
            }
            if ((IsFlowNode(e.ParentModelItem) || this.ModelItem.Equals(e.ParentModelItem)) && !this.internalViewStateChange)
            {
                ModelItem itemOnCanvas = this.GetCorrespondingElementOnCanvas(e.ParentModelItem);
                if (this.modelElement.ContainsKey(itemOnCanvas))
                {
                    if (e.Key.Equals(shapeLocation))
                    {
                        if (e.NewValue != null)
                        {
                            FreeFormPanel.SetLocation(this.modelElement[itemOnCanvas], (Point)e.NewValue);
                            this.panel.InvalidateMeasure();
                            if (e.OldValue != null)
                            {
                                this.shapeLocations.Remove((Point)e.OldValue);
                            }
                            this.shapeLocations.Add((Point)e.NewValue);
                        }
                    }
                    else
                    {
                        if (this.ModelItem.Equals(e.ParentModelItem) &&
                            e.Key.Equals(ConnectorViewStateKey))
                        {
                            changedConnector = this.GetLinkOnCanvas(e.ParentModelItem, e.ParentModelItem.Properties["StartNode"].Value, "StartNode");
                        }
                        else if (typeof(FlowStep).IsAssignableFrom(e.ParentModelItem.ItemType) &&
                                 e.Key.Equals(ConnectorViewStateKey))
                        {
                            changedConnector = this.GetLinkOnCanvas(e.ParentModelItem, e.ParentModelItem.Properties["Next"].Value, "Next");
                        }
                        else if (typeof(FlowDecision).IsAssignableFrom(e.ParentModelItem.ItemType))
                        {
                            if (e.Key.Equals(TrueConnectorViewStateKey))
                            {
                                changedConnector = this.GetLinkOnCanvas(e.ParentModelItem, e.ParentModelItem.Properties["True"].Value, "True");
                            }
                            else if (e.Key.Equals(FalseConnectorViewStateKey))
                            {
                                changedConnector = this.GetLinkOnCanvas(e.ParentModelItem, e.ParentModelItem.Properties["False"].Value, "False");
                            }
                        }
                        else if (GenericFlowSwitchHelper.IsGenericFlowSwitch(e.ParentModelItem.ItemType))
                        {
                            if (e.Key.Equals(FlowchartDesigner.FlowSwitchDefaultViewStateKey, StringComparison.CurrentCulture))
                            {
                                changedConnector = this.GetLinkOnCanvas(e.ParentModelItem, e.ParentModelItem.Properties["Default"].Value, e.Key);
                            }
                            else if (e.Key.EndsWith(CaseViewStateKeyAppendString, StringComparison.CurrentCulture))
                            {
                                string switchCaseName = e.Key.Substring(0, e.Key.Length - CaseViewStateKeyAppendString.Length);
                                object switchCase     = switchCaseName;
                                Type   genericType    = e.ParentModelItem.ItemType.GetGenericArguments()[0];
                                switchCase = GenericFlowSwitchHelper.GetObject(switchCaseName, genericType);

                                if (GenericFlowSwitchHelper.ContainsCaseKey(e.ParentModelItem.Properties["Cases"], switchCase))
                                {
                                    //Prepending with GenericFlowSwitchHelper.FlowSwitchCasesKeyIdentifier to differentiate between the property Default and the key Default.
                                    changedConnector = this.GetLinkOnCanvas(e.ParentModelItem, GenericFlowSwitchHelper.GetCaseModelItem(e.ParentModelItem.Properties["Cases"], switchCase), GenericFlowSwitchHelper.FlowSwitchCasesKeyIdentifier + switchCase);
                                }
                            }
                        }
                    }
                }
            }
            if (changedConnector != null)
            {
                if (e.NewValue != null)
                {
                    Fx.Assert(e.NewValue is PointCollection, "e.NewValue is not PointCollection");
                    changedConnector.Points = e.NewValue as PointCollection;
                    this.panel.RemoveConnectorEditor();
                    this.panel.InvalidateMeasure();
                }
            }
        }