public static ShapeRange Execute(PowerPointPresentation presentation, PowerPointSlide slide, Selection selection)
        {
            ShapeRange selectedShapes     = selection.ShapeRange;
            Shape      firstSelectedShape = selectedShapes[1];

            // Temporarily save the animation
            Shape tempShapeForAnimation = slide.Shapes.AddShape(Microsoft.Office.Core.MsoAutoShapeType.msoShapeRectangle, 0, 0, 1, 1);

            slide.TransferAnimation(firstSelectedShape, tempShapeForAnimation);

            // Ungroup first selection and add into list
            string       groupName             = firstSelectedShape.Name;
            bool         isFirstSelectionGroup = false;
            List <Shape> newShapesList         = new List <Shape>();

            if (firstSelectedShape.IsCorrupted())
            {
                firstSelectedShape = ShapeUtil.CorruptionCorrection(firstSelectedShape, slide);
            }
            if (firstSelectedShape.IsAGroup())
            {
                isFirstSelectionGroup = true;
                ShapeRange ungroupedShapes = firstSelectedShape.Ungroup();
                foreach (Shape shape in ungroupedShapes)
                {
                    newShapesList.Add(shape);
                }
            }
            else
            {
                newShapesList.Add(firstSelectedShape);
            }

            // Add all other selections into list
            for (int i = 2; i <= selectedShapes.Count; i++)
            {
                Shape shape = selectedShapes[i];
                if (shape.IsCorrupted())
                {
                    shape = ShapeUtil.CorruptionCorrection(shape, slide);
                }
                newShapesList.Add(shape);
            }

            // Create the new group from the list
            selectedShapes = slide.ToShapeRange(newShapesList);
            Shape selectedGroup = selectedShapes.Group();

            selectedGroup.Name = isFirstSelectionGroup ? groupName : selectedGroup.Name;

            // Transfer the animation
            slide.TransferAnimation(tempShapeForAnimation, selectedGroup);
            tempShapeForAnimation.SafeDelete();

            return(slide.ToShapeRange(selectedGroup));
        }
Beispiel #2
0
#pragma warning disable 0618

        public static void Convert(PowerPointPresentation pres, PowerPointSlide slide, PowerPoint.Selection selection)
        {
            if (ShapeUtil.IsSelectionShapeOrText(selection))
            {
                PowerPoint.Shape shape = GetShapeFromSelection(selection);
                int originalZOrder     = shape.ZOrderPosition;
                // In case shape is corrupted
                if (ShapeUtil.IsCorrupted(shape))
                {
                    shape = ShapeUtil.CorruptionCorrection(shape, slide);
                }
                ConvertToPictureForShape(pres, slide, shape, originalZOrder);
            }
            else
            {
                MessageBox.Show(ShortcutsLabText.ErrorTypeNotSupported, ShortcutsLabText.ErrorWindowTitle);
            }
        }
        internal static ShapeRange UngroupAllShapeRange(PowerPointSlide curSlide, ShapeRange shapeRange)
        {
            List <Shape> originalShapeList  = new List <Shape>();
            List <Shape> ungroupedShapeList = new List <Shape>();

            for (int i = 1; i <= shapeRange.Count; i++)
            {
                Shape shape = shapeRange[i];
                if (ShapeUtil.IsCorrupted(shape))
                {
                    shape = ShapeUtil.CorruptionCorrection(shape, curSlide);
                }
                originalShapeList.Add(shape);
            }

            for (int i = 0; i < originalShapeList.Count; i++)
            {
                if (originalShapeList[i].Type == Office.MsoShapeType.msoGroup)
                {
                    ShapeRange subRange = originalShapeList[i].Ungroup();
                    foreach (Shape item in subRange)
                    {
                        originalShapeList.Add(item);
                    }
                }
                else if (originalShapeList[i].Type == Office.MsoShapeType.msoPlaceholder ||
                         originalShapeList[i].Type == Office.MsoShapeType.msoTextBox ||
                         originalShapeList[i].Type == Office.MsoShapeType.msoAutoShape ||
                         originalShapeList[i].Type == Office.MsoShapeType.msoFreeform)
                {
                    ungroupedShapeList.Add(originalShapeList[i]);
                }
                else
                {
                    throw new Exception(EffectsLabText.ErrorBlurSelectedNonShapeOrTextBox);
                }
            }

            ShapeRange ungroupedShapeRange = curSlide.ToShapeRange(ungroupedShapeList);

            return(ungroupedShapeRange);
        }
        // Sealed method: Subclasses should override ExecutePasteAction instead
        protected sealed override void ExecuteAction(string ribbonId)
        {
            this.StartNewUndoEntry();

            PowerPointPresentation presentation = this.GetCurrentPresentation();
            PowerPointSlide        slide        = this.GetCurrentSlide();
            Selection selection = this.GetCurrentSelection();

            if (ClipboardUtil.IsClipboardEmpty())
            {
                Logger.Log(ribbonId + " failed. Clipboard is empty.");
                MessageBox.Show(PasteLabText.ErrorEmptyClipboard, PasteLabText.ErrorDialogTitle);
                return;
            }

            ShapeRange passedSelectedShapes      = null;
            ShapeRange passedSelectedChildShapes = null;

            if (ShapeUtil.IsSelectionShape(selection) && !IsSelectionIgnored(ribbonId))
            {
                // When pasting some objects, the selection may change to the pasted object (e.g. jpg from desktop).
                // Therefore we must capture the selection first.
                ShapeRange selectedShapes = selection.ShapeRange;

                // Preserve selection by tagging them
                for (int i = 1; i <= selectedShapes.Count; i++)
                {
                    selectedShapes[i].Tags.Add(SelectOrderTagName, i.ToString());
                }

                ShapeRange selectedChildShapes = null;
                if (selection.HasChildShapeRange)
                {
                    selectedChildShapes = selection.ChildShapeRange;
                    for (int i = 1; i <= selectedChildShapes.Count; i++)
                    {
                        selectedChildShapes[i].Tags.Add(SelectChildOrderTagName, i.ToString());
                    }
                }

                // Corruption correction
                ShapeRange correctedShapes = ShapeUtil.CorruptionCorrection(selectedShapes, slide);

                // Reselect the preserved selections
                List <Shape> correctedShapeList      = new List <Shape>();
                List <Shape> correctedChildShapeList = new List <Shape>();
                foreach (Shape shape in correctedShapes)
                {
                    correctedShapeList.Add(shape);
                    correctedChildShapeList.AddRange(ShapeUtil.GetChildrenWithNonEmptyTag(shape, SelectChildOrderTagName));
                }
                correctedShapeList.Sort((sh1, sh2) => int.Parse(sh1.Tags[SelectOrderTagName]) - int.Parse(sh2.Tags[SelectOrderTagName]));
                correctedChildShapeList.Sort((sh1, sh2) => int.Parse(sh1.Tags[SelectChildOrderTagName]) - int.Parse(sh2.Tags[SelectChildOrderTagName]));
                passedSelectedShapes      = slide.ToShapeRange(correctedShapeList);
                passedSelectedChildShapes = slide.ToShapeRange(correctedChildShapeList);

                // Remove shape tags after they have been used
                ShapeUtil.DeleteTagFromShapes(passedSelectedShapes, SelectOrderTagName);
                ShapeUtil.DeleteTagFromShapes(passedSelectedChildShapes, SelectChildOrderTagName);
            }

            ShapeRange result = ExecutePasteAction(ribbonId, presentation, slide, passedSelectedShapes, passedSelectedChildShapes);

            if (result != null)
            {
                result.Select();
            }
        }
Beispiel #5
0
        // Sealed method: Subclasses should override ExecutePasteAction instead
        protected sealed override void ExecuteAction(string ribbonId)
        {
            this.StartNewUndoEntry();

            PowerPointPresentation presentation = this.GetCurrentPresentation();
            PowerPointSlide        slide        = this.GetCurrentSlide();
            Selection selection = this.GetCurrentSelection();

            if (GraphicsUtil.IsClipboardEmpty())
            {
                Logger.Log(ribbonId + " failed. Clipboard is empty.");
                return;
            }

            ShapeRange passedSelectedShapes      = null;
            ShapeRange passedSelectedChildShapes = null;

            if (ShapeUtil.IsSelectionShape(selection) && !IsSelectionIgnored(ribbonId))
            {
                // Save clipboard onto a temp slide, because CorruptionCorrrection uses Copy-Paste
                PowerPointSlide tempClipboardSlide  = presentation.AddSlide(index: slide.Index);
                ShapeRange      tempClipboardShapes = PasteShapesFromClipboard(tempClipboardSlide);

                // Nothing is pasted, stop now
                if (tempClipboardShapes == null)
                {
                    tempClipboardSlide.Delete();
                    return;
                }

                // Preserve selection using tags
                ShapeRange selectedShapes = selection.ShapeRange;
                for (int i = 1; i <= selectedShapes.Count; i++)
                {
                    selectedShapes[i].Tags.Add(SelectOrderTagName, i.ToString());
                }

                ShapeRange selectedChildShapes = null;
                if (selection.HasChildShapeRange)
                {
                    selectedChildShapes = selection.ChildShapeRange;
                    for (int i = 1; i <= selectedChildShapes.Count; i++)
                    {
                        selectedChildShapes[i].Tags.Add(SelectChildOrderTagName, i.ToString());
                    }
                }

                // Corruption correction
                ShapeRange correctedShapes = ShapeUtil.CorruptionCorrection(selectedShapes, slide);

                // Reselect the preserved selections
                List <Shape> correctedShapeList      = new List <Shape>();
                List <Shape> correctedChildShapeList = new List <Shape>();
                foreach (Shape shape in correctedShapes)
                {
                    correctedShapeList.Add(shape);
                    correctedChildShapeList.AddRange(ShapeUtil.GetChildrenWithNonEmptyTag(shape, SelectChildOrderTagName));
                }
                correctedShapeList.Sort((sh1, sh2) => int.Parse(sh1.Tags[SelectOrderTagName]) - int.Parse(sh2.Tags[SelectOrderTagName]));
                correctedChildShapeList.Sort((sh1, sh2) => int.Parse(sh1.Tags[SelectChildOrderTagName]) - int.Parse(sh2.Tags[SelectChildOrderTagName]));
                passedSelectedShapes      = slide.ToShapeRange(correctedShapeList);
                passedSelectedChildShapes = slide.ToShapeRange(correctedChildShapeList);

                // Remove the tags after they have been used
                ShapeUtil.DeleteTagFromShapes(passedSelectedShapes, SelectOrderTagName);
                ShapeUtil.DeleteTagFromShapes(passedSelectedChildShapes, SelectChildOrderTagName);

                // Revert clipboard
                tempClipboardShapes.Copy();
                tempClipboardSlide.Delete();
            }

            ShapeRange result = ExecutePasteAction(ribbonId, presentation, slide, passedSelectedShapes, passedSelectedChildShapes);

            if (result != null)
            {
                result.Select();
            }
        }