Text Sections

From Apache OpenOffice Wiki
Jump to: navigation, search

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
         // Insert two paragraph breaks
             mxDocCursor, ControlCharacter.PARAGRAPH_BREAK, false);
             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'
         // 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)
         // Insert a string into the Child_Section
         mxDocText.insertString(mxDocCursor, "This is a test", false);
         // Go to the end of the document
         // Go back two paragraphs
         xParaCursor.gotoPreviousParagraph (false);
         xParaCursor.gotoPreviousParagraph (false);
         // Go to the end of the document, selecting the two paragraphs
         // Create another text section and access it's XNamed interface
         XNamed xParentNamed = (XNamed) UnoRuntime.queryInterface(XNamed.class,
         // 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
             mxDocCursor, ControlCharacter.PARAGRAPH_BREAK, false);
         // And select the new pargraph
         // 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
         // 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);
     } catch (Exception e) {
         e.printStackTrace (System.out);
Content on this page is licensed under the Public Documentation License (PDL).
Personal tools
In other languages