Online: Copy hyperlink location. / Core side.

Payload format is added to LOK_CALLBACK_CLIPBOARD_CHANGED.
Clipboard changed event is not fired when "copy hyperlink location" command is issued.
So i added a call to LOK_CALLBACK_CLIPBOARD_CHANGED inside TextDataObject::CopyStringTo function.

Change-Id: I8157572288da88b5522662e13abe151ef8548b34
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/103164
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Reviewed-by: Jan Holesovsky <kendy@collabora.com>
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/103872
Tested-by: Jenkins
diff --git a/include/LibreOfficeKit/LibreOfficeKitEnums.h b/include/LibreOfficeKit/LibreOfficeKitEnums.h
index 750e64f..9a0eb01 100644
--- a/include/LibreOfficeKit/LibreOfficeKitEnums.h
+++ b/include/LibreOfficeKit/LibreOfficeKitEnums.h
@@ -644,10 +644,9 @@ typedef enum
     * Notification that the clipboard contents have changed.
     * Typically fired in response to copying to clipboard.
     *
     * The payload currently is empty and it's up to the
     * client to get the contents, if necessary. However,
     * in the future the contents might be included for
     * convenience.
     * Payload is optional. When payload is empty, Online gets string from selected text.
     * Payload format is JSON.
     * Example: { "mimeType": "string", "content": "some content" }
     */
    LOK_CALLBACK_CLIPBOARD_CHANGED = 38,

diff --git a/include/vcl/unohelp2.hxx b/include/vcl/unohelp2.hxx
index a954744..91c4ce6 100644
--- a/include/vcl/unohelp2.hxx
+++ b/include/vcl/unohelp2.hxx
@@ -25,6 +25,9 @@
#include <rtl/ustring.hxx>
#include <osl/mutex.hxx>
#include <vcl/dllapi.h>
#include <comphelper/lok.hxx>
#include <LibreOfficeKit/LibreOfficeKitEnums.h>
#include <boost/property_tree/json_parser.hpp>

namespace com::sun::star::datatransfer::clipboard {
    class XClipboard;
@@ -56,7 +59,8 @@ namespace vcl::unohelper {
        /// copies a given string to a given clipboard
        static  void    CopyStringTo(
            const OUString& rContent,
            const css::uno::Reference< css::datatransfer::clipboard::XClipboard >& rxClipboard
            const css::uno::Reference< css::datatransfer::clipboard::XClipboard >& rxClipboard,
            std::function<void (int, const char*)> *callback = nullptr
        );
    };

diff --git a/sc/source/ui/view/editsh.cxx b/sc/source/ui/view/editsh.cxx
index 9e8768f..83e4ada 100644
--- a/sc/source/ui/view/editsh.cxx
+++ b/sc/source/ui/view/editsh.cxx
@@ -641,7 +641,14 @@ void ScEditShell::Execute( SfxRequest& rReq )
                {
                    uno::Reference<datatransfer::clipboard::XClipboard> xClipboard
                        = pEditView->GetWindow()->GetClipboard();
                    vcl::unohelper::TextDataObject::CopyStringTo(pURLField->GetURL(), xClipboard);

                    if (comphelper::LibreOfficeKit::isActive())
                    {
                        std::function<void (int, const char*)> callback = [&] (int callbackType, const char* text) { rViewData.GetViewShell()->libreOfficeKitViewCallback(callbackType, text); } ;
                        vcl::unohelper::TextDataObject::CopyStringTo(pURLField->GetURL(), xClipboard, &callback);
                    }
                    else
                        vcl::unohelper::TextDataObject::CopyStringTo(pURLField->GetURL(), xClipboard, nullptr);
                }
            }
        break;
diff --git a/sd/source/ui/view/drviews2.cxx b/sd/source/ui/view/drviews2.cxx
index 8f511aa..f32acb5 100644
--- a/sd/source/ui/view/drviews2.cxx
+++ b/sd/source/ui/view/drviews2.cxx
@@ -2250,7 +2250,18 @@ void DrawViewShell::FuTemporary(SfxRequest& rReq)
                {
                    uno::Reference<datatransfer::clipboard::XClipboard> xClipboard
                        = pOutView->GetWindow()->GetClipboard();
                    vcl::unohelper::TextDataObject::CopyStringTo(pURLField->GetURL(), xClipboard);

                    if (comphelper::LibreOfficeKit::isActive())
                    {
                        std::function<void (int, const char*)> callback = [&] (int callbackType, const char* text)
                        {
                            SfxViewFrame* pFrame = GetViewFrame();
                            pFrame->GetViewShell()->libreOfficeKitViewCallback(callbackType, text);
                        };
                        vcl::unohelper::TextDataObject::CopyStringTo(pURLField->GetURL(), xClipboard, &callback);
                    }
                    else
                        vcl::unohelper::TextDataObject::CopyStringTo(pURLField->GetURL(), xClipboard);
                }
            }

diff --git a/sw/source/uibase/shells/textsh1.cxx b/sw/source/uibase/shells/textsh1.cxx
index 8944d9c..14844e1 100644
--- a/sw/source/uibase/shells/textsh1.cxx
+++ b/sw/source/uibase/shells/textsh1.cxx
@@ -100,6 +100,7 @@
#include <bookmrk.hxx>
#include <linguistic/misc.hxx>
#include <editeng/splwrap.hxx>
#include <LibreOfficeKit/LibreOfficeKitEnums.h>

using namespace ::com::sun::star;
using namespace com::sun::star::beans;
@@ -1349,10 +1350,16 @@ void SwTextShell::Execute(SfxRequest &rReq)
            const SwFormatINetFormat& rINetFormat = dynamic_cast<const SwFormatINetFormat&>( aSet.Get(RES_TXTATR_INETFMT) );
            if( nSlot == SID_COPY_HYPERLINK_LOCATION )
            {
                OUString hyperlinkLocation = rINetFormat.GetValue();
                ::uno::Reference< datatransfer::clipboard::XClipboard > xClipboard = GetView().GetEditWin().GetClipboard();
                vcl::unohelper::TextDataObject::CopyStringTo(
                        rINetFormat.GetValue(),
                        xClipboard );

                if (comphelper::LibreOfficeKit::isActive())
                {
                    std::function<void (int, const char*)> callback = [&] (int callbackType, const char* text) { GetView().libreOfficeKitViewCallback(callbackType, text); } ;
                    vcl::unohelper::TextDataObject::CopyStringTo(hyperlinkLocation, xClipboard, &callback );
                }
                else
                    vcl::unohelper::TextDataObject::CopyStringTo(hyperlinkLocation, xClipboard, nullptr );
            }
            else
                rWrtSh.ClickToINetAttr(rINetFormat);
diff --git a/vcl/source/app/unohelp2.cxx b/vcl/source/app/unohelp2.cxx
index 9005467..8e33aee 100644
--- a/vcl/source/app/unohelp2.cxx
+++ b/vcl/source/app/unohelp2.cxx
@@ -40,7 +40,8 @@ namespace vcl::unohelper {
    }

    void TextDataObject::CopyStringTo( const OUString& rContent,
        const uno::Reference< datatransfer::clipboard::XClipboard >& rxClipboard )
        const uno::Reference< datatransfer::clipboard::XClipboard >& rxClipboard,
        std::function<void (int, const char*)> *callback)
    {
        SAL_WARN_IF( !rxClipboard.is(), "vcl", "TextDataObject::CopyStringTo: invalid clipboard!" );
        if ( !rxClipboard.is() )
@@ -56,6 +57,16 @@ namespace vcl::unohelper {
            uno::Reference< datatransfer::clipboard::XFlushableClipboard > xFlushableClipboard( rxClipboard, uno::UNO_QUERY );
            if( xFlushableClipboard.is() )
                xFlushableClipboard->flushClipboard();

            if (callback != nullptr && comphelper::LibreOfficeKit::isActive())
            {
                boost::property_tree::ptree aTree;
                aTree.put("content", rContent);
                aTree.put("mimeType", "text/plain");
                std::stringstream aStream;
                boost::property_tree::write_json(aStream, aTree);
                (*callback)(LOK_CALLBACK_CLIPBOARD_CHANGED, aStream.str().c_str());
            }
        }
        catch( const uno::Exception& )
        {