Inheritance: LiteralStringParaHookup
Example #1
0
		public void HookupSimpleString()
		{
			MockData1 data1 = new MockData1(m_wsFrn, m_wsEng);
			data1.SimpleThree = "foo";

			MockParaBox mockPara = new MockParaBox();
			var mlHook = new StringHookup(data1, () => data1.SimpleThree, hookup => data1.SimpleThreeChanged += hookup.StringPropChanged,
				hookup => data1.SimpleThreeChanged -= hookup.StringPropChanged, mockPara);
			mlHook.ClientRunIndex = 5;

			data1.SimpleThree = "bar";

			data1.RaiseSimpleThreeChanged();
			Assert.AreEqual(5, mockPara.TheIndex, "Should have fired the event and notified the correct index");
			Assert.AreEqual("bar", mockPara.TheString, "Should have informed para of new string");

			mlHook.Dispose();
		}
Example #2
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;
		}
Example #3
0
		// Add to the root a text paragraph which reflects the SimpleText property.
		private void AddSimpleTextPara(AssembledStyles styles, int ws, RootBox root)
		{
			var items = new List<IClientRun>();
			var run = new StringClientRun("This is the day that the Lord has made. We will rejoice and be glad in it",
										  styles.WithWs(ws));
			items.Add(run);
			var source = new TextSource(items);
			var para = new ParaBox(styles, source);
			var hookup = new StringHookup(this, () => this.SimpleText,
										  hook => SimpleTextChanged += hook.StringPropChanged,
										  hook => SimpleTextChanged -= hook.StringPropChanged, para);
			hookup.Writer = newVal => SimpleText = newVal;
			run.Hookup = hookup;
			root.AddBox(para);
		}
		public void InsertCharInEmptyLine()
		{
			string contents = "";
			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 root = new RootBox(styles);
			var block = new BlockBox(styles, Color.Red, 20000, 10000);
			root.AddBox(block);
			root.AddBox(para);
			var layoutArgs = MakeLayoutInfo(Int32.MaxValue / 2, m_gm.VwGraphics, factory);
			root.Layout(layoutArgs);
			Assert.That(root.Height, Is.EqualTo(13 + block.Height));
			Assert.That(para.Width, Is.EqualTo(FakeRenderEngine.SimulatedWidth(contents)));
			Assert.That(root.Width, Is.EqualTo(block.Width));
			int simulatedWidth = FakeRenderEngine.SimulatedWidth("x");
			Assert.That(root.Width, Is.GreaterThan(para.Width + simulatedWidth));
			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;
			var oldRootWidth = root.Width;

			var ip = root.SelectAtEnd();
			ip.InsertText("x");
			Assert.That(root.Height, Is.EqualTo(13 + block.Height));
			Assert.That(root.Width, Is.EqualTo(oldRootWidth));
			Assert.That(para.Width, Is.EqualTo(simulatedWidth));
			var expectedInvalidate = new Rectangle(-RootBox.InvalidateMargin,
							- RootBox.InvalidateMargin + block.Height,
							simulatedWidth + RootBox.InvalidateMargin * 2,
							13 + 2 * RootBox.InvalidateMargin);
			Assert.That(site.RectsInvalidatedInRoot, Has.Member(expectedInvalidate));
		}
		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);
		}
		private MockData1 HookDataToClientRun(ParaBox para, string contents1, int runIndex)
		{
			var data1 = new MockData1(ParaBuilderTests.s_simpleStringWs, ParaBuilderTests.s_simpleStringWs);
			data1.SimpleThree = contents1;
			var hookup = new StringHookup(data1, () => data1.SimpleThree,
										  hook => data1.SimpleThreeChanged += hook.StringPropChanged,
										  hook => data1.SimpleThreeChanged -= hook.StringPropChanged, para);
			hookup.Writer = newVal => data1.SimpleThree = newVal;
			hookup.ClientRunIndex = runIndex;
			(para.Source.ClientRuns[runIndex] as StringClientRun).Hookup = hookup;
			return data1;
		}