progressbombDominik GundackerHow to add progress showing images on each slide of a presentation
There will be a bomb with a fuse. The flame will burn down the fuse till it reaches the bomb at the last slide. Then there will be a additional slide at the end that shows the explosion
/* Macro, which generates a fuse with a bomb, when the fuse has burned down,
the bomb will explode */
/* 03_bomb.rex */
xScriptContext=uno.getScriptContext() -- get the xScriptContext object
oDoc=xScriptContext~getDocument -- get the document service (an XModel object)
/* retrieving the important interfaces to get access to the drawpages */
xDrawPagesSupplier=oDoc~{%see com.sun.star.drawing.XDrawPagesSupplier%XDrawPagesSupplier}
xImpressFactory = oDoc~{%see com.sun.star.lang.XMultiServiceFactory%XMultiServiceFactory}
xDrawPages = xDrawPagesSupplier~getDrawPages
/* global service manager for shape grouper */
xContext = xScriptContext~getComponentContext
XMcf = xContext~getServiceManager
CALL removeSelection oDoc
/* remove the explosion page, if it exists */
CALL getNumberOfVisibleSlides xDrawPages
pagecount=result
IF pagecount <= 2 THEN
DO
.bsf.dialog~messageBox("This presentation has less than three slide. "-
"There is no need for running this macro!", "ERROR", "error")
EXIT 0
END
pagecount=xDrawPages~{%see com.sun.star.container.XIndexAccess%XIndexAccess}~getCount
DO i = 1 TO pagecount - 1
xDrawPage = xDrawPages~getByIndex(i)~{%see com.sun.star.drawing.XDrawPage%XDrawPage}
IF(xDrawPage~{%see com.sun.star.container.XNamed%XNamed}~getName() == "explosion_page") THEN
DO
xDrawPages~remove(xDrawPage)
ITERATE
END
END
/* initialize all variables (height, width, etc.) */
CALL getNumberOfVisibleSlides xDrawPages
pagecount=result
firstDrawPageProps = xDrawPages~getByIndex(0)~{%see com.sun.star.drawing.XDrawPage%XDrawPage}~{%see com.sun.star.beans.XPropertySet%XPropertySet}
width = firstDrawPageProps~getPropertyValue("Width")
height = firstDrawPageProps~getPropertyValue("Height")
bombPositionX = width - 2500
shapeX = 500
shapeY = height - 2450
step = trunc( (width - 3150) / (pagecount - 2))
positionFlame = shapeX
lengthCord = bombPositionX - 800
CALL GetPresentationDirectory oDoc~getURL
directory = result
separator = .uno~file.separator
CALL getFirstVisibleSlide xDrawPages
startIndex = result + 1
pagecount=xDrawPages~{%see com.sun.star.container.XIndexAccess%XIndexAccess}~getCount
DO i = 0 TO pagecount - 1
xDrawPage = xDrawPages~getByIndex(i)~{%see com.sun.star.drawing.XDrawPage%XDrawPage}
/* remove existing bombs, if necessary */
xShapes = xDrawPage~{%see com.sun.star.drawing.XShapes%XShapes}
DO j = 0 TO xShapes~getCount - 1
xShape = xShapes~getByIndex(j)
IF(xShape~{%see com.sun.star.container.XNamed%XNamed}~getName() == "bomb_group") THEN
DO
xShapeGroup = xShape~{%see com.sun.star.drawing.XShapeGroup%XShapeGroup}
xDrawPage~remove(xShapeGroup)
END
END
xProps = xDrawPage~{%see com.sun.star.beans.XPropertySet%XPropertySet}
IF(xProps~getPropertyValue("Visible") == 0 | i < startIndex) THEN
ITERATE
/* creating and positioning of the bomb */
bomb = xImpressFactory~createInstance(-
"{%see com.sun.star.drawing.GraphicObjectShape}")
bomb = bomb~{%see com.sun.star.drawing.XShape%XShape}
CALL setSizeAndPosition bomb, 2100, 2150, bombPositionX, shapeY
bombProps=bomb~{%see com.sun.star.beans.XPropertySet%XPropertySet}
bombProps~setPropertyValue("GraphicURL",-
uno.convertToURL(directory||separator||"bomb.gif"))
xDrawPage~add(bomb)
/* creating and positioning of the cord */
cord = xImpressFactory~createInstance(-
"{%see com.sun.star.drawing.RectangleShape}")
cord = cord~{%see com.sun.star.drawing.XShape%XShape}
CALL setSizeAndPosition cord, lengthCord, 100,-
positionFlame + 700, shapeY + 1300
cordProps=cord~{%see com.sun.star.beans.XPropertySet%XPropertySet}
cordProps~setPropertyValue("FillColor", box("int", "FFFF00"x ~c2d))
xDrawPage~add(cord)
/* creating and positioning of the fuse */
fuse = xImpressFactory~createInstance(-
"{%see com.sun.star.drawing.GraphicObjectShape}")
fuse = fuse~{%see com.sun.star.drawing.XShape%XShape}
CALL setSizeAndPosition fuse, 1000, 1000, positionFlame, shapeY + 940
fuseProps=fuse~{%see com.sun.star.beans.XPropertySet%XPropertySet}
fuseProps~setPropertyValue("GraphicURL",-
uno.convertToURL(directory||separator||"fuse.png"))
xDrawPage~add(fuse)
/* create the group */
shapeGroup = xMcf~createInstanceWithContext(-
"{%see com.sun.star.drawing.ShapeCollection}", xContext)
shapeGroup = shapeGroup~{%see com.sun.star.drawing.XShapes%XShapes}
shapeGroup~add(bomb)
shapeGroup~add(cord)
shapeGroup~add(fuse)
xShapeGrouper = xDrawPage~{%see com.sun.star.drawing.XShapeGrouper%XShapeGrouper}
xShapeGroup = xShapeGrouper~group(shapeGroup)
name = xShapeGroup~{%see com.sun.star.container.XNamed%XNamed}
name~setName("bomb_group")
positionFlame = positionFlame + step
lengthCord = lengthCord - step
END
/* creating, resizing and positioning of the explosion page and content*/
xDrawPages~insertNewByIndex(pagecount)
explosionPage = xDrawPages~getByIndex(pagecount)~{%see com.sun.star.drawing.XDrawPage%XDrawPage}
explosionPage~{%see com.sun.star.container.XNamed%XNamed}~setName("explosion_page")
textShape = xImpressFactory~createInstance("{%see com.sun.star.drawing.TextShape}")
textShape = textShape~{%see com.sun.star.drawing.XShape%XShape}
CALL setSizeAndPosition textShape, 23000, 3000, 3000, 2000
explosionPage~add(textShape)
explosion = xImpressFactory~createInstance(-
"{%see com.sun.star.drawing.GraphicObjectShape}")
explosion = explosion~{%see com.sun.star.drawing.XShape%XShape}
CALL setSizeAndPosition explosion, 20000, 15000, 4200, 5000
explosionPage~add(explosion)
explosionProps = explosion~{%see com.sun.star.beans.XPropertySet%XPropertySet}
explosionProps~setPropertyValue("GraphicURL",-
uno.convertToURL(directory||separator||"explosion.jpg"))
textProps = textShape~{%see com.sun.star.beans.XPropertySet%XPropertySet}
textProps~setPropertyValue("TextFitToSize",-
bsf.getConstant("{%see com.sun.star.drawing.TextFitToSizeType}","PROPORTIONAL"))
effects = bsf.wrapStaticFields("{%see com.sun.star.presentation.AnimationEffect}")
speeds = bsf.wrapStaticFields("{%see com.sun.star.presentation.AnimationSpeed}")
textProps~setPropertyValue("Effect", effects~FADE_FROM_CENTER)
textProps~setPropertyValue("Speed", speeds~FAST)
explosionProps~setPropertyValue("Effect", effects~HORIZONTAL_ROTATE)
explosionProps~setPropertyValue("Speed", speeds~MEDIUM)
/* formating the textshapes */
textShape~{%see com.sun.star.text.XText%XText}~setString("BOOOOOOOMMMMM!!!!!!")
explosionPageProps = explosionPage~{%see com.sun.star.beans.XPropertySet%XPropertySet}
explosionPageProps~setPropertyValue("Effect",-
bsf.getConstant("{%see com.sun.star.presentation.FadeEffect}", "RANDOM"))
explosionPageProps~setPropertyValue("Speed", speeds~MEDIUM)
EXIT 0
/* routine for getting the directory of the presentation */
GetPresentationDirectory :
use arg path
separator = .uno~file.separator
full = REVERSE(uno.convertFromURL(path))
parse var full "pdo." filename (separator) directory
directory = REVERSE(directory)
return directory
/* Returns the number of visible slides */
getNumberOfVisibleSlides :
USE ARG xDrawPages
count = 0
pagecount=xDrawPages~{%see com.sun.star.container.XIndexAccess%XIndexAccess}~getCount
DO i = 0 TO pagecount - 1
xDrawPage = xDrawPages~getByIndex(i)~{%see com.sun.star.drawing.XDrawPage%XDrawPage}
xProps = xDrawPage~{%see com.sun.star.beans.XPropertySet%XPropertySet}
IF(xProps~getPropertyValue("Visible") == 1) THEN
count = count + 1
END
return count
/* Returns the index of the first visible slide */
getFirstVisibleSlide :
USE ARG xDrawPages
index = -1
pagecount=xDrawPages~{%see com.sun.star.container.XIndexAccess%XIndexAccess}~getCount
DO i = 0 TO pagecount - 1
xDrawPage = xDrawPages~getByIndex(i)~{%see com.sun.star.drawing.XDrawPage%XDrawPage}
xProps = xDrawPage~{%see com.sun.star.beans.XPropertySet%XPropertySet}
IF(xProps~getPropertyValue("Visible") == 1) THEN
return i
END
return index
::requires UNO.CLS -- load UNO support for OpenOffice.org
/* routine for positioning and resizing a shape */
::routine setSizeAndPosition
use arg shape, width, height, posX, posY
shape~setSize(-
.bsf~new("{%see com.sun.star.awt.Size}", width, height))
shape~setPosition(.bsf~new("{%see com.sun.star.awt.Point}", posX, posY))
/* routine for removing selection*/
::routine removeSelection
use arg oDoc
model= oDoc~{%see com.sun.star.frame.XModel%XModel}
controller = model~getCurrentController()
selectionController = controller~{%see com.sun.star.view.XSelectionSupplier%XSelectionSupplier}
selected = selectionController~getSelection()
selectionController~select(.nil)