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 $
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
;
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
);
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
);
70 // ============================================================================
72 ContextHandlerRef
OoxFontContext::onCreateContext( sal_Int32 nElement
, const AttributeList
& rAttribs
)
75 mxFont
->importAttribs( nElement
, rAttribs
);
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
);
96 if( nElement
== XLS_TOKEN( color
) )
97 mxBorder
->importColor( getCurrentElement(), rAttribs
);
102 // ============================================================================
104 ContextHandlerRef
OoxFillContext::onCreateContext( sal_Int32 nElement
, const AttributeList
& rAttribs
)
106 if( mxFill
.get() ) switch( getCurrentElement() )
108 case XLS_TOKEN( fill
):
111 case XLS_TOKEN( patternFill
): mxFill
->importPatternFill( rAttribs
); return this;
112 case XLS_TOKEN( gradientFill
): mxFill
->importGradientFill( rAttribs
); return this;
115 case XLS_TOKEN( patternFill
):
118 case XLS_TOKEN( fgColor
): mxFill
->importFgColor( rAttribs
); break;
119 case XLS_TOKEN( bgColor
): mxFill
->importBgColor( rAttribs
); break;
122 case XLS_TOKEN( gradientFill
):
123 if( nElement
== XLS_TOKEN( stop
) )
125 mfGradPos
= rAttribs
.getDouble( XML_position
, -1.0 );
129 case XLS_TOKEN( stop
):
130 if( nElement
== XLS_TOKEN( color
) )
131 mxFill
->importColor( rAttribs
, mfGradPos
);
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
):
152 case XLS_TOKEN( alignment
): mxXf
->importAlignment( rAttribs
); break;
153 case XLS_TOKEN( protection
): mxXf
->importProtection( rAttribs
); break;
160 // ============================================================================
162 ContextHandlerRef
OoxDxfContext::onCreateContext( sal_Int32 nElement
, const AttributeList
& rAttribs
)
164 if( mxDxf
.get() ) switch( getCurrentElement() )
166 case XLS_TOKEN( dxf
):
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;
175 case XLS_TOKEN( alignment
): mxDxf
->importAlignment( rAttribs
); break;
176 case XLS_TOKEN( protection
): mxDxf
->importProtection( rAttribs
); break;
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;
201 case XLS_TOKEN( styleSheet
):
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;
216 case XLS_TOKEN( colors
):
217 if( nElement
== XLS_TOKEN( indexedColors
) ) return new OoxIndexedColorsContext( *this );
219 case XLS_TOKEN( numFmts
):
220 if( nElement
== XLS_TOKEN( numFmt
) ) getStyles().importNumFmt( rAttribs
);
222 case XLS_TOKEN( fonts
):
223 if( nElement
== XLS_TOKEN( font
) ) return new OoxFontContext( *this, getStyles().createFont() );
225 case XLS_TOKEN( borders
):
226 if( nElement
== XLS_TOKEN( border
) ) return new OoxBorderContext( *this, getStyles().createBorder() );
228 case XLS_TOKEN( fills
):
229 if( nElement
== XLS_TOKEN( fill
) ) return new OoxFillContext( *this, getStyles().createFill() );
231 case XLS_TOKEN( cellXfs
):
232 if( nElement
== XLS_TOKEN( xf
) ) return new OoxXfContext( *this, getStyles().createCellXf(), true );
234 case XLS_TOKEN( cellStyleXfs
):
235 if( nElement
== XLS_TOKEN( xf
) ) return new OoxXfContext( *this, getStyles().createStyleXf(), false );
237 case XLS_TOKEN( dxfs
):
238 if( nElement
== XLS_TOKEN( dxf
) ) return new OoxDxfContext( *this, getStyles().createDxf() );
240 case XLS_TOKEN( cellStyles
):
241 if( nElement
== XLS_TOKEN( cellStyle
) ) getStyles().importCellStyle( rAttribs
);
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;
255 case OOBIN_ID_STYLESHEET
:
258 case OOBIN_ID_COLORS
:
259 case OOBIN_ID_NUMFMTS
:
261 case OOBIN_ID_BORDERS
:
263 case OOBIN_ID_CELLXFS
:
264 case OOBIN_ID_CELLSTYLEXFS
:
266 case OOBIN_ID_CELLSTYLES
: return this;
270 case OOBIN_ID_COLORS
:
271 if( nRecId
== OOBIN_ID_INDEXEDCOLORS
) return new OoxIndexedColorsContext( *this );
273 case OOBIN_ID_NUMFMTS
:
274 if( nRecId
== OOBIN_ID_NUMFMT
) getStyles().importNumFmt( rStrm
);
277 if( nRecId
== OOBIN_ID_FONT
) getStyles().createFont()->importFont( rStrm
);
279 case OOBIN_ID_BORDERS
:
280 if( nRecId
== OOBIN_ID_BORDER
) getStyles().createBorder()->importBorder( rStrm
);
283 if( nRecId
== OOBIN_ID_FILL
) getStyles().createFill()->importFill( rStrm
);
285 case OOBIN_ID_CELLXFS
:
286 if( nRecId
== OOBIN_ID_XF
) getStyles().createCellXf()->importXf( rStrm
, true );
288 case OOBIN_ID_CELLSTYLEXFS
:
289 if( nRecId
== OOBIN_ID_XF
) getStyles().createStyleXf()->importXf( rStrm
, false );
292 if( nRecId
== OOBIN_ID_DXF
) getStyles().createDxf()->importDxf( rStrm
);
294 case OOBIN_ID_CELLSTYLES
:
295 if( nRecId
== OOBIN_ID_CELLSTYLE
) getStyles().importCellStyle( rStrm
);
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 },
325 void OoxStylesFragment::finalizeImport()
327 getStyles().finalizeImport();
330 // ============================================================================