public IVisio.Page CreatePage(FormPage formpage)
        {
            this._form_page = formpage;

            this._page      = this._visio_pages.Add();
            this._page.Name = formpage.Name;

            // Update the Page Cells
            var pagesheet  = this._page.PageSheet;
            var pagewriter = new FormulaWriterSRC();

            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;
            pagecells.SetFormulas(pagewriter);
            pagewriter.Commit(pagesheet);


            this.Reset();
            return(this._page);
        }
Exemplo n.º 2
0
        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 = string.Format("Controls.Row_{0}", row + 1);
            }

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

            var writer = new FormulaWriterSRC();

            ctrl.SetFormulas(writer, row);
            writer.Commit(shape);

            return(row);
        }
Exemplo n.º 3
0
        private static void VerifyPageSizeToFit(IVisio.Document doc,
                                                VA.Drawing.Size bottomleft_margin,
                                                VA.Drawing.Size upperright_margin,
                                                VA.Drawing.Size shape_size,
                                                VA.Drawing.Size padding_size,
                                                double expected_pinx,
                                                double expected_piny)
        {
            var page = doc.Pages.Add();

            var pagecells = new VA.Pages.PageCells();

            pagecells.PageTopMargin    = upperright_margin.Height;
            pagecells.PageBottomMargin = bottomleft_margin.Height;
            pagecells.PageLeftMargin   = bottomleft_margin.Width;
            pagecells.PageRightMargin  = upperright_margin.Width;

            var page_writer = new FormulaWriterSRC();

            pagecells.SetFormulas(page_writer);
            page_writer.Commit(page.PageSheet);


            var shape = page.DrawRectangle(5, 5, 5 + shape_size.Width, 5 + shape_size.Height);

            page.ResizeToFitContents(padding_size);
            var xform  = VA.Shapes.XFormCells.GetCells(shape);
            var pinpos = xform.GetPinPosResult();

            Assert.AreEqual(expected_pinx, pinpos.X, 0.1);
            Assert.AreEqual(expected_piny, pinpos.Y, 0.1);
            page.Delete(0);
        }
Exemplo n.º 4
0
        protected override void ProcessRecord()
        {
            if (this.FitContents)
            {
                var bordersize = new VisioAutomation.Drawing.Size(this.BorderWidth, this.BorderWidth);
                this.Client.Page.ResizeToFitContents(bordersize, true);
            }

            if (this.Width > 0 || this.Height > 0)
            {
                var page      = this.Client.Application.Get().ActivePage;
                var pagecells = VisioAutomation.Pages.PageCells.GetCells(page.PageSheet);

                var newpagecells = new VisioAutomation.Pages.PageCells();

                if (this.Width > 0)
                {
                    newpagecells.PageWidth = this.Width;
                }

                if (this.Height > 0)
                {
                    newpagecells.PageHeight = this.Height;
                }

                var writer = new FormulaWriterSRC();
                newpagecells.SetFormulas(writer);
                writer.BlastGuards = true;
                writer.Commit(page);
            }
        }
Exemplo n.º 5
0
        public short Render(IVisio.Shape shape)
        {
            short sec_index = GeometryHelper.AddSection(shape);
            short row_count = shape.RowCount[sec_index];

            var writer = new FormulaWriterSRC();

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

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

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

            writer.Commit(shape);
            return(0);
        }
Exemplo n.º 6
0
 public void SetFormulas(FormulaWriterSRC writer)
 {
     foreach (var pair in this.Pairs)
     {
         writer.SetFormula(pair.SRC, pair.Formula);
     }
 }
Exemplo n.º 7
0
        /// <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 = GetTabStopCount(shape);

            if (num_existing_tabstops < 1)
            {
                return;
            }

            var cell_tabstopcount = shape.CellsSRC[ShapeSheet.SRCConstants.Tabs_StopCount.Section, ShapeSheet.SRCConstants.Tabs_StopCount.Row, ShapeSheet.SRCConstants.Tabs_StopCount.Cell];

            cell_tabstopcount.FormulaForce = "0";

            const string formula = "0";

            var writer = new FormulaWriterSRC();

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

            writer.Commit(shape);
        }
Exemplo n.º 8
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 writer = new FormulaWriterSRC();

            connection_point_cells.SetFormulas(writer, n);
            writer.Commit(shape);

            return(n);
        }
Exemplo n.º 9
0
 internal void ApplyFormulas(FormulaWriterSRC writer, short row)
 {
     writer.SetFormula(SRCCON.CharColor.CopyWithNewRow(row), this.Color);
     writer.SetFormula(SRCCON.CharFont.CopyWithNewRow(row), this.Font);
     writer.SetFormula(SRCCON.CharSize.CopyWithNewRow(row), this.Size);
     writer.SetFormula(SRCCON.CharStyle.CopyWithNewRow(row), this.Style);
     writer.SetFormula(SRCCON.CharColorTrans.CopyWithNewRow(row), this.Transparency);
     writer.SetFormula(SRCCON.CharAsianFont.CopyWithNewRow(row), this.AsianFont);
     writer.SetFormula(SRCCON.CharCase.CopyWithNewRow(row), this.Case);
     writer.SetFormula(SRCCON.CharComplexScriptFont.CopyWithNewRow(row), this.ComplexScriptFont);
     writer.SetFormula(SRCCON.CharComplexScriptSize.CopyWithNewRow(row), this.ComplexScriptSize);
     writer.SetFormula(SRCCON.CharDblUnderline.CopyWithNewRow(row), this.DoubleUnderline);
     writer.SetFormula(SRCCON.CharDoubleStrikethrough.CopyWithNewRow(row), this.DoubleStrikeThrough);
     writer.SetFormula(SRCCON.CharLangID.CopyWithNewRow(row), this.LangID);
     writer.SetFormula(SRCCON.CharFontScale.CopyWithNewRow(row), this.FontScale);
     writer.SetFormula(SRCCON.CharLangID.CopyWithNewRow(row), this.LangID);
     writer.SetFormula(SRCCON.CharLetterspace.CopyWithNewRow(row), this.Letterspace);
     writer.SetFormula(SRCCON.CharLocale.CopyWithNewRow(row), this.Locale);
     writer.SetFormula(SRCCON.CharLocalizeFont.CopyWithNewRow(row), this.LocalizeFont);
     writer.SetFormula(SRCCON.CharOverline.CopyWithNewRow(row), this.Overline);
     writer.SetFormula(SRCCON.CharPerpendicular.CopyWithNewRow(row), this.Perpendicular);
     writer.SetFormula(SRCCON.CharPos.CopyWithNewRow(row), this.Pos);
     writer.SetFormula(SRCCON.CharRTLText.CopyWithNewRow(row), this.RTLText);
     writer.SetFormula(SRCCON.CharStrikethru.CopyWithNewRow(row), this.Strikethru);
     writer.SetFormula(SRCCON.CharUseVertical.CopyWithNewRow(row), this.UseVertical);
 }
Exemplo n.º 10
0
        private static void SetSize(IVisio.Page page, Drawing.Size size)
        {
            var writer = new FormulaWriterSRC();

            writer.SetFormula(VisioAutomation.ShapeSheet.SRCConstants.PageWidth, size.Width);
            writer.SetFormula(VisioAutomation.ShapeSheet.SRCConstants.PageHeight, size.Height);
            writer.Commit(page.PageSheet);
        }
Exemplo n.º 11
0
 public void SetFormulas(FormulaWriterSRC writer, short row)
 {
     foreach (var pair in this.Pairs)
     {
         var new_src = pair.SRC.CopyWithNewRow(row);
         writer.SetFormula(new_src, pair.Formula);
     }
 }
        public static void Set(IVisio.Shape shape, short row, CustomPropertyCells cp)
        {
            if (shape == null)
            {
                throw new ArgumentNullException(nameof(shape));
            }

            var writer = new FormulaWriterSRC();
            cp.SetFormulas(writer, row);
            writer.Commit(shape);
        }
Exemplo n.º 13
0
        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));
            }

            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[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 = GetTabTagForStops(stops.Count);

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

            // add tab properties for each stop
            var writer = new FormulaWriterSRC();

            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(tab_section, row, (short)(i + 1));
                var src_tabalign = new ShapeSheet.SRC(tab_section, row, (short)(i + 2));
                var src_tabother = new ShapeSheet.SRC(tab_section, row, (short)(i + 3));

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

            writer.Commit(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));
            }

            UserDefinedCellHelper.CheckValidName(name);

            if (UserDefinedCellHelper.Contains(shape, name))
            {
                string full_prop_name = UserDefinedCellHelper.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(
                UserDefinedCellHelper._userdefinedcell_section,
                name,
                (short)IVisio.VisRowIndices.visRowUser);

            var writer = new FormulaWriterSRC();

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

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

            writer.Commit(shape);
        }
Exemplo n.º 15
0
        public static void SetPageSize(IVisio.Page page, VA.Drawing.Size size)
        {
            if (page == null)
            {
                throw new System.ArgumentNullException(nameof(page));
            }

            var page_sheet = page.PageSheet;

            var writer = new FormulaWriterSRC(2);

            writer.SetFormula(VA.ShapeSheet.SRCConstants.PageWidth, size.Width);
            writer.SetFormula(VA.ShapeSheet.SRCConstants.PageHeight, size.Height);
            writer.Commit(page_sheet);
        }
Exemplo n.º 16
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 writer      = new FormulaWriterSRC(2);
                writer.SetFormula(VisioAutomation.ShapeSheet.SRCConstants.PageWidth, new_size.Width);
                writer.SetFormula(VisioAutomation.ShapeSheet.SRCConstants.PageHeight, new_size.Height);
                writer.Commit(page_sheet);
            }
        }
Exemplo n.º 17
0
        public static int Set(
            IVisio.Shape shape,
            short row,
            HyperlinkCells hyperlink)
        {
            if (shape == null)
            {
                throw new ArgumentNullException(nameof(shape));
            }

            var writer = new FormulaWriterSRC();

            hyperlink.SetFormulas(writer, row);
            writer.Commit(shape);

            return(row);
        }
 internal void ApplyFormulas(FormulaWriterSRC writer, short row)
 {
     writer.SetFormula(SRCCON.Para_IndLeft.CopyWithNewRow(row), this.IndentLeft);
     writer.SetFormula(SRCCON.Para_IndFirst.CopyWithNewRow(row), this.IndentFirst);
     writer.SetFormula(SRCCON.Para_IndRight.CopyWithNewRow(row), this.IndentRight);
     writer.SetFormula(SRCCON.Para_SpAfter.CopyWithNewRow(row), this.SpacingAfter);
     writer.SetFormula(SRCCON.Para_SpBefore.CopyWithNewRow(row), this.SpacingBefore);
     writer.SetFormula(SRCCON.Para_SpLine.CopyWithNewRow(row), this.SpacingLine);
     writer.SetFormula(SRCCON.Para_HorzAlign.CopyWithNewRow(row), this.HorizontalAlign);
     writer.SetFormula(SRCCON.Para_BulletFont.CopyWithNewRow(row), this.BulletFont);
     writer.SetFormula(SRCCON.Para_Bullet.CopyWithNewRow(row), this.Bullet);
     writer.SetFormula(SRCCON.Para_BulletFontSize.CopyWithNewRow(row), this.BulletFontSize);
     writer.SetFormula(SRCCON.Para_LocalizeBulletFont.CopyWithNewRow(row), this.LocBulletFont);
     writer.SetFormula(SRCCON.Para_TextPosAfterBullet.CopyWithNewRow(row), this.TextPosAfterBullet);
     writer.SetFormula(SRCCON.Para_Flags.CopyWithNewRow(row), this.Flags);
     writer.SetFormula(SRCCON.Para_BulletStr.CopyWithNewRow(row), this.BulletString);
 }
Exemplo n.º 19
0
        private void Update(short section_index, short row_index, FormulaWriterSRC writer)
        {
            var x_src = new VA.ShapeSheet.SRC(section_index, row_index, ShapeSheet.SRCConstants.Geometry_X.Cell);
            var y_src = new VA.ShapeSheet.SRC(section_index, row_index, ShapeSheet.SRCConstants.Geometry_Y.Cell);
            var a_src = new VA.ShapeSheet.SRC(section_index, row_index, ShapeSheet.SRCConstants.Geometry_A.Cell);
            var b_src = new VA.ShapeSheet.SRC(section_index, row_index, ShapeSheet.SRCConstants.Geometry_B.Cell);
            var c_src = new VA.ShapeSheet.SRC(section_index, row_index, ShapeSheet.SRCConstants.Geometry_C.Cell);
            var d_src = new VA.ShapeSheet.SRC(section_index, row_index, ShapeSheet.SRCConstants.Geometry_D.Cell);
            var e_src = new VA.ShapeSheet.SRC(section_index, row_index, ShapeSheet.SRCConstants.Geometry_E.Cell);

            writer.SetFormula(x_src, this.X);
            writer.SetFormula(y_src, this.Y);
            writer.SetFormula(a_src, this.A);
            writer.SetFormula(b_src, this.B);
            writer.SetFormula(c_src, this.C);
            writer.SetFormula(d_src, this.D);
            writer.SetFormula(e_src, this.E);
        }
Exemplo n.º 20
0
        public void Apply(IVisio.Page page)
        {
            var pagecells = new PageLayoutFormulas();

            this.SetPageCells(pagecells);

            var writer = new FormulaWriterSRC();

            writer.SetFormula(VisioAutomation.ShapeSheet.SRCConstants.AvenueSizeX, pagecells.AvenueSizeX);
            writer.SetFormula(VisioAutomation.ShapeSheet.SRCConstants.AvenueSizeY, pagecells.AvenueSizeY);
            writer.SetFormula(VisioAutomation.ShapeSheet.SRCConstants.LineRouteExt, pagecells.LineRouteExt);
            writer.SetFormula(VisioAutomation.ShapeSheet.SRCConstants.RouteStyle, pagecells.RouteStyle);
            writer.SetFormula(VisioAutomation.ShapeSheet.SRCConstants.PlaceStyle, pagecells.PlaceStyle);

            var pagesheet = page.PageSheet;

            writer.Commit(pagesheet);
            page.Layout();
        }
Exemplo n.º 21
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 writer = new FormulaWriterSRC(3);

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

            using (var undoscope = this._client.Application.NewUndoScope("Set Page Orientation"))
            {
                writer.Commit(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 = string.Format("Could not retrieve cell for custom property \"{0}\"", full_prop_name);
                    throw new InternalAssertionException(msg);
                }

                var writer = new FormulaWriterSRC();
                cp.SetFormulas(writer, cell_propname.Row);
                writer.Commit(shape);

                return;

            }

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

            CustomPropertyHelper.Set(shape, row, cp);
        }
Exemplo n.º 23
0
        public void Page_Query()
        {
            var page1     = this.GetNewPage(new VA.Drawing.Size(4, 3));
            var pagecells = VA.Pages.PageCells.GetCells(page1.PageSheet);

            Assert.AreEqual("4.0000 in.", pagecells.PageWidth.Result);
            Assert.AreEqual("3.0000 in.", pagecells.PageHeight.Result);

            // Double each side
            pagecells.PageWidth  = "8.0";
            pagecells.PageHeight = "6.0";

            var writer = new FormulaWriterSRC();

            pagecells.SetFormulas(writer);
            writer.Commit(page1.PageSheet);

            var pagecells2 = VA.Pages.PageCells.GetCells(page1.PageSheet);

            Assert.AreEqual("8.0000 in.", pagecells2.PageWidth.Result);
            Assert.AreEqual("6.0000 in.", pagecells2.PageHeight.Result);
            page1.Delete(0);
        }
Exemplo n.º 24
0
        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 writer = new FormulaWriterSRC();

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

            using (var undoscope = this._client.Application.NewUndoScope("Reset Page Origin"))
            {
                writer.Commit(page.PageSheet);
            }
        }
Exemplo n.º 25
0
        public static void Duplicate(
            IVisio.Page src_page,
            IVisio.Page dest_page)
        {
            init_page_srcs();

            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 System.ArgumentException("Destination Page cannot be Source Page");
            }


            if (src_page != app.ActivePage)
            {
                throw new System.ArgumentException("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();
            }

            // Get the Cells from the Source
            var query = new VisioAutomation.ShapeSheet.Queries.Query();
            int i     = 0;

            foreach (var src in page_srcs)
            {
                query.AddCell(src, "Col" + i.ToString());
                i++;
            }
            var src_surface  = new VisioAutomation.ShapeSheet.ShapeSheetSurface(src_page.PageSheet);
            var src_formulas = query.GetFormulas(src_surface);

            // Set the Cells on the Destination

            var writer = new FormulaWriterSRC();

            for (i = 0; i < page_srcs.Count; i++)
            {
                writer.SetFormula(page_srcs[i], src_formulas.Cells[i]);
            }
            writer.Commit(dest_page.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);
            }
        }
Exemplo n.º 26
0
        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 writer = new FormulaWriterSRC();

            foreach (var region in regions_to_format)
            {
                // Apply character formatting
                var charcells = region.Element.CharacterFormatting;
                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");
                    }

                    writer.Clear();
                    charcells.ApplyFormulas(writer, rownum);
                    writer.Commit(shape);
                }

                // Apply paragraph formatting
                var paracells = region.Element.ParagraphFormatting;
                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");
                    }

                    writer.Clear();
                    paracells.ApplyFormulas(writer, rownum);
                    writer.Commit(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;
            }
        }
Exemplo n.º 27
0
        public void AddTo(IVisio.Shape shape, FormulaWriterSRC writer, short row, short section)
        {
            short row_index = shape.AddRow(section, row, (short)this.GetRowTagType());

            this.Update(section, row_index, writer);
        }