[Libreoffice-commits] core.git: sw/inc sw/qa sw/source

Jakub Trzebiatowski ubap.dev at gmail.com
Thu May 26 19:01:09 UTC 2016


 sw/inc/tblafmt.hxx                  |    7 +
 sw/inc/unostyle.hxx                 |   29 ++++++++
 sw/qa/python/check_styles.py        |   38 ++++++----
 sw/source/core/unocore/unostyle.cxx |  129 ++++++++++++++++++++++++++++++++++--
 sw/source/uibase/app/docstyle.cxx   |    3 
 5 files changed, 186 insertions(+), 20 deletions(-)

New commits:
commit d4188f643db050c962a937547d19a9a08bd2235d
Author: Jakub Trzebiatowski <ubap.dev at gmail.com>
Date:   Tue May 24 16:44:19 2016 +0200

    Sw UNO API TableStyles getByName
    
    Implementing TableStyle family getByName, hasByName, getByIndex
    Implementing SwXTextTableStyle
    Implementing basic tests
    
    Change-Id: I256189db8631a713c4aae6b449409bbfaa776f24
    Reviewed-on: https://gerrit.libreoffice.org/25410
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Miklos Vajna <vmiklos at collabora.co.uk>

diff --git a/sw/inc/tblafmt.hxx b/sw/inc/tblafmt.hxx
index f98067a..73c1f5a 100644
--- a/sw/inc/tblafmt.hxx
+++ b/sw/inc/tblafmt.hxx
@@ -230,6 +230,8 @@ class SW_DLLPUBLIC SwTableAutoFormat
     friend void FinitCore();       // To destroy default pointer.
     static SwBoxAutoFormat* pDfltBoxAutoFormat;
 
+    css::uno::WeakReference<css::uno::XInterface> m_wXObject;
+
     OUString m_aName;
     sal_uInt16 nStrResId;
 
@@ -292,6 +294,11 @@ public:
 
     bool Load( SvStream& rStream, const SwAfVersions& );
     bool Save( SvStream& rStream, sal_uInt16 fileVersion ) const;
+
+    css::uno::WeakReference<css::uno::XInterface> const& GetXObject() const
+        { return m_wXObject; }
+    void SetXObject(css::uno::Reference<css::uno::XInterface> const& xObject)
+        { m_wXObject = xObject; }
 };
 
 class SW_DLLPUBLIC SwTableAutoFormatTable
diff --git a/sw/inc/unostyle.hxx b/sw/inc/unostyle.hxx
index 72b6b04..9a56b5c 100644
--- a/sw/inc/unostyle.hxx
+++ b/sw/inc/unostyle.hxx
@@ -246,6 +246,35 @@ protected:
     virtual void Modify( const SfxPoolItem* pOld, const SfxPoolItem *pNew) override;
 
 };
+
+class SwTableAutoFormat;
+
+/// A text table style is a uno api wrapper for a SwTableAutoFormat
+class SwXTextTableStyle : public cppu::WeakImplHelper<css::style::XStyle, css::lang::XServiceInfo>
+{
+    OUString m_sTableAutoFormatName;
+    SwDocShell* m_pDocShell;
+
+    SwTableAutoFormat* GetTableAutoFormat();
+public:
+    SwXTextTableStyle(SwDocShell* pDocShell, const OUString& rTableAutoFormatName);
+    //XStyle
+    virtual sal_Bool SAL_CALL isUserDefined() throw (css::uno::RuntimeException, std::exception) override;
+    virtual sal_Bool SAL_CALL isInUse() throw (css::uno::RuntimeException, std::exception) override;
+    virtual OUString SAL_CALL getParentStyle() throw (css::uno::RuntimeException, std::exception) override;
+    virtual void SAL_CALL setParentStyle(const OUString& aParentStyle ) throw (css::container::NoSuchElementException, css::uno::RuntimeException, std::exception) override;
+
+    //XNamed
+    virtual OUString SAL_CALL getName() throw(css::uno::RuntimeException, std::exception) override;
+    virtual void SAL_CALL setName(const OUString& rName) throw(css::uno::RuntimeException, std::exception) override;
+
+    //XServiceInfo
+    virtual OUString SAL_CALL getImplementationName() throw(css::uno::RuntimeException, std::exception) override;
+    virtual sal_Bool SAL_CALL supportsService(const OUString& rServiceName) throw(css::uno::RuntimeException, std::exception) override;
+    virtual css::uno::Sequence<OUString> SAL_CALL getSupportedServiceNames() throw(css::uno::RuntimeException, std::exception) override;
+
+    static css::uno::Reference<css::style::XStyle> CreateXTextTableStyle(SwDocShell* pDocShell, const OUString& rTableAutoFormatName);
+};
 #endif
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/qa/python/check_styles.py b/sw/qa/python/check_styles.py
index 4f9cefb..79972ef 100644
--- a/sw/qa/python/check_styles.py
+++ b/sw/qa/python/check_styles.py
@@ -48,7 +48,7 @@ class CheckStyle(unittest.TestCase):
             xStyleFamilies.getByName("foobarbaz")
         xDoc.dispose()
 
-    def __test_StyleFamily(self, xFamily, vExpectedNames):
+    def __test_StyleFamily(self, xFamily, vExpectedNames, sElementImplName):
         self.assertEqual(xFamily.ImplementationName, "XStyleFamily")
         self.assertEqual(len(xFamily.SupportedServiceNames), 1)
 
@@ -67,7 +67,7 @@ class CheckStyle(unittest.TestCase):
 
         for sStylename in xFamily.ElementNames:
             self.assertTrue(xFamily.hasByName(sStylename))
-            self.assertEqual(xFamily[sStylename].ImplementationName, "SwXStyle")
+            self.assertEqual(xFamily[sStylename].ImplementationName, sElementImplName)
             self.assertFalse(xFamily[sStylename].isUserDefined())
 
         vExpectedNames.sort()
@@ -75,12 +75,12 @@ class CheckStyle(unittest.TestCase):
         vNames.sort()
         self.assertListEqual(vNames, vExpectedNames)
 
-    def __test_StyleFamilyIndex(self, xFamily, vExpectedNames):
+    def __test_StyleFamilyIndex(self, xFamily, vExpectedNames, sElementImplName):
         self.assertEqual(xFamily.Count, len(vExpectedNames))
 
         for nIndex in range(xFamily.Count):
             xStyle = xFamily.getByIndex(nIndex)
-            self.assertEqual(xStyle.ImplementationName, "SwXStyle")
+            self.assertEqual(xStyle.ImplementationName, sElementImplName)
             self.assertIn(xStyle.Name, vExpectedNames)
             self.assertFalse(xStyle.isUserDefined())
 
@@ -123,8 +123,8 @@ class CheckStyle(unittest.TestCase):
         xDoc = CheckStyle._uno.openEmptyWriterDoc()
         xCharStyles = xDoc.StyleFamilies["CharacterStyles"]
         vEmptyDocStyles = ['Default Style', 'Footnote Symbol', 'Page Number', 'Caption characters', 'Drop Caps', 'Numbering Symbols', 'Bullet Symbols', 'Internet link', 'Visited Internet Link', 'Placeholder', 'Index Link', 'Endnote Symbol', 'Line numbering', 'Main index entry', 'Footnote anchor', 'Endnote anchor', 'Rubies', 'Vertical Numbering Symbols', 'Emphasis', 'Citation', 'Strong Emphasis', 'Source Text', 'Example', 'User Entry', 'Variable', 'Definition', 'Teletype']
-        self.__test_StyleFamily(xCharStyles, vEmptyDocStyles)
-        self.__test_StyleFamilyIndex(xCharStyles, vEmptyDocStyles)
+        self.__test_StyleFamily(xCharStyles, vEmptyDocStyles, "SwXStyle")
+        self.__test_StyleFamilyIndex(xCharStyles, vEmptyDocStyles, "SwXStyle")
         self.__test_StyleFamilyInsert(xDoc, xCharStyles, vEmptyDocStyles, "com.sun.star.style.CharacterStyle", "com.sun.star.style.ParagraphStyle")
         xDoc.dispose()
 
@@ -132,8 +132,8 @@ class CheckStyle(unittest.TestCase):
         xDoc = CheckStyle._uno.openEmptyWriterDoc()
         xParaStyles = xDoc.StyleFamilies["ParagraphStyles"]
         vEmptyDocStyles = ['Standard', 'Heading', 'Text body', 'List', 'Caption', 'Index', 'First line indent', 'Hanging indent', 'Text body indent', 'Salutation', 'Signature', 'List Indent', 'Marginalia', 'Heading 1', 'Heading 2', 'Heading 3', 'Heading 4', 'Heading 5', 'Heading 6', 'Heading 7', 'Heading 8', 'Heading 9', 'Heading 10', 'Title', 'Subtitle', 'Numbering 1 Start', 'Numbering 1', 'Numbering 1 End', 'Numbering 1 Cont.', 'Numbering 2 Start', 'Numbering 2', 'Numbering 2 End', 'Numbering 2 Cont.', 'Numbering 3 Start', 'Numbering 3', 'Numbering 3 End', 'Numbering 3 Cont.', 'Numbering 4 Start', 'Numbering 4', 'Numbering 4 End', 'Numbering 4 Cont.', 'Numbering 5 Start', 'Numbering 5', 'Numbering 5 End', 'Numbering 5 Cont.', 'List 1 Start', 'List 1', 'List 1 End', 'List 1 Cont.', 'List 2 Start', 'List 2', 'List 2 End', 'List 2 Cont.', 'List 3 Start', 'List 3', 'List 3 End', 'List 3 Cont.', 'List 4 Start', 'List 4', 'List 4 End', 'List 4 Cont.', 'List 5 Start', 'List 5', 'List 5 E
 nd', 'List 5 Cont.', 'Index Heading', 'Index 1', 'Index 2', 'Index 3', 'Index Separator', 'Contents Heading', 'Contents 1', 'Contents 2', 'Contents 3', 'Contents 4', 'Contents 5', 'User Index Heading', 'User Index 1', 'User Index 2', 'User Index 3', 'User Index 4', 'User Index 5', 'Contents 6', 'Contents 7', 'Contents 8', 'Contents 9', 'Contents 10', 'Illustration Index Heading', 'Illustration Index 1', 'Object index heading', 'Object index 1', 'Table index heading', 'Table index 1', 'Bibliography Heading', 'Bibliography 1', 'User Index 6', 'User Index 7', 'User Index 8', 'User Index 9', 'User Index 10', 'Header', 'Header left', 'Header right', 'Footer', 'Footer left', 'Footer right', 'Table Contents', 'Table Heading', 'Illustration', 'Table', 'Text', 'Frame contents', 'Footnote', 'Addressee', 'Sender', 'Endnote', 'Drawing', 'Quotations', 'Preformatted Text', 'Horizontal Line', 'List Contents', 'List Heading']
-        self.__test_StyleFamily(xParaStyles, vEmptyDocStyles)
-        self.__test_StyleFamilyIndex(xParaStyles, vEmptyDocStyles)
+        self.__test_StyleFamily(xParaStyles, vEmptyDocStyles, "SwXStyle")
+        self.__test_StyleFamilyIndex(xParaStyles, vEmptyDocStyles, "SwXStyle")
         self.__test_StyleFamilyInsert(xDoc, xParaStyles, vEmptyDocStyles, "com.sun.star.style.ParagraphStyle", "com.sun.star.style.CharacterStyle")
         xDoc.dispose()
 
@@ -141,8 +141,8 @@ class CheckStyle(unittest.TestCase):
         xDoc = CheckStyle._uno.openEmptyWriterDoc()
         xPageStyles = xDoc.StyleFamilies["PageStyles"]
         vEmptyDocStyles = ['Standard', 'First Page', 'Left Page', 'Right Page', 'Envelope', 'Index', 'HTML', 'Footnote', 'Endnote', 'Landscape']
-        self.__test_StyleFamily(xPageStyles, vEmptyDocStyles)
-        self.__test_StyleFamilyIndex(xPageStyles, vEmptyDocStyles)
+        self.__test_StyleFamily(xPageStyles, vEmptyDocStyles, "SwXStyle")
+        self.__test_StyleFamilyIndex(xPageStyles, vEmptyDocStyles, "SwXStyle")
         self.__test_StyleFamilyInsert(xDoc, xPageStyles, vEmptyDocStyles, "com.sun.star.style.PageStyle", "com.sun.star.style.CharacterStyle")
         xDoc.dispose()
 
@@ -150,8 +150,8 @@ class CheckStyle(unittest.TestCase):
         xDoc = CheckStyle._uno.openEmptyWriterDoc()
         xFrameStyles = xDoc.StyleFamilies["FrameStyles"]
         vEmptyDocStyles = ['Formula', 'Frame', 'Graphics', 'Labels', 'Marginalia', 'OLE', 'Watermark']
-        self.__test_StyleFamily(xFrameStyles, vEmptyDocStyles)
-        self.__test_StyleFamilyIndex(xFrameStyles, vEmptyDocStyles)
+        self.__test_StyleFamily(xFrameStyles, vEmptyDocStyles, "SwXStyle")
+        self.__test_StyleFamilyIndex(xFrameStyles, vEmptyDocStyles, "SwXStyle")
         self.__test_StyleFamilyInsert(xDoc, xFrameStyles, vEmptyDocStyles, "com.sun.star.style.FrameStyle", "com.sun.star.style.CharacterStyle")
         xDoc.dispose()
 
@@ -159,11 +159,21 @@ class CheckStyle(unittest.TestCase):
         xDoc = CheckStyle._uno.openEmptyWriterDoc()
         xNumberingStyles = xDoc.StyleFamilies["NumberingStyles"]
         vEmptyDocStyles = ['List 1', 'List 2', 'List 3', 'List 4', 'List 5', 'Numbering 1', 'Numbering 2', 'Numbering 3', 'Numbering 4', 'Numbering 5']
-        self.__test_StyleFamily(xNumberingStyles, vEmptyDocStyles)
-        self.__test_StyleFamilyIndex(xNumberingStyles, vEmptyDocStyles)
+        self.__test_StyleFamily(xNumberingStyles, vEmptyDocStyles, "SwXStyle")
+        self.__test_StyleFamilyIndex(xNumberingStyles, vEmptyDocStyles, "SwXStyle")
         self.__test_StyleFamilyInsert(xDoc, xNumberingStyles, vEmptyDocStyles, "com.sun.star.style.NumberingStyle", "com.sun.star.style.CharacterStyle")
         xDoc.dispose()
 
+    def test_TableFamily(self):
+        xDoc = CheckStyle._uno.openEmptyWriterDoc()
+        xTableStyles = xDoc.StyleFamilies["TableStyles"]
+        vEmptyDocStyles = ['Default Style']
+        self.__test_StyleFamily(xTableStyles, vEmptyDocStyles, "SwXTextTableStyle")
+        self.__test_StyleFamilyIndex(xTableStyles, vEmptyDocStyles, "SwXTextTableStyle")
+        for sStyleName in vEmptyDocStyles:
+            self.assertIsNotNone(xTableStyles.getByName(sStyleName))
+        xDoc.dispose()
+
 if __name__ == '__main__':
     unittest.main()
 
diff --git a/sw/source/core/unocore/unostyle.cxx b/sw/source/core/unocore/unostyle.cxx
index e0d874f..0c60416 100644
--- a/sw/source/core/unocore/unostyle.cxx
+++ b/sw/source/core/unocore/unostyle.cxx
@@ -701,9 +701,14 @@ sal_Int32 lcl_GetCountOrName<SfxStyleFamily::Pseudo>(const SwDoc& rDoc, OUString
 }
 
 template<>
-sal_Int32 lcl_GetCountOrName<SfxStyleFamily::Table>(const SwDoc& rDoc, OUString* /*pString*/, sal_Int32 /*nIndex*/)
+sal_Int32 lcl_GetCountOrName<SfxStyleFamily::Table>(const SwDoc& rDoc, OUString* pString, sal_Int32 nIndex)
 {
-    return rDoc.GetDocShell()->GetDoc()->GetTableStyles().size();
+    const auto pAutoFormats = &rDoc.GetTableStyles();
+    const sal_Int32 nCount = pAutoFormats->size();
+    if (0 <= nIndex && nIndex < nCount)
+        *pString = pAutoFormats->operator[](nIndex).GetName();
+
+    return nCount;
 }
 
 template<SfxStyleFamily eFamily>
@@ -721,6 +726,10 @@ template<>
 uno::Reference< css::style::XStyle> lcl_CreateStyle<SfxStyleFamily::Page>(SfxStyleSheetBasePool* pBasePool, SwDocShell* pDocShell, const OUString& sStyleName)
     { return pBasePool ? new SwXPageStyle(*pBasePool, pDocShell, SfxStyleFamily::Page, sStyleName) : new SwXPageStyle(pDocShell); };
 
+template<>
+uno::Reference< css::style::XStyle> lcl_CreateStyle<SfxStyleFamily::Table>(SfxStyleSheetBasePool* /*pBasePool*/, SwDocShell* pDocShell, const OUString& sStyleName)
+    { return SwXTextTableStyle::CreateXTextTableStyle(pDocShell, sStyleName); };
+
 uno::Reference<css::style::XStyle> SwXStyleFamilies::CreateStyle(SfxStyleFamily eFamily, SwDoc& rDoc)
 {
     auto pEntries(lcl_GetStyleFamilyEntries());
@@ -808,8 +817,8 @@ uno::Any XStyleFamily::getByName(const OUString& rName)
     SwStyleNameMapper::FillUIName(rName, sStyleName, m_rEntry.m_aPoolId, true);
     if(!m_pBasePool)
         throw uno::RuntimeException();
-    m_pBasePool->SetSearchMask(m_rEntry.m_eFamily);
-    SfxStyleSheetBase* pBase = m_pBasePool->Find(sStyleName);
+    SfxStyleSheetIteratorPtr pIt = m_pBasePool->CreateIterator(m_rEntry.m_eFamily, SFXSTYLEBIT_ALL);
+    SfxStyleSheetBase* pBase = pIt->Find(sStyleName);
     if(!pBase)
         throw container::NoSuchElementException();
     uno::Reference<style::XStyle> xStyle = FindStyle(sStyleName);
@@ -841,8 +850,8 @@ sal_Bool XStyleFamily::hasByName(const OUString& rName) throw( uno::RuntimeExcep
         throw uno::RuntimeException();
     OUString sStyleName;
     SwStyleNameMapper::FillUIName(rName, sStyleName, m_rEntry.m_aPoolId, true);
-    m_pBasePool->SetSearchMask(m_rEntry.m_eFamily);
-    SfxStyleSheetBase* pBase = m_pBasePool->Find(sStyleName);
+    SfxStyleSheetIteratorPtr pIt = m_pBasePool->CreateIterator(m_rEntry.m_eFamily, SFXSTYLEBIT_ALL);
+    SfxStyleSheetBase* pBase = pIt->Find(sStyleName);
     return nullptr != pBase;
 }
 
@@ -4229,4 +4238,112 @@ uno::Sequence< beans::PropertyValue > SwXAutoStyle::getProperties() throw (uno::
     return aRet;
 }
 
+SwXTextTableStyle::SwXTextTableStyle(SwDocShell* pDocShell, const OUString& rTableAutoFormatName)
+{
+    m_pDocShell = pDocShell;
+    m_sTableAutoFormatName = rTableAutoFormatName;
+}
+
+uno::Reference<css::style::XStyle> SwXTextTableStyle::CreateXTextTableStyle(SwDocShell* pDocShell, const OUString& rTableAutoFormatName)
+{
+    uno::Reference<css::style::XStyle> xTextTableStyle;
+    const size_t nStyles = pDocShell->GetDoc()->GetTableStyles().size();
+    for(size_t i=0; i < nStyles; ++i)
+    {
+        SwTableAutoFormat* pAutoFormat = &pDocShell->GetDoc()->GetTableStyles()[i];
+        if (pAutoFormat->GetName() == rTableAutoFormatName)
+        {
+            xTextTableStyle.set(pAutoFormat->GetXObject(), uno::UNO_QUERY);
+            if (!xTextTableStyle.is())
+            {
+                xTextTableStyle.set(new SwXTextTableStyle(pDocShell, rTableAutoFormatName));
+                pAutoFormat->SetXObject(xTextTableStyle);
+            }
+            break;
+        }
+    }
+
+    // If corresponding AutoFormat doesn't exist create a XStyle but don't register it.
+    if (!xTextTableStyle.is())
+    {
+        xTextTableStyle.set(new SwXTextTableStyle(pDocShell, rTableAutoFormatName));
+        SAL_INFO("sw.uno", "creating SwXTextTableStyle for non existing SwTableAutoFormat");
+    }
+
+    return xTextTableStyle;
+}
+
+SwTableAutoFormat* SwXTextTableStyle::GetTableAutoFormat()
+{
+    const size_t nStyles = m_pDocShell->GetDoc()->GetTableStyles().size();
+    for(size_t i=0; i < nStyles; ++i)
+    {
+        SwTableAutoFormat* pAutoFormat = &m_pDocShell->GetDoc()->GetTableStyles()[i];
+        if (pAutoFormat->GetName() == m_sTableAutoFormatName)
+            return pAutoFormat;
+    }
+    SAL_WARN("sw.uno", "lost SwTableAutoFormat and SwXTextTableStyle integrity");
+    return nullptr;
+}
+
+// XStyle
+sal_Bool SAL_CALL SwXTextTableStyle::isUserDefined() throw (css::uno::RuntimeException, std::exception)
+{
+    return false;
+}
+
+sal_Bool SAL_CALL SwXTextTableStyle::isInUse() throw (css::uno::RuntimeException, std::exception)
+{
+    return false;
+}
+
+OUString SAL_CALL SwXTextTableStyle::getParentStyle() throw (css::uno::RuntimeException, std::exception)
+{
+    return OUString();
+}
+
+void SAL_CALL SwXTextTableStyle::setParentStyle( const OUString& /*aParentStyle*/ ) throw (css::container::NoSuchElementException, css::uno::RuntimeException, std::exception)
+{ }
+
+//XNamed
+OUString SAL_CALL SwXTextTableStyle::getName() throw(css::uno::RuntimeException, std::exception)
+{
+    return m_sTableAutoFormatName;
+}
+
+void SAL_CALL SwXTextTableStyle::setName(const OUString& rName) throw(css::uno::RuntimeException, std::exception)
+{
+    const size_t nStyles = m_pDocShell->GetDoc()->GetTableStyles().size();
+    for(size_t i=0; i < nStyles; ++i)
+    {
+        SwTableAutoFormat* pAutoFormat = &m_pDocShell->GetDoc()->GetTableStyles()[i];
+        if (pAutoFormat->GetName() == rName)
+        {
+            SAL_INFO("sw.uno", "SwXTextTableStyle with given name already exists");
+            return;
+        }
+    }
+
+    SwTableAutoFormat* pAutoFormat = GetTableAutoFormat();
+    if (pAutoFormat)
+        pAutoFormat->SetName(rName);
+
+    m_sTableAutoFormatName = rName;
+}
+
+//XServiceInfo
+OUString SAL_CALL SwXTextTableStyle::getImplementationName() throw(css::uno::RuntimeException, std::exception)
+{
+    return {"SwXTextTableStyle"};
+}
+
+sal_Bool SAL_CALL SwXTextTableStyle::supportsService(const OUString& rServiceName) throw(css::uno::RuntimeException, std::exception)
+{
+    return cppu::supportsService(this, rServiceName);
+}
+
+css::uno::Sequence<OUString> SAL_CALL SwXTextTableStyle::getSupportedServiceNames() throw(css::uno::RuntimeException, std::exception)
+{
+    return {"com.sun.star.style.Style"};
+}
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/uibase/app/docstyle.cxx b/sw/source/uibase/app/docstyle.cxx
index 0171cf5..13e22a6 100644
--- a/sw/source/uibase/app/docstyle.cxx
+++ b/sw/source/uibase/app/docstyle.cxx
@@ -323,6 +323,9 @@ sal_uInt32 SwStyleSheetIterator::SwPoolFormatList::FindName(SfxStyleFamily eFam,
         case SfxStyleFamily::Pseudo:
             cStyle = cNUMRULE;
             break;
+        case SfxStyleFamily::Table:
+            cStyle = cTABSTYLE;
+            break;
         default:
             cStyle = ' ';
             break;


More information about the Libreoffice-commits mailing list