From 17f440e7e7f1621edebc58f8be5e85b68ee7dcf4 Mon Sep 17 00:00:00 2001 From: Jakub Trzebiatowski Date: Thu, 16 Jun 2016 13:40:59 +0200 Subject: GSoC Table Styles, TableStyle isInUse, isUserDefined, mutex fixes Also added: + SwXTextCellStyle::IsInUse() + check_styles.py SwXTextTableStyle::isUserDefined() tests Change-Id: I76cb166107f186098599c4a8da6f94f7c40cc545 Reviewed-on: https://gerrit.libreoffice.org/26366 Tested-by: Jenkins Reviewed-by: Miklos Vajna --- sw/source/core/unocore/unostyle.cxx | 54 +++++++++++++++++++++++++++++++++++-- 1 file changed, 52 insertions(+), 2 deletions(-) (limited to 'sw/source') diff --git a/sw/source/core/unocore/unostyle.cxx b/sw/source/core/unocore/unostyle.cxx index ffc96191fd19..ab000ae0d6ec 100644 --- a/sw/source/core/unocore/unostyle.cxx +++ b/sw/source/core/unocore/unostyle.cxx @@ -61,6 +61,7 @@ #include #include #include +#include #include #include #include @@ -4408,11 +4409,36 @@ const CellStyleNameMap& SwXTextTableStyle::GetCellStyleNameMap() // XStyle sal_Bool SAL_CALL SwXTextTableStyle::isUserDefined() throw (uno::RuntimeException, std::exception) { - return false; + SolarMutexGuard aGuard; + // only first style is not user defined + if (m_pDocShell->GetDoc()->GetTableStyles()[0].GetName() == m_sTableAutoFormatName) + return false; + + return true; } sal_Bool SAL_CALL SwXTextTableStyle::isInUse() throw (uno::RuntimeException, std::exception) { + SolarMutexGuard aGuard; + uno::Reference xTablesSupp(m_pDocShell->GetModel(), uno::UNO_QUERY); + if (!xTablesSupp.is()) + return false; + + uno::Reference xTables(xTablesSupp->getTextTables(), uno::UNO_QUERY); + if (!xTables.is()) + return false; + + const sal_Int32 nCount = xTables->getCount(); + for (sal_Int32 i=0; i < nCount; ++i) + { + uno::Reference xTablePropertySet; + xTables->getByIndex(i) >>= xTablePropertySet; + OUString sTableTemplateName; + if (xTablePropertySet.is() && (xTablePropertySet->getPropertyValue("TableTemplateName") >>= sTableTemplateName) + && sTableTemplateName == m_sTableAutoFormatName) + return true; + } + return false; } @@ -4427,6 +4453,7 @@ void SAL_CALL SwXTextTableStyle::setParentStyle(const OUString& /*aParentStyle*/ //XNamed OUString SAL_CALL SwXTextTableStyle::getName() throw(uno::RuntimeException, std::exception) { + SolarMutexGuard aGuard; OUString sProgName; SwStyleNameMapper::FillProgName(m_sTableAutoFormatName, sProgName, nsSwGetPoolIdFromName::GET_POOLID_TABSTYLE, true); return m_sTableAutoFormatName; @@ -4621,6 +4648,7 @@ css::uno::Reference SwXTextCellStyle::CreateXTextCellStyle(S // XStyle sal_Bool SAL_CALL SwXTextCellStyle::isUserDefined() throw (css::uno::RuntimeException, std::exception) { + SolarMutexGuard aGuard; // if this cell belong to first table style then its defaut style if (&m_pDocShell->GetDoc()->GetTableStyles()[0] == m_pDocShell->GetDoc()->GetTableStyles().FindAutoFormat(m_sParentStyle)) return false; @@ -4630,7 +4658,26 @@ sal_Bool SAL_CALL SwXTextCellStyle::isUserDefined() throw (css::uno::RuntimeExce sal_Bool SAL_CALL SwXTextCellStyle::isInUse() throw (css::uno::RuntimeException, std::exception) { - return false; + SolarMutexGuard aGuard; + uno::Reference xFamiliesSupplier(m_pDocShell->GetModel(), uno::UNO_QUERY); + if (!xFamiliesSupplier.is()) + return false; + + uno::Reference xFamilies(xFamiliesSupplier->getStyleFamilies(), uno::UNO_QUERY); + if (!xFamilies.is()) + return false; + + uno::Reference xTableStyles; + xFamilies->getByName("TableStyles") >>= xTableStyles; + if (!xTableStyles.is()) + return false; + + uno::Reference xStyle; + xTableStyles->getByName(m_sParentStyle) >>= xStyle; + if (!xStyle.is()) + return false; + + return xStyle->isInUse(); } OUString SAL_CALL SwXTextCellStyle::getParentStyle() throw (css::uno::RuntimeException, std::exception) @@ -4640,6 +4687,7 @@ OUString SAL_CALL SwXTextCellStyle::getParentStyle() throw (css::uno::RuntimeExc void SAL_CALL SwXTextCellStyle::setParentStyle(const OUString& sParentStyle) throw (css::container::NoSuchElementException, css::uno::RuntimeException, std::exception) { + SolarMutexGuard aGuard; // Changing parent to one which is unaware of it will lead to a something unexcpected. getName() rely on a parent. SAL_INFO("sw.uno", "Changing SwXTextCellStyle parent"); m_sParentStyle = sParentStyle; @@ -4648,6 +4696,7 @@ void SAL_CALL SwXTextCellStyle::setParentStyle(const OUString& sParentStyle) thr //XNamed OUString SAL_CALL SwXTextCellStyle::getName() throw(css::uno::RuntimeException, std::exception) { + SolarMutexGuard aGuard; OUString sName; // if style is physical then we request a name from doc @@ -4672,6 +4721,7 @@ OUString SAL_CALL SwXTextCellStyle::getName() throw(css::uno::RuntimeException, void SAL_CALL SwXTextCellStyle::setName(const OUString& sName) throw(css::uno::RuntimeException, std::exception) { + SolarMutexGuard aGuard; // if style is physical then we can not rename it. if (!m_bPhysical) m_sName = sName; -- cgit