Difference between revisions of "Documentation/DevGuide/Text/Navigating"

From Apache OpenOffice Wiki
Jump to: navigation, search
(Page was somehow broken. Trying to restore it piece by piece.)
(... restoring ...)
Line 17: Line 17:
 
<!--<idltopic>com.sun.star.text.XTextContent</idltopic>-->
 
<!--<idltopic>com.sun.star.text.XTextContent</idltopic>-->
 
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:
 
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 <code>getAnchor()</code> method at the interface <idl>com.sun.star.text.XTextContent</idl>, 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 <code>PropertySet</code> of the cursor. The corresponding cursor properties are:
 +
 +
* <code>DocumentIndexMark</code>
 +
* <code>TextField</code>
 +
* <code>ReferenceMark</code>
 +
* <code>Footnote</code>
 +
* <code>Endnote</code>
 +
* <code>DocumentIndex</code>
 +
* <code>TextTable</code>
 +
* <code>TextFrame</code>
 +
* <code>Cell</code>
 +
* <code>TextSection</code>
 +
 +
=== Search and Replace ===
 +
 +
<!--<idltopic>com.sun.star.util.XSearchable;com.sun.star.util.XReplaceable;com.sun.star.util.SearchDescriptor</idltopic>-->
 +
The writer model supports the interface <idl>com.sun.star.util.XReplaceable</idl> that inherits from the interface <idl>com.sun.star.util.XSearchable</idl> 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 <code>createSearchDescriptor()</code> or <code>createReplaceDescriptor()</code>. You receive a service that supports the interface <idl>com.sun.star.util.XPropertyReplace</idl> 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 <code>findFirst()</code>, <code>findNext()</code>, <code>findAll()</code> or <code>replaceAll()</code>.
 +
 +
The methods <code>findFirst()</code> and <code>findNext()</code> return a <idl>com.sun.star.uno.XInterface</idl> pointing to an object that contains the found item. If the search is not successful, a null reference to an <code>XInterface</code> is returned, that is, if you try to query other interfaces from it, null is returned. The method <code>findAll()</code> returns a <idl>com.sun.star.container.XIndexAccess</idl> containing one or more <idl>com.sun.star.uno.XInterface</idl> pointing to the found text ranges or if they failed an empty interface. The method <code>replaceAll()</code> returns the number of replaced occurrences only.
 +
 +
[[Image:XPropertyReplace.png|none|thumb|400px|XPropertyReplace]]
 +
 +
The interface <idl>com.sun.star.util.XPropertyReplace</idl> is required to describe your search. It is a powerful interface and inherits from <code>XReplaceDescriptor</code>, <code>XSearchDescriptor</code> and <code>XPropertySet</code>.
 +
 +
The target of your search is described by a string containing a search text or a style name using <code>setSearchString()</code>. Correspondingly, provide the text string or style name that should replace the found occurrence of the search target to the <code>XReplaceDescriptor</code> using <code>setReplaceString()</code>. Refine the search mode through the properties included in the service <idl>com.sun.star.util.SearchDescriptor</idl>:

Revision as of 14:10, 17 October 2019



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.

XPropertyReplace

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:

Personal tools
In other languages