https://bugs.documentfoundation.org/show_bug.cgi?id=125485

Neil Roberts <[email protected]> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |[email protected]

--- Comment #12 from Neil Roberts <[email protected]> ---
It looks like there’s no code to handle the URL text field in a writer document
and instead it only works for editeng. For example if you create a new Draw
document with some shapes then this macro works to add a link to all of the
shapes in the first page:

    model = XSCRIPTCONTEXT.getDocument()
    page = model.getDrawPages().getByIndex(0)

    for i in range(page.getCount()):
        shape = page.getByIndex(i)
        url = model.createInstance("com.sun.star.text.TextField.URL")
        url.Representation = "LibreOffice website"
        url.URL = "https://libreoffice.org";
        curs = shape.createTextCursor()
        shape.insertTextContent(curs, url, False)

In a Writer document it looks like links are instead handled by setting the
HyperLinkURL property on the text. For example you can use this code snippet to
add a link to the beginning of the document:

    model = XSCRIPTCONTEXT.getDocument()
    text = model.Text
    curs = text.createTextCursor()
    curs.setString("LibreOffice Website")
    curs.setPropertyValue("HyperLinkURL", "https://libreoffice.org";)

It might be nice to make Writer handle TextField.URL and convert it to some
text with the right properties. I think we would need to add an entry for it in
the aProvNamesId table in unocoll.cxx. Without that it looks like
createInstance falls back to creating a text field for editeng, but then it
throws an exception when you try to use it with insertTextContent because that
expects the cursor to be an SvxUnoTextRange but it is an SwXTextRange. I think
that explains the diverging code paths taken in comment #1.

-- 
You are receiving this mail because:
You are the assignee for the bug.

Reply via email to