1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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"
22 #include <oox/helper/attributelist.hxx>
27 using namespace ::oox::core
;
29 IndexedColorsContext::IndexedColorsContext( WorkbookFragmentBase
& rFragment
) :
30 WorkbookContextBase( rFragment
)
34 ContextHandlerRef
IndexedColorsContext::onCreateContext( sal_Int32 nElement
, const AttributeList
& rAttribs
)
36 switch( getCurrentElement() )
38 case XLS_TOKEN( indexedColors
):
39 if( nElement
== XLS_TOKEN( rgbColor
) ) getStyles().importPaletteColor( rAttribs
);
45 ContextHandlerRef
IndexedColorsContext::onCreateRecordContext( sal_Int32 nRecId
, SequenceInputStream
& rStrm
)
47 switch( getCurrentElement() )
49 case BIFF12_ID_INDEXEDCOLORS
:
50 if( nRecId
== BIFF12_ID_RGBCOLOR
) getStyles().importPaletteColor( rStrm
);
56 ContextHandlerRef
FontContext::onCreateContext( sal_Int32 nElement
, const AttributeList
& rAttribs
)
59 mxFont
->importAttribs( nElement
, rAttribs
);
63 void BorderContext::onStartElement( const AttributeList
& rAttribs
)
65 if( mxBorder
.get() && (getCurrentElement() == XLS_TOKEN( border
)) )
66 mxBorder
->importBorder( rAttribs
);
69 ContextHandlerRef
BorderContext::onCreateContext( sal_Int32 nElement
, const AttributeList
& rAttribs
)
71 if( mxBorder
.get() ) switch( getCurrentElement() )
73 case XLS_TOKEN( border
):
74 mxBorder
->importStyle( nElement
, rAttribs
);
78 if( nElement
== XLS_TOKEN( color
) )
79 mxBorder
->importColor( getCurrentElement(), rAttribs
);
84 ContextHandlerRef
FillContext::onCreateContext( sal_Int32 nElement
, const AttributeList
& rAttribs
)
86 if( mxFill
.get() ) switch( getCurrentElement() )
88 case XLS_TOKEN( fill
):
91 case XLS_TOKEN( patternFill
): mxFill
->importPatternFill( rAttribs
); return this;
92 case XLS_TOKEN( gradientFill
): mxFill
->importGradientFill( rAttribs
); return this;
95 case XLS_TOKEN( patternFill
):
98 case XLS_TOKEN( fgColor
): mxFill
->importFgColor( rAttribs
); break;
99 case XLS_TOKEN( bgColor
): mxFill
->importBgColor( rAttribs
); break;
102 case XLS_TOKEN( gradientFill
):
103 if( nElement
== XLS_TOKEN( stop
) )
105 mfGradPos
= rAttribs
.getDouble( XML_position
, -1.0 );
109 case XLS_TOKEN( stop
):
110 if( nElement
== XLS_TOKEN( color
) )
111 mxFill
->importColor( rAttribs
, mfGradPos
);
117 void XfContext::onStartElement( const AttributeList
& rAttribs
)
119 if( mxXf
.get() && (getCurrentElement() == XLS_TOKEN( xf
)) )
120 mxXf
->importXf( rAttribs
, mbCellXf
);
123 ContextHandlerRef
XfContext::onCreateContext( sal_Int32 nElement
, const AttributeList
& rAttribs
)
125 if( mxXf
.get() ) switch( getCurrentElement() )
127 case XLS_TOKEN( xf
):
130 case XLS_TOKEN( alignment
): mxXf
->importAlignment( rAttribs
); break;
131 case XLS_TOKEN( protection
): mxXf
->importProtection( rAttribs
); break;
138 ContextHandlerRef
DxfContext::onCreateContext( sal_Int32 nElement
, const AttributeList
& rAttribs
)
140 if( mxDxf
.get() ) switch( getCurrentElement() )
142 case XLS_TOKEN( dxf
):
145 case XLS_TOKEN( font
): return new FontContext( *this, mxDxf
->createFont() );
146 case XLS_TOKEN( border
): return new BorderContext( *this, mxDxf
->createBorder() );
147 case XLS_TOKEN( fill
): return new FillContext( *this, mxDxf
->createFill() );
149 case XLS_TOKEN( numFmt
): mxDxf
->importNumFmt( rAttribs
); break;
151 case XLS_TOKEN( alignment
): mxDxf
->importAlignment( rAttribs
); break;
152 case XLS_TOKEN( protection
): mxDxf
->importProtection( rAttribs
); break;
160 StylesFragment::StylesFragment( const WorkbookHelper
& rHelper
, const OUString
& rFragmentPath
) :
161 WorkbookFragmentBase( rHelper
, rFragmentPath
)
165 ContextHandlerRef
StylesFragment::onCreateContext( sal_Int32 nElement
, const AttributeList
& rAttribs
)
167 switch( getCurrentElement() )
169 case XML_ROOT_CONTEXT
:
170 if( nElement
== XLS_TOKEN( styleSheet
) ) return this;
173 case XLS_TOKEN( styleSheet
):
176 case XLS_TOKEN( colors
):
177 case XLS_TOKEN( numFmts
):
178 case XLS_TOKEN( fonts
):
179 case XLS_TOKEN( borders
):
180 case XLS_TOKEN( fills
):
181 case XLS_TOKEN( cellXfs
):
182 case XLS_TOKEN( cellStyleXfs
):
183 case XLS_TOKEN( dxfs
):
184 case XLS_TOKEN( cellStyles
): return this;
188 case XLS_TOKEN( colors
):
189 if( nElement
== XLS_TOKEN( indexedColors
) ) return new IndexedColorsContext( *this );
191 case XLS_TOKEN( numFmts
):
192 if( nElement
== XLS_TOKEN( numFmt
) ) getStyles().importNumFmt( rAttribs
);
194 case XLS_TOKEN( fonts
):
195 if( nElement
== XLS_TOKEN( font
) ) return new FontContext( *this, getStyles().createFont() );
197 case XLS_TOKEN( borders
):
198 if( nElement
== XLS_TOKEN( border
) ) return new BorderContext( *this, getStyles().createBorder() );
200 case XLS_TOKEN( fills
):
201 if( nElement
== XLS_TOKEN( fill
) ) return new FillContext( *this, getStyles().createFill() );
203 case XLS_TOKEN( cellXfs
):
204 if( nElement
== XLS_TOKEN( xf
) ) return new XfContext( *this, getStyles().createCellXf(), true );
206 case XLS_TOKEN( cellStyleXfs
):
207 if( nElement
== XLS_TOKEN( xf
) ) return new XfContext( *this, getStyles().createStyleXf(), false );
209 case XLS_TOKEN( dxfs
):
210 if( nElement
== XLS_TOKEN( dxf
) ) return new DxfContext( *this, getStyles().createDxf() );
212 case XLS_TOKEN( cellStyles
):
213 if( nElement
== XLS_TOKEN( cellStyle
) ) getStyles().importCellStyle( rAttribs
);
219 ContextHandlerRef
StylesFragment::onCreateRecordContext( sal_Int32 nRecId
, SequenceInputStream
& rStrm
)
221 switch( getCurrentElement() )
223 case XML_ROOT_CONTEXT
:
224 if( nRecId
== BIFF12_ID_STYLESHEET
) return this;
227 case BIFF12_ID_STYLESHEET
:
230 case BIFF12_ID_COLORS
:
231 case BIFF12_ID_NUMFMTS
:
232 case BIFF12_ID_FONTS
:
233 case BIFF12_ID_BORDERS
:
234 case BIFF12_ID_FILLS
:
235 case BIFF12_ID_CELLXFS
:
236 case BIFF12_ID_CELLSTYLEXFS
:
238 case BIFF12_ID_CELLSTYLES
: return this;
242 case BIFF12_ID_COLORS
:
243 if( nRecId
== BIFF12_ID_INDEXEDCOLORS
) return new IndexedColorsContext( *this );
245 case BIFF12_ID_NUMFMTS
:
246 if( nRecId
== BIFF12_ID_NUMFMT
) getStyles().importNumFmt( rStrm
);
248 case BIFF12_ID_FONTS
:
249 if( nRecId
== BIFF12_ID_FONT
) getStyles().createFont()->importFont( rStrm
);
251 case BIFF12_ID_BORDERS
:
252 if( nRecId
== BIFF12_ID_BORDER
) getStyles().createBorder()->importBorder( rStrm
);
254 case BIFF12_ID_FILLS
:
255 if( nRecId
== BIFF12_ID_FILL
) getStyles().createFill()->importFill( rStrm
);
257 case BIFF12_ID_CELLXFS
:
258 if( nRecId
== BIFF12_ID_XF
) getStyles().createCellXf()->importXf( rStrm
, true );
260 case BIFF12_ID_CELLSTYLEXFS
:
261 if( nRecId
== BIFF12_ID_XF
) getStyles().createStyleXf()->importXf( rStrm
, false );
264 if( nRecId
== BIFF12_ID_DXF
) getStyles().createDxf()->importDxf( rStrm
);
266 case BIFF12_ID_CELLSTYLES
:
267 if( nRecId
== BIFF12_ID_CELLSTYLE
) getStyles().importCellStyle( rStrm
);
273 const RecordInfo
* StylesFragment::getRecordInfos() const
275 static const RecordInfo spRecInfos
[] =
277 { BIFF12_ID_BORDERS
, BIFF12_ID_BORDERS
+ 1 },
278 { BIFF12_ID_CELLSTYLES
, BIFF12_ID_CELLSTYLES
+ 1 },
279 { BIFF12_ID_CELLSTYLEXFS
, BIFF12_ID_CELLSTYLEXFS
+ 1 },
280 { BIFF12_ID_CELLXFS
, BIFF12_ID_CELLXFS
+ 1 },
281 { BIFF12_ID_COLORS
, BIFF12_ID_COLORS
+ 1 },
282 { BIFF12_ID_DXFS
, BIFF12_ID_DXFS
+ 1 },
283 { BIFF12_ID_FILLS
, BIFF12_ID_FILLS
+ 1 },
284 { BIFF12_ID_FONTS
, BIFF12_ID_FONTS
+ 1 },
285 { BIFF12_ID_INDEXEDCOLORS
, BIFF12_ID_INDEXEDCOLORS
+ 1 },
286 { BIFF12_ID_MRUCOLORS
, BIFF12_ID_MRUCOLORS
+ 1 },
287 { BIFF12_ID_NUMFMTS
, BIFF12_ID_NUMFMTS
+ 1 },
288 { BIFF12_ID_STYLESHEET
, BIFF12_ID_STYLESHEET
+ 1 },
289 { BIFF12_ID_TABLESTYLES
, BIFF12_ID_TABLESTYLES
+ 1 },
295 void StylesFragment::finalizeImport()
297 getStyles().finalizeImport();
303 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */