Difference between revisions of "Documentation/DevGuide/Text/Reference Marks"
OOoWikiBot (Talk | contribs) m (Robot: Changing Category:Text Documents) |
|||
(3 intermediate revisions by 2 users not shown) | |||
Line 5: | Line 5: | ||
|NextPage=Documentation/DevGuide/Text/Footnotes and Endnotes | |NextPage=Documentation/DevGuide/Text/Footnotes and Endnotes | ||
}} | }} | ||
− | {{DISPLAYTITLE:Reference Marks}} | + | {{Documentation/DevGuideLanguages|Documentation/DevGuide/Text/{{SUBPAGENAME}}}} |
+ | {{DISPLAYTITLE:Reference Marks}} | ||
<!--<idltopic>com.sun.star.text.ReferenceMark</idltopic>--> | <!--<idltopic>com.sun.star.text.ReferenceMark</idltopic>--> | ||
A reference mark is a text content that is used as a target for <idl>com.sun.star.text.textfield.GetReference</idl> text fields. These text fields show the contents of reference marks in a text document and allows the user to jump to the reference mark. Reference marks support the <idl>com.sun.star.text.XTextContent</idl> and <idl>com.sun.star.container.XNamed</idl> interfaces. They can be accessed by using the text document's <idl>com.sun.star.text.XReferenceMarksSupplier</idl> interface that defines a single method <code>getReferenceMarks()</code>. | A reference mark is a text content that is used as a target for <idl>com.sun.star.text.textfield.GetReference</idl> text fields. These text fields show the contents of reference marks in a text document and allows the user to jump to the reference mark. Reference marks support the <idl>com.sun.star.text.XTextContent</idl> and <idl>com.sun.star.container.XNamed</idl> interfaces. They can be accessed by using the text document's <idl>com.sun.star.text.XReferenceMarksSupplier</idl> interface that defines a single method <code>getReferenceMarks()</code>. | ||
Line 11: | Line 12: | ||
The returned collection is a <idl>com.sun.star.text.ReferenceMarks</idl> service which has a <idl>com.sun.star.container.XNameAccess</idl> and a <idl>com.sun.star.container.XIndexAccess</idl> interface. | The returned collection is a <idl>com.sun.star.text.ReferenceMarks</idl> service which has a <idl>com.sun.star.container.XNameAccess</idl> and a <idl>com.sun.star.container.XIndexAccess</idl> interface. | ||
<!--[SOURCE:Text/TextDocuments.java]--> | <!--[SOURCE:Text/TextDocuments.java]--> | ||
− | + | <syntaxhighlight lang="java"> | |
/** This method demonstrates how to create and insert reference marks, and GetReference Text Fields | /** This method demonstrates how to create and insert reference marks, and GetReference Text Fields | ||
*/ | */ | ||
Line 67: | Line 68: | ||
XPropertySet xFieldProps = (XPropertySet) UnoRuntime.queryInterface( | XPropertySet xFieldProps = (XPropertySet) UnoRuntime.queryInterface( | ||
XPropertySet.class, mxDocFactory.createInstance( | XPropertySet.class, mxDocFactory.createInstance( | ||
− | "com.sun.star.text. | + | "com.sun.star.text.textfield.GetReference")); |
// Get the XReferenceMarksSupplier interface of the document | // Get the XReferenceMarksSupplier interface of the document | ||
Line 125: | Line 126: | ||
} | } | ||
} | } | ||
− | + | </syntaxhighlight> | |
The name of a reference mark can be used in a <idl>com.sun.star.text.textfield.GetReference</idl> text field to refer to the position of the reference mark. | The name of a reference mark can be used in a <idl>com.sun.star.text.textfield.GetReference</idl> text field to refer to the position of the reference mark. | ||
{{PDL1}} | {{PDL1}} | ||
− | [[Category:Documentation/ | + | [[Category:Documentation/Developer's Guide/Text Documents]] |
Latest revision as of 14:27, 3 January 2021
A reference mark is a text content that is used as a target for com.sun.star.text.textfield.GetReference text fields. These text fields show the contents of reference marks in a text document and allows the user to jump to the reference mark. Reference marks support the com.sun.star.text.XTextContent and com.sun.star.container.XNamed interfaces. They can be accessed by using the text document's com.sun.star.text.XReferenceMarksSupplier interface that defines a single method getReferenceMarks()
.
The returned collection is a com.sun.star.text.ReferenceMarks service which has a com.sun.star.container.XNameAccess and a com.sun.star.container.XIndexAccess interface.
/** This method demonstrates how to create and insert reference marks, and GetReference Text Fields */ protected void ReferenceExample () { try { // Go to the end of the document mxDocCursor.gotoEnd(false); // Insert a paragraph break mxDocText.insertControlCharacter( mxDocCursor, ControlCharacter.PARAGRAPH_BREAK, false); // Get the Paragraph cursor XParagraphCursor xParaCursor = (XParagraphCursor) UnoRuntime.queryInterface( XParagraphCursor.class, mxDocCursor); // Move the cursor into the new paragraph xParaCursor.gotoPreviousParagraph(false); // Create a new ReferenceMark and get it's XNamed interface XNamed xRefMark = (XNamed) UnoRuntime.queryInterface(XNamed.class, mxDocFactory.createInstance("com.sun.star.text.ReferenceMark")); // Set the name to TableHeader xRefMark.setName("TableHeader"); // Get the TextTablesSupplier interface of the document XTextTablesSupplier xTableSupplier = (XTextTablesSupplier) UnoRuntime.queryInterface( XTextTablesSupplier.class, mxDoc); // Get an XIndexAccess of TextTables XIndexAccess xTables = (XIndexAccess) UnoRuntime.queryInterface( XIndexAccess.class, xTableSupplier.getTextTables()); // We've only inserted one table, so get the first one from index zero XTextTable xTable = (XTextTable) UnoRuntime.queryInterface( XTextTable.class, xTables.getByIndex(0)); // Get the first cell from the table XText xTableText = (XText) UnoRuntime.queryInterface( XText.class, xTable.getCellByName("A1")); // Get a text cursor for the first cell XTextCursor xTableCursor = xTableText.createTextCursor(); // Get the XTextContent interface of the reference mark so we can insert it XTextContent xContent = (XTextContent) UnoRuntime.queryInterface( XTextContent.class, xRefMark); // Insert the reference mark into the first cell of the table xTableText.insertTextContent (xTableCursor, xContent, false); // Create a 'GetReference' text field to refer to the reference mark we just inserted, // and get it's XPropertySet interface XPropertySet xFieldProps = (XPropertySet) UnoRuntime.queryInterface( XPropertySet.class, mxDocFactory.createInstance( "com.sun.star.text.textfield.GetReference")); // Get the XReferenceMarksSupplier interface of the document XReferenceMarksSupplier xRefSupplier = (XReferenceMarksSupplier) UnoRuntime.queryInterface( XReferenceMarksSupplier.class, mxDoc); // Get an XNameAccess which refers to all inserted reference marks XNameAccess xMarks = (XNameAccess) UnoRuntime.queryInterface(XNameAccess.class, xRefSupplier.getReferenceMarks()); // Put the names of each reference mark into an array of strings String[] aNames = xMarks.getElementNames(); // Make sure that at least 1 reference mark actually exists // (well, we just inserted one!) if (aNames.length > 0) { // Output the name of the first reference mark ('TableHeader') System.out.println ("GetReference text field inserted for ReferenceMark : " + aNames[0]); // Set the SourceName of the GetReference text field to 'TableHeader' xFieldProps.setPropertyValue("SourceName", aNames[0]); // specify that the source is a reference mark (could also be a footnote, // bookmark or sequence field) xFieldProps.setPropertyValue ("ReferenceFieldSource", new Short( ReferenceFieldSource.REFERENCE_MARK)); // We want the reference displayed as 'above' or 'below' xFieldProps.setPropertyValue("ReferenceFieldPart", new Short (ReferenceFieldPart.UP_DOWN)); // Get the XTextContent interface of the GetReference text field XTextContent xRefContent = (XTextContent) UnoRuntime.queryInterface( XTextContent.class, xFieldProps); // Go to the end of the document mxDocCursor.gotoEnd(false); // Make some text to precede the reference mxDocText.insertString(mxDocText.getEnd(), "The table ", false); // Insert the text field mxDocText.insertTextContent(mxDocText.getEnd(), xRefContent, false); // And some text after the reference.. mxDocText.insertString( mxDocText.getEnd(), " contains the sum of some random numbers.", false); // Refresh the document XRefreshable xRefresh = (XRefreshable) UnoRuntime.queryInterface( XRefreshable.class, mxDoc); xRefresh.refresh(); } } catch (Exception e) { e.printStackTrace(System.out); } }
The name of a reference mark can be used in a com.sun.star.text.textfield.GetReference text field to refer to the position of the reference mark.
Content on this page is licensed under the Public Documentation License (PDL). |