sc/sdi/cellsh.sdi             |    1 +
 sc/source/ui/view/cellsh.cxx  |    1 +
 sc/source/ui/view/cellsh1.cxx |   24 ++++++++++++++++++++++++
 sc/source/ui/view/gridwin.cxx |   11 +++++++----
 svx/sdi/svx.sdi               |    1 +
 5 files changed, 34 insertions(+), 4 deletions(-)

New commits:
commit 0533474cb0188aede59841bf4d547106949f2760
Author:     Jaume Pujantell <jaume.pujant...@collabora.com>
AuthorDate: Tue Jun 25 09:49:46 2024 +0200
Commit:     Miklos Vajna <vmik...@collabora.com>
CommitDate: Fri Jun 28 11:22:46 2024 +0200

    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 <jenkinscollaboraoff...@gmail.com>
    Reviewed-by: Miklos Vajna <vmik...@collabora.com>

diff --git a/sc/sdi/cellsh.sdi b/sc/sdi/cellsh.sdi
index 7370d142607e..9aed584061a3 100644
--- a/sc/sdi/cellsh.sdi
+++ b/sc/sdi/cellsh.sdi
@@ -182,6 +182,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; ]
diff --git a/sc/source/ui/view/cellsh.cxx b/sc/source/ui/view/cellsh.cxx
index 7694061e6093..5b9f0de8e68d 100644
--- a/sc/source/ui/view/cellsh.cxx
+++ b/sc/source/ui/view/cellsh.cxx
@@ -295,6 +295,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
diff --git a/sc/source/ui/view/cellsh1.cxx b/sc/source/ui/view/cellsh1.cxx
index 3a44db570119..b3d3d491166b 100644
--- a/sc/source/ui/view/cellsh1.cxx
+++ b/sc/source/ui/view/cellsh1.cxx
@@ -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>
@@ -3202,6 +3203,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;
diff --git a/sc/source/ui/view/gridwin.cxx b/sc/source/ui/view/gridwin.cxx
index 3cf47209647c..fc368a7cd8c3 100644
--- a/sc/source/ui/view/gridwin.cxx
+++ b/sc/source/ui/view/gridwin.cxx
@@ -2492,7 +2492,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.getStr());
                 } else
                     ScGlobal::OpenURL(aUrl, aTarget);
@@ -2621,9 +2623,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.getStr());
         }
     }
diff --git a/svx/sdi/svx.sdi b/svx/sdi/svx.sdi
index 2614660495e7..9062a5351582 100644
--- a/svx/sdi/svx.sdi
+++ b/svx/sdi/svx.sdi
@@ -12411,6 +12411,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,

Reply via email to