public void DiffRuns() { var styles = new AssembledStyles(); var root = new RootBoxFdo(styles); var mock1 = new MockData1(23, 23); mock1.SimpleThree = "new stuff"; var mock2 = new MockData1(23, 23); mock2.SimpleThree = "old contents"; var mock3 = new MockData1(23, 23); mock3.SimpleThree = "different things"; var engine = new FakeRenderEngine() { Ws = 23, SegmentHeight = 13 }; var factory = new FakeRendererFactory(); factory.SetRenderer(23, engine); root.Builder.Show(Paragraph.Containing(Display.Of(() => mock1.SimpleThree, 23), Display.Of(() => mock2.SimpleThree, 23), Display.Of(() => mock3.SimpleThree, 23))); var layoutArgs = MakeLayoutInfo(Int32.MaxValue / 2, m_gm.VwGraphics, factory); root.Layout(layoutArgs); 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; int x = FakeRenderEngine.SimulatedWidth("new stuf") + 2; var location = new Point(x, 8); EventArgs e = new EventArgs(); MouseEventArgs m = new MouseEventArgs(MouseButtons.Left, 1, location.X, location.Y, 0); root.OnMouseDown(m, Keys.None, site.m_vwGraphics, site.m_transform); root.OnMouseClick(m, Keys.None, site.m_vwGraphics, site.m_transform); root.OnDoubleClick(e); Assert.That(!root.Selection.IsInsertionPoint, "Should be ranged selection"); Assert.That((root.Selection as RangeSelection).SelectedText(), Is.EqualTo("stuff")); x = FakeRenderEngine.SimulatedWidth("new stuff") + 2; location = new Point(x, 8); m = new MouseEventArgs(MouseButtons.Left, 1, location.X, location.Y, 0); root.OnMouseDown(m, Keys.None, site.m_vwGraphics, site.m_transform); root.OnMouseClick(m, Keys.None, site.m_vwGraphics, site.m_transform); root.OnDoubleClick(e); Assert.That(!root.Selection.IsInsertionPoint, "Should be ranged selection"); Assert.That((root.Selection as RangeSelection).SelectedText(), Is.EqualTo("old ")); x = FakeRenderEngine.SimulatedWidth("new stuff old contents") + 2; location = new Point(x, 8); m = new MouseEventArgs(MouseButtons.Left, 1, location.X, location.Y, 0); root.OnMouseDown(m, Keys.None, site.m_vwGraphics, site.m_transform); root.OnMouseClick(m, Keys.None, site.m_vwGraphics, site.m_transform); root.OnDoubleClick(e); Assert.That(!root.Selection.IsInsertionPoint, "Should be ranged selection"); Assert.That((root.Selection as RangeSelection).SelectedText(), Is.EqualTo("different ")); }
public void Select() { var styles = new AssembledStyles(); var root = new RootBoxFdo(styles); var mock1 = new MockData1(23, 23); mock1.SimpleThree = "new old contents"; var engine = new FakeRenderEngine() { Ws = 23, SegmentHeight = 13 }; var factory = new FakeRendererFactory(); factory.SetRenderer(23, engine); root.Builder.Show(Display.Of(() => mock1.SimpleThree, 23)); var layoutArgs = MakeLayoutInfo(Int32.MaxValue / 2, m_gm.VwGraphics, factory); root.Layout(layoutArgs); 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; int x = FakeRenderEngine.SimulatedWidth("new ") + 2; var location = new Point(x, 8); EventArgs e = new EventArgs(); MouseEventArgs m = new MouseEventArgs(MouseButtons.Left, 1, location.X, location.Y, 0); root.OnMouseDown(m, Keys.None, site.m_vwGraphics, site.m_transform); root.OnDoubleClick(e); Assert.That(!root.Selection.IsInsertionPoint, "Should be ranged selection"); Assert.That((root.Selection as RangeSelection).SelectedText(), Is.EqualTo("old ")); mock1.SimpleThree = "new old:contents"; x = FakeRenderEngine.SimulatedWidth("new o") + 2; location = new Point(x, 8); m = new MouseEventArgs(MouseButtons.Left, 1, location.X, location.Y, 0); root.OnMouseDown(m, Keys.None, site.m_vwGraphics, site.m_transform); root.OnMouseClick(m, Keys.None, site.m_vwGraphics, site.m_transform); root.OnDoubleClick(e); Assert.That(!root.Selection.IsInsertionPoint, "Should be ranged selection"); Assert.That((root.Selection as RangeSelection).SelectedText(), Is.EqualTo("old")); mock1.SimpleThree = "new(old contents"; x = FakeRenderEngine.SimulatedWidth("new ol") + 2; location = new Point(x, 8); m = new MouseEventArgs(MouseButtons.Left, 1, location.X, location.Y, 0); root.OnMouseDown(m, Keys.None, site.m_vwGraphics, site.m_transform); root.OnMouseClick(m, Keys.None, site.m_vwGraphics, site.m_transform); root.OnDoubleClick(e); Assert.That(!root.Selection.IsInsertionPoint, "Should be ranged selection"); Assert.That((root.Selection as RangeSelection).SelectedText(), Is.EqualTo("old ")); mock1.SimpleThree = "newo1dcontents"; x = FakeRenderEngine.SimulatedWidth("new o1d") + 2; location = new Point(x, 8); m = new MouseEventArgs(MouseButtons.Left, 1, location.X, location.Y, 0); root.OnMouseDown(m, Keys.None, site.m_vwGraphics, site.m_transform); root.OnMouseClick(m, Keys.None, site.m_vwGraphics, site.m_transform); root.OnDoubleClick(e); Assert.That(!root.Selection.IsInsertionPoint, "Should be ranged selection"); Assert.That((root.Selection as RangeSelection).SelectedText(), Is.EqualTo("newo1dcontents")); }
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 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 BasicCopy() { var styles = new AssembledStyles(); var root = new RootBoxFdo(styles); var mock1 = new MockData1(23, 23); mock1.SimpleThree = "old contents"; var engine = new FakeRenderEngine() { Ws = 23, SegmentHeight = 13 }; var factory = new FakeRendererFactory(); factory.SetRenderer(23, engine); root.Builder.Show(Display.Of(() => mock1.SimpleThree, 23)); var layoutArgs = MakeLayoutInfo(Int32.MaxValue / 2, m_gm.VwGraphics, factory); root.Layout(layoutArgs); 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; int x = FakeRenderEngine.SimulatedWidth("old ") + 2; var location = new Point(x, 8); Clipboard.SetDataObject(""); Assert.That(root.CanCopy(), Is.EqualTo(false), "Should not be able to copy"); root.OnEditCopy(); Assert.That(mock1.SimpleThree, Is.EqualTo("old contents"), "Nothing should have changed"); Assert.That(Clipboard.GetDataObject().GetData(DataFormats.StringFormat), Is.EqualTo(""), "Nothing should have been copied"); MouseEventArgs e = new MouseEventArgs(MouseButtons.Left, 1, 2, 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"); 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(mock1.SimpleThree, Is.EqualTo("old contents"), "Selected String should be \"old contents\""); Assert.That(Clipboard.GetDataObject().GetData(DataFormats.StringFormat), Is.EqualTo("old "), "Selected String should be \"old \""); }
public void DiffWS() { var tsf = TsStrFactoryClass.Create(); var styles = new AssembledStyles(); var root = new RootBoxFdo(styles); var mock1 = new MockData1(23, 23); mock1.SimpleTwo = tsf.MakeString("newoldcontents", 23); var bldr = mock1.SimpleTwo.GetBldr(); bldr.SetIntPropValues(3, 6, (int)FwTextPropType.ktptWs, (int)FwTextPropVar.ktpvDefault, 24); bldr.SetIntPropValues(6, 14, (int)FwTextPropType.ktptWs, (int)FwTextPropVar.ktpvDefault, 25); mock1.SimpleTwo = bldr.GetString(); var engine = new FakeRenderEngine() { Ws = 23, SegmentHeight = 13 }; var factory = new FakeRendererFactory(); factory.SetRenderer(23, engine); root.Builder.Show(Display.Of(() => mock1.SimpleTwo)); var layoutArgs = MakeLayoutInfo(Int32.MaxValue / 2, m_gm.VwGraphics, factory); root.Layout(layoutArgs); 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; int x = FakeRenderEngine.SimulatedWidth("ne") + 2; var location = new Point(x, 8); EventArgs e = new EventArgs(); MouseEventArgs m = new MouseEventArgs(MouseButtons.Left, 1, location.X, location.Y, 0); root.OnMouseDown(m, Keys.None, site.m_vwGraphics, site.m_transform); root.OnMouseClick(m, Keys.None, site.m_vwGraphics, site.m_transform); root.OnDoubleClick(e); Assert.That(!root.Selection.IsInsertionPoint, "Should be ranged selection"); Assert.That((root.Selection as RangeSelection).SelectedText(), Is.EqualTo("new")); x = FakeRenderEngine.SimulatedWidth("new") + 2; location = new Point(x, 8); m = new MouseEventArgs(MouseButtons.Left, 1, location.X, location.Y, 0); root.OnMouseDown(m, Keys.None, site.m_vwGraphics, site.m_transform); root.OnMouseClick(m, Keys.None, site.m_vwGraphics, site.m_transform); root.OnDoubleClick(e); Assert.That(!root.Selection.IsInsertionPoint, "Should be ranged selection"); Assert.That((root.Selection as RangeSelection).SelectedText(), Is.EqualTo("old")); x = FakeRenderEngine.SimulatedWidth("newold") + 2; location = new Point(x, 8); m = new MouseEventArgs(MouseButtons.Left, 1, location.X, location.Y, 0); root.OnMouseDown(m, Keys.None, site.m_vwGraphics, site.m_transform); root.OnMouseClick(m, Keys.None, site.m_vwGraphics, site.m_transform); root.OnDoubleClick(e); Assert.That(!root.Selection.IsInsertionPoint, "Should be ranged selection"); Assert.That((root.Selection as RangeSelection).SelectedText(), Is.EqualTo("contents")); x = FakeRenderEngine.SimulatedWidth("newold"); location = new Point(x, 8); // at the right edge of the d at the end of newold m = new MouseEventArgs(MouseButtons.Left, 1, location.X, location.Y, 0); root.OnMouseDown(m, Keys.None, site.m_vwGraphics, site.m_transform); root.OnMouseClick(m, Keys.None, site.m_vwGraphics, site.m_transform); root.OnDoubleClick(e); Assert.That(!root.Selection.IsInsertionPoint, "Should be ranged selection"); Assert.That((root.Selection as RangeSelection).SelectedText(), Is.EqualTo("old")); }
public void DragCopyRtf() { var stylesheet = new MockStylesheet(); var styleFirst = stylesheet.AddStyle("first", false); var styleSecond = stylesheet.AddStyle("second", false); var propsTrue = new MockStyleProp<bool>() {Value = true, ValueIsSet = true}; var charInfo = new MockCharStyleInfo(); styleFirst.DefaultCharacterStyleInfo = charInfo; charInfo.Bold = propsTrue; // Todo: make styleSecond have pretty much everything else. var charInfo2 = new MockCharStyleInfo(); styleSecond.DefaultCharacterStyleInfo = charInfo2; charInfo2.FontColor = MakeColorProp(Color.Red); charInfo2.BackColor = MakeColorProp(Color.Yellow); charInfo2.UnderlineColor = MakeColorProp(Color.Green); charInfo2.Italic = propsTrue; charInfo2.FontName = new MockStyleProp<string>() {Value = "Arial", ValueIsSet = true}; var styles = new AssembledStyles(stylesheet); var root = new RootBoxFdo(styles); var mock1 = new MockData1(23, 23); mock1.SimpleThree = "This is"; var mock2 = new MockData1(23, 23); mock2.SimpleThree = " the day"; var mock3 = new MockData1(23, 23); mock3.SimpleThree = " that the"; var engine = new FakeRenderEngine() { Ws = 23, SegmentHeight = 13 }; var factory = new FakeRendererFactory(); var wsf = new MockWsf(); engine.WritingSystemFactory = wsf; var wsEngine = wsf.MakeMockEngine(23, "en", engine); factory.SetRenderer(23, engine); root.Builder.Show( Paragraph.Containing( Display.Of(() => mock1.SimpleThree, 23).Style("first"), Display.Of(() => mock2.SimpleThree, 23).Style("second"), Display.Of(() => mock3.SimpleThree, 23).Style("first") )); var layoutArgs = MakeLayoutInfo(Int32.MaxValue / 2, m_gm.VwGraphics, factory); root.Layout(layoutArgs); 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; SelectionBuilder.In(root).Offset("This ".Length).To.Offset("This is the day that".Length).Install(); int indent = FakeRenderEngine.SimulatedWidth("This "); root.OnMouseDown(new MouseEventArgs(MouseButtons.Left, 1, indent + 5, 4, 0), Keys.None, m_gm.VwGraphics, ptrans); root.OnMouseMove(new MouseEventArgs(MouseButtons.Left, 1, indent + 5, 4, 0), Keys.None, m_gm.VwGraphics, ptrans); Assert.That(GetStringDropData(site), Is.EqualTo("is the day that")); // The order of the font and colors in the color table is arbitrary. This happens to be what the code does now. For some reason // Color.Green has green only 128. // The order of items in the definition of a style is arbitrary. // We're not doing anything yet for background color. \highlightN can specify background color for a character run, // but it can't be part of a style definition. Assert.That(GetRtfDropData(site), Is.EqualTo( RangeSelection.RtfPrefix + @"{\fonttbl{\f0 MockFont;}{\f1 Arial;}}" + @"{\colortbl ;\red0\green0\blue0;\red255\green255\blue255;\red255\green0\blue0;\red255\green255\blue0;\red0\green128\blue0;}" + @"{\stylesheet{\*\cs1\b\additive first;\*\cs2\i\f1\cf3\ulc5\additive second;}}" + RangeSelection.RtfDataPrefix + @"{\*\cs1\b is}{\*\cs2\i\f1\cf3\ulc5\highlight4 the day}{\*\cs1\b that\par}" + @"}")); // Todo: handle styles that depend on WS // Todo: handle more than two runs // Todo: handle runs where actual formatting differs from style-specified formatting // Todo: handle multiple paragraphs // Todo: handle paragraph styles }
public void DragCopyRtf() { var stylesheet = new MockStylesheet(); var styleFirst = stylesheet.AddStyle("first", false); var styleSecond = stylesheet.AddStyle("second", false); var propsTrue = new MockStyleProp <bool>() { Value = true, ValueIsSet = true }; var charInfo = new MockCharStyleInfo(); styleFirst.DefaultCharacterStyleInfo = charInfo; charInfo.Bold = propsTrue; // Todo: make styleSecond have pretty much everything else. var charInfo2 = new MockCharStyleInfo(); styleSecond.DefaultCharacterStyleInfo = charInfo2; charInfo2.FontColor = MakeColorProp(Color.Red); charInfo2.BackColor = MakeColorProp(Color.Yellow); charInfo2.UnderlineColor = MakeColorProp(Color.Green); charInfo2.Italic = propsTrue; charInfo2.FontName = new MockStyleProp <string>() { Value = "Arial", ValueIsSet = true }; var styles = new AssembledStyles(stylesheet); var root = new RootBoxFdo(styles); var mock1 = new MockData1(23, 23); mock1.SimpleThree = "This is"; var mock2 = new MockData1(23, 23); mock2.SimpleThree = " the day"; var mock3 = new MockData1(23, 23); mock3.SimpleThree = " that the"; var engine = new FakeRenderEngine() { Ws = 23, SegmentHeight = 13 }; var factory = new FakeRendererFactory(); var wsf = new MockWsf(); engine.WritingSystemFactory = wsf; var wsEngine = wsf.MakeMockEngine(23, "en", engine); factory.SetRenderer(23, engine); root.Builder.Show( Paragraph.Containing( Display.Of(() => mock1.SimpleThree, 23).Style("first"), Display.Of(() => mock2.SimpleThree, 23).Style("second"), Display.Of(() => mock3.SimpleThree, 23).Style("first") )); var layoutArgs = MakeLayoutInfo(Int32.MaxValue / 2, m_gm.VwGraphics, factory); root.Layout(layoutArgs); 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; SelectionBuilder.In(root).Offset("This ".Length).To.Offset("This is the day that".Length).Install(); int indent = FakeRenderEngine.SimulatedWidth("This "); root.OnMouseDown(new MouseEventArgs(MouseButtons.Left, 1, indent + 5, 4, 0), Keys.None, m_gm.VwGraphics, ptrans); root.OnMouseMove(new MouseEventArgs(MouseButtons.Left, 1, indent + 5, 4, 0), Keys.None, m_gm.VwGraphics, ptrans); Assert.That(GetStringDropData(site), Is.EqualTo("is the day that")); // The order of the font and colors in the color table is arbitrary. This happens to be what the code does now. For some reason // Color.Green has green only 128. // The order of items in the definition of a style is arbitrary. // We're not doing anything yet for background color. \highlightN can specify background color for a character run, // but it can't be part of a style definition. Assert.That(GetRtfDropData(site), Is.EqualTo( RangeSelection.RtfPrefix + @"{\fonttbl{\f0 MockFont;}{\f1 Arial;}}" + @"{\colortbl ;\red0\green0\blue0;\red255\green255\blue255;\red255\green0\blue0;\red255\green255\blue0;\red0\green128\blue0;}" + @"{\stylesheet{\*\cs1\b\additive first;\*\cs2\i\f1\cf3\ulc5\additive second;}}" + RangeSelection.RtfDataPrefix + @"{\*\cs1\b is}{\*\cs2\i\f1\cf3\ulc5\highlight4 the day}{\*\cs1\b that\par}" + @"}")); // Todo: handle styles that depend on WS // Todo: handle more than two runs // Todo: handle runs where actual formatting differs from style-specified formatting // Todo: handle multiple paragraphs // Todo: handle paragraph styles }
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 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)); }