docmodel/source/theme/Theme.cxx                      |   75 +++++++++----------
 sd/source/ui/slidesorter/controller/SlsClipboard.cxx |   15 +++
 2 files changed, 51 insertions(+), 39 deletions(-)

New commits:
commit 44f49131facf53632c6da66eb8ce2fdef734cb1d
Author:     Mike Kaganski <[email protected]>
AuthorDate: Sun Jun 15 23:27:55 2025 +0500
Commit:     Xisco Fauli <[email protected]>
CommitDate: Mon Jun 16 14:47:04 2025 +0200

    tdf#167023: only try PasteSlidesFromSystemClipboard with correct descriptor
    
    PasteSlidesFromSystemClipboard seems to have some serious side effects,
    making following paste of different flavors fail. So check the object
    descriptor, which allows to avoid the problematic code for non-Impress
    objects. This also improves performance. But the underlying problem is
    not fixed here.
    
    Change-Id: I3c58c502900eb7c76b08b77945049bfa6a149182
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/186526
    Reviewed-by: Mike Kaganski <[email protected]>
    Tested-by: Jenkins
    Signed-off-by: Xisco Fauli <[email protected]>
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/186550

diff --git a/sd/source/ui/slidesorter/controller/SlsClipboard.cxx 
b/sd/source/ui/slidesorter/controller/SlsClipboard.cxx
index 9661e98b0945..1ded3c5ab719 100644
--- a/sd/source/ui/slidesorter/controller/SlsClipboard.cxx
+++ b/sd/source/ui/slidesorter/controller/SlsClipboard.cxx
@@ -73,6 +73,7 @@
 #include <rtl/ustring.hxx>
 #include <vcl/svapp.hxx>
 
+#include <comphelper/classids.hxx>
 #include <comphelper/storagehelper.hxx>
 
 using namespace ::com::sun::star;
@@ -950,6 +951,20 @@ bool Clipboard::PasteSlidesFromSystemClipboard()
     TransferableDataHelper aDataHelper(
         
TransferableDataHelper::CreateFromSystemClipboard(pDrawViewShell->GetActiveWindow()));
 
+    {
+        // Only attempt to load EMBED_SOURCE, if its descriptor is correct
+        if (!aDataHelper.HasFormat(SotClipboardFormatId::OBJECTDESCRIPTOR))
+            return false;
+
+        TransferableObjectDescriptor aObjDesc;
+        if 
(!aDataHelper.GetTransferableObjectDescriptor(SotClipboardFormatId::OBJECTDESCRIPTOR,
+                                                         aObjDesc))
+            return false;
+
+        if (aObjDesc.maClassName != SvGlobalName(SO3_SIMPRESS_CLASSID))
+            return false;
+    }
+
     SdDrawDocument* pDocument = mrSlideSorter.GetModel().GetDocument();
     assert(pDocument);
     OUString aDocShellID = 
SfxObjectShell::CreateShellID(pDocument->GetDocSh());
commit 90dec68c914aed6529ce8bfde5b1df05bc74b6c6
Author:     Mike Kaganski <[email protected]>
AuthorDate: Sun Jun 15 15:40:48 2025 +0500
Commit:     Xisco Fauli <[email protected]>
CommitDate: Mon Jun 16 14:46:52 2025 +0200

    Related: tdf#167018 Generalize and deduplicate Theme::FromAny
    
    Let it also handle a hypothetical non-UnoTheme implementation (it
    is possible to create these e.g. from Basic / Python code). When
    handling it, use theme name as color set name (there seems to be
    no UNO API to get color set name?). And use the same code for the
    creation of Theme from PropertyValue list.
    
    The check that enumrange<ThemeColorType> does not iterate through
    ThemeColorType::Unknown is redundant, since that value is outside
    of [0, LAST] range.
    
    Change-Id: Iae6770f196011deeb2a92d3b64af514fb6a53d06
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/186513
    Reviewed-by: Mike Kaganski <[email protected]>
    Tested-by: Jenkins
    Signed-off-by: Xisco Fauli <[email protected]>
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/186549

diff --git a/docmodel/source/theme/Theme.cxx b/docmodel/source/theme/Theme.cxx
index 55a39f2b6afd..63a6ce6843e3 100644
--- a/docmodel/source/theme/Theme.cxx
+++ b/docmodel/source/theme/Theme.cxx
@@ -18,6 +18,7 @@
 #include <sal/log.hxx>
 #include <sal/types.h>
 #include <o3tl/enumrange.hxx>
+#include <o3tl/underlyingenumvalue.hxx>
 #include <com/sun/star/util/Color.hpp>
 #include <com/sun/star/beans/PropertyValue.hpp>
 #include <com/sun/star/lang/IllegalArgumentException.hpp>
@@ -84,58 +85,54 @@ void Theme::ToAny(uno::Any& rVal) const
     rVal <<= aMap.getAsConstPropertyValueList();
 }
 
+static std::shared_ptr<model::ColorSet> makeColorSet(const OUString& name,
+                                                     const 
uno::Sequence<util::Color>& colors)
+{
+    auto colorset = std::make_shared<model::ColorSet>(name);
+    for (auto eThemeColorType : o3tl::enumrange<model::ThemeColorType>())
+    {
+        const size_t nIndex(o3tl::to_underlying(eThemeColorType));
+        if (nIndex >= colors.size())
+            break;
+        const Color aColor(ColorTransparency, colors[nIndex]);
+        colorset->add(eThemeColorType, aColor);
+    }
+    return colorset;
+}
+
 std::shared_ptr<Theme> Theme::FromAny(const uno::Any& rVal)
 {
     if (css::uno::Reference<css::util::XTheme> xTheme; rVal >>= xTheme)
     {
+        if (!xTheme)
+            return {};
+
         if (auto* pUnoTheme = dynamic_cast<UnoTheme*>(xTheme.get()))
             return pUnoTheme->getTheme();
-        else
-            throw css::lang::IllegalArgumentException();
+
+        auto pTheme = std::make_shared<Theme>(xTheme->getName());
+        if (auto aColors = xTheme->getColorSet(); aColors.hasElements())
+            pTheme->setColorSet(makeColorSet(xTheme->getName(), aColors)); // 
Reuse theme name
+        return pTheme;
     }
 
     comphelper::SequenceAsHashMap aMap(rVal);
-    std::shared_ptr<Theme> pTheme;
-    std::shared_ptr<model::ColorSet> pColorSet;
-
-    auto it = aMap.find(u"Name"_ustr);
-    if (it != aMap.end())
-    {
-        OUString aName;
-        it->second >>= aName;
-        pTheme = std::make_shared<Theme>(aName);
-    }
 
-    it = aMap.find(u"ColorSchemeName"_ustr);
-    if (it != aMap.end() && pTheme)
-    {
-        OUString aName;
-        it->second >>= aName;
-        pColorSet = std::make_shared<model::ColorSet>(aName);
-        pTheme->setColorSet(pColorSet);
-    }
+    OUString aThemeName;
+    if (auto it = aMap.find(u"Name"_ustr); it != aMap.end())
+        it->second >>= aThemeName;
+    else
+        return {};
+    auto pTheme = std::make_shared<Theme>(aThemeName);
 
-    it = aMap.find(u"ColorScheme"_ustr);
-    if (it != aMap.end() && pColorSet)
+    if (auto it = aMap.find(u"ColorSchemeName"_ustr); it != aMap.end())
     {
-        uno::Sequence<util::Color> aColors;
-        it->second >>= aColors;
+        OUString aColorSchemeName;
+        it->second >>= aColorSchemeName;
 
-        SAL_WARN_IF(aColors.size() > 12, "svx",
-                    "Theme::FromAny: number of colors greater than max theme 
colors supported");
-
-        for (auto eThemeColorType : o3tl::enumrange<model::ThemeColorType>())
-        {
-            if (eThemeColorType != model::ThemeColorType::Unknown)
-            {
-                size_t nIndex(static_cast<sal_Int16>(eThemeColorType));
-                if (nIndex < aColors.size())
-                {
-                    Color aColor(ColorTransparency, aColors[nIndex]);
-                    pColorSet->add(eThemeColorType, aColor);
-                }
-            }
-        }
+        pTheme->setColorSet(makeColorSet(
+            aColorSchemeName,
+            aMap.getUnpackedValueOrDefault(u"ColorScheme"_ustr, 
uno::Sequence<util::Color>{})));
     }
 
     return pTheme;

Reply via email to