cui/source/dialogs/hltpbase.cxx      |   30 +++++++++++++++++++++++++++---
 cui/source/inc/hltpbase.hxx          |    6 ++++++
 include/svx/hlnkitem.hxx             |   10 ++++++++++
 sc/source/ui/drawfunc/drawsh5.cxx    |    2 ++
 sc/source/ui/drawfunc/drtxtob.cxx    |    1 +
 sc/source/ui/view/cellsh.cxx         |    1 +
 sc/source/ui/view/editsh.cxx         |    1 +
 sd/source/ui/view/drviewsf.cxx       |    6 ++++++
 svx/source/items/hlnkitem.cxx        |   12 ++++++++++--
 sw/source/uibase/shells/annotsh.cxx  |    2 ++
 sw/source/uibase/shells/drwbassh.cxx |    2 ++
 sw/source/uibase/shells/drwtxtex.cxx |    2 ++
 sw/source/uibase/shells/frmsh.cxx    |    3 +++
 sw/source/uibase/shells/textsh.cxx   |    2 ++
 14 files changed, 75 insertions(+), 5 deletions(-)

New commits:
commit 1fcbf68244a460b8442a54945c00e21c5c68351c
Author:     Maya Stephens <maya.steph...@collabora.com>
AuthorDate: Mon Aug 18 14:39:15 2025 +0000
Commit:     Pedro Silva <pedro.si...@collabora.com>
CommitDate: Thu Aug 21 12:22:26 2025 +0200

    Hide hyperlink dialog fields based on selection
    
    Hides the name field in all cases except writer text or draw text, as these 
seem to be the only types of text that can store link names.
    Hides text field for non-text links, such as shapes or images.
    If a shell does not set the properties m_showText or m_showName, deafult 
values to true, to avoid regressions for unimplemented shells.
    
    Change-Id: I228dc7f9d65c5cb17717afb79feb515376cd4d31
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/189885
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>
    Reviewed-by: Michael Stahl <michael.st...@collabora.com>

diff --git a/cui/source/dialogs/hltpbase.cxx b/cui/source/dialogs/hltpbase.cxx
index df5586269025..f996beb3b651 100644
--- a/cui/source/dialogs/hltpbase.cxx
+++ b/cui/source/dialogs/hltpbase.cxx
@@ -112,7 +112,10 @@ 
SvxHyperlinkTabPageBase::SvxHyperlinkTabPageBase(weld::Container* pParent,
   , mxEdText(xBuilder->weld_entry(u"name"_ustr))
   , mxBtScript(xBuilder->weld_button(u"script"_ustr))
   , mxFormLabel(xBuilder->weld_label(u"form_label"_ustr))
+  , mxNameLabel(xBuilder->weld_label(u"name_label"_ustr))
+  , mxIndicationLabel(xBuilder->weld_label(u"indication_label"_ustr))
   , mxFrameLabel(xBuilder->weld_label(u"frame_label"_ustr))
+  , mxFurtherSettings(xBuilder->weld_label(u"label1"_ustr))
   , mbIsCloseDisabled( false )
   , mpDialog( pDlg )
   , mbStdControlsInit( false )
@@ -230,6 +233,9 @@ void SvxHyperlinkTabPageBase::HideMarkWnd()
 // Fill Dialogfields
 void SvxHyperlinkTabPageBase::FillStandardDlgFields ( const SvxHyperlinkItem* 
pHyperlinkItem )
 {
+    m_showName = pHyperlinkItem->GetShowName();
+    m_showText = pHyperlinkItem->GetShowText();
+
     // Form
     OUString aStrFormText = CuiResId( RID_CUISTR_HYPERDLG_FROM_TEXT );
     OUString aStrFormButton = CuiResId( RID_CUISTR_HYPERDLG_FORM_BUTTON );
@@ -268,9 +274,27 @@ void SvxHyperlinkTabPageBase::FillStandardDlgFields ( 
const SvxHyperlinkItem* pH
         mxLbForm->append_text( aStrFormText );
         mxLbForm->append_text( aStrFormButton );
         mxLbForm->set_active( pHyperlinkItem->GetInsertMode() == HLINK_BUTTON 
? 1 : 0 );
+
+        if (pHyperlinkItem->GetShowName()) {
+            mxNameLabel->show();
+            mxEdText->show();
+            mxFurtherSettings->show();
+        } else {
+            mxNameLabel->hide();
+            mxEdText->hide();
+            mxFurtherSettings->hide();
+        }
+
+        if (pHyperlinkItem->GetShowText()) {
+            mxEdIndication->show();
+            mxIndicationLabel->show();
+        } else {
+            mxEdIndication->hide();
+            mxIndicationLabel->hide();
+        }
     }
 
-    // URL
+    // Text
     mxEdIndication->set_text( pHyperlinkItem->GetName() );
 
     // Name
@@ -479,7 +503,7 @@ bool SvxHyperlinkTabPageBase::FillItemSet( SfxItemSet* rOut)
     SvxMacroTableDtor* pTable = GetMacroTable();
 
     SvxHyperlinkItem aItem( SID_HYPERLINK_SETLINK, aStrName, aStrURL, 
aStrFrame,
-                            aStrIntName, eMode, nEvents, pTable );
+                            aStrIntName, eMode, nEvents, pTable, m_showName, 
m_showText );
     rOut->Put (aItem);
 
     return true;
@@ -522,7 +546,7 @@ DeactivateRC SvxHyperlinkTabPageBase::DeactivatePage( 
SfxItemSet* _pSet)
     if( _pSet )
     {
         SvxHyperlinkItem aItem( SID_HYPERLINK_GETLINK, aStrName, aStrURL, 
aStrFrame,
-                                aStrIntName, eMode, nEvents, pTable );
+                                aStrIntName, eMode, nEvents, pTable, 
m_showName, m_showText );
         _pSet->Put( aItem );
     }
 
diff --git a/cui/source/inc/hltpbase.hxx b/cui/source/inc/hltpbase.hxx
index acb84198ad25..449b3b57bebe 100644
--- a/cui/source/inc/hltpbase.hxx
+++ b/cui/source/inc/hltpbase.hxx
@@ -52,10 +52,16 @@ private:
     std::unique_ptr<weld::Entry> mxEdText;
     std::unique_ptr<weld::Button> mxBtScript;
     std::unique_ptr<weld::Label> mxFormLabel;
+    std::unique_ptr<weld::Label> mxNameLabel;
+    std::unique_ptr<weld::Label> mxIndicationLabel;
     std::unique_ptr<weld::Label> mxFrameLabel;
+    std::unique_ptr<weld::Label> mxFurtherSettings;
 
     bool                        mbIsCloseDisabled;
 
+    bool m_showName = true;
+    bool m_showText = true;
+
     css::uno::Reference< css::frame::XFrame >
                                 mxDocumentFrame;
 
diff --git a/include/svx/hlnkitem.hxx b/include/svx/hlnkitem.hxx
index a17385f165fc..6859d1a04902 100644
--- a/include/svx/hlnkitem.hxx
+++ b/include/svx/hlnkitem.hxx
@@ -53,6 +53,9 @@ class SVX_DLLPUBLIC SvxHyperlinkItem final : public 
SfxPoolItem
     SvxLinkInsertMode eType;
     OUString sReplacementText;
 
+    bool m_showName = true;
+    bool m_showText = true;
+
     OUString sIntName;
     std::unique_ptr<SvxMacroTableDtor>  pMacroTable;
 
@@ -71,6 +74,7 @@ public:
                                     SvxLinkInsertMode eTyp,
                                     HyperDialogEvent nEvents,
                                     SvxMacroTableDtor const *pMacroTbl,
+                                    bool showName = true, bool showText = true,
                                     OUString aReplacementText = OUString());
 
     virtual bool             operator==( const SfxPoolItem& ) const override;
@@ -90,6 +94,12 @@ public:
     const   OUString& GetTargetFrame() const { return sTarget; }
     void    SetTargetFrame(const OUString& rTarget) { sTarget = rTarget; }
 
+    bool GetShowName() const { return m_showName; }
+    void    SetShowName(const bool show) { m_showName = show; }
+
+    bool GetShowText() const { return m_showText; }
+    void    SetShowText(const bool show) { m_showText = show; }
+
     SvxLinkInsertMode GetInsertMode() const { return eType; }
     void    SetInsertMode( SvxLinkInsertMode eNew ) { eType = eNew; }
 
diff --git a/sc/source/ui/drawfunc/drawsh5.cxx 
b/sc/source/ui/drawfunc/drawsh5.cxx
index 58b3f3538da6..6f9fa3abced2 100644
--- a/sc/source/ui/drawfunc/drawsh5.cxx
+++ b/sc/source/ui/drawfunc/drawsh5.cxx
@@ -61,6 +61,8 @@ void ScDrawShell::GetHLinkState( SfxItemSet& rSet )           
  //  Hyperlink
         //  Hyperlink
 
     SvxHyperlinkItem aHLinkItem;
+    aHLinkItem.SetShowName(false);
+    aHLinkItem.SetShowText(false);
 
     if ( rMarkList.GetMarkCount() == 1 )              // URL-Button marked ?
     {
diff --git a/sc/source/ui/drawfunc/drtxtob.cxx 
b/sc/source/ui/drawfunc/drtxtob.cxx
index 8f845016ac2a..33b97a26e0b0 100644
--- a/sc/source/ui/drawfunc/drtxtob.cxx
+++ b/sc/source/ui/drawfunc/drtxtob.cxx
@@ -379,6 +379,7 @@ void ScDrawTextObjectBar::GetState( SfxItemSet& rSet )
     if ( rSet.GetItemState( SID_HYPERLINK_GETLINK ) != SfxItemState::UNKNOWN )
     {
         SvxHyperlinkItem aHLinkItem;
+        aHLinkItem.SetShowName(false);
         SdrView* pView = mrViewData.GetScDrawView();
         OutlinerView* pOutView = pView->GetTextEditOutlinerView();
         if ( pOutView )
diff --git a/sc/source/ui/view/cellsh.cxx b/sc/source/ui/view/cellsh.cxx
index f18c6ceb30e5..23af261add38 100644
--- a/sc/source/ui/view/cellsh.cxx
+++ b/sc/source/ui/view/cellsh.cxx
@@ -673,6 +673,7 @@ void ScCellShell::GetHLinkState( SfxItemSet& rSet )
     //  if the cell at the cursor contains only a link, return that link
 
     SvxHyperlinkItem aHLinkItem;
+    aHLinkItem.SetShowName(false);
     if ( !GetViewData().GetView()->HasBookmarkAtCursor( &aHLinkItem ) )
     {
         // tdf#80043 - put selected text into item
diff --git a/sc/source/ui/view/editsh.cxx b/sc/source/ui/view/editsh.cxx
index eae7f783c93f..f91bd6c66366 100644
--- a/sc/source/ui/view/editsh.cxx
+++ b/sc/source/ui/view/editsh.cxx
@@ -784,6 +784,7 @@ void ScEditShell::GetState( SfxItemSet& rSet )
             case SID_HYPERLINK_GETLINK:
                 {
                     SvxHyperlinkItem aHLinkItem;
+                    aHLinkItem.SetShowName(false);
                     bool bCellLinksOnly
                         = 
(ScModule::get()->GetAppOptions().GetLinksInsertedLikeMSExcel()
                           && 
rViewData.GetSfxDocShell()->GetMedium()->GetFilter()->IsMSOFormat())
diff --git a/sd/source/ui/view/drviewsf.cxx b/sd/source/ui/view/drviewsf.cxx
index 5e6fe08f4ee3..11f5d46caede 100644
--- a/sd/source/ui/view/drviewsf.cxx
+++ b/sd/source/ui/view/drviewsf.cxx
@@ -88,6 +88,9 @@ void DrawViewShell::GetCtrlState(SfxItemSet &rSet)
 
         if (pOLV)
         {
+            aHLinkItem.SetShowText(true);
+            aHLinkItem.SetShowName(true);
+
             const SvxFieldItem* pFieldItem = pOLV->GetFieldAtSelection();
             const SvxFieldData* pField = pFieldItem ? pFieldItem->GetField() : 
nullptr;
             if( auto pUrlField = dynamic_cast< const SvxURLField *>( pField ) )
@@ -111,6 +114,9 @@ void DrawViewShell::GetCtrlState(SfxItemSet &rSet)
             const SdrMarkList& rMarkList = mpDrawView->GetMarkedObjectList();
             if (rMarkList.GetMarkCount() > 0)
             {
+                aHLinkItem.SetShowText(false);
+                aHLinkItem.SetShowName(false);
+
                 bool bFound = false;
 
                 SdrObject* pMarkedObj = 
rMarkList.GetMark(0)->GetMarkedSdrObj();
diff --git a/svx/source/items/hlnkitem.cxx b/svx/source/items/hlnkitem.cxx
index b56c9bc5c955..41f857f55c37 100644
--- a/svx/source/items/hlnkitem.cxx
+++ b/svx/source/items/hlnkitem.cxx
@@ -36,6 +36,9 @@ SvxHyperlinkItem::SvxHyperlinkItem( const SvxHyperlinkItem& 
rHyperlinkItem ):
     nMacroEvents = rHyperlinkItem.nMacroEvents;
     sReplacementText = rHyperlinkItem.sReplacementText;
 
+    m_showName = rHyperlinkItem.m_showName;
+    m_showText = rHyperlinkItem.m_showText;
+
     if( rHyperlinkItem.GetMacroTable() )
         pMacroTable.reset( new SvxMacroTableDtor( 
*rHyperlinkItem.GetMacroTable() ) );
 
@@ -43,13 +46,15 @@ SvxHyperlinkItem::SvxHyperlinkItem( const SvxHyperlinkItem& 
rHyperlinkItem ):
 
 SvxHyperlinkItem::SvxHyperlinkItem( TypedWhichId<SvxHyperlinkItem> _nWhich, 
OUString aName, OUString aURL,
                                     OUString aTarget, OUString aIntName, 
SvxLinkInsertMode eTyp,
-                                    HyperDialogEvent nEvents, 
SvxMacroTableDtor const *pMacroTbl, OUString aReplacementText):
+                                    HyperDialogEvent nEvents, 
SvxMacroTableDtor const *pMacroTbl, bool showName, bool showText, OUString 
aReplacementText):
     SfxPoolItem (_nWhich ),
     sName       (std::move(aName)),
     sURL        (std::move(aURL)),
     sTarget     (std::move(aTarget)),
     eType       (eTyp),
     sReplacementText (std::move(aReplacementText)),
+    m_showName    (showName),
+    m_showText    (showText),
     sIntName (std::move(aIntName)),
     nMacroEvents (nEvents)
 {
@@ -74,7 +79,9 @@ bool SvxHyperlinkItem::operator==( const SfxPoolItem& rAttr ) 
const
                   eType   == rItem.eType   &&
                   sIntName == rItem.sIntName &&
                   nMacroEvents == rItem.nMacroEvents &&
-                  sReplacementText == rItem.sReplacementText);
+                  sReplacementText == rItem.sReplacementText &&
+                  m_showText == rItem.m_showText &&
+                  m_showName == rItem.m_showName);
     if (!bRet)
         return false;
 
@@ -186,6 +193,7 @@ bool SvxHyperlinkItem::PutValue( const css::uno::Any& rVal, 
sal_uInt8 nMemberId
                 return false;
             sReplacementText = aStr;
         break;
+        // Currently no way to put showName or showValue; these are set by the 
shell
         default:
             return false;
     }
diff --git a/sw/source/uibase/shells/annotsh.cxx 
b/sw/source/uibase/shells/annotsh.cxx
index 55d489bf7468..bbfa3e7292b3 100644
--- a/sw/source/uibase/shells/annotsh.cxx
+++ b/sw/source/uibase/shells/annotsh.cxx
@@ -1113,6 +1113,8 @@ void SwAnnotationShell::StateInsert(SfxItemSet &rSet)
             case SID_HYPERLINK_GETLINK:
                 {
                     SvxHyperlinkItem aHLinkItem;
+                    aHLinkItem.SetShowName(false);
+                    aHLinkItem.SetShowText(true);
                     aHLinkItem.SetInsertMode(HLINK_FIELD);
 
                     const SvxFieldItem* pFieldItem = 
pOLV->GetFieldAtSelection();
diff --git a/sw/source/uibase/shells/drwbassh.cxx 
b/sw/source/uibase/shells/drwbassh.cxx
index e6db5b16c626..f70765b9cacf 100644
--- a/sw/source/uibase/shells/drwbassh.cxx
+++ b/sw/source/uibase/shells/drwbassh.cxx
@@ -989,6 +989,8 @@ void SwDrawBaseShell::GetState(SfxItemSet& rSet)
                     SdrObject* pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
                     OUString sHyperLink = pObj->getHyperlink();
                     SvxHyperlinkItem aHLinkItem;
+                    aHLinkItem.SetShowName(false);
+                    aHLinkItem.SetShowText(false);
                     aHLinkItem.SetURL(sHyperLink);
                     rSet.Put(aHLinkItem);
                 }
diff --git a/sw/source/uibase/shells/drwtxtex.cxx 
b/sw/source/uibase/shells/drwtxtex.cxx
index beec3dbe7705..706a03acb4f4 100644
--- a/sw/source/uibase/shells/drwtxtex.cxx
+++ b/sw/source/uibase/shells/drwtxtex.cxx
@@ -1269,6 +1269,8 @@ void SwDrawTextShell::StateInsert(SfxItemSet &rSet)
             case SID_HYPERLINK_GETLINK:
                 {
                     SvxHyperlinkItem aHLinkItem;
+                    aHLinkItem.SetShowName(false);
+                    aHLinkItem.SetShowText(false);
                     aHLinkItem.SetInsertMode(HLINK_FIELD);
 
                     const SvxFieldItem* pFieldItem = 
pOLV->GetFieldAtSelection();
diff --git a/sw/source/uibase/shells/frmsh.cxx 
b/sw/source/uibase/shells/frmsh.cxx
index 775551cfd9f6..5e226be93503 100644
--- a/sw/source/uibase/shells/frmsh.cxx
+++ b/sw/source/uibase/shells/frmsh.cxx
@@ -920,6 +920,9 @@ void SwFrameShell::GetState(SfxItemSet& rSet)
             {
                 SvxHyperlinkItem aHLinkItem;
 
+                aHLinkItem.SetShowName(false);
+                aHLinkItem.SetShowText(false);
+
                 SfxItemSetFixed<RES_URL, RES_URL> aURLSet(GetPool());
                 rSh.GetFlyFrameAttr( aURLSet );
 
diff --git a/sw/source/uibase/shells/textsh.cxx 
b/sw/source/uibase/shells/textsh.cxx
index b36ba7aa4852..cfd2d3a8ac45 100644
--- a/sw/source/uibase/shells/textsh.cxx
+++ b/sw/source/uibase/shells/textsh.cxx
@@ -702,6 +702,8 @@ void SwTextShell::StateInsert( SfxItemSet &rSet )
                     rSh.GetCurAttr( aSet );
 
                     SvxHyperlinkItem aHLinkItem;
+                    aHLinkItem.SetShowName(true);
+                    aHLinkItem.SetShowText(true);
                     if(const SwFormatINetFormat* pINetFormat = 
aSet.GetItemIfSet(RES_TXTATR_INETFMT, false))
                     {
                         aHLinkItem.SetURL(pINetFormat->GetValue());

Reply via email to