[Libreoffice-commits] core.git: Branch 'distro/collabora/cp-6.0' - sd/inc sd/qa sd/source

Mike Kaganski mike.kaganski at collabora.com
Tue May 29 07:23:18 UTC 2018


 sd/inc/stlsheet.hxx         |    3 +
 sd/qa/unit/misc-tests.cxx   |   34 +++++++++++
 sd/source/core/stlsheet.cxx |  126 ++++++++++++++++++++++++++------------------
 3 files changed, 114 insertions(+), 49 deletions(-)

New commits:
commit cc1a43017912324909aca7812e1619d337362bbc
Author: Mike Kaganski <mike.kaganski at 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 <ci at libreoffice.org>
    Reviewed-by: Mike Kaganski <mike.kaganski at collabora.com>
    Reviewed-on: https://gerrit.libreoffice.org/54985
    Tested-by: Mike Kaganski <mike.kaganski at collabora.com>

diff --git a/sd/inc/stlsheet.hxx b/sd/inc/stlsheet.hxx
index a24a2b31cafc..4407c63b631b 100644
--- a/sd/inc/stlsheet.hxx
+++ b/sd/inc/stlsheet.hxx
@@ -81,6 +81,9 @@ public:
     static void BroadcastSdStyleSheetChange(SfxStyleSheetBase const * 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 e995d0146957..f0e493683737 100644
--- a/sd/qa/unit/misc-tests.cxx
+++ b/sd/qa/unit/misc-tests.cxx
@@ -62,6 +62,7 @@ public:
     void testTdf99396TextEdit();
     void testFillGradient();
     void testTdf44774();
+    void testTdf38225();
 
     CPPUNIT_TEST_SUITE(SdMiscTest);
     CPPUNIT_TEST(testTdf96206);
@@ -70,6 +71,7 @@ public:
     CPPUNIT_TEST(testTdf99396TextEdit);
     CPPUNIT_TEST(testFillGradient);
     CPPUNIT_TEST(testTdf44774);
+    CPPUNIT_TEST(testTdf38225);
     CPPUNIT_TEST_SUITE_END();
 
 private:
@@ -328,6 +330,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 3cd669294b1a..585d0b6cbfae 100644
--- a/sd/source/core/stlsheet.cxx
+++ b/sd/source/core/stlsheet.cxx
@@ -580,55 +580,76 @@ bool SdStyleSheet::HasClearParentSupport() const
     return true;
 }
 
-void SdStyleSheet::SetHelpId( const OUString& r, sal_uLong nId )
+namespace
 {
-    SfxStyleSheet::SetHelpId( r, nId );
+struct ApiNameMap
+{
+    OUStringLiteral mpApiName;
+    sal_uInt32 mnHelpId;
+} const pApiNameMap[]
+    = { { OUStringLiteral("title"), HID_PSEUDOSHEET_TITLE },
+        { OUStringLiteral("subtitle"), HID_PSEUDOSHEET_SUBTITLE },
+        { OUStringLiteral("background"), HID_PSEUDOSHEET_BACKGROUND },
+        { OUStringLiteral("backgroundobjects"), HID_PSEUDOSHEET_BACKGROUNDOBJECTS },
+        { OUStringLiteral("notes"), HID_PSEUDOSHEET_NOTES },
+        { OUStringLiteral("standard"), HID_STANDARD_STYLESHEET_NAME },
+        { OUStringLiteral("objectwitharrow"), HID_POOLSHEET_OBJWITHARROW },
+        { OUStringLiteral("objectwithshadow"), HID_POOLSHEET_OBJWITHSHADOW },
+        { OUStringLiteral("objectwithoutfill"), HID_POOLSHEET_OBJWITHOUTFILL },
+        { OUStringLiteral("text"), HID_POOLSHEET_TEXT },
+        { OUStringLiteral("textbody"), HID_POOLSHEET_TEXTBODY },
+        { OUStringLiteral("textbodyjustfied"), HID_POOLSHEET_TEXTBODY_JUSTIFY },
+        { OUStringLiteral("textbodyindent"), HID_POOLSHEET_TEXTBODY_INDENT },
+        { OUStringLiteral("title"), HID_POOLSHEET_TITLE },
+        { OUStringLiteral("title1"), HID_POOLSHEET_TITLE1 },
+        { OUStringLiteral("title2"), HID_POOLSHEET_TITLE2 },
+        { OUStringLiteral("headline"), HID_POOLSHEET_HEADLINE },
+        { OUStringLiteral("headline1"), HID_POOLSHEET_HEADLINE1 },
+        { OUStringLiteral("headline2"), HID_POOLSHEET_HEADLINE2 },
+        { OUStringLiteral("measure"), HID_POOLSHEET_MEASURE } };
+
+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 ) )
-    {
-        msApiName = "outline";
-        msApiName += OUStringLiteral1( '1' + (nId - HID_PSEUDOSHEET_OUTLINE1) );
-    }
-    else
+    for (const auto& i : pApiNameMap)
+        if (nId == i.mnHelpId)
+            return i.mpApiName;
+
+    return OUString();
+}
+
+sal_uInt32 GetHelpIdForApiName(const OUString& sName)
+{
+    OUString sRest;
+    if (sName.startsWith("outline", &sRest))
     {
-        static struct ApiNameMap
+        if (sRest.getLength() == 1)
         {
-            OUStringLiteral mpApiName;
-            sal_uInt32      mnHelpId;
-        }
-        const pApiNameMap[] =
-        {
-            { OUStringLiteral("title"),            HID_PSEUDOSHEET_TITLE },
-            { OUStringLiteral("subtitle"),         HID_PSEUDOSHEET_SUBTITLE },
-            { OUStringLiteral("background"),       HID_PSEUDOSHEET_BACKGROUND },
-            { OUStringLiteral("backgroundobjects"),HID_PSEUDOSHEET_BACKGROUNDOBJECTS },
-            { OUStringLiteral("notes"),            HID_PSEUDOSHEET_NOTES },
-            { OUStringLiteral("standard"),         HID_STANDARD_STYLESHEET_NAME },
-            { OUStringLiteral("objectwitharrow"),  HID_POOLSHEET_OBJWITHARROW },
-            { OUStringLiteral("objectwithshadow"), HID_POOLSHEET_OBJWITHSHADOW },
-            { OUStringLiteral("objectwithoutfill"),HID_POOLSHEET_OBJWITHOUTFILL },
-            { OUStringLiteral("text"),             HID_POOLSHEET_TEXT },
-            { OUStringLiteral("textbody"),         HID_POOLSHEET_TEXTBODY },
-            { OUStringLiteral("textbodyjustfied"), HID_POOLSHEET_TEXTBODY_JUSTIFY },
-            { OUStringLiteral("textbodyindent"),   HID_POOLSHEET_TEXTBODY_INDENT },
-            { OUStringLiteral("title"),            HID_POOLSHEET_TITLE },
-            { OUStringLiteral("title1"),           HID_POOLSHEET_TITLE1 },
-            { OUStringLiteral("title2"),           HID_POOLSHEET_TITLE2 },
-            { OUStringLiteral("headline"),         HID_POOLSHEET_HEADLINE },
-            { OUStringLiteral("headline1"),        HID_POOLSHEET_HEADLINE1 },
-            { OUStringLiteral("headline2"),        HID_POOLSHEET_HEADLINE2 },
-            { OUStringLiteral("measure"),          HID_POOLSHEET_MEASURE }
-        };
-
-        for (std::size_t i = 0; i != SAL_N_ELEMENTS(pApiNameMap); ++i)
-        {
-            if( nId == pApiNameMap[i].mnHelpId )
-            {
-                msApiName = pApiNameMap[i].mpApiName;
-                break;
-            }
+            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;
     }
+
+    for (const auto& i : pApiNameMap)
+        if (sName == i.mpApiName)
+            return i.mnHelpId;
+
+    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 )
@@ -828,6 +849,18 @@ Sequence< OUString > SAL_CALL SdStyleSheet::getSupportedServiceNames()
     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(SfxHintId::DataChanged));
+    }
+    return bResult;
+}
+
 // XNamed
 OUString SAL_CALL SdStyleSheet::getName()
 {
@@ -840,12 +873,7 @@ void SAL_CALL SdStyleSheet::setName( const OUString& rName  )
 {
     SolarMutexGuard aGuard;
     throwIfDisposed();
-
-    if( SetName( rName ) )
-    {
-        msApiName = rName;
-        Broadcast(SfxHint(SfxHintId::DataChanged));
-    }
+    SetName(rName);
 }
 
 // XStyle


More information about the Libreoffice-commits mailing list