Download StarOffice™ Programmer`s Tutorial

Transcript
would start a new paragraph at the end of the current textRange. Again, you must
move the range beyond the newly inserted text with c.collapseToEnd( ), if you
want to insert text into the new paragraph.
Similarly, to insert a line break, you’d use
oText.insertControlCharacter(oCursor,_
com.sun.star.text.ControlCharacter.LINE_BREAK,FALSE)
The following control characters are defined:
PARAGRAPH_BREAK: A new paragraph
LINE_BREAK: Start a new line in the current paragraph.
HARD_HYPHEN: A fixed hyphenation character that hyphenation cannot remove.
SOFT_HYPHEN: Indicating a possible hyphenation point, visible in the document
only if actual hyphenation occurs at this point.
HARD_SPACE: A fixed space that can neither be stretched nor compressed by
justification.
The control characters are actually constants that can be inserted in your program
code by prepending com.sun.star.text.ControlCharacter. to the name of
the character to insert, as shown above in the short examples. The following code
segment illustrates the use of all control characters.
oCursor = oText.createTextCursor()
oCursor.gotoStart(FALSE)
oText.insertString(oCursor,"My first piece of Text",FALSE)
oText.insertControlCharacter(oCursor,_
com.sun.star.text.ControlCharacter.PARAGRAPH_BREAK,FALSE)
oText.insertString(oCursor,_
"second Line In first paragraph", FALSE)
oText.insertControlCharacter(oCursor,_
com.sun.star.text.ControlCharacter.LINE_BREAK,FALSE)
oText.insertString(oCursor,"Second paragraph", FALSE)
oText.insertControlCharacter(oCursor,_
com.sun.star.text.ControlCharacter.PARAGRAPH_BREAK, FALSE)
oText.insertString(oCursor,_
"First Line In 3rd paragraph,", FALSE)
oText.insertString(oCursor," a fixed hyphen", FALSE)
oText.insertControlCharacter(oCursor,_
com.sun.star.text.ControlCharacter.HARD_HYPHEN,FALSE)
oText.insertString(oCursor,", a soft hyphen,", FALSE)
oText.insertControlCharacter(oCursor,_
com.sun.star.text.ControlCharacter.SOFT_HYPHEN,FALSE)
oText.insertString(oCursor," And a fixed space", FALSE)
oText.insertControlCharacter(oCursor,_
com.sun.star.text.ControlCharacter.HARD_SPACE,FALSE)
oText.insertString(oCursor,"between two words", FALSE)
oText.insertControlCharacter(oCursor, _
com.sun.star.text.ControlCharacter.PARAGRAPH_BREAK,FALSE)
oText.insertString(oCursor,"New page starts here",FALSE)
oCursor.gotoStartOfParagraph(TRUE)
oCursor.breakType = com.sun.star.style.BreakType.PAGE_BEFORE
54
StarOffice Programmer’s Tutorial ♦ May 2000