Update ooo320-m1
[ooovba.git] / oox / source / xls / stylesfragment.cxx
blob194c2605f38f6da0c226d46a0becf1abbcd6e048
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: stylesfragment.cxx,v $
10 * $Revision: 1.4 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #include "oox/xls/stylesfragment.hxx"
32 #include "oox/helper/attributelist.hxx"
34 using ::rtl::OUString;
35 using ::oox::core::ContextHandlerRef;
36 using ::oox::core::RecordInfo;
38 namespace oox {
39 namespace xls {
41 // ============================================================================
43 OoxIndexedColorsContext::OoxIndexedColorsContext( OoxWorkbookFragmentBase& rFragment ) :
44 OoxWorkbookContextBase( rFragment )
48 ContextHandlerRef OoxIndexedColorsContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs )
50 switch( getCurrentElement() )
52 case XLS_TOKEN( indexedColors ):
53 if( nElement == XLS_TOKEN( rgbColor ) ) getStyles().importPaletteColor( rAttribs );
54 break;
56 return 0;
59 ContextHandlerRef OoxIndexedColorsContext::onCreateRecordContext( sal_Int32 nRecId, RecordInputStream& rStrm )
61 switch( getCurrentElement() )
63 case OOBIN_ID_INDEXEDCOLORS:
64 if( nRecId == OOBIN_ID_RGBCOLOR ) getStyles().importPaletteColor( rStrm );
65 break;
67 return 0;
70 // ============================================================================
72 ContextHandlerRef OoxFontContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs )
74 if( mxFont.get() )
75 mxFont->importAttribs( nElement, rAttribs );
76 return 0;
79 // ============================================================================
81 void OoxBorderContext::onStartElement( const AttributeList& rAttribs )
83 if( mxBorder.get() && (getCurrentElement() == XLS_TOKEN( border )) )
84 mxBorder->importBorder( rAttribs );
87 ContextHandlerRef OoxBorderContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs )
89 if( mxBorder.get() ) switch( getCurrentElement() )
91 case XLS_TOKEN( border ):
92 mxBorder->importStyle( nElement, rAttribs );
93 return this;
95 default:
96 if( nElement == XLS_TOKEN( color ) )
97 mxBorder->importColor( getCurrentElement(), rAttribs );
99 return 0;
102 // ============================================================================
104 ContextHandlerRef OoxFillContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs )
106 if( mxFill.get() ) switch( getCurrentElement() )
108 case XLS_TOKEN( fill ):
109 switch( nElement )
111 case XLS_TOKEN( patternFill ): mxFill->importPatternFill( rAttribs ); return this;
112 case XLS_TOKEN( gradientFill ): mxFill->importGradientFill( rAttribs ); return this;
114 break;
115 case XLS_TOKEN( patternFill ):
116 switch( nElement )
118 case XLS_TOKEN( fgColor ): mxFill->importFgColor( rAttribs ); break;
119 case XLS_TOKEN( bgColor ): mxFill->importBgColor( rAttribs ); break;
121 break;
122 case XLS_TOKEN( gradientFill ):
123 if( nElement == XLS_TOKEN( stop ) )
125 mfGradPos = rAttribs.getDouble( XML_position, -1.0 );
126 return this;
128 break;
129 case XLS_TOKEN( stop ):
130 if( nElement == XLS_TOKEN( color ) )
131 mxFill->importColor( rAttribs, mfGradPos );
132 break;
134 return 0;
137 // ============================================================================
139 void OoxXfContext::onStartElement( const AttributeList& rAttribs )
141 if( mxXf.get() && (getCurrentElement() == XLS_TOKEN( xf )) )
142 mxXf->importXf( rAttribs, mbCellXf );
145 ContextHandlerRef OoxXfContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs )
147 if( mxXf.get() ) switch( getCurrentElement() )
149 case XLS_TOKEN( xf ):
150 switch( nElement )
152 case XLS_TOKEN( alignment ): mxXf->importAlignment( rAttribs ); break;
153 case XLS_TOKEN( protection ): mxXf->importProtection( rAttribs ); break;
155 break;
157 return 0;
160 // ============================================================================
162 ContextHandlerRef OoxDxfContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs )
164 if( mxDxf.get() ) switch( getCurrentElement() )
166 case XLS_TOKEN( dxf ):
167 switch( nElement )
169 case XLS_TOKEN( font ): return new OoxFontContext( *this, mxDxf->createFont() );
170 case XLS_TOKEN( border ): return new OoxBorderContext( *this, mxDxf->createBorder() );
171 case XLS_TOKEN( fill ): return new OoxFillContext( *this, mxDxf->createFill() );
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
179 break;
181 return 0;
184 // ============================================================================
186 OoxStylesFragment::OoxStylesFragment( const WorkbookHelper& rHelper, const OUString& rFragmentPath ) :
187 OoxWorkbookFragmentBase( rHelper, rFragmentPath )
191 // oox.core.ContextHandler2Helper interface -----------------------------------
193 ContextHandlerRef OoxStylesFragment::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs )
195 switch( getCurrentElement() )
197 case XML_ROOT_CONTEXT:
198 if( nElement == XLS_TOKEN( styleSheet ) ) return this;
199 break;
201 case XLS_TOKEN( styleSheet ):
202 switch( nElement )
204 case XLS_TOKEN( colors ):
205 case XLS_TOKEN( numFmts ):
206 case XLS_TOKEN( fonts ):
207 case XLS_TOKEN( borders ):
208 case XLS_TOKEN( fills ):
209 case XLS_TOKEN( cellXfs ):
210 case XLS_TOKEN( cellStyleXfs ):
211 case XLS_TOKEN( dxfs ):
212 case XLS_TOKEN( cellStyles ): return this;
214 break;
216 case XLS_TOKEN( colors ):
217 if( nElement == XLS_TOKEN( indexedColors ) ) return new OoxIndexedColorsContext( *this );
218 break;
219 case XLS_TOKEN( numFmts ):
220 if( nElement == XLS_TOKEN( numFmt ) ) getStyles().importNumFmt( rAttribs );
221 break;
222 case XLS_TOKEN( fonts ):
223 if( nElement == XLS_TOKEN( font ) ) return new OoxFontContext( *this, getStyles().createFont() );
224 break;
225 case XLS_TOKEN( borders ):
226 if( nElement == XLS_TOKEN( border ) ) return new OoxBorderContext( *this, getStyles().createBorder() );
227 break;
228 case XLS_TOKEN( fills ):
229 if( nElement == XLS_TOKEN( fill ) ) return new OoxFillContext( *this, getStyles().createFill() );
230 break;
231 case XLS_TOKEN( cellXfs ):
232 if( nElement == XLS_TOKEN( xf ) ) return new OoxXfContext( *this, getStyles().createCellXf(), true );
233 break;
234 case XLS_TOKEN( cellStyleXfs ):
235 if( nElement == XLS_TOKEN( xf ) ) return new OoxXfContext( *this, getStyles().createStyleXf(), false );
236 break;
237 case XLS_TOKEN( dxfs ):
238 if( nElement == XLS_TOKEN( dxf ) ) return new OoxDxfContext( *this, getStyles().createDxf() );
239 break;
240 case XLS_TOKEN( cellStyles ):
241 if( nElement == XLS_TOKEN( cellStyle ) ) getStyles().importCellStyle( rAttribs );
242 break;
244 return 0;
247 ContextHandlerRef OoxStylesFragment::onCreateRecordContext( sal_Int32 nRecId, RecordInputStream& rStrm )
249 switch( getCurrentElement() )
251 case XML_ROOT_CONTEXT:
252 if( nRecId == OOBIN_ID_STYLESHEET ) return this;
253 break;
255 case OOBIN_ID_STYLESHEET:
256 switch( nRecId )
258 case OOBIN_ID_COLORS:
259 case OOBIN_ID_NUMFMTS:
260 case OOBIN_ID_FONTS:
261 case OOBIN_ID_BORDERS:
262 case OOBIN_ID_FILLS:
263 case OOBIN_ID_CELLXFS:
264 case OOBIN_ID_CELLSTYLEXFS:
265 case OOBIN_ID_DXFS:
266 case OOBIN_ID_CELLSTYLES: return this;
268 break;
270 case OOBIN_ID_COLORS:
271 if( nRecId == OOBIN_ID_INDEXEDCOLORS ) return new OoxIndexedColorsContext( *this );
272 break;
273 case OOBIN_ID_NUMFMTS:
274 if( nRecId == OOBIN_ID_NUMFMT ) getStyles().importNumFmt( rStrm );
275 break;
276 case OOBIN_ID_FONTS:
277 if( nRecId == OOBIN_ID_FONT ) getStyles().createFont()->importFont( rStrm );
278 break;
279 case OOBIN_ID_BORDERS:
280 if( nRecId == OOBIN_ID_BORDER ) getStyles().createBorder()->importBorder( rStrm );
281 break;
282 case OOBIN_ID_FILLS:
283 if( nRecId == OOBIN_ID_FILL ) getStyles().createFill()->importFill( rStrm );
284 break;
285 case OOBIN_ID_CELLXFS:
286 if( nRecId == OOBIN_ID_XF ) getStyles().createCellXf()->importXf( rStrm, true );
287 break;
288 case OOBIN_ID_CELLSTYLEXFS:
289 if( nRecId == OOBIN_ID_XF ) getStyles().createStyleXf()->importXf( rStrm, false );
290 break;
291 case OOBIN_ID_DXFS:
292 if( nRecId == OOBIN_ID_DXF ) getStyles().createDxf()->importDxf( rStrm );
293 break;
294 case OOBIN_ID_CELLSTYLES:
295 if( nRecId == OOBIN_ID_CELLSTYLE ) getStyles().importCellStyle( rStrm );
296 break;
298 return 0;
301 // oox.core.FragmentHandler2 interface ----------------------------------------
303 const RecordInfo* OoxStylesFragment::getRecordInfos() const
305 static const RecordInfo spRecInfos[] =
307 { OOBIN_ID_BORDERS, OOBIN_ID_BORDERS + 1 },
308 { OOBIN_ID_CELLSTYLES, OOBIN_ID_CELLSTYLES + 1 },
309 { OOBIN_ID_CELLSTYLEXFS, OOBIN_ID_CELLSTYLEXFS + 1 },
310 { OOBIN_ID_CELLXFS, OOBIN_ID_CELLXFS + 1 },
311 { OOBIN_ID_COLORS, OOBIN_ID_COLORS + 1 },
312 { OOBIN_ID_DXFS, OOBIN_ID_DXFS + 1 },
313 { OOBIN_ID_FILLS, OOBIN_ID_FILLS + 1 },
314 { OOBIN_ID_FONTS, OOBIN_ID_FONTS + 1 },
315 { OOBIN_ID_INDEXEDCOLORS, OOBIN_ID_INDEXEDCOLORS + 1 },
316 { OOBIN_ID_MRUCOLORS, OOBIN_ID_MRUCOLORS + 1 },
317 { OOBIN_ID_NUMFMTS, OOBIN_ID_NUMFMTS + 1 },
318 { OOBIN_ID_STYLESHEET, OOBIN_ID_STYLESHEET + 1 },
319 { OOBIN_ID_TABLESTYLES, OOBIN_ID_TABLESTYLES + 1 },
320 { -1, -1 }
322 return spRecInfos;
325 void OoxStylesFragment::finalizeImport()
327 getStyles().finalizeImport();
330 // ============================================================================
332 } // namespace xls
333 } // namespace oox