Ejemplo n.º 1
0
        public void ScrollToShowSelection()
        {
            ParaBox        para;
            RootBox        root = ParaBuilderTests.MakeTestParaSimpleString(m_gm.VwGraphics, ParaBuilderTests.MockBreakOption.ThreeFullLines, out para);
            PaintTransform ptrans = new PaintTransform(2, 4, 96, 96, 0, 0, 96, 96);
            int            dx, dy;

            // If there is no selection we should not move.
            root.ScrollToShowSelection(m_gm.VwGraphics, ptrans, new Rectangle(10, 10, 30, 50), out dx, out dy);
            Assert.That(dx, Is.EqualTo(0));
            Assert.That(dy, Is.EqualTo(0));
            InsertionPoint ip = root.SelectAtEnd();

            ip.Install();

            // Take control of where the selection thinks it is.
            var seg = ((StringBox)para.FirstBox).Segment as MockSegment;

            seg.NextPosIpResult = new MockSegment.PositionsOfIpResults()
            {
                PrimaryHere = true, RectPrimary = new Rect(20, 30, 22, 40)
            };
            var rect = ip.GetSelectionLocation(m_gm.VwGraphics, ptrans);

            Assert.That(rect.Top, Is.EqualTo(30));
            Assert.That(rect.Bottom, Is.EqualTo(40));

            // Todo JohnT: all current tests pass without horizontal scrolling. Eventually implement that.
            // It's entirely inside the rectangle: don't scroll.
            root.ScrollToShowSelection(m_gm.VwGraphics, ptrans, new Rectangle(10, 10, 30, 50), out dx, out dy);
            Assert.That(dx, Is.EqualTo(0));
            Assert.That(dy, Is.EqualTo(0));
            // a special case of entirely inside: not by the desired margin: still don't scroll.
            root.ScrollToShowSelection(m_gm.VwGraphics, ptrans, new Rectangle(10, 28, 30, 14), out dx, out dy);
            Assert.That(dx, Is.EqualTo(0));
            Assert.That(dy, Is.EqualTo(0));

            // It's above a rectangle that can easily hold it: should end 10 pixels inside. Scrolling down 15 pixels will do that.
            root.ScrollToShowSelection(m_gm.VwGraphics, ptrans, new Rectangle(10, 35, 30, 70), out dx, out dy);
            Assert.That(dx, Is.EqualTo(0));
            Assert.That(dy, Is.EqualTo(15));

            // It's below a rectangle that can easily hold it: should end 10 pixels inside. Scrolling up 25 pixels will do that.
            // (The bottom of the rectangle is at 25, 15 pix above the bottom of the selection rectangle.)
            root.ScrollToShowSelection(m_gm.VwGraphics, ptrans, new Rectangle(10, -20, 30, 45), out dx, out dy);
            Assert.That(dx, Is.EqualTo(0));
            Assert.That(dy, Is.EqualTo(-25));

            // It's above a rectangle that can not hold it comfortably: should end just inside. Scrolling down 5 pixels will do that.
            root.ScrollToShowSelection(m_gm.VwGraphics, ptrans, new Rectangle(10, 35, 30, 20), out dx, out dy);
            Assert.That(dx, Is.EqualTo(0));
            Assert.That(dy, Is.EqualTo(5));

            // It's below a rectangle that can not hold it comfortably: should end just inside. Scrolling up 15 pixels will do that.
            // (The bottom of the rectangle is at 25, 15 pix above the bottom of the selection rectangle.)
            root.ScrollToShowSelection(m_gm.VwGraphics, ptrans, new Rectangle(10, 0, 30, 25), out dx, out dy);
            Assert.That(dx, Is.EqualTo(0));
            Assert.That(dy, Is.EqualTo(-15));

            // Pathologically, it may not be possible to display all of it at all. It's currently 12 pixels below the
            // target rectangle. We move it so its top is one pixel above, that is, 12 plus 9 pixels.
            root.ScrollToShowSelection(m_gm.VwGraphics, ptrans, new Rectangle(10, 10, 30, 8), out dx, out dy);
            Assert.That(dx, Is.EqualTo(0));
            Assert.That(dy, Is.EqualTo(-21));
            // A similar case moving up. 10 pixels would align the tops; we move 2 less.
            root.ScrollToShowSelection(m_gm.VwGraphics, ptrans, new Rectangle(10, 40, 30, 6), out dx, out dy);
            Assert.That(dx, Is.EqualTo(0));
            Assert.That(dy, Is.EqualTo(8));

            // Todo JohnT: cases involving ranges. Mostly these work the same, when things fit. There are special cases
            // when the range is not entirely visible, but its DragEnd is; also when the range doesn't entirely fit,
            // but possibly its dragEnd does.
        }