Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #include "stylesfragment.hxx"
21 :
22 : #include "oox/helper/attributelist.hxx"
23 :
24 : namespace oox {
25 : namespace xls {
26 :
27 : // ============================================================================
28 :
29 : using namespace ::oox::core;
30 :
31 : using ::rtl::OUString;
32 :
33 : // ============================================================================
34 :
35 1 : IndexedColorsContext::IndexedColorsContext( WorkbookFragmentBase& rFragment ) :
36 1 : WorkbookContextBase( rFragment )
37 : {
38 1 : }
39 :
40 56 : ContextHandlerRef IndexedColorsContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs )
41 : {
42 56 : switch( getCurrentElement() )
43 : {
44 : case XLS_TOKEN( indexedColors ):
45 56 : if( nElement == XLS_TOKEN( rgbColor ) ) getStyles().importPaletteColor( rAttribs );
46 56 : break;
47 : }
48 56 : return 0;
49 : }
50 :
51 0 : ContextHandlerRef IndexedColorsContext::onCreateRecordContext( sal_Int32 nRecId, SequenceInputStream& rStrm )
52 : {
53 0 : switch( getCurrentElement() )
54 : {
55 : case BIFF12_ID_INDEXEDCOLORS:
56 0 : if( nRecId == BIFF12_ID_RGBCOLOR ) getStyles().importPaletteColor( rStrm );
57 0 : break;
58 : }
59 0 : return 0;
60 : }
61 :
62 : // ============================================================================
63 :
64 265 : ContextHandlerRef FontContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs )
65 : {
66 265 : if( mxFont.get() )
67 265 : mxFont->importAttribs( nElement, rAttribs );
68 265 : return 0;
69 : }
70 :
71 : // ============================================================================
72 :
73 66 : void BorderContext::onStartElement( const AttributeList& rAttribs )
74 : {
75 66 : if( mxBorder.get() && (getCurrentElement() == XLS_TOKEN( border )) )
76 11 : mxBorder->importBorder( rAttribs );
77 66 : }
78 :
79 55 : ContextHandlerRef BorderContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs )
80 : {
81 55 : if( mxBorder.get() ) switch( getCurrentElement() )
82 : {
83 : case XLS_TOKEN( border ):
84 55 : mxBorder->importStyle( nElement, rAttribs );
85 55 : return this;
86 :
87 : default:
88 0 : if( nElement == XLS_TOKEN( color ) )
89 0 : mxBorder->importColor( getCurrentElement(), rAttribs );
90 : }
91 0 : return 0;
92 : }
93 :
94 : // ============================================================================
95 :
96 68 : ContextHandlerRef FillContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs )
97 : {
98 68 : if( mxFill.get() ) switch( getCurrentElement() )
99 : {
100 : case XLS_TOKEN( fill ):
101 44 : switch( nElement )
102 : {
103 44 : case XLS_TOKEN( patternFill ): mxFill->importPatternFill( rAttribs ); return this;
104 0 : case XLS_TOKEN( gradientFill ): mxFill->importGradientFill( rAttribs ); return this;
105 : }
106 0 : break;
107 : case XLS_TOKEN( patternFill ):
108 24 : switch( nElement )
109 : {
110 2 : case XLS_TOKEN( fgColor ): mxFill->importFgColor( rAttribs ); break;
111 22 : case XLS_TOKEN( bgColor ): mxFill->importBgColor( rAttribs ); break;
112 : }
113 24 : break;
114 : case XLS_TOKEN( gradientFill ):
115 0 : if( nElement == XLS_TOKEN( stop ) )
116 : {
117 0 : mfGradPos = rAttribs.getDouble( XML_position, -1.0 );
118 0 : return this;
119 : }
120 0 : break;
121 : case XLS_TOKEN( stop ):
122 0 : if( nElement == XLS_TOKEN( color ) )
123 0 : mxFill->importColor( rAttribs, mfGradPos );
124 0 : break;
125 : }
126 24 : return 0;
127 : }
128 :
129 : // ============================================================================
130 :
131 186 : void XfContext::onStartElement( const AttributeList& rAttribs )
132 : {
133 186 : if( mxXf.get() && (getCurrentElement() == XLS_TOKEN( xf )) )
134 186 : mxXf->importXf( rAttribs, mbCellXf );
135 186 : }
136 :
137 68 : ContextHandlerRef XfContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs )
138 : {
139 68 : if( mxXf.get() ) switch( getCurrentElement() )
140 : {
141 : case XLS_TOKEN( xf ):
142 68 : switch( nElement )
143 : {
144 35 : case XLS_TOKEN( alignment ): mxXf->importAlignment( rAttribs ); break;
145 33 : case XLS_TOKEN( protection ): mxXf->importProtection( rAttribs ); break;
146 : }
147 68 : break;
148 : }
149 68 : return 0;
150 : }
151 :
152 : // ============================================================================
153 :
154 110 : ContextHandlerRef DxfContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs )
155 : {
156 110 : if( mxDxf.get() ) switch( getCurrentElement() )
157 : {
158 : case XLS_TOKEN( dxf ):
159 110 : switch( nElement )
160 : {
161 20 : case XLS_TOKEN( font ): return new FontContext( *this, mxDxf->createFont() );
162 0 : case XLS_TOKEN( border ): return new BorderContext( *this, mxDxf->createBorder() );
163 20 : case XLS_TOKEN( fill ): return new FillContext( *this, mxDxf->createFill() );
164 :
165 70 : case XLS_TOKEN( numFmt ): mxDxf->importNumFmt( rAttribs ); break;
166 : #if 0
167 : case XLS_TOKEN( alignment ): mxDxf->importAlignment( rAttribs ); break;
168 : case XLS_TOKEN( protection ): mxDxf->importProtection( rAttribs ); break;
169 : #endif
170 : }
171 70 : break;
172 : }
173 70 : return 0;
174 : }
175 :
176 : // ============================================================================
177 :
178 11 : StylesFragment::StylesFragment( const WorkbookHelper& rHelper, const OUString& rFragmentPath ) :
179 11 : WorkbookFragmentBase( rHelper, rFragmentPath )
180 : {
181 11 : }
182 :
183 515 : ContextHandlerRef StylesFragment::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs )
184 : {
185 515 : switch( getCurrentElement() )
186 : {
187 : case XML_ROOT_CONTEXT:
188 11 : if( nElement == XLS_TOKEN( styleSheet ) ) return this;
189 0 : break;
190 :
191 : case XLS_TOKEN( styleSheet ):
192 88 : switch( nElement )
193 : {
194 : case XLS_TOKEN( colors ):
195 : case XLS_TOKEN( numFmts ):
196 : case XLS_TOKEN( fonts ):
197 : case XLS_TOKEN( borders ):
198 : case XLS_TOKEN( fills ):
199 : case XLS_TOKEN( cellXfs ):
200 : case XLS_TOKEN( cellStyleXfs ):
201 : case XLS_TOKEN( dxfs ):
202 81 : case XLS_TOKEN( cellStyles ): return this;
203 : }
204 7 : break;
205 :
206 : case XLS_TOKEN( colors ):
207 1 : if( nElement == XLS_TOKEN( indexedColors ) ) return new IndexedColorsContext( *this );
208 0 : break;
209 : case XLS_TOKEN( numFmts ):
210 29 : if( nElement == XLS_TOKEN( numFmt ) ) getStyles().importNumFmt( rAttribs );
211 29 : break;
212 : case XLS_TOKEN( fonts ):
213 44 : if( nElement == XLS_TOKEN( font ) ) return new FontContext( *this, getStyles().createFont() );
214 0 : break;
215 : case XLS_TOKEN( borders ):
216 11 : if( nElement == XLS_TOKEN( border ) ) return new BorderContext( *this, getStyles().createBorder() );
217 0 : break;
218 : case XLS_TOKEN( fills ):
219 24 : if( nElement == XLS_TOKEN( fill ) ) return new FillContext( *this, getStyles().createFill() );
220 0 : break;
221 : case XLS_TOKEN( cellXfs ):
222 37 : if( nElement == XLS_TOKEN( xf ) ) return new XfContext( *this, getStyles().createCellXf(), true );
223 0 : break;
224 : case XLS_TOKEN( cellStyleXfs ):
225 149 : if( nElement == XLS_TOKEN( xf ) ) return new XfContext( *this, getStyles().createStyleXf(), false );
226 0 : break;
227 : case XLS_TOKEN( dxfs ):
228 70 : if( nElement == XLS_TOKEN( dxf ) ) return new DxfContext( *this, getStyles().createDxf() );
229 0 : break;
230 : case XLS_TOKEN( cellStyles ):
231 51 : if( nElement == XLS_TOKEN( cellStyle ) ) getStyles().importCellStyle( rAttribs );
232 51 : break;
233 : }
234 87 : return 0;
235 : }
236 :
237 0 : ContextHandlerRef StylesFragment::onCreateRecordContext( sal_Int32 nRecId, SequenceInputStream& rStrm )
238 : {
239 0 : switch( getCurrentElement() )
240 : {
241 : case XML_ROOT_CONTEXT:
242 0 : if( nRecId == BIFF12_ID_STYLESHEET ) return this;
243 0 : break;
244 :
245 : case BIFF12_ID_STYLESHEET:
246 0 : switch( nRecId )
247 : {
248 : case BIFF12_ID_COLORS:
249 : case BIFF12_ID_NUMFMTS:
250 : case BIFF12_ID_FONTS:
251 : case BIFF12_ID_BORDERS:
252 : case BIFF12_ID_FILLS:
253 : case BIFF12_ID_CELLXFS:
254 : case BIFF12_ID_CELLSTYLEXFS:
255 : case BIFF12_ID_DXFS:
256 0 : case BIFF12_ID_CELLSTYLES: return this;
257 : }
258 0 : break;
259 :
260 : case BIFF12_ID_COLORS:
261 0 : if( nRecId == BIFF12_ID_INDEXEDCOLORS ) return new IndexedColorsContext( *this );
262 0 : break;
263 : case BIFF12_ID_NUMFMTS:
264 0 : if( nRecId == BIFF12_ID_NUMFMT ) getStyles().importNumFmt( rStrm );
265 0 : break;
266 : case BIFF12_ID_FONTS:
267 0 : if( nRecId == BIFF12_ID_FONT ) getStyles().createFont()->importFont( rStrm );
268 0 : break;
269 : case BIFF12_ID_BORDERS:
270 0 : if( nRecId == BIFF12_ID_BORDER ) getStyles().createBorder()->importBorder( rStrm );
271 0 : break;
272 : case BIFF12_ID_FILLS:
273 0 : if( nRecId == BIFF12_ID_FILL ) getStyles().createFill()->importFill( rStrm );
274 0 : break;
275 : case BIFF12_ID_CELLXFS:
276 0 : if( nRecId == BIFF12_ID_XF ) getStyles().createCellXf()->importXf( rStrm, true );
277 0 : break;
278 : case BIFF12_ID_CELLSTYLEXFS:
279 0 : if( nRecId == BIFF12_ID_XF ) getStyles().createStyleXf()->importXf( rStrm, false );
280 0 : break;
281 : case BIFF12_ID_DXFS:
282 0 : if( nRecId == BIFF12_ID_DXF ) getStyles().createDxf()->importDxf( rStrm );
283 0 : break;
284 : case BIFF12_ID_CELLSTYLES:
285 0 : if( nRecId == BIFF12_ID_CELLSTYLE ) getStyles().importCellStyle( rStrm );
286 0 : break;
287 : }
288 0 : return 0;
289 : }
290 :
291 0 : const RecordInfo* StylesFragment::getRecordInfos() const
292 : {
293 : static const RecordInfo spRecInfos[] =
294 : {
295 : { BIFF12_ID_BORDERS, BIFF12_ID_BORDERS + 1 },
296 : { BIFF12_ID_CELLSTYLES, BIFF12_ID_CELLSTYLES + 1 },
297 : { BIFF12_ID_CELLSTYLEXFS, BIFF12_ID_CELLSTYLEXFS + 1 },
298 : { BIFF12_ID_CELLXFS, BIFF12_ID_CELLXFS + 1 },
299 : { BIFF12_ID_COLORS, BIFF12_ID_COLORS + 1 },
300 : { BIFF12_ID_DXFS, BIFF12_ID_DXFS + 1 },
301 : { BIFF12_ID_FILLS, BIFF12_ID_FILLS + 1 },
302 : { BIFF12_ID_FONTS, BIFF12_ID_FONTS + 1 },
303 : { BIFF12_ID_INDEXEDCOLORS, BIFF12_ID_INDEXEDCOLORS + 1 },
304 : { BIFF12_ID_MRUCOLORS, BIFF12_ID_MRUCOLORS + 1 },
305 : { BIFF12_ID_NUMFMTS, BIFF12_ID_NUMFMTS + 1 },
306 : { BIFF12_ID_STYLESHEET, BIFF12_ID_STYLESHEET + 1 },
307 : { BIFF12_ID_TABLESTYLES, BIFF12_ID_TABLESTYLES + 1 },
308 : { -1, -1 }
309 : };
310 0 : return spRecInfos;
311 : }
312 :
313 11 : void StylesFragment::finalizeImport()
314 : {
315 11 : getStyles().finalizeImport();
316 11 : }
317 :
318 : // ============================================================================
319 :
320 : } // namespace xls
321 9 : } // namespace oox
322 :
323 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|