tdf#158031 editeng SID_OPEN_HYPERLINK: use AlsoCheckBeforeCursor
This patch depends on prior patches for this bug report.
This fixes nothing being opened if the mouse was right-clicked
over that second half of the hyperlink (since a "smart" positioning
set the cursor after the field instead of before it).
Note that for some reason, OPEN always seemed to work with the mouse,
even though other hyperlink menu options using the same code
failed to find the field! So this code change is mainly for consistency.
However, I WAS able to make it always fail,
by moving the mouse away once the popup menu arrived,
and then using the KEYBOARD to "Open Hyperlink".
In that case, it always failed (because the field
was not selected, and not under the mouse).
Change-Id: I8fcd0386de6cea8c6a937afb6f63061ed62d4cb1
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/159016
Tested-by: Jenkins
Reviewed-by: Justin Luth <jluth@mail.com>
diff --git a/sc/source/ui/drawfunc/drtxtob.cxx b/sc/source/ui/drawfunc/drtxtob.cxx
index 65da5aa..1339e27 100644
--- a/sc/source/ui/drawfunc/drtxtob.cxx
+++ b/sc/source/ui/drawfunc/drtxtob.cxx
@@ -292,8 +292,10 @@ void ScDrawTextObjectBar::Execute( SfxRequest &rReq )
break;
case SID_OPEN_HYPERLINK:
if (const SvxFieldData* pField = pOutView->GetFieldAtCursor())
{
const SvxFieldItem* pFieldItem
= pOutView->GetFieldAtSelection(/*AlsoCheckBeforeCursor=*/true);
const SvxFieldData* pField = pFieldItem ? pFieldItem->GetField() : nullptr;
if (const SvxURLField* pURLField = dynamic_cast<const SvxURLField*>(pField))
{
ScGlobal::OpenURL(pURLField->GetURL(), pURLField->GetTargetFrame(), true);
diff --git a/sc/source/ui/view/editsh.cxx b/sc/source/ui/view/editsh.cxx
index ba76f89..c48b777 100644
--- a/sc/source/ui/view/editsh.cxx
+++ b/sc/source/ui/view/editsh.cxx
@@ -639,9 +639,10 @@ void ScEditShell::Execute( SfxRequest& rReq )
break;
case SID_OPEN_HYPERLINK:
{
std::unique_ptr<const SvxFieldData> aSvxFieldDataPtr(GetURLField());
const SvxURLField* pURLField(static_cast<const SvxURLField*>(aSvxFieldDataPtr.get()));
if ( pURLField )
const SvxFieldItem* pFieldItem
= pEditView->GetFieldAtSelection(/*AlsoCheckBeforeCursor=*/true);
const SvxFieldData* pField = pFieldItem ? pFieldItem->GetField() : nullptr;
if (const SvxURLField* pURLField = dynamic_cast<const SvxURLField*>(pField))
ScGlobal::OpenURL( pURLField->GetURL(), pURLField->GetTargetFrame(), true );
return;
}
diff --git a/sd/source/ui/view/drviews2.cxx b/sd/source/ui/view/drviews2.cxx
index fab59b5..ae77f55 100644
--- a/sd/source/ui/view/drviews2.cxx
+++ b/sd/source/ui/view/drviews2.cxx
@@ -2243,7 +2243,9 @@ void DrawViewShell::FuTemporary(SfxRequest& rReq)
OutlinerView* pOutView = mpDrawView->GetTextEditOutlinerView();
if ( pOutView )
{
const SvxFieldData* pField = pOutView->GetFieldAtCursor();
const SvxFieldItem* pFieldItem
= pOutView->GetFieldAtSelection(/*AlsoCheckBeforeCursor=*/true);
const SvxFieldData* pField = pFieldItem ? pFieldItem->GetField() : nullptr;
if( auto pURLField = dynamic_cast< const SvxURLField *>( pField ) )
{
SfxStringItem aUrl( SID_FILE_NAME, pURLField->GetURL() );
diff --git a/sw/source/uibase/shells/drwtxtex.cxx b/sw/source/uibase/shells/drwtxtex.cxx
index dc10ba4..9c42185 100644
--- a/sw/source/uibase/shells/drwtxtex.cxx
+++ b/sw/source/uibase/shells/drwtxtex.cxx
@@ -494,7 +494,9 @@ void SwDrawTextShell::Execute( SfxRequest &rReq )
case SID_OPEN_HYPERLINK:
{
const SvxFieldData* pField = pOLV->GetFieldAtCursor();
const SvxFieldItem* pFieldItem
= pOLV->GetFieldAtSelection(/*AlsoCheckBeforeCursor=*/true);
const SvxFieldData* pField = pFieldItem ? pFieldItem->GetField() : nullptr;
if (const SvxURLField* pURLField = dynamic_cast<const SvxURLField*>(pField))
{
SfxStringItem aUrl(SID_FILE_NAME, pURLField->GetURL());