editeng/source/editeng/editeng.cxx  |    3 ++-
 editeng/source/editeng/impedit2.cxx |    6 ++++--
 include/editeng/editeng.hxx         |    3 ++-
 sc/inc/editutil.hxx                 |    2 +-
 sc/source/core/tool/editutil.cxx    |    7 +++++--
 5 files changed, 14 insertions(+), 7 deletions(-)

New commits:
commit b9362e87a3646a6693b81fb0d40e28ce7813a251
Author:     Samuel Mehrbrodt <samuel.mehrbr...@allotropia.de>
AuthorDate: Tue Nov 30 23:34:11 2021 +0100
Commit:     Samuel Mehrbrodt <samuel.mehrbr...@allotropia.de>
CommitDate: Mon Dec 6 14:11:44 2021 +0100

    tdf#145671 Don't open URL twice in cell edit mode
    
    Change-Id: I8a324d6a037c8a5c0efc0b2825657513c2f9841c
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/126159
    Tested-by: Jenkins
    Reviewed-by: Samuel Mehrbrodt <samuel.mehrbr...@allotropia.de>

diff --git a/editeng/source/editeng/editeng.cxx 
b/editeng/source/editeng/editeng.cxx
index ae30e651b594..b557dd693d72 100644
--- a/editeng/source/editeng/editeng.cxx
+++ b/editeng/source/editeng/editeng.cxx
@@ -2588,8 +2588,9 @@ OUString EditEngine::CalcFieldValue( const SvxFieldItem&, 
sal_Int32, sal_Int32,
     return OUString(' ');
 }
 
-void EditEngine::FieldClicked( const SvxFieldItem& )
+bool EditEngine::FieldClicked( const SvxFieldItem& )
 {
+    return false;
 }
 
 
diff --git a/editeng/source/editeng/impedit2.cxx 
b/editeng/source/editeng/impedit2.cxx
index 47672cb090f3..cbbfddff51c7 100644
--- a/editeng/source/editeng/impedit2.cxx
+++ b/editeng/source/editeng/impedit2.cxx
@@ -611,8 +611,11 @@ bool ImpEditEngine::MouseButtonUp( const MouseEvent& 
rMEvt, EditView* pView )
             Point aLogicClick = rOutDev.PixelToLogic(rMEvt.GetPosPixel());
             if (const SvxFieldItem* pFld = pView->GetField(aLogicClick))
             {
+                bool bUrlOpened = GetEditEnginePtr()->FieldClicked( *pFld );
+                auto pUrlField = dynamic_cast<const 
SvxURLField*>(pFld->GetField());
+
                 // tdf#121039 When in edit mode, editeng is responsible for 
opening the URL on mouse click
-                if (auto pUrlField = dynamic_cast<const 
SvxURLField*>(pFld->GetField()))
+                if (!bUrlOpened && pUrlField)
                 {
                     bool bCtrlClickHappened = rMEvt.IsMod1();
                     bool bCtrlClickSecOption
@@ -627,7 +630,6 @@ bool ImpEditEngine::MouseButtonUp( const MouseEvent& rMEvt, 
EditView* pView )
                                       
css::system::SystemShellExecuteFlags::DEFAULTS);
                     }
                 }
-                GetEditEnginePtr()->FieldClicked( *pFld );
             }
         }
     }
diff --git a/include/editeng/editeng.hxx b/include/editeng/editeng.hxx
index fb109d7baa53..560f3be1a83a 100644
--- a/include/editeng/editeng.hxx
+++ b/include/editeng/editeng.hxx
@@ -516,7 +516,8 @@ public:
                              const Color& rTextLineColor);
     virtual OUString  GetUndoComment( sal_uInt16 nUndoId ) const;
     virtual bool    SpellNextDocument();
-    virtual void    FieldClicked( const SvxFieldItem& rField );
+    /** @return true, when click was consumed. false otherwise. */
+    virtual bool    FieldClicked( const SvxFieldItem& rField );
     virtual OUString CalcFieldValue( const SvxFieldItem& rField, sal_Int32 
nPara, sal_Int32 nPos, std::optional<Color>& rTxtColor, std::optional<Color>& 
rFldColor );
 
     // override this if access to bullet information needs to be provided
diff --git a/sc/inc/editutil.hxx b/sc/inc/editutil.hxx
index 1353544b96e3..04975b05ccc0 100644
--- a/sc/inc/editutil.hxx
+++ b/sc/inc/editutil.hxx
@@ -180,7 +180,7 @@ public:
 
     void SetExecuteURL(bool bSet)    { bExecuteURL = bSet; }
 
-    virtual void    FieldClicked( const SvxFieldItem& rField ) override;
+    virtual bool    FieldClicked( const SvxFieldItem& rField ) override;
     virtual OUString CalcFieldValue( const SvxFieldItem& rField, sal_Int32 
nPara, sal_Int32 nPos, std::optional<Color>& rTxtColor, std::optional<Color>& 
rFldColor ) override;
 };
 
diff --git a/sc/source/core/tool/editutil.cxx b/sc/source/core/tool/editutil.cxx
index 40957b3362b1..331f50af8b93 100644
--- a/sc/source/core/tool/editutil.cxx
+++ b/sc/source/core/tool/editutil.cxx
@@ -895,14 +895,17 @@ OUString ScFieldEditEngine::CalcFieldValue( const 
SvxFieldItem& rField,
     return ScEditUtil::GetCellFieldValue(*pFieldData, mpDoc, &rTxtColor);
 }
 
-void ScFieldEditEngine::FieldClicked( const SvxFieldItem& rField )
+bool ScFieldEditEngine::FieldClicked( const SvxFieldItem& rField )
 {
     if (!bExecuteURL)
-        return;
+        return false;
+
     if (const SvxURLField* pURLField = dynamic_cast<const 
SvxURLField*>(rField.GetField()))
     {
         ScGlobal::OpenURL(pURLField->GetURL(), pURLField->GetTargetFrame());
+        return true;
     }
+    return false;
 }
 
 ScNoteEditEngine::ScNoteEditEngine( SfxItemPool* pEnginePoolP,

Reply via email to