Exemple #1
0
        public override void SetSize(Rect sourceRect, BaseFrameworkElement target, ILayoutDesigner targetLayoutDesigner)
        {
            Rect childRect = targetLayoutDesigner.GetChildRect(target);

            childRect.Height = sourceRect.Height;
            targetLayoutDesigner.SetChildRect(target, childRect, false, true);
        }
        private void SetGridHeightCore(GridElement grid, double height)
        {
            BaseFrameworkElement sizeElement = this.GetSizeElement((BaseFrameworkElement)grid);

            if (sizeElement.ViewModel.RootNode == sizeElement)
            {
                if (!double.IsNaN(sizeElement.Height))
                {
                    sizeElement.Height = height;
                }
                else
                {
                    if (double.IsNaN((double)sizeElement.GetLocalOrDefaultValue(DesignTimeProperties.DesignHeightProperty)))
                    {
                        return;
                    }
                    sizeElement.SetValue(DesignTimeProperties.DesignHeightProperty, (object)height);
                }
            }
            else
            {
                ILayoutDesigner designerForChild = sizeElement.ViewModel.GetLayoutDesignerForChild((SceneElement)sizeElement, true);
                Rect            rect             = designerForChild.GetChildRect(sizeElement);
                rect = new Rect(rect.Left, rect.Top, rect.Width, height);
                designerForChild.SetChildRect(sizeElement, rect, false, true);
            }
        }
Exemple #3
0
 public static void AdjustPathForAnimations(PathElement pathElement, SceneEditTransaction editTransaction)
 {
     using (pathElement.ViewModel.ForceBaseValue())
     {
         System.Windows.Media.Geometry geometry1 = (System.Windows.Media.Geometry)pathElement.GetLocalOrDefaultValueAsWpf(PathElement.DataProperty);
         PathGeometry pathGeometry = new PathGeometry();
         pathGeometry.AddGeometry(geometry1);
         Rect bounds = PathCommandHelper.InflateRectByStrokeWidth(pathGeometry.Bounds, pathElement, false);
         PropertyReference propertyReference = PathCommandHelper.GetPathDataPropertyReference(pathElement.Platform);
         Rect            maxAnimatedExtent   = PathCommandHelper.FindMaxAnimatedExtent((SceneElement)pathElement, bounds, propertyReference);
         double          num1             = Math.Min(0.0, maxAnimatedExtent.Left);
         double          num2             = Math.Min(0.0, maxAnimatedExtent.Top);
         Vector          vector           = new Vector(-num1, -num2);
         ILayoutDesigner designerForChild = pathElement.ViewModel.GetLayoutDesignerForChild((SceneElement)pathElement, true);
         editTransaction.Update();
         Rect childRect = designerForChild.GetChildRect((BaseFrameworkElement)pathElement);
         childRect.X     += num1;
         childRect.Y     += num2;
         childRect.Width  = Math.Max(maxAnimatedExtent.Width, childRect.Width);
         childRect.Height = Math.Max(maxAnimatedExtent.Height, childRect.Height);
         designerForChild.SetChildRect((BaseFrameworkElement)pathElement, childRect);
         Transform    transform = (Transform) new TranslateTransform(vector.X, vector.Y);
         PathGeometry geometry2 = PathGeometryUtilities.TransformGeometry((System.Windows.Media.Geometry)pathGeometry, transform);
         if (!pathElement.DesignerContext.ActiveDocument.ProjectContext.IsCapabilitySet(PlatformCapability.IsWpf))
         {
             PathGeometryUtilities.EnsureOnlySingleSegmentsInGeometry(geometry2);
         }
         pathElement.PathGeometry = geometry2;
         PathCommandHelper.TransformPointKeyframes((SceneElement)pathElement, propertyReference, transform);
         pathElement.SetValueAsWpf(ShapeElement.StretchProperty, (object)(Stretch)(pathElement.HasVertexAnimations ? 0 : 1));
     }
 }
Exemple #4
0
        public override void Execute()
        {
            BaseFrameworkElement selectedElement = this.SelectedElement;
            SceneViewModel       sceneViewModel1 = this.SceneViewModel;
            bool flag1 = true;
            BaseFrameworkElement frameworkElement = selectedElement;
            int             num1             = flag1 ? true : false;
            ILayoutDesigner designerForChild = sceneViewModel1.GetLayoutDesignerForChild((SceneElement)frameworkElement, num1 != 0);
            SceneNode       parent           = selectedElement.Parent;
            IProperty       propertyForChild = parent.GetPropertyForChild((SceneNode)selectedElement);
            ISceneNodeCollection <SceneNode> collectionForProperty = parent.GetCollectionForProperty((IPropertyId)propertyForChild);
            int index = collectionForProperty.IndexOf((SceneNode)selectedElement);

            if (!BehaviorHelper.EnsureBlendSDKLibraryAssemblyReferenced(this.SceneViewModel, "Microsoft.Expression.Controls") || !ProjectContext.GetProjectContext(selectedElement.ProjectContext).IsTypeSupported(ProjectNeutralTypes.PathListBox))
            {
                return;
            }
            using (this.SceneViewModel.DisableUpdateChildrenOnAddAndRemove())
            {
                SceneViewModel sceneViewModel2    = this.SceneViewModel;
                bool           flag2              = false;
                string         unitMakeLayoutPath = StringTable.UndoUnitMakeLayoutPath;
                int            num2 = flag2 ? true : false;
                using (SceneEditTransaction editTransaction = sceneViewModel2.CreateEditTransaction(unitMakeLayoutPath, num2 != 0))
                {
                    using (this.SceneViewModel.ForceBaseValue())
                    {
                        using (this.SceneViewModel.DisableDrawIntoState())
                        {
                            this.SceneViewModel.ElementSelectionSet.Clear();
                            Rect childRect = designerForChild.GetChildRect(selectedElement);
                            selectedElement.EnsureNamed();
                            PathListBoxElement pathListBoxElement = (PathListBoxElement)this.SceneViewModel.CreateSceneNode(ProjectNeutralTypes.PathListBox);
                            LayoutPathNode     layoutPathNode     = (LayoutPathNode)this.SceneViewModel.CreateSceneNode(ProjectNeutralTypes.LayoutPath);
                            BindingSceneNode   bindingSceneNode   = (BindingSceneNode)this.SceneViewModel.CreateSceneNode(PlatformTypes.Binding);
                            bindingSceneNode.ElementName = selectedElement.Name;
                            layoutPathNode.SetValue(LayoutPathNode.SourceElementProperty, (object)bindingSceneNode.DocumentNode);
                            pathListBoxElement.LayoutPaths.Add((SceneNode)layoutPathNode);
                            if (!collectionForProperty.FixedCapacity.HasValue || collectionForProperty.Count < collectionForProperty.FixedCapacity.Value)
                            {
                                collectionForProperty.Insert(index, (SceneNode)pathListBoxElement);
                            }
                            else
                            {
                                GridElement gridElement = (GridElement)this.SceneViewModel.CreateSceneNode(PlatformTypes.Grid);
                                collectionForProperty[index] = (SceneNode)gridElement;
                                gridElement.Children.Add((SceneNode)pathListBoxElement);
                                gridElement.Children.Add((SceneNode)selectedElement);
                            }
                            editTransaction.Update();
                            designerForChild.SetChildRect((BaseFrameworkElement)pathListBoxElement, childRect);
                            this.SceneViewModel.ElementSelectionSet.SetSelection((SceneElement)pathListBoxElement);
                            editTransaction.Commit();
                        }
                    }
                }
            }
        }
Exemple #5
0
        protected void MoveDraggedElementsInContainer()
        {
            Point point1 = this.DragCurrentPosition;

            if (this.IsConstraining)
            {
                point1 = this.ConstrainPointToAxis(this.DragStartPosition, this.DragCurrentPosition);
            }
            Point point2 = this.ActiveView.TransformPoint((IViewObject)this.ActiveView.HitTestRoot, this.LayoutContainer.Visual, point1);
            Point point3 = this.ActiveView.TransformPoint((IViewObject)this.ActiveView.HitTestRoot, this.LayoutContainer.Visual, this.DragStartPosition);

            for (int index = 0; index < this.DraggedElements.Count; ++index)
            {
                BaseFrameworkElement child = this.DraggedElements[index];
                if (child.IsViewObjectValid)
                {
                    LayoutOverrides overridesToIgnore = LayoutOverrides.None;
                    if (point1.X != this.DragStartPosition.X)
                    {
                        overridesToIgnore |= LayoutOverrides.CenterHorizontalAlignment;
                    }
                    if (point1.Y != this.DragStartPosition.Y)
                    {
                        overridesToIgnore |= LayoutOverrides.CenterVerticalAlignment;
                    }
                    if (this.Context.IsRecordingKeyframes)
                    {
                        Vector             vector             = point2 - point3;
                        CanonicalTransform canonicalTransform = this.Context.BaseRenderTransforms[index];
                        double             num1 = RoundingHelper.RoundLength(vector.X + canonicalTransform.TranslationX);
                        double             num2 = RoundingHelper.RoundLength(vector.Y + canonicalTransform.TranslationY);
                        if (!object.Equals((object)canonicalTransform.TranslationX, (object)num1))
                        {
                            child.SetValue(child.Platform.Metadata.CommonProperties.RenderTransformTranslationX, (object)num1);
                        }
                        if (!object.Equals((object)canonicalTransform.TranslationY, (object)num2))
                        {
                            child.SetValue(child.Platform.Metadata.CommonProperties.RenderTransformTranslationY, (object)num2);
                        }
                    }
                    else
                    {
                        Point           location         = point2;
                        ILayoutDesigner designerForChild = this.ActiveView.ViewModel.GetLayoutDesignerForChild((SceneElement)child, false);
                        Rect            childRect        = designerForChild.GetChildRect(child);
                        Point           point4           = this.ActiveView.TransformPoint(child.Visual, this.LayoutContainer.Visual, this.Context.Offsets[index]);
                        point4.Offset(-childRect.X, -childRect.Y);
                        location.Offset(-point4.X, -point4.Y);
                        Rect rect = new Rect(location, this.Context.LayoutCacheRecords[index].Rect.Size);
                        designerForChild.SetChildRect(child, rect, this.Context.LayoutCacheRecords[index].Overrides, overridesToIgnore, LayoutOverrides.None);
                    }
                }
            }
            this.Context.Transaction.UpdateEditTransaction();
        }
Exemple #6
0
 public override void Execute()
 {
     PerformanceUtility.StartPerformanceSequence(PerformanceEvent.Make3D);
     try
     {
         using (this.SceneViewModel.DisableUpdateChildrenOnAddAndRemove())
         {
             BaseFrameworkElement frameworkElement = (BaseFrameworkElement)this.SceneViewModel.ElementSelectionSet.PrimarySelection;
             using (SceneEditTransaction editTransaction = this.SceneViewModel.CreateEditTransaction(this.UndoUnitName, false))
             {
                 ILayoutDesigner designerForChild = this.SceneViewModel.GetLayoutDesignerForChild((SceneElement)frameworkElement, true);
                 Rect            childRect        = designerForChild.GetChildRect(frameworkElement);
                 DocumentNode    newValue         = this.CreateValue(frameworkElement);
                 if (newValue == null)
                 {
                     editTransaction.Cancel();
                 }
                 else if (this.CreateResource && this.ProcessAsResource(frameworkElement, newValue) == null)
                 {
                     editTransaction.Cancel();
                 }
                 else
                 {
                     if (this.ShouldReplaceOriginal)
                     {
                         this.SceneViewModel.AnimationEditor.DeleteAllAnimationsInSubtree((SceneElement)frameworkElement);
                         Dictionary <IPropertyId, SceneNode> properties = SceneElementHelper.StoreProperties((SceneNode)frameworkElement, true);
                         this.SceneViewModel.ElementSelectionSet.Clear();
                         BaseFrameworkElement element = this.CreateElement(frameworkElement);
                         using (this.SceneViewModel.ForceBaseValue())
                         {
                             element.Name = frameworkElement.Name;
                             ISceneNodeCollection <SceneNode> collectionForChild = frameworkElement.ParentElement.GetCollectionForChild((SceneNode)frameworkElement);
                             int index = collectionForChild.IndexOf((SceneNode)frameworkElement);
                             frameworkElement.Remove();
                             this.Postprocess(frameworkElement, element, properties, childRect);
                             collectionForChild.Insert(index, (SceneNode)element);
                             SceneElementHelper.ApplyProperties((SceneNode)element, properties);
                             editTransaction.Update();
                             designerForChild.SetChildRect(element, childRect);
                         }
                         this.SceneViewModel.ElementSelectionSet.SetSelection((SceneElement)element);
                     }
                     editTransaction.Commit();
                 }
             }
         }
     }
     finally
     {
         PerformanceUtility.EndPerformanceSequence(PerformanceEvent.Make3D);
     }
 }
        protected override void ApplyScale(Vector scale, Point center)
        {
            Dictionary <SceneElement, Size> dictionary = this.CalculateClampedSizes(ref scale);
            Vector          vector1 = new Vector(scale.X < 0.0 ? -1.0 : 1.0, scale.Y < 0.0 ? -1.0 : 1.0);
            Matrix          startSharedTransform = this.StartSharedTransform;
            Matrix          inverseMatrix        = ElementUtilities.GetInverseMatrix(startSharedTransform);
            ILayoutDesigner designerForChild     = this.ActiveSceneViewModel.GetLayoutDesignerForChild(this.EditingElementSet.PrimaryElement, true);

            foreach (SceneElement index in this.EditingElementSet.Elements)
            {
                double width  = dictionary[index].Width;
                double height = dictionary[index].Height;
                Rect   rect1  = this.StartBoundsDictionary[index];
                Point  renderTransformOrigin = ((Base2DElement)index).RenderTransformOrigin;
                Point  point1  = new Point(rect1.X + rect1.Width * renderTransformOrigin.X, rect1.Y + rect1.Height * renderTransformOrigin.Y);
                Matrix matrix1 = this.ElementToElementsTransformDictionary[index];
                Matrix matrix2 = new Matrix();
                matrix2.Translate(-center.X, -center.Y);
                matrix1 *= matrix2;
                Point  point2  = matrix1.Transform(point1);
                Vector vector2 = new Point(point2.X * scale.X, point2.Y * scale.Y) - point2;
                Vector vector3 = new Vector((width - rect1.Width) * renderTransformOrigin.X, (height - rect1.Height) * renderTransformOrigin.Y);
                Vector vector4 = vector2 * startSharedTransform - vector3;
                Matrix matrix3 = this.StartTransformsDictionary[index];
                Matrix m       = new Matrix();
                m.Scale(scale.X, scale.Y);
                Matrix matrix4 = ElementUtilities.GetInverseMatrix(m) * matrix3 * inverseMatrix;
                Vector vector5 = new Vector(matrix3.OffsetX, matrix3.OffsetY) * inverseMatrix;
                matrix4.ScaleAt(scale.X, scale.Y, vector5.X, vector5.Y);
                CanonicalDecomposition newTransform = new CanonicalDecomposition(matrix4 * startSharedTransform);
                newTransform.ScaleX      *= vector1.X;
                newTransform.ScaleY      *= vector1.Y;
                newTransform.Translation += vector4;
                AdornedToolBehavior.UpdateElementTransform(index, newTransform, AdornedToolBehavior.TransformPropertyFlags.Scale | AdornedToolBehavior.TransformPropertyFlags.Skew | AdornedToolBehavior.TransformPropertyFlags.RotatationAngle);
                Rect rect2 = this.initialRects[index];
                rect2.Offset(newTransform.TranslationX - this.initialTransforms[index].TranslationX, newTransform.TranslationY - this.initialTransforms[index].TranslationY);
                rect2.Width  = width;
                rect2.Height = height;
                BaseFrameworkElement child             = (BaseFrameworkElement)index;
                LayoutOverrides      overridesToIgnore = (LayoutOverrides)(0 | (!object.Equals((object)width, (object)rect1.Width) ? 16 : 0) | (!object.Equals((object)height, (object)rect1.Height) ? 32 : 0));
                designerForChild.SetChildRect(child, rect2, this.initialOverrides[index], overridesToIgnore, LayoutOverrides.None);
                if (!object.Equals((object)width, (object)rect1.Width) || !object.Equals((object)height, (object)rect1.Height))
                {
                    PathElement.EnsureStretchIsFill((SceneNode)index);
                }
                PathElement.PathTransformHelper pathTransformHelper;
                if (this.pathTransformHelpers.TryGetValue(index, out pathTransformHelper))
                {
                    pathTransformHelper.Update(scale.X * vector1.X, scale.Y * vector1.Y);
                }
            }
        }
Exemple #8
0
        public override sealed void Execute()
        {
            BaseFrameworkElement child1            = this.SceneViewModel.ElementSelectionSet.PrimarySelection as BaseFrameworkElement;
            BaseFrameworkElement frameworkElement  = child1.ParentElement as BaseFrameworkElement;
            ILayoutDesigner      designerForParent = frameworkElement.ViewModel.GetLayoutDesignerForParent((SceneElement)frameworkElement, true);
            Rect childRect1 = designerForParent.GetChildRect(child1);

            using (SceneEditTransaction editTransaction = this.SceneViewModel.CreateEditTransaction(this.UndoDescription))
            {
                foreach (BaseFrameworkElement child2 in this.SceneViewModel.ElementSelectionSet.Selection)
                {
                    Rect   childRect2 = designerForParent.GetChildRect(child2);
                    Vector offset     = this.GetOffset(childRect1, childRect2);
                    childRect2.Offset(offset);
                    designerForParent.SetChildRect(child2, childRect2, false, false);
                }
                editTransaction.Commit();
            }
        }
Exemple #9
0
        protected override void ApplyScale(Vector scale, Point center)
        {
            Vector             scale1             = new Vector(Math.Abs(scale.X), Math.Abs(scale.Y));
            Vector             scale2             = new Vector(scale.X < 0.0 ? -1.0 : 1.0, scale.Y < 0.0 ? -1.0 : 1.0);
            Vector             vector1            = new Vector(this.StartCenter.X, this.StartCenter.Y);
            Size               newSize            = this.ComputeNewSize(scale1);
            Point              topLeft            = this.StartBounds.TopLeft;
            CanonicalTransform canonicalTransform = new CanonicalTransform(this.StartTransform);

            canonicalTransform.ApplyScale(scale, this.StartCenter, center);
            Point point1 = (topLeft - vector1) * canonicalTransform.TransformGroup.Value + vector1;
            Point renderTransformOrigin = this.BaseEditingElement.RenderTransformOrigin;

            renderTransformOrigin.X *= newSize.Width;
            renderTransformOrigin.Y *= newSize.Height;
            CanonicalTransform newTransform = new CanonicalTransform(this.StartTransform);

            newTransform.ApplyScale(scale2, renderTransformOrigin, center);
            Vector vector2 = (Vector)renderTransformOrigin;
            Point  point2  = (topLeft - vector2) * newTransform.TransformGroup.Value + vector2;

            newTransform.Translation += point1 - point2;
            AdornedToolBehavior.UpdateElementTransform(this.EditingElement, newTransform, AdornedToolBehavior.TransformPropertyFlags.Scale);
            ILayoutDesigner designerForChild = this.ActiveSceneViewModel.GetLayoutDesignerForChild(this.EditingElement, true);
            Rect            rect             = this.initialRect;

            rect.Offset(newTransform.TranslationX - this.StartTransform.TranslationX, newTransform.TranslationY - this.StartTransform.TranslationY);
            rect.Width  = newSize.Width;
            rect.Height = newSize.Height;
            LayoutOverrides overridesToIgnore = (LayoutOverrides)(0 | (!object.Equals((object)rect.Width, (object)this.StartSize.Width) ? 16 : 0) | (!object.Equals((object)rect.Height, (object)this.StartSize.Height) ? 32 : 0));

            designerForChild.SetChildRect(this.BaseEditingElement, rect, this.initialOverrides, overridesToIgnore, LayoutOverrides.None);
            if (!object.Equals((object)rect.Width, (object)this.StartSize.Width) || !object.Equals((object)rect.Height, (object)this.StartSize.Height))
            {
                PathElement.EnsureStretchIsFill((SceneNode)this.EditingElement);
            }
            if (this.transformHelper == null)
            {
                return;
            }
            this.transformHelper.Update(scale1.X, scale1.Y);
        }
Exemple #10
0
        protected virtual void DoUpdateElementPosition(Point pointBegin, Point pointEnd)
        {
            IViewVisual viewVisual1 = this.ActiveSceneInsertionPoint.SceneElement.Visual as IViewVisual;
            IViewVisual viewVisual2 = this.LayoutTargetElement.Visual as IViewVisual;
            IViewVisual visual      = viewVisual2 != null ? viewVisual2.VisualParent as IViewVisual : (IViewVisual)null;

            if (visual != null && viewVisual1 != visual && (viewVisual1 != null && this.ActiveSceneViewModel.ProjectContext.ResolveType(PlatformTypes.UIElement).RuntimeType.IsAssignableFrom(visual.TargetType)))
            {
                GeneralTransform generalTransform = viewVisual1.TransformToVisual(visual);
                pointBegin = generalTransform.Transform(pointBegin);
                pointEnd   = generalTransform.Transform(pointEnd);
            }
            double width  = Math.Abs(pointEnd.X - pointBegin.X);
            double height = Math.Abs(pointEnd.Y - pointBegin.Y);

            this.ReplaceSubTransaction();
            ILayoutDesigner designerForChild = this.ActiveSceneViewModel.GetLayoutDesignerForChild((SceneElement)this.LayoutTargetElement, true);
            Vector          vector           = new Vector(Math.Min(pointBegin.X, pointEnd.X), Math.Min(pointBegin.Y, pointEnd.Y));
            Rect            rect             = new Rect(vector.X, vector.Y, width, height);

            designerForChild.SetChildRect(this.LayoutTargetElement, rect, LayoutOverrides.None, LayoutOverrides.Width | LayoutOverrides.Height, LayoutOverrides.None, SetRectMode.CreateAtPosition);
        }
Exemple #11
0
        public static Transform ReplacePathGeometry(PathElement pathElement, PathGeometry pathGeometry, SceneEditTransaction editTransaction)
        {
            Transform transform1 = Transform.Identity;

            using (pathElement.ViewModel.ForceBaseValue())
            {
                if (pathGeometry == null)
                {
                    pathElement.ClearLocalValue(PathElement.DataProperty);
                }
                else
                {
                    editTransaction.Update();
                    ILayoutDesigner designerForChild = pathElement.ViewModel.GetLayoutDesignerForChild((SceneElement)pathElement, true);
                    Rect            childRect        = designerForChild.GetChildRect((BaseFrameworkElement)pathElement);
                    Path            path             = pathElement.Path;
                    Transform       transform2       = path == null ? (Transform)null : path.RenderTransform;
                    Point           point1           = path == null ? new Point(0.0, 0.0) : path.RenderTransformOrigin;
                    double          num           = path == null || path.Stroke == null ? 0.0 : path.StrokeThickness;
                    Rect            bounds        = pathGeometry.Bounds;
                    PathGeometry    pathGeometry1 = new PathGeometry();
                    pathGeometry1.AddGeometry((System.Windows.Media.Geometry)pathGeometry);
                    Rect   rect1   = PathCommandHelper.InflateRectByStrokeWidth(pathGeometry1.Bounds, pathElement, false);
                    Vector vector1 = new Vector(-rect1.Left, -rect1.Top);
                    transform1 = (Transform) new TranslateTransform(vector1.X, vector1.Y);
                    PathGeometry pathGeometry2 = PathGeometryUtilities.TransformGeometry((System.Windows.Media.Geometry)pathGeometry1, transform1);
                    pathElement.PathGeometry = pathGeometry2;
                    PropertyReference propertyReference = PathCommandHelper.GetPathDataPropertyReference(pathElement.Platform);
                    PathCommandHelper.TransformPointKeyframes((SceneElement)pathElement, propertyReference, transform1);
                    if (!bounds.IsEmpty)
                    {
                        bounds.Inflate(num / 2.0, num / 2.0);
                        Rect rect2 = new Rect(childRect.Left + bounds.Left, childRect.Top + bounds.Top, bounds.Width, bounds.Height);
                        editTransaction.Update();
                        designerForChild.SetChildRect((BaseFrameworkElement)pathElement, rect2);
                        if (pathElement.IsSet(Base2DElement.RenderTransformOriginProperty) != PropertyState.Set)
                        {
                            if (transform2 != null)
                            {
                                if (transform2.Value.IsIdentity)
                                {
                                    goto label_15;
                                }
                            }
                            else
                            {
                                goto label_15;
                            }
                        }
                        Vector vector2 = childRect.TopLeft + new Vector(point1.X * childRect.Width, point1.Y * childRect.Height) - rect2.TopLeft;
                        Point  point2  = new Point(0.0, 0.0);
                        if (rect2.Width != 0.0)
                        {
                            point2.X = vector2.X / rect2.Width;
                        }
                        if (rect2.Height != 0.0)
                        {
                            point2.Y = vector2.Y / rect2.Height;
                        }
                        pathElement.RenderTransformOrigin = point2;
                    }
                }
            }
label_15:
            return(transform1);
        }
Exemple #12
0
        public static PathElement ConvertToPath(BaseFrameworkElement element)
        {
            SceneViewModel  viewModel        = element.ViewModel;
            PathGeometry    pathGeometry     = PathConversionHelper.ConvertToPathGeometry((SceneElement)element);
            PathElement     pathElement      = (PathElement)viewModel.CreateSceneNode(PlatformTypes.Path);
            ILayoutDesigner designerForChild = viewModel.GetLayoutDesignerForChild((SceneElement)element, true);
            Rect            childRect        = designerForChild.GetChildRect(element);
            Transform       transform1       = Transform.Identity;

            if (element.IsSet(Base2DElement.RenderTransformProperty) == PropertyState.Set)
            {
                transform1 = (Transform)element.GetComputedValueAsWpf(Base2DElement.RenderTransformProperty);
            }
            Point point1 = new Point(0.5, 0.5);

            if (element.IsSet(Base2DElement.RenderTransformOriginProperty) == PropertyState.Set)
            {
                point1 = (Point)element.GetComputedValueAsWpf(Base2DElement.RenderTransformOriginProperty);
            }
            bool flag = false;

            using (SceneEditTransaction editTransaction = viewModel.CreateEditTransaction(StringTable.UndoUnitConvertToPath, true))
            {
                using (viewModel.ForceBaseValue())
                {
                    pathElement.PathGeometry = pathGeometry;
                    pathElement.SetValueAsWpf(ShapeElement.StretchProperty, (object)Stretch.Fill);
                    Brush textForeground = PathCommandHelper.GetTextForeground(element);
                    if (textForeground != null)
                    {
                        flag = true;
                        pathElement.SetValueAsWpf(ShapeElement.FillProperty, (object)textForeground);
                    }
                    viewModel.AnimationEditor.DeleteAllAnimations((SceneNode)element);
                    Dictionary <IPropertyId, SceneNode> properties         = SceneElementHelper.StoreProperties((SceneNode)element);
                    ISceneNodeCollection <SceneNode>    collectionForChild = element.Parent.GetCollectionForChild((SceneNode)element);
                    int index = collectionForChild.IndexOf((SceneNode)element);
                    collectionForChild[index] = (SceneNode)pathElement;
                    if (flag)
                    {
                        List <IPropertyId> list = new List <IPropertyId>();
                        foreach (KeyValuePair <IPropertyId, SceneNode> keyValuePair in properties)
                        {
                            IPropertyId key = keyValuePair.Key;
                            DependencyPropertyReferenceStep propertyReferenceStep = key as DependencyPropertyReferenceStep;
                            if (propertyReferenceStep != null && !propertyReferenceStep.IsAttachable && (propertyReferenceStep.MemberType != MemberType.DesignTimeProperty && !PlatformTypeHelper.GetDeclaringType((IMember)propertyReferenceStep).IsAssignableFrom(typeof(Path))))
                            {
                                list.Add(key);
                            }
                        }
                        foreach (IPropertyId key in list)
                        {
                            properties.Remove(key);
                        }
                    }
                    SceneElementHelper.ApplyProperties((SceneNode)pathElement, properties);
                }
                if (ProjectNeutralTypes.PrimitiveShape.IsAssignableFrom((ITypeId)element.Type))
                {
                    using (viewModel.ForceBaseValue())
                    {
                        Rect   bounds          = pathGeometry.Bounds;
                        double halfStrokeWidth = PathCommandHelper.GetHalfStrokeWidth(pathElement);
                        bounds.Inflate(halfStrokeWidth / 2.0, halfStrokeWidth / 2.0);
                        if (transform1 != Transform.Identity && bounds.Size != childRect.Size)
                        {
                            Point point2 = (Point)pathElement.GetComputedValueAsWpf(Base2DElement.RenderTransformOriginProperty);
                            Point point3 = new Point(point2.X * childRect.Width, point2.Y * childRect.Height);
                            Point point4 = new Point((point3.X - bounds.X) / bounds.Width, (point3.Y - bounds.Y) / bounds.Height);
                            pathElement.SetValueAsWpf(Base2DElement.RenderTransformOriginProperty, (object)point4);
                        }
                        bounds.Offset(childRect.Left, childRect.Top);
                        editTransaction.Update();
                        designerForChild.SetChildRect((BaseFrameworkElement)pathElement, bounds);
                    }
                }
                if (flag && !pathGeometry.IsEmpty())
                {
                    using (viewModel.ForceBaseValue())
                    {
                        Rect bounds = pathGeometry.Bounds;
                        bounds.Offset(childRect.Left, childRect.Top);
                        Point point2 = new Point(bounds.Left + point1.X * bounds.Width, bounds.Top + point1.Y * bounds.Height);
                        Point point3 = new Point(childRect.Left + childRect.Width * point1.X, childRect.Top + childRect.Height * point1.Y);
                        Point point4 = new TransformGroup()
                        {
                            Children =
                            {
                                (Transform) new TranslateTransform(-point3.X, -point3.Y),
                                transform1,
                                (Transform) new TranslateTransform(point3.X,  point3.Y)
                            }
                        }.Transform(point2);
                        Transform transform2 = (Transform) new CanonicalTransform(transform1)
                        {
                            TranslationX = 0.0,
                            TranslationY = 0.0
                        }.TransformGroup;
                        Rect rect = new Rect(point4.X - bounds.Width * point1.X, point4.Y - bounds.Height * point1.Y, bounds.Width, bounds.Height);
                        pathElement.SetValueAsWpf(Base2DElement.RenderTransformOriginProperty, (object)point1);
                        editTransaction.Update();
                        designerForChild.SetChildRect((BaseFrameworkElement)pathElement, rect);
                        pathElement.RenderTransform = transform2;
                    }
                }
                editTransaction.Commit();
            }
            return(pathElement);
        }
Exemple #13
0
        public virtual bool AddToDocument(IProjectItem projectItem, IView view, ISceneInsertionPoint insertionPoint, Rect rect)
        {
            SceneView sceneView = view as SceneView;

            if (sceneView != null && sceneView.IsDesignSurfaceEnabled && insertionPoint != null)
            {
                SceneViewModel viewModel = sceneView.ViewModel;
                string         str       = insertionPoint.SceneNode.DocumentNode.Context.MakeResourceReference(projectItem.DocumentReference.Path);
                if (!string.IsNullOrEmpty(str))
                {
                    SceneElement element = this.CreateElement(viewModel, insertionPoint, str);
                    if (element != null)
                    {
                        try
                        {
                            using (SceneEditTransaction editTransaction = viewModel.CreateEditTransaction(StringTable.AssetAddAssetUndo))
                            {
                                IList <SceneElement> list = this.AddToDocumentInternal(str, element, insertionPoint, viewModel, editTransaction);
                                editTransaction.Update();
                                if (sceneView.IsValid && list.Count > 0)
                                {
                                    element = list[0];
                                    if (element != null && element.IsViewObjectValid && (this.designerContext.ActiveView == sceneView && sceneView.ViewRoot != null) && element.Visual != null)
                                    {
                                        sceneView.EnsureVisible(element.Visual);
                                    }
                                    BaseFrameworkElement child = element as BaseFrameworkElement;
                                    if (child != null)
                                    {
                                        SetRectMode setRectMode = SetRectMode.CreateAtPosition;
                                        if (rect.IsEmpty)
                                        {
                                            rect        = new Rect(0.0, 0.0, double.PositiveInfinity, double.PositiveInfinity);
                                            setRectMode = SetRectMode.CreateDefault;
                                        }
                                        if (double.IsPositiveInfinity(rect.Width))
                                        {
                                            rect.Width = this.GetNativeWidth((SceneElement)child);
                                        }
                                        if (double.IsPositiveInfinity(rect.Height))
                                        {
                                            rect.Height = this.GetNativeHeight((SceneElement)child);
                                        }
                                        using (viewModel.ForceBaseValue())
                                        {
                                            ILayoutDesigner designerForChild = viewModel.GetLayoutDesignerForChild((SceneElement)child, true);
                                            LayoutOverrides layoutOverrides  = LayoutOverrides.HorizontalAlignment | LayoutOverrides.VerticalAlignment;
                                            designerForChild.SetChildRect(child, rect, LayoutOverrides.None, layoutOverrides, layoutOverrides, setRectMode);
                                        }
                                    }
                                    viewModel.ElementSelectionSet.SetSelection((ICollection <SceneElement>)list, (SceneElement)null);
                                }
                                editTransaction.Commit();
                            }
                            return(true);
                        }
                        catch (InvalidOperationException ex)
                        {
                            this.DesignerContext.MessageDisplayService.ShowError(string.Format((IFormatProvider)CultureInfo.CurrentCulture, StringTable.AssetElementInsertionFailedDialogMessage, new object[2]
                            {
                                (object)element.Name,
                                (object)ex.Message
                            }));
                        }
                    }
                }
            }
            return(false);
        }
Exemple #14
0
        protected override void EndEditingInternal(bool pathJustCreated)
        {
            Matrix identity = Matrix.Identity;

            if (!pathJustCreated)
            {
                Transform geometryTransform = this.pathElement.GeometryTransform;
                if (geometryTransform != null)
                {
                    identity = geometryTransform.Value;
                }
            }
            Rect extent1 = PathGeometryUtilities.TightExtent(this.PathGeometry, identity);
            Rect extent2 = extent1;
            bool flag1   = false;

            if (this.ViewModel.AnimationEditor.IsKeyFraming)
            {
                if ((Stretch)this.pathElement.GetLocalOrDefaultValueAsWpf(ShapeElement.StretchProperty) != Stretch.None)
                {
                    flag1 = true;
                    if (!pathJustCreated)
                    {
                        extent1 = PathGeometryUtilities.TightExtent(this.pathElement.PathGeometry, Matrix.Identity);
                    }
                    using (this.ViewModel.ForceBaseValue())
                    {
                        using (this.ViewModel.AnimationEditor.DeferKeyFraming())
                        {
                            this.pathElement.SetValueAsWpf(ShapeElement.StretchProperty, (object)Stretch.None);
                            this.ViewModel.Document.OnUpdatedEditTransaction();
                        }
                    }
                }
                if (this.pathElement.EnsureSingleSegmentsInPathGeometry())
                {
                    this.ViewModel.Document.OnUpdatedEditTransaction();
                }
            }
            Rect         extent3        = PathCommandHelper.InflateRectByStrokeWidth(extent1, this.pathElement, pathJustCreated);
            Rect         rect1          = PathCommandHelper.InflateRectByStrokeWidth(extent2, this.pathElement, pathJustCreated);
            Rect         computedBounds = this.pathElement.GetComputedBounds((Base2DElement)this.pathElement);
            PathGeometry pathGeometry1  = this.PathGeometry;

            if (flag1 && !pathJustCreated)
            {
                ScenePathEditorTarget.NormalizePathGeometry(pathGeometry1, extent3, computedBounds);
            }
            if (flag1)
            {
                this.OnMatrixChanged();
            }
            Vector    vector1     = new Vector(extent3.Left, extent3.Top);
            Transform transform   = (Transform)null;
            Point     centerPoint = new Point();
            bool      flag2       = (Stretch)this.pathElement.GetComputedValueAsWpf(ShapeElement.StretchProperty) == Stretch.None && (this.ViewModel.AnimationEditor.IsKeyFraming || this.pathElement.HasVertexAnimations) && !pathJustCreated;

            if (flag2 && !computedBounds.Contains(rect1))
            {
                ILayoutDesigner designerForChild = this.ViewModel.GetLayoutDesignerForChild((SceneElement)this.pathElement, true);
                Rect            childRect        = designerForChild.GetChildRect((BaseFrameworkElement)this.pathElement);
                double          x       = Math.Min(0.0, rect1.Left);
                double          y       = Math.Min(0.0, rect1.Top);
                Vector          vector2 = new Vector(x, y);
                centerPoint = this.pathElement.RenderTransformOrigin;
                transform   = this.pathElement.RenderTransform;
                if (transform != null && !transform.Value.IsIdentity)
                {
                    using (this.ViewModel.ForceBaseValue())
                    {
                        using (this.ViewModel.AnimationEditor.DeferKeyFraming())
                            this.UpdateCenterPoint(new Point(0.0, 0.0));
                    }
                    vector2 *= transform.Value;
                }
                double num1 = Math.Max(0.0, rect1.Right - computedBounds.Right);
                double num2 = Math.Max(0.0, rect1.Bottom - computedBounds.Bottom);
                childRect.X      += vector2.X;
                childRect.Y      += vector2.Y;
                childRect.Width  += -x + num1;
                childRect.Height += -y + num2;
                using (this.ViewModel.ForceBaseValue())
                {
                    using (this.ViewModel.AnimationEditor.DeferKeyFraming())
                        designerForChild.SetChildRect((BaseFrameworkElement)this.pathElement, childRect);
                }
                if (x != 0.0 || y != 0.0)
                {
                    this.AdjustKeyframes(new Vector(x, y));
                    ScenePathEditorTarget.UpdateAllPoints(pathGeometry1, new Vector(x, y), 1.0, 1.0);
                    PathGeometry pathGeometry2 = this.pathElement.PathGeometry;
                    ScenePathEditorTarget.UpdateAllPoints(pathGeometry2, new Vector(x, y), 1.0, 1.0);
                    this.pathElement.PathGeometry = pathGeometry2;
                }
                this.ViewModel.Document.OnUpdatedEditTransaction();
                if (transform != null && !transform.Value.IsIdentity)
                {
                    using (this.ViewModel.ForceBaseValue())
                    {
                        using (this.ViewModel.AnimationEditor.DeferKeyFraming())
                            this.UpdateCenterPoint(centerPoint);
                    }
                }
            }
            if (!flag2 && (Stretch)this.pathElement.GetComputedValueAsWpf(ShapeElement.StretchProperty) == Stretch.None)
            {
                ScenePathEditorTarget.UpdateAllPoints(pathGeometry1, vector1, 1.0, 1.0);
            }
            if (!flag2)
            {
                using (this.ViewModel.ForceBaseValue())
                {
                    using (this.ViewModel.AnimationEditor.DeferKeyFraming())
                    {
                        centerPoint = this.pathElement.RenderTransformOrigin;
                        transform   = this.pathElement.RenderTransform;
                        if (!extent3.IsEmpty)
                        {
                            if (transform != null && !transform.Value.IsIdentity)
                            {
                                this.UpdateCenterPoint(new Point(0.0, 0.0));
                                vector1 *= transform.Value;
                            }
                            ILayoutDesigner designerForChild = this.ViewModel.GetLayoutDesignerForChild((SceneElement)this.pathElement, false);
                            Rect            rect2            = designerForChild.GetChildRect((BaseFrameworkElement)this.pathElement);
                            if (pathJustCreated)
                            {
                                rect2 = new Rect(0.0, 0.0, 0.0, 0.0);
                            }
                            double width  = extent3.Width;
                            double height = extent3.Height;
                            rect2.Offset(vector1);
                            rect2.Width  = width;
                            rect2.Height = height;
                            designerForChild.SetChildRect((BaseFrameworkElement)this.pathElement, rect2);
                        }
                    }
                }
            }
            if (this.pathElement.IsAttached && (this.ViewModel.AnimationEditor.IsKeyFraming || this.pathElement.HasVertexAnimations) && !pathJustCreated)
            {
                new PathDiff((Base2DElement)this.pathElement, PathElement.DataProperty, this.PathDiffChangeList).SetPathUsingMinimalDiff(pathGeometry1);
            }
            else
            {
                this.pathElement.PathGeometry = pathGeometry1;
            }
            if (flag2)
            {
                return;
            }
            using (this.ViewModel.ForceBaseValue())
            {
                using (this.ViewModel.AnimationEditor.DeferKeyFraming())
                {
                    if (extent3.IsEmpty)
                    {
                        return;
                    }
                    this.ViewModel.Document.OnUpdatedEditTransaction();
                    if (transform == null || transform.Value.IsIdentity)
                    {
                        return;
                    }
                    this.UpdateCenterPoint(centerPoint);
                }
            }
        }
        public override void Execute(object arg)
        {
            DesignerContext designerContext      = this.DesignerContext;
            SceneViewModel  activeSceneViewModel = designerContext.ActiveSceneViewModel;
            ITypeId         type = this.Type;

            if (type is ProjectNeutralTypeId)
            {
                bool flag = activeSceneViewModel.ProjectContext.PlatformMetadata.IsSupported((ITypeResolver)this.DesignerContext.ActiveSceneViewModel.ProjectContext, type);
                if (!flag && this.IsDragDropContainer)
                {
                    IMessageDisplayService messageDisplayService = activeSceneViewModel.DesignerContext.MessageDisplayService;
                    flag = ToolkitHelper.EnsureSilverlightToolkitTypeAvailable((ITypeResolver)activeSceneViewModel.ProjectContext, type, messageDisplayService, StringTable.SilverlightToolkitDragDropNotInstalled, StringTable.SilverlightToolkitDragDropIncorrectVersion);
                }
                if (!flag)
                {
                    return;
                }
            }
            using (SceneEditTransaction editTransaction = designerContext.ActiveDocument.CreateEditTransaction(string.Format((IFormatProvider)CultureInfo.CurrentCulture, StringTable.UndoUnitGroupIntoLayoutType, new object[1]
            {
                (object)this.Type.Name
            })))
            {
                List <SceneElement> list1    = new List <SceneElement>();
                List <SceneNode>    elements = new List <SceneNode>();
                list1.AddRange((IEnumerable <SceneElement>)designerContext.SelectionManager.ElementSelectionSet.Selection);
                GroupIntoLayoutTypeCommand.OrientationHelper orientationHelper = new GroupIntoLayoutTypeCommand.OrientationHelper();
                list1.Sort((IComparer <SceneElement>) new ZOrderComparer <SceneElement>(this.SceneViewModel.RootNode));
                List <LayoutCacheRecord> list2 = new List <LayoutCacheRecord>(list1.Count);
                Rect empty = Rect.Empty;
                for (int index = 0; index < list1.Count; ++index)
                {
                    list2.Add((LayoutCacheRecord)null);
                    BaseFrameworkElement element = list1[index] as BaseFrameworkElement;
                    if (element != null)
                    {
                        ILayoutDesigner designerForChild   = element.ViewModel.GetLayoutDesignerForChild((SceneElement)element, true);
                        Rect            roundedUpChildRect = LayoutRoundingHelper.GetRoundedUpChildRect(designerForChild, element);
                        empty.Union(roundedUpChildRect);
                        orientationHelper.AddChildRect((SceneNode)element, roundedUpChildRect);
                        LayoutCacheRecord layoutCacheRecord = designerForChild.CacheLayout(element);
                        list2[index] = layoutCacheRecord;
                        elements.Add((SceneNode)element);
                    }
                }
                Dictionary <IPropertyId, SceneNode> properties = (Dictionary <IPropertyId, SceneNode>)null;
                using (this.SceneViewModel.ForceBaseValue())
                {
                    using (this.SceneViewModel.DisableDrawIntoState())
                    {
                        SceneElement sceneElement1 = (SceneElement)null;
                        SceneElement sceneElement2 = (SceneElement)activeSceneViewModel.CreateSceneNode(type);
                        Orientation? nullable      = orientationHelper.ApplyOrientation(sceneElement2);
                        if (nullable.HasValue)
                        {
                            orientationHelper.SortElements(elements, nullable.Value);
                        }
                        int num;
                        if (list1.Count == 1 && list1[0] is BaseFrameworkElement)
                        {
                            int?fixedCapacity = sceneElement2.DefaultContent.FixedCapacity;
                            num = fixedCapacity.GetValueOrDefault() != 1 ? 0 : (fixedCapacity.HasValue ? true : false);
                        }
                        else
                        {
                            num = 0;
                        }
                        bool flag = num != 0;
                        if (sceneElement2 != null)
                        {
                            activeSceneViewModel.GetLayoutDesignerForParent(sceneElement2, true);
                        }
                        foreach (SceneElement sceneElement3 in list1)
                        {
                            if (sceneElement3 != null)
                            {
                                BaseFrameworkElement frameworkElement = sceneElement3 as BaseFrameworkElement;
                                ILayoutDesigner      layoutDesigner   = frameworkElement == null ? (ILayoutDesigner)null : sceneElement3.ViewModel.GetLayoutDesignerForChild((SceneElement)frameworkElement, true);
                                if (flag)
                                {
                                    properties = SceneElementHelper.StoreProperties((SceneNode)sceneElement3, layoutDesigner.GetLayoutProperties(), true);
                                }
                                if (this.SceneViewModel.LockedInsertionPoint != null && this.SceneViewModel.LockedInsertionPoint.SceneElement == sceneElement3)
                                {
                                    sceneElement1 = sceneElement3;
                                }
                            }
                        }
                        if (list1.Count == 1)
                        {
                            VisualStateManagerSceneNode.MoveStates(list1[0], sceneElement2);
                        }
                        using (activeSceneViewModel.DisableUpdateChildrenOnAddAndRemove())
                        {
                            SceneElement primarySelection = designerContext.SelectionManager.ElementSelectionSet.PrimarySelection;
                            designerContext.SelectionManager.ElementSelectionSet.Clear();
                            Dictionary <IPropertyId, List <SceneNode> > storedChildren = new Dictionary <IPropertyId, List <SceneNode> >();
                            storedChildren.Add((IPropertyId)sceneElement2.DefaultContentProperty, elements);
                            ISceneNodeCollection <SceneNode> collectionContainer = primarySelection.GetCollectionContainer();
                            foreach (SceneElement sceneElement3 in list1)
                            {
                                if (sceneElement3 != primarySelection)
                                {
                                    sceneElement3.Remove();
                                }
                            }
                            int index1 = collectionContainer.IndexOf((SceneNode)primarySelection);
                            primarySelection.Remove();
                            collectionContainer.Insert(index1, (SceneNode)sceneElement2);
                            ChangeLayoutTypeCommand.ApplyChildren(sceneElement2, storedChildren, empty.Size);
                            if (flag)
                            {
                                SceneElementHelper.FixElementNameBindingsInStoredProperties((SceneNode)list1[0], (SceneNode)sceneElement2, properties);
                                SceneElementHelper.ApplyProperties((SceneNode)sceneElement2, properties);
                            }
                            else
                            {
                                ILayoutDesigner designerForChild = sceneElement2.ViewModel.GetLayoutDesignerForChild(sceneElement2, true);
                                if (sceneElement2.IsViewObjectValid)
                                {
                                    LayoutOverrides layoutOverrides   = LayoutOverrides.None;
                                    LayoutOverrides overridesToIgnore = LayoutOverrides.None;
                                    if (nullable.HasValue && nullable.Value == Orientation.Horizontal)
                                    {
                                        layoutOverrides |= LayoutOverrides.Width;
                                    }
                                    else
                                    {
                                        overridesToIgnore |= LayoutOverrides.Width;
                                    }
                                    if (nullable.HasValue && nullable.Value == Orientation.Vertical)
                                    {
                                        layoutOverrides |= LayoutOverrides.Height;
                                    }
                                    else
                                    {
                                        overridesToIgnore |= LayoutOverrides.Height;
                                    }
                                    designerForChild.SetChildRect((BaseFrameworkElement)sceneElement2, empty, layoutOverrides, overridesToIgnore, LayoutOverrides.None);
                                }
                            }
                            editTransaction.Update();
                            if (sceneElement2.IsViewObjectValid)
                            {
                                this.SceneViewModel.DefaultView.UpdateLayout();
                                SceneElement    parentElement     = primarySelection.ParentElement;
                                ILayoutDesigner designerForParent = activeSceneViewModel.GetLayoutDesignerForParent(parentElement, true);
                                for (int index2 = 0; index2 < list1.Count; ++index2)
                                {
                                    SceneElement         sceneElement3    = list1[index2];
                                    BaseFrameworkElement frameworkElement = sceneElement3 as BaseFrameworkElement;
                                    if (frameworkElement != null)
                                    {
                                        LayoutCacheRecord layoutCacheRecord = list2[index2];
                                        Rect rect = LayoutRoundingHelper.RoundUpLayoutRect(frameworkElement, layoutCacheRecord.Rect);
                                        rect.Location = (Point)(rect.Location - empty.Location);
                                        designerForParent.ClearUnusedLayoutProperties(frameworkElement);
                                        designerForParent.SetChildRect(frameworkElement, rect, flag ? LayoutOverrides.None : layoutCacheRecord.Overrides, LayoutOverrides.Margin | LayoutOverrides.GridBox, LayoutOverrides.None);
                                        if (this.IsDragDropContainer)
                                        {
                                            sceneElement3.SetValue(Base2DElement.AllowDropProperty, (object)true);
                                        }
                                    }
                                }
                            }
                            if (sceneElement1 != null)
                            {
                                this.SceneViewModel.SetLockedInsertionPoint(sceneElement1);
                            }
                        }
                        designerContext.SelectionManager.ElementSelectionSet.SetSelection(sceneElement2);
                        editTransaction.Commit();
                    }
                }
            }
        }
Exemple #16
0
        private SceneNode[] Ungroup(SceneEditTransaction transaction, BaseFrameworkElement group)
        {
            SceneElement parentElement = group.ParentElement;

            if (parentElement == null)
            {
                return(new SceneNode[0]);
            }
            transaction.Update();
            ILayoutDesigner designerForParent1       = this.SceneViewModel.GetLayoutDesignerForParent(parentElement, true);
            Rect            childRect                = designerForParent1.GetChildRect(group);
            Matrix          effectiveRenderTransform = group.GetEffectiveRenderTransform(false);

            SceneNode[] array = new SceneNode[group.DefaultContent.Count];
            group.DefaultContent.CopyTo(array, 0);
            using (this.SceneViewModel.DisableUpdateChildrenOnAddAndRemove())
            {
                Transform[]         transformArray         = new Transform[array.Length];
                Point[]             pointArray             = new Point[array.Length];
                LayoutCacheRecord[] layoutCacheRecordArray = new LayoutCacheRecord[array.Length];
                ILayoutDesigner     designerForParent2     = group.ViewModel.GetLayoutDesignerForParent((SceneElement)group, true);
                for (int index = 0; index < array.Length; ++index)
                {
                    BaseFrameworkElement frameworkElement = array[index] as BaseFrameworkElement;
                    if (frameworkElement != null)
                    {
                        transformArray[index] = (Transform)frameworkElement.GetComputedValueAsWpf(Base2DElement.RenderTransformProperty);
                        pointArray[index]     = frameworkElement.RenderTransformOrigin;
                        designerForParent2.GetChildRect(frameworkElement);
                        LayoutCacheRecord layoutCacheRecord = designerForParent2.CacheLayout(frameworkElement);
                        layoutCacheRecordArray[index] = layoutCacheRecord;
                    }
                }
                int num1;
                if (array.Length == 1 && array[0] is BaseFrameworkElement)
                {
                    int?fixedCapacity = group.DefaultContent.FixedCapacity;
                    num1 = fixedCapacity.GetValueOrDefault() != 1 ? 0 : (fixedCapacity.HasValue ? true : false);
                }
                else
                {
                    num1 = 0;
                }
                bool flag = num1 != 0;
                if (flag)
                {
                    Dictionary <IPropertyId, SceneNode> properties = SceneElementHelper.StoreProperties((SceneNode)group, designerForParent1.GetLayoutProperties(), true);
                    SceneElementHelper.FixElementNameBindingsInStoredProperties((SceneNode)group, array[0], properties);
                    if (!SceneElementHelper.ApplyProperties(array[0], properties))
                    {
                        flag = false;
                    }
                }
                if (array.Length == 1 && array[0] is SceneElement)
                {
                    VisualStateManagerSceneNode.MoveStates((SceneElement)group, (SceneElement)array[0]);
                }
                using (this.SceneViewModel.ForceBaseValue())
                {
                    SceneElement sceneElement = (SceneElement)null;
                    for (int index = 0; index < array.Length; ++index)
                    {
                        BaseFrameworkElement frameworkElement = array[index] as BaseFrameworkElement;
                        if (frameworkElement != null)
                        {
                            if (this.SceneViewModel.LockedInsertionPoint != null && this.SceneViewModel.LockedInsertionPoint.SceneElement == frameworkElement)
                            {
                                sceneElement = (SceneElement)frameworkElement;
                            }
                            DocumentNodeHelper.PreserveFormatting(frameworkElement.DocumentNode);
                            frameworkElement.Remove();
                        }
                    }
                    ISceneNodeCollection <SceneNode> collectionContainer = group.GetCollectionContainer();
                    int index1 = collectionContainer.IndexOf((SceneNode)group);
                    this.SceneViewModel.AnimationEditor.DeleteAllAnimationsInSubtree((SceneElement)group);
                    this.SceneViewModel.RemoveElement((SceneNode)group);
                    Matrix matrix1 = effectiveRenderTransform;
                    matrix1.OffsetX = 0.0;
                    matrix1.OffsetY = 0.0;
                    for (int index2 = array.Length - 1; index2 >= 0; --index2)
                    {
                        BaseFrameworkElement frameworkElement = array[index2] as BaseFrameworkElement;
                        if (frameworkElement != null)
                        {
                            Matrix matrix2 = (transformArray[index2] ?? Transform.Identity).Value;
                            collectionContainer.Insert(index1, (SceneNode)frameworkElement);
                            CanonicalTransform canonicalTransform = new CanonicalTransform((Transform) new MatrixTransform(matrix2 * matrix1));
                            if (frameworkElement.GetLocalValue(Base2DElement.RenderTransformProperty) != null || !canonicalTransform.TransformGroup.Value.IsIdentity)
                            {
                                frameworkElement.SetValue(Base2DElement.RenderTransformProperty, canonicalTransform.GetPlatformTransform(frameworkElement.Platform.GeometryHelper));
                                if (frameworkElement.IsSet(Base2DElement.RenderTransformOriginProperty) == PropertyState.Unset)
                                {
                                    frameworkElement.SetValueAsWpf(Base2DElement.RenderTransformOriginProperty, (object)new Point(0.5, 0.5));
                                }
                            }
                        }
                    }
                    transaction.Update();
                    if (sceneElement != null)
                    {
                        this.SceneViewModel.SetLockedInsertionPoint(sceneElement);
                    }
                    bool[] flagArray = new bool[array.Length];
                    int    length    = 0;
                    for (int index2 = 0; index2 < array.Length; ++index2)
                    {
                        BaseFrameworkElement frameworkElement = array[index2] as BaseFrameworkElement;
                        if (frameworkElement != null && array[index2].Parent != null)
                        {
                            if (!flag)
                            {
                                LayoutCacheRecord layoutCacheRecord = layoutCacheRecordArray[index2];
                                Rect  rect1  = layoutCacheRecord.Rect;
                                Point point1 = new Point(rect1.X + rect1.Width * pointArray[index2].X, rect1.Y + rect1.Height * pointArray[index2].Y);
                                Point point2 = effectiveRenderTransform.Transform(point1);
                                Rect  rect2  = new Rect(rect1.TopLeft + point2 - point1 + (Vector)childRect.TopLeft, rect1.Size);
                                designerForParent1.ClearUnusedLayoutProperties(frameworkElement);
                                designerForParent1.SetChildRect(frameworkElement, rect2, layoutCacheRecord.Overrides, LayoutOverrides.Margin | LayoutOverrides.GridBox, LayoutOverrides.None);
                            }
                            flagArray[index2] = true;
                            ++length;
                        }
                    }
                    SceneNode[] sceneNodeArray = new SceneNode[length];
                    int         num2           = 0;
                    for (int index2 = 0; index2 < array.Length; ++index2)
                    {
                        if (flagArray[index2])
                        {
                            sceneNodeArray[num2++] = array[index2];
                        }
                    }
                    return(sceneNodeArray);
                }
            }
        }
Exemple #17
0
        private void SetLayout(ISceneInsertionPoint insertionPoint, Rect rect, SceneNode node, SceneNode layoutTarget, SceneEditTransaction undo)
        {
            if (!PlatformTypes.UIElement.IsAssignableFrom((ITypeId)node.Type))
            {
                return;
            }
            bool flag1 = false;
            bool flag2 = false;

            if (node.IsSet(BaseFrameworkElement.WidthProperty) == PropertyState.Set && double.IsNaN(rect.Width))
            {
                rect.Width = (double)node.GetLocalOrDefaultValueAsWpf(BaseFrameworkElement.WidthProperty);
                flag1      = true;
            }
            if (node.IsSet(BaseFrameworkElement.HeightProperty) == PropertyState.Set && double.IsNaN(rect.Height))
            {
                rect.Height = (double)node.GetLocalOrDefaultValueAsWpf(BaseFrameworkElement.HeightProperty);
                flag2       = true;
            }
            using (this.ViewModel.ForceBaseValue())
            {
                BaseFrameworkElement child = layoutTarget as BaseFrameworkElement;
                if (child == null)
                {
                    return;
                }
                SetRectMode     setRectMode      = SetRectMode.Default;
                ILayoutDesigner designerForChild = child.ViewModel.GetLayoutDesignerForChild((SceneElement)child, true);
                if (double.IsNaN(rect.Width) || double.IsNaN(rect.Height))
                {
                    setRectMode = SetRectMode.CreateDefault;
                    bool flag3 = PlatformTypes.Control.IsAssignableFrom((ITypeId)node.Type) || PlatformTypes.TextBlock.IsAssignableFrom((ITypeId)node.Type);
                    for (int index = 0; index < DefaultTypeInstantiator.SizeNonExceptions.Length; ++index)
                    {
                        if (DefaultTypeInstantiator.SizeNonExceptions[index].Equals((object)node.Type))
                        {
                            flag3 = false;
                        }
                    }
                    if (!flag3)
                    {
                        BaseFrameworkElement frameworkElement = insertionPoint.SceneNode as BaseFrameworkElement;
                        if (frameworkElement != null)
                        {
                            Rect   computedTightBounds = frameworkElement.GetComputedTightBounds();
                            double val1_1 = 100.0;
                            double val1_2 = 100.0;
                            if (ProjectNeutralTypes.GridSplitter.IsAssignableFrom((ITypeId)node.Type))
                            {
                                val1_1 = 5.0;
                            }
                            else if (PlatformTypes.Button.IsAssignableFrom((ITypeId)node.Type))
                            {
                                val1_1 = 75.0;
                            }
                            else if (PlatformTypes.ComboBox.IsAssignableFrom((ITypeId)node.Type))
                            {
                                val1_1 = 120.0;
                            }
                            if (PlatformTypes.ProgressBar.IsAssignableFrom((ITypeId)node.Type))
                            {
                                val1_2 = 10.0;
                            }
                            else if (PlatformTypes.Button.IsAssignableFrom((ITypeId)node.Type) || PlatformTypes.ComboBox.IsAssignableFrom((ITypeId)node.Type))
                            {
                                val1_2 = double.NaN;
                            }
                            if ((designerForChild.GetWidthConstraintMode(child) & LayoutConstraintMode.CanvasLike) == LayoutConstraintMode.NonOverlappingGridlike)
                            {
                                val1_1 = Math.Min(val1_1, computedTightBounds.Width);
                            }
                            if ((designerForChild.GetHeightConstraintMode(child) & LayoutConstraintMode.CanvasLike) == LayoutConstraintMode.NonOverlappingGridlike)
                            {
                                val1_2 = Math.Min(val1_2, computedTightBounds.Height);
                            }
                            rect = new Rect(rect.Left, rect.Top, double.IsNaN(rect.Width) ? val1_1 : rect.Width, double.IsNaN(rect.Height) ? val1_2 : rect.Height);
                        }
                    }
                }
                LayoutOverrides layoutOverrides   = LayoutOverrides.None;
                LayoutOverrides overridesToIgnore = LayoutOverrides.None;
                Rect            rect1             = rect;
                if (double.IsNaN(rect.Width))
                {
                    layoutOverrides |= LayoutOverrides.Width;
                    rect1.Width      = 0.0;
                }
                else
                {
                    overridesToIgnore |= LayoutOverrides.Width;
                }
                if (double.IsNaN(rect.Height))
                {
                    layoutOverrides |= LayoutOverrides.Height;
                    rect1.Height     = 0.0;
                }
                else
                {
                    overridesToIgnore |= LayoutOverrides.Height;
                }
                designerForChild.SetChildRect(child, rect1, layoutOverrides, overridesToIgnore, LayoutOverrides.None, setRectMode);
                undo.Update();
                IViewVisual viewVisual = child.ViewObject as IViewVisual;
                if (viewVisual == null || !double.IsNaN(rect.Width) && !double.IsNaN(rect.Height))
                {
                    return;
                }
                viewVisual.UpdateLayout();
                Rect childRect = designerForChild.GetChildRect(child);
                if (double.IsNaN(rect.Width) && !flag1)
                {
                    if (viewVisual.RenderSize.Width < 5.0)
                    {
                        rect1.Width        = 100.0;
                        layoutOverrides   &= ~LayoutOverrides.Width;
                        overridesToIgnore |= LayoutOverrides.Width;
                    }
                    else
                    {
                        rect1.Width = childRect.Width;
                    }
                }
                if (double.IsNaN(rect.Height) && !flag2)
                {
                    if (viewVisual.RenderSize.Height < 5.0)
                    {
                        rect1.Height       = 100.0;
                        layoutOverrides   &= ~LayoutOverrides.Height;
                        overridesToIgnore |= LayoutOverrides.Height;
                    }
                    else
                    {
                        rect1.Height = childRect.Height;
                    }
                }
                LayoutOverrides nonExplicitOverrides = LayoutOverrides.None;
                if (PlatformTypes.FlowDocumentScrollViewer.IsAssignableFrom((ITypeId)child.Type) || PlatformTypes.RichTextBox.IsAssignableFrom((ITypeId)child.Type))
                {
                    nonExplicitOverrides = LayoutOverrides.Width;
                }
                designerForChild.SetChildRect(child, rect1, layoutOverrides, overridesToIgnore, nonExplicitOverrides, setRectMode);
            }
        }
        public override void Execute()
        {
            string               fileName           = "test";
            IProject             activeProject      = this.DesignerContext.ActiveProject;
            TemplateItemHelper   templateItemHelper = new TemplateItemHelper(activeProject, (IList <string>)null, (IServiceProvider)this.DesignerContext.Services);
            IProjectItemTemplate templateItem       = templateItemHelper.FindTemplateItem("UserControl");

            if (templateItem == null)
            {
                this.DesignerContext.MessageDisplayService.ShowError(StringTable.MakeUserControlTemplateNotFound);
            }
            else
            {
                SceneViewModel      activeSceneViewModel = this.DesignerContext.ActiveSceneViewModel;
                List <SceneElement> elements             = new List <SceneElement>();
                elements.AddRange((IEnumerable <SceneElement>)activeSceneViewModel.ElementSelectionSet.Selection);
                elements.Sort((IComparer <SceneElement>) new ZOrderComparer <SceneElement>(activeSceneViewModel.RootNode));
                if (this.ShowUI)
                {
                    string recommendedName = this.GetRecommendedName((IEnumerable <SceneElement>)elements);
                    MakeUserControlDialog userControlDialog = new MakeUserControlDialog(this.DesignerContext, this.DialogTitle, templateItemHelper, recommendedName);
                    bool?nullable = userControlDialog.ShowDialog();
                    if ((!nullable.GetValueOrDefault() ? 1 : (!nullable.HasValue ? true : false)) != 0)
                    {
                        return;
                    }
                    fileName = userControlDialog.ControlName;
                }
                List <IProjectItem>        itemsToOpen  = (List <IProjectItem>)null;
                IProjectItem               projectItem1 = (IProjectItem)null;
                IEnumerable <IProjectItem> source       = (IEnumerable <IProjectItem>)null;
                try
                {
                    source = templateItemHelper.AddProjectItemsForTemplateItem(templateItem, fileName, this.DesignerContext.ProjectManager.TargetFolderForProject(activeProject), CreationOptions.DoNotAllowOverwrites | CreationOptions.DoNotSelectCreatedItems | CreationOptions.DoNotSetDefaultImportPath, out itemsToOpen);
                }
                catch (Exception ex)
                {
                    if (ex is NotSupportedException || ErrorHandling.ShouldHandleExceptions(ex))
                    {
                        this.DesignerContext.MessageDisplayService.ShowError(string.Format((IFormatProvider)CultureInfo.CurrentCulture, StringTable.ProjectNewFileErrorDialogMessage, new object[2]
                        {
                            (object)fileName,
                            (object)ex.Message
                        }));
                    }
                    else
                    {
                        throw;
                    }
                }
                if (source == null || EnumerableExtensions.CountIsLessThan <IProjectItem>(source, 1))
                {
                    return;
                }
                if (itemsToOpen != null && itemsToOpen.Count > 0)
                {
                    projectItem1 = Enumerable.FirstOrDefault <IProjectItem>((IEnumerable <IProjectItem>)itemsToOpen);
                    projectItem1.OpenDocument(false, true);
                }
                if (projectItem1 != null && projectItem1.IsOpen && projectItem1.DocumentType.CanView)
                {
                    Rect empty = Rect.Empty;
                    for (int index = 0; index < elements.Count; ++index)
                    {
                        BaseFrameworkElement child = elements[index] as BaseFrameworkElement;
                        if (child != null)
                        {
                            Rect childRect = child.ViewModel.GetLayoutDesignerForChild((SceneElement)child, true).GetChildRect(child);
                            empty.Union(childRect);
                        }
                    }
                    Rect         rect              = RoundingHelper.RoundRect(empty);
                    SceneElement parentElement     = elements[0].ParentElement;
                    bool         useLayoutRounding = LayoutRoundingHelper.GetUseLayoutRounding(parentElement);
                    DataObject   dataObject        = (DataObject)null;
                    using (activeSceneViewModel.ForceBaseValue())
                    {
                        PastePackage pastePackage = new PastePackage(activeSceneViewModel);
                        pastePackage.CopyStoryboardsReferencingElements = true;
                        pastePackage.AddElements(elements);
                        dataObject = pastePackage.GetPasteDataObject();
                    }
                    SceneView sceneView = projectItem1.OpenView(true) as SceneView;
                    if (sceneView != null)
                    {
                        SceneViewModel     viewModel           = sceneView.ViewModel;
                        ProjectXamlContext projectXamlContext  = ProjectXamlContext.FromProjectContext(viewModel.ViewRoot.ProjectContext);
                        ClassAttributes    rootClassAttributes = viewModel.DocumentRoot.RootClassAttributes;
                        ITypeId            typeId = (ITypeId)null;
                        if (projectXamlContext != null && rootClassAttributes != null)
                        {
                            projectXamlContext.RefreshUnbuiltTypeDescriptions();
                            if (rootClassAttributes != null)
                            {
                                typeId = (ITypeId)projectXamlContext.GetType(projectXamlContext.ProjectAssembly.Name, rootClassAttributes.QualifiedClassName);
                            }
                        }
                        if (typeId != null && this.CheckForCircularReference((IEnumerable <SceneElement>)elements, typeId))
                        {
                            this.DesignerContext.MessageDisplayService.ShowError(StringTable.MakeUserControlCircularReferenceFound);
                            this.CleanupAfterCancel(projectItem1);
                            return;
                        }
                        using (SceneEditTransaction editTransaction = viewModel.CreateEditTransaction(StringTable.UndoUnitMakeUserControl))
                        {
                            if (!rect.IsEmpty)
                            {
                                viewModel.RootNode.SetValue(DesignTimeProperties.DesignWidthProperty, (object)rect.Width);
                                viewModel.RootNode.SetValue(DesignTimeProperties.DesignHeightProperty, (object)rect.Height);
                                if (this.AddToApplicationFlow)
                                {
                                    viewModel.RootNode.SetValue(BaseFrameworkElement.WidthProperty, (object)rect.Width);
                                    viewModel.RootNode.SetValue(BaseFrameworkElement.HeightProperty, (object)rect.Height);
                                }
                            }
                            IProperty property = LayoutRoundingHelper.ResolveUseLayoutRoundingProperty(viewModel.RootNode);
                            if (property != null)
                            {
                                viewModel.RootNode.SetValue((IPropertyId)property, (object)(bool)(useLayoutRounding ? true : false));
                            }
                            ILayoutDesigner         designerForParent = viewModel.GetLayoutDesignerForParent(viewModel.ActiveSceneInsertionPoint.SceneElement, true);
                            bool                    canceledPasteOperation;
                            ICollection <SceneNode> nodes = PasteCommand.PasteData(viewModel, new SafeDataObject((IDataObject)dataObject), viewModel.ActiveSceneInsertionPoint, out canceledPasteOperation);
                            if (canceledPasteOperation)
                            {
                                editTransaction.Cancel();
                                this.CleanupAfterCancel(projectItem1);
                                return;
                            }
                            editTransaction.Update();
                            if (nodes.Count > 0)
                            {
                                viewModel.DefaultView.UpdateLayout();
                                viewModel.SelectNodes(nodes);
                                if (designerForParent != null)
                                {
                                    foreach (SceneNode sceneNode in (IEnumerable <SceneNode>)nodes)
                                    {
                                        BaseFrameworkElement child = sceneNode as BaseFrameworkElement;
                                        if (child != null && child.IsViewObjectValid)
                                        {
                                            Rect childRect = child.ViewModel.GetLayoutDesignerForChild((SceneElement)child, true).GetChildRect(child);
                                            childRect.Location = (Point)(childRect.Location - rect.Location);
                                            designerForParent.SetChildRect(child, childRect);
                                        }
                                    }
                                }
                            }
                            editTransaction.Commit();
                        }
                        if (this.AddToApplicationFlow && this.DesignerContext.PrototypingService != null)
                        {
                            this.DesignerContext.PrototypingService.PromoteToCompositionScreen(projectItem1);
                        }
                        if (typeId != null)
                        {
                            using (activeSceneViewModel.ForceBaseValue())
                            {
                                using (activeSceneViewModel.DisableDrawIntoState())
                                {
                                    using (SceneEditTransaction editTransaction = activeSceneViewModel.CreateEditTransaction(StringTable.UndoUnitMakeUserControl))
                                    {
                                        using (activeSceneViewModel.DisableUpdateChildrenOnAddAndRemove())
                                        {
                                            SceneElement primarySelection = activeSceneViewModel.ElementSelectionSet.PrimarySelection;
                                            IProperty    propertyForChild = parentElement.GetPropertyForChild((SceneNode)primarySelection);
                                            PropertySceneInsertionPoint sceneInsertionPoint = new PropertySceneInsertionPoint(parentElement, propertyForChild);
                                            SceneNode sceneNode = (SceneNode)null;
                                            if (sceneInsertionPoint.CanInsert(typeId))
                                            {
                                                foreach (SceneElement element in elements)
                                                {
                                                    if (element != primarySelection)
                                                    {
                                                        activeSceneViewModel.AnimationEditor.DeleteAllAnimationsInSubtree(element);
                                                        element.Remove();
                                                    }
                                                }
                                                ISceneNodeCollection <SceneNode> collectionForProperty = parentElement.GetCollectionForProperty((IPropertyId)propertyForChild);
                                                int index = collectionForProperty.IndexOf((SceneNode)primarySelection);
                                                activeSceneViewModel.AnimationEditor.DeleteAllAnimationsInSubtree(primarySelection);
                                                primarySelection.Remove();
                                                sceneNode = activeSceneViewModel.CreateSceneNode(typeId);
                                                collectionForProperty.Insert(index, sceneNode);
                                                this.DesignerContext.ViewService.ActiveView = (IView)activeSceneViewModel.DefaultView;
                                                editTransaction.Update();
                                                activeSceneViewModel.DefaultView.UpdateLayout();
                                                BaseFrameworkElement child = sceneNode as BaseFrameworkElement;
                                                if (child != null && child.IsViewObjectValid)
                                                {
                                                    activeSceneViewModel.GetLayoutDesignerForParent(parentElement, true).SetChildRect(child, rect);
                                                }
                                            }
                                            if (this.AddToApplicationFlow)
                                            {
                                                if (sceneNode != null)
                                                {
                                                    sceneNode.SetValue(DesignTimeProperties.IsPrototypingCompositionProperty, (object)true);
                                                }
                                            }
                                        }
                                        editTransaction.Commit();
                                    }
                                }
                            }
                            this.DesignerContext.ViewService.ActiveView = (IView)viewModel.DefaultView;
                        }
                    }
                }
                if (itemsToOpen == null || itemsToOpen.Count <= 1)
                {
                    return;
                }
                foreach (IProjectItem projectItem2 in itemsToOpen)
                {
                    if (projectItem1 != projectItem2)
                    {
                        projectItem2.OpenView(true);
                    }
                }
            }
        }
 private static void SetElementRect(ILayoutDesigner layoutDesigner, BaseFrameworkElement element, Rect rect)
 {
     layoutDesigner.SetChildRect(element, rect, LayoutOverrides.HorizontalAlignment | LayoutOverrides.VerticalAlignment | LayoutOverrides.Width | LayoutOverrides.Height, LayoutOverrides.None, LayoutOverrides.None);
     element.ClearLocalValue(DesignTimeProperties.LayoutOverridesProperty);
 }