22#include <com/sun/star/frame/XModel.hpp>
23#include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
24#include <com/sun/star/table/XTableRows.hpp>
25#include <com/sun/star/table/XMergeableCell.hpp>
26#include <com/sun/star/table/XMergeableCellRange.hpp>
27#include <com/sun/star/table/XTable.hpp>
28#include <com/sun/star/text/XText.hpp>
29#include <com/sun/star/container/XNameContainer.hpp>
30#include <com/sun/star/lang/XMultiServiceFactory.hpp>
31#include <com/sun/star/lang/XSingleServiceFactory.hpp>
32#include <com/sun/star/style/XStyle.hpp>
70 OUString msDefaultCellStyleName;
79 sal_Int32 nElement,
const css::uno::Reference< css::xml::sax::XFastAttributeList >& AttrList )
override;
87 sal_Int32 mnStartColumn;
89 sal_Int32 mnEndColumn;
92 MergeInfo( sal_Int32 nStartColumn, sal_Int32 nStartRow, sal_Int32 nColumnSpan, sal_Int32 nRowSpan )
93 : mnStartColumn( nStartColumn ), mnStartRow( nStartRow ), mnEndColumn( nStartColumn + nColumnSpan - 1 ), mnEndRow( nStartRow + nRowSpan - 1 ) {};
103 std::vector< XMLPropertyState >& rProperties,
104 const OUString& rValue,
117 rProperties.push_back(aFillProperty);
122 rProperties.push_back(aFillProperty);
127 rProperties.push_back(aColorProperty);
143 const css::uno::Reference< css::xml::sax::XFastAttributeList >& AttrList )
override;
145 virtual void SAL_CALL
endFastElement(sal_Int32 nElement)
override;
155 css::uno::Reference< css::table::XTable >
mxTable;
174 XMLCellImportContext( SvXMLImport& rImport,
175 const Reference< XMergeableCell >& xCell,
176 const OUString& sDefaultCellStyleName,
178 const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList );
182 const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList )
override;
184 virtual void SAL_CALL
endFastElement(sal_Int32 nElement)
override;
186 sal_Int32 getColumnSpan()
const {
return mnColSpan; }
187 sal_Int32 getRowSpan()
const {
return mnRowSpan; }
188 sal_Int32 getRepeated()
const {
return mnRepeated; }
190 Reference< XMergeableCell > mxCell;
191 Reference< XTextCursor > mxCursor;
192 Reference< XTextCursor > mxOldCursor;
193 bool mbListContextPushed;
201 XMLTableTemplateContext( SvXMLImport& rImport );
205 sal_Int32 nElement,
const css::uno::Reference< css::xml::sax::XFastAttributeList >& AttrList )
override;
207 virtual void SAL_CALL
endFastElement(sal_Int32 nElement)
override;
211 const OUString& rValue )
override;
214 OUString msTemplateStyleName;
226css::uno::Reference< css::xml::sax::XFastContextHandler > XMLProxyContext::createFastChildContext( sal_Int32 nElement,
const Reference< XFastAttributeList >& xAttrList )
229 return mxParent->createFastChildContext( nElement, xAttrList );
239 Reference<XMultiServiceFactory> xFac(rImport.GetModel(), UNO_QUERY);
242 Sequence<OUString> sSNS = xFac->getAvailableServiceNames();
247 SAL_WARN(
"xmloff.table",
"Error while checking available service names");
280 return new XMLTableTemplateContext(
mrImport );
285 auto xPtr = std::make_shared<XMLTableTemplate>();
286 xPtr->swap( xTableTemplate );
297 Reference< XStyleFamiliesSupplier > xFamiliesSupp(
mrImport.GetModel(), UNO_QUERY_THROW );
298 Reference< XNameAccess > xFamilies( xFamiliesSupp->getStyleFamilies() );
300 const OUString aTableFamily(
mbWriter ?
u"TableStyles" :
u"table");
301 const OUString aCellFamily(
mbWriter ?
u"CellStyles" :
u"cell");
302 Reference< XNameContainer > xTableFamily( xFamilies->getByName( aTableFamily ), UNO_QUERY_THROW );
303 Reference< XNameAccess > xCellFamily( xFamilies->getByName( aCellFamily ), UNO_QUERY_THROW );
305 Reference< XSingleServiceFactory >
xFactory( xTableFamily, UNO_QUERY );
307 Reference< XMultiServiceFactory > xMultiFactory(
mrImport.GetModel(), UNO_QUERY_THROW );
313 xMultiFactory->createInstance(
"com.sun.star.style.TableStyle"), UNO_QUERY_THROW);
315 std::shared_ptr< XMLTableTemplate > xT( rTemplate.second );
317 for(
const auto& rStyle : *xT )
try
319 const OUString sPropName( rStyle.first );
321 xTemplate->replaceByName( sPropName, xCellFamily->getByName( sStyleName ) );
351, mxTable( xColumnRowRange, UNO_QUERY )
352, mxColumns( xColumnRowRange->getColumns() )
353, mxRows( xColumnRowRange->getRows() )
355, mnCurrentColumn( -1 )
363 auto xInfo = std::make_shared<ColumnInfo>();
365 sal_Int32 nRepeated = 1;
370 switch (aIter.getToken())
373 nRepeated = aIter.toInt32();
376 xInfo->msStyleName = aIter.toString();
379 xInfo->msDefaultCellStyleName = aIter.toString();
411 const sal_Int32 nCount1 =
mxColumns->getCount();
412 const sal_Int32 nCount2 = sal::static_int_cast< sal_Int32 >(
maColumnInfos.size() );
413 if( nCount1 < nCount2 )
414 mxColumns->insertByIndex( nCount1, nCount2 - nCount1 );
418 for( sal_Int32 nCol = 0; nCol < nCount2; nCol++ )
422 if( pAutoStyles && !xInfo->msStyleName.isEmpty() )
430 Reference< XPropertySet > xColProps(
mxColumns->getByIndex(nCol), UNO_QUERY_THROW );
453 const sal_Int32 nRowCount =
mxRows->getCount();
467 switch(aIter.getToken())
470 sStyleName = aIter.toString();
481 if( !sStyleName.isEmpty() )
499 return new XMLProxyContext(
GetImport(), xThis );
513 const sal_Int32 nColumnSpan = pCellContext->getColumnSpan();
514 const sal_Int32 nRowSpan = pCellContext->getRowSpan();
515 if( (nColumnSpan > 1) || (nRowSpan > 1) )
518 const sal_Int32 nRepeated = pCellContext->getRepeated();
521 OSL_FAIL(
"xmloff::XMLTableImportContext::ImportCell(), import of repeated Cells not implemented (TODO)");
537 const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList )
552 return new XMLProxyContext(
GetImport(), xThis );
555 SAL_WARN(
"xmloff",
"unknown element");
561 for(
const std::shared_ptr< MergeInfo >& xInfo :
maMergeInfos )
565 Reference< XCellRange > xRange(
mxTable->getCellRangeByPosition( xInfo->mnStartColumn, xInfo->mnStartRow, xInfo->mnEndColumn, xInfo->mnEndRow ) );
566 Reference< XMergeableCellRange > xCursor(
mxTable->createCursorByRange( xRange ), UNO_QUERY_THROW );
589XMLCellImportContext::XMLCellImportContext( SvXMLImport& rImport,
590 const Reference< XMergeableCell >& xCell,
591 const OUString& sDefaultCellStyleName,
593 const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList )
596, mbListContextPushed( false )
606 switch (aIter.getToken())
630 if( sStyleName.isEmpty() )
631 sStyleName = sDefaultCellStyleName;
633 if( sStyleName.isEmpty() )
646 Reference< XPropertySet > xCellSet( mxCell, UNO_QUERY );
652css::uno::Reference< css::xml::sax::XFastContextHandler > XMLCellImportContext::createFastChildContext(
654 const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList )
659 Reference< XText > xText( mxCell, UNO_QUERY );
663 mxOldCursor = xTxtImport->GetCursor();
664 mxCursor = xText->createTextCursor();
666 xTxtImport->SetCursor( mxCursor );
670 xTxtImport->PushListContext();
671 mbListContextPushed =
true;
680 pContext = GetImport().GetTextImport()->CreateTextChildContext( GetImport(), nElement, xAttrList );
688void XMLCellImportContext::endFastElement(sal_Int32 )
693 mxCursor->gotoEnd(
false );
694 mxCursor->goLeft( 1,
true );
695 mxCursor->setString(
"" );
698 GetImport().GetTextImport()->ResetCursor();
702 GetImport().GetTextImport()->SetCursor( mxOldCursor );
705 if (mbListContextPushed) {
706 GetImport().GetTextImport()->PopListContext();
711XMLTableTemplateContext::XMLTableTemplateContext( SvXMLImport& rImport )
716void XMLTableTemplateContext::SetAttribute( sal_Int32 nElement,
717 const OUString& rValue )
723 msTemplateStyleName = rValue;
727void XMLTableTemplateContext::endFastElement(sal_Int32 )
730 if( xTableImport.is() )
731 xTableImport->addTableTemplate( msTemplateStyleName, maTableTemplate );
734css::uno::Reference< css::xml::sax::XFastContextHandler > XMLTableTemplateContext::createFastChildContext(
736 const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList )
749 switch (aIter.getToken())
771 switch (aIter.getToken())
std::map< OUString, OUString > XMLTableTemplate
unotools::WeakReference< AnimationNode > mxParent
constexpr OUStringLiteral sTemplateName
This class deliberately does not support XWeak, to improve performance when loading large documents.
virtual void SAL_CALL endFastElement(sal_Int32 Element) override
endFastElement is called before a context will be destructed, but after an elements context has been ...
SvXMLImport & GetImport()
virtual css::uno::Reference< XFastContextHandler > SAL_CALL createFastChildContext(sal_Int32 Element, const css::uno::Reference< css::xml::sax::XFastAttributeList > &Attribs) override
virtual bool handleSpecialItem(XMLPropertyState &rProperty, ::std::vector< XMLPropertyState > &rProperties, const OUString &rValue, const SvXMLUnitConverter &rUnitConverter, const SvXMLNamespaceMap &rNamespaceMap) const
this method is called for every item that has the MID_FLAG_SPECIAL_ITEM_IMPORT flag set
const rtl::Reference< XMLPropertySetMapper > & getPropertySetMapper() const
SvXMLImportPropertyMapper(SvXMLImportPropertyMapper const &)=delete
virtual void SetAttribute(sal_Int32 nElement, const OUString &rValue)
const SvXMLStyleContext * FindStyleChildContext(XmlStyleFamily nFamily, const OUString &rName, bool bCreateIndex=false) const
the SvXMLTypeConverter converts values of various types from their internal representation to the tex...
SvXMLImportContext * ImportRow(const Reference< XFastAttributeList > &xAttrList)
Reference< XTableRows > mxRows
sal_Int32 mnCurrentColumn
XMLTableImportContext(const rtl::Reference< XMLTableImport > &xThis, Reference< XColumnRowRange > const &xColumnRowRange)
SvXMLImportContextRef ImportColumn(const Reference< XFastAttributeList > &xAttrList)
OUString msDefaultCellStyleName
virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &AttrList) override
OUString GetDefaultCellStyleName() const
css::uno::Reference< css::table::XTable > mxTable
std::vector< std::shared_ptr< ColumnInfo > > maColumnInfos
virtual void SAL_CALL endFastElement(sal_Int32 nElement) override
endFastElement is called before a context will be destructed, but after an elements context has been ...
std::vector< std::shared_ptr< MergeInfo > > maMergeInfos
Reference< XTableColumns > mxColumns
SvXMLImportContextRef ImportCell(sal_Int32 nElement, const Reference< XFastAttributeList > &xAttrList)
virtual ~XMLTableImport() override
void finishStyles()
Inserts all table templates.
friend class XMLTableImportContext
SvXMLImportContext * CreateTableContext(css::uno::Reference< css::table::XColumnRowRange > const &xColumnRowRange)
XMLTableImport(SvXMLImport &rImport, const rtl::Reference< XMLPropertySetMapper > &xCellPropertySetMapper, const rtl::Reference< XMLPropertyHandlerFactory > &xFactoryRef)
XMLTableTemplateMap maTableTemplates
rtl::Reference< SvXMLImportPropertyMapper > mxCellImportPropertySetMapper
rtl::Reference< SvXMLImportPropertyMapper > mxColumnImportPropertySetMapper
SvXMLStyleContext * CreateTableTemplateContext(sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList)
void addTableTemplate(const OUString &rsStyleName, XMLTableTemplate &xTableTemplate)
rtl::Reference< SvXMLImportPropertyMapper > mxRowImportPropertySetMapper
static SvXMLImportPropertyMapper * CreateParaExtPropMapper(SvXMLImport &)
static SvXMLImportPropertyMapper * CreateTableCellExtPropMapper(SvXMLImport &)
#define TOOLS_WARN_EXCEPTION(area, stream)
Reference< XSingleServiceFactory > xFactory
#define SAL_WARN(area, stream)
sal_Int32 findValue(const css::uno::Sequence< T1 > &_rList, const T2 &_rValue)
FastAttributeList & castToFastAttributeList(const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList)
OUString toString(OptionInfo const *info)
Handling of tokens in XML:
@ XML_DEFAULT_CELL_STYLE_NAME
@ XML_NUMBER_COLUMNS_SPANNED
@ XML_NUMBER_ROWS_SPANNED
@ XML_NUMBER_COLUMNS_REPEATED
bool IsXMLToken(std::u16string_view rString, enum XMLTokenEnum eToken)
compare eToken to the string
const OUString & GetXMLToken(enum XMLTokenEnum eToken)
return the OUString representation for eToken
sal_Int32 toInt32(std::u16string_view rStr)
::xmloff::token::XMLTokenEnum meElement
Smart struct to transport an Any with an index to the appropriate property-name.
const XMLPropertyMapEntry * getColumnPropertiesMap()
const TableStyleElement * getTableStyleMap()
const TableStyleElement * getWriterSpecificTableStyleMap()
const XMLPropertyMapEntry * getRowPropertiesMap()
const XMLPropertyMapEntry * getCellPropertiesMap()
#define XMLOFF_WARN_UNKNOWN_ELEMENT(area, token)
#define XMLOFF_WARN_UNKNOWN(area, rIter)
#define XML_ELEMENT(prefix, name)
constexpr bool IsTokenInNamespace(sal_Int32 nToken, sal_uInt16 nNamespacePrefix)
constexpr sal_Int32 TOKEN_MASK
constexpr sal_uInt16 XML_NAMESPACE_DRAW
constexpr sal_uInt16 XML_NAMESPACE_TABLE
constexpr sal_uInt16 XML_NAMESPACE_LO_EXT