Get the paragraph just before an image in Basic

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Get the paragraph just before an image in Basic

Guillon Benoit
Hello,

I would like to retrieve the paragraph just before the selected image in
Writer. My goal is to insert a frame after this paragraph, and anchor
the image to this frame, (exactly what appends when a caption is added
to an image)

My code is:

oSelectedObject = ThisComponent.getCurrentSelection()
    ' if the selected object is an image
    if
oSelectedObject.supportsService("com.sun.star.text.TextGraphicObject") Then

*        *' there is already a frame around the image
        if
oSelectedObject.getAnchor.Text.supportsService("com.sun.star.text.TextFrame")
then
             ' do something
         else
             ' no frame, I have to create a new frame just before the
image and anchor the image to it
             oViewCursor =
ThisComponent.getCurrentController().getViewCursor()
             oViewCursor.goUp(1, False)

             => it raises a RuntimeException , with the message "no text
selection"

When I create a new TextCursor, like this:

oCursor = oSelectedObject.getAnchor().Text.createTextCursor()

The cursor is positioned at the document's start and I don't know how I
can move this cursor to the paragraph before the selected image.

Does somebody have an idea ?

Thanks

Benoit.


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Get the paragraph just before an image in Basic

Laurent Godard-3
Hi Benoit

> When I create a new TextCursor, like this:
>
> oCursor = oSelectedObject.getAnchor().Text.createTextCursor()
>
> The cursor is positioned at the document's start and I don't know how I
> can move this cursor to the paragraph before the selected image.
>
> Does somebody have an idea ?

did you try a createTextCursorByRange(oSelectedObject.getAnchor()) ?
or something approaching

Laurent


--
Laurent Godard <[hidden email]> - Ingénierie OpenOffice.org
Indesko >> http://www.indesko.com
Nuxeo CPS >> http://www.nuxeo.com - http://www.cps-project.org
Livre "Programmation OpenOffice.org", Eyrolles 2004

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Get the paragraph just before an image in Basic

Guillon Benoit
Yes ! Thank you Laurent, the new cursor is located just after the image.
Thus, I can use "gotoPreviousParagraph" to go to the paragraph just
before the image.

Thanks again

Benoit.

Laurent Godard wrote:

> Hi Benoit
>
>> When I create a new TextCursor, like this:
>>
>> oCursor = oSelectedObject.getAnchor().Text.createTextCursor()
>>
>> The cursor is positioned at the document's start and I don't know how
>> I can move this cursor to the paragraph before the selected image.
>>
>> Does somebody have an idea ?
>
>
> did you try a createTextCursorByRange(oSelectedObject.getAnchor()) ?
> or something approaching
>
> Laurent
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Get the paragraph just before an image in Basic

Laurent Godard-3
Bonjour Benoit

> Yes ! Thank you Laurent, the new cursor is located just after the image.
> Thus, I can use "gotoPreviousParagraph" to go to the paragraph just
> before the image.
>

Bien/Good !!

> Thanks again
>

de rien/You're welcome

Laurent

--
Laurent Godard <[hidden email]> - Ingénierie OpenOffice.org
Indesko >> http://www.indesko.com
Nuxeo CPS >> http://www.nuxeo.com - http://www.cps-project.org
Livre "Programmation OpenOffice.org", Eyrolles 2004

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]