Version 6.4.0.3, tag libreoffice-6.4.0.3
[LibreOffice.git] / sc / source / filter / oox / stylesfragment.cxx
blob2c2c9968703d5a45127e71f96d9cc591b72b7a88
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <stylesfragment.hxx>
21 #include <biffhelper.hxx>
23 #include <oox/helper/attributelist.hxx>
24 #include <oox/token/namespaces.hxx>
25 #include <oox/token/tokens.hxx>
27 namespace oox {
28 namespace xls {
30 using namespace ::oox::core;
32 IndexedColorsContext::IndexedColorsContext( WorkbookFragmentBase& rFragment ) :
33 WorkbookContextBase( rFragment )
37 ContextHandlerRef IndexedColorsContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs )
39 switch( getCurrentElement() )
41 case XLS_TOKEN( indexedColors ):
42 if( nElement == XLS_TOKEN( rgbColor ) ) getStyles().importPaletteColor( rAttribs );
43 break;
45 return nullptr;
48 ContextHandlerRef IndexedColorsContext::onCreateRecordContext( sal_Int32 nRecId, SequenceInputStream& rStrm )
50 switch( getCurrentElement() )
52 case BIFF12_ID_INDEXEDCOLORS:
53 if( nRecId == BIFF12_ID_RGBCOLOR ) getStyles().importPaletteColor( rStrm );
54 break;
56 return nullptr;
59 ContextHandlerRef FontContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs )
61 if( mxFont.get() )
62 mxFont->importAttribs( nElement, rAttribs );
63 return nullptr;
66 void BorderContext::onStartElement( const AttributeList& rAttribs )
68 if( mxBorder.get() && (getCurrentElement() == XLS_TOKEN( border )) )
69 mxBorder->importBorder( rAttribs );
72 ContextHandlerRef BorderContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs )
74 if( mxBorder.get() ) switch( getCurrentElement() )
76 case XLS_TOKEN( border ):
77 mxBorder->importStyle( nElement, rAttribs );
78 return this;
80 default:
81 if( nElement == XLS_TOKEN( color ) )
82 mxBorder->importColor( getCurrentElement(), rAttribs );
84 return nullptr;
87 ContextHandlerRef FillContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs )
89 if( mxFill.get() ) switch( getCurrentElement() )
91 case XLS_TOKEN( fill ):
92 switch( nElement )
94 case XLS_TOKEN( patternFill ): mxFill->importPatternFill( rAttribs ); return this;
95 case XLS_TOKEN( gradientFill ): mxFill->importGradientFill( rAttribs ); return this;
97 break;
98 case XLS_TOKEN( patternFill ):
99 switch( nElement )
101 case XLS_TOKEN( fgColor ): mxFill->importFgColor( rAttribs ); break;
102 case XLS_TOKEN( bgColor ): mxFill->importBgColor( rAttribs ); break;
104 break;
105 case XLS_TOKEN( gradientFill ):
106 if( nElement == XLS_TOKEN( stop ) )
108 mfGradPos = rAttribs.getDouble( XML_position, -1.0 );
109 return this;
111 break;
112 case XLS_TOKEN( stop ):
113 if( nElement == XLS_TOKEN( color ) )
114 mxFill->importColor( rAttribs, mfGradPos );
115 break;
117 return nullptr;
120 void XfContext::onStartElement( const AttributeList& rAttribs )
122 if( mxXf.get() && (getCurrentElement() == XLS_TOKEN( xf )) )
123 mxXf->importXf( rAttribs, mbCellXf );
126 ContextHandlerRef XfContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs )
128 if( mxXf.get() ) switch( getCurrentElement() )
130 case XLS_TOKEN( xf ):
131 switch( nElement )
133 case XLS_TOKEN( alignment ): mxXf->importAlignment( rAttribs ); break;
134 case XLS_TOKEN( protection ): mxXf->importProtection( rAttribs ); break;
136 break;
138 return nullptr;
141 ContextHandlerRef DxfContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs )
143 if( mxDxf.get() ) switch( getCurrentElement() )
145 case XLS_TOKEN( dxf ):
146 switch( nElement )
148 case XLS_TOKEN( font ): return new FontContext( *this, mxDxf->createFont() );
149 case XLS_TOKEN( border ): return new BorderContext( *this, mxDxf->createBorder() );
150 case XLS_TOKEN( fill ): return new FillContext( *this, mxDxf->createFill() );
152 case XLS_TOKEN( numFmt ): mxDxf->importNumFmt( rAttribs ); break;
153 #if 0
154 case XLS_TOKEN( alignment ): mxDxf->importAlignment( rAttribs ); break;
155 case XLS_TOKEN( protection ): mxDxf->importProtection( rAttribs ); break;
156 #endif
158 break;
161 if( mxExtDxf.get() ) switch( getCurrentElement() )
163 case XLS14_TOKEN( dxf ):
164 switch( nElement )
166 case XLS_TOKEN( font ): return new FontContext( *this, mxExtDxf->createFont() );
167 case XLS_TOKEN( border ): return new BorderContext( *this, mxExtDxf->createBorder() );
168 case XLS_TOKEN( fill ): return new FillContext( *this, mxExtDxf->createFill() );
169 case XLS_TOKEN( numFmt ): mxExtDxf->importNumFmt( rAttribs ); break;
171 break;
173 return nullptr;
176 StylesFragment::StylesFragment( const WorkbookHelper& rHelper, const OUString& rFragmentPath ) :
177 WorkbookFragmentBase( rHelper, rFragmentPath )
181 ContextHandlerRef StylesFragment::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs )
183 switch( getCurrentElement() )
185 case XML_ROOT_CONTEXT:
186 if( nElement == XLS_TOKEN( styleSheet ) ) return this;
187 break;
189 case XLS_TOKEN( styleSheet ):
190 switch( nElement )
192 case XLS_TOKEN( colors ):
193 case XLS_TOKEN( numFmts ):
194 case XLS_TOKEN( fonts ):
195 case XLS_TOKEN( borders ):
196 case XLS_TOKEN( fills ):
197 case XLS_TOKEN( cellXfs ):
198 case XLS_TOKEN( cellStyleXfs ):
199 case XLS_TOKEN( dxfs ):
200 case XLS_TOKEN( cellStyles ): return this;
202 break;
204 case XLS_TOKEN( colors ):
205 if( nElement == XLS_TOKEN( indexedColors ) ) return new IndexedColorsContext( *this );
206 break;
207 case XLS_TOKEN( numFmts ):
208 if( nElement == XLS_TOKEN( numFmt ) ) getStyles().importNumFmt( rAttribs );
209 break;
210 case XLS_TOKEN( fonts ):
211 if( nElement == XLS_TOKEN( font ) ) return new FontContext( *this, getStyles().createFont() );
212 break;
213 case XLS_TOKEN( borders ):
214 if( nElement == XLS_TOKEN( border ) ) return new BorderContext( *this, getStyles().createBorder() );
215 break;
216 case XLS_TOKEN( fills ):
217 if( nElement == XLS_TOKEN( fill ) ) return new FillContext( *this, getStyles().createFill() );
218 break;
219 case XLS_TOKEN( cellXfs ):
220 if( nElement == XLS_TOKEN( xf ) ) return new XfContext( *this, getStyles().createCellXf(), true );
221 break;
222 case XLS_TOKEN( cellStyleXfs ):
223 if( nElement == XLS_TOKEN( xf ) ) return new XfContext( *this, getStyles().createStyleXf(), false );
224 break;
225 case XLS_TOKEN( dxfs ):
226 if( nElement == XLS_TOKEN( dxf ) ) return new DxfContext( *this, getStyles().createDxf() );
227 break;
228 case XLS_TOKEN( cellStyles ):
229 if( nElement == XLS_TOKEN( cellStyle ) ) getStyles().importCellStyle( rAttribs );
230 break;
232 return nullptr;
235 ContextHandlerRef StylesFragment::onCreateRecordContext( sal_Int32 nRecId, SequenceInputStream& rStrm )
237 switch( getCurrentElement() )
239 case XML_ROOT_CONTEXT:
240 if( nRecId == BIFF12_ID_STYLESHEET ) return this;
241 break;
243 case BIFF12_ID_STYLESHEET:
244 switch( nRecId )
246 case BIFF12_ID_COLORS:
247 case BIFF12_ID_NUMFMTS:
248 case BIFF12_ID_FONTS:
249 case BIFF12_ID_BORDERS:
250 case BIFF12_ID_FILLS:
251 case BIFF12_ID_CELLXFS:
252 case BIFF12_ID_CELLSTYLEXFS:
253 case BIFF12_ID_DXFS:
254 case BIFF12_ID_CELLSTYLES: return this;
256 break;
258 case BIFF12_ID_COLORS:
259 if( nRecId == BIFF12_ID_INDEXEDCOLORS ) return new IndexedColorsContext( *this );
260 break;
261 case BIFF12_ID_NUMFMTS:
262 if( nRecId == BIFF12_ID_NUMFMT ) getStyles().importNumFmt( rStrm );
263 break;
264 case BIFF12_ID_FONTS:
265 if( nRecId == BIFF12_ID_FONT ) getStyles().createFont()->importFont( rStrm );
266 break;
267 case BIFF12_ID_BORDERS:
268 if( nRecId == BIFF12_ID_BORDER ) getStyles().createBorder()->importBorder( rStrm );
269 break;
270 case BIFF12_ID_FILLS:
271 if( nRecId == BIFF12_ID_FILL ) getStyles().createFill()->importFill( rStrm );
272 break;
273 case BIFF12_ID_CELLXFS:
274 if( nRecId == BIFF12_ID_XF ) getStyles().createCellXf()->importXf( rStrm, true );
275 break;
276 case BIFF12_ID_CELLSTYLEXFS:
277 if( nRecId == BIFF12_ID_XF ) getStyles().createStyleXf()->importXf( rStrm, false );
278 break;
279 case BIFF12_ID_DXFS:
280 if( nRecId == BIFF12_ID_DXF ) getStyles().createDxf()->importDxf( rStrm );
281 break;
282 case BIFF12_ID_CELLSTYLES:
283 if( nRecId == BIFF12_ID_CELLSTYLE ) getStyles().importCellStyle( rStrm );
284 break;
286 return nullptr;
289 const RecordInfo* StylesFragment::getRecordInfos() const
291 static const RecordInfo spRecInfos[] =
293 { BIFF12_ID_BORDERS, BIFF12_ID_BORDERS + 1 },
294 { BIFF12_ID_CELLSTYLES, BIFF12_ID_CELLSTYLES + 1 },
295 { BIFF12_ID_CELLSTYLEXFS, BIFF12_ID_CELLSTYLEXFS + 1 },
296 { BIFF12_ID_CELLXFS, BIFF12_ID_CELLXFS + 1 },
297 { BIFF12_ID_COLORS, BIFF12_ID_COLORS + 1 },
298 { BIFF12_ID_DXFS, BIFF12_ID_DXFS + 1 },
299 { BIFF12_ID_FILLS, BIFF12_ID_FILLS + 1 },
300 { BIFF12_ID_FONTS, BIFF12_ID_FONTS + 1 },
301 { BIFF12_ID_INDEXEDCOLORS, BIFF12_ID_INDEXEDCOLORS + 1 },
302 { BIFF12_ID_MRUCOLORS, BIFF12_ID_MRUCOLORS + 1 },
303 { BIFF12_ID_NUMFMTS, BIFF12_ID_NUMFMTS + 1 },
304 { BIFF12_ID_STYLESHEET, BIFF12_ID_STYLESHEET + 1 },
305 { BIFF12_ID_TABLESTYLES, BIFF12_ID_TABLESTYLES + 1 },
306 { -1, -1 }
308 return spRecInfos;
311 void StylesFragment::finalizeImport()
313 getStyles().finalizeImport();
316 } // namespace xls
317 } // namespace oox
319 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */