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.

Doc = ThisComponent<br />

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

Page.Name = "First"<br />

Creating and Deleting Pages<br />

The Structure of Drawings<br />

The DrawPages container of a drawing document is also used to create and delete individual pages. The<br />

following example uses the hasByName method to check if a page called MyPage exists. If it does, the method<br />

determines a corresponding object reference by using the getByName method and then saves the reference in a<br />

variable in Page. If the corresponding page does not exist, it is created and inserted in the drawing document by<br />

the insertNewByIndex method. The argument of the method is the position, counted from 0, of the existing<br />

page after which the new page will be inserted. Then the new page is renamed.<br />

Dim Doc As Object<br />

Dim Page As Object<br />

Doc = ThisComponent<br />

If Doc.Drawpages.hasByName("MyPage") Then<br />

Page = Doc.Drawpages.getByName("MyPage")<br />

Else<br />

Page = Doc.Drawpages.insertNewByIndex(2)<br />

Page.Name = "MyPage" ' you should always rename a new page<br />

' MyPage is the fourth page of the document, i.e. position 3<br />

End If<br />

The hasByName and getByName methods are obtained from the com.sun.star.container.XNameAccess interface.<br />

The insertNewByIndex method is obtained from the com.sun.star.drawing.XDrawPages interface. The same<br />

interface provides the method remove to delete (remove) a page:<br />

Dim Doc As Object<br />

Doc = ThisComponent<br />

If Doc.Drawpages.hasByName("MyPage") Then<br />

Page = Doc.Drawpages.getByName("MyPage")<br />

Doc.Drawpages.remove(Page)<br />

End If<br />

Duplicating a Page<br />

A copy of a given page is created, not from the DrawPages container, but from the drawing document itself with<br />

the method duplicate. The copy is created at the next position after the original page, with a default name.<br />

Dim Doc As Object<br />

Dim Page As Object, ClonedPage As Object<br />

Doc = ThisComponent<br />

Page = Doc.Drawpages.getByName("MyPage")<br />

ClonedPage = Doc.duplicate(Page)<br />

ClonedPage.Name = "MyCopy" ' you should always rename a new page<br />

Moving a Page<br />

The API does not provide a method to change the position of a page inside a drawing document.<br />

Elementary Properties of Drawing Objects<br />

Drawing objects include shapes (rectangles, circles, and so on), lines, and text objects. All of these share a number<br />

of common features and support the com.sun.star.drawing.Shape service. This service defines the Size<br />

and Position properties of a drawing object.<br />

<strong>OpenOffice</strong>.<strong>org</strong> Basic also offers several other services through which you can modify such properties, as<br />

formatting or apply fills. The formatting options that are available depend on the type of drawing object.<br />

Chapter 8 · Drawings and Presentations 113

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

Saved successfully!

Ooh no, something went wrong!