/// <summary>
 /// Stretches all selected shapes to the left edge of reference shape
 /// </summary>
 /// <param name="stretchShapes">The shapes to stretch</param>
 public void StretchLeft(PowerPoint.ShapeRange stretchShapes)
 {
     var appropriateStretch = new GetAppropriateStretchAction((referenceEdge, checkShape) =>
     {
         // Opposite stretch
         if (GetRight(checkShape) < referenceEdge)
         {
             return StretchRightAction;
         }
         return StretchLeftAction;
     });
     var defaultReferenceEdge = new GetDefaultReferenceEdge(referenceShape => referenceShape.VisualLeft);
     Stretch(stretchShapes, appropriateStretch, defaultReferenceEdge, StretchType.Left);
 }
        /// <summary>
        /// Stretches all selected shapes to the right edge of reference shape
        /// </summary>
        /// <param name="stretchShapes">The shapes to stretch</param>
        public void StretchRight(PowerPoint.ShapeRange stretchShapes)
        {
            var appropriateStretch = new GetAppropriateStretchAction((referenceEdge, checkShape) =>
            {
                // Opposite stretch
                if (checkShape.VisualLeft > referenceEdge)
                {
                    return(StretchLeftAction);
                }
                return(StretchRightAction);
            });
            var defaultReferenceEdge = new GetDefaultReferenceEdge(referenceShape => referenceShape.VisualLeft + referenceShape.AbsoluteWidth);

            Stretch(stretchShapes, appropriateStretch, defaultReferenceEdge, StretchType.Right);
        }
        /// <summary>
        /// Stretches all selected shapes to the left edge of reference shape
        /// </summary>
        /// <param name="stretchShapes">The shapes to stretch</param>
        public void StretchBottom(PowerPoint.ShapeRange stretchShapes)
        {
            var appropriateStretch = new GetAppropriateStretchAction((referenceEdge, checkShape) =>
            {
                // Opposite stretch
                if (checkShape.VisualTop > referenceEdge)
                {
                    return(StretchTopAction);
                }
                return(StretchBottomAction);
            });
            var defaultReferenceEdge = new GetDefaultReferenceEdge(referenceShape => referenceShape.VisualTop + referenceShape.AbsoluteHeight);

            Stretch(stretchShapes, appropriateStretch, defaultReferenceEdge, StretchType.Bottom);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Stretches all selected shapes to the left edge of reference shape
        /// </summary>
        /// <param name="stretchShapes">The shapes to stretch</param>
        public void StretchLeft(PowerPoint.ShapeRange stretchShapes)
        {
            GetAppropriateStretchAction appropriateStretch = new GetAppropriateStretchAction((referenceEdge, checkShape) =>
            {
                // Opposite stretch
                if (GetRight(checkShape) < referenceEdge)
                {
                    return(StretchRightAction);
                }
                return(StretchLeftAction);
            });
            GetDefaultReferenceEdge defaultReferenceEdge = new GetDefaultReferenceEdge(referenceShape => referenceShape.VisualLeft);

            Stretch(stretchShapes, appropriateStretch, defaultReferenceEdge, StretchType.Left);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Stretches all selected shapes to the top edge of reference shape
        /// </summary>
        /// <param name="stretchShapes">The shapes to stretch</param>
        public void StretchTop(PowerPoint.ShapeRange stretchShapes)
        {
            GetAppropriateStretchAction appropriateStretch = new GetAppropriateStretchAction((referenceEdge, checkShape) =>
            {
                // Opposite stretch
                if (GetBottom(checkShape) < referenceEdge)
                {
                    return(StretchBottomAction);
                }
                return(StretchTopAction);
            });
            GetDefaultReferenceEdge defaultReferenceEdge = new GetDefaultReferenceEdge(referenceShape => referenceShape.VisualTop);

            Stretch(stretchShapes, appropriateStretch, defaultReferenceEdge, StretchType.Top);
        }
        /// <summary>
        /// Stretch shapes in the list
        /// </summary>
        /// <param name="stretchShapes">The shapes to stretch</param>
        /// <param name="stretchAction">The function to use to stretch</param>
        /// <param name="defaultReferenceEdge">The function to return the default reference edge</param>
        /// <param name="stretchType">The type of stretch to perform</param>
        private void Stretch(PowerPoint.ShapeRange stretchShapes, GetAppropriateStretchAction stretchAction,
                             GetDefaultReferenceEdge defaultReferenceEdge, StretchType stretchType)
        {
            if (!ValidateSelection(stretchShapes))
            {
                return;
            }

            var referenceShape = GetReferenceShape(stretchShapes, defaultReferenceEdge, stretchType);
            var referenceEdge  = defaultReferenceEdge(new PPShape(referenceShape));

            for (var i = 1; i <= stretchShapes.Count; i++)
            {
                if (referenceShape.Equals(stretchShapes[i]))
                {
                    continue;
                }
                var stretchShape = new PPShape(stretchShapes[i]);
                var sa           = stretchAction(referenceEdge, stretchShape);
                sa(referenceEdge, stretchShape);
            }
        }
        private PowerPoint.Shape GetReferenceShape(PowerPoint.ShapeRange shapes, GetDefaultReferenceEdge getReferenceEdge,
                                                   StretchType stretchType)
        {
            var refShapeIndex = 1;

            if (ReferenceType == StretchRefType.Outermost)
            {
                var refPpShape = new PPShape(shapes[1]);
                for (var i = 2; i <= shapes.Count; i++)
                {
                    var tempPpShape = new PPShape(shapes[i]);
                    if (((stretchType == StretchType.Left || stretchType == StretchType.Top) &&
                         getReferenceEdge(refPpShape) > getReferenceEdge(tempPpShape)) ||
                        ((stretchType == StretchType.Right || stretchType == StretchType.Bottom) &&
                         getReferenceEdge(refPpShape) < getReferenceEdge(tempPpShape)))
                    {
                        refPpShape    = tempPpShape;
                        refShapeIndex = i;
                    }
                }
            }

            return(shapes[refShapeIndex]);
        }
        private PowerPoint.Shape GetReferenceShape(PowerPoint.ShapeRange shapes, GetDefaultReferenceEdge getReferenceEdge,
            StretchType stretchType)
        {
            var refShapeIndex = 1;

            if (ReferenceType == StretchRefType.Outermost)
            {
                var refPpShape = new PPShape(shapes[1]);
                for (var i = 2; i <= shapes.Count; i++)
                {
                    var tempPpShape = new PPShape(shapes[i]);
                    if (((stretchType == StretchType.Left || stretchType == StretchType.Top) &&
                        getReferenceEdge(refPpShape) > getReferenceEdge(tempPpShape)) ||
                        ((stretchType == StretchType.Right || stretchType == StretchType.Bottom) &&
                        getReferenceEdge(refPpShape) < getReferenceEdge(tempPpShape)))
                    {
                        refPpShape = tempPpShape;
                        refShapeIndex = i;
                    }
                }
            }

            return shapes[refShapeIndex];

        }
        /// <summary>
        /// Stretch shapes in the list
        /// </summary>
        /// <param name="stretchShapes">The shapes to stretch</param>
        /// <param name="stretchAction">The function to use to stretch</param>
        /// <param name="defaultReferenceEdge">The function to return the default reference edge</param>
        /// <param name="stretchType">The type of stretch to perform</param>
        private void Stretch(PowerPoint.ShapeRange stretchShapes, GetAppropriateStretchAction stretchAction, 
            GetDefaultReferenceEdge defaultReferenceEdge, StretchType stretchType)
        {
            if (!ValidateSelection(stretchShapes))
            {
                return;
            }

            var referenceShape = GetReferenceShape(stretchShapes, defaultReferenceEdge, stretchType);
            var referenceEdge = defaultReferenceEdge(new PPShape(referenceShape));

            for (var i = 1; i <= stretchShapes.Count; i++)
            {
                if (referenceShape.Equals(stretchShapes[i]))
                {
                    continue;
                }
                var stretchShape = new PPShape(stretchShapes[i]);
                var sa = stretchAction(referenceEdge, stretchShape);
                sa(referenceEdge, stretchShape);
            }
        }
 /// <summary>
 /// Stretches all selected shapes to the left edge of reference shape
 /// </summary>
 /// <param name="stretchShapes">The shapes to stretch</param>
 public void StretchBottom(PowerPoint.ShapeRange stretchShapes)
 {
     var appropriateStretch = new GetAppropriateStretchAction((referenceEdge, checkShape) =>
     {
         // Opposite stretch
         if (checkShape.VisualTop > referenceEdge)
         {
             return StretchTopAction;
         }
         return StretchBottomAction;
     });
     var defaultReferenceEdge = new GetDefaultReferenceEdge(referenceShape => referenceShape.VisualTop + referenceShape.AbsoluteHeight);
     Stretch(stretchShapes, appropriateStretch, defaultReferenceEdge, StretchType.Bottom);
 }