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