diff options
author | Akash Shetye <shetyeakash@gmail.com> | 2013-06-25 11:24:34 +0530 |
---|---|---|
committer | Kohei Yoshida <kohei.yoshida@gmail.com> | 2013-08-05 14:30:19 -0400 |
commit | f2dd5e1e3f43a2dc113ca2e7201878efa3fc451f (patch) | |
tree | aa0cc524c5000d95f7d720cca4a9e699113a3881 | |
parent | 5ee29a4969d52118d083468db728b53f5a466c06 (diff) |
Adds support for table style tag reading and filling in the formatting object
This patch contains the bulk of the style.xml parsing modifications to read the <tableStyle> and <tableStyleElement> tags and fill in the ScDBDataFormatting information.
Change-Id: Ic3981dcb29ee09b26940b51dd94d750603e1c4f4
-rw-r--r-- | sc/source/filter/inc/stylesbuffer.hxx | 24 | ||||
-rw-r--r-- | sc/source/filter/inc/stylesfragment.hxx | 15 | ||||
-rw-r--r-- | sc/source/filter/oox/stylesbuffer.cxx | 45 | ||||
-rw-r--r-- | sc/source/filter/oox/stylesfragment.cxx | 24 |
4 files changed, 106 insertions, 2 deletions
diff --git a/sc/source/filter/inc/stylesbuffer.hxx b/sc/source/filter/inc/stylesbuffer.hxx index cbedfb3a2464..c8c783de7919 100644 --- a/sc/source/filter/inc/stylesbuffer.hxx +++ b/sc/source/filter/inc/stylesbuffer.hxx @@ -36,6 +36,7 @@ #include <editeng/svxenum.hxx> #include <editeng/frmdir.hxx> #include "attarray.hxx" +#include "dbdataformatting.hxx" #include <list> class ScMarkData; @@ -785,6 +786,23 @@ typedef ::boost::shared_ptr< Dxf > DxfRef; // ============================================================================ +/* Contains attributes for table styles from the <tableStyle> element */ +class TableStyle : public WorkbookHelper +{ +public: + explicit TableStyle( const WorkbookHelper& rHelper, const OUString& rTableStyleName ); + void importTableStyleElement( const AttributeList& rAttribs ); + void finalizeImport(); +private: + typedef ::boost::shared_ptr< ::ScDBDataFormatting > TableFormattingRef; + + TableFormattingRef mxTableFormatting; +}; + +typedef ::boost::shared_ptr< TableStyle > TableStyleRef; + +// ============================================================================ + /** Contains attributes of a cell style, e.g. from the cellStyle element. */ struct CellStyleModel { @@ -920,7 +938,9 @@ public: /** Creates a new empty differential formatting object. @param opnDxfId (out-param) The identifier of the new DXF object. */ DxfRef createDxf( sal_Int32* opnDxfId = 0 ); - + /** Creates a new TableStyle object for storing table formatting. + @param opnTableStyleId (out-param) The identifier of the new TableStyle object. */ + TableStyleRef createTableStyle(const OUString& rTableStyleName, sal_Int32* opnTableStyleId = 0 ); /** Appends a new color to the color palette. */ void importPaletteColor( const AttributeList& rAttribs ); /** Inserts a new number format code. */ @@ -995,6 +1015,7 @@ private: typedef RefVector< Fill > FillVector; typedef RefVector< Xf > XfVector; typedef RefVector< Dxf > DxfVector; + typedef RefVector< TableStyle > TableStyleVector; typedef ::std::map< sal_Int32, OUString > DxfStyleMap; ColorPalette maPalette; /// Color palette. @@ -1006,6 +1027,7 @@ private: XfVector maStyleXfs; /// List of cell styles. CellStyleBuffer maCellStyles; /// All built-in and user defined cell styles. DxfVector maDxfs; /// List of differential cell styles. + TableStyleVector maTableStyles; /// List of Table styles for tables. mutable DxfStyleMap maDxfStyles; /// Maps DXF identifiers to Calc style sheet names. }; diff --git a/sc/source/filter/inc/stylesfragment.hxx b/sc/source/filter/inc/stylesfragment.hxx index 5e8f1770c34d..43370af1f1c2 100644 --- a/sc/source/filter/inc/stylesfragment.hxx +++ b/sc/source/filter/inc/stylesfragment.hxx @@ -124,6 +124,21 @@ private: // ============================================================================ +class TableStyleContext : public WorkbookContextBase +{ +public: + template< typename ParentType > + inline explicit TableStyleContext( ParentType& rParent, const TableStyleRef& rxTableStyle ) : + WorkbookContextBase( rParent ), mxTableStyle( rxTableStyle ) {} +protected: + virtual ::oox::core::ContextHandlerRef onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs ); + +private: + TableStyleRef mxTableStyle; +}; + +// ============================================================================ + class StylesFragment : public WorkbookFragmentBase { public: diff --git a/sc/source/filter/oox/stylesbuffer.cxx b/sc/source/filter/oox/stylesbuffer.cxx index e34080eca1f9..218e000aff0a 100644 --- a/sc/source/filter/oox/stylesbuffer.cxx +++ b/sc/source/filter/oox/stylesbuffer.cxx @@ -2630,6 +2630,41 @@ void Dxf::writeToPropertySet( PropertySet& rPropSet ) const // ============================================================================ +TableStyle::TableStyle( const WorkbookHelper& rHelper, const OUString& rTableStyleName ) : + WorkbookHelper( rHelper ) +{ + mxTableFormatting.reset( new ::ScDBDataFormatting() ); + mxTableFormatting->SetTableStyleName( rTableStyleName ); +} + +void TableStyle::importTableStyleElement( const AttributeList& rAttribs ) +{ + //Get the table Style element type. + OUString aStyleElementType = rAttribs.getXString( XML_type, OUString() ); + //Extract the Dxf Id and create such a style + sal_Int32 aDxfId = static_cast< sal_Int32 >( rAttribs.getInteger( XML_dxfId, -1 ) ); + SAL_WARN_IF( (aDxfId == -1) ,"sc", "TableStyle::importTableStyleElement - DxfId not defined for table style element" ); + //Should I stop on finding this missing feild or keep going? + OUString aDxfStyleName = getStyles().createDxfStyle( aDxfId ); + if( aStyleElementType.equals("firstColumnStripe") ) + mxTableFormatting->SetFirstColStripeStyle( aDxfStyleName ); + else if( aStyleElementType.equals("secondColumnStripe") ) + mxTableFormatting->SetSecondColStripeStyle( aDxfStyleName ); + else if( aStyleElementType.equals("firstRowStripe") ) + mxTableFormatting->SetFirstRowStripeStyle( aDxfStyleName ); + else if( aStyleElementType.equals("secondRowStripe") ) + mxTableFormatting->SetSecondRowStripeStyle( aDxfStyleName ); + //Though the Dxf styles are being imported, the bsckground color etc + //is not showing up. +} + +void TableStyle::finalizeImport() +{ +} + + +// ============================================================================ + namespace { const sal_Char* const spcLegacyStyleNamePrefix = "Excel_BuiltIn_"; @@ -3086,6 +3121,14 @@ DxfRef StylesBuffer::createDxf( sal_Int32* opnDxfId ) return xDxf; } +TableStyleRef StylesBuffer::createTableStyle( const OUString& rTableStyleName, sal_Int32* opnTableStyleId ) // should I be using sal_Int32 here?? +{ + if( opnTableStyleId ) *opnTableStyleId = static_cast< sal_Int32 >( maTableStyles.size() ); + TableStyleRef xTableStyle( new TableStyle( *this, rTableStyleName ) ); + maTableStyles.push_back( xTableStyle ); + return xTableStyle; +} + void StylesBuffer::importPaletteColor( const AttributeList& rAttribs ) { maPalette.importPaletteColor( rAttribs ); @@ -3136,6 +3179,8 @@ void StylesBuffer::finalizeImport() maCellStyles.finalizeImport(); // differential formatting (for conditional formatting) maDxfs.forEachMem( &Dxf::finalizeImport ); + // Table Styles + maTableStyles.forEachMem( &TableStyle::finalizeImport ); } sal_Int32 StylesBuffer::getPaletteColor( sal_Int32 nPaletteIdx ) const diff --git a/sc/source/filter/oox/stylesfragment.cxx b/sc/source/filter/oox/stylesfragment.cxx index ee21b2a07877..2a6bb94fb01e 100644 --- a/sc/source/filter/oox/stylesfragment.cxx +++ b/sc/source/filter/oox/stylesfragment.cxx @@ -174,6 +174,23 @@ ContextHandlerRef DxfContext::onCreateContext( sal_Int32 nElement, const Attribu // ============================================================================ +ContextHandlerRef TableStyleContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs ) +{ + if( mxTableStyle.get() ) switch( getCurrentElement() ) + { + case XLS_TOKEN( tableStyle ): + switch( nElement ) + { + case XLS_TOKEN( tableStyleElement ): + mxTableStyle->importTableStyleElement( rAttribs ); + break; + } + } + return 0; +} + +// ============================================================================ + StylesFragment::StylesFragment( const WorkbookHelper& rHelper, const OUString& rFragmentPath ) : WorkbookFragmentBase( rHelper, rFragmentPath ) { @@ -198,7 +215,8 @@ ContextHandlerRef StylesFragment::onCreateContext( sal_Int32 nElement, const Att case XLS_TOKEN( cellXfs ): case XLS_TOKEN( cellStyleXfs ): case XLS_TOKEN( dxfs ): - case XLS_TOKEN( cellStyles ): return this; + case XLS_TOKEN( cellStyles ): + case XLS_TOKEN( tableStyles ): return this; } break; @@ -229,6 +247,10 @@ ContextHandlerRef StylesFragment::onCreateContext( sal_Int32 nElement, const Att case XLS_TOKEN( cellStyles ): if( nElement == XLS_TOKEN( cellStyle ) ) getStyles().importCellStyle( rAttribs ); break; + case XLS_TOKEN( tableStyles ): + OUString aTableStyleName = rAttribs.getXString( XML_name, OUString() ); + if( nElement == XLS_TOKEN( tableStyle ) ) return new TableStyleContext( *this, getStyles().createTableStyle( aTableStyleName ) ); + break; } return 0; } |