1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir #include "oox/xls/stylesfragment.hxx" 29*cdf0e10cSrcweir 30*cdf0e10cSrcweir #include "oox/helper/attributelist.hxx" 31*cdf0e10cSrcweir 32*cdf0e10cSrcweir namespace oox { 33*cdf0e10cSrcweir namespace xls { 34*cdf0e10cSrcweir 35*cdf0e10cSrcweir // ============================================================================ 36*cdf0e10cSrcweir 37*cdf0e10cSrcweir using namespace ::oox::core; 38*cdf0e10cSrcweir 39*cdf0e10cSrcweir using ::rtl::OUString; 40*cdf0e10cSrcweir 41*cdf0e10cSrcweir // ============================================================================ 42*cdf0e10cSrcweir 43*cdf0e10cSrcweir IndexedColorsContext::IndexedColorsContext( WorkbookFragmentBase& rFragment ) : 44*cdf0e10cSrcweir WorkbookContextBase( rFragment ) 45*cdf0e10cSrcweir { 46*cdf0e10cSrcweir } 47*cdf0e10cSrcweir 48*cdf0e10cSrcweir ContextHandlerRef IndexedColorsContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs ) 49*cdf0e10cSrcweir { 50*cdf0e10cSrcweir switch( getCurrentElement() ) 51*cdf0e10cSrcweir { 52*cdf0e10cSrcweir case XLS_TOKEN( indexedColors ): 53*cdf0e10cSrcweir if( nElement == XLS_TOKEN( rgbColor ) ) getStyles().importPaletteColor( rAttribs ); 54*cdf0e10cSrcweir break; 55*cdf0e10cSrcweir } 56*cdf0e10cSrcweir return 0; 57*cdf0e10cSrcweir } 58*cdf0e10cSrcweir 59*cdf0e10cSrcweir ContextHandlerRef IndexedColorsContext::onCreateRecordContext( sal_Int32 nRecId, SequenceInputStream& rStrm ) 60*cdf0e10cSrcweir { 61*cdf0e10cSrcweir switch( getCurrentElement() ) 62*cdf0e10cSrcweir { 63*cdf0e10cSrcweir case BIFF12_ID_INDEXEDCOLORS: 64*cdf0e10cSrcweir if( nRecId == BIFF12_ID_RGBCOLOR ) getStyles().importPaletteColor( rStrm ); 65*cdf0e10cSrcweir break; 66*cdf0e10cSrcweir } 67*cdf0e10cSrcweir return 0; 68*cdf0e10cSrcweir } 69*cdf0e10cSrcweir 70*cdf0e10cSrcweir // ============================================================================ 71*cdf0e10cSrcweir 72*cdf0e10cSrcweir ContextHandlerRef FontContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs ) 73*cdf0e10cSrcweir { 74*cdf0e10cSrcweir if( mxFont.get() ) 75*cdf0e10cSrcweir mxFont->importAttribs( nElement, rAttribs ); 76*cdf0e10cSrcweir return 0; 77*cdf0e10cSrcweir } 78*cdf0e10cSrcweir 79*cdf0e10cSrcweir // ============================================================================ 80*cdf0e10cSrcweir 81*cdf0e10cSrcweir void BorderContext::onStartElement( const AttributeList& rAttribs ) 82*cdf0e10cSrcweir { 83*cdf0e10cSrcweir if( mxBorder.get() && (getCurrentElement() == XLS_TOKEN( border )) ) 84*cdf0e10cSrcweir mxBorder->importBorder( rAttribs ); 85*cdf0e10cSrcweir } 86*cdf0e10cSrcweir 87*cdf0e10cSrcweir ContextHandlerRef BorderContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs ) 88*cdf0e10cSrcweir { 89*cdf0e10cSrcweir if( mxBorder.get() ) switch( getCurrentElement() ) 90*cdf0e10cSrcweir { 91*cdf0e10cSrcweir case XLS_TOKEN( border ): 92*cdf0e10cSrcweir mxBorder->importStyle( nElement, rAttribs ); 93*cdf0e10cSrcweir return this; 94*cdf0e10cSrcweir 95*cdf0e10cSrcweir default: 96*cdf0e10cSrcweir if( nElement == XLS_TOKEN( color ) ) 97*cdf0e10cSrcweir mxBorder->importColor( getCurrentElement(), rAttribs ); 98*cdf0e10cSrcweir } 99*cdf0e10cSrcweir return 0; 100*cdf0e10cSrcweir } 101*cdf0e10cSrcweir 102*cdf0e10cSrcweir // ============================================================================ 103*cdf0e10cSrcweir 104*cdf0e10cSrcweir ContextHandlerRef FillContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs ) 105*cdf0e10cSrcweir { 106*cdf0e10cSrcweir if( mxFill.get() ) switch( getCurrentElement() ) 107*cdf0e10cSrcweir { 108*cdf0e10cSrcweir case XLS_TOKEN( fill ): 109*cdf0e10cSrcweir switch( nElement ) 110*cdf0e10cSrcweir { 111*cdf0e10cSrcweir case XLS_TOKEN( patternFill ): mxFill->importPatternFill( rAttribs ); return this; 112*cdf0e10cSrcweir case XLS_TOKEN( gradientFill ): mxFill->importGradientFill( rAttribs ); return this; 113*cdf0e10cSrcweir } 114*cdf0e10cSrcweir break; 115*cdf0e10cSrcweir case XLS_TOKEN( patternFill ): 116*cdf0e10cSrcweir switch( nElement ) 117*cdf0e10cSrcweir { 118*cdf0e10cSrcweir case XLS_TOKEN( fgColor ): mxFill->importFgColor( rAttribs ); break; 119*cdf0e10cSrcweir case XLS_TOKEN( bgColor ): mxFill->importBgColor( rAttribs ); break; 120*cdf0e10cSrcweir } 121*cdf0e10cSrcweir break; 122*cdf0e10cSrcweir case XLS_TOKEN( gradientFill ): 123*cdf0e10cSrcweir if( nElement == XLS_TOKEN( stop ) ) 124*cdf0e10cSrcweir { 125*cdf0e10cSrcweir mfGradPos = rAttribs.getDouble( XML_position, -1.0 ); 126*cdf0e10cSrcweir return this; 127*cdf0e10cSrcweir } 128*cdf0e10cSrcweir break; 129*cdf0e10cSrcweir case XLS_TOKEN( stop ): 130*cdf0e10cSrcweir if( nElement == XLS_TOKEN( color ) ) 131*cdf0e10cSrcweir mxFill->importColor( rAttribs, mfGradPos ); 132*cdf0e10cSrcweir break; 133*cdf0e10cSrcweir } 134*cdf0e10cSrcweir return 0; 135*cdf0e10cSrcweir } 136*cdf0e10cSrcweir 137*cdf0e10cSrcweir // ============================================================================ 138*cdf0e10cSrcweir 139*cdf0e10cSrcweir void XfContext::onStartElement( const AttributeList& rAttribs ) 140*cdf0e10cSrcweir { 141*cdf0e10cSrcweir if( mxXf.get() && (getCurrentElement() == XLS_TOKEN( xf )) ) 142*cdf0e10cSrcweir mxXf->importXf( rAttribs, mbCellXf ); 143*cdf0e10cSrcweir } 144*cdf0e10cSrcweir 145*cdf0e10cSrcweir ContextHandlerRef XfContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs ) 146*cdf0e10cSrcweir { 147*cdf0e10cSrcweir if( mxXf.get() ) switch( getCurrentElement() ) 148*cdf0e10cSrcweir { 149*cdf0e10cSrcweir case XLS_TOKEN( xf ): 150*cdf0e10cSrcweir switch( nElement ) 151*cdf0e10cSrcweir { 152*cdf0e10cSrcweir case XLS_TOKEN( alignment ): mxXf->importAlignment( rAttribs ); break; 153*cdf0e10cSrcweir case XLS_TOKEN( protection ): mxXf->importProtection( rAttribs ); break; 154*cdf0e10cSrcweir } 155*cdf0e10cSrcweir break; 156*cdf0e10cSrcweir } 157*cdf0e10cSrcweir return 0; 158*cdf0e10cSrcweir } 159*cdf0e10cSrcweir 160*cdf0e10cSrcweir // ============================================================================ 161*cdf0e10cSrcweir 162*cdf0e10cSrcweir ContextHandlerRef DxfContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs ) 163*cdf0e10cSrcweir { 164*cdf0e10cSrcweir if( mxDxf.get() ) switch( getCurrentElement() ) 165*cdf0e10cSrcweir { 166*cdf0e10cSrcweir case XLS_TOKEN( dxf ): 167*cdf0e10cSrcweir switch( nElement ) 168*cdf0e10cSrcweir { 169*cdf0e10cSrcweir case XLS_TOKEN( font ): return new FontContext( *this, mxDxf->createFont() ); 170*cdf0e10cSrcweir case XLS_TOKEN( border ): return new BorderContext( *this, mxDxf->createBorder() ); 171*cdf0e10cSrcweir case XLS_TOKEN( fill ): return new FillContext( *this, mxDxf->createFill() ); 172*cdf0e10cSrcweir 173*cdf0e10cSrcweir case XLS_TOKEN( numFmt ): mxDxf->importNumFmt( rAttribs ); break; 174*cdf0e10cSrcweir #if 0 175*cdf0e10cSrcweir case XLS_TOKEN( alignment ): mxDxf->importAlignment( rAttribs ); break; 176*cdf0e10cSrcweir case XLS_TOKEN( protection ): mxDxf->importProtection( rAttribs ); break; 177*cdf0e10cSrcweir #endif 178*cdf0e10cSrcweir } 179*cdf0e10cSrcweir break; 180*cdf0e10cSrcweir } 181*cdf0e10cSrcweir return 0; 182*cdf0e10cSrcweir } 183*cdf0e10cSrcweir 184*cdf0e10cSrcweir // ============================================================================ 185*cdf0e10cSrcweir 186*cdf0e10cSrcweir StylesFragment::StylesFragment( const WorkbookHelper& rHelper, const OUString& rFragmentPath ) : 187*cdf0e10cSrcweir WorkbookFragmentBase( rHelper, rFragmentPath ) 188*cdf0e10cSrcweir { 189*cdf0e10cSrcweir } 190*cdf0e10cSrcweir 191*cdf0e10cSrcweir ContextHandlerRef StylesFragment::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs ) 192*cdf0e10cSrcweir { 193*cdf0e10cSrcweir switch( getCurrentElement() ) 194*cdf0e10cSrcweir { 195*cdf0e10cSrcweir case XML_ROOT_CONTEXT: 196*cdf0e10cSrcweir if( nElement == XLS_TOKEN( styleSheet ) ) return this; 197*cdf0e10cSrcweir break; 198*cdf0e10cSrcweir 199*cdf0e10cSrcweir case XLS_TOKEN( styleSheet ): 200*cdf0e10cSrcweir switch( nElement ) 201*cdf0e10cSrcweir { 202*cdf0e10cSrcweir case XLS_TOKEN( colors ): 203*cdf0e10cSrcweir case XLS_TOKEN( numFmts ): 204*cdf0e10cSrcweir case XLS_TOKEN( fonts ): 205*cdf0e10cSrcweir case XLS_TOKEN( borders ): 206*cdf0e10cSrcweir case XLS_TOKEN( fills ): 207*cdf0e10cSrcweir case XLS_TOKEN( cellXfs ): 208*cdf0e10cSrcweir case XLS_TOKEN( cellStyleXfs ): 209*cdf0e10cSrcweir case XLS_TOKEN( dxfs ): 210*cdf0e10cSrcweir case XLS_TOKEN( cellStyles ): return this; 211*cdf0e10cSrcweir } 212*cdf0e10cSrcweir break; 213*cdf0e10cSrcweir 214*cdf0e10cSrcweir case XLS_TOKEN( colors ): 215*cdf0e10cSrcweir if( nElement == XLS_TOKEN( indexedColors ) ) return new IndexedColorsContext( *this ); 216*cdf0e10cSrcweir break; 217*cdf0e10cSrcweir case XLS_TOKEN( numFmts ): 218*cdf0e10cSrcweir if( nElement == XLS_TOKEN( numFmt ) ) getStyles().importNumFmt( rAttribs ); 219*cdf0e10cSrcweir break; 220*cdf0e10cSrcweir case XLS_TOKEN( fonts ): 221*cdf0e10cSrcweir if( nElement == XLS_TOKEN( font ) ) return new FontContext( *this, getStyles().createFont() ); 222*cdf0e10cSrcweir break; 223*cdf0e10cSrcweir case XLS_TOKEN( borders ): 224*cdf0e10cSrcweir if( nElement == XLS_TOKEN( border ) ) return new BorderContext( *this, getStyles().createBorder() ); 225*cdf0e10cSrcweir break; 226*cdf0e10cSrcweir case XLS_TOKEN( fills ): 227*cdf0e10cSrcweir if( nElement == XLS_TOKEN( fill ) ) return new FillContext( *this, getStyles().createFill() ); 228*cdf0e10cSrcweir break; 229*cdf0e10cSrcweir case XLS_TOKEN( cellXfs ): 230*cdf0e10cSrcweir if( nElement == XLS_TOKEN( xf ) ) return new XfContext( *this, getStyles().createCellXf(), true ); 231*cdf0e10cSrcweir break; 232*cdf0e10cSrcweir case XLS_TOKEN( cellStyleXfs ): 233*cdf0e10cSrcweir if( nElement == XLS_TOKEN( xf ) ) return new XfContext( *this, getStyles().createStyleXf(), false ); 234*cdf0e10cSrcweir break; 235*cdf0e10cSrcweir case XLS_TOKEN( dxfs ): 236*cdf0e10cSrcweir if( nElement == XLS_TOKEN( dxf ) ) return new DxfContext( *this, getStyles().createDxf() ); 237*cdf0e10cSrcweir break; 238*cdf0e10cSrcweir case XLS_TOKEN( cellStyles ): 239*cdf0e10cSrcweir if( nElement == XLS_TOKEN( cellStyle ) ) getStyles().importCellStyle( rAttribs ); 240*cdf0e10cSrcweir break; 241*cdf0e10cSrcweir } 242*cdf0e10cSrcweir return 0; 243*cdf0e10cSrcweir } 244*cdf0e10cSrcweir 245*cdf0e10cSrcweir ContextHandlerRef StylesFragment::onCreateRecordContext( sal_Int32 nRecId, SequenceInputStream& rStrm ) 246*cdf0e10cSrcweir { 247*cdf0e10cSrcweir switch( getCurrentElement() ) 248*cdf0e10cSrcweir { 249*cdf0e10cSrcweir case XML_ROOT_CONTEXT: 250*cdf0e10cSrcweir if( nRecId == BIFF12_ID_STYLESHEET ) return this; 251*cdf0e10cSrcweir break; 252*cdf0e10cSrcweir 253*cdf0e10cSrcweir case BIFF12_ID_STYLESHEET: 254*cdf0e10cSrcweir switch( nRecId ) 255*cdf0e10cSrcweir { 256*cdf0e10cSrcweir case BIFF12_ID_COLORS: 257*cdf0e10cSrcweir case BIFF12_ID_NUMFMTS: 258*cdf0e10cSrcweir case BIFF12_ID_FONTS: 259*cdf0e10cSrcweir case BIFF12_ID_BORDERS: 260*cdf0e10cSrcweir case BIFF12_ID_FILLS: 261*cdf0e10cSrcweir case BIFF12_ID_CELLXFS: 262*cdf0e10cSrcweir case BIFF12_ID_CELLSTYLEXFS: 263*cdf0e10cSrcweir case BIFF12_ID_DXFS: 264*cdf0e10cSrcweir case BIFF12_ID_CELLSTYLES: return this; 265*cdf0e10cSrcweir } 266*cdf0e10cSrcweir break; 267*cdf0e10cSrcweir 268*cdf0e10cSrcweir case BIFF12_ID_COLORS: 269*cdf0e10cSrcweir if( nRecId == BIFF12_ID_INDEXEDCOLORS ) return new IndexedColorsContext( *this ); 270*cdf0e10cSrcweir break; 271*cdf0e10cSrcweir case BIFF12_ID_NUMFMTS: 272*cdf0e10cSrcweir if( nRecId == BIFF12_ID_NUMFMT ) getStyles().importNumFmt( rStrm ); 273*cdf0e10cSrcweir break; 274*cdf0e10cSrcweir case BIFF12_ID_FONTS: 275*cdf0e10cSrcweir if( nRecId == BIFF12_ID_FONT ) getStyles().createFont()->importFont( rStrm ); 276*cdf0e10cSrcweir break; 277*cdf0e10cSrcweir case BIFF12_ID_BORDERS: 278*cdf0e10cSrcweir if( nRecId == BIFF12_ID_BORDER ) getStyles().createBorder()->importBorder( rStrm ); 279*cdf0e10cSrcweir break; 280*cdf0e10cSrcweir case BIFF12_ID_FILLS: 281*cdf0e10cSrcweir if( nRecId == BIFF12_ID_FILL ) getStyles().createFill()->importFill( rStrm ); 282*cdf0e10cSrcweir break; 283*cdf0e10cSrcweir case BIFF12_ID_CELLXFS: 284*cdf0e10cSrcweir if( nRecId == BIFF12_ID_XF ) getStyles().createCellXf()->importXf( rStrm, true ); 285*cdf0e10cSrcweir break; 286*cdf0e10cSrcweir case BIFF12_ID_CELLSTYLEXFS: 287*cdf0e10cSrcweir if( nRecId == BIFF12_ID_XF ) getStyles().createStyleXf()->importXf( rStrm, false ); 288*cdf0e10cSrcweir break; 289*cdf0e10cSrcweir case BIFF12_ID_DXFS: 290*cdf0e10cSrcweir if( nRecId == BIFF12_ID_DXF ) getStyles().createDxf()->importDxf( rStrm ); 291*cdf0e10cSrcweir break; 292*cdf0e10cSrcweir case BIFF12_ID_CELLSTYLES: 293*cdf0e10cSrcweir if( nRecId == BIFF12_ID_CELLSTYLE ) getStyles().importCellStyle( rStrm ); 294*cdf0e10cSrcweir break; 295*cdf0e10cSrcweir } 296*cdf0e10cSrcweir return 0; 297*cdf0e10cSrcweir } 298*cdf0e10cSrcweir 299*cdf0e10cSrcweir const RecordInfo* StylesFragment::getRecordInfos() const 300*cdf0e10cSrcweir { 301*cdf0e10cSrcweir static const RecordInfo spRecInfos[] = 302*cdf0e10cSrcweir { 303*cdf0e10cSrcweir { BIFF12_ID_BORDERS, BIFF12_ID_BORDERS + 1 }, 304*cdf0e10cSrcweir { BIFF12_ID_CELLSTYLES, BIFF12_ID_CELLSTYLES + 1 }, 305*cdf0e10cSrcweir { BIFF12_ID_CELLSTYLEXFS, BIFF12_ID_CELLSTYLEXFS + 1 }, 306*cdf0e10cSrcweir { BIFF12_ID_CELLXFS, BIFF12_ID_CELLXFS + 1 }, 307*cdf0e10cSrcweir { BIFF12_ID_COLORS, BIFF12_ID_COLORS + 1 }, 308*cdf0e10cSrcweir { BIFF12_ID_DXFS, BIFF12_ID_DXFS + 1 }, 309*cdf0e10cSrcweir { BIFF12_ID_FILLS, BIFF12_ID_FILLS + 1 }, 310*cdf0e10cSrcweir { BIFF12_ID_FONTS, BIFF12_ID_FONTS + 1 }, 311*cdf0e10cSrcweir { BIFF12_ID_INDEXEDCOLORS, BIFF12_ID_INDEXEDCOLORS + 1 }, 312*cdf0e10cSrcweir { BIFF12_ID_MRUCOLORS, BIFF12_ID_MRUCOLORS + 1 }, 313*cdf0e10cSrcweir { BIFF12_ID_NUMFMTS, BIFF12_ID_NUMFMTS + 1 }, 314*cdf0e10cSrcweir { BIFF12_ID_STYLESHEET, BIFF12_ID_STYLESHEET + 1 }, 315*cdf0e10cSrcweir { BIFF12_ID_TABLESTYLES, BIFF12_ID_TABLESTYLES + 1 }, 316*cdf0e10cSrcweir { -1, -1 } 317*cdf0e10cSrcweir }; 318*cdf0e10cSrcweir return spRecInfos; 319*cdf0e10cSrcweir } 320*cdf0e10cSrcweir 321*cdf0e10cSrcweir void StylesFragment::finalizeImport() 322*cdf0e10cSrcweir { 323*cdf0e10cSrcweir getStyles().finalizeImport(); 324*cdf0e10cSrcweir } 325*cdf0e10cSrcweir 326*cdf0e10cSrcweir // ============================================================================ 327*cdf0e10cSrcweir 328*cdf0e10cSrcweir } // namespace xls 329*cdf0e10cSrcweir } // namespace oox 330