summaryrefslogtreecommitdiff
path: root/sw
diff options
context:
space:
mode:
Diffstat (limited to 'sw')
-rw-r--r--sw/inc/tblafmt.hxx1
-rw-r--r--sw/inc/unostyle.hxx7
-rw-r--r--sw/qa/extras/odfexport/data/table_styles_1.odtbin0 -> 9874 bytes
-rw-r--r--sw/qa/extras/odfexport/odfexport.cxx40
-rw-r--r--sw/source/core/doc/tblafmt.cxx14
-rw-r--r--sw/source/core/unocore/unostyle.cxx94
-rw-r--r--sw/source/filter/basflt/shellio.cxx3
-rw-r--r--sw/source/filter/xml/xmlfmt.cxx39
-rw-r--r--sw/source/filter/xml/xmltble.cxx4
-rw-r--r--sw/source/filter/xml/xmltbli.cxx3
-rw-r--r--sw/source/filter/xml/xmltbli.hxx1
11 files changed, 201 insertions, 5 deletions
diff --git a/sw/inc/tblafmt.hxx b/sw/inc/tblafmt.hxx
index 0eb799ac2a87..06aa12b6adcc 100644
--- a/sw/inc/tblafmt.hxx
+++ b/sw/inc/tblafmt.hxx
@@ -276,6 +276,7 @@ public:
void SetBoxFormat( const SwBoxAutoFormat& rNew, sal_uInt8 nPos );
const SwBoxAutoFormat& GetBoxFormat( sal_uInt8 nPos ) const;
SwBoxAutoFormat& GetBoxFormat( sal_uInt8 nPos );
+ static const SwBoxAutoFormat& GetDefaultBoxFormat();
void SetName( const OUString& rNew ) { m_aName = rNew; nStrResId = USHRT_MAX; }
const OUString& GetName() const { return m_aName; }
diff --git a/sw/inc/unostyle.hxx b/sw/inc/unostyle.hxx
index cc24073874a6..a2b5f522a23e 100644
--- a/sw/inc/unostyle.hxx
+++ b/sw/inc/unostyle.hxx
@@ -348,6 +348,7 @@ class SwXTextCellStyle : public cppu::WeakImplHelper
<
css::style::XStyle,
css::beans::XPropertySet,
+ css::beans::XPropertyState,
css::lang::XServiceInfo
>
{
@@ -399,6 +400,12 @@ class SwXTextCellStyle : public cppu::WeakImplHelper
virtual void SAL_CALL addVetoableChangeListener(const OUString& PropertyName, const css::uno::Reference<css::beans::XVetoableChangeListener>& aListener) throw(css::beans::UnknownPropertyException, css::lang::WrappedTargetException, css::uno::RuntimeException, std::exception) override;
virtual void SAL_CALL removeVetoableChangeListener(const OUString& PropertyName, const css::uno::Reference<css::beans::XVetoableChangeListener>& aListener) throw(css::beans::UnknownPropertyException, css::lang::WrappedTargetException, css::uno::RuntimeException, std::exception) override;
+ //XPropertyState
+ virtual css::beans::PropertyState SAL_CALL getPropertyState(const OUString& PropertyName) throw(css::beans::UnknownPropertyException, css::uno::RuntimeException, std::exception) override;
+ virtual css::uno::Sequence<css::beans::PropertyState> SAL_CALL getPropertyStates(const css::uno::Sequence< OUString >& aPropertyName) throw(css::beans::UnknownPropertyException, css::uno::RuntimeException, std::exception) override;
+ virtual void SAL_CALL setPropertyToDefault(const OUString& PropertyName) throw(css::beans::UnknownPropertyException, css::uno::RuntimeException, std::exception) override;
+ virtual css::uno::Any SAL_CALL getPropertyDefault(const OUString& aPropertyName) throw(css::beans::UnknownPropertyException, css::lang::WrappedTargetException, 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;
diff --git a/sw/qa/extras/odfexport/data/table_styles_1.odt b/sw/qa/extras/odfexport/data/table_styles_1.odt
new file mode 100644
index 000000000000..701fd92c2aaa
--- /dev/null
+++ b/sw/qa/extras/odfexport/data/table_styles_1.odt
Binary files differ
diff --git a/sw/qa/extras/odfexport/odfexport.cxx b/sw/qa/extras/odfexport/odfexport.cxx
index aa384775a1ed..313d2cfd39e8 100644
--- a/sw/qa/extras/odfexport/odfexport.cxx
+++ b/sw/qa/extras/odfexport/odfexport.cxx
@@ -816,6 +816,46 @@ DECLARE_ODFEXPORT_TEST(testEmbeddedPdf, "embedded-pdf.odt")
CPPUNIT_ASSERT(!getProperty<OUString>(xShape, "ReplacementGraphicURL").isEmpty());
}
+DECLARE_ODFEXPORT_TEST(testTableStyles1, "table_styles_1.odt")
+{
+ // Table styles basic graphic test.
+ // Doesn't cover all attributes.
+ uno::Reference<style::XStyleFamiliesSupplier> XFamiliesSupplier(mxComponent, uno::UNO_QUERY);
+ uno::Reference<container::XNameAccess> xFamilies(XFamiliesSupplier->getStyleFamilies());
+ uno::Reference<container::XNameAccess> xCellFamily(xFamilies->getByName("CellStyles"), uno::UNO_QUERY);
+ uno::Reference<beans::XPropertySet> xCell1Style;
+ xCellFamily->getByName("Test style.1") >>= xCell1Style;
+
+ sal_Int64 nInt64 = 0xF0F0F0;
+ sal_Int32 nInt32 = 0xF0F0F0;
+ table::BorderLine2 oBorder;
+
+ xCell1Style->getPropertyValue("BackColor") >>= nInt64;
+ CPPUNIT_ASSERT_EQUAL(sal_Int64(0xCC0000), nInt64);
+ xCell1Style->getPropertyValue("WritingMode") >>= nInt32;
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(4), nInt32);
+ xCell1Style->getPropertyValue("VertOrient") >>= nInt32;
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(0), nInt32);
+ xCell1Style->getPropertyValue("BorderDistance") >>= nInt32;
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(97), nInt32);
+ xCell1Style->getPropertyValue("LeftBorderDistance") >>= nInt32;
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(97), nInt32);
+ xCell1Style->getPropertyValue("RightBorderDistance") >>= nInt32;
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(97), nInt32);
+ xCell1Style->getPropertyValue("TopBorderDistance") >>= nInt32;
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(97), nInt32);
+ xCell1Style->getPropertyValue("BottomBorderDistance") >>= nInt32;
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(97), nInt32);
+ xCell1Style->getPropertyValue("RightBorder") >>= oBorder;
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(0), oBorder.Color);
+ xCell1Style->getPropertyValue("LeftBorder") >>= oBorder;
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(0), oBorder.Color);
+ xCell1Style->getPropertyValue("TopBorder") >>= oBorder;
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(0), oBorder.Color);
+ xCell1Style->getPropertyValue("BottomBorder") >>= oBorder;
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(0), oBorder.Color);
+}
+
#endif
CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/sw/source/core/doc/tblafmt.cxx b/sw/source/core/doc/tblafmt.cxx
index 66202a1b4a01..0034998e75f3 100644
--- a/sw/source/core/doc/tblafmt.cxx
+++ b/sw/source/core/doc/tblafmt.cxx
@@ -709,6 +709,14 @@ SwBoxAutoFormat& SwTableAutoFormat::GetBoxFormat( sal_uInt8 nPos )
return *pFormat;
}
+const SwBoxAutoFormat& SwTableAutoFormat::GetDefaultBoxFormat()
+{
+ if(!pDfltBoxAutoFormat)
+ pDfltBoxAutoFormat = new SwBoxAutoFormat();
+
+ return *pDfltBoxAutoFormat;
+}
+
void SwTableAutoFormat::UpdateFromSet( sal_uInt8 nPos,
const SfxItemSet& rSet,
UpdateFlags eFlags,
@@ -847,7 +855,11 @@ void SwTableAutoFormat::UpdateToSet(sal_uInt8 nPos, SfxItemSet& rSet,
rSet.Put( rChg.GetBackground() );
rSet.Put(rChg.GetTextOrientation());
- rSet.Put(rChg.GetVerticalAlignment());
+
+ // Do not put a VertAlign when it has default value.
+ // It prevents the export of default value by automatic cell-styles export.
+ if (rChg.GetVerticalAlignment().GetVertOrient() != GetDefaultBoxFormat().GetVerticalAlignment().GetVertOrient())
+ rSet.Put(rChg.GetVerticalAlignment());
if( IsValueFormat() && pNFormatr )
{
diff --git a/sw/source/core/unocore/unostyle.cxx b/sw/source/core/unocore/unostyle.cxx
index 87e3c55cc34f..c38c1e31978c 100644
--- a/sw/source/core/unocore/unostyle.cxx
+++ b/sw/source/core/unocore/unostyle.cxx
@@ -26,6 +26,7 @@
#include <svl/style.hxx>
#include <svl/itemiter.hxx>
#include <svl/zforlist.hxx>
+#include <svl/zformat.hxx>
#include <svx/pageitem.hxx>
#include <editeng/sizeitem.hxx>
#include <editeng/ulspitem.hxx>
@@ -4925,11 +4926,47 @@ void SAL_CALL SwXTextCellStyle::setPropertyValue(const OUString& rPropertyName,
{
case RES_BACKGROUND:
{
- SvxBrushItem rBrush( m_pBoxAutoFormat->GetBackground() );
+ SvxBrushItem rBrush = m_pBoxAutoFormat->GetBackground();
rBrush.PutValue(aValue, 0);
m_pBoxAutoFormat->SetBackground(rBrush);
return;
}
+ case RES_BOX:
+ {
+ SvxBoxItem rBox = m_pBoxAutoFormat->GetBox();
+ rBox.PutValue(aValue, pEntry->nMemberId);
+ m_pBoxAutoFormat->SetBox(rBox);
+ return;
+ }
+ case RES_VERT_ORIENT:
+ {
+ SwFormatVertOrient rVertOrient = m_pBoxAutoFormat->GetVerticalAlignment();
+ rVertOrient.PutValue(aValue, pEntry->nMemberId);
+ m_pBoxAutoFormat->SetVerticalAlignment(rVertOrient);
+ return;
+ }
+ case RES_FRAMEDIR:
+ {
+ SvxFrameDirectionItem rDirItem = m_pBoxAutoFormat->GetTextOrientation();
+ rDirItem.PutValue(aValue, pEntry->nMemberId);
+ m_pBoxAutoFormat->SetTextOrientation(rDirItem);
+ return;
+ }
+ case RES_BOXATR_FORMAT:
+ {
+ sal_uInt32 nKey;
+ if (aValue >>= nKey)
+ {
+ // FIXME: Its not working for old "automatic" currency formats, which are still in use by autotbl.fmt.
+ // Scenario:
+ // 1) Mark all styles present by default in autotbl.fmt as default.
+ // 2) convert all currencies present in autotbl.fmt before calling this code
+ const SvNumberformat* pNumFormat = m_pDocShell->GetDoc()->GetNumberFormatter()->GetEntry(nKey);
+ if (pNumFormat)
+ m_pBoxAutoFormat->SetValueFormat(pNumFormat->GetFormatstring(), pNumFormat->GetLanguage(), GetAppLanguage());
+ }
+ return;
+ }
default:
SAL_WARN("sw.uno", "SwXTextCellStyle unknown nWID");
throw css::uno::RuntimeException();
@@ -5014,6 +5051,61 @@ void SAL_CALL SwXTextCellStyle::removeVetoableChangeListener( const OUString& /*
SAL_WARN("sw.uno", "not implemented");
}
+//XPropertyState
+css::beans::PropertyState SAL_CALL SwXTextCellStyle::getPropertyState(const OUString& rPropertyName) throw(css::beans::UnknownPropertyException, css::uno::RuntimeException, std::exception)
+{
+ SolarMutexGuard aGuard;
+ uno::Sequence<OUString> aNames { rPropertyName };
+ uno::Sequence<beans::PropertyState> aStates = getPropertyStates(aNames);
+ return aStates.getConstArray()[0];
+}
+
+css::uno::Sequence<css::beans::PropertyState> SAL_CALL SwXTextCellStyle::getPropertyStates(const css::uno::Sequence<OUString>& aPropertyNames) throw(css::beans::UnknownPropertyException, css::uno::RuntimeException, std::exception)
+{
+ SolarMutexGuard aGuard;
+ uno::Sequence<beans::PropertyState> aRet(aPropertyNames.getLength());
+ beans::PropertyState* pStates = aRet.getArray();
+ const SwBoxAutoFormat& rDefaultBoxFormat = SwTableAutoFormat::GetDefaultBoxFormat();
+ const SfxItemPropertyMap& rMap = aSwMapProvider.GetPropertySet(PROPERTY_MAP_CELL_STYLE)->getPropertyMap();
+ const OUString* pNames = aPropertyNames.getConstArray();
+ for(sal_Int32 i=0; i < aPropertyNames.getLength(); ++i)
+ {
+ const OUString sPropName = pNames[i];
+ const SfxItemPropertySimpleEntry* pEntry = rMap.getByName(sPropName);
+ if(pEntry)
+ {
+ switch(pEntry->nWID)
+ {
+ case RES_VERT_ORIENT:
+ if (m_pBoxAutoFormat->GetVerticalAlignment() == rDefaultBoxFormat.GetVerticalAlignment())
+ pStates[i] = beans::PropertyState_DEFAULT_VALUE;
+ break;
+ default:
+ // falltrough to DIRECT_VALUE, to export properties for which getPropertyStates is not implemented
+ pStates[i] = beans::PropertyState_DIRECT_VALUE;
+ }
+ }
+ else
+ {
+ SAL_WARN("sw.uno", "SwXTextCellStyle unknown property:" + sPropName);
+ throw css::beans::UnknownPropertyException();
+ }
+ }
+ return aRet;
+}
+
+void SAL_CALL SwXTextCellStyle::setPropertyToDefault(const OUString& /*PropertyName*/) throw(css::beans::UnknownPropertyException, css::uno::RuntimeException, std::exception)
+{
+ SAL_WARN("sw.uno", "not implemented");
+}
+
+css::uno::Any SAL_CALL SwXTextCellStyle::getPropertyDefault(const OUString& /*aPropertyName*/) throw(css::beans::UnknownPropertyException, css::lang::WrappedTargetException, css::uno::RuntimeException, std::exception)
+{
+ SAL_WARN("sw.uno", "not implemented");
+ uno::Any aRet;
+ return aRet;
+}
+
//XServiceInfo
OUString SAL_CALL SwXTextCellStyle::getImplementationName() throw(css::uno::RuntimeException, std::exception)
{
diff --git a/sw/source/filter/basflt/shellio.cxx b/sw/source/filter/basflt/shellio.cxx
index 0961d7762b97..94e6d013b177 100644
--- a/sw/source/filter/basflt/shellio.cxx
+++ b/sw/source/filter/basflt/shellio.cxx
@@ -49,6 +49,7 @@
#include <undobj.hxx>
#include <swundo.hxx>
#include <swtable.hxx>
+#include <tblafmt.hxx>
#include <tblsel.hxx>
#include <pagedesc.hxx>
#include <poolfmt.hxx>
@@ -344,6 +345,8 @@ sal_uLong SwReader::Read( const Reader& rOptions )
pDoc->ChkCondColls();
pDoc->SetAllUniqueFlyNames();
pDoc->getIDocumentState().SetLoaded();
+ // Clear unassigned cell styles, because they aren't needed anymore.
+ pDoc->GetCellStyles().clear();
pDoc->GetIDocumentUndoRedo().DoUndo(bDocUndo);
if (!bReadPageDescs)
diff --git a/sw/source/filter/xml/xmlfmt.cxx b/sw/source/filter/xml/xmlfmt.cxx
index dcf39d823327..02a261fd3d8d 100644
--- a/sw/source/filter/xml/xmlfmt.cxx
+++ b/sw/source/filter/xml/xmlfmt.cxx
@@ -699,6 +699,10 @@ class SwXMLStylesContext_Impl : public SvXMLStylesContext
protected:
+ virtual SvXMLStyleContext *CreateStyleChildContext( sal_uInt16 nPrefix,
+ const OUString& rLocalName,
+ const css::uno::Reference< css::xml::sax::XAttributeList > & xAttrList ) override;
+
virtual SvXMLStyleContext *CreateStyleStyleChildContext( sal_uInt16 nFamily,
sal_uInt16 nPrefix, const OUString& rLocalName,
const uno::Reference< xml::sax::XAttributeList > & xAttrList ) override;
@@ -729,6 +733,22 @@ public:
virtual void EndElement() override;
};
+SvXMLStyleContext *SwXMLStylesContext_Impl::CreateStyleChildContext( sal_uInt16 nPrefix,
+ const OUString& rLocalName,
+ const css::uno::Reference< css::xml::sax::XAttributeList > & xAttrList )
+{
+ SvXMLStyleContext* pContext = nullptr;
+
+ if(nPrefix == XML_NAMESPACE_TABLE && IsXMLToken(rLocalName, XML_TABLE_TEMPLATE))
+ {
+ rtl::Reference<XMLTableImport> xTableImport = GetImport().GetShapeImport()->GetShapeTableImport();
+ pContext = xTableImport->CreateTableTemplateContext(nPrefix, rLocalName, xAttrList);
+ }
+ if (!pContext)
+ pContext = SvXMLStylesContext::CreateStyleChildContext(nPrefix, rLocalName, xAttrList);
+
+ return pContext;
+}
SvXMLStyleContext *SwXMLStylesContext_Impl::CreateStyleStyleChildContext(
sal_uInt16 nFamily, sal_uInt16 nPrefix, const OUString& rLocalName,
@@ -746,8 +766,13 @@ SvXMLStyleContext *SwXMLStylesContext_Impl::CreateStyleStyleChildContext(
case XML_STYLE_FAMILY_TABLE_COLUMN:
case XML_STYLE_FAMILY_TABLE_ROW:
case XML_STYLE_FAMILY_TABLE_CELL:
- pStyle = new SwXMLItemSetStyleContext_Impl( GetSwImport(), nPrefix,
- rLocalName, xAttrList, *this, nFamily );
+ // Distinguish real and automatic styles.
+ if (IsAutomaticStyle())
+ pStyle = new SwXMLItemSetStyleContext_Impl(GetSwImport(), nPrefix, rLocalName, xAttrList, *this, nFamily);
+ else if (nFamily == XML_STYLE_FAMILY_TABLE_CELL) // Real cell styles are used for table-template import.
+ pStyle = new XMLPropStyleContext(GetSwImport(), nPrefix, rLocalName, xAttrList, *this, nFamily);
+ else
+ SAL_WARN("sw.xml", "Context does not exists for non automatic table, column or row style.");
break;
case XML_STYLE_FAMILY_SD_GRAPHICS_ID:
// As long as there are no element items, we can use the text
@@ -855,6 +880,9 @@ rtl::Reference < SvXMLImportPropertyMapper > SwXMLStylesContext_Impl::GetImportP
else if( nFamily == XML_STYLE_FAMILY_TABLE_ROW )
xMapper = XMLTextImportHelper::CreateTableRowDefaultExtPropMapper(
const_cast<SwXMLStylesContext_Impl*>( this )->GetImport() );
+ else if( nFamily == XML_STYLE_FAMILY_TABLE_CELL )
+ xMapper = XMLTextImportHelper::CreateTableCellExtPropMapper(
+ const_cast<SwXMLStylesContext_Impl*>( this )->GetImport() );
else
xMapper = SvXMLStylesContext::GetImportPropertyMapper( nFamily );
return xMapper;
@@ -866,7 +894,10 @@ uno::Reference < container::XNameContainer > SwXMLStylesContext_Impl::GetStylesC
uno::Reference < container::XNameContainer > xStyles;
if( XML_STYLE_FAMILY_SD_GRAPHICS_ID == nFamily )
xStyles = const_cast<SvXMLImport *>(&GetImport())->GetTextImport()->GetFrameStyles();
- else
+ else if( XML_STYLE_FAMILY_TABLE_CELL == nFamily )
+ xStyles = const_cast<SvXMLImport *>(&GetImport())->GetTextImport()->GetCellStyles();
+
+ if (!xStyles.is())
xStyles = SvXMLStylesContext::GetStylesContainer( nFamily );
return xStyles;
@@ -876,6 +907,8 @@ OUString SwXMLStylesContext_Impl::GetServiceName( sal_uInt16 nFamily ) const
{
if( XML_STYLE_FAMILY_SD_GRAPHICS_ID == nFamily )
return OUString( "com.sun.star.style.FrameStyle" );
+ else if( XML_STYLE_FAMILY_TABLE_CELL == nFamily )
+ return OUString( "com.sun.star.style.CellStyle" );
return SvXMLStylesContext::GetServiceName( nFamily );
}
diff --git a/sw/source/filter/xml/xmltble.cxx b/sw/source/filter/xml/xmltble.cxx
index 59a2f24db9dd..124debfa84b1 100644
--- a/sw/source/filter/xml/xmltble.cxx
+++ b/sw/source/filter/xml/xmltble.cxx
@@ -1095,6 +1095,10 @@ void SwXMLExport::ExportTable( const SwTableNode& rTableNd )
EncodeStyleName( pTableFormat->GetName() ) );
}
+ // table:template-name=
+ if (!rTable.GetTableStyleName().isEmpty())
+ AddAttribute(XML_NAMESPACE_TABLE, XML_TEMPLATE_NAME, rTable.GetTableStyleName());
+
sal_uInt16 nPrefix = XML_NAMESPACE_TABLE;
if (const SwFrameFormat* pFlyFormat = rTableNd.GetFlyFormat())
{
diff --git a/sw/source/filter/xml/xmltbli.cxx b/sw/source/filter/xml/xmltbli.cxx
index d8f0d8d7ae60..60c2327505b1 100644
--- a/sw/source/filter/xml/xmltbli.cxx
+++ b/sw/source/filter/xml/xmltbli.cxx
@@ -1319,6 +1319,8 @@ SwXMLTableContext::SwXMLTableContext( SwXMLImport& rImport,
aName = rValue;
else if( IsXMLToken( aLocalName, XML_DEFAULT_CELL_STYLE_NAME ) )
m_aDfltCellStyleName = rValue;
+ else if( IsXMLToken( aLocalName, XML_TEMPLATE_NAME ) )
+ m_aTemplateName = rValue;
}
else if ( (XML_NAMESPACE_XML == nPrefix) &&
IsXMLToken( aLocalName, XML_ID ) )
@@ -2661,6 +2663,7 @@ void SwXMLTableContext::MakeTable()
m_pTableNode->GetTable().SetRowsToRepeat( m_nHeaderRows );
m_pTableNode->GetTable().SetTableModel( !m_bHasSubTables );
+ m_pTableNode->GetTable().SetTableStyleName( m_aTemplateName );
const SfxItemSet *pAutoItemSet = nullptr;
if( !m_aStyleName.isEmpty() &&
diff --git a/sw/source/filter/xml/xmltbli.hxx b/sw/source/filter/xml/xmltbli.hxx
index 9acb2fde0833..04fd0b945434 100644
--- a/sw/source/filter/xml/xmltbli.hxx
+++ b/sw/source/filter/xml/xmltbli.hxx
@@ -49,6 +49,7 @@ class SwXMLTableContext : public XMLTextTableContext
{
OUString m_aStyleName;
OUString m_aDfltCellStyleName;
+ OUString m_aTemplateName;
//! Holds basic information about a column's width.
struct ColumnWidthInfo {