public static bool ShapesMatch(ShapeKey lSK, ShapeKey rSK) { if (lSK == null) { throw new ArgumentNullException("lSK"); } if (rSK == null) { throw new ArgumentNullException("rSK"); } return(lSK.ShapesMatch(rSK)); }
/// <summary> /// Finds the shapes selected in the active window. /// </summary> /// <returns>A shapes object representing the selected shape(s) /// or null if no selected shapes could be found. If non-null, /// guaranteed to contain at least one shape.</returns> public PowerPoint.ShapeRange GetSelectedShapes() { PowerPoint.DocumentWindow window = this.GetActiveWindow(); // Only gather the selection of a slide if it is in the active window. // TODO: may want to restrict this to regular slides rather than slide masters. // Would look something like: GetSlidePane(window).ViewType == PowerPoint.PpViewType.ppViewSlide if (window == null || window.ViewType != PowerPoint.PpViewType.ppViewNormal || window.ActivePane != GetSlidePane(window)) { return(null); } PowerPoint.Selection selection = window.Selection; if (selection == null) { return(null); } // Find the shapes associated with this selection. PowerPoint.ShapeRange shapes = null; // Only one of shapes and shape should be set in this switch; the other // should be left null. switch (selection.Type) { case PowerPoint.PpSelectionType.ppSelectionShapes: shapes = selection.ShapeRange; break; case PowerPoint.PpSelectionType.ppSelectionText: // Try to find a shape associated with the text. PowerPoint.Shape shape = null; object parent = selection.TextRange.Parent; if (parent is PowerPoint.Shape) { shape = (PowerPoint.Shape)parent; } else if (parent is PowerPoint.TextFrame) { parent = ((PowerPoint.TextFrame)parent).Parent; if (parent is PowerPoint.Shape) { shape = (PowerPoint.Shape)parent; } } // Transform the shape into a ShapeRange if (shape != null && window.View.Slide is PowerPoint.Slide) { PowerPoint.Shapes slideShapes = ((PowerPoint.Slide)window.View.Slide).Shapes; int i; for (i = 1; i <= slideShapes.Count; i++) { if (ShapeKey.ShapesMatch(slideShapes[i], this.GetSlideFromShape(slideShapes[i]).SlideID, shape, this.GetSlideFromShape(shape).SlideID)) { break; } } if (i <= slideShapes.Count) { shapes = ((PowerPoint.Slide)window.View.Slide).Shapes.Range(i); } } break; default: break; } if (shapes == null || shapes.Count == 0) { return(null); } else { return(shapes); } }
public static bool ShapesMatch(ShapeKey lSK, ShapeKey rSK) { if (lSK == null) throw new ArgumentNullException("lSK"); if (rSK == null) throw new ArgumentNullException("rSK"); return lSK.ShapesMatch(rSK); }