Example #1
0
        protected override ShapeRange ExecutePasteAction(string ribbonId, PowerPointPresentation presentation, PowerPointSlide slide,
                                                         ShapeRange selectedShapes, ShapeRange selectedChildShapes)
        {
            if (selectedShapes.Count <= 0)
            {
                Logger.Log("PasteIntoGroup failed. No valid shape is selected.");
                return(null);
            }

            if (selectedShapes.Count == 1 && !ShapeUtil.IsAGroup(selectedShapes[1]))
            {
                Logger.Log("PasteIntoGroup failed. Selection is only a single shape.");
                return(null);
            }

            ShapeRange pastingShapes = ClipboardUtil.PasteShapesFromClipboard(presentation, slide);

            if (pastingShapes == null)
            {
                Logger.Log("PasteLab: Could not paste clipboard contents.");
                MessageBox.Show(PasteLabText.ErrorPaste, PasteLabText.ErrorDialogTitle);
                return(null);
            }

            return(PasteIntoGroup.Execute(presentation, slide, selectedShapes, pastingShapes));
        }
        public static void Execute(PowerPointPresentation pres, PowerPointSlide slide, ShapeRange pastingShapes, float slideWidth, float slideHeight)
        {
            pastingShapes = ShapeUtil.GetShapesWhenTypeNotMatches(slide, pastingShapes, Microsoft.Office.Core.MsoShapeType.msoPlaceholder);
            if (pastingShapes.Count == 0)
            {
                return;
            }

            Shape pastingShape = pastingShapes[1];

            if (pastingShapes.Count > 1)
            {
                pastingShape = pastingShapes.Group();
            }

            // Temporary house the latest clipboard shapes
            ShapeRange origClipboardShapes = ClipboardUtil.PasteShapesFromClipboard(pres, slide);
            // Compression of large image(s)
            Shape shapeToFitSlide = GraphicsUtil.CompressImageInShape(pastingShape, slide);

            // Bring the same original shapes back into clipboard, preserving original size
            origClipboardShapes.Cut();

            shapeToFitSlide.LockAspectRatio = Microsoft.Office.Core.MsoTriState.msoTrue;

            PPShape ppShapeToFitSlide = new PPShape(shapeToFitSlide);

            ResizeShape(ppShapeToFitSlide, slideWidth, slideHeight);
            ppShapeToFitSlide.VisualCenter = new System.Drawing.PointF(slideWidth / 2, slideHeight / 2);
        }
        protected override ShapeRange ExecutePasteAction(string ribbonId, PowerPointPresentation presentation, PowerPointSlide slide,
                                                         ShapeRange selectedShapes, ShapeRange selectedChildShapes)
        {
            PPMouse.Coordinates coordinates  = PPMouse.RightClickCoordinates;
            DocumentWindow      activeWindow = this.GetCurrentWindow();

            float positionX = 0;
            float positionY = 0;

            if (activeWindow.ActivePane.ViewType == PpViewType.ppViewSlide)
            {
                int xref = activeWindow.PointsToScreenPixelsX(100) - activeWindow.PointsToScreenPixelsX(0);
                int yref = activeWindow.PointsToScreenPixelsY(100) - activeWindow.PointsToScreenPixelsY(0);
                positionX = ((coordinates.X - activeWindow.PointsToScreenPixelsX(0)) / xref) * 100;
                positionY = ((coordinates.Y - activeWindow.PointsToScreenPixelsY(0)) / yref) * 100;
            }

            ShapeRange pastingShapes = ClipboardUtil.PasteShapesFromClipboard(presentation, slide);

            if (pastingShapes == null)
            {
                Logger.Log("PasteLab: Could not paste clipboard contents.");
                MessageBox.Show(PasteLabText.ErrorPaste, PasteLabText.ErrorDialogTitle);
                return(null);
            }

            return(PasteAtCursorPosition.Execute(presentation, slide, pastingShapes, positionX, positionY));
        }
Example #4
0
        protected override ShapeRange ExecutePasteAction(string ribbonId, PowerPointPresentation presentation, PowerPointSlide slide,
                                                         ShapeRange selectedShapes, ShapeRange selectedChildShapes)
        {
            ShapeRange pastingShapes = ClipboardUtil.PasteShapesFromClipboard(slide);

            if (pastingShapes == null)
            {
                return(null);
            }

            PasteToFillSlide.Execute(slide, pastingShapes, presentation.SlideWidth, presentation.SlideHeight);
            return(null);
        }
Example #5
0
        protected override ShapeRange ExecutePasteAction(string ribbonId, PowerPointPresentation presentation, PowerPointSlide slide,
                                                         ShapeRange selectedShapes, ShapeRange selectedChildShapes)
        {
            ShapeRange pastingShapes = ClipboardUtil.PasteShapesFromClipboard(presentation, slide);

            if (pastingShapes == null)
            {
                Logger.Log("PasteLab: Could not paste clipboard contents.");
                MessageBox.Show(PasteLabText.ErrorPaste, PasteLabText.ErrorDialogTitle);
                return(null);
            }

            PasteToFillSlide.Execute(presentation, slide, pastingShapes, presentation.SlideWidth, presentation.SlideHeight);
            return(null);
        }
Example #6
0
        protected override ShapeRange ExecutePasteAction(string ribbonId, PowerPointPresentation presentation, PowerPointSlide slide,
                                                         ShapeRange selectedShapes, ShapeRange selectedChildShapes)
        {
            PowerPointSlide tempSlide         = presentation.AddSlide(index: slide.Index);
            ShapeRange      tempPastingShapes = ClipboardUtil.PasteShapesFromClipboard(tempSlide);

            if (tempPastingShapes == null)
            {
                tempSlide.Delete();
                return(ClipboardUtil.PasteShapesFromClipboard(slide));
            }

            ShapeRange pastingShapes = slide.CopyShapesToSlide(tempPastingShapes);

            tempSlide.Delete();

            return(pastingShapes);
        }
        protected override ShapeRange ExecutePasteAction(string ribbonId, PowerPointPresentation presentation, PowerPointSlide slide,
                                                         ShapeRange selectedShapes, ShapeRange selectedChildShapes)
        {
            if (selectedShapes.Count <= 0)
            {
                MessageBox.Show(TextCollection.PasteLabText.ReplaceWithClipboardActionHandlerReminderText, TextCollection.CommonText.ErrorTitle);
                return(null);
            }

            ShapeRange pastingShapes = ClipboardUtil.PasteShapesFromClipboard(slide);

            if (pastingShapes == null)
            {
                return(null);
            }

            return(ReplaceWithClipboard.Execute(presentation, slide, selectedShapes, selectedChildShapes, pastingShapes));
        }
Example #8
0
        protected override ShapeRange ExecutePasteAction(string ribbonId, PowerPointPresentation presentation, PowerPointSlide slide,
                                                         ShapeRange selectedShapes, ShapeRange selectedChildShapes)
        {
            if (selectedShapes.Count <= 0)
            {
                MessageBox.Show("Please select at least one shape.", "Error");
                return(null);
            }

            ShapeRange pastingShapes = ClipboardUtil.PasteShapesFromClipboard(slide);

            if (pastingShapes == null)
            {
                return(null);
            }

            return(ReplaceWithClipboard.Execute(presentation, slide, selectedShapes, selectedChildShapes, pastingShapes));
        }
Example #9
0
        protected override ShapeRange ExecutePasteAction(string ribbonId, PowerPointPresentation presentation, PowerPointSlide slide,
                                                         ShapeRange selectedShapes, ShapeRange selectedChildShapes)
        {
            if (selectedShapes.Count <= 0)
            {
                MessageBox.Show(TextCollection.PasteLabText.ReplaceWithClipboardActionHandlerReminderText, TextCollection.CommonText.ErrorTitle);
                return(null);
            }

            this.StartNewUndoEntry();

            ShapeRange pastingShapes = ClipboardUtil.PasteShapesFromClipboard(presentation, slide);

            if (pastingShapes == null)
            {
                Logger.Log("PasteLab: Could not paste clipboard contents.");
                MessageBox.Show(PasteLabText.ErrorPaste, PasteLabText.ErrorDialogTitle);
                return(null);
            }

            return(ReplaceWithClipboard.Execute(presentation, slide, selectedShapes, selectedChildShapes, pastingShapes));
        }
        protected override ShapeRange ExecutePasteAction(string ribbonId, PowerPointPresentation presentation, PowerPointSlide slide,
                                                         ShapeRange selectedShapes, ShapeRange selectedChildShapes)
        {
            PowerPointSlide tempSlide         = presentation.AddSlide(index: slide.Index);
            ShapeRange      tempPastingShapes = ClipboardUtil.PasteShapesFromClipboard(presentation, tempSlide);

            if (tempPastingShapes == null)
            {
                tempSlide.Delete();
                ShapeRange shapes = ClipboardUtil.PasteShapesFromClipboard(presentation, slide);
                if (shapes == null)
                {
                    Logger.Log("PasteLab: Could not paste clipboard contents.");
                    MessageBox.Show(PasteLabText.ErrorPaste, PasteLabText.ErrorDialogTitle);
                }
                return(shapes);
            }

            ShapeRange pastingShapes = slide.CopyShapesToSlide(tempPastingShapes);

            tempSlide.Delete();

            return(pastingShapes);
        }
        // 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.");
                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;

                // Save clipboard onto a temp slide, because CorruptionCorrrection uses Copy-Paste
                PowerPointSlide tempClipboardSlide  = presentation.AddSlide(index: slide.Index);
                ShapeRange      tempClipboardShapes = ClipboardUtil.PasteShapesFromClipboard(tempClipboardSlide);

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

                // 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);

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

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

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