Beispiel #1
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)));
        }
Beispiel #2
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)));
		}