diff options
author | Caolán McNamara <caolan.mcnamara@collabora.com> | 2024-06-10 12:41:14 +0100 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.com> | 2024-06-11 09:34:53 +0200 |
commit | 3693180fd7ce9520faa07f71e71ddaa4fa4e27b0 (patch) | |
tree | 355543955bb6d59c5e553232b1c6ab9d44c1fa46 | |
parent | f5ffa3567628033f2824dbebe107e1df339847fc (diff) |
Resolves: tdf#161430 reindex the correct style if there are duplicate names
and
Related: tdf#161430 add test case to guard against its return
Change-Id: I6d4e96faef3ec6caa038edf7595f91f20d964807
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/168479
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
(cherry picked from commit 9fa0b6977ba8292bfcc313caf080733090974c3f)
Change-Id: Ia2b12ab696632a4f08fd4c20472646dcfd9058c6
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/168636
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
-rw-r--r-- | include/svl/IndexedStyleSheets.hxx | 2 | ||||
-rw-r--r-- | include/svl/style.hxx | 1 | ||||
-rw-r--r-- | sd/qa/unit/data/odp/tdf161430.odp | bin | 0 -> 109149 bytes | |||
-rw-r--r-- | sd/qa/unit/import-tests2.cxx | 23 | ||||
-rw-r--r-- | svl/source/items/IndexedStyleSheets.cxx | 16 | ||||
-rw-r--r-- | svl/source/items/style.cxx | 36 |
6 files changed, 63 insertions, 15 deletions
diff --git a/include/svl/IndexedStyleSheets.hxx b/include/svl/IndexedStyleSheets.hxx index 910acd9e2566..4904d5346a94 100644 --- a/include/svl/IndexedStyleSheets.hxx +++ b/include/svl/IndexedStyleSheets.hxx @@ -144,6 +144,8 @@ public: void Clear(StyleSheetDisposer& cleanup); void Reindex(); + void ReindexOnNameChange(const SfxStyleSheetBase& style, const OUString& rOldName, + const OUString& rNewName); /** Warning: counting for n starts at 0, i.e., the 0th style sheet is the first that is found. */ SfxStyleSheetBase* GetNthStyleSheetThatMatchesPredicate(sal_Int32 n, diff --git a/include/svl/style.hxx b/include/svl/style.hxx index fc12dc0be74e..eeab434dc45b 100644 --- a/include/svl/style.hxx +++ b/include/svl/style.hxx @@ -275,6 +275,7 @@ public: virtual SfxStyleSheetBase* Find( const OUString&, SfxStyleFamily eFam, SfxStyleSearchBits n=SfxStyleSearchBits::All ); void Reindex(); + void ReindexOnNameChange(const SfxStyleSheetBase& style, const OUString& rOldName, const OUString& rNewName); /** Add a style sheet. * Not an actual public function. Do not call it from non-subclasses. */ diff --git a/sd/qa/unit/data/odp/tdf161430.odp b/sd/qa/unit/data/odp/tdf161430.odp Binary files differnew file mode 100644 index 000000000000..1ac9acac85b6 --- /dev/null +++ b/sd/qa/unit/data/odp/tdf161430.odp diff --git a/sd/qa/unit/import-tests2.cxx b/sd/qa/unit/import-tests2.cxx index 0224d01032be..43d1a2d1c099 100644 --- a/sd/qa/unit/import-tests2.cxx +++ b/sd/qa/unit/import-tests2.cxx @@ -58,6 +58,9 @@ #include <sfx2/linkmgr.hxx> #include <vcl/BitmapReadAccess.hxx> #include <vcl/dibtools.hxx> +#include <sdresid.hxx> +#include <stlpool.hxx> +#include <strings.hrc> using namespace ::com::sun::star; @@ -1982,6 +1985,26 @@ CPPUNIT_TEST_FIXTURE(SdImportTest2, testMasterSlides) CPPUNIT_ASSERT_EQUAL(sal_Int32(7), xMasterPages->getCount()); } +CPPUNIT_TEST_FIXTURE(SdImportTest2, testTdf161430) +{ + // Without the bug fix this opens with the classic solid 'blue' background used in "Outline 1" + // as seen in slide 3 + createSdImpressDoc("odp/tdf161430.odp"); + SdXImpressDocument* pXImpressDocument = dynamic_cast<SdXImpressDocument*>(mxComponent.get()); + CPPUNIT_ASSERT(pXImpressDocument); + SdDrawDocument* pDoc = pXImpressDocument->GetDoc(); + + SdStyleSheetPool* const pPool(pDoc->GetSdStyleSheetPool()); + + OUString aStyleName(SdResId(STR_PSEUDOSHEET_OUTLINE) + " 1"); + SfxStyleSheetBase* pStyleSheet = pPool->Find(aStyleName, SfxStyleFamily::Pseudo); + CPPUNIT_ASSERT(pStyleSheet); + + const XFillStyleItem& rFillStyle = pStyleSheet->GetItemSet().Get(XATTR_FILLSTYLE); + drawing::FillStyle eXFS = rFillStyle.GetValue(); + CPPUNIT_ASSERT_EQUAL(drawing::FillStyle_NONE, eXFS); +} + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svl/source/items/IndexedStyleSheets.cxx b/svl/source/items/IndexedStyleSheets.cxx index 57e2dddbf1c1..90df6beb4fb4 100644 --- a/svl/source/items/IndexedStyleSheets.cxx +++ b/svl/source/items/IndexedStyleSheets.cxx @@ -83,6 +83,22 @@ sal_Int32 IndexedStyleSheets::GetNumberOfStyleSheets() const } void +IndexedStyleSheets::ReindexOnNameChange(const SfxStyleSheetBase& style, const OUString& rOldName, const OUString& rNewName) +{ + std::pair<MapType::const_iterator, MapType::const_iterator> range = mPositionsByName.equal_range(rOldName); + for (MapType::const_iterator it = range.first; it != range.second; ++it) + { + if (mStyleSheets[it->second].get() == &style) + { + unsigned nPos = it->second; + mPositionsByName.erase(it); + mPositionsByName.insert(std::make_pair(rNewName, nPos)); + break; + } + } +} + +void IndexedStyleSheets::AddStyleSheet(const rtl::Reference< SfxStyleSheetBase >& style) { if (!HasStyleSheet(style)) { diff --git a/svl/source/items/style.cxx b/svl/source/items/style.cxx index 41551e506498..916b1621b4f0 100644 --- a/svl/source/items/style.cxx +++ b/svl/source/items/style.cxx @@ -163,24 +163,24 @@ bool SfxStyleSheetBase::SetName(const OUString& rName, bool bReIndexNow) if(rName.isEmpty()) return false; - if( aName != rName ) - { - OUString aOldName = aName; - SfxStyleSheetBase *pOther = m_pPool->Find( rName, nFamily ) ; - if ( pOther && pOther != this ) - return false; + if( aName == rName ) + return true; - if ( !aName.isEmpty() ) - m_pPool->ChangeParent(aName, rName, nFamily, false); + OUString aOldName = aName; + SfxStyleSheetBase *pOther = m_pPool->Find( rName, nFamily ) ; + if ( pOther && pOther != this ) + return false; - if ( aFollow == aName ) - aFollow = rName; - aName = rName; - if (bReIndexNow) - m_pPool->Reindex(); + if ( !aName.isEmpty() ) + m_pPool->ChangeParent(aName, rName, nFamily, false); - m_pPool->Broadcast( SfxStyleSheetModifiedHint( aOldName, *this ) ); - } + if ( aFollow == aName ) + aFollow = rName; + aName = rName; + if (bReIndexNow) + m_pPool->ReindexOnNameChange(*this, aOldName, rName); + + m_pPool->Broadcast( SfxStyleSheetModifiedHint( aOldName, *this ) ); return true; } @@ -890,6 +890,12 @@ SfxStyleSheetBasePool::Reindex() pImpl->mxIndexedStyleSheets->Reindex(); } +void +SfxStyleSheetBasePool::ReindexOnNameChange(const SfxStyleSheetBase& style, const OUString& rOldName, const OUString& rNewName) +{ + pImpl->mxIndexedStyleSheets->ReindexOnNameChange(style, rOldName, rNewName); +} + const svl::IndexedStyleSheets& SfxStyleSheetBasePool::GetIndexedStyleSheets() const { |