Exemplo n.º 1
0
		public void PaintParaBox()
		{
			AssembledStyles styles = new AssembledStyles();
			var clientRuns = new List<IClientRun>();
			BlockBox box0 = new BlockBox(styles, Color.Red, 72000, 36000);
			clientRuns.Add(box0);
			BlockBox box1 = new BlockBox(styles, Color.Blue, 36000, 18000);
			clientRuns.Add(box1);
			BlockBox box2 = new BlockBox(styles, Color.Red, 24000, 18000);
			clientRuns.Add(box2);
			BlockBox box3 = new BlockBox(styles, Color.Red, 72000, 36000);
			clientRuns.Add(box3);
			BlockBox box4 = new BlockBox(styles, Color.Red, 36000, 36000);
			clientRuns.Add(box4);

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

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

			PaintTransform ptrans = new PaintTransform(2, 2, 96, 96, 0, 0, 96, 96);
			root.Paint(graphics, ptrans);
			Assert.AreEqual(5, graphics.RectanglesDrawn.Count);
			VerifyRect(2, 2, 96, 48, graphics, 0, Color.Red);
			VerifyRect(2, 48+2, 48, 24, graphics, 1, Color.Blue);
			VerifyRect(2+48, 48 + 2, 32, 24, graphics, 2, Color.Red);
			VerifyRect(2, 24 + 48 + 2, 96, 48, graphics, 3, Color.Red);
			VerifyRect(2, 48 + 24 + 48 + 2, 48, 48, graphics, 4, Color.Red);
		}
Exemplo n.º 2
0
		public void SimpleString()
		{
			ParaBox para;
			RootBox root = ParaBuilderTests.MakeTestParaSimpleString(m_gm.VwGraphics, ParaBuilderTests.MockBreakOption.ThreeFullLines, out para);
			PaintTransform ptrans = new PaintTransform(2, 4, 96, 100, 0, -10, 120, 128);
			root.Paint(m_gm.VwGraphics, ptrans);

			ParaBox pb = root.FirstBox as ParaBox;
			Assert.IsNotNull(pb);
			StringBox first = pb.FirstBox as StringBox;
			Assert.IsNotNull(first);
			MockSegment seg1 = first.Segment as MockSegment;
			Assert.IsNotNull(seg1);
			Assert.AreEqual(m_gm.VwGraphics, seg1.LastDrawTextCall.vg);
			Assert.AreEqual(0, seg1.LastDrawTextCall.ichBase);
			VerifySimpleRect(seg1.LastDrawTextCall.rcSrc, -2, -4, 96, 100);
			VerifySimpleRect(seg1.LastDrawTextCall.rcDst, 0, 10, 120, 128);

			StringBox second = first.Next as StringBox;
			Assert.IsNotNull(second);
			MockSegment seg2 = second.Segment as MockSegment;
			Assert.IsNotNull(seg2);
			VerifySimpleRect(seg2.LastDrawTextCall.rcSrc, -2, -14, 96, 100);
			VerifySimpleRect(seg2.LastDrawTextCall.rcDst, 0, 10, 120, 128);

			StringBox third = second.Next as StringBox;
			Assert.IsNotNull(third);
			MockSegment seg3 = third.Segment as MockSegment;
			Assert.IsNotNull(seg3);
			VerifySimpleRect(seg3.LastDrawTextCall.rcSrc, -2, -24, 96, 100);
			VerifySimpleRect(seg3.LastDrawTextCall.rcDst, 0, 10, 120, 128);

			Assert.AreEqual(root, third.Root);
		}
Exemplo n.º 3
0
		public void MakeSimpleRange()
		{
			ParaBox para;
			RootBox root = ParaBuilderTests.MakeTestParaSimpleString(m_gm.VwGraphics, ParaBuilderTests.MockBreakOption.ThreeFullLines, out para);
			InsertionPoint ip = root.SelectAtEnd();
			InsertionPoint ip2 = new InsertionPoint(ip.Hookup, ip.StringPosition - 2, false);
			RangeSelection range = new RangeSelection(ip, ip2);
			Assert.AreEqual(ip, range.Anchor);
			Assert.AreEqual(ip2, range.DragEnd);
			Assert.That(range.EndBeforeAnchor, Is.True);
			Assert.That(range.Start, Is.EqualTo(ip2));
			Assert.That(range.End, Is.EqualTo(ip));
			StringBox first = para.FirstBox as StringBox;
			StringBox second = para.FirstBox.Next as StringBox;
			StringBox third = second.Next as StringBox;
			MockSegment seg3 = third.Segment as MockSegment;
			seg3.DrawRangeLeft = 17;
			seg3.DrawRangeRight = 23;

			PaintTransform ptrans = new PaintTransform(2, 4, 96, 100, 0, 10, 120, 128);
			range.Draw(m_gm.VwGraphics, ptrans);

			// All three segments should be invited to draw it, though only one will.
			// The top of rsSrc gets more negative each line; the destination rectangle where we actually draw keeps getting lower.
			// Remember the effect of 10 pixels of scroll offset.
			VerifyRangeSegmentDrawing(para, first, first.Segment as MockSegment, range, -4, -6, 4);
			VerifyRangeSegmentDrawing(para, second, second.Segment as MockSegment, range, -14, 4, 14);
			VerifyRangeSegmentDrawing(para, third, seg3, range , -24, 14, 24);
		}
Exemplo n.º 4
0
		private void SetupFakeRootSite(RootBox root)
		{
			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;
		}
Exemplo n.º 5
0
		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"));
		}
Exemplo n.º 6
0
		public override void PaintForeground(IVwGraphics vg, PaintTransform ptrans)
		{
			if (Segment == null)
				return;
			int dxdWidth;
			PaintTransform segTrans = ptrans.PaintTransformOffsetBy(Left, Top);

			if (AnyColoredBackground)
				Segment.DrawTextNoBackground(IchMin, vg, segTrans.SourceRect, segTrans.DestRect, out dxdWidth);
			else
				Segment.DrawText(IchMin, vg, segTrans.SourceRect, segTrans.DestRect, out dxdWidth); // more efficient.
		}
Exemplo n.º 7
0
		public void DrawIP()
		{
			ParaBox para;
			RootBox root = ParaBuilderTests.MakeTestParaSimpleString(m_gm.VwGraphics, ParaBuilderTests.MockBreakOption.ThreeFullLines, out para);
			InsertionPoint ip = root.SelectAtEnd();
			ip.Install();
			Assert.AreEqual(ip, root.Selection);
			Assert.AreEqual(para, ip.Para, "IP should know about the paragraph it is in");
			Assert.AreEqual(para.Source.Length, ip.StringPosition, "the IP should be at the end of the paragraph");
			Assert.AreEqual(true, ip.AssociatePrevious, "selection at end should always associate previous in non-empty para");


			StringBox third = para.FirstBox.Next.Next as StringBox;
			Assert.IsNotNull(third, "para with three simple lines should have three string boxes");
			MockSegment seg3 = third.Segment as MockSegment;
			Assert.IsNotNull(seg3);
			PaintTransform ptrans = new PaintTransform(2, 4, 96, 100, 0, -10, 120, 128);
			ip.Draw(m_gm.VwGraphics, ptrans);
			StringBox first = para.FirstBox as StringBox;
			StringBox second = para.FirstBox.Next as StringBox;
			// All three segments should be invited to draw it, though only one will.
			var seg1 = first.Segment as MockSegment;
			VerifySegmentDrawing(para, first, seg1, -4);
			var seg2 = second.Segment as MockSegment;
			VerifySegmentDrawing(para, second, seg2, -14);
			VerifySegmentDrawing(para, third, seg3, - 24);

			seg1.NextPosIpResult = new MockSegment.PositionsOfIpResults();
			seg1.NextPosIpResult.PrimaryHere = false;
			seg2.NextPosIpResult = new MockSegment.PositionsOfIpResults();
			seg2.NextPosIpResult.PrimaryHere = false;
			seg3.NextPosIpResult = new MockSegment.PositionsOfIpResults();
			seg3.NextPosIpResult.RectPrimary = new Rect(5,6,7,9);
			seg3.NextPosIpResult.PrimaryHere = true;
			Rectangle selRect = ip.GetSelectionLocation(m_gm.VwGraphics, ptrans);
			// All three should be asked for the position, though only the third returns a useful one.
			VerifySelLocation(para, first, seg1, -4);
			VerifySelLocation(para, second, seg2, -14);
			VerifySelLocation(para, third, seg3, -24);
			Assert.AreEqual(new Rectangle(5, 6, 2, 3), selRect);

			// The final thing that goes into drawing IPs is the Invalidate call.
			MockSite site = new MockSite();
			site.m_transform = ptrans;
			site.m_vwGraphics = m_gm.VwGraphics;
			root.Site = site;
			ip.Invalidate();
			Assert.IsNotNull(site.GraphicsHolder, "Invalidate should have created a Graphics holder");
			Assert.IsTrue(site.GraphicsHolder.WasDisposed, "invalidate should have disposed of the Graphics Holder");
			Assert.AreEqual(1, site.RectsInvalidated.Count, "invalidate should have invalidated one rectangle");
			Assert.AreEqual(new Rectangle(5, 6, 2, 3), site.RectsInvalidated[0], "invalidate should have invalidated the selection rectangle");
		}
Exemplo n.º 8
0
		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));
		}
Exemplo n.º 9
0
		public void PaintBarBox()
		{
			AssembledStyles styles = new AssembledStyles();
			BlockBox box = new BlockBox(styles, Color.Red, 72000, 36000);

			RootBox root = new RootBox(styles);
			root.AddBox(box);
			LayoutInfo transform = MakeLayoutInfo();
			root.Layout(transform);

			PaintTransform ptrans = new PaintTransform(2, 2, 96, 96, 0, 0, 96, 96);
			MockGraphics graphics = new MockGraphics();
			root.Paint(graphics, ptrans);
			Assert.AreEqual(1, graphics.RectanglesDrawn.Count);
			Assert.AreEqual(new Rectangle(2, 2, 96, 48), graphics.RectanglesDrawn[0]);
			Assert.AreEqual((int)ColorUtil.ConvertColorToBGR(Color.Red), graphics.BackColor);
		}
Exemplo n.º 10
0
		public void PaintPictureBox()
		{
			AssembledStyles styles = new AssembledStyles();
			Bitmap bm = new Bitmap(20, 30);
			ImageBox box = new ImageBox(styles.WithMargins(new Thickness(72.0 / 96.0 * 2.0))
				.WithBorders(new Thickness(72.0 / 96.0 * 3.0))
				.WithPads(new Thickness(72.0 / 96.0 * 7.0, 72.0 / 96.0 * 8.0, 72.0 / 96.0 * 11.0, 72.0 / 96.0 * 13.0)), bm);

			RootBox root = new RootBox(styles);
			BlockBox block = new BlockBox(styles, Color.Yellow, 2000, 4000);
			root.AddBox(block);
			root.AddBox(box);
			LayoutInfo transform = MakeLayoutInfo();
			root.Layout(transform);
			Assert.That(box.Height, Is.EqualTo(30 + 2*2+3*2+8+13));
			Assert.That(box.Width, Is.EqualTo(20 + 2*2 +3*2 + 7 + 11));
			Assert.That(box.Ascent, Is.EqualTo(box.Height));

			PaintTransform ptrans = new PaintTransform(2, 4, 96, 96, 10, 40, 96, 96);
			MockGraphics graphics = new MockGraphics();
			root.Paint(graphics, ptrans);
			Assert.That(graphics.LastRenderPictureArgs, Is.Not.Null);
			Assert.That(graphics.LastRenderPictureArgs.Picture, Is.EqualTo(box.Picture));
			Assert.That(graphics.LastRenderPictureArgs.X, Is.EqualTo(2-10 + 2 + 3 + 7));
			Assert.That(graphics.LastRenderPictureArgs.Y, Is.EqualTo(4 - 40 + block.Height + 2 + 3 + 8));
			Assert.That(graphics.LastRenderPictureArgs.Cx, Is.EqualTo(20));
			Assert.That(graphics.LastRenderPictureArgs.Cy, Is.EqualTo(30));
			int hmWidth = box.Picture.Width;
			int hmHeight = box.Picture.Height;
			Assert.That(graphics.LastRenderPictureArgs.XSrc, Is.EqualTo(0));
			Assert.That(graphics.LastRenderPictureArgs.YSrc, Is.EqualTo(hmHeight));
			Assert.That(graphics.LastRenderPictureArgs.CxSrc, Is.EqualTo(hmWidth));
			Assert.That(graphics.LastRenderPictureArgs.CySrc, Is.EqualTo(-hmHeight));
			Assert.That(graphics.LastRenderPictureArgs.RcWBounds.left, Is.EqualTo(2 - 10 + 2 + 3 + 7));
			Assert.That(graphics.LastRenderPictureArgs.RcWBounds.top, Is.EqualTo(4 - 40 + block.Height + 2 + 3 + 8));
			Assert.That(graphics.LastRenderPictureArgs.RcWBounds.right, Is.EqualTo(2 - 10 + 2 + 3 + 7 + 20));
			Assert.That(graphics.LastRenderPictureArgs.RcWBounds.bottom, Is.EqualTo(4 - 40 + block.Height + 2 + 3 + 8 + 30));
		}
Exemplo n.º 11
0
		public void TestClick()
		{
			ParaBox para;
			RootBox root = ParaBuilderTests.MakeTestParaSimpleString(m_gm.VwGraphics, ParaBuilderTests.MockBreakOption.ThreeFullLines, out para);
			PaintTransform ptrans = new PaintTransform(2, 4, 96, 100, 0, 0, 120, 128);
			var seg = FirstMockSegment(root);
			seg.OnPointToCharReturn(4, false);
			var sel = root.GetSelectionAt(new Point(5, 10), m_gm.VwGraphics, ptrans);
			Assert.That(sel.IsInsertionPoint);
			Assert.That(((InsertionPoint)sel).StringPosition, Is.EqualTo(4));
			Assert.That(((InsertionPoint)sel).AssociatePrevious, Is.False);
			Assert.That(seg.PointToCharVg, Is.EqualTo(m_gm.VwGraphics));
			Assert.That(seg.PointToCharIchBase, Is.EqualTo(0));
			// not much of a test, but we don't have any way to offset paras yet
			Assert.That(seg.PointToCharRcDst, Is.EqualTo(ptrans.DestRect));
			Assert.That(seg.PointToCharRcSrc, Is.EqualTo(ptrans.SourceRect));
			// Should be offset by the Paint transform origin.
			Assert.That(seg.PointToCharClickPosition, Is.EqualTo(new Point(5, 10)));

			seg = SecondMockSegment(root);
			seg.OnPointToCharReturn(14, true);
			sel = root.GetSelectionAt(new Point(7, 20), m_gm.VwGraphics, ptrans);
			Assert.That(sel.IsInsertionPoint);
			Assert.That(((InsertionPoint)sel).StringPosition, Is.EqualTo(14));
			Assert.That(((InsertionPoint)sel).AssociatePrevious, Is.True);
			Assert.That(seg.PointToCharVg, Is.EqualTo(m_gm.VwGraphics));
			Assert.That(seg.PointToCharIchBase, Is.EqualTo(IchMinOfSecondStringBox(root)));
			// Should be offset by the Paint transform origin and the origin of the second box.
			var topLeft = TopLeftOfSecondStringBox(root);
			Assert.That(seg.PointToCharClickPosition, Is.EqualTo(new Point(7, 20)));
		}
Exemplo n.º 12
0
		public override void PaintBackground(IVwGraphics vg, PaintTransform ptrans)
		{
			// Review JohnT: do we want to allow individual strings to paint borders etc? Should we call base?
			// base.PaintBackground(vg, ptrans);
			if (Segment == null)
				return;

			int dxdWidth;
			PaintTransform segTrans = ptrans.PaintTransformOffsetBy(Left, Top);
			// Ideally, we'd just draw the background, but we don't have that capability currently.
			// The current implementation of DrawTextNoBackground does a good job of redrawing
			// the foreground text, even if it's already been painted.
			if (AnyColoredBackground)
				Segment.DrawText(IchMin, vg, segTrans.SourceRect, segTrans.DestRect, out dxdWidth);
			int dichLim = Segment.get_Lim(IchMin);
			int ichLim = IchMin + dichLim;
			int ichMinRun = IchMin;
			int ichLimRun;
			int dydOffset = Math.Max(1, segTrans.DpiY/96); // distance between double underline, also up and down for squiggle.
			for (; ichMinRun < ichLim; ichMinRun = ichLimRun)
			{
				int clrUnder;
				var unt = Paragraph.Source.GetUnderlineInfo(ichMinRun, out clrUnder, out ichLimRun);
				ichLimRun = Math.Min(ichLimRun, ichLim);
				Debug.Assert(ichLimRun > ichMinRun);
				if (unt == FwUnderlineType.kuntNone)
					continue;
				// Get info about where to draw underlines for this run
				//int ydApproxUnderline = rcSrcChild.MapYTo(psbox->Ascent(), rcDst);
				//// GetCharPlacement seems to be the really expensive part of underlining; don't do it
				//// if the underline is nowhere near the clip rectangle. Times 2 and times 3 are both one more multiple
				//// than typically needed.
				//if (ydApproxUnderline - dydOffset * 2 < ydTopClip - 1 || ydApproxUnderline + dydOffset * 3 > ydBottomClip + 1)
				//    continue;
				int[] lefts, rights, tops;
				int cxd;
				Segment.GetCharPlacement(IchMin, vg, ichMinRun,
					ichLimRun, segTrans.SourceRect, segTrans.DestRect, true, 0, out cxd,
					null, null, null);
				using (var rgxdLefts = MarshalEx.ArrayToNative<int>(cxd))
				using (var rgxdRights = MarshalEx.ArrayToNative<int>(cxd))
				using (var rgydTops = MarshalEx.ArrayToNative<int>(cxd))
				{
					Segment.GetCharPlacement(IchMin, vg, ichMinRun,
						ichLimRun, segTrans.SourceRect, segTrans.DestRect, true, cxd, out cxd,
						rgxdLefts, rgxdRights, rgydTops);
					lefts = MarshalEx.NativeToArray<int>(rgxdLefts, cxd);
					rights = MarshalEx.NativeToArray<int>(rgxdRights, cxd);
					tops = MarshalEx.NativeToArray<int>(rgydTops, cxd);
				}
				for (int ixd = 0; ixd < cxd; ixd++)
				{
					// top of underline 1 pixel below baseline
					int ydDrawAt = tops[ixd];
					// underline is drawn at most one offset above ydDrawAt and at most 2 offsets below.
					// Skip the work if it is clipped.
					//if (ydDrawAt - dydOffset < ydBottomClip + 1 && ydDrawAt + dydOffset * 2 > ydTopClip - 1)
					//{
					//int xLeft = max(rgxdLefts[ixd], xdLeftClip - 1);
					//int xRight = min(rgxdRights[ixd], xdRightClip + 1);
					int xLeft = lefts[ixd];
					int xRight = rights[ixd];
					DrawUnderline(vg, xLeft, xRight, ydDrawAt,
						segTrans.DpiX/96, dydOffset,
						clrUnder, unt, segTrans.XOffsetScroll);
					//}
				}
			}
		}
Exemplo n.º 13
0
 public override void PaintForeground(IVwGraphics vg, PaintTransform ptrans)
 {
     ((MockGraphics)vg).DrawActions.Add(this);
 }
Exemplo n.º 14
0
		internal void DrawIp(InsertionPoint ip, IVwGraphics vg, PaintTransform ptrans)
		{
			PaintTransform segTrans = ptrans.PaintTransformOffsetBy(Left, Top);
			Segment.DrawInsertionPoint(IchMin, vg, segTrans.SourceRect, segTrans.DestRect,
				ip.RenderParaPosition, ip.AssociatePrevious, true, LgIPDrawMode.kdmNormal);

		}
Exemplo n.º 15
0
		/// <summary>
		///  Get the IP location, if in this segment; if not return a dummy rectangle and 'here' will be false.
		/// </summary>
		public Rectangle GetIpLocation(InsertionPoint ip, IVwGraphics vg, PaintTransform ptrans, out bool here)
		{
			PaintTransform segTrans = ptrans.PaintTransformOffsetBy(Left, Top);
			Rect rectPrimary, rectSec;
			bool fPrimaryHere, fSecHere;
			Segment.PositionsOfIP(IchMin, vg, segTrans.SourceRect, segTrans.DestRect,
								  ip.RenderParaPosition, ip.AssociatePrevious, LgIPDrawMode.kdmNormal, out rectPrimary,
								  out rectSec,
								  out fPrimaryHere, out fSecHere);
			if (fPrimaryHere)
			{
				here = true;
				return new Rectangle(rectPrimary.left, rectPrimary.top, rectPrimary.right - rectPrimary.left,
									 rectPrimary.bottom - rectPrimary.top);
			}
			here = false;
			return new Rectangle();
		}
Exemplo n.º 16
0
		public void ParaSequenceTest()
		{
			var owner = new MockData1(55, 77);
			var styles = new AssembledStyles();
			var root = new RootBoxFdo(styles);
			var layoutInfo = MakeLayoutInfo(int.MaxValue/2, m_gm.VwGraphics, 55);
			SetupFakeRootSite(root);
			var engine = layoutInfo.RendererFactory.GetRenderer(55, m_gm.VwGraphics) as FakeRenderEngine;
			MockSite site = new MockSite();
			int topLazy = 0; // top of the part of the root box that is occupied by the lazy stuff, relative to the top of the root box itself.
			root.Site = site;
			PaintTransform ptrans = new PaintTransform(2, 4, 96, 96, 0, 10, 96, 96);
			site.m_transform = ptrans;
			site.m_vwGraphics = m_gm.VwGraphics;
			root.Builder.Show(LazyDisplay.Of(() => owner.ObjSeq1).Using((bldr, md) => bldr.AddString(() => md.SimpleThree, 55)));
			var heightOfOneItem = layoutInfo.MpToPixelsY(LazyBox<MockData1>.DefaultItemHeight * 1000);
			// This does two things: it makes sure the boxes produced by expanding a lazy box item won't be the SAME size,
			// so we'll get nontrivial changes in root box size; and it makes sure we don't have to expand MORE items than
			// expected based on the height estimate, which could throw off our predictions of what gets expanded.
			// Todo: we need a test where we DO have to expand more items after the initial estimate.
			engine.SegmentHeight = heightOfOneItem + 2;
			root.Layout(layoutInfo);
			VerifyParagraphs(root, new string[0]);

			var child1 = new MockData1(55, 77);
			var child1String = "Hello world, this is a wide string";
			child1.SimpleThree = child1String;
			owner.InsertIntoObjSeq1(0, child1);
			Assert.That(root.FirstBox, Is.TypeOf(typeof(LazyBox<MockData1>)));
			var lazyBox = (LazyBox<MockData1>)root.FirstBox;
			Assert.That(lazyBox.Width, Is.EqualTo(int.MaxValue / 2)); // no margins, should equal avail width.
			Assert.That(lazyBox.Height, Is.EqualTo(heightOfOneItem));
			var lazyTop = lazyBox.Top;
			var lazyBottom = lazyBox.Bottom;
			var oldRootHeight = root.Height;
			int invalidateWidth = lazyBox.Width + 2 * RootBox.InvalidateMargin;
			var expectedInvalidate1 = new Rectangle(-RootBox.InvalidateMargin, -RootBox.InvalidateMargin,
				invalidateWidth,
				lazyBox.Height + 2 * RootBox.InvalidateMargin);
			Assert.That(site.RectsInvalidatedInRoot, Has.Member(expectedInvalidate1));
			site.RectsInvalidatedInRoot.Clear();
			var lazyHookup = ((IHookup) lazyBox).ParentHookup as LazyHookup<MockData1>;
			Assert.That(lazyHookup, Is.Not.Null);
			Assert.That(lazyHookup.Children[0], Is.EqualTo(lazyBox));
			Assert.That(lazyHookup.Children, Has.Count.EqualTo(1));
			root.LazyExpanded += root_LazyExpanded;
			using (var lc = new LayoutCallbacks(root))
			{
				root.PrepareToPaint(layoutInfo, null, 0, 200);
			}
			VerifyParagraphs(root, new [] { child1String });
			Assert.That(child1.SimpleThreeHookupCount, Is.EqualTo(1), "expanding lazy box should set up a hookup for the string");
			Assert.That(site.RectsInvalidatedInRoot, Is.Empty, "we don't need to invalidate expanding something that's never been painted");
			VerifyExpandArgs(0, lazyTop + 2, lazyBottom + 2, root.Height - oldRootHeight);
			Assert.That(lazyHookup.Children, Has.Count.EqualTo(1));
			Assert.That(lazyHookup.Children[0], Is.TypeOf(typeof(ItemHookup)), "the lazy box standing for item hookups should have been replaced");

			// Now replace that one object with a list of several. I want to be able to expand two at the start, one at the end,
			// and one in the middle, and leave two lazy boxes behind. Then expand the rest and make them go away. So I need six.
			var values = new MockData1[10];
			for (int i = 0; i < 10; i++)
			{
				values[i] = new MockData1(55, 77);
				values[i].SimpleThree = i.ToString();
			}
			var newValues = values.Take(6).ToArray();
			site.RectsInvalidatedInRoot.Clear();
			int phase2RootHeight = root.Height;
			int phase2RootWidth = root.Width;
			owner.ReplaceObjSeq1(newValues);
			var expectedInvalidate2 = new Rectangle(-RootBox.InvalidateMargin, -RootBox.InvalidateMargin,
				phase2RootWidth + 2 * RootBox.InvalidateMargin,
				phase2RootHeight + 2 * RootBox.InvalidateMargin);
			Assert.That(site.RectsInvalidatedInRoot, Has.Member(expectedInvalidate2), "should invalidate the old replaced paragraph.");
			lazyBox = (LazyBox<MockData1>)root.FirstBox;
			Assert.That(lazyBox.Width, Is.EqualTo(int.MaxValue / 2)); // no margins, should equal avail width.
			Assert.That(root.LastBox, Is.EqualTo(lazyBox), "old paragraph should have been replaced");
			Assert.That(lazyHookup.Children[0], Is.EqualTo(lazyBox), "after second replace we just have the lazy box");
			Assert.That(lazyHookup.Children, Has.Count.EqualTo(1), "should not have anything but lazy box after second replace");
			Assert.That(lazyBox.Height, Is.EqualTo(6*heightOfOneItem));

			// Make it expand the first two items.
			site.RectsInvalidatedInRoot.Clear();
			m_expandArgs.Clear();
			oldRootHeight = root.Height;
			using (var lc = new LayoutCallbacks(root))
			{
				root.PrepareToPaint(layoutInfo, null, 0, heightOfOneItem * 2 - 2);
			}
			VerifyParagraphs(root, new[] { "0", "1", null }); // Should have two paras then lazy box
			Assert.That(newValues[0].SimpleThreeHookupCount, Is.EqualTo(1), "expanding lazy box should set up a hookup for the string");
			Assert.That(newValues[1].SimpleThreeHookupCount, Is.EqualTo(1), "expanding lazy box should set up a hookup for the string");
			Assert.That(site.RectsInvalidatedInRoot, Is.Empty, "we don't need to invalidate expanding something that's never been painted");
			Assert.That(root.Height, Is.Not.EqualTo(oldRootHeight));
			VerifyExpandArgs(0, 2, heightOfOneItem * 2 + 2, root.Height - oldRootHeight); // +2's from root layout offset
			Assert.That(lazyHookup.Children, Has.Count.EqualTo(3));
			Assert.That(lazyHookup.Children[0], Is.TypeOf(typeof(ItemHookup)), "a regular item hookup for the first expanded item should be inserted");
			Assert.That(lazyHookup.Children[1], Is.TypeOf(typeof(ItemHookup)), "a regular item hookup for the 2nd expanded item should be inserted");
			Assert.That(lazyHookup.Children[2], Is.TypeOf(typeof(LazyBox<MockData1>)), "the lazy box standing for item hookups should still be there");
			lazyBox = root.FirstBox.Next.Next as LazyBox<MockData1>;
			Assert.That(lazyBox, Is.Not.Null);
			Assert.That(lazyBox.Height, Is.EqualTo(heightOfOneItem * 4));

			int topOfLastItem = lazyBox.Bottom - heightOfOneItem + 2;
			// Make it expand the last item.
			site.RectsInvalidatedInRoot.Clear();
			m_expandArgs.Clear();
			oldRootHeight = root.Height;
			using (var lc = new LayoutCallbacks(root))
			{
				root.PrepareToPaint(layoutInfo, null, topOfLastItem + 2, topOfLastItem + 10);
			}
			VerifyParagraphs(root, new[] { "0", "1", null, "5" }); // Should have two paras then lazy box then last para
			Assert.That(newValues[5].SimpleThreeHookupCount, Is.EqualTo(1), "expanding lazy box should set up a hookup for the string");
			Assert.That(site.RectsInvalidatedInRoot, Is.Empty, "we don't need to invalidate expanding something that's never been painted");
			Assert.That(root.Height, Is.Not.EqualTo(oldRootHeight));
			VerifyExpandArgs(0, topOfLastItem, topOfLastItem + heightOfOneItem, root.Height - oldRootHeight);
			Assert.That(lazyHookup.Children, Has.Count.EqualTo(4));
			Assert.That(lazyHookup.Children[0], Is.TypeOf(typeof(ItemHookup)), "a regular item hookup for the first expanded item should be inserted");
			Assert.That(lazyHookup.Children[1], Is.TypeOf(typeof(ItemHookup)), "a regular item hookup for the 2nd expanded item should be inserted");
			Assert.That(lazyHookup.Children[2], Is.TypeOf(typeof(LazyBox<MockData1>)), "the lazy box standing for item hookups should still be there");
			Assert.That(lazyHookup.Children[3], Is.TypeOf(typeof(ItemHookup)), "a regular item hookup for the last expanded item should be inserted");
			lazyBox = root.FirstBox.Next.Next as LazyBox<MockData1>;
			Assert.That(lazyBox, Is.Not.Null);
			Assert.That(lazyBox.Height, Is.EqualTo(heightOfOneItem * 3));

			// Expand middle item in lazy box, leaving two lazy boxes.
			int topOfMiddleItem = lazyBox.Top + heightOfOneItem + 2;
			site.RectsInvalidatedInRoot.Clear();
			m_expandArgs.Clear();
			oldRootHeight = root.Height;
			using (var lc = new LayoutCallbacks(root))
			{
				root.PrepareToPaint(layoutInfo, null, topOfMiddleItem + 2, topOfMiddleItem + 10);
			}
			VerifyParagraphs(root, new[] { "0", "1", null, "3", null, "5" }); // Should have two paras then lazy box then middle para then another lazy then last para
			Assert.That(newValues[3].SimpleThreeHookupCount, Is.EqualTo(1), "expanding lazy box should set up a hookup for the string");
			Assert.That(site.RectsInvalidatedInRoot, Is.Empty, "we don't need to invalidate expanding something that's never been painted");
			Assert.That(root.Height, Is.Not.EqualTo(oldRootHeight));
			VerifyExpandArgs(0, topOfMiddleItem, topOfMiddleItem + heightOfOneItem, root.Height - oldRootHeight);
			Assert.That(lazyHookup.Children, Has.Count.EqualTo(6));
			Assert.That(lazyHookup.Children[0], Is.TypeOf(typeof(ItemHookup)), "a regular item hookup for the first expanded item should be inserted");
			Assert.That(lazyHookup.Children[1], Is.TypeOf(typeof(ItemHookup)), "a regular item hookup for the 2nd expanded item should be inserted");
			Assert.That(lazyHookup.Children[2], Is.TypeOf(typeof(LazyBox<MockData1>)), "the lazy box standing for item hookups should still be there");
			Assert.That(lazyHookup.Children[3], Is.TypeOf(typeof(ItemHookup)), "a regular item hookup for the last expanded item should be inserted");
			Assert.That(lazyHookup.Children[4], Is.TypeOf(typeof(LazyBox<MockData1>)), "the lazy box standing for item hookups should still be there");
			Assert.That(lazyHookup.Children[5], Is.TypeOf(typeof(ItemHookup)), "a regular item hookup for the last expanded item should be inserted");
			lazyBox = root.FirstBox.Next.Next as LazyBox<MockData1>;
			Assert.That(lazyBox, Is.Not.Null);
			Assert.That(lazyBox.Height, Is.EqualTo(heightOfOneItem));
			var lazyBox2 = lazyBox.Next.Next as LazyBox<MockData1>;
			Assert.That(lazyBox2, Is.Not.Null);
			Assert.That(lazyBox2.Height, Is.EqualTo(heightOfOneItem));
			// Expand lazy box when it is between two other items. (Also verify expanding two lazy boxes in one PrepareToPaint.)
			int topOfFirstLazy = lazyBox.Top + 2;
			int topOfLastLazy = lazyBox2.Top + 2;
			site.RectsInvalidatedInRoot.Clear();
			m_expandArgs.Clear();
			oldRootHeight = root.Height;
			using (var lc = new LayoutCallbacks(root))
			{
				root.PrepareToPaint(layoutInfo, null, topOfFirstLazy + 2, topOfLastLazy + 2);
			}
			VerifyParagraphs(root, new[] { "0", "1", "2", "3", "4", "5" }); // Should have all the real paragraphs now.
			Assert.That(newValues[2].SimpleThreeHookupCount, Is.EqualTo(1), "expanding lazy box should set up a hookup for the string");
			Assert.That(newValues[4].SimpleThreeHookupCount, Is.EqualTo(1), "expanding lazy box should set up a hookup for the string");
			Assert.That(site.RectsInvalidatedInRoot, Is.Empty, "we don't need to invalidate expanding something that's never been painted");
			Assert.That(root.Height, Is.Not.EqualTo(oldRootHeight));
			var delta = engine.SegmentHeight - heightOfOneItem;
			VerifyExpandArgs(0, topOfFirstLazy, topOfFirstLazy + heightOfOneItem, delta);
			VerifyExpandArgs(1, topOfLastLazy + delta, topOfLastLazy + delta + heightOfOneItem, delta);
			Assert.That(lazyHookup.Children, Has.Count.EqualTo(6));
			Assert.That(lazyHookup.Children[0], Is.TypeOf(typeof(ItemHookup)), "a regular item hookup for the first expanded item should be inserted");
			Assert.That(lazyHookup.Children[1], Is.TypeOf(typeof(ItemHookup)), "a regular item hookup for the 2nd expanded item should be inserted");
			Assert.That(lazyHookup.Children[2], Is.TypeOf(typeof(ItemHookup)), "a regular item hookup for the 3rd expanded item should be inserted");
			Assert.That(lazyHookup.Children[3], Is.TypeOf(typeof(ItemHookup)), "a regular item hookup for the 4th expanded item should be inserted");
			Assert.That(lazyHookup.Children[4], Is.TypeOf(typeof(ItemHookup)), "a regular item hookup for the 5th expanded item should be inserted");
			Assert.That(lazyHookup.Children[5], Is.TypeOf(typeof(ItemHookup)), "a regular item hookup for the last expanded item should be inserted");

			// Now try removing the first two items.
			site.RectsInvalidatedInRoot.Clear();
			int heightOfFirst2Paras = root.FirstBox.Next.Bottom - root.FirstBox.Top;
			int phase3RootWidth = root.Width;
			int phase3RootHeight = root.Height;
			var phase3Values = newValues.Skip(2).ToArray();
			owner.ReplaceObjSeq1(phase3Values);
			var expectedInvalidate3 = new Rectangle(-RootBox.InvalidateMargin, -RootBox.InvalidateMargin,
				phase3RootWidth + 2 * RootBox.InvalidateMargin,
				phase3RootHeight + 2 * RootBox.InvalidateMargin);
			Assert.That(site.RectsInvalidatedInRoot, Has.Member(expectedInvalidate3), "should invalidate the whole old root box; everything changes or moves.");
			VerifyParagraphs(root, new[] {"2", "3", "4", "5" }); // Should have last 4 paragraphs now (not made lazy).

			// Now try removing the last item.
			site.RectsInvalidatedInRoot.Clear();
			int phase4RootWidth = root.Width;
			var phase4Values = phase3Values.Take(3).ToArray();
			var topOfPara4 = root.FirstBox.Next.Next.Bottom + topLazy;
			owner.ReplaceObjSeq1(phase4Values);
			var expectedInvalidate4 = new Rectangle(-RootBox.InvalidateMargin, topOfPara4 - RootBox.InvalidateMargin,
				phase4RootWidth + 2 * RootBox.InvalidateMargin,
				root.FirstBox.Height + 2 * RootBox.InvalidateMargin);
			Assert.That(site.RectsInvalidatedInRoot, Has.Member(expectedInvalidate4), "should invalidate the old replaced paragraphs.");
			VerifyParagraphs(root, new[] { "2", "3", "4" }); // Should have last 3 paragraphs now (not made lazy).

			// Now try removing a middle item.
			site.RectsInvalidatedInRoot.Clear();
			int phase5RootWidth = root.Width;
			var phase5Values = new [] {newValues[2], newValues[4]};
			var topOfPara3 = root.FirstBox.Bottom + topLazy;
			var phase4RootHeight = root.Height;
			owner.ReplaceObjSeq1(phase5Values);
			var expectedInvalidate5 = new Rectangle(-RootBox.InvalidateMargin, topOfPara3 - RootBox.InvalidateMargin,
				phase5RootWidth + 2 * RootBox.InvalidateMargin,
				phase4RootHeight - topOfPara3 + 2 * RootBox.InvalidateMargin);
			Assert.That(site.RectsInvalidatedInRoot, Has.Member(expectedInvalidate5), "should invalidate the old replaced paragraphs.");
			VerifyParagraphs(root, new[] { "2", "4" }); // Should have remaining 2 paragraphs now (not made lazy).

			// Insert three items at start: 0, 1, 3, 2, 4.
			site.RectsInvalidatedInRoot.Clear();
			int phase6RootWidth = root.Width;
			var phase6Values = new[] {newValues[0], newValues[1], newValues[3], newValues[2], newValues[4] };
			owner.ReplaceObjSeq1(phase6Values);
			int lazyWidth = root.LastLayoutInfo.MaxWidth; // current standard width for lazy boxes.
			var expectedInvalidate6 = new Rectangle(-RootBox.InvalidateMargin, topLazy - RootBox.InvalidateMargin,
				lazyWidth + 2 * RootBox.InvalidateMargin,
				root.Height + 2 * RootBox.InvalidateMargin);
			Assert.That(site.RectsInvalidatedInRoot, Has.Member(expectedInvalidate6), "should invalidate everything...all moved or added.");
			VerifyParagraphs(root, new[] {null, "2", "4" }); // Should have added lazy box at start.
			VerifyLazyContents(root.FirstBox, new[] {newValues[0], newValues[1], newValues[3]});

			// Insert at end: 0, 1, 3, 2, 4, 9. I think we've tested the invalidate rects enough.
			var phase7Values = new[] { values[0], values[1], values[3], values[2], values[4], values[9] };
			owner.ReplaceObjSeq1(phase7Values);
			VerifyParagraphs(root, new[] { null, "2", "4", null }); // Should have added lazy box at end.
			VerifyLazyContents(root.LastBox, new[] { values[9] });
			// Insert between two non-lazy items: 0, 1, 3, 2, 5, 6, 4, 9.
			var phase8Values = new[] { values[0], values[1], values[3], values[2], values[5], values[6], values[4], values[9] };
			owner.ReplaceObjSeq1(phase8Values);
			VerifyParagraphs(root, new[] { null, "2", null, "4", null }); // Should have added lazy box in middle.
			VerifyLazyContents(root.FirstBox.Next.Next, new[] { values[5], values[6] });
			// Try a more complex overwrite. We'll replace the last item in the first lazy box and the first one in the second
			var phase9Values = new[] { values[0], values[1], values[7], values[2], values[8], values[6], values[4], values[9] };
			owner.ReplaceObjSeq1(phase9Values);
			VerifyParagraphs(root, new[] { null, "4", null }); // Should replace first 3 items with new lazy box.
			VerifyLazyContents(root.FirstBox, new[] { values[0], values[1], values[7], values[2], values[8], values[6] });
		}
Exemplo n.º 17
0
        public void FlashInsertionPoint()
        {
            AssembledStyles styles     = new AssembledStyles();
            var             clientRuns = new List <IClientRun>();
            BlockBox        box0       = new BlockBox(styles, Color.Red, 72000, 36000);

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

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

            root.Layout(layoutArgs);

            var sel = new DummySelection();

            root.Selection = sel;

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

            root.Paint(graphics, ptrans);

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

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

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

            var ip = new DummySelection();

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

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


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

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

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

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

            // range should get drawn even though IP was hidden.
            root.FlashInsertionPoint();       // back to hidden
            root.Selection = sel;             // back to range.
            sel.ClearResults();
            root.Paint(graphics, ptrans);
            Assert.AreEqual(graphics, sel.VgUsedToDraw);
            Assert.AreEqual(ptrans, sel.TransformUsedToDraw);
        }
Exemplo n.º 18
0
		/// <summary>
		/// Get the location where a range selection is drawn within this paragraph. This is a rectangle that contains
		/// anything this paragraph draws for DrawRange with the same arguments. It is not critical that it contains
		/// nothing more, but is important that it contains nothing less. It should be fairly close (e.g., close enough
		/// to estimate a scroll position to show the selection). This rectangle may need to be combined with those
		/// from other paragraphs involved in a selection to get a rectangle covering the whole selection.
		/// </summary>
		internal Rectangle GetRangeLocation(RangeSelection sel, IVwGraphics vg1, PaintTransform ptrans)
		{
			var bounds = new Rect();
			bool first = true;
			DoRangePaintingOp(sel, vg1, ptrans,
				(box, vg, childTrans, top, bottom, ichMin, ichLim)
				=>
				{
					first = GetRangeLocationInBox(box, vg, childTrans, top, bottom, ichMin, ichLim, first, ref bounds);
				});
			return new Rectangle(bounds.left, bounds.top, bounds.right - bounds.left, bounds.bottom - bounds.top);
		}
Exemplo n.º 19
0
		private static bool GetRangeLocationInBox(Box box, IVwGraphics vg, PaintTransform ptrans, int top, int bottom, int ichMin, int ichLim,
			bool first, ref Rect bounds)
		{
			var sb = box as StringBox;
			if (sb == null)
				return first; // didn't get one here, no change to first
			PaintTransform segTrans = ptrans.PaintTransformOffsetBy(sb.Left, sb.Top);
			Rect bounds1;
			if (sb.Segment.PositionOfRange(sb.IchMin, vg, segTrans.SourceRect,
					segTrans.DestRect, ichMin, ichLim, top, bottom, true, out bounds1)
				&& bounds1.right > bounds1.left)
			{
				if (first)
				{
					bounds = bounds1;
				}
				else
				{
					bounds = new Rect(Math.Min(bounds.left, bounds1.left),
						Math.Min(bounds.top, bounds1.top),
						Math.Max(bounds.right, bounds1.right),
						Math.Max(bounds.bottom, bounds1.bottom));
				}
				return false; // got first rectangle, no longer looking for first one
			}
			return first; // didn't get one yet, no change to first.
		}
Exemplo n.º 20
0
        public void ScrollToShowSelection()
        {
            ParaBox        para;
            RootBox        root = ParaBuilderTests.MakeTestParaSimpleString(m_gm.VwGraphics, ParaBuilderTests.MockBreakOption.ThreeFullLines, out para);
            PaintTransform ptrans = new PaintTransform(2, 4, 96, 96, 0, 0, 96, 96);
            int            dx, dy;

            // If there is no selection we should not move.
            root.ScrollToShowSelection(m_gm.VwGraphics, ptrans, new Rectangle(10, 10, 30, 50), out dx, out dy);
            Assert.That(dx, Is.EqualTo(0));
            Assert.That(dy, Is.EqualTo(0));
            InsertionPoint ip = root.SelectAtEnd();

            ip.Install();

            // Take control of where the selection thinks it is.
            var seg = ((StringBox)para.FirstBox).Segment as MockSegment;

            seg.NextPosIpResult = new MockSegment.PositionsOfIpResults()
            {
                PrimaryHere = true, RectPrimary = new Rect(20, 30, 22, 40)
            };
            var rect = ip.GetSelectionLocation(m_gm.VwGraphics, ptrans);

            Assert.That(rect.Top, Is.EqualTo(30));
            Assert.That(rect.Bottom, Is.EqualTo(40));

            // Todo JohnT: all current tests pass without horizontal scrolling. Eventually implement that.
            // It's entirely inside the rectangle: don't scroll.
            root.ScrollToShowSelection(m_gm.VwGraphics, ptrans, new Rectangle(10, 10, 30, 50), out dx, out dy);
            Assert.That(dx, Is.EqualTo(0));
            Assert.That(dy, Is.EqualTo(0));
            // a special case of entirely inside: not by the desired margin: still don't scroll.
            root.ScrollToShowSelection(m_gm.VwGraphics, ptrans, new Rectangle(10, 28, 30, 14), out dx, out dy);
            Assert.That(dx, Is.EqualTo(0));
            Assert.That(dy, Is.EqualTo(0));

            // It's above a rectangle that can easily hold it: should end 10 pixels inside. Scrolling down 15 pixels will do that.
            root.ScrollToShowSelection(m_gm.VwGraphics, ptrans, new Rectangle(10, 35, 30, 70), out dx, out dy);
            Assert.That(dx, Is.EqualTo(0));
            Assert.That(dy, Is.EqualTo(15));

            // It's below a rectangle that can easily hold it: should end 10 pixels inside. Scrolling up 25 pixels will do that.
            // (The bottom of the rectangle is at 25, 15 pix above the bottom of the selection rectangle.)
            root.ScrollToShowSelection(m_gm.VwGraphics, ptrans, new Rectangle(10, -20, 30, 45), out dx, out dy);
            Assert.That(dx, Is.EqualTo(0));
            Assert.That(dy, Is.EqualTo(-25));

            // It's above a rectangle that can not hold it comfortably: should end just inside. Scrolling down 5 pixels will do that.
            root.ScrollToShowSelection(m_gm.VwGraphics, ptrans, new Rectangle(10, 35, 30, 20), out dx, out dy);
            Assert.That(dx, Is.EqualTo(0));
            Assert.That(dy, Is.EqualTo(5));

            // It's below a rectangle that can not hold it comfortably: should end just inside. Scrolling up 15 pixels will do that.
            // (The bottom of the rectangle is at 25, 15 pix above the bottom of the selection rectangle.)
            root.ScrollToShowSelection(m_gm.VwGraphics, ptrans, new Rectangle(10, 0, 30, 25), out dx, out dy);
            Assert.That(dx, Is.EqualTo(0));
            Assert.That(dy, Is.EqualTo(-15));

            // Pathologically, it may not be possible to display all of it at all. It's currently 12 pixels below the
            // target rectangle. We move it so its top is one pixel above, that is, 12 plus 9 pixels.
            root.ScrollToShowSelection(m_gm.VwGraphics, ptrans, new Rectangle(10, 10, 30, 8), out dx, out dy);
            Assert.That(dx, Is.EqualTo(0));
            Assert.That(dy, Is.EqualTo(-21));
            // A similar case moving up. 10 pixels would align the tops; we move 2 less.
            root.ScrollToShowSelection(m_gm.VwGraphics, ptrans, new Rectangle(10, 40, 30, 6), out dx, out dy);
            Assert.That(dx, Is.EqualTo(0));
            Assert.That(dy, Is.EqualTo(8));

            // Todo JohnT: cases involving ranges. Mostly these work the same, when things fit. There are special cases
            // when the range is not entirely visible, but its DragEnd is; also when the range doesn't entirely fit,
            // but possibly its dragEnd does.
        }
Exemplo n.º 21
0
        public void ArrowKeys()
        {
            var engine = new FakeRenderEngine()
            {
                Ws = 34, SegmentHeight = 13
            };
            var factory = new FakeRendererFactory();

            factory.SetRenderer(34, engine);
            var styles = new AssembledStyles().WithWs(34);
            var root   = new RootBoxFdo(styles);
            var para1  = AddPara("This i~^s the~ day", styles, root);
            var para2  = AddPara("", styles, root);
            var para3  = AddPara(new string[] { "that" + MUSICAL_SYMBOL_SEMIBREVIS_WHITE + " the Lord", "has made" },
                                 styles, root);
            var para4 = AddPara(new string[] { "we will", "", "rejoice" }, styles, root);

            int widthThisIsThe = FakeRenderEngine.SimulatedWidth("This is the");
            var layoutArgs     = MakeLayoutInfo(widthThisIsThe + 2, m_gm.VwGraphics, factory);

            root.Layout(layoutArgs);
            Assert.That(root.Height, Is.EqualTo(13 * 8), "A two-line and a one-line and a three-line and a two-line paragraph");
            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;

            // Simple left movement.
            var ipThisIsTheDay = para1.SelectAtEnd();
            var ipThisIsTheDa  = ipThisIsTheDay.MoveByKey(new KeyEventArgs(Keys.Left));

            VerifyIp(ipThisIsTheDa, para1, "This i~^s the~ da", false, "left from end");
            var ipThisIsTheD = ipThisIsTheDa.MoveByKey(new KeyEventArgs(Keys.Left));

            VerifyIp(ipThisIsTheD, para1, "This i~^s the~ d", false, "left from no special plae");

            // Left from one run into an adjacent non-empty run
            var ipThatTheLord2 = ((TextClientRun)para3.Source.ClientRuns[1]).SelectAt(para3, 0, false);
            var ipThatTheLor   = ipThatTheLord2.MoveByKey(new KeyEventArgs(Keys.Left));

            VerifyIp(ipThatTheLor, para3, "that" + MUSICAL_SYMBOL_SEMIBREVIS_WHITE + " the Lor", false, "left from start run2");

            // Left from one run into an adjacent empty run. Is this right or should we skip over it into
            // another run so we actually move a character?
            var ipStartOfRejoice = ((TextClientRun)para4.Source.ClientRuns[2]).SelectAt(para4, 0, false);
            var ipEmptyPara4     = ipStartOfRejoice.MoveByKey(new KeyEventArgs(Keys.Left));

            VerifyIp(ipEmptyPara4, para4, "we will", false, "left from start run into empty");

            // Out of the empty run into the previous one.
            var ipWeWil = ipEmptyPara4.MoveByKey(new KeyEventArgs(Keys.Left));

            VerifyIp(ipWeWil, para4, "we wil", false, "left from empty run");

            // back from one para into another.
            var ipPara2    = para2.SelectAtStart();
            var ipEndPara1 = ipPara2.MoveByKey(new KeyEventArgs(Keys.Left));

            VerifyIp(ipEndPara1, para1, "This i~^s the~ day", true, "left from one para to another");

            // back at the very start.
            var ipStart = para1.SelectAtStart();

            Assert.That(ipStart.MoveByKey(new KeyEventArgs(Keys.Left)), Is.Null);

            // back after a surrogate pair should not stop in the middle.
            var ipThatSurrogate = ((TextClientRun)para3.Source.ClientRuns[0]).SelectAt(para3,
                                                                                       ("that" + MUSICAL_SYMBOL_SEMIBREVIS_WHITE).Length, false);
            var ipThat = ipThatSurrogate.MoveByKey(new KeyEventArgs(Keys.Left));

            VerifyIp(ipThat, para3, "that", false, "left over surrogate pair");

            // Back to a place between diacritic and base should not stop.
            var ipThisI_Diacritics = ((TextClientRun)para1.Source.ClientRuns[0]).SelectAt(para1,
                                                                                          "This i~^".Length, false);
            var ipThisSpace = ipThisI_Diacritics.MoveByKey(new KeyEventArgs(Keys.Left));

            VerifyIp(ipThisSpace, para1, "This ", false, "left over diacritics");

            // We can use many of the same ones to check right movement.
            var ipThisIsTheDa_r = ipThisIsTheD.MoveByKey(new KeyEventArgs(Keys.Right));

            VerifyIp(ipThisIsTheDa_r, para1, "This i~^s the~ da", true, "simple right");

            // Move right into an empty paragraph.
            // Review JohnT: should this IP in an empty para associate forward or back?
            var ipStartP2 = ipThisIsTheDay.MoveByKey(new KeyEventArgs(Keys.Right));

            VerifyIp(ipStartP2, para2, "", false, "right into empty para");
            // Should definitely associate with the character following, not the nonexistent preceding one.
            var ipStartP3 = ipStartP2.MoveByKey(new KeyEventArgs(Keys.Right));

            VerifyIp(ipStartP3, para3, "", false, "right to start of non-empty para");

            var ipP3_t = ipStartP3.MoveByKey(new KeyEventArgs(Keys.Right));

            VerifyIp(ipP3_t, para3, "t", true, "simple right");

            var ipThatSurrogate2 = ipThat.MoveByKey(new KeyEventArgs(Keys.Right));

            VerifyIp(ipThatSurrogate2, para3, "that" + MUSICAL_SYMBOL_SEMIBREVIS_WHITE, true, "right over surrogate pair");

            var ipThatTheLord_left = ((TextClientRun)para3.Source.ClientRuns[0]).SelectAt(para3,
                                                                                          ("that" + MUSICAL_SYMBOL_SEMIBREVIS_WHITE + " the Lord").Length, true);
            var ipThatTheLord_space = ipThatTheLord_left.MoveByKey(new KeyEventArgs(Keys.Right));

            VerifyIp(ipThatTheLord_space, para3, "that" + MUSICAL_SYMBOL_SEMIBREVIS_WHITE + " the Lord ", true, "right from end run1");

            var ipEnd = para4.SelectAtEnd();

            Assert.That(ipEnd.MoveByKey(new KeyEventArgs(Keys.Right)), Is.Null);

            // Also can't make range by moving right from end.
            Assert.That(ipEnd.MoveByKey(new KeyEventArgs(Keys.Right | Keys.Shift)), Is.Null);

            var rangeThatSurrogate2 = ipThat.MoveByKey(new KeyEventArgs(Keys.Right | Keys.Shift));

            VerifyRange(rangeThatSurrogate2, para3, "that", para3, "that" + MUSICAL_SYMBOL_SEMIBREVIS_WHITE, "shift-right over surrogate pair");

            var rangeThatTha = ipThat.MoveByKey(new KeyEventArgs(Keys.Left | Keys.Shift));

            VerifyRange(rangeThatTha, para3, "that", para3, "tha", "shift-left end before anchor");

            // left from a range puts us at the start of the range
            var ipThat2 = rangeThatSurrogate2.MoveByKey(new KeyEventArgs(Keys.Left));

            VerifyIp(ipThat2, para3, "that", false, "left from range to IP");
            // right from a range puts us at the end of the range
            var ipThatSurrrogate2 = rangeThatSurrogate2.MoveByKey(new KeyEventArgs(Keys.Right));

            VerifyIp(ipThatSurrrogate2, para3, "that" + MUSICAL_SYMBOL_SEMIBREVIS_WHITE, true, "right from range");

            // shift-left from a 1-char range collapses it to an IP
            var ipThat3 = rangeThatSurrogate2.MoveByKey(new KeyEventArgs(Keys.Left | Keys.Shift));

            VerifyIp(ipThat3, para3, "that", false, "left over surrogate pair");

            // shift-right from a range makes one with the same anchor but an extended end
            var rangeThatSurrogateSpace = rangeThatSurrogate2.MoveByKey(new KeyEventArgs(Keys.Right | Keys.Shift));

            VerifyRange(rangeThatSurrogateSpace, para3, "that", para3, "that" + MUSICAL_SYMBOL_SEMIBREVIS_WHITE + " ", "shift-right from range");

            // shift-right from a range that can't grow returns null.
            var ipWeWillRejoic = (InsertionPoint)ipEnd.MoveByKey(new KeyEventArgs(Keys.Left));
            var range1AtEnd    = new RangeSelection(ipWeWillRejoic, ipEnd);

            Assert.That(range1AtEnd.MoveByKey(new KeyEventArgs(Keys.Right | Keys.Shift)), Is.Null);

            // Home key.
            var ipStartP2_2 = ipThat.MoveByKey(new KeyEventArgs(Keys.Home));

            VerifyIp(ipStartP2_2, para3, "", false, "home in Para 3");

            var ipStart_2 = ipThat.MoveByKey(new KeyEventArgs(Keys.Home | Keys.Control));

            VerifyIp(ipStart_2, para1, "", false, "ctrl-home in Para 3");

            // End key.
            var ipEndP2 = ipThat.MoveByKey(new KeyEventArgs(Keys.End));

            VerifyIp(ipEndP2, para3, "that" + MUSICAL_SYMBOL_SEMIBREVIS_WHITE + " the Lord" + "has made",
                     true, "end in Para 3");

            var ipEnd_2 = ipThat.MoveByKey(new KeyEventArgs(Keys.End | Keys.Control));

            VerifyIp(ipEnd_2, para4, "we will" + "rejoice", true, "ctrl-end in Para 3");

            // Down key
            var ipThisIsThe_R = ipStart.MoveByKey(new KeyEventArgs(Keys.Down));

            VerifyIp(ipThisIsThe_R, para1, "This i~^s the~ ", false, "down from start line 1");

            var ipTh           = para1.SelectAt(2, true);
            var ipThisIsTheDa2 = ipTh.MoveByKey(new KeyEventArgs(Keys.Down));

            VerifyIp(ipThisIsTheDa2, para1, "This i~^s the~ da", false, "down from 2 chars into line 1");

            var ipThisIdTh      = para1.SelectAt("This i~^s th".Length, false);
            var ipThisIsTheDay2 = ipThisIdTh.MoveByKey(new KeyEventArgs(Keys.Down));

            VerifyIp(ipThisIsTheDay2, para1, "This i~^s the~ day", true, "down from near end line 1");

            // Empty para: arbitrary which way it associates.
            var ipPara2Down = ipThisIsTheDay2.MoveByKey(new KeyEventArgs(Keys.Down));

            VerifyIp(ipPara2Down, para2, "", true, "down twice from near end line 1");

            // Going on down, we should remember the starting X position and end up about that
            // far into the next full-length line. The 'i' characters in the first line make it
            // a bit iffy; might be closer to the start of the 'e' at the end of 'the'.
            // The other complication is that our fake render engine is not smart about surrogate pairs,
            // and treats the musical semibrevis as two ordinary characters.
            // Omitting the diacritics in the first paragraph, our selection starts 10 characters in.
            // The result string here is 9 characters, since with no narrow letters on this para,
            // we end up closer to the left of the 'e'.
            var ipThatTheSpaceDown = ipPara2Down.MoveByKey(new KeyEventArgs(Keys.Down));

            VerifyIp(ipThatTheSpaceDown, para3, "that" + MUSICAL_SYMBOL_SEMIBREVIS_WHITE + " th", false,
                     "down 3x from near end line 1");

            Assert.That(ipEnd.MoveByKey(new KeyEventArgs(Keys.Down)), Is.Null);

            var ipPara2Up = ipThatTheSpaceDown.MoveByKey(new KeyEventArgs(Keys.Up));

            VerifyIp(ipPara2Up, para2, "", true, "back up aligned with near end line 1");

            var ipThisIsTheDayUp = ipPara2Up.MoveByKey(new KeyEventArgs(Keys.Up));

            VerifyIp(ipThisIsTheDayUp, para1, "This i~^s the~ day", true, "up from para2 aligned near end line 1");
            // It's going to be looking for a position right at the boundary...either assocPrev would be
            // reasonable.
            var ipThisIdTh2Up = ipThisIsTheDayUp.MoveByKey(new KeyEventArgs(Keys.Up));

            VerifyIp(ipThisIdTh2Up, para1, "This i~^s th", false, "up from end para 1 aligned near end line 1");

            //var ipPara2_2 = ipThisIsTheDay.MoveByKey(new KeyEventArgs(Keys.Down));
            //VerifyIp(ipPara2_2, para2, "", true, "down from end para 1");

            // Todo:
            // HandleSpecialKey is called from OnKeyDown and should handle at least these:
            //case Keys.PageUp:
            //case Keys.PageDown:
            //case Keys.End:
            //case Keys.Home:
            //case Keys.Left: // done
            //case Keys.Up:
            //case Keys.Right: // done
            //case Keys.Down:
            //case Keys.F7: // the only two function keys currently known to the Views code,
            //case Keys.F8: // used for left and right arrow by string character amounts.
            // Test Left: (done)
            // - char to char in same line
            //	- skipping diacritics
            //	- skipping surrogate pairs
            // - to another line in same paragraph
            // - to previous (empty?) paragraph
            // - at very start (nothing happens)
            // - range collapses to start
            // - anything special to test if there are multiple runs? e.g., at boundary
            // - skip over embedded pictures
            // - eventually drop into embedded boxes that contain text?
            // Similarly right (done)
            // Down:
            // - same para, there is text below
            // - same para, no text immediately below on same line (goes to end of previous line)
            //  - eventually: what should happen if logical and physical end of next line don't coincide?
            // - down again to a longer line: should stay aligned with start position (what resets this??)
            // etc for others.
        }
Exemplo n.º 22
0
 /// <summary>
 /// Draw a range selection. For now we assume the range is entirely within this paragraph, but this will eventually change.
 /// Todo JohnT: handle non-string-box children and ranges that don't start or end in this paragraph.
 /// Optimize JohnT: there may be a safe way to skip string boxes outside the selection.
 /// </summary>
 public void DrawRange(RangeSelection range, IVwGraphics vg, PaintTransform ptrans)
 {
     DoRangePaintingOp(range, vg, ptrans, DrawSelectionInBox);
 }
Exemplo n.º 23
0
        public void MouseEvents()
        {
            var string1 = "This is the day that the Lord has made.";

            var engine = new FakeRenderEngine()
            {
                Ws = 34, SegmentHeight = 13
            };
            var factory = new FakeRendererFactory();

            factory.SetRenderer(34, engine);
            var runStyle = new AssembledStyles().WithWs(34);

            var style = new AssembledStyles();
            var root  = new RootBox(style);
            var para1 = MakePara(style, runStyle, string1);

            root.AddBox(para1);
            PaintTransform ptrans     = new PaintTransform(2, 2, 96, 96, 0, 0, 96, 96);
            var            layoutArgs = new LayoutInfo(2, 2, 96, 96, FakeRenderEngine.SimulatedWidth("This is the day "), m_gm.VwGraphics, factory);

            root.Layout(layoutArgs);
            var mouseArgs = new MouseEventArgs(MouseButtons.Left, 1, 2, 5, 0);

            root.OnMouseDown(mouseArgs, Keys.None, m_gm.VwGraphics, ptrans);
            Assert.That(root.Selection, Is.TypeOf(typeof(InsertionPoint)));
            Assert.That(((InsertionPoint)root.Selection).LogicalParaPosition, Is.EqualTo(0));
            Assert.That(((InsertionPoint)root.Selection).AssociatePrevious, Is.False);

            // In a different place, tests moving the selection and also getting AssociatePrevious true.
            int widthThis  = FakeRenderEngine.SimulatedWidth("This");
            var mouseArgs2 = new MouseEventArgs(MouseButtons.Left, 1, 2 + widthThis - 1, 5, 0);

            root.OnMouseDown(mouseArgs2, Keys.None, m_gm.VwGraphics, ptrans);
            Assert.That(root.Selection, Is.TypeOf(typeof(InsertionPoint)));
            Assert.That(((InsertionPoint)root.Selection).LogicalParaPosition, Is.EqualTo(4));
            Assert.That(((InsertionPoint)root.Selection).AssociatePrevious, Is.True);

            // A click in the same place should not make a new selection.
            var sel = root.Selection;

            root.OnMouseDown(mouseArgs2, Keys.None, m_gm.VwGraphics, ptrans);             // no change
            Assert.That(root.Selection, Is.EqualTo(sel));

            // A shift-click close enough to the same place to be the same character position but difference AssocPrevious
            // should make the appropriate new IP, not a range.
            var mouseArgs2b = new MouseEventArgs(MouseButtons.Left, 1, 2 + widthThis + 1, 5, 0);

            root.OnMouseDown(mouseArgs2b, Keys.Shift, m_gm.VwGraphics, ptrans);
            Assert.That(root.Selection, Is.TypeOf(typeof(InsertionPoint)));
            Assert.That(((InsertionPoint)root.Selection).LogicalParaPosition, Is.EqualTo(4));
            Assert.That(((InsertionPoint)root.Selection).AssociatePrevious, Is.False);

            // A shift-click should make a range.
            root.OnMouseDown(mouseArgs, Keys.Shift, m_gm.VwGraphics, ptrans);
            Assert.That(root.Selection, Is.TypeOf(typeof(RangeSelection)));
            var anchor = ((RangeSelection)root.Selection).Anchor;
            var drag   = ((RangeSelection)root.Selection).DragEnd;

            Assert.That(anchor.LogicalParaPosition, Is.EqualTo(4));
            Assert.That(drag.LogicalParaPosition, Is.EqualTo(0));

            // shift-click further right: should move the drag end
            var mouseArgs3 = new MouseEventArgs(MouseButtons.Left, 1, 2 + 4, 5, 0);

            root.OnMouseDown(mouseArgs3, Keys.Shift, m_gm.VwGraphics, ptrans);
            Assert.That(root.Selection, Is.TypeOf(typeof(RangeSelection)));
            anchor = ((RangeSelection)root.Selection).Anchor;
            drag   = ((RangeSelection)root.Selection).DragEnd;
            Assert.That(anchor.LogicalParaPosition, Is.EqualTo(4));
            Assert.That(drag.LogicalParaPosition, Is.EqualTo(1));

            // mouse move, to a different position
            root.OnMouseMove(mouseArgs, Keys.None, m_gm.VwGraphics, ptrans);
            sel = root.Selection;
            Assert.That(sel, Is.TypeOf(typeof(RangeSelection)));
            anchor = ((RangeSelection)root.Selection).Anchor;
            drag   = ((RangeSelection)root.Selection).DragEnd;
            Assert.That(anchor.LogicalParaPosition, Is.EqualTo(4));
            Assert.That(drag.LogicalParaPosition, Is.EqualTo(0));

            // mouse move to the same position: no new selection.
            root.OnMouseMove(mouseArgs, Keys.None, m_gm.VwGraphics, ptrans);             // no actual movement
            Assert.That(root.Selection, Is.EqualTo(sel));
            Assert.That(((RangeSelection)root.Selection).DragEnd, Is.EqualTo(drag));

            // mouse move to an IP at the anchor should return us to an IP
            root.OnMouseMove(mouseArgs2b, Keys.None, m_gm.VwGraphics, ptrans);
            Assert.That(root.Selection, Is.TypeOf(typeof(InsertionPoint)));
            Assert.That(((InsertionPoint)root.Selection).LogicalParaPosition, Is.EqualTo(4));
            Assert.That(((InsertionPoint)root.Selection).AssociatePrevious, Is.False);

            // mouse down on next line makes a selection there. Confirm proper passing of srcRect for vertical offset
            var mouseArgs4 = new MouseEventArgs(MouseButtons.Left, 1, 2 + 4, 2 + 16, 0);

            root.OnMouseDown(mouseArgs4, Keys.None, m_gm.VwGraphics, ptrans);
            var paraBox = (ParaBox)root.FirstBox;
            var seg2    = ((StringBox)paraBox.FirstBox.Next).Segment as FakeSegment;

            Assert.That(seg2, Is.Not.Null);
            Assert.That(seg2.LastPointToCharArgs, Is.Not.Null);
            var topOfseg2 = paraBox.FirstBox.Height;

            Assert.That(seg2.LastPointToCharArgs.RcSrc, Is.EqualTo(new Rect(-2, -2 - topOfseg2, 94, 94 - topOfseg2)));
        }
Exemplo n.º 24
0
 public override Rectangle GetSelectionLocation(IVwGraphics graphics, PaintTransform transform)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 25
0
        public void SubParaSequenceTest()
        {
            var owner      = new MockData1(55, 77);
            var styles     = new AssembledStyles();
            var root       = new RootBoxFdo(styles);
            var layoutInfo = MakeLayoutInfo(int.MaxValue / 2, m_gm.VwGraphics, 55);

            SetupFakeRootSite(root);
            var      engine = layoutInfo.RendererFactory.GetRenderer(55, m_gm.VwGraphics) as FakeRenderEngine;
            MockSite site   = new MockSite();

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

            site.m_transform  = ptrans;
            site.m_vwGraphics = m_gm.VwGraphics;
            root.Builder.Show(Paragraph.Containing(Display.Of(() => owner.ObjSeq1).Using((bldr, md) => bldr.AddString(() => md.SimpleThree, 55))));
            root.Layout(layoutInfo);
            VerifyParagraphs(root, new [] { "" });

            //// Insert the first item into owner.ObjSeq1 and check all the right connections appear
            var child1       = new MockData1(55, 77);
            var child1String = "Hello world, this is a wide string";

            child1.SimpleThree = child1String;
            owner.InsertIntoObjSeq1(0, child1);
            VerifyParagraphs(root, new string[] { child1String });
            Assert.That(child1.SimpleThreeHookupCount, Is.EqualTo(1), "Builder.AddString should set up a hookup for the string");
            int invalidateWidth     = FakeRenderEngine.SimulatedWidth(child1String) + 2 * RootBox.InvalidateMargin;
            var expectedInvalidate1 = new Rectangle(-RootBox.InvalidateMargin, -RootBox.InvalidateMargin,
                                                    invalidateWidth,
                                                    engine.SegmentHeight + 2 * RootBox.InvalidateMargin);

            Assert.That(site.RectsInvalidatedInRoot, Has.Member(expectedInvalidate1));

            // Insert a second item and check again.
            var child2 = new MockData1(55, 77);

            child2.SimpleThree = "Another world";
            invalidateWidth   += FakeRenderEngine.SimulatedWidth("Another world");
            site.RectsInvalidated.Clear();
            owner.InsertIntoObjSeq1(1, child2);
            VerifyParagraphs(root, new string[] { child1String + "Another world" });
            Assert.That(child2.SimpleThreeHookupCount, Is.EqualTo(1), "Builder.AddString should set up a hookup for the string");
            var expectedInvalidate2 = new Rectangle(-RootBox.InvalidateMargin, -RootBox.InvalidateMargin,
                                                    invalidateWidth,
                                                    engine.SegmentHeight + 2 * RootBox.InvalidateMargin);

            Assert.That(site.RectsInvalidatedInRoot, Has.Member(expectedInvalidate2));

            // Insert a third item between the first two.
            var child3 = new MockData1(55, 77);

            child3.SimpleThree = "Inserted world";
            invalidateWidth   += FakeRenderEngine.SimulatedWidth("Inserted world");
            site.RectsInvalidated.Clear();
            owner.InsertIntoObjSeq1(1, child3);
            VerifyParagraphs(root, new string[] { child1String + "Inserted world" + "Another world" });
            var expectedInvalidate3 = new Rectangle(-RootBox.InvalidateMargin, -RootBox.InvalidateMargin,
                                                    invalidateWidth,
                                                    engine.SegmentHeight + 2 * RootBox.InvalidateMargin);

            Assert.That(site.RectsInvalidatedInRoot, Has.Member(expectedInvalidate3));

            // Insert a fourth item at the start.
            var child4 = new MockData1(55, 77);

            child4.SimpleThree = "Beginning of world";
            invalidateWidth   += FakeRenderEngine.SimulatedWidth("Beginning of world");
            site.RectsInvalidated.Clear();
            owner.InsertIntoObjSeq1(0, child4);
            VerifyParagraphs(root, new string[] { "Beginning of world" + child1String + "Inserted world" + "Another world" });
            var expectedInvalidate4 = new Rectangle(-RootBox.InvalidateMargin, -RootBox.InvalidateMargin,
                                                    invalidateWidth,
                                                    engine.SegmentHeight + 2 * RootBox.InvalidateMargin);

            Assert.That(site.RectsInvalidatedInRoot, Has.Member(expectedInvalidate4));

            // Delete the first item.
            site.RectsInvalidated.Clear();
            owner.RemoveAtObjSeq1(0);
            VerifyParagraphs(root, new string[] { child1String + "Inserted world" + "Another world" });
            Assert.That(child4.SimpleThreeHookupCount, Is.EqualTo(0), "The hookup for a deleted object should be disposed.");
            Assert.That(site.RectsInvalidatedInRoot, Has.Member(expectedInvalidate4));

            // Delete a middle item.
            site.RectsInvalidated.Clear();
            owner.RemoveAtObjSeq1(1);
            VerifyParagraphs(root, new string[] { child1String + "Another world" });
            Assert.That(child3.SimpleThreeHookupCount, Is.EqualTo(0), "The hookup for a deleted object should be disposed.");
            Assert.That(site.RectsInvalidatedInRoot, Has.Member(expectedInvalidate3));

            // Delete the last item.
            site.RectsInvalidated.Clear();
            owner.RemoveAtObjSeq1(1);
            VerifyParagraphs(root, new string[] { child1String });
            Assert.That(child2.SimpleThreeHookupCount, Is.EqualTo(0), "The hookup for a deleted object should be disposed.");
            Assert.That(site.RectsInvalidatedInRoot, Has.Member(expectedInvalidate2));

            // Delete the only remaining item.
            site.RectsInvalidated.Clear();
            owner.RemoveAtObjSeq1(0);
            VerifyParagraphs(root, new string[] { "" });
            Assert.That(child1.SimpleThreeHookupCount, Is.EqualTo(0), "The hookup for a deleted object should be disposed.");
            Assert.That(site.RectsInvalidatedInRoot, Has.Member(expectedInvalidate1));

            // Eventually add some operations that allow inserting and deleting multiple items.

            // We also need to be able to insert two or more object sequences into the same containing box.
            // That's probably another test, perhaps a view of the root where for each data item,
            // we insert its subitems, then for those insert paragraphs.
            // Let's assume there's always one top-level hookup for the root.
        }
Exemplo n.º 26
0
        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));
        }
Exemplo n.º 27
0
 /// <summary>
 /// Get the location, in the coordinates indicated by the transform, of a rectangle that contains the
 /// primary insertion point.
 /// Todo JohnT: there should be a parallel routine to get the location of the secondary rectangle.
 /// </summary>
 public abstract Rectangle GetSelectionLocation(IVwGraphics graphics, PaintTransform transform);
Exemplo n.º 28
0
 internal override void Draw(IVwGraphics vg, PaintTransform ptrans)
 {
     Para.DrawIp(this, vg, Para.Container.ChildTransformFromRootTransform(ptrans));
 }
Exemplo n.º 29
0
		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
		}
Exemplo n.º 30
0
        //public bool IsShowingEmptySubstitute
        //{
        //    get
        //    {
        //        var run = ContainingRun as StringClientRun;
        //        return run != null && run.Substitute != null;
        //    }
        //}

        ///// <summary>
        ///// Invalidate the selection, that is, mark the rectangle it occupies as needing to be painted in the containing control.
        ///// </summary>
        //internal override void Invalidate()
        //{
        //    base.Invalidate();
        //    // Todo: invalidate the secondary rectangle, if that isn't included in the GetSelectionLocation one.
        //}

        /// <summary>
        /// Get the location, in the coordinates indicated by the transform, of a rectangle that contains the
        /// primary insertion point.
        /// Todo JohnT: there should be a parallel routine to get the location of the secondary rectangle.
        /// </summary>
        public override Rectangle GetSelectionLocation(IVwGraphics graphics, PaintTransform transform)
        {
            return(Para.GetIpLocation(this, graphics, transform));
        }
Exemplo n.º 31
0
        public void BasicDrop()
        {
            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;

            var dataObj  = new DataObject(DataFormats.StringFormat, "new ");
            int x        = FakeRenderEngine.SimulatedWidth("old ") + 2;
            var location = new Point(x, 8);

            // A drag to where we can drop, allowing both copy and move, no keys held
            var dragArgs = new DragEventArgs(dataObj, (int)DragDropKeyStates.None, 200, 300,
                                             DragDropEffects.Copy | DragDropEffects.Move,
                                             DragDropEffects.None);

            root.OnDragEnter(dragArgs, location, m_gm.VwGraphics, ptrans);
            Assert.That(dragArgs.Effect, Is.EqualTo(DragDropEffects.Move));
            Assert.That(root.DragState, Is.EqualTo(WindowDragState.DraggingHere));
            root.OnDragLeave();
            Assert.That(root.DragState, Is.EqualTo(WindowDragState.None));

            // Though other factors would favor move, only copy is allowed here.
            dragArgs = new DragEventArgs(dataObj, (int)DragDropKeyStates.None, 200, 300,
                                         DragDropEffects.Copy,
                                         DragDropEffects.None);
            root.OnDragEnter(dragArgs, location, m_gm.VwGraphics, ptrans);
            Assert.That(dragArgs.Effect, Is.EqualTo(DragDropEffects.Copy));

            // Though otherwise we could copy, there is no text data in the data object.
            dragArgs = new DragEventArgs(new DataObject(), (int)DragDropKeyStates.None, 200, 300,
                                         DragDropEffects.Copy | DragDropEffects.Move,
                                         DragDropEffects.None);
            root.OnDragEnter(dragArgs, location, m_gm.VwGraphics, ptrans);
            Assert.That(dragArgs.Effect, Is.EqualTo(DragDropEffects.None));

            dragArgs = new DragEventArgs(dataObj, (int)DragDropKeyStates.ControlKey, 200, 300,
                                         DragDropEffects.Copy | DragDropEffects.Move,
                                         DragDropEffects.None);
            root.OnDragEnter(dragArgs, location, m_gm.VwGraphics, ptrans);
            Assert.That(dragArgs.Effect, Is.EqualTo(DragDropEffects.Copy));

            root.OnDragDrop(dragArgs, location, m_gm.VwGraphics, ptrans);
            Assert.That(mock1.SimpleThree, Is.EqualTo("old new contents"));
        }
Exemplo n.º 32
0
        public void BasicPaste()
        {
            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;

            var dataObj  = new DataObject(DataFormats.StringFormat, "new ");
            int x        = FakeRenderEngine.SimulatedWidth("new old ") + 2;
            var location = new Point(x, 8);

            Clipboard.SetDataObject("");

            Assert.That(root.CanPaste(), Is.EqualTo(false), "Should not be able to Paste");
            root.OnEditPaste();
            Assert.That(mock1.SimpleThree, Is.EqualTo("old contents"), "Nothing should have changed");

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

            root.OnMouseDown(e, Keys.None, site.m_vwGraphics, site.m_transform);

            Clipboard.SetDataObject(dataObj);
            Assert.That(root.CanPaste(), Is.EqualTo(true), "Should be able to Paste");
            root.OnEditPaste();
            Assert.That(mock1.SimpleThree, Is.EqualTo("new old contents"), "Selected String should be \"new old contents\"");
            Assert.That(Clipboard.GetDataObject().GetData(DataFormats.StringFormat), Is.Not.EqualTo(null), "Selected String should not be null");
            Assert.That(Clipboard.GetDataObject().GetData(DataFormats.StringFormat), Is.EqualTo("new "), "Selected String should be \"new \"");

            dataObj  = new DataObject(DataFormats.StringFormat, "new ");
            x        = FakeRenderEngine.SimulatedWidth("") + 2;
            location = new Point(x, 8);
            e        = new MouseEventArgs(MouseButtons.Left, 1, location.X, location.Y, 0);
            Clipboard.SetDataObject(dataObj);

            root.OnMouseDown(e, Keys.None, site.m_vwGraphics, site.m_transform);
            x        = FakeRenderEngine.SimulatedWidth("new old ") + 2;
            location = new Point(x, 8);
            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.Selection, Is.Not.EqualTo(null), "Selection should now be assigned");
            Assert.That(root.Selection.DragDropData, Is.Not.EqualTo(null), "Selection should now be assigned");
            root.OnEditPaste();
            Assert.That(mock1.SimpleThree, Is.EqualTo("new contents"), "Selected String should be \"new contents\"");
            Assert.That(Clipboard.GetDataObject().GetData(DataFormats.StringFormat), Is.EqualTo("new "), "Selected String should be \"new \"");
        }
Exemplo n.º 33
0
		internal void DrawRange(int ichMin, int ichLim, IVwGraphics vg, PaintTransform ptrans, int topOfLine, int bottomOfLine)
		{
			PaintTransform segTrans = ptrans.PaintTransformOffsetBy(Left, Top);
			// Todo JohnT: here or in client we need to handle ranges that don't start and end in this paragraph.
			// Todo JohnT: the last true appears to be what the old Views code normally passes, but there may be some case where
			// we should pass false.
			// Todo JohnT: passing the top and bottom of the string box as ydTop and ydBottom will not work when we have specified line spacing.
			Segment.DrawRange(IchMin, vg, segTrans.SourceRect, segTrans.DestRect,
				ichMin, ichLim, topOfLine, bottomOfLine, true, true);
		}
Exemplo n.º 34
0
        public void MultiParaPaste()
        {
            var styles = new AssembledStyles();
            var root   = new RootBoxFdo(styles);
            var owner  = new MockData1(23, 23);
            var mock1  = new MockData1(23, 23);

            owner.InsertIntoObjSeq1(0, mock1);
            mock1.SimpleThree = "This 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("is the\r\nday that the\r\nLord ");

            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.CanPaste(), Is.EqualTo(true), "Should be able to paste");
            root.OnEditPaste();
            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 \"");
            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"));


            x        = FakeRenderEngine.SimulatedWidth("") + 2;
            location = new Point(x, 8);
            e        = new MouseEventArgs(MouseButtons.Left, 1, location.X, location.Y, 0);
            root.OnMouseDown(e, Keys.None, site.m_vwGraphics, site.m_transform);

            mock1.SimpleThree = "";
            owner             = new MockData1();
            owner.InsertIntoObjSeq1(0, mock1);
            root.Builder.Show(
                Display.Of(() => owner.ObjSeq1).Using((bldr, md) => bldr.AddString(() => md.SimpleThree, 23)).EditParagraphsUsing(po));
            root.Layout(layoutArgs);

            Clipboard.SetDataObject(
                "\r\nThis is the\r\n\r\n\r\nDay that the\r\nLord\r\n\r\nHas\r\n\r\n\r\nMade\r\nW\r\n");

            Assert.That(root.CanPaste(), Is.EqualTo(true), "Should be able to paste");
            root.OnEditPaste();
            string testString = "";

            foreach (MockData1 obj in owner.ObjSeq1)
            {
                string nextString = obj.SimpleThree;
                testString += "\r\n";
                testString += nextString;
            }
            Assert.That(testString,
                        Is.EqualTo("\r\nThis is the\r\n\r\n\r\nDay that the\r\nLord\r\n\r\nHas\r\n\r\n\r\nMade\r\nW\r\n\r\n"));
        }
Exemplo n.º 35
0
		internal override Selection MakeSelectionAt(Point where, IVwGraphics vg, PaintTransform ptrans)
		{
			var segTrans = ptrans.PaintTransformOffsetBy(Left, Top);
			int ich;
			bool assocPrev;
			Segment.PointToChar(IchMin, vg, segTrans.SourceRect, segTrans.DestRect, where, out ich, out assocPrev);
			return Paragraph.SelectAt(ich, assocPrev);
		}
Exemplo n.º 36
0
        public void NestedDivsLayout()
        {
            var      styles = new AssembledStyles();
            BlockBox box1   = new BlockBox(styles, Color.Red, 72000, 36000);
            BlockBox box2   = new BlockBox(styles, Color.Blue, 108000, 18000);
            BlockBox box3   = new BlockBox(styles, Color.Orange, 72000, 18000);
            BlockBox box4   = new BlockBox(styles, Color.Orange, 72000, 18000);
            var      div1   = new DivBox(styles);
            var      div2   = new DivBox(styles);

            div1.AddBox(box1);
            div1.AddBox(box2);
            div2.AddBox(box3);
            div2.AddBox(box4);
            RootBox root = new RootBox(styles);

            root.AddBox(div1);
            root.AddBox(div2);
            LayoutInfo layoutArgs = MakeLayoutInfo();

            root.Layout(layoutArgs);
            Assert.That(box1.Height, Is.EqualTo(48));
            Assert.That(box2.Height, Is.EqualTo(24));
            Assert.That(root.Height, Is.EqualTo(48 + 24 + 24 + 24));
            Assert.That(box1.Left, Is.EqualTo(0));
            Assert.That(box2.Left, Is.EqualTo(0));
            Assert.That(box1.Top, Is.EqualTo(0));
            Assert.That(box2.Top, Is.EqualTo(48));
            Assert.That(div2.Top, Is.EqualTo(48 + 24));
            Assert.That(box4.Top, Is.EqualTo(24));
            Assert.That(box1.Width, Is.EqualTo(96));
            Assert.That(box2.Width, Is.EqualTo(144));
            Assert.That(root.Width, Is.EqualTo(144));

            // Now try changing the size of a block.
            MockSite site = new MockSite();

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

            site.m_transform  = ptrans;
            site.m_vwGraphics = m_gm.VwGraphics;
            box2.UpdateSize(144000, 36000);
            Assert.That(box2.Width, Is.EqualTo(96 * 2));
            Assert.That(box2.Height, Is.EqualTo(48));
            Assert.That(div1.Height, Is.EqualTo(96));                // two children now both 48 high.
            Assert.That(root.Height, Is.EqualTo(48 + 48 + 24 + 24)); // new heights of 4 children.
            Assert.That(root.Width, Is.EqualTo(96 * 2));
            // Since it got both wider and higher, we should invalidate at least the whole current size.
            var bigInvalidate = root.InvalidateRect;

            Assert.That(site.RectsInvalidatedInRoot, Has.Member(bigInvalidate));

            site.RectsInvalidated.Clear();
            box2.UpdateSize(108000, 36000);
            Assert.That(root.Height, Is.EqualTo(48 + 48 + 24 + 24)); // unchanged this time
            Assert.That(root.Width, Is.EqualTo(144));                // narrower box2 still determines it
            // Got narrower, at least the whole old invalidate rectangle should be invalidated.
            Assert.That(site.RectsInvalidatedInRoot, Has.Member(bigInvalidate));

            site.RectsInvalidated.Clear();
            box2.UpdateSize(108000, 18000);
            Assert.That(root.Height, Is.EqualTo(48 + 24 + 24 + 24)); // new smaller value
            Assert.That(root.Width, Is.EqualTo(144));                //  unchanged this time
            // It got shorter. We want an optimized invalidate rectangle that does not
            // include the top box. But it must include the space at the bottom that the root box used to occupy.
            // There are other possible implementations, but currently, we expect the old rectangle of box2
            // to be invalidated (its in the fixmap so its own Relayout does this);
            // the shrinkage area at the bottom of div2;
            // and the area computed because div2 moved.
            VerifyExpectedRectangle(site.RectsInvalidatedInRoot, 0, 48, 144, 48);             // old box2
            VerifyExpectedRectangle(site.RectsInvalidatedInRoot, 0, 48 + 24, 144, 24);        // shrinkage of div1
            // This is from the new top of div2 to its old bottom (old bottom was 48 + 48 + 24 + 24)
            VerifyExpectedRectangle(site.RectsInvalidatedInRoot, 0, 48 + 24, 144, 48 + 24);

            site.RectsInvalidated.Clear();
            box2.UpdateSize(108000, 72000);
            Assert.That(root.Height, Is.EqualTo(48 + 96 + 24 + 24)); // new larger value
            Assert.That(root.Width, Is.EqualTo(144));                //  unchanged this time
            // It got longer. We want an optimized invalidate rectangle that does not
            // include the top box. But it must include the space at the bottom where the root box grew.
            // There are other possible implementations, but currently, we expect the old rectangle of box2
            // to be invalidated (it returns true from Relayout);
            // the growth area at the bottom of div2;
            // and the area computed because div2 moved.
            VerifyExpectedRectangle(site.RectsInvalidatedInRoot, 0, 48, 144, 96);             // new box2
            VerifyExpectedRectangle(site.RectsInvalidatedInRoot, 0, 48 + 24, 144, 96 - 24);   // new part of div1 occupied by box2
            // This is from the old top of div2 to its new bottom (48 + 96 + 24 + 24)
            VerifyExpectedRectangle(site.RectsInvalidatedInRoot, 0, 48 + 24, 144, 96 + 24);
        }
Exemplo n.º 37
0
		/// <summary>
		/// Some common logic for several tests. Returns the old paragraph height (before the change).
		/// </summary>
		private int TestChangeNotAffectingLineBreaks(out ParaBox para, Action<string[]> wordsModifier,
			Func<ParaBox, Rectangle, Rectangle> invalidRectModifier,
			Action<List<MockSegment>> potentialSegsModifier)
		{
			RootBox root = MakeTestParaSimpleString(m_gm.VwGraphics, MockBreakOption.ThreeFullLines, out para);
			int result = para.Height;
			Rectangle expectedInvalidate = para.InvalidateRect;
			var modWords = new string[s_simpleStringWords.Length];
			Array.Copy(s_simpleStringWords, modWords, modWords.Length);
			wordsModifier(modWords); // make whatever change we intend to the text.
			var layoutArgs = MakeLayoutInfo(Int32.MaxValue / 2, m_gm.VwGraphics);
			var engine = root.LastLayoutInfo.RendererFactory.GetRenderer(s_simpleStringWs, m_gm.VwGraphics) as MockRenderEngine;
			var modContents = AssembleStrings(modWords);
			SetupMockEngineForThreeLines(modContents, engine, modWords);
			// The one we want to modify is the fourth to be added; this is the same engine, so it already has
			// the three potential segments from the original layout.
			potentialSegsModifier(engine.m_potentialSegsInOrder);
			MockSite site = new MockSite();
			root.Site = site;
			PaintTransform ptrans = new PaintTransform(2, 4, 96, 100, 0, 10, 120, 128);
			site.m_transform = ptrans;
			site.m_vwGraphics = m_gm.VwGraphics;
			var hookup = new StringHookup(null, null, hook => DoNothing(), hook => DoNothing(), para);
			((StringClientRun) para.Source.ClientRuns[0]).Hookup = hookup;
			para.StringChanged(0, modContents);
			Assert.AreEqual(modContents, para.Source.RenderText);
			Assert.That(((StringClientRun) para.Source.ClientRuns[0]).Hookup, Is.EqualTo(hookup));
			int ichEndFirstLine = SumStringLengths(modWords, 0, 3);
			// We inserted at the start, so only the first line should have been invalidated; but char offsets for other lines should have changed.
			VerifySegment(para, 0, s_widthFirstMockSeg, ichEndFirstLine, 0);
			int ichEndSecondLine = SumStringLengths(modWords, 0, 6);
			VerifySegment(para, 1, s_widthSecondMockSeg, ichEndSecondLine - ichEndFirstLine, ichEndFirstLine);
			VerifySegment(para, 2, s_widthThirdMockSeg, modContents.Length - ichEndSecondLine, ichEndSecondLine);
			expectedInvalidate = invalidRectModifier(para, expectedInvalidate);
			Assert.That(site.RectsInvalidatedInRoot, Has.Member(expectedInvalidate));
			return result;
		}
Exemplo n.º 38
0
		public void BasicDrop()
		{
			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;

			var dataObj = new DataObject(DataFormats.StringFormat, "new ");
			int x = FakeRenderEngine.SimulatedWidth("old ") + 2;
			var location = new Point(x, 8);

			// A drag to where we can drop, allowing both copy and move, no keys held
			var dragArgs = new DragEventArgs(dataObj, (int) DragDropKeyStates.None, 200,300,
				DragDropEffects.Copy | DragDropEffects.Move,
				DragDropEffects.None);
			root.OnDragEnter(dragArgs, location, m_gm.VwGraphics, ptrans);
			Assert.That(dragArgs.Effect, Is.EqualTo(DragDropEffects.Move));
			Assert.That(root.DragState, Is.EqualTo(WindowDragState.DraggingHere));
			root.OnDragLeave();
			Assert.That(root.DragState, Is.EqualTo(WindowDragState.None));

			// Though other factors would favor move, only copy is allowed here.
			dragArgs = new DragEventArgs(dataObj, (int)DragDropKeyStates.None, 200,300,
				DragDropEffects.Copy,
				DragDropEffects.None);
			root.OnDragEnter(dragArgs, location, m_gm.VwGraphics, ptrans);
			Assert.That(dragArgs.Effect, Is.EqualTo(DragDropEffects.Copy));

			// Though otherwise we could copy, there is no text data in the data object.
			dragArgs = new DragEventArgs(new DataObject(), (int)DragDropKeyStates.None, 200,300,
				DragDropEffects.Copy | DragDropEffects.Move,
				DragDropEffects.None);
			root.OnDragEnter(dragArgs, location, m_gm.VwGraphics, ptrans);
			Assert.That(dragArgs.Effect, Is.EqualTo(DragDropEffects.None));

			dragArgs = new DragEventArgs(dataObj, (int)DragDropKeyStates.ControlKey, 200,300,
				DragDropEffects.Copy | DragDropEffects.Move,
				DragDropEffects.None);
			root.OnDragEnter(dragArgs, location, m_gm.VwGraphics, ptrans);
			Assert.That(dragArgs.Effect, Is.EqualTo(DragDropEffects.Copy));

			root.OnDragDrop(dragArgs, location, m_gm.VwGraphics, ptrans);
			Assert.That(mock1.SimpleThree, Is.EqualTo("old new contents"));
		}
Exemplo n.º 39
0
        public void NestedRowsLayout()
        {
            var styles = new AssembledStyles();
            var box1   = new LayoutInfoRecorderBox(styles, Color.Red, 72000, 36000);
            var box2   = new LayoutInfoRecorderBox(styles, Color.Blue, 108000, 18000);
            var box3   = new LayoutInfoRecorderBox(styles, Color.Orange, 72000, 18000);
            var box4   = new LayoutInfoRecorderBox(styles, Color.Orange, 72000, 18000);
            var widths = new FixedColumnWidths(new[] { 34, 67, 99 });
            // pass widths to RowBox constructor
            var row1 = new RowBox(styles, widths, false);
            var row2 = new RowBox(styles, widths, false);

            row1.AddBox(box1);
            row1.AddBox(box2);
            row2.AddBox(box3);
            row2.AddBox(box4);
            RootBox root = new RootBox(styles);

            root.AddBox(row1);
            root.AddBox(row2);
            LayoutInfo layoutArgs = MakeLayoutInfo();

            root.Layout(layoutArgs);
            Assert.That(box1.LastLayoutInfo.MaxWidth, Is.EqualTo(34));
            Assert.That(box1.Height, Is.EqualTo(48));
            Assert.That(box2.Height, Is.EqualTo(24));
            Assert.That(box3.Height, Is.EqualTo(24));
            Assert.That(box4.Height, Is.EqualTo(24));
            Assert.That(root.Height, Is.EqualTo(48 + 24));
            Assert.That(box1.Left, Is.EqualTo(0));
            Assert.That(box2.Left, Is.EqualTo(96));
            Assert.That(box3.Left, Is.EqualTo(0));
            Assert.That(box4.Left, Is.EqualTo(96));
            Assert.That(row1.Top, Is.EqualTo(0));
            Assert.That(box1.Top, Is.EqualTo(0));
            Assert.That(box2.Top, Is.EqualTo(0));
            Assert.That(row2.Top, Is.EqualTo(48));
            Assert.That(box3.Top, Is.EqualTo(0));
            Assert.That(box4.Top, Is.EqualTo(0));
            Assert.That(box1.Width, Is.EqualTo(96));
            Assert.That(box2.Width, Is.EqualTo(144));
            Assert.That(box3.Width, Is.EqualTo(96));
            Assert.That(box4.Width, Is.EqualTo(96));
            Assert.That(root.Width, Is.EqualTo(96 + 144));

            // Now try changing the size of a block.
            MockSite site = new MockSite();

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

            site.m_transform  = ptrans;
            site.m_vwGraphics = m_gm.VwGraphics;
            box2.UpdateSize(144000, 36000);
            Assert.That(box2.Width, Is.EqualTo(96 * 2));
            Assert.That(box2.Height, Is.EqualTo(48));
            Assert.That(row1.Height, Is.EqualTo(48));
            Assert.That(root.Height, Is.EqualTo(72));
            Assert.That(root.Width, Is.EqualTo(96 * 3));
            // Since it got both wider and higher, we should invalidate at least the whole current size.
            var bigInvalidate = root.InvalidateRect;

            Assert.That(site.RectsInvalidatedInRoot, Has.Member(bigInvalidate));

            site.RectsInvalidated.Clear();
            box2.UpdateSize(108000, 18000);
            Assert.That(root.Height, Is.EqualTo(48 + 24));             // unchanged this time
            Assert.That(root.Width, Is.EqualTo(96 + 144));             // narrower box2 still determines it
            // Got narrower, at least the whole old invalidate rectangle should be invalidated.
            Assert.That(site.RectsInvalidatedInRoot, Has.Member(bigInvalidate));

            site.RectsInvalidated.Clear();
            box2.UpdateSize(72000, 18000);
            Assert.That(root.Height, Is.EqualTo(48 + 24));             // unchanged this time
            Assert.That(root.Width, Is.EqualTo(144 + 48));             // new smaller value
            // It got thinner. We want an optimized invalidate rectangle that does not
            // include the left boxes. But it must include the space at the right that the root box used to occupy.
            // There are other possible implementations, but currently, we expect the old rectangle of box2
            // to be invalidated (it's in the fixmap so its own Relayout does this);
            // the shrinkage area at the right of row2;
            // and the area computed because row2 moved.
            //VerifyExpectedRectangle(site.RectsInvalidatedInRoot, 0, 48, 48, 144); // old box2
            //VerifyExpectedRectangle(site.RectsInvalidatedInRoot, 0, 48 + 24, 144, 24); // shrinkage of row1
            // This is from the new left of div2 to its old right (old right was 48 + 48 + 24 + 24)
            //VerifyExpectedRectangle(site.RectsInvalidatedInRoot, 0, 48 + 24, 144, 48 + 24);

            site.RectsInvalidated.Clear();
            box2.UpdateSize(144000, 18000);
            Assert.That(root.Height, Is.EqualTo(48 + 24));             //  unchanged this time
            Assert.That(root.Width, Is.EqualTo(144 + 144));            // new larger value
            // It got wider. We want an optimized invalidate rectangle that does not
            // include the left boxes. But it must include the space at the right where the root box grew.
            // There are other possible implementations, but currently, we expect the old rectangle of box2
            // to be invalidated (it returns true from Relayout);
            // the growth area at the right of div2;
            // and the area computed because div2 moved.
            //VerifyExpectedRectangle(site.RectsInvalidatedInRoot, 0, 48, 144, 96); // new box2
            //VerifyExpectedRectangle(site.RectsInvalidatedInRoot, 0, 48 + 24, 144, 96 - 24); // new part of div1 occupied by box2
            // This is from the old left of div2 to its new right (48 + 96 + 24 + 24)
            //VerifyExpectedRectangle(site.RectsInvalidatedInRoot, 0, 48 + 24, 144, 96 + 24);
        }
Exemplo n.º 40
0
        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);
        }
Exemplo n.º 41
0
        public void TypingInComplexPara()
        {
            ParaBox   para;
            RootBox   root      = ParaBuilderTests.MakeTestParaThreeStrings(m_gm.VwGraphics, ParaBuilderTests.MockBreakOption.ThreeFullLines, out para);
            string    contents0 = ParaBuilderTests.AssembleStrings(ParaBuilderTests.s_firstGroupWords);
            MockData1 data0     = HookDataToClientRun(para, contents0, 0);
            string    contents1 = ParaBuilderTests.AssembleStrings(ParaBuilderTests.s_secondGroupWords);
            MockData1 data1     = HookDataToClientRun(para, contents1, 1);
            string    contents2 = ParaBuilderTests.AssembleStrings(ParaBuilderTests.s_thirdGroupWords);

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

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

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

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

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

            ip.InsertText("x");

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

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

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

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

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

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

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

            // Then typing an 'z' should add it to the first string.
            newLastWord = newLastWord.Substring(0, newLastWord.Length - 1) + "z";
            modWords0   = ModifyWords(ParaBuilderTests.s_firstGroupWords,
                                      ParaBuilderTests.s_firstGroupWords.Length - 1,
                                      newLastWord);
            ParaBuilderTests.SetupMockEngineForThreeStringsPara(modWords0, ParaBuilderTests.s_secondGroupWords,
                                                                ParaBuilderTests.s_thirdGroupWords, root.LastLayoutInfo);
            ip.InsertText("z");
            newFirstContents = newFirstContents + "z";
            Assert.AreEqual(newFirstContents + contents1 + contents2, para.Source.RenderText);
            Assert.AreEqual(newFirstContents, data0.SimpleThree);
            Assert.AreEqual(contents1, data1.SimpleThree);
            Assert.AreEqual(newFirstContents.Length, ip.StringPosition);
            Assert.IsTrue(ip.AssociatePrevious);
        }
Exemplo n.º 42
0
		public void NestedDivsLayout()
		{
			var styles = new AssembledStyles();
			BlockBox box1 = new BlockBox(styles, Color.Red, 72000, 36000);
			BlockBox box2 = new BlockBox(styles, Color.Blue, 108000, 18000);
			BlockBox box3 = new BlockBox(styles, Color.Orange, 72000, 18000);
			BlockBox box4 = new BlockBox(styles, Color.Orange, 72000, 18000);
			var div1 = new DivBox(styles);
			var div2 = new DivBox(styles);
			div1.AddBox(box1);
			div1.AddBox(box2);
			div2.AddBox(box3);
			div2.AddBox(box4);
			RootBox root = new RootBox(styles);
			root.AddBox(div1);
			root.AddBox(div2);
			LayoutInfo layoutArgs = MakeLayoutInfo();
			root.Layout(layoutArgs);
			Assert.That(box1.Height, Is.EqualTo(48));
			Assert.That(box2.Height, Is.EqualTo(24));
			Assert.That(root.Height, Is.EqualTo(48 + 24 + 24 + 24));
			Assert.That(box1.Left, Is.EqualTo(0));
			Assert.That(box2.Left, Is.EqualTo(0));
			Assert.That(box1.Top, Is.EqualTo(0));
			Assert.That(box2.Top, Is.EqualTo(48));
			Assert.That(div2.Top, Is.EqualTo(48 + 24));
			Assert.That(box4.Top, Is.EqualTo(24));
			Assert.That(box1.Width, Is.EqualTo(96));
			Assert.That(box2.Width, Is.EqualTo(144));
			Assert.That(root.Width, Is.EqualTo(144));

			// Now try changing the size of a block.
			MockSite site = new MockSite();
			root.Site = site;
			PaintTransform ptrans = new PaintTransform(2, 4, 96, 96, 0, 10, 120, 128);
			site.m_transform = ptrans;
			site.m_vwGraphics = m_gm.VwGraphics;
			box2.UpdateSize(144000, 36000);
			Assert.That(box2.Width, Is.EqualTo(96*2));
			Assert.That(box2.Height, Is.EqualTo(48));
			Assert.That(div1.Height, Is.EqualTo(96)); // two children now both 48 high.
			Assert.That(root.Height, Is.EqualTo(48 +48 + 24 + 24)); // new heights of 4 children.
			Assert.That(root.Width, Is.EqualTo(96*2));
			// Since it got both wider and higher, we should invalidate at least the whole current size.
			var bigInvalidate = root.InvalidateRect;
			Assert.That(site.RectsInvalidatedInRoot, Has.Member(bigInvalidate));

			site.RectsInvalidated.Clear();
			box2.UpdateSize(108000, 36000);
			Assert.That(root.Height, Is.EqualTo(48 + 48 + 24 + 24)); // unchanged this time
			Assert.That(root.Width, Is.EqualTo(144)); // narrower box2 still determines it
			// Got narrower, at least the whole old invalidate rectangle should be invalidated.
			Assert.That(site.RectsInvalidatedInRoot, Has.Member(bigInvalidate));

			site.RectsInvalidated.Clear();
			box2.UpdateSize(108000, 18000);
			Assert.That(root.Height, Is.EqualTo(48 + 24 + 24 + 24)); // new smaller value
			Assert.That(root.Width, Is.EqualTo(144)); //  unchanged this time
			// It got shorter. We want an optimized invalidate rectangle that does not
			// include the top box. But it must include the space at the bottom that the root box used to occupy.
			// There are other possible implementations, but currently, we expect the old rectangle of box2
			// to be invalidated (its in the fixmap so its own Relayout does this);
			// the shrinkage area at the bottom of div2;
			// and the area computed because div2 moved.
			VerifyExpectedRectangle(site.RectsInvalidatedInRoot, 0, 48, 144, 48); // old box2
			VerifyExpectedRectangle(site.RectsInvalidatedInRoot, 0, 48 + 24, 144, 24); // shrinkage of div1
			// This is from the new top of div2 to its old bottom (old bottom was 48 + 48 + 24 + 24)
			VerifyExpectedRectangle(site.RectsInvalidatedInRoot, 0, 48 + 24, 144, 48 + 24);

			site.RectsInvalidated.Clear();
			box2.UpdateSize(108000, 72000);
			Assert.That(root.Height, Is.EqualTo(48 + 96 + 24 + 24)); // new larger value
			Assert.That(root.Width, Is.EqualTo(144)); //  unchanged this time
			// It got longer. We want an optimized invalidate rectangle that does not
			// include the top box. But it must include the space at the bottom where the root box grew.
			// There are other possible implementations, but currently, we expect the old rectangle of box2
			// to be invalidated (it returns true from Relayout);
			// the growth area at the bottom of div2;
			// and the area computed because div2 moved.
			VerifyExpectedRectangle(site.RectsInvalidatedInRoot, 0, 48, 144, 96); // new box2
			VerifyExpectedRectangle(site.RectsInvalidatedInRoot, 0, 48 + 24, 144, 96 - 24); // new part of div1 occupied by box2
			// This is from the old top of div2 to its new bottom (48 + 96 + 24 + 24)
			VerifyExpectedRectangle(site.RectsInvalidatedInRoot, 0, 48 + 24, 144, 96 + 24);
		}
Exemplo n.º 43
0
 /// <summary>
 /// Draw the selection on the VwGraphics.
 /// </summary>
 internal abstract void Draw(IVwGraphics vg, PaintTransform ptrans);
Exemplo n.º 44
0
		/// <summary>
		/// Draw the selection on the VwGraphics.
		/// </summary>
		internal abstract void Draw(IVwGraphics vg, PaintTransform ptrans);
Exemplo n.º 45
0
        public void ParaSequenceTest()
        {
            var owner      = new MockData1(55, 77);
            var styles     = new AssembledStyles();
            var root       = new RootBoxFdo(styles);
            var layoutInfo = MakeLayoutInfo(int.MaxValue / 2, m_gm.VwGraphics, 55);

            SetupFakeRootSite(root);
            var      engine  = layoutInfo.RendererFactory.GetRenderer(55, m_gm.VwGraphics) as FakeRenderEngine;
            MockSite site    = new MockSite();
            int      topLazy = 0;        // top of the part of the root box that is occupied by the lazy stuff, relative to the top of the root box itself.

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

            site.m_transform  = ptrans;
            site.m_vwGraphics = m_gm.VwGraphics;
            root.Builder.Show(LazyDisplay.Of(() => owner.ObjSeq1).Using((bldr, md) => bldr.AddString(() => md.SimpleThree, 55)));
            var heightOfOneItem = layoutInfo.MpToPixelsY(LazyBox <MockData1> .DefaultItemHeight * 1000);

            // This does two things: it makes sure the boxes produced by expanding a lazy box item won't be the SAME size,
            // so we'll get nontrivial changes in root box size; and it makes sure we don't have to expand MORE items than
            // expected based on the height estimate, which could throw off our predictions of what gets expanded.
            // Todo: we need a test where we DO have to expand more items after the initial estimate.
            engine.SegmentHeight = heightOfOneItem + 2;
            root.Layout(layoutInfo);
            VerifyParagraphs(root, new string[0]);

            var child1       = new MockData1(55, 77);
            var child1String = "Hello world, this is a wide string";

            child1.SimpleThree = child1String;
            owner.InsertIntoObjSeq1(0, child1);
            Assert.That(root.FirstBox, Is.TypeOf(typeof(LazyBox <MockData1>)));
            var lazyBox = (LazyBox <MockData1>)root.FirstBox;

            Assert.That(lazyBox.Width, Is.EqualTo(int.MaxValue / 2));             // no margins, should equal avail width.
            Assert.That(lazyBox.Height, Is.EqualTo(heightOfOneItem));
            var lazyTop             = lazyBox.Top;
            var lazyBottom          = lazyBox.Bottom;
            var oldRootHeight       = root.Height;
            int invalidateWidth     = lazyBox.Width + 2 * RootBox.InvalidateMargin;
            var expectedInvalidate1 = new Rectangle(-RootBox.InvalidateMargin, -RootBox.InvalidateMargin,
                                                    invalidateWidth,
                                                    lazyBox.Height + 2 * RootBox.InvalidateMargin);

            Assert.That(site.RectsInvalidatedInRoot, Has.Member(expectedInvalidate1));
            site.RectsInvalidatedInRoot.Clear();
            var lazyHookup = ((IHookup)lazyBox).ParentHookup as LazyHookup <MockData1>;

            Assert.That(lazyHookup, Is.Not.Null);
            Assert.That(lazyHookup.Children[0], Is.EqualTo(lazyBox));
            Assert.That(lazyHookup.Children, Has.Count.EqualTo(1));
            root.LazyExpanded += root_LazyExpanded;
            using (var lc = new LayoutCallbacks(root))
            {
                root.PrepareToPaint(layoutInfo, null, 0, 200);
            }
            VerifyParagraphs(root, new [] { child1String });
            Assert.That(child1.SimpleThreeHookupCount, Is.EqualTo(1), "expanding lazy box should set up a hookup for the string");
            Assert.That(site.RectsInvalidatedInRoot, Is.Empty, "we don't need to invalidate expanding something that's never been painted");
            VerifyExpandArgs(0, lazyTop + 2, lazyBottom + 2, root.Height - oldRootHeight);
            Assert.That(lazyHookup.Children, Has.Count.EqualTo(1));
            Assert.That(lazyHookup.Children[0], Is.TypeOf(typeof(ItemHookup)), "the lazy box standing for item hookups should have been replaced");

            // Now replace that one object with a list of several. I want to be able to expand two at the start, one at the end,
            // and one in the middle, and leave two lazy boxes behind. Then expand the rest and make them go away. So I need six.
            var values = new MockData1[10];

            for (int i = 0; i < 10; i++)
            {
                values[i]             = new MockData1(55, 77);
                values[i].SimpleThree = i.ToString();
            }
            var newValues = values.Take(6).ToArray();

            site.RectsInvalidatedInRoot.Clear();
            int phase2RootHeight = root.Height;
            int phase2RootWidth  = root.Width;

            owner.ReplaceObjSeq1(newValues);
            var expectedInvalidate2 = new Rectangle(-RootBox.InvalidateMargin, -RootBox.InvalidateMargin,
                                                    phase2RootWidth + 2 * RootBox.InvalidateMargin,
                                                    phase2RootHeight + 2 * RootBox.InvalidateMargin);

            Assert.That(site.RectsInvalidatedInRoot, Has.Member(expectedInvalidate2), "should invalidate the old replaced paragraph.");
            lazyBox = (LazyBox <MockData1>)root.FirstBox;
            Assert.That(lazyBox.Width, Is.EqualTo(int.MaxValue / 2));             // no margins, should equal avail width.
            Assert.That(root.LastBox, Is.EqualTo(lazyBox), "old paragraph should have been replaced");
            Assert.That(lazyHookup.Children[0], Is.EqualTo(lazyBox), "after second replace we just have the lazy box");
            Assert.That(lazyHookup.Children, Has.Count.EqualTo(1), "should not have anything but lazy box after second replace");
            Assert.That(lazyBox.Height, Is.EqualTo(6 * heightOfOneItem));

            // Make it expand the first two items.
            site.RectsInvalidatedInRoot.Clear();
            m_expandArgs.Clear();
            oldRootHeight = root.Height;
            using (var lc = new LayoutCallbacks(root))
            {
                root.PrepareToPaint(layoutInfo, null, 0, heightOfOneItem * 2 - 2);
            }
            VerifyParagraphs(root, new[] { "0", "1", null });             // Should have two paras then lazy box
            Assert.That(newValues[0].SimpleThreeHookupCount, Is.EqualTo(1), "expanding lazy box should set up a hookup for the string");
            Assert.That(newValues[1].SimpleThreeHookupCount, Is.EqualTo(1), "expanding lazy box should set up a hookup for the string");
            Assert.That(site.RectsInvalidatedInRoot, Is.Empty, "we don't need to invalidate expanding something that's never been painted");
            Assert.That(root.Height, Is.Not.EqualTo(oldRootHeight));
            VerifyExpandArgs(0, 2, heightOfOneItem * 2 + 2, root.Height - oldRootHeight);             // +2's from root layout offset
            Assert.That(lazyHookup.Children, Has.Count.EqualTo(3));
            Assert.That(lazyHookup.Children[0], Is.TypeOf(typeof(ItemHookup)), "a regular item hookup for the first expanded item should be inserted");
            Assert.That(lazyHookup.Children[1], Is.TypeOf(typeof(ItemHookup)), "a regular item hookup for the 2nd expanded item should be inserted");
            Assert.That(lazyHookup.Children[2], Is.TypeOf(typeof(LazyBox <MockData1>)), "the lazy box standing for item hookups should still be there");
            lazyBox = root.FirstBox.Next.Next as LazyBox <MockData1>;
            Assert.That(lazyBox, Is.Not.Null);
            Assert.That(lazyBox.Height, Is.EqualTo(heightOfOneItem * 4));

            int topOfLastItem = lazyBox.Bottom - heightOfOneItem + 2;

            // Make it expand the last item.
            site.RectsInvalidatedInRoot.Clear();
            m_expandArgs.Clear();
            oldRootHeight = root.Height;
            using (var lc = new LayoutCallbacks(root))
            {
                root.PrepareToPaint(layoutInfo, null, topOfLastItem + 2, topOfLastItem + 10);
            }
            VerifyParagraphs(root, new[] { "0", "1", null, "5" });             // Should have two paras then lazy box then last para
            Assert.That(newValues[5].SimpleThreeHookupCount, Is.EqualTo(1), "expanding lazy box should set up a hookup for the string");
            Assert.That(site.RectsInvalidatedInRoot, Is.Empty, "we don't need to invalidate expanding something that's never been painted");
            Assert.That(root.Height, Is.Not.EqualTo(oldRootHeight));
            VerifyExpandArgs(0, topOfLastItem, topOfLastItem + heightOfOneItem, root.Height - oldRootHeight);
            Assert.That(lazyHookup.Children, Has.Count.EqualTo(4));
            Assert.That(lazyHookup.Children[0], Is.TypeOf(typeof(ItemHookup)), "a regular item hookup for the first expanded item should be inserted");
            Assert.That(lazyHookup.Children[1], Is.TypeOf(typeof(ItemHookup)), "a regular item hookup for the 2nd expanded item should be inserted");
            Assert.That(lazyHookup.Children[2], Is.TypeOf(typeof(LazyBox <MockData1>)), "the lazy box standing for item hookups should still be there");
            Assert.That(lazyHookup.Children[3], Is.TypeOf(typeof(ItemHookup)), "a regular item hookup for the last expanded item should be inserted");
            lazyBox = root.FirstBox.Next.Next as LazyBox <MockData1>;
            Assert.That(lazyBox, Is.Not.Null);
            Assert.That(lazyBox.Height, Is.EqualTo(heightOfOneItem * 3));

            // Expand middle item in lazy box, leaving two lazy boxes.
            int topOfMiddleItem = lazyBox.Top + heightOfOneItem + 2;

            site.RectsInvalidatedInRoot.Clear();
            m_expandArgs.Clear();
            oldRootHeight = root.Height;
            using (var lc = new LayoutCallbacks(root))
            {
                root.PrepareToPaint(layoutInfo, null, topOfMiddleItem + 2, topOfMiddleItem + 10);
            }
            VerifyParagraphs(root, new[] { "0", "1", null, "3", null, "5" });             // Should have two paras then lazy box then middle para then another lazy then last para
            Assert.That(newValues[3].SimpleThreeHookupCount, Is.EqualTo(1), "expanding lazy box should set up a hookup for the string");
            Assert.That(site.RectsInvalidatedInRoot, Is.Empty, "we don't need to invalidate expanding something that's never been painted");
            Assert.That(root.Height, Is.Not.EqualTo(oldRootHeight));
            VerifyExpandArgs(0, topOfMiddleItem, topOfMiddleItem + heightOfOneItem, root.Height - oldRootHeight);
            Assert.That(lazyHookup.Children, Has.Count.EqualTo(6));
            Assert.That(lazyHookup.Children[0], Is.TypeOf(typeof(ItemHookup)), "a regular item hookup for the first expanded item should be inserted");
            Assert.That(lazyHookup.Children[1], Is.TypeOf(typeof(ItemHookup)), "a regular item hookup for the 2nd expanded item should be inserted");
            Assert.That(lazyHookup.Children[2], Is.TypeOf(typeof(LazyBox <MockData1>)), "the lazy box standing for item hookups should still be there");
            Assert.That(lazyHookup.Children[3], Is.TypeOf(typeof(ItemHookup)), "a regular item hookup for the last expanded item should be inserted");
            Assert.That(lazyHookup.Children[4], Is.TypeOf(typeof(LazyBox <MockData1>)), "the lazy box standing for item hookups should still be there");
            Assert.That(lazyHookup.Children[5], Is.TypeOf(typeof(ItemHookup)), "a regular item hookup for the last expanded item should be inserted");
            lazyBox = root.FirstBox.Next.Next as LazyBox <MockData1>;
            Assert.That(lazyBox, Is.Not.Null);
            Assert.That(lazyBox.Height, Is.EqualTo(heightOfOneItem));
            var lazyBox2 = lazyBox.Next.Next as LazyBox <MockData1>;

            Assert.That(lazyBox2, Is.Not.Null);
            Assert.That(lazyBox2.Height, Is.EqualTo(heightOfOneItem));
            // Expand lazy box when it is between two other items. (Also verify expanding two lazy boxes in one PrepareToPaint.)
            int topOfFirstLazy = lazyBox.Top + 2;
            int topOfLastLazy  = lazyBox2.Top + 2;

            site.RectsInvalidatedInRoot.Clear();
            m_expandArgs.Clear();
            oldRootHeight = root.Height;
            using (var lc = new LayoutCallbacks(root))
            {
                root.PrepareToPaint(layoutInfo, null, topOfFirstLazy + 2, topOfLastLazy + 2);
            }
            VerifyParagraphs(root, new[] { "0", "1", "2", "3", "4", "5" });             // Should have all the real paragraphs now.
            Assert.That(newValues[2].SimpleThreeHookupCount, Is.EqualTo(1), "expanding lazy box should set up a hookup for the string");
            Assert.That(newValues[4].SimpleThreeHookupCount, Is.EqualTo(1), "expanding lazy box should set up a hookup for the string");
            Assert.That(site.RectsInvalidatedInRoot, Is.Empty, "we don't need to invalidate expanding something that's never been painted");
            Assert.That(root.Height, Is.Not.EqualTo(oldRootHeight));
            var delta = engine.SegmentHeight - heightOfOneItem;

            VerifyExpandArgs(0, topOfFirstLazy, topOfFirstLazy + heightOfOneItem, delta);
            VerifyExpandArgs(1, topOfLastLazy + delta, topOfLastLazy + delta + heightOfOneItem, delta);
            Assert.That(lazyHookup.Children, Has.Count.EqualTo(6));
            Assert.That(lazyHookup.Children[0], Is.TypeOf(typeof(ItemHookup)), "a regular item hookup for the first expanded item should be inserted");
            Assert.That(lazyHookup.Children[1], Is.TypeOf(typeof(ItemHookup)), "a regular item hookup for the 2nd expanded item should be inserted");
            Assert.That(lazyHookup.Children[2], Is.TypeOf(typeof(ItemHookup)), "a regular item hookup for the 3rd expanded item should be inserted");
            Assert.That(lazyHookup.Children[3], Is.TypeOf(typeof(ItemHookup)), "a regular item hookup for the 4th expanded item should be inserted");
            Assert.That(lazyHookup.Children[4], Is.TypeOf(typeof(ItemHookup)), "a regular item hookup for the 5th expanded item should be inserted");
            Assert.That(lazyHookup.Children[5], Is.TypeOf(typeof(ItemHookup)), "a regular item hookup for the last expanded item should be inserted");

            // Now try removing the first two items.
            site.RectsInvalidatedInRoot.Clear();
            int heightOfFirst2Paras = root.FirstBox.Next.Bottom - root.FirstBox.Top;
            int phase3RootWidth     = root.Width;
            int phase3RootHeight    = root.Height;
            var phase3Values        = newValues.Skip(2).ToArray();

            owner.ReplaceObjSeq1(phase3Values);
            var expectedInvalidate3 = new Rectangle(-RootBox.InvalidateMargin, -RootBox.InvalidateMargin,
                                                    phase3RootWidth + 2 * RootBox.InvalidateMargin,
                                                    phase3RootHeight + 2 * RootBox.InvalidateMargin);

            Assert.That(site.RectsInvalidatedInRoot, Has.Member(expectedInvalidate3), "should invalidate the whole old root box; everything changes or moves.");
            VerifyParagraphs(root, new[] { "2", "3", "4", "5" });            // Should have last 4 paragraphs now (not made lazy).

            // Now try removing the last item.
            site.RectsInvalidatedInRoot.Clear();
            int phase4RootWidth = root.Width;
            var phase4Values    = phase3Values.Take(3).ToArray();
            var topOfPara4      = root.FirstBox.Next.Next.Bottom + topLazy;

            owner.ReplaceObjSeq1(phase4Values);
            var expectedInvalidate4 = new Rectangle(-RootBox.InvalidateMargin, topOfPara4 - RootBox.InvalidateMargin,
                                                    phase4RootWidth + 2 * RootBox.InvalidateMargin,
                                                    root.FirstBox.Height + 2 * RootBox.InvalidateMargin);

            Assert.That(site.RectsInvalidatedInRoot, Has.Member(expectedInvalidate4), "should invalidate the old replaced paragraphs.");
            VerifyParagraphs(root, new[] { "2", "3", "4" });             // Should have last 3 paragraphs now (not made lazy).

            // Now try removing a middle item.
            site.RectsInvalidatedInRoot.Clear();
            int phase5RootWidth  = root.Width;
            var phase5Values     = new [] { newValues[2], newValues[4] };
            var topOfPara3       = root.FirstBox.Bottom + topLazy;
            var phase4RootHeight = root.Height;

            owner.ReplaceObjSeq1(phase5Values);
            var expectedInvalidate5 = new Rectangle(-RootBox.InvalidateMargin, topOfPara3 - RootBox.InvalidateMargin,
                                                    phase5RootWidth + 2 * RootBox.InvalidateMargin,
                                                    phase4RootHeight - topOfPara3 + 2 * RootBox.InvalidateMargin);

            Assert.That(site.RectsInvalidatedInRoot, Has.Member(expectedInvalidate5), "should invalidate the old replaced paragraphs.");
            VerifyParagraphs(root, new[] { "2", "4" });             // Should have remaining 2 paragraphs now (not made lazy).

            // Insert three items at start: 0, 1, 3, 2, 4.
            site.RectsInvalidatedInRoot.Clear();
            int phase6RootWidth = root.Width;
            var phase6Values    = new[] { newValues[0], newValues[1], newValues[3], newValues[2], newValues[4] };

            owner.ReplaceObjSeq1(phase6Values);
            int lazyWidth           = root.LastLayoutInfo.MaxWidth;   // current standard width for lazy boxes.
            var expectedInvalidate6 = new Rectangle(-RootBox.InvalidateMargin, topLazy - RootBox.InvalidateMargin,
                                                    lazyWidth + 2 * RootBox.InvalidateMargin,
                                                    root.Height + 2 * RootBox.InvalidateMargin);

            Assert.That(site.RectsInvalidatedInRoot, Has.Member(expectedInvalidate6), "should invalidate everything...all moved or added.");
            VerifyParagraphs(root, new[] { null, "2", "4" });            // Should have added lazy box at start.
            VerifyLazyContents(root.FirstBox, new[] { newValues[0], newValues[1], newValues[3] });

            // Insert at end: 0, 1, 3, 2, 4, 9. I think we've tested the invalidate rects enough.
            var phase7Values = new[] { values[0], values[1], values[3], values[2], values[4], values[9] };

            owner.ReplaceObjSeq1(phase7Values);
            VerifyParagraphs(root, new[] { null, "2", "4", null });             // Should have added lazy box at end.
            VerifyLazyContents(root.LastBox, new[] { values[9] });
            // Insert between two non-lazy items: 0, 1, 3, 2, 5, 6, 4, 9.
            var phase8Values = new[] { values[0], values[1], values[3], values[2], values[5], values[6], values[4], values[9] };

            owner.ReplaceObjSeq1(phase8Values);
            VerifyParagraphs(root, new[] { null, "2", null, "4", null });             // Should have added lazy box in middle.
            VerifyLazyContents(root.FirstBox.Next.Next, new[] { values[5], values[6] });
            // Try a more complex overwrite. We'll replace the last item in the first lazy box and the first one in the second
            var phase9Values = new[] { values[0], values[1], values[7], values[2], values[8], values[6], values[4], values[9] };

            owner.ReplaceObjSeq1(phase9Values);
            VerifyParagraphs(root, new[] { null, "4", null });             // Should replace first 3 items with new lazy box.
            VerifyLazyContents(root.FirstBox, new[] { values[0], values[1], values[7], values[2], values[8], values[6] });
        }
Exemplo n.º 46
0
		private void VerifyPaint(RootBox root, Rectangle clipRect, int xScrollOffset, int yScrollOffset, Rectangle[] paintRects)
		{
			MockGraphics graphics = new MockGraphics();
			graphics.ClipRectangle = clipRect;
			PaintTransform ptrans = new PaintTransform(0, 0, 96, 96, xScrollOffset, yScrollOffset, 96, 96);
			root.Paint(graphics, ptrans);
			var drawActions = graphics.DrawActions; // after the paint, it gets created when first rect added.
			if (paintRects == null || paintRects.Length == 0)
			{
				Assert.IsTrue(drawActions == null || drawActions.Count == 0);
				return;
			}
			Assert.That(drawActions, Has.Count.EqualTo(paintRects.Length * 2));
			int position = 0;
			// First all the blocks get drawn in their PaintBackground routine
			foreach (var rect in paintRects)
			{
				VerifyRect(drawActions, ref position, rect);
			}
			// Then we verify that the PaintForeground routines got called.
			for (; position < drawActions.Count; position++)
				Assert.That(drawActions[position], Is.InstanceOf(typeof(FgBlockBox)));
		}
Exemplo n.º 47
0
		public void BasicDragMove()
		{
			var styles = new AssembledStyles();
			var root = new RootBoxFdo(styles);
			var mock1 = new MockData1(23, 23);
			mock1.SimpleThree = "This is the day";
			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;

			SelectionBuilder.In(root).Offset("This ".Length).To.Offset("This is ".Length).Install();

			var dataObj = new DataObject(DataFormats.StringFormat, "is ");
			int x = FakeRenderEngine.SimulatedWidth("This is the ") + 2;
			var location = new Point(x, 8);

			// A drag to where we can drop, allowing both copy and move, no keys held
			var dragArgs = new DragEventArgs(dataObj, (int)DragDropKeyStates.None, 200, 300,
				DragDropEffects.Copy | DragDropEffects.Move,
				DragDropEffects.None);
			root.OnDragEnter(dragArgs, location, m_gm.VwGraphics, ptrans);
			Assert.That(dragArgs.Effect, Is.EqualTo(DragDropEffects.Move));
			Assert.That(root.DragState, Is.EqualTo(WindowDragState.DraggingHere));

			var qcdArgs = new QueryContinueDragEventArgs((int) DragDropKeyStates.None, false, DragAction.Drop);
			root.OnQueryContinueDrag(qcdArgs);
			Assert.That(root.DragState, Is.EqualTo(WindowDragState.InternalMove));
			root.OnDragLeave();
			Assert.That(root.DragState, Is.EqualTo(WindowDragState.InternalMove), "DragLeave should not clear InternalMove");

			root.OnDragDrop(dragArgs, location, m_gm.VwGraphics, ptrans);
			Assert.That(mock1.SimpleThree, Is.EqualTo("This the is day"));
			Assert.That(root.DragState, Is.EqualTo(WindowDragState.None));

			// Now let's drag the 'is' out to another window.
			SelectionBuilder.In(root).Offset("This the ".Length).To.Offset("This the is ".Length).Install();
			qcdArgs = new QueryContinueDragEventArgs((int)DragDropKeyStates.None, false, DragAction.Drop);
			root.OnQueryContinueDrag(qcdArgs);
			Assert.That(root.DragState, Is.EqualTo(WindowDragState.None),
				"We should only set InternalMove if this window is the destination");
			Assert.That(mock1.SimpleThree, Is.EqualTo("This the day"));

			// Check that we can't drag inside our own selection.
			SelectionBuilder.In(root).Offset("This ".Length).To.Offset("This the".Length).Install();
			x = FakeRenderEngine.SimulatedWidth("This t") + 2;
			location = new Point(x, 8);
			dragArgs = new DragEventArgs(dataObj, (int)DragDropKeyStates.None, 200, 300,
							DragDropEffects.Copy | DragDropEffects.Move,
							DragDropEffects.None);
			root.DragState = WindowDragState.InternalMove;
			root.OnDragDrop(dragArgs, location, m_gm.VwGraphics, ptrans);
			Assert.That(dragArgs.Effect, Is.EqualTo(DragDropEffects.None));
			Assert.That(mock1.SimpleThree, Is.EqualTo("This the day"));
		}
Exemplo n.º 48
0
        public void ParaSequenceTest()
        {
            var owner      = new MockData1(55, 77);
            var styles     = new AssembledStyles();
            var root       = new RootBoxFdo(styles);
            var layoutInfo = MakeLayoutInfo(int.MaxValue / 2, m_gm.VwGraphics, 55);

            SetupFakeRootSite(root);
            var      engine = layoutInfo.RendererFactory.GetRenderer(55, m_gm.VwGraphics) as FakeRenderEngine;
            MockSite site   = new MockSite();

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

            site.m_transform  = ptrans;
            site.m_vwGraphics = m_gm.VwGraphics;
            root.Builder.Show(Display.Of(() => owner.ObjSeq1).Using((bldr, md) => bldr.AddString(() => md.SimpleThree, 55)));
            root.Layout(layoutInfo);
            VerifyParagraphs(root, new string[0]);
            //var seqHookup = new IndependentSequenceHookup<MockData1>(owner);

            // Tell seqHookup how to make a display of one MockData1:
            //  - make a paragraph
            //  - make it display the SimpleDataThree property of the item (editable)
            //  - Make an item hookup that knows about the paragraph and the StringHookup for SimpleDataThree
            //  - that hookup should be connected to the Item Hookup

            // Tell seqHookup how it relates to the root box
            //  - Somehow the item hookup for each item gets inserted into the right place in seqHookup's children,
            //  - and the paragraph for the item gets inserted into the right place in the rootbox.

            // Tell seqHookup to get its items from ObjSeq1 and to listen for ObjSeq1Changed.

            // (Eventually I'd like to be able to do all the above something like this:
            // root.Builder.AddObjSeq(()=>owner.ObjSeq1, (md, bldr)=>bldr.AddString(()=>md.SimpleThree);

            // Insert the first item into owner.ObjSeq1 and check all the right connections appear
            var child1       = new MockData1(55, 77);
            var child1String = "Hello world, this is a wide string";

            child1.SimpleThree = child1String;
            owner.InsertIntoObjSeq1(0, child1);
            // The first string we insert is deliberately the widest. After that, the width of the pile
            // remains constant, allowing us to test smarter, smaller invalidate rectangles; when the width
            // changes we invalidate the whole pile.
            VerifyParagraphs(root, new string[] { child1String });
            Assert.That(child1.SimpleThreeHookupCount, Is.EqualTo(1), "Builder.AddString should set up a hookup for the string");
            int invalidateWidth     = FakeRenderEngine.SimulatedWidth(child1String) + 2 * RootBox.InvalidateMargin;
            var expectedInvalidate1 = new Rectangle(-RootBox.InvalidateMargin, -RootBox.InvalidateMargin,
                                                    invalidateWidth,
                                                    engine.SegmentHeight + 2 * RootBox.InvalidateMargin);

            Assert.That(site.RectsInvalidatedInRoot, Has.Member(expectedInvalidate1));

            // Insert a second item and check again.
            var child2 = new MockData1(55, 77);

            child2.SimpleThree = "Another world";
            site.RectsInvalidated.Clear();
            owner.InsertIntoObjSeq1(1, child2);
            VerifyParagraphs(root, new string[] { child1String, "Another world" });
            Assert.That(child2.SimpleThreeHookupCount, Is.EqualTo(1), "Builder.AddString should set up a hookup for the string");
            var expectedInvalidate2 = new Rectangle(-RootBox.InvalidateMargin,
                                                    engine.SegmentHeight - RootBox.InvalidateMargin,
                                                    invalidateWidth,
                                                    engine.SegmentHeight + 2 * RootBox.InvalidateMargin);

            Assert.That(site.RectsInvalidatedInRoot, Has.Member(expectedInvalidate2));

            // Insert a third item between the first two.
            var child3 = new MockData1(55, 77);

            child3.SimpleThree = "Inserted world";
            owner.InsertIntoObjSeq1(1, child3);
            VerifyParagraphs(root, new string[] { child1String, "Inserted world", "Another world" });
            var expectedInvalidate3 = new Rectangle(-RootBox.InvalidateMargin,
                                                    engine.SegmentHeight - RootBox.InvalidateMargin,
                                                    invalidateWidth,
                                                    engine.SegmentHeight * 2 + 2 * RootBox.InvalidateMargin);

            Assert.That(site.RectsInvalidatedInRoot, Has.Member(expectedInvalidate3));

            // Insert a fourth item at the start.
            var child4 = new MockData1(55, 77);

            child4.SimpleThree = "Beginning of world";
            owner.InsertIntoObjSeq1(0, child4);
            VerifyParagraphs(root, new string[] { "Beginning of world", child1String, "Inserted world", "Another world" });
            var expectedInvalidate4 = new Rectangle(-RootBox.InvalidateMargin,
                                                    -RootBox.InvalidateMargin,
                                                    invalidateWidth,
                                                    engine.SegmentHeight * 4 + 2 * RootBox.InvalidateMargin);

            Assert.That(site.RectsInvalidatedInRoot, Has.Member(expectedInvalidate4));

            // Delete the first item.
            //var topHookup = root.RootHookup as IndependentSequenceHookup<MockData1>;
            //Assert.That(topHookup, Is.Not.Null);
            owner.RemoveAtObjSeq1(0);
            VerifyParagraphs(root, new string[] { child1String, "Inserted world", "Another world" });
            Assert.That(child4.SimpleThreeHookupCount, Is.EqualTo(0), "The hookup for a deleted object should be disposed.");
            Assert.That(site.RectsInvalidatedInRoot, Has.Member(expectedInvalidate4));

            // Delete a middle item.
            owner.RemoveAtObjSeq1(1);
            VerifyParagraphs(root, new string[] { child1String, "Another world" });
            Assert.That(child3.SimpleThreeHookupCount, Is.EqualTo(0), "The hookup for a deleted object should be disposed.");
            Assert.That(site.RectsInvalidatedInRoot, Has.Member(expectedInvalidate3));

            // Delete the last item.
            owner.RemoveAtObjSeq1(1);
            VerifyParagraphs(root, new string[] { child1String });
            Assert.That(child2.SimpleThreeHookupCount, Is.EqualTo(0), "The hookup for a deleted object should be disposed.");
            Assert.That(site.RectsInvalidatedInRoot, Has.Member(expectedInvalidate2));

            // Delete the only remaining item.
            owner.RemoveAtObjSeq1(0);
            VerifyParagraphs(root, new string[0]);
            Assert.That(child1.SimpleThreeHookupCount, Is.EqualTo(0), "The hookup for a deleted object should be disposed.");
            Assert.That(site.RectsInvalidatedInRoot, Has.Member(expectedInvalidate1));

            // Eventually add some operations that allow inserting and deleting multiple items.

            // We also need to be able to insert two or more object sequences into the same containing box.
            // That's probably another test, perhaps a view of the root where for each data item,
            // we insert its subitems, then for those insert paragraphs.
            // Let's assume there's always one top-level hookup for the root.
        }
Exemplo n.º 49
0
        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"));
        }
Exemplo n.º 50
0
 internal override void Draw(IVwGraphics vg, PaintTransform ptrans)
 {
     VgUsedToDraw        = vg;
     TransformUsedToDraw = ptrans;
 }
Exemplo n.º 51
0
		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"));
		}
Exemplo n.º 52
0
        public void NumericSurrogates()
        {
            var styles = new AssembledStyles();
            var root   = new RootBoxFdo(styles);
            var mock1  = new MockData1(23, 23);

            mock1.SimpleThree = "new o" + NumericSurrogatePair + "ld contents";
            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)));
            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 ol") + 2;
            var            location = new Point(x, 8);
            EventArgs      e        = new EventArgs();
            MouseEventArgs m        = new MouseEventArgs(MouseButtons.Left, 1, location.X, location.Y, 0);
            string         test     = "o" + NumericSurrogatePair + "ld ";

            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(test));

            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(test));

            x        = FakeRenderEngine.SimulatedWidth("new old") + 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(test));

            mock1.SimpleThree = "new " + NumericSurrogatePair + " contents";
            x        = FakeRenderEngine.SimulatedWidth("new o") + 2;
            location = new Point(x, 8);
            m        = new MouseEventArgs(MouseButtons.Left, 1, location.X, location.Y, 0);
            test     = NumericSurrogatePair + " ";

            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(test));

            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(test));
        }
Exemplo n.º 53
0
        public override void PaintBackground(IVwGraphics vg, PaintTransform ptrans)
        {
            // Review JohnT: do we want to allow individual strings to paint borders etc? Should we call base?
            // base.PaintBackground(vg, ptrans);
            if (Segment == null)
            {
                return;
            }

            int            dxdWidth;
            PaintTransform segTrans = ptrans.PaintTransformOffsetBy(Left, Top);

            // Ideally, we'd just draw the background, but we don't have that capability currently.
            // The current implementation of DrawTextNoBackground does a good job of redrawing
            // the foreground text, even if it's already been painted.
            if (AnyColoredBackground)
            {
                Segment.DrawText(IchMin, vg, segTrans.SourceRect, segTrans.DestRect, out dxdWidth);
            }
            int dichLim   = Segment.get_Lim(IchMin);
            int ichLim    = IchMin + dichLim;
            int ichMinRun = IchMin;
            int ichLimRun;
            int dydOffset = Math.Max(1, segTrans.DpiY / 96);           // distance between double underline, also up and down for squiggle.

            for (; ichMinRun < ichLim; ichMinRun = ichLimRun)
            {
                int clrUnder;
                var unt = Paragraph.Source.GetUnderlineInfo(ichMinRun, out clrUnder, out ichLimRun);
                ichLimRun = Math.Min(ichLimRun, ichLim);
                Debug.Assert(ichLimRun > ichMinRun);
                if (unt == FwUnderlineType.kuntNone)
                {
                    continue;
                }
                // Get info about where to draw underlines for this run
                //int ydApproxUnderline = rcSrcChild.MapYTo(psbox->Ascent(), rcDst);
                //// GetCharPlacement seems to be the really expensive part of underlining; don't do it
                //// if the underline is nowhere near the clip rectangle. Times 2 and times 3 are both one more multiple
                //// than typically needed.
                //if (ydApproxUnderline - dydOffset * 2 < ydTopClip - 1 || ydApproxUnderline + dydOffset * 3 > ydBottomClip + 1)
                //    continue;
                int[] lefts, rights, tops;
                int   cxd;
                Segment.GetCharPlacement(IchMin, vg, ichMinRun,
                                         ichLimRun, segTrans.SourceRect, segTrans.DestRect, true, 0, out cxd,
                                         null, null, null);
                using (var rgxdLefts = MarshalEx.ArrayToNative <int>(cxd))
                    using (var rgxdRights = MarshalEx.ArrayToNative <int>(cxd))
                        using (var rgydTops = MarshalEx.ArrayToNative <int>(cxd))
                        {
                            Segment.GetCharPlacement(IchMin, vg, ichMinRun,
                                                     ichLimRun, segTrans.SourceRect, segTrans.DestRect, true, cxd, out cxd,
                                                     rgxdLefts, rgxdRights, rgydTops);
                            lefts  = MarshalEx.NativeToArray <int>(rgxdLefts, cxd);
                            rights = MarshalEx.NativeToArray <int>(rgxdRights, cxd);
                            tops   = MarshalEx.NativeToArray <int>(rgydTops, cxd);
                        }
                for (int ixd = 0; ixd < cxd; ixd++)
                {
                    // top of underline 1 pixel below baseline
                    int ydDrawAt = tops[ixd];
                    // underline is drawn at most one offset above ydDrawAt and at most 2 offsets below.
                    // Skip the work if it is clipped.
                    //if (ydDrawAt - dydOffset < ydBottomClip + 1 && ydDrawAt + dydOffset * 2 > ydTopClip - 1)
                    //{
                    //int xLeft = max(rgxdLefts[ixd], xdLeftClip - 1);
                    //int xRight = min(rgxdRights[ixd], xdRightClip + 1);
                    int xLeft  = lefts[ixd];
                    int xRight = rights[ixd];
                    DrawUnderline(vg, xLeft, xRight, ydDrawAt,
                                  segTrans.DpiX / 96, dydOffset,
                                  clrUnder, unt, segTrans.XOffsetScroll);
                    //}
                }
            }
        }
Exemplo n.º 54
0
        public void ComplexRangeDrawing()
        {
            var string1 = "This is the day that the Lord has made.";
            var string2 = "We will rejoice and be glad in it.";
            var string3 = "Love the Lord your God with all your heart.";

            var engine = new FakeRenderEngine()
            {
                Ws = 34, SegmentHeight = 13
            };
            var factory = new FakeRendererFactory();

            factory.SetRenderer(34, engine);
            var runStyle = new AssembledStyles().WithWs(34);

            var lineHeightMp = 20000;
            var style        = new AssembledStyles().WithLineHeight(lineHeightMp);
            var root         = new RootBox(style);
            var para1        = MakePara(style, runStyle, string1);

            root.AddBox(para1);
            var div = new DivBox(style);

            root.AddBox(div);
            var para2 = MakePara(style, runStyle, string2);

            div.AddBox(para2);
            var para3 = MakePara(style, runStyle, string3);

            div.AddBox(para3);

            // This width makes each paragraph take three lines.
            var layoutArgs = new LayoutInfo(2, 2, 96, 96, FakeRenderEngine.SimulatedWidth("This is the day "), m_gm.VwGraphics, factory);

            root.Layout(layoutArgs);

            var ip1    = para1.SelectAt(1, false);
            var ip2    = para1.SelectAt(3, true);
            var range1 = new RangeSelection(ip1, ip2);

            Assert.That(range1.EndBeforeAnchor, Is.False);
            Assert.That(range1.Start, Is.EqualTo(ip1));
            Assert.That(range1.End, Is.EqualTo(ip2));

            PaintTransform ptrans  = new PaintTransform(2, 2, 96, 96, 0, 0, 96, 96);
            var            sbox1_1 = para1.FirstBox as StringBox;

            range1.Draw(m_gm.VwGraphics, ptrans);
            int topOffset           = -2; // top of RcSrc for top of root box.
            int topYd               = 2;  // destination coord corresponding to top of root box.
            int leftXd              = 2;  // destination coord corresponding to left of root box.
            int bottomOfFirstLine   = topYd + engine.SegmentHeight;
            int lineHeight          = ptrans.MpToPixelsY(lineHeightMp);
            int bottomOfFirstHilite = bottomOfFirstLine + (lineHeight - engine.SegmentHeight) / 2;

            VerifyRangeSegmentDrawing(para1, sbox1_1, range1, topOffset, topYd, bottomOfFirstHilite);
            var sbox1_2 = sbox1_1.Next as StringBox;
            int bottomOfSecondHilite = bottomOfFirstHilite + lineHeight;

            VerifyRangeSegmentDrawing(para1, sbox1_2, range1, topOffset - lineHeight, bottomOfFirstHilite, bottomOfSecondHilite);
            var sbox1_3 = sbox1_2.Next as StringBox;
            int bottomOfThirddHilite = bottomOfSecondHilite + lineHeight - para1.Ascent;

            VerifyRangeSegmentDrawing(para1, sbox1_3, range1, topOffset - lineHeight * 2, bottomOfSecondHilite, bottomOfThirddHilite);

            // A two-line selection has much the same results.
            var ip3    = para1.SelectAt(sbox1_2.IchMin + 2, true);
            var range2 = new RangeSelection(ip1, ip3);

            range2.Draw(m_gm.VwGraphics, ptrans);
            VerifyRangeSegmentDrawing(para1, sbox1_1, range2, topOffset, topYd, bottomOfFirstHilite);
            VerifyRangeSegmentDrawing(para1, sbox1_2, range2, topOffset - lineHeight, bottomOfFirstHilite, bottomOfSecondHilite);
            VerifyRangeSegmentDrawing(para1, sbox1_3, range2, topOffset - lineHeight * 2, bottomOfSecondHilite, bottomOfThirddHilite);

            // Try multi-para selection in paras in same div.
            var ip2_3  = para2.SelectAt(3, false);
            var ip3_4  = para3.SelectAt(4, true);
            var range3 = new RangeSelection(ip2_3, ip3_4);

            range3.Draw(m_gm.VwGraphics, ptrans);
            var sbox2_1               = para2.FirstBox as StringBox;
            int topOfPara2            = topYd + para1.Height;
            int bottomOfFirstLineP2   = topOfPara2 + engine.SegmentHeight;
            int bottomOfFirstHiliteP2 = bottomOfFirstLineP2 + (lineHeight - engine.SegmentHeight) / 2;

            VerifyRangeSegmentDrawing(para2, sbox2_1, range3, topOffset - para1.Height, topOfPara2, bottomOfFirstHiliteP2);
            var sbox2_2 = sbox2_1.Next as StringBox;
            int bottomOfSecondHiliteP2 = bottomOfFirstHiliteP2 + lineHeight;

            VerifyRangeSegmentDrawing(para2, sbox2_2, range3, topOffset - para1.Height - lineHeight,
                                      bottomOfFirstHiliteP2, bottomOfSecondHiliteP2);
            var sbox2_3 = sbox2_2.Next as StringBox;
            int bottomOfThirddHiliteP2 = bottomOfSecondHiliteP2 + lineHeight - para2.Ascent;

            VerifyRangeSegmentDrawing(para2, sbox2_3, range3, topOffset - para1.Height - lineHeight * 2,
                                      bottomOfSecondHiliteP2, bottomOfThirddHiliteP2);
            var sbox3_1               = para3.FirstBox as StringBox;
            int topOfPara3            = topOfPara2 + para2.Height;
            var bottomOfFirstLineP3   = topOfPara3 + engine.SegmentHeight;
            var bottomOfFirstHiliteP3 = bottomOfFirstLineP3 + (lineHeight - engine.SegmentHeight) / 2;

            VerifyRangeSegmentDrawing(para3, sbox3_1, range3, topOffset - para1.Height - para2.Height, topOfPara3, bottomOfFirstHiliteP3);
            // Currently the other two segments of para3 will also be asked to draw it, but we've already checked how tops and bottoms
            // are worked out, and we don't care if these beyond-the-end segments draw it or not. Better not to test, then we can
            // optimize freely.

            // Now try a range that is (backwards and) across a div boundary
            var range4 = new RangeSelection(ip3_4, ip2);

            Assert.That(range4.EndBeforeAnchor, Is.True);
            Assert.That(range4.Start.SameLocation(ip2), Is.True);
            Assert.That(range4.End.SameLocation(ip3_4), Is.True);
            ClearSegmentDrawing(sbox1_3);
            ClearSegmentDrawing(sbox2_1);
            ClearSegmentDrawing(sbox3_1);
            range4.Draw(m_gm.VwGraphics, ptrans);
            // Several others should get drawn as well, but I think it's sufficient to verify tha something gets done correct in each para.
            VerifyRangeSegmentDrawing(para1, sbox1_3, range4, topOffset - lineHeight * 2, bottomOfSecondHilite, bottomOfThirddHilite);
            VerifyRangeSegmentDrawing(para2, sbox2_1, range4, topOffset - para1.Height, topOfPara2, bottomOfFirstHiliteP2);
            VerifyRangeSegmentDrawing(para3, sbox3_1, range4, topOffset - para1.Height - para2.Height, topOfPara3, bottomOfFirstHiliteP3);

            var range5 = new RangeSelection(ip2, ip3_4);

            Assert.That(range5.EndBeforeAnchor, Is.False);
            Assert.That(range5.Start.SameLocation(ip2), Is.True);
            Assert.That(range5.End.SameLocation(ip3_4), Is.True);

            // While we've got these selections, it's a good chance to check out GetSelectionLocation
            // The first one is a simple rectangle in the first string box.
            SetSelectionLocation(sbox1_1, 15, 20);
            Assert.That(range1.GetSelectionLocation(m_gm.VwGraphics, ptrans), Is.EqualTo(
                            new Rectangle(15, topYd, 20 - 15, bottomOfFirstHilite - topYd)));
            SetSelectionLocation(sbox1_2, 18, 25);
            Assert.That(range2.GetSelectionLocation(m_gm.VwGraphics, ptrans), Is.EqualTo(
                            new Rectangle(15, topYd, 25 - 15, bottomOfSecondHilite - topYd)));
            SetSelectionLocation(sbox3_1, 22, 27);
            Assert.That(range4.GetSelectionLocation(m_gm.VwGraphics, ptrans), Is.EqualTo(
                            new Rectangle(leftXd, topYd, para2.Width, bottomOfFirstHiliteP3 - topYd)));
        }
Exemplo n.º 55
0
		/// <summary>
		/// Get the location, in the coordinates indicated by the transform, of a rectangle that contains the
		/// primary insertion point.
		/// Todo JohnT: there should be a parallel routine to get the location of the secondary rectangle.
		/// </summary>
		public abstract Rectangle GetSelectionLocation(IVwGraphics graphics, PaintTransform transform);
Exemplo n.º 56
0
        public void BasicDragMove()
        {
            var styles = new AssembledStyles();
            var root   = new RootBoxFdo(styles);
            var mock1  = new MockData1(23, 23);

            mock1.SimpleThree = "This is the day";
            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;

            SelectionBuilder.In(root).Offset("This ".Length).To.Offset("This is ".Length).Install();

            var dataObj  = new DataObject(DataFormats.StringFormat, "is ");
            int x        = FakeRenderEngine.SimulatedWidth("This is the ") + 2;
            var location = new Point(x, 8);

            // A drag to where we can drop, allowing both copy and move, no keys held
            var dragArgs = new DragEventArgs(dataObj, (int)DragDropKeyStates.None, 200, 300,
                                             DragDropEffects.Copy | DragDropEffects.Move,
                                             DragDropEffects.None);

            root.OnDragEnter(dragArgs, location, m_gm.VwGraphics, ptrans);
            Assert.That(dragArgs.Effect, Is.EqualTo(DragDropEffects.Move));
            Assert.That(root.DragState, Is.EqualTo(WindowDragState.DraggingHere));

            var qcdArgs = new QueryContinueDragEventArgs((int)DragDropKeyStates.None, false, DragAction.Drop);

            root.OnQueryContinueDrag(qcdArgs);
            Assert.That(root.DragState, Is.EqualTo(WindowDragState.InternalMove));
            root.OnDragLeave();
            Assert.That(root.DragState, Is.EqualTo(WindowDragState.InternalMove), "DragLeave should not clear InternalMove");

            root.OnDragDrop(dragArgs, location, m_gm.VwGraphics, ptrans);
            Assert.That(mock1.SimpleThree, Is.EqualTo("This the is day"));
            Assert.That(root.DragState, Is.EqualTo(WindowDragState.None));

            // Now let's drag the 'is' out to another window.
            SelectionBuilder.In(root).Offset("This the ".Length).To.Offset("This the is ".Length).Install();
            qcdArgs = new QueryContinueDragEventArgs((int)DragDropKeyStates.None, false, DragAction.Drop);
            root.OnQueryContinueDrag(qcdArgs);
            Assert.That(root.DragState, Is.EqualTo(WindowDragState.None),
                        "We should only set InternalMove if this window is the destination");
            Assert.That(mock1.SimpleThree, Is.EqualTo("This the day"));

            // Check that we can't drag inside our own selection.
            SelectionBuilder.In(root).Offset("This ".Length).To.Offset("This the".Length).Install();
            x        = FakeRenderEngine.SimulatedWidth("This t") + 2;
            location = new Point(x, 8);
            dragArgs = new DragEventArgs(dataObj, (int)DragDropKeyStates.None, 200, 300,
                                         DragDropEffects.Copy | DragDropEffects.Move,
                                         DragDropEffects.None);
            root.DragState = WindowDragState.InternalMove;
            root.OnDragDrop(dragArgs, location, m_gm.VwGraphics, ptrans);
            Assert.That(dragArgs.Effect, Is.EqualTo(DragDropEffects.None));
            Assert.That(mock1.SimpleThree, Is.EqualTo("This the day"));
        }
Exemplo n.º 57
0
			public override void PaintForeground(IVwGraphics vg, PaintTransform ptrans)
			{
				((MockGraphics)vg).DrawActions.Add(this);
			}
Exemplo n.º 58
0
        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));
        }
Exemplo n.º 59
0
		public void NestedRowsLayout()
		{
			var styles = new AssembledStyles();
			var box1 = new LayoutInfoRecorderBox(styles, Color.Red, 72000, 36000);
			var box2 = new LayoutInfoRecorderBox(styles, Color.Blue, 108000, 18000);
			var box3 = new LayoutInfoRecorderBox(styles, Color.Orange, 72000, 18000);
			var box4 = new LayoutInfoRecorderBox(styles, Color.Orange, 72000, 18000);
			var widths = new FixedColumnWidths(new[] {34, 67, 99});
			// pass widths to RowBox constructor
			var row1 = new RowBox(styles, widths, false);
			var row2 = new RowBox(styles, widths, false);
			row1.AddBox(box1);
			row1.AddBox(box2);
			row2.AddBox(box3);
			row2.AddBox(box4);
			RootBox root = new RootBox(styles);
			root.AddBox(row1);
			root.AddBox(row2);
			LayoutInfo layoutArgs = MakeLayoutInfo();
			root.Layout(layoutArgs);
			Assert.That(box1.LastLayoutInfo.MaxWidth, Is.EqualTo(34));
			Assert.That(box1.Height, Is.EqualTo(48));
			Assert.That(box2.Height, Is.EqualTo(24));
			Assert.That(box3.Height, Is.EqualTo(24));
			Assert.That(box4.Height, Is.EqualTo(24));
			Assert.That(root.Height, Is.EqualTo(48 + 24));
			Assert.That(box1.Left, Is.EqualTo(0));
			Assert.That(box2.Left, Is.EqualTo(96));
			Assert.That(box3.Left, Is.EqualTo(0));
			Assert.That(box4.Left, Is.EqualTo(96));
			Assert.That(row1.Top, Is.EqualTo(0));
			Assert.That(box1.Top, Is.EqualTo(0));
			Assert.That(box2.Top, Is.EqualTo(0));
			Assert.That(row2.Top, Is.EqualTo(48));
			Assert.That(box3.Top, Is.EqualTo(0));
			Assert.That(box4.Top, Is.EqualTo(0));
			Assert.That(box1.Width, Is.EqualTo(96));
			Assert.That(box2.Width, Is.EqualTo(144));
			Assert.That(box3.Width, Is.EqualTo(96));
			Assert.That(box4.Width, Is.EqualTo(96));
			Assert.That(root.Width, Is.EqualTo(96 + 144));

			// Now try changing the size of a block.
			MockSite site = new MockSite();
			root.Site = site;
			PaintTransform ptrans = new PaintTransform(2, 4, 96, 96, 0, 10, 120, 128);
			site.m_transform = ptrans;
			site.m_vwGraphics = m_gm.VwGraphics;
			box2.UpdateSize(144000, 36000);
			Assert.That(box2.Width, Is.EqualTo(96 * 2));
			Assert.That(box2.Height, Is.EqualTo(48));
			Assert.That(row1.Height, Is.EqualTo(48));
			Assert.That(root.Height, Is.EqualTo(72));
			Assert.That(root.Width, Is.EqualTo(96 * 3));
			// Since it got both wider and higher, we should invalidate at least the whole current size.
			var bigInvalidate = root.InvalidateRect;
			Assert.That(site.RectsInvalidatedInRoot, Has.Member(bigInvalidate));

			site.RectsInvalidated.Clear();
			box2.UpdateSize(108000, 18000);
			Assert.That(root.Height, Is.EqualTo(48 + 24)); // unchanged this time
			Assert.That(root.Width, Is.EqualTo(96 + 144)); // narrower box2 still determines it
			// Got narrower, at least the whole old invalidate rectangle should be invalidated.
			Assert.That(site.RectsInvalidatedInRoot, Has.Member(bigInvalidate));

			site.RectsInvalidated.Clear();
			box2.UpdateSize(72000, 18000);
			Assert.That(root.Height, Is.EqualTo(48 + 24)); // unchanged this time
			Assert.That(root.Width, Is.EqualTo(144 + 48)); // new smaller value
			// It got thinner. We want an optimized invalidate rectangle that does not
			// include the left boxes. But it must include the space at the right that the root box used to occupy.
			// There are other possible implementations, but currently, we expect the old rectangle of box2
			// to be invalidated (it's in the fixmap so its own Relayout does this);
			// the shrinkage area at the right of row2;
			// and the area computed because row2 moved.
			//VerifyExpectedRectangle(site.RectsInvalidatedInRoot, 0, 48, 48, 144); // old box2
			//VerifyExpectedRectangle(site.RectsInvalidatedInRoot, 0, 48 + 24, 144, 24); // shrinkage of row1
			// This is from the new left of div2 to its old right (old right was 48 + 48 + 24 + 24)
			//VerifyExpectedRectangle(site.RectsInvalidatedInRoot, 0, 48 + 24, 144, 48 + 24);

			site.RectsInvalidated.Clear();
			box2.UpdateSize(144000, 18000);
			Assert.That(root.Height, Is.EqualTo(48 + 24)); //  unchanged this time
			Assert.That(root.Width, Is.EqualTo(144 + 144)); // new larger value
			// It got wider. We want an optimized invalidate rectangle that does not
			// include the left boxes. But it must include the space at the right where the root box grew.
			// There are other possible implementations, but currently, we expect the old rectangle of box2
			// to be invalidated (it returns true from Relayout);
			// the growth area at the right of div2;
			// and the area computed because div2 moved.
			//VerifyExpectedRectangle(site.RectsInvalidatedInRoot, 0, 48, 144, 96); // new box2
			//VerifyExpectedRectangle(site.RectsInvalidatedInRoot, 0, 48 + 24, 144, 96 - 24); // new part of div1 occupied by box2
			// This is from the old left of div2 to its new right (48 + 96 + 24 + 24)
			//VerifyExpectedRectangle(site.RectsInvalidatedInRoot, 0, 48 + 24, 144, 96 + 24);
		}
Exemplo n.º 60
0
        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
        }