summaryrefslogtreecommitdiff
path: root/sw/source
diff options
context:
space:
mode:
authorJakub Trzebiatowski <ubap.dev@gmail.com>2016-06-16 13:40:59 +0200
committerMiklos Vajna <vmiklos@collabora.co.uk>2016-06-17 07:18:54 +0000
commit17f440e7e7f1621edebc58f8be5e85b68ee7dcf4 (patch)
tree3ee7574863e74e67dc6a40aac19b66e8e7bd1ecc /sw/source
parent67afad9f35f1fa7838a2beca43be0d9b330a755a (diff)
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 <ci@libreoffice.org> Reviewed-by: Miklos Vajna <vmiklos@collabora.co.uk>
Diffstat (limited to 'sw/source')
-rw-r--r--sw/source/core/unocore/unostyle.cxx54
1 files changed, 52 insertions, 2 deletions
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 <sfx2/printer.hxx>
#include <com/sun/star/style/ParagraphStyleCategory.hpp>
#include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
+#include <com/sun/star/text/XTextTablesSupplier.hpp>
#include <com/sun/star/beans/PropertyAttribute.hpp>
#include <com/sun/star/beans/NamedValue.hpp>
#include <com/sun/star/drawing/BitmapMode.hpp>
@@ -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<text::XTextTablesSupplier> xTablesSupp(m_pDocShell->GetModel(), uno::UNO_QUERY);
+ if (!xTablesSupp.is())
+ return false;
+
+ uno::Reference<container::XIndexAccess> 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<beans::XPropertySet> 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<css::style::XStyle> 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<style::XStyleFamiliesSupplier> xFamiliesSupplier(m_pDocShell->GetModel(), uno::UNO_QUERY);
+ if (!xFamiliesSupplier.is())
+ return false;
+
+ uno::Reference<container::XNameAccess> xFamilies(xFamiliesSupplier->getStyleFamilies(), uno::UNO_QUERY);
+ if (!xFamilies.is())
+ return false;
+
+ uno::Reference<container::XNameAccess> xTableStyles;
+ xFamilies->getByName("TableStyles") >>= xTableStyles;
+ if (!xTableStyles.is())
+ return false;
+
+ uno::Reference<style::XStyle> 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;