vcl/inc/salvtables.hxx        |    3 ++
 vcl/source/app/salvtables.cxx |   57 ++++++++----------------------------------
 2 files changed, 15 insertions(+), 45 deletions(-)

New commits:
commit 36566e4b5fd161f8f3fe424f8483aa520f02aef1
Author:     Michael Weghorn <m.wegh...@posteo.de>
AuthorDate: Fri Jul 25 17:12:20 2025 +0200
Commit:     Michael Weghorn <m.wegh...@posteo.de>
CommitDate: Fri Jul 25 20:51:52 2025 +0200

    vcl: Deduplicate both SalInstanceIconView::insert variants
    
    Extract a helper method to reuse instead of implementing
    almost exactly the same logic twice.
    
    Change-Id: I5a09ff5146e595639dbb30eeb6b16a1fc6bde832
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/188357
    Tested-by: Jenkins
    Reviewed-by: Michael Weghorn <m.wegh...@posteo.de>

diff --git a/vcl/inc/salvtables.hxx b/vcl/inc/salvtables.hxx
index a1f1ca65eb16..5a000d1c31fa 100644
--- a/vcl/inc/salvtables.hxx
+++ b/vcl/inc/salvtables.hxx
@@ -1916,6 +1916,9 @@ private:
     DECL_LINK(TooltipHdl, SvTreeListEntry*, OUString);
     DECL_LINK(DumpImageHdl, const ::IconView::encoded_image_query&, bool);
 
+    void insert(int pos, const OUString* pStr, const OUString* pId, const 
Image& rImage,
+                weld::TreeIter* pRet);
+
 public:
     SalInstanceIconView(::IconView* pIconView, SalInstanceBuilder* pBuilder, 
bool bTakeOwnership);
 
diff --git a/vcl/source/app/salvtables.cxx b/vcl/source/app/salvtables.cxx
index d68de8b0bcd9..4cdde27397ff 100644
--- a/vcl/source/app/salvtables.cxx
+++ b/vcl/source/app/salvtables.cxx
@@ -5436,7 +5436,7 @@ void SalInstanceIconView::thaw()
 }
 
 void SalInstanceIconView::insert(int pos, const OUString* pStr, const 
OUString* pId,
-                                 const OUString* pIconName, weld::TreeIter* 
pRet)
+                                 const Image& rImage, weld::TreeIter* pRet)
 {
     disable_notify_events();
     auto nInsertPos = pos == -1 ? TREELIST_APPEND : pos;
@@ -5450,10 +5450,7 @@ void SalInstanceIconView::insert(int pos, const 
OUString* pStr, const OUString*
         pUserData = nullptr;
 
     SvTreeListEntry* pEntry = new SvTreeListEntry;
-    Image aImage;
-    if (pIconName)
-        aImage = createImage(*pIconName);
-    pEntry->AddItem(std::make_unique<SvLBoxContextBmp>(aImage, aImage, false));
+    pEntry->AddItem(std::make_unique<SvLBoxContextBmp>(rImage, rImage, false));
 
     if (pStr)
         pEntry->AddItem(std::make_unique<SvLBoxString>(*pStr));
@@ -5470,37 +5467,17 @@ void SalInstanceIconView::insert(int pos, const 
OUString* pStr, const OUString*
 }
 
 void SalInstanceIconView::insert(int pos, const OUString* pStr, const 
OUString* pId,
-                                 const BitmapEx* pIcon, weld::TreeIter* pRet)
+                                 const OUString* pIconName, weld::TreeIter* 
pRet)
 {
-    disable_notify_events();
-    auto nInsertPos = pos == -1 ? TREELIST_APPEND : pos;
-    void* pUserData;
-    if (pId)
-    {
-        m_aUserData.emplace_back(std::make_unique<OUString>(*pId));
-        pUserData = m_aUserData.back().get();
-    }
-    else
-        pUserData = nullptr;
-
-    SvTreeListEntry* pEntry = new SvTreeListEntry;
-
-    Image aImage;
-    if (pIcon)
-        aImage = Image(*pIcon);
-    pEntry->AddItem(std::make_unique<SvLBoxContextBmp>(aImage, aImage, false));
-    if (pStr)
-        pEntry->AddItem(std::make_unique<SvLBoxString>(*pStr));
-    pEntry->SetUserData(pUserData);
-    m_xIconView->Insert(pEntry, nullptr, nInsertPos);
-
-    if (pRet)
-    {
-        SalInstanceTreeIter* pVclRetIter = 
static_cast<SalInstanceTreeIter*>(pRet);
-        pVclRetIter->iter = pEntry;
-    }
+    const Image aImage = pIconName ? createImage(*pIconName) : Image();
+    insert(pos, pStr, pId, aImage, pRet);
+}
 
-    enable_notify_events();
+void SalInstanceIconView::insert(int pos, const OUString* pStr, const 
OUString* pId,
+                                 const BitmapEx* pIcon, weld::TreeIter* pRet)
+{
+    const Image aImage = pIcon ? Image(*pIcon) : Image();
+    insert(pos, pStr, pId, aImage, pRet);
 }
 
 void SalInstanceIconView::insert_separator(int pos, const OUString* /* pId */)
commit 9b4f72e5397f391f1f527992f6e754613f92dd8c
Author:     Michael Weghorn <m.wegh...@posteo.de>
AuthorDate: Fri Jul 25 17:06:58 2025 +0200
Commit:     Michael Weghorn <m.wegh...@posteo.de>
CommitDate: Fri Jul 25 20:51:41 2025 +0200

    vcl: Deduplicate SalInstanceIconView::insert code paths a bit
    
    This is also in preparation of extracting a helper
    for both SalInstanceIconView::insert variants that
    takes a const Image& param and can be called by both.
    
    Change-Id: Ic7b4f56cf0401c31d2a15f4e97909e78e8baf805
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/188356
    Reviewed-by: Michael Weghorn <m.wegh...@posteo.de>
    Tested-by: Jenkins

diff --git a/vcl/source/app/salvtables.cxx b/vcl/source/app/salvtables.cxx
index c20a3da2aa57..d68de8b0bcd9 100644
--- a/vcl/source/app/salvtables.cxx
+++ b/vcl/source/app/salvtables.cxx
@@ -5450,16 +5450,11 @@ void SalInstanceIconView::insert(int pos, const 
OUString* pStr, const OUString*
         pUserData = nullptr;
 
     SvTreeListEntry* pEntry = new SvTreeListEntry;
+    Image aImage;
     if (pIconName)
-    {
-        Image aImage(createImage(*pIconName));
-        pEntry->AddItem(std::make_unique<SvLBoxContextBmp>(aImage, aImage, 
false));
-    }
-    else
-    {
-        Image aDummy;
-        pEntry->AddItem(std::make_unique<SvLBoxContextBmp>(aDummy, aDummy, 
false));
-    }
+        aImage = createImage(*pIconName);
+    pEntry->AddItem(std::make_unique<SvLBoxContextBmp>(aImage, aImage, false));
+
     if (pStr)
         pEntry->AddItem(std::make_unique<SvLBoxString>(*pStr));
     pEntry->SetUserData(pUserData);
@@ -5489,16 +5484,11 @@ void SalInstanceIconView::insert(int pos, const 
OUString* pStr, const OUString*
         pUserData = nullptr;
 
     SvTreeListEntry* pEntry = new SvTreeListEntry;
+
+    Image aImage;
     if (pIcon)
-    {
-        Image aImage(*pIcon);
-        pEntry->AddItem(std::make_unique<SvLBoxContextBmp>(aImage, aImage, 
false));
-    }
-    else
-    {
-        Image aDummy;
-        pEntry->AddItem(std::make_unique<SvLBoxContextBmp>(aDummy, aDummy, 
false));
-    }
+        aImage = Image(*pIcon);
+    pEntry->AddItem(std::make_unique<SvLBoxContextBmp>(aImage, aImage, false));
     if (pStr)
         pEntry->AddItem(std::make_unique<SvLBoxString>(*pStr));
     pEntry->SetUserData(pUserData);

Reply via email to