UNO Interface


An interface defines how something interacts with its environment. For example, an automobile has multiple interfaces, including an interface for turning the headlights on and off and another interface for starting the car. A UNO interface resembles a group of subroutine and function declarations; arguments and return types are specified along with functionality.

You can use the interface to retrieve data from an object, set data in an object, or tell an object to do something. The interface indicates how an object can be used, but it says nothing about the implementation. For example, if an interface contains the method GetHeight that returns an integer, it's natural to assume that the object contains an integer property named Height. It's possible, however, that the height is derived or calculated from other properties. The interface does not specify how the height is obtained, just that it is available. A UNO structure, however, contains properties that are accessed directly; the internal representation is not hidden.

Tip  

All UNO interface names start with the capital letter X.

UNO interface names start with the capital letter X, which makes it easy to recognize an interface. Hungarian notation also makes it easier to identify an interface when you see one. For example, the interface com.sun.star.text.XTextRange specifies a section of text with both a start and end position. Objects that support the XTextRange interface are also used to identify an object's position in the text. The start and end positions may be the same. The XTextRange interface defines the methods in Table 2 .

Table 2: Methods defined by the com.sun.star.text.XTextRange interface.

Method

Description

getText()

Return the com.sun.star.text.XText interface that contains this XTextRange.

getStart()

Return a com.sun.star.text.XTextRange that references only the start position.

getEnd()

Return a com.sun.star.text.XTextRange that references only the end position.

getString()

Return a string that includes the text inside this text range.

setString(str)

Set the string for this text range, replacing existing text and clearing all styles.

Tip  

A UNO interface may be derived from another. Every UNO interface is required to be derived from com.sun.star.uno.XInterface.

A new UNO interface may be derived from another. This is not something that you do, but rather it's something that is done by the designer of the interface. The derived interface supports all of the methods defined in the interface from which it is derived. For example, the com.sun.star.text.XTextCursor extends the XTextRange interface to allow it to extend the selected range. The XTextRange interface supplies no method to change a text range by itself. Any object that implements the XTextCursor interface, however, supports the methods in Table 2 and the new methods introduced by the XTextCursor interface. The methods defined by the interfaces XTextCursor and XTextRange are used to manipulate OpenOffice.org Writer documents.




OpenOffice.org Macros Explained
OpenOffice.org Macros Explained
ISBN: 1930919514
EAN: 2147483647
Year: 2004
Pages: 203

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net