progress bar progress Dominik Gundacker How to add a progress bar to each slide of a presentation /* Macro, which generates a progress bar at the bottom of each slide */ /* 01_progressbar.rex */ xScriptContext=uno.getScriptContext() -- get the xScriptContext object oDoc=xScriptContext~getDocument -- get the document service (an XModel object) printable = oDoc~{%see com.sun.star.view.XPrintable%XPrintable} /* 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") shapeWidthBorder = width - 1000 shapeHeight = 750 shapeX = 500 shapeY = height - 1250 IF pagecount == 1 THEN DO .bsf.dialog~messageBox("This presentation has only one slide. "- "There is no need for a progressbar!", "ERROR", "error") EXIT 0 END CALL getNumberOfVisibleSlides xDrawPages pagecount=result step = trunc((width - 1000) / (pagecount - 1)) pagecount=xDrawPages~{%see com.sun.star.container.XIndexAccess%XIndexAccess}~getCount currentStatus = step 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 bars, 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() == "progressbar_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 border of the bar shape */ barBorder = xImpressFactory~createInstance(- "{%see com.sun.star.drawing.RectangleShape}") barBorder = barBorder~{%see com.sun.star.drawing.XShape%XShape} CALL setSizeAndPosition barBorder, shapeWidthBorder, shapeHeight,- shapeX, shapeY xDrawPage~add(barBorder) barBorderProps=barBorder~{%see com.sun.star.beans.XPropertySet%XPropertySet} fillStyles = bsf.wrapStaticFields("{%see com.sun.star.drawing.FillStyle}") barBorderProps~setPropertyValue("FillStyle", fillStyles~none) CALL setShadowAndFormat(barBorderProps) /* creating and positioning of the statusbar shape */ statusBarShape = xImpressFactory~createInstance(- "{%see com.sun.star.drawing.RectangleShape}") statusBarShape = statusBarShape~{%see com.sun.star.drawing.XShape%XShape} CALL setSizeAndPosition statusBarShape, currentStatus, shapeHeight,- shapeX, shapeY currentStatus = currentStatus + step xDrawPage~add(statusBarShape) /* changing the colors of the filling */ statusBarShapeProps=statusBarShape~{%see com.sun.star.beans.XPropertySet%XPropertySet} statusBarShapeProps~setPropertyValue("FillStyle",fillStyles~gradient) CALL CreateGradientObject statusBarShapeProps~setPropertyValue("FillGradient", result) statusBarShapeProps~setPropertyValue("LineStyle",- bsf.getConstant("{%see com.sun.star.drawing.LineStyle}", "NONE")) CALL setShadowAndFormat(statusBarShapeProps) /* create the group */ shapeGroup = xMcf~createInstanceWithContext(- "{%see com.sun.star.drawing.ShapeCollection}", xContext) shapeGroup = shapeGroup~{%see com.sun.star.drawing.XShapes%XShapes} shapeGroup~add(barBorder) shapeGroup~add(statusBarShape) xShapeGrouper = xDrawPage~{%see com.sun.star.drawing.XShapeGrouper%XShapeGrouper} xShapeGroup = xShapeGrouper~group(shapeGroup) name = xShapeGroup~{%see com.sun.star.container.XNamed%XNamed} name~setName("progressbar_group") END EXIT 0 /* Function for creating the GradientObject */ CreateGradientObject : gradient = .bsf~new("{%see com.sun.star.awt.Gradient}") gradient~Style = bsf.getConstant("{%see com.sun.star.awt.GradientStyle}", "LINEAR") gradient~StartColor = 9282303 gradient~EndColor = 0 gradient~Angle = 120 gradient~Border = 0 gradient~XOffset = 0 gradient~YOffset = 0 gradient~StartIntensity = 100 gradient~EndIntensity = 100 gradient~StepCount = 10 return gradient /* 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 setting the shadow*/ ::routine setShadowAndFormat use arg props props~setPropertyValue("CornerRadius", box("int", 300)) props~setPropertyValue("Shadow", box("boolean", .true)) props~setPropertyValue("ShadowXDistance", box("int", 150)) props~setPropertyValue("ShadowYDistance", box("int", 150)) /* 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)