Anda di halaman 1dari 108

OpenOffice.org 3.

1 Developer's Guide

Copyright
This document is published under the PDL. See: http://www.openoffice.org/licenses/PDL.html

Contents

Copyright.......................................................................................................................................2

Preface.......................................................................................5

7 Text Documents...........................................................................7 Creating and Loading Te t Documents ......................................................................................!" Storing ........................................................................................................................................!# $ porting ....................................................................................................................................!% Printer and Print &ob Settings .....................................................................................................!' Printing (ultiple Pages on one Page ..........................................................................................2) *ord Processing .........................................................................................................................2! Strings .........................................................................................................................................2! Te t Contents +ther Than Strings ..............................................................................................2" Control Characters ......................................................................................................................2, Cursors ........................................................................................................................................"! Locating Te t Contents ..............................................................................................................."2 Search and -eplace .....................................................................................................................". Table /rchitecture ......................................................................................................................."# 0nde es ........................................................................................................................................#1 0nde mar2s ................................................................................................................................%2 3ase 4rames 5s. Drawing Shapes ...............................................................................................%' Drawing Shapes ..........................................................................................................................'2 Styles ..........................................................................................................................................1. Paragraph Styles .........................................................................................................................1# 4rame Styles ...............................................................................................................................1# Page Styles ..................................................................................................................................1% 6umbering Styles .......................................................................................................................1%

7eneral Document 0nformation ..................................................................................................11 Document Properties ..................................................................................................................11 Creating Default Settings ..........................................................................................................!)) Creating Document Settings .....................................................................................................!)) Paragraph and +utline 6umbering ...........................................................................................!)! Line 6umbering ........................................................................................................................!)" 6umber 4ormats .......................................................................................................................!)"

Preface

This guide pro5ides..... Note Throughout this document8 the +pen+ffice.org installation directory is represented in synta as install-dir.

C H A P

! "

Text Documents

0n the +pen+ffice.org /P08 a te t document is a document model which is able to handle te t contents. / document in our conte t is a product of wor2 that can be stored and printed to ma2e the result of the wor2 a permanent resource. 3y model we mean data that forms the basis of a document and is organi9ed in a manner that allows wor2ing with the data independently from their 5isual representation in a graphical user interface. 0t is important to understand that de5elopers ha5e to wor2 with the model directly8 when they want to change it through the +pen+ffice.org /P0. The model has a controller ob:ect which enables de5elopers to manipulate the 5isual presentation of the document in the user interface. 3ut the controller is not used to change a document. The controller ser5es two purposes. The controller interacts with the user interface for mo5ement8 such as mo5ing the 5isible te t cursor8 flipping through screen pages or changing the 9oom factor. The second purpose is getting information about the current 5iew status8 such as the current selection8 the current page8 the total page count or the line count. /utomatic page or line brea2s are not really part of the document data8 but rather something that is needed in a certain presentation of the document.

;eeping the difference between model and controller in mind8 we will now discuss the parts of a te t document model in the +pen+ffice.org /P0. The te t document model in the +pen+ffice.org /P0 has fi5e ma:or architectural areas8 cf. 0llustration ! below. The fi5e areas are:

te t ser5ice manager <document internal= draw page te t content suppliers


7

Text Documents

ob:ects for styling and numbering

The core of the te t document model is the te t. 0t consists of character strings organi9ed in paragraphs and other te t contents. The usage of te t will be discussed in *or2ing with Te t Documents. The ser5ice manager of the document model creates all te t contents for the model8 e cept for the paragraphs. 6ote that the document ser5ice manager is different from the main ser5ice manager that is used when connecting to the office. $ach document model has its own ser5ice manager8 so that the ser5ices can be adapted to the document when re>uired. $ amples for te t contents created by the te t document ser5ice manager are te t tables8 te t fields8 drawing shapes8 te t frames or graphic ob:ects. The ser5ice manager is as2ed for a te t content8 then you insert it into the te t. /fterwards8 the ma:ority of these te t contents in a te t can be retrie5ed from the model using te t content suppliers. The e ception are drawing shapes. They can be found on the DrawPage8 which is discussed below. /bo5e the te t lies the DrawPage. 0t is used for drawing contents. 0magine it as a transparent layer with contents that can affect the te t under the layer8 for instance by forcing it to wrap around contents on the DrawPage. ?owe5er8 te t can also wrap through DrawPage contents8 so the similarity is limited. 4inally8 there are ser5ices that allow for document wide styling and structuring of the te t. /mong them are style family suppliers for paragraphs8 characters8 pages and numbering patterns8 and suppliers for line and outline numbering. 3esides these fi5e architectural areas8 there are a number of aspects co5ering the document character of our model: 0t is printable8 storable8 modifiable8 it can be refreshed8 its contents are able to be searched and replaced and it supplies general information about itself. These aspects are shown at the lower right of the illustration.

OpenOffice.org 3.1 Developer's Guide April !!"

Text Documents

Text Document Model 4inally8 the controller pro5ides access to the graphical user interface for the model and has 2nowledge about the current 5iew status in the user interface8 cf. the upper left of the diagram abo5e. The usage of te t is discussed in the section *or2ing with Te t Documents.

!$%&ple' (ields in % e&pl%te


/ll following code samples are contained in TextDocuments.java. This file is located in the Samples folder that comes with the resources for the de5eloper@s manual. The e amples use the en5ironment from chapter 4irst Steps8 for instance8 connecting using the getRemoteServiceManager() method. *e want to use a template file containing te t fields and boo2mar2s and insert te t into the fields and at the cursor position. The suitable template file TextTemplateWithUserFields.odt lies in the Samples folder8 as well. $dit the path to this file below before running the sample.

#$%pter 7 Text Documents

"

Text Documents

The first step is to load the file as a template8 so that +pen+ffice.org creates a new8 untitled document. /s in the chapter 4irst Steps8 we ha5e to connect8 get the Des2top ob:ect8 >uery its XComponentLoader interface and call loadComponentFromUrl(). This time we tell +pen+ffice.org how it should load the file. The 2ey for loading parameters is the se>uence of PropertyValue structs passed to loadComponentFromUrl(). The appropriate PropertyValue name is A !emplate and we ha5e to set A !emplate to true.
"##$Load$a$document$a $template$#" $$protected$XComponent$newDocComponentFrom!emplate(String$loadUrl)$t%row $ &ava'lang'()ception$* $$$$$$""$get$t%e$remote$ ervice$manager $$$$$$m)RemoteServiceManager$+$t%i 'getRemoteServiceManager(unoUrl), $$$$$$""$retrieve$t%e$De -top$o.&ect/$we$need$it $XComponentLoader $$$$$$0.&ect$de -top$+$m)RemoteServiceManager'create1n tance2it%Conte)t( $$$$$$$$$$3com' un' tar'4rame'De -top3/$m)RemoteConte)t), $$$$$$XComponentLoader$)ComponentLoader$+$ (XComponentLoader)UnoRuntime'5uery1nter4ace( $$$$$$$$$$XComponentLoader'cla /$de -top), $$ $$$$$$""$de4ine$load$propertie $according$to$ com' un' tar'document'MediaDe criptor $$$$$$""$t%e$.oolean$property$A !emplate$tell $t%e$o44ice$to$create$a$new$ document $$$$$$""$4rom$t%e$given$4ile $$$$$$PropertyValue67$loadProp $+$new$PropertyValue687, $$$$$$loadProp 697$+$new$PropertyValue(), $$$$$$loadProp 697':ame$+$3A !emplate3, $$$$$$loadProp 697'Value$+$new$;oolean(true),$ $$$$$$""$load $$$$$$return$)ComponentLoader'loadComponentFromURL(loadUrl/$3<.lan-3/$9/$ loadProp ),$ $$=

6ow that we are able to load a te t document as template8 we will open an e isting template file that contains fi5e te t fields and a boo2mar2. *e want to demonstrate how to insert te t at predefined positions in a document. Te t fields and boo2mar2s are supplied by the appropriate X!e)tField Supplier and X;oo-mar- Supplier interfaces. Their fully >ualified names are com.sun.star.te t.ATe t4ieldsSupplier and com.sun.star.te t.A3oo2mar2sSupplier. The X!e)tField Supplier pro5ides collections of te t fields in our te t. *e use document 5ariable fields for our purpose8 which are com.sun.star.te t.te tfield.Bser ser5ices. /ll Bser fields ha5e a field master that holds the actual content of the 5ariable. Therefore8 the !e)tField collection8 as well as the FieldMa ter are re>uired for our e ample. *e get the field masters for the fi5e fields by name and set their Content property. 4inally8 we refresh the te t fields so that they reflect the changes made to the field masters. The X;oo-mar- Supplier returns all boo2mar2s in our document. The collection of boo2mar2s is a com.sun.star.container.A6ame/ccess 8 so that the boo2mar2s are retrie5ed by name. $5ery ob:ect in a te t supports the interface X!e)tContent that has a method

1!

OpenOffice.org 3.1 Developer's Guide April !!"

Text Documents

getAnc%or(). The anchor is the te t range an ob:ect ta2es up8 so getAnc%or() retrie5es is an X!e)tRange. 4rom the chapter 4irst Steps8 a com.sun.star.te t.ATe t-ange allows setting the

string of a te t range. +ur boo2mar2 is a te t content and therefore must support X!e)tContent. 0nserting te t at a boo2mar2 position is straightforward: get the anchor of the boo2mar2 and set its string.
"##$Sample$4or$u e$o4$template $$$$$$!%i $ ample$u e $t%e$4ile$!e)t!emplate2it%U erField 'odt$4rom$t%e$ Sample $4older' $$$$$$!%e$4ile$contain $a$num.er$o4$U er$te)t$4ield $(Varia.le $>$U er)$and$a$ .oo-mar$$$$$$w%ic%$we$u e$to$4ill$in$variou $value $$$#" $$protected$void$template()ample()$t%row $&ava'lang'()ception$* $$$$$$""$create$a$ mall$%a %ta.le$t%at$ imulate $a$row et$wit%$column $$$$$$?a %ta.le$recipient$+$new$?a %ta.le(), $$$$$$recipient'put(3Company3/$3Manatee$;oo- 3), $$$$$$recipient'put(3Contact3/$3Rod$Martin3), $$$$$$recipient'put(3@1P3/$3ABCDE3), $$$$$$recipient'put(3City3/$3Fort$Lauderdale3), $$$$$$recipient'put(3State3/$3Florida3), $$$$$$ $$$$$$""$load$template$wit%$U er$4ield $and$.oo-mar$$$$$$XComponent$)!emplateComponent$+$newDocComponentFrom!emplate( $$$$$$34ileF"""XF"devmanual"Sample "!e)t!emplate2it%U erField 'odt3), $$$$$$ $$$$$$""$get$X!e)tField Supplier$and$X;oo-mar- Supplier$inter4ace $4rom$ document$component $$$$$$X!e)tField Supplier$)!e)tField Supplier$+$ (X!e)tField Supplier)UnoRuntime'5uery1nter4ace( $$$$$$$$$$X!e)tField Supplier'cla /$)!emplateComponent), $$$$$$X;oo-mar- Supplier$);oo-mar- Supplier$+$ (X;oo-mar- Supplier)UnoRuntime'5uery1nter4ace( $$$$$$$$$$X;oo-mar- Supplier'cla /$)!emplateComponent), $$$$$$ $$$$$$""$acce $t%e$!e)tField $and$t%e$!e)tFieldMa ter $collection $$$$$$X:ameAcce $):amedFieldMa ter $+$ )!e)tField Supplier'get!e)tFieldMa ter (), $$$$$$X(numerationAcce $)(numeratedField $+$ )!e)tField Supplier'get!e)tField (), $$$$$$ $$$$$$""$iterate$over$%a %ta.le$and$in ert$value $into$4ield$ma ter $$$$$$&ava'util'(numeration$-ey $+$recipient'-ey (), $$$$$$w%ile$(-ey '%a More(lement ())$* $$$$$$$$$$""$get$column$name $$$$$$$$$$String$-ey$+$(String)-ey 'ne)t(lement(), $$$$$$$$$$ $$$$$$$$$$""$acce $corre ponding$4ield$ma ter $$$$$$$$$$0.&ect$4ieldMa ter$+$):amedFieldMa ter 'get;y:ame( $$$$$$$$$$$$$$3com' un' tar'te)t'4ieldma ter'U er'3$G$-ey), $$$$$$$$$$ $$$$$$$$$$""$5uery$t%e$XPropertySet$inter4ace/$we$need$to$ et$t%e$Content$ property $$$$$$$$$$XPropertySet$)PropertySet$+$(XPropertySet)UnoRuntime'5uery1nter4ace( $$$$$$$$$$$$$$XPropertySet'cla /$4ieldMa ter), $$$$$$$$$$ $$$$$$$$$$""$in ert$t%e$column$value$into$4ield$ma ter

#$%pter 7 Text Documents

11

Text Documents

$$$$$$$$$$)PropertySet' etPropertyValue(3Content3/$recipient'get(-ey)), $$$$$$= $$$$$$ $$$$$$""$a4terward $we$mu t$re4re %$t%e$te)t4ield $collection $$$$$$XRe4re %a.le$)Re4re %a.le$+$(XRe4re %a.le)UnoRuntime'5uery1nter4ace( $$$$$$$$$$XRe4re %a.le'cla /$)(numeratedField ), $$$$$$)Re4re %a.le're4re %(), $$$$$$ $$$$$$""$acce ing$t%e$;oo-mar- $collection$o4$t%e$document $$$$$$X:ameAcce $):amed;oo-mar- $+$);oo-mar- Supplier'get;oo-mar- (), $$$$$$ $$$$$$""$4ind$t%e$.oo-mar-$named$3Su. cription3 $$$$$$0.&ect$.oo-mar-$+$):amed;oo-mar- 'get;y:ame(3Su. cription3), $$$$$$ $$$$$$""$we$need$it $X!e)tRange$w%ic%$i $availa.le$4rom$getAnc%or()/$ $$$$$$""$ o$5uery$4or$X!e)tContent $$$$$$X!e)tContent$);oo-mar-Content$+$(X!e)tContent)UnoRuntime'5uery1nter4ace( $$$$$$$$$$X!e)tContent'cla /$.oo-mar-), $$$$$$ $$$$$$""$get$t%e$anc%or$o4$t%e$.oo-mar-$(it $X!e)tRange) $$$$$$X!e)tRange$);oo-mar-Range$+$);oo-mar-Content'getAnc%or(), $$$$$$ $$$$$$""$ et$ tring$at$t%e$.oo-mar-$po ition $$$$$$);oo-mar-Range' etString(3 u. cription$4or$t%e$Manatee$Hournal3), $$=

!$%&ple' )isi*le Cursor Position


/s discussed earlier8 the +pen+ffice.org /P0 distinguishes between the model and controller. This difference is mirrored in two different 2inds of cursors in the /P0: model cursors and 5isible cursors. The 5isible cursor is also called 5iew cursor. The second e ample assumes that the user has selected a te t range in a paragraph and e pects something to happen at that cursor position. Setting character and paragraph styles8 and retrie5ing the current page number at the 5iew cursor position is demonstrated in the e ample. The 5iew cursor will be transformed into a model cursor. *e want to wor2 with the current document8 therefore we cannot use loadComponentFromURL(). -ather8 we as2 the com.sun.star.frame.Des2top ser5ice for the current component. +nce we ha5e the current component C which is our document model C we go from the model to the controller and get the 5iew cursor. The 5iew cursor has properties for the current character and paragraph style. The e ample uses builtCin styles and sets the property C%arStyle:ame to DIuotationD and ParaStyle:ame to DIuotation D. 4urthermore8 the 5iew cursor 2nows about the automatic page brea2s. 3ecause we are interested in the current page number8 we get it from the 5iew cursor and print it out.

OpenOffice.org 3.1 Developer's Guide April !!"

Text Documents

The model cursor is much more powerful than the 5iew cursor when it comes to possible mo5ements and editing capabilities. *e create a model cursor from the 5iew cursor. Two steps are necessary: *e as2 the 5iew cursor for its Te t ser5ice8 then we ha5e the Te t ser5ice create a model cursor based on the current cursor position. The model cursor 2nows where the paragraph ends8 so we go there and insert a string.
"##$Sample$4or$document$c%ange /$ tarting$at$t%e$current$view$cur or$po ition $$$$$$!%e$ ample$c%ange $t%e$paragrap%$ tyle$and$t%e$c%aracter$ tyle$at$t%e$ current $$$$$$view$cur or$ election $$$$$$0pen$t%e$ ample$4ile$ViewCur or()ampleFile/$ elect$ ome$te)t$and$run$t%e$ e)ample $$$$$$!%e$current$paragrap%$will$.e$ et$to$Iuotation $paragrap%$ tyle$ $$$$$$!%e$ elected$te)t$will$.e$ et$to$Iuotation$c%aracter$ tyle $$$#" $$private$void$viewCur or()ample()$t%row $&ava'lang'()ception$* $$$$$$""$get$t%e$remote$ ervice$manager $$$$$$m)RemoteServiceManager$+$t%i 'getRemoteServiceManager(unoUrl), $$ $$$$$$""$get$t%e$De -top$ ervice $$$$$$0.&ect$de -top$+$m)RemoteServiceManager'create1n tance2it%Conte)t( $$$$$$$$$$3com' un' tar'4rame'De -top3/$m)RemoteConte)t), $$$$$$ $$$$$$""$5uery$it $XDe -top$inter4ace/$we$need$t%e$current$component $$$$$$XDe -top$)De -top$+$(XDe -top)UnoRuntime'5uery1nter4ace( $$$$$$$$$$XDe -top'cla /$de -top), $$$$$$ $$$$$$""$retrieve$t%e$current$component$and$acce $t%e$controller $$$$$$XComponent$)CurrentComponent$+$)De -top'getCurrentComponent(), $$$$$$ $$$$$$""$get$t%e$XModel$inter4ace$4rom$t%e$component $$$$$$XModel$)Model$+$(XModel)UnoRuntime'5uery1nter4ace(XModel'cla /$ )CurrentComponent), $$$$$$ $$$$$$""$t%e$model$-now $it $controller $$$$$$XController$)Controller$+$)Model'getCurrentController(), $$$$$$ $$$$$$""$t%e$controller$give $u $t%e$!e)tViewCur or $$$$$$""$5uery$t%e$viewcur or$ upplier$inter4ace$ $$$$$$X!e)tViewCur orSupplier$)ViewCur orSupplier$+$ $$$$$$$$$$(X!e)tViewCur orSupplier)UnoRuntime'5uery1nter4ace( $$$$$$$$$$$$$$X!e)tViewCur orSupplier'cla /$)Controller), $$$$$$ $$$$$$""$get$t%e$cur or$ $$$$$$X!e)tViewCur or$)ViewCur or$+$)ViewCur orSupplier'getViewCur or(), $$$$$$ $$$$$$""$5uery$it $XPropertySet$inter4ace/$we$want$to$ et$c%aracter$and$ paragrap%$propertie $$$$$$XPropertySet$)Cur orPropertySet$+$ (XPropertySet)UnoRuntime'5uery1nter4ace( $$$$$$$$$$XPropertySet'cla /$)ViewCur or), $$$$$$ $$$$$$""$ et$t%e$appropriate$propertie $4or$c%aracter$and$paragrap%$ tyle $$$$$$)Cur orPropertySet' etPropertyValue(3C%arStyle:ame3/$3Iuotation3), $$$$$$$$$$)Cur orPropertySet' etPropertyValue(3ParaStyle:ame3/$3Iuotation 3), $$$$$$ $$$$$$""$print$t%e$current$page$num.er$>$we$need$t%e$XPageCur or$inter4ace$4or$

#$%pter 7 Text Documents

13

Text Documents

t%i $$$$$$XPageCur or$)PageCur or$+$(XPageCur or)UnoRuntime'5uery1nter4ace( $$$$$$$$$$XPageCur or'cla /$)ViewCur or), $$$$$$Sy tem'out'println(3!%e$current$page$num.er$i $3$G$ )PageCur or'getPage()), $$$$$$ $$$$$$""$t%e$model$cur or$i $muc%$more$power4ul/$ o$ $$$$$$""$we$create$a$model$cur or$at$t%e$current$view$cur or$po ition$wit%$t%e$ 4ollowing$ tep F $$$$$$""$we$get$t%e$!e)t$ ervice$4rom$t%e$!e)tViewCur or/$t%e$cur or$i $an$ X!e)tRange$and$%a $ $$$$$$""$t%ere4ore$a$met%od$get!e)t() $$$$$$X!e)t$)Document!e)t$+$)ViewCur or'get!e)t(), $$$$$$ $$$$$$""$t%e$te)t$create $a$model$cur or$4rom$t%e$viewcur or $$$$$$X!e)tCur or$)ModelCur or$+$ )Document!e)t'create!e)tCur or;yRange()ViewCur or'getStart()), $$$$$$ $$$$$$""$now$we$could$5uery$X2ordCur or/$XSentenceCur or$and$XParagrap%Cur or $$$$$$""$or$XDocument1n erta.le/$XSorta.le$or$XContent(numerationAcce $$$$$$""$and$wor-$wit%$t%e$propertie $o4$com' un' tar'te)t'!e)tCur or $$$$$$""$in$t%i $ca e$we$&u t$go$to$t%e$end$o4$t%e$paragrap%$and$add$ ome$ te)t' $$$$$$XParagrap%Cur or$)Paragrap%Cur or$+$ (XParagrap%Cur or)UnoRuntime'5uery1nter4ace( $$$$$$$$$$XParagrap%Cur or'cla /$)ModelCur or), $$$$$$ $$$$$$""$goto$t%e$end$o4$t%e$paragrap% $$$$$$)Paragrap%Cur or'goto(nd04Paragrap%(4al e), $$$$$$)Paragrap%Cur or' etString(3$#####$Fin$de$ emanaJ$######3), $$=

H%ndling e$t Docu&ent (iles

Cre%ting %nd +o%ding e$t Docu&ents


0f a document in +pen+ffice.org is re>uired8 begin by getting a com.sun.star.frame.Des2top ser5ice from the ser5ice manager. The des2top handles all document components in +pen+ffice.org8 among other things. 0t is discussed thoroughly in the chapter +ffice De5elopment. +ffice documents are often called components8 because they support the com.sun.star.lang.AComponent interface. /n XComponent is a B6+ ob:ect that can be disposed e plicitly and broadcast an e5ent to other B6+ ob:ects when this happens. The Des2top can load new and e isting components from a B-L. 4or this purpose it has a com.sun.star.frame.AComponentLoader interface that has one single method to load and

1&

OpenOffice.org 3.1 Developer's Guide April !!"

#re%ting %nd 'o%ding Text Documents

instantiate components from a B-L into a frame:


com' un' tar'langFFXComponent$loadComponentFromURL(6in7$ tring$aURL/$ $$$$$$$$$$6in7$ tring$a!argetFrame:ame/$ $$$$$$$$$$6in7$long$nSearc%Flag /$ $$$$$$$$$$6in7$ e5uenceK$comFF unFF tarFF.ean FFPropertyValue$L$aArg $),

The interesting parameters in our conte t are the B-L that describes which resource should be loaded and the se>uence of load arguments. 4or the target frame pass D<.lan-D and set the search flags to ). 0n most cases you will not want to reuse an e isting frame. The B-L can be a 4ileF B-L8 a %ttpF B-L8 an 4tpF B-L or a privateF B-L. Loo2 up the correct B-L format in the load B-L bo in the function bar of +pen+ffice.org. 4or new writer documents8 a special B-L scheme has to be used. The scheme is Dpri5ate:D8 followed by DfactoryD as hostname. The resource is DswriterD for +pen+ffice.org writer documents. 4or a new writer document8 use DprivateF4actory" writerD. The load arguments are described in com.sun.star.document.(ediaDescriptor. The arguments A !emplate and ?idden ha5e properties that are boolean 5alues. 0f A !emplate is true8 the loader creates a new untitled document from the gi5en B-L. 0f it is false8 template files are loaded for editing. 0f ?idden is true8 the document is loaded in the bac2ground. This is useful when generating a document in the bac2ground without letting the user obser5eE for e ample8 it can be used to generate a document and print it without pre5iewing. +ffice de5elopment describes other a5ailable options. The section $ ample: 4ields in a Template discusses a complete e ample about how loading wor2s. The following snippet loads a document in hidden mode:
""$(t%e$met%od$getRemoteServiceManager$i $de cri.ed$in$t%e$c%apter$Fir t$ Step ) $$m)RemoteServiceManager$+$t%i 'getRemoteServiceManager(unoUrl), $$ $$""$retrieve$t%e$De -top$o.&ect/$we$need$it $XComponentLoader $$0.&ect$de -top$+$m)RemoteServiceManager'create1n tance2it%Conte)t( $$3com' un' tar'4rame'De -top3/$m)RemoteConte)t), $$ $$""$5uery$t%e$XComponentLoader$inter4ace$4rom$t%e$De -top$ ervice $$XComponentLoader$)ComponentLoader$+$ (XComponentLoader)UnoRuntime'5uery1nter4ace( $$$$$$XComponentLoader'cla /$de -top), $$ $$""$de4ine$load$propertie $according$to$com' un' tar'document'MediaDe criptor $$ $$"#$or$ imply$create$an$empty$array$o4$com' un' tar'.ean 'PropertyValue$ truct F $$$$$PropertyValue67$loadProp $+$new$PropertyValue697 $$$#" $$ $$""$t%e$.oolean$property$?idden$tell $t%e$o44ice$to$open$a$4ile$in$%idden$ mode $$PropertyValue67$loadProp $+$new$PropertyValue687, $$loadProp 697$+$new$PropertyValue(), $$loadProp 697':ame$+$3?idden3,

#$%pter 7 Text Documents

15

#re%ting %nd 'o%ding Text Documents

$$loadProp 697'Value$+$new$;oolean(true),$ $$ $$""$load $$return$)ComponentLoader'loadComponentFromURL(loadUrl/$3<.lan-3/$9/$ loadProp ),

,%ving e$t Docu&ents

,toring
Documents are storable through their interface com.sun.star.frame.AStorable. This interface is discussed in detail in +ffice De5elopment. /n XStora.le implements these operations:
.oolean$%a Location() $$ tring$getLocation() $$.oolean$i Readonly() $$void$ tore()$ $$void$ toreA URL($6in7$ tring$aURL/$ e5uenceK$ comFF unFF tarFF.ean FFPropertyValue$L$aArg ) $$void$ tore!oURL($6in7$ tring$aURL/$ e5uenceK$ comFF unFF tarFF.ean FFPropertyValue$L$aArg )

The method names are e5ident. The method toreA Url() is the e act representation of File - Save As8that is8 it changes the current document location. 0n contrast8 tore!oUrl() stores a copy to a new location8 but lea5es the current document B-L untouched.

!$porting
4or e porting purposes8 a filter name can be passed to toreA URL() and tore!oURL() that triggers an e port to other file formats. The property needed for this purpose is the string argument 4ilter6ame that ta2es filter names defined in the configuration file:
K044icePat%LM %areMcon4igMregi tryMin tanceMorgMopeno44iceM044iceM!ypeDetectio n')ml

0n TypeDetection.xml8 loo2 for KFilter"L elements8 their c4gFname attribute contains the needed strings for Filter:ame. The proper filter name for Star*riter ,. is DStar*riter ,.)D8 and the e port format D(S *ord 1%D is also popular. This is the element in TypeDetection.xml that describes the (S *ord 1% filter:

1(

OpenOffice.org 3.1 Developer's Guide April !!"

)xporting

KFilter$c4gFname+3MS$2ord$NE3L $$$$$K1n talled$c4gFtype+3.oolean3LtrueK"1n talledL$ $$$$$KU1:ame$c4gFtype+3 tring3$c4gFlocaliOed+3true3L $$$$$$$Kc4gFvalue$)mlFlang+3en>US3LMicro o4t$2ord$NE"P999"XPK"c4gFvalueL$ $$$$$K"U1:ameL $$$$$KData$ c4gFtype+3 tring3LA/writer<MS<2ord<NE/com' un' tar'te)t'!e)tDocument//DE/C22Q/ 9//K"DataL$ $$K"FilterL

The following method stores a document using this filter:


"##$Store$a$document/$u ing$t%e$MS$2ord$NE"P999"XP$Filter$#" $$$$$$protected$void$ toreDocComponent(XComponent$)Doc/$String$ toreUrl)$ t%row $&ava'lang'()ception$* $$ $$$$$$$$$$XStora.le$)Stora.le$+$ (XStora.le)UnoRuntime'5uery1nter4ace(XStora.le'cla /$)Doc), $$$$$$$$$$PropertyValue67$ toreProp $+$new$PropertyValue687, $$$$$$$$$$ toreProp 697$+$new$PropertyValue(), $$$$$$$$$$ toreProp 697':ame$+$3Filter:ame3, $$$$$$$$$$ toreProp 697'Value$+$3MS$2ord$NE3,$ $$$$$$$$$$)Stora.le' toreA URL( toreUrl/$ toreProp ),$ $$$$$$=

0f an empty array of PropertyValue structs is passed8 the nati5e .odt format of +pen+ffice.org is used.

Printing e$t Docu&ents

Printer %nd Print -o* ,ettings


Printing is a common office functionality. The chapter +ffice De5elopment pro5ides inCdepth information about it. The writer document implements the com.sun.star.5iew.APrintable interface for printing. 0t consists of three methods:
e5uenceK$comFF unFF tarFF.ean FFPropertyValue$L$getPrinter$() $$void$ etPrinter$($6in7$ e5uenceK$comFF unFF tarFF.ean FFPropertyValue$L$ aPrinter) $$void$print$($6in7$ e5uenceK$comFF unFF tarFF.ean FFPropertyValue$L$)0ption )

The following code is used with a gi5en document Doc to print to the standard printer without any settings:
""$5uery$t%e$XPrinta.le$inter4ace$4rom$your$document $$XPrinta.le$)Printa.le$+$

#$%pter 7 Text Documents

17

*rinter %nd *rint +o, -ettings

(XPrinta.le)UnoRuntime'5uery1nter4ace(XPrinta.le'cla $$ $$""$create$an$empty$print0ption $array $$PropertyValue67$print0pt $+$new$PropertyValue697, $$ $$""$-ic-$o44$printing $$)Printa.le'print(print0pt ),

/$)Doc),

There are two groups of properties in5ol5ed in general printing. The first one is used with etPrinter() and getPrinter() that controls the printer8 and the second one is passed to print() and controls the print :ob. :com.sun.star.5iew.PrinterDescriptor comprises the properties for the printer: Properties of co&.sun.st%r.vie..PrinterDescriptor com.sun.star.5iew.PrinterDescriptor:6ame tring C Specifies the name of the printer >ueue to be used. com.sun.star.5iew.PrinterDescriptor:Paper+ rientation com.sun.star.5iew.Paper+rientation . Specifies the orientation of the paper. com.sun.star.5iew.PrinterDescriptor:Paper4 ormat com.sun.star.5iew.Paper4ormat . Specifies a predefined paper si9e or if the paper si9e is a userCdefined si9e. com.sun.star.5iew.PrinterDescriptor:PaperSi 9e com.sun.star.awt.Si9e . Specifies the si9e of the paper in !/!)) mm. com.sun.star.5iew.PrinterDescriptor:0s3usy .oolean C 0ndicates if the printer is busy. com.sun.star.5iew.PrinterDescriptor:CanSet .oolean C 0ndicates if the printer allows Paper+rientation changes to Paper0rientation. com.sun.star.5iew.PrinterDescriptor:CanSet .oolean C 0ndicates if the printer allows Paper4ormat changes to PaperFormat. com.sun.star.5iew.PrinterDescriptor:CanSet .oolean C 0ndicates if the printer allows PaperSi9e changes to PaperSiOe. com.sun.star.5iew.Print+ptions contains the following possibilities for a print :ob: Properties of co&.sun.st%r.vie..PrintOptions com.sun.star.5iew.Print+ptions:CopyCount %ort C Specifies the number of copies to print. com.sun.star.5iew.Print+ptions:4ile6ame tring C Specifies the name of a file to print to8 if set. com.sun.star.5iew.Print+ptions:Collate .oolean C /d5ises the printer to collate the pages of the copies. 0f true8 a whole document is printed prior to the ne t copy8 otherwise the page copies are completed together. com.sun.star.5iew.Print+ptions:Pages tring C Specifies the pages to print in the

18

OpenOffice.org 3.1 Developer's Guide April !!"

*rinter %nd *rint +o, -ettings

com.sun.star.5iew.Print+ptions:*ait

same format as in the print dialog of the 7B0 <e.g. D!8 .8 "C%8 1CD= .oolean C /d5ises that the print :ob should be performed synchronously8 i.e. wait until printing is complete before returning from printing. +therwise return is immediate and following actions <e.g. closing the corresponding model= may fail until printing is complete. Default is false.

The following method uses PrinterDe criptor and Print0ption to print to a special printer8 and preselect the pages to print.
protected$void$printDocComponent(XComponent$)Doc)$t%row $&ava'lang'()ception$* $$$$$$XPrinta.le$)Printa.le$+$ (XPrinta.le)UnoRuntime'5uery1nter4ace(XPrinta.le'cla /$)Doc), $$$$$$PropertyValue67$printerDe c$+$new$PropertyValue687, $$$$$$printerDe c697$+$new$PropertyValue(), $$$$$$printerDe c697':ame$+$3:ame3, $$$$$$printerDe c697'Value$+$3CD$PDF$Creator3,$ $$ $$$$$$)Printa.le' etPrinter(printerDe c),$ $$ $$$$$$PropertyValue67$print0pt $+$new$PropertyValue687, $$$$$$print0pt 697$+$new$PropertyValue(), $$$$$$print0pt 697':ame$+$3Page 3, $$$$$$print0pt 697'Value$+$3A>C/E3,$ $$ $$$$$$)Printa.le'print(print0pt ), $$=

Printing /ultiple P%ges on one P%ge


The interface com.sun.star.te t.APagePrintable is used to print more than one document page to a single printed page.
e5uenceK$comFF unFF tarFF.ean FFPropertyValue$L$getPagePrintSetting () $$void$ etPagePrintSetting ($6in7$ e5uenceK$ comFF unFF tarFF.ean FFPropertyValue$L$aSetting ) $$void$printPage ($6in7$ e5uenceK$comFF unFF tarFF.ean FFPropertyValue$L$ )0ption )

The first two methods getPagePrintSetting () and etPagePrintSetting () control the page printing. They use a se>uence of com.sun.star.beans.PropertyFalues whose possible 5alues are defined in com.sun.star.te t.PagePrintSettings: Properties of co&.sun.st%r.te$t.P%gePrint,ettings com.sun.star.te t.PagePrintSettings:Page-o %ort C 6umber of rows in which document ws pages should appear on the output page.

#$%pter 7 Text Documents

1"

*rinting .ultiple *%ges on one *%ge

com.sun.star.te t.PagePrintSettings:PageCo lumns

%ort C 6umber of columns in which document pages should appear on the output page. com.sun.star.te t.PagePrintSettings:Left(ar long C Left margin on the output page. gin com.sun.star.te t.PagePrintSettings:-ight( long C -ight margin on the output page. argin com.sun.star.te t.PagePrintSettings:Top(ar long C Top margin on the output page. gin com.sun.star.te t.PagePrintSettings:3ottom long C 3ottom margin on the output page. (argin com.sun.star.te t.PagePrintSettings:?ori(a long C (argin between the columns on the rgin output page. com.sun.star.te t.PagePrintSettings:Fert(ar long C (argin between the rows on the gin output page. com.sun.star.te t.PagePrintSettings:0sLands .oolean C Determines if the output page is in cape landscape format.

The method printPage () prints the document according to the pre5ious settings. The argument for the printPage () method may contain the Print0ption as described in the section abo5e <containing the properties CopyCount8 File:ame8 Collate and Page =.

0or1ing .ith e$t Docu&ents

0ord Processing
The te t model in the illustration below shows that wor2ing with te t starts with the method get!e)t() at the X!e)tDocument interface of the document model. 0t returns a com.sun.star.te t.Te t ser5ice that handles te t in +pen+ffice.org. The Te t ser5ice has two mandatory interfaces and no properties:

Service com.sun.star.text.Text (mandatory interfaces only) The X!e)t is used to edit a te t8 and X(numerationAcce is used to iterate o5er te t. The following sections discuss these aspects of the Te t ser5ice.

OpenOffice.org 3.1 Developer's Guide April !!"

/ord *rocessing

!diting e$t
/s pre5iously discussed in the introductory chapter 4irst Steps8 the interface com.sun.star.te t.ATe t incorporates three interfaces: X!e)t8 XSimple!e)t and X!e)tRange. *hen wor2ing with an X!e)t8 you wor2 with the string it contains8 or you insert and remo5e contents other than strings8 such as tables8 te t fields8 and graphics.

,trings
The X!e)t is handled as a whole. There are two possibilities if the te t is handled as one string. The complete string can be set at once8 or strings can be added at the beginning or end of the e isting te t. These are the appropriate methods used for that purpose:
void$ etString($6in7$ tring$te)t)$String$getString()

Consider the following e ample:


"##$Setting$t%e$w%ole$te)t$o4$a$document$a $one$ tring$#"$protected$void$ ;ody!e)t()ample()$*$$$$$""$;ody$!e)t$and$!e)tDocument$e)ample$$$$$try$*$$$$$$$$ ""$demon trate$ imple$te)t$in ertion$$$$$$$$$m)Doc!e)t' etString(3!%i $i $t%e$ new$.ody$te)t$o4$t%e$document'3$$$$$$$$$$$$$$G$3MnMn!%i $i $on$t%e$ econd$ line'MnMn3),$$$$$=$catc%$(()ception$e)$*$$$$$$$$$e'printStac-!race$ (Sy tem'out),$$$$$=$=

3eginning and end of a te t can be determined calling getStart() and get(nd():


comFF unFF tarFFte)tFFX!e)tRange$getStart()$comFF unFF tarFFte)tFFX!e)tRange$ get(nd()

The following e ample adds te t using the start and end range of a te t:
"##$Adding$a$ tring$at$t%e$end$or$t%e$.eginning$o4$te)t$#"$protected$void$ !e)tRange()ample()$*$$$$$try$*$$$$$$$$$""$Ret$a$te)t$range$re4erring$to$t%e$ .eginning$o4$t%e$te)t$document$$$$$$$$$X!e)tRange$)Start$+$ m)Doc!e)t'getStart(),$$$$$$$$$""$u e$ etString$to$in ert$te)t$at$t%e$.eginning$ )Start' etString$(3!%i $i $te)t$in erted$at$t%e$.eginning'MnMn3),$$$$$$$$$""$ Ret$a$te)t$range$re4erring$to$t%e$end$o4$t%e$te)t$document$$$$$$$$$X!e)tRange$ )(nd$+$m)Doc!e)t'get(nd(),$$$$$$$$$""$u e$ etString$to$in ert$te)t$at$t%e$end$$ )(nd' etString$(3!%i $i $te)t$in erted$at$t%e$end'MnMn3),$$$$$=$catc%$ (()ception$e)$*$$$$$$$$$e'printStac-!race(Sy tem'out),$$$$$=$=

The abo5e code is not 5ery fle ible. To gain fle ibility8 create a te t cursor that is a mo5able te t range. 6ote that such a te t cursor is not 5isible in the user interface. The X!e)t creates a cursor that wor2s on the model immediately. The following methods can be used to get as many cursors as re>uired:
comFF unFF tarFFte)tFFX!e)tCur or$create!e)tCur or()$ comFF unFF tarFFte)tFFX!e)tCur or$create!e)tCur or;yRange$($$$$$$$$$$$$$$$$$$$$

#$%pter 7 Text Documents

-trings

comFF unFF tarFFte)tFFX!e)tRange$a!e)tPo ition)

The te t cursor tra5els through the te t as a DcollapsedD te t range with identical start and end as a point in te t8 or it can e pand while it mo5es to contain a target string. This is controlled with the methods of the X!e)tCur or interface:
""$moving$t%e$cur or$""$i4$.()pand$i $true/$t%e$cur or$e)pand $w%ile$it$ travel $.oolean$goLe4t($6in7$ %ort$nCount/$6in7$.oolean$.()pand)$.oolean$ goRig%t($6in7$ %ort$nCount/$6in7$.oolean$.()pand)$void$gotoStart($6in7$.oolean$ .()pand)$void$goto(nd($6in7$.oolean$.()pand)$void$gotoRange($6in7$ comFF unFF tarFFte)tFFX!e)tRange$)Range/$6in7$.oolean$.()pand) ""$controlling$t%e$collap ed$ tatu $o4$t%e$cur or$void$collap e!oStart()$void$ collap e!o(nd()$.oolean$i Collap ed()

0n writer8 a te t cursor has three interfaces that inherit from X!e)tCur or: com.sun.star.te t.A*ordCursor8 com.sun.star.te t.ASentenceCursor and com.sun.star.te t.AParagraphCursor. These interfaces introduce the following additional mo5ements and status chec2s:
.oolean$goto:e)t2ord($6in7$.oolean$.()pand)$.oolean$gotoPreviou 2ord($6in7$ .oolean$.()pand)$.oolean$goto(nd042ord($6in7$.oolean$.()pand)$.oolean$ gotoStart042ord($6in7$.oolean$.()pand)$$.oolean$i Start042ord()$.oolean$ i (nd042ord() .oolean$goto:e)tSentence($6in7$.oolean$()pand)$.oolean$ gotoPreviou Sentence($6in7$.oolean$()pand)$.oolean$gotoStart04Sentence($6in7$ .oolean$()pand)$.oolean$goto(nd04Sentence($6in7$.oolean$()pand)$$.oolean$ i Start04Sentence()$.oolean$i (nd04Sentence() .oolean$gotoStart04Paragrap%($6in7$.oolean$.()pand)$.oolean$ goto(nd04Paragrap%($6in7$.oolean$.()pand)$.oolean$goto:e)tParagrap%($6in7$ .oolean$.()pand)$.oolean$gotoPreviou Paragrap%($6in7$.oolean$.()pand)$$.oolean$ i Start04Paragrap%()$.oolean$i (nd04Paragrap%()

Since X!e)tCur or inherits from X!e)tRange8 a cursor is an X!e)tRange and incorporates the methods of an X!e)tRange:
comFF unFF tarFFte)tFFX!e)t$get!e)t()$comFF unFF tarFFte)tFFX!e)tRange$ getStart()$comFF unFF tarFFte)tFFX!e)tRange$get(nd()$ tring$getString()$void$ etString($6in7$ tring$aString)

The cursor can be told where it is re>uired and the string content can be set later. This does ha5e a drawbac2. /fter setting the string8 the inserted string is always selected. That means further te t can not be added without mo5ing the cursor again. Therefore the most fle ible method to insert strings by means of a cursor is the method in ertString() in X!e)t. 0t ta2es an X!e)tRange as the target range that is replaced during insertion8 a string to insert8 and a boolean parameter that determines if the inserted te t should be absorbed by the cursor after it has been inserted. The X!e)tRange could be any X!e)tRange. The X!e)tCur or is an X!e)tRange8 so it is used here:
void$in ertString($6in7$comFF unFF tarFFte)tFFX!e)tRange$)Range/$$$$$$$$$$$$$$$ 6in7$ tring$aString/$$$$$$$$$$$$$$$$$$$$$6in7$.oolean$.A. or.)

To insert te t se>uentially the .A. or. parameter must be set to false8 so that the X!e)tRange$ collapses at the end of the inserted string after insertion. 0f .A. or. is true8 the te t range

OpenOffice.org 3.1 Developer's Guide April !!"

-trings

selects the new inserted string. The string that was selected by the te t range prior to insertion is deleted. Consider the use of in ertString() below:
"##$moving$a$te)t$cur or/$ electing$te)t$and$overwriting$it$#"$protected$void$ !e)tCur or()ample()$*$$$$$try$*$$$$$$$$$""$Fir t/$get$t%e$XSentenceCur or$ inter4ace$o4$our$te)t$cur or$$$$$$$$$XSentenceCur or$)SentenceCur or$+$ (XSentenceCur or)UnoRuntime'5uery1nter4ace($$$$$$$$$$$$$XSentenceCur or'cla /$ m)DocCur or), ""$Roto$t%e$ne)t$cur or/$wit%out$ electing$it$$$$$$$$$ )SentenceCur or'goto:e)tSentence(4al e), ""$Ret$t%e$X2ordCur or$inter4ace$o4$our$te)t$cur or$$$$$$$$$X2ordCur or$ )2ordCur or$+$(X2ordCur or)$ UnoRuntime'5uery1nter4ace($$$$$$$$$$$$$X2ordCur or'cla /$m)DocCur or), ""$S-ip$t%e$4ir t$4our$word $o4$t%i $ entence$and$ elect$t%e$4i4t%$$$$$$$$$ )2ordCur or'goto:e)t2ord(4al e),$$$$$$$$$)2ordCur or'goto:e)t2ord(4al e),$$$$$$ )2ordCur or'goto:e)t2ord(4al e),$$$$$$$$$)2ordCur or'goto:e)t2ord(4al e),$$$$$$ )2ordCur or'goto:e)t2ord(true), ""$U e$t%e$XSimple!e)t$inter4ace$to$in ert$a$word$at$t%e$current$cur or$$$$$$$$ ""$location/$over>writing$$$$$$$$$""$t%e$current$ election$(t%e$4i4t%$word$ elected$a.ove)$$$$$$$$$m)Doc!e)t'in ertString()2ordCur or/$3old$3/$true), ""$Acce $t%e$property$ et$o4$t%e$cur or/$and$ et$t%e$currently$ elected$te)t$$ ""$(w%ic%$i $t%e$ tring$we$&u t$in erted)$to$.e$.old$$$$$$$$$XPropertySet$ )Cur orProp $+$(XPropertySet)$ UnoRuntime'5uery1nter4ace($$$$$$$$$$$$$XPropertySet'cla /$m)DocCur or),$$$$$$$ )Cur orProp ' etPropertyValue(3C%ar2eig%t3/$new$ Float(com' un' tar'awt'Font2eig%t';0LD)), ""$replace$t%e$S'S$at$t%e$end$o4$t%e$ entence$wit%$a$new$ tring$$$$$$$$$ )SentenceCur or'goto(nd04Sentence(4al e),$$$$$$$$$ )2ordCur or'gotoPreviou 2ord(true),$$$$$$$$$ m)Doc!e)t'in ertString()2ordCur or/$$$$$$$$$$$$$$3/$w%ic%$%a $.een$c%anged$ wit%$te)t$cur or J3/$true),$$$$$=$catc%$(()ception$e)$ *$$$$$$$$$e'printStac-!race(Sy tem'out),$$$$$=$=

e$t Contents Other h%n ,trings


Bp to this point8 we ha5e discussed paragraphs made up of character strings. Te t can also contain other ob:ects besides character strings in paragraphs. They all support the interface com.sun.star.te t.ATe tContent. 0n fact8 e5erything in te ts must support X!e)tContent. / te t content is an ob:ect that is attached to a com.sun.star.te t.ATe t-ange. The te t range it is attached to is called the anchor of the te t content. /ll te t contents mentioned below8 starting with tables8 support the ser5ice com.sun.star.te t.Te tContent. 0t includes the interface com.sun.star.te t.ATe tContent that inherits from the interface com.sun.star.lang.AComponent. The !e)tContent ser5ices may

#$%pter 7 Text Documents

Text #ontents Ot$er T$%n -trings

ha5e the following properties: Properties of co&.sun.st%r.te$t. e$tContent com.sun.star.te t.Te tContent:/nchorType Describes the base the ob:ect is positioned to8 according to com.sun.star.te t.Te tContent/nchorType. com.sun.star.te t.Te tContent:/nchorType / se>uence of s com.sun.star.te t.Te tContent/nchorType that contains all allowed anchor types for the ob:ect. com.sun.star.te t.Te tContent:Te t*rap Determines the way the surrounding te t flows around the ob:ect8 according to com.sun.star.te t.*rapTe t(ode. The method di po e() of the XComponent interface deletes the ob:ect from the document. Since a te t content is an XComponent8 com.sun.star.lang.A$5entListener can be added or remo5ed with the methods add(ventLi tener() and remove(ventLi tener(). These methods are called bac2 when the ob:ect is disposed. +ther e5ents are not supported. The method getAnc%or() at the X!e)tContent interface returns a te t range which reflects the te t position where the ob:ect is located. This method may return a 5oid ob:ect8 for e ample8 for te t frames that are bound to a page. The method getAnc%or() is used in situations where an X!e)tRange is re>uired. 4or instance8 placeholder fields <com.sun.star.te t.te tfield.&ump$dit= can be filled out using their getAnc%or() method. /lso8 you can get a boo2mar28 retrie5e its X!e)tRange from getAnc%or() and use it to insert a string at the boo2mar2 position. The method attac%() is an intended method to attach te t contents to the document8 but it is currently not implemented. /ll te t contents C including paragraphs C can be created by the ser5ice manager of the document. They are created using the factory methods create1n tance() or create1n tance2it%Argument () at the com.sun.star.lang.A(ultiSer5ice4actory interface of the document. /ll te t contents C except for paragraphs C can be inserted into te t using the com.sun.star.te t.ATe t method in ert!e)tContent(). They can be remo5ed by calling remove!e)tContent(). Starting with the section Tables8 there are code samples showing the usage of the document ser5ice manager with in ert!e)tContent().
void$in ert!e)tContent($6in7$comFF unFF tarFFte)tFFX!e)tRange$)Range/$$$$$$$$$$ 6in7$comFF unFF tarFFte)tFFX!e)tContent$)Content/$.oolean$.A. or.),$void$ remove!e)tContent($6in7$comFF unFF tarFFte)tFFX!e)tContent$)Content)

Paragraphs cannot be inserted by in ert!e)tContent(). +nly the interface XRelative!e)tContent1n ert can insert paragraphs. / paragraph created by the ser5ice manager can be used for creating a new paragraph before or after a table8 or a te t section

&

OpenOffice.org 3.1 Developer's Guide April !!"

Text #ontents Ot$er T$%n -trings

positioned at the beginning or the end of page where no cursor can insert new paragraphs. Cf. the section 0nserting a Paragraph where no Cursor can go below.

Control Ch%r%cters
*e ha5e used &a5a escape se>uences for paragraph brea2s8 but this may not be feasible in e5ery language. (oreo5er8 +pen+ffice.org supports a number of control characters that can be used. There are two possibilities: use the method
void$in ertControlC%aracter($6in7$comFF unFF tarFFte)tFFX!e)tRange$)Range/$$$$$ 6in7$ %ort$nControlC%aracter/$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$6in7$.oolean$ .A. or.)

to insert single control characters as defined in the constants group com.sun.star.te t.ControlCharacter8 or use the corresponding unicode character from the following list as escape se>uence in a string if your language supports it. 0n &a5a8 Bnicode characters in strings can be incorporated using the Mu???? escape se>uence8 where ? represents a he adecimal digit
PARARRAP?<;R(AT L1:(<;R(AT ?ARD<?UP?(: S0F!<?UP?(: ?ARD<SPAC( APP(:D<PARARRAP?

0nsert a paragraph brea2 <U:1C0D($9)999D=. 0nserts a line brea2 inside of the paragraph <U:1C0D($9)999A=. / character that appears li2e a dash8 but pre5ents hyphenation at its position <U:1C0D($9)P988=. (ar2s a preferred position for hyphenation <U:1C0D($9)99AD=. / character that appears li2e a space8 but pre5ents hyphenation at this point <U:1C0D($9)99A9=. / new paragraph is appended <no B60C+D$ for this function=.

The section 4ormatting describes how page brea2s are created by setting certain paragraph properties.

2ter%ting over e$t


The second interface of com.sun.star.te t.Te t is X(numerationAcce . / Te t ser5ice enumerates all paragraphs in a te t and returns ob:ects which support com.sun.star.te t.Paragraph. This includes tables8 because writer sees tables as speciali9ed paragraphs that support the com.sun.star.te t.Te tTable ser5ice. Paragraphs also ha5e an com.sun.star.container.A$numeration/ccess of their own. They can enumerate e5ery single te t portion that they contain. / te t portion is a te t range containing

#$%pter 7 Text Documents

#ontrol #$%r%cters

a uniform piece of information that appears within the te t flow. /n ordinary paragraph8 formatted in a uniform manner and containing nothing but a string8 enumerates :ust a single te t portion. 0n a paragraph that has specially formatted words or other contents8 the te t portion enumeration returns one com.sun.star.te t.Te tPortion ser5ice for each differently formatted string8 and for e5ery other te t content. Te t portions include the ser5ice com.sun.star.te t.Te t-ange and ha5e the properties listed below: Properties of co&.sun.st%r.te$t. e$tPortion com.sun.star.te t.Te tPortion:Te tPortio tring C Contains the type of the te t portion nType <see below=. com.sun.star.te t.Te tPortion:ControlCh %ort C -eturns the control character if the te t aracter portion contains a control character as defined in com.sun.star.te t.ControlCharacter . com.sun.star.te t.Te tPortion:3oo2mar2 com.sun.star.te t.ATe tContent . Contains the boo2mar2 if the portion has Te tPortionTypeGD3oo2mar2D. com.sun.star.te t.Te tPortion:0sCollapse .oolean C Determines whether the portion is a d point only. com.sun.star.te t.Te tPortion:0sStart .oolean C Determines whether the portion is a start portion if two portions are needed to include an ob:ect8 that is8 Document1nde)Mar-. Possible Falues for !e)tPortion!ype are: e$tPortion ype 3,tring4 DTe tD DTe t4ieldD DTe tContentD D4ootnoteD DControlCharacterD D-eference(ar2D DDocument0nde (ar2D D3oo2mar2D D-edlineD D-ubyD Description a portion with mere string content / com.sun.star.te t.Te t4ield content. / te t content supplied through the interface XContent(numerationAcce . / footnote or an endnote. / control character. / reference mar2. / document inde mar2. / boo2mar2. / redline portion which is a result of the change trac2ing feature. / ruby attribute which is used in /sian te t.

The te t portion enumeration of a paragraph does not supply contents which do belong to the paragraph8 but do not fuse together with the te t flow. These could be te t frames8 graphic ob:ects8 embedded ob:ects or drawing shapes anchored at the paragraph8 characters or as character. The !e)tPortion!ype D!e)tContentD indicate if there is a content anchored at a character or as a character. 0f you ha5e a !e)tContent portion type8 you 2now that there are shape ob:ects anchored at a character or as a character.

OpenOffice.org 3.1 Developer's Guide April !!"

#ontrol #$%r%cters

This last group of data contained in a te t8 Paragrap% and !e)tPortion in writer support the interface com.sun.star.container.AContent$numeration/ccess. This interface tells which te t contents other than the te t flow contents e ist8 and supplies them as an com.sun.star.container.A$numeration:
e5uenceK$ tring$L$getAvaila.leService:ame ()$ comFF unFF tarFFcontainerFFX(numeration$createContent(numeration($6in7$ tring$ aService:ame)

The XContent(numerationAcce of the paragraph lists the shape ob:ects anchored at the paragraph while the XContent(numerationAcce of a te t portion lists the shape ob:ects anchored at a character or as a character. Note Precisely the same enumerations are a5ailable for the current te t cursor selection. The te t cursor enumerates paragraphs8 te t portions and te t contents :ust li2e the ser5ice com.sun.star.te t.Te t itself. The enumeration access to te t through paragraphs and te t portions is used if e5ery single paragraph in a te t needs to be touched. The application area for this enumeration are e port filters8 that uses this enumeration to go o5er the whole document8 writing out the paragraphs to the target file. The following code snippet centers all paragraphs in a te t.
"##$!%i $met%od$demon trate $%ow$to$iterate$over$paragrap% $#"$protected$void$ Paragrap%()ample$()$*$$$$$try$*$$$$$$$$$""$!%e$ ervice$ Scom' un' tar'te)t'!e)tS$ upport $t%e$X(numerationAcce $inter4ace$ to$$$$$$$$$""$provide$an$enumeration$$$$$$$$$""$o4$t%e$paragrap% $contained$.y$ t%e$te)t$t%e$ ervice$re4er $to' ""$?ere/$we$acce $t%i $inter4ace$$$$$$$$$X(numerationAcce $)ParaAcce $+$ (X(numerationAcce )$ UnoRuntime'5uery1nter4ace($$$$$$$$$$$$$X(numerationAcce 'cla /$m)Doc!e)t),$$$ ""$Call$t%e$X(numerationAcce S $only$met%od$to$acce $t%e$actual$(numeration$$ X(numeration$)Para(num$+$)ParaAcce 'create(numeration(), ""$2%ile$t%ere$are$paragrap% /$do$t%ing $to$t%em$$$$$$$$$w%ile$ ()Para(num'%a More(lement ())$*$$$$$$$$$$$$$""$Ret$a$re4erence$to$t%e$ne)t$ paragrap% $XService1n4o$inter4ace'$!e)t!a.le $$$$$$$$$$$$$""$are$al o$part$o4$ t%i $$$$$$$$$$$$$""$enumeration$acce /$ o$we$a -$t%e$element$i4$it$i $a$ !e)t!a.le/$i4$it$$$$$$$$$$$$$""$doe nSt$ upport$t%e$$$$$$$$$$$$$""$ com' un' tar'te)t'!e)t!a.le$ ervice/$t%en$it$i $ a4e$to$a ume$t%at$it$$$$$$$$$ ""$really$i $a$paragrap%$$$$$$$$$$$$$XService1n4o$)1n4o$+$(XService1n4o)$ UnoRuntime'5uery1nter4ace($$$$$$$$$$$$$$$$$XService1n4o'cla /$ )Para(num'ne)t(lement()),$$$$$$$$$$$$$i4$(J )1n4o' upport Service(3com' un' tar'te)t'!e)t!a.le3))$*$$$$$$$$$$$$$$$$$""$ Acce $t%e$paragrap%S $property$ et'''t%e$propertie $in$ t%i $$$$$$$$$$$$$$$$$""$property$ et$are$li ted$$$$$$$$$$$$$$$$$""$inF$ com' un' tar' tyle'Paragrap%Propertie $$$$$$$$$$$$$$$$$XPropertySet$)Set$+$ (XPropertySet)$ UnoRuntime'5uery1nter4ace($$$$$$$$$$$$$$$$$$$$$XPropertySet'cla /$)1n4o),$$$$$ ""$Set$t%e$&u ti4ication$to$.e$center$&u ti4ied$$$$$$$$$$$$$$$$$ )Set' etPropertyValue(3ParaAd&u t3/$ com' un' tar' tyle'Paragrap%Ad&u t'C(:!(R),$$$$$$$$$$$$$=$$$$$$$$$=$$$$$=$ catc%$(()ception$e)$*$$$$$$$$$e'printStac-!race$(Sy tem'out),$$$$$=$=

#$%pter 7 Text Documents

#ontrol #$%r%cters

2nserting % P%r%gr%ph .here no Cursor c%n go


The ser5ice com.sun.star.te t.Te t has an optional interface com.sun.star.te t.A-elati5eTe tContent0nsert which is a5ailable in Te t ser5ices in writer. The intention of this interface is to insert paragraphs in positions where no cursor or te t portion can be located to use the in ert!e)tContent() method. These situation occurs when te t sections or te t tables are at the start or end of the document8 or if they follow each other directly.
void$in ert!e)tContent;e4ore($6in7$comFF unFF tarFFte)tFFX!e)tContent$ ):ewContent/$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$6in7$ comFF unFF tarFFte)tFFX!e)tContent$)Succe or)$$void$ in ert!e)tContentA4ter($6in7$comFF unFF tarFFte)tFFX!e)tContent$):ewContent/$$$ 6in7$comFF unFF tarFFte)tFFX!e)tContent$)Predece or)

The only supported te t contents are com.sun.star.te t.Paragraph as new content8 and com.sun.star.te t.Te tSection and com.sun.star.te t.Te tTable as successor or predecessor.

,orting e$t
0t is possible to sort te t or the content of te t tables. Sorting of te t is done by the te t cursor that supports com.sun.star.util.ASortable. 0t contains two methods:
e5uenceK$comFF unFF tarFF.ean FFPropertyValue$L$createSortDe criptor()$void$ ort($6in7$ e5uenceK$comFF unFF tarFF.ean FFPropertyValue$L$)De criptor)

The method createSortDe criptor() returns a se>uence of com.sun.star.beans.PropertyFalue that pro5ides the elements as described in the ser5ice com.sun.star.te t.Te tSortDescriptor. The method ort() sorts the te t that is selected by the cursor8 by the gi5en parameters. Sorting of tables happens directly at the table ser5ice8 which supports XSorta.le. Sorting is a common feature of +pen+ffice.org and it is described in detail in +ffice De5elopment.

2nserting e$t (iles


The te t cursor in writer supports the interface com.sun.star.document.ADocument0nsertable
8 OpenOffice.org 3.1 Developer's Guide April !!"

#ontrol #$%r%cters

which has a single method to insert a file at the current cursor position:
void$in ertDocumentFromURL($6in7$ tring$aURL/$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ 6in7$ e5uenceK$comFF unFF tarFF.ean FFPropertyValue$L$a0ption )

Pass a B-L and an empty se>uence of PropertyValue structs. ?owe5er8 load properties could be used as described in com.sun.star.document.(ediaDescriptor.

Auto e$t
The auto te t function can be used to organi9e reusable te t passages. They allow storing te t8 including the formatting and all other contents in a te t bloc2 collection to apply them later. Three ser5ices deal with auto te t in +pen+ffice.org:

com.sun.star.te t./utoTe tContainer specifies the entire collection of auto te ts com.sun.star.te t./utoTe t7roup describes a category of auto te ts com.sun.star.te t./utoTe t$ntry is a single auto te t.

"##$1n ert$an$autote)t$at$t%e$current$cur or$po ition$o4$given$cur or$ m)DocCur or#" ""$Ret$an$X:ameAcce $inter4ace$to$all$auto$te)t$group $4rom$t%e$document$ 4actory$X:ameAcce $)Container$+$(X:ameAcce )$UnoRuntime'5uery1nter4ace($$$$$$ X:ameAcce 'cla /$ m)Factory'create1n tance(3com' un' tar'te)t'Auto!e)tContainer3)), ""$Ret$t%e$autote)t$group$Standard$)Rroup$+$(XAuto!e)tRroup)$ UnoRuntime'5uery1nter4ace($$$$$XAuto!e)tRroup'cla /$ )Container'get;y:ame(3Standard3)), ""$get$t%e$entry$;e t$2i %e $(;2)$XAuto!e)t(ntry$)(ntry$+$ (XAuto!e)t(ntry)UnoRuntime'5uery1nter4ace$($$$$$$XAuto!e)t(ntry'cla /$ )Rroup'get;y:ame$(3;23)), ""$in ert$t%e$modi4ied$autote)t$.loc-$at$t%e$cur or$po ition$ )(ntry'apply!o(m)DocCur or), "##$Add$a$new$autote)t$entry$to$t%e$Auto!e)tContainer$$#"$""$Select$t%e$la t$ paragrap%$in$t%e$document$)ParaCur or'gotoPreviou Paragrap%(true), ""$Ret$t%e$XAuto!e)tContainer$inter4ace$o4$t%e$Auto!e)tContainer$ ervice$ XAuto!e)tContainer$)Auto!e)tCont$+$(XAuto!e)tContainer)$ UnoRuntime'5uery1nter4ace($$$$$XAuto!e)tContainer'cla /$)Container$), ""$14$t%e$AP1()ampleRroup$already$e)i t /$remove$it$ o$we$can$add$a$new$one$i4$ ()Container'%a ;y:ame(3AP1()ampleRroup3))$$$$$ )Auto!e)tCont'remove;y:ame(3AP1()ampleRroup3$), ""$Create$a$new$auto>te)t$group$called$AP1()ampleRroup$XAuto!e)tRroup$ ):ewRroup$+$)Auto!e)tCont'in ert:ew;y:ame$($3AP1()ampleRroup3$), ""$Create$and$in ert$a$new$auto$te)t$entry$containing$t%e$current$cur or$ election$XAuto!e)t(ntry$):ew(ntry$+$):ewRroup'in ert:ew;y:ame($$$$$3:A(3/$ 3:ew$Auto!e)t(ntry3/$)ParaCur or), ""$Ret$t%e$XSimple!e)t$and$X!e)t$inter4ace $o4$t%e$new$autote)t$.loc-$ XSimple!e)t$)Simple!e)t$+$(XSimple!e)t)$ UnoRuntime'5uery1nter4ace($$$$$XSimple!e)t'cla /$):ew(ntry),$$$$$$$$$X!e)t$

#$%pter 7 Text Documents

"

#ontrol #$%r%cters

)!e)t$+$(X!e)t)$UnoRuntime'5uery1nter4ace(X!e)t'cla /$):ew(ntry), ""$1n ert$a$ tring$at$t%e$.eginning$o4$t%e$autote)t$.loc-$ )Simple!e)t'in ertString()!e)t'getStart()/$$$$$$3!%i $ tring$wa $in erted$ u ing$t%e$AP1JMnMn3/$4al e),

The current implementation forces the user to close the Auto!e)t(ntry instance when they are changed8 so that the changes can ta2e effect. ?owe5er8 the new Auto!e)t is not written to dis2 until the destructor of the Auto!e)t(ntry instance inside the writer is called. *hen this e ample has finished e ecuting8 the file on dis2 correctly contains the complete te t D !%i $ tring$wa $in erted$u ing$t%e$AP1JMnMnSome$te)t$4or$a$new$autote)t$.loc- D8 but there is no way in &a5a to call the destructor. 0t is not clear when the garbage collector deletes the ob:ect and writes the modifications to dis2.

(or&%tting
/ multitude of character8 paragraph and other properties are a5ailable for te t in +pen+ffice.org. ?owe5er8 the ob:ects implemented in the writer do not pro5ide properties that support com.sun.star.beans.APropertyChangeListener or com.sun.star.beans.AFetoableChangeListener yet. Character and paragraph properties are a5ailable in the following ser5ices: ,ervices supporting Ch%r%cter %nd P%r%gr%ph Properties com.sun.star.te t.Te tCursor com.sun.star.te t.Paragraph com.sun.star.te t.Te tPortion com.sun.star.te t.Te tTableCursor com.sun.star.te t.Shape com.sun.star.table.Cell-ange com.sun.star.te t.Te tDocument "e&%r1 0f collapsed8 the C%aracterPropertie refer to the position on the right hand side of the cursor.

0n te t tables. The model offers a selected number of character properties which apply to the entire document. These are: C%arFont:ame8 C%arFontStyle:ame8 C%arFontFamily8 C%arFontC%arSet8 C%arFontPitc% and their /sian counterparts C%arFontStyle:ameA ian8 C%arFontFamilyA ian8 C%arFontC%arSetA ian8 C%arFontPitc%A ian.

The character properties are described in the ser5ices com.sun.star.style.CharacterProperties8 com.sun.star.style.CharacterProperties/sian and com.sun.star.style.CharacterPropertiesComple .

3!

OpenOffice.org 3.1 Developer's Guide April !!"

#ontrol #$%r%cters

com.sun.star.style.CharacterProperties describes common character properties for all language 9ones and character properties in *estern te t. The following table pro5ides possible 5alues. Properties of co&.sun.st%r.style.Ch%r%cterProperties com.sun.star.style.CharacterProperties: tring C This property specifies the name of the Char4ont6ame font in western te t. com.sun.star.style.CharacterProperties: tring C This property contains the name of the Char4ontStyle6ame font style. com.sun.star.style.CharacterProperties: %ort C This property contains font family that is Char4ont4amily specified in com.sun.star.awt.4ont4amily . Possible 5alues are: D+6T;6+*8 D$C+-/T0F$8 (+D$-68 -+(/68 SC-0PT8 S*0SS8 and SHST$(. com.sun.star.style.CharacterProperties: %ort C This property contains the te t encoding Char4ontCharSet of the font that is specified in com.sun.star.awt.CharSet . Possible 5alues are: D+6T;6+*8 /6S0 (/C8 03(PCI".%8 03(PCI',)8 03(PCI'#)8 03(PCI'#!8 03(PCI'#.8 03(PCI'#,8 and SHST$( SH(3+L. com.sun.star.style.CharacterProperties: %ort C This property contains the font pitch that Char4ontPitch is specified in com.sun.star.awt.4ontPitch . The word font pitch refers to characters per inch8 but the possible 5alues are D+6T;6+*8 40A$D and F/-0/3L$. F/-0/3L$ points to the difference between proportional and unproportional fonts. com.sun.star.style.CharacterProperties: long C This property contains the 5alue of the te t CharColor color in /-73 notation. /-73 has four bytes denoting alpha8 red8 green and blue. 0n he notation8 this can be used con5eniently: 9)AARRRR;;. The // </lpha= can be )) or left out. com.sun.star.style.CharacterProperties: 6optional7$ %ort C Property which contains the Char$scapement relati5e 5alue of the character height in subscription or superscription. com.sun.star.style.CharacterProperties: 4loat C This 5alue contains the height of the Char?eight characters in point. com.sun.star.style.CharacterProperties: %ort C This property contains the 5alue for the CharBnderline character underline that is specified in com.sun.star.awt.4ontBnderline . / lot of underline types are a5ailable. Some possible 5alues are S067L$8 D+B3L$8 and D+TT$D.
#$%pter 7 Text Documents 31

#ontrol #$%r%cters

com.sun.star.style.CharacterProperties: Char*eight

4loat C This property contains the 5alue of the

com.sun.star.style.CharacterProperties: CharPosture

com.sun.star.style.CharacterProperties: Char/uto;erning com.sun.star.style.CharacterProperties: Char3ac2Color com.sun.star.style.CharacterProperties: Char3ac2Transparent com.sun.star.style.CharacterProperties: CharCase(ap

com.sun.star.style.CharacterProperties: CharCrossed+ut com.sun.star.style.CharacterProperties: Char4lash com.sun.star.style.CharacterProperties: CharStri2eout

com.sun.star.style.CharacterProperties: Char*ord(ode com.sun.star.style.CharacterProperties: Char;erning com.sun.star.style.CharacterProperties: CharLocale com.sun.star.style.CharacterProperties: Char;eepTogether

font weight8 cf. J com.sun.star.awt.4ont*eight . / lot of weights are possible. The common ones are 3+LD and 6+-(/L. long C This property contains the posture of the font as defined in com.sun.star.awt.4ontSlant . The most common 5alues are 0T/L0C and 6+6$. 6optional7$.oolean C Property to determine whether the 2erning tables from the current font are used. 6optional7$long C Property which contains the te t bac2ground color in ARR;F$9)AARRRR;;. 6optional7$.oolean C Determines if the te t bac2ground color is set to transparent. 6optional7$ %ort C Property which contains the 5alue of the caseCmapping of the te t for formatting and displaying. Possible Case(aps are 6+6$8 BPP$-C/S$8 L+*$-C/S$8 T0TL$8 and S(/LLC/PS as defined in the constants group com.sun.star.style.Case(ap . <optional= 6optional7$.oolean C This property is true if the characters are crossed out. 6optional7$.oolean C 0f this optional property is true 8 then the characters are flashing 6optional7$ %ort C Determines the type of the stri2ethrough of the character as defined in com.sun.star.awt.4ontStri2eout . Falues are 6+6$8 S067L$8 D+B3L$8 D+6T;6+*8 3+LD8 and SL/S? A. 6optional7$.oolean C 0f this property is true 8 the underline and stri2eCthrough properties are not applied to white spaces. 6optional7$ %ort C Property which contains the 5alue of the 2erning of the characters.
truct

com.sun.star.lang.Locale . Contains the locale <language and country= of the characters. 6optional7$.oolean C Property which mar2s a range of characters to pre5ent it from being

OpenOffice.org 3.1 Developer's Guide April !!"

#ontrol #$%r%cters

bro2en into two lines. com.sun.star.style.CharacterProperties: Char6oLine3rea2 com.sun.star.style.CharacterProperties: CharShadowed com.sun.star.style.CharacterProperties: Char4ontType
6optional7$.oolean C Property which mar2s a

com.sun.star.style.CharacterProperties: CharStyle6ame com.sun.star.style.CharacterProperties: CharContoured com.sun.star.style.CharacterProperties: CharCombine0s+n com.sun.star.style.CharacterProperties: CharCombinePrefi com.sun.star.style.CharacterProperties: CharCombineSuffi com.sun.star.style.CharacterProperties: Char$mphasis com.sun.star.style.CharacterProperties: Char-elief com.sun.star.style.CharacterProperties: -ubyTe t com.sun.star.style.CharacterProperties: -uby/d:ust com.sun.star.style.CharacterProperties: -ubyCharStyle6ame com.sun.star.style.CharacterProperties: -uby0s/bo5e com.sun.star.style.CharacterProperties: Char-otation com.sun.star.style.CharacterProperties: Char-otation0s4itToLine

range of characters to ignore a line brea2 in this area. 6optional7$.oolean C True if the characters are formatted and displayed with a shadow effect. <optional= 6optional7$ %ort C Property which specifies the fundamental technology of the font as specified in com.sun.star.awt.4ontType . Possible 5alues are D+6T;6+*8 -/ST$-8 D$F0C$8 and SC/L/3L$. 6optional7$ tring C Specifies the name of the style of the font. 6optional7$.oolean C True if the characters are formatted and displayed with a contour effect. 6optional7$.oolean C True if te t is formatted in two lines. 6optional7$ tring C Contains the prefi string <usually parenthesis= before te t that is formatted in two lines. 6optional7$ tring C Contains the suffi string <usually parenthesis= after te t that is formatted in two lines. 6optional7$ %ort C Contains the font emphasis 5alue com.sun.star.te t.4ont$mphasis . 6optional7$ %ort C Contains the relief 5alue as 4ont-elief. 6optional7$ tring C Contains the te t that is set as ruby. 6optional7$ %ort C Determines the ad:ustment of the ruby te t as -uby/d:ust. 6optional7$ tring C Contains the name of the character style that is applied to -ubyTe t <optional=. 6optional7$.oolean C Determines whether the ruby te t is printed abo5e/left or below/right of the te t <optional= . 6optional7$ %ort C Determines the rotation of a character in degree. 6optional7$ %ort C Determines whether the te t formatting tries to fit rotated te t into the

#$%pter 7 Text Documents

33

#ontrol #$%r%cters

com.sun.star.style.CharacterProperties: CharScale*idth com.sun.star.style.CharacterProperties: ?yperLin2B-L com.sun.star.style.CharacterProperties: ?yperLin2Target com.sun.star.style.CharacterProperties: ?yperLin26ame com.sun.star.style.CharacterProperties: FisitedCharStyle6ame com.sun.star.style.CharacterProperties: Bn5isitedCharStyle6ame com.sun.star.style.CharacterProperties: Char$scapement?eight

com.sun.star.style.CharacterProperties: Char6o?yphenation com.sun.star.style.CharacterProperties: CharBnderlineColor com.sun.star.style.CharacterProperties: CharBnderline?asColor com.sun.star.style.CharacterProperties: CharStyle6ames com.sun.star.style.CharacterProperties: Char?idden com.sun.star.style.CharacterProperties: Te tBserDefined/ttributes

surrounded line height. 6optional7$ %ort C Determines the percentage 5alue of scaling of characters. 6optional7$ tring C contains the B-L of a hyperlin2 if the B-L is set. 6optional7$ tring C contains the name of the target for a hyperlin2 if the target is set. 6optional7$ tring C contains the name of the hyperlin2 if the name is set. 6optional7$ tring C Contains the character style name for 5isited hyperlin2s. 6optional7$ tring C Contains the character style name for un5isited hyperlin2s. 6optional7$.yte C This is the additional height used for subscript or superscript characters in units of percent. 4or subscript characters the 5alue is negati5e and for superscript characters positi5e. 6optional7$.oolean C True if the word can be hyphenated at the character. com.sun.star.util.Color C 7i5es the color of the underline for that character. .oolean C True if the CharunderlineColor is used for an underline 6optional7$ e5uenceK tringL C specifies the names of the all styles applied to the font. 6optional7$.oolean C True if the characters are in5isible
6optional7

com.sun.star.container.A6ameContainer C This property stores ml attributes. They will be sa5ed to and restored from automatic styles inside ml files.

com.sun.star.style.CharacterProperties/sian describes properties used in /sian te t. /ll of these properties ha5e a counterpart in C%aracterPropertie . They apply as soon as a te t is recogni9ed as /sian by the employed Bnicode character subset. Properties of co&.sun.st%r.style.Ch%r%cterPropertiesAsi%n com.sun.star.style.CharacterProperties/s 4loat C This 5alue contains the height of the ian:Char?eight/sian characters in point. com.sun.star.style.CharacterProperties/s 4loat C This property contains the 5alue of the ian:Char*eight/sian font weight. com.sun.star.style.CharacterProperties/s tring C This property specifies the name of ian:Char4ont6ame/sian the font style. com.sun.star.style.CharacterProperties/s tring C This property contains the name of the

3&

OpenOffice.org 3.1 Developer's Guide April !!"

#ontrol #$%r%cters

ian:Char4ontStyle6ame/sian com.sun.star.style.CharacterProperties/s ian:Char4ont4amily/sian com.sun.star.style.CharacterProperties/s ian:Char4ontCharSet/sian com.sun.star.style.CharacterProperties/s ian:Char4ontPitch/sian com.sun.star.style.CharacterProperties/s ian:CharPosture/sian com.sun.star.style.CharacterProperties/s ian:CharLocale/sian

font style. %ort C This property contains the font family that is specified in com.sun.star.awt.4ont4amily. %ort C This property contains the te t encoding of the font that is specified in com.sun.star.awt.CharSet. %ort C This property contains the font pitch that is specified in com.sun.star.awt.4ontPitch. long C This property contains the 5alue of the posture of the font as defined in com.sun.star.awt.4ontSlant. struct com.sun.star.lang.Locale C Contains the 5alue of the locale.

The comple properties com.sun.star.style.CharacterPropertiesComple refer to the same character settings as in C%aracterPropertie A ian8 only they ha5e the suffi DComple D instead of D/sianD. com.sun.star.style.ParagraphPropertiescomprises paragraph properties. Properties of co&.sun.st%r.style.P%r%gr%phProperties com.sun.star.style.ParagraphProperties:P long C Determines the ad:ustment of a ara/d:ust paragraph. com.sun.star.style.ParagraphProperties:P 6optional7 struct araLineSpacing com.sun.star.style.LineSpacing C Determines the line spacing of a paragraph. com.sun.star.style.ParagraphProperties:P 6optional7$long C Contains the paragraph ara3ac2Color bac2ground color. com.sun.star.style.ParagraphProperties:P 6optional7$.oolean C This 5alue is true if the ara3ac2Transparent paragraph bac2ground color is set to transparent. com.sun.star.style.ParagraphProperties:P 6optional7$ tring C Contains the 5alue of a ara3ac27raphicB-L lin2 for the bac2ground graphic of a paragraph. com.sun.star.style.ParagraphProperties:P 6optional7$ tring C Contains the name of ara3ac27raphic4ilter the graphic filter for the bac2ground graphic of a paragraph. com.sun.star.style.ParagraphProperties:P 6optional7$long C Contains the 5alue for the ara3ac27raphicLocation position of a bac2ground graphic according to com.sun.star.style.7raphicLocation. com.sun.star.style.ParagraphProperties:P %ort C Determines the ad:ustment of the last araLastLine/d:ust line. com.sun.star.style.ParagraphProperties:P 6optional7$.oolean C Determines if single ara$ pandSingle*ord words are stretched. com.sun.star.style.ParagraphProperties:P long C Determines the left margin of the araLeft(argin paragraph in !/!)) mm.

#$%pter 7 Text Documents

35

#ontrol #$%r%cters

com.sun.star.style.ParagraphProperties:P ara-ight(argin com.sun.star.style.ParagraphProperties:P araTop(argin com.sun.star.style.ParagraphProperties:P ara3ottom(argin com.sun.star.style.ParagraphProperties:P araLine6umberCount com.sun.star.style.ParagraphProperties:P araLine6umberStartFalue com.sun.star.style.ParagraphProperties:P ara0s?yphenation com.sun.star.style.ParagraphProperties:P ageDesc6ame com.sun.star.style.ParagraphProperties:P age6umber+ffset com.sun.star.style.ParagraphProperties:P ageStyle6ame com.sun.star.style.ParagraphProperties:P ara-egister(ode/cti5e com.sun.star.style.ParagraphProperties:P araTabStops com.sun.star.style.ParagraphProperties:P araStyle6ame com.sun.star.style.ParagraphProperties:D ropCap4ormat

long C Determines the right margin of the

paragraph in !/!)) mm. long C Determines the top margin of the paragraph in !/!)) mm. long C Determines the bottom margin of the paragraph in !/!)) mm. 6optional7$.oolean C Determines if the paragraph is included in the line numbering. 6optional7$.oolean C Contains the start 5alue for the line numbering. 6optional7$.oolean C Pre5ents the paragraph from getting hyphenated. 6optional7$ tring C 0f this property is set8 it creates a page brea2 before the paragraph it belongs to and assigns the 5alue as the name of the new page style sheet to use. 6optional7$ %ort C 0f a page brea2 property is set at a paragraph8 this property contains the new 5alue for the page number. 6optional7$ tring C Contains the page style name. 6optional7$.oolean C Determines if the register mode is applied to a paragraph.
6optional7$ e5uence$ Kcom.sun.star.style.TabStopL. Specifies the

com.sun.star.style.ParagraphProperties:D ropCap*hole*ord com.sun.star.style.ParagraphProperties:P ara;eepTogether com.sun.star.style.ParagraphProperties:P araSplit com.sun.star.style.ParagraphProperties:6 umberingLe5el

positions and 2inds of the tab stops within this paragraph. 6optional7$ tring C Contains the name of the current paragraph style. 6optional7 struct com.sun.star.style.DropCap4ormat specifies whether the first characters of the paragraph are displayed in capital letters and how they are formatted. 6optional7$.oolean C Specifies if the property DropCapFormat is applied to the whole first word. 6optional7$.oolean C Setting this property to true pre5ents page or column brea2s between this and the following paragraph. 6optional7$.oolean C Setting this property to false pre5ents the paragraph from getting split into two pages or columns. 6optional7$ %ort C Specifies the numbering le5el of the paragraph.

3(

OpenOffice.org 3.1 Developer's Guide April !!"

#ontrol #$%r%cters

com.sun.star.style.ParagraphProperties:6 umbering-ules

com.sun.star.container.A0nde -eplace . Contains the numbering rules applied to this paragraph. com.sun.star.style.ParagraphProperties:6 6optional7$ %ort C Specifies the start 5alue umberingStartFalue for numbering if a new numbering starts at this paragraph. com.sun.star.style.ParagraphProperties:P 6optional7$.oolean C Determines if the ara0s6umbering-estart numbering rules restart8 counting at the current paragraph. com.sun.star.style.ParagraphProperties:6 6optional7$ tring C Specifies the name of umberingStyle6ame the style for the numbering. com.sun.star.style.ParagraphProperties:P 6optional7$.yte C Specifies the minimum ara+rphans number of lines of the paragraph that ha5e to be at bottom of a page if the paragraph is spread o5er more than one page. com.sun.star.style.ParagraphProperties:P 6optional7$.yte C Specifies the minimum ara*idows number of lines of the paragraph that ha5e to be at top of a page if the paragraph is spread o5er more than one page. com.sun.star.style.ParagraphProperties:P 6optional7 struct araShadow4ormat com.sun.star.table.Shadow4ormat . Determines the type8 color8 and si9e of the shadow. com.sun.star.style.ParagraphProperties/s 6optional7$.oolean C Determines if hanging ian:Para0s?angingPunctuation punctuation is allowed. com.sun.star.style.ParagraphProperties/s 6optional7$.oolean C Determines if a ian:Para0sCharacterDistance distance between /sian te t8 western te t or comple te t is set. com.sun.star.style.ParagraphProperties/s 6optional7$.oolean C Determines if the the ian:Para0s4orbidden-ules rules for forbidden characters at the start or end of te t lines are considered.

com.sun.star.style.ParagraphProperties/sian describes some further properties used in /sian te t. Properties of co&.sun.st%r.style.P%r%gr%phPropertiesAsi%n com.sun.star.style.ParagraphProperties/s 6optional7$.oolean C Determines if hanging ian:Para0s?angingPunctuation punctuation is allowed. com.sun.star.style.ParagraphProperties/s 6optional7$.oolean C Determines if a ian:Para0sCharacterDistance distance between /sian te t8 western te t or comple te t is set. com.sun.star.style.ParagraphProperties/s 6optional7$.oolean C Determines if the the ian:Para0s4orbidden-ules rules for forbidden characters at the start or end

#$%pter 7 Text Documents

37

#ontrol #$%r%cters

of te t lines are considered. +b:ects supporting these properties support com.sun.star.beans.APropertySet8 as well. To change the properties8 use the method etPropertyValue().
"##$!%i $ nippet$ %ow $t%e$nece ary$ tep $to$ et$a$property$at$t%e$$$$$$ current$po ition$o4$a$given$te)t$cur or$m)DocCur or$$#" ""$5uery$t%e$XPropertySet$inter4ace$XPropertySet$)Cur orProp $+$(XPropertySet)$ UnoRuntime'5uery1nter4ace(XPropertySet'cla /$m)DocCur or), ""$call$ etPropertyValue/$pa ing$in$a$Float$o.&ect$ )Cur orProp ' etPropertyValue(3C%ar2eig%t3/$new$Float$ ($com' un' tar'awt'Font2eig%t';0LD)),

The same procedure is used for all properties. The more comple properties are described here. 0f a change of the page style is re>uired the paragraph property PageDe c:ame has to be set using an e isting page style name. This forces a page brea2 at the cursor position and the new inserted page uses the re>uested page style. The property Page:um.er044 et has to be set to start with a new page count. 0f inserting an additional paragraph should be a5oided8 the cursor must be placed at the beginning of the first paragraph before inserting it. 0f a page brea2 <or a column brea2= without a change in the used style is re>uired8 the property ;rea-!ype is set using the 5alues of com.sun.star.style.3rea2Type: P%ge *re%1 com.sun.star.style.3rea2Type Description Page or column brea2 as described in com.sun.star.style.3rea2Type . Possible 5alues are 6+6$8 C+LB(6I3$4+-$8 C+LB(6I/4T$-8 C+LB(6I3+T?8 P/7$I3$4+-$8 P/7$I/4T$-8 and P/7$I3+T?. Setting the property forces a page or column brea2 at the current te t cursor position8 paragraph or te t table.

The property ParaLine:um.erCount is used to include a paragraph in the line numbering. The setting of the line numbering options is done using the property set pro5ided by the com.sun.star.te t.ALine6umberingProperties interface implemented at the te t document model. To create a hyperlin2 these properties are set at the current cursor position or the current J0DL:com.sun.star.te t.ParagraphK ser5ice. J3B7#"!LK?yperlin2 properties are not specified for paragraphs in the /P0 reference. Hyperlin1 Properties
?yperLin-URL ?yperLin-!arget ?yperLin-:ame

Description
tring C Contains the B-L. tring C Contains the name of the target frame and can be

left blan2. tring C The name of the hyperlin2 can be left blan2.

38

OpenOffice.org 3.1 Developer's Guide April !!"

#ontrol #$%r%cters

Unvi itedC%arStyle:ame

tring C The names of the character styles used to emphasi9e 5isited or not 5isited lin2s. 0f left blan28 the default character styles 0nternet Lin2/Fisited 0nternet Lin2 are applied automatically.

Vi itedC%arStyle:ame ?yperLin-(vent

$5ents attached to the hyperlin2. The names of the e5ents are +nClic28 +n(ouse+5er8 and +n(ouse+ut. $ach returned e5ent is a se>uence of com.sun.star.beans.PropertyFalue 8 with three elements named $5entType8 (acro6ame and Library. /ll elements contain string 5alues. The $5entType contains the 5alue DStar3asicD for JP-+DBCT6/($K 3asic macros . The macro name contains the path to the macro8 for e ample8 Standard.(odule!.(ain. The library contains the name of the library.

Some properties are connected with each other. There may be side effects or dependencies between the following properties: 0nterdependencies between Properties
ParaRig%tMargin8 ParaLe4tMargin8 ParaFir tLine1ndent8 Para1 AutoFir tLine1ndent Para!opMargin8 Para;ottomMargin ParaRrap%icURL"Filter"Location8 Para;ac-Color8 Para;ac-!ran parent Para1 ?yp%enation8 Para?yp%enationMa)LeadingC%ar "Ma)!railingC%ar "Ma)?yp%en Le4t"Rig%t"!op";ottom;order8 Le4t"Rig%t"!op";ottom;orderDi tance8 ;orderDi tance DropCapFormat8 DropCap2%ole2ord8 DropCapC%arStyle:ame PageDe c:ame8 Page:um.er044 et8 PageStyle:ame ?yperLin-URL":ame"!arget8 Unvi itedC%arStyle:ame8 Vi itedC%arStyle:ame C%ar( capement8 C%arAuto( capement8 C%ar( capement?eig%t C%arFont:ame8 C%arFontStyle:ame8 C%arFontFamily8 C%arFontPitc% C%arStri-e0ut8 C%arCro ed0ut

#$%pter 7 Text Documents

3"

#ontrol #$%r%cters

C%arUnderline8 C%arUnderlineColor8 C%arUnderline?a Color C%arCom.ine1 0n8 C%arCom.inePre4i)8 C%arCom.ineSu44i) Ru.y!e)t8 Ru.yAd&u t8 Ru.yC%arStyle:ame8 Ru.y1 A.ove

N%vig%ting

Cursors
The te t model cursor allows for free na5igation o5er the model by character8 words8 sentences8 or paragraphs. There can be se5eral model cursors at the same time. (odel cursor creation8 mo5ement and usage is discussed in the section *ord Processing . The te t model cursors are com.sun.star.te t.Te tCursor ser5ices that are based on the interface com.sun.star.te t.ATe tCursor8 which is based on com.sun.star.te t.ATe t-ange. The te t 5iew cursor enables the user to tra5el o5er the document in the 5iew by character8 line8 screen page and document page. There is only one te t 5iew cursor. Certain information about the current layout8 such as the number of lines and page number must be retrie5ed at the 5iew cursor. The chapter Te t Document Controller below discusses the 5iew cursor in detail. The te t 5iew cursor is a com.sun.star.te t.Te tFiewCursor ser5ice that includes com.sun.star.te t.Te tLayoutCursor.

+oc%ting e$t Contents


The te t document model has suppliers that yield all te t contents in a document as collections. To find a particular te t content8 such as boo2mar2s or te t fields8 use the appropriate supplier interface. The following supplier interfaces are a5ailable at the model: ,upplier interf%ces com.sun.star.te t.ATe tTablesSupplier com.sun.star.te t.ATe t4ramesSupplier com.sun.star.te t.ATe t7raphic+b:ects Supplier
&!

/ethods
com' un' tar'container'X:ameAcce get!e)t!a.le () com' un' tar'container'X:ameAcce get!e)tFrame () com' un' tar'container'X:ameAcce getRrap%ic0.&ect () $ $ $

OpenOffice.org 3.1 Developer's Guide April !!"

'oc%ting Text #ontents

com.sun.star.te t.ATe t$mbedded+b:ec com' un' tar'container'X:ameAcce $ get(m.edded0.&ect () tsSupplier com' un' tar'container'X(numerationAcce com.sun.star.te t.ATe t4ieldsSupplier
$get!e)tField () com' un' tar'container'X:ameAcce get!e)tFieldMa ter () com' un' tar'container'X:ameAcce get;oo-mar- () com' un' tar'container'X:ameAcce getRe4erenceMar- () $ $ $

com.sun.star.te t.A3oo2mar2sSupplier com.sun.star.te t.A-eference(ar2sSup plier com.sun.star.te t.A4ootnotesSupplier

com.sun.star.te t.A$ndnotesSupplier

com.sun.star.te t.ATe tSectionsSupplie r com.sun.star.te t.ADocument0nde esSu pplier com.sun.star.document.A-edlinesSuppl ier

com' un' tar'container'X1nde)Acce $ getFootnote () com' un' tar'.ean 'XPropertySet$ getFootnoteSetting () com' un' tar'container'X1nde)Acce $ get(ndnote () com' un' tar'.ean 'XPropertySet$ get(ndnoteSetting () com' un' tar'container'X:ameAcce $ get!e)tSection () com' un' tar'container'X1nde)Acce getDocument1nde)e () $

com' un' tar'container'X(numerationAcce $getRedline ()

Hou can wor2 with te t content directly8 set properties and use its interfaces8 or find out where it is and do an action at the te t content location in the te t. To find out where a te t content is located call the getAnc%or() method at the interface com.sun.star.te t.ATe tContent8 which e5ery te t content must support. 0n addition8 te t contents located at the current te t cursor position or the content where the cursor is currently located are pro5ided in the PropertySet of the cursor. The corresponding cursor properties are:

Document1nde)Mar!e)tField Re4erenceMarFootnote (ndnote Document1nde) !e)t!a.le !e)tFrame Cell !e)tSection

#$%pter 7 Text Documents

&1

-e%rc$ %nd 0epl%ce

,e%rch %nd "epl%ce


The writer model supports the interface com.sun.star.util.A-eplaceablethat inherits from the interface com.sun.star.util.ASearchable for searching and replacing in te t. 0t contains the following methods:
comFF unFF tarFFutilFFXSearc%De criptor$createSearc%De criptor()$$ comFF unFF tarFFutilFFXReplaceDe criptor$createReplaceDe criptor() comFF unFF tarFFunoFFX1nter4ace$4indFir t($6in7$ comFF unFF tarFFutilFFXSearc%De criptor$)De c)$$ comFF unFF tarFFunoFFX1nter4ace$4ind:e)t($6in7$comFF unFF tarFFunoFFX1nter4ace$ )StartAt/$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$6in7$ comFF unFF tarFFutilFFXSearc%De criptor$)De c)$$ comFF unFF tarFFcontainerFFX1nde)Acce $4indAll($6in7$ comFF unFF tarFFutilFFXSearc%De criptor$)De c) long$replaceAll($6in7$comFF unFF tarFFutilFFXSearc%De criptor$)De c)

To search or replace te t8 first create a descriptor ser5ice using createSearc%De criptor() or createReplaceDe criptor(). Hou recei5e a ser5ice that supports the interface com.sun.star.util.AProperty-eplace with methods to describe what you are searching for8 what you want to replace with and what attributes you are loo2ing for. 0t is described in detail below. Pass in this descriptor to the methods 4indFir t()8 4ind:e)t()8 4indAll() or replaceAll(). The methods 4indFir t() and 4ind:e)t() return a com.sun.star.uno.A0nterface pointing to an ob:ect that contains the found item. 0f the search is not successful8 a null reference to an X1nter4ace is returned8 that is8 if you try to >uery other interfaces from it8 null is returned. The method 4indAll() returns a com.sun.star.container.A0nde /ccess containing one or more com.sun.star.uno.A0nterface pointing to the found te t ranges or if they failed an empty interface. The method replaceAll() returns the number of replaced occurrences only.

&

OpenOffice.org 3.1 Developer's Guide April !!"

-e%rc$ %nd 0epl%ce

XPropertyReplace The interface com.sun.star.util.AProperty-eplace is re>uired to describe your search. 0t is a powerful interface and inherits from XReplaceDe criptor8 XSearc%De criptor and XPropertySet. The target of your search is described by a string containing a search te t or a style name using etSearc%String(). Correspondingly8 pro5ide the te t string or style name that should replace the found occurrence of the search target to the XReplaceDe criptor using etReplaceString(). -efine the search mode through the properties included in the ser5ice com.sun.star.util.SearchDescriptor: Properties of co&.sun.st%r.util.,e%rchDescriptor com.sun.star.util.SearchDescriptor:Sear .oolean C Search bac2ward ch3ac2wards com.sun.star.util.SearchDescriptor:Sear .oolean C Search is case sensiti5e. chCaseSensiti5e com.sun.star.util.SearchDescriptor:Sear .oolean C Search interpreting the search string ch-egular$ pression as a regular e pression. com.sun.star.util.SearchDescriptor:Sear .oolean C Bse similarity search using the four chSimilarity following options:

#$%pter 7 Text Documents

&3

-e%rc$ %nd 0epl%ce

com.sun.star.util.SearchDescriptor:Sear chSimilarity/dd com.sun.star.util.SearchDescriptor:Sear chSimilarity$ change com.sun.star.util.SearchDescriptor:Sear chSimilarity-ela

com.sun.star.util.SearchDescriptor:Sear chSimilarity-emo5e

com.sun.star.util.SearchDescriptor:Sear chStyles com.sun.star.util.SearchDescriptor:Sear ch*ords

%ort C Determines the number of characters the word in the document may be longer than the search string for it to remain 5alid. %ort C Determines how many characters in the search term can be e changed. .oolean C 0f true8 the 5alues of added8 e changed8 and remo5ed characters are combined The search term is then found if the word in the document can be generated through any combination of these three conditions. %ort C Determines how many characters the word in the document may be shorter than the search string for it to remain 5alid. The characters may be remo5ed from the word at any position. .oolean C Determines if the search and replace string should be interpreted as paragraph style names. 6ote that the Display 6ame of the style has to be used. .oolean C Determines if the search should find complete words only.

0n XPropertyReplace8 the methods to get and set search attributes8 and replace attributes allow the attributes to search for to be defined and the attributes to insert instead of the e isting attributes. /ll of these methods e pect a se>uence of com.sun.star.beans.PropertyFalue structs. /ny properties contained in the ser5ices com.sun.star.style.CharacterProperties8 com.sun.star.style.CharacterProperties/sian and com.sun.star.style.ParagraphProperties can be used for an attribute search. 0f etValueSearc%(4al e) is used8 +pen+ffice.org chec2s if an attribute e ists8 whereas etValueSearc%(true) finds specific attribute 5alues. 0f only searching to see if an attribute e ists at all8 it is sufficient to pass a PropertyValue struct with the 6ame field set to the name of the re>uired attribute. The following code snippet replaces all occurrences of the te t Drandom numbersD by the bold te t Dreplaced numbersD in a gi5en document m)Doc.
XReplacea.le$)Replacea.le$+$(XReplacea.le)$ UnoRuntime'5uery1nter4ace(XReplacea.le'cla /$m)Doc),$XReplaceDe criptor$ )RepDe c$+$)Replacea.le'createReplaceDe criptor(), ""$ et$a$ tring$to$ earc%$4or$)RepDe c' etSearc%String(3random$num.er 3), ""$ et$t%e$ tring$to$.e$in erted$)RepDe c' etReplaceString(3replaced$ num.er 3), ""$create$an$array$o4$one$property$value$4or$a$C%ar2eig%t$property$ PropertyValue67$aReplaceArg $+$new$PropertyValue687, ""$create$PropertyValue$ truct$aReplaceArg 697$+$new$PropertyValue(),$""$ C%ar2eig%t$ %ould$.e$.old$aReplaceArg 697':ame$+$3C%ar2eig%t3,$ aReplaceArg 697'Value$+$new$Float(com' un' tar'awt'Font2eig%t';0LD),

&&

OpenOffice.org 3.1 Developer's Guide April !!"

-e%rc$ %nd 0epl%ce

""$ et$our$ e5uence$wit%$one$property$value$a $ReplaceAttri.ute$ XPropertyReplace$)PropRepl$+$(XPropertyReplace)$UnoRuntime'5uery1nter4ace($$$$$ XPropertyReplace'cla /$)RepDe c),$ )PropRepl' etReplaceAttri.ute (aReplaceArg ), ""$replace$long$nRe ult$+$)Replacea.le'replaceAll()RepDe c),

%*les

%*le Architecture
+pen+ffice.org te t tables consist of rows8 rows consist of one or more cells8 and cells can contain te t or rows. There is no logical concept of columns. 4rom the /P0@s perspecti5e8 a table acts as if it had columns8 as long as there are no split or merged cells. Cells in a row are counted alphabetically starting from /8 where rows are counted numerically8 starting from !. This results in a cellCrow addressing pattern8 where the cell letter is denoted first </CMff.=8 followed by the row number <!ff.=: /! /2 /. /" 3! 32 3. 3" C! C2 C. C" D! D2 D. D"

*hen a cell is split 5ertically8 the new cell gets the letter of the former rightChandCside neighbor cell and the former neighbor cell gets the ne t letter in the alphabet. Consider the e ample table below: 32 was split 5ertically8 a new cell C2 is inserted and the former C2 became D28 D2 became $28 and so forth. *hen cells are merged 5ertically8 the resulting cell counts as one cell and gets one letter. The neighbor cell to the right gets the subse>uent letter. 3" in the table below shows this. The former 3" and C" ha5e been merged8 so the former D" could become C". The cell name D" is no longer re>uired. /s shown8 there is no way to address a column C anymore8 for the cells C! to C" no longer form a column: /! /2 /. /" 3! 32 5ertically split in two 3. 3" merged with C" C2 newly inserted C! D2 C. D! $2 D. C"

#$%pter 7 Text Documents

&5

T%,le Arc$itecture

*hen cells are split hori9ontally8 +pen+ffice.org simply inserts as many rows into the cell as re>uired. 0n our e ample table8 we continued by splitting C2 first hori9ontally and then 5ertically so that there is a range of four cells. The writer treats the content of C2 as two rows and starts counting cells within rows. To address the new cells8 it e tends the original cell name C2 by new addresses following the cellCrow pattern. The upper row gets row number ! and the first cell in the row gets cell number !8 resulting in the cell address C2.!.!8 where the latter ! indicates the row and the former ! indicates the first cell in the row. The right neighbor of C2.!.! is C2.2.!. The subaddress 2.! means the second cell in the first row. /! /2 C2.!.2 /. /" 3! 32 5ertically split in two C2.2.2 3. 3" merged with C" C2.!.! C2.2.! C! D2 C. D! $2 D. C"

The cellCrow pattern is used for all further subaddressing as the cells are split and merged. The cell addresses can change radically depending on the table structure generated by +pen+ffice.org. The ne t table shows what happens when $2 is merged with D.. The table is reorgani9ed8 so that it has three rows instead of four. The second row contains two cells8 /2 and 32 <sicN=. The cell /2 has two rows8 as shown from the cell subaddresses: The upper row consists of four cells8 namely /2.!.! through /2.".!8 whereas the lower row consists of the three cells /2.!.2 through /2...2. The cell range C2.!.!:C2.2.2 that was formerly contained in cell C2 is now in cell /2...! that denotes the third cell in the first row of /2. *ithin the address of the cell /2...!8 +pen+ffice.org has started a new subaddressing le5el using the cellCrow pattern again. /! /2.!.! /2...!.!.2 /2.!.2 /. 3! /2.2.! /2...!.2.2 /2.2.2 3. /2...!.!.! /2...!.2.! C! /2.".! D! 4ormer $2 merged with former D. 3ecomes 32N C.

/2...2

Cell addresses can become complicated. The cell address can be loo2ed up in the user interface. Set the 7B0 te t cursor in the desired cell and obser5e the lowerCright corner of the status bar in the te t document. -emember that there are only DcolumnsD in a te t table8 as long as there are no split or merged cells. Te t tables support the ser5ice com.sun.star.te t.Te tTable8 which includes the ser5ice

&(

OpenOffice.org 3.1 Developer's Guide April !!"

T%,le Arc$itecture

com.sun.star.te t.Te tContent:

Service com.sun.star.text.TextTable The ser5ice com.sun.star.te t.Te tTableoffers access to table cells in two different ways:

Hields named table cells which are organi9ed in rows and columns. Pro5ides a table cursor to tra5el through the table cells and alter the cell properties.

These aspects are reflected in the interface com.sun.star.te t.ATe tTable which inherits from com.sun.star.te t.ATe tContent. 0t can be seen as a rectangular range of cells defined by numeric column inde es8 as described by com.sun.star.table.ACell-ange. This aspect ma2es te t tables compatible with spreadsheet tables. /lso8 te t tables ha5e a name8 can be sorted8 charts can be based on them8 and predefined formats can be applied to the tables. The latter aspects are co5ered by the interfaces com.sun.star.container.A6amed8 com.sun.star.util.ASortable8 com.sun.star.chart.AChartData/rray and com.sun.star.table.A/uto4ormattable. The usage of these interfaces and the properties of the Te tTable ser5ice are discussed below.

#$%pter 7 Text Documents

&7

T%,le Arc$itecture

N%&ed %*le Cells in "o.s5 Colu&ns %nd the %*le Cursor


The interface X!e)t!a.le introduces the following methods to initiali9e a table8 wor2 with table cells8 rows and columns8 and create a table cursor:
void$initialiOe($6in7$long$nRow /$6in7$long$nColumn ) e5uenceK$ tring$L$getCell:ame ()$$comFF unFF tarFFta.leFFXCell$getCell;y:ame($ 6in7$ tring$aCell:ame) comFF unFF tarFFta.leFFX!a.leRow $getRow ()$$ comFF unFF tarFFta.leFFX!a.leColumn $getColumn () comFF unFF tarFFte)tFFX!e)t!a.leCur or$createCur or;yCell:ame($6in7$ tring$ aCell:ame)

The method initialiOe() sets the number of rows and columns prior to inserting the table into the te t. 6onCinitiali9ed tables default to two rows and two columns. The method getCell:ame () returns a se>uence of strings containing the names of all cells in the table in /!J.!.!K notation. The method getCell;y:ame() e pects a cell name in /!J.!.!K notation8 and returns a cell ob:ect that is a com.sun.star.table.ACell and a com.sun.star.te t.ATe t. The ad5antage of getCell;y:ame() is its ability to retrie5e cells e5en in tables with split or merged cells. The method getRow () returns a table row container supporting com.sun.star.table.ATable-ows that is a com.sun.star.container.A0nde /ccess8 and introduces the following methods to insert an arbitrary number of table rows below a gi5en row inde position and remo5e rows from a certain position:
void$in ert;y1nde)$($6in7$long$n1nde)/$6in7$long$nCount)$void$remove;y1nde)$ ($6in7$long$n1nde)/$6in7$long$nCount)

The following table shows which X!a.leRow methods wor2 under which circumstances. /ethod in co&.sun.st%r.t%*le.6 %*le"o.s com.sun.star.container.A$lement/ccess:get$lementType<= com.sun.star.container.A$lement/ccess:has$lements<= com.sun.star.container.A0nde /ccess:get3y0nde <= com.sun.star.container.A0nde /ccess:getCount<= com.sun.star.table.ATable-ows:insert3y0nde <= com.sun.star.table.ATable-ows:remo5e3y0nde <= 2n ,i&ple t%*le A A A A A A 2n Co&ple$ %*le A A A A C C

$5ery row returned by getRow () supports the ser5ice com.sun.star.te t.Te tTable-ow8 that is8 it is a com.sun.star.beans.APropertySetwhich features these properties:

&8

OpenOffice.org 3.1 Developer's Guide April !!"

T%,le Arc$itecture

Properties of co&.sun.st%r.te$t. e$t %*le"o. com.sun.star.te t.Te tTable-ow:3ac2Col long C Specifies the color of the bac2ground in or ) //--7733 notation. com.sun.star.te t.Te tTable-ow:3ac2Tra .oolean C 0f true8 the bac2ground color 5alue nsparent in D;ac-ColorD is not 5isible. J)K tring C Contains the B-L of a bac2ground graphic. com.sun.star.te t.Te tTable-ow:3ac27ra tring C Contains the name of the file filter of phic4ilter a bac2ground graphic. com.sun.star.te t.Te tTable-ow:3ac27ra phicLocation com.sun.star.style.7raphicLocation . Determines the position of the bac2ground graphic. com.sun.star.te t.Te tTable-ow:TableCo Defines the column width and its merging lumnSeparators beha5ior. 0t contains a se>uence of com.sun.star.te t.TableColumnSeparator structs with the fields Position and 0sFisible. The 5alue of Position is relati5e to the table property com.sun.star.te t.Te tTable:TableColumn-elati 5eSum. 0sFisible refers to merged cells where the separator becomes in5isible. com.sun.star.te t.Te tTable-ow:?eight long C Contains the height of the table row. com.sun.star.te t.Te tTable-ow:0s/uto? .oolean C 0f the 5alue of this property is true8 eight the height of the table row depends on the content of the table cells. The method getColumn () is similar to getRow ()8 but restrictions apply. 0t returns a table column container supporting com.sun.star.table.ATableColumns that is a com.sun.star.container.A0nde /ccess and introduces the following methods to insert an arbitrary number of table columns behind a gi5en column inde position and remo5e columns from a certain position:
void$in ert;y1nde)($6in7$long$n1nde)/$6in7$long$nCount)$void$ remove;y1nde)($6in7$long$n1nde)/$6in7$long$nCount)

The following table shows which X!a.leColumn methods wor2 in which situation. /ethods in co&.sun.st%r.t%*le.6 %*leColu&ns com.sun.star.container.A$lement/ccess:get$lementType<= com.sun.star.container.A$lement/ccess:has$lements<= com.sun.star.container.A0nde /ccess:get3y0nde <= 2n ,i&ple %*le A A A <but returned ob:ect supports 2n Co&ple $ %*le A A C

#$%pter 7 Text Documents

&"

T%,le Arc$itecture

com.sun.star.container.A0nde /ccess:getCount<= com.sun.star.table.ATableColumns:insert3y0nde <= com.sun.star.table.ATableColumns:remo5e3y0nde <=

A0nterface only= A A A

C C C

The method createCur or;yCell:ame() creates a te t table cursor that can select a cell range in the table8 merge or split cells8 and read and write cell properties of the selected cell range. 0t is a com.sun.star.te t.Te tTableCursor ser5ice with the interfaces com.sun.star.te t.ATe tTableCursor and com.sun.star.beans.APropertySet.

com.sun.star.text.TextTableCursor These are the methods contained in X!e)t!a.leCur or:


tring$getRange:ame() .oolean$goLe4t($6in7$ %ort$nCount/$6in7$.oolean$.()pand)$.oolean$goRig%t($6in7$ %ort$nCount/$6in7$.oolean$.()pand)$.oolean$goUp($6in7$ %ort$nCount/$6in7$ .oolean$.()pand)$.oolean$goDown($6in7$ %ort$nCount/$6in7$.oolean$.()pand) void$gotoStart($6in7$.oolean$.()pand)$void$goto(nd($6in7$.oolean$.()pand)$ .oolean$gotoCell;y:ame($6in7$ tring$aCell:ame/$6in7$.oolean$.()pand) .oolean$mergeRange()$.oolean$ plitRange($6in7$ %ort$Count/$6in7$.oolean$ ?oriOontal)

Tra5eling through the table calls the cursor@s goLe4t()8 goRig%t()8 goUp()8 goDown()8 gotoStart()8 goto(nd()8 and gotoCell;y:ame() methods8 passing true to select cells on the way. +nce a cell range is selected8 apply character and paragraph properties to the cells in the range as defined in the ser5ices com.sun.star.style.CharacterProperties8 com.sun.star.style.CharacterProperties/sian8 com.sun.star.style.CharacterPropertiesComple and com.sun.star.style.ParagraphProperties. (oreo5er8 split and merge cells using the te t

5!

OpenOffice.org 3.1 Developer's Guide April !!"

T%,le Arc$itecture

table cursor. /n e ample is pro5ided below.

2nde$ed Cells %nd Cell "%nges


The interface com.sun.star.table.ACell-ange pro5ides access to cells using their row and column inde as position8 and to create sub ranges of tables:
comFF unFF tarFFta.leFFXCell$getCell;yPo ition($6in7$long$nColumn/$6in7$long$ nRow)$$comFF unFF tarFFta.leFFXCellRange$getCellRange;yPo ition($6in7$long$ nLe4t/$6in7$long$n!op/$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ 6in7$long$nRig%t/$6in7$long$n;ottom)$$comFF unFF tarFFta.leFFXCellRange$ getCellRange;y:ame($6in7$ tring$aRange)

The method getCell;yPo ition() returns a cell ob:ect supporting the interfaces com.sun.star.table.ACell and com.sun.star.te t.ATe t. To find the cell the name is internally created from the position using the naming scheme described abo5e and returns this cell if it e ists. Calling getCell;yPo ition(8/$8) in the table at the beginning of this chapter returns the cell D32D . The methods getCellRange;yPo ition() and getCellRange;y:ame() return a range ob:ect that is described below. The name of the range is created with the topCleft cell and bottomCright cell of the table separated by a colon F as in A8F;B. 3oth methods fail when the structure of the table contains merged or split cells.

%*le N%&ing5 ,orting5 Ch%rting %nd Autofor&%tting


$ach table has a uni>ue name that can be read and written using the interface com.sun.star.container.A6amed. / te t table is a com.sun.star.container.A6amed. 0ts method createSortDe criptor() returns a se>uence of com.sun.star.beans.PropertyFalue structs that pro5ides the elements as described in the ser5ice com.sun.star.te t.Te tSortDescriptor. The method ort() sorts the table content by the gi5en parameters. The interface com.sun.star.chart.AChartData/rray is used to connect a table or a range inside of a table to a chart. 0t reads and writes the 5alues of a range8 and sets the column and row labels. The inherited interface com.sun.star.chart.AChartData enables the chart to connect listeners to be notified when changes to the 5alues of a table are made. 4or details about charting8 refer to chapter Charts.

#$%pter 7 Text Documents

51

T%,le Arc$itecture

The interface com.sun.star.table.A/uto4ormattable pro5ides in its method autoFormat() a method to format the table using a predefined table format. To access the a5ailable auto formats8 the ser5ice com.sun.star.sheet.Table/uto4ormats has to be accessed. 4or details8 refer to chapter Table /uto 4ormats.

e$t %*le Properties


The te t table supports the properties described in the ser5ice com.sun.star.te t.Te tTable: Properties of co&.sun.st%r.te$t. e$t %*le com.sun.star.te t.Te tTable:3ac2Color long C Contains the color of the table bac2ground. com.sun.star.te t.Te tTable:3ac27raphic4i tring C Contains the name of the file filter lter for the bac2ground graphic. com.sun.star.te t.Te tTable:3ac27raphicL ocation com.sun.star.style.7raphicLocation . Determines the position of the bac2ground graphic. com.sun.star.te t.Te tTable:3ac27raphicB tring C Contains the B-L for the -L bac2ground graphic. com.sun.star.te t.Te tTable:3ac2Transpare .oolean C Determines if the bac2ground nt color is transparent. com.sun.star.te t.Te tTable:3ottom(argin long C Determines the bottom margin. com.sun.star.te t.Te tTable:3rea2Type com.sun.star.style.3rea2Type. Determines the type of brea2 that is applied at the beginning of the table. com.sun.star.te t.Te tTable:ChartColumn/ .oolean C Determines if the first column of sLabel the table should be treated as a is labels when a chart is to be created. com.sun.star.te t.Te tTable:Chart-ow/sL .oolean C Determines if the first row of the abel table should be treated as a is labels when a chart is to be created. com.sun.star.te t.Te tTable:?ori+rient %ort C Contains the hori9ontal orientation according to com.sun.star.te t.?ori+rientation. com.sun.star.te t.Te tTable:0s*idth-elati5 .oolean C Determines if the 5alue of the e relati5e width is 5alid. com.sun.star.te t.Te tTable:;eepTogether .oolean C Setting this property to true pre5ents page or column brea2s between this table and the following paragraph or te t table. com.sun.star.te t.Te tTable:Left(argin long C Contains the left margin of the table.

OpenOffice.org 3.1 Developer's Guide April !!"

T%,le Arc$itecture

com.sun.star.te t.Te tTable:PageDesc6am e com.sun.star.te t.Te tTable:Page6umber+ ffset com.sun.star.te t.Te tTable:-elati5e*idth com.sun.star.te t.Te tTable:-epeat?eadlin e com.sun.star.te t.Te tTable:-ight(argin com.sun.star.te t.Te tTable:Shadow4ormat

tring C 0f this property is set8 it creates a page brea2 before the table and assigns the 5alue as the name of the new page style sheet to use. %ort C 0f a page brea2 property is set at the table8 this property contains the new 5alue for the page number. %ort C Determines the width of the table relati5e to its en5ironment. .oolean C Determines if the first row of the table is repeated on e5ery new page. long C Contains the right margin of the table. truct

com.sun.star.te t.Te tTable:Split com.sun.star.te t.Te tTable:Table3order

com.sun.star.te t.Te tTable:TableColumnelati5eSum com.sun.star.te t.Te tTable:TableColumnS eparators

com.sun.star.table.Shadow4ormat determines the type8 color and si9e of the shadow. .oolean C Setting this property to false pre5ents the table from getting spread on two pages. struct com.sun.star.table.Table3order . Contains the description of the table borders. %ort C Contains the sum of the column width 5alues used in TableColumnSeparators.
e5uence

com.sun.star.te t.Te tTable:Top(argin com.sun.star.te t.Te tTable:*idth

Ocom.sun.star.te t.TableColumnSeparatorP. Defines the column width and its merging beha5ior. 0t contains a se>uence of com.sun.star.te t.TableColumnSeparator structs with the fields Position and 0sFisible. The 5alue of Position is relati5e to the table property com.sun.star.te t.Te tTable:TableColumn-el ati5eSum. 1 Vi i.le refers to merged cells where the separator becomes in5isible. 0n tables with merged or split cells8 the se>uence !a.leColumnSeparator is empty. long C Determines the top margin. long C Contains the absolute table width.

#$%pter 7 Text Documents

53

T%,le Arc$itecture

2nserting %*les
To create and insert a new te t table8 a fi5eCstep procedure must be followed: !. 7et the ser5ice manager of the te t document8 >uerying the document@s factory interface com.sun.star.lang.A(ultiSer5ice4actory. 2. +rder a new te t table from the factory by its ser5ice name Dcom' un' tar'te)t'!e)t!a.leD8 using the factory method create1n tance(). .. 4rom the ob:ect recei5ed8 >uery the com.sun.star.te t.ATe tTableinterface that inherits from com.sun.star.te t.ATe tContent. ". 0f necessary8 initiali9e the table with the number of rows and columns. 4or this purpose8
X!e)t!a.le offers the initialiOe() method.

,. 0nsert the table into the te t using the in ert!e)tContent() method at its com.sun.star.te t.ATe t interface. The method in ert!e)tContent() e pects an X!e)tContent to insert. Since X!e)t!a.le inherits from X!e)tContent8 pass the X!e)t!a.le interface retrie5ed pre5iously. Hou are now ready to get cells8 fill in te t8 5alues and formulas and set the table and cell properties as needed. 0n the following code sample8 there is a small helper function to put random numbers between C!))) and !))) into the table to demonstrate formulas:
"##$!%i $met%od$return $a$random$dou.le$w%ic%$i nSt$too$%ig%$or$too$low$$#"$ protected$dou.le$getRandomDou.le()$*$$$$$return$((maRandom'ne)t1nt()$V$8999)$#$ maRandom'ne)tDou.le()),$=

The following helper function inserts a string into a cell 2nown by its name and sets its te t color to white:
"##$!%i $met%od$ et $t%e$te)t$colour$o4$t%e$cell$re4ered$to$.y$ Cell:ame$to$ w%ite$and$in ert $$$$$t%e$ tring$ !e)t$in$it$$#"$pu.lic$ tatic$void$ in ert1ntoCell(String$ Cell:ame/$String$ !e)t/$X!e)t!a.le$)!a.le)$*$$$$$""$ Acce $t%e$X!e)t$inter4ace$o4$t%e$cell$re4erred$to$.y$ Cell:ame$$$$$X!e)t$ )Cell!e)t$+$(X!e)t)$UnoRuntime'5uery1nter4ace($$$$$$$$$X!e)t'cla /$ )!a.le'getCell;y:ame( Cell:ame)), ""$create$a$te)t$cur or$4rom$t%e$cell $X!e)t$inter4ace$$$$$X!e)tCur or$ )CellCur or$+$)Cell!e)t'create!e)tCur or(), ""$Ret$t%e$property$ et$o4$t%e$cellS $!e)tCur or$$$$$XPropertySet$ )CellCur orProp $+$ (XPropertySet)UnoRuntime'5uery1nter4ace($$$$$$$$$XPropertySet'cla /$ )CellCur or), try$*$$$$$$$$$""$Set$t%e$colour$o4$t%e$te)t$to$w%ite$$$$$$$$$ )CellCur orProp ' etPropertyValue(3C%arColor3/$new$1nteger(8DEEEP8C)),$$$$$=$

5&

OpenOffice.org 3.1 Developer's Guide April !!"

T%,le Arc$itecture

catc%$(()ception$e)$*$$$$$$$$$e'printStac-!race(Sy tem'out),$$$$$= ""$Set$t%e$te)t$in$t%e$cell$to$ !e)t$$$$$)Cell!e)t' etString( !e)t),$=

Bsing the abo5e helper functions8 create a te t table and insert it into the te t document.
"##$!%i $met%od$ %ow $%ow$to$create$and$in ert$a$te)t$ta.le/$a $well$a $in ert$ te)t$and$4ormulae$$$$$into$t%e$cell $o4$t%e$ta.le$$#"$protected$void$ !e)t!a.le()ample$()$*$$$$$try$$$$$$*$$$$$$$$$""$Create$a$new$ta.le$4rom$t%e$ documentS $4actory$$$$$$$$$X!e)t!a.le$)!a.le$+$(X!e)t!a.le)$ UnoRuntime'5uery1nter4ace($$$$$$$$$$$$$$X!e)t!a.le'cla /$m)DocFactory$ 'create1n tance($$$$$$$$$$$$$$$$$3com' un' tar'te)t'!e)t!a.le3$)$), ""$Speci4y$t%at$we$want$t%e$ta.le$to$%ave$B$row $and$B$column $$$$$$$$$ )!a.le'initialiOe($B/$B$), ""$1n ert$t%e$ta.le$into$t%e$document$$$$$$$$$ m)Doc!e)t'in ert!e)tContent($m)DocCur or/$)!a.le/$4al e),$$$$$$$$$""$Ret$an$ X1nde)Acce $o4$t%e$ta.le$row $$$$$$$$$X1nde)Acce $)Row $+$)!a.le'getRow (), ""$Acce $t%e$property$ et$o4$t%e$4ir t$row$(propertie $li ted$in$ ervice$ de criptionF$$$$$$$$$""$com' un' tar'te)t'!e)t!a.leRow)$$$$$$$$$XPropertySet$ )Row$+$(XPropertySet)$ UnoRuntime'5uery1nter4ace($$$$$$$$$$$$$$XPropertySet'cla /$)Row 'get;y1nde)$($ 9$)$),$$$$$$$$$""$14$;ac-!ran parant$i $4al e/$t%en$t%e$.ac-ground$color$i $ vi i.le$$$$$$$$$)Row' etPropertyValue($3;ac-!ran parent3/$new$;oolean(4al e)),$ ""$Speci4y$t%e$color$o4$t%e$.ac-ground$to$.e$dar-$.lue$$$$$$$$$ )Row' etPropertyValue($3;ac-Color3/$new$1nteger(DE89NAP)), ""$Acce $t%e$property$ et$o4$t%e$w%ole$ta.le$$$$$$$$$XPropertySet$)!a.leProp $ +$(XPropertySet)UnoRuntime'5uery1nter4ace($$$$$$$$$$$$$$XPropertySet'cla /$ )!a.le$),$$$$$$$$$""$2e$want$vi i.le$.ac-ground$color $$$$$$$$$ )!a.leProp ' etPropertyValue($3;ac-!ran parent3/$new$ ;oolean(4al e)),$$$$$$$$$""$Set$t%e$.ac-ground$colour$to$lig%t$.lue$$$$$$$$$ )!a.leProp ' etPropertyValue($3;ac-Color3/$new$1nteger(8ABP8QPA)), ""$ et$t%e$te)t$(and$te)t$colour)$o4$all$t%e$cell $in$t%e$4ir t$row$o4$t%e$ ta.le$$$$$$$$$in ert1ntoCell($3A83/$3Fir t$Column3/$)!a.le$),$$$$$$$$$ in ert1ntoCell($3;83/$3Second$Column3/$)!a.le$),$$$$$$$$$in ert1ntoCell($3C83/$ 3!%ird$Column3/$)!a.le$),$$$$$$$$$in ert1ntoCell($3D83/$3Re ult 3/$)!a.le$), ""$1n ert$random$num.er $into$t%e$4ir t$t%i $t%ree$cell $o4$eac%$$$$$$$$$""$ remaining$row$$$$$$$$$)!a.le'getCell;y:ame($3AP3$)' etValue($getRandomDou.le()$ ),$$$$$$$$$)!a.le'getCell;y:ame($3;P3$)' etValue($getRandomDou.le()$),$$$$$$$$$ )!a.le'getCell;y:ame($3CP3$)' etValue($getRandomDou.le()$), )!a.le'getCell;y:ame($3AA3$)' etValue($getRandomDou.le()$),$$$$$$$$$ )!a.le'getCell;y:ame($3;A3$)' etValue($getRandomDou.le()$),$$$$$$$$$ )!a.le'getCell;y:ame($3CA3$)' etValue($getRandomDou.le()$), )!a.le'getCell;y:ame($3AB3$)' etValue($getRandomDou.le()$),$$$$$$$$$ )!a.le'getCell;y:ame($3;B3$)' etValue($getRandomDou.le()$),$$$$$$$$$ )!a.le'getCell;y:ame($3CB3$)' etValue($getRandomDou.le()$), ""$Set$t%e$la t$cell$in$eac%$row$to$.e$a$4ormula$t%at$calculate $$$$$$$$$""$ t%e$ um$o4$t%e$4ir t$t%ree$cell $$$$$$$$$ )!a.le'getCell;y:ame($3DP3$)' etFormula($3 um$KAPFCPL3$),$$$$$$$$$ )!a.le'getCell;y:ame($3DA3$)' etFormula($3 um$KAAFCAL3$),$$$$$$$$$ )!a.le'getCell;y:ame($3DB3$)' etFormula($3 um$KABFCBL3$),$$$$$=$$$$$$catc%$ (()ception$e)$$$$$$*$$$$$$$$$e'printStac-!race$($Sy tem'out$),$$$$$=$=

The ne t sample inserts auto te t entries into a table8 splitting cells during its course.
"##$!%i $e)ample$demon trate $t%e$u e$o4$t%e$Auto!e)tContainer/$Auto!e)tRroup$ and$Auto!e)t(ntry$ ervice $$$$$and$ %ow $%ow$to$create/$in ert$and$modi4y$auto$

#$%pter 7 Text Documents

55

T%,le Arc$itecture

te)t$.loc- $$#"$protected$void$Auto!e)t()ample$()$*$$$$$try$$$$$*$$$$$$$$$""$ Ro$to$t%e$end$o4$t%e$document$$$$$$$$$m)DocCur or'goto(nd($4al e$),$$$$$$$$$""$ 1n ert$two$paragrap% $$$$$$$$$m)Doc!e)t'in ertControlC%aracter$($m)DocCur or/$$ ControlC%aracter'PARARRAP?<;R(AT/$4al e$),$$$$$$$$$ m)Doc!e)t'in ertControlC%aracter$($m)DocCur or/$$$$$$$$$$$$$$ ControlC%aracter'PARARRAP?<;R(AT/$4al e$),$$$$$$$$$""$Po ition$t%e$cur or$in$ t%e$ econd$paragrap%$$$$$$$$$XParagrap%Cur or$)ParaCur or$+$(XParagrap%Cur or)$ UnoRuntime'5uery1nter4ace($$$$$$$$$$$$$XParagrap%Cur or'cla /$m)DocCur or$),$$ )ParaCur or'gotoPreviou Paragrap%$($4al e$), ""$Ret$an$X:ameAcce $inter4ace$to$all$auto$te)t$group $4rom$t%e$document$ 4actory$$$$$$$$$X:ameAcce $)Container$+$(X:ameAcce )$ UnoRuntime'5uery1nter4ace($$$$$$$$$$$$$$X:ameAcce 'cla /$ m)Factory'create1n tance$ ($$$$$$$$$$$$$$$$$3com' un' tar'te)t'Auto!e)tContainer3$)$), ""$Create$a$new$ta.le$at$t%e$document$4actory$$$$$$$$$X!e)t!a.le$)!a.le$+$ (X!e)t!a.le)$UnoRuntime'5uery1nter4ace($$$$$$$$$$$$$$X!e)t!a.le'cla /$ m)DocFactory$'create1n tance($$$$$$$$$$$$$$$$$$3com' un' tar'te)t'!e)t!a.le3$)$ ), ""$Store$t%e$name $o4$all$auto$te)t$group $in$an$array$o4$ tring $$$$$$$$$ String67$aRroup:ame $+$)Container'get(lement:ame (), ""$Ma-e$ ure$we$%ave$at$lea t$one$group$name$$$$$$$$$i4$($aRroup:ame 'lengt%$L$ 9$)$$$$$$$$$$*$$$$$$$$$$$$$""$initiali e$t%e$ta.le$to$%ave$a$row$4or$every$ autote)t$group$$$$$$$$$$$$$$""in$a$ ingle$column$G$one$$$$$$$$$$$$$""$ additional$row$4or$a$%eader$$$$$$$$$$$$$ )!a.le'initialiOe($aRroup:ame 'lengt%G8/8), ""$Acce $t%e$XPropertySet$o4$t%e$ta.le$$$$$$$$$$$$$XPropertySet$)!a.leProp $+$ (XPropertySet)UnoRuntime'5uery1nter4ace($$$$$$$$$$$$$$$$$XPropertySet'cla /$ )!a.le$), ""$2e$want$a$vi i.le$.ac-ground$$$$$$$$$$$$$ )!a.leProp ' etPropertyValue($3;ac-!ran parent3/$new$;oolean(4al e)), ""$2e$want$t%e$.ac-ground$to$.e$lig%t$.lue$$$$$$$$$$$$$ )!a.leProp ' etPropertyValue($3;ac-Color3/$new$1nteger(8ABP8QPA)), ""$1n ert$t%e$ta.le$into$t%e$document$$$$$$$$$$$$$m)Doc!e)t'in ert!e)tContent($ m)DocCur or/$)!a.le/$4al e), ""$Ret$an$X1nde)Acce $to$all$ta.le$row $$$$$$$$$$$$$X1nde)Acce $)Row $+$ )!a.le'getRow (), ""$Ret$t%e$4ir t$row$in$t%e$ta.le$$$$$$$$$$$$$XPropertySet$)Row$+$ (XPropertySet)$UnoRuntime'5uery1nter4ace($$$$$$$$$$$$$$$$$XPropertySet'cla /$ )Row 'get;y1nde)$($9$)$), ""$2e$want$t%e$.ac-ground$o4$t%e$4ir t$row$to$.e$vi i.le$too$$$$$$$$$$$$$ )Row' etPropertyValue($3;ac-!ran parent3/$new$;oolean(4al e)), ""$And$letS $ma-e$it$dar-$.lue$$$$$$$$$$$$$)Row' etPropertyValue($3;ac-Color3/$ new$1nteger(DE89NAP)), ""$Put$a$de cription$o4$t%e$ta.le$content $into$t%e$4ir t$cell$$$$$$$$$$$$$ in ert1ntoCell($3A83/$3Auto!e)t$Rroup 3/$)!a.le), ""$Create$a$ta.le$cur or$pointing$at$t%e$ econd$cell$in$t%e$4ir t$column$$$$$$$ X!e)t!a.leCur or$)!a.leCur or$+$)!a.le'createCur or;yCell:ame$($3AP3$), ""$Loop$over$t%e$group$name $$$$$$$$$$$$$4or$($int$i$+$9$,$i$K$ aRroup:ame 'lengt%$,$i$GG$)$$$$$$$$$$$$$*$$$$$$$$$$$$$$$$$""$Ret$t%e$name$o4$ t%e$current$cell$$$$$$$$$$$$$$$$$String$ Cell:ame$+$)!a.leCur or'getRange:ame$ (), ""$Ret$t%e$X!e)t$inter4ace$o4$t%e$current$cell$$$$$$$$$$$$$$$$$X!e)t$)Cell!e)t$ +$(X!e)t)$UnoRuntime'5uery1nter4ace$($$$$$$$$$$$$$$$$$$$$$$X!e)t'cla /$

5(

OpenOffice.org 3.1 Developer's Guide April !!"

T%,le Arc$itecture

)!a.le'getCell;y:ame$($ Cell:ame$)$), ""$Set$t%e$cell$content $o4$t%e$current$cell$to$.e$$$$$$$$$$$$$$$$$$""t%e$name$ o4$t%e$o4$an$autote)t$group$$$$$$$$$$$$$$$$$)Cell!e)t' etString$ ($aRroup:ame 6i7$), ""$Acce $t%e$autote)t$gruop$wit%$t%i $name$$$$$$$$$$$$$$$$$XAuto!e)tRroup$ )Rroup$+$($XAuto!e)tRroup$)$UnoRuntime'5uery1nter4ace$ ($$$$$$$$$$$$$$$$$$$$$XAuto!e)tRroup'cla /)Container'get;y:ame(aRroup:ame 6i7 )), ""$Ret$t%e$title $o4$eac%$autote)t$.loc-$in$t%i $group$$$$$$$$$$$$$$$$$String$ 67$a;loc-:ame $+$)Rroup'get!itle (), ""$Ma-e$ ure$t%at$t%e$autote)t$group$contain $at$lea t$one$.loc-$$$$$$$$$$$$$$$ i4$($a;loc-:ame 'lengt%$L$9$)$$$$$$$$$$$$$$$$$*$$$$$$$$$$$$$$$$$$$$$""$Split$ t%e$current$cell$vertically$into$two$ eperate$cell $$$$$$$$$$$$$$$$$$$$$ )!a.leCur or' plitRange$($( %ort)$8/$4al e$), ""$Put$t%e$cur or$in$t%e$newly$created$rig%t$%and$cell$$$$$$$$$$$$$$$$$$$$$$""$ and$ elect$it$$$$$$$$$$$$$$$$$$$$$)!a.leCur or'goRig%t$($( %ort)$8/$4al e$), ""$Split$t%i $cell$%oriOontally$to$ma-e$a$ eperate$ cell$$$$$$$$$$$$$$$$$$$$$$""$4or$eac%$Autote)t$.loc-$$$$$$$$$$$$$$$$$$$$$i4$ ($($a;loc-:ame 'lengt%$>8$)$L$9$)$$$$$$$$$$$$$$$$$$$$$$$$$ )!a.leCur or' plitRange$($$$$$$$$$$$$$$$$$$$$$$$$$$$$$$( %ort)$ (a;loc-:ame 'lengt%$>$8)/$true$), ""$loop$over$t%e$.loc-$name $$$$$$$$$$$$$$$$$$$$$4or$($int$&$+$9$,$&$K$ a;loc-:ame 'lengt%$,$&$GG$)$$$$$$$$$$$$$$$$$$$$$*$$$$$$$$$$$$$$$$$$$$$$$$$""$ Ret$t%e$X!e)t$inter4ace$o4$t%e$current$cell$$$$$$$$$$$$$$$$$$$$$$$$$)Cell!e)t$ +$(X!e)t)$UnoRuntime'5uery1nter4ace$($$$$$$$$$$$$$$$$$$$$$$$$$$$$$X!e)t'cla /$ )!a.le'getCell;y:ame$($$$$$$$$$$$$$$$$$$$$$$$$$$$$$)!a.leCur or'getRange:ame()$ )$), ""$Set$t%e$te)t$content $o4$t%e$current$cell$to$t%e$$$$$$$$$$$$$$$$$$$$$$$$$""$ title$o4$an$Autote)t$.loc-$$$$$$$$$$$$$$$$$$$$$$$$$)Cell!e)t' etString$ ($a;loc-:ame 6&7$), ""$Move$t%e$cur or$down$one$cell$$$$$$$$$$$$$$$$$$$$$$$$$ )!a.leCur or'goDown($( %ort)8/$4al e),$$$$$$$$$$$$$$$$$$$$$=$$$$$$$$$$$$$$$$$=$ ""$Ro$.ac-$to$t%e$cell$we$originally$ plit$$$$$$$$$$$$$$$$$ )!a.leCur or'gotoCell;y:ame$($ Cell:ame/$4al e$), ""$Ro$down$one$cell$$$$$$$$$$$$$$$$$)!a.leCur or'goDown($( %ort)8/$4al e),$$$$$ = XAuto!e)tRroup$)Rroup,$$$$$$$$$$$$$String$67$a;loc-:ame , ""$Add$a$dept%$ o$t%at$we$only$generate$P99$num.er $.e4ore$$$$$$$$$$$$$$""$ giving$up$on$4inding$a$random$autote)t$group$t%at$contain $autote)t$.loc- $$$$$ int$nDept%$+$9,$$$$$$$$$$$$$do$$$$$$$$$$$$$*$$$$$$$$$$$$$$$$$""$Renerate$a$ random/$po itive$num.er$w%ic%$i $lower$t%an$$$$$$$$$$$$$$$$$$""$t%e$num.er$o4$ autote)t$group $$$$$$$$$$$$$$$$$int$nRandom$+$Mat%'a. $($maRandom'ne)t1nt()$V$ aRroup:ame 'lengt%$), ""$Ret$t%e$autote)t$group$at$t%i $name$$$$$$$$$$$$$$$$$)Rroup$+$ ($XAuto!e)tRroup$)$UnoRuntime'5uery1nter4ace$ ($$$$$$$$$$$$$$$$$$$$$XAuto!e)tRroup'cla /$)Container'get;y:ame$($$$$$$$$$$$$$ aRroup:ame 6$nRandom$7$)$), ""$Fill$our$ tring$array$wit%$t%e$name $o4$all$t%e$.loc- $in$t%i $$$$$$$$$$$$$$ ""$group$$$$$$$$$$$$$$$$$a;loc-:ame $+$)Rroup'get(lement:ame (), ""$increment$our$dept%$counter$$$$$$$$$$$$$$$$$GGnDept%,$$$$$$$$$$$$$=$$$$$$$$$ w%ile$($nDept%$K$P99$WW$a;loc-:ame 'lengt%$++$9$),$$$$$$$$$$$$$""$14$we$ managed$to$4ind$a$group$containg$.loc- '''$$$$$$$$$$$$$i4$($a;loc-:ame 'lengt%$ L$9$)$$$$$$$$$$$$$*$$$$$$$$$$$$$$$$$""$Pic-$a$random$.loc-$in$t%i $group$and$

#$%pter 7 Text Documents

57

T%,le Arc$itecture

get$itS $$$$$$$$$$$$$$$$$""$XAuto!e)t(ntry$inter4ace$$$$$$$$$$$$$$$$$int$ nRandom$+$Mat%'a. $($maRandom'ne)t1nt()$$$$$$$$$$$$$$$$$$$$$$V$ a;loc-:ame 'lengt%$),$$$$$$$$$$$$$$$$$XAuto!e)t(ntry$)(ntry$+$($XAuto!e)t(ntry$ )$$$$$$$$$$$$$$$$$$$$$UnoRuntime'5uery1nter4ace$ ($$$$$$$$$$$$$$$$$$$$$$$$$$XAuto!e)t(ntry'cla /$)Rroup'get;y:ame$($$$$$$$$$$$$ a;loc-:ame 6$nRandom$7$)$),$$$$$$$$$$$$$$$$$""$in ert$t%e$modi4ied$autote)t$ .loc-$at$t%e$end$o4$t%e$document$$$$$$$$$$$$$$$$$)(ntry'apply!o$ ($m)DocCur or$), ""$Ret$t%e$title $o4$all$te)t$.loc- $in$t%i $Auto!e)t$group$$$$$$$$$$$$$$$$$ String$67$a;loc-!itle $+$)Rroup'get!itle (), ""$Ret$t%e$X:amed$inter4ace$o4$t%e$autote)t$group$$$$$$$$$$$$$$$$$X:amed$ )Rroup:amed$+$($X:amed$)$UnoRuntime'5uery1nter4ace$ ($$$$$$$$$$$$$$$$$$$$$X:amed'cla /$)Rroup$), ""$0utput$t%e$ %ort$cut$and$title$o4$t%e$random$.loc-$$$$$$$$$$$$$$$$$$""and$ t%e$name$o4$t%e$group$itS $4rom$$$$$$$$$$$$$$$$$Sy tem'out'println$($31n erted$ t%e$Autote)t$S3$G$a;loc-!itle 6nRandom7$$$$$$$$$$$$$$$$$$$$$$G$3S/$ %ortcut$S3$ G$a;loc-:ame 6nRandom7$G$3S$4rom$group$S3$$$$$$$$$$$$$$$$$$$$$$$$$$G$ )Rroup:amed'get:ame()$),$$$$$$$$$$$$$=$$$$$$$$$= ""$Ro$to$t%e$end$o4$t%e$document$$$$$$$$$m)DocCur or'goto(nd($4al e$),$$$$$$$$$ ""$1n ert$new$paragrap%$$$$$$$$$m)Doc!e)t'in ertControlC%aracter$($$$$$$$$$$$$$ m)DocCur or/$ControlC%aracter'PARARRAP?<;R(AT/$4al e$), ""$Po ition$cur or$in$new$paragrap%$$$$$$$$$)ParaCur or'gotoPreviou Paragrap%$ ($4al e$), ""$1n ert$a$ tring$in$t%e$new$paragrap%$$$$$$$$$m)Doc!e)t'in ertString$ ($m)DocCur or/$3Some$te)t$4or$a$new$autote)t$.loc-3/$4al e$), ""$Ro$to$t%e$end$o4$t%e$document$$$$$$$$$m)DocCur or'goto(nd($4al e$),$$$$$=$$$ catc%$(()ception$e)$$$$$$*$$$$$$$$$e'printStac-!race$($Sy tem'out$),$$$$$=$=

Accessing !$isting %*les


To access the tables contained in a te t document8 the te t document model supports the interface com.sun.star.te t.ATe tTablesSupplier with one single method get!e)t!a.le (). 0t returns a com.sun.star.te t.Te tTables ser5ice8 which is a named and inde ed collection8 that is8 tables are retrie5ed using com.sun.star.container.A6ame/ccess or com.sun.star.container.A0nde /ccess. The following snippet iterates o5er the te t tables in a gi5en te t document ob:ect m)Doc and colors them green.
import$com' un' tar'te)t'X!e)t!a.le Supplier,$import$ com' un' tar'container'X:ameAcce ,$import$ com' un' tar'container'X1nde)Acce ,$import$com' un' tar'.ean 'XPropertySet, ''' ""$4ir t$5uery$t%e$X!e)t!a.le Supplier$inter4ace$4rom$our$document$ X!e)t!a.le Supplier$)!a.le Supplier$+$(X!e)t!a.le Supplier)$ UnoRuntime'5uery1nter4ace($$$$$X!e)t!a.le Supplier'cla /$m)Doc$),$""$get$t%e$ ta.le $collection$X:ameAcce $):amed!a.le $+$)!a.le Supplier'get!e)t!a.le (), ""$now$5uery$t%e$X1nde)Acce $4rom$t%e$ta.le $collection$X1nde)Acce $

58

OpenOffice.org 3.1 Developer's Guide April !!"

T%,le Arc$itecture

)1nde)ed!a.le $+$(X1nde)Acce )$ UnoRuntime'5uery1nter4ace($$$$$X1nde)Acce 'cla /$):amed!a.le ), ""$we$need$propertie $XPropertySet$)!a.leProp $+$null, ""$get$t%e$ta.le $4or$(int$i$+$9,$i$K$)1nde)ed!a.le 'getCount(),$iGG)$ *$$$$$0.&ect$ta.le$+$)1nde)ed!a.le 'get;y1nde)(i),$$$$$""$t%e$propertie /$ plea eJ$$$$$)!a.leProp $+$(XPropertySet)$ UnoRuntime'5uery1nter4ace($$$$$$$$$XPropertySet'cla /$ta.le), ""$color$t%e$ta.le$lig%t$green$in$4ormat$9)RRRR;;$$$$$ )!a.leProp ' etPropertyValue(3;ac-Color3/$new$1nteger(9)CQFF;N)),$=

e$t (ields
Te t fields are te t contents that add a second le5el of information to te t ranges. Bsually their appearance fuses together with the surrounding te t8 but actually the presented te t comes from elsewhere. 4ield commands can insert the current date8 page number8 total page numbers8 a crossCreference to another area of te t8 the content of certain database fields8 and many 5ariables8 such as fields with changing 5alues8 into the document. There are some fields that contain their own data8 where others get the data from an attached field master.

Text

ields and Text

ield Masters

4ields are created using the com.sun.star.lang.A(ultiSer5ice4actory of the model before inserting them using in ert!e)tContent(). The following te t field ser5ices are a5ailable: e$t (ield ,ervice N%&e Description

#$%pter 7 Text Documents

5"

T%,le Arc$itecture

com.sun.star.te t.te tfield./nnotation com.sun.star.te t.te tfield./uthor com.sun.star.te t.te tfield.3ibliography

/nnotation created through Insert - Note. Shows the author of the document. 3ibliographic entry created by Insert Indexes and Tables - Bibliography Entry. The content is the source of the creation of bibliographic inde es. The se>uence KPropertyValueL in the property D4ieldsD contains pairs of the name of the field and its content8 such as: 0dentifierG/3C11 3ibliographicTypeG!

The names of the fields are defined in com.sun.star.te t.3ibliographyData4ield . / bibliographic entry depends on com.sun.star.te t.fieldmaster.3ibliography com.sun.star.te t.te tfield.Chapter Show the chapter information. com.sun.star.te t.te tfield.CharacterCount Show the character count of the document. com.sun.star.te t.te tfield.CombinedChar Combines up to si characters as one te t acters ob:ect that is formatted in two lines. com.sun.star.te t.te tfield.ConditionalTe 0nserts te t depending on a condition. t com.sun.star.te t.te tfield.Database The form letter field showing the content from a database. Depends on com.sun.star.te t.fieldmaster.Database. com.sun.star.te t.te tfield.Database6ame Shows the name of a database. com.sun.star.te t.te tfield.Database6e tS 0ncrements the cursor that points to a database et selection. com.sun.star.te t.te tfield.Database6umb Shows the set number of a database cursor. er+fSet com.sun.star.te t.te tfield.DatabaseSet6u Databases C /ny -ecord. Sets the number of a mber database cursor. com.sun.star.te t.te tfield.DateTime Shows a date or time 5alue. com.sun.star.te t.te tfield.DD$ Shows the result of a DD$ operation. Depends on com.sun.star.te t.fieldmaster.DD$. com.sun.star.te t.te tfield.docinfo.Change Shows the name of the author of the last /uthor change of the document. com.sun.star.te t.te tfield.docinfo.Change Shows the date and time of the last change of DateTime the document. com.sun.star.te t.te tfield.docinfo.Create Shows the name of the creator of the /uthor document. com.sun.star.te t.te tfield.docinfo.Create Shows the date and time of the document DateTime creation. com.sun.star.te t.te tfield.docinfo.Custo Shows the content of an user defined field of

(!

OpenOffice.org 3.1 Developer's Guide April !!"

T%,le Arc$itecture

m com.sun.star.te t.te tfield.docinfo.Descri ption com.sun.star.te t.te tfield.docinfo.$ditTi me com.sun.star.te t.te tfield.docinfo.0nfo)

the document info. Shows the description contained in the document information. Shows the time of the editing of the document. Shows the content of the first user defined info field of the document info. This ser5ice has been remo5ed in ++o ..)E use com.sun.star.te t.te tfield.docinfo.Custom instead. Shows the content of the second user defined info field of the document info. This ser5ice has been remo5ed in ++o ..)E use com.sun.star.te t.te tfield.docinfo.Custom instead. Shows the content of the third user defined info field of the document info. This ser5ice has been remo5ed in ++o ..)E use com.sun.star.te t.te tfield.docinfo.Custom instead. Shows the content of the fourth user defined info field of the document info. This ser5ice has been remo5ed in ++o ..)E use com.sun.star.te t.te tfield.docinfo.Custom instead. Shows the 2eywords contained in the document info. Shows the name of the author of the last printing. Shows the date and time of the last printing.

com.sun.star.te t.te tfield.docinfo.0nfo!

com.sun.star.te t.te tfield.docinfo.0nfo2

com.sun.star.te t.te tfield.docinfo.0nfo.

com.sun.star.te rds com.sun.star.te uthor com.sun.star.te ateTime com.sun.star.te n com.sun.star.te com.sun.star.te com.sun.star.te ctCount com.sun.star.te com.sun.star.te com.sun.star.te com.sun.star.te

t.te tfield.docinfo.;eywo t.te tfield.docinfo.Print/ t.te tfield.docinfo.PrintD

t.te tfield.docinfo.-e5isio Shows the re5ision contained in the document info. t.te tfield.docinfo.Sub:ect Shows the sub:ect contained in the document info. t.te tfield.docinfo.Title Shows the title contained in the document info. t.te tfield.$mbedded+b:e Shows the number of embedded ob:ects contained in the document. t.te tfield.$ tendedBser Shows the user data of the +ffice user. t.te tfield.4ile6ame Shows the file name <B-L= of the document. t.te tfield.7et$ pression Fariables C Show Fariable. Shows the 5alue set by the pre5ious occurrence of Set$ pression. t.te tfield.7et-eference -eferences C 0nsert -eference. Shows a reference to a reference mar28 boo2mar28 number range field8 footnote or an endnote.

#$%pter 7 Text Documents

(1

T%,le Arc$itecture

com.sun.star.te t.te tfield.7raphic+b:ect Count com.sun.star.te t.te tfield.?iddenParagra ph com.sun.star.te t.te tfield.?iddenTe t com.sun.star.te t.te tfield.0nput com.sun.star.te t.te tfield.0nputBser com.sun.star.te t.te tfield.&ump$dit com.sun.star.te t.te tfield.(acro com.sun.star.te t.te tfield.PageCount com.sun.star.te t.te tfield.Page6umber com.sun.star.te t.te tfield.ParagraphCoun t com.sun.star.te t.te tfield.-eferencePage 7et com.sun.star.te t.te tfield.-eferencePage Set com.sun.star.te t.te tfield.Script com.sun.star.te t.te tfield.Set$ pression

Shows the number of graphic ob:ect in the document. Depending on a condition8 the field hides the paragraph it is contained in. Depending on a condition the field shows or hides a te t. The field acti5ates a dialog to input a 5alue that changes a related Bser field or
Set()pre ion$4ield'$

com.sun.star.te t.te tfield.TableCount com.sun.star.te t.te tfield.Table4ormula com.sun.star.te t.te tfield.Template6ame com.sun.star.te t.te tfield.Bser

com.sun.star.te t.te tfield.*ordCount

The field acti5ates a dialog to input a string that is displayed by the field. This field is not connected to 5ariables. / placeholder field with an attached interaction to insert te t8 a te t table8 te t frame8 graphic ob:ect or an +L$ ob:ect. / field connected to a macro that is e ecuted on a clic2 to the field. To e ecute such a macro8 use the dispatch <cf. /ppendi =. Shows the number of pages of the document. Shows the page number <current8 pre5ious8 ne t=. Shows the number of paragraphs contained in the document. Displays the page number with respect to the reference point8 that is determined by the te t field -eferencePageSet. 0nserts a starting point for additional page numbers that can be switched on or off. Contains a script or a B-L to a script. Fariables C Set Fariable. / 5ariable field. The 5alue is 5alid until the ne t occurrence of Set()pre ion field. The actual 5alue depends on com.sun.star.te t.fieldmaster.Set$ pression. Shows the number of te t tables of the document. Contains a formula to calculate in a te t table. Shows the name of the template the current document is created from. Fariables C Bser 4ield. Creates a global document 5ariable and displays it whene5er this field occurs in the te t. Depends on com.sun.star.te t.fieldmaster.Bser. Shows the number of words contained in the document.

OpenOffice.org 3.1 Developer's Guide April !!"

T%,le Arc$itecture

/ll fields support the interfaces com.sun.star.te t.ATe t4ield8 com.sun.star.util.ABpdatable8 com.sun.star.te t.ADependentTe t4ield and the ser5ice com.sun.star.te t.Te tContent. The method getPre entation() of the interface com.sun.star.te t.ATe t4ield returns the te tual representation of the result of the te t field operation8 such as a date8 time8 5ariable 5alue8 or the command8 such as C?/PT$-8 T0($ <fi ed= depending on the boolean parameter. The method update() of the interface com.sun.star.util.ABpdatableaffects only the following field types: Date and time fields are set to the current date and time. The ()tendedU er fields that show parts of the user data set for +pen+ffice.org8 such as the 6ame8 City8 Phone 6o. and the /uthor fields that are set to the current 5alues. The File:ame fields are updated with the current name of the file. The Doc1n4o'XXX fields are updated with the current document info of the document.

/ll other fields ignore calls to update(). Some of these fields need a field master that pro5ides the data that appears in the field. This applies to the field types Data.a e8 Set()pre ion8 DD(8 U er and ;i.liograp%y. The interface com.sun.star.te t.ADependentTe t4ield handles these pairs of 4ield(asters and Te t4ields. The method attac%!e)tFieldMa ter() must be called prior to inserting the field into the document. The method get!e)tFieldMa ter() does not wor2 unless the dependent field is inserted into the document. To create a 5alid te t field master8 the instance has to be created using the com.sun.star.lang.A(ultiSer5ice4actory interface of the model with the appropriate ser5ice name: e$t (ield /%ster ,ervice N%&es com.sun.star.te t.fieldmaster.Bser com.sun.star.te t.fieldmaster.DD$ com.sun.star.te t.fieldmaster.Set$ pressio n com.sun.star.te t.fieldmaster.Database com.sun.star.te t.fieldmaster.3ibliography Description Contains the global 5ariable that is created and displayed by the fieldtype com.sun.star.te t.te tfield.Bser. The DD$ command for a com.sun.star.te t.te tfield.DD$. 6umbering settings if the corresponding com.sun.star.te t.te tfield.Set$ pression is a number range. / sub type of e pression. Data source definition for a com.sun.star.te t.te tfield.Database. Display settings and sorting for com.sun.star.te t.te tfield.3ibliography.

The property 6ame has to be set after the field instance is created8 e cept for the Data.a e field master type where the properties Data.a e:ame8 Data.a e!a.le:ame8 DataColumn:ame and Data.a eCommand!ype are set instead of the :ame property.
#$%pter 7 Text Documents (3

T%,le Arc$itecture

To access e isting te t fields and field masters8 use the interface com.sun.star.te t.ATe t4ieldsSupplier that is implemented at the te t document model. 0ts method get!e)tField () returns a com.sun.star.te t.Te t4ields container which is a com.sun.star.container.A$numeration/ccess and can be refreshed through the re4re %() method in its interface com.sun.star.util.A-efreshable. 0ts method get!e)tFieldMa ter () returns a com.sun.star.te t.Te t4ield(asters container holding the te t field masters of the document. This container pro5ides a com.sun.star.container.A6ame/ccess interface. /ll field masters8 e cept for Data.a e are named by the ser5ice name followed by the name of the field master. The Data.a e field masters create their names by appending the Data.a e:ame8 Data!a.le:ame and DataColumn:ame to the ser5ice name. Consider the following e amples for this naming con5ention: Dcom.sun.star.te t.fieldmaster.Set$ pression.0 llustrationD (aster for 0llustration number range. 6umber ranges are builtCin Set()pre ion fields present in e5ery document. Dcom.sun.star.te t.fieldmaster.Bser.CompanyD (aster for U er field <global document 5ariable=8 inserted with display name Company. Dcom.sun.star.te t.fieldmaster.Database.3iblio (aster for form letter field referring to the graphy.biblio.0dentifierD column 1denti4ier in the builtCin dbase database table biblio. $ach te t field master has a property 1n tance:ame that contains its name in the format of the related container. Some Set()pre ion te t field masters are always a5ailable if they are not deleted. These are the masters with the names Te t8 0llustration8 Table and Drawing. They are predefined as number range field masters used for captions of te t frames8 graphics8 te t tables and drawings. 6ote that these predefined names are internal names that are usually not used at the user interface. The following methods show how to create and insert te t fields.
"##$!%i $met%od$in ert $.ot%$a$date$4ield$and$a$u er$4ield$containing$t%e$ num.er$SBPS$$#"$protected$void$!e)tField()ample()$*$$$$$try$*$$$$$$$$$""$U e$ t%e$te)t$documentS $4actory$to$create$a$Date!ime$te)t$4ield/$$$$$$$$$$""$and$ acce $itS $$$$$$$$$""$X!e)tField$inter4ace$$$$$$$$$X!e)tField$)DateField$+$ (X!e)tField)$UnoRuntime'5uery1nter4ace($$$$$$$$$$$$$X!e)tField'cla /$ m)DocFactory'create1n tance($$$$$$$$$$$$$$$$$3com' un' tar'te)t'te)t4ield'Date !ime3)), ""$1n ert$it$at$t%e$end$o4$t%e$document$$$$$$$$$m)Doc!e)t'in ert!e)tContent$ ($m)Doc!e)t'get(nd()/$)DateField/$4al e$), ""$U e$t%e$te)t$documentS $4actory$to$create$a$u er$te)t$4ield/$$$$$$$$$$""$ and$acce $itS $XDependent!e)tField$inter4ace$$$$$$$$$XDependent!e)tField$

(&

OpenOffice.org 3.1 Developer's Guide April !!"

T%,le Arc$itecture

)U erField$+$(XDependent!e)tField)$UnoRuntime'5uery1nter4ace$ ($$$$$$$$$$$$$XDependent!e)tField'cla /$m)DocFactory'create1n tance($$$$$$$$$$ 3com' un' tar'te)t'te)t4ield'U er3)), ""$Create$a$4ieldma ter$4or$our$newly$created$U er$!e)t$4ield/$and$acce $itS $ ""$XPropertySet$inter4ace$$$$$$$$$XPropertySet$)Ma terPropSet$+$(XPropertySet)$ UnoRuntime'5uery1nter4ace($$$$$$$$$$$$$XPropertySet'cla /$ m)DocFactory'create1n tance($$$$$$$$$$$$$$$$$3com' un' tar'te)t'4ieldma ter'U er3)), ""$Set$t%e$name$and$value$o4$t%e$FieldMa ter$$$$$$$$$ )Ma terPropSet' etPropertyValue$(3:ame3/$3U er(mperor3),$$$$$$$$$ )Ma terPropSet' etPropertyValue$(3Value3/$new$1nteger(BP)), ""$Attac%$t%e$4ield$ma ter$to$t%e$u er$4ield$$$$$$$$$ )U erField'attac%!e)tFieldMa ter$()Ma terPropSet), ""$Move$t%e$cur or$to$t%e$end$o4$t%e$document$$$$$$$$$ m)DocCur or'goto(nd(4al e),$$$$$$$$$""$in ert$a$paragrap%$.rea-$u ing$t%e$ XSimple!e)t$inter4ace$$$$$$$$$ m)Doc!e)t'in ertControlC%aracter($$$$$$$$$$$$$$m)DocCur or/$ ControlC%aracter'PARARRAP?<;R(AT/$4al e), ""$1n ert$t%e$u er$4ield$at$t%e$end$o4$t%e$document$$$$$$$$$ m)Doc!e)t'in ert!e)tContent(m)Doc!e)t'get(nd()/$)U erField/$4al e),$$$$$=$ catc%$(()ception$e)$*$$$$$$$$$e'printStac-!race$(Sy tem'out),$$$$$=$=

7oo1&%r1s
/ 3oo2mar2 is a te t content that mar2s a position inside of a paragraph or a te t selection that supports the com.sun.star.te t.Te tContent ser5ice. To search for a boo2mar28 the te t document model implements the interface com.sun.star.te t.A3oo2mar2sSupplier that supplies a collection of the boo2mar2s. The collection supports the ser5ice com.sun.star.te t.3oo2mar2s which consists of com.sun.star.container.A6ame/ccess and com.sun.star.container.A0nde /ccess. The boo2mar2 name can be read and changed through its <com.sun.star.container.A6amed= interface. To insert8 remo5e or change te t8 or attributes starting from the position of a boo2mar28 retrie5e its com.sun.star.te t.ATe t-ange by calling getAnc%or() at its com.sun.star.te t.ATe tContent interface. Then use getString() or etString() at the X!e)tRange8 or pass this X!e)tRange to methods e pecting a te t range8 such as com.sun.star.te t.ASimpleTe t:createTe tCursor3y-ange<=8 com.sun.star.te t.ASimpleTe t:insertString<= or com.sun.star.te t.ATe t:insertTe tContent<=.

#$%pter 7 Text Documents

(5

T%,le Arc$itecture

ip 8 (a2e sure that the access to the boo2mar2 anchor position always uses the correct te t ob:ect. Since e5ery X!e)tRange 2nows its surrounding te t8 use the get!e)t() method of the boo2mar2@s anchor. 0t is not allowed to call a!e)t'create!e)tCur or;yRange(oAnc%or) when a!e)t represents a different area of the document than the boo2mar2 <different te t frames8 body te t and te t frame...= Bse the create1n tance method of the com.sun.star.lang.A(ultiSer5ice4actory interface pro5ided by the te t document model to insert an new boo2mar2 into the document. The ser5ice name is Dcom' un' tar'te)t';oo-mar-D. Then use the boo2mar2@s com.sun.star.container.A6amed interface and call et:ame(). 0f no name is set8 +pen+ffice.org ma2es up generic names8 such as 3oo2mar2! and 3oo2mar22. Similarly8 if a name is used that is not uni>ue8 writer automatically appends a number to the boo2mar2 name. The boo2mar2 ob:ect obtained from create1n tance() can only be inserted once.
""$in erting$and$retrieving$a$.oo-mar-$0.&ect$.oo-mar-$+$ m)DocFactory'create1n tance$($3com' un' tar'te)t';oo-mar-3$), ""$name$t%e$.oo-mar-$X:amed$):amed$+$(X:amed)$UnoRuntime'5uery1nter4ace$($$$$$$ X:amed'cla /$.oo-mar-$),$):amed' et:ame(3MyUni5ue;oo-mar-:ame3), ""$get$X!e)tContent$inter4ace$$X!e)tContent$)!e)tContent$+$(X!e)tContent)$ UnoRuntime'5uery1nter4ace$($$$$$$X!e)tContent'cla /$.oo-mar-$), ""$in ert$.oo-mar-$at$t%e$end$o4$t%e$document$""$in tead$o4$m)Doc!e)t'get(nd$ you$could$u e$a$te)t$cur orS $X!e)tRange$inter4ace$or$any$X!e)tRange$ m)Doc!e)t'in ert!e)tContent$($m)Doc!e)t'get(nd()/$)!e)tContent/$4al e$), ""$5uery$X;oo-mar- Supplier$4rom$document$model$and$get$.oo-mar- $collection$ X;oo-mar- Supplier$);oo-mar- Supplier$+$ (X;oo-mar- Supplier)UnoRuntime'5uery1nter4ace($$$$$X;oo-mar- Supplier'cla /$ )2riterComponent),$X:ameAcce $):amed;oo-mar- $+$ );oo-mar- Supplier'get;oo-mar- (), ""$retrieve$.oo-mar-$.y$name$0.&ect$4ound;oo-mar-$+$ ):amed;oo-mar- 'get;y:ame(3MyUni5ue;oo-mar-:ame3),$X!e)tContent$)Found;oo-mar-$ +$(X!e)tContent)UnoRuntime'5uery1nter4ace($$$$$X!e)tContent'cla /$ 4ound;oo-mar-), ""$wor-$wit%$.oo-mar-$X!e)tRange$)Found$+$)Found;oo-mar-'getAnc%or(),$ )Found' etString(3$!%e$t%roat$mi-e/$glued$to$%er$nec-/$3$$$$$$G$3loo-ed$a $ muc%$a $po i.le$li-e$an$analge ic$dermadi -'3),

2nde$es %nd 2nde$ /%r1s


0nde es are te t contents that pull together information that is dispersed o5er the document. They can contain chapter headings8 locations of 2ey words8 locations of arbitrary inde mar2s and locations of te t ob:ects8 such as illustrations8 ob:ects or tables. 0n addition8 +pen+ffice.org features a bibliographical inde .

((

OpenOffice.org 3.1 Developer's Guide April !!"

1ndexes

2nde$es
The following inde ser5ices are a5ailable in +pen+ffice.org: 2nde$ ,ervice N%&e com.sun.star.te t.Document0nde com.sun.star.te t.Content0nde com.sun.star.te t.Bser0nde com.sun.star.te t.0llustration0nde com.sun.star.te t.+b:ect0nde com.sun.star.te t.Table0nde com.sun.star.te t.3ibliography Description alphabetical inde table of contents user defined inde table of all illustrations contained in the document table of all ob:ects contained in the document table of all te t tables contained in the document bibliographical inde

To access the inde es of a document8 the te t document model supports the interface com.sun.star.te t.ADocument0nde esSupplier with a single method getDocument1nde)e (). The returned ob:ect is a com.sun.star.te t.Document0nde es ser5ice supporting the interfaces com.sun.star.container.A0nde /ccess and com.sun.star.container.A6ame/ccess. /ll inde es support the ser5ices com.sun.star.te t.Te tContent and com.sun.star.te t.3ase0nde that include the interface com.sun.star.te t.ADocument0nde . This interface is used to access the ser5ice name of the inde and update the current content of an inde :
tring$getService:ame()$void$update()

4urthermore8 inde es ha5e properties and a name8 and support:


com' un' tar'.ean 'XPropertySet

pro5ides the properties that determine how the inde is created and which elements are included into the inde .
com' un' tar'container'X:amed

pro5ides a uni>ue name of the inde 8 not necessarily the title of the inde . /n inde is usually composed of two te t sections which are pro5ided as properties. The pro5ided property ContentSection includes the complete inde and the property ?eaderSection contains the title if there is one. They enable the inde to ha5e bac2ground or column attributes independent of the surrounding page format 5alid at the inde position. 0n addition8 there may be different settings for the content and the heading of the inde . ?owe5er8 these te t sections are not part of the document@s te t section container. The inde es are structured by le5els. The number of le5els depends on the inde type. The content inde has ten le5els8 corresponding to the number of a5ailable chapter numbering le5els8 which is ten. /lphabetical inde es ha5e four le5els8 one of which is used to insert separators8 that are usually characters that show the alphabet. The bibliography has 22 le5els8

#$%pter 7 Text Documents

(7

1ndexes

according to the number of a5ailable bibliographical type entries <com.sun.star.te t.3ibliographyDataType=. /ll other inde types only ha5e one le5el. 4or all le5els8 define a separate structure that is pro5ided by the property LevelFormat of the ser5ice com.sun.star.te t.3ase0nde . LevelFormat contains the 5arious le5els as a com.sun.star.container.A0nde -eplace ob:ect. $ach le5el is a se>uence of com.sun.star.beans.PropertyFalues which are defined in the ser5ice com.sun.star.te t.Document0nde Le5el4ormat. /lthough LevelFormat pro5ides a le5el for the heading8 changing that le5el is not supported. $ach com.sun.star.beans.PropertyFalues se>uence has to contain at least one com.sun.star.beans.PropertyFalue with the name !o-en!ype. This PropertyValue struct must contain one of the following string 5alues in its Falue member 5ariable: o1en ype )%lue 3,tring4 D!o-en(ntry:um.erD /e%ning The number of an entry. This is only supported in tables of content and it mar2s the appearance of the chapter number. Te t of the entry8 for e ample8 it might contain the heading te t in tables of content or the name of a te t reference in a bibliography. (ar2s a tab stop to be inserted. Addition%l ,e9uence /e&*ers 3option%l4
C%aracterStyle:ame

D!o-en(ntry!e)tD

C%aracterStyle:ame

D!o-en!a.StopD

D!o-en!e)tD D!o-enPage:um.erD D!o-enC%apter1n4oD

0nserted te t.

(ar2s the insertion of the page number. (ar2s the insertion of a chapter C%aracterStyle:ame field to be inserted. +nly supported in alphabetical inde es. Chapter4ormat

!a.StopPo ition !a.StopRig%tAligned !a.StopFillC%aracter C%aracterStyle:ame C%aracterStyle:ame !e)t C%aracterStyle:ame

D!o-en?yperlin-Star tD D!o-en?yperlin-(ndD D!o-en;i.liograp%yD ataFieldD

Start of a hyperlin2 to :ump to the referred heading. +nly supported in tables of content. $nd of a hyperlin2 to :ump to the referred heading. +nly supported in tables of content. ;i.liograp%yDataField 0dentifies one of the .) possible C%aracterStyle:ame 3ibliographyData4ields. The number .) comes from the 0DL

(8

OpenOffice.org 3.1 Developer's Guide April !!"

1ndexes

reference of 3ilbliographyData4ields. /n e ample for such a se>uence of PropertyValue struct could be constructed li2e this:
PropertyValue67$inde)!o-en $+$new$PropertyValue687,$inde)!o-en $697$+$new$ PropertyValue(),$inde)!o-en $697':ame$+$3!o-en!ype3,$inde)!o-en $697'Value$+$ 3!o-en?yperlin-Start3,

The following table e plains the se>uence members which can be present8 in addition to the !o-en!ype member8 as mentioned abo5e. Addition%l Properties of co&.sun.st%r.te$t.Docu&ent2nde$+evel(or&%t tring C 6ame of the character style that has to be applied to the appearance of the entry. !a.StopPo ition long C Position of the tab stop in !/!)) mm. !a.StopRig%tAligned .oolean C The tab stop is to be inserted at the end of the line and right aligned. This is used before page number entries. !a.StopFillC%aracter tring C The first character of this string is used as a fill character for the tab stop. C%apterFormat %ort C Type of the chapter info as defined in com.sun.star.te t.Chapter4ormat. ;i.liograp%yDataField Type of the bibliographical entry as defined in com.sun.star.te t.3ibliographyData4ield.
C%aracterStyle:ame

2nde$ &%r1s
0nde mar2s are te t contents whose contents and positions are collected and displayed in inde es. To access all inde mar2s that are related to an inde 8 use the property 1nde)Mar- of the inde . 0t contains a se>uence of com.sun.star.te t.ADocument0nde (ar2 interfaces. /ll inde mar2s support the ser5ice com.sun.star.te t.3ase0nde (ar2 that includes com.sun.star.te t.Te tContent. /lso8 they all implement the interfaces com.sun.star.te t.ADocument0nde (ar2 and com.sun.star.beans.APropertySet. The XDocument1nde)Mar- inherits from X!e)tContent and defines two methods:
tring$getMar-(ntry()$void$ etMar-(ntry($6in7$ tring$an1nde)(ntry)

+pen+ffice.org supports three different inde mar2 ser5ices:


com.sun.star.te t.Document0nde (ar2 for entries in alphabetical inde es. com.sun.star.te t.Bser0nde (ar2for user defined inde es. com.sun.star.te t.Content0nde (ar2 for entries in tables of content which are independent
("

#$%pter 7 Text Documents

1ndex m%r2s

from chapter headings. /n inde mar2 can be set at a point in te t or it can mar2 a portion of a paragraph8 usually a word. 0t cannot contain te t across paragraph brea2s. 0f the inde mar2 does not include te t8 the ;a e1nde)Mar- property Alternative!e)t has to be set8 otherwise there will be no string to insert into the inde . 0nserting Content1nde)Mar- and a table of contents inde :
"##$!%i $met%od$demon trate $%ow$to$in ert$inde)e $and$inde)$mar- $$#"$ protected$void$1nde)()ample$()$*$$$$$try$$$$$*$$$$$$$$$""$Ro$to$t%e$end$o4$t%e$ document$$$$$$$$$m)DocCur or'goto(nd($4al e$),$$$$$$$$$""$1n ert$a$new$ paragrap%$and$po ition$t%e$cur or$in$it$$$$$$$$$ m)Doc!e)t'in ertControlC%aracter$($m)DocCur or/$ ControlC%aracter'PARARRAP?<;R(AT/$4al e$),$$$$$$$$$XParagrap%Cur or$ )ParaCur or$+$(XParagrap%Cur or)$$$$$$$$$$$$$$ UnoRuntime'5uery1nter4ace($XParagrap%Cur or'cla /$m)DocCur or$),$$$$$$$$$ )ParaCur or'gotoPreviou Paragrap%$($4al e$), ""$Create$a$new$Content1nde)Mar-$and$get$itS $XPropertySet$inter4ace$$$$$$$$$ XPropertySet$)(ntry$+$(XPropertySet)$ UnoRuntime'5uery1nter4ace($XPropertySet'cla /$$$$$$$$$$$$$$ m)DocFactory'create1n tance$($3com' un' tar'te)t'Content1nde)Mar-3$)$), ""$Set$t%e$te)t$to$.e$di played$in$t%e$inde)$$$$$$$$$)(ntry' etPropertyValue$($ 3Alternative!e)t3/$3;ig$dog J$Falling$on$my$%eadJ3$), ""$!%e$Level$property$<mu t<$.e$ et$$$$$$$$$)(ntry' etPropertyValue$($3Level3/$ new$S%ort$($( %ort)$8$)$), ""$Create$a$Content1nde)$and$acce $itS $XPropertySet$inter4ace$$$$$$$$$ XPropertySet$)1nde)$+$(XPropertySet)$ UnoRuntime'5uery1nter4ace($XPropertySet'cla /$$$$$$$$$$$$$$ m)DocFactory'create1n tance$($3com' un' tar'te)t'Content1nde)3$)$), ""$Again/$t%e$Level$property$<mu t<$.e$ et$$$$$$$$$)1nde)' etPropertyValue$ ($3Level3/$new$S%ort$($( %ort)$89$)$), ""$Acce $t%e$X!e)tContent$inter4ace $o4$.ot%$t%e$1nde)$and$t%e$1nde)Mar-$$$$$$ X!e)tContent$)1nde)Content$+$(X!e)tContent)$UnoRuntime'5uery1nter4ace($$$$$$$$$ X!e)tContent'cla /$)1nde)$),$$$$$$$$$X!e)tContent$)(ntryContent$+$ (X!e)tContent)$UnoRuntime'5uery1nter4ace($$$$$$$$$$$$$$X!e)tContent'cla /$ )(ntry$), ""$1n ert$.ot%$in$t%e$document$$$$$$$$$m)Doc!e)t'in ert!e)tContent$ ($m)DocCur or/$)(ntryContent/$4al e$),$$$$$$$$$m)Doc!e)t'in ert!e)tContent$ ($m)DocCur or/$)1nde)Content/$4al e$), ""$Ret$t%e$XDocument1nde)$inter4ace$o4$t%e$1nde)$$$$$$$$$XDocument1nde)$ )Doc1nde)$+$(XDocument1nde))$ UnoRuntime'5uery1nter4ace($$$$$$$$$$$$$$XDocument1nde)'cla /$)1nde)$), ""$And$call$itS $update$met%od$$$$$$$$$)Doc1nde)'update(),$$$$$=$$$$$catc%$ (()ception$e)$$$$$$*$$$$$$$$$e'printStac-!race$($Sy tem'out$),$$$$$=$=

7!

OpenOffice.org 3.1 Developer's Guide April !!"

1ndex m%r2s

"eference /%r1s
/ reference mar2 is a te t content that is used as a target for com.sun.star.te t.te tfield.7et-eference te t fields. These te t fields show the contents of reference mar2s in a te t document and allows the user to :ump to the reference mar2. -eference mar2s support the com.sun.star.te t.ATe tContent and com.sun.star.container.A6amed interfaces. They can be accessed by using the te t document@s com.sun.star.te t.A-eference(ar2sSupplier interface that defines a single method getRe4erenceMar- (). The returned collection is a com.sun.star.te t.-eference(ar2s ser5ice which has a com.sun.star.container.A6ame/ccess and a com.sun.star.container.A0nde /ccess interface.
"##$!%i $met%od$demon trate $%ow$to$create$and$in ert$re4erence$mar- /$and$ RetRe4erence$!e)t$Field $$#"$protected$void$Re4erence()ample$()$*$$$$$try$*$$$$ ""$Ro$to$t%e$end$o4$t%e$document$$$$$$$$$m)DocCur or'goto(nd(4al e), ""$1n ert$a$paragrap%$.rea-$$$$$$$$$m)Doc!e)t'in ertControlC%aracter($$$$$$$$$$ m)DocCur or/$ControlC%aracter'PARARRAP?<;R(AT/$4al e), ""$Ret$t%e$Paragrap%$cur or$$$$$$$$$XParagrap%Cur or$)ParaCur or$+$ (XParagrap%Cur or)$ UnoRuntime'5uery1nter4ace($$$$$$$$$$$$$XParagrap%Cur or'cla /$m)DocCur or), ""$Move$t%e$cur or$into$t%e$new$paragrap%$$$$$$$$$ )ParaCur or'gotoPreviou Paragrap%(4al e), ""$Create$a$new$Re4erenceMar-$and$get$itS $X:amed$inter4ace$$$$$$$$$X:amed$ )Re4Mar-$+$(X:amed)$UnoRuntime'5uery1nter4ace(X:amed'cla /$$$$$$$$$$$$$$ m)DocFactory'create1n tance(3com' un' tar'te)t'Re4erenceMar-3)), ""$Set$t%e$name$to$!a.le?eader$$$$$$$$$)Re4Mar-' et:ame(3!a.le?eader3), ""$Ret$t%e$!e)t!a.le Supplier$inter4ace$o4$t%e$document$$$$$$$$$ X!e)t!a.le Supplier$)!a.leSupplier$+$(X!e)t!a.le Supplier)$ UnoRuntime'5uery1nter4ace($$$$$$$$$$$$$X!e)t!a.le Supplier'cla /$m)Doc), ""$Ret$an$X1nde)Acce $o4$!e)t!a.le $$$$$$$$$X1nde)Acce $)!a.le $+$ (X1nde)Acce )$UnoRuntime'5uery1nter4ace($$$$$$$$$$$$$X1nde)Acce 'cla /$ )!a.leSupplier'get!e)t!a.le ()), ""$2eSve$only$in erted$one$ta.le/$ o$get$t%e$4ir t$one$4rom$inde)$Oero$$$$$$$$$ X!e)t!a.le$)!a.le$+$(X!e)t!a.le)$ UnoRuntime'5uery1nter4ace($$$$$$$$$$$$$X!e)t!a.le'cla /$ )!a.le 'get;y1nde)(9)), ""$Ret$t%e$4ir t$cell$4rom$t%e$ta.le$$$$$$$$$X!e)t$)!a.le!e)t$+$(X!e)t)$ UnoRuntime'5uery1nter4ace($$$$$$$$$$$$$X!e)t'cla /$ )!a.le'getCell;y:ame(3A83)), ""$Ret$a$te)t$cur or$4or$t%e$4ir t$cell$$$$$$$$$X!e)tCur or$)!a.leCur or$+$ )!a.le!e)t'create!e)tCur or(), ""$Ret$t%e$X!e)tContent$inter4ace$o4$t%e$re4erence$mar-$ o$we$can$in ert$it$$$$ X!e)tContent$)Content$+$(X!e)tContent)$ UnoRuntime'5uery1nter4ace($$$$$$$$$$$$$X!e)tContent'cla /$)Re4Mar-), ""$1n ert$t%e$re4erence$mar-$into$t%e$4ir t$cell$o4$t%e$ta.le$$$$$$$$$ )!a.le!e)t'in ert!e)tContent$()!a.leCur or/$)Content/$4al e), ""$Create$a$SRetRe4erenceS$te)t$4ield$to$re4er$to$t%e$re4erence$mar-$we$&u t$ in erted/$$$$$$$$$""$and$get$itS $XPropertySet$inter4ace$$$$$$$$$XPropertySet$

#$%pter 7 Text Documents

71

1ndex m%r2s

)FieldProp $+$(XPropertySet)$ UnoRuntime'5uery1nter4ace($$$$$$$$$$$$$XPropertySet'cla /$ m)DocFactory'create1n tance($$$$$$$$$$$$$$$$$3com' un' tar'te)t'te)t4ield'RetR e4erence3)), ""$Ret$t%e$XRe4erenceMar- Supplier$inter4ace$o4$t%e$document$$$$$$$$$ XRe4erenceMar- Supplier$)Re4Supplier$+$(XRe4erenceMar- Supplier)$ UnoRuntime'5uery1nter4ace($$$$$$$$$$$$$XRe4erenceMar- Supplier'cla /$m)Doc), ""$Ret$an$X:ameAcce $w%ic%$re4er $to$all$in erted$re4erence$mar- $$$$$$$$$ X:ameAcce $)Mar- $+$(X:ameAcce )$ UnoRuntime'5uery1nter4ace(X:ameAcce 'cla /$$$$$$$$$$$$$ )Re4Supplier'getRe4erenceMar- ()), ""$Put$t%e$name $o4$eac%$re4erence$mar-$into$an$array$o4$ tring $$$$$$$$$ String67$a:ame $+$)Mar- 'get(lement:ame (), ""$Ma-e$ ure$t%at$at$lea t$8$re4erence$mar-$actually$e)i t $$$$$$$$$$""$(well/$ we$&u t$in erted$oneJ)$$$$$$$$$i4$(a:ame 'lengt%$L$9)$*$$$$$$$$$$$$$""$0utput$ t%e$name$o4$t%e$4ir t$re4erence$mar-$(S!a.le?eaderS)$$$$$$$$$$$$$ Sy tem'out'println$(3RetRe4erence$te)t$4ield$in erted$4or$Re4erenceMar-$F$3$$$$ G$a:ame 697), ""$Set$t%e$Source:ame$o4$t%e$RetRe4erence$te)t$4ield$to$S!a.le?eaderS$$$$$$$$$$ )FieldProp ' etPropertyValue(3Source:ame3/$a:ame 697), ""$ peci4y$t%at$t%e$ ource$i $a$re4erence$mar-$(could$al o$.e$a$4ootnote/$$$$$$ ""$.oo-mar-$or$ e5uence$4ield)$$$$$$$$$$$$$)FieldProp ' etPropertyValue$ (3Re4erenceFieldSource3/$new$ S%ort($$$$$$$$$$$$$$$$$Re4erenceFieldSource'R(F(R(:C(<MART)), ""$2e$want$t%e$re4erence$di played$a $Sa.oveS$or$S.elowS$$$$$$$$$$$$$ )FieldProp ' etPropertyValue(3Re4erenceFieldPart3/$$$$$$$$$$$$$$$$$$new$S%ort$ (Re4erenceFieldPart'UP<D02:)), ""$Ret$t%e$X!e)tContent$inter4ace$o4$t%e$RetRe4erence$te)t$4ield$$$$$$$$$$$$$ X!e)tContent$)Re4Content$+$(X!e)tContent)$UnoRuntime'5uery1nter4ace($$$$$$$$$$$ X!e)tContent'cla /$)FieldProp ), ""$Ro$to$t%e$end$o4$t%e$document$$$$$$$$$$$$$m)DocCur or'goto(nd(4al e), ""$Ma-e$ ome$te)t$to$precede$t%e$re4erence$$$$$$$$$$$$$ m)Doc!e)t'in ertString(m)Doc!e)t'get(nd()/$3!%e$ta.le$3/$4al e), ""$1n ert$t%e$te)t$4ield$$$$$$$$$$$$$ m)Doc!e)t'in ert!e)tContent(m)Doc!e)t'get(nd()/$)Re4Content/$4al e), ""$And$ ome$te)t$a4ter$t%e$re4erence''$$$$$$$$$$$$$ m)Doc!e)t'in ertString($m)Doc!e)t'get(nd()/$$$$$$$$$$$$$$$$$$3$contain $t%e$ um$o4$ ome$random$num.er '3/$4al e), ""$Re4re %$t%e$document$$$$$$$$$$$$$XRe4re %a.le$)Re4re %$+$(XRe4re %a.le)$ UnoRuntime'5uery1nter4ace($$$$$$$$$$$$$$$$$XRe4re %a.le'cla /$m)Doc),$$$$$$$$$ )Re4re %'re4re %(),$$$$$$$$$=$$$$$=$catc%$(()ception$e)$ *$$$$$$$$$e'printStac-!race(Sy tem'out),$$$$$=$=

The name of a reference mar2 can be used in a com.sun.star.te t.te tfield.7et-eference te t field to refer to the position of the reference mar2.

OpenOffice.org 3.1 Developer's Guide April !!"

1ndex m%r2s

(ootnotes %nd !ndnotes


4ootnotes and endnotes are te t contents that pro5ide bac2ground information for the reader that appears in page footers or at the end of a document. 4ootnotes and endnotes implement the ser5ice com.sun.star.te t.4ootnote that includes com.sun.star.te t.Te tContent. The Footnote ser5ice has the interfaces com.sun.star.te t.ATe t and com.sun.star.te t.A4ootnote that inherit from com.sun.star.te t.ATe tContent. The XFootnote introduces the following methods:
tring$getLa.el()$void$ etLa.el($6in7$ tring$aLa.el)

The Footnote ser5ice defines a property Re4erence1d that is used for import and e port8 and contains an internal se>uential number. The interface com.sun.star.te t.ATe t which is pro5ided by the com.sun.star.te t.4ootnote ser5ice accesses the te t ob:ect in the footnote area where the footnote te t is located. 0t is not allowed to insert te t tables into this te t ob:ect. *hile footnotes can be placed at the end of a page or the end of a document8 endnotes always appear at the end of a document. $ndnote numbering is separate from footnote numbering. 4ootnotes are accessed using the com.sun.star.te t.A4ootnotesSupplier interface of the te t document through the method getFoot:ote (). $ndnotes are accessed similarly by calling get(ndnote () at the te t document@s com.sun.star.te t.A$ndnotesSupplier interface. 3oth of these methods return a com.sun.star.container.A0nde /ccess. / label is set for a footnote or endnote to determine if automatic footnote numbering is used. 0f no label is set <G empty string=8 the footnote is labeled automatically. There are footnote and endnote settings that specify how the automatic labeling is formatted. These settings are obtained from the document model using the interfaces com.sun.star.te t.A4ootnotesSupplier and com.sun.star.te t.A$ndnotesSupplier. The corresponding methods are getFootnoteSetting () and get(ndnoteSetting (). The ob:ect recei5ed is a com.sun.star.beans.APropertySet and has the properties described in com.sun.star.te t.4ootnoteSettings: Properties of co&.sun.st%r.te$t.(ootnote,ettings com.sun.star.te t.4ootnoteSettings:/nc tring C Contains the name of the character horCharStyle6ame style that is used for the label in the document te t. com.sun.star.te t.4ootnoteSettings:Char tring C Contains the name of the character Style6ame style that is used for the label in front of the footnote/endnote te t. com.sun.star.te t.4ootnoteSettings:6um %ort C Contains the numbering type for the beringType numbering of the footnotes or endnotes. com.sun.star.te t.4ootnoteSettings:Page tring C Contains the page style that is used for

#$%pter 7 Text Documents

73

1ndex m%r2s

Style6ame com.sun.star.te t.4ootnoteSettings:Para Style6ame com.sun.star.te t.4ootnoteSettings:Prefi com.sun.star.te t.4ootnoteSettings:Start /t com.sun.star.te t.4ootnoteSettings:Suffi com.sun.star.te n6otice com.sun.star.te 6otice com.sun.star.te noteCounting com.sun.star.te ion$nd+fDoc t.4ootnoteSettings:3egi t.4ootnoteSettings:$nd t.4ootnoteSettings:4oot t.4ootnoteSettings:Posit

the page that contains the footnote or endnote te ts. tring C Contains the paragraph style that is used for the footnote or endnote te t. tring C Contains the prefi for the footnote or endnote symbol. %ort C Contains the first number of the automatic numbering of footnotes or endnotes. tring C Contains the suffi for the footnote/endnote symbol. 6optional7$ tring C Contains the string at the restart of the footnote te t after a brea2. 6optional7$ tring C Contains the string at the end of a footnote part in front of a brea2. 6optional7$.oolean C Contains the type of the counting for the footnote numbers 6optional7$.oolean C 0f true8 the footnote te t is shown at the end of the document.

The 4ootnotes ser5ice applies to footnotes and endnotes. The following sample wor2s with footnotes
"##$!%i $met%od$demon trate $%ow$to$create$and$in ert$4ootnote /$and$%ow$to$ acce $t%e$$$$$XFootnote Supplier$inter4ace$o4$t%e$document$$#"$protected$void$ Footnote()ample$()$*$$$$$try$$$$$*$$$$$$$$$""$Create$a$new$4ootnote$4rom$t%e$ document$4actory$and$get$itS $$$$$$$$$""$XFootnote$inter4ace$$$$$$$$$XFootnote$ )Footnote$+$(XFootnote)$UnoRuntime'5uery1nter4ace($XFootnote'cla /$$$$$$$$$$$$ m)DocFactory'create1n tance$($3com' un' tar'te)t'Footnote3$)$), ""$Set$t%e$la.el$to$S:um.er S$$$$$$$$$)Footnote' etLa.el$($3:um.er 3$), ""$Ret$t%e$4ootnote $X!e)tContent$inter4ace$ o$we$can'''$$$$$$$$$X!e)tContent$ )Content$+$($X!e)tContent$)$UnoRuntime'5uery1nter4ace$ ($$$$$$$$$$$$$$X!e)tContent'cla /$)Footnote$), ""$'''in ert$it$into$t%e$document$$$$$$$$$m)Doc!e)t'in ert!e)tContent$ ($m)DocCur or/$)Content/$4al e$), ""$Ret$t%e$XFootnote Supplier$inter4ace$o4$t%e$document$$$$$$$$$ XFootnote Supplier$)FootnoteSupplier$+$(XFootnote Supplier)$ UnoRuntime'5uery1nter4ace($$$$$$$$$$$$$XFootnote Supplier'cla /$m)Doc$), ""$Ret$an$X1nde)Acce $inter4ace$to$all$4ootnote $$$$$$$$$X1nde)Acce $ )Footnote $+$($X1nde)Acce $)$UnoRuntime'5uery1nter4ace$ ($$$$$$$$$$$$$X1nde)Acce 'cla /$)FootnoteSupplier'getFootnote ()$), ""$Ret$t%e$XFootnote$inter4ace$to$t%e$4ir t$4ootnote$in erted$(S:um.er S)$$$$$$ XFootnote$):um.er $+$($XFootnote$)$UnoRuntime'5uery1nter4ace$ ($$$$$$$$$$$$$$XFootnote'cla /$)Footnote 'get;y1nde)($9$)$), ""$Ret$t%e$XSimple!e)t$inter4ace$to$t%e$Footnote$$$$$$$$$XSimple!e)t$)Simple$+$ (XSimple!e)t$)$UnoRuntime'5uery1nter4ace$($$$$$$$$$$$$$XSimple!e)t'cla /$ ):um.er $), ""$Create$a$te)t$cur or$4or$t%e$4oot$note$te)t$$$$$$$$$X!e)tRange$)Range$+$ (X!e)tRange$)$UnoRuntime'5uery1nter4ace$($$$$$$$$$$$$$X!e)tRange'cla /$ )Simple'create!e)tCur or()$),

7&

OpenOffice.org 3.1 Developer's Guide April !!"

1ndex m%r2s

""$And$in ert$t%e$actual$te)t$o4$t%e$4ootnote'$$$$$$$$$)Simple'in ertString$($$ )Range/$3$!%e$num.er $were$generated$.y$u ing$&ava'util'Random3/$ 4al e$),$$$$$=$$$$$catc%$(()ception$e)$$$$$$*$$$$$$$$$e'printStac-!race$ ($Sy tem'out$),$$$$$=$=

,h%pe O*:ects in e$t

7%se (r%&es vs. Dr%.ing ,h%pes


Shape ob:ects are te t contents that act independently of the ordinary te t flow. The surrounding te t may wrap around them. Shape ob:ects can lie in front or behind te t8 and be anchored to paragraphs or characters in the te t. /nchoring allows the shape ob:ects to follow the paragraphs and characters while the user is writing. Currently8 there are two different 2inds of shape ob:ects in +pen+ffice.org8 base frames and drawing shapes.

7%se (r%&es
The first group are shape ob:ects that are com.sun.star.te t.3ase4rames. The three ser5ices com.sun.star.te t.Te t4rame8 com.sun.star.te t.Te t7raphic+b:ect and com.sun.star.te t.Te t$mbedded+b:ect are all based on the ser5ice com.sun.star.te t.3ase4rame. The !e)tFrame contain an independent te t area that can be positioned freely o5er ordinary te t. The !e)tRrap%ic0.&ect are bitmaps or 5ector oriented images in a format supported by +pen+ffice.org internally. The !e)t(m.edded0.&ect are areas containing a document type other than the document they are embedded in8 such as charts8 formulas8 internal +pen+ffice.org documents <Calc/Draw/0mpress=8 or +L$ ob:ects. The !e)tFrame 8 !e)tRrap%ic0.&ect and !e)t(m.edded0.&ect in a te t are supplied by their corresponding supplier interfaces at the document model:

com.sun.star.te t.ATe t4ramesSupplier com.sun.star.te t.ATe t7raphic+b:ectsSupplier com.sun.star.te t.ATe t$mbedded+b:ectsSupplier.

These interfaces all ha5e one single get method that supplies the respecti5e Shape ob:ects collection:
comFF unFF tarFFcontainerFFX:ameAcce comFF unFF tarFFcontainerFFX:ameAcce comFF unFF tarFFcontainerFFX:ameAcce $get!e)tFrame ()$ $get!e)t(m.edded0.&ect ()$ $get!e)tRrap%ic0.&ect ()

#$%pter 7 Text Documents

75

3%se 4r%mes vs. Dr%5ing -$%pes

The method get!e)tFrame () returns a com.sun.star.te t.Te t4rames collection8 get!e)t(m.edded0.&ect () returns a com.sun.star.te t.Te t$mbedded+b:ects collection and get!e)tRrap%ic0.&ect () yields a com.sun.star.te t.Te t7raphic+b:ects collection. /ll of these collections support com.sun.star.container.A0nde /ccess and com.sun.star.container.A6ame/ccess. The !e)tFrame collection may <optional= support the com.sun.star.container.AContainer interface to broadcast an e5ent when an (lement is added to the collection. ?owe5er8 the current implementation of the !e)tFrame collection does not support this. The ser5ice com.sun.star.te t.3ase4rame defines the common properties and interfaces of te t frames8 graphic ob:ects and embedded ob:ects. 0t includes the ser5ices com.sun.star.te t.3ase4rameProperties and com.sun.star.te t.Te tContent8 and defines the following interfaces. The position and si9e of a ;a eFrame is co5ered by com.sun.star.drawing.AShape. /ll ;a eFrame ob:ects share a ma:ority of the core implementation of drawing ob:ects. Therefore8 they ha5e a position and si9e on the DrawPage. The name of a ;a eFrame is set and read through com.sun.star.container.A6amed. The names of the frame ob:ects ha5e to be uni>ue for te t frames8 graphic ob:ects and embedded ob:ects8 respecti5ely. The com.sun.star.beans.APropertySet has to be present8 because many aspects of ;a eFrame $ are controlled through properties. The interface com.sun.star.document.A$5entsSupplier is not a part of the ;a eFrame ser5ice8 but is a5ailable in te t frames8 graphic ob:ects and embedded ob:ects. This interface pro5ides access to the e5ent macros that may be attached to the ob:ect in the 7B0. The properties of ;a eFrame are those of the ser5ice com.sun.star.te t.Te tContent8 as well there is a number of frame properties defined in the ser5ice com.sun.star.te t.3ase4rameProperties: Properties of co&.sun.st%r.te$t.7%se(r%&eProperties com.sun.star.te t.3ase4rameProperties: %ort C Contains the number of the page where /nchorPage6o the ob:ects are anchored. com.sun.star.te t.3ase4rameProperties: com.sun.star.te t.ATe t4rame. Contains the te t /nchor4rame frame the current frame is anchored to. com.sun.star.te t.3ase4rameProperties: long C Contains the color of the bac2ground of 3ac2Color the ob:ect. com.sun.star.te t.3ase4rameProperties: tring C Contains the B-L for the bac2ground 3ac27raphicB-L graphic. com.sun.star.te t.3ase4rameProperties: tring C Contains the name of the file filter for 3ac27raphic4ilter the bac2ground graphic. com.sun.star.te t.3ase4rameProperties: Determines the position of the bac2ground 3ac27raphicLocation graphic according to
7( OpenOffice.org 3.1 Developer's Guide April !!"

3%se 4r%mes vs. Dr%5ing -$%pes

com.sun.star.te t.3ase4rameProperties: Left3order com.sun.star.te t.3ase4rameProperties: -ight3order com.sun.star.te t.3ase4rameProperties: Top3order com.sun.star.te t.3ase4rameProperties: 3ottom3order com.sun.star.te t.3ase4rameProperties: 3orderDistance com.sun.star.te t.3ase4rameProperties: Left3orderDistance com.sun.star.te t.3ase4rameProperties: -ight3orderDistance com.sun.star.te t.3ase4rameProperties: Top3orderDistance com.sun.star.te t.3ase4rameProperties: 3ottom3orderDistance com.sun.star.te t.3ase4rameProperties: 3ac2Transparent com.sun.star.te t.3ase4rameProperties: ContentProtected com.sun.star.te t.3ase4rameProperties: Left(argin com.sun.star.te t.3ase4rameProperties: -ight(argin com.sun.star.te t.3ase4rameProperties: Top(argin com.sun.star.te t.3ase4rameProperties: 3ottom(argin com.sun.star.te t.3ase4rameProperties: ?eight com.sun.star.te t.3ase4rameProperties: *idth com.sun.star.te t.3ase4rameProperties: -elati5e?eight com.sun.star.te t.3ase4rameProperties: -elati5e*idth com.sun.star.te t.3ase4rameProperties: 0sSync*idthTo?eight com.sun.star.te t.3ase4rameProperties: 0sSync?eightTo*idth com.sun.star.te t.3ase4rameProperties:

com.sun.star.style.7raphicLocation . Struct$com.sun.star.table.3orderLine. Contains the left border of the ob:ect. Struct$com.sun.star.table.3orderLine. Contains the right border of the ob:ect. Struct$com.sun.star.table.3orderLine. Contains the top border of the ob:ect. Struct$com.sun.star.table.3orderLine. Contains the bottom border of the ob:ect. long C Contains the distance from the border to the ob:ect. long C Contains the distance from the left border to the ob:ect. long C Contains the distance from the right border to the ob:ect. long C Contains the distance from the top border to the ob:ect. long C Contains the distance from the bottom border to the ob:ect. .oolean C 0f true8 the property 3ac2Color is ignored. .oolean C Determines if the content is protected.
long C Contains the left margin of the ob:ect. long C Contains the right margin of the ob:ect. long C Contains the top margin of the ob:ect. long C Contains the bottom margin of the ob:ect. long C Contains the height of the ob:ect <!/!))

mm=.
long C Contains the width of the ob:ect <!/!))

mm=.
%ort C Contains the relati5e height of the ob:ect. %ort C Contains the relati5e width of the ob:ect. .oolean C Determines if the width follows the

height.
.oolean C Determines if the height follows the

width.
%ort C Determines the hori9ontal orientation of

#$%pter 7 Text Documents

77

3%se 4r%mes vs. Dr%5ing -$%pes

?ori+rient com.sun.star.te t.3ase4rameProperties: ?ori+rientPosition com.sun.star.te t.3ase4rameProperties: ?ori+rient-elation com.sun.star.te t.3ase4rameProperties: Fert+rient com.sun.star.te t.3ase4rameProperties: Fert+rientPosition com.sun.star.te t.3ase4rameProperties: Fert+rient-elation com.sun.star.te t.3ase4rameProperties: ?yperLin2B-L com.sun.star.te t.3ase4rameProperties: ?yperLin2Target com.sun.star.te t.3ase4rameProperties: ?yperLin26ame com.sun.star.te t.3ase4rameProperties: +pa>ue com.sun.star.te t.3ase4rameProperties: PageToggle com.sun.star.te t.3ase4rameProperties: PositionProtected com.sun.star.te t.3ase4rameProperties: Print com.sun.star.te t.3ase4rameProperties: Shadow4ormat com.sun.star.te t.3ase4rameProperties: Ser5er(ap com.sun.star.te t.3ase4rameProperties: Si9e com.sun.star.te t.3ase4rameProperties: Si9eProtected com.sun.star.te t.3ase4rameProperties: Surround com.sun.star.te t.3ase4rameProperties: Surround/nchor+nly

the ob:ect according to com.sun.star.te t.?ori+rientation. long C Contains the hori9ontal position of the ob:ect <!/!)) mm=. %ort C Determines the en5ironment of the ob:ect the orientation is related according to com.sun.star.te t.-el+rientation. %ort C Determines the 5ertical orientation of the ob:ect. long C Contains the 5ertical position of the ob:ect <!/!)) mm=. Falid only if
!e)t(m.edded0.&ectFFVert0rient$i $ Vert0rientationFF:0:(KodeL'$ %ort C Determines the en5ironment of the

ob:ect the orientation is related according to com.sun.star.te t.-el+rientation. tring C Contains the B-L of a hyperlin2 that is set at the ob:ect. tring C Contains the name of the target for a hyperlin2 that is set at the ob:ect. tring C Contains the name of the hyperlin2 that is set at the ob:ect. .oolean C Determines if the ob:ect is opa>ue or transparent for te t. .oolean C Determines if the ob:ect is mirrored on e5en pages. .oolean C Determines if the position is protected. .oolean C Determines if the ob:ect is included in printing. Struct$com.sun.star.table.Shadow4ormat. Contains the type of the shadow of the ob:ect. .oolean C Determines if the ob:ect gets an image map from a ser5er. Struct$com.sun.star.awt.Si9e. Contains the si9e of the ob:ect. .oolean C Determines if the si9e is protected. JdeprecatedK. Determines the type of the surrounding te t. .oolean C Determines if the te t of the paragraph where the ob:ect is anchored8 wraps around the ob:ect.

78

OpenOffice.org 3.1 Developer's Guide April !!"

Dr%5ing -$%pes

Dr%.ing ,h%pes
The second group of shape ob:ects are the 5aried drawing shapes that can be inserted into te t8 such as rectangles and ellipses. They are based on com.sun.star.te t.Shape. The ser5ice te)t'S%ape includes com.sun.star.drawing.Shape8 but adds a number of properties related to shapes in te t <cf. Drawing Shapes below=. 0n addition8 drawing shapes support the interface com.sun.star.te t.ATe tContent so that they can be inserted into an ATe t. There are no speciali9ed supplier interfaces for drawing shapes. /ll the drawing shapes on the DrawPage ob:ect are supplied by the document model@s com.sun.star.drawing.ADrawPageSupplier and its single method:
comFF unFF tarFFdrawingFFXDrawPage$getDrawPage()

ip 8 The DrawPage not only contains drawing shapes8 but the ;a eFrame shape ob:ects too8 if the document contains any.

e$t (r%&es
/ te t frame is a com.sun.star.te t.Te t4rame ser5ice consisting of com.sun.star.te t.3ase4rame and the interface com.sun.star.te t.ATe t4rame.The X!e)tFrame$ is based on com.sun.star.te t.ATe tContent and introduces one method to pro5ide the X!e)t of the frame:
comFF unFF tarFFte)tFFX!e)t$get!e)t()

The properties of com.sun.star.te t.Te t4rame that add to the ;a eFrame are the following: Properties of co&.sun.st%r.te$t. e$t(r%&e t.Te t4rame:4rame?eight long C Contains the metric height 5alue of the frame. t.Te t4rame:4rame*idth/ long C Contains the metric width 5alue of the frame. t.Te t4rame:4rame*idthP .yte C Specifies a width relati5e to the width of the surrounding te t. t.Te t4rame:4rame?eightP .yte C Specifies a width relati5e to the width of the surrounding te t. t.Te t4rame:4rame0s/uto .oolean C 0f D/utomatic?eightD is set8 the ob:ect grows if it is re>uired by the frame content. com.sun.star.te t.Te t4rame:Si9eType %ort C Determines the interpretation of the height and relati5e height properties. com.sun.star.te /bsolute com.sun.star.te bsolute com.sun.star.te ercent com.sun.star.te ercent com.sun.star.te matic?eight

#$%pter 7 Text Documents

7"

Dr%5ing -$%pes

/dditionally8 te t frames are com.sun.star.te t.Te t ser5ices and support all of its interfaces8 e cept for com.sun.star.te t.ATe t-ange(o5er. Te t frames can be connected to a chain8 that is8 the te t of the first te t frame flows into the ne t chain element if it does not fit. The properties C%ainPrev:ame and C%ain:e)t:ame are pro5ided to ta2e ad5antage of this feature. They contain the names of the predecessor and successor of a frame. /ll frames ha5e to be empty to chain frames8 e cept for the first member of the chain. Ch%ined e$t (r%&e Property com.sun.star.te t.ChainedTe t4rame:Cha tring C 6ame of the predecessor of the frame. inPre56ame com.sun.star.te t.ChainedTe t4rame:Cha tring C 6ame of the successor of the frame. in6e t6ame The effect at the /P0 is that the 5isible te t content of the chain members is only accessible at the first frame in the chain. The content of the following chain members is not shown when chained before their content is set. The /P0 reference does not 2now the properties abo5e. 0nstead8 it specifies a com.sun.star.te t.ChainedTe t4rame with an XC%aina.le interface8 but this is not yet supported by te t frames. The following e ample uses te t frames:
"##$!%i $met%od$ %ow $%ow$to$create$and$manipulate$te)t$4rame $$#"$protected$ void$!e)tFrame()ample$()$*$$$$$try$$$$$$*$$$$$$$$$""$U e$t%e$documentS $ 4actory$to$create$a$new$te)t$4rame$and$immediately$acce $$$$$$$$$$""$itS $ X!e)tFrame$inter4ace$$$$$$$$$X!e)tFrame$)Frame$+$(X!e)tFrame)$ UnoRuntime'5uery1nter4ace$($$$$$$$$$$$$$X!e)tFrame'cla /$ m)DocFactory'create1n tance$ ($$$$$$$$$$$$$$$$$3com' un' tar'te)t'!e)tFrame3$)$), ""$Acce $t%e$XS%ape$inter4ace$o4$t%e$!e)tFrame$$$$$$$$$XS%ape$)S%ape$+$ (XS%ape)$UnoRuntime'5uery1nter4ace(XS%ape'cla /$)Frame),$$$$$$$$$""$Acce $ t%e$XPropertySet$inter4ace$o4$t%e$!e)tFrame$$$$$$$$$XPropertySet$)FrameProp $+$ (XPropertySet)UnoRuntime'5uery1nter4ace($$$$$$$$$$$$$XPropertySet'cla /$ )Frame$), ""$Set$t%e$ iOe$o4$t%e$new$!e)t$Frame$u ing$t%e$XS%apeS $S etSiOeS$met%od$$$$$$ SiOe$aSiOe$+$new$SiOe(),$$$$$$$$$aSiOe'?eig%t$+$B99,$$$$$$$$$aSiOe'2idt%$+$ 8C999,$$$$$$$$$)S%ape' etSiOe(aSiOe),$$$$$$$$$""$Set$t%e$Anc%or!ype$to$ com' un' tar'te)t'!e)tContentAnc%or!ype'AS<C?ARAC!(R$$$$$$$$$ )FrameProp ' etPropertyValue($3Anc%or!ype3/$!e)tContentAnc%or!ype'AS<C?ARAC!(R$ ),$$$$$$$$$""$Ro$to$t%e$end$o4$t%e$te)t$document$$$$$$$$$ m)DocCur or'goto(nd($4al e$),$$$$$$$$$""$1n ert$a$new$paragrap%$$$$$$$$$ m)Doc!e)t'in ertControlC%aracter$($$$$$$$$$$$$$$m)DocCur or/$ ControlC%aracter'PARARRAP?<;R(AT/$4al e$),$$$$$$$$$""$!%en$in ert$t%e$new$ 4rame$$$$$$$$$m)Doc!e)t'in ert!e)tContent(m)DocCur or/$)Frame/$4al e), ""$Acce $t%e$X!e)t$inter4ace$o4$t%e$te)t$contained$wit%in$t%e$4rame$$$$$$$$$ X!e)t$)Frame!e)t$+$)Frame'get!e)t(),$$$$$$$$$""$Create$a$!e)tCur or$over$t%e$ 4rameS $content $$$$$$$$$X!e)tCur or$)FrameCur or$+$ )Frame!e)t'create!e)tCur or(),$$$$$$$$$""$1n ert$ ome$te)t$into$t%e$4rame$$$$$$ )Frame!e)t'in ertString($$$$$$$$$$$$$$)FrameCur or/$3!%e$4ir t$line$in$t%e$

8!

OpenOffice.org 3.1 Developer's Guide April !!"

Dr%5ing -$%pes

newly$created$te)t$4rame'3/$4al e$),$$$$$$$$$)Frame!e)t'in ertString($$$$$$$$$$ )FrameCur or/$3Mn!%e$ econd$line$in$t%e$new$te)t$4rame'3/$4al e$),$$$$$$$$$""$ 1n ert$a$paragrap%$.rea-$into$t%e$document$(not$t%e$4rame)$$$$$$$$$ m)Doc!e)t'in ertControlC%aracter$($$$$$$$$$$$$$$m)DocCur or/$ ControlC%aracter'PARARRAP?<;R(AT/$4al e$),$$$$$=$$$$$$catc%$(()ception$e)$$$$$$ *$$$$$$$$$e'printStac-!race$($Sy tem'out$),$$$$$=$=

!&*edded O*:ects
/ !e)t(m.edded0.&ect is a com.sun.star.te t.3ase4rame pro5iding the interface com.sun.star.document.A$mbedded+b:ectSupplier. The only method of this interface8 com::sun::star::lang::AComponent get$mbedded+b:ect <= pro5ides access to the model of the embedded document. That way8 an embedded +pen+ffice.org spreadsheet8 drawing8 chart or a formula document can be used in a te t o5er its document model. /n embedded ob:ect is inserted by using the document@s factory to create an instance of the the ser5ice com.sun.star.te t.Te t$mbedded+b:ect. The type of ob:ect is determined by setting the string property CLS0D to an appropriate 5alue before inserting the ob:ect as te t content in the document.
"""###########################################################################$ ""$commentF$Step$8F$get$t%e$De -top$o.&ect$4rom$t%e$o44ice$""$Step$PF$open$an$ empty$te)t$document$""$Step$AF$in ert$a$ ample$te)t$ta.le$""$Step$BF$in ert$a$ C%art$o.&ect$""$Step$CF$in ert$data$4rom$te)t$ta.le$into$C%art$o.&ect$ ""########################################################################### import$com' un' tar'uno'UnoRuntime, pu.lic$cla $0le0.&ect$* pu.lic$ tatic$void$main(String$arg 67)$*$$$$$$$$$""$Uou$need$t%e$de -top$to$ create$a$document$$$$$$$$$""$!%e$getDe -top$met%od$doe $t%e$U:0$.oot trapping/$ get $t%e$$$$$$$$$""$remote$ ervie$manager$and$t%e$de -top$o.&ect'$$$$$$$$$ com' un' tar'4rame'XDe -top$)De -top$+$null,$$$$$$$$$)De -top$+$getDe -top(), com' un' tar'te)t'X!e)tDocument$)!e)tDocument$+$$$$$$$$$$$$$ create!e)tdocument($)De -top$), com' un' tar'te)t'X!e)t!a.le$)!e)t!a.le$+$$$$$$$$$$$$$$ create()ample!a.le($)!e)tDocument$), try$*$$$$$$$$$$$$$""$create$!e)t(m.edded0.&ect$$$$$$$$$$$$$ com' un' tar'lang'XMultiServiceFactory$)DocMSF$+$ (com' un' tar'lang'XMultiServiceFactory)$$$$$$$$$$$$$ UnoRuntime'5uery1nter4ace(com' un' tar'lang'XMultiServiceFactory'cla /$ )!e)tDocument),$$$$$$$$$$$$$com' un' tar'te)t'X!e)tContent$)0.&$+$ (com' un' tar'te)t'X!e)tContent)$$$$$$$$$$$$$ UnoRuntime'5uery1nter4ace(com' un' tar'te)t'X!e)tContent'cla /$$$$$$$$$$$$$$$$ )DocMSF'create1n tance($3com' un' tar'te)t'!e)t(m.edded0.&ect3$)), ""$ et$cla $id$4or$c%art$o.&ect$to$determine$t%e$type$$$$$$$$$$$$$$""$o4$ o.&ect$to$.e$in erted$$$$$$$$$$$$$com' un' tar'.ean 'XPropertySet$)PS$+$ (com' un' tar'.ean 'XPropertySet)$$$$$$$$$$$$$ UnoRuntime'5uery1nter4ace(com' un' tar'.ean 'XPropertySet'cla /$)0.&),$$$$$$$$ )PS' etPropertyValue($3CLS1D3/$38PdcaePD>PQ84>B8D4>aPAB>cA9QD8PEAQPe3$),

#$%pter 7 Text Documents

81

Dr%5ing -$%pes

""$in ert$o.&ect$in$document$$$$$$$$$$$$$com' un' tar'te)t'X!e)tCur or$)Cur or$ +$)!e)tDocument'get!e)t()'create!e)tCur or(),$$$$$$$$$$$$$ com' un' tar'te)t'X!e)tRange$)Range$+$(com' un' tar'te)t'X!e)tRange)$$$$$$$$$$$ UnoRuntime'5uery1nter4ace(com' un' tar'te)t'X!e)tRange'cla /$)Cur or),$$$$$$$$ )!e)tDocument'get!e)t()'in ert!e)tContent($)Range/$)0.&/$4al e$), ""$acce $o.&ect $model$$$$$$$$$$$$$ com' un' tar'document'X(m.edded0.&ectSupplier$)(0S$+$ (com' un' tar'document'X(m.edded0.&ectSupplier)$$$$$$$$$$$$$ UnoRuntime'5uery1nter4ace(com' un' tar'document'X(m.edded0.&ectSupplier'cla /$ )0.&),$$$$$$$$$$$$$com' un' tar'lang'XComponent$)Model$+$ )(0S'get(m.edded0.&ect(), ""$get$ta.le$data$$$$$$$$$$$$$com' un' tar'c%art'XC%artDataArray$)DocCDA$+$ (com' un' tar'c%art'XC%artDataArray)$$$$$$$$$$$$$ UnoRuntime'5uery1nter4ace(com' un' tar'c%art'XC%artDataArray'cla /$ )!e)t!a.le),$$$$$$$$$$$$$dou.le6767$aData$+$)DocCDA'getData(), ""$in ert$ta.le$data$in$C%art$o.&ect$$$$$$$$$$$$$ com' un' tar'c%art'XC%artDocument$)C%artDoc$+$ (com' un' tar'c%art'XC%artDocument)$$$$$$$$$$$$$ UnoRuntime'5uery1nter4ace(com' un' tar'c%art'XC%artDocument'cla /$)Model),$$$$ com' un' tar'c%art'XC%artDataArray$)C%artDataArray$+$ (com' un' tar'c%art'XC%artDataArray)$$$$$$$$$$$$$ UnoRuntime'5uery1nter4ace(com' un' tar'c%art'XC%artDataArray'cla /$ )C%artDoc'getData()),$$$$$$$$$$$$$)C%artDataArray' etData($aData$), ""$to$remove$t%e$em.edded$o.&ect$&u t$uncomment$t%e$ne)t$line$$$$$$$$$$$$$ "")!e)tDocument'get!e)t()'remove!e)tContent($)0.&$),$$$$$$$$$=$$$$$$$$$ catc%($()ception$e)$*$$$$$$$$$$$$$e'printStac-!race(Sy tem'err),$$$$$$$$$= Sy tem'out'println(3Done3), Sy tem'e)it(9),$$$$$= protected$ tatic$com' un' tar'te)t'X!e)t!a.le$ create()ample!a.le($$$$$$$$$com' un' tar'te)t'X!e)tDocument$)!e)tDocument$)$$$$ *$$$$$$$$$com' un' tar'lang'XMultiServiceFactory$)DocMSF$+$$$$$$$$$$$$$ (com' un' tar'lang'XMultiServiceFactory)$UnoRuntime'5uery1nter4ace($$$$$$$$$$$$ com' un' tar'lang'XMultiServiceFactory'cla /$)!e)tDocument), com' un' tar'te)t'X!e)t!a.le$)!!$+$null, try$*$$$$$$$$$$$$$0.&ect$o1nt$+$ )DocMSF'create1n tance(3com' un' tar'te)t'!e)t!a.le3),$$$$$$$$$$$$$)!!$+$ (com' un' tar'te)t'X!e)t!a.le)$$$$$$$$$$$$$ UnoRuntime'5uery1nter4ace(com' un' tar'te)t'X!e)t!a.le'cla /o1nt), ""initialiOe$t%e$te)t$ta.le$wit%$B$column $an$C$row $$$$$$$$$$$$$ )!!'initialiOe(B/C), =$catc%$(()ception$e)$*$$$$$$$$$$$$$Sy tem'err'println(3CouldnSt$create$ in tance$3G$e),$$$$$$$$$$$$$e'printStac-!race(Sy tem'err),$$$$$$$$$= com' un' tar'te)t'X!e)t$)!e)t$+$)!e)tDocument'get!e)t(), ""create$a$cur or$o.&ect$$$$$$$$$com' un' tar'te)t'X!e)tCur or$)!Cur or$+$ )!e)t'create!e)tCur or(), ""in ert$t%e$ta.le$$$$$$$$$try$*$$$$$$$$$$$$$)!e)t'in ert!e)tContent()!Cur or/$ )!!/$4al e), =$catc%$(()ception$e)$*$$$$$$$$$$$$$Sy tem'err'println(3CouldnSt$in ert$t%e$ ta.le$3$G$e),$$$$$$$$$$$$$e'printStac-!race(Sy tem'err),$$$$$$$$$= ""$in erting$ ample$data$$$$$$$$$()!!'getCell;y:ame(3AP3))' etValue(C'9),$$$$$$ ()!!'getCell;y:ame(3AA3))' etValue(C'C),$$$$$$$$$ ()!!'getCell;y:ame(3AB3))' etValue(C'E),$$$$$$$$$ ()!!'getCell;y:ame(3;P3))' etValue(P'A),$$$$$$$$$

OpenOffice.org 3.1 Developer's Guide April !!"

Dr%5ing -$%pes

()!!'getCell;y:ame(3;A3))' etValue(P'P),$$$$$$$$$ ()!!'getCell;y:ame(3;B3))' etValue(P'B),$$$$$$$$$ ()!!'getCell;y:ame(3CP3))' etValue(D),$$$$$$$$$ ()!!'getCell;y:ame(3CA3))' etValue(D),$$$$$$$$$ ()!!'getCell;y:ame(3CB3))' etValue(D),$$$$$$$$$ ()!!'getCell;y:ame(3DP3))' etValue(A),$$$$$$$$$ ()!!'getCell;y:ame(3DA3))' etValue(A'C),$$$$$$$$$ ()!!'getCell;y:ame(3DB3))' etValue(B),$$$$$$$$$ ()!!'getCell;y:ame(3(P3))' etValue(Q),$$$$$$$$$ ()!!'getCell;y:ame(3(A3))' etValue(C),$$$$$$$$$ ()!!'getCell;y:ame(3(B3))' etValue(A), return$)!!,$$$$$= pu.lic$ tatic$com' un' tar'4rame'XDe -top$getDe -top()$ *$$$$$$$$$com' un' tar'4rame'XDe -top$)De -top$+$null,$$$$$$$$$ com' un' tar'lang'XMultiComponentFactory$)MCF$+$null, try$*$$$$$$$$$$$$$com' un' tar'uno'XComponentConte)t$)Conte)t$+$null, ""$get$t%e$remote$o44ice$component$conte)t$$$$$$$$$$$$$)Conte)t$+$ com' un' tar'comp'%elper';oot trap'.oot trap(), ""$get$t%e$remote$o44ice$ ervice$manager$$$$$$$$$$$$$)MCF$+$ )Conte)t'getServiceManager(),$$$$$$$$$$$$$i4($)MCF$J+$null$)$*$$$$$$$$$$$$$$$$$ Sy tem'out'println(3Connected$to$a$running$o44ice$'''3), 0.&ect$oDe -top$+$ )MCF'create1n tance2it%Conte)t($$$$$$$$$$$$$$$$$$$$$3com' un' tar'4rame'De -to p3/$)Conte)t),$$$$$$$$$$$$$$$$$)De -top$+$(com' un' tar'4rame'XDe -top)$ UnoRuntime'5uery1nter4ace($$$$$$$$$$$$$$$$$$$$$com' un' tar'4rame'XDe -top'cla /$oDe -top),$$$$$$$$$$$$$=$$$$$$$$$$$$$el e$$$$$$$$$$$$$$$$$ Sy tem'out'println($3CanSt$create$a$de -top'$:o$connection/$no$remote$o44ice$ ervicemanager$availa.leJ3$),$$$$$$$$$=$$$$$$$$$catc%($()ception$e)$*$$$$$$$$$$ e'printStac-!race(Sy tem'err),$$$$$$$$$$$$$Sy tem'e)it(8),$$$$$$$$$= return$)De -top,$$$$$= pu.lic$ tatic$com' un' tar'te)t'X!e)tDocument$ create!e)tdocument($$$$$$$$$com' un' tar'4rame'XDe -top$)De -top$)$$$$$*$$$$$$$ com' un' tar'te)t'X!e)tDocument$a!e)tDocument$+$null, try$*$$$$$$$$$$$$$com' un' tar'lang'XComponent$)Component$+$ Create:ewDocument()De -top/$3 writer3),$$$$$$$$$$$$$a!e)tDocument$+$ (com' un' tar'te)t'X!e)tDocument)$$$$$$$$$$$$$$$$$UnoRuntime'5uery1nter4ace($$$ com' un' tar'te)t'X!e)tDocument'cla /$)Component),$$$$$$$$$=$$$$$$$$$ catc%($()ception$e)$*$$$$$$$$$$$$$e'printStac-!race(Sy tem'err),$$$$$$$$$= return$a!e)tDocument,$$$$$= protected$ tatic$com' un' tar'lang'XComponent$ Create:ewDocument($$$$$$$$$com' un' tar'4rame'XDe -top$)De -top/$$$$$$$$$ String$ Document!ype$)$$$$$*$$$$$$$$$String$ URL$+$3privateF4actory"3$G$ Document!ype, com' un' tar'lang'XComponent$)Component$+$null,$$$$$$$$$ com' un' tar'4rame'XComponentLoader$)ComponentLoader$+$null,$$$$$$$$$ com' un' tar'.ean 'PropertyValue$)Value 67$+$$$$$$$$$$$$$new$ com' un' tar'.ean 'PropertyValue687,$$$$$$$$$com' un' tar'.ean 'PropertyValue$ )(mptyArg 67$+$$$$$$$$$$$$$new$com' un' tar'.ean 'PropertyValue697, try$*$$$$$$$$$$$$$)ComponentLoader$+$(com' un' tar'4rame'XComponentLoader)$$$$$ UnoRuntime'5uery1nter4ace($$$$$$$$$$$$$$$$$$$$$com' un' tar'4rame'XComponentLo ader'cla /$)De -top), )Component$+$)ComponentLoader'loadComponentFromURL($$$$$$$$$$$$$$$$$ URL/$ 3<.lan-3/$9/$)(mptyArg ),$$$$$$$$$=$$$$$$$$$catc%($()ception$e)$ *$$$$$$$$$$$$$e'printStac-!race(Sy tem'err),$$$$$$$$$=

#$%pter 7 Text Documents

83

Dr%5ing -$%pes

return$)Component$,$$$$$=$=

Gr%phic O*:ects
/ !e)tRrap%ic0.&ect is a ;a eFrame and does not pro5ide any additional interfaces8 compared with com.sun.star.te t.3ase4rame. ?owe5er8 it introduces a number of properties that allow manipulating of a graphic ob:ect. They are described in the ser5ice com.sun.star.te t.Te t7raphic+b:ect: Properties of co&.sun.st%r.te$t. e$tGr%phicO*:ect com.sun.star.te t.Te t7raphic+b:ect:0ma com.sun.star.container.A0nde Container. ge(ap -eturns the clientCside image map if one is assigned to the ob:ect. com.sun.star.te t.Te t7raphic+b:ect:Co .oolean C Determines if the content is protected ntentProtected against changes from the user interface. com.sun.star.te t.Te t7raphic+b:ect:Sur .oolean C Determines if the te t wraps around roundContour the contour of the ob:ect. com.sun.star.te t.Te t7raphic+b:ect:Co .oolean C The te t flows only around the ntour+utside contour of the ob:ect. com.sun.star.te t.Te t7raphic+b:ect:Co 6optional7$ truct com.sun.star.drawing.PointSe>uenceSe>uence ntourPolyPolygon . Contains the contour of the ob:ect as PolyPolygon. truct com.sun.star.te t.Te t7raphic+b:ect:7ra com.sun.star.te t.7raphicCrop phicCrop . Contains the cropping of the ob:ect. com.sun.star.te t.Te t7raphic+b:ect:?or .oolean C Determines if the ob:ect is i(irrored+n$5enPages hori9ontally mirrored on e5en pages. com.sun.star.te t.Te t7raphic+b:ect:?or .oolean C Determines if the ob:ect is i(irrored+n+ddPages hori9ontally mirrored on odd pages. com.sun.star.te t.Te t7raphic+b:ect:Fer .oolean C Determines if the ob:ect is mirrored t(irrored 5ertically. com.sun.star.te t.Te t7raphic+b:ect:7ra tring C Contains the B-L of the bac2ground phicB-L graphic of the ob:ect. com.sun.star.te t.Te t7raphic+b:ect:7ra tring C Contains the name of the filter of the phic4ilter bac2ground graphic of the ob:ect. com.sun.star.te t.Te t7raphic+b:ect:/ct ualSi9e com.sun.star.awt.Si9e . Contains the original si9e of the bitmap in the graphic ob:ect. com.sun.star.te t.Te t7raphic+b:ect:/d: %ort C Changes the display of the luminance. 0t ustLuminance contains percentage 5alues between C!)) and L!)).
8& OpenOffice.org 3.1 Developer's Guide April !!"

Dr%5ing -$%pes

com.sun.star.te t.Te t7raphic+b:ect:/d: ustContrast com.sun.star.te t.Te t7raphic+b:ect:/d: ust-ed com.sun.star.te t.Te t7raphic+b:ect:/d: ust7reen com.sun.star.te t.Te t7raphic+b:ect:/d: ust3lue com.sun.star.te t.Te t7raphic+b:ect:7a mma com.sun.star.te t.Te t7raphic+b:ect:7ra phic0s0n5erted com.sun.star.te t.Te t7raphic+b:ect:Tra nsparency com.sun.star.te t.Te t7raphic+b:ect:7ra phicColor(ode

%ort C Changes the display of contrast. 0t contains percentage 5alues between C!)) and L!)). %ort C Changes the display of the red color channel. 0t contains percentage 5alues between C!)) and L!)). %ort C Changes the display of the green color channel. 0t contains percentage 5alues between C!)) and L!)). %ort C Changes the display of the blue color channel. 0t contains percentage 5alues between C!)) and L!)). dou.le C Determines the gamma 5alue of the graphic. .oolean C Determines if the graphic is displayed in in5erted colors. 0t contains percentage 5alues between C!)) and L!)). %ort C (easure of transparency. 0t contains percentage 5alues between C!)) and L!)). long C Contains the ColorMode according to com.sun.star.drawing.Color(ode .

0%rning !e)tRrap%ic0.&ect files can currently only be lin2ed when inserted through /P0 which means only their B-L is stored with the document. $mbedding of graphics is not supported. This applies to bac2ground graphics which can be set8 for e ample8 to paragraphs8 tables or te t sections.

Dr%.ing ,h%pes
The writer uses the same drawing engine as +pen+ffice.org impress and +pen+ffice.org draw. The limitations are that in writer only one draw page can e ist and .D ob:ects are not supported. /ll drawing shapes support these properties: Properties of co&.sun.st%r.dr%.ing.,h%pe com.sun.star.drawing.Shape:M+rder 6optional7$long C 0s used to >uery or change the @0rder of this Shape . com.sun.star.drawing.Shape:Layer0D 6optional7$ %ort C This is the 0D of the layer to which this shape is attached. com.sun.star.drawing.Shape:Layer6ame 6optional7$ tring C This is the name of the layer to which this Shape is attached. com.sun.star.drawing.Shape:Printable 6optional7$.oolean C 0f this is false8 the shape
#$%pter 7 Text Documents 85

Dr%5ing -$%pes

com.sun.star.drawing.Shape:(o5eProte ct com.sun.star.drawing.Shape:6ame com.sun.star.drawing.Shape:Si9eProtect com.sun.star.drawing.Shape:Style com.sun.star.drawing.Shape:Transforma tion

is not 5isible on printer outputs. 6optional7 boolean C *hen set to true8 this shape cannot be mo5ed interacti5ely in the user interface. 6optional7$ tring C This is the name of this shape. 6optional7$.oolean C *hen set to true8 this shape may not be si9ed interacti5ely in the user interface.
6optional7

com.sun.star.style.AStyle . Determines the style for this shape.


6optional7

com.sun.star.drawing.?omogen(atri This property lets you get and set the transformation matri for this shape. The transformation is a . . blended matri and can contain translation8 rotation8 shearing and scaling.
6optional7

com.sun.star.drawing.Shape:ShapeBser Defined/ttributes

com.sun.star.container.A6ameContainer . This property stores ml attributes. They are sa5ed to and restored from automatic styles inside ml files.

0n addition to the properties of the shapes nati5ely supported by the drawing engine8 the writer shape adds some properties8 so that they are usable for te t documents. These are defined in the ser5ice com.sun.star.te t.Shape: Properties of co&.sun.st%r.te$t.,h%pe com.sun.star.te t.Shape:/nchorPage6o %ort C Contains the number of the page where the ob:ects are anchored. com.sun.star.te t.Shape:/nchor4rame com.sun.star.te t.ATe t4rame. Contains the te t frame the current frame is anchored to. com.sun.star.te t.Shape:Surround/ncho .oolean C Determines if the te t of the r+nly paragraph in which the ob:ect is anchored8 wraps around the ob:ect. 6optional7 com.sun.star.te t.Shape:/nchorType com.sun.star.te t.Te tContent/nchorType . Specifies how the te t content is attached to its surrounding te t. com.sun.star.te t.Shape:?ori+rient %ort C Determines the hori9ontal orientation of the ob:ect. com.sun.star.te t.Shape:?ori+rientPosit long C Contains the hori9ontal position of the ion ob:ect <!/!)) mm=. com.sun.star.te t.Shape:?ori+rient-elat %ort C Determines the en5ironment of the ion ob:ect to which the orientation is related.

8(

OpenOffice.org 3.1 Developer's Guide April !!"

Dr%5ing -$%pes

com.sun.star.te t.Shape:Fert+rient com.sun.star.te t.Shape:Fert+rientPositi on com.sun.star.te on com.sun.star.te com.sun.star.te com.sun.star.te com.sun.star.te com.sun.star.te t.Shape:Fert+rient-elati t.Shape:Left(argin t.Shape:-ight(argin t.Shape:Top(argin t.Shape:3ottom(argin t.Shape:Surround

%ort C Determines the 5ertical orientation of the ob:ect. long C Contains the 5ertical position of the ob:ect <!/!)) mm=. Falid only if !e)t(m.edded0.&ectFFVert0rient$i $ Vert0rientationFF:0:(. %ort C Determines the en5ironment of the

com.sun.star.te t.Shape:Surround/ncho r+nly com.sun.star.te t.Shape:SurroundConto ur com.sun.star.te t.Shape:Contour+utside com.sun.star.te t.Shape:+pa>ue com.sun.star.te t.Shape:Te t-ange

ob:ect to which the orientation is related. long C Contains the left margin of the ob:ect. long C Contains the right margin of the ob:ect. long C Contains the top margin of the ob:ect. long C Contains the bottom margin of the ob:ect. 6deprecated7. Determines the type of the surrounding te t. .oolean C Determines if the te t of the paragraph in which the ob:ect is anchored8 wraps around the ob:ect. .oolean C Determines if the te t wraps around the contour of the ob:ect. .oolean C The te t flows only around the contour of the ob:ect. .oolean C Determines if the ob:ect is opa>ue or transparent for te t. com.sun.star.te t.ATe t-ange. Contains a te t range where the shape should be anchored to.

The chapter Drawing Documents and Presentation Documents describes how to use shapes and the interface of the draw page. / sample that creates and inserts drawing shapes:
"##$!%i $met%od$demon trate $%ow$to$create$and$manipulate$ %ape /$and$%ow$to$ acce $t%e$draw$page$$$$$o4$t%e$document$to$in ert$ %ape $$#"$protected$void$ DrawPage()ample$()$*$$$$$try$*$$$$$$$$$""$Ro$to$t%e$end$o4$t%e$document$$$$$$$$ m)DocCur or'goto(nd(4al e),$$$$$$$$$""$1n ert$two$new$paragrap% $$$$$$$$$ m)Doc!e)t'in ertControlC%aracter(m)DocCur or/$$$$$$$$$ ControlC%aracter'PARARRAP?<;R(AT/$4al e),$$$$$$$$$ m)Doc!e)t'in ertControlC%aracter(m)DocCur or/$$$$$$$$$$$$$ ControlC%aracter'PARARRAP?<;R(AT/$4al e), ""$Ret$t%e$XParagrap%Cur or$inter4ace$o4$our$document$cur or$$$$$$$$$ XParagrap%Cur or$)ParaCur or$+$(XParagrap%Cur or)$$$$$$$$$$$$$$ UnoRuntime'5uery1nter4ace(XParagrap%Cur or'cla /$m)DocCur or), ""$Po ition$t%e$cur or$in$t%e$Pnd$paragrap%$$$$$$$$$ )ParaCur or'gotoPreviou Paragrap%(4al e), ""$Create$a$RectangleS%ape$u ing$t%e$document$4actory$$$$$$$$$XS%ape$)Rect$+$ (XS%ape)$UnoRuntime'5uery1nter4ace($$$$$$$$$$$$$$XS%ape'cla /$ m)DocFactory'create1n tance($$$$$$$$$$$$$$$$$3com' un' tar'drawing'RectangleS% ape3)), ""$Create$an$(llip eS%ape$u ing$t%e$document$4actory$$$$$$$$$XS%ape$)(llip e$+$

#$%pter 7 Text Documents

87

Dr%5ing -$%pes

(XS%ape)$UnoRuntime'5uery1nter4ace($$$$$$$$$$$$$$XS%ape'cla /$ m)DocFactory'create1n tance($$$$$$$$$$$$$$$$$$3com' un' tar'drawing'(llip eS%a pe3)), ""$Set$t%e$ iOe$o4$.ot%$t%e$ellip e$and$t%e$rectangle$$$$$$$$$SiOe$aSiOe$+$new$ SiOe(),$$$$$$$$$aSiOe'?eig%t$+$B999,$$$$$$$$$aSiOe'2idt%$+$89999,$$$$$$$$$ )Rect' etSiOe(aSiOe),$$$$$$$$$aSiOe'?eig%t$+$A999,$$$$$$$$$aSiOe'2idt%$+$D999,$ )(llip e' etSiOe(aSiOe), ""$Set$t%e$po ition$o4$t%e$Rectangle$to$t%e$rig%t$o4$t%e$ellip e$$$$$$$$$Point$ aPoint$+$new$Point(),$$$$$$$$$aPoint'X$+$D899,$$$$$$$$$aPoint'U$+$9,$$$$$$$$$ )Rect' etPo ition$(aPoint), ""$Ret$t%e$XPropertySet$inter4ace $o4$.ot%$ %ape $$$$$$$$$XPropertySet$ )RectProp $+$(XPropertySet)$ UnoRuntime'5uery1nter4ace($$$$$$$$$$$$$$XPropertySet'cla /$)Rect),$$$$$$$$$ XPropertySet$)(llip eProp $+$(XPropertySet)$UnoRuntime'5uery1nter4ace($$$$$$$$$ XPropertySet'cla /$)(llip e), ""$And$ et$t%e$Anc%or!ype $o4$.ot%$ %ape $to$SA!<PARARRAP?S$$$$$$$$$ )RectProp ' etPropertyValue(3Anc%or!ype3/$!e)tContentAnc%or!ype'A!<PARARRAP?),$ )(llip eProp ' etPropertyValue(3Anc%or!ype3/$ !e)tContentAnc%or!ype'A!<PARARRAP?), ""$Acce $t%e$XDrawPageSupplier$inter4ace$o4$t%e$document$$$$$$$$$ XDrawPageSupplier$)DrawPageSupplier$+$(XDrawPageSupplier)$ UnoRuntime'5uery1nter4ace($$$$$$$$$$$$$XDrawPageSupplier'cla /$m)Doc), ""$Ret$t%e$XS%ape $inter4ace$o4$t%e$draw$page$$$$$$$$$XS%ape $)S%ape $+$ (XS%ape )$UnoRuntime'5uery1nter4ace($$$$$$$$$$$$$$XS%ape 'cla /$ )DrawPageSupplier'getDrawPage()), ""$Add$.ot%$ %ape $$$$$$$$$)S%ape 'add$()(llip e),$$$$$$$$$)S%ape 'add$ ()Rect), "#$$$$$$$$$!%i $doe nSt$wor-/$1$am$a ured$t%at$FM($and$AMA$are$4i)ing$it' XS%ape $)Rrouper$+$(XS%ape )$ UnoRuntime'5uery1nter4ace($$$$$$$$$$$$$$XS%ape 'cla /$ m)DocFactory'create1n tance($$$$$$$$$$$$$$$$$$3com' un' tar'drawing'RroupS%ape 3)), XS%ape$)RrouperS%ape$+$(XS%ape)$UnoRuntime'5uery1nter4ace(XS%ape'cla /$ )Rrouper),$$$$$$$$$)S%ape 'add$()RrouperS%ape), )Rrouper'add$()Rect),$$$$$$$$$)Rrouper'add$()(llip e), XS%apeRrouper$)S%apeRrouper$+$(XS%apeRrouper)$UnoRuntime'5uery1nter4ace($$$$$$$ XS%apeRrouper'cla /$)S%ape ),$$$$$$$$$)S%apeRrouper'group$()Rrouper),$$$$$$$$$ #" =$catc%$(()ception$e)$*$$$$$$$$$e'printStac-!race(Sy tem'out),$$$$$=$=

"edline
-edlines are te t portions created in the user interface by switching on Edit - Changes Record. -edlines in a document are accessed through the com.sun.star.document.A-edlinesSupplier interface at the document model. / collection of redlines as com.sun.star.beans.APropertySet ob:ects are recei5ed that can be accessed as com.sun.star.container.A0nde /ccess or as com.sun.star.container.A$numeration/ccess.

88

OpenOffice.org 3.1 Developer's Guide April !!"

Dr%5ing -$%pes

Their properties are described in com.sun.star.te t.-edlinePortion. 0f a change is recorded8 but not 5isible because the option Edit - Changes - Sho has been switched off8 redline te t is contained in the property Redline!e)t8 which is a com.sun.star.te t.ATe t. Calling XPropertySet'getPropertySet1n4o() on a redline property set crashes the office.

"u*y
-uby te t is a character layout attribute used in /sian languages. -uby te t appears abo5e or below te t in left to right writing8 and left to right of te t in top to bottom writing. 4or e amples8 cf. http://www.w..org/T-/!111/*DCrubyC!111).22/. -uby te t is created using the appropriate character properties from the ser5ice com.sun.star.style.CharacterProperties where5er this ser5ice is supported. ?owe5er8 the /sian languages support must be switched on in Tools - !ptions - "ang#ageSettings - "ang#ages. There is no con5enient supplier interface for ruby te t at the model at this time. ?owe5er8 the controller has an interface com.sun.star.te t.A-ubySelection that pro5ides access to rubies contained in the current selection. To find ruby te t in the model8 enumerate all te t portions in all paragraphs and chec2 if the property !e)tPortion!ype contains the string DRu.yD to find ruby te t. *hen there is ruby te t8 access the Ru.y!e)t property of the te t portion that contains ruby te t as a string. Ch%r%cterProperties for "u*y e$t com.sun.star.style.CharacterProperties:-ub yTe t com.sun.star.style.CharacterProperties:-ub y/d:ust com.sun.star.style.CharacterProperties:-ub yCharStyle6ame com.sun.star.style.CharacterProperties:-ub y0s/bo5e Description Contains the te t that is set as ruby. Determines the ad:ustment of the ruby te t as Ru.yAd&u t. Contains the name of the character style that is applied to Ru.y!e)t. Determines if the ruby te t is printed abo5e/left or below/right of the te t

#$%pter 7 Text Documents

8"

Dr%5ing -$%pes

Over%ll Docu&ent (e%tures

,tyles
Styles distinguish sections in a document that are commonly formatted and separates this information from the actual formatting. This way it is possible to unify the appearance of a document8 and ad:ust the formatting of a document by altering a style8 instead of local format settings after the document has been completed. Styles are pac2ages of attributes that can be applied to te t or te t contents in a single step. The following style families are a5ailable in +pen+ffice.org. ,tyle (%&ilies CharacterStyles ParagraphStyles Description Character styles are used to format single characters or entire words and phrases. Character styles can be nested. Paragraph styles are used to format entire paragraphs. /part from the normal format settings for paragraphs8 the paragraph style also defines the font to be used8 and the paragraph style for the following paragraph. 4rame styles are used to format graphic and te t frames. These Styles are used to >uic2ly format graphics and frames automatically. Page styles are used to structure the page. 0f a D6e t StyleD is specified8 the +pen+ffice.org automatically applies the specified page style when an automatic page brea2 occurs. 6umbering styles are used to format paragraphs in numbered or bulleted te t.

4rameStyles PageStyles 6umberingStyles

The te t document model implements the interface com.sun.star.style.AStyle4amiliesSupplier to access these styles. 0ts method getStyleFamilie () returns a collection of com.sun.star.style.Style4amilies with a com.sun.star.container.A6ame/ccess interface. The com.sun.star.container.A6ame/ccess interface retrie5es the style families by the names listed abo5e. The StyleFamilie ser5ice supports a com.sun.star.container.A0nde /ccess. 4rom the StyleFamilie 8 retrie5e one of the families listed abo5e by name or inde . / collection of styles are recei5ed which is a com.sun.star.style.Style4amily ser5ice8 pro5iding access to the single styles through an com.sun.star.container.A6ameContainer or an com.sun.star.container.A0nde /ccess. $ach style is a com.sun.star.style.Style and supports the interface com.sun.star.style.AStyle that inherits from com.sun.star.container.A6amed. The XStyle contains:

"!

OpenOffice.org 3.1 Developer's Guide April !!"

-t6les

tring$get:ame()$void$ et:ame($6in7$ tring$a:ame)$.oolean$i U erDe4ined()$ .oolean$i 1nU e()$ tring$getParentStyle()$void$ etParentStyle($6in7$ tring$ aParentStyle)

The office comes with a set of default styles. These styles use programmatic names on the /P0 le5el. The method et:ame() in XStyle always throws an e ception if called at such styles. The same applies to changing the property Category. /t the user interface locali9ed names are used. The user interface names are pro5ided through the property U er1nter4ace:ame. 6ote that page and numbering styles are not hierarchical and cannot ha5e parent styles. The method getParentStyle() always returns an empty string8 and the method etParentStyle() throws a com.sun.star.uno.-untime$ ception when called at a default style. The method i U erDe4ined() determines whether a style is defined by a user or is a builtCin style. / builtCin style cannot be deleted. /dditionally the builtCin styles ha5e two different names: a true ob:ect name and an alias that is displayed at the user interface. This is not usually 5isible in an $nglish +pen+ffice.org 5ersion8 e cept for the default styles that are named DStandardD as programmatic name and DDefaultD in the user interface. The Style ser5ice defines the following properties which are shared by all styles: Properties of co&.sun.st%r.style.,tyle com.sun.star.style.Style:0sPhysical 6optional/$readonly7$.oolean C Determines if a style is physically created. com.sun.star.style.Style:4ollowSty 6optional7$.oolean C Contains the name of the le style that is applied to the ne t paragraph. com.sun.star.style.Style:Display6 6optional/$readonly7$ tring C Contains the name ame of the style as is displayed in the user interface. com.sun.star.style.Style:0s/utoBp 6optional7$ tring C Determines if a style is date automatically updated when the properties of an ob:ect that the style is applied to are changed. com.sun.star.style.Style:ParaStyle 6optional/$property7$ e5uenceK Conditions com.sun.star.beans:6amedFalue L C Defines the conte t and styles for conditional paragraphs. This property is only a5ailable if the style is a conditional paragraph style. To determine the user interface name8 each style has a string property Di play:ame that contains the name that is used at the user interface. 0t is not allowed to use a Di play:ame of a style as a name of a userCdefined style of the same style family. The builtCin styles are not created actually as long as they are not used in the document. The property 1 P%y ical chec2s for this. 0t is necessary8 for file e port purposes8 to detect styles which do not need to be e ported. Conditional paragraph styles are handled by the property

#$%pter 7 Text Documents

"1

-t6les

com.sun.star.style.Style:ParaStyleConditions. The se>uence consists of pairs where the name part <the first part= of the pair defines the conte t where the style <the second part8 a string that denotes a style name or an empty string= should be applied to. /ssigning an empty string to the style name will disable the conditional style for that conte t. The StyleFamilie collection can load styles. 4or this purpose8 the interface com.sun.star.style.AStyleLoader is a5ailable at the StyleFamilie collection. 0t consists of two methods:
void$loadStyle FromURL($6in7$ tring$URL/$$$$$$$$$$$$$$$$$$$$$$$$$$6in7$ e5uenceK$comFF unFF tarFF.ean FFPropertyValue$L$a0ption )$ e5uenceK$ comFF unFF tarFF.ean FFPropertyValue$L$getStyleLoader0ption ()

The method loadStyle FromURL() enables the document to import styles from other documents. The e pected se>uence of PropertyValue structs can contain the following properties: Properties for lo%d,tyles(ro&;"+34
Load!e)tStyle

Description Determines if character and paragraph styles are to be imported. 0t is not possible to select character styles and paragraph styles separately. .oolean C 0mport frame styles only. .oolean C 0mport page styles only. .oolean C 0mport numbering styles only. .oolean C Determines if internal styles are o5erwritten if the source document contains styles ha5ing the same name.

LoadFrameStyle LoadPageStyle Load:um.eringStyle 0verwriteStyle

The method getStyleLoader0ption () returns a se>uence of these PropertyValue structs8 set to their default 5alues.

Ch%r%cter ,tyles
Character styles support all properties defined in the ser5ices com.sun.star.style.CharacterProperties and com.sun.star.style.CharacterProperties/sian. They are created using the com.sun.star.lang.A(ultiSer5ice4actory interface of the te t document model using the ser5ice name Dcom' un' tar' tyle'C%aracterStyleD. The default style that is shown in the user interface and accessible through the /P0 is not a style8 but a tool to remo5e applied character styles. Therefore8 its properties cannot be changed. Set the property C%arStyle:ame at an ob:ect including the ser5ice com.sun.star.style.CharacterProperties to set its character style.

"

OpenOffice.org 3.1 Developer's Guide April !!"

*%r%gr%p$ -t6les

P%r%gr%ph ,tyles
Paragraph styles support all properties defined in the ser5ices com.sun.star.style.ParagraphProperties and com.sun.star.style.ParagraphProperties/sian. They are created using the com.sun.star.lang.A(ultiSer5ice4actory interface of the te t document model using the ser5ice name Dcom' un' tar' tyle'Paragrap%StyleD. /dditionally8 there is a ser5ice com.sun.star.style.ConditionalParagraphStyle which creates conditional paragraph styles. Conditional styles are paragraph styles that ha5e different effects8 depending on the conte t. There is currently no support of the condition properties at the /P0. Set the property ParaStyle:ame at an ob:ect8 including the ser5ice com.sun.star.style.ParagraphProperties to set its paragraph style.

(r%&e ,tyles
4rame styles support all properties defined in the ser5ices com.sun.star.te t.3ase4rameProperties. The frame styles are applied to te t frames8 graphic ob:ects and embedded ob:ects. They are created using the com.sun.star.lang.A(ultiSer5ice4actory interface of the te t document model using the ser5ice name Dcom' un' tar' tyle'FrameStyleD. Set the property FrameStyle:ame at com.sun.star.te t.3ase4rame ob:ects to set their frame style.

P%ge ,tyles
Page styles are controlled 5ia properties. The page related properties are defined in the ser5ices com.sun.star.style.PageStyle. They are created using the com.sun.star.lang.A(ultiSer5ice4actory interface of the te t document model using the ser5ice name Dcom' un' tar' tyle'PageStyleD.

#$%pter 7 Text Documents

"3

*%ge -t6les

/s mentioned abo5e8 page styles are not hierarchical. The section Page Layout discusses page styles. The PageStyle is set at the current te t cursor position by setting the property PageDe c:ame$ to an e isting page style name.This will insert a new page that uses the new page style. 0f no new page should be inserted8 the cursor has to be at the beginning of the first paragraph.

Nu&*ering ,tyles
6umbering styles support all properties defined in the ser5ices com.sun.star.te t.6umberingStyle. They are created using the com.sun.star.lang.A(ultiSer5ice4actory interface of the te t document model using the ser5ice name Dcom' un' tar' tyle':um.eringStyleD. The structure of the numbering rules is described in section Line 6umbering and +utline 6umbering. The name of the numbering style is set in the property :um.eringStyle:ame of paragraphs <set through the PropertySet of a !e)tCur or= or a paragraph style to apply the numbering to the paragraphs. The following e ample demonstrates the use of paragraph styles:
"##$!%i $met%od$demon trate $%ow$to$create/$in ert$and$apply$ tyle $$#"$ protected$void$Style ()ample()$*$$$$$try$*$$$$$$$$$""$Ro$to$t%e$end$o4$t%e$ document$$$$$$$$$m)DocCur or'goto(nd(4al e), ""$1n ert$two$paragrap%$.rea- $$$$$$$$$m)Doc!e)t'in ertControlC%aracter($$$$$$$ m)DocCur or/$ControlC%aracter'PARARRAP?<;R(AT/$4al e),$$$$$$$$$ m)Doc!e)t'in ertControlC%aracter($$$$$$$$$$$$$$m)DocCur or/$ ControlC%aracter'PARARRAP?<;R(AT/$4al e), ""$Create$a$new$ tyle$4rom$t%e$documentS $4actory$$$$$$$$$XStyle$)Style$+$ (XStyle)$UnoRuntime'5uery1nter4ace($$$$$$$$$$$$$$XStyle'cla /$ m)DocFactory'create1n tance(3com' un' tar' tyle'Paragrap%Style3)), ""$Acce $t%e$XPropertySet$inter4ace$o4$t%e$new$ tyle$$$$$$$$$XPropertySet$ )StyleProp $+$(XPropertySet)$ UnoRuntime'5uery1nter4ace($$$$$$$$$$$$$XPropertySet'cla /$)Style), ""$Rive$t%e$new$ tyle$a$lig%t$.lue$.ac-ground$$$$$$$$$ )StyleProp ' etPropertyValue$(3Para;ac-Color3/$new$1nteger(8ABP8QPA)), ""$Ret$t%e$StyleFamilie Supplier$inter4ace$o4$t%e$document$$$$$$$$$ XStyleFamilie Supplier$)Supplier$+$ (XStyleFamilie Supplier)UnoRuntime'5uery1nter4ace($$$$$$$$$$$$$XStyleFamilie S upplier'cla /$m)Doc), ""$U e$t%e$StyleFamilie Supplier$inter4ace$to$get$t%e$X:ameAcce $inter4ace$o4$ t%e$$$$$$$$$""$actual$ tyle$4amilie $$$$$$$$$X:ameAcce $)Familie $+$ (X:ameAcce )$UnoRuntime'5uery1nter4ace$($$$$$$$$$$$$$$X:ameAcce 'cla /$

"&

OpenOffice.org 3.1 Developer's Guide April !!"

7um,ering -t6les

)Supplier'getStyleFamilie ()), ""$Acce $t%e$SParagrap%Style S$Family$$$$$$$$$X:ameContainer$)Family$+$ (X:ameContainer)$UnoRuntime'5uery1nter4ace($$$$$$$$$$$$$$X:ameContainer'cla /$ )Familie 'get;y:ame(3Paragrap%Style 3)), ""$1n ert$t%e$newly$created$ tyle$into$t%e$Paragrap%Style $4amily$$$$$$$$$ )Family'in ert;y:ame$(3All>Singing$All>Dancing$Style3/$)Style), ""$Ret$t%e$XParagrap%Cur or$inter4ace$o4$t%e$document$cur or$$$$$$$$$ XParagrap%Cur or$)ParaCur or$+$(XParagrap%Cur or)$UnoRuntime'5uery1nter4ace($$$ XParagrap%Cur or'cla /$m)DocCur or), ""$Select$t%e$4ir t$paragrap%$in erted$$$$$$$$$ )ParaCur or'gotoPreviou Paragrap%(4al e),$$$$$$$$$ )ParaCur or'gotoPreviou Paragrap%(true), ""$Acce $t%e$property$ et$o4$t%e$cur or$ election$$$$$$$$$XPropertySet$ )Cur orProp $+$(XPropertySet)$ UnoRuntime'5uery1nter4ace($$$$$$$$$$$$$XPropertySet'cla /$m)DocCur or), ""$Set$t%e$ tyle$o4$t%e$cur or$ election$to$our$newly$created$ tyle$$$$$$$$$ )Cur orProp ' etPropertyValue(3ParaStyle:ame3/$3All>Singing$All>Dancing$ Style3), ""$Ro$.ac-$to$t%e$end$$$$$$$$$m)DocCur or'goto(nd(4al e), ""$Select$t%e$la t$paragrap%$in$t%e$document$$$$$$$$$ )ParaCur or'goto:e)tParagrap%(true), ""$And$re et$itS $ tyle$to$SStandardS$(t%e$programmatic$name$4or$t%e$de4ault$ tyle)$$$$$$$$$)Cur orProp ' etPropertyValue(3ParaStyle:ame3/$3Standard3), =$catc%$(()ception$e)$*$$$$$$$$$e'printStac-!race$(Sy tem'out),$$$$$=$=

,ettings

Gener%l Docu&ent 2nfor&%tion


Te t documents offer general information about the document through their com.sun.star.document.ADocument0nfoSupplier interface. The Document1n4o is a common +pen+ffice.org feature and is discussed in +ffice De5elopment. The XDocument1n4oSupplier has one single method:
comFF unFF tarFFdocumentFFXDocument1n4o$getDocument1n4o()

which returns a com.sun.star.document.Document0nfo ser5ice8 offering the statistical information about the document that is a5ailable through File - $roperties in the 7B0.

#$%pter 7 Text Documents

"5

Document *roperties

Docu&ent Properties
The model implements a com.sun.star.beans.APropertySet that pro5ides properties concerning character formatting and general settings. The properties for character attributes are C%arFont:ame8 C%arFontStyle:ame8 C%arFontFamily8 C%arFontC%arSet8 C%arFontPitc% and their /sian counterparts C%arFontStyle:ameA ian8 C%arFontFamilyA ian8 C%arFontC%arSetA ian8 C%arFontPitc%A ian. The following properties handle general settings: Properties of co&.sun.st%r.te$t. e$tDocu&ent com.sun.star.te t./d5ancedTe tDocume com.sun.star.lang.Locale. Default locale of the nt:CharLocale document. com.sun.star.te t./d5ancedTe tDocume long C 6umber of characters. nt:CharacterCount com.sun.star.te t./d5ancedTe tDocume long C 6umber of paragraphs. nt:ParagraphCount com.sun.star.te t./d5ancedTe tDocume long C 6umber of words. nt:*ordCount com.sun.star.te t./d5ancedTe tDocume tring C Contains all that characters that are nt:*ordSeparator treated as separators between words to determine word count. com.sun.star.te t.Te tDocument:-edlin %ort C Displays redlines as defined in eDisplayType com.sun.star.document.-edlineDisplayType. -ecordChanges .oolean C Determines if redlining is switched on. com.sun.star.te t.Te tDocument:ShowC .oolean C Determines if redlines are displayed. hanges com.sun.star.te t.Te tDocument:-edlin e5uence$K$.yte$L. Contains the password eProtection;ey 2ey. com.sun.star.document.Settings:4orbidd com.sun.star.i!'n.4orbiddenCharacters. Contains enCharacters characters that are not allowed to be at the first or last character of a te t line. TwoDigitHear %ort C Determines the start of the range8 for e ample8 when entering a twoCdigit year. com.sun.star.te t.7enericTe tDocument tring C The B-L to the file that contains the :0nde /uto(ar24ileB-L search words and settings of the automatic mar2ing of inde mar2s for alphabetical inde es. com.sun.star.document.+fficeDocument .oolean C 0f true8 the first form ob:ect is selected :/utomaticControl4ocus when the document is loaded. com.sun.star.document.+fficeDocument .oolean C Determines if form <database= :/pply4ormDesign(ode controls are in the design mode.

"(

OpenOffice.org 3.1 Developer's Guide April !!"

Document *roperties

com.sun.star.te t.Te tDocument:?ide4i eldTips

.oolean C 0f true8 the automatic tips displayed

for some types of te t fields are suppressed.

Cre%ting Def%ult ,ettings


The com.sun.star.lang.A(ultiSer5ice4actory implemented at the model pro5ides the ser5ice com.sun.star.te t.Defaults. Bse this ser5ice to find out default 5alues to set paragraph and character properties of the document to default.

Cre%ting Docu&ent ,ettings


/nother set of properties can be created by the ser5ice name com.sun.star.document.Settings that contains a number of additional settings.

+ine Nu&*ering %nd Outline Nu&*ering


+pen+ffice.org pro5ides automatic numbering for te ts. 4or instance8 paragraphs can be numbered or listed with bullets in a hierarchical manner8 chapter headings can be numbered and lines can be counted and numbered.

P%r%gr%ph %nd Outline Nu&*ering


com' un' tar'te)t':um.eringRule

The 2ey for paragraph numbering is the paragraph property :um.eringRule . This property is pro5ided by paragraphs and numbering styles and is a member of com.sun.star.style.ParagraphProperties. / similar ob:ect controls outline numbering and is returned from the method:
comFF unFF tarFFcontainerFFX1nde)Replace$getC%apter:um.eringRule ()

#$%pter 7 Text Documents

"7

*%r%gr%p$ %nd Outline 7um,ering

at the com.sun.star.te t.AChapter6umberingSupplier interface that is implemented at the document model. These ob:ects pro5ide an interface com.sun.star.container.A0nde -eplace. $ach element of the container represents a numbering le5el. The writer document pro5ides ten numbering le5els. The highest le5el is 9ero. $ach le5el of the container consists of a se>uence of com.sun.star.beans.PropertyFalue. The two related ob:ects differ in some of properties they pro5ide. 3oth of them pro5ide the following properties: Co&&on Properties for P%r%gr%ph %nd Outline Nu&*ering in co&.sun.st%r.te$t.Nu&*ering+evel com.sun.star.te t.6umberingLe5el:/d: %ort C /d:ustment of the numbering symbol ust defined in com.sun.star.te t.?ori+rientation. com.sun.star.te t.6umberingLe5el:Pare %ort C Determines if higher numbering le5els nt6umbering are included in the numbering8 for e ample8 2...!.2. com.sun.star.te t.6umberingLe5el:Prefi tring C Contains strings that surround the numbering symbol8 for e ample8 brac2ets. com.sun.star.te i com.sun.star.te Style6ame com.sun.star.te *ith com.sun.star.te Line+ffset t.6umberingLe5el:Suff t.6umberingLe5el:Char
tring C 6ame of the character style that is applied to the number symbol. t.6umberingLe5el:Start %ort C Determines the 5alue the numbering starts with. The default is one. t.6umberingLe5el:4irst long C 0nfluences the left indent and left margin of the numbering.

com.sun.star.te t.6umberingLe5el:Left (argin com.sun.star.te t.6umberingLe5el:Sym bolTe tDistance com.sun.star.te t.6umberingLe5el:6u mberingType P%r%gr%ph Nu&*ering"ules Properties in co&.sun.st%r.te$t.Nu&*ering+evel com.sun.star.te t.6umberingLe5el:3ullet Char

6optional7$long C Distance between the

numbering symbol and the te t of the paragraph. %ort C Determines the type of the numbering defined in com.sun.star.style.6umberingType. Description

+nly paragraphs ha5e the following properties in their :um.eringRule property:

tring C Determines the bullet character if the numbering type is set to :um.ering!ypeFFC?AR<SP(C1AL.

"8

OpenOffice.org 3.1 Developer's Guide April !!"

*%r%gr%p$ %nd Outline 7um,ering

com.sun.star.te t.6umberingLe5el:3ullet 4ont6ame

tring C Determines the bullet font if the numbering type is set to :um.ering!ypeFFC?AR<SP(C1AL. com.sun.star.te t.6umberingLe5el:7raphi tring C Determines the type8 si9e and cB-L orientation of a graphic when the numbering type is set to :um.ering!ypeFF;1!MAP. 7raphic3itmap Bndocumented 7raphicSi9e Bndocumented com.sun.star.te t.6umberingLe5el:Fert+r %ort C Fertical orientation of a graphic ient according to com.sun.star.te t.Fert+rientation

+nly the chapter numbering rules pro5ide the following property: Property of Description co&.sun.st%r.te$t.Ch%pterNu&*erin g"ule com.sun.star.te t.Chapter6umbering-ule: tring C Contains the name of the paragraph ?eadingStyle6ame style that mar2s a paragraph as a chapter heading. Note 6ote that the 6umbering-ules ser5ice is returned by 5alue li2e most properties in the +pen+ffice.org /P08 therefore you must get the rules from the XPropertySet8 change them and put the :um.eringRule ob:ect bac2 into the property. The following is an e ample for the :um.eringRule ser5ice:
"##$!%i $met%od$demon trate $%ow$to$ et$num.ering$type $and$num.ering$level $ u ing$t%e$$$$$com' un' tar'te)t':um.eringRule $ ervice$$#"$protected$void$ :um.ering()ample()$*$$$$$try$*$$$$$$$$$""$Ro$to$t%e$end$o4$t%e$document$$$$$$$$ m)DocCur or'goto(nd(4al e),$$$$$$$$$""$Ret$t%e$Relative!e)tContent1n ert$ inter4ace$o4$t%e$document$$$$$$$$$XRelative!e)tContent1n ert$)Relative$+$ (XRelative!e)tContent1n ert)$$$$$$$$$$$$$ UnoRuntime'5uery1nter4ace(XRelative!e)tContent1n ert'cla /$m)Doc!e)t), ""$U e$t%e$documentS $4actory$to$create$t%e$:um.eringRule $ ervice/$and$get$ itS $$$$$$$$$""$X1nde)Acce $inter4ace$$$$$$$$$X1nde)Acce $):um$+$ (X1nde)Acce )$UnoRuntime'5uery1nter4ace(X1nde)Acce 'cla /$$$$$$$$$$$$$ m)DocFactory'create1n tance(3com' un' tar'te)t':um.eringRule 3)), ""$Al o$get$t%e$:um.eringRuleS $X1nde)Replace$inter4ace$$$$$$$$$X1nde)Replace$ )Replace$+$(X1nde)Replace)$ UnoRuntime'5uery1nter4ace($$$$$$$$$$$$$X1nde)Replace'cla /$):um), ""$Create$an$array$o4$XPropertySet /$one$4or$eac%$o4$t%e$t%ree$paragrap% $ weSre$a.out$$$$$$$$$""$to$create$$$$$$$$$XPropertySet$)Para 67$+$new$ XPropertySet6A7,$$$$$$$$$4or$(int$i$+$9$,$i$K$A$,$GG$i)$*$$$$$$$$$$$$$""$ Create$a$new$paragrap%$$$$$$$$$$$$$X!e)tContent$):ewPara$+$(X!e)tContent)$ UnoRuntime'5uery1nter4ace($$$$$$$$$$$$$$$$$X!e)tContent'cla /$ m)DocFactory'create1n tance($$$$$$$$$$$$$$$$$$$$$3com' un' tar'te)t'Paragrap%3 )), ""$Ret$t%e$XPropertySet$inter4ace$o4$t%e$new$paragrap%$and$put$it$in$our$array$ )Para 6i7$+$(XPropertySet)$ UnoRuntime'5uery1nter4ace($$$$$$$$$$$$$$$$$$XPropertySet'cla /$):ewPara), ""$1n ert$t%e$new$paragrap%$into$t%e$document$a4ter$t%e$4i %$ ection'$A $it$i $

#$%pter 7 Text Documents

""

*%r%gr%p$ %nd Outline 7um,ering

""$an$in ert$$$$$$$$$$$$$""$relative$to$t%e$4i %$ ection/$t%e$4ir t$paragrap%$ in erted$will$.e$.elow$$$$$$$$$$$$$""$t%e$ne)t$two$$$$$$$$$$$$$ )Relative'in ert!e)tContentA4ter$():ewPara/$m)Fi %Section), ""$Separate$4rom$t%e$a.ove/$.ut$al o$need $to$.e$done$t%ree$time ""$Ret$t%e$PropertyValue$ e5uence$4or$t%i $num.ering$level$$$$$$$$$$$$$ PropertyValue67$aProp $+$(PropertyValue$67)$):um'get;y1nde)(i), ""$1terate$over$t%e$PropertyValueS $4or$t%i $num.ering$level/$loo-ing$4or$t%e$$ ""$S:um.ering!ypeS$property$$$$$$$$$$$$$4or$(int$&$+$9$,$&$K$aProp 'lengt%$,$G G&)$*$$$$$$$$$$$$$$$$$i4$(aProp 6&7':ame'e5ual $(3:um.ering!ype3))$*$$$$$$$$$$$ ""$0nce$we$4ind$it/$ et$itS $value$to$a$new$type/$$$$$$$$$$$$$$$$$$$$$$""$ dependent$on$w%ic%$$$$$$$$$$$$$$$$$$$$$""$num.ering$level$weSre$currently$on$$$ witc%$($i$)$*$$$$$$$$$$$$$$$$$$$$$$$$$ca e$9$F$aProp 6&7'Value$+$new$ S%ort(:um.ering!ype'R0MA:<UPP(R),$$$$$$$$$$$$$$$$$$$$$$$$$.rea-,$$$$$$$$$$$$$$$ ca e$8$F$aProp 6&7'Value$+$new$S%ort(:um.ering!ype'C?ARS<UPP(R<L(!!(R),$$$$$$$$ .rea-,$$$$$$$$$$$$$$$$$$$$$$$$$ca e$P$F$aProp 6&7'Value$+$new$ S%ort(:um.ering!ype'ARA;1C),$$$$$$$$$$$$$$$$$$$$$$$$$$$$$.rea-,$$$$$$$$$$$$$$$$ =$$$$$$$$$$$$$$$$$$$$$""$Put$t%e$updated$PropertyValue$ e5uence$.ac-$into$t%e$$ ""$:um.eringRule $ ervice$$$$$$$$$$$$$$$$$$$$$)Replace'replace;y1nde)$(i/$ aProp ),$$$$$$$$$$$$$$$$$$$$$$.rea-,$$$$$$$$$$$$$$$$$=$$$$$$$$$$$$$=$$$$$$$$$=$ ""$Ret$t%e$XParagrap%Cur or$inter4ace$o4$our$te)t$cur or$$$$$$$$$ XParagrap%Cur or$)ParaCur or$+$(XParagrap%Cur or)$UnoRuntime'5uery1nter4ace($$$ XParagrap%Cur or'cla /$m)DocCur or),$$$$$$$$$""$Ro$to$t%e$end$o4$t%e$ document/$t%en$ elect$t%e$preceding$paragrap% $$$$$$$$$ m)DocCur or'goto(nd(4al e),$$$$$$$$$)ParaCur or'gotoPreviou Paragrap%$4al e),$$ )ParaCur or'gotoPreviou Paragrap%$true),$$$$$$$$$ )ParaCur or'gotoPreviou Paragrap%$true), ""$Ret$t%e$XPropertySet$o4$t%e$cur orS $currently$ elected$te)t$$$$$$$$$ XPropertySet$)Cur orProp $+$(XPropertySet)$UnoRuntime'5uery1nter4ace($$$$$$$$$$ XPropertySet'cla /$m)DocCur or), ""$Set$t%e$updated$:um.ering$rule $to$t%e$cur orS $property$ et$$$$$$$$$ )Cur orProp ' etPropertyValue$(3:um.eringRule 3/$):um),$$$$$$$$$$$$$ m)DocCur or'goto(nd(4al e), ""$Set$t%e$4ir t$paragrap%$t%at$wa $in erted$to$a$num.ering$level$o4$P$(t%u $ it$will$$$$$$$$$""$%ave$Ara.ic$ tyle$num.ering)$$$$$$$$$ )Para 697' etPropertyValue$(3:um.eringLevel3/$new$S%ort$(( %ort)$P)), ""$Set$t%e$ econd$paragrap%$t%at$wa $in erted$to$a$num.ering$level$o4$8$(t%u $ it$will$$$$$$$$$""$%ave$SC%ar $Upper$LetterS$ tyle$num.ering)$$$$$$$$$ )Para 687' etPropertyValue$(3:um.eringLevel3/$new$S%ort(( %ort)$8)), ""$Set$t%e$t%ird$paragrap%$t%at$wa $in erted$to$a$num.ering$level$o4$9$(t%u $ it$will$$$$$$$$$""$%ave$SRoman$UpperS$ tyle$num.ering)$$$$$$$$$ )Para 6P7' etPropertyValue(3:um.eringLevel3/$new$S%ort(( %ort)$9)),$$$$$=$ catc%$(()ception$e)$*$$$$$$$$$e'printStac-!race$(Sy tem'out),$$$$$=$=

+ine Nu&*ering
The te t document model supports the interface com.sun.star.te t.ALine6umberingProperties. The pro5ided ob:ect has the properties described in the ser5ice com.sun.star.te t.Line6umberingProperties. 0t is used in con:unction with the paragraph properties ParaLine:um.erCount and ParaLine:um.erStartValue.

1!!

OpenOffice.org 3.1 Developer's Guide April !!"

7um,er 4orm%ts

Nu&*er (or&%ts
The te t document model pro5ides access to the number formatter through aggregation8 that is8 it pro5ides the interface com.sun.star.util.A6umber4ormatsSupplier seamlessly. The number formatter is used to format numerical 5alues. 4or details8 refer to 6umber 4ormats. 0n te t8 te t fields with numeric content and table cells pro5ide a property :um.erFormat that contains a long 5alue that refers to a number format.

e$t ,ections
/ te t section is a range of complete paragraphs that can ha5e its own format settings and source location8 separate from the surrounding te t. Te t sections can be nested in a hierarchical structure. 4or e ample8 a section is formatted to ha5e te t columns that different column settings in a te t on a paragraph by paragraph basis. The content of a section can be lin2ed through file lin2s or o5er a DD$ connection. The te t sections support the ser5ice com.sun.star.te t.Te tSection. To access the sections8 the te t document model implements the interface com.sun.star.te t.ATe tSectionsSupplier that pro5ides an interface com.sun.star.container.A6ame/ccess. The returned ob:ects support the interface com.sun.star.container.A0nde /ccess8 as well. (aster documents implement the structure of sub documents using lin2ed te t sections. /n e ample demonstrating the creation8 insertion and lin2ing of te t sections:
"##$!%i $met%od$demon trate $%ow$to$create$lin-ed$and$unlin-ed$ ection $$$#"$ protected$void$!e)tSection()ample()$*$$$$$try$*$$$$$$$$$""$Ro$to$t%e$end$o4$ t%e$document$$$$$$$$$m)DocCur or'goto(nd(4al e),$$$$$$$$$""$1n ert$two$ paragrap%$.rea- $$$$$$$$$ m)Doc!e)t'in ertControlC%aracter($$$$$$$$$$$$$$m)DocCur or/$ ControlC%aracter'PARARRAP?<;R(AT/$4al e),$$$$$$$$$ m)Doc!e)t'in ertControlC%aracter($$$$$$$$$$$$$$m)DocCur or/$ ControlC%aracter'PARARRAP?<;R(AT/$true), ""$Create$a$new$!e)tSection$4rom$t%e$document$4actory$and$acce $itS $X:amed$ inter4ace$$$$$$$$$X:amed$)C%ild:amed$+$(X:amed)$UnoRuntime'5uery1nter4ace($$$$$ X:amed'cla /$m)DocFactory'create1n tance(3com' un' tar'te)t'!e)tSection3)),$$$ ""$Set$t%e$new$ ection $name$to$SC%ild<SectionS$$$$$$$$$ )C%ild:amed' et:ame(3C%ild<Section3), ""$Acce $t%e$C%ild<SectionS $X!e)tContent$inter4ace$and$in ert$it$into$t%e$

#$%pter 7 Text Documents

1!1

7um,er 4orm%ts

document$$$$$$$$$X!e)tContent$)C%ildSection$+$(X!e)tContent)$ UnoRuntime'5uery1nter4ace($$$$$$$$$$$$$X!e)tContent'cla /$)C%ild:amed),$$$$$$$ m)Doc!e)t'in ert!e)tContent$(m)DocCur or/$)C%ildSection/$4al e), ""$Acce $t%e$XParagrap%Cur or$inter4ace$o4$our$te)t$cur or$$$$$$$$$ XParagrap%Cur or$)ParaCur or$+$(XParagrap%Cur or)$UnoRuntime'5uery1nter4ace($$$ XParagrap%Cur or'cla /$m)DocCur or), ""$Ro$.ac-$one$paragrap%$(into$C%ild<Section)$$$$$$$$$ )ParaCur or'gotoPreviou Paragrap%(4al e), ""$1n ert$a$ tring$into$t%e$C%ild<Section$$$$$$$$$ m)Doc!e)t'in ertString(m)DocCur or/$3!%i $i $a$te t3/$4al e), ""$Ro$to$t%e$end$o4$t%e$document$$$$$$$$$m)DocCur or'goto(nd(4al e), ""$Ro$.ac-$two$paragrap% $$$$$$$$$)ParaCur or'gotoPreviou Paragrap%$(4al e),$$$ )ParaCur or'gotoPreviou Paragrap%$(4al e),$$$$$$$$$""$Ro$to$t%e$end$o4$t%e$ document/$ electing$t%e$two$paragrap% $$$$$$$$$m)DocCur or'goto(nd(true), ""$Create$anot%er$te)t$ ection$and$acce $itS $X:amed$inter4ace$$$$$$$$$X:amed$ )Parent:amed$+$(X:amed)$UnoRuntime'5uery1nter4ace(X:amed'cla /$$$$$$$$$$$$$ m)DocFactory'create1n tance(3com' un' tar'te)t'!e)tSection3)), ""$Set$t%i $te)t$ ectionS $name$to$Parent<Section$$$$$$$$$)Parent:amed' et:ame$ (3Parent<Section3), ""$Acce $t%e$Parent<SectionS $X!e)tContent$inter4ace$'''$$$$$$$$$X!e)tContent$ )ParentSection$+$(X!e)tContent)$ UnoRuntime'5uery1nter4ace($$$$$$$$$$$$$X!e)tContent'cla /$)Parent:amed),$$$$$$ ""$'''and$in ert$it$into$t%e$document$$$$$$$$$ m)Doc!e)t'in ert!e)tContent(m)DocCur or/$)ParentSection/$4al e), ""$Ro$to$t%e$end$o4$t%e$document$$$$$$$$$m)DocCur or'goto(nd$ (4al e),$$$$$$$$$""$1n ert$a$new$paragrap%$$$$$$$$$ m)Doc!e)t'in ertControlC%aracter($$$$$$$$$$$$$$m)DocCur or/$ ControlC%aracter'PARARRAP?<;R(AT/$4al e),$$$$$$$$$""$And$ elect$t%e$new$ pargrap%$$$$$$$$$)ParaCur or'gotoPreviou Paragrap%(true), ""$Create$a$new$!e)t$Section$and$acce $itS $X:amed$inter4ace$$$$$$$$$X:amed$ )Lin-:amed$+$(X:amed)$UnoRuntime'5uery1nter4ace($$$$$$$$$$$$$X:amed'cla /$ m)DocFactory'create1n tance(3com' un' tar'te)t'!e)tSection3)),$$$$$$$$$""$Set$ t%e$new$te)t$ ectionS $name$to$Lin-ed<Section$$$$$$$$$ )Lin-:amed' et:ame(3Lin-ed<Section3), ""$Acce $t%e$Lin-ed<SectionS $X!e)tContent$inter4ace$$$$$$$$$X!e)tContent$ )Lin-edSection$+$(X!e)tContent)$ UnoRuntime'5uery1nter4ace($$$$$$$$$$$$$X!e)tContent'cla /$)Lin-:amed),$$$$$$$$ ""$And$in ert$t%e$Lin-ed<Section$into$t%e$document$$$$$$$$$ m)Doc!e)t'in ert!e)tContent(m)DocCur or/$)Lin-edSection/$4al e), ""$Acce $t%e$Lin-ed<SectionS $XPropertySet$inter4ace$$$$$$$$$XPropertySet$ )Lin-Prop $+$(XPropertySet)$ UnoRuntime'5uery1nter4ace($$$$$$$$$$$$$$XPropertySet'cla /$)Lin-:amed),$$$$$$$ ""$Set$t%e$lin-ed$ ection$to$.e$lin-ed$to$t%e$C%ild<Section$$$$$$$$$ )Lin-Prop ' etPropertyValue(3Lin-Region3/$3C%ild<Section3), ""$Acce $t%e$XPropertySet$inter4ace$o4$t%e$C%ild<Section$$$$$$$$$XPropertySet$ )C%ildProp $+$(XPropertySet)$ UnoRuntime'5uery1nter4ace($$$$$$$$$$$$$XPropertySet'cla /$)C%ild:amed),$$$$$$$ ""$Set$t%e$C%ild<SectionS $.ac-ground$colour$to$.lue$$$$$$$$$ )C%ildProp ' etPropertyValue(3;ac-Color3/$new$1nteger(8ABP8QPA)), ""$Re4re %$t%e$document/$ o$t%e$lin-ed$ ection$matc%e $t%e$C%ild<Section$$$$$$$ XRe4re %a.le$)Re4re %$+$(XRe4re %a.le)$UnoRuntime'5uery1nter4ace($$$$$$$$$$$$$$ XRe4re %a.le'cla /$m)Doc),$$$$$$$$$)Re4re %'re4re %(),$$$$$=$catc%$(()ception$ e)$*$$$$$$$$$e'printStac-!race$(Sy tem'out),$$$$$=$=

1!

OpenOffice.org 3.1 Developer's Guide April !!"

7um,er 4orm%ts

P%ge +%yout
/ page layout in +pen+ffice.org is always a page style. / page can not be hard formatted. To change the current page layout8 retrie5e the current page style from the te t cursor property PageStyle:ame and get this page style from the StyleFamily$PageStyle . Changes of the page layout happen through the properties described in com.sun.star.style.PageProperties. -efer to the /P0 reference for details on all the possible properties8 including the header and footer te ts which are part of these properties. /s headers or footers are connected to a page style8 the te t ob:ects are pro5ided as properties of the style. Depending on the setting of the page layout8 there is one header and footer te t ob:ect per style a5ailable or there are two8 a left and right header8 and footer te t: co&.sun.st%r.style.P%geProperties cont%ining He%ders %nd (ooters com.sun.star.style.PageProperties:?eaderTe t com.sun.star.style.PageProperties:?eaderTe tLeft com.sun.star.style.PageProperties:?eaderTe t-ight com.sun.star.style.PageProperties:4ooterTe t com.sun.star.style.PageProperties:4ooterTe tLeft com.sun.star.style.PageProperties:4ooterTe t-ight Description com.sun.star.te com.sun.star.te com.sun.star.te com.sun.star.te com.sun.star.te com.sun.star.te t.Te t.Te t.Te t.Te t.Te t.Te t t t t t t

The page layout of a page style can be e>ual on left and right pages8 mirrored8 or separate for right and left pages. This is controlled by the property PageStyleLayout that e pects 5alues from the enum com.sun.star.style.PageStyleLayout. /s long as left and right pages are e>ual8 ?eader!e)t and ?eaderRig%t!e)t are identical. The same applies to the footers. The te t ob:ects in headers and footers are only a5ailable if headers or footers are switched on8 using the properties ?eader1 0n and Footer1 0n. Drawing ob:ects cannot be inserted into headers or footers.

Colu&ns
Te t frames8 te t sections and page styles can be formatted to ha5e columns. The width of columns is relati5e since the absolute width of the ob:ect is un2nown in the model. The layout formatting is responsible for calculating the actual widths of the columns. Columns are applied using the property !e)tColumn . 0t e pects a com.sun.star.te t.Te tColumns ser5ice that has to be created by the document factory. The

#$%pter 7 Text Documents

1!3

7um,er 4orm%ts

interface com.sun.star.te t.ATe tColumns refines the characteristics of the te t columns before applying the created !e)tColumn ser5ice to the property !e)tColumn . Consider the following e ample to see how to wor2 with te t columns:
"##$!%i $met%od$demon trate $t%e$X!e)tColumn $inter4ace$and$%ow$to$in ert$a$ .lan-$paragrap%$$$$$u ing$t%e$XRelative!e)tContent1n ert$inter4ace$$#"$ protected$void$!e)tColumn ()ample()$*$$$$$try$*$$$$$$$$$""$Ro$to$t%e$end$o4$ t%e$doucment$$$$$$$$$m)DocCur or'goto(nd(4al e),$$$$$$$$$""$in ert$a$new$ paragrap%$$$$$$$$$m)Doc!e)t'in ertControlC%aracter(m)DocCur or/$ ControlC%aracter'PARARRAP?<;R(AT/$4al e), ""$in ert$t%e$ tring$S1$am$a$4i %'S$899$time $$$$$$$$$4or$(int$i$+$9$,$i$K$899$ ,$GGi)$*$$$$$$$$$$$$$m)Doc!e)t'in ertString(m)DocCur or/$31$am$a$4i %'3/$ 4al e),$$$$$$$$$=$$$$$$$$$""$in ert$a$paragrap%$.rea-$a4ter$t%e$te)t$$$$$$$$$ m)Doc!e)t'in ertControlC%aracter(m)DocCur or/$ ControlC%aracter'PARARRAP?<;R(AT/$4al e), ""$Ret$t%e$XParagrap%Cur or$inter4ace$o4$our$te)t$cur or$$$$$$$$$ XParagrap%Cur or$)ParaCur or$+$(XParagrap%Cur or)$UnoRuntime'5uery1nter4ace($$$ XParagrap%Cur or'cla /$m)DocCur or),$$$$$$$$$""$Hump$.ac-$.e4ore$all$t%e$te)t$ we$&u t$in erted$$$$$$$$$)ParaCur or'gotoPreviou Paragrap%(4al e),$$$$$$$$$ )ParaCur or'gotoPreviou Paragrap%(4al e), ""$1n ert$a$ tring$at$t%e$.eginning$o4$t%e$.loc-$o4$te)t$$$$$$$$$ m)Doc!e)t'in ertString(m)DocCur or/$3Fi %$ ection$.egin F3/$4al e), ""$!%en$ elect$all$o4$t%e$te)t$$$$$$$$$)ParaCur or'goto:e)tParagrap%(true),$$$$ )ParaCur or'goto:e)tParagrap%(true), ""$Create$a$new$te)t$ ection$and$get$itS $X:amed$inter4ace$$$$$$$$$X:amed$ )Section:amed$+$(X:amed)$UnoRuntime'5uery1nter4ace($$$$$$$$$$$$$X:amed'cla /$ m)DocFactory'create1n tance(3com' un' tar'te)t'!e)tSection3)), ""$Set$t%e$name$o4$our$new$ ection$(appropiately)$to$SFi %S$$$$$$$$$ )Section:amed' et:ame(3Fi %3), ""$Create$t%e$!e)tColumn $ ervice$and$get$itS $X!e)tColumn $inter4ace$$$$$$$$$ X!e)tColumn $)Column $+$(X!e)tColumn )$ UnoRuntime'5uery1nter4ace($$$$$$$$$$$$$X!e)tColumn 'cla /$ m)DocFactory'create1n tance(3com' un' tar'te)t'!e)tColumn 3)), ""$2e$want$t%ree$column $$$$$$$$$)Column ' etColumnCount(( %ort)$A), ""$Ret$t%e$!e)tColumn /$and$ma-e$t%e$middle$one$narrow$wit%$a$larger$margin$$$$ ""$on$t%e$le4t$t%an$t%e$rig%t$$$$$$$$$!e)tColumn67$aSe5uence$+$ )Column 'getColumn $(),$$$$$$$$$aSe5uence687'2idt%$"+$P,$$$$$$$$$ aSe5uence687'Le4tMargin$+$AC9,$$$$$$$$$aSe5uence687'Rig%tMargin$+$P99,$$$$$$$$$ ""$Set$t%e$updated$!e)tColumn $.ac-$to$t%e$X!e)tColumn $$$$$$$$$ )Column ' etColumn (aSe5uence), ""$Ret$t%e$property$ et$inter4ace$o4$our$SFi %S$ ection$$$$$$$$$XPropertySet$ )SectionProp $+$(XPropertySet)$ UnoRuntime'5uery1nter4ace($$$$$$$$$$$$$XPropertySet'cla /$)Section:amed), ""$Set$t%e$column $to$t%e$!e)t$Section$$$$$$$$$ )SectionProp ' etPropertyValue(3!e)tColumn 3/$)Column ), ""$Ret$t%e$X!e)tContent$inter4ace$o4$our$SFi %S$ ection$$$$$$$$$m)Fi %Section$ +$(X!e)tContent)$UnoRuntime'5uery1nter4ace($$$$$$$$$$$$$X!e)tContent'cla /$ )Section:amed), ""$1n ert$t%e$SFi %S$ ection$over$t%e$currently$ elected$te)t$$$$$$$$$ m)Doc!e)t'in ert!e)tContent(m)DocCur or/$m)Fi %Section/$true), ""$Ret$t%e$wonder4ul$XRelative!e)tContent1n ert$inter4ace$$$$$$$$$ XRelative!e)tContent1n ert$)Relative$+$(XRelative!e)tContent1n ert)$$$$$$$$$$$$

1!&

OpenOffice.org 3.1 Developer's Guide April !!"

7um,er 4orm%ts

UnoRuntime'5uery1nter4ace(XRelative!e)tContent1n ert'cla /$m)Doc!e)t), ""$Create$a$new$empty$paragrap%$and$get$itS $X!e)tContent$inter4ace$$$$$$$$$ X!e)tContent$):ewPara$+$(X!e)tContent)$ UnoRuntime'5uery1nter4ace(X!e)tContent'cla /$$$$$$$$$$$$$$ m)DocFactory'create1n tance(3com' un' tar'te)t'Paragrap%3)), ""$1n ert$t%e$empty$paragrap%$a4ter$t%e$4i %$!e)t$Section$$$$$$$$$ )Relative'in ert!e)tContentA4ter():ewPara/$m)Fi %Section),$$$$$=$catc%$ (()ception$e)$*$$$$$$$$$e'printStac-!race(Sy tem'out),$$$$$=$=

The te t columns property consists of com.sun.star.te t.Te tColumn structs. The *idth elements of all structs in the !e)tColumn se>uence ma2e up a sum8 that is pro5ided by the method getRe4erenceValue() of the X!e)tColumn interface. To determine the metric width of an actual column8 the reference 5alue and the columns width element ha5e to be calculated using the metric width of the ob:ect <page8 te t frame8 te t section= and a rule of three8 for e ample:
nColumnA2idt%$+$aColumn 6A7'2idt%$"$)!e)tColumn 'getRe4erenceValue()$#$ Real0.&ect2idt%

The column margins <Le4tMargin8 and Rig%tMargin elements of the struct= are inside of the column. Their 5alues do not influence the column width. They :ust limit the space a5ailable for the column content. The default column setting in +pen+ffice.org creates columns with e>ual margins at inner columns8 and no left margin at the leftmost column and no right margin at the rightmost column. Therefore8 the relati5e width of the first and last column is smaller than those of the inner columns. This causes a limitation of this property: Setting the te t columns with e>ual column content widths and e>ual margins is only possible when the width of the ob:ect <te t frame8 te t section= can be determined. Bnfortunately this is impossible when the width of the ob:ect depends on its en5ironment itself.

+in1 %rgets
The interface com.sun.star.document.ALin2TargetSupplier of the document model pro5ides all elements of the document that can be used as lin2 targets. These targets can be used for load B-Ls and sets the selection to a certain position ob:ect inside of a document. /n e ample of a B-L containing a lin2 target is Dfile:///c:/documents/document ! "oo#mar#nameD. This interface is used from the hyperlin2 dialog to detect the lin2s a5ailable inside of a document. The interface com.sun.star.container.A6ame/ccess returned by the method getLin- () pro5ides access to an array of target types. These types are:

#$%pter 7 Text Documents

1!5

7um,er 4orm%ts

Tables Te t frame 7raphics +L$+b:ects Sections ?eadings 3oo2mar2s.

The names of the elements depend on the installed language. $ach returned ob:ect supports the interfaces com.sun.star.beans.APropertySet and interface com.sun.star.container.A6ame/ccess. The property set pro5ides the properties Lin-Di play:ame <string= and Lin-Di play;itmap <com.sun.star.awt.A3itmap=. $ach of these ob:ects pro5ides an array of targets of the relating type. $ach target returned supports the interface com.sun.star.beans.APropertySet and the property Lin-Di play:ame <string=. The name of the ob:ects is the boo2mar2 to be added to the document B-L8 for e ample8 DTa"le !ta"leD. The Lin-Di play:ame contains the name of the ob:ect8 e.g. D!a.le8D.

e$t Docu&ent Controller


The te t document model 2nows its controller and it can loc2 the controller to bloc2 user interaction. The appropriate methods in the model@s com.sun.star.frame.A(odel interface are:
void$loc-Controller ()$void$unloc-Controller ()$.oolean$%a Controller Loc-ed()$ comFF unFF tarFF4rameFFXController$getCurrentController()$void$ etCurrentController($6in7$comFF unFF tarFF4rameFFXController$)Controller)

The controller returned by getCurrentController() shares the following interfaces with all other document controllers in +pen+ffice.org:

com.sun.star.frame.AController com.sun.star.frame.ADispatchPro5ider com.sun.star.ui.AConte t(enu0nterceptor

Document controllers are e plained in the +ffice De5elopment.

e$t)ie.
The writer controller implementation supports the interface
1!( OpenOffice.org 3.1 Developer's Guide April !!"

7um,er 4orm%ts

com.sun.star.5iew.ASelectionSupplier that returns the ob:ect that is currently selected in the user interface. 0ts method getSelection() returns an any that may contain the following ob:ect depending on the selection: ,election Te t "eturned O*:ect com.sun.star.container.A0nde /ccess containing one or more com.sun.star.uno.A0nterface pointing to a te t range. com.sun.star.uno.A0nterface pointing to a table cursor. com.sun.star.uno.A0nterface pointing to a te t frame. com.sun.star.uno.A0nterface pointing to a graphic ob:ect. com.sun.star.uno.A0nterface pointing to an +L$ ob:ect. com.sun.star.uno.A0nterface pointing to a com.sun.star.drawing.ShapeCollection containing one or more shapes.

Selection of table cells Te t frame 7raphic ob:ect +L$ ob:ect Shape8 4orm control

com' un' tar'view'XControlAcce

pro5ides access to the controller of form controls.


com' un' tar'te)t'X!e)tViewCur orSupplier

pro5ides access to the cursor of the 5iew.


com' un' tar'te)t'XRu.ySelection

pro5ides access to rubies contained in the selection. This interface is necessary for /sian language support.
com' un' tar'view'XViewSetting Supplier

pro5ides access to the settings of the 5iew as described in the ser5ice com.sun.star.te t.FiewSettings. Properties of co&.sun.st%r.te$t.)ie.,ettings com.sun.star.te t.FiewSettings:Show/n .oolean C 0f true8 annotations <notes= are 5isible. notations com.sun.star.te t.FiewSettings:Show3r .oolean C 0f true8 paragraph line brea2s are ea2s 5isible. com.sun.star.te t.FiewSettings:ShowDr .oolean C 0f true8 shapes are 5isible. awings
#$%pter 7 Text Documents 1!7

7um,er 4orm%ts

com.sun.star.te t.FiewSettings:Show4ie ldCommands com.sun.star.te t.FiewSettings:Show4o otnote3ac2ground com.sun.star.te t.FiewSettings:Show7r aphics com.sun.star.te t.FiewSettings:Show?i ddenParagraphs com.sun.star.te t.FiewSettings:Show?i ddenTe t com.sun.star.te t.FiewSettings:Show?o ri-uler com.sun.star.te t.FiewSettings:Show?o riScroll3ar com.sun.star.te t.FiewSettings:Show0n de (ar23ac2ground com.sun.star.te t.FiewSettings:ShowPa ra3rea2s com.sun.star.te t.FiewSettings:ShowPr otectedSpaces com.sun.star.te t.FiewSettings:ShowSo ft?yphens com.sun.star.te t.FiewSettings:ShowSp aces com.sun.star.te t.FiewSettings:ShowTa ble3oundaries com.sun.star.te t.FiewSettings:ShowTa bles com.sun.star.te t.FiewSettings:ShowTa bstops com.sun.star.te t.FiewSettings:ShowTe t3oundaries com.sun.star.te t.FiewSettings:ShowTe t4ield3ac2ground com.sun.star.te t.FiewSettings:ShowFe rt-uler com.sun.star.te t.FiewSettings:ShowFe rtScroll3ar com.sun.star.te t.FiewSettings:Smooth Scrolling com.sun.star.te t.FiewSettings:Solid(a r2?andles com.sun.star.te t.FiewSettings:MoomTy pe

.oolean C 0f true8 te t fields are shown with their

commands8 otherwise the content is 5isible. .oolean C 0f true8 footnotes symbols are displayed with gray bac2ground. .oolean C 0f true8 graphic ob:ects are 5isible.
.oolean C 0f true8 hidden paragraphs are

displayed. .oolean C 0f true8 hidden te t is displayed.


.oolean C 0f true8 the hori9ontal ruler is

displayed. .oolean C 0f true8 the hori9ontal scroll bar is displayed. .oolean C 0f true 8 inde mar2s are displayed with gray bac2ground. .oolean C 0f true 8 paragraph brea2s are 5isible.
.oolean C 0f true8 protected spaces <hard spaces=

are displayed with gray bac2ground. .oolean C 0f true8 soft hyphens are displayed with gray bac2ground. .oolean C 0f true8 spaces are displayed with dots.
.oolean C 0f true8 table boundaries are displayed. .oolean C 0f true8 tables are 5isible. .oolean C 0f true8 tab stops are 5isible. .oolean C 0f true8 te t boundaries are displayed. .oolean C 0f true8 te t fields are displayed with

gray bac2ground. .oolean C 0f true8 the 5ertical ruler is displayed.


.oolean C 0f true8 the 5ertical scroll bar is

displayed. .oolean C 0f true8 smooth scrolling is acti5e.


.oolean C 0f true8 handles of drawing ob:ects are

5isible. %ort C defines the 9oom type for the document as defined in com.sun.star.5iew.DocumentMoomType

1!8

OpenOffice.org 3.1 Developer's Guide April !!"

7um,er 4orm%ts

com.sun.star.te t.FiewSettings:MoomFa lue

%ort C defines the 9oom 5alue to use8 the 5alue is gi5en as percentage. Falid only if the property @oom!ype is set to com.sun.star.5iew.DocumentMoomType:3HIF/ LB$.

0n Star+ffice #.) and +pen+ffice.org !.) you can only influence the 9oom factor by setting the @oom!ype to ;U<VALU( and ad:usting @oomValue e plicitly. The other 9oom types ha5e no effect.

e$t)ie.Cursor
The te t controller has a 5isible cursor that is used in the 7B0. 7et the com.sun.star.te t.Te tFiewCursor by calling get!e)tViewCur or() at the com.sun.star.te t.ATe tFiewCursorSupplier interface of the current te t document controller. 0t supports the following cursor capabilities that depend on ha5ing the necessary information about the current layout state8 therefore it is not supported by the model cursor.
com' un' tar'te)t'XPageCur or .oolean$&ump!oFir tPage()$.oolean$&ump!oLa tPage()$.oolean$&ump!oPage($6in7$ long$page:o)$long$getPage()$.oolean$&ump!o:e)tPage()$.oolean$ &ump!oPreviou Page()$.oolean$&ump!o(nd04Page()$.oolean$&ump!oStart04Page() com' un' tar'view'XScreenCur or .oolean$ creenDown()$.oolean$ creenUp() com' un' tar'view'XLineCur or .oolean$goDown($6in7$long$line /$6in7$.oolean$.()pand)$.oolean$goUp($6in7$long$ line /$6in7$.oolean$.()pand)$.oolean$i AtStart04Line()$.oolean$i At(nd04Line()$ void$goto(nd04Line($6in7$.oolean$.()pand)$void$gotoStart04Line($6in7$.oolean$ .()pand) com' un' tar'view'XViewCur or .oolean$goLe4t($6in7$long$c%aracter /$6in7$.oolean$.()pand)$.oolean$ goRig%t($6in7$long$c%aracter /$6in7$.oolean$.()pand)$.oolean$goDown($6in7$long$ c%aracter /$6in7$.oolean$.()pand)$.oolean$goUp($6in7$long$c%aracter /$6in7$ .oolean$.()pand)

/dditionally the interface com.sun.star.beans.APropertySet is supported. Currently8 the 5iew cursor does not ha5e the capabilities as the document cursor does. Therefore8 it is necessary to create a document cursor to ha5e access to the full te t cursor functionality. The method create!e)tCur or;yRange() is used:
X!e)t$)Cr r!e)t$+$)ViewCur or'get!e)t(),$""$Create$a$!e)tCur or$over$t%e$view$ cur orS $content $X!e)tCur or$)DocumentCur or$+$ )View!e)t'create!e)tCur or;yRange()ViewCur or'getStart()),$ )DocumentCur or'gotoRange()ViewCur or'get(nd()/$true),

#$%pter 7 Text Documents

1!"

Anda mungkin juga menyukai