21.08.2013 Views

OpenOffice.org BASIC Guide - OpenOffice.org wiki

OpenOffice.org BASIC Guide - OpenOffice.org wiki

OpenOffice.org BASIC Guide - OpenOffice.org wiki

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Editing Drawing Objects<br />

Dim Size As New com.sun.star.awt.Size<br />

Dim NewPos As New com.sun.star.awt.Point<br />

Dim Height As Long<br />

Dim Width As Long<br />

Doc = ThisComponent<br />

Page = Doc.DrawPages(0)<br />

Point.x = 3000<br />

Point.y = 3000<br />

Size.Width = 3000<br />

Size.Height = 3000<br />

' create square drawing element<br />

Square = Doc.createInstance("com.sun.star.drawing.RectangleShape")<br />

Square.Size = Size<br />

Square.Position = Point<br />

Square.FillColor = RGB(255,128,128)<br />

Page.add(Square)<br />

' create circle drawing element<br />

Circle = Doc.createInstance("com.sun.star.drawing.EllipseShape")<br />

Circle.Size = Size<br />

Circle.Position = Point<br />

Circle.FillColor = RGB(255,128,128)<br />

Circle.FillColor = RGB(0,255,0)<br />

Page.add(Circle)<br />

' combine square and circle drawing elements<br />

Shapes = createUnoService("com.sun.star.drawing.ShapeCollection")<br />

Shapes.add(Square)<br />

Shapes.add(Circle)<br />

Group = Page.group(Shapes)<br />

' centre combined drawing elements<br />

Height = Page.Height<br />

Width = Page.Width<br />

NewPos.X = Width / 2<br />

NewPos.Y = Height / 2<br />

Height = Group.Size.Height<br />

Width = Group.Size.Width<br />

NewPos.X = NewPos.X - Width / 2<br />

NewPos.Y = NewPos.Y - Height / 2<br />

Group.Position = NewPos<br />

This code creates a rectangle and a circle and inserts them into a page. It then creates an object that supports the<br />

com.sun.star.drawing.ShapeCollection service and uses the Add method to add the rectangle and the circle to this<br />

object. The ShapeCollection is added to the page using the Group method and returns the actual Group object<br />

that can be edited like an individual Shape.<br />

If you want to format the individual objects of a group, apply the formatting before you add them to the group.<br />

You cannot modify the objects once they are in the group.<br />

Rotating and Shearing Drawing Objects<br />

All of the drawing objects that are described in the previous sections can also be rotated and sheared using the<br />

com.sun.star.drawing.RotationDescriptor service.<br />

The service provides the following properties:<br />

RotateAngle (Long)<br />

rotary angle in hundredths of a degree<br />

ShearAngle (Long)<br />

shear angle in hundredths of a degree<br />

The following example creates a rectangle and rotates it by 30 degrees using the RotateAngle property:<br />

Dim Doc As Object<br />

Dim Page As Object<br />

Dim RectangleShape As Object<br />

Dim Point As New com.sun.star.awt.Point<br />

Dim Size As New com.sun.star.awt.Size<br />

126 <strong>OpenOffice</strong>.<strong>org</strong> 3.2 <strong>BASIC</strong> <strong>Guide</strong> · March 2010

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!