public List <int> AddControlToShapes(TargetShapes targetshapes, ControlCells ctrl)
        {
            if (ctrl == null)
            {
                throw new System.ArgumentNullException(nameof(ctrl));
            }

            targetshapes = targetshapes.ResolveToShapes(this._client);

            if (targetshapes.Shapes.Count < 1)
            {
                return(new List <int>(0));
            }

            var control_indices = new List <int>();

            using (var undoscope = this._client.Undo.NewUndoScope(nameof(AddControlToShapes)))
            {
                foreach (var shape in targetshapes.Shapes)
                {
                    int ci = ControlHelper.Add(shape, ctrl);
                    control_indices.Add(ci);
                }
            }

            return(control_indices);
        }
예제 #2
0
        public List <int> Add(VisioScripting.Models.TargetShapes targets, ControlCells ctrl)
        {
            this._client.Application.AssertApplicationAvailable();
            this._client.Document.AssertDocumentAvailable();

            if (ctrl == null)
            {
                throw new System.ArgumentNullException(nameof(ctrl));
            }

            targets = targets.ResolveShapes(this._client);

            if (targets.Shapes.Count < 1)
            {
                return(new List <int>(0));
            }


            var control_indices = new List <int>();

            using (var undoscope = this._client.Application.NewUndoScope("Add Control"))
            {
                foreach (var shape in targets.Shapes)
                {
                    int ci = ControlHelper.Add(shape, ctrl);
                    control_indices.Add(ci);
                }
            }

            return(control_indices);
        }
예제 #3
0
        public void Controls_AddRemove()
        {
            var page1 = this.GetNewPage();

            var s1 = page1.DrawRectangle(0, 0, 4, 1);

            // Ensure we start with 0 controls
            Assert.AreEqual(0, ControlHelper.GetCount(s1));

            // Add the first control
            int ci1 = ControlHelper.Add(s1);

            Assert.AreEqual(1, ControlHelper.GetCount(s1));

            // Add the second control
            int ci2 = ControlHelper.Add(s1);

            Assert.AreEqual(2, ControlHelper.GetCount(s1));

            // retrieve the control information
            var controls = ControlCells.GetCells(s1);

            // verify that the controls were set propery
            Assert.AreEqual(2, controls.Count);
            Assert.AreEqual("Width*0", controls[0].X.Formula);
            Assert.AreEqual("Controls.Row_1", controls[0].XDynamics.Formula);
            Assert.AreEqual("Width*0", controls[1].X.Formula);
            Assert.AreEqual("Controls.Row_2", controls[1].XDynamics.Formula);

            // Delete both controls
            ControlHelper.Delete(s1, 0);
            Assert.AreEqual(1, ControlHelper.GetCount(s1));
            ControlHelper.Delete(s1, 0);
            Assert.AreEqual(0, ControlHelper.GetCount(s1));

            page1.Delete(0);
        }
예제 #4
0
        public void ShapeSheet_Query_NonExistentSections()
        {
            var page1 = this.GetNewPage();
            var s1    = page1.DrawRectangle(0, 0, 2, 2);
            var s2    = page1.DrawRectangle(2, 1, 3, 3);
            var s3    = page1.DrawRectangle(3, 1, 4, 2);
            var s4    = page1.DrawRectangle(4, -1, 5, 1);

            var shapes   = new[] { s1, s2, s3, s4 };
            var shapeids = shapes.Select(s => s.ID).ToList();

            // First verify that none of the shapes have the controls section locally or otherwise
            foreach (var s in shapes)
            {
                Assert.AreEqual(0, s.SectionExists[(short)IVisio.VisSectionIndices.visSectionControls, 1]);
                Assert.AreEqual(0, s.SectionExists[(short)IVisio.VisSectionIndices.visSectionControls, 0]);
            }

            // Try to retrieve the control cells rows for each shape, every shape should return zero rows
            foreach (var s in shapes)
            {
                var r1 = ControlCells.GetCells(s);
                Assert.AreEqual(0, r1.Count);
            }

            // Try to retrieve the control cells rows for all shapes at once, every shape should return a collection of zero rows
            var r2 = ControlCells.GetCells(page1, shapeids);

            Assert.AreEqual(shapes.Count(), r2.Count);
            for (int i = 0; i < shapes.Count(); i++)
            {
                Assert.AreEqual(0, r2[i].Count);
            }

            // Add a Controls row to shape2
            var cc = new ControlCells();

            ControlHelper.Add(s2, cc);

            // Now verify that none of the shapes *except s2* have the controls section locally or otherwise
            foreach (var s in shapes)
            {
                if (s != s2)
                {
                    Assert.AreEqual(0, s.SectionExists[(short)IVisio.VisSectionIndices.visSectionControls, 1]);
                    Assert.AreEqual(0, s.SectionExists[(short)IVisio.VisSectionIndices.visSectionControls, 0]);
                }
                else
                {
                    Assert.AreEqual(-1, s.SectionExists[(short)IVisio.VisSectionIndices.visSectionControls, 1]);
                    Assert.AreEqual(-1, s.SectionExists[(short)IVisio.VisSectionIndices.visSectionControls, 0]);
                }
            }

            // Try to retrieve the control cells rows for each shape, every shape should return zero rows *except for s2*
            foreach (var s in shapes)
            {
                if (s != s2)
                {
                    var r1 = ControlCells.GetCells(s);
                    Assert.AreEqual(0, r1.Count);
                }
                else
                {
                    var r1 = ControlCells.GetCells(s);
                    Assert.AreEqual(1, r1.Count);
                }
            }

            // Try to retrieve the control cells rows for all shapes at once, every shape *except s2* should return a collection of zero rows
            var r3 = ControlCells.GetCells(page1, shapeids);

            Assert.AreEqual(shapes.Count(), r3.Count);
            for (int i = 0; i < shapes.Count(); i++)
            {
                if (shapes[i] != s2)
                {
                    Assert.AreEqual(0, r3[i].Count);
                }
                else
                {
                    Assert.AreEqual(1, r3[i].Count);
                }
            }

            page1.Delete(0);
        }