private void BodyofUserPromptTest(MockData1 data1, Flow promptField, Func<string> reader) { var engine = new FakeRenderEngine() { Ws = 34, SegmentHeight = 13 }; var factory = new FakeRendererFactory(); factory.SetRenderer(34, engine); factory.SetRenderer(35, engine); factory.SetRenderer(0, engine); // for literals var styles = new AssembledStyles().WithWs(34); var root = new RootBoxFdo(styles); root.Builder.Show( Paragraph.Containing( Display.Of("lead in ", 34), promptField, Display.Of("trailing", 34) ) ); var para = (ParaBox)root.FirstBox; Assert.That(para.Source.RenderText, Is.EqualTo("lead in type here trailing")); int width = FakeRenderEngine.SimulatedWidth("lead in type her"); // should make it take 2 lines and split prompt. var layoutArgs = MakeLayoutInfo(width, m_gm.VwGraphics, factory); root.Layout(layoutArgs); MockSite site = new MockSite(); PaintTransform ptrans = new PaintTransform(2, 4, 96, 96, 0, 10, 96, 96); site.m_transform = ptrans; site.m_vwGraphics = m_gm.VwGraphics; root.Site = site; // Click on "type here" produces an IP in the empty string. int leadWidth = FakeRenderEngine.SimulatedWidth("lead in "); var mouseArgs = new MouseEventArgs(MouseButtons.Left, 1, 2 + leadWidth + 3, 0, 0); root.OnMouseDown(mouseArgs, Keys.None, m_gm.VwGraphics, ptrans); var ip = root.Selection as InsertionPoint; Assert.That(ip, Is.Not.Null); Assert.That(ip.LogicalParaPosition, Is.EqualTo("lead in ".Length)); Assert.That(ip.StringPosition, Is.EqualTo(0)); // IP is drawn as range covering "type here" ip.Draw(m_gm.VwGraphics, ptrans); var first = (StringBox)para.FirstBox; VerifyRangeSegmentDrawing(para, first, (FakeSegment)first.Segment, "lead in ".Length, "lead in type here ".Length, -4, 4 - 10, 4 - 10 + 13); var second = (StringBox)first.Next; VerifyRangeSegmentDrawing(para, second, (FakeSegment)second.Segment, "lead in ".Length, "lead in type here ".Length, -4 - 13, 4 - 10 + 13, 4 - 10 + 13 * 2); // Check that we get a sensible answer for the selection's containing rectangle. ((FakeSegment) first.Segment).LeftPositionOfRangeResult = 17; ((FakeSegment)first.Segment).RightPositionOfRangeResult = 29; ((FakeSegment)second.Segment).LeftPositionOfRangeResult = 5; ((FakeSegment)second.Segment).RightPositionOfRangeResult = 13; var rect = ip.GetSelectionLocation(m_gm.VwGraphics, ptrans); Assert.That(rect.Top, Is.EqualTo(4 - 10)); Assert.That(rect.Bottom, Is.EqualTo(4 - 10 + 13*2)); Assert.That(rect.Left, Is.EqualTo(5)); Assert.That(rect.Right, Is.EqualTo(29)); VerifyRangeSegmentQuery(para, first, (FakeSegment)first.Segment, "lead in ".Length, "lead in type here ".Length, -4, 4 - 10, 4 - 10 + 13); VerifyRangeSegmentQuery(para, second, (FakeSegment)second.Segment, "lead in ".Length, "lead in type here ".Length, -4 - 13, 4 - 10 + 13, 4 - 10 + 13 * 2); Assert.That(second.IchMin, Is.EqualTo("lead in type ".Length)); // When the IP is drawn like this, it doesn't flash! site.RectsInvalidatedInRoot.Clear(); site.RectsInvalidated.Clear(); root.FlashInsertionPoint(); // Call twice just in case somehow only some invalidates worked. root.FlashInsertionPoint(); Assert.That(site.RectsInvalidated, Is.Empty); Assert.That(site.RectsInvalidatedInRoot, Is.Empty); // Typing something else makes "type here" go away and produces a normal IP after it. ip.InsertText("x"); Assert.That(reader(), Is.EqualTo("x")); Assert.That(para.Source.RenderText, Is.EqualTo("lead in xtrailing")); ip = root.Selection as InsertionPoint; Assert.That(ip, Is.Not.Null); Assert.That(ip.ShouldFlash, Is.True); Assert.That(ip.LogicalParaPosition, Is.EqualTo("lead in x".Length)); // Deleting back to empty string makes "type here" reappear. ip.Backspace(); Assert.That(reader(), Is.EqualTo("")); Assert.That(para.Source.RenderText, Is.EqualTo("lead in type here trailing")); ip = root.Selection as InsertionPoint; Assert.That(ip, Is.Not.Null); Assert.That(ip.ShouldFlash, Is.False); Assert.That(ip.LogicalParaPosition, Is.EqualTo("lead in ".Length)); Assert.That(ip.LastRenderParaPosition, Is.EqualTo("lead in type here ".Length)); second = (StringBox)para.FirstBox.Next; Assert.That(second.IchMin, Is.EqualTo("lead in type ".Length)); // Click after "type here" produces an IP at the right place in the following string. // We've arranged for the prompt to be split, so this is after the word 'here' on the second line. int hereTWidth = FakeRenderEngine.SimulatedWidth("here t"); mouseArgs = new MouseEventArgs(MouseButtons.Left, 1, 2 + hereTWidth - 1, 4 - 10 + 13 + 2, 0); root.OnMouseDown(mouseArgs, Keys.None, m_gm.VwGraphics, ptrans); ip = root.Selection as InsertionPoint; Assert.That(ip, Is.Not.Null); Assert.That(ip.LogicalParaPosition, Is.EqualTo("lead in t".Length)); Assert.That(ip.AssociatePrevious, Is.True); Assert.That(ip.StringPosition, Is.EqualTo(1)); Assert.That(ip.RenderParaPosition, Is.EqualTo("lead in type here t".Length)); // Also try a click in the second-line part of the prompt. int herWidth = FakeRenderEngine.SimulatedWidth("her"); mouseArgs = new MouseEventArgs(MouseButtons.Left, 1, 2 + herWidth - 1, 4 - 10 + 13 + 2, 0); root.OnMouseDown(mouseArgs, Keys.None, m_gm.VwGraphics, ptrans); ip = root.Selection as InsertionPoint; Assert.That(ip, Is.Not.Null); Assert.That(ip.LogicalParaPosition, Is.EqualTo("lead in ".Length)); Assert.That(ip.StringPosition, Is.EqualTo(0)); Assert.That(ip.RenderParaPosition, Is.EqualTo("lead in ".Length)); Assert.That(ip.LastRenderParaPosition, Is.EqualTo("lead in type here ".Length)); }
private void BodyofUserPromptTest(MockData1 data1, Flow promptField, Func <string> reader) { var engine = new FakeRenderEngine() { Ws = 34, SegmentHeight = 13 }; var factory = new FakeRendererFactory(); factory.SetRenderer(34, engine); factory.SetRenderer(35, engine); factory.SetRenderer(0, engine); // for literals var styles = new AssembledStyles().WithWs(34); var root = new RootBoxFdo(styles); root.Builder.Show( Paragraph.Containing( Display.Of("lead in ", 34), promptField, Display.Of("trailing", 34) ) ); var para = (ParaBox)root.FirstBox; Assert.That(para.Source.RenderText, Is.EqualTo("lead in type here trailing")); int width = FakeRenderEngine.SimulatedWidth("lead in type her"); // should make it take 2 lines and split prompt. var layoutArgs = MakeLayoutInfo(width, m_gm.VwGraphics, factory); root.Layout(layoutArgs); MockSite site = new MockSite(); PaintTransform ptrans = new PaintTransform(2, 4, 96, 96, 0, 10, 96, 96); site.m_transform = ptrans; site.m_vwGraphics = m_gm.VwGraphics; root.Site = site; // Click on "type here" produces an IP in the empty string. int leadWidth = FakeRenderEngine.SimulatedWidth("lead in "); var mouseArgs = new MouseEventArgs(MouseButtons.Left, 1, 2 + leadWidth + 3, 0, 0); root.OnMouseDown(mouseArgs, Keys.None, m_gm.VwGraphics, ptrans); var ip = root.Selection as InsertionPoint; Assert.That(ip, Is.Not.Null); Assert.That(ip.LogicalParaPosition, Is.EqualTo("lead in ".Length)); Assert.That(ip.StringPosition, Is.EqualTo(0)); // IP is drawn as range covering "type here" ip.Draw(m_gm.VwGraphics, ptrans); var first = (StringBox)para.FirstBox; VerifyRangeSegmentDrawing(para, first, (FakeSegment)first.Segment, "lead in ".Length, "lead in type here ".Length, -4, 4 - 10, 4 - 10 + 13); var second = (StringBox)first.Next; VerifyRangeSegmentDrawing(para, second, (FakeSegment)second.Segment, "lead in ".Length, "lead in type here ".Length, -4 - 13, 4 - 10 + 13, 4 - 10 + 13 * 2); // Check that we get a sensible answer for the selection's containing rectangle. ((FakeSegment)first.Segment).LeftPositionOfRangeResult = 17; ((FakeSegment)first.Segment).RightPositionOfRangeResult = 29; ((FakeSegment)second.Segment).LeftPositionOfRangeResult = 5; ((FakeSegment)second.Segment).RightPositionOfRangeResult = 13; var rect = ip.GetSelectionLocation(m_gm.VwGraphics, ptrans); Assert.That(rect.Top, Is.EqualTo(4 - 10)); Assert.That(rect.Bottom, Is.EqualTo(4 - 10 + 13 * 2)); Assert.That(rect.Left, Is.EqualTo(5)); Assert.That(rect.Right, Is.EqualTo(29)); VerifyRangeSegmentQuery(para, first, (FakeSegment)first.Segment, "lead in ".Length, "lead in type here ".Length, -4, 4 - 10, 4 - 10 + 13); VerifyRangeSegmentQuery(para, second, (FakeSegment)second.Segment, "lead in ".Length, "lead in type here ".Length, -4 - 13, 4 - 10 + 13, 4 - 10 + 13 * 2); Assert.That(second.IchMin, Is.EqualTo("lead in type ".Length)); // When the IP is drawn like this, it doesn't flash! site.RectsInvalidatedInRoot.Clear(); site.RectsInvalidated.Clear(); root.FlashInsertionPoint(); // Call twice just in case somehow only some invalidates worked. root.FlashInsertionPoint(); Assert.That(site.RectsInvalidated, Is.Empty); Assert.That(site.RectsInvalidatedInRoot, Is.Empty); // Typing something else makes "type here" go away and produces a normal IP after it. ip.InsertText("x"); Assert.That(reader(), Is.EqualTo("x")); Assert.That(para.Source.RenderText, Is.EqualTo("lead in xtrailing")); ip = root.Selection as InsertionPoint; Assert.That(ip, Is.Not.Null); Assert.That(ip.ShouldFlash, Is.True); Assert.That(ip.LogicalParaPosition, Is.EqualTo("lead in x".Length)); // Deleting back to empty string makes "type here" reappear. ip.Backspace(); Assert.That(reader(), Is.EqualTo("")); Assert.That(para.Source.RenderText, Is.EqualTo("lead in type here trailing")); ip = root.Selection as InsertionPoint; Assert.That(ip, Is.Not.Null); Assert.That(ip.ShouldFlash, Is.False); Assert.That(ip.LogicalParaPosition, Is.EqualTo("lead in ".Length)); Assert.That(ip.LastRenderParaPosition, Is.EqualTo("lead in type here ".Length)); second = (StringBox)para.FirstBox.Next; Assert.That(second.IchMin, Is.EqualTo("lead in type ".Length)); // Click after "type here" produces an IP at the right place in the following string. // We've arranged for the prompt to be split, so this is after the word 'here' on the second line. int hereTWidth = FakeRenderEngine.SimulatedWidth("here t"); mouseArgs = new MouseEventArgs(MouseButtons.Left, 1, 2 + hereTWidth - 1, 4 - 10 + 13 + 2, 0); root.OnMouseDown(mouseArgs, Keys.None, m_gm.VwGraphics, ptrans); ip = root.Selection as InsertionPoint; Assert.That(ip, Is.Not.Null); Assert.That(ip.LogicalParaPosition, Is.EqualTo("lead in t".Length)); Assert.That(ip.AssociatePrevious, Is.True); Assert.That(ip.StringPosition, Is.EqualTo(1)); Assert.That(ip.RenderParaPosition, Is.EqualTo("lead in type here t".Length)); // Also try a click in the second-line part of the prompt. int herWidth = FakeRenderEngine.SimulatedWidth("her"); mouseArgs = new MouseEventArgs(MouseButtons.Left, 1, 2 + herWidth - 1, 4 - 10 + 13 + 2, 0); root.OnMouseDown(mouseArgs, Keys.None, m_gm.VwGraphics, ptrans); ip = root.Selection as InsertionPoint; Assert.That(ip, Is.Not.Null); Assert.That(ip.LogicalParaPosition, Is.EqualTo("lead in ".Length)); Assert.That(ip.StringPosition, Is.EqualTo(0)); Assert.That(ip.RenderParaPosition, Is.EqualTo("lead in ".Length)); Assert.That(ip.LastRenderParaPosition, Is.EqualTo("lead in type here ".Length)); }