diff options
-rw-r--r-- | editeng/source/misc/urlfieldhelper.cxx | 28 | ||||
-rw-r--r-- | include/editeng/urlfieldhelper.hxx | 5 | ||||
-rw-r--r-- | sc/source/ui/drawfunc/drtxtob.cxx | 6 | ||||
-rw-r--r-- | sc/source/ui/view/editsh.cxx | 15 | ||||
-rw-r--r-- | sd/source/ui/view/drviews2.cxx | 3 | ||||
-rw-r--r-- | sd/source/ui/view/drviews7.cxx | 15 | ||||
-rw-r--r-- | sd/source/ui/view/drviewsf.cxx | 2 | ||||
-rw-r--r-- | sw/source/uibase/shells/drwtxtex.cxx | 7 |
8 files changed, 33 insertions, 48 deletions
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 2be1ccd2c6c2..b2ba46958b5d 100644 --- a/sd/source/ui/view/drviews2.cxx +++ b/sd/source/ui/view/drviews2.cxx @@ -1200,8 +1200,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 565283ce1c3a..5533c62510b8 100644 --- a/sd/source/ui/view/drviewsf.cxx +++ b/sd/source/ui/view/drviewsf.cxx @@ -505,7 +505,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 d91e90b94d25..fc1f4175357d 100644 --- a/sw/source/uibase/shells/drwtxtex.cxx +++ b/sw/source/uibase/shells/drwtxtex.cxx @@ -536,10 +536,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; @@ -979,7 +976,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; |