diff options
author | Miklos Vajna <vmiklos@collabora.com> | 2022-06-29 08:55:17 +0200 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.com> | 2022-07-04 08:10:26 +0200 |
commit | 424fc806a0b96343bec8c74aef7dfc14eda2618d (patch) | |
tree | aa7e7e1c299b576206b3849143e5e31bcdcaa7a1 /sd | |
parent | b16f2e3a39255dcb3e8cb064c81f6d2b33efb9cb (diff) |
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.
(cherry picked from commit c09eb0f74c0a110e4a4cfc4783b59883aad30475)
Conflicts:
sd/qa/unit/uiimpress.cxx
Change-Id: I3fb65548dca1d78631311de56c15fdb655b9645a
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/136751
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Diffstat (limited to 'sd')
-rw-r--r-- | sd/qa/unit/uiimpress.cxx | 15 | ||||
-rw-r--r-- | sd/source/ui/view/drviews2.cxx | 34 |
2 files changed, 33 insertions, 16 deletions
diff --git a/sd/qa/unit/uiimpress.cxx b/sd/qa/unit/uiimpress.cxx index 9b58251ffc93..23fabc297d86 100644 --- a/sd/qa/unit/uiimpress.cxx +++ b/sd/qa/unit/uiimpress.cxx @@ -960,6 +960,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, testThemeShapeInsert) { // Given a document with a theme, accent1 color is set to 0x000004: diff --git a/sd/source/ui/view/drviews2.cxx b/sd/source/ui/view/drviews2.cxx index 02a3e3364c1c..5ca1f2d9c50a 100644 --- a/sd/source/ui/view/drviews2.cxx +++ b/sd/source/ui/view/drviews2.cxx @@ -598,24 +598,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); } } } |