cui/source/dialogs/cuihyperdlg.cxx |   57 ++++++++++++++++---------------------
 cui/source/inc/cuihyperdlg.hxx     |    3 -
 2 files changed, 27 insertions(+), 33 deletions(-)

New commits:
commit 977fde9468cc26b17680dbf798ea100e8f1584b4
Author:     Maya Stephens <maya.steph...@collabora.com>
AuthorDate: Thu Aug 28 11:40:55 2025 +0000
Commit:     Michael Stahl <michael.st...@collabora.com>
CommitDate: Fri Sep 12 11:36:03 2025 +0200

    Change how SvxHpLinkDlg::SetPage functions
    
    A few changes:
     - Use msRememberedPageId instead of GetCurrPageId as default, as this
    should be updated whenever the page is changed
     - Count Https links as using the internet tab
     - Reset every page instead of only the current page with the information
       - This prevents the dialog box from changing size in online
     - Prevent crashes from trying to open a type of page not supported in LoKit
       - Trying to open the document tab in LoKit causes a crash
       - Fix this by not allowing this option to be selected for links starting 
ftp://
       - Additionally, allow nullptr to be returned and handle by just exiting 
the
    function, in case another problem appears in the future
    
    Change-Id: I509dc699d3517600dfc329722bc5f1192b4e7956
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/190532
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>
    Reviewed-by: Michael Stahl <michael.st...@collabora.com>

diff --git a/cui/source/dialogs/cuihyperdlg.cxx 
b/cui/source/dialogs/cuihyperdlg.cxx
index be8cd6f47a4a..11f03e6c98d1 100644
--- a/cui/source/dialogs/cuihyperdlg.cxx
+++ b/cui/source/dialogs/cuihyperdlg.cxx
@@ -176,7 +176,14 @@ SvxHpLinkDlg::~SvxHpLinkDlg()
     pOutSet.reset();
 }
 
-void SvxHpLinkDlg::Activate() {
+IconChoicePage* SvxHpLinkDlg::GetTabPage( std::u16string_view rPageId )
+{
+    const IconChoicePageData* p = GetPageData(rPageId);
+    return (p == nullptr) ? nullptr : p->xPage.get();
+}
+
+void SvxHpLinkDlg::Activate()
+{
     if (mbGrabFocus) {
         static_cast<SvxHyperlinkTabPageBase 
*>(GetTabPage(GetCurPageId()))->SetInitFocus();
         mbGrabFocus = false;
@@ -233,48 +240,36 @@ IMPL_LINK_NOARG(SvxHpLinkDlg, ClickApplyHdl_Impl, 
weld::Button&, void)
 |************************************************************************/
 void SvxHpLinkDlg::SetPage ( SvxHyperlinkItem const * pItem )
 {
-    OUString sPageId(u"internet"_ustr);
+    mpItemSet->Put(*pItem);
 
     const OUString& aStrURL(pItem->GetURL());
     INetURLObject aURL(aStrURL);
     INetProtocol eProtocolTyp = aURL.GetProtocol();
 
-    switch ( eProtocolTyp )
-    {
-        case INetProtocol::Http :
-        case INetProtocol::Ftp :
-            sPageId = "internet";
-            break;
-        case INetProtocol::File :
-            sPageId = "document";
-            break;
-        case INetProtocol::Mailto :
-            sPageId = "mail";
-            break;
-        default :
-            if (aStrURL.startsWith("#"))
-                sPageId = "document";
-            else
-            {
-                // not valid
-                sPageId = GetCurPageId();
-            }
-            break;
+    OUString sPageId(msRememberedPageId);
+
+    if (eProtocolTyp == INetProtocol::Http || eProtocolTyp == 
INetProtocol::Https || eProtocolTyp == INetProtocol::Ftp) {
+        sPageId = "internet";
+    } else if (eProtocolTyp == INetProtocol::Mailto) {
+        sPageId = "mail";
+    } else if (!comphelper::LibreOfficeKit::isActive() &&
+        (eProtocolTyp == INetProtocol::File || aStrURL.startsWith("#"))) {
+        sPageId = "document";
     }
 
-    ShowPage (sPageId);
+    IconChoicePage* pPage = GetTabPage(sPageId);
 
-    SvxHyperlinkTabPageBase* pCurrentPage = 
static_cast<SvxHyperlinkTabPageBase*>(GetTabPage( sPageId ));
+    // Switching to tab that doesn't exist should not crash
+    if (pPage == nullptr) { return; }
 
+    ShowPage (sPageId);
     mbIsHTMLDoc = (pItem->GetInsertMode() & HLINK_HTMLMODE) != 0;
 
-    IconChoicePage* pPage = GetTabPage (sPageId);
-    if(pPage)
-    {
-        SfxItemSet& aPageSet = const_cast<SfxItemSet&>(pPage->GetItemSet ());
-        aPageSet.Put ( *pItem );
+    SfxItemSet& aPageSet = const_cast<SfxItemSet&>(pPage->GetItemSet ());
+    aPageSet.Put ( *pItem );
 
-        pCurrentPage->Reset( aPageSet );
+    for (std::unique_ptr<IconChoicePageData>& page: maPageList) {
+        page->xPage->Reset(*pSet);
     }
 }
 
diff --git a/cui/source/inc/cuihyperdlg.hxx b/cui/source/inc/cuihyperdlg.hxx
index 8423d8c49759..0f2e8f1ab4bd 100644
--- a/cui/source/inc/cuihyperdlg.hxx
+++ b/cui/source/inc/cuihyperdlg.hxx
@@ -99,8 +99,7 @@ private:
     DECL_LINK (ClickOkHdl_Impl, weld::Button&, void );
     DECL_LINK (ClickApplyHdl_Impl, weld::Button&, void );
 
-    IconChoicePage*         GetTabPage( std::u16string_view rPageId )
-                                { return GetPageData(rPageId)->xPage.get(); }
+    IconChoicePage* GetTabPage( std::u16string_view rPageId );
 
     void                    ActivatePageImpl ();
     void                    DeActivatePageImpl ();

Reply via email to