Exemplo n.º 1
0
        public void MultiParaCopy()
        {
            var styles = new AssembledStyles();
            var root   = new RootBoxFdo(styles);
            var owner  = new MockData1(23, 23);
            var mock1  = new MockData1(23, 23);
            var mock2  = new MockData1(23, 23);
            var mock3  = new MockData1(23, 23);

            owner.InsertIntoObjSeq1(0, mock1);
            owner.InsertIntoObjSeq1(1, mock2);
            owner.InsertIntoObjSeq1(2, mock3);
            mock1.SimpleThree = "This is the";
            mock2.SimpleThree = "day that the";
            mock3.SimpleThree = "Lord has made";
            var engine = new FakeRenderEngine()
            {
                Ws = 23, SegmentHeight = 13
            };
            var factory = new FakeRendererFactory();

            factory.SetRenderer(23, engine);
            var            layoutInfo = HookupTests.MakeLayoutInfo(int.MaxValue / 2, m_gm.VwGraphics, 23);
            PaintTransform ptrans     = new PaintTransform(2, 2, 96, 96, 0, 0, 96, 96);
            MockSite       site       = new MockSite();

            site.m_transform  = ptrans;
            site.m_vwGraphics = m_gm.VwGraphics;
            root.Site         = site;
            var po = new MockReceiveParagraphOperations();

            root.Builder.Show(Display.Of(() => owner.ObjSeq1).Using((bldr, md) => bldr.AddString(() => md.SimpleThree, 23))
                              .EditParagraphsUsing(po));
            var layoutArgs = MakeLayoutInfo(Int32.MaxValue / 2, m_gm.VwGraphics, factory);

            root.Layout(layoutArgs);

            int x        = FakeRenderEngine.SimulatedWidth("This ") + 2;
            var location = new Point(x, 8);

            Clipboard.SetDataObject("");

            MouseEventArgs e = new MouseEventArgs(MouseButtons.Left, 1, location.X, location.Y, 0);

            root.OnMouseDown(e, Keys.None, site.m_vwGraphics, site.m_transform);
            Assert.That(root.CanCopy(), Is.EqualTo(false), "Should not be able to copy");
            x        = FakeRenderEngine.SimulatedWidth("Lord") + 2;
            location = new Point(x, 29);
            e        = new MouseEventArgs(MouseButtons.Left, 1, location.X, location.Y, 0);
            root.OnMouseMove(e, Keys.None, site.m_vwGraphics, site.m_transform);

            Assert.That(root.CanCopy(), Is.EqualTo(true), "Should be able to copy");
            root.OnEditCopy();
            Assert.That(owner.ObjSeq1[0].SimpleThree + owner.ObjSeq1[1].SimpleThree + owner.ObjSeq1[2].SimpleThree, Is.EqualTo("This is the" + "day that the" + "Lord has made"));
            Assert.That(Clipboard.GetDataObject().GetData(DataFormats.StringFormat), Is.EqualTo("is the\r\nday that the\r\nLord"), "Selected String should be \"is the\nday that the\nLord \"");
        }
        public void SendingInsertLineBreak()
        {
            var owner  = new MockData1(55, 77);
            var child1 = new MockData1(55, 77);
            var child2 = new MockData1(55, 77);

            owner.InsertIntoObjSeq1(0, child1);
            owner.InsertIntoObjSeq1(1, child2);
            child1.SimpleThree = "Hello World. ";
            child2.SimpleThree = "This is a test.";

            var styles     = new AssembledStyles();
            var root       = new RootBoxFdo(styles);
            var layoutInfo = HookupTests.MakeLayoutInfo(int.MaxValue / 2, m_gm.VwGraphics, 55);

            SetupFakeRootSite(root);
            var po = new MockSendParagraphOperations();

            root.Builder.Show(Display.Of(() => owner.ObjSeq1).Using((bldr, md) => bldr.AddString(() => md.SimpleThree, 55))
                              .EditParagraphsUsing(po));
            Assert.That(po.Hookup, Is.Not.Null);
            root.Layout(layoutInfo);
            var para = (ParaBox)root.FirstBox;
            var ip   = para.SelectAtEnd();

            ip.InsertLineBreak();
            Assert.That(po.InsertFollowingParagraphIp, Is.EqualTo(ip), "should have called InsertFollowingParagraph with right IP");
            Assert.That(po.InsertFollowingParagraphActionPerformed, Is.False, "make selection action performed too soon");
            ((MockSite)root.Site).DoPendingAfterNotificationTasks();
            Assert.That(po.InsertFollowingParagraphActionPerformed, Is.True, "make selection action not performed or not saved");

            po.InsertFollowingParagraphIp = null;
            ip = para.SelectAtStart();
            ip.InsertLineBreak();
            Assert.That(po.InsertFollowingParagraphIp, Is.Null);
            Assert.That(po.InsertPrecedingParagraphIp, Is.EqualTo(ip), "should have called InsertPrecedingParagraph with right IP");
            Assert.That(po.InsertPrecedingParagraphActionPerformed, Is.False, "make selection action performed too soon");
            ((MockSite)root.Site).DoPendingAfterNotificationTasks();
            Assert.That(po.InsertPrecedingParagraphActionPerformed, Is.True, "make selection action not performed or not saved");
            // Todo: test sending InsertLineBreak when selection mid-paragraph, also empty paragraph.
        }
Exemplo n.º 3
0
        public void DrawIPMultiRunPara()
        {
            var     styles = new AssembledStyles();
            RootBox root   = new RootBoxFdo(styles);

            root.Builder.Show(Paragraph.Containing(
                                  Display.Of("first"), Display.Of("second"), Display.Of("third")));
            SetupFakeRootSite(root);
            var layoutInfo = HookupTests.MakeLayoutInfo(int.MaxValue / 2, m_gm.VwGraphics, 55);

            root.Layout(layoutInfo);
            InsertionPoint ip = root.SelectAtEnd();

            ip.Install();
            var para = (ParaBox)root.FirstBox;

            Assert.AreEqual(ip, root.Selection);
            Assert.AreEqual(para, ip.Para, "IP should know about the paragraph it is in");
            Assert.AreEqual("third".Length, ip.StringPosition, "IP position is relative to run");
            Assert.AreEqual(true, ip.AssociatePrevious, "selection at end should always associate previous in non-empty para");


            StringBox sbox = para.FirstBox as StringBox;

            Assert.That(sbox, Is.EqualTo(para.LastBox), "uniform text in infinite width should make one string box");
            var seg = sbox.Segment as FakeSegment;

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

            ip.Draw(m_gm.VwGraphics, ptrans);
            VerifySegmentDrawing(para, sbox, seg.LastDrawIpCall, -4);

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

            VerifySelLocation(para, sbox, seg.LastPosIpCall, -4);
            Assert.AreEqual(new Rectangle(5, 6, 2, 3), selRect);
        }
Exemplo n.º 4
0
        public void BackgroundAndUnderlinePainting()
        {
            var     styles = new AssembledStyles();
            RootBox root   = new RootBoxFdo(styles);

            SetupFakeRootSite(root);
            var layoutInfo = HookupTests.MakeLayoutInfo(int.MaxValue / 2, m_gm.VwGraphics, 55);

            root.RendererFactory = layoutInfo.RendererFactory;
            root.Builder.Show(
                Paragraph.Containing(
                    Display.Of("plain"),
                    Display.Of("underOnYellow").Underline(FwUnderlineType.kuntSingle).BackColor(Color.Yellow)
                    ),
                Paragraph.Containing(
                    Display.Of("doubleRedOnPink").Underline(FwUnderlineType.kuntDouble, Color.Red).BackColor(Color.Pink),
                    Display.Of("dotted").Underline(FwUnderlineType.kuntDotted),
                    Display.Of("dottedOnYellow").Underline(FwUnderlineType.kuntDotted).BackColor(Color.Yellow)
                    ),
                Paragraph.Containing(
                    Display.Of("dashed").Underline(FwUnderlineType.kuntDashed),
                    Display.Of("dashedRed").Underline(FwUnderlineType.kuntDashed).ForeColor(Color.Red),
                    Display.Of("squiggle").Underline(FwUnderlineType.kuntSquiggle)
                    )
                );
            root.Layout(layoutInfo);

            var para1      = (ParaBox)root.FirstBox;
            var stringBox1 = (StringBox)para1.FirstBox;
            var seg1       = (FakeSegment)stringBox1.Segment;
            // A convenient place to test that literals get Chrp with default user ws.
            LgCharRenderProps chrp;
            int ichMin, ichLim;

            para1.Source.GetCharProps(0, out chrp, out ichMin, out ichLim);
            Assert.That(chrp.ws, Is.EqualTo(layoutInfo.RendererFactory.UserWs));
            // This segment has just one chunk of underline, the second run.
            seg1.NextCharPlacementResults.Add(new FakeSegment.CharPlacementResults()
            {
                Lefts = new[] { 10 }, Rights = new[] { 20 }, Tops = new[] { 15 }
            });
            // Todo: add expectations for each run of underlining.

            var para2      = (ParaBox)para1.Next;
            var stringBox2 = (StringBox)para2.FirstBox;
            var seg2       = (FakeSegment)stringBox2.Segment;

            // For the double red underline, we'll pretend there are two line segments.
            seg2.NextCharPlacementResults.Add(new FakeSegment.CharPlacementResults()
            {
                Lefts = new[] { 5, 15 }, Rights = new[] { 10, 20 }, Tops = new[] { 15, 16 }
            });
            seg2.NextCharPlacementResults.Add(new FakeSegment.CharPlacementResults()
            {
                Lefts = new[] { 12 }, Rights = new[] { 22 }, Tops = new[] { 13 }
            });
            seg2.NextCharPlacementResults.Add(new FakeSegment.CharPlacementResults()
            {
                Lefts = new[] { 30 }, Rights = new[] { 41 }, Tops = new[] { 12 }
            });

            var para3      = (ParaBox)para2.Next;
            var stringBox3 = (StringBox)para3.FirstBox;
            var seg3       = (FakeSegment)stringBox3.Segment;

            seg3.NextCharPlacementResults.Add(new FakeSegment.CharPlacementResults()
            {
                Lefts = new[] { 0 }, Rights = new[] { 10 }, Tops = new[] { 11 }
            });
            seg3.NextCharPlacementResults.Add(new FakeSegment.CharPlacementResults()
            {
                Lefts = new[] { 10 }, Rights = new[] { 20 }, Tops = new[] { 11 }
            });
            seg3.NextCharPlacementResults.Add(new FakeSegment.CharPlacementResults()
            {
                Lefts = new[] { 30 }, Rights = new[] { 40 }, Tops = new[] { 11 }
            });

            // We want to keep track of the sequence of paint operations in all three segments.
            var drawActions = new List <object>();

            seg1.DrawActions = seg2.DrawActions = seg3.DrawActions = drawActions;
            var vg = new MockGraphics();

            vg.DrawActions = drawActions;

            var site = (MockSite)root.Site;

            root.Paint(vg, site.m_transform);
            var paintTrans = site.m_transform;

            // We should have asked about each run of distinct underlining.
            VerifyCharPlacementCall(seg1, 0, "plain".Length, "plain".Length + "underOnYellow".Length,
                                    paintTrans.SourceRect, paintTrans.DestRect, vg, 1);

            // para/seg 2
            Rect srcRect = paintTrans.SourceRect;

            srcRect.top    -= para1.Height;
            srcRect.bottom -= para1.Height;
            VerifyCharPlacementCall(seg2, 0, 0, "doubleRedOnPink".Length,
                                    srcRect, paintTrans.DestRect, vg, 2);
            VerifyCharPlacementCall(seg2, 0, "doubleRedOnPink".Length, "doubleRedOnPink".Length + "dotted".Length,
                                    srcRect, paintTrans.DestRect, vg, 1);
            VerifyCharPlacementCall(seg2, 0, "doubleRedOnPink".Length + "dotted".Length,
                                    "doubleRedOnPink".Length + "dotted".Length + "dottedOnYellow".Length,
                                    srcRect, paintTrans.DestRect, vg, 1);

            // para/seg 3
            srcRect.top    -= para2.Height;
            srcRect.bottom -= para2.Height;
            VerifyCharPlacementCall(seg3, 0, 0, "dashed".Length,
                                    srcRect, paintTrans.DestRect, vg, 1);
            VerifyCharPlacementCall(seg3, 0, "dashed".Length, "dashed".Length + "dashedRed".Length,
                                    srcRect, paintTrans.DestRect, vg, 1);
            VerifyCharPlacementCall(seg3, 0, "dashed".Length + "dashedRed".Length,
                                    "dashed".Length + "dashedRed".Length + "squiggle".Length,
                                    srcRect, paintTrans.DestRect, vg, 1);
            // Todo: eventually arrange a run where ichBase is non-zero, and check what happens.

            // We want to check a lot of things about the drawing.
            // - all the background color and underline drawing should happen before any of the text drawing.
            // - the right stuff should be drawn to construct the underlines
            // - in particular dotted, dashed, and squiggle underlines should have the gaps and alternations
            // aligned, even if in different segments.

            // Todo: check actual line segs drawn

            int position = 0;             // in drawActions

            // Normal calls to Draw have the effect of painting the background. All three backgrounds
            // should be painted before the foreground. First we paint seg1 with background, since it has some.
            VerifyDraw(drawActions, ref position, seg1);
            // Next we draw its one horizontal line of underline.
            VerifyHorzLine(drawActions, ref position, 10, 20, 15, 1, new int[] { int.MaxValue }, 10);

            // Then segment 2's background
            VerifyDraw(drawActions, ref position, seg2);
            // And various lots of underline: double takes 2 per segment
            VerifyHorzLine(drawActions, ref position, 5, 10, 17, 1, new int[] { int.MaxValue }, 5);
            VerifyHorzLine(drawActions, ref position, 5, 10, 15, 1, new int[] { int.MaxValue }, 5);
            VerifyHorzLine(drawActions, ref position, 15, 20, 18, 1, new int[] { int.MaxValue }, 15);
            VerifyHorzLine(drawActions, ref position, 15, 20, 16, 1, new int[] { int.MaxValue }, 15);
            // dotted has non-trivial array of dx values (2 pix each)
            VerifyHorzLine(drawActions, ref position, 12, 22, 13, 1, new int[] { 2, 2 }, 12);
            // dotted has non-trivial array of dx values (2 pix each)
            VerifyHorzLine(drawActions, ref position, 30, 41, 12, 1, new int[] { 2, 2 }, 30);
            // No background in para 3, doesn't get a draw background call.
            //VerifyDraw(drawActions, ref position, seg3);
            // But underlines still drawn in the background phase
            // Dashed line
            VerifyHorzLine(drawActions, ref position, 0, 10, 11, 1, new int[] { 6, 3 }, 0);
            VerifyHorzLine(drawActions, ref position, 10, 20, 11, 1, new int[] { 6, 3 }, 10);
            // Todo: verify line segs drawn for squiggle.
            VerifyLine(drawActions, ref position, 30, 12, 32, 10, ColorUtil.ConvertColorToBGR(Color.Black));
            VerifyLine(drawActions, ref position, 32, 10, 34, 12, ColorUtil.ConvertColorToBGR(Color.Black));
            VerifyLine(drawActions, ref position, 34, 12, 36, 10, ColorUtil.ConvertColorToBGR(Color.Black));
            VerifyLine(drawActions, ref position, 36, 10, 38, 12, ColorUtil.ConvertColorToBGR(Color.Black));
            VerifyLine(drawActions, ref position, 38, 12, 40, 10, ColorUtil.ConvertColorToBGR(Color.Black));
            VerifyNbDraw(drawActions, ref position, seg1);
            VerifyNbDraw(drawActions, ref position, seg2);
            VerifyDraw(drawActions, ref position, seg3);
        }
        public void CombinedParaOperations()
        {
            // Set up a simple multi-para layout using the ObjSeq2 and SimpleThree properties of MockData1
            AssembledStyles styles = new AssembledStyles();
            RootBox         root   = new RootBoxFdo(styles);
            var             owner  = new MockData1();
            var             p1     = new MockData1(10, 11);
            var             p2     = new MockData1(10, 11);

            p1.SimpleThree = "Hello World";
            p2.SimpleThree = "This is a test";
            owner.ObjSeq2.Add(p1);
            owner.ObjSeq2.Add(p2);
            var po = new MockReceiveParagraphOperations();

            root.Builder.Show(Display.Of(() => owner.ObjSeq2)
                              .Using((builder, para) => builder.AddString(() => para.SimpleThree, 10))
                              .EditParagraphsUsing(po));
            SetupFakeRootSite(root);
            var layoutInfo = HookupTests.MakeLayoutInfo(int.MaxValue / 2, m_gm.VwGraphics, 55);

            root.Layout(layoutInfo);
            var ip = root.FirstBox.SelectAtEnd();

            // Insert at end of paragraph.
            ip.InsertLineBreak();
            Assert.That(owner.ObjSeq2.Count, Is.EqualTo(3));
            Assert.That(owner.ObjSeq2[0], Is.EqualTo(p1));
            Assert.That(owner.ObjSeq2[2], Is.EqualTo(p2));
            var p3 = owner.ObjSeq2[1];             // empty inserted paragraph.

            ((MockSite)root.Site).DoPendingAfterNotificationTasks();
            ip = (InsertionPoint)root.Selection;
            Assert.That(root.FirstBox.Next.Next, Is.Not.Null);
            Assert.That(ip.StringPosition, Is.EqualTo(0));
            Assert.That(ip.Para, Is.EqualTo(root.FirstBox.Next));

            // Insert at start of paragraph. To make it unambiguously the start, give p3 some data,
            // and since that might eventually destroy the selection, reset it.
            var rootHookup = ip.Hookup.ParentHookup.ParentHookup;             // StringHookup, ItemHookup, Sequence

            p3.SimpleThree = "First insert";
            ip             = (InsertionPoint)SelectionBuilder.In(rootHookup)[1].Offset(0).Install();
            ip.InsertLineBreak();
            Assert.That(owner.ObjSeq2.Count, Is.EqualTo(4));
            Assert.That(owner.ObjSeq2[0], Is.EqualTo(p1));
            Assert.That(owner.ObjSeq2[2], Is.EqualTo(p3));
            Assert.That(owner.ObjSeq2[3], Is.EqualTo(p2));
            var p4 = owner.ObjSeq2[1];             // empty inserted paragraph (before p3).

            Assert.That(root.FirstBox.Next.Next.Next, Is.Not.Null);
            ((MockSite)root.Site).DoPendingAfterNotificationTasks();
            ip = (InsertionPoint)root.Selection;
            Assert.That(ip.StringPosition, Is.EqualTo(0));
            Assert.That(ip.Para, Is.EqualTo(root.FirstBox.Next.Next));

            // Split a paragraph.
            var oldObjects = owner.ObjSeq2.ToArray();

            ip = (InsertionPoint)SelectionBuilder.In(rootHookup)[2].Offset("First ".Length).Install();
            ip.InsertLineBreak();
            Assert.That(owner.ObjSeq2.Count, Is.EqualTo(5));
            Assert.That(owner.ObjSeq2[1], Is.EqualTo(oldObjects[1]));
            Assert.That(owner.ObjSeq2[2], Is.EqualTo(oldObjects[2]));
            Assert.That(owner.ObjSeq2[4], Is.EqualTo(oldObjects[3])); // insert between 2 and 3
            var p5 = owner.ObjSeq2[3];                                // inserted paragraph.

            ((MockSite)root.Site).DoPendingAfterNotificationTasks();
            ip = (InsertionPoint)root.Selection;
            Assert.That(ip.StringPosition, Is.EqualTo(0));
            Assert.That(ip.Para, Is.EqualTo(root.FirstBox.Next.Next.Next));
            Assert.That(owner.ObjSeq2[2].SimpleThree, Is.EqualTo("First "));
            Assert.That(owner.ObjSeq2[3].SimpleThree, Is.EqualTo("insert"));

            // Combine two paragraphs by backspace at start of line.
            oldObjects = owner.ObjSeq2.ToArray();
            ip.Backspace();
            Assert.That(owner.ObjSeq2.Count, Is.EqualTo(4));
            Assert.That(owner.ObjSeq2[1], Is.EqualTo(oldObjects[1]));
            Assert.That(owner.ObjSeq2[2], Is.EqualTo(oldObjects[2]));
            Assert.That(owner.ObjSeq2[3], Is.EqualTo(oldObjects[4]));             // delete item 3
            ((MockSite)root.Site).DoPendingAfterNotificationTasks();
            ip = (InsertionPoint)root.Selection;
            Assert.That(ip.StringPosition, Is.EqualTo("First ".Length));
            Assert.That(ip.Para, Is.EqualTo(root.FirstBox.Next.Next));
            Assert.That(owner.ObjSeq2[2].SimpleThree, Is.EqualTo("First insert"));
        }
Exemplo n.º 6
0
        public void CombinedParaOperationsFdo()
        {
            // Set up a simple multi-para layout using the ObjSeq2 and SimpleThree properties of MockData1
            AssembledStyles styles = new AssembledStyles();
            var             root   = new RootBoxFdo(styles);
            var             text   = Cache.ServiceLocator.GetInstance <ITextFactory>().Create();
            //Cache.LangProject.TextsOC.Add(text);
            var owner = Cache.ServiceLocator.GetInstance <IStTextFactory>().Create();

            text.ContentsOA = owner;
            IStTxtPara p1 = MakePara(owner, "Hello World");
            var        p2 = MakePara(owner, "This is a test");

            m_actionHandler.EndUndoTask();             // Finish settin up data, we want to control from now on.

            var po = new StTextParagraphOperations(owner);

            root.Builder.Show(Display.Of(() => owner.ParagraphsOS).Using((builder, para) => builder.AddString(()
                                                                                                              => ((IStTxtPara)para).Contents)).EditParagraphsUsing(po));
            SetupFakeRootSite(root);
            var layoutInfo = HookupTests.MakeLayoutInfo(int.MaxValue / 2, m_gm.VwGraphics, 55);

            root.Layout(layoutInfo);
            var ip = root.FirstBox.SelectAtEnd();

            // Insert at end of paragraph.
            m_actionHandler.BeginUndoTask("undo insert line break", "redo insert");
            ip.InsertLineBreak();
            m_actionHandler.EndUndoTask();
            Assert.That(owner.ParagraphsOS.Count, Is.EqualTo(3));
            Assert.That(owner.ParagraphsOS[0], Is.EqualTo(p1));
            Assert.That(owner.ParagraphsOS[2], Is.EqualTo(p2));
            var p3 = (IStTxtPara)owner.ParagraphsOS[1];             // empty inserted paragraph.

            Assert.That(p3.Contents.Length, Is.EqualTo(0));
            Assert.That(p3.Contents.get_WritingSystem(0), Is.EqualTo(Cache.DefaultVernWs));
            ((MockSite)root.Site).DoPendingAfterNotificationTasks();
            ip = (InsertionPoint)root.Selection;
            Assert.That(root.FirstBox.Next.Next, Is.Not.Null);
            Assert.That(ip.StringPosition, Is.EqualTo(0));
            Assert.That(ip.Para, Is.EqualTo(root.FirstBox.Next));

            // Insert at start of paragraph. To make it unambiguously the start, give p3 some data,
            // and since that might eventually destroy the selection, reset it.
            var rootHookup = ip.Hookup.ParentHookup.ParentHookup;             // StringHookup, ItemHookup, Sequence

            UndoableUnitOfWorkHelper.Do("adjust contents", "redo", m_actionHandler,
                                        () => p3.Contents = Cache.TsStrFactory.MakeString("First insert", Cache.DefaultVernWs));
            ip = (InsertionPoint)SelectionBuilder.In(rootHookup)[1].Offset(0).Install();
            m_actionHandler.BeginUndoTask("undo insert line break", "redo insert");
            ip.InsertLineBreak();
            m_actionHandler.EndUndoTask();
            Assert.That(owner.ParagraphsOS.Count, Is.EqualTo(4));
            Assert.That(owner.ParagraphsOS[0], Is.EqualTo(p1));
            Assert.That(owner.ParagraphsOS[2], Is.EqualTo(p3));
            Assert.That(owner.ParagraphsOS[3], Is.EqualTo(p2));
            var p4 = (IStTxtPara)owner.ParagraphsOS[1];             // empty inserted paragraph (before p3).

            Assert.That(root.FirstBox.Next.Next.Next, Is.Not.Null);
            Assert.That(p4.Contents.get_WritingSystem(0), Is.EqualTo(Cache.DefaultVernWs));
            ((MockSite)root.Site).DoPendingAfterNotificationTasks();
            ip = (InsertionPoint)root.Selection;
            Assert.That(ip.StringPosition, Is.EqualTo(0));
            Assert.That(ip.Para, Is.EqualTo(root.FirstBox.Next.Next));

            // Split a paragraph.
            var oldObjects = owner.ParagraphsOS.ToArray();

            ip = (InsertionPoint)SelectionBuilder.In(rootHookup)[2].Offset("First ".Length).Install();
            m_actionHandler.BeginUndoTask("undo insert line break", "redo insert");
            ip.InsertLineBreak();
            m_actionHandler.EndUndoTask();
            Assert.That(owner.ParagraphsOS.Count, Is.EqualTo(5));
            Assert.That(owner.ParagraphsOS[1], Is.EqualTo(oldObjects[1]));
            Assert.That(owner.ParagraphsOS[2], Is.EqualTo(oldObjects[2]));
            Assert.That(owner.ParagraphsOS[4], Is.EqualTo(oldObjects[3])); // insert between 2 and 3
            var p5 = (IStTxtPara)owner.ParagraphsOS[3];                    // inserted paragraph.

            ((MockSite)root.Site).DoPendingAfterNotificationTasks();
            ip = (InsertionPoint)root.Selection;
            Assert.That(ip.StringPosition, Is.EqualTo(0));
            Assert.That(ip.Para, Is.EqualTo(root.FirstBox.Next.Next.Next));
            Assert.That(((IStTxtPara)owner.ParagraphsOS[2]).Contents.Text, Is.EqualTo("First "));
            Assert.That(((IStTxtPara)owner.ParagraphsOS[3]).Contents.Text, Is.EqualTo("insert"));

            // Combine two paragraphs by backspace at start of line.
            oldObjects = owner.ParagraphsOS.ToArray();
            m_actionHandler.BeginUndoTask("undo backspace", "redo backspace");
            ip.Backspace();
            m_actionHandler.EndUndoTask();
            Assert.That(owner.ParagraphsOS.Count, Is.EqualTo(4));
            Assert.That(owner.ParagraphsOS[1], Is.EqualTo(oldObjects[1]));
            Assert.That(owner.ParagraphsOS[2], Is.EqualTo(oldObjects[2]));
            Assert.That(owner.ParagraphsOS[3], Is.EqualTo(oldObjects[4]));             // delete item 3
            ((MockSite)root.Site).DoPendingAfterNotificationTasks();
            ip = (InsertionPoint)root.Selection;
            Assert.That(ip.StringPosition, Is.EqualTo("First ".Length));
            Assert.That(ip.Para, Is.EqualTo(root.FirstBox.Next.Next));
            Assert.That(((IStTxtPara)owner.ParagraphsOS[2]).Contents.Text, Is.EqualTo("First insert"));
        }
Exemplo n.º 7
0
        public void DrawingBordersandBackground()
        {
            var root = new RootBoxFdo(new AssembledStyles());

            SetupFakeRootSite(root);
            var layoutInfo = HookupTests.MakeLayoutInfo(int.MaxValue / 2, m_gm.VwGraphics, 55);

            root.RendererFactory = layoutInfo.RendererFactory;
            var mock1 = new MockData1()
            {
                SimpleThree = "This is the first paragraph."
            };
            // The length of the second paragraph is found by experiment to be enough so that
            // despite its lacking borders it also breaks into 2 lines in the second step.
            var mock2 = new MockData1()
            {
                SimpleThree = "Here is another paragraph. It needs to be a bit longer."
            };

            root.Builder.Show(
                Paragraph.Containing(Display.Of(() => mock1.SimpleThree)).BackColor(Color.Red)
                .Margins(1.Points(), 2.Points(), 3.Points(), 4.Points())
                .Borders(5.Points(), 6.Points(), 7.Points(), 8.Points(), Color.Blue)
                .Pads(9.Points(), 10.Points(), 11.Points(), 12.Points()),
                Paragraph.Containing(Display.Of(() => mock2.SimpleThree)).BackColor(Color.Yellow)
                .Margins(1.Points(), 2.Points(), 3.Points(), 4.Points()));
            root.Layout(layoutInfo);
            // We want to keep track of the sequence of paint operations in all three segments.
            var drawActions = new List <object>();
            var vg          = new MockGraphics();

            vg.DrawActions = drawActions;
            var para1      = (ParaBox)root.FirstBox;
            var stringbox1 = (StringBox)para1.FirstBox;
            var seg1       = (FakeSegment)stringbox1.Segment;

            seg1.DrawActions = drawActions;
            var para2      = (ParaBox)para1.Next;
            var stringbox2 = (StringBox)para2.FirstBox;
            var seg2       = (FakeSegment)stringbox2.Segment;

            seg2.DrawActions = drawActions;

            var site = (MockSite)root.Site;

            root.Paint(vg, site.m_transform);
            var paintTrans = site.m_transform;
            int position   = 0;

            int red      = (int)ColorUtil.ConvertColorToBGR(Color.Red);
            int margLeft = layoutInfo.MpToPixelsX(1000);

            Assert.That(margLeft, Is.EqualTo(1));
            int bordLeft = layoutInfo.MpToPixelsX(5000);

            Assert.That(bordLeft, Is.EqualTo(7));
            int xOffset = 2 - 100;             // how far it is pushed over by the offsets of the layoutInfo
            int margTop = layoutInfo.MpToPixelsY(2000);

            Assert.That(margTop, Is.EqualTo(3));
            int bordTop = layoutInfo.MpToPixelsY(6000);

            Assert.That(bordTop, Is.EqualTo(8));
            int yOffset = 2 - 200;             // how far it is pushed down by the offsets of the layoutInfo
            int padLeft = layoutInfo.MpToPixelsX(9000);

            Assert.That(padLeft, Is.EqualTo(12));
            int padRight = layoutInfo.MpToPixelsX(11000);

            Assert.That(padRight, Is.EqualTo(15));
            int padTop = layoutInfo.MpToPixelsY(10000);

            Assert.That(padTop, Is.EqualTo(13));
            int padBottom = layoutInfo.MpToPixelsY(12000);

            Assert.That(padBottom, Is.EqualTo(16));
            // First it should draw a background rectangle for the first paragraph.
            // It is indented by the left margin and the left border, and down by the top margin and border.
            // The other side is determined by the size of the embedded box and the two pads.
            VerifyRect(drawActions, ref position, margLeft + bordLeft + xOffset, margTop + bordTop + yOffset,
                       margLeft + bordLeft + xOffset + stringbox1.Width + padLeft + padRight,
                       margTop + bordTop + yOffset + stringbox1.Height + padTop + padBottom,
                       red);
            int bordBottom = layoutInfo.MpToPixelsY(8000);

            Assert.That(bordBottom, Is.EqualTo(11));
            int blue = (int)ColorUtil.ConvertColorToBGR(Color.Blue);

            // It's arbitrary what order we draw the borders, and I wish the test didn't specify it,
            // but in fact the current implementation draws the left border first.
            VerifyRect(drawActions, ref position, margLeft + xOffset, margTop + yOffset,
                       margLeft + bordLeft + xOffset,
                       margTop + bordTop + yOffset + padTop + stringbox1.Height + padBottom + bordBottom,
                       blue);
            int bordRight = layoutInfo.MpToPixelsX(7000);

            Assert.That(bordRight, Is.EqualTo(9));
            // Then the top border
            VerifyRect(drawActions, ref position, margLeft + xOffset, margTop + yOffset,
                       margLeft + bordLeft + xOffset + padLeft + stringbox1.Width + padRight + bordRight,
                       margTop + bordTop + yOffset,
                       blue);
            // Then the right border
            VerifyRect(drawActions, ref position,
                       margLeft + bordLeft + xOffset + padLeft + stringbox1.Width + padRight,
                       margTop + yOffset,
                       margLeft + bordLeft + xOffset + padLeft + stringbox1.Width + padRight + bordRight,
                       margTop + bordTop + yOffset + padTop + stringbox1.Height + padBottom + bordBottom,
                       blue);
            // Then the bottom border
            VerifyRect(drawActions, ref position,
                       margLeft + xOffset,
                       margTop + bordTop + yOffset + padTop + stringbox1.Height + padBottom,
                       margLeft + bordLeft + xOffset + padLeft + stringbox1.Width + padRight + bordRight,
                       margTop + bordTop + yOffset + padTop + stringbox1.Height + padBottom + bordBottom,
                       blue);
            // Figure an adjusted y offset for the second paragraph. Everything is down by the height
            // of the first paragraph, except that the top and bottom margins overlap by the
            // height of the smaller.
            int yOffset2 = yOffset + para1.Height - margTop;
            int yellow   = (int)ColorUtil.ConvertColorToBGR(Color.Yellow);

            // Next a background block for the second paragraph.
            // (Background color should be reset for the embedded string boxes, so they should not draw their own
            // background.)
            VerifyRect(drawActions, ref position, margLeft + xOffset, margTop + yOffset2,
                       margLeft + xOffset + stringbox2.Width,
                       margTop + yOffset2 + stringbox2.Height,
                       yellow);
            // Verify the position where the text is drawn
            VerifyDraw(drawActions, ref position, seg1, margLeft + bordLeft + padLeft + 2, margTop + bordTop + padTop + 2);
            VerifyDraw(drawActions, ref position, seg2, margLeft + 2, para1.Height + 2);             //margTop cancels out
            // And that should be all!
            Assert.That(position, Is.EqualTo(drawActions.Count));

            // Verify that multi-lines in a paragraph are appropriately laid out with margin etc.
            int maxWidth = para1.Width - FakeRenderEngine.SimulatedWidth("paragraph");

            // This maxWidth should force each paragraph to make two segments.
            layoutInfo = HookupTests.MakeLayoutInfo(maxWidth, m_gm.VwGraphics, 55);
            root.Layout(layoutInfo);
            drawActions.Clear();
            position = 0;
            var stringbox1a = (StringBox)para1.FirstBox;
            var seg1a       = (FakeSegment)stringbox1a.Segment;

            seg1a.DrawActions = drawActions;
            var stringbox1b = (StringBox)stringbox1a.Next;
            var seg1b       = (FakeSegment)stringbox1b.Segment;

            seg1b.DrawActions = drawActions;
            var stringbox2a = (StringBox)para2.FirstBox;
            var seg2a       = (FakeSegment)stringbox2a.Segment;

            seg2a.DrawActions = drawActions;
            var stringbox2b = (StringBox)stringbox2a.Next;
            var seg2b       = (FakeSegment)stringbox2b.Segment;

            seg2b.DrawActions = drawActions;

            root.Paint(vg, site.m_transform);
            int margRight = layoutInfo.MpToPixelsX(3000);

            Assert.That(margRight, Is.EqualTo(4));
            // First it should draw a background rectangle for the first paragraph.
            // It is indented by the left margin and the left border, and down by the top margin and border.
            // The other side is determined by maxWidth minus the right margin and border.
            int contentHeight1 = stringbox1a.Height + stringbox1b.Height;

            VerifyRect(drawActions, ref position, margLeft + bordLeft + xOffset, margTop + bordTop + yOffset,
                       maxWidth - margRight - bordRight + xOffset,
                       margTop + bordTop + yOffset + contentHeight1 + padTop + padBottom,
                       red);
            // It's arbitrary what order we draw the borders, and I wish the test didn't specify it,
            // but in fact the current implementation draws the left border first.
            VerifyRect(drawActions, ref position, margLeft + xOffset, margTop + yOffset,
                       margLeft + bordLeft + xOffset,
                       margTop + bordTop + yOffset + padTop + contentHeight1 + padBottom + bordBottom,
                       blue);
            // Then the top border
            VerifyRect(drawActions, ref position, margLeft + xOffset, margTop + yOffset,
                       maxWidth - margRight + xOffset,
                       margTop + bordTop + yOffset,
                       blue);
            // Then the right border
            VerifyRect(drawActions, ref position,
                       maxWidth - margRight - bordRight + xOffset,
                       margTop + yOffset,
                       maxWidth - margRight + xOffset,
                       margTop + bordTop + yOffset + padTop + contentHeight1 + padBottom + bordBottom,
                       blue);
            // Then the bottom border
            VerifyRect(drawActions, ref position,
                       margLeft + xOffset,
                       margTop + bordTop + yOffset + padTop + contentHeight1 + padBottom,
                       maxWidth - margRight + xOffset,
                       margTop + bordTop + yOffset + padTop + contentHeight1 + padBottom + bordBottom,
                       blue);
            // Figure an adjusted y offset for the second paragraph. Everything is down by the height
            // of the first paragraph, except that the top and bottom margins overlap by the
            // height of the smaller.
            yOffset2 = yOffset + para1.Height - margTop;
            // Next a background block for the second paragraph.
            // (Background color should be reset for the embedded string boxes, so they should not draw their own
            // background.)
            VerifyRect(drawActions, ref position, margLeft + xOffset, margTop + yOffset2,
                       maxWidth - margRight + xOffset,
                       margTop + yOffset2 + stringbox2a.Height + stringbox2b.Height,
                       yellow);
            // Verify the position where the text is drawn
            VerifyDraw(drawActions, ref position, seg1a, margLeft + bordLeft + padLeft + 2, margTop + bordTop + padTop + 2);
            VerifyDraw(drawActions, ref position, seg1b, margLeft + bordLeft + padLeft + 2,
                       margTop + bordTop + padTop + 2 + stringbox1a.Height);
            VerifyDraw(drawActions, ref position, seg2a, margLeft + 2, para1.Height + 2);                      //margTop cancels out
            VerifyDraw(drawActions, ref position, seg2b, margLeft + 2, para1.Height + 2 + stringbox2a.Height); //margTop cancels out
            // And that should be all!
            Assert.That(position, Is.EqualTo(drawActions.Count));

            // A quick check that Relayout puts things in the same places.
            drawActions.Clear();
            position = 0;
            var fixupMap = new Dictionary <Box, Rectangle>();

            fixupMap[para1] = new Rectangle(0, 0, 10, 10);
            var oldstring1aLeft = stringbox1a.Left;
            var oldstring1bTop  = stringbox1b.Top;

            using (var lcb = new LayoutCallbacks(root))
                root.Relayout(layoutInfo, fixupMap, lcb);
            Assert.That(drawActions.Count, Is.EqualTo(0));
            Assert.That(para1.FirstBox.Left, Is.EqualTo(oldstring1aLeft));
            Assert.That(para1.FirstBox.Next.Top, Is.EqualTo(oldstring1bTop));
        }
Exemplo n.º 8
0
        public void PileAndBlock()
        {
            var root = new RootBoxFdo(new AssembledStyles());

            SetupFakeRootSite(root);
            var layoutInfo = HookupTests.MakeLayoutInfo(int.MaxValue / 2, m_gm.VwGraphics, 55);

            root.RendererFactory = layoutInfo.RendererFactory;
            var mock1 = new MockData1()
            {
                SimpleThree = "This is the first paragraph."
            };
            // The length of the second paragraph is found by experiment to be enough so that
            // despite its lacking borders it also breaks into 2 lines in the second step.
            var mock2 = new MockData1()
            {
                SimpleThree = "Here is another paragraph. It needs to be a bit longer."
            };

            root.Builder.Show(
                Div.Containing(
                    Display.Block(Color.Red, 25000, 18000).BackColor(Color.Purple)
                    .Margins(3000, 3000, 3000, 3000)
                    .Border(5000, Color.Blue)
                    .Pads(4000, 4000, 4000, 4000),
                    Display.Block(Color.Green, 25000, 18000)
                    ).BackColor(Color.Pink)                     // these apply to div.
                .Margins(1000, 1000, 1000, 1000)
                .Border(2000, Color.Gold)
                .Pads(6000, 6000, 6000, 6000));
            root.Layout(layoutInfo);
            // We want to keep track of the sequence of paint operations in all three segments.
            var drawActions = new List <object>();
            var vg          = new MockGraphics();

            vg.DrawActions = drawActions;

            var site = (MockSite)root.Site;

            root.Paint(vg, site.m_transform);
            var paintTrans = site.m_transform;
            int position   = 0;
            int xOffset    = 2 - 100;          // how far it is pushed over by the offsets of the layoutInfo
            int yOffset    = 2 - 200;          // how far it is pushed down by the offsets of the layoutInfo

            int red    = (int)ColorUtil.ConvertColorToBGR(Color.Red);
            int pink   = (int)ColorUtil.ConvertColorToBGR(Color.Pink);
            int purple = (int)ColorUtil.ConvertColorToBGR(Color.Purple);
            int blue   = (int)ColorUtil.ConvertColorToBGR(Color.Blue);
            int green  = (int)ColorUtil.ConvertColorToBGR(Color.Green);
            int gold   = (int)ColorUtil.ConvertColorToBGR(Color.Gold);
            // Technically we could do different conversions in the two directions, but for this test both dpi are the same.
            int margPile    = layoutInfo.MpToPixelsX(1000);
            int bordPile    = layoutInfo.MpToPixelsX(2000);
            int padPile     = layoutInfo.MpToPixelsX(6000);
            int blockWidth  = layoutInfo.MpToPixelsX(25000);
            int blockHeight = layoutInfo.MpToPixelsX(18000);
            int margBlock   = layoutInfo.MpToPixelsX(3000);
            int bordBlock   = layoutInfo.MpToPixelsX(5000);
            int padBlock    = layoutInfo.MpToPixelsX(4000);

            // First a background rectangle for the whole pile.
            var leftPilePad   = margPile + bordPile + xOffset;
            var topPilePad    = margPile + bordPile + yOffset;
            var rightPilePad  = margPile + bordPile + 2 * padPile + blockWidth + 2 * margBlock + 2 * bordBlock + 2 * padBlock + xOffset;
            var bottomPilePad = margPile + bordPile + 2 * padPile + 2 * blockHeight + 2 * margBlock + 2 * bordBlock + 2 * padBlock + yOffset;

            VerifyRect(drawActions, ref position, leftPilePad, topPilePad, rightPilePad, bottomPilePad, pink);
            // Left border, whole pile
            VerifyRect(drawActions, ref position, leftPilePad - bordPile, topPilePad - bordPile,
                       leftPilePad, bottomPilePad + bordPile, gold);
            // top border, whole pile
            VerifyRect(drawActions, ref position, leftPilePad - bordPile, topPilePad - bordPile,
                       rightPilePad + bordPile, topPilePad, gold);
            // right border, whole pile
            VerifyRect(drawActions, ref position, rightPilePad, topPilePad - bordPile,
                       rightPilePad + bordPile, bottomPilePad + bordPile, gold);
            // bottom border, whole pile
            VerifyRect(drawActions, ref position, leftPilePad - bordPile, bottomPilePad,
                       rightPilePad + bordPile, bottomPilePad + bordPile, gold);

            // background and border for first block.
            var leftBlockPad   = margPile + bordPile + padPile + margBlock + bordBlock + xOffset;
            var topBlockPad    = margPile + bordPile + padPile + margBlock + bordBlock + yOffset;
            var rightBlockPad  = margPile + bordPile + padPile + margBlock + bordBlock + 2 * padBlock + blockWidth + xOffset;
            var bottomBlockPad = margPile + bordPile + padPile + margBlock + bordBlock + 2 * padBlock + blockHeight + yOffset;

            VerifyRect(drawActions, ref position, leftBlockPad, topBlockPad, rightBlockPad, bottomBlockPad, purple);
            // Left border, whole pile
            VerifyRect(drawActions, ref position, leftBlockPad - bordBlock, topBlockPad - bordBlock,
                       leftBlockPad, bottomBlockPad + bordBlock, blue);
            // top border, whole pile
            VerifyRect(drawActions, ref position, leftBlockPad - bordBlock, topBlockPad - bordBlock,
                       rightBlockPad + bordBlock, topBlockPad, blue);
            // right border, whole pile
            VerifyRect(drawActions, ref position, rightBlockPad, topBlockPad - bordBlock,
                       rightBlockPad + bordBlock, bottomBlockPad + bordBlock, blue);
            // bottom border, whole pile
            VerifyRect(drawActions, ref position, leftBlockPad - bordBlock, bottomBlockPad,
                       rightBlockPad + bordBlock, bottomBlockPad + bordBlock, blue);
            // The first block itself.
            VerifyRect(drawActions, ref position, leftBlockPad + padBlock, topBlockPad + padBlock,
                       leftBlockPad + padBlock + blockWidth, topBlockPad + padBlock + blockHeight, red);
            // The second block itself.
            var topBlock2 = bottomBlockPad + bordBlock + margBlock;

            VerifyRect(drawActions, ref position, leftPilePad + padPile, topBlock2,
                       leftPilePad + padPile + blockWidth, topBlock2 + blockHeight, green);
            // And that should be all!
            Assert.That(position, Is.EqualTo(drawActions.Count));

            // A quick check that Relayout puts things in the same places.
            drawActions.Clear();
            var fixupMap = new Dictionary <Box, Rectangle>();
            var div1     = (DivBox)root.FirstBox;
            var block1   = div1.FirstBox;

            fixupMap[div1]   = new Rectangle(0, 0, 10, 10);
            fixupMap[block1] = new Rectangle(0, 0, 10, 10);
            var oldblock1Left = block1.Left;
            var oldblock1bTop = block1.Top;

            using (var lcb = new LayoutCallbacks(root))
                root.Relayout(layoutInfo, fixupMap, lcb);
            Assert.That(drawActions.Count, Is.EqualTo(0));
            Assert.That(div1.FirstBox.Left, Is.EqualTo(oldblock1Left));
            Assert.That(div1.FirstBox.Top, Is.EqualTo(oldblock1bTop));
        }