Hello Bernard,

On Friday 27 March 2009, 09:50, Bernard Marcelly wrote:
> Hi Ariel,
>
> Message de Ariel Constenla-Haile  date 2009-03-27 11:58 :
> > look at the code I attached to my answer in [email protected]
> > (IIRC I CCed this list and you, so you'll get the fileon your mail).
> >
> > Grouping with a css.drawing.GroupShape seems not to work in Wirter (may
> > be you can submit an issue with your demo attached), so better try
> > grouping with a css.drawing.ShapeCollection.
> >
> > Regards
>
> The code example for Writer in the Developer's Guide Wiki should be
> completely changed.
> <http://wiki.services.openoffice.org/wiki/Documentation/DevGuide/Text/Drawi
>ng_Shapes> Could you replace it by the Writer part of your demo code ?

the Dev's Guide TextDocument example has several errors (try for example the 
TextSection demo). The bellow [*] is my version of the DrawPageExample() (I'll 
try to commit this weekend all text, drawing and spreadsheet examples).

I guess I could change that wiki page now, but may be it's better to finish the 
examples rework and QA first. At the end, some good soul will have to read 
every wiki page and make the respective changes to adapt the examples.


Regards

*********************************************************************

[*]
    /** 
     * This method demonstrates how to create and manipulate shapes, 
     * and how to access the draw page of the document to insert shapes
     */
    protected void DrawPageExample() {
        try {
            // Go to the start of the document
            mxDocCursor.gotoStart(false);
            mxDocText.insertControlCharacter(mxDocCursor,
                    ControlCharacter.PARAGRAPH_BREAK, false);

            // Get the XParagraphCursor interface of our document cursor
            XParagraphCursor xParaCursor = 
                    (XParagraphCursor) UnoRuntime.queryInterface(
                        XParagraphCursor.class, mxDocCursor);

            // Position the cursor in the 2nd paragraph
            xParaCursor.gotoPreviousParagraph(false);

            // Create a RectangleShape using the document factory
            XShape xRect = (XShape) UnoRuntime.queryInterface(
                    XShape.class, mxDocFactory.createInstance(
                    "com.sun.star.drawing.RectangleShape"));

            // Create an EllipseShape using the document factory
            XShape xEllipse = (XShape) UnoRuntime.queryInterface(
                    XShape.class, mxDocFactory.createInstance(
                    "com.sun.star.drawing.EllipseShape"));

            // Set the size of both the ellipse and the rectangle
            Size aSize = new Size();
            aSize.Height = 4000;
            aSize.Width = 10000;            
            xRect.setSize(aSize);
            
            aSize.Height = 3000;
            aSize.Width = 6000;
            xEllipse.setSize(aSize);

            // Set the position of the Rectangle to the right of the ellipse
            Point aPoint = new Point();
            aPoint.X = 6100;
            aPoint.Y = 0;
            xRect.setPosition(aPoint);

            // Get the XPropertySet interfaces of both shapes
            XPropertySet xRectProps = (XPropertySet) 
UnoRuntime.queryInterface(
                    XPropertySet.class, xRect);
            XPropertySet xEllipseProps = (XPropertySet) 
UnoRuntime.queryInterface(
                    XPropertySet.class, xEllipse);

            // And set the AnchorTypes of both shapes to 'AT_PARAGRAPH'
            // Grouping of objects in text documents works 
            // ONLY if none of the objects has an anchor of type AS_CHARACTER
            xRectProps.setPropertyValue(
                    "AnchorType", TextContentAnchorType.AT_PARAGRAPH);
            xEllipseProps.setPropertyValue(
                    "AnchorType", TextContentAnchorType.AT_PARAGRAPH);
            
            // We could access the XDrawPageSupplier interface of the document
            XDrawPageSupplier xDrawPageSupplier = 
                    (XDrawPageSupplier) UnoRuntime.queryInterface(
                        XDrawPageSupplier.class, mxDoc);

            XDrawPage xDrawPage = xDrawPageSupplier.getDrawPage();
            // and add the shapes to the DrawPage
            /*xDrawPage.add(xRect);
            xDrawPage.add(xEllipse);*/

            //...but in Writer it is better to insert the Shapes as 
TextContent
            // for better layout control
            XTextContent xRectTextContent = (XTextContent) 
UnoRuntime.queryInterface(
                    XTextContent.class, xRect);
            XTextContent xEllipseTextContent = (XTextContent) 
UnoRuntime.queryInterface(
                    XTextContent.class, xEllipse);

            mxDocCursor.getText().insertTextContent(mxDocCursor, 
xRectTextContent, false);
            mxDocCursor.getText().insertTextContent(mxDocCursor, 
xEllipseTextContent, false);
            
            /*
             * The example below creates a group using the 
             * com.sun.star.drawing.XShapeGrouper interface. 
             * For this purpose, the shapes that are to be grouped 
             * have to be added to a com.sun.star.drawing.ShapeCollection
             * that is created by the XMultiComponentFactory of the *global* 
             * service manager, NOT the document's XMultiServiceFactory.
             * It is a container of shapes that is accessed using the 
interface
             * com.sun.star.drawing.XShapes.
             */
            XShapes xShapesCollection = (XShapes) UnoRuntime.queryInterface(
                    XShapes.class, 
                    getMultiComponentFactory().createInstanceWithContext(
                        "com.sun.star.drawing.ShapeCollection", m_xContext));
            xShapesCollection.add(xRect);
            xShapesCollection.add(xEllipse);
            
            XShapeGrouper xShapeGrouper = 
                    (XShapeGrouper) UnoRuntime.queryInterface(
                        XShapeGrouper.class, xDrawPage);
            XShapeGroup xShapeGroup = xShapeGrouper.group(xShapesCollection);
            
            XPropertySet xShapeGroupProps = (XPropertySet) 
UnoRuntime.queryInterface(
                    XPropertySet.class, xShapeGroup);
            xShapeGroupProps.setPropertyValue("Surround", WrapTextMode.NONE);
            xShapeGroupProps.setPropertyValue("BottomMargin", new 
Integer(500));
            xShapeGroupProps.setPropertyValue("TopMargin", new Integer(500));
            
            //=================================================================
            /* 
             * It is also possible to create GroupShapes directly
             * WITHOUT using the XDrawPage' XShapeGrouper interface.
             * The following code demonstrates the creation of a 
             * com.sun.star.drawing.GroupShape that takes up other shapes.
             *
             * NOTE: in the current OOo version, this method does not layout
             * the shapes properly

            // create a group shape first
            XShape xGroupShape = (XShape) UnoRuntime.queryInterface(
                    XShape.class, mxDocFactory.createInstance(
                        "com.sun.star.drawing.GroupShape"));
            
            // before it is possible to insert shapes inside this group,
            // the group shape must have been added to the draw page
            // ... or in Writer inserted as TextContent
            XTextContent xGroupShapeTextContent = (XTextContent) 
UnoRuntime.queryInterface(
                    XTextContent.class, xGroupShape);

            mxDocCursor.getText().insertTextContent(mxDocCursor, 
xGroupShapeTextContent, false);

            // query for the XShapes interface, which will take our new shapes
            XShapes xShapesGroup = (XShapes)UnoRuntime.queryInterface(
                    XShapes.class, xGroupShape);
            
            // new shapes can be inserted into the group shape collection 
DIRECTLY
            // NO need to add them first to the draw page
            xShapesGroup.add( xRect );
            xShapesGroup.add( xEllipse );
            */
            
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

-- 
Ariel Constenla-Haile
La Plata, Argentina


"Aus der Kriegsschule des Lebens
                - Was mich nicht umbringt,
        macht mich härter."
                Nietzsche Götzendämmerung, Sprüche und Pfeile, 8.

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to