clock progress remaining slides Dominik Gundacker How to add a clock that displays the remaining slides of a presentation

The clock will turn more red as the progress advances in the presentation

/* Macro, which generates a clock that counts down to the end of the presentation */ /* 04_clock.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 /* initialize all variables (height, width, etc.) */ 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 - 2000 shapeX = 500 shapeY = height - 1250 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 step = trunc((36000) / (pagecount - 2)) /* start at 12 o clock */ endAngle = 9000 startAngle = 9000 stopAngle = -27000 /* start with white */ colorValue = 16777215 stepRed = trunc( 255 / (pagecount - 2)) circleKinds = bsf.wrapStaticFields("{%see com.sun.star.drawing.CircleKind}") pagecount=xDrawPages~{%see com.sun.star.container.XIndexAccess%XIndexAccess}~getCount CALL getFirstVisibleSlide xDrawPages startIndex = result + 1 DO i = 0 TO pagecount - 1 xDrawPage = xDrawPages~getByIndex(i)~{%see com.sun.star.drawing.XDrawPage%XDrawPage} /* remove existing clocks, 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() == "clock_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 background shape of the clock */ clockBackground = xImpressFactory~createInstance(- "{%see com.sun.star.drawing.EllipseShape}") clockBackground = clockBackground~{%see com.sun.star.drawing.XShape%XShape} CALL setSizeAndPosition clockBackground, 1500, 1500,- trunc(width / 2) - 750, height - 1800 clockBackgroundProps=clockBackground~{%see com.sun.star.beans.XPropertySet%XPropertySet} clockBackgroundProps~setPropertyValue("CircleKind", circleKinds~FULL) clockBackgroundProps~setPropertyValue("FillColor",- box("int", "FFFFFF"x ~c2d)) xDrawPage~add(clockBackground) clock = xImpressFactory~createInstance(- "{%see com.sun.star.drawing.EllipseShape}") clock = clock~{%see com.sun.star.drawing.XShape%XShape} CALL setSizeAndPosition clock, 1500, 1500,- trunc(width / 2) - 750, height - 1800 xDrawPage~add(clock) clockProps=clock~{%see com.sun.star.beans.XPropertySet%XPropertySet} /* create the group */ shapeGroup = xMcf~createInstanceWithContext(- "{%see com.sun.star.drawing.ShapeCollection}", xContext) shapeGroup = shapeGroup~{%see com.sun.star.drawing.XShapes%XShapes} shapeGroup~add(clockBackground) shapeGroup~add(clock) xShapeGrouper = xDrawPage~{%see com.sun.star.drawing.XShapeGrouper%XShapeGrouper} xShapeGroup = xShapeGrouper~group(shapeGroup) name = xShapeGroup~{%see com.sun.star.container.XNamed%XNamed} name~setName("clock_group") IF(startAngle <> stopAngle) THEN DO /* set the start and the end angle for the section */ clockProps~setPropertyValue("CircleKind", circleKinds~SECTION) clockProps~setPropertyValue("CircleStartAngle", box("int", startAngle)) clockProps~setPropertyValue("CircleEndAngle", box("int", endAngle)) startAngle = startAngle - step /* adjust color */ color = box("int", colorValue) colorValue = colorValue - (stepRed * 256) - stepRed END ELSE color = box("int", "FF0000"x ~c2d) clockProps~setPropertyValue("FillColor", color) END EXIT 0 /* 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)