sd/inc/stlsheet.hxx | 3 sd/qa/unit/misc-tests.cxx | 34 +++++++++++ sd/source/core/stlsheet.cxx | 136 +++++++++++++++++++++++++++----------------- 3 files changed, 122 insertions(+), 51 deletions(-)
New commits: commit 47bd52d8657673f5310c85d2912c3dd2f3adf125 Author: Mike Kaganski <mike.kagan...@collabora.com> Date: Sun May 27 14:02:09 2018 +0300 tdf#38225: update API name when renaming using a base class ref ... but don't update it in case it's a predefined API name Change-Id: I20075a4e085bdeab8374860c16e7eb2a72772c33 Reviewed-on: https://gerrit.libreoffice.org/54879 Tested-by: Jenkins <c...@libreoffice.org> Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com> Reviewed-on: https://gerrit.libreoffice.org/54985 Tested-by: Mike Kaganski <mike.kagan...@collabora.com> Reviewed-on: https://gerrit.libreoffice.org/55021 diff --git a/sd/inc/stlsheet.hxx b/sd/inc/stlsheet.hxx index a57f3fe9c187..f775e9995913 100644 --- a/sd/inc/stlsheet.hxx +++ b/sd/inc/stlsheet.hxx @@ -82,6 +82,9 @@ public: static void BroadcastSdStyleSheetChange(SfxStyleSheetBase* pStyleSheet, PresentationObjects ePO, SfxStyleSheetBasePool* pSSPool); + // SfxStyleSheetBase + virtual bool SetName(const OUString& rNewName, bool bReindexNow = true) override; + // XInterface virtual void SAL_CALL release( ) throw () override; diff --git a/sd/qa/unit/misc-tests.cxx b/sd/qa/unit/misc-tests.cxx index 046e97f20525..c50f731da234 100644 --- a/sd/qa/unit/misc-tests.cxx +++ b/sd/qa/unit/misc-tests.cxx @@ -53,6 +53,7 @@ public: void testTdf99396(); void testTdf99396TextEdit(); void testTdf44774(); + void testTdf38225(); CPPUNIT_TEST_SUITE(SdMiscTest); CPPUNIT_TEST(testTdf96206); @@ -60,6 +61,7 @@ public: CPPUNIT_TEST(testTdf99396); CPPUNIT_TEST(testTdf99396TextEdit); CPPUNIT_TEST(testTdf44774); + CPPUNIT_TEST(testTdf38225); CPPUNIT_TEST_SUITE_END(); private: @@ -285,6 +287,38 @@ void SdMiscTest::testTdf44774() CPPUNIT_ASSERT_EQUAL(OUString("StyleA"), pStyle->GetParent()); } +void SdMiscTest::testTdf38225() +{ + sd::DrawDocShellRef xDocShRef = new sd::DrawDocShell(SfxObjectCreateMode::EMBEDDED, false, + DocumentType::Draw); + const uno::Reference<frame::XLoadable> xLoadable(xDocShRef->GetModel(), uno::UNO_QUERY_THROW); + xLoadable->initNew(); + SfxStyleSheetBasePool* pSSPool = xDocShRef->GetStyleSheetPool(); + + // Create a new style with a name + pSSPool->Make("StyleWithName1", SfxStyleFamily::Para, SFXSTYLEBIT_USERDEF); + + // Now save the file and reload + xDocShRef = saveAndReload(xDocShRef.get(), ODG); + pSSPool = xDocShRef->GetStyleSheetPool(); + + SfxStyleSheetBase* pStyle = pSSPool->Find("StyleWithName1", SfxStyleFamily::Para); + CPPUNIT_ASSERT(pStyle); + + // Rename the style + CPPUNIT_ASSERT(pStyle->SetName("StyleWithName2")); + + // Save the file and reload again + xDocShRef = saveAndReload(xDocShRef.get(), ODG); + pSSPool = xDocShRef->GetStyleSheetPool(); + + // The problem was that the style kept the old name upon reloading + pStyle = pSSPool->Find("StyleWithName1", SfxStyleFamily::Para); + CPPUNIT_ASSERT(!pStyle); + pStyle = pSSPool->Find("StyleWithName2", SfxStyleFamily::Para); + CPPUNIT_ASSERT(pStyle); +} + CPPUNIT_TEST_SUITE_REGISTRATION(SdMiscTest); CPPUNIT_PLUGIN_IMPLEMENT(); diff --git a/sd/source/core/stlsheet.cxx b/sd/source/core/stlsheet.cxx index b3380370836f..2d44daba6356 100644 --- a/sd/source/core/stlsheet.cxx +++ b/sd/source/core/stlsheet.cxx @@ -611,59 +611,86 @@ bool SdStyleSheet::HasClearParentSupport() const return true; } -void SdStyleSheet::SetHelpId( const OUString& r, sal_uLong nId ) +namespace { - SfxStyleSheet::SetHelpId( r, nId ); +struct ApiNameMap +{ + const sal_Char* mpApiName; + sal_uInt32 mnApiNameLength; + sal_uInt32 mnHelpId; +} const pApiNameMap[] + = { { RTL_CONSTASCII_STRINGPARAM("title"), HID_PSEUDOSHEET_TITLE }, + { RTL_CONSTASCII_STRINGPARAM("subtitle"), HID_PSEUDOSHEET_SUBTITLE }, + { RTL_CONSTASCII_STRINGPARAM("background"), HID_PSEUDOSHEET_BACKGROUND }, + { RTL_CONSTASCII_STRINGPARAM("backgroundobjects"), HID_PSEUDOSHEET_BACKGROUNDOBJECTS }, + { RTL_CONSTASCII_STRINGPARAM("notes"), HID_PSEUDOSHEET_NOTES }, + { RTL_CONSTASCII_STRINGPARAM("standard"), HID_STANDARD_STYLESHEET_NAME }, + { RTL_CONSTASCII_STRINGPARAM("objectwitharrow"), HID_POOLSHEET_OBJWITHARROW }, + { RTL_CONSTASCII_STRINGPARAM("objectwithshadow"), HID_POOLSHEET_OBJWITHSHADOW }, + { RTL_CONSTASCII_STRINGPARAM("objectwithoutfill"), HID_POOLSHEET_OBJWITHOUTFILL }, + { RTL_CONSTASCII_STRINGPARAM("text"), HID_POOLSHEET_TEXT }, + { RTL_CONSTASCII_STRINGPARAM("textbody"), HID_POOLSHEET_TEXTBODY }, + { RTL_CONSTASCII_STRINGPARAM("textbodyjustfied"), HID_POOLSHEET_TEXTBODY_JUSTIFY }, + { RTL_CONSTASCII_STRINGPARAM("textbodyindent"), HID_POOLSHEET_TEXTBODY_INDENT }, + { RTL_CONSTASCII_STRINGPARAM("title"), HID_POOLSHEET_TITLE }, + { RTL_CONSTASCII_STRINGPARAM("title1"), HID_POOLSHEET_TITLE1 }, + { RTL_CONSTASCII_STRINGPARAM("title2"), HID_POOLSHEET_TITLE2 }, + { RTL_CONSTASCII_STRINGPARAM("headline"), HID_POOLSHEET_HEADLINE }, + { RTL_CONSTASCII_STRINGPARAM("headline1"), HID_POOLSHEET_HEADLINE1 }, + { RTL_CONSTASCII_STRINGPARAM("headline2"), HID_POOLSHEET_HEADLINE2 }, + { RTL_CONSTASCII_STRINGPARAM("measure"), HID_POOLSHEET_MEASURE }, + { nullptr, 0, 0 } }; + +OUString GetApiNameForHelpId(sal_uLong nId) +{ + if ((nId >= HID_PSEUDOSHEET_OUTLINE1) && (nId <= HID_PSEUDOSHEET_OUTLINE9)) + return "outline" + OUStringLiteral1('1' + (nId - HID_PSEUDOSHEET_OUTLINE1)); - if( (nId >= HID_PSEUDOSHEET_OUTLINE1) && ( nId <= HID_PSEUDOSHEET_OUTLINE9 ) ) + const ApiNameMap* p = pApiNameMap; + while (p->mpApiName) { - msApiName = "outline"; - msApiName += OUStringLiteral1( '1' + (nId - HID_PSEUDOSHEET_OUTLINE1) ); + if (nId == p->mnHelpId) + return OUString(p->mpApiName, p->mnApiNameLength, RTL_TEXTENCODING_ASCII_US); + ++p; } - else + + return OUString(); +} + +sal_uInt32 GetHelpIdForApiName(const OUString& sName) +{ + OUString sRest; + if (sName.startsWith("outline", &sRest)) { - static struct ApiNameMap + if (sRest.getLength() == 1) { - const sal_Char* mpApiName; - sal_uInt32 mnApiNameLength; - sal_uInt32 mnHelpId; - } - pApiNameMap[] = - { - { RTL_CONSTASCII_STRINGPARAM( "title" ), HID_PSEUDOSHEET_TITLE }, - { RTL_CONSTASCII_STRINGPARAM( "subtitle" ), HID_PSEUDOSHEET_SUBTITLE }, - { RTL_CONSTASCII_STRINGPARAM( "background" ), HID_PSEUDOSHEET_BACKGROUND }, - { RTL_CONSTASCII_STRINGPARAM( "backgroundobjects" ),HID_PSEUDOSHEET_BACKGROUNDOBJECTS }, - { RTL_CONSTASCII_STRINGPARAM( "notes" ), HID_PSEUDOSHEET_NOTES }, - { RTL_CONSTASCII_STRINGPARAM( "standard" ), HID_STANDARD_STYLESHEET_NAME }, - { RTL_CONSTASCII_STRINGPARAM( "objectwitharrow" ), HID_POOLSHEET_OBJWITHARROW }, - { RTL_CONSTASCII_STRINGPARAM( "objectwithshadow" ), HID_POOLSHEET_OBJWITHSHADOW }, - { RTL_CONSTASCII_STRINGPARAM( "objectwithoutfill" ),HID_POOLSHEET_OBJWITHOUTFILL }, - { RTL_CONSTASCII_STRINGPARAM( "text" ), HID_POOLSHEET_TEXT }, - { RTL_CONSTASCII_STRINGPARAM( "textbody" ), HID_POOLSHEET_TEXTBODY }, - { RTL_CONSTASCII_STRINGPARAM( "textbodyjustfied" ), HID_POOLSHEET_TEXTBODY_JUSTIFY }, - { RTL_CONSTASCII_STRINGPARAM( "textbodyindent" ), HID_POOLSHEET_TEXTBODY_INDENT }, - { RTL_CONSTASCII_STRINGPARAM( "title" ), HID_POOLSHEET_TITLE }, - { RTL_CONSTASCII_STRINGPARAM( "title1" ), HID_POOLSHEET_TITLE1 }, - { RTL_CONSTASCII_STRINGPARAM( "title2" ), HID_POOLSHEET_TITLE2 }, - { RTL_CONSTASCII_STRINGPARAM( "headline" ), HID_POOLSHEET_HEADLINE }, - { RTL_CONSTASCII_STRINGPARAM( "headline1" ), HID_POOLSHEET_HEADLINE1 }, - { RTL_CONSTASCII_STRINGPARAM( "headline2" ), HID_POOLSHEET_HEADLINE2 }, - { RTL_CONSTASCII_STRINGPARAM( "measure" ), HID_POOLSHEET_MEASURE }, - { nullptr, 0, 0 } - }; - - ApiNameMap* p = pApiNameMap; - while( p->mpApiName ) - { - if( nId == p->mnHelpId ) - { - msApiName = OUString( p->mpApiName, p->mnApiNameLength, RTL_TEXTENCODING_ASCII_US ); - break; - } - p++; + sal_Unicode ch = sRest.toChar(); + if ('1' <= ch && ch <= '9') + return HID_PSEUDOSHEET_OUTLINE1 + ch - '1'; } + // No other pre-defined names start with "outline" + return 0; } + + const ApiNameMap* p = pApiNameMap; + while (p->mpApiName) + { + if (sName.equalsAscii(p->mpApiName)) + return p->mnHelpId; + ++p; + } + + return 0; +} +} + +void SdStyleSheet::SetHelpId( const OUString& r, sal_uLong nId ) +{ + SfxStyleSheet::SetHelpId( r, nId ); + + const OUString sNewApiName = GetApiNameForHelpId(nId); + if (!sNewApiName.isEmpty()) + msApiName = sNewApiName; } OUString SdStyleSheet::GetFamilyString( SfxStyleFamily eFamily ) @@ -867,6 +894,18 @@ Sequence< OUString > SAL_CALL SdStyleSheet::getSupportedServiceNames() throw(Run return aNameSequence; } +bool SdStyleSheet::SetName(const OUString& rNewName, bool bReindexNow) +{ + const bool bResult = SfxUnoStyleSheet::SetName(rNewName, bReindexNow); + // Don't overwrite predefined API names + if (bResult && GetHelpIdForApiName(msApiName) == 0) + { + msApiName = rNewName; + Broadcast(SfxHint(SFX_HINT_DATACHANGED)); + } + return bResult; +} + // XNamed OUString SAL_CALL SdStyleSheet::getName() throw(RuntimeException, std::exception) { @@ -879,12 +918,7 @@ void SAL_CALL SdStyleSheet::setName( const OUString& rName ) throw(RuntimeExcep { SolarMutexGuard aGuard; throwIfDisposed(); - - if( SetName( rName ) ) - { - msApiName = rName; - Broadcast(SfxHint(SFX_HINT_DATACHANGED)); - } + SetName(rName); } // XStyle _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits