21.08.2013 Views

OpenOffice.org BASIC Guide.pdf - OpenOffice.org wiki

OpenOffice.org BASIC Guide.pdf - OpenOffice.org wiki

OpenOffice.org BASIC Guide.pdf - OpenOffice.org wiki

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Editing Text Documents 98<br />

Terminology differs from that used in VBA: In terms of scope of function, the Range object from VBA<br />

can be compared with the TextCursor object in <strong>OpenOffice</strong>.<strong>org</strong> and not — as the name possibly<br />

suggests — with the Range object in <strong>OpenOffice</strong>.<strong>org</strong>.<br />

The TextCursor object in <strong>OpenOffice</strong>.<strong>org</strong>, for example, provides methods for navigating and<br />

changing text which are included in the Range object in VBA (for example, MoveStart,<br />

MoveEnd, InsertBefore, InsertAfter). The corresponding counterparts of the TextCursor<br />

object in <strong>OpenOffice</strong>.<strong>org</strong> are described in the following sections.<br />

Navigating within a Text<br />

The TextCursor object in <strong>OpenOffice</strong>.<strong>org</strong> Basic acts independently from the visible cursor in<br />

a text document. A program-controlled position change of a TextCursor object has no<br />

impact whatsoever on the visible cursor. Several TextCursor objects can even be opened for<br />

the same document and used in various positions, which are independent of one another.<br />

A TextCursor object is created using the createTextCursor call:<br />

Dim Doc As Object<br />

Dim Cursor As Object<br />

Doc = StarDesktop.CurrentComponent<br />

Cursor = Doc.Text.createTextCursor()<br />

The Cursor object created in this way supports the com.sun.star.text.TextCursor service,<br />

which in turn provides a whole range of methods for navigating within text documents. The<br />

following example first moves the TextCursor ten characters to the left and then three<br />

characters to the right:<br />

Cursor.goLeft(10, False)<br />

Cursor.goRight(3, False)<br />

A TextCursor can highlight a complete area. This can be compared with highlighting a point<br />

in the text using the mouse. The False parameter in the previous function call specifies<br />

whether the area passed over with the cursor movement is highlighted. For example, the<br />

TextCursor in the following example<br />

Cursor.goLeft(10, False)<br />

Cursor.goRight(3, True)<br />

first moves ten characters to the right without highlighting, and then moves back three<br />

characters and highlights this. The area highlighted by the TextCursor therefore begins<br />

after the seventh character in the text and ends after the tenth character.<br />

Here are the central methods that the

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

Saved successfully!

Ooh no, something went wrong!