Beispiel #1
0
        public static void AddHighlightBulletsText()
        {
            try
            {
                var currentSlide = PowerPointCurrentPresentationInfo.CurrentSlide as PowerPointSlide;

                PowerPoint.ShapeRange selectedShapes = null;
                Office.TextRange2     selectedText   = null;

                //Get shapes to consider for animation
                List <PowerPoint.Shape> shapesToUse = null;
                switch (userSelection)
                {
                case HighlightTextSelection.kShapeSelected:
                    selectedShapes = Globals.ThisAddIn.Application.ActiveWindow.Selection.ShapeRange;
                    shapesToUse    = GetShapesToUse(currentSlide, selectedShapes);
                    break;

                case HighlightTextSelection.kTextSelected:
                    selectedShapes = Globals.ThisAddIn.Application.ActiveWindow.Selection.ShapeRange;
                    selectedText   = Globals.ThisAddIn.Application.ActiveWindow.Selection.TextRange2.TrimText();
                    shapesToUse    = GetShapesToUse(currentSlide, selectedShapes);
                    break;

                case HighlightTextSelection.kNoneSelected:
                    currentSlide.DeleteIndicator();
                    currentSlide.DeleteShapesWithPrefix("PPTLabsHighlightBackgroundShape");
                    shapesToUse = GetAllUsableShapesInSlide(currentSlide);
                    break;

                default:
                    break;
                }

                if (currentSlide.Name.Contains("PPTLabsHighlightBulletsSlide"))
                {
                    ProcessExistingHighlightSlide(currentSlide, shapesToUse);
                }

                if (shapesToUse == null || shapesToUse.Count == 0)
                {
                    return;
                }

                currentSlide.Name = "PPTLabsHighlightBulletsSlide" + DateTime.Now.ToString("yyyyMMddHHmmssffff");

                PowerPoint.Sequence sequence = currentSlide.TimeLine.MainSequence;
                bool isFirstShape            = IsFirstShape(currentSlide);

                foreach (PowerPoint.Shape sh in shapesToUse)
                {
                    if (!sh.Name.Contains("HighlightTextShape"))
                    {
                        sh.Name = "HighlightTextShape" + DateTime.Now.ToString("yyyyMMddHHmmssffff");
                    }

                    //Add Font Appear effect for all paragraphs within shape
                    int currentIndex = sequence.Count;
                    sequence.AddEffect(sh, PowerPoint.MsoAnimEffect.msoAnimEffectChangeFontColor, PowerPoint.MsoAnimateByLevel.msoAnimateTextByFifthLevel, PowerPoint.MsoAnimTriggerType.msoAnimTriggerOnPageClick);
                    var appearEffects = AsList(sequence, currentIndex + 1, sequence.Count + 1);

                    //Add Font Disappear effect for all paragraphs within shape
                    currentIndex = sequence.Count;
                    sequence.AddEffect(sh, PowerPoint.MsoAnimEffect.msoAnimEffectChangeFontColor, PowerPoint.MsoAnimateByLevel.msoAnimateTextByFifthLevel, PowerPoint.MsoAnimTriggerType.msoAnimTriggerWithPrevious);
                    var disappearEffects = AsList(sequence, currentIndex + 1, sequence.Count + 1);

                    //Remove effects for paragraphs without bullet points
                    var markedForRemoval = GetParagraphsToRemove(sh, selectedText);
                    // assert appearEffects.Count == disappearEffects.Count;
                    // assert markedForRemoval.Count <= appearEffects.Count;
                    for (int i = markedForRemoval.Count - 1; i >= 0; --i)
                    {
                        // delete from back.
                        int index = markedForRemoval[i];
                        appearEffects[index].Delete();
                        appearEffects.RemoveAt(index);
                        disappearEffects[index].Delete();
                        disappearEffects.RemoveAt(index);
                    }

                    if (appearEffects.Count == 0)
                    {
                        continue;
                    }

                    RearrangeEffects(appearEffects, disappearEffects);
                    FormatAppearEffects(appearEffects, isFirstShape);
                    FormatDisappearEffects(disappearEffects);
                    isFirstShape = false;
                }

                Globals.ThisAddIn.Application.CommandBars.ExecuteMso("AnimationPreview");
                PowerPointPresentation.Current.AddAckSlide();
            }
            catch (Exception e)
            {
                Logger.LogException(e, "AddHighlightBulletsText");
                throw;
            }
        }
        private static void AddFrameAnimationEffects(PowerPointSlide animationSlide, PowerPoint.Shape initialShape, float incrementLeft, float incrementTop, float incrementWidth, float incrementHeight, float incrementRotation, float incrementFont, float duration, int numFrames)
        {
            PowerPoint.Shape    lastShape = initialShape;
            PowerPoint.Sequence sequence  = animationSlide.TimeLine.MainSequence;
            for (int i = 1; i <= numFrames; i++)
            {
                PowerPoint.Shape dupShape = initialShape.Duplicate()[1];
                if (i != 1 && animationType != FrameMotionAnimationType.kZoomToAreaDeMagnify)
                {
                    sequence[sequence.Count].Delete();
                }

                if (animationType == FrameMotionAnimationType.kInSlideAnimate || animationType == FrameMotionAnimationType.kZoomToAreaPan || animationType == FrameMotionAnimationType.kZoomToAreaDeMagnify)
                {
                    animationSlide.DeleteShapeAnimations(dupShape);
                }

                if (animationType == FrameMotionAnimationType.kZoomToAreaPan)
                {
                    dupShape.Name = "PPTLabsMagnifyPanAreaGroup" + DateTime.Now.ToString("yyyyMMddHHmmssffff");
                }

                dupShape.LockAspectRatio = Office.MsoTriState.msoFalse;
                dupShape.Left            = initialShape.Left;
                dupShape.Top             = initialShape.Top;

                if (incrementWidth != 0.0f)
                {
                    dupShape.ScaleWidth((1.0f + (incrementWidth * i)), Office.MsoTriState.msoFalse, Office.MsoScaleFrom.msoScaleFromMiddle);
                }

                if (incrementHeight != 0.0f)
                {
                    dupShape.ScaleHeight((1.0f + (incrementHeight * i)), Office.MsoTriState.msoFalse, Office.MsoScaleFrom.msoScaleFromMiddle);
                }

                if (incrementRotation != 0.0f)
                {
                    dupShape.Rotation += (incrementRotation * i);
                }

                if (incrementLeft != 0.0f)
                {
                    dupShape.Left += (incrementLeft * i);
                }

                if (incrementTop != 0.0f)
                {
                    dupShape.Top += (incrementTop * i);
                }

                if (incrementFont != 0.0f)
                {
                    dupShape.TextFrame.TextRange.Font.Size += (incrementFont * i);
                }

                if (i == 1 && (animationType == FrameMotionAnimationType.kInSlideAnimate || animationType == FrameMotionAnimationType.kZoomToAreaPan))
                {
                    PowerPoint.Effect appear = sequence.AddEffect(dupShape, PowerPoint.MsoAnimEffect.msoAnimEffectAppear, PowerPoint.MsoAnimateByLevel.msoAnimateLevelNone, PowerPoint.MsoAnimTriggerType.msoAnimTriggerOnPageClick);
                }
                else
                {
                    PowerPoint.Effect appear = sequence.AddEffect(dupShape, PowerPoint.MsoAnimEffect.msoAnimEffectAppear, PowerPoint.MsoAnimateByLevel.msoAnimateLevelNone, PowerPoint.MsoAnimTriggerType.msoAnimTriggerWithPrevious);
                    appear.Timing.TriggerDelayTime = ((duration / numFrames) * i);
                }

                PowerPoint.Effect disappear = sequence.AddEffect(lastShape, PowerPoint.MsoAnimEffect.msoAnimEffectAppear, PowerPoint.MsoAnimateByLevel.msoAnimateLevelNone, PowerPoint.MsoAnimTriggerType.msoAnimTriggerWithPrevious);
                disappear.Exit = Office.MsoTriState.msoTrue;
                disappear.Timing.TriggerDelayTime = ((duration / numFrames) * i);

                lastShape = dupShape;
            }

            if (animationType == FrameMotionAnimationType.kInSlideAnimate || animationType == FrameMotionAnimationType.kZoomToAreaPan || animationType == FrameMotionAnimationType.kZoomToAreaDeMagnify)
            {
                PowerPoint.Effect disappearLast = sequence.AddEffect(lastShape, PowerPoint.MsoAnimEffect.msoAnimEffectAppear, PowerPoint.MsoAnimateByLevel.msoAnimateLevelNone, PowerPoint.MsoAnimTriggerType.msoAnimTriggerAfterPrevious);
                disappearLast.Exit = Office.MsoTriState.msoTrue;
                disappearLast.Timing.TriggerDelayTime = duration;
            }
        }