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.

frame objects are set to the starting values required.<br />

More Than Just Text<br />

The interaction between the AnchorType (from the TextContent Service) and VertOrient (from the<br />

BaseFrameProperties Service) properties should be noted here. AnchorType receives the AS_CHARACTER<br />

value. The text frame is therefore inserted directly in the text flow and behaves like a character. It can, for<br />

example, be moved into the next line if a line break occurs. The LINE_TOP value of the VertOrient property<br />

ensures that the upper edge of the text frame is at the same height as the upper edge of the character.<br />

Once initialization is complete, the text frame is finally inserted in the text document using a call from<br />

insertTextContent.<br />

To edit the content of a text frame, the user uses the TextCursor, which has already been mentioned numerous<br />

times and is also available for text frames.<br />

Dim Doc As Object<br />

Dim TextTables As Object<br />

Dim Cursor As Object<br />

Dim Frame As Object<br />

Dim FrameCursor As Object<br />

Doc = ThisComponent<br />

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

Frame = Doc.createInstance("com.sun.star.text.TextFrame")<br />

Frame.Width = 3000<br />

Frame.Height = 1000<br />

Doc.Text.insertTextContent(Cursor, Frame, False)<br />

FrameCursor = Frame.createTextCursor()<br />

FrameCursor.charWeight = com.sun.star.awt.FontWeight.BOLD<br />

FrameCursor.paraAdjust = com.sun.star.style.ParagraphAdjust.CENTER<br />

FrameCursor.String = "This is a small Test!"<br />

The example creates a text frame, inserts this in the current document and opens a TextCursor for the text<br />

frame. This cursor is used to set the frame font to bold type and to set the paragraph orientation to centered. The<br />

text frame is finally assigned the “This is a small test!” string.<br />

Text Fields<br />

Text fields are TextContent objects because they provide additional logic extending beyond pure text. Text<br />

fields can be inserted in a text document using the same methods as those used for other TextContent objects:<br />

Dim Doc As Object<br />

Dim DateTimeField As Object<br />

Dim Cursor As Object<br />

Doc = ThisComponent<br />

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

DateTimeField = Doc.createInstance("com.sun.star.text.textfield.DateTime")<br />

DateTimeField.IsFixed = False<br />

DateTimeField.IsDate = True<br />

Doc.Text.insertTextContent(Cursor, DateTimeField, False)<br />

The example inserts a text field with the current date at the start of the current text document. The True value of<br />

the IsDate property results in only the date and not time being displayed. The False value for IsFixed ensures<br />

that the date is automatically updated when the document is opened.<br />

Note – VBA : While the type of a field in VBA is specified by a parameter of the Document.Fields.Add<br />

method, the name of the service that is responsible for the field type in question defines it in <strong>OpenOffice</strong>.<strong>org</strong><br />

Basic.<br />

Note – StarOffice 5 : In the past, text fields were accessed using a whole range of methods that<br />

<strong>OpenOffice</strong>.<strong>org</strong> made available in the old Selection object (for example InsertField, DeleteUserField,<br />

SetCurField).<br />

In <strong>OpenOffice</strong>.<strong>org</strong>, the fields are administered using an object-oriented concept. To create a text field, a text field<br />

Chapter 6 · Text Documents 87

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

Saved successfully!

Ooh no, something went wrong!