sd/qa/unit/uiimpress.cxx | 15 +++++++++++++++ sd/source/ui/view/drviews2.cxx | 34 ++++++++++++++++++---------------- 2 files changed, 33 insertions(+), 16 deletions(-)
New commits: commit c09eb0f74c0a110e4a4cfc4783b59883aad30475 Author: Miklos Vajna <vmik...@collabora.com> AuthorDate: Wed Jun 29 08:55:17 2022 +0200 Commit: Miklos Vajna <vmik...@collabora.com> CommitDate: Wed Jun 29 12:33:34 2022 +0200 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 <vmik...@collabora.com> Tested-by: Jenkins diff --git a/sd/qa/unit/uiimpress.cxx b/sd/qa/unit/uiimpress.cxx index 2433d7c4cb73..b309b4e4754f 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 d7a6bc6a2c78..39f5458bfcd6 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()); - } - 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()); + 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); } - pArgs->Put(aColorItem); } } }