Hi!

Thanks for all your help. Now I was able to add the second textfield below the 
other one. I think the order in which the textfields are created and added is 
important that it work.

Here is my code:


call bsf.import "com.sun.star.style.BreakType", "pageBreakType" -- for enum you 
need a class import
call bsf.import "com.sun.star.text.ControlCharacter", "ctlChar"

oDesktop         = UNO.createDesktop()
xComponentLoader = oDesktop~XDesktop~XComponentLoader

url = "private:factory/swriter"
xWriterComponent = xComponentLoader~loadComponentFromURL(url, "_blank", 0, 
.UNO~noProps)

xDocumentFactory = xWriterComponent~XMultiServiceFactory
xTextDocument    = xWriterComponent~XTextDocument
xDocText         = xTextDocument~getText
xDocTextCursor   = xDocText~createTextCursorByRange(xDocText~getStart)
xDocFactory      = xTextDocument~XMultiServiceFactory

/* create a RectangleShape */
Shape = xDocFactory~createInstance("com.sun.star.drawing.RectangleShape")
xShape = Shape~xShape

size = .bsf~new("com.sun.star.awt.Size", 8000 /*width*/, 8000 /*height*/)
xShape~setSize(size)

xShapeProps=xShape~xPropertySet
at_para=bsf.getConstant("com.sun.star.text.TextContentAnchorType","AT_PARAGRAPH")
xShapeProps~setPropertyValue("AnchorType", at_para)
xShapeProps~setPropertyValue("FillColor", box("int", "C0 C0 C0"x ~c2d))
 
-- create a text field at the document factory
xTextFieldProps=xDocFactory~createInstance("com.sun.star.text.TextField.URL")~XPropertySet

xTextFieldProps~setPropertyValue("Representation","OpenOffice.org API Project")
xTextFieldProps~setPropertyValue("TargetFrame", "_blank")
xTextFieldProps~setPropertyValue("URL", "http://api.openoffice.org";)

-- get the XTextContent of the shape and the field
xShapeTextContent=xShape~XTextContent
xFieldTextContent=xTextFieldProps~XTextContent

-- the shape is inserted at the DOCUMENT text
xDocText~insertTextContent(xDocTextCursor, xShapeTextContent, .false)

-- access the text inside the shape,
-- and create a text cursor
xShapeText       = xShape~XText
xShapeTextCursor = xShapeText~createTextCursor

-- insert the field at the SHAPE text
paraBreak=.CtlChar~paragraph_break     -- gets used multiple times in this 
routine
xShapeText~insertTextContent(xShapeTextCursor, xFieldTextContent, .false)
xShapeText~insertControlCharacter(xShapeTextCursor, .CtlChar~paragraph_break, 
.false)

xTextFieldProps=xDocFactory~createInstance("com.sun.star.text.TextField.URL")~XPropertySet
xTextFieldProps~setPropertyValue("Representation", "Another URL text field")
xTextFieldProps~setPropertyValue("TargetFrame", "_blank")
xTextFieldProps~setPropertyValue("URL", "http://api.openoffice.org";)


xFieldTextContent=xTextFieldProps~XTextContent
xShapeText~insertTextContent(xShapeTextCursor, xFieldTextContent, .false)

::requires UNO.cls



Regards 
Nicole


-------- Original-Nachricht --------
> Datum: Sat, 06 Sep 2008 07:18:47 -0300
> Von: Ariel Constenla-Haile <[EMAIL PROTECTED]>
> An: [email protected]
> Betreff: Re: [api-dev] add more textfields to one shape

> Hi Nicole,
> 
> Nicole Scholz escribió:
> > Hi Marc!
> > 
> > Thanks for your answer. I tried to insert a paragraph break and a line
> break but the textfield is inserted right to the other one and not below.
> Perhaps there is another possibility to change the position of the textfield.
> > 
> > Here is my code:
> > 
> > /* create a RectangleShape */
> > Shape =
> xDocFactory~createInstance("com.sun.star.drawing.RectangleShape")
> > xShape = Shape~xShape
> > 
> > size = .bsf~new("com.sun.star.awt.Size", 8000 /*width*/, 5000
> /*height*/)
> > xShape~setSize(size)
> > 
> > xShapeProps=xShape~xPropertySet
> >
> at_para=bsf.getConstant("com.sun.star.text.TextContentAnchorType","AT_PARAGRAPH")
> > xShapeProps~setPropertyValue("AnchorType", at_para)
> > xShapeProps~setPropertyValue("FillColor", box("int", "C0 C0 C0"x ~c2d))
> >  
> > -- create a text field at the document factory
> >
> xTextFieldProps=xDocFactory~createInstance("com.sun.star.text.TextField.URL")~XPropertySet
> > linebreak = "0a"x
> > text = "OpenOffice.org API Project"
> > xTextFieldProps~setPropertyValue("Representation",text  "0a0909"x)
> > xTextFieldProps~setPropertyValue("TargetFrame", "_blank")
> > xTextFieldProps~setPropertyValue("URL", "http://api.openoffice.org";)
> > 
> >
> xTextFieldProps1=xDocFactory~createInstance("com.sun.star.text.TextField.URL")~XPropertySet
> > xTextFieldProps1~setPropertyValue("Representation", "GMX")
> > xTextFieldProps1~setPropertyValue("TargetFrame", "_blank")
> > xTextFieldProps1~setPropertyValue("URL", "http://www.gmx.at";)
> > 
> > 
> > -- get the XTextContent of the shape and the field
> > xShapeTextContent=xShape~XTextContent
> > xFieldTextContent=xTextFieldProps~XTextContent
> > xFieldTextContent1=xTextFieldProps1~XTextContent
> > 
> > -- the shape is inserted at the DOCUMENT text
> > xDocText~insertTextContent(xDocTextCursor, xShapeTextContent, .false)
> > 
> > -- access the text inside the shape,
> > -- and create a text cursor
> > xShapeText       = xShape~XText
> > xShapeTextCursor = xShapeText~createTextCursor
> > 
> > call bsf.import "com.sun.star.text.ControlCharacter", "ctlChar"
> > 
> > -- insert the field at the SHAPE text
> > paraBreak=.CtlChar~paragraph_break     -- gets used multiple times in
> this routine
> > xShapeText~insertTextContent(xShapeTextCursor, xFieldTextContent,
> .false)
> > xShapeText~insertControlCharacter(xShapeTextCursor~getEnd,
> .CtlChar~paragraph_break, .false)
> > xShapeText~insertTextContent(xShapeTextCursor, xFieldTextContent1,
> .false)
> 
> the code I attach looks quite like yours. In Java the only problem is that
> 
> xShapeText.insertControlCharacter(xShapeTextCursor.getEnd(),
>                      ControlCharacter.PARAGRAPH_BREAK, false);
> 
> does not insert the paragraph break, but any way the fields are inserted 
> in the right order, one after the other.
> See if translating line by line the Java code to ooRex solves the problem.
> 
> Regards
> Ariel.
> 
> -- 
> Ariel Constenla-Haile
> La Plata, Argentina
> 
> [EMAIL PROTECTED]
> http://www.ArielConstenlaHaile.com.ar/ooo/
> 
> 
> 
> "Aus der Kriegsschule des Lebens
>               - Was mich nicht umbringt,
>       macht mich härter."
>               Nietzsche Götzendämmerung, Sprüche und Pfeile, 8.

-- 
Der GMX SmartSurfer hilft bis zu 70% Ihrer Onlinekosten zu sparen! 
Ideal für Modem und ISDN: http://www.gmx.net/de/go/smartsurfer

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to