Exemplo n.º 1
0
        public void ClippingCanvasTest()
        {
            var mine = new UserControlPoker()
            {
                Width = 30, Height = 30
            };
            var content = new Canvas()
            {
                Width = 50, Height = 50
            };

            mine.SetContent(content);

            CreateAsyncTest(mine, () => {
                Assert.AreEqual(new Size(30, 30), mine.MeasureArg, "MeasureArg");
                Assert.AreEqual(new Size(30, 30), mine.MeasureResult, "MeasureResult");
                Assert.AreEqual(new Size(30, 30), mine.DesiredSize, "poker Desired");
                Assert.AreEqual(new Size(30, 30), content.DesiredSize, "canvas desired");

                Assert.AreEqual(new Size(30, 30), mine.ArrangeArg, "ArrangeArg");
                Assert.AreEqual(new Size(30, 30), mine.ArrangeResult, "ArrangeArg");
                Assert.AreEqual(new Size(50, 50), new Size(content.ActualWidth, content.ActualHeight), "content actual");
                Assert.AreEqual(new Size(30, 30), mine.RenderSize, "uc rendersize");
                Assert.AreEqual(new Size(50, 50), content.RenderSize, "content rendersize");
                Assert.AreEqual(new Rect(0, 0, 30, 30), LayoutInformation.GetLayoutSlot(content), "content slot");
                Assert.IsNull(LayoutInformation.GetLayoutClip(content), "clip");
            }
                            );
        }
Exemplo n.º 2
0
        public void LayoutCanvasInTreeWidth250Test()
        {
            var parent = new Canvas();
            var sub    = new Border();
            var tb     = new TextBlock();
            var sub_tb = new TextBlock();

            sub_tb.Text  = tb.Text = "The truth is Hidden";
            sub_tb.Width = tb.Width = 250;
            sub.Child    = sub_tb;

            parent.Children.Add(tb);
            parent.Children.Add(sub);

            CreateAsyncTest(parent, () => {
                Assert.AreEqual(HorizontalAlignment.Stretch, tb.HorizontalAlignment, "tb horiz");
                Assert.AreEqual(HorizontalAlignment.Stretch, sub_tb.HorizontalAlignment, "tb horiz");
                Assert.AreEqual(new Size(sub_tb.ActualWidth, sub_tb.ActualHeight), new Size(tb.ActualWidth, tb.ActualHeight), "actual are equal");
                Assert.IsTrue(sub_tb.ActualWidth < sub_tb.Width, "sub_tb.ActualWidth < sub_tb.Width");
                Assert.IsTrue(tb.ActualWidth < tb.Width, "tb Actualwidth < tb.Width");
                Assert.AreEqual(new Size(0, 0), tb.RenderSize, "tb 0,0 rendersize");
                Assert.AreNotEqual(sub_tb.RenderSize, tb.RenderSize, "rendersizes are equal");
                Assert.IsNull(LayoutInformation.GetLayoutClip(tb), "tb null clip");
                Assert.IsNull(LayoutInformation.GetLayoutClip(sub_tb), "sub_tb has clip");
            });
        }
Exemplo n.º 3
0
        public void ClippingCanvasTest_notree()
        {
            var mine = new UserControlPoker()
            {
                Width = 30, Height = 30
            };
            var content = new Canvas()
            {
                Width = 50, Height = 50
            };

            mine.SetContent(content);

            mine.Measure(new Size(Double.PositiveInfinity, Double.PositiveInfinity));

            Assert.AreEqual(new Size(30, 30), mine.MeasureArg, "MeasureArg");
            Assert.AreEqual(new Size(30, 30), mine.MeasureResult, "MeasureResult");
            Assert.AreEqual(new Size(30, 30), mine.DesiredSize, "poker Desired");
            Assert.AreEqual(new Size(30, 30), content.DesiredSize, "canvas desired");

            mine.Arrange(new Rect(0, 0, mine.DesiredSize.Width, mine.DesiredSize.Height));

            Assert.AreEqual(new Size(30, 30), mine.ArrangeArg, "ArrangeArg");
            Assert.AreEqual(new Size(30, 30), mine.ArrangeResult, "ArrangeResult");
            Assert.AreEqual(new Size(50, 50), new Size(content.ActualWidth, content.ActualHeight), "content actual");
            Assert.AreEqual(new Size(50, 50), content.RenderSize, "content rendersize");
            Assert.AreEqual(new Rect(0, 0, 30, 30), LayoutInformation.GetLayoutSlot(content), "content slot");
            Assert.IsNull(LayoutInformation.GetLayoutClip(content), "clip");
        }
Exemplo n.º 4
0
        public void LayoutCanvasInTreeTest()
        {
            var parent = new Canvas();
            var sub    = new Border();
            var tb     = new TextBlock();
            var sub_tb = new TextBlock();

            sub_tb.Text = tb.Text = "The truth is Hidden";
            sub.Child   = sub_tb;

            parent.Children.Add(tb);
            parent.Children.Add(sub);

            CreateAsyncTest(parent, () => {
                Assert.AreEqual(new Size(sub_tb.ActualWidth, sub_tb.ActualHeight), new Size(tb.ActualWidth, tb.ActualHeight), "actual are equal");
                Assert.AreEqualWithDelta(sub_tb.RenderSize.Width, sub_tb.ActualWidth, 1, "RenderWidth");
                Assert.AreEqualWithDelta(sub_tb.RenderSize.Height, sub_tb.ActualHeight, 1, "RenderHeight");
                Assert.AreNotEqual(sub_tb.RenderSize, tb.RenderSize, "rendersizes are notequal");
                Assert.AreEqual(new Size(0, 0), tb.RenderSize, "tb 0,0 rendersize");
                Assert.IsNull(LayoutInformation.GetLayoutClip(tb), "tb null clip");
                Assert.IsNull(LayoutInformation.GetLayoutClip(sub_tb), "sub_tb has no clip");
                Rect slot = LayoutInformation.GetLayoutSlot(sub_tb);
                Assert.IsTrue(Math.Ceiling(sub_tb.ActualWidth) == slot.Width, "slot is rounded up to actual");
            });
        }
Exemplo n.º 5
0
        public void LayoutCanvasInTreeWrapTest()
        {
            var parent = new Canvas();
            var sub    = new Border();
            var tb     = new TextBlock();
            var sub_tb = new TextBlock();

            sub_tb.Text     = tb.Text = "The truth is Hidden";
            sub.Child       = sub_tb;
            tb.TextWrapping = sub_tb.TextWrapping = TextWrapping.Wrap;

            parent.Children.Add(tb);
            parent.Children.Add(sub);

            // Notice that we don't wrap even though the slot is slightly
            // smaller than our actual

            CreateAsyncTest(parent, () => {
                Assert.IsTrue(tb.UseLayoutRounding, "use layout rounding");
                Assert.IsTrue(sub_tb.UseLayoutRounding, "use layout rounding");
                Assert.AreEqual(new Size(sub_tb.ActualWidth, sub_tb.ActualHeight), new Size(tb.ActualWidth, tb.ActualHeight), "actual are equal");
                Assert.AreEqual(new Size(sub_tb.ActualWidth, sub_tb.ActualHeight), new Size(tb.ActualWidth, tb.ActualHeight), "actual are equal");
                Assert.AreNotEqual(sub_tb.RenderSize, tb.RenderSize, "rendersizes are notequal");
                Assert.AreEqual(new Size(0, 0), tb.RenderSize, "tb 0,0 rendersize");
                Assert.AreEqualWithDelta(sub_tb.RenderSize.Width, sub_tb.ActualWidth, 1, "RenderWidth");
                Assert.AreEqualWithDelta(sub_tb.RenderSize.Height, sub_tb.ActualHeight, 1, "RenderHeight");
                Assert.IsNull(LayoutInformation.GetLayoutClip(tb), "tb null clip");
                Assert.IsNull(LayoutInformation.GetLayoutClip(sub_tb), "sub_tb has no clip");
                Rect slot = LayoutInformation.GetLayoutSlot(sub_tb);
                Assert.IsTrue(Math.Ceiling(sub_tb.ActualWidth) == slot.Width, "slot is rounded up to actual");
            });
        }
Exemplo n.º 6
0
        public void MinWidthOnParentTest()
        {
            StackPanel sp = new StackPanel {
                MinWidth = 200
            };
            LayoutPoker c = new LayoutPoker {
                Height = 25
            };

            sp.Children.Add(c);

            sp.Measure(new Size(100, 100));

            Assert.AreEqual(new Size(200, 25), c.MeasureArg, "c.Measure");

            Assert.AreEqual(new Size(0, 25), c.DesiredSize);

            sp.Arrange(new Rect(0, 0, 100, 100));

            Assert.AreEqual(new Size(200, 25), c.ArrangeArg, "c.Arrange");

            // now check desired/render sizes

            // the child is oblivious to the parent's maxheight
            Assert.AreEqual(new Size(0, 0), c.RenderSize, "c.RenderedSize");
            Assert.AreEqual(new Size(0, 25), c.DesiredSize, "c.DesiredSize");
            Assert.IsNull(LayoutInformation.GetLayoutClip(c), "c.LayoutClip == null");

            // the parent's maxheight clips
            Assert.AreEqual(new Size(200, 100), sp.RenderSize, "sp.RenderSize");
            Assert.AreEqual(new Size(100, 25), sp.DesiredSize, "sp.DesiredSize");
            Assert.IsNotNull(LayoutInformation.GetLayoutClip(sp), "sp.LayoutClip != null");
        }
Exemplo n.º 7
0
 public void FindElsWithLayoutClip()
 {
     foreach (var fe in FENode.Flatten(new FENode(this)))
     {
         var lc = LayoutInformation.GetLayoutClip(fe);
         var ls = LayoutInformation.GetLayoutSlot(fe);
     }
 }
Exemplo n.º 8
0
        public static Rect ClippedBoundsRelativeTo(this FrameworkElement element, Visual relativeTo)
        {
            var clip = LayoutInformation.GetLayoutClip(element);
            var rect = new Rect(element.RenderSize);

            if (clip != null)
            {
                rect.Intersect(((RectangleGeometry)clip).Bounds);
            }

            return(element.TransformToVisual(relativeTo).TransformBounds(rect));
        }
Exemplo n.º 9
0
        public GeometryHilightManipulator(IDocumentView view, FrameworkElement el)
            : base(view, el)
        {
            VisualBrush brush = new VisualBrush(AdornedElement);

            hilightRect.Opacity = 0.5;
            hilightRect.Fill    = brush;

            path.Data            = LayoutInformation.GetLayoutClip(AdornedElement as FrameworkElement);
            path.Stroke          = Brushes.Black;
            path.StrokeThickness = 1;

            visualChildren.Add(hilightRect);
            visualChildren.Add(path);
        }
Exemplo n.º 10
0
        string FormatLayoutClip(FrameworkElement f)
        {
            Geometry g = LayoutInformation.GetLayoutClip(f);

            if (g == null)
            {
                return("(null)");
            }
            if (g.GetType() != typeof(RectangleGeometry))
            {
                return(string.Format("Complex({0})", g.GetType()));
            }

            RectangleGeometry rg = (RectangleGeometry)g;

            return(string.Format("Rectangle({0})", rg.Rect));
        }
Exemplo n.º 11
0
        public void MaxOnElement()
        {
            LayoutPoker c = new LayoutPoker {
                MaxWidth = 50, MaxHeight = 50
            };

            c.Measure(new Size(1000, 1000));

            Assert.AreEqual(new Size(50, 50), c.MeasureArg, "c.MeasureArg");

            c.Arrange(new Rect(0, 0, 1000, 1000));

            Assert.AreEqual(new Size(50, 50), c.ArrangeArg, "c.ArrangeArg");

            Assert.AreEqual(new Size(0, 0), c.RenderSize, "c.RenderSize");
            Assert.AreEqual(new Size(0, 0), c.DesiredSize, "c.DesiredSize");
            Assert.IsNull(LayoutInformation.GetLayoutClip(c), "c.LayoutClip == null");
        }
Exemplo n.º 12
0
        public void ClippingPanelTest()
        {
            var mine = new UserControlPoker()
            {
                Width = 30, Height = 30
            };
            var content = new PanelPoker()
            {
                Width = 50, Height = 50
            };

            mine.SetContent(content);

            content.Measured += (Size result) => {
                content.MeasureResult = new Size(0, 0);
            };

            content.Arranged += (Size result) => {
                content.ArrangeResult = content.ArrangeArg;
            };

            CreateAsyncTest(mine, () => {
                Assert.AreEqual(new Size(30, 30), mine.MeasureArg, "MeasureArg");
                Assert.AreEqual(new Size(30, 30), mine.MeasureResult, "MeasureResult");
                Assert.AreEqual(new Size(30, 30), mine.DesiredSize, "parent Desired");
                Assert.AreEqual(new Size(30, 30), content.DesiredSize, "content desired");

                Assert.AreEqual(new Size(30, 30), mine.ArrangeArg, "ArrangeArg");
                Assert.AreEqual(new Size(30, 30), mine.ArrangeResult, "ArrangeArg");
                Assert.AreEqual(new Size(50, 50), new Size(content.ActualWidth, content.ActualHeight), "content actual");
                Assert.AreEqual(new Size(30, 30), mine.RenderSize, "parent rendersize");
                Assert.AreEqual(new Size(50, 50), content.RenderSize, "content rendersize");
                Assert.AreEqual(new Rect(0, 0, 30, 30), LayoutInformation.GetLayoutSlot(content), "content slot");
                Assert.IsNotNull(LayoutInformation.GetLayoutClip(content), "clip");

                RectangleGeometry rect = LayoutInformation.GetLayoutClip(content) as RectangleGeometry;
                Assert.IsNotNull(rect);

                Assert.AreEqual(LayoutInformation.GetLayoutSlot(content), rect.Rect, "clip == slot");
            }
                            );
        }
Exemplo n.º 13
0
            private void UpdateForegroundBrush(object sender, EventArgs e)
            {
                // determine if the TextBlock has been clipped
                var layoutClip = LayoutInformation.GetLayoutClip(_textBlock);

                bool needsClipping = layoutClip != null &&
                                     ((_textBlock.TextWrapping == TextWrapping.NoWrap && layoutClip.Bounds.Width > 0 &&
                                       layoutClip.Bounds.Width < _textBlock.ActualWidth) ||
                                      (_textBlock.TextWrapping == TextWrapping.Wrap && layoutClip.Bounds.Height > 0 &&
                                       layoutClip.Bounds.Height < _textBlock.ActualHeight));

                // if the TextBlock was clipped, but is no longer clipped, then
                // strip all the fancy features
                if (_isClipped && !needsClipping)
                {
                    if (GetShowTextInToolTipWhenTrimmed(_textBlock))
                    {
                        _textBlock.ClearValue(ToolTipService.ToolTipProperty);
                    }

                    _textBlock.Foreground = new SolidColorBrush {
                        Color = _foregroundColor
                    };
                    _brush     = null;
                    _isClipped = false;
                }

                // if the TextBlock has just become clipped, make its
                // content show in its tooltip
                if (needsClipping && GetShowTextInToolTipWhenTrimmed(_textBlock))
                {
                    var toolTip = ToolTipService.GetToolTip(_textBlock) as ToolTip;

                    if (toolTip == null)
                    {
                        toolTip = new ToolTip();
                        ToolTipService.SetToolTip(_textBlock, toolTip);

                        toolTip.Style = _textBlock.GetValue(ToolTipStyleProperty) as Style;
                    }

                    toolTip.Content = _textBlock.Text;
                }

                // here's the real magic: if the TextBlock is clipped
                // update its Foreground brush to make it fade out just
                // inside the clip boundary
                if (needsClipping)
                {
                    var visibleWidth  = layoutClip.Bounds.Width;
                    var visibleHeight = layoutClip.Bounds.Height;

                    var verticalClip = _textBlock.TextWrapping == TextWrapping.Wrap;

                    if (_brush == null)
                    {
                        _brush = verticalClip ? GetVerticalClipBrush(visibleHeight) : GetHorizontalClipBrush(visibleWidth);
                        _textBlock.Foreground = _brush;
                    }
                    else if (verticalClip && VerticalBrushNeedsUpdating(_brush, visibleHeight))
                    {
                        _brush.EndPoint = new Point(0, visibleHeight);
                        _brush.GradientStops[1].Offset = (visibleHeight - FadeHeight) / visibleHeight;
                    }
                    else if (!verticalClip && HorizontalBrushNeedsUpdating(_brush, visibleWidth))
                    {
                        _brush.EndPoint = new Point(visibleWidth, 0);
                        _brush.GradientStops[1].Offset = (visibleWidth - FadeWidth) / visibleWidth;
                    }

                    _isClipped = true;
                }
            }
Exemplo n.º 14
0
            private void UpdateForegroundBrush(object sender, EventArgs e)
            {
                Geometry layoutClip = LayoutInformation.GetLayoutClip((FrameworkElement)this._textBlock);
                Rect     bounds;
                int      num;

                if (layoutClip != null)
                {
                    if (this._textBlock.TextWrapping == TextWrapping.NoWrap)
                    {
                        bounds = layoutClip.Bounds;
                        if (bounds.Width > 0.0)
                        {
                            bounds = layoutClip.Bounds;
                            if (bounds.Width < this._textBlock.ActualWidth)
                            {
                                num = 1;
                                goto label_10;
                            }
                        }
                    }
                    if (this._verticalFadingEnabled && this._textBlock.TextWrapping == TextWrapping.Wrap)
                    {
                        bounds = layoutClip.Bounds;
                        if (bounds.Height > 0.0)
                        {
                            bounds = layoutClip.Bounds;
                            num    = bounds.Height < this._textBlock.ActualHeight ? 1 : 0;
                            goto label_10;
                        }
                    }
                    num = 0;
                }
                else
                {
                    num = 0;
                }
label_10:
                bool flag1 = num != 0;

                if (this._isClipped && !flag1)
                {
                    this._textBlock.OpacityMask = this._opacityMask;
                    this._brush     = (LinearGradientBrush)null;
                    this._isClipped = false;
                }
                if (!flag1)
                {
                    return;
                }
                bounds = layoutClip.Bounds;
                double width = bounds.Width;

                bounds = layoutClip.Bounds;
                double height = bounds.Height;
                bool   flag2  = this._textBlock.TextWrapping == TextWrapping.Wrap;

                if (this._brush == null)
                {
                    this._brush = flag2 ? this.GetVerticalClipBrush(height) : this.GetHorizontalClipBrush(width);
                    this._textBlock.OpacityMask = (Brush)this._brush;
                }
                else if (flag2 && FadeTrimming.VerticalBrushNeedsUpdating(this._brush, height))
                {
                    this._brush.EndPoint = new Point(0.0, height);
                    this._brush.GradientStops[1].Offset = (height - 20.0) / height;
                }
                else if (!flag2 && FadeTrimming.HorizontalBrushNeedsUpdating(this._brush, width))
                {
                    this._brush.EndPoint = new Point(width, 0.0);
                    this._brush.GradientStops[1].Offset = (width - 10.0) / width;
                }
                this._isClipped = true;
            }