protected override void ExecuteAction(string ribbonId)
        {
            this.StartNewUndoEntry();
            PowerPointPresentation pres  = this.GetCurrentPresentation();
            PowerPointSlide        slide = this.GetCurrentSlide();
            Selection selection          = this.GetCurrentSelection();

            CustomTaskPane shapesLabPane = this.GetTaskPane(typeof(CustomShapePane));

            if (shapesLabPane == null)
            {
                this.RegisterTaskPane(typeof(CustomShapePane), ShapesLabText.TaskPanelTitle);
                shapesLabPane = this.GetTaskPane(typeof(CustomShapePane));
            }
            if (shapesLabPane == null)
            {
                return;
            }
            shapesLabPane.Visible = true;

            CustomShapePane customShapePane = shapesLabPane.Control as CustomShapePane;

            customShapePane.InitCustomShapePaneStorage();
            customShapePane.AddShapeFromSelection(selection);
        }
        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 = PasteShapesFromClipboard(slide);

            if (pastingShapes == null)
            {
                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)
        {
            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));
        }
Example #5
0
        public static ShapeRange Execute(PowerPointPresentation presentation, PowerPointSlide slide,
                                         ShapeRange pastingShapes, float positionX, float positionY)
        {
            if (pastingShapes.Count > 1)
            {
                // Get Left and Top of pasting shapes as a group
                float pastingGroupLeft = int.MaxValue;
                float pastingGroupTop  = int.MaxValue;
                foreach (Shape shape in pastingShapes)
                {
                    pastingGroupLeft = Math.Min(shape.Left, pastingGroupLeft);
                    pastingGroupTop  = Math.Min(shape.Top, pastingGroupTop);
                }

                foreach (Shape shape in pastingShapes)
                {
                    if (shape.IsAChild())
                    {
                        continue;
                    }
                    shape.IncrementLeft(positionX - pastingGroupLeft);
                    shape.IncrementTop(positionY - pastingGroupTop);
                }
            }
            else
            {
                pastingShapes[1].Left = positionX;
                pastingShapes[1].Top  = positionY;
            }

            return(pastingShapes);
        }
Example #6
0
        /// <summary>
        /// To avoid corrupted shape.
        /// Corrupted shape is produced when delete or cut a shape programmatically, but then users undo it.
        /// After that, most of operations on corrupted shapes will throw an exception.
        /// One solution for this is to re-allocate its memory: simply cut/copy and paste before using its property.
        /// </summary>
        /// <param name="shape"> Shape to be corrected </param>
        /// <returns> The corrected shape </returns>
        public static Shape CorruptionCorrection(Shape shape, PowerPointSlide ownerSlide)
        {
            Shape correctedShape = null;

            // Utilises deprecated PowerPointPresentation class as ShapeUtil does not utilise ActionFramework
            PowerPointPresentation pres = PowerPointPresentation.Current;

            // While doing corruption correction, we don't want to affect the clipboard
            ClipboardUtil.RestoreClipboardAfterAction(() =>
            {
                correctedShape = ownerSlide.CopyShapeToSlide(shape);
                // Success
                return(correctedShape);
            }, pres, ownerSlide);

            if (correctedShape != null)
            {
                shape.Delete();
                return(correctedShape);
            }
            else
            {
                // There were problems with the copying of the shape to the slide (could be a placeholder) thus we just return the original shape
                return(shape);
            }
        }
        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));
        }
        /// <summary>
        /// Pastes clipboard content into new temp slide using the DocumentWindow's View.Paste()
        /// Though this paste will work for most clipboard objects (even web pictures), it will change the undo history.
        /// </summary>
        private static Shape TryPastingOntoView(PowerPointPresentation pres, PowerPointSlide tempSlide, PowerPointSlide origSlide)
        {
            try
            {
                // Utilises deprecated Globals class as ClipboardUtil does not utilise ActionFramework
                DocumentWindow workingWindow = Globals.ThisAddIn.Application.ActiveWindow;
                pres.GotoSlide(tempSlide.Index);
                int origShapesCount = tempSlide.Shapes.Count;

                // Note: This will change the undo history
                workingWindow.View.Paste();
                pres.GotoSlide(origSlide.Index);
                int finalShapesCount = tempSlide.Shapes.Count;
                if (finalShapesCount > origShapesCount)
                {
                    return(tempSlide.Shapes.Range()[finalShapesCount]);
                }
                else
                {
                    return(null);
                }
            }
            catch (COMException e)
            {
                // May be thrown if cannot be pasted
                Logger.LogException(e, "TryPastingOntoView");
                return(null);
            }
        }
Example #9
0
        /// <summary>
        /// Insert shape which is copied from `templatedShape` to slide
        /// Precondition: shapeName must not exist in slide before applying the method
        /// </summary>
        /// <param name="slide"></param>
        /// <param name="templatedShape">Shape whose format is to be copied over</param>
        /// <param name="shapeName"></param>
        /// <param name="text"></param>
        /// <returns>the copied shape</returns>
        public static Shape InsertTemplatedShapeToSlide(PowerPointSlide slide, Shape templatedShape, string shapeName, string text)
        {
            float slideWidth            = PowerPointPresentation.Current.SlideWidth;
            float slideHeight           = PowerPointPresentation.Current.SlideHeight;
            PowerPointPresentation pres = ActionFrameworkExtensions.GetCurrentPresentation();
            Shape copiedShape;

            // templatedShape and its associated animations are duplicated
            if (templatedShape == null)
            {
                throw new Exception("Templated shape is null");
            }
            try
            {
                copiedShape = ClipboardUtil.RestoreClipboardAfterAction(() =>
                {
                    return(slide.Shapes.SafeCopyPlaceholder(templatedShape));
                }, pres, slide);
            }
            catch
            {
                throw new Exception("Error copy and paste shape.");
            }
            if (copiedShape == null)
            {
                throw new Exception("Copied shape is null");
            }
            copiedShape.Name = shapeName;

            copiedShape.TextFrame.TextRange.Text = text;
            copiedShape.TextFrame.WordWrap       = MsoTriState.msoTrue;

            copiedShape.TextFrame.AutoSize = PpAutoSize.ppAutoSizeShapeToFitText;

            // copy shape to the default callout / caption position
            if (StringUtility.ExtractFunctionFromString(copiedShape.Name) == ELearningLabText.CalloutIdentifier)
            {
                copiedShape.Left = 10;
                copiedShape.Top  = 10;
                copiedShape.TextEffect.Alignment = MsoTextEffectAlignment.msoTextEffectAlignmentLeft;
            }
            else if (StringUtility.ExtractFunctionFromString(copiedShape.Name) == ELearningLabText.CaptionIdentifier)
            {
                copiedShape.Left   = 0;
                copiedShape.Top    = slideHeight - 100;
                copiedShape.Width  = slideWidth;
                copiedShape.Height = 100;
                copiedShape.Top    = slideHeight - copiedShape.Height;
                copiedShape.TextEffect.Alignment = MsoTextEffectAlignment.msoTextEffectAlignmentCentered;
            }

            // remove associated animation with copiedShape because we only want the shape to be copied.
            slide.RemoveAnimationsForShape(copiedShape);
            if (StringUtility.ExtractFunctionFromString(copiedShape.Name) == ELearningLabText.CaptionIdentifier)
            {
                copiedShape.Top = slideHeight - copiedShape.Height;
            }
            return(copiedShape);
        }
        protected override void ExecuteAction(string ribbonId)
        {
            this.StartNewUndoEntry();
            PowerPointPresentation pres  = this.GetCurrentPresentation();
            PowerPointSlide        slide = this.GetCurrentSlide();

            AutoZoom.AddDrillDownAnimation(pres, slide);
        }
Example #11
0
        /// <summary>
        /// Saves shape in storage
        /// Returns a key to find the shape by,
        /// or null if the shape cannot be copied
        /// </summary>
        /// <param name="shape"></param>
        /// <param name="formats">Required for msoPlaceholder</param>
        /// <returns>identifier of copied shape</returns>
        public string CopyShape(Shape shape, Format[] formats)
        {
            #pragma warning disable 618
            PowerPointPresentation pres  = PowerPointPresentation.Current;
            PowerPointSlide        slide = PowerPointCurrentPresentationInfo.CurrentSlide;
            Shape copiedShape            = null;
            if (shape.Type == MsoShapeType.msoPlaceholder)
            {
                ClipboardUtil.RestoreClipboardAfterAction(() =>
                {
                    copiedShape = ShapeUtil.CopyMsoPlaceHolder(formats, shape, GetTemplateShapes());
                    return(ClipboardUtil.ClipboardRestoreSuccess);
                }, pres, slide);
            }
            else
            {
                try
                {
                    ClipboardUtil.RestoreClipboardAfterAction(() =>
                    {
                        copiedShape = Slides[0].Shapes.SafeCopyPlaceholder(shape);
                        return(ClipboardUtil.ClipboardRestoreSuccess);
                    }, pres, slide);
                }
                catch
                {
                    copiedShape = null;
                }
            }
            #pragma warning restore 618

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

            string shapeKey = nextKey.ToString();
            nextKey++;
            copiedShape.Name = shapeKey;

            #pragma warning disable 618
            if (Globals.ThisAddIn.IsApplicationVersion2013())
            {
                // sync glow, 2013 gives the wrong Glow.Fill color after copying the shape
                SyncFormats(shape, copiedShape, _glowFormats);
                // sync shape fill, 2013 gives the wrong fill color after copying the shape
                SyncFormats(shape, copiedShape, _fillFormats);

                // backup artistic effects for 2013
                // ForceSave() will make artistic effect permanent on the shapes for 2013 and no longer retrievable
                List <MsoPictureEffectType> extractedEffects = ArtisticEffectFormat.GetArtisticEffects(copiedShape);
                _backupArtisticEffects.Add(shapeKey, extractedEffects);
            }
            #pragma warning restore 618

            ForceSave();
            return(shapeKey);
        }
        private static void SaveClipboard(PowerPointPresentation pres, PowerPointSlide origSlide, out PowerPointSlide tempClipboardSlide, out ShapeRange tempClipboardShapes, out SlideRange tempPastedSlide)
        {
            Logger.Log("RestoreClipboardAfterAction: Trying to paste as slide.", ActionFramework.Common.Logger.LogType.Info);
            ClipboardUtilData data = PPLClipboard.Instance.LockAndRelease(() => SaveClipboardUnsafe(pres, origSlide));

            tempClipboardSlide  = data.tempClipboardSlide;
            tempClipboardShapes = data.tempClipboardShapes;
            tempPastedSlide     = data.tempPastedSlide;
        }
        protected override void ExecuteAction(string ribbonId)
        {
            this.StartNewUndoEntry();
            PowerPointPresentation pres  = this.GetCurrentPresentation();
            PowerPointSlide        slide = this.GetCurrentSlide();
            Selection selection          = GetSelection();

            ConvertToPicture.Convert(pres, slide, selection);
        }
        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));
        }
Example #15
0
        private void CreateTooltipOnSlide(int slideNo)
        {
            PowerPointSlide        currentSlide = PowerPointSlide.FromSlideFactory(PpOperations.GetCurrentSlide());
            PowerPointPresentation presentation = new PowerPointPresentation(Pres);
            Shape triggerShape = PowerPointLabs.TooltipsLab.CreateTooltip.GenerateTriggerShape(
                presentation, currentSlide);
            Shape callout = PowerPointLabs.TooltipsLab.CreateTooltip.GenerateCalloutWithReferenceTriggerShape(currentSlide, triggerShape);

            ConvertToTooltip.AddTriggerAnimation(currentSlide, triggerShape, callout);
        }
Example #16
0
        protected override IEnumerable <DestinationFile> ConvertApplicableImageThenSave(
            SourceFile source,
            ImageFileKind destinationKind,
            ArgumentOptionCollection optionCollection,
            ILogger logger)
        {
            var savedImageFiles = new List <DestinationFile>();

            try
            {
                using (var powerPointApplication = new PowerPointApplication(new Application()))
                {
                    var application  = powerPointApplication.Application;
                    var presentation = application.Presentations;
                    using (var presenationFile = new PowerPointPresentation(presentation.Open(
                                                                                FileName: source.Path,
                                                                                ReadOnly: MsoTriState.msoTrue,
                                                                                Untitled: MsoTriState.msoTrue,
                                                                                WithWindow: MsoTriState.msoTrue)))
                    {
                        var file = presenationFile.Presentation;
                        foreach (var slide in EnumeratePowerPointSlides(file))
                        {
                            if (!optionCollection.PowerpointPageRange.Contains((uint)slide.SlideNumber))
                            {
                                continue;
                            }
                            slide.Select();
                            slide.Shapes.SelectAll();
                            var selection = application.ActiveWindow.Selection;
                            var shapes    = selection.ShapeRange;

                            var destinationPathForSlide = $"{Path.GetDirectoryName(source.Path)}\\{Path.GetFileNameWithoutExtension(source.Path)}{slide.SlideNumber}{destinationKind.GetExtensionWithDot()}";
                            var destinationForSlide     = new DestinationFile(destinationPathForSlide);
                            if (!DeleteExistingFileIfNecessary(destinationForSlide, optionCollection, logger))
                            {
                                continue;
                            }

                            //create emf
                            shapes.Export(destinationForSlide.Path, PpShapeFormat.ppShapeFormatEMF);
                            savedImageFiles.Add(destinationForSlide);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                logger.WriteLog($"Failed to convert powerpoint slide to emf images: {e.Message}\n{e.StackTrace}", LogLevel.Error);
            }

            return(savedImageFiles);
        }
        protected override void ExecuteAction(string ribbonId)
        {
            this.StartNewUndoEntry();
            PowerPointPresentation pres  = this.GetCurrentPresentation();
            PowerPointSlide        slide = this.GetCurrentSlide();

            ClipboardUtil.RestoreClipboardAfterAction(() =>
            {
                ZoomToArea.AddZoomToArea();
                return(ClipboardUtil.ClipboardRestoreSuccess);
            }, pres, slide);
        }
        protected override ShapeRange ExecutePasteAction(string ribbonId, PowerPointPresentation presentation, PowerPointSlide slide,
                                                         ShapeRange selectedShapes, ShapeRange selectedChildShapes)
        {
            ShapeRange pastingShapes = PasteShapesFromClipboard(slide);

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

            PasteToFillSlide.Execute(slide, pastingShapes, presentation.SlideWidth, presentation.SlideHeight);
            return(null);
        }
Example #19
0
#pragma warning disable 0618
        public static void AddDrillDownAnimation(PowerPointPresentation pres, PowerPointSlide slide)
        {
            if (!IsSelectingShapes())
            {
                return;
            }

            ClipboardUtil.RestoreClipboardAfterAction(() =>
            {
                AddDrillDownAnimation(Globals.ThisAddIn.Application.ActiveWindow.Selection.ShapeRange[1],
                                      PowerPointCurrentPresentationInfo.CurrentSlide);
                return(ClipboardUtil.ClipboardRestoreSuccess);
            }, pres, slide);
        }
Example #20
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);
        }
        protected override void ExecuteAction(string ribbonId)
        {
            PowerPointPresentation presentation = this.GetCurrentPresentation();
            PowerPointSlide        slide        = this.GetCurrentSlide();
            Selection selection = this.GetCurrentSelection();

            if (!ShapeUtil.IsSelectionShape(selection) || selection.ShapeRange.Count < 2)
            {
                MessageBox.Show(TextCollection.ShortcutsLabText.AddIntoGroupActionHandlerReminderText, TextCollection.CommonText.ErrorTitle);
                return;
            }

            ShapeRange result = AddIntoGroup.Execute(presentation, slide, selection);

            result.Select();
        }
        protected override void ExecuteAction(string ribbonId)
        {
            PowerPointPresentation presentation = this.GetCurrentPresentation();
            PowerPointSlide        slide        = this.GetCurrentSlide();
            Selection selection = this.GetCurrentSelection();

            if (!ShapeUtil.IsSelectionShape(selection) || selection.ShapeRange.Count < 2)
            {
                MessageBox.Show("Please select more than one shape.", "Error");
                return;
            }

            ShapeRange result = AddIntoGroup.Execute(presentation, slide, selection);

            result.Select();
        }
        /// <summary>
        /// To avoid changing the clipboard during a copy/cut and paste action.
        /// One solution for this is to save clipboard into a temp slide and revert clipboard afterwards.
        /// </summary>
        public static void RestoreClipboardAfterAction(System.Action action, PowerPointPresentation pres, PowerPointSlide origSlide)
        {
            if (!IsClipboardEmpty())
            {
                // Save clipboard onto a temp slide
                PowerPointSlide tempClipboardSlide  = null;
                ShapeRange      tempClipboardShapes = null;
                SlideRange      tempPastedSlide     = null;
                Shape           tempClipboardShape  = null;

                Logger.Log("RestoreClipboardAfterAction: Trying to paste as slide.", ActionFramework.Common.Logger.LogType.Info);
                tempPastedSlide = TryPastingAsSlide(pres, origSlide);

                if (tempPastedSlide == null)
                {
                    tempClipboardSlide = pres.AddSlide();
                    Logger.Log("RestoreClipboardAfterAction: Trying to paste as text.", ActionFramework.Common.Logger.LogType.Info);
                    tempClipboardShapes = TryPastingAsText(tempClipboardSlide);
                }

                if (tempPastedSlide == null && (tempClipboardShapes == null || tempClipboardShapes.Count < 1))
                {
                    Logger.Log("RestoreClipboardAfterAction: Trying to paste as shape.", ActionFramework.Common.Logger.LogType.Info);
                    tempClipboardShapes = TryPastingAsShape(tempClipboardSlide);
                }

                if (tempPastedSlide == null && (tempClipboardShapes == null || tempClipboardShapes.Count < 1))
                {
                    Logger.Log("RestoreClipboardAfterAction: Trying to paste onto current view of the document window.", ActionFramework.Common.Logger.LogType.Info);
                    tempClipboardShape = TryPastingOntoView(pres, tempClipboardSlide, origSlide);
                }

                action();

                RestoreClipboard(tempClipboardShape, tempClipboardShapes, tempPastedSlide);
                if (tempClipboardSlide != null)
                {
                    tempClipboardSlide.Delete();
                }
            }
            else
            {
                // Clipboard is empty, we can just run the action function
                action();
            }
        }
 private static SlideRange TryPastingAsSlide(PowerPointPresentation pres, PowerPointSlide origSlide)
 {
     try
     {
         // try pasting as slide
         SlideRange slides = pres.PasteSlide();
         // Ensure that the view is at the original slide
         pres.GotoSlide(origSlide.Index);
         return((slides.Count >= 1) ? slides : null);
     }
     catch (COMException e)
     {
         // May be thrown if clipboard is not a slide
         Logger.LogException(e, "TryPastingAsSlide");
         return(null);
     }
 }
        private static ClipboardUtilData SaveClipboardUnsafe(PowerPointPresentation pres, PowerPointSlide origSlide)
        {
            PowerPointSlide tempClipboardSlide  = null;
            ShapeRange      tempClipboardShapes = null;
            SlideRange      tempPastedSlide     = null;

            tempPastedSlide = TryPastingAsSlide(pres, origSlide);

            if (tempPastedSlide == null)
            {
                tempClipboardSlide = pres.AddSlide();
                Logger.Log("RestoreClipboardAfterAction: Trying to paste as text.", ActionFramework.Common.Logger.LogType.Info);
                tempClipboardShapes = TryPastingAsText(tempClipboardSlide);
            }

            if (CheckIfPastingFailed(tempPastedSlide, tempClipboardShapes))
            {
                Logger.Log("RestoreClipboardAfterAction: Trying to paste as shape.", ActionFramework.Common.Logger.LogType.Info);
                tempClipboardShapes = TryPastingAsShape(tempClipboardSlide);
            }

            if (CheckIfPastingFailed(tempPastedSlide, tempClipboardShapes))
            {
                Logger.Log("RestoreClipboardAfterAction: Trying to paste as PNG picture", ActionFramework.Common.Logger.LogType.Info);
                tempClipboardShapes = TryPastingAsPNG(tempClipboardSlide);
            }

            if (CheckIfPastingFailed(tempPastedSlide, tempClipboardShapes))
            {
                Logger.Log("RestoreClipboardAfterAction: Trying to paste as bitmap picture", ActionFramework.Common.Logger.LogType.Info);
                tempClipboardShapes = TryPastingAsBitmap(tempClipboardSlide);
            }

            if (CheckIfPastingFailed(tempPastedSlide, tempClipboardShapes))
            {
                Logger.Log("RestoreClipboardAfterAction: Trying to paste onto view", ActionFramework.Common.Logger.LogType.Info);
                tempClipboardShapes = TryPastingOntoView(pres, tempClipboardSlide, origSlide);
            }
            return(new ClipboardUtilData()
            {
                tempClipboardSlide = tempClipboardSlide,
                tempClipboardShapes = tempClipboardShapes,
                tempPastedSlide = tempPastedSlide
            });
        }
        protected override ShapeRange ExecutePasteAction(string ribbonId, PowerPointPresentation presentation, PowerPointSlide slide,
                                                         ShapeRange selectedShapes, ShapeRange selectedChildShapes)
        {
            PowerPointSlide tempSlide         = presentation.AddSlide(index: slide.Index);
            ShapeRange      tempPastingShapes = PasteShapesFromClipboard(tempSlide);

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

            ShapeRange pastingShapes = slide.CopyShapesToSlide(tempPastingShapes);

            tempSlide.Delete();

            return(pastingShapes);
        }
Example #27
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);
            }
        }
Example #28
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 = PasteShapesFromClipboard(slide);

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

            return(ReplaceWithClipboard.Execute(presentation, slide, selectedShapes, selectedChildShapes, 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));
        }
        protected override void ExecuteAction(string ribbonId)
        {
            if (this.GetAddIn().Application.ActiveWindow.Selection.Type !=
                Microsoft.Office.Interop.PowerPoint.PpSelectionType.ppSelectionShapes)
            {
                return;
            }

            this.StartNewUndoEntry();
            PowerPointPresentation pres  = this.GetCurrentPresentation();
            PowerPointSlide        slide = this.GetCurrentSlide();

            ClipboardUtil.RestoreClipboardAfterAction(() =>
            {
                Spotlight.AddSpotlightEffect();
                return(ClipboardUtil.ClipboardRestoreSuccess);
            }, pres, slide);
        }
    internal void RemoveControl(PowerPointPresentation.Views.PresentationControl control)
    {
      lock (_presentationControls)
      {
        if (!_presentationControls.Contains(control)) return;

        _presentationControls.Remove(control);
      }

      PresentationPanel.Children.Remove(control);

      #region Обновить цвета контролов

      lock (_presentationControls)
      {
        for (int i = 0; i < _presentationControls.Count; i++)
        {
          var brush = i % 2 == 0
          ? (Brush)new BrushConverter().ConvertFrom("#BDBCB6")
          : (Brush)new BrushConverter().ConvertFrom("#D2F5FD");

          _presentationControls[i].FindChildren<GroupBox>().ToList().ForEach(c => { c.Background = brush; c.BorderBrush = brush; });
        }
      }

      #endregion

      UpdateControlList();
    }