public void DragStartsOnMoveInSelection() { string contents = "This is the day."; var engine = new FakeRenderEngine() {Ws = 34, SegmentHeight = 13}; var factory = new FakeRendererFactory(); factory.SetRenderer(34, engine); var styles = new AssembledStyles().WithWs(34); var clientRuns = new List<IClientRun>(); var run = new StringClientRun(contents, styles); clientRuns.Add(run); var source = new TextSource(clientRuns, null); var para = new ParaBox(styles, source); var extraBox = new BlockBox(styles, Color.Red, 50, 72000); // tall, narrow spacer at top var root = new RootBoxFdo(styles); root.AddBox(extraBox); root.AddBox(para); var layoutArgs = MakeLayoutInfo(Int32.MaxValue/2, m_gm.VwGraphics, factory); root.Layout(layoutArgs); Assert.That(root.Height, Is.EqualTo(96 + 13)); Assert.That(root.Width, Is.EqualTo(FakeRenderEngine.SimulatedWidth(contents))); var ip1 = run.SelectAt(para, 5, false); var ip2 = run.SelectAt(para, 7, true); var range = new RangeSelection(ip1, ip2); range.Install(); PaintTransform ptrans = new PaintTransform(2, 2, 96, 96, 0, 0, 96, 96); var sbox = para.FirstBox as StringBox; MockSite site = new MockSite(); site.m_transform = ptrans; site.m_vwGraphics = m_gm.VwGraphics; root.Site = site; int indent = FakeRenderEngine.SimulatedWidth("This "); root.OnMouseDown(new MouseEventArgs(MouseButtons.Left, 1, indent + 5, 100, 0), Keys.None, m_gm.VwGraphics, ptrans); root.OnMouseMove(new MouseEventArgs(MouseButtons.Left, 1, indent + 5, 100, 0), Keys.None, m_gm.VwGraphics, ptrans); Assert.That(GetStringDropData(site), Is.EqualTo("is")); Assert.That(site.LastDoDragDropArgs.AllowedEffects, Is.EqualTo(DragDropEffects.Copy), "editing not possible in this paragraph, we can only copy"); Assert.That(root.Selection, Is.EqualTo(range), "selection should not be changed by drag drop"); site.LastDoDragDropArgs = null; root.OnMouseDown(new MouseEventArgs(MouseButtons.Left, 1, 3, 100, 0), Keys.None, m_gm.VwGraphics, ptrans); Assert.That(site.LastDoDragDropArgs, Is.Null, "click outside selection should not initiate drag"); // Tack on an extra check that a read-only view does not handle drop. var dataObj = new DataObject(DataFormats.StringFormat, "new "); var dragArgs = new DragEventArgs(dataObj, (int)DragDropKeyStates.ControlKey, 10, 8, DragDropEffects.Copy | DragDropEffects.Move, DragDropEffects.None); root.OnDragEnter(dragArgs, new Point(14, 8), m_gm.VwGraphics, ptrans); Assert.That(dragArgs.Effect, Is.EqualTo(DragDropEffects.None)); Assert.That(root.DragState, Is.EqualTo(WindowDragState.DraggingHere)); }
private void InitRedBox() { var styles = new AssembledStyles(); RootBox root = new RootBoxFdo(styles); var block = new BlockBox(styles, Color.Red, 72000, 36000); root.AddBox(block); theSharpView.Root = root; }
private void InitSeveralBoxes() { var styles = new AssembledStyles(); RootBox root = new RootBoxFdo(styles); var items = new List <IClientRun>(); items.Add(new BlockBox(styles, Color.Red, 72000, 36000)); items.Add(new BlockBox(styles, Color.Blue, 36000, 18000)); items.Add(new BlockBox(styles, Color.Orange, 18000, 36000)); items.Add(new BlockBox(styles, Color.Green, 72000, 18000)); items.Add(new ImageBox(styles.WithBackColor(Color.Pink).WithBorderColor(Color.Blue) .WithBorders(new Thickness(2.0)).WithPads(new Thickness(4.0)), new Icon(SystemIcons.Shield, 40, 40).ToBitmap())); items.Add(new BlockBox(styles, Color.Yellow, 72000, 36000)); var source = new TextSource(items); var para = new ParaBox(styles, source); root.AddBox(para); theSharpView.Root = root; }
public void BidiLayout() { string content1 = "This is the "; string contentRtl = "day "; string content3 = "that "; // Two writing systems int wsLtr = 5; int wsRtl = 6; // Two corresponding renderers var factory = new FakeRendererFactory(); var engineLtr = new FakeRenderEngine() { Ws = wsLtr, SegmentHeight = 13 }; factory.SetRenderer(wsLtr, engineLtr); var engineRtl = new FakeRenderEngine() {Ws = wsRtl, SegmentHeight = 13 }; engineRtl.RightToLeft = true; factory.SetRenderer(wsRtl, engineRtl); // Two corresponding styles (and a vanilla one) var styles = new AssembledStyles(); var stylesLtr = new AssembledStyles().WithWs(wsLtr); var stylesRtl = new AssembledStyles().WithWs(wsRtl); var clientRuns = new List<IClientRun>(); var run1 = new StringClientRun(content1, stylesLtr); clientRuns.Add(run1); var runRtl = new StringClientRun(contentRtl, stylesRtl); clientRuns.Add(runRtl); var run3 = new StringClientRun(content3, stylesLtr); clientRuns.Add(run3); var root = new RootBoxFdo(styles); var source = new TextSource(clientRuns, null); var para = new ParaBox(styles, source); root.AddBox(para); var stylesParaRtl = styles.WithRightToLeft(true); var sourceRtl = new TextSource(clientRuns, null); var paraRtl = new ParaBox(stylesParaRtl, sourceRtl); root.AddBox(paraRtl); var layoutArgs = MakeLayoutInfo(Int32.MaxValue / 2, m_gm.VwGraphics, factory); root.Layout(layoutArgs); // "day " being upstream should make two distinct boxes. // We should get something like // "This is the yad that ", where the space between "yad" and "that" is the one that // follows the 'y' in "day". var box1 = para.FirstBox as StringBox; var box2 = box1.Next as StringBox; var box3 = box2.Next as StringBox; var box4 = box3.Next as StringBox; Assert.That(box4, Is.Not.Null); Assert.That(box1.Segment.get_Lim(box1.IchMin) == content1.Length); Assert.That(box2.Segment.get_Lim(box2.IchMin) == contentRtl.Length - 1); Assert.That(box3.Segment.get_Lim(box3.IchMin) == 1); Assert.That(box4.Segment.get_Lim(box4.IchMin) == content3.Length); Assert.That(box1.Left, Is.LessThan(box2.Left)); Assert.That(box2.Left, Is.LessThan(box3.Left)); Assert.That(box3.Left, Is.LessThan(box4.Left)); // In the second paragraph, the two LRT runs are upstream. We should get boxes // "This is the", " ", "day ", "that" and " " (but the final space will have zero width at end of line) // The effect should be something like // that yad This is the", where the space between "yad" and "This" is the one following "the", // and the one between "that" and "yad" is the one following "day", and the space following "that" // is invisible at the end of the line to the left of 'that'. var boxR1 = paraRtl.FirstBox as StringBox; var boxR2 = boxR1.Next as StringBox; var boxR3 = boxR2.Next as StringBox; var boxR4 = boxR3.Next as StringBox; var boxR5 = boxR4.Next as StringBox; Assert.That(boxR5, Is.Not.Null); Assert.That(boxR1.Segment.get_Lim(boxR1.IchMin) == content1.Length - 1); Assert.That(boxR2.Segment.get_Lim(boxR2.IchMin) == 1); Assert.That(boxR3.Segment.get_Lim(boxR3.IchMin) == contentRtl.Length); Assert.That(boxR4.Segment.get_Lim(boxR4.IchMin) == content3.Length - 1); Assert.That(boxR5.Segment.get_Lim(boxR5.IchMin) == 1); }
public void DragStartsOnMoveInSelection() { string contents = "This is the day."; var engine = new FakeRenderEngine() { Ws = 34, SegmentHeight = 13 }; var factory = new FakeRendererFactory(); factory.SetRenderer(34, engine); var styles = new AssembledStyles().WithWs(34); var clientRuns = new List <IClientRun>(); var run = new StringClientRun(contents, styles); clientRuns.Add(run); var source = new TextSource(clientRuns, null); var para = new ParaBox(styles, source); var extraBox = new BlockBox(styles, Color.Red, 50, 72000); // tall, narrow spacer at top var root = new RootBoxFdo(styles); root.AddBox(extraBox); root.AddBox(para); var layoutArgs = MakeLayoutInfo(Int32.MaxValue / 2, m_gm.VwGraphics, factory); root.Layout(layoutArgs); Assert.That(root.Height, Is.EqualTo(96 + 13)); Assert.That(root.Width, Is.EqualTo(FakeRenderEngine.SimulatedWidth(contents))); var ip1 = run.SelectAt(para, 5, false); var ip2 = run.SelectAt(para, 7, true); var range = new RangeSelection(ip1, ip2); range.Install(); PaintTransform ptrans = new PaintTransform(2, 2, 96, 96, 0, 0, 96, 96); var sbox = para.FirstBox as StringBox; MockSite site = new MockSite(); site.m_transform = ptrans; site.m_vwGraphics = m_gm.VwGraphics; root.Site = site; int indent = FakeRenderEngine.SimulatedWidth("This "); root.OnMouseDown(new MouseEventArgs(MouseButtons.Left, 1, indent + 5, 100, 0), Keys.None, m_gm.VwGraphics, ptrans); root.OnMouseMove(new MouseEventArgs(MouseButtons.Left, 1, indent + 5, 100, 0), Keys.None, m_gm.VwGraphics, ptrans); Assert.That(GetStringDropData(site), Is.EqualTo("is")); Assert.That(site.LastDoDragDropArgs.AllowedEffects, Is.EqualTo(DragDropEffects.Copy), "editing not possible in this paragraph, we can only copy"); Assert.That(root.Selection, Is.EqualTo(range), "selection should not be changed by drag drop"); site.LastDoDragDropArgs = null; root.OnMouseDown(new MouseEventArgs(MouseButtons.Left, 1, 3, 100, 0), Keys.None, m_gm.VwGraphics, ptrans); Assert.That(site.LastDoDragDropArgs, Is.Null, "click outside selection should not initiate drag"); // Tack on an extra check that a read-only view does not handle drop. var dataObj = new DataObject(DataFormats.StringFormat, "new "); var dragArgs = new DragEventArgs(dataObj, (int)DragDropKeyStates.ControlKey, 10, 8, DragDropEffects.Copy | DragDropEffects.Move, DragDropEffects.None); root.OnDragEnter(dragArgs, new Point(14, 8), m_gm.VwGraphics, ptrans); Assert.That(dragArgs.Effect, Is.EqualTo(DragDropEffects.None)); Assert.That(root.DragState, Is.EqualTo(WindowDragState.DraggingHere)); }
public void Contains() { var styles = new AssembledStyles(); var runStyle = styles.WithWs(32); var root = new RootBoxFdo(styles); var para1 = MakePara(styles, runStyle, "This is the day"); var para2 = MakePara(styles, runStyle, "that the Lord has made"); var para3 = MakePara(styles, runStyle, "We will rejoice"); var div = new DivBox(styles); var para4 = MakePara(styles, runStyle, "and be glad in it"); var para5 = MakePara(styles, runStyle, ""); var para6 = MakePara(styles, runStyle, "Rejoice!"); root.AddBox(para1); root.AddBox(para2); div.AddBox(para3); div.AddBox(para4); root.AddBox(div); root.AddBox(para5); root.AddBox(para6); var run1 = para1.Source.ClientRuns[0] as StringClientRun; var ip1_0 = run1.SelectAt(para1, 0, false); var ip1_2p = run1.SelectAt(para1, 2, true); var range1_0_2 = new RangeSelection(ip1_0, ip1_2p); Assert.That(range1_0_2.Contains(ip1_0), Is.True, "selection at start of range is included"); Assert.That(range1_0_2.Contains(ip1_2p), Is.True, "selection at end of range is included"); var ip1_1p = run1.SelectAt(para1, 1, true); Assert.That(range1_0_2.Contains(ip1_1p), Is.True, "selection in middle of 1-para range is included"); var ip1_3p = run1.SelectAt(para1, 3, true); Assert.That(range1_0_2.Contains(ip1_3p), Is.False); var ip1_2a = run1.SelectAt(para1, 2, false); Assert.That(range1_0_2.Contains(ip1_2a), Is.False, "ip at end associated following is not included"); var ip1_5p = run1.SelectAt(para1, 5, true); var range1_2_5 = new RangeSelection(ip1_2a, ip1_5p); Assert.That(range1_2_5.Contains(ip1_0), Is.False, "IP before start in same para not included"); Assert.That(range1_2_5.Contains(ip1_2p), Is.False, "IP at start associated previous not included"); Assert.That(range1_2_5.Contains(ip1_2a), Is.True, "IP at start not associated previous is included"); var run2 = para2.Source.ClientRuns[0] as StringClientRun; var ip2_2p = run2.SelectAt(para2, 2, true); Assert.That(range1_2_5.Contains(ip2_2p), Is.False, "IP in following paragraph not included"); var ip2_5p = run2.SelectAt(para2, 5, true); var ip2_2a = run2.SelectAt(para2, 2, false); var range2_5_2 = new RangeSelection(ip2_5p, ip2_2a); var ip2_3a = run2.SelectAt(para2, 3, false); Assert.That(range2_5_2.Contains(ip2_3a), Is.True, "IP in middle of backwards selection is included"); Assert.That(range2_5_2.Contains(ip1_2a), Is.False, "IP in previous para not included"); var run6 = para6.Source.ClientRuns[0] as StringClientRun; var ip6_2p = run6.SelectAt(para6, 2, true); var ip1_5a = run1.SelectAt(para1, 5, false); var range1_5_6_2 = new RangeSelection(ip1_5a, ip6_2p); Assert.That(range1_5_6_2.Contains(ip1_0), Is.False, "IP before multi-para not included"); Assert.That(range1_5_6_2.Contains(ip1_3p), Is.False, "IP before multi-para not included, even with offset > end offset"); var ip6_4a = run6.SelectAt(para6, 4, false); Assert.That(range1_5_6_2.Contains(ip6_4a), Is.False, "IP after multi-para not included, even with offset < start offset"); Assert.That(range1_5_6_2.Contains(ip2_3a), Is.True, "IP middle para of multi is included"); var run4 = para4.Source.ClientRuns[0] as StringClientRun; var ip40 = run4.SelectAt(para4, 0, false); Assert.That(range1_5_6_2.Contains(ip40), Is.True, "IP in div within multi is included"); var run5 = para5.Source.ClientRuns[0] as StringClientRun; var ip50a = run5.SelectAt(para5, 0, false); Assert.That(range1_5_6_2.Contains(ip50a), Is.True, "IP in empty para within multi is included"); // I'm not absolutely sure this is the right design, but it's rather arbitrary whether an IP in an empty // paragraph associates forward or backward. If a range extends to the empty paragraph, I think it should // be included either way. var range1_5_5_0 = new RangeSelection(ip1_5a, ip50a); Assert.That(range1_5_5_0.Contains(ip50a), Is.True, "IP (ap false) in empty para at end of multi is included"); var range5_0_6_2 = new RangeSelection(ip50a, ip6_2p); Assert.That(range5_0_6_2.Contains(ip50a), Is.True, "IP (ap false) in empty para at start of multi is included"); var ip50p = run5.SelectAt(para5, 0, true); Assert.That(range1_5_5_0.Contains(ip50p), Is.True, "IP (ap true) in empty para at end of multi is included"); Assert.That(range5_0_6_2.Contains(ip50p), Is.True, "IP (ap true) in empty para at end of multi is included"); }
public void InsertGrowsPara() { string contents = "This is the day."; var engine = new FakeRenderEngine() { Ws = 34, SegmentHeight = 13 }; var factory = new FakeRendererFactory(); factory.SetRenderer(34, engine); var styles = new AssembledStyles().WithWs(34); var clientRuns = new List<IClientRun>(); var run = new StringClientRun(contents, styles); clientRuns.Add(run); var data1 = new MockData1(34, 35); data1.SimpleThree = contents; var source = new TextSource(clientRuns, null); var para = new ParaBox(styles, source); var hookup = new StringHookup(this, () => data1.SimpleThree, hook => data1.SimpleThreeChanged += hook.StringPropChanged, hook => data1.SimpleThreeChanged -= hook.StringPropChanged, para); hookup.Writer = newVal => data1.SimpleThree = newVal; run.Hookup = hookup; var extraBox = new BlockBox(styles, Color.Red, 50, 72000); var root = new RootBoxFdo(styles); root.SizeChanged += root_SizeChanged; root.AddBox(para); root.AddBox(extraBox); var layoutArgs = MakeLayoutInfo(Int32.MaxValue / 2, m_gm.VwGraphics, factory); root.Layout(layoutArgs); Assert.IsTrue(m_sizeChangedCalled); Assert.That(root.Height, Is.EqualTo(13 + 96)); Assert.That(root.Width, Is.EqualTo(FakeRenderEngine.SimulatedWidth(contents))); int widthThisIsThe = FakeRenderEngine.SimulatedWidth("This is the"); layoutArgs = MakeLayoutInfo(widthThisIsThe + 2, m_gm.VwGraphics, factory); root.Layout(layoutArgs); Assert.That(root.Height, Is.EqualTo(26 + 96), "two line para is twice the height"); Assert.That(root.Width, Is.EqualTo(widthThisIsThe + 2), "two-line para occupies full available width"); Assert.That(extraBox.Top, Is.EqualTo(26)); PaintTransform ptrans = new PaintTransform(2, 4, 96, 100, 0, 10, 120, 128); MockSite site = new MockSite(); site.m_transform = ptrans; site.m_vwGraphics = m_gm.VwGraphics; root.Site = site; m_sizeChangedCalled = false; var ip = para.SelectAtEnd(); ip.InsertText(" We will be"); Assert.That(para.Height, Is.EqualTo(39), "inserted text makes para a line higher"); Assert.That(root.Height, Is.EqualTo(39 + 96), "root grows when para does"); Assert.That(root.Width, Is.EqualTo(widthThisIsThe + 2), "three-line para occupies full available width"); Assert.That(extraBox.Top, Is.EqualTo(39)); Assert.IsTrue(m_sizeChangedCalled); }
public void InsertGrowsPara() { string contents = "This is the day."; var engine = new FakeRenderEngine() { Ws = 34, SegmentHeight = 13 }; var factory = new FakeRendererFactory(); factory.SetRenderer(34, engine); var styles = new AssembledStyles().WithWs(34); var clientRuns = new List <IClientRun>(); var run = new StringClientRun(contents, styles); clientRuns.Add(run); var data1 = new MockData1(34, 35); data1.SimpleThree = contents; var source = new TextSource(clientRuns, null); var para = new ParaBox(styles, source); var hookup = new StringHookup(this, () => data1.SimpleThree, hook => data1.SimpleThreeChanged += hook.StringPropChanged, hook => data1.SimpleThreeChanged -= hook.StringPropChanged, para); hookup.Writer = newVal => data1.SimpleThree = newVal; run.Hookup = hookup; var extraBox = new BlockBox(styles, Color.Red, 50, 72000); var root = new RootBoxFdo(styles); root.SizeChanged += root_SizeChanged; root.AddBox(para); root.AddBox(extraBox); var layoutArgs = MakeLayoutInfo(Int32.MaxValue / 2, m_gm.VwGraphics, factory); root.Layout(layoutArgs); Assert.IsTrue(m_sizeChangedCalled); Assert.That(root.Height, Is.EqualTo(13 + 96)); Assert.That(root.Width, Is.EqualTo(FakeRenderEngine.SimulatedWidth(contents))); int widthThisIsThe = FakeRenderEngine.SimulatedWidth("This is the"); layoutArgs = MakeLayoutInfo(widthThisIsThe + 2, m_gm.VwGraphics, factory); root.Layout(layoutArgs); Assert.That(root.Height, Is.EqualTo(26 + 96), "two line para is twice the height"); Assert.That(root.Width, Is.EqualTo(widthThisIsThe + 2), "two-line para occupies full available width"); Assert.That(extraBox.Top, Is.EqualTo(26)); PaintTransform ptrans = new PaintTransform(2, 4, 96, 100, 0, 10, 120, 128); MockSite site = new MockSite(); site.m_transform = ptrans; site.m_vwGraphics = m_gm.VwGraphics; root.Site = site; m_sizeChangedCalled = false; var ip = para.SelectAtEnd(); ip.InsertText(" We will be"); Assert.That(para.Height, Is.EqualTo(39), "inserted text makes para a line higher"); Assert.That(root.Height, Is.EqualTo(39 + 96), "root grows when para does"); Assert.That(root.Width, Is.EqualTo(widthThisIsThe + 2), "three-line para occupies full available width"); Assert.That(extraBox.Top, Is.EqualTo(39)); Assert.IsTrue(m_sizeChangedCalled); }