private void ExecuteBlurAction(string feature, Selection selection, Models.PowerPointPresentation pres, Models.PowerPointSlide slide, int percentage)
        {
            ClipboardUtil.RestoreClipboardAfterAction(() =>
            {
                switch (feature)
                {
                case EffectsLabText.BlurrinessFeatureSelected:
                    EffectsLabBlur.ExecuteBlurSelected(slide, selection, percentage);
                    break;

                case EffectsLabText.BlurrinessFeatureRemainder:
                    EffectsLabBlur.ExecuteBlurRemainder(slide, selection, percentage);
                    break;

                case EffectsLabText.BlurrinessFeatureBackground:
                    EffectsLabBlur.ExecuteBlurBackground(slide, selection, percentage);
                    break;

                default:
                    Logger.Log(feature + " does not exist!", Common.Logger.LogType.Error);
                    break;
                }
                return(ClipboardUtil.ClipboardRestoreSuccess);
            }, pres, slide);
        }
Example #2
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);
        }
Example #3
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);
        }
        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);
        }
Example #5
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);
        }
        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);
        }
        private static void ConvertToPictureForShape(PowerPointPresentation pres, PowerPointSlide slide, PowerPoint.Shape shape, int originalZOrder)
        {
            float rotation = 0;

            try
            {
                rotation       = shape.Rotation;
                shape.Rotation = 0;
            }
            catch (Exception e)
            {
                Logger.LogException(e, "Chart cannot be rotated.");
            }

            ClipboardUtil.RestoreClipboardAfterAction(() =>
            {
                float x      = shape.Left;
                float y      = shape.Top;
                float width  = shape.Width;
                float height = shape.Height;

                Shape pic = slide.Shapes.SafeCopyPNG(shape);
                shape.SafeDelete();

                pic.Left     = x + (width - pic.Width) / 2;
                pic.Top      = y + (height - pic.Height) / 2;
                pic.Rotation = rotation;
                // move picture to original z-order
                while (pic.ZOrderPosition > originalZOrder)
                {
                    pic.ZOrder(Office.MsoZOrderCmd.msoSendBackward);
                }
                while (pic.ZOrderPosition < originalZOrder)
                {
                    pic.ZOrder(Office.MsoZOrderCmd.msoBringForward);
                }
                pic.Select();
                return(pic);
            }, pres, slide);
        }
Example #8
0
        protected override void ExecuteAction(string ribbonId)
        {
            this.StartNewUndoEntry();
            PowerPointPresentation pres     = this.GetCurrentPresentation();
            PowerPointSlide        curSlide = this.GetCurrentSlide();
            Selection selection             = this.GetCurrentSelection();

            ClipboardUtil.RestoreClipboardAfterAction(() =>
            {
                if (ribbonId.Contains(EffectsLabText.RecolorRemainderMenuId))
                {
                    if (ribbonId.Contains(EffectsLabText.GrayScaleTag))
                    {
                        EffectsLabRecolor.GrayScaleRemainderEffect(curSlide, selection);
                    }
                    else if (ribbonId.Contains(EffectsLabText.BlackWhiteTag))
                    {
                        EffectsLabRecolor.BlackWhiteRemainderEffect(curSlide, selection);
                    }
                    else if (ribbonId.Contains(EffectsLabText.GothamTag))
                    {
                        EffectsLabRecolor.GothamRemainderEffect(curSlide, selection);
                    }
                    else if (ribbonId.Contains(EffectsLabText.SepiaTag))
                    {
                        EffectsLabRecolor.SepiaRemainderEffect(curSlide, selection);
                    }
                    else
                    {
                        Logger.Log(ribbonId + " does not exist!", Common.Logger.LogType.Error);
                    }
                }
                else if (ribbonId.Contains(EffectsLabText.RecolorBackgroundMenuId))
                {
                    if (ribbonId.Contains(EffectsLabText.GrayScaleTag))
                    {
                        EffectsLabRecolor.GrayScaleBackgroundEffect(curSlide, selection);
                    }
                    else if (ribbonId.Contains(EffectsLabText.BlackWhiteTag))
                    {
                        EffectsLabRecolor.BlackWhiteBackgroundEffect(curSlide, selection);
                    }
                    else if (ribbonId.Contains(EffectsLabText.GothamTag))
                    {
                        EffectsLabRecolor.GothamBackgroundEffect(curSlide, selection);
                    }
                    else if (ribbonId.Contains(EffectsLabText.SepiaTag))
                    {
                        EffectsLabRecolor.SepiaBackgroundEffect(curSlide, selection);
                    }
                    else
                    {
                        Logger.Log(ribbonId + " does not exist!", Common.Logger.LogType.Error);
                    }
                }
                else
                {
                    Logger.Log(ribbonId + " does not exist!", Common.Logger.LogType.Error);
                }
                return(ClipboardUtil.ClipboardRestoreSuccess);
            }, pres, curSlide);
        }