Пример #1
0
        public override bool EvaluateLayout(DesignerView view, UIElement adorner)
        {
            if (view == null)
            {
                throw new ArgumentNullException("view");
            }
            if (adorner == null)
            {
                throw new ArgumentNullException("adorner");
            }
            BaseAdornerLayout.GetCache((DependencyObject)adorner).DesignerView = view;
            BaseAdornerLayout.EnsureActualValues((DependencyObject)adorner);
            ViewItem element = AdornerProperties.GetView((DependencyObject)adorner);

            if (BaseAdornerLayout.IsAdornableElement(view, element))
            {
                object obj = adorner.ReadLocalValue(BaseAdornerLayout.OriginalVisibilityProperty);
                if (obj != DependencyProperty.UnsetValue)
                {
                    adorner.SetValue(UIElement.VisibilityProperty, obj);
                    adorner.ClearValue(BaseAdornerLayout.OriginalVisibilityProperty);
                }
            }
            else
            {
                if (element != (ViewItem)null && adorner.ReadLocalValue(BaseAdornerLayout.OriginalVisibilityProperty) == DependencyProperty.UnsetValue)
                {
                    adorner.SetValue(BaseAdornerLayout.OriginalVisibilityProperty, (object)adorner.Visibility);
                    adorner.Visibility = Visibility.Collapsed;
                }
                element = (ViewItem)null;
            }
            BaseAdornerLayout.CheckAndInvalidateAdorner(view, element, adorner);
            return(true);
        }
Пример #2
0
 public override void AdornerPropertyChanged(DependencyObject adorner, DependencyPropertyChangedEventArgs args)
 {
     if (args.Property != AdornerProperties.ModelProperty || BaseAdornerLayout.GetCache(adorner).DesignerView == null)
     {
         return;
     }
     BaseAdornerLayout.EnsureActualValues(adorner);
 }
        public override bool EvaluateLayout(DesignerView view, UIElement adorner)
        {
            BaseAdornerLayout.LayoutCache cache = BaseAdornerLayout.GetCache((DependencyObject)adorner);
            Matrix m1_1 = cache.ElementToDesignerViewTransformMatrix;
            Matrix m1_2 = cache.DesignerViewToViewportMatrix;
            bool   flag = base.EvaluateLayout(view, adorner);

            if (!MathUtilities.AreClose(m1_1, cache.ElementToDesignerViewTransformMatrix) || !MathUtilities.AreClose(m1_2, cache.DesignerViewToViewportMatrix))
            {
                this.SetupTransform(adorner);
            }
            return(flag);
        }
        private void SetupTransform(UIElement adorner)
        {
            BaseAdornerLayout.LayoutCache cache = BaseAdornerLayout.GetCache((DependencyObject)adorner);
            CanonicalTransform            canonicalTransform1 = new CanonicalTransform(cache.ElementToDesignerViewTransformMatrix);
            CanonicalTransform            canonicalTransform2 = new CanonicalTransform(cache.DesignerViewToViewportMatrix);
            Vector vector = VectorUtilities.Scale(canonicalTransform1.Scale, canonicalTransform2.Scale);

            adorner.SetValue(TransformAwareAdornerLayout.DesignerElementScalingFactorWithZoom, (object)vector);
            CanonicalTransform canonicalTransform3 = new CanonicalTransform(canonicalTransform1);

            canonicalTransform3.Scale = VectorUtilities.Unscale(new Vector((double)Math.Sign(vector.X), (double)Math.Sign(vector.Y)), canonicalTransform2.Scale);
            AdornerPanel adornerPanel = adorner as AdornerPanel;

            if (adornerPanel != null)
            {
                if (!adornerPanel.UseMirrorTransform)
                {
                    canonicalTransform3.Scale = VectorUtilities.Unscale(new Vector(1.0, 1.0), canonicalTransform2.Scale);
                }
                else
                {
                    adornerPanel.IsMirroredTransform = vector.X < 0.0;
                }
            }
            Transform renderTransform = AdornerProperties.GetRenderTransform((DependencyObject)adorner);
            Transform transform       = (Transform)canonicalTransform3.ToTransform();

            if (renderTransform != null)
            {
                transform = (Transform) new TransformGroup()
                {
                    Children =
                    {
                        transform,
                        renderTransform
                    }
                }
            }
            ;
            adorner.RenderTransform = transform;
        }
Пример #5
0
        private static void EnsureActualValues(DependencyObject adorner)
        {
            ViewItem  view  = AdornerProperties.GetView(adorner);
            ModelItem model = AdornerProperties.GetModel(adorner);

            BaseAdornerLayout.LayoutCache cache = BaseAdornerLayout.GetCache(adorner);
            if (cache.Model == model && !(cache.View != view))
            {
                return;
            }
            if (cache.Model != null)
            {
                cache.Model.PropertyChanged -= new PropertyChangedEventHandler(BaseAdornerLayout.OnModelItemPropertyChanged);
            }
            cache.Model = model;
            cache.View  = view;
            if (model == null)
            {
                return;
            }
            model.PropertyChanged += new PropertyChangedEventHandler(BaseAdornerLayout.OnModelItemPropertyChanged);
        }
        public override void Arrange(UIElement adorner)
        {
            BaseAdornerLayout.LayoutCache cache = BaseAdornerLayout.GetCache((DependencyObject)adorner);
            Matrix m1_1 = cache.ElementToDesignerViewTransformMatrix;
            Matrix m1_2 = cache.DesignerViewToViewportMatrix;

            if (!MathUtilities.AreClose(m1_1, cache.ElementToDesignerViewTransformMatrix) || !MathUtilities.AreClose(m1_2, cache.DesignerViewToViewportMatrix))
            {
                this.SetupTransform(adorner);
            }
            Vector   scale = (Vector)adorner.GetValue(TransformAwareAdornerLayout.DesignerElementScalingFactorWithZoom);
            ViewItem view  = AdornerProperties.GetView((DependencyObject)adorner);

            this.SetAdornerBounds(adorner, view, new Point(0.0, 0.0), scale);
            if (!(view != (ViewItem)null) || cache.PlatformObjectHashCode == 0 || cache.PlatformObjectHashCode == view.PlatformObject.GetHashCode())
            {
                return;
            }
            cache.View                   = view;
            cache.RenderSize             = view.RenderSize;
            cache.PlatformObjectHashCode = view.PlatformObject.GetHashCode();
        }
        public override Size ArrangeChildren(FrameworkElement parent, UIElementCollection internalChildren, Size finalSize)
        {
            AdornerPanel adornerPanel = parent as AdornerPanel;

            if (adornerPanel == null)
            {
                return(finalSize);
            }
            ModelItem model          = adornerPanel.Model;
            ViewItem  adornedElement = model == null ? (ViewItem)null : model.View;
            Vector    vector         = (Vector)parent.GetValue(TransformAwareAdornerLayout.DesignerElementScalingFactorWithZoom);

            foreach (UIElement uiElement in internalChildren)
            {
                uiElement.SetValue(TransformAwareAdornerLayout.DesignerElementScalingFactorWithZoom, (object)vector);
                AdornerPlacementCollection currentPlacements = AdornerPanel.GetCurrentPlacements(uiElement);
                currentPlacements.ComputePlacement(AdornerCoordinateSpaces.Default, uiElement, adornedElement, new Vector(1.0, 1.0), finalSize);
                Rect finalRect = new Rect((Point)currentPlacements.TopLeft, (Size)currentPlacements.Size);
                finalRect.Width  = BaseAdornerLayout.ValidateDouble(finalRect.Width, uiElement.RenderSize.Width);
                finalRect.Height = BaseAdornerLayout.ValidateDouble(finalRect.Height, uiElement.RenderSize.Height);
                uiElement.Arrange(finalRect);
                if (uiElement is FrameworkElement)
                {
                    if (adornerPanel.IsMirroredTransform)
                    {
                        uiElement.SetValue(FrameworkElement.FlowDirectionProperty, (object)FlowDirection.RightToLeft);
                        uiElement.RenderTransform = TransformAwareAdornerLayout.RTLAdornerTransformGroup.Create(uiElement, finalRect.Width);
                    }
                    else
                    {
                        uiElement.RenderTransform = TransformAwareAdornerLayout.RTLAdornerTransformGroup.Unwrap(uiElement);
                        uiElement.SetValue(FrameworkElement.FlowDirectionProperty, (object)FlowDirection.LeftToRight);
                    }
                }
            }
            return(finalSize);
        }
Пример #8
0
        private static void CheckAndInvalidateAdorner(DesignerView view, ViewItem element, UIElement adorner)
        {
            if (view.Context == null)
            {
                return;
            }
            Matrix m1 = TransformUtil.GetTransformToImmediateParent((DependencyObject)view).Value;
            Matrix identity;
            Size   s1;

            if (element != (ViewItem)null)
            {
                identity = TransformUtil.GetSelectionFrameTransformToDesignerView(view.Context, element).Value;
                s1       = element.RenderSize;
            }
            else
            {
                identity = Matrix.Identity;
                s1       = Size.Empty;
            }
            BaseAdornerLayout.LayoutCache cache = BaseAdornerLayout.GetCache((DependencyObject)adorner);
            bool flag1 = false;
            bool flag2 = false;
            bool flag3 = false;

            if (element != (ViewItem)null && !MathUtilities.AreClose(s1, cache.RenderSize))
            {
                flag1 = true;
            }
            if (element != (ViewItem)null && !MathUtilities.AreClose(identity, cache.ElementToDesignerViewTransformMatrix))
            {
                flag1 = true;
                flag2 = true;
            }
            if (!MathUtilities.AreClose(m1, cache.DesignerViewToViewportMatrix))
            {
                flag1 = true;
                flag2 = true;
            }
            if (element != (ViewItem)null && !element.IsVisible)
            {
                ViewItem view1 = view.Context.Services.GetRequiredService <ModelService>().Root.View;
                for (ViewItem viewItem = element; viewItem != view1 && viewItem != (ViewItem)null; viewItem = viewItem.VisualParent)
                {
                    if (viewItem.Visibility == Visibility.Collapsed)
                    {
                        flag3 = true;
                        break;
                    }
                }
            }
            if (flag3)
            {
                object obj = adorner.ReadLocalValue(UIElement.VisibilityProperty);
                if (adorner.ReadLocalValue(BaseAdornerLayout.CachedVisibilityProperty) == DependencyProperty.UnsetValue)
                {
                    if (obj != DependencyProperty.UnsetValue)
                    {
                        adorner.SetValue(BaseAdornerLayout.CachedVisibilityProperty, obj);
                    }
                    else
                    {
                        adorner.SetValue(BaseAdornerLayout.CachedVisibilityProperty, (object)Visibility.Visible);
                    }
                    adorner.Visibility = Visibility.Collapsed;
                }
            }
            else
            {
                object obj = adorner.ReadLocalValue(BaseAdornerLayout.CachedVisibilityProperty);
                if (obj != DependencyProperty.UnsetValue)
                {
                    adorner.SetValue(UIElement.VisibilityProperty, obj);
                }
                adorner.ClearValue(BaseAdornerLayout.CachedVisibilityProperty);
            }
            if (!flag1 && !flag2)
            {
                return;
            }
            if (element != (ViewItem)null)
            {
                cache.RenderSize = s1;
                cache.ElementToDesignerViewTransformMatrix = identity;
                cache.PlatformObjectHashCode = element.PlatformObject.GetHashCode();
            }
            cache.DesignerViewToViewportMatrix = m1;
            cache.DesignerView = view;
            UIElement uiElement = VisualTreeHelper.GetParent((DependencyObject)adorner) as UIElement;

            if (flag1)
            {
                adorner.InvalidateMeasure();
                if (uiElement != null)
                {
                    uiElement.InvalidateMeasure();
                }
            }
            if (!flag2)
            {
                return;
            }
            adorner.InvalidateVisual();
            if (uiElement == null)
            {
                return;
            }
            uiElement.InvalidateVisual();
        }