[Libreoffice-commits] core.git: Branch 'feature/gsoc-calc-enhanced-db-range' - sc/source

Akash Shetye shetyeakash at gmail.com
Mon Jun 24 22:56:58 PDT 2013


 sc/source/filter/inc/stylesbuffer.hxx   |   24 ++++++++++++++++-
 sc/source/filter/inc/stylesfragment.hxx |   15 ++++++++++
 sc/source/filter/oox/stylesbuffer.cxx   |   45 ++++++++++++++++++++++++++++++++
 sc/source/filter/oox/stylesfragment.cxx |   24 ++++++++++++++++-
 4 files changed, 106 insertions(+), 2 deletions(-)

New commits:
commit c0801d4dbda418835ad30c89fce8f2185a5fffe5
Author: Akash Shetye <shetyeakash at gmail.com>
Date:   Tue Jun 25 11:24:34 2013 +0530

    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

diff --git a/sc/source/filter/inc/stylesbuffer.hxx b/sc/source/filter/inc/stylesbuffer.hxx
index 32b439c..10a18ab 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;
@@ -787,6 +788,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
 {
@@ -922,7 +940,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. */
@@ -997,6 +1017,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.
@@ -1008,6 +1029,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 5e8f177..43370af 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 cead31d..5428a34 100644
--- a/sc/source/filter/oox/stylesbuffer.cxx
+++ b/sc/source/filter/oox/stylesbuffer.cxx
@@ -2649,6 +2649,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_";
@@ -3105,6 +3140,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 );
@@ -3155,6 +3198,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 ee21b2a..2a6bb94 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;
 }


More information about the Libreoffice-commits mailing list