Navigating
Cursors
The text model cursor allows for free navigation over the model by character, words, sentences, or paragraphs. There can be several model cursors at the same time. Model cursor creation, movement and usage is discussed in the section Word Processing . The text model cursors are com.sun.star.text.TextCursor services that are based on the interface com.sun.star.text.XTextCursor, which is based on com.sun.star.text.XTextRange.
The text view cursor enables the user to travel over the document in the view by character, line, screen page and document page. There is only one text view cursor. Certain information about the current layout, such as the number of lines and page number must be retrieved at the view cursor. The chapter Text Document Controller below discusses the view cursor in detail. The text view cursor is a com.sun.star.text.TextViewCursor service that includes com.sun.star.text.TextLayoutCursor.
Locating Text Contents
The text document model has suppliers that yield all text contents in a document as collections. To find a particular text content, such as bookmarks or text fields, use the appropriate supplier interface. The following supplier interfaces are available at the model:
(table missing!!!!)
You can work with text content directly, set properties and use its interfaces, or find out where it is and do an action at the text content location in the text. To find out where a text content is located call the getAnchor()
method at the interface com.sun.star.text.XTextContent, which every text content must support.
In addition, text contents located at the current text cursor position or the content where the cursor is currently located are provided in the PropertySet
of the cursor. The corresponding cursor properties are:
-
DocumentIndexMark
-
TextField
-
ReferenceMark
-
Footnote
-
Endnote
-
DocumentIndex
-
TextTable
-
TextFrame
-
Cell
-
TextSection
Search and Replace
The writer model supports the interface com.sun.star.util.XReplaceable that inherits from the interface com.sun.star.util.XSearchable for searching and replacing in text. It contains the following methods:
com::sun::star::util::XSearchDescriptor createSearchDescriptor() com::sun::star::util::XReplaceDescriptor createReplaceDescriptor() com::sun::star::uno::XInterface findFirst( [in] com::sun::star::util::XSearchDescriptor xDesc) com::sun::star::uno::XInterface findNext( [in] com::sun::star::uno::XInterface xStartAt, [in] com::sun::star::util::XSearchDescriptor xDesc) com::sun::star::container::XIndexAccess findAll( [in] com::sun::star::util::XSearchDescriptor xDesc) long replaceAll( [in] com::sun::star::util::XSearchDescriptor xDesc)
To search or replace text, first create a descriptor service using createSearchDescriptor()
or createReplaceDescriptor()
. You receive a service that supports the interface com.sun.star.util.XPropertyReplace with methods to describe what you are searching for, what you want to replace with and what attributes you are looking for. It is described in detail below.
Pass in this descriptor to the methods findFirst()
, findNext()
, findAll()
or replaceAll()
.
The methods findFirst()
and findNext()
return a com.sun.star.uno.XInterface pointing to an object that contains the found item. If the search is not successful, a null reference to an XInterface
is returned, that is, if you try to query other interfaces from it, null is returned. The method findAll()
returns a com.sun.star.container.XIndexAccess containing one or more com.sun.star.uno.XInterface pointing to the found text ranges or if they failed an empty interface. The method replaceAll()
returns the number of replaced occurrences only.
The interface com.sun.star.util.XPropertyReplace is required to describe your search. It is a powerful interface and inherits from XReplaceDescriptor
, XSearchDescriptor
and XPropertySet
.
The target of your search is described by a string containing a search text or a style name using setSearchString()
. Correspondingly, provide the text string or style name that should replace the found occurrence of the search target to the XReplaceDescriptor
using setReplaceString()
. Refine the search mode through the properties included in the service com.sun.star.util.SearchDescriptor: