sc/sdi/cellsh.sdi             |    2 +
 sc/source/ui/inc/gridwin.hxx  |    3 +-
 sc/source/ui/view/cellsh1.cxx |   54 ++++++++++++++++++++++++++++++++++++++++--
 sc/source/ui/view/gridwin.cxx |   14 +++++++---
 svx/sdi/svx.sdi               |    4 +--
 5 files changed, 67 insertions(+), 10 deletions(-)

New commits:
commit d54f049ee7ca9b4bb0452412196d2d709ef048d8
Author:     Jaume Pujantell <jaume.pujant...@collabora.com>
AuthorDate: Mon Jul 8 22:27:24 2024 +0200
Commit:     Miklos Vajna <vmik...@collabora.com>
CommitDate: Tue Jul 16 08:21:23 2024 +0200

    lok calc: allow remove and edit hypelink outside of edit mode
    
    Right now .uno:EditHyperlink and .uno:RemoveHyperlink only work on
    edit mode or inside a draw object, but LOK_CALLBACK_HYPERLINK_CLICKED
    is dispatched outside of edit mode.
    
    Change-Id: I26fb0c2e1ac438631ea71e33282e201f0a215d05
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/170171
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>
    Reviewed-by: Miklos Vajna <vmik...@collabora.com>
    (cherry picked from commit decb72c909b3f8296fb5c6b57b267c1079a865be)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/170478
    Tested-by: Jenkins

diff --git a/sc/sdi/cellsh.sdi b/sc/sdi/cellsh.sdi
index 233b12249917..44e87cd69119 100644
--- a/sc/sdi/cellsh.sdi
+++ b/sc/sdi/cellsh.sdi
@@ -184,6 +184,8 @@ interface CellSelection
     SID_CLIPBOARD_FORMAT_ITEMS  [ ExecMethod = ExecuteEdit; StateMethod = 
GetClipState; ]
     SID_EXTERNAL_SOURCE [ ExecMethod = ExecuteEdit; StateMethod = 
GetBlockState; ]
     SID_COPY_HYPERLINK_LOCATION [ ExecMethod = ExecuteEdit; StateMethod = 
GetBlockState; ]
+    SID_EDIT_HYPERLINK [ ExecMethod = ExecuteEdit; StateMethod = 
GetBlockState; ]
+    SID_REMOVE_HYPERLINK [ 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/inc/gridwin.hxx b/sc/source/ui/inc/gridwin.hxx
index 76cbe56f4c4e..f456712b616f 100644
--- a/sc/source/ui/inc/gridwin.hxx
+++ b/sc/source/ui/inc/gridwin.hxx
@@ -396,7 +396,8 @@ public:
     /// Get the cell selection, coordinates are in logic units.
     void GetCellSelection(std::vector<tools::Rectangle>& rLogicRects);
 
-    bool GetEditUrl( const Point& rPos, OUString* pName=nullptr, OUString* 
pUrl=nullptr, OUString* pTarget=nullptr );
+    bool GetEditUrl(const Point& rPos, OUString* pName = nullptr, OUString* 
pUrl = nullptr,
+                    OUString* pTarget = nullptr, SCCOL* pnCol= nullptr);
 
     virtual css::uno::Reference< css::accessibility::XAccessible > 
CreateAccessible() override;
 
diff --git a/sc/source/ui/view/cellsh1.cxx b/sc/source/ui/view/cellsh1.cxx
index 55b65bce1979..888ab37c9ed4 100644
--- a/sc/source/ui/view/cellsh1.cxx
+++ b/sc/source/ui/view/cellsh1.cxx
@@ -46,6 +46,7 @@
 #include <svx/hlnkitem.hxx>
 #include <basic/sbxcore.hxx>
 #include <editeng/editview.hxx>
+#include <editeng/urlfieldhelper.hxx>
 #include <svtools/cliplistener.hxx>
 
 #include <cellsh.hxx>
@@ -3223,8 +3224,8 @@ void ScCellShell::ExecuteEdit( SfxRequest& rReq )
                 {
                     const Point aPoint(pPosX->GetValue() * rData.GetPPTX(),
                                        pPosY->GetValue() * rData.GetPPTY());
-                    OUString aName, aUrl;
-                    if (pWindow->GetEditUrl(aPoint, &aName, &aUrl))
+                    OUString aUrl;
+                    if (pWindow->GetEditUrl(aPoint, nullptr, &aUrl))
                     {
                         uno::Reference<datatransfer::clipboard::XClipboard> 
xClipboard
                             = pWindow->GetClipboard();
@@ -3236,6 +3237,55 @@ void ScCellShell::ExecuteEdit( SfxRequest& rReq )
             }
             break;
 
+        case SID_EDIT_HYPERLINK:
+        case SID_REMOVE_HYPERLINK:
+            {
+                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());
+                    SCCOL nPosX;
+                    SCROW nPosY;
+                    ScSplitPos eWhich = rData.GetActivePart();
+                    rData.GetPosFromPixel(aPoint.X(), aPoint.Y(), eWhich, 
nPosX, nPosY);
+                    if (pWindow->GetEditUrl(aPoint, nullptr, nullptr, nullptr, 
&nPosX))
+                    {
+                        pTabViewShell->SetCursor(nPosX, nPosY);
+                        pTabViewShell->UpdateInputHandler();
+                        pScMod->SetInputMode(SC_INPUT_TABLE);
+                        ScInputHandler* pHdl = 
pScMod->GetInputHdl(pTabViewShell);
+                        if (rData.HasEditView(eWhich) && pHdl)
+                        {
+                            // Set text cursor where clicked
+                            EditView* pEditView = rData.GetEditView(eWhich);
+                            MouseEvent aEditEvt(aPoint, 1, 
MouseEventModifiers::SYNTHETIC,
+                                                MOUSE_LEFT, 0);
+                            pEditView->MouseButtonDown(aEditEvt);
+                            pEditView->MouseButtonUp(aEditEvt);
+                            if (nSlot == SID_REMOVE_HYPERLINK)
+                            {
+                                pHdl->DataChanging();
+                                URLFieldHelper::RemoveURLField(*pEditView);
+                                pHdl->DataChanged();
+                                pHdl->EnterHandler();
+                            }
+                            else
+                            {
+                                pEditView->SelectFieldAtCursor();
+                                
rData.GetViewShell()->GetViewFrame().GetDispatcher()->Execute(
+                                    SID_HYPERLINK_DIALOG);
+                            }
+                            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 48d9bddbce4e..18ce21d2004a 100644
--- a/sc/source/ui/view/gridwin.cxx
+++ b/sc/source/ui/view/gridwin.cxx
@@ -2593,7 +2593,8 @@ void ScGridWindow::MouseButtonUp( const MouseEvent& rMEvt 
)
         //  Only execute on ButtonUp, if ButtonDown also was done on a URL
 
         OUString aName, aUrl, aTarget;
-        if ( GetEditUrl( rMEvt.GetPosPixel(), &aName, &aUrl, &aTarget ) )
+        SCCOL nUrlCellX;
+        if (GetEditUrl(rMEvt.GetPosPixel(), &aName, &aUrl, &aTarget, 
&nUrlCellX))
         {
             nMouseStatus = SC_GM_NONE;              // Ignore double-click
             bool isTiledRendering = comphelper::LibreOfficeKit::isActive();
@@ -2613,7 +2614,8 @@ void ScGridWindow::MouseButtonUp( const MouseEvent& rMEvt 
)
                 {
                     aPos = rMEvt.GetPosPixel();
                     mrViewData.GetPosFromPixel( aPos.X(), aPos.Y(), eWhich, 
nPosX, nPosY );
-                    OString aCursor = 
pViewShell->GetViewData().describeCellCursorAt(nPosX, nPosY);
+                    OString aCursor
+                        = 
pViewShell->GetViewData().describeCellCursorAt(nUrlCellX, nPosY);
                     double fPPTX = pViewShell->GetViewData().GetPPTX();
                     int mouseX = aPos.X() / fPPTX;
                     int mouseY = aPos.Y() / fPPTX;
@@ -2741,7 +2743,7 @@ void ScGridWindow::MouseButtonUp( const MouseEvent& rMEvt 
)
         OUString aName, aUrl, aTarget;
         ScTabViewShell* pViewShell = mrViewData.GetViewShell();
         if (pViewShell && nPosX == m_nDownPosX && nPosY == m_nDownPosY
-            && GetEditUrl(aPos, &aName, &aUrl, &aTarget))
+            && GetEditUrl(aPos, &aName, &aUrl, &aTarget, &nPosX))
         {
             OString aMsg(aUrl.toUtf8() + " coordinates: "
                          + 
pViewShell->GetViewData().describeCellCursorAt(nPosX, nPosY) + ", "
@@ -5886,8 +5888,8 @@ std::vector<UrlData> ScGridWindow::GetEditUrls(const 
ScAddress& rSelectedCell)
     return vUrls;
 }
 
-bool ScGridWindow::GetEditUrl( const Point& rPos,
-                               OUString* pName, OUString* pUrl, OUString* 
pTarget )
+bool ScGridWindow::GetEditUrl(const Point& rPos, OUString* pName, OUString* 
pUrl, OUString* pTarget,
+                              SCCOL* pnCol)
 {
     ScTabViewShell* pViewSh = mrViewData.GetViewShell();
     ScInputHandler* pInputHdl = nullptr;
@@ -5910,6 +5912,8 @@ bool ScGridWindow::GetEditUrl( const Point& rPos,
     bool bFound = lcl_GetHyperlinkCell(rDoc, nPosX, nPosY, nTab, aCell, sURL);
     if( !bFound )
         return false;
+    if (pnCol)
+        *pnCol = nPosX;
 
     const ScPatternAttr* pPattern = rDoc.GetPattern( nPosX, nPosY, nTab );
     // bForceToTop = sal_False, use the cell's real position
diff --git a/svx/sdi/svx.sdi b/svx/sdi/svx.sdi
index afb8a60717d7..51ab792cf969 100644
--- a/svx/sdi/svx.sdi
+++ b/svx/sdi/svx.sdi
@@ -9705,7 +9705,7 @@ SfxVoidItem OpenHyperlinkOnCursor SID_OPEN_HYPERLINK
 ]
 
 SfxVoidItem EditHyperlink SID_EDIT_HYPERLINK
-()
+(SfxInt32Item PositionX FN_PARAM_1, SfxInt32Item PositionY FN_PARAM_2)
 [
     AutoUpdate = FALSE,
     FastCall = FALSE,
@@ -12459,7 +12459,7 @@ SfxVoidItem SignSignatureLine SID_SIGN_SIGNATURELINE
 ]
 
 SfxVoidItem RemoveHyperlink SID_REMOVE_HYPERLINK
-()
+(SfxInt32Item PositionX FN_PARAM_1, SfxInt32Item PositionY FN_PARAM_2)
 [
     AutoUpdate = FALSE,
     FastCall = FALSE,

Reply via email to