public static int Set(
            IVisio.Shape shape,
            short row,
            ControlCells ctrl)
        {
            if (shape == null)
            {
                throw new ArgumentNullException(nameof(shape));
            }


            if (!ctrl.XDynamics.Formula.HasValue)
            {
                ctrl.XDynamics = $"Controls.Row_{row + 1}";
            }

            if (!ctrl.YDynamics.Formula.HasValue)
            {
                ctrl.YDynamics = $"Controls.Row_{row + 1}.Y";
            }

            var update = new ShapeSheet.Update();
            update.SetFormulas(ctrl, row);
            update.Execute(shape);

            return row;
        }
Exemple #2
0
 public void Apply(ShapeSheet.Update update, short id)
 {
     update.SetFormulaIgnoreNull(id, ShapeSheet.SRCConstants.AvenueSizeX, this.AvenueSizeX);
     update.SetFormulaIgnoreNull(id, ShapeSheet.SRCConstants.AvenueSizeY, this.AvenueSizeY);
     update.SetFormulaIgnoreNull(id, ShapeSheet.SRCConstants.BlockSizeX, this.BlockSizeX);
     update.SetFormulaIgnoreNull(id, ShapeSheet.SRCConstants.BlockSizeY, this.BlockSizeY);
     update.SetFormulaIgnoreNull(id, ShapeSheet.SRCConstants.CtrlAsInput, this.CtrlAsInput);
     update.SetFormulaIgnoreNull(id, ShapeSheet.SRCConstants.DynamicsOff, this.DynamicsOff);
     update.SetFormulaIgnoreNull(id, ShapeSheet.SRCConstants.EnableGrid, this.EnableGrid);
     update.SetFormulaIgnoreNull(id, ShapeSheet.SRCConstants.LineAdjustFrom, this.LineAdjustFrom);
     update.SetFormulaIgnoreNull(id, ShapeSheet.SRCConstants.LineAdjustTo, this.LineAdjustTo);
     update.SetFormulaIgnoreNull(id, ShapeSheet.SRCConstants.LineJumpCode, this.LineJumpCode);
     update.SetFormulaIgnoreNull(id, ShapeSheet.SRCConstants.LineJumpFactorX, this.LineJumpFactorX);
     update.SetFormulaIgnoreNull(id, ShapeSheet.SRCConstants.LineJumpFactorY, this.LineJumpFactorY);
     update.SetFormulaIgnoreNull(id, ShapeSheet.SRCConstants.LineJumpStyle, this.LineJumpStyle);
     update.SetFormulaIgnoreNull(id, ShapeSheet.SRCConstants.LineRouteExt, this.LineRouteExt);
     update.SetFormulaIgnoreNull(id, ShapeSheet.SRCConstants.LineToLineX, this.LineToLineX);
     update.SetFormulaIgnoreNull(id, ShapeSheet.SRCConstants.LineToLineY, this.LineToLineY);
     update.SetFormulaIgnoreNull(id, ShapeSheet.SRCConstants.LineToNodeX, this.LineToNodeX);
     update.SetFormulaIgnoreNull(id, ShapeSheet.SRCConstants.LineToNodeY, this.LineToNodeY);
     update.SetFormulaIgnoreNull(id, ShapeSheet.SRCConstants.PageLineJumpDirX, this.PageLineJumpDirX);
     update.SetFormulaIgnoreNull(id, ShapeSheet.SRCConstants.PageLineJumpDirY, this.PageLineJumpDirY);
     update.SetFormulaIgnoreNull(id, ShapeSheet.SRCConstants.PageShapeSplit, this.PageShapeSplit);
     update.SetFormulaIgnoreNull(id, ShapeSheet.SRCConstants.PlaceDepth, this.PlaceDepth);
     update.SetFormulaIgnoreNull(id, ShapeSheet.SRCConstants.PlaceFlip, this.PlaceFlip);
     update.SetFormulaIgnoreNull(id, ShapeSheet.SRCConstants.PlaceStyle, this.PlaceStyle);
     update.SetFormulaIgnoreNull(id, ShapeSheet.SRCConstants.PlowCode, this.PlowCode);
     update.SetFormulaIgnoreNull(id, ShapeSheet.SRCConstants.ResizePage, this.ResizePage);
     update.SetFormulaIgnoreNull(id, ShapeSheet.SRCConstants.RouteStyle, this.RouteStyle);
 }
Exemple #3
0
 internal void ApplyFormulas(ShapeSheet.Update update, short row)
 {
     update.SetFormulaIgnoreNull(SRCCON.CharColor.ForRow(row), this.Color);
     update.SetFormulaIgnoreNull(SRCCON.CharFont.ForRow(row), this.Font);
     update.SetFormulaIgnoreNull(SRCCON.CharSize.ForRow(row), this.Size);
     update.SetFormulaIgnoreNull(SRCCON.CharStyle.ForRow(row), this.Style);
     update.SetFormulaIgnoreNull(SRCCON.CharColorTrans.ForRow(row), this.Transparency);
     update.SetFormulaIgnoreNull(SRCCON.CharAsianFont.ForRow(row), this.AsianFont);
     update.SetFormulaIgnoreNull(SRCCON.CharCase.ForRow(row), this.Case);
     update.SetFormulaIgnoreNull(SRCCON.CharComplexScriptFont.ForRow(row), this.ComplexScriptFont);
     update.SetFormulaIgnoreNull(SRCCON.CharComplexScriptSize.ForRow(row), this.ComplexScriptSize);
     update.SetFormulaIgnoreNull(SRCCON.CharDblUnderline.ForRow(row), this.DoubleUnderline);
     update.SetFormulaIgnoreNull(SRCCON.CharDoubleStrikethrough.ForRow(row), this.DoubleStrikeThrough);
     update.SetFormulaIgnoreNull(SRCCON.CharLangID.ForRow(row), this.LangID);
     update.SetFormulaIgnoreNull(SRCCON.CharFontScale.ForRow(row), this.FontScale);
     update.SetFormulaIgnoreNull(SRCCON.CharLangID.ForRow(row), this.LangID);
     update.SetFormulaIgnoreNull(SRCCON.CharLetterspace.ForRow(row), this.Letterspace);
     update.SetFormulaIgnoreNull(SRCCON.CharLocale.ForRow(row), this.Locale);
     update.SetFormulaIgnoreNull(SRCCON.CharLocalizeFont.ForRow(row), this.LocalizeFont);
     update.SetFormulaIgnoreNull(SRCCON.CharOverline.ForRow(row), this.Overline);
     update.SetFormulaIgnoreNull(SRCCON.CharPerpendicular.ForRow(row), this.Perpendicular);
     update.SetFormulaIgnoreNull(SRCCON.CharPos.ForRow(row), this.Pos);
     update.SetFormulaIgnoreNull(SRCCON.CharRTLText.ForRow(row), this.RTLText);
     update.SetFormulaIgnoreNull(SRCCON.CharStrikethru.ForRow(row), this.Strikethru);
     update.SetFormulaIgnoreNull(SRCCON.CharUseVertical.ForRow(row), this.UseVertical);
 }
        public static int Set(
            IVisio.Shape shape,
            short row,
            ControlCells ctrl)
        {
            if (shape == null)
            {
                throw new ArgumentNullException(nameof(shape));
            }


            if (!ctrl.XDynamics.Formula.HasValue)
            {
                ctrl.XDynamics = $"Controls.Row_{row + 1}";
            }

            if (!ctrl.YDynamics.Formula.HasValue)
            {
                ctrl.YDynamics = $"Controls.Row_{row + 1}.Y";
            }

            var update = new ShapeSheet.Update();
            update.SetFormulas(ctrl, row);
            update.Execute(shape);

            return row;
        }
        public IVisio.Page CreatePage(FormPage formpage)
        {
            this.FormPage = formpage;

            this.page = this.VisioPages.Add();
            this.page.Name = formpage.Name;

            // Update the Page Cells
            var pagesheet = this.page.PageSheet;
            var pageupdate = new ShapeSheet.Update();

            var pagecells = new Pages.PageCells();
            pagecells.PageWidth = formpage.Size.Width;
            pagecells.PageHeight = formpage.Size.Height;
            pagecells.PageLeftMargin = formpage.Margin.Left;
            pagecells.PageRightMargin = formpage.Margin.Right;
            pagecells.PageTopMargin = formpage.Margin.Top;
            pagecells.PageBottomMargin = formpage.Margin.Bottom;
            pageupdate.SetFormulas(pagecells);
            pageupdate.Execute(pagesheet);


            this.Reset();
            return this.page;
        }
Exemple #6
0
        public void SetLock(IList <IVisio.Shape> target_shapes, Shapes.LockCells lockcells)
        {
            this.Client.Application.AssertApplicationAvailable();
            this.Client.Document.AssertDocumentAvailable();

            var shapes = this.GetTargetShapes(target_shapes);

            if (shapes.Count < 1)
            {
                return;
            }

            var selection = this.Client.Selection.Get();
            var shapeids  = selection.GetIDs();
            var update    = new ShapeSheet.Update();

            foreach (int shapeid in shapeids)
            {
                update.SetFormulas((short)shapeid, lockcells);
            }

            var application = this.Client.Application.Get();

            using (var undoscope = this.Client.Application.NewUndoScope("Set Shape Lock Properties"))
            {
                var active_page = application.ActivePage;
                update.Execute(active_page);
            }
        }
Exemple #7
0
        public void SetSize(IList <IVisio.Shape> target_shapes, double?w, double?h)
        {
            this.Client.Application.AssertApplicationAvailable();
            this.Client.Document.AssertDocumentAvailable();

            var shapes = this.GetTargetShapes(target_shapes);

            if (shapes.Count < 1)
            {
                return;
            }

            var shapeids = shapes.Select(s => s.ID).ToList();
            var update   = new ShapeSheet.Update();

            foreach (int shapeid in shapeids)
            {
                if (w.HasValue && w.Value >= 0)
                {
                    update.SetFormula((short)shapeid, ShapeSheet.SRCConstants.Width, w.Value);
                }
                if (h.HasValue && h.Value >= 0)
                {
                    update.SetFormula((short)shapeid, ShapeSheet.SRCConstants.Height, h.Value);
                }
            }

            var application = this.Client.Application.Get();

            using (var undoscope = this.Client.Application.NewUndoScope("Set Shape Size"))
            {
                var active_page = application.ActivePage;
                update.Execute(active_page);
            }
        }
        public IVisio.Page CreatePage(FormPage formpage)
        {
            this.FormPage = formpage;

            this.page      = this.VisioPages.Add();
            this.page.Name = formpage.Name;

            // Update the Page Cells
            var pagesheet  = this.page.PageSheet;
            var pageupdate = new ShapeSheet.Update();

            var pagecells = new Pages.PageCells();

            pagecells.PageWidth        = formpage.Size.Width;
            pagecells.PageHeight       = formpage.Size.Height;
            pagecells.PageLeftMargin   = formpage.Margin.Left;
            pagecells.PageRightMargin  = formpage.Margin.Right;
            pagecells.PageTopMargin    = formpage.Margin.Top;
            pagecells.PageBottomMargin = formpage.Margin.Bottom;
            pageupdate.SetFormulas(pagecells);
            pageupdate.Execute(pagesheet);


            this.Reset();
            return(this.page);
        }
Exemple #9
0
 public void Apply(ShapeSheet.Update update, short shapeid_label, short shapeid_box)
 {
     update.SetFormulas(shapeid_label, this.CharacterCells, 0);
     update.SetFormulas(shapeid_label, this.ParagraphCells, 0);
     update.SetFormulas(shapeid_box, this.FormatCells);
     update.SetFormulas(shapeid_label, this.TextBlockCells);
 }
        /// <summary>
        /// Remove all tab stops on the shape
        /// </summary>
        /// <param name="shape"></param>
        private static void ClearTabStops(IVisio.Shape shape)
        {
            if (shape == null)
            {
                throw new System.ArgumentNullException(nameof(shape));
            }

            int num_existing_tabstops = TextFormat.GetTabStopCount(shape);

            if (num_existing_tabstops < 1)
            {
                return;
            }

            var cell_tabstopcount = shape.CellsSRC[TextFormat.src_tabstopcount.Section, TextFormat.src_tabstopcount.Row, TextFormat.src_tabstopcount.Cell];

            cell_tabstopcount.FormulaForce = "0";

            const string formula = "0";

            var update = new ShapeSheet.Update();

            for (int i = 1; i < num_existing_tabstops * 3; i++)
            {
                var src = new ShapeSheet.SRC(TextFormat.tab_section, (short)IVisio.VisRowIndices.visRowTab,
                                             (short)i);
                update.SetFormula(src, formula);
            }

            update.Execute(shape);
        }
        public static int Add(
            IVisio.Shape shape,
            ConnectionPointCells cp)
        {
            if (shape == null)
            {
                throw new System.ArgumentNullException(nameof(shape));
            }

            if (!cp.X.Formula.HasValue)
            {
                throw new System.ArgumentException("Must provide an X Formula");
            }

            if (!cp.Y.Formula.HasValue)
            {
                throw new System.ArgumentException("Must provide an Y Formula");
            }

            var n = shape.AddRow((short)IVisio.VisSectionIndices.visSectionConnectionPts,
                                 (short)IVisio.VisRowIndices.visRowLast,
                                 (short)IVisio.VisRowTags.visTagCnnctPt);

            var update = new ShapeSheet.Update();
            update.SetFormulas(cp,n);
            update.Execute(shape);

            return n;
        }
Exemple #12
0
        public static int Add(
            IVisio.Shape shape,
            ConnectionPointCells connection_point_cells)
        {
            if (shape == null)
            {
                throw new System.ArgumentNullException(nameof(shape));
            }

            if (!connection_point_cells.X.Formula.HasValue)
            {
                string msg = "Must provide an X Formula";
                throw new System.ArgumentException(msg, nameof(connection_point_cells));
            }

            if (!connection_point_cells.Y.Formula.HasValue)
            {
                string msg = "Must provide an Y Formula";
                throw new System.ArgumentException(msg, nameof(connection_point_cells));
            }

            var n = shape.AddRow((short)IVisio.VisSectionIndices.visSectionConnectionPts,
                                 (short)IVisio.VisRowIndices.visRowLast,
                                 (short)IVisio.VisRowTags.visTagCnnctPt);

            var update = new ShapeSheet.Update();

            update.SetFormulas(connection_point_cells, n);
            update.Execute(shape);

            return(n);
        }
Exemple #13
0
        public void PasteFormat(IVisio.Page page, IList <int> shapeids, FormatCategory category, bool applyformulas)
        {
            var update = new ShapeSheet.Update();

            foreach (var shape_id in shapeids)
            {
                foreach (var cellrec in this.Cells)
                {
                    if (!cellrec.MatchesCategory(category))
                    {
                        continue;
                    }

                    var sidsrc = new ShapeSheet.SIDSRC((short)shape_id, cellrec.SRC);

                    if (applyformulas)
                    {
                        update.SetFormula(sidsrc, cellrec.Formula);
                    }
                    else
                    {
                        if (cellrec.Result != null)
                        {
                            update.SetFormula(sidsrc, cellrec.Result);
                        }
                    }
                }
            }

            update.Execute(page);
        }
Exemple #14
0
        public short Render(IVisio.Shape shape)
        {
            short sec_index = GeometryHelper.AddSection(shape);
            short row_count = shape.RowCount[sec_index];

            var update = new ShapeSheet.Update();

            var src_nofill      = ShapeSheet.SRCConstants.Geometry_NoFill.ForSectionAndRow(sec_index, 0);
            var src_noline      = ShapeSheet.SRCConstants.Geometry_NoLine.ForSectionAndRow(sec_index, 0);
            var src_noshow      = ShapeSheet.SRCConstants.Geometry_NoShow.ForSectionAndRow(sec_index, 0);
            var src_nosnap      = ShapeSheet.SRCConstants.Geometry_NoSnap.ForSectionAndRow(sec_index, 0);
            var src_noquickdrag = ShapeSheet.SRCConstants.Geometry_NoQuickDrag.ForSectionAndRow(sec_index, 0);

            update.SetFormulaIgnoreNull(src_nofill, this.NoFill);
            update.SetFormulaIgnoreNull(src_noline, this.NoLine);
            update.SetFormulaIgnoreNull(src_noshow, this.NoShow);
            update.SetFormulaIgnoreNull(src_nosnap, this.NoSnap);
            update.SetFormulaIgnoreNull(src_noquickdrag, this.NoQuickDrag);

            foreach (var row in this.Rows)
            {
                row.AddTo(shape, update, row_count, sec_index);
                row_count++;
            }

            update.Execute(shape);
            return(0);
        }
        public void Render(IVisio.Page page)
        {
            if (page == null)
            {
                throw new System.ArgumentNullException(nameof(page));
            }


            // First handle any page properties
            if (this.Name!=null)
            {
                page.NameU = this.Name;
            }

            this.VisioPage = page;

            var page_sheet = page.PageSheet;

            var app = page.Application;


            using (var perfscope = new Application.PerfScope(app, this.PerfSettings))
            {
                if (this.Size.HasValue)
                {
                    this.PageCells.PageHeight = this.Size.Value.Height;
                    this.PageCells.PageWidth = this.Size.Value.Width;
                }

                var update = new ShapeSheet.Update();
                update.SetFormulas((short)page_sheet.ID, this.PageCells);
                update.Execute(page);
                
                // Then render the shapes
                this.Shapes.Render(page);

                // Perform any additional layout
                if (this.Layout != null)
                {
                    this.Layout.Apply(page);
                }

                // Optionally, perform page resizing to fit contents
                if (this.ResizeToFit)
                {
                    if (this.ResizeToFitMargin.HasValue)
                    {
                        page.ResizeToFitContents(this.ResizeToFitMargin.Value);
                    }
                    else
                    {
                        page.ResizeToFitContents();
                    }
                }
            }

        }
Exemple #16
0
        public void ApplyFormus(ShapeSheet.Update update)
        {
            short titleshape_id = this.VisioShape.ID16;

            update.SetFormulas(titleshape_id, this.TextBlockCells);
            update.SetFormulas(titleshape_id, this.ParagraphCells, 0);
            update.SetFormulas(titleshape_id, this.CharacterCells, 0);
            update.SetFormulas(titleshape_id, this.FormatCells);
        }
Exemple #17
0
        public void Render(IVisio.Page page)
        {
            if (page == null)
            {
                throw new System.ArgumentNullException(nameof(page));
            }


            // First handle any page properties
            if (this.Name != null)
            {
                page.NameU = this.Name;
            }

            this.VisioPage = page;

            var page_sheet = page.PageSheet;

            var app = page.Application;


            using (var perfscope = new Application.PerfScope(app, this.PerfSettings))
            {
                if (this.Size.HasValue)
                {
                    this.PageCells.PageHeight = this.Size.Value.Height;
                    this.PageCells.PageWidth  = this.Size.Value.Width;
                }

                var update = new ShapeSheet.Update();
                update.SetFormulas((short)page_sheet.ID, this.PageCells);
                update.Execute(page);

                // Then render the shapes
                this.Shapes.Render(page);

                // Perform any additional layout
                if (this.Layout != null)
                {
                    this.Layout.Apply(page);
                }

                // Optionally, perform page resizing to fit contents
                if (this.ResizeToFit)
                {
                    if (this.ResizeToFitMargin.HasValue)
                    {
                        page.ResizeToFitContents(this.ResizeToFitMargin.Value);
                    }
                    else
                    {
                        page.ResizeToFitContents();
                    }
                }
            }
        }
        public void ToogleCase(IList <IVisio.Shape> target_shapes)
        {
            this.Client.Application.AssertApplicationAvailable();
            this.Client.Document.AssertDocumentAvailable();

            var shapes = this.GetTargetShapes(target_shapes);

            if (shapes.Count < 1)
            {
                return;
            }

            var application = this.Client.Application.Get();

            using (var undoscope = this.Client.Application.NewUndoScope("Toggle Shape Text Case"))
            {
                var shapeids = shapes.Select(s => s.ID).ToList();

                var page = application.ActivePage;
                // Store all the formatting
                var formats = Text.TextFormat.GetFormat(page, shapeids);

                // Change the text - this will wipe out all the character and paragraph formatting
                foreach (var shape in shapes)
                {
                    string t = shape.Text;
                    if (t.Length < 1)
                    {
                        continue;
                    }
                    shape.Text = TextCommandsUtil.toggle_case(t);
                }

                // Now restore all the formatting - based on any initial formatting from the text

                var update = new ShapeSheet.Update();
                for (int i = 0; i < shapes.Count; i++)
                {
                    var format = formats[i];

                    if (format.CharacterFormats.Count > 0)
                    {
                        var fmt = format.CharacterFormats[0];
                        update.SetFormulas((short)shapeids[i], fmt, 0);
                    }

                    if (format.ParagraphFormats.Count > 0)
                    {
                        var fmt = format.ParagraphFormats[0];
                        update.SetFormulas((short)shapeids[i], fmt, 0);
                    }
                }

                update.Execute(page);
            }
        }
Exemple #19
0
        private static void SetSize(IVisio.Page page, Drawing.Size size)
        {
            var page_cells = new PageCells();

            page_cells.PageHeight = size.Height;
            page_cells.PageWidth  = size.Width;
            var pageupdate = new ShapeSheet.Update();

            pageupdate.SetFormulas(page_cells);
            pageupdate.Execute(page.PageSheet);
        }
        public void Apply(IVisio.Page page)
        {
            var pagecells = new PageCells();
            this.SetPageCells(pagecells);

            var update = new ShapeSheet.Update();
            update.SetFormulas(pagecells);
            var pagesheet = page.PageSheet;
            update.Execute(pagesheet);
            page.Layout();
        }
        public static void Set(IVisio.Shape shape, short row, CustomPropertyCells cp)
        {
            if (shape == null)
            {
                throw new ArgumentNullException(nameof(shape));
            }

            var update = new ShapeSheet.Update();
            update.SetFormulas(cp, row);
            update.Execute(shape);
        }
Exemple #22
0
        private static void update_xfrms(IVisio.Page page, IList <int> shapeids, IList <Shapes.XFormCells> xfrms)
        {
            var update = new ShapeSheet.Update();

            for (int i = 0; i < shapeids.Count; i++)
            {
                var shape_id = shapeids[i];
                var xfrm     = xfrms[i];
                update.SetFormulas((short)shape_id, xfrm);
            }
            update.Execute(page);
        }
Exemple #23
0
        public static void Set(IVisio.Shape shape, short row, CustomPropertyCells cp)
        {
            if (shape == null)
            {
                throw new ArgumentNullException(nameof(shape));
            }

            var update = new ShapeSheet.Update();

            update.SetFormulas(cp, row);
            update.Execute(shape);
        }
        public void Finish()
        {
            var update = new ShapeSheet.Update();

            foreach (var block in this.Blocks)
            {
                update.SetFormulas((short)block.VisioShapeID, block.FormatCells);
                update.SetFormulas((short)block.VisioShapeID, block.TextBlockCells);
                update.SetFormulas((short)block.VisioShapeID, block.ParagraphCells, 0);
                update.SetFormulas((short)block.VisioShapeID, block.CharacterCells, 0);
            }
            update.Execute(this.page);
        }
        public static void SetTabStops(IVisio.Shape shape, IList <TabStop> stops)
        {
            if (shape == null)
            {
                throw new System.ArgumentNullException(nameof(shape));
            }

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

            TextFormat.ClearTabStops(shape);
            if (stops.Count < 1)
            {
                return;
            }

            const short row = 0;
            var         invariant_culture  = System.Globalization.CultureInfo.InvariantCulture;
            var         vis_tab_stop_count = (short)IVisio.VisCellIndices.visTabStopCount;
            var         tabstopcountcell   = shape.CellsSRC[TextFormat.tab_section, row, vis_tab_stop_count];

            tabstopcountcell.FormulaU = stops.Count.ToString(invariant_culture);

            // set the number of tab stobs allowed for the shape
            var tagtab = TextFormat.GetTabTagForStops(stops.Count);

            shape.RowType[TextFormat.tab_section, (short)IVisio.VisRowIndices.visRowTab] = (short)tagtab;

            // add tab properties for each stop
            var update = new ShapeSheet.Update();

            for (int stop_index = 0; stop_index < stops.Count; stop_index++)
            {
                int i = stop_index * 3;

                var alignment = ((int)stops[stop_index].Alignment).ToString(invariant_culture);
                var position  = ((int)stops[stop_index].Position).ToString(invariant_culture);

                var src_tabpos   = new ShapeSheet.SRC(TextFormat.tab_section, row, (short)(i + 1));
                var src_tabalign = new ShapeSheet.SRC(TextFormat.tab_section, row, (short)(i + 2));
                var src_tabother = new ShapeSheet.SRC(TextFormat.tab_section, row, (short)(i + 3));

                update.SetFormula(src_tabpos, position);    // tab position
                update.SetFormula(src_tabalign, alignment); // tab alignment
                update.SetFormula(src_tabother, "0");       // tab unknown
            }

            update.Execute(shape);
        }
Exemple #26
0
        public void Apply(IVisio.Page page)
        {
            var pagecells = new PageCells();

            this.SetPageCells(pagecells);

            var update = new ShapeSheet.Update();

            update.SetFormulas(pagecells);
            var pagesheet = page.PageSheet;

            update.Execute(pagesheet);
            page.Layout();
        }
        public static void Set(IVisio.Shape shape, string name, ShapeSheet.FormulaLiteral value, ShapeSheet.FormulaLiteral prompt)
        {
            if (shape == null)
            {
                throw new System.ArgumentNullException(nameof(shape));
            }

            UserDefinedCellsHelper.CheckValidName(name);

            if (UserDefinedCellsHelper.Contains(shape, name))
            {
                string full_prop_name = UserDefinedCellsHelper.GetRowName(name);

                if (value.HasValue)
                {
                    string value_cell_name = full_prop_name;
                    var cell = shape.CellsU[value_cell_name];
                    cell.FormulaU = value.Encode();                    
                }

                if (prompt.HasValue)
                {
                    string prompt_cell_name = full_prop_name+".Prompt";
                    var cell = shape.CellsU[prompt_cell_name];
                    cell.FormulaU = prompt.Encode();                                        
                }
                return;
            }

            short row = shape.AddNamedRow(
                UserDefinedCellsHelper._userdefinedcell_section,
                name,
                (short)IVisio.VisRowIndices.visRowUser);

            var update = new ShapeSheet.Update();

            if (value.HasValue)
            {
                var src = new ShapeSheet.SRC(UserDefinedCellsHelper._userdefinedcell_section, row, (short)IVisio.VisCellIndices.visUserValue);
                update.SetFormula(src, value.Encode());
            }

            if (prompt.HasValue)
            {
                var src = new ShapeSheet.SRC(UserDefinedCellsHelper._userdefinedcell_section, row, (short)IVisio.VisCellIndices.visUserPrompt);
                update.SetFormula(src, prompt.Encode());
            }

            update.Execute(shape);
        }
        public static void Set(IVisio.Shape shape, string name, ShapeSheet.FormulaLiteral value, ShapeSheet.FormulaLiteral prompt)
        {
            if (shape == null)
            {
                throw new System.ArgumentNullException(nameof(shape));
            }

            UserDefinedCellsHelper.CheckValidName(name);

            if (UserDefinedCellsHelper.Contains(shape, name))
            {
                string full_prop_name = UserDefinedCellsHelper.GetRowName(name);

                if (value.HasValue)
                {
                    string value_cell_name = full_prop_name;
                    var    cell            = shape.CellsU[value_cell_name];
                    cell.FormulaU = value.Encode();
                }

                if (prompt.HasValue)
                {
                    string prompt_cell_name = full_prop_name + ".Prompt";
                    var    cell             = shape.CellsU[prompt_cell_name];
                    cell.FormulaU = prompt.Encode();
                }
                return;
            }

            short row = shape.AddNamedRow(
                UserDefinedCellsHelper._userdefinedcell_section,
                name,
                (short)IVisio.VisRowIndices.visRowUser);

            var update = new ShapeSheet.Update();

            if (value.HasValue)
            {
                var src = new ShapeSheet.SRC(UserDefinedCellsHelper._userdefinedcell_section, row, (short)IVisio.VisCellIndices.visUserValue);
                update.SetFormula(src, value.Encode());
            }

            if (prompt.HasValue)
            {
                var src = new ShapeSheet.SRC(UserDefinedCellsHelper._userdefinedcell_section, row, (short)IVisio.VisCellIndices.visUserPrompt);
                update.SetFormula(src, prompt.Encode());
            }

            update.Execute(shape);
        }
        private void UpdateCells(RenderContext ctx)
        {
            this.UpdateCellsWithDropSizes(ctx);

            var update            = new ShapeSheet.Update();
            var shapes_with_cells = this.shapes.Where(s => s.Cells != null);

            foreach (var shape in shapes_with_cells)
            {
                var   fmt = shape.Cells;
                short id  = shape.VisioShapeID;
                fmt.Apply(update, id);
            }
            update.Execute(ctx.VisioPage);
        }
        public static void set_text_wrapping(IVisio.Page page,
                                             IList <int> shapeids,
                                             bool wrap)
        {
            const string formula_wrap    = "WIDTH*1";
            const string formula_no_wrap = "TEXTWIDTH(TheText)";
            string       formula         = wrap ? formula_wrap : formula_no_wrap;
            var          update          = new ShapeSheet.Update();

            foreach (int shapeid in shapeids)
            {
                update.SetFormula((short)shapeid, ShapeSheet.SRCConstants.TxtWidth, formula);
            }

            update.Execute(page);
        }
        public static void set_text_wrapping(IVisio.Page page,
                                               IList<int> shapeids,
                                               bool wrap)
        {
            const string formula_wrap = "WIDTH*1";
            const string formula_no_wrap = "TEXTWIDTH(TheText)";
            string formula = wrap ? formula_wrap : formula_no_wrap;
            var update = new ShapeSheet.Update();
            
            foreach (int shapeid in shapeids)
            {
                update.SetFormula((short)shapeid, ShapeSheet.SRCConstants.TxtWidth, formula);
            }

            update.Execute(page);
        }
        public static int Set(
            IVisio.Shape shape,
            short row,
            HyperlinkCells hyperlink)
        {
            if (shape == null)
            {
                throw new ArgumentNullException(nameof(shape));
            }

            var update = new ShapeSheet.Update();

            update.SetFormulas(hyperlink, row);
            update.Execute(shape);

            return(row);
        }
Exemple #33
0
        public void SetSize(Drawing.Size new_size)
        {
            this.Client.Application.AssertApplicationAvailable();
            this.Client.Document.AssertDocumentAvailable();

            var application = this.Client.Application.Get();

            using (var undoscope = this.Client.Application.NewUndoScope("Set Page Size"))
            {
                var active_page = application.ActivePage;
                var page_sheet  = active_page.PageSheet;
                var update      = new ShapeSheet.Update(2);
                update.SetFormula(ShapeSheet.SRCConstants.PageWidth, new_size.Width);
                update.SetFormula(ShapeSheet.SRCConstants.PageHeight, new_size.Height);
                update.Execute(page_sheet);
            }
        }
        public void FitShapeToText(IList <IVisio.Shape> target_shapes)
        {
            this.Client.Application.AssertApplicationAvailable();
            this.Client.Document.AssertDocumentAvailable();

            var shapes = this.GetTargetShapes2D(target_shapes);

            if (shapes.Count < 1)
            {
                return;
            }

            var application = this.Client.Application.Get();
            var active_page = application.ActivePage;
            var shapeids    = shapes.Select(s => s.ID).ToList();

            using (var undoscope = this.Client.Application.NewUndoScope("FitShapeToText"))
            {
                // Calculate the new sizes for each shape
                var new_sizes = new List <Drawing.Size>(shapeids.Count);
                foreach (var shape in shapes)
                {
                    var text_bounding_box = shape.GetBoundingBox(Microsoft.Office.Interop.Visio.VisBoundingBoxArgs.visBBoxUprightText).Size;
                    var wh_bounding_box   = shape.GetBoundingBox(Microsoft.Office.Interop.Visio.VisBoundingBoxArgs.visBBoxUprightWH).Size;

                    double max_w    = System.Math.Max(text_bounding_box.Width, wh_bounding_box.Width);
                    double max_h    = System.Math.Max(text_bounding_box.Height, wh_bounding_box.Height);
                    var    max_size = new Drawing.Size(max_w, max_h);
                    new_sizes.Add(max_size);
                }

                var src_width  = ShapeSheet.SRCConstants.Width;
                var src_height = ShapeSheet.SRCConstants.Height;

                var update = new ShapeSheet.Update();
                for (int i = 0; i < new_sizes.Count; i++)
                {
                    var shapeid  = shapeids[i];
                    var new_size = new_sizes[i];
                    update.SetFormula((short)shapeid, src_width, new_size.Width);
                    update.SetFormula((short)shapeid, src_height, new_size.Height);
                }

                update.Execute(active_page);
            }
        }
 internal void ApplyFormulas(ShapeSheet.Update update, short row)
 {
     update.SetFormulaIgnoreNull(SRCCON.Para_IndLeft.ForRow(row), this.IndentLeft);
     update.SetFormulaIgnoreNull(SRCCON.Para_IndFirst.ForRow(row), this.IndentFirst);
     update.SetFormulaIgnoreNull(SRCCON.Para_IndRight.ForRow(row), this.IndentRight);
     update.SetFormulaIgnoreNull(SRCCON.Para_SpAfter.ForRow(row), this.SpacingAfter);
     update.SetFormulaIgnoreNull(SRCCON.Para_SpBefore.ForRow(row), this.SpacingBefore);
     update.SetFormulaIgnoreNull(SRCCON.Para_SpLine.ForRow(row), this.SpacingLine);
     update.SetFormulaIgnoreNull(SRCCON.Para_HorzAlign.ForRow(row), this.HorizontalAlign);
     update.SetFormulaIgnoreNull(SRCCON.Para_BulletFont.ForRow(row), this.BulletFont);
     update.SetFormulaIgnoreNull(SRCCON.Para_Bullet.ForRow(row), this.Bullet);
     update.SetFormulaIgnoreNull(SRCCON.Para_BulletFontSize.ForRow(row), this.BulletFontSize);
     update.SetFormulaIgnoreNull(SRCCON.Para_LocalizeBulletFont.ForRow(row), this.LocBulletFont);
     update.SetFormulaIgnoreNull(SRCCON.Para_TextPosAfterBullet.ForRow(row), this.TextPosAfterBullet);
     update.SetFormulaIgnoreNull(SRCCON.Para_Flags.ForRow(row), this.Flags);
     update.SetFormulaIgnoreNull(SRCCON.Para_BulletStr.ForRow(row), this.BulletString);
 }
Exemple #36
0
        private void Update(short section, short row_index, ShapeSheet.Update update)
        {
            var x_src = ShapeSheet.SRCConstants.Geometry_X.ForSectionAndRow(section, row_index);
            var y_src = ShapeSheet.SRCConstants.Geometry_Y.ForSectionAndRow(section, row_index);
            var a_src = ShapeSheet.SRCConstants.Geometry_A.ForSectionAndRow(section, row_index);
            var b_src = ShapeSheet.SRCConstants.Geometry_B.ForSectionAndRow(section, row_index);
            var c_src = ShapeSheet.SRCConstants.Geometry_C.ForSectionAndRow(section, row_index);
            var d_src = ShapeSheet.SRCConstants.Geometry_D.ForSectionAndRow(section, row_index);
            var e_src = ShapeSheet.SRCConstants.Geometry_E.ForSectionAndRow(section, row_index);

            update.SetFormulaIgnoreNull(x_src, this.X);
            update.SetFormulaIgnoreNull(y_src, this.Y);
            update.SetFormulaIgnoreNull(a_src, this.A);
            update.SetFormulaIgnoreNull(b_src, this.B);
            update.SetFormulaIgnoreNull(c_src, this.C);
            update.SetFormulaIgnoreNull(d_src, this.D);
            update.SetFormulaIgnoreNull(e_src, this.E);
        }
        private static short[] DropManyU(
            IVisio.Page page,
            IList <IVisio.Master> masters,
            IList <Drawing.Rectangle> rects)
        {
            var points   = rects.Select(r => r.Center).ToList();
            var shapeids = Pages.PageHelper.DropManyU(page, masters, points);

            var xfrm = new Shapes.XFormCells();

            var update = new ShapeSheet.Update(points.Count * 2);

            for (int i = 0; i < rects.Count(); i++)
            {
                xfrm.Width  = rects[i].Width;
                xfrm.Height = rects[i].Height;
                update.SetFormulas(shapeids[i], xfrm);
            }
            update.Execute(page);

            return(shapeids);
        }
Exemple #38
0
        public void SetOrientation(Pages.PrintPageOrientation orientation)
        {
            this.Client.Application.AssertApplicationAvailable();
            this.Client.Document.AssertDocumentAvailable();

            var app         = this.Client.Application.Get();
            var application = app;

            var active_page = application.ActivePage;

            if (orientation != Pages.PrintPageOrientation.Landscape && orientation != Pages.PrintPageOrientation.Portrait)
            {
                throw new System.ArgumentOutOfRangeException(nameof(orientation), "must be either Portrait or Landscape");
            }

            var old_orientation = PageCommands.GetOrientation(active_page);

            if (old_orientation == orientation)
            {
                // don't need to do anything
                return;
            }

            var old_size = this.GetSize();

            double new_height = old_size.Width;
            double new_width  = old_size.Height;

            var update = new ShapeSheet.Update(3);

            update.SetFormula(ShapeSheet.SRCConstants.PageWidth, new_width);
            update.SetFormula(ShapeSheet.SRCConstants.PageHeight, new_height);
            update.SetFormula(ShapeSheet.SRCConstants.PrintPageOrientation, (int)orientation);

            using (var undoscope = this.Client.Application.NewUndoScope("Set Page Orientation"))
            {
                update.Execute(active_page.PageSheet);
            }
        }
        public static void Set(
            IVisio.Shape shape,
            string name,
            CustomPropertyCells cp)
        {
            if (shape == null)
            {
                throw new ArgumentNullException(nameof(shape));
            }

            CustomPropertyHelper.CheckValidCustomPropertyName(name);

            if (CustomPropertyHelper.Contains(shape, name))
            {
                string full_prop_name = CustomPropertyHelper.GetRowName(name);
                var cell_propname = shape.CellsU[full_prop_name];

                if (cell_propname == null)
                {
                    string msg = $"Could not retrieve cell for custom property \"{full_prop_name}\"";
                    throw new AutomationException(msg);
                }

                var update = new ShapeSheet.Update();
                update.SetFormulas(cp, cell_propname.Row);
                update.Execute(shape);

                return;

            }

            short row = shape.AddNamedRow(
                (short)IVisio.VisSectionIndices.visSectionProp,
                name,
                (short)IVisio.VisRowIndices.visRowProp);

            CustomPropertyHelper.Set(shape, row, cp);
        }
        public void Set(IList<IVisio.Shape> target_shapes, Shapes.FormatCells format)
        {
            this.Client.Application.AssertApplicationAvailable();
            this.Client.Document.AssertDocumentAvailable();

            var shapes = this.GetTargetShapes(target_shapes);

            if (shapes.Count<1)
            {
                return;
            }

            var update = new ShapeSheet.Update();
            var shapeids = shapes.Select(s => s.ID).ToList();

            foreach (int shapeid in shapeids)
            {
                update.SetFormulas((short)shapeid, format);
            }

            var application = this.Client.Application.Get();
            update.Execute(application.ActivePage);            
        }
        public static void Duplicate(
            IVisio.Page src_page,
            IVisio.Page dest_page)
        {
            var app = src_page.Application;
            short copy_paste_flags = (short)IVisio.VisCutCopyPasteCodes.visCopyPasteNoTranslate;

            // handle the source page
            if (src_page == null)
            {
                throw new System.ArgumentNullException(nameof(src_page));
            }

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

            if (dest_page == src_page)
            {
                throw new AutomationException("Destination Page cannot be Source Page");
            }


            if (src_page != app.ActivePage)
            {
                throw new AutomationException("Source page must be active page.");
            }

            var src_page_shapes = src_page.Shapes;
            int num_src_shapes=src_page_shapes.Count;

            if (num_src_shapes > 0)
            {
                var active_window = app.ActiveWindow;
                active_window.SelectAll();
                var selection = active_window.Selection;
                selection.Copy(copy_paste_flags);
                active_window.DeselectAll();
            }

            var src_pagesheet = src_page.PageSheet;
            var pagecells = PageCells.GetCells(src_pagesheet);


            // handle the dest page

            // first update all the page cells
            var dest_pagesheet = dest_page.PageSheet;
            var update = new ShapeSheet.Update();
            update.SetFormulas(pagecells);
            update.Execute(dest_pagesheet);

            // make sure the new page looks like the old page
            dest_page.Background = src_page.Background;
            
            // then paste any contents from the first page
            if (num_src_shapes>0)
            {
                dest_page.Paste(copy_paste_flags);                
            }
        }
        public void SetSize(Drawing.Size new_size)
        {
            this.Client.Application.AssertApplicationAvailable();
            this.Client.Document.AssertDocumentAvailable();

            var application = this.Client.Application.Get();
            using (var undoscope = this.Client.Application.NewUndoScope("Set Page Size"))
            {
                var active_page = application.ActivePage;
                var page_sheet = active_page.PageSheet;
                var update = new ShapeSheet.Update(2);
                update.SetFormula(ShapeSheet.SRCConstants.PageWidth, new_size.Width);
                update.SetFormula(ShapeSheet.SRCConstants.PageHeight, new_size.Height);
                update.Execute(page_sheet);
            }
        }
        public void ResetOrigin(IVisio.Page page)
        {
            this.Client.Application.AssertApplicationAvailable();
            this.Client.Document.AssertDocumentAvailable();

            var application = this.Client.Application.Get();
            if (page == null)
            {
                page = application.ActivePage;
            }

            var update = new ShapeSheet.Update();

            update.SetFormula(ShapeSheet.SRCConstants.XGridOrigin, "0.0");
            update.SetFormula(ShapeSheet.SRCConstants.YGridOrigin, "0.0");
            update.SetFormula(ShapeSheet.SRCConstants.XRulerOrigin, "0.0");
            update.SetFormula(ShapeSheet.SRCConstants.YRulerOrigin, "0.0");

            using (var undoscope = this.Client.Application.NewUndoScope("Reset Page Origin"))
            {
                update.Execute(page.PageSheet);
            }
        }
        public void SetOrientation(Pages.PrintPageOrientation orientation)
        {
            this.Client.Application.AssertApplicationAvailable();
            this.Client.Document.AssertDocumentAvailable();

            var app = this.Client.Application.Get();
            var application = app;

            var active_page = application.ActivePage;

            if (orientation != Pages.PrintPageOrientation.Landscape && orientation != Pages.PrintPageOrientation.Portrait)
            {
                throw new System.ArgumentOutOfRangeException(nameof(orientation), "must be either Portrait or Landscape");
            }

            var old_orientation = PageCommands.GetOrientation(active_page);

            if (old_orientation == orientation)
            {
                // don't need to do anything
                return;
            }

            var old_size = this.GetSize();

            double new_height = old_size.Width;
            double new_width = old_size.Height;

            var update = new ShapeSheet.Update(3);
            update.SetFormula(ShapeSheet.SRCConstants.PageWidth, new_width);
            update.SetFormula(ShapeSheet.SRCConstants.PageHeight, new_height);
            update.SetFormula(ShapeSheet.SRCConstants.PrintPageOrientation, (int)orientation);

            using (var undoscope = this.Client.Application.NewUndoScope("Set Page Orientation"))
            {
                update.Execute(active_page.PageSheet);
            }
        }
 private static void SetSize(IVisio.Page page, Drawing.Size size)
 {
     var page_cells = new PageCells();
     page_cells.PageHeight = size.Height;
     page_cells.PageWidth = size.Width;
     var pageupdate = new ShapeSheet.Update();
     pageupdate.SetFormulas(page_cells);
     pageupdate.Execute(page.PageSheet);
 }
        public void PasteSize(IList<IVisio.Shape> target_shapes, bool paste_width, bool paste_height)
        {
            this.Client.Application.AssertApplicationAvailable();
            this.Client.Document.AssertDocumentAvailable();
            
            var shapes = this.GetTargetShapes(target_shapes);

            if (shapes.Count < 1)
            {
                return;
            }

            if ((!this.cached_size_width.HasValue) && (!this.cached_size_height.HasValue))
            {
                return;
            }

            var update = new ShapeSheet.Update();
            var shapeids = shapes.Select(s => s.ID).ToList();

            foreach (var shapeid in shapeids)
            {
                if (paste_width)
                {
                    update.SetFormula((short)shapeid, ShapeSheet.SRCConstants.Width, this.cached_size_width.Value);
                }

                if (paste_height)
                {
                    update.SetFormula((short)shapeid, ShapeSheet.SRCConstants.Height, this.cached_size_height.Value);
                }
            }

            var application = this.Client.Application.Get();
            var active_page = application.ActivePage;
            update.Execute(active_page);
        }
        /// <summary>
        /// Remove all tab stops on the shape
        /// </summary>
        /// <param name="shape"></param>
        private static void ClearTabStops(IVisio.Shape shape)
        {
            if (shape == null)
            {
                throw new System.ArgumentNullException(nameof(shape));
            }

            int num_existing_tabstops = TextFormat.GetTabStopCount(shape);

            if (num_existing_tabstops < 1)
            {
                return;
            }

            var cell_tabstopcount = shape.CellsSRC[TextFormat.src_tabstopcount.Section, TextFormat.src_tabstopcount.Row, TextFormat.src_tabstopcount.Cell];
            cell_tabstopcount.FormulaForce = "0";

            const string formula = "0";

            var update = new ShapeSheet.Update();
            for (int i = 1; i < num_existing_tabstops * 3; i++)
            {
                var src = new ShapeSheet.SRC(TextFormat.tab_section, (short)IVisio.VisRowIndices.visRowTab,
                                                (short)i);
                update.SetFormula(src, formula);
            }

            update.Execute(shape);
        }
        public void SetSize(IList<IVisio.Shape> target_shapes, double? w, double? h)
        {
            this.Client.Application.AssertApplicationAvailable();
            this.Client.Document.AssertDocumentAvailable();

            var shapes = this.GetTargetShapes(target_shapes);
            if (shapes.Count < 1)
            {
                return;
            } 

            var shapeids = shapes.Select(s=>s.ID).ToList();
            var update = new ShapeSheet.Update();
            foreach (int shapeid in shapeids)
            {
                if (w.HasValue && w.Value>=0)
                {
                    update.SetFormula((short)shapeid, ShapeSheet.SRCConstants.Width, w.Value);
                }
                if (h.HasValue && h.Value >= 0)
                {
                    update.SetFormula((short)shapeid, ShapeSheet.SRCConstants.Height, h.Value);                    
                }
            }

            var application = this.Client.Application.Get();
            using (var undoscope = this.Client.Application.NewUndoScope("Set Shape Size"))
            {
                var active_page = application.ActivePage;
                update.Execute(active_page);
            }
        }
        public void SetLock(IList<IVisio.Shape> target_shapes, Shapes.LockCells lockcells)
        {
            this.Client.Application.AssertApplicationAvailable();
            this.Client.Document.AssertDocumentAvailable();

            var shapes = this.GetTargetShapes(target_shapes);
            if (shapes.Count < 1)
            {
                return;
            } 

            var selection = this.Client.Selection.Get();
            var shapeids = selection.GetIDs();
            var update = new ShapeSheet.Update();

            foreach (int shapeid in shapeids)
            {
                update.SetFormulas((short)shapeid, lockcells);
            }

            var application = this.Client.Application.Get();
            using (var undoscope = this.Client.Application.NewUndoScope("Set Shape Lock Properties"))
            {
                var active_page = application.ActivePage;
                update.Execute(active_page);
            }
        }
        private static void update_xfrms(IVisio.Page page, IList<int> shapeids, IList<Shapes.XFormCells> xfrms)
        {

            var update = new ShapeSheet.Update();
            for (int i = 0; i < shapeids.Count; i++)
            {
                var shape_id = shapeids[i];
                var xfrm = xfrms[i];
                update.SetFormulas((short)shape_id, xfrm);
            }
            update.Execute(page);
        }
 public ShapeSheetUpdate(Client client, IVisio.Page page)
 {
     this.Client = client;
     this.TargetPage = page;
     this.update = new ShapeSheet.Update();
 }
        private static short[] DropManyU(
            IVisio.Page page,
            IList<IVisio.Master> masters,
            IList<Drawing.Rectangle> rects)
        {
            var points = rects.Select(r => r.Center).ToList();
            var shapeids = Pages.PageHelper.DropManyU(page, masters, points);

            var xfrm = new Shapes.XFormCells();

            var update = new ShapeSheet.Update(points.Count*2);
            for (int i = 0; i < rects.Count(); i++)
            {
                xfrm.Width = rects[i].Width;
                xfrm.Height = rects[i].Height;
                update.SetFormulas(shapeids[i], xfrm);
            }
            update.Execute(page);

            return shapeids;
        }
        public void MoveTextToBottom(IList<IVisio.Shape> target_shapes)
        {
            this.Client.Application.AssertApplicationAvailable();
            this.Client.Document.AssertDocumentAvailable();

            var shapes = this.GetTargetShapes(target_shapes);
            if (shapes.Count < 1)
            {
                return ;
            }

            var update = new ShapeSheet.Update();
            foreach (var shape in shapes)
            {
                if (0 ==
                    shape.RowExists[
                        (short) IVisio.VisSectionIndices.visSectionObject, (short) IVisio.VisRowIndices.visRowTextXForm,
                        (short) IVisio.VisExistsFlags.visExistsAnywhere])
                {
                    shape.AddRow((short)IVisio.VisSectionIndices.visSectionObject, (short)IVisio.VisRowIndices.visRowTextXForm, (short)IVisio.VisRowTags.visTagDefault); 
                    
                }
            }

            var application = this.Client.Application.Get();
            var shapeids = shapes.Select(s=>s.ID);
            foreach (int shapeid in shapeids)
            {
                update.SetFormula((short)shapeid, ShapeSheet.SRCConstants.TxtHeight, "Height*0"); 
                update.SetFormula((short)shapeid, ShapeSheet.SRCConstants.TxtPinY, "Height*0"); 
                update.SetFormula((short)shapeid, ShapeSheet.SRCConstants.VerticalAlign, "0");
            } 
            var active_page = application.ActivePage; 
            update.Execute(active_page);
        }
 public void Finish()
 {
     var update = new ShapeSheet.Update();
     foreach (var block in this.Blocks)
     {
         update.SetFormulas((short)block.VisioShapeID,block.FormatCells);
         update.SetFormulas((short)block.VisioShapeID,block.TextBlockCells);
         update.SetFormulas((short)block.VisioShapeID,block.ParagraphCells, 0);
         update.SetFormulas((short)block.VisioShapeID,block.CharacterCells, 0);
     }
     update.Execute(this.page);
 }
        public static void SetTabStops(IVisio.Shape shape, IList<TabStop> stops)
        {
            if (shape == null)
            {
                throw new System.ArgumentNullException(nameof(shape));
            }

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

            TextFormat.ClearTabStops(shape);
            if (stops.Count < 1)
            {
                return;
            }

            const short row = 0;
            var invariant_culture = System.Globalization.CultureInfo.InvariantCulture;
            var vis_tab_stop_count = (short)IVisio.VisCellIndices.visTabStopCount;
            var tabstopcountcell = shape.CellsSRC[TextFormat.tab_section, row, vis_tab_stop_count];
            tabstopcountcell.FormulaU = stops.Count.ToString(invariant_culture);

            // set the number of tab stobs allowed for the shape
            var tagtab = TextFormat.GetTabTagForStops(stops.Count);
            shape.RowType[TextFormat.tab_section, (short)IVisio.VisRowIndices.visRowTab] = (short)tagtab;

            // add tab properties for each stop
            var update = new ShapeSheet.Update();
            for (int stop_index = 0; stop_index < stops.Count; stop_index++)
            {
                int i = stop_index * 3;

                var alignment = ((int)stops[stop_index].Alignment).ToString(invariant_culture);
                var position = ((int)stops[stop_index].Position).ToString(invariant_culture);

                var src_tabpos = new ShapeSheet.SRC(TextFormat.tab_section, row, (short)(i + 1));
                var src_tabalign = new ShapeSheet.SRC(TextFormat.tab_section, row, (short)(i + 2));
                var src_tabother = new ShapeSheet.SRC(TextFormat.tab_section, row, (short)(i + 3));

                update.SetFormula(src_tabpos, position); // tab position
                update.SetFormula(src_tabalign, alignment); // tab alignment
                update.SetFormula(src_tabother, "0"); // tab unknown
            }

            update.Execute(shape);
        }
        public IVisio.Page Render(IVisio.Document doc)
        {
            if (!this.IsLayedOut)
            {
                string msg =
                    $"{typeof (ContainerLayout).Name} usage error. Call PerformLayout() before calling Render().";
                throw new AutomationException(msg);
            }
            // create a new drawing
            var app = doc.Application;
            var docs = app.Documents;
            var pages = doc.Pages;
            var page = pages.Add();

            // load the stencil used to draw the items
            var item_stencil = docs.OpenStencil(this.LayoutOptions.ManualItemStencil);
            var item_stencil_masters = item_stencil.Masters;
            var item_master = item_stencil_masters[this.LayoutOptions.ManualItemMaster];
            var plain_container_master = item_stencil_masters[this.LayoutOptions.ManualContainerMaster];

            var page_shapes = page.Shapes;

            // Drop the container shapes
            var ct_items = this.Containers.ToList();
            var ct_rects = ct_items.Select(item => item.Rectangle).ToList();
            var masters = ct_items.Select(i => plain_container_master).ToList();
            short[] ct_shapeids = ContainerLayout.DropManyU(page, masters, ct_rects);

            // associate each container with the corresponding shape oject and shape id
            for (int i = 0; i < ct_items.Count; i++)
            {
                var ct_item = ct_items[i];
                var ct_shapeid = ct_shapeids[i];
                var shape = page_shapes[ct_shapeid];
                ct_item.VisioShape = shape;
                ct_item.ShapeID = ct_shapeid;
            }

            // Render the items
            var items = this.ContainerItems.ToList();
            var item_rects = items.Select(item => item.Rectangle).ToList();
            var item_masters = items.Select(i => item_master).ToList();
            short[] shapeids = ContainerLayout.DropManyU(page, item_masters, item_rects);

            // Associate each item with the corresponding shape object and shape id
            for (int i = 0; i < items.Count; i++)
            {
                var item = items[i];
                var shapeid = shapeids[i];
                var shape = page_shapes[shapeid];
                item.VisioShape = shape;
                item.ShapeID = shapeid;
            }

            // Often useful to show everthing because these diagrams can get large
            app.ActiveWindow.ViewFit = (short)IVisio.VisWindowFit.visFitPage;

            // Set the items
            foreach (var item in items.Where(i => i.Text != null))
            {
                item.VisioShape.Text = item.Text;
            }

            var update = new ShapeSheet.Update();

            // Format the containers and shapes

            foreach (var item in this.Containers)
            {
                this.LayoutOptions.ContainerFormatting.Apply(update, item.ShapeID,item.ShapeID);
            }

            foreach (var item in this.ContainerItems)
            {
                this.LayoutOptions.ContainerItemFormatting.Apply(update, item.ShapeID, item.ShapeID);
            }

            update.BlastGuards = true;
            update.Execute(page);

            // Set the Container Text
            foreach (var ct in this.Containers)
            {
                if (ct.Text != null)
                {
                    ct.Text.SetText(ct.VisioShape);
                }
            }

            page.ResizeToFitContents();
            app.ActiveWindow.ViewFit = (short)IVisio.VisWindowFit.visFitPage;

            return page;
        }
        public void ToogleCase(IList<IVisio.Shape> target_shapes)
        {
            this.Client.Application.AssertApplicationAvailable();
            this.Client.Document.AssertDocumentAvailable();
            
            var shapes = this.GetTargetShapes(target_shapes);

            if (shapes.Count < 1)
            {
                return;
            }

            var application = this.Client.Application.Get();
            using (var undoscope = this.Client.Application.NewUndoScope("Toggle Shape Text Case"))
            {
                var shapeids = shapes.Select(s => s.ID).ToList();

                var page = application.ActivePage;
                // Store all the formatting
                var formats = Text.TextFormat.GetFormat(page, shapeids);

                // Change the text - this will wipe out all the character and paragraph formatting
                foreach (var shape in shapes)
                {
                    string t = shape.Text;
                    if (t.Length < 1)
                    {
                        continue;
                    }
                    shape.Text = TextCommandsUtil.toggle_case(t);
                }

                // Now restore all the formatting - based on any initial formatting from the text

                var update = new ShapeSheet.Update();
                for (int i = 0; i < shapes.Count; i++)
                {
                    var format = formats[i];

                    if (format.CharacterFormats.Count>0)
                    {
                        var fmt = format.CharacterFormats[0];
                        update.SetFormulas((short) shapeids[i], fmt, 0);
                    }

                    if (format.ParagraphFormats.Count > 0)
                    {
                        var fmt = format.ParagraphFormats[0];
                        update.SetFormulas((short)shapeids[i], fmt, 0);
                    }
                }

                update.Execute(page);
            }
        }
        public void FitShapeToText(IList<IVisio.Shape> target_shapes)
        {
            this.Client.Application.AssertApplicationAvailable();
            this.Client.Document.AssertDocumentAvailable();

            var shapes = this.GetTargetShapes2D(target_shapes);
            if (shapes.Count < 1)
            {
                return;
            }

            var application = this.Client.Application.Get();
            var active_page = application.ActivePage;
            var shapeids = shapes.Select(s => s.ID).ToList();

            using (var undoscope = this.Client.Application.NewUndoScope("FitShapeToText"))
            {
                // Calculate the new sizes for each shape
                var new_sizes = new List<Drawing.Size>(shapeids.Count);
                foreach (var shape in shapes)
                {
                    var text_bounding_box = shape.GetBoundingBox(Microsoft.Office.Interop.Visio.VisBoundingBoxArgs.visBBoxUprightText).Size;
                    var wh_bounding_box = shape.GetBoundingBox(Microsoft.Office.Interop.Visio.VisBoundingBoxArgs.visBBoxUprightWH).Size;

                    double max_w = System.Math.Max(text_bounding_box.Width, wh_bounding_box.Width);
                    double max_h = System.Math.Max(text_bounding_box.Height, wh_bounding_box.Height);
                    var max_size = new Drawing.Size(max_w, max_h);
                    new_sizes.Add(max_size);
                }

                var src_width = ShapeSheet.SRCConstants.Width;
                var src_height = ShapeSheet.SRCConstants.Height;

                var update = new ShapeSheet.Update();
                for (int i = 0; i < new_sizes.Count; i++)
                {
                    var shapeid = shapeids[i];
                    var new_size = new_sizes[i];
                    update.SetFormula((short)shapeid, src_width, new_size.Width);
                    update.SetFormula((short)shapeid, src_height, new_size.Height);
                }

                update.Execute(active_page);
            }
        }
        public void SetText(IVisio.Shape shape)
        {
            if (shape == null)
            {
                throw new System.ArgumentNullException(nameof(shape));
            }

            // First just set all the text
            string full_doc_inner_text = this.GetInnerText();
            shape.Text = full_doc_inner_text;

            // Find all the regions needing formatting
            var markupinfo = this.GetMarkupInfo();
            var regions_to_format = markupinfo.FormatRegions.Where(region => region.Length >= 1).ToList();

            
            var default_chars_bias = IVisio.VisCharsBias.visBiasLeft;


            var update = new ShapeSheet.Update();

            foreach (var region in regions_to_format)
            {

                // Apply character formatting
                var charcells = region.Element.CharacterCells;
                if (charcells != null)
                {
                    var chars = shape.Characters;
                    chars.Begin = region.Start;
                    chars.End = region.End;
                    chars.CharProps[ShapeSheet.SRCConstants.CharColor.Cell] = 0;
                    short rownum = chars.CharPropsRow[(short) default_chars_bias];

                    if (rownum < 0)
                    {
                        throw new AutomationException("Could not create Character row");
                    }

                    update.Clear();
                    charcells.ApplyFormulas(update, rownum);
                    update.Execute(shape);
                }

                // Apply paragraph formatting
                var paracells = region.Element.ParagraphCells;
                if (paracells != null)
                {
                    var chars = shape.Characters;
                    chars.Begin = region.Start;
                    chars.End = region.End;
                    chars.ParaProps[ShapeSheet.SRCConstants.Para_Bullet.Cell] = 0;
                    short rownum = chars.ParaPropsRow[(short) default_chars_bias];

                    if (rownum < 0)
                    {
                        throw new AutomationException("Could not create Paragraph row");
                    }

                    update.Clear();
                    paracells.ApplyFormulas(update, rownum);
                    update.Execute(shape);
                }
            }

            // Insert the fields
            // note: Fields are added in reverse because it is simpler to keep track of the insertion positions
            foreach (var field_region in markupinfo.FieldRegions.Where(region => region.Length >= 1).Reverse())
            {
                var chars = shape.Characters;
                chars.Begin = field_region.Start;
                chars.End = field_region.End;
                chars.AddField((short) field_region.Field.Category, (short) field_region.Field.Code,
                               (short) field_region.Field.Format);
                var fr = field_region;
            }
        }
        public void PasteFormat(IVisio.Page page, IList<int> shapeids, FormatCategory category, bool applyformulas)
        {
            var update = new ShapeSheet.Update();

            foreach (var shape_id in shapeids)
            {
                foreach (var cellrec in this.Cells)
                {
                    if (!cellrec.MatchesCategory(category))
                    {
                        continue;
                    }

                    var sidsrc = new ShapeSheet.SIDSRC((short)shape_id, cellrec.SRC);

                    if (applyformulas)
                    {
                        update.SetFormula(sidsrc, cellrec.Formula);
                        
                    }
                    else
                    {
                        if (cellrec.Result != null)
                        {
                            update.SetFormula(sidsrc, cellrec.Result);
                        }
                    }
                }
            }

            update.Execute(page);
        }