Difference between revisions of "Documentation/DevGuide/Text/Text Sections"
OOoWikiBot (Talk | contribs) m (FINAL VERSION FOR L10N) |
|||
(One intermediate revision by the same user not shown) | |||
Line 12: | Line 12: | ||
For example, a section is formatted to have text columns that different column settings in a text on a paragraph by paragraph basis. The content of a section can be linked through file links or over a DDE connection. | For example, a section is formatted to have text columns that different column settings in a text on a paragraph by paragraph basis. The content of a section can be linked through file links or over a DDE connection. | ||
− | The text sections support the service <idl>com.sun.star.text.TextSection</idl>. To access the sections, the text document model implements the interface <idl>com.sun.star.text.XTextSectionsSupplier</idl> that provides an interface <idl>com.sun.star.container.XNameAccess</idl> . The returned objects support the interface <idl>com.sun.star.container.XIndexAccess</idl>, as well. | + | The text sections support the service <idl>com.sun.star.text.TextSection</idl>. To access the sections, the text document model implements the interface <idl>com.sun.star.text.XTextSectionsSupplier</idl> that provides an interface <idl>com.sun.star.container.XNameAccess</idl>. The returned objects support the interface <idl>com.sun.star.container.XIndexAccess</idl>, as well. |
Master documents implement the structure of sub documents using linked text sections. | Master documents implement the structure of sub documents using linked text sections. | ||
Line 18: | Line 18: | ||
An example demonstrating the creation, insertion and linking of text sections: | An example demonstrating the creation, insertion and linking of text sections: | ||
<!--[SOURCE:Text/TextDocuments.java]--> | <!--[SOURCE:Text/TextDocuments.java]--> | ||
− | + | <syntaxhighlight lang="java"> | |
/** This method demonstrates how to create linked and unlinked sections | /** This method demonstrates how to create linked and unlinked sections | ||
*/ | */ | ||
Line 114: | Line 114: | ||
} | } | ||
} | } | ||
− | + | </syntaxhighlight> | |
{{PDL1}} | {{PDL1}} | ||
[[Category:Documentation/Developer's Guide/Text Documents]] | [[Category:Documentation/Developer's Guide/Text Documents]] |
Latest revision as of 14:47, 3 January 2021
A text section is a range of complete paragraphs that can have its own format settings and source location, separate from the surrounding text. Text sections can be nested in a hierarchical structure.
For example, a section is formatted to have text columns that different column settings in a text on a paragraph by paragraph basis. The content of a section can be linked through file links or over a DDE connection.
The text sections support the service com.sun.star.text.TextSection. To access the sections, the text document model implements the interface com.sun.star.text.XTextSectionsSupplier that provides an interface com.sun.star.container.XNameAccess. The returned objects support the interface com.sun.star.container.XIndexAccess, as well.
Master documents implement the structure of sub documents using linked text sections.
An example demonstrating the creation, insertion and linking of text sections:
/** This method demonstrates how to create linked and unlinked sections */ protected void TextSectionExample() { try { // Go to the end of the document mxDocCursor.gotoEnd(false); // Insert two paragraph breaks mxDocText.insertControlCharacter( mxDocCursor, ControlCharacter.PARAGRAPH_BREAK, false); mxDocText.insertControlCharacter( mxDocCursor, ControlCharacter.PARAGRAPH_BREAK, true); // Create a new TextSection from the document factory and access it's XNamed interface XNamed xChildNamed = (XNamed) UnoRuntime.queryInterface( XNamed.class, mxDocFactory.createInstance("com.sun.star.text.TextSection")); // Set the new sections name to 'Child_Section' xChildNamed.setName("Child_Section"); // Access the Child_Section's XTextContent interface and insert it into the document XTextContent xChildSection = (XTextContent) UnoRuntime.queryInterface( XTextContent.class, xChildNamed); mxDocText.insertTextContent (mxDocCursor, xChildSection, false); // Access the XParagraphCursor interface of our text cursor XParagraphCursor xParaCursor = (XParagraphCursor) UnoRuntime.queryInterface( XParagraphCursor.class, mxDocCursor); // Go back one paragraph (into Child_Section) xParaCursor.gotoPreviousParagraph(false); // Insert a string into the Child_Section mxDocText.insertString(mxDocCursor, "This is a test", false); // Go to the end of the document mxDocCursor.gotoEnd(false); // Go back two paragraphs xParaCursor.gotoPreviousParagraph (false); xParaCursor.gotoPreviousParagraph (false); // Go to the end of the document, selecting the two paragraphs mxDocCursor.gotoEnd(true); // Create another text section and access it's XNamed interface XNamed xParentNamed = (XNamed) UnoRuntime.queryInterface(XNamed.class, mxDocFactory.createInstance("com.sun.star.text.TextSection")); // Set this text section's name to Parent_Section xParentNamed.setName ("Parent_Section"); // Access the Parent_Section's XTextContent interface ... XTextContent xParentSection = (XTextContent) UnoRuntime.queryInterface( XTextContent.class, xParentNamed); // ...and insert it into the document mxDocText.insertTextContent(mxDocCursor, xParentSection, false); // Go to the end of the document mxDocCursor.gotoEnd (false); // Insert a new paragraph mxDocText.insertControlCharacter( mxDocCursor, ControlCharacter.PARAGRAPH_BREAK, false); // And select the new pargraph xParaCursor.gotoPreviousParagraph(true); // Create a new Text Section and access it's XNamed interface XNamed xLinkNamed = (XNamed) UnoRuntime.queryInterface( XNamed.class, mxDocFactory.createInstance("com.sun.star.text.TextSection")); // Set the new text section's name to Linked_Section xLinkNamed.setName("Linked_Section"); // Access the Linked_Section's XTextContent interface XTextContent xLinkedSection = (XTextContent) UnoRuntime.queryInterface( XTextContent.class, xLinkNamed); // And insert the Linked_Section into the document mxDocText.insertTextContent(mxDocCursor, xLinkedSection, false); // Access the Linked_Section's XPropertySet interface XPropertySet xLinkProps = (XPropertySet) UnoRuntime.queryInterface( XPropertySet.class, xLinkNamed); // Set the linked section to be linked to the Child_Section xLinkProps.setPropertyValue("LinkRegion", "Child_Section"); // Access the XPropertySet interface of the Child_Section XPropertySet xChildProps = (XPropertySet) UnoRuntime.queryInterface( XPropertySet.class, xChildNamed); // Set the Child_Section's background colour to blue xChildProps.setPropertyValue("BackColor", new Integer(13421823)); // Refresh the document, so the linked section matches the Child_Section XRefreshable xRefresh = (XRefreshable) UnoRuntime.queryInterface( XRefreshable.class, mxDoc); xRefresh.refresh(); } catch (Exception e) { e.printStackTrace (System.out); } }
Content on this page is licensed under the Public Documentation License (PDL). |