include/svx/ColorSets.hxx       |   19 +++++++++++++++++++
 sd/qa/unit/uiimpress.cxx        |   40 ++++++++++++++++++++++++++++++++++++++++
 sd/source/ui/func/fuconstr.cxx  |   39 +++++++++++++++++++++++++++++++++++++++
 sd/source/ui/view/drviewse.cxx  |    5 +++++
 svx/sdi/svx.sdi                 |    2 +-
 svx/source/styles/ColorSets.cxx |   10 ++++++++++
 6 files changed, 114 insertions(+), 1 deletion(-)

New commits:
commit 1cbf5cec4b189c71a11d0cbf62eed229d882620a
Author:     Miklos Vajna <vmik...@collabora.com>
AuthorDate: Mon Jun 20 09:46:44 2022 +0200
Commit:     Miklos Vajna <vmik...@collabora.com>
CommitDate: Tue Jun 21 15:56:05 2022 +0200

    sd theme: consider accent1 color when inserting shape with solid fill
    
    Once a theme is defined for the master page of the current slide,
    PowerPoint inserts a shapes with their fill color & line color set based
    on that theme (so this color is master-page-specific), while Impress
    sets the fill & line color based on the default shape style.
    
    The Impress behavior has the benefit of doing the usual style-based
    formatting, but now a document-level style overwrites a
    (master-)slide-specific theme, which is inconsistent.
    
    Fix the problem by extending sd::FuConstruct::SetStyleSheet(): if we
    construct a shape with fill, then not only apply the style sheet, but
    also set the fill & line color based on the theme (if there is any).
    
    Note that this works both in case the shape is instantly created on
    click (LOK case) or when the user first draws a top-left -> bottom-right
    point pair to define the position / size of the shape. At the same time
    line colors don't support themes yet, so that color is just a plain value
    for now.
    
    Change-Id: Ic6ae8f91bd719bd80f2b56f12b001d29b0961e6e
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/136138
    Reviewed-by: Miklos Vajna <vmik...@collabora.com>
    Tested-by: Jenkins
    (cherry picked from commit 486810603fb3f84847bb549004ed0394a2e22d0b)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/136156

diff --git a/include/svx/ColorSets.hxx b/include/svx/ColorSets.hxx
index 07e24ee9302b..eace8ca2663c 100644
--- a/include/svx/ColorSets.hxx
+++ b/include/svx/ColorSets.hxx
@@ -69,6 +69,23 @@ public:
     const ColorSet& getColorSet(std::u16string_view rName);
 };
 
+/// Offsets into the color list of a theme.
+enum class ThemeColorType
+{
+    DK1 = 0,
+    LT1 = 1,
+    DK2 = 2,
+    LT2 = 3,
+    ACCENT1 = 4,
+    ACCENT2 = 5,
+    ACCENT3 = 6,
+    ACCENT4 = 7,
+    ACCENT5 = 8,
+    ACCENT6 = 9,
+    HLINK = 10,
+    FOLHLINK = 11,
+};
+
 /// A named theme has a named color set.
 class SVXCORE_DLLPUBLIC Theme
 {
@@ -94,6 +111,8 @@ public:
     void UpdateSdrPage(const SdrPage* pPage);
 
     std::vector<Color> GetColors() const;
+
+    Color GetColor(ThemeColorType eType) const;
 };
 
 } // end of namespace svx
diff --git a/sd/qa/unit/uiimpress.cxx b/sd/qa/unit/uiimpress.cxx
index f67d8fa32e4e..2433d7c4cb73 100644
--- a/sd/qa/unit/uiimpress.cxx
+++ b/sd/qa/unit/uiimpress.cxx
@@ -15,6 +15,8 @@
 #include <com/sun/star/uno/Reference.hxx>
 #include <com/sun/star/drawing/FillStyle.hpp>
 #include <com/sun/star/drawing/XDrawView.hpp>
+#include <com/sun/star/drawing/XDrawPage.hpp>
+#include <com/sun/star/drawing/XMasterPageTarget.hpp>
 #include <com/sun/star/frame/DispatchHelper.hpp>
 #include <com/sun/star/table/XMergeableCell.hpp>
 #include <com/sun/star/text/WritingMode2.hpp>
@@ -43,6 +45,7 @@
 #include <undo/undomanager.hxx>
 #include <vcl/scheduler.hxx>
 #include <comphelper/propertyvalue.hxx>
+#include <comphelper/sequenceashashmap.hxx>
 
 #include <ViewShell.hxx>
 #include <app.hrc>
@@ -1049,6 +1052,43 @@ CPPUNIT_TEST_FIXTURE(SdUiImpressTest, testTdf127696)
     CPPUNIT_ASSERT(bContoured);
 }
 
+CPPUNIT_TEST_FIXTURE(SdUiImpressTest, testThemeShapeInsert)
+{
+    // Given a document with a theme, accent1 color is set to 0x000004:
+    mxComponent = loadFromDesktop("private:factory/simpress",
+                                  
"com.sun.star.presentation.PresentationDocument");
+    uno::Reference<drawing::XDrawPagesSupplier> 
xDrawPagesSupplier(mxComponent, uno::UNO_QUERY);
+    uno::Reference<drawing::XDrawPage> 
xDrawPage(xDrawPagesSupplier->getDrawPages()->getByIndex(0),
+                                                 uno::UNO_QUERY);
+    uno::Reference<drawing::XMasterPageTarget> xMasterPageTarget(xDrawPage, 
uno::UNO_QUERY);
+    uno::Reference<beans::XPropertySet> 
xMasterPage(xMasterPageTarget->getMasterPage(),
+                                                    uno::UNO_QUERY);
+    comphelper::SequenceAsHashMap aMap;
+    aMap["Name"] <<= OUString("mytheme");
+    aMap["ColorSchemeName"] <<= OUString("mycolorscheme");
+    uno::Sequence<util::Color> aColorScheme
+        = { 0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, 0xb };
+    aMap["ColorScheme"] <<= aColorScheme;
+    uno::Any aTheme(aMap.getAsConstPropertyValueList());
+    xMasterPage->setPropertyValue("Theme", aTheme);
+
+    // When inserting a shape:
+    uno::Sequence<beans::PropertyValue> aArgs = {
+        comphelper::makePropertyValue("CreateDirectly", true),
+    };
+    dispatchCommand(mxComponent, ".uno:BasicShapes.round-rectangle", aArgs);
+
+    // Then make sure the that fill color of the last shape is the accent1 
color:
+    sal_Int32 nShapeIndex = xDrawPage->getCount() - 1;
+    uno::Reference<beans::XPropertySet> 
xShape(xDrawPage->getByIndex(nShapeIndex), uno::UNO_QUERY);
+    sal_Int32 nFillColor{};
+    xShape->getPropertyValue("FillColor") >>= nFillColor;
+    // Without the accompanying fix in place, this test would have failed with:
+    // - Expected: 0 / 0x000004 (~black)
+    // - Actual  : 7512015 / 0x729fcf (~blue)
+    CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(0x4), nFillColor);
+}
+
 CPPUNIT_PLUGIN_IMPLEMENT();
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sd/source/ui/func/fuconstr.cxx b/sd/source/ui/func/fuconstr.cxx
index a473a4558edd..9d6f363209f2 100644
--- a/sd/source/ui/func/fuconstr.cxx
+++ b/sd/source/ui/func/fuconstr.cxx
@@ -26,6 +26,9 @@
 #include <sfx2/dispatch.hxx>
 #include <sfx2/viewfrm.hxx>
 #include <tools/debug.hxx>
+#include <svx/xflclit.hxx>
+#include <svx/xlineit0.hxx>
+#include <svx/xlnclit.hxx>
 
 #include <app.hrc>
 #include <strings.hrc>
@@ -367,6 +370,42 @@ void FuConstruct::SetStyleSheet( SfxItemSet& rAttr, 
SdrObject* pObj,
                 pObj->SetMergedItemSet(aAttr);
             }
         }
+        else
+        {
+            // Creating an object with fill.
+            SdrPage* pThemePage = pPage;
+            if (pThemePage->TRG_HasMasterPage())
+            {
+                pThemePage = &pThemePage->TRG_GetMasterPage();
+            }
+
+            svx::Theme* pTheme = pThemePage->getSdrPageProperties().GetTheme();
+            if (pTheme)
+            {
+                // We construct an object on a page where the master page has 
a theme. Take the
+                // accent1 color from that theme, make sure it has priority 
over the shape's
+                // document-global style.
+                SfxItemSet aAttr(mpView->GetDefaultAttr());
+
+                aAttr.Put(XFillStyleItem(css::drawing::FillStyle_SOLID));
+
+                svx::ThemeColorType eColorType = svx::ThemeColorType::ACCENT1;
+                Color aColor = pTheme->GetColor(eColorType);
+                XFillColorItem aFillColorItem("", aColor);
+                
aFillColorItem.GetThemeColor().SetThemeIndex(static_cast<sal_Int16>(eColorType));
+                aAttr.Put(aFillColorItem);
+
+                aAttr.Put(XLineStyleItem(css::drawing::LineStyle_SOLID));
+
+                // Line color is 50% darker than the fill color.
+                aColor.ApplyTintOrShade(-5000);
+                XLineColorItem aLineColorItem("", aColor);
+                // TODO no theme or theme effect for line colors yet.
+                aAttr.Put(aLineColorItem);
+
+                pObj->SetMergedItemSet(aAttr);
+            }
+        }
     }
 }
 
diff --git a/sd/source/ui/view/drviewse.cxx b/sd/source/ui/view/drviewse.cxx
index 64e9e88b5396..309eb2b85a63 100644
--- a/sd/source/ui/view/drviewse.cxx
+++ b/sd/source/ui/view/drviewse.cxx
@@ -527,6 +527,11 @@ void DrawViewShell::FuPermanent(SfxRequest& rReq)
             rReq.Done();
 
             bCreateDirectly = comphelper::LibreOfficeKit::isActive();
+            const SfxItemSet* pArgs = rReq.GetArgs();
+            if (pArgs && pArgs->HasItem(FN_PARAM_1))
+            {
+                bCreateDirectly = static_cast<const 
SfxBoolItem&>(pArgs->Get(FN_PARAM_1)).GetValue();
+            }
 
             if ( nSId != SID_DRAW_CS_ID )
             {
diff --git a/svx/sdi/svx.sdi b/svx/sdi/svx.sdi
index 3c8a3642c04a..de7ef9914b4c 100644
--- a/svx/sdi/svx.sdi
+++ b/svx/sdi/svx.sdi
@@ -10512,7 +10512,7 @@ SfxVoidItem SbaBrwInsert SID_SBA_BRW_INSERT
 
 
 SfxStringItem BasicShapes SID_DRAWTBX_CS_BASIC
-(SfxStringItem BasicShapes SID_DRAWTBX_CS_BASIC)
+(SfxStringItem BasicShapes SID_DRAWTBX_CS_BASIC, SfxBoolItem CreateDirectly 
FN_PARAM_1)
 [
     AutoUpdate = TRUE,
     FastCall = FALSE,
diff --git a/svx/source/styles/ColorSets.cxx b/svx/source/styles/ColorSets.cxx
index 6b2db4831a22..240b65e2b10a 100644
--- a/svx/source/styles/ColorSets.cxx
+++ b/svx/source/styles/ColorSets.cxx
@@ -360,6 +360,16 @@ std::vector<Color> Theme::GetColors() const
     return aColors;
 }
 
+Color Theme::GetColor(ThemeColorType eType) const
+{
+    if (!mpColorSet)
+    {
+        return {};
+    }
+
+    return mpColorSet->getColor(static_cast<size_t>(eType));
+}
+
 } // end of namespace svx
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Reply via email to