Beispiel #1
0
        public void Relayout()
        {
            var styles     = new AssembledStyles();
            var box        = new MockBox(styles);
            var fixMap     = new Dictionary <Box, Rectangle>();
            var layoutInfo = ParaBuilderTests.MakeLayoutInfo(100, m_gm.VwGraphics);
            var site       = new MockSite();
            var root       = new RootBox(styles);

            root.Site = site;

            using (var lcb = new LayoutCallbacks(root))
            {
                Assert.IsFalse(box.Relayout(layoutInfo, fixMap, lcb),
                               "Relayout of box never laid out should return false (can't have old loc)");
            }
            Assert.AreEqual(layoutInfo, box.LastLayoutTransform, "Relayout of box never laid out should call Layout() with same transform");
            Assert.AreEqual(0, site.RectsInvalidated.Count, "Relayout of box never laid out should not invalidate anything");

            box.LastLayoutTransform = null;
            using (var lcb = new LayoutCallbacks(root))
                Assert.IsFalse(box.Relayout(layoutInfo, fixMap, lcb), "Relayout of box not in map should return false");
            Assert.IsNull(box.LastLayoutTransform, "Relayout of box not in map should not call Layout()");
            Assert.AreEqual(0, site.RectsInvalidated.Count, "Relayout of box not in map should not invalidate anything");

            fixMap[box] = new Rectangle(2, 3, 4, 7);
            using (var lcb = new LayoutCallbacks(root))
                Assert.IsTrue(box.Relayout(layoutInfo, fixMap, lcb), "Relayout of box in map should return true");
            Assert.AreEqual(layoutInfo, box.LastLayoutTransform, "Relayout of box in map should call Layout() with same transform");
            Assert.AreEqual(1, site.RectsInvalidatedInRoot.Count, "Relayout of box in map should invalidate rect from map");
            Assert.AreEqual(new Rectangle(2, 3, 4, 7), site.RectsInvalidatedInRoot[0], "Relayout of box in map should invalidate proper rect");
        }
Beispiel #2
0
        public void TestClick()
        {
            ParaBox        para;
            RootBox        root   = ParaBuilderTests.MakeTestParaSimpleString(m_gm.VwGraphics, ParaBuilderTests.MockBreakOption.ThreeFullLines, out para);
            PaintTransform ptrans = new PaintTransform(2, 4, 96, 100, 0, 0, 120, 128);
            var            seg    = FirstMockSegment(root);

            seg.OnPointToCharReturn(4, false);
            var sel = root.GetSelectionAt(new Point(5, 10), m_gm.VwGraphics, ptrans);

            Assert.That(sel.IsInsertionPoint);
            Assert.That(((InsertionPoint)sel).StringPosition, Is.EqualTo(4));
            Assert.That(((InsertionPoint)sel).AssociatePrevious, Is.False);
            Assert.That(seg.PointToCharVg, Is.EqualTo(m_gm.VwGraphics));
            Assert.That(seg.PointToCharIchBase, Is.EqualTo(0));
            // not much of a test, but we don't have any way to offset paras yet
            Assert.That(seg.PointToCharRcDst, Is.EqualTo(ptrans.DestRect));
            Assert.That(seg.PointToCharRcSrc, Is.EqualTo(ptrans.SourceRect));
            // Should be offset by the Paint transform origin.
            Assert.That(seg.PointToCharClickPosition, Is.EqualTo(new Point(5, 10)));

            seg = SecondMockSegment(root);
            seg.OnPointToCharReturn(14, true);
            sel = root.GetSelectionAt(new Point(7, 20), m_gm.VwGraphics, ptrans);
            Assert.That(sel.IsInsertionPoint);
            Assert.That(((InsertionPoint)sel).StringPosition, Is.EqualTo(14));
            Assert.That(((InsertionPoint)sel).AssociatePrevious, Is.True);
            Assert.That(seg.PointToCharVg, Is.EqualTo(m_gm.VwGraphics));
            Assert.That(seg.PointToCharIchBase, Is.EqualTo(IchMinOfSecondStringBox(root)));
            // Should be offset by the Paint transform origin and the origin of the second box.
            var topLeft = TopLeftOfSecondStringBox(root);

            Assert.That(seg.PointToCharClickPosition, Is.EqualTo(new Point(7, 20)));
        }
Beispiel #3
0
 public void MoveLeft()
 {
     ParaBox        para;
     RootBox        root = ParaBuilderTests.MakeTestParaSimpleString(m_gm.VwGraphics, ParaBuilderTests.MockBreakOption.ThreeFullLines, out para);
     InsertionPoint ip   = root.SelectAtEnd();
     // Todo: try moving left. Eventualy cover various options, such as from start of paragraph, over diacritics, etc.
 }
Beispiel #4
0
        public void MakeSimpleRange()
        {
            ParaBox        para;
            RootBox        root  = ParaBuilderTests.MakeTestParaSimpleString(m_gm.VwGraphics, ParaBuilderTests.MockBreakOption.ThreeFullLines, out para);
            InsertionPoint ip    = root.SelectAtEnd();
            InsertionPoint ip2   = new InsertionPoint(ip.Hookup, ip.StringPosition - 2, false);
            RangeSelection range = new RangeSelection(ip, ip2);

            Assert.AreEqual(ip, range.Anchor);
            Assert.AreEqual(ip2, range.DragEnd);
            Assert.That(range.EndBeforeAnchor, Is.True);
            Assert.That(range.Start, Is.EqualTo(ip2));
            Assert.That(range.End, Is.EqualTo(ip));
            StringBox   first  = para.FirstBox as StringBox;
            StringBox   second = para.FirstBox.Next as StringBox;
            StringBox   third  = second.Next as StringBox;
            MockSegment seg3   = third.Segment as MockSegment;

            seg3.DrawRangeLeft  = 17;
            seg3.DrawRangeRight = 23;

            PaintTransform ptrans = new PaintTransform(2, 4, 96, 100, 0, 10, 120, 128);

            range.Draw(m_gm.VwGraphics, ptrans);

            // All three segments should be invited to draw it, though only one will.
            // The top of rsSrc gets more negative each line; the destination rectangle where we actually draw keeps getting lower.
            // Remember the effect of 10 pixels of scroll offset.
            VerifyRangeSegmentDrawing(para, first, first.Segment as MockSegment, range, -4, -6, 4);
            VerifyRangeSegmentDrawing(para, second, second.Segment as MockSegment, range, -14, 4, 14);
            VerifyRangeSegmentDrawing(para, third, seg3, range, -24, 14, 24);
        }
Beispiel #5
0
        public void DrawIP()
        {
            ParaBox        para;
            RootBox        root = ParaBuilderTests.MakeTestParaSimpleString(m_gm.VwGraphics, ParaBuilderTests.MockBreakOption.ThreeFullLines, out para);
            InsertionPoint ip   = root.SelectAtEnd();

            ip.Install();
            Assert.AreEqual(ip, root.Selection);
            Assert.AreEqual(para, ip.Para, "IP should know about the paragraph it is in");
            Assert.AreEqual(para.Source.Length, ip.StringPosition, "the IP should be at the end of the paragraph");
            Assert.AreEqual(true, ip.AssociatePrevious, "selection at end should always associate previous in non-empty para");


            StringBox third = para.FirstBox.Next.Next as StringBox;

            Assert.IsNotNull(third, "para with three simple lines should have three string boxes");
            MockSegment seg3 = third.Segment as MockSegment;

            Assert.IsNotNull(seg3);
            PaintTransform ptrans = new PaintTransform(2, 4, 96, 100, 0, -10, 120, 128);

            ip.Draw(m_gm.VwGraphics, ptrans);
            StringBox first  = para.FirstBox as StringBox;
            StringBox second = para.FirstBox.Next as StringBox;
            // All three segments should be invited to draw it, though only one will.
            var seg1 = first.Segment as MockSegment;

            VerifySegmentDrawing(para, first, seg1, -4);
            var seg2 = second.Segment as MockSegment;

            VerifySegmentDrawing(para, second, seg2, -14);
            VerifySegmentDrawing(para, third, seg3, -24);

            seg1.NextPosIpResult             = new MockSegment.PositionsOfIpResults();
            seg1.NextPosIpResult.PrimaryHere = false;
            seg2.NextPosIpResult             = new MockSegment.PositionsOfIpResults();
            seg2.NextPosIpResult.PrimaryHere = false;
            seg3.NextPosIpResult             = new MockSegment.PositionsOfIpResults();
            seg3.NextPosIpResult.RectPrimary = new Rect(5, 6, 7, 9);
            seg3.NextPosIpResult.PrimaryHere = true;
            Rectangle selRect = ip.GetSelectionLocation(m_gm.VwGraphics, ptrans);

            // All three should be asked for the position, though only the third returns a useful one.
            VerifySelLocation(para, first, seg1, -4);
            VerifySelLocation(para, second, seg2, -14);
            VerifySelLocation(para, third, seg3, -24);
            Assert.AreEqual(new Rectangle(5, 6, 2, 3), selRect);

            // The final thing that goes into drawing IPs is the Invalidate call.
            MockSite site = new MockSite();

            site.m_transform  = ptrans;
            site.m_vwGraphics = m_gm.VwGraphics;
            root.Site         = site;
            ip.Invalidate();
            Assert.IsNotNull(site.GraphicsHolder, "Invalidate should have created a Graphics holder");
            Assert.IsTrue(site.GraphicsHolder.WasDisposed, "invalidate should have disposed of the Graphics Holder");
            Assert.AreEqual(1, site.RectsInvalidated.Count, "invalidate should have invalidated one rectangle");
            Assert.AreEqual(new Rectangle(5, 6, 2, 3), site.RectsInvalidated[0], "invalidate should have invalidated the selection rectangle");
        }
Beispiel #6
0
        public void SimpleString()
        {
            ParaBox        para;
            RootBox        root   = ParaBuilderTests.MakeTestParaSimpleString(m_gm.VwGraphics, ParaBuilderTests.MockBreakOption.ThreeFullLines, out para);
            PaintTransform ptrans = new PaintTransform(2, 4, 96, 100, 0, -10, 120, 128);

            root.Paint(m_gm.VwGraphics, ptrans);

            ParaBox pb = root.FirstBox as ParaBox;

            Assert.IsNotNull(pb);
            StringBox first = pb.FirstBox as StringBox;

            Assert.IsNotNull(first);
            MockSegment seg1 = first.Segment as MockSegment;

            Assert.IsNotNull(seg1);
            Assert.AreEqual(m_gm.VwGraphics, seg1.LastDrawTextCall.vg);
            Assert.AreEqual(0, seg1.LastDrawTextCall.ichBase);
            VerifySimpleRect(seg1.LastDrawTextCall.rcSrc, -2, -4, 96, 100);
            VerifySimpleRect(seg1.LastDrawTextCall.rcDst, 0, 10, 120, 128);

            StringBox second = first.Next as StringBox;

            Assert.IsNotNull(second);
            MockSegment seg2 = second.Segment as MockSegment;

            Assert.IsNotNull(seg2);
            VerifySimpleRect(seg2.LastDrawTextCall.rcSrc, -2, -14, 96, 100);
            VerifySimpleRect(seg2.LastDrawTextCall.rcDst, 0, 10, 120, 128);

            StringBox third = second.Next as StringBox;

            Assert.IsNotNull(third);
            MockSegment seg3 = third.Segment as MockSegment;

            Assert.IsNotNull(seg3);
            VerifySimpleRect(seg3.LastDrawTextCall.rcSrc, -2, -24, 96, 100);
            VerifySimpleRect(seg3.LastDrawTextCall.rcDst, 0, 10, 120, 128);

            Assert.AreEqual(root, third.Root);
        }
Beispiel #7
0
        public void PaintParaBox()
        {
            AssembledStyles styles     = new AssembledStyles();
            var             clientRuns = new List <IClientRun>();
            BlockBox        box0       = new BlockBox(styles, Color.Red, 72000, 36000);

            clientRuns.Add(box0);
            BlockBox box1 = new BlockBox(styles, Color.Blue, 36000, 18000);

            clientRuns.Add(box1);
            BlockBox box2 = new BlockBox(styles, Color.Red, 24000, 18000);

            clientRuns.Add(box2);
            BlockBox box3 = new BlockBox(styles, Color.Red, 72000, 36000);

            clientRuns.Add(box3);
            BlockBox box4 = new BlockBox(styles, Color.Red, 36000, 36000);

            clientRuns.Add(box4);

            TextSource source = new TextSource(clientRuns, null);
            ParaBox    para   = new ParaBox(styles, source);
            RootBox    root   = new RootBox(styles);

            root.AddBox(para);

            MockGraphics graphics   = new MockGraphics();
            LayoutInfo   layoutArgs = ParaBuilderTests.MakeLayoutInfo(100, graphics);

            root.Layout(layoutArgs);

            PaintTransform ptrans = new PaintTransform(2, 2, 96, 96, 0, 0, 96, 96);

            root.Paint(graphics, ptrans);
            Assert.AreEqual(5, graphics.RectanglesDrawn.Count);
            VerifyRect(2, 2, 96, 48, graphics, 0, Color.Red);
            VerifyRect(2, 48 + 2, 48, 24, graphics, 1, Color.Blue);
            VerifyRect(2 + 48, 48 + 2, 32, 24, graphics, 2, Color.Red);
            VerifyRect(2, 24 + 48 + 2, 96, 48, graphics, 3, Color.Red);
            VerifyRect(2, 48 + 24 + 48 + 2, 48, 48, graphics, 4, Color.Red);
        }
Beispiel #8
0
        public void SimpleTyping()
        {
            ParaBox        para;
            RootBox        root        = ParaBuilderTests.MakeTestParaSimpleString(m_gm.VwGraphics, ParaBuilderTests.MockBreakOption.ThreeFullLines, out para);
            string         oldContents = para.Source.RenderText;
            var            data1       = HookDataToClientRun(para, oldContents, 0);
            InsertionPoint ip          = root.SelectAtEnd();

            ip.Install();
            MockSite site = new MockSite();

            root.Site = site;
            PaintTransform ptrans = new PaintTransform(2, 4, 96, 100, 0, 10, 120, 128);

            site.m_transform  = ptrans;
            site.m_vwGraphics = m_gm.VwGraphics;
            var engine   = root.LastLayoutInfo.RendererFactory.GetRenderer(ParaBuilderTests.s_simpleStringWs, m_gm.VwGraphics) as MockRenderEngine;
            var modWords = new string[ParaBuilderTests.s_simpleStringWords.Length];

            Array.Copy(ParaBuilderTests.s_simpleStringWords, modWords, modWords.Length);
            modWords[modWords.Length - 1] = modWords[modWords.Length - 1] + "x";
            var modContents = ParaBuilderTests.AssembleStrings(modWords);

            ParaBuilderTests.SetupMockEngineForThreeLines(modContents, engine, modWords);

            ip.InsertText("x");

            string expected = oldContents + "x";

            Assert.AreEqual(expected, para.Source.RenderText);
            Assert.AreEqual(expected, data1.SimpleThree);
            Assert.AreEqual(expected.Length, ip.StringPosition);

            ip.Backspace();

            Assert.AreEqual(oldContents, para.Source.RenderText);
            Assert.AreEqual(oldContents, data1.SimpleThree);
            Assert.AreEqual(oldContents.Length, ip.StringPosition);
        }
Beispiel #9
0
 LayoutInfo MakeLayoutInfo()
 {
     return(ParaBuilderTests.MakeLayoutInfo(Int32.MaxValue, null));
 }
Beispiel #10
0
        public void FlashInsertionPoint()
        {
            AssembledStyles styles     = new AssembledStyles();
            var             clientRuns = new List <IClientRun>();
            BlockBox        box0       = new BlockBox(styles, Color.Red, 72000, 36000);

            clientRuns.Add(box0);
            TextSource source = new TextSource(clientRuns, null);
            ParaBox    para   = new ParaBox(styles, source);
            RootBox    root   = new RootBox(styles);

            root.AddBox(para);
            MockGraphics graphics   = new MockGraphics();
            LayoutInfo   layoutArgs = ParaBuilderTests.MakeLayoutInfo(100, graphics);

            root.Layout(layoutArgs);

            var sel = new DummySelection();

            root.Selection = sel;

            PaintTransform ptrans = new PaintTransform(2, 2, 96, 96, 0, 0, 96, 96);

            root.Paint(graphics, ptrans);

            Assert.AreEqual(graphics, sel.VgUsedToDraw);
            Assert.AreEqual(ptrans, sel.TransformUsedToDraw);

            sel.ClearResults();
            root.FlashInsertionPoint();

            Assert.IsFalse(sel.WasInvalidated, "flash IP should not cause range to be invalidated");

            var ip = new DummySelection();

            ip.SimulateIP  = true;
            root.Selection = ip;
            Assert.IsTrue(ip.WasInvalidated);

            // Initial paint after being installed should indeed paint the IP (so it appears at once)
            ip.ClearResults();
            root.Paint(graphics, ptrans);
            Assert.AreEqual(graphics, ip.VgUsedToDraw);
            Assert.AreEqual(ptrans, ip.TransformUsedToDraw);


            // Each flash should invalide it.
            sel.ClearResults();
            root.FlashInsertionPoint();
            Assert.IsTrue(ip.WasInvalidated);

            // The second paint should do nothing to the IP.
            ip.ClearResults();
            root.Paint(graphics, ptrans);
            Assert.AreEqual(null, ip.VgUsedToDraw);

            // One more flash
            ip.ClearResults();
            root.FlashInsertionPoint();
            Assert.IsTrue(ip.WasInvalidated);

            // And now back to drawing the IP.
            ip.ClearResults();
            root.Paint(graphics, ptrans);
            Assert.AreEqual(graphics, ip.VgUsedToDraw);
            Assert.AreEqual(ptrans, ip.TransformUsedToDraw);

            // range should get drawn even though IP was hidden.
            root.FlashInsertionPoint();       // back to hidden
            root.Selection = sel;             // back to range.
            sel.ClearResults();
            root.Paint(graphics, ptrans);
            Assert.AreEqual(graphics, sel.VgUsedToDraw);
            Assert.AreEqual(ptrans, sel.TransformUsedToDraw);
        }
Beispiel #11
0
        public void ValidSelections()
        {
            AssembledStyles styles     = new AssembledStyles();
            var             clientRuns = new List <IClientRun>();
            var             run0       = new StringClientRun("First run", styles);
            var             run1       = new StringClientRun("Middle run", styles);
            BlockBox        box0       = new BlockBox(styles, Color.Red, 72000, 36000);
            var             run2       = new StringClientRun("Last run", styles);

            clientRuns.Add(run0);
            clientRuns.Add(run1);
            clientRuns.Add(box0);
            clientRuns.Add(run2);
            TextSource source = new TextSource(clientRuns, null);
            ParaBox    para0  = new ParaBox(styles, source);

            run0.Hookup = new LiteralStringParaHookup(para0, para0);
            run1.Hookup = new LiteralStringParaHookup(para0, para0);
            run2.Hookup = new LiteralStringParaHookup(para0, para0);
            DivBox  div  = new DivBox(styles);
            RootBox root = new RootBox(styles);

            para0.Container = div;
            MockGraphics graphics   = new MockGraphics();
            LayoutInfo   layoutArgs = ParaBuilderTests.MakeLayoutInfo(100, graphics);

            root.Layout(layoutArgs);

            root.AddBox(div);
            var sel = para0.SelectAtStart();

            root.Selection = sel;

            Assert.That(!root.Selection.IsValid);

            div.AddBox(para0);
            root.RemoveBoxes(div, div);
            div.Container = root;

            Assert.That(!root.Selection.IsValid);

            root.AddBox(div);

            Assert.That(root.Selection.IsValid);

            (root.Selection as InsertionPoint).Hookup.ClientRunIndex = 4;

            Assert.That(!root.Selection.IsValid);

            (root.Selection as InsertionPoint).Hookup.ClientRunIndex = 2;

            Assert.That(!root.Selection.IsValid);

            (root.Selection as InsertionPoint).Hookup.ClientRunIndex = 0;
            (root.Selection as InsertionPoint).StringPosition        = 10;

            Assert.That(!root.Selection.IsValid);

            (root.Selection as InsertionPoint).StringPosition = 0;
            run0.Hookup = null;

            Assert.That(!root.Selection.IsValid);

            run0.Hookup    = new LiteralStringParaHookup(para0, para0);
            sel            = para0.SelectAtStart();
            root.Selection = sel;

            Assert.That(root.Selection.IsValid);
        }
Beispiel #12
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.
        }
Beispiel #13
0
        public void TypingInComplexPara()
        {
            ParaBox   para;
            RootBox   root      = ParaBuilderTests.MakeTestParaThreeStrings(m_gm.VwGraphics, ParaBuilderTests.MockBreakOption.ThreeFullLines, out para);
            string    contents0 = ParaBuilderTests.AssembleStrings(ParaBuilderTests.s_firstGroupWords);
            MockData1 data0     = HookDataToClientRun(para, contents0, 0);
            string    contents1 = ParaBuilderTests.AssembleStrings(ParaBuilderTests.s_secondGroupWords);
            MockData1 data1     = HookDataToClientRun(para, contents1, 1);
            string    contents2 = ParaBuilderTests.AssembleStrings(ParaBuilderTests.s_thirdGroupWords);

            // Type an 'x' which will go to the start of the second string.
            InsertionPoint ip = para.SelectAt(contents0.Length, false);

            ip.Install();
            MockSite site = new MockSite();

            root.Site = site;
            PaintTransform ptrans = new PaintTransform(2, 4, 96, 100, 0, 10, 120, 128);

            site.m_transform  = ptrans;
            site.m_vwGraphics = m_gm.VwGraphics;
            var modWords = ModifyWords(ParaBuilderTests.s_secondGroupWords, 0, "x" + ParaBuilderTests.s_secondGroupWords[0]);

            ParaBuilderTests.SetupMockEngineForThreeStringsPara(ParaBuilderTests.s_firstGroupWords, modWords, ParaBuilderTests.s_thirdGroupWords, root.LastLayoutInfo);

            ip.InsertText("x");

            Assert.AreEqual(contents0, data0.SimpleThree);
            Assert.AreEqual("x" + contents1, data1.SimpleThree);
            Assert.AreEqual(contents0 + "x" + contents1 + contents2, para.Source.RenderText);
            Assert.AreEqual(1, ip.StringPosition);

            ParaBuilderTests.SetupMockEngineForThreeStringsPara(ParaBuilderTests.s_firstGroupWords, ParaBuilderTests.s_secondGroupWords,
                                                                ParaBuilderTests.s_thirdGroupWords, root.LastLayoutInfo);
            ip.Backspace();

            Assert.AreEqual(contents0 + contents1 + contents2, para.Source.RenderText);
            Assert.AreEqual(contents0, data0.SimpleThree);
            Assert.AreEqual(contents1, data1.SimpleThree);
            Assert.AreEqual(0, ip.StringPosition);
            Assert.IsFalse(ip.AssociatePrevious);

            // Another backspace, at the end of the first string, should edit that.
            var newLastWord = ParaBuilderTests.s_firstGroupWords.Last();
            var modWords0   = ModifyWords(ParaBuilderTests.s_firstGroupWords,
                                          ParaBuilderTests.s_firstGroupWords.Length - 1,
                                          newLastWord.Substring(0, newLastWord.Length - 1));

            ParaBuilderTests.SetupMockEngineForThreeStringsPara(modWords0, ParaBuilderTests.s_secondGroupWords,
                                                                ParaBuilderTests.s_thirdGroupWords, root.LastLayoutInfo);
            ip.Backspace();

            var newFirstContents = contents0.Substring(0, contents0.Length - 1);

            Assert.AreEqual(newFirstContents + contents1 + contents2, para.Source.RenderText);
            Assert.AreEqual(newFirstContents, data0.SimpleThree);
            Assert.AreEqual(contents1, data1.SimpleThree);
            Assert.AreEqual(newFirstContents.Length, ip.StringPosition);
            Assert.IsTrue(ip.AssociatePrevious);

            // Then typing an 'z' should add it to the first string.
            newLastWord = newLastWord.Substring(0, newLastWord.Length - 1) + "z";
            modWords0   = ModifyWords(ParaBuilderTests.s_firstGroupWords,
                                      ParaBuilderTests.s_firstGroupWords.Length - 1,
                                      newLastWord);
            ParaBuilderTests.SetupMockEngineForThreeStringsPara(modWords0, ParaBuilderTests.s_secondGroupWords,
                                                                ParaBuilderTests.s_thirdGroupWords, root.LastLayoutInfo);
            ip.InsertText("z");
            newFirstContents = newFirstContents + "z";
            Assert.AreEqual(newFirstContents + contents1 + contents2, para.Source.RenderText);
            Assert.AreEqual(newFirstContents, data0.SimpleThree);
            Assert.AreEqual(contents1, data1.SimpleThree);
            Assert.AreEqual(newFirstContents.Length, ip.StringPosition);
            Assert.IsTrue(ip.AssociatePrevious);
        }