sd/qa/unit/uiimpress.cxx | 15 +++++++++++++++ sd/source/ui/view/drviews2.cxx | 35 +++++++++++++++++++---------------- 2 files changed, 34 insertions(+), 16 deletions(-)
New commits: commit 424fc806a0b96343bec8c74aef7dfc14eda2618d Author: Miklos Vajna <vmik...@collabora.com> AuthorDate: Wed Jun 29 08:55:17 2022 +0200 Commit: Miklos Vajna <vmik...@collabora.com> CommitDate: Mon Jul 4 08:10:26 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. (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 <jenkinscollaboraoff...@gmail.com> Reviewed-by: Miklos Vajna <vmik...@collabora.com> 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); } } } commit b16f2e3a39255dcb3e8cb064c81f6d2b33efb9cb Author: Caolán McNamara <caol...@redhat.com> AuthorDate: Sun Apr 10 14:20:11 2022 +0100 Commit: Miklos Vajna <vmik...@collabora.com> CommitDate: Mon Jul 4 08:10:08 2022 +0200 cid#1503836 silence Dereference null return value (cherry picked from commit 64046625553ecbfd9fe0661e5b6f48e283a909e0) Change-Id: I11dae0872d1f4add67b59ffd9696134c1dd2dbea Reviewed-on: https://gerrit.libreoffice.org/c/core/+/136750 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com> Reviewed-by: Miklos Vajna <vmik...@collabora.com> diff --git a/sd/source/ui/view/drviews2.cxx b/sd/source/ui/view/drviews2.cxx index 9918368dda65..02a3e3364c1c 100644 --- a/sd/source/ui/view/drviews2.cxx +++ b/sd/source/ui/view/drviews2.cxx @@ -597,8 +597,9 @@ public: if (nSlot == SID_ATTR_FILL_COLOR) { // Merge the color parameters to the color itself. - XFillColorItem aColorItem( - *static_cast<const XFillColorItem*>(pArgs->GetItem(SID_ATTR_FILL_COLOR))); + 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) { auto pIntItem = static_cast<const SfxInt16Item*>(pItem);