Update git submodules
[LibreOffice.git] / sc / source / filter / oox / stylesfragment.cxx
blob1d20b98519ff349e0b5cfd22fc447dc78889a385
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::xls {
29 using namespace ::oox::core;
31 IndexedColorsContext::IndexedColorsContext( WorkbookFragmentBase& rFragment ) :
32 WorkbookContextBase( rFragment )
36 ContextHandlerRef IndexedColorsContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs )
38 switch( getCurrentElement() )
40 case XLS_TOKEN( indexedColors ):
41 if( nElement == XLS_TOKEN( rgbColor ) ) getStyles().importPaletteColor( rAttribs );
42 break;
44 return nullptr;
47 ContextHandlerRef IndexedColorsContext::onCreateRecordContext( sal_Int32 nRecId, SequenceInputStream& rStrm )
49 switch( getCurrentElement() )
51 case BIFF12_ID_INDEXEDCOLORS:
52 if( nRecId == BIFF12_ID_RGBCOLOR ) getStyles().importPaletteColor( rStrm );
53 break;
55 return nullptr;
58 ContextHandlerRef FontContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs )
60 if( mxFont )
61 mxFont->importAttribs( nElement, rAttribs );
62 return nullptr;
65 void BorderContext::onStartElement( const AttributeList& rAttribs )
67 if( mxBorder && (getCurrentElement() == XLS_TOKEN( border )) )
68 mxBorder->importBorder( rAttribs );
71 ContextHandlerRef BorderContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs )
73 if( mxBorder ) switch( getCurrentElement() )
75 case XLS_TOKEN( border ):
76 mxBorder->importStyle( nElement, rAttribs );
77 return this;
79 default:
80 if( nElement == XLS_TOKEN( color ) )
81 mxBorder->importColor( getCurrentElement(), rAttribs );
83 return nullptr;
86 ContextHandlerRef FillContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs )
88 if( mxFill ) switch( getCurrentElement() )
90 case XLS_TOKEN( fill ):
91 switch( nElement )
93 case XLS_TOKEN( patternFill ): mxFill->importPatternFill( rAttribs ); return this;
94 case XLS_TOKEN( gradientFill ): mxFill->importGradientFill( rAttribs ); return this;
96 break;
97 case XLS_TOKEN( patternFill ):
98 switch( nElement )
100 case XLS_TOKEN( fgColor ): mxFill->importFgColor( rAttribs ); break;
101 case XLS_TOKEN( bgColor ): mxFill->importBgColor( rAttribs ); break;
103 break;
104 case XLS_TOKEN( gradientFill ):
105 if( nElement == XLS_TOKEN( stop ) )
107 mfGradPos = rAttribs.getDouble( XML_position, -1.0 );
108 return this;
110 break;
111 case XLS_TOKEN( stop ):
112 if( nElement == XLS_TOKEN( color ) )
113 mxFill->importColor( rAttribs, mfGradPos );
114 break;
116 return nullptr;
119 void XfContext::onStartElement( const AttributeList& rAttribs )
121 if( mxXf && (getCurrentElement() == XLS_TOKEN( xf )) )
122 mxXf->importXf( rAttribs, mbCellXf );
125 ContextHandlerRef XfContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs )
127 if( mxXf ) switch( getCurrentElement() )
129 case XLS_TOKEN( xf ):
130 switch( nElement )
132 case XLS_TOKEN( alignment ): mxXf->importAlignment( rAttribs ); break;
133 case XLS_TOKEN( protection ): mxXf->importProtection( rAttribs ); break;
135 break;
137 return nullptr;
140 ContextHandlerRef DxfContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs )
142 switch( getCurrentElement() )
144 case XLS_TOKEN( dxf ):
145 switch( nElement )
147 case XLS_TOKEN( font ): return new FontContext( *this, mxDxf->createFont() );
148 case XLS_TOKEN( border ): return new BorderContext( *this, mxDxf->createBorder() );
149 case XLS_TOKEN( fill ): return new FillContext( *this, mxDxf->createFill() );
151 case XLS_TOKEN( numFmt ): mxDxf->importNumFmt( rAttribs ); break;
152 #if 0
153 case XLS_TOKEN( alignment ): mxDxf->importAlignment( rAttribs ); break;
154 #endif
155 case XLS_TOKEN( protection ): mxDxf->createProtection()->importProtection( rAttribs ); break;
157 break;
159 case XLS14_TOKEN( dxf ):
160 switch( nElement )
162 case XLS_TOKEN( font ): return new FontContext( *this, mxDxf->createFont() );
163 case XLS_TOKEN( border ): return new BorderContext( *this, mxDxf->createBorder() );
164 case XLS_TOKEN( fill ): return new FillContext( *this, mxDxf->createFill() );
165 case XLS_TOKEN( numFmt ): mxDxf->importNumFmt( rAttribs ); break;
166 case XLS_TOKEN( protection ): mxDxf->createProtection()->importProtection( rAttribs ); break;
168 break;
170 return nullptr;
173 StylesFragment::StylesFragment( const WorkbookHelper& rHelper, const OUString& rFragmentPath ) :
174 WorkbookFragmentBase( rHelper, rFragmentPath )
178 ContextHandlerRef StylesFragment::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs )
180 switch( getCurrentElement() )
182 case XML_ROOT_CONTEXT:
183 if( nElement == XLS_TOKEN( styleSheet ) ) return this;
184 break;
186 case XLS_TOKEN( styleSheet ):
187 switch( nElement )
189 case XLS_TOKEN( colors ):
190 case XLS_TOKEN( numFmts ):
191 case XLS_TOKEN( fonts ):
192 case XLS_TOKEN( borders ):
193 case XLS_TOKEN( fills ):
194 case XLS_TOKEN( cellXfs ):
195 case XLS_TOKEN( cellStyleXfs ):
196 case XLS_TOKEN( dxfs ):
197 case XLS_TOKEN( cellStyles ): return this;
199 break;
201 case XLS_TOKEN( colors ):
202 if( nElement == XLS_TOKEN( indexedColors ) ) return new IndexedColorsContext( *this );
203 break;
204 case XLS_TOKEN( numFmts ):
205 if( nElement == XLS_TOKEN( numFmt ) ) getStyles().importNumFmt( rAttribs );
206 break;
207 case XLS_TOKEN( fonts ):
208 if( nElement == XLS_TOKEN( font ) ) return new FontContext( *this, getStyles().createFont() );
209 break;
210 case XLS_TOKEN( borders ):
211 if( nElement == XLS_TOKEN( border ) ) return new BorderContext( *this, getStyles().createBorder() );
212 break;
213 case XLS_TOKEN( fills ):
214 if( nElement == XLS_TOKEN( fill ) ) return new FillContext( *this, getStyles().createFill() );
215 break;
216 case XLS_TOKEN( cellXfs ):
217 if( nElement == XLS_TOKEN( xf ) ) return new XfContext( *this, getStyles().createCellXf(), true );
218 break;
219 case XLS_TOKEN( cellStyleXfs ):
220 if( nElement == XLS_TOKEN( xf ) ) return new XfContext( *this, getStyles().createStyleXf(), false );
221 break;
222 case XLS_TOKEN( dxfs ):
223 if( nElement == XLS_TOKEN( dxf ) ) return new DxfContext( *this, getStyles().createDxf() );
224 break;
225 case XLS_TOKEN( cellStyles ):
226 if( nElement == XLS_TOKEN( cellStyle ) ) getStyles().importCellStyle( rAttribs );
227 break;
229 return nullptr;
232 ContextHandlerRef StylesFragment::onCreateRecordContext( sal_Int32 nRecId, SequenceInputStream& rStrm )
234 switch( getCurrentElement() )
236 case XML_ROOT_CONTEXT:
237 if( nRecId == BIFF12_ID_STYLESHEET ) return this;
238 break;
240 case BIFF12_ID_STYLESHEET:
241 switch( nRecId )
243 case BIFF12_ID_COLORS:
244 case BIFF12_ID_NUMFMTS:
245 case BIFF12_ID_FONTS:
246 case BIFF12_ID_BORDERS:
247 case BIFF12_ID_FILLS:
248 case BIFF12_ID_CELLXFS:
249 case BIFF12_ID_CELLSTYLEXFS:
250 case BIFF12_ID_DXFS:
251 case BIFF12_ID_CELLSTYLES: return this;
253 break;
255 case BIFF12_ID_COLORS:
256 if( nRecId == BIFF12_ID_INDEXEDCOLORS ) return new IndexedColorsContext( *this );
257 break;
258 case BIFF12_ID_NUMFMTS:
259 if( nRecId == BIFF12_ID_NUMFMT ) getStyles().importNumFmt( rStrm );
260 break;
261 case BIFF12_ID_FONTS:
262 if( nRecId == BIFF12_ID_FONT ) getStyles().createFont()->importFont( rStrm );
263 break;
264 case BIFF12_ID_BORDERS:
265 if( nRecId == BIFF12_ID_BORDER ) getStyles().createBorder()->importBorder( rStrm );
266 break;
267 case BIFF12_ID_FILLS:
268 if( nRecId == BIFF12_ID_FILL ) getStyles().createFill()->importFill( rStrm );
269 break;
270 case BIFF12_ID_CELLXFS:
271 if( nRecId == BIFF12_ID_XF ) getStyles().createCellXf()->importXf( rStrm, true );
272 break;
273 case BIFF12_ID_CELLSTYLEXFS:
274 if( nRecId == BIFF12_ID_XF ) getStyles().createStyleXf()->importXf( rStrm, false );
275 break;
276 case BIFF12_ID_DXFS:
277 if( nRecId == BIFF12_ID_DXF ) getStyles().createDxf()->importDxf( rStrm );
278 break;
279 case BIFF12_ID_CELLSTYLES:
280 if( nRecId == BIFF12_ID_CELLSTYLE ) getStyles().importCellStyle( rStrm );
281 break;
283 return nullptr;
286 const RecordInfo* StylesFragment::getRecordInfos() const
288 static const RecordInfo spRecInfos[] =
290 { BIFF12_ID_BORDERS, BIFF12_ID_BORDERS + 1 },
291 { BIFF12_ID_CELLSTYLES, BIFF12_ID_CELLSTYLES + 1 },
292 { BIFF12_ID_CELLSTYLEXFS, BIFF12_ID_CELLSTYLEXFS + 1 },
293 { BIFF12_ID_CELLXFS, BIFF12_ID_CELLXFS + 1 },
294 { BIFF12_ID_COLORS, BIFF12_ID_COLORS + 1 },
295 { BIFF12_ID_DXFS, BIFF12_ID_DXFS + 1 },
296 { BIFF12_ID_FILLS, BIFF12_ID_FILLS + 1 },
297 { BIFF12_ID_FONTS, BIFF12_ID_FONTS + 1 },
298 { BIFF12_ID_INDEXEDCOLORS, BIFF12_ID_INDEXEDCOLORS + 1 },
299 { BIFF12_ID_MRUCOLORS, BIFF12_ID_MRUCOLORS + 1 },
300 { BIFF12_ID_NUMFMTS, BIFF12_ID_NUMFMTS + 1 },
301 { BIFF12_ID_STYLESHEET, BIFF12_ID_STYLESHEET + 1 },
302 { BIFF12_ID_TABLESTYLES, BIFF12_ID_TABLESTYLES + 1 },
303 { -1, -1 }
305 return spRecInfos;
308 void StylesFragment::finalizeImport()
310 getStyles().finalizeImport();
313 } // namespace oox::xls
315 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */