tdf#149748 sd theme: fix crash on selecting none from color bar
Opening Impress, going to view -> color bar to enable it and then
clicking on "none" resulted in a crash.
This went wrong in commit f5db3b12ae1cd3bfe6ee5d260aec9532cc65f2dc (sd
theme: add UI (sidebar) for shape fill color, 2022-04-06), where I
assumed that in case the slot is a SID_ATTR_FILL_COLOR, then its item
set also has a SID_ATTR_FILL_COLOR key. This is usually true, but not in
case of "no color" (i.e. transparent).
Fix the problem by just skipping theming metadata for such a color.
It seems to me that the color set of a theme is not allowed to contain
such "no color" colors, so this should be safe.
Change-Id: I3fb65548dca1d78631311de56c15fdb655b9645a
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/136599
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Tested-by: Jenkins
diff --git a/sd/qa/unit/uiimpress.cxx b/sd/qa/unit/uiimpress.cxx
index 2433d7c..b309b4e 100644
--- a/sd/qa/unit/uiimpress.cxx
+++ b/sd/qa/unit/uiimpress.cxx
@@ -1008,6 +1008,21 @@ CPPUNIT_TEST_FIXTURE(SdUiImpressTest, testFillColorTheme)
CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int16>(6000), nFillColorLumOff);
}
CPPUNIT_TEST_FIXTURE(SdUiImpressTest, testFillColorNoColor)
{
// Given an empty Impress document:
mxComponent = loadFromDesktop("private:factory/simpress",
"com.sun.star.presentation.PresentationDocument");
auto pImpressDocument = dynamic_cast<SdXImpressDocument*>(mxComponent.get());
sd::ViewShell* pViewShell = pImpressDocument->GetDocShell()->GetViewShell();
SfxDispatcher* pDispatcher = pViewShell->GetViewFrame()->GetDispatcher();
// When dispatching a fill color that only has a fill style (no color), then make sure we don't
// crash:
XFillStyleItem aXFillStyleItem(drawing::FillStyle_NONE);
pDispatcher->ExecuteList(SID_ATTR_FILL_COLOR, SfxCallMode::RECORD, { &aXFillStyleItem });
}
CPPUNIT_TEST_FIXTURE(SdUiImpressTest, testTdf127696)
{
mxComponent = loadFromDesktop("private:factory/simpress",
diff --git a/sd/source/ui/view/drviews2.cxx b/sd/source/ui/view/drviews2.cxx
index d7a6bc6..39f5458 100644
--- a/sd/source/ui/view/drviews2.cxx
+++ b/sd/source/ui/view/drviews2.cxx
@@ -599,24 +599,26 @@ public:
{
// Merge the color parameters to the color itself.
const XFillColorItem* pColorItem = static_cast<const XFillColorItem*>(pArgs->GetItem(SID_ATTR_FILL_COLOR));
assert(pColorItem);
XFillColorItem aColorItem(*pColorItem);
if (pArgs->GetItemState(SID_ATTR_COLOR_THEME_INDEX, false, &pItem) == SfxItemState::SET)
if (pColorItem)
{
auto pIntItem = static_cast<const SfxInt16Item*>(pItem);
aColorItem.GetThemeColor().SetThemeIndex(pIntItem->GetValue());
XFillColorItem aColorItem(*pColorItem);
if (pArgs->GetItemState(SID_ATTR_COLOR_THEME_INDEX, false, &pItem) == SfxItemState::SET)
{
auto pIntItem = static_cast<const SfxInt16Item*>(pItem);
aColorItem.GetThemeColor().SetThemeIndex(pIntItem->GetValue());
}
if (pArgs->GetItemState(SID_ATTR_COLOR_LUM_MOD, false, &pItem) == SfxItemState::SET)
{
auto pIntItem = static_cast<const SfxInt16Item*>(pItem);
aColorItem.GetThemeColor().SetLumMod(pIntItem->GetValue());
}
if (pArgs->GetItemState(SID_ATTR_COLOR_LUM_OFF, false, &pItem) == SfxItemState::SET)
{
auto pIntItem = static_cast<const SfxInt16Item*>(pItem);
aColorItem.GetThemeColor().SetLumOff(pIntItem->GetValue());
}
pArgs->Put(aColorItem);
}
if (pArgs->GetItemState(SID_ATTR_COLOR_LUM_MOD, false, &pItem) == SfxItemState::SET)
{
auto pIntItem = static_cast<const SfxInt16Item*>(pItem);
aColorItem.GetThemeColor().SetLumMod(pIntItem->GetValue());
}
if (pArgs->GetItemState(SID_ATTR_COLOR_LUM_OFF, false, &pItem) == SfxItemState::SET)
{
auto pIntItem = static_cast<const SfxInt16Item*>(pItem);
aColorItem.GetThemeColor().SetLumOff(pIntItem->GetValue());
}
pArgs->Put(aColorItem);
}
}
}