[Libreoffice-commits] core.git: editeng/source include/editeng sc/source sd/source sw/source

Samuel Mehrbrodt (via logerrit) logerrit at kemper.freedesktop.org
Thu Dec 5 15:01:10 UTC 2019


 editeng/source/misc/urlfieldhelper.cxx |   28 +++++++++++++++++-----------
 include/editeng/urlfieldhelper.hxx     |    5 +++--
 sc/source/ui/drawfunc/drtxtob.cxx      |    6 ++----
 sc/source/ui/view/editsh.cxx           |   15 ++++-----------
 sd/source/ui/view/drviews2.cxx         |    3 +--
 sd/source/ui/view/drviews7.cxx         |   15 +++------------
 sd/source/ui/view/drviewsf.cxx         |    2 +-
 sw/source/uibase/shells/drwtxtex.cxx   |    7 ++-----
 8 files changed, 33 insertions(+), 48 deletions(-)

New commits:
commit f31c3ebb60e4678eb09e377b638b368531df47dc
Author:     Samuel Mehrbrodt <Samuel.Mehrbrodt at cib.de>
AuthorDate: Wed Dec 4 15:19:00 2019 +0100
Commit:     Samuel Mehrbrodt <Samuel.Mehrbrodt at cib.de>
CommitDate: Thu Dec 5 15:59:50 2019 +0100

    tdf#128666 Only enable hyperlink actions when just the field is selected
    
    Change-Id: I984df967877a47fb9f89c3626737348a87d3ffa5
    Reviewed-on: https://gerrit.libreoffice.org/84418
    Tested-by: Jenkins
    Reviewed-by: Samuel Mehrbrodt <Samuel.Mehrbrodt at cib.de>

diff --git a/editeng/source/misc/urlfieldhelper.cxx b/editeng/source/misc/urlfieldhelper.cxx
index 6df7171e14c0..564bc54e781e 100644
--- a/editeng/source/misc/urlfieldhelper.cxx
+++ b/editeng/source/misc/urlfieldhelper.cxx
@@ -11,27 +11,33 @@
 
 #include <editeng/flditem.hxx>
 #include <editeng/editview.hxx>
+#include <editeng/editeng.hxx>
 
-void URLFieldHelper::RemoveURLField(Outliner* pOutl, const OutlinerView* pOLV)
+void URLFieldHelper::RemoveURLField(EditView& pEditView)
 {
-    if (!pOutl || !pOLV)
-        return;
-
-    const SvxFieldData* pField = pOLV->GetFieldAtCursor();
+    pEditView.SelectFieldAtCursor();
+    const SvxFieldData* pField = pEditView.GetFieldAtCursor();
     if (auto pUrlField = dynamic_cast<const SvxURLField*>(pField))
     {
-        ESelection aSel = pOLV->GetSelection();
-        pOutl->QuickInsertText(pUrlField->GetRepresentation(), aSel);
-        pOLV->GetEditView().Invalidate();
+        ESelection aSel = pEditView.GetSelection();
+        pEditView.GetEditEngine()->QuickInsertText(pUrlField->GetRepresentation(), aSel);
+        pEditView.Invalidate();
     }
 }
 
-bool URLFieldHelper::IsCursorAtURLField(const OutlinerView* pOLV)
+bool URLFieldHelper::IsCursorAtURLField(const EditView& pEditView)
 {
-    if (!pOLV)
+    // tdf#128666 Make sure only URL field (or nothing) is selected
+    ESelection aSel = pEditView.GetSelection();
+    auto nSelectedParas = aSel.nEndPara - aSel.nStartPara;
+    auto nSelectedChars = aSel.nEndPos - aSel.nStartPos;
+    bool bIsValidSelection
+        = nSelectedParas == 0
+          && (nSelectedChars == 0 || nSelectedChars == 1 || nSelectedChars == -1);
+    if (!bIsValidSelection)
         return false;
 
-    const SvxFieldData* pField = pOLV->GetFieldAtCursor();
+    const SvxFieldData* pField = pEditView.GetFieldAtCursor();
     if (dynamic_cast<const SvxURLField*>(pField))
         return true;
 
diff --git a/include/editeng/urlfieldhelper.hxx b/include/editeng/urlfieldhelper.hxx
index 547e2654ea9b..e6c7c92935a4 100644
--- a/include/editeng/urlfieldhelper.hxx
+++ b/include/editeng/urlfieldhelper.hxx
@@ -12,12 +12,13 @@
 #include <sal/config.h>
 #include <editeng/editengdllapi.h>
 #include <editeng/outliner.hxx>
+#include <editeng/editview.hxx>
 
 class EDITENG_DLLPUBLIC URLFieldHelper
 {
 public:
-    static void RemoveURLField(Outliner* pOutl, const OutlinerView* pOLV);
-    static bool IsCursorAtURLField(const OutlinerView* pOLV);
+    static void RemoveURLField(EditView& pEditView);
+    static bool IsCursorAtURLField(const EditView& pEditView);
 };
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
diff --git a/sc/source/ui/drawfunc/drtxtob.cxx b/sc/source/ui/drawfunc/drtxtob.cxx
index daf58d072eea..6cc27d4368c3 100644
--- a/sc/source/ui/drawfunc/drtxtob.cxx
+++ b/sc/source/ui/drawfunc/drtxtob.cxx
@@ -326,8 +326,7 @@ void ScDrawTextObjectBar::Execute( SfxRequest &rReq )
         case SID_REMOVE_HYPERLINK:
             {
                 // Ensure the field is selected first
-                pOutView->SelectFieldAtCursor();
-                URLFieldHelper::RemoveURLField(pOutliner, pOutView);
+                URLFieldHelper::RemoveURLField(pOutView->GetEditView());
             }
             break;
 
@@ -412,8 +411,7 @@ void ScDrawTextObjectBar::GetState( SfxItemSet& rSet )
         || rSet.GetItemState(SID_REMOVE_HYPERLINK) != SfxItemState::UNKNOWN)
     {
         SdrView* pView = pViewData->GetScDrawView();
-        OutlinerView* pOutView = pView->GetTextEditOutlinerView();
-        if( !URLFieldHelper::IsCursorAtURLField(pOutView) )
+        if( !URLFieldHelper::IsCursorAtURLField(pView->GetTextEditOutlinerView()->GetEditView()) )
         {
             rSet.DisableItem( SID_OPEN_HYPERLINK );
             rSet.DisableItem( SID_EDIT_HYPERLINK );
diff --git a/sc/source/ui/view/editsh.cxx b/sc/source/ui/view/editsh.cxx
index ebcde629df8b..80a7bf1cdea2 100644
--- a/sc/source/ui/view/editsh.cxx
+++ b/sc/source/ui/view/editsh.cxx
@@ -33,6 +33,7 @@
 #include <editeng/flditem.hxx>
 #include <editeng/flstitem.hxx>
 #include <editeng/fontitem.hxx>
+#include <editeng/urlfieldhelper.hxx>
 #include <svx/hlnkitem.hxx>
 #include <vcl/EnumContext.hxx>
 #include <editeng/postitem.hxx>
@@ -646,15 +647,7 @@ void ScEditShell::Execute( SfxRequest& rReq )
         break;
         case SID_REMOVE_HYPERLINK:
             {
-                // Ensure the field is selected first
-                pEditView->SelectFieldAtCursor();
-                const SvxURLField* pURLField = GetURLField();
-                if (pURLField)
-                {
-                    ESelection aSel = pEditView->GetSelection();
-                    pEditView->GetEditEngine()->QuickInsertText(pURLField->GetRepresentation(), aSel);
-                }
-
+                URLFieldHelper::RemoveURLField(*pEditView);
             }
         break;
 
@@ -786,8 +779,8 @@ void ScEditShell::GetState( SfxItemSet& rSet )
             case SID_COPY_HYPERLINK_LOCATION:
             case SID_REMOVE_HYPERLINK:
                 {
-                    if ( !GetURLField() )
-                        rSet.DisableItem( nWhich );
+                    if (!URLFieldHelper::IsCursorAtURLField(*pEditView))
+                        rSet.DisableItem (nWhich);
                 }
                 break;
 
diff --git a/sd/source/ui/view/drviews2.cxx b/sd/source/ui/view/drviews2.cxx
index 233d4a108135..12a2b8919be6 100644
--- a/sd/source/ui/view/drviews2.cxx
+++ b/sd/source/ui/view/drviews2.cxx
@@ -1195,8 +1195,7 @@ void DrawViewShell::FuTemporary(SfxRequest& rReq)
                 OutlinerView* pOutView = mpDrawView->GetTextEditOutlinerView();
                 if (pOutView)
                     pOutView->SelectFieldAtCursor();
-                URLFieldHelper::RemoveURLField(mpDrawView->GetTextEditOutliner(),
-                                               mpDrawView->GetTextEditOutlinerView());
+                URLFieldHelper::RemoveURLField(pOutView->GetEditView());
             }
         }
         Cancel();
diff --git a/sd/source/ui/view/drviews7.cxx b/sd/source/ui/view/drviews7.cxx
index 7372d2327ff0..0874a587a3a1 100644
--- a/sd/source/ui/view/drviews7.cxx
+++ b/sd/source/ui/view/drviews7.cxx
@@ -33,6 +33,7 @@
 #include <editeng/flditem.hxx>
 #include <editeng/outlobj.hxx>
 #include <editeng/sizeitem.hxx>
+#include <editeng/urlfieldhelper.hxx>
 #include <officecfg/Office/Impress.hxx>
 #include <svx/svxids.hrc>
 #include <svx/svdpagv.hxx>
@@ -1449,18 +1450,8 @@ void DrawViewShell::GetMenuState( SfxItemSet &rSet )
         if( mpDrawView->IsTextEdit() )
         {
             OutlinerView* pOLV = mpDrawView->GetTextEditOutlinerView();
-            if (pOLV)
-            {
-                const SvxFieldItem* pFieldItem = pOLV->GetFieldUnderMousePointer();
-                if (!pFieldItem)
-                    pFieldItem = pOLV->GetFieldAtSelection();
-                if (pFieldItem)
-                {
-                    const SvxFieldData* pField = pFieldItem->GetField();
-                    if (dynamic_cast<const SvxURLField*>(pField))
-                        bDisableEditHyperlink = false;
-                }
-            }
+            if (pOLV && URLFieldHelper::IsCursorAtURLField(pOLV->GetEditView()))
+                bDisableEditHyperlink = false;
         }
         else
         {
diff --git a/sd/source/ui/view/drviewsf.cxx b/sd/source/ui/view/drviewsf.cxx
index 5977fb697140..1b46491c65c8 100644
--- a/sd/source/ui/view/drviewsf.cxx
+++ b/sd/source/ui/view/drviewsf.cxx
@@ -511,7 +511,7 @@ void DrawViewShell::GetAttrState( SfxItemSet& rSet )
 
             case SID_REMOVE_HYPERLINK:
             {
-                if (!URLFieldHelper::IsCursorAtURLField(mpDrawView->GetTextEditOutlinerView()))
+                if (!URLFieldHelper::IsCursorAtURLField(mpDrawView->GetTextEditOutlinerView()->GetEditView()))
                     rSet.DisableItem(nWhich);
             }
             break;
diff --git a/sw/source/uibase/shells/drwtxtex.cxx b/sw/source/uibase/shells/drwtxtex.cxx
index ae7af539ad73..4f67f27449d9 100644
--- a/sw/source/uibase/shells/drwtxtex.cxx
+++ b/sw/source/uibase/shells/drwtxtex.cxx
@@ -535,10 +535,7 @@ void SwDrawTextShell::Execute( SfxRequest &rReq )
 
         case SID_REMOVE_HYPERLINK:
         {
-            // Ensure the field is selected first
-            pOLV->SelectFieldAtCursor();
-            URLFieldHelper::RemoveURLField(pSdrView->GetTextEditOutliner(),
-                                           pOLV);
+            URLFieldHelper::RemoveURLField(pOLV->GetEditView());
         }
         break;
 
@@ -981,7 +978,7 @@ void SwDrawTextShell::GetState(SfxItemSet& rSet)
             case SID_OPEN_HYPERLINK:
             case SID_COPY_HYPERLINK_LOCATION:
             {
-                if (!URLFieldHelper::IsCursorAtURLField(pOLV))
+                if (!URLFieldHelper::IsCursorAtURLField(pOLV->GetEditView()))
                     rSet.DisableItem(nWhich);
             }
             break;


More information about the Libreoffice-commits mailing list