private static void ConvertToPictureForShape(PowerPoint.Shape shape) { float rotation = 0; try { rotation = shape.Rotation; shape.Rotation = 0; } catch (Exception e) { PowerPointLabsGlobals.LogException(e, "Chart cannot be rotated."); } shape.Copy(); float x = shape.Left; float y = shape.Top; float width = shape.Width; float height = shape.Height; shape.Delete(); var pic = PowerPointCurrentPresentationInfo.CurrentSlide.Shapes.PasteSpecial(PowerPoint.PpPasteDataType.ppPastePNG)[1]; pic.Left = x + (width - pic.Width) / 2; pic.Top = y + (height - pic.Height) / 2; pic.Rotation = rotation; pic.Select(); }
public static void AddSpotlightEffect() { try { var currentSlide = PowerPointCurrentPresentationInfo.CurrentSlide as PowerPointSlide; PowerPoint.ShapeRange selectedShapes = Globals.ThisAddIn.Application.ActiveWindow.Selection.ShapeRange; var addedSlide = currentSlide.CreateSpotlightSlide() as PowerPointSpotlightSlide; List <PowerPoint.Shape> spotlightShapes = new List <PowerPoint.Shape>(); addedSlide.DeleteShapesWithPrefix("SpotlightShape"); foreach (PowerPoint.Shape spotShape in selectedShapes) { addedSlide.DeleteShapesWithPrefix(spotShape.Name); PreFormatShapeOnCurrentSlide(spotShape); PowerPoint.Shape spotlightShape = addedSlide.CreateSpotlightShape(spotShape); CreateSpotlightDuplicate(spotlightShape); spotlightShapes.Add(spotlightShape); PostFormatShapeOnCurrentSlide(currentSlide, spotShape); } addedSlide.PrepareForSpotlight(); addedSlide.AddSpotlightEffect(spotlightShapes); currentSlide.DeleteShapesWithPrefix("SpotlightShape"); PowerPointPresentation.Current.AddAckSlide(); } catch (Exception e) { PowerPointLabsGlobals.LogException(e, "SpotlightBtnClick"); throw; } }
public static void AddAutoAnimation() { try { //Get References of current and next slides var currentSlide = PowerPointCurrentPresentationInfo.CurrentSlide as PowerPointSlide; if (currentSlide == null || currentSlide.Index == PowerPointPresentation.Current.SlideCount) { System.Windows.Forms.MessageBox.Show("Please select the correct slide", "Unable to Add Animations"); return; } PowerPointSlide nextSlide = PowerPointPresentation.Current.Slides[currentSlide.Index]; if (!GetMatchingShapeDetails(currentSlide, nextSlide)) { System.Windows.Forms.MessageBox.Show("No matching Shapes were found on the next slide", "Animation Not Added"); return; } AddCompleteAnimations(currentSlide, nextSlide); } catch (Exception e) { PowerPointLabsGlobals.LogException(e, "AddAnimationButtonClick"); Views.ErrorDialogWrapper.ShowDialog("PowerPointLabs", e.Message, e); } }
public static void AddAnimationInSlide() { try { var currentSlide = PowerPointCurrentPresentationInfo.CurrentSlide as PowerPointSlide; var selectedShapes = Globals.ThisAddIn.Application.ActiveWindow.Selection.ShapeRange as PowerPoint.ShapeRange; currentSlide.RemoveAnimationsForShapes(selectedShapes.Cast <PowerPoint.Shape>().ToList()); if (!isHighlightBullets && !isHighlightTextFragments) { FormatInSlideAnimateShapes(selectedShapes); } if (selectedShapes.Count == 1) { InSlideAnimateSingleShape(currentSlide, selectedShapes[1]); } else { InSlideAnimateMultiShape(currentSlide, selectedShapes); } if (!isHighlightBullets && !isHighlightTextFragments) { Globals.ThisAddIn.Application.CommandBars.ExecuteMso("AnimationPreview"); PowerPointPresentation.Current.AddAckSlide(); } } catch (Exception e) { PowerPointLabsGlobals.LogException(e, "AddAnimationInSlide"); throw; } }
public static System.Drawing.Bitmap GetConvertToPicMenuImage(Office.IRibbonControl control) { try { return(new System.Drawing.Bitmap(Properties.Resources.ConvertToPicture)); } catch (Exception e) { PowerPointLabsGlobals.LogException(e, "GetConvertToPicMenuImage"); throw; } }
public static Bitmap GetCutOutShapeMenuImage(Office.IRibbonControl control) { try { return(new Bitmap(Properties.Resources.CutOutShapeMenu)); } catch (Exception e) { PowerPointLabsGlobals.LogException(e, "GetCutOutShapeMenuImage"); throw; } }
public static void AddHighlightedTextFragments() { try { var currentSlide = PowerPointCurrentPresentationInfo.CurrentSlide as PowerPointSlide; PowerPoint.ShapeRange selectedShapes = null; Office.TextRange2 selectedText = null; //Get shapes to consider for animation switch (userSelection) { case HighlightTextSelection.kShapeSelected: return; case HighlightTextSelection.kTextSelected: selectedShapes = Globals.ThisAddIn.Application.ActiveWindow.Selection.ShapeRange; selectedText = Globals.ThisAddIn.Application.ActiveWindow.Selection.TextRange2.TrimText(); break; case HighlightTextSelection.kNoneSelected: return; default: return; } if (selectedText.Length <= 0) { return; } if (selectedShapes.Count != 1) { return; } List <PowerPoint.Shape> selectionToAnimate = GetShapesFromLinesInText(currentSlide, selectedText, selectedShapes[1]); GroupShapesForAnimation(selectionToAnimate); List <PowerPoint.Shape> shapesToAnimate = GetShapesToAnimate(currentSlide); SelectShapes(shapesToAnimate); RunAnimateInSlide(); } catch (Exception e) { PowerPointLabsGlobals.LogException(e, "AddHighlightedTextFragments"); throw; } }
public static void AddZoomToArea() { if (!IsSelectingShapes()) { return; } try { var currentSlide = PowerPointCurrentPresentationInfo.CurrentSlide; DeleteExistingZoomToAreaSlides(currentSlide); currentSlide.Name = "PPTLabsZoomToAreaSlide" + DateTime.Now.ToString("yyyyMMddHHmmssffff"); var selectedShapes = Globals.ThisAddIn.Application.ActiveWindow.Selection.ShapeRange; var zoomRectangles = ReplaceWithZoomRectangleImages(currentSlide, selectedShapes); MakeInvisible(zoomRectangles); List <PowerPoint.Shape> editedSelectedShapes = GetEditedShapesForZoomToArea(currentSlide, zoomRectangles); var addedSlides = AddMultiSlideZoomToArea(currentSlide, editedSelectedShapes); if (!multiSlideZoomChecked) { Graphics.SquashSlides(addedSlides); } MakeVisible(zoomRectangles); Globals.ThisAddIn.Application.ActiveWindow.View.GotoSlide(currentSlide.Index); PowerPointPresentation.Current.AddAckSlide(); // Always call ReleaseComObject and GC.Collect after shape deletion to prevent shape corruption after undo. System.Runtime.InteropServices.Marshal.ReleaseComObject(selectedShapes); GC.Collect(); } catch (Exception e) { PowerPointLabsGlobals.LogException(e, "AddZoomToArea"); ErrorDialogWrapper.ShowDialog("Error when adding zoom to area", "An error occurred when adding zoom to area.", e); throw; } }
public static void AddHighlightBulletsBackground() { try { var currentSlide = PowerPointCurrentPresentationInfo.CurrentSlide as PowerPointSlide; currentSlide.Name = "PPTLabsHighlightBulletsSlide" + DateTime.Now.ToString("yyyyMMddHHmmssffff"); PowerPoint.ShapeRange selectedShapes = null; Office.TextRange2 selectedText = null; //Get shapes to consider for animation List <PowerPoint.Shape> shapesToUse = null; switch (userSelection) { case HighlightBackgroundSelection.kShapeSelected: selectedShapes = Globals.ThisAddIn.Application.ActiveWindow.Selection.ShapeRange; shapesToUse = GetShapesToUse(currentSlide, selectedShapes); break; case HighlightBackgroundSelection.kTextSelected: selectedShapes = Globals.ThisAddIn.Application.ActiveWindow.Selection.ShapeRange; selectedText = Globals.ThisAddIn.Application.ActiveWindow.Selection.TextRange2.TrimText(); shapesToUse = GetShapesToUse(currentSlide, selectedShapes); break; case HighlightBackgroundSelection.kNoneSelected: currentSlide.DeleteIndicator(); currentSlide.DeleteShapesWithPrefix("PPTLabsHighlightBackgroundShape"); shapesToUse = GetAllUsableShapesInSlide(currentSlide); break; default: break; } Globals.ThisAddIn.Application.ActiveWindow.Selection.Unselect(); Globals.ThisAddIn.Application.ActiveWindow.View.GotoSlide(currentSlide.Index); if (shapesToUse == null || shapesToUse.Count == 0) { return; } SelectOldShapesToAnimate(currentSlide, shapesToUse); bool newShapesAdded = AddNewShapesToAnimate(currentSlide, shapesToUse, selectedText); if (newShapesAdded) { bool oldValue = AnimateInSlide.frameAnimationChecked; AnimateInSlide.frameAnimationChecked = false; AnimateInSlide.isHighlightBullets = true; AnimateInSlide.AddAnimationInSlide(); AnimateInSlide.frameAnimationChecked = oldValue; PowerPointPresentation.Current.AddAckSlide(); } Globals.ThisAddIn.Application.ActiveWindow.Selection.Unselect(); } catch (Exception e) { PowerPointLabsGlobals.LogException(e, "AddHighlightBulletsBackground"); throw; } }
public static void AddDrillDownAnimation(PowerPoint.Shape selectedShape, PowerPointSlide currentSlide, out PowerPointDrillDownSlide addedSlide, bool includeAckSlide = true, bool deletePreviouslyAdded = true) { try { if (currentSlide == null || currentSlide.Index == PowerPointPresentation.Current.SlideCount) { System.Windows.Forms.MessageBox.Show("No next slide is found. Please select the correct slide", "Unable to Add Animations"); addedSlide = null; return; } //Pick up the border and shadow style, to be applied to zoomed shape selectedShape.PickUp(); PrepareZoomShape(currentSlide, ref selectedShape); PowerPointSlide nextSlide = GetNextSlide(currentSlide, deletePreviouslyAdded); PowerPoint.Shape nextSlidePicture = null, shapeToZoom = null; currentSlide.HideIndicator(); if (backgroundZoomChecked) { nextSlidePicture = GetNextSlidePictureWithBackground(currentSlide, nextSlide); nextSlidePicture.Apply(); PrepareNextSlidePicture(currentSlide, selectedShape, ref nextSlidePicture); addedSlide = (PowerPointDrillDownSlide)currentSlide.CreateDrillDownSlide(); addedSlide.DeleteAllShapes(); nextSlidePicture.Copy(); shapeToZoom = addedSlide.Shapes.Paste()[1]; addedSlide.DeleteShapeAnimations(shapeToZoom); currentSlide.Copy(); var backgroundShape = addedSlide.Shapes.PasteSpecial(PowerPoint.PpPasteDataType.ppPastePNG)[1]; backgroundShape.Apply(); Utils.Graphics.FitShapeToSlide(ref backgroundShape); backgroundShape.ZOrder(Office.MsoZOrderCmd.msoSendBackward); backgroundShape.Name = "PPTZoomInShape" + DateTime.Now.ToString("yyyyMMddHHmmssffff"); addedSlide.PrepareForDrillDown(); addedSlide.AddDrillDownAnimationBackground(backgroundShape, shapeToZoom, nextSlidePicture); } else { PowerPoint.Shape pictureOnNextSlide = null; nextSlidePicture = GetNextSlidePictureWithoutBackground(currentSlide, nextSlide, out pictureOnNextSlide); nextSlidePicture.Apply(); PrepareNextSlidePicture(currentSlide, selectedShape, ref nextSlidePicture); addedSlide = (PowerPointDrillDownSlide)currentSlide.CreateDrillDownSlide(); addedSlide.DeleteAllShapes(); nextSlidePicture.Copy(); shapeToZoom = addedSlide.Shapes.Paste()[1]; addedSlide.DeleteShapeAnimations(shapeToZoom); currentSlide.Copy(); var backgroundShape = addedSlide.Shapes.PasteSpecial(PowerPoint.PpPasteDataType.ppPastePNG)[1]; backgroundShape.Apply(); Utils.Graphics.FitShapeToSlide(ref backgroundShape); backgroundShape.ZOrder(Office.MsoZOrderCmd.msoSendBackward); backgroundShape.Name = "PPTZoomInShape" + DateTime.Now.ToString("yyyyMMddHHmmssffff"); addedSlide.PrepareForDrillDown(); addedSlide.AddDrillDownAnimationNoBackground(backgroundShape, shapeToZoom, pictureOnNextSlide); pictureOnNextSlide.Delete(); } currentSlide.ShowIndicator(); Globals.ThisAddIn.Application.ActiveWindow.View.GotoSlide(addedSlide.Index); Globals.ThisAddIn.Application.CommandBars.ExecuteMso("AnimationPreview"); if (includeAckSlide) { PowerPointPresentation.Current.AddAckSlide(); } } catch (Exception e) { PowerPointLabsGlobals.LogException(e, "AddDrillDownAnimation"); ErrorDialogWrapper.ShowDialog("Error when adding drill down animation", "An error occurred when adding drill down animation.", e); throw; } }
public static void AddStepBackAnimation(PowerPoint.Shape selectedShape, PowerPointSlide currentSlide, out PowerPointStepBackSlide addedSlide, bool includeAckSlide = true, bool deletePreviouslyAdded = true) { try { if (currentSlide == null || currentSlide.Index == 1) { System.Windows.Forms.MessageBox.Show("No previous slide is found. Please select the correct slide", "Unable to Add Animations"); addedSlide = null; return; } //Pick up the border and shadow style, to be applied to zoomed shape selectedShape.PickUp(); PrepareZoomShape(currentSlide, ref selectedShape); PowerPointSlide previousSlide = GetPreviousSlide(currentSlide, deletePreviouslyAdded); PowerPoint.Shape previousSlidePicture = null, shapeToZoom = null; currentSlide.HideIndicator(); if (backgroundZoomChecked) { previousSlidePicture = GetPreviousSlidePictureWithBackground(currentSlide, previousSlide); previousSlidePicture.Apply(); PreparePreviousSlidePicture(currentSlide, selectedShape, ref previousSlidePicture); addedSlide = (PowerPointStepBackSlide)previousSlide.CreateStepBackSlide(); addedSlide.DeleteAllShapes(); PowerPoint.Shape backgroundShape = null; shapeToZoom = GetStepBackWithBackgroundShapeToZoom(currentSlide, addedSlide, previousSlidePicture, out backgroundShape); shapeToZoom.Apply(); addedSlide.PrepareForStepBack(); addedSlide.AddStepBackAnimationBackground(shapeToZoom, backgroundShape, previousSlidePicture); } else { addedSlide = (PowerPointStepBackSlide)previousSlide.CreateStepBackSlide(); addedSlide.DeleteAllShapes(); shapeToZoom = GetStepBackWithoutBackgroundShapeToZoom(currentSlide, addedSlide, previousSlide); shapeToZoom.Apply(); shapeToZoom.Copy(); previousSlidePicture = currentSlide.Shapes.PasteSpecial(PowerPoint.PpPasteDataType.ppPastePNG)[1]; previousSlidePicture.Apply(); PreparePreviousSlidePicture(currentSlide, selectedShape, ref previousSlidePicture); addedSlide.PrepareForStepBack(); addedSlide.AddStepBackAnimationNonBackground(shapeToZoom, previousSlidePicture); } currentSlide.ShowIndicator(); currentSlide.Transition.EntryEffect = PowerPoint.PpEntryEffect.ppEffectFadeSmoothly; currentSlide.Transition.Duration = 0.25f; Globals.ThisAddIn.Application.ActiveWindow.View.GotoSlide(addedSlide.Index); Globals.ThisAddIn.Application.CommandBars.ExecuteMso("AnimationPreview"); if (includeAckSlide) { PowerPointPresentation.Current.AddAckSlide(); } } catch (Exception e) { PowerPointLabsGlobals.LogException(e, "AddStepBackAnimation"); ErrorDialogWrapper.ShowDialog("Error when adding step back animation", "An error occurred when adding step back animation.", e); throw; } }
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) { PowerPointLabsGlobals.LogException(e, "AddHighlightBulletsText"); throw; } }
public static void ReloadAutoAnimation() { try { var selectedSlide = PowerPointCurrentPresentationInfo.CurrentSlide as PowerPointSlide; PowerPointSlide currentSlide = null, animatedSlide = null, nextSlide = null; if (selectedSlide.Name.StartsWith("PPSlideAnimated")) { nextSlide = PowerPointPresentation.Current.Slides[selectedSlide.Index]; currentSlide = PowerPointPresentation.Current.Slides[selectedSlide.Index - 2]; animatedSlide = selectedSlide; ManageSlidesForReload(currentSlide, nextSlide, animatedSlide); } else if (selectedSlide.Name.StartsWith("PPSlideStart")) { animatedSlide = PowerPointPresentation.Current.Slides[selectedSlide.Index]; nextSlide = PowerPointPresentation.Current.Slides[selectedSlide.Index + 1]; currentSlide = selectedSlide; ManageSlidesForReload(currentSlide, nextSlide, animatedSlide); } else if (selectedSlide.Name.StartsWith("PPSlideEnd")) { animatedSlide = PowerPointPresentation.Current.Slides[selectedSlide.Index - 2]; currentSlide = PowerPointPresentation.Current.Slides[selectedSlide.Index - 3]; nextSlide = selectedSlide; ManageSlidesForReload(currentSlide, nextSlide, animatedSlide); } else if (selectedSlide.Name.StartsWith("PPSlideMulti")) { if (selectedSlide.Index > 2) { animatedSlide = PowerPointPresentation.Current.Slides[selectedSlide.Index - 2]; currentSlide = PowerPointPresentation.Current.Slides[selectedSlide.Index - 3]; nextSlide = selectedSlide; if (animatedSlide.Name.StartsWith("PPSlideAnimated")) { ManageSlidesForReload(currentSlide, nextSlide, animatedSlide); } } if (selectedSlide.Index < PowerPointPresentation.Current.SlideCount - 1) { animatedSlide = PowerPointPresentation.Current.Slides[selectedSlide.Index]; nextSlide = PowerPointPresentation.Current.Slides[selectedSlide.Index + 1]; currentSlide = selectedSlide; if (animatedSlide.Name.StartsWith("PPSlideAnimated")) { ManageSlidesForReload(currentSlide, nextSlide, animatedSlide); } } } else { System.Windows.Forms.MessageBox.Show("The current slide was not added by PowerPointLabs Auto Animate", "Error"); } } catch (Exception e) { PowerPointLabsGlobals.LogException(e, "ReloadAutoAnimation"); Views.ErrorDialogWrapper.ShowDialog("PowerPointLabs", e.Message, e); } }