lok calc: allow copy hyperlink outside of edit mode

Right now .uno:CopyHyperlinkLocation only works on edit mode or
inside a draw object, but LOK_CALLBACK_HYPERLINK_CLICKED is
dispatched outside of edit mode and the copy command from
the pop-up is ignored.

Since there is no text cursor, the position of the hyperlink is
needed to discriminate the correct field, since there could be
multiple hyperlink fields inside the same cell.

Change-Id: If545cf56e631adcdb914c4e799a309bc8bd0422f
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/169507
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
(cherry picked from commit 0533474cb0188aede59841bf4d547106949f2760)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/169729
Tested-by: Jenkins
Reviewed-by: Jaume Pujantell <jaume.pujantell@collabora.com>
This commit is contained in:
Jaume Pujantell 2024-06-25 09:49:46 +02:00
parent 83a8d5a275
commit b32aa67f17
5 changed files with 34 additions and 4 deletions

View file

@ -183,6 +183,7 @@ interface CellSelection
SID_PASTE_TEXTIMPORT_DIALOG [ ExecMethod = ExecuteEdit; StateMethod = GetClipState; ]
SID_CLIPBOARD_FORMAT_ITEMS [ ExecMethod = ExecuteEdit; StateMethod = GetClipState; ]
SID_EXTERNAL_SOURCE [ ExecMethod = ExecuteEdit; StateMethod = GetBlockState; ]
SID_COPY_HYPERLINK_LOCATION [ ExecMethod = ExecuteEdit; StateMethod = GetBlockState; ]
FID_MERGE_ON [ ExecMethod = Execute; StateMethod = GetState; ]
FID_MERGE_OFF [ ExecMethod = Execute; StateMethod = GetState; ]
FID_MERGE_TOGGLE [ ExecMethod = Execute; StateMethod = GetState; ]

View file

@ -294,6 +294,7 @@ void ScCellShell::GetBlockState( SfxItemSet& rSet )
break;
case SID_COPY: // copy
case SID_COPY_HYPERLINK_LOCATION:
// not editable because of matrix only? Do not damage matrix
//! is not called, when protected AND matrix, we will have
//! to live with this... is caught in Copy-Routine, otherwise

View file

@ -35,6 +35,7 @@
#include <sfx2/dispatch.hxx>
#include <sfx2/request.hxx>
#include <vcl/commandinfoprovider.hxx>
#include <vcl/unohelp2.hxx>
#include <vcl/svapp.hxx>
#include <vcl/weld.hxx>
#include <svx/svxdlg.hxx>
@ -3212,6 +3213,29 @@ void ScCellShell::ExecuteEdit( SfxRequest& rReq )
}
break;
case SID_COPY_HYPERLINK_LOCATION:
{
ScViewData& rData = GetViewData();
ScGridWindow* pWindow = rData.GetActiveWin();
const SfxInt32Item* pPosX = rReq.GetArg<SfxInt32Item>(FN_PARAM_1);
const SfxInt32Item* pPosY = rReq.GetArg<SfxInt32Item>(FN_PARAM_2);
if (pWindow && pPosX && pPosY)
{
const Point aPoint(pPosX->GetValue() * rData.GetPPTX(),
pPosY->GetValue() * rData.GetPPTY());
OUString aName, aUrl;
if (pWindow->GetEditUrl(aPoint, &aName, &aUrl))
{
uno::Reference<datatransfer::clipboard::XClipboard> xClipboard
= pWindow->GetClipboard();
vcl::unohelper::TextDataObject::CopyStringTo(aUrl, xClipboard,
rData.GetViewShell());
rReq.Done();
}
}
}
break;
default:
OSL_FAIL("incorrect slot in ExecuteEdit");
break;

View file

@ -2616,7 +2616,9 @@ void ScGridWindow::MouseButtonUp( const MouseEvent& rMEvt )
OString aCursor = pViewShell->GetViewData().describeCellCursorAt(nPosX, nPosY);
double fPPTX = pViewShell->GetViewData().GetPPTX();
int mouseX = aPos.X() / fPPTX;
OString aMsg(aUrl.toUtf8() + " coordinates: " + aCursor + ", " + OString::number(mouseX));
int mouseY = aPos.Y() / fPPTX;
OString aMsg(aUrl.toUtf8() + " coordinates: " + aCursor + ", "
+ OString::number(mouseX) + ", " + OString::number(mouseY));
pViewShell->libreOfficeKitViewCallback(LOK_CALLBACK_HYPERLINK_CLICKED, aMsg);
} else
ScGlobal::OpenURL(aUrl, aTarget);
@ -2741,9 +2743,10 @@ void ScGridWindow::MouseButtonUp( const MouseEvent& rMEvt )
if (pViewShell && nPosX == m_nDownPosX && nPosY == m_nDownPosY
&& GetEditUrl(aPos, &aName, &aUrl, &aTarget))
{
OString aMsg(aUrl.toUtf8() + " coordinates: " +
pViewShell->GetViewData().describeCellCursorAt(nPosX, nPosY) + ", " +
OString::number(aPos.X() / pViewShell->GetViewData().GetPPTX()));
OString aMsg(aUrl.toUtf8() + " coordinates: "
+ pViewShell->GetViewData().describeCellCursorAt(nPosX, nPosY) + ", "
+ OString::number(aPos.X() / pViewShell->GetViewData().GetPPTX()) + ", "
+ OString::number(aPos.Y() / pViewShell->GetViewData().GetPPTY()));
pViewShell->libreOfficeKitViewCallback(LOK_CALLBACK_HYPERLINK_CLICKED, aMsg);
}
}

View file

@ -12476,6 +12476,7 @@ SfxVoidItem RemoveHyperlink SID_REMOVE_HYPERLINK
]
SfxVoidItem CopyHyperlinkLocation SID_COPY_HYPERLINK_LOCATION
(SfxInt32Item PositionX FN_PARAM_1, SfxInt32Item PositionY FN_PARAM_2)
[
AutoUpdate = FALSE,
FastCall = FALSE,