Hello Nicole,

Nicole Scholz escribió:
Hi!

I tried to add a hyperlink to a text within a rectangle. Usually a hyperlink is set on the textproperties with setpropertyvalue and then the hyperlink for example: xTextProps~setPropertyValue("HyperLinkURL", “www.google.at”)

Now I would like to add the hyperlink to a shape. I tried it the same way with 
the xText within the shape.

xShapeText = Shape~xText
xShapeTextCursor = xShapeText~createTextCursor
props = xShapeTextCursor~xPropertySet
props~setPropertyValue("HyperLinkURL", “www.google.at”)

But this does not work. I get the exception that the method is not found. Can 
someone give me a hint why I get this error and how I can get the hyperlink 
into the shape?

as you have realized, an hyperlink within a shape can not be set as a
character property of the shape's text.
You will also realize how to do this if you try in the graphical user
interface:

* open a new OOo Draw document
* draw any shape, let's say an ellipse
* double-click the shape in order to insert text inside it
* type any URL, for example www.google.at
* as soon as you press the space key, this text truns into an URL *field*

So the key to the answer is: an hyperlink within a shape is inserted as
an URL text field.

Sure you have noticed that in Calc/Draw/Impress, when you select the
menu "Insert" - "Hyperlink", an URL text field is inserted. In
Draw/Impress case, the field is inside a text shape.

In *theory*, as an API client, you can achieve this doing the following:

* instantiate a shape at the doc. factory
* add the shape to a draw page
* instantiate a com.sun.star.text.texfield.URL
[http://api.openoffice.org/docs/common/ref/com/sun/star/text/textfield/URL.html]
at the doc. factory
* get the shape's css.text.XText and insert the field as a text content

In practice, I see the following issues (look at the macros in
http://www.ArielConstenlaHaile.com.ar/ooo/temp/field_inside_shape.odt):

* Writer:
     *  com.sun.star.text.texfield.URL does not figure among the avaible
        services at the doc. factory, nor can be instantiated by this
        name. You have to use "com.sun.star.text.TextField.URL"
     *  the document view does not know how to handle them, that is:
            * the pointer does not change from an ARROW to a REFHAND
              when the mouse is over the field
            * the URL is never dispatched when clicking the text field
            * if you double-click the shape to edit its text, then the
              field will look like an hyperlink (pointer changes to
              REFHAND when mouse over), but the URL is not dispatched

* Calc
    * same issue with the service name, in fact all text field services
      names are in uppercase, while the name of the module is
      "textfield", NOT "TextField":
                com.sun.star.text.TextField.URL
                com.sun.star.text.TextField.PageNumber
                com.sun.star.text.TextField.PageCount
                com.sun.star.text.TextField.Date
                com.sun.star.text.TextField.Time
                com.sun.star.text.TextField.DocumentTitle
                com.sun.star.text.TextField.FileName
                com.sun.star.text.TextField.SheetName
    * you can instantiate a com.sun.star.text.TextField.URL at the
      doc.'s factory, but if you try to insert it as text content at a
      shape's XText, then you get an error. Looks like you can insert
      this field only inside a cell, not a shape
      [notice that in the macro I find a way to fool Calc, but that's
      just a trick and not how one must really proceed]
    * if you try in the GUI (drawing a shape, typying an URL inside it,
      etc), the field works as expected; so it's an API issue

* Draw/Impress
    * here the desolation is bigger: there are no text field services
      available at the doc.'s service factory, nor can they be
      instantiated.

Sometimes I have the feeling that some OOo developers don't care much
about us API clients.

Concerning the Draw/Impress issue, *just* adding the service names in
the css.lang.XMultiServiceFactory implementation in
SdXImpressDocument::createInstance() (and
SdXImpressDocument::getAvailableServiceNames() for the sake of
completness) in sd/source/ui/unoidl/unomodel.cxx solves the issue:

//*****************************************************************


uno::Reference< uno::XInterface > SAL_CALL
SdXImpressDocument::createInstance( const OUString& aServiceSpecifier )
        throw(uno::Exception, uno::RuntimeException)
{
        OGuard aGuard( Application::GetSolarMutex() );

        if( NULL == mpDoc )
                throw lang::DisposedException();

        //...

//-----------------------------------------------------------------------------

    // corret case for textfield module
        if( ( 0 == aServiceSpecifier.reverseCompareToAsciiL(
RTL_CONSTASCII_STRINGPARAM("com.sun.star.text.TextField.DateTime") ) ) ||
        ( 0 == aServiceSpecifier.reverseCompareToAsciiL(
RTL_CONSTASCII_STRINGPARAM("com.sun.star.text.textfield.DateTime") ) ) )
        {
                return (::cppu::OWeakObject * )new SvxUnoTextField( 
ID_EXT_DATEFIELD );
        }

    // add URL field
    if( 0 == aServiceSpecifier.reverseCompareToAsciiL(
RTL_CONSTASCII_STRINGPARAM("com.sun.star.text.textfield.URL") ) )
        {
                return (::cppu::OWeakObject * )new SvxUnoTextField( ID_URLFIELD 
);
        }

    // add file field
    if( 0 == aServiceSpecifier.reverseCompareToAsciiL(
RTL_CONSTASCII_STRINGPARAM("com.sun.star.text.textfield.FileName") ) )
        {
                return (::cppu::OWeakObject * )new SvxUnoTextField( 
ID_EXT_FILEFIELD );
        }

    // add author field
    if( 0 == aServiceSpecifier.reverseCompareToAsciiL(
RTL_CONSTASCII_STRINGPARAM("com.sun.star.text.textfield.Author") ) )
        {
                return (::cppu::OWeakObject * )new SvxUnoTextField( 
ID_AUTHORFIELD );
        }

    // add page number field
    if( 0 == aServiceSpecifier.reverseCompareToAsciiL(
RTL_CONSTASCII_STRINGPARAM("com.sun.star.text.textfield.PageNumber") ) )
        {
                return (::cppu::OWeakObject * )new SvxUnoTextField( 
ID_PAGEFIELD );
        }

//-----------------------------------------------------------------------------

        //...
}


//*******************************************************************

uno::Sequence< OUString > SAL_CALL
SdXImpressDocument::getAvailableServiceNames()
        throw(uno::RuntimeException)
{
        OGuard aGuard( Application::GetSolarMutex() );

        if( NULL == mpDoc )
                throw lang::DisposedException();

        const uno::Sequence< OUString > aSNS_ORG(
SvxFmMSFactory::getAvailableServiceNames() );

        uno::Sequence< OUString > aSNS( mbImpressDoc ? (40) : (25) );

        sal_uInt16 i(0);

        //...

//-----------------------------------------------------------------------------

    // text fields
        aSNS[i++] = OUString(
RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.TextField.DateTime"));
    aSNS[i++] = OUString(
RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.textfield.DateTime"));
    aSNS[i++] = OUString(
RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.textfield.URL"));
    aSNS[i++] = OUString(
RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.textfield.FileName"));
    aSNS[i++] = OUString(
RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.textfield.Author"));
    aSNS[i++] = OUString(
RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.textfield.PageNumber"));

//-----------------------------------------------------------------------------

        //...
}

//****************************************************************

This works fine (I debug it) because the doc. model and the doc. view
*already* know how to handle this type of fields I added (one could of
course think about adding *more* text field types, but one should then
also modify the relevant parts of code).

I didn't have the time to look at the Writer/Calc sources, but at least
correcting the services names in Writer sounds easy.

Regards
Ariel.


--
Ariel Constenla-Haile
La Plata, Argentina

[EMAIL PROTECTED]
[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.





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

Reply via email to