xref: /aoo41x/main/oox/source/xls/stylesfragment.cxx (revision ca5ec200)
1*ca5ec200SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*ca5ec200SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*ca5ec200SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*ca5ec200SAndrew Rist  * distributed with this work for additional information
6*ca5ec200SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*ca5ec200SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*ca5ec200SAndrew Rist  * "License"); you may not use this file except in compliance
9*ca5ec200SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*ca5ec200SAndrew Rist  *
11*ca5ec200SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*ca5ec200SAndrew Rist  *
13*ca5ec200SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*ca5ec200SAndrew Rist  * software distributed under the License is distributed on an
15*ca5ec200SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*ca5ec200SAndrew Rist  * KIND, either express or implied.  See the License for the
17*ca5ec200SAndrew Rist  * specific language governing permissions and limitations
18*ca5ec200SAndrew Rist  * under the License.
19*ca5ec200SAndrew Rist  *
20*ca5ec200SAndrew Rist  *************************************************************/
21*ca5ec200SAndrew Rist 
22*ca5ec200SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #include "oox/xls/stylesfragment.hxx"
25cdf0e10cSrcweir 
26cdf0e10cSrcweir #include "oox/helper/attributelist.hxx"
27cdf0e10cSrcweir 
28cdf0e10cSrcweir namespace oox {
29cdf0e10cSrcweir namespace xls {
30cdf0e10cSrcweir 
31cdf0e10cSrcweir // ============================================================================
32cdf0e10cSrcweir 
33cdf0e10cSrcweir using namespace ::oox::core;
34cdf0e10cSrcweir 
35cdf0e10cSrcweir using ::rtl::OUString;
36cdf0e10cSrcweir 
37cdf0e10cSrcweir // ============================================================================
38cdf0e10cSrcweir 
IndexedColorsContext(WorkbookFragmentBase & rFragment)39cdf0e10cSrcweir IndexedColorsContext::IndexedColorsContext( WorkbookFragmentBase& rFragment ) :
40cdf0e10cSrcweir     WorkbookContextBase( rFragment )
41cdf0e10cSrcweir {
42cdf0e10cSrcweir }
43cdf0e10cSrcweir 
onCreateContext(sal_Int32 nElement,const AttributeList & rAttribs)44cdf0e10cSrcweir ContextHandlerRef IndexedColorsContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs )
45cdf0e10cSrcweir {
46cdf0e10cSrcweir     switch( getCurrentElement() )
47cdf0e10cSrcweir     {
48cdf0e10cSrcweir         case XLS_TOKEN( indexedColors ):
49cdf0e10cSrcweir             if( nElement == XLS_TOKEN( rgbColor ) ) getStyles().importPaletteColor( rAttribs );
50cdf0e10cSrcweir         break;
51cdf0e10cSrcweir     }
52cdf0e10cSrcweir     return 0;
53cdf0e10cSrcweir }
54cdf0e10cSrcweir 
onCreateRecordContext(sal_Int32 nRecId,SequenceInputStream & rStrm)55cdf0e10cSrcweir ContextHandlerRef IndexedColorsContext::onCreateRecordContext( sal_Int32 nRecId, SequenceInputStream& rStrm )
56cdf0e10cSrcweir {
57cdf0e10cSrcweir     switch( getCurrentElement() )
58cdf0e10cSrcweir     {
59cdf0e10cSrcweir         case BIFF12_ID_INDEXEDCOLORS:
60cdf0e10cSrcweir             if( nRecId == BIFF12_ID_RGBCOLOR ) getStyles().importPaletteColor( rStrm );
61cdf0e10cSrcweir         break;
62cdf0e10cSrcweir     }
63cdf0e10cSrcweir     return 0;
64cdf0e10cSrcweir }
65cdf0e10cSrcweir 
66cdf0e10cSrcweir // ============================================================================
67cdf0e10cSrcweir 
onCreateContext(sal_Int32 nElement,const AttributeList & rAttribs)68cdf0e10cSrcweir ContextHandlerRef FontContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs )
69cdf0e10cSrcweir {
70cdf0e10cSrcweir     if( mxFont.get() )
71cdf0e10cSrcweir         mxFont->importAttribs( nElement, rAttribs );
72cdf0e10cSrcweir     return 0;
73cdf0e10cSrcweir }
74cdf0e10cSrcweir 
75cdf0e10cSrcweir // ============================================================================
76cdf0e10cSrcweir 
onStartElement(const AttributeList & rAttribs)77cdf0e10cSrcweir void BorderContext::onStartElement( const AttributeList& rAttribs )
78cdf0e10cSrcweir {
79cdf0e10cSrcweir     if( mxBorder.get() && (getCurrentElement() == XLS_TOKEN( border )) )
80cdf0e10cSrcweir         mxBorder->importBorder( rAttribs );
81cdf0e10cSrcweir }
82cdf0e10cSrcweir 
onCreateContext(sal_Int32 nElement,const AttributeList & rAttribs)83cdf0e10cSrcweir ContextHandlerRef BorderContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs )
84cdf0e10cSrcweir {
85cdf0e10cSrcweir     if( mxBorder.get() ) switch( getCurrentElement() )
86cdf0e10cSrcweir     {
87cdf0e10cSrcweir         case XLS_TOKEN( border ):
88cdf0e10cSrcweir             mxBorder->importStyle( nElement, rAttribs );
89cdf0e10cSrcweir             return this;
90cdf0e10cSrcweir 
91cdf0e10cSrcweir         default:
92cdf0e10cSrcweir             if( nElement == XLS_TOKEN( color ) )
93cdf0e10cSrcweir                 mxBorder->importColor( getCurrentElement(), rAttribs );
94cdf0e10cSrcweir     }
95cdf0e10cSrcweir     return 0;
96cdf0e10cSrcweir }
97cdf0e10cSrcweir 
98cdf0e10cSrcweir // ============================================================================
99cdf0e10cSrcweir 
onCreateContext(sal_Int32 nElement,const AttributeList & rAttribs)100cdf0e10cSrcweir ContextHandlerRef FillContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs )
101cdf0e10cSrcweir {
102cdf0e10cSrcweir     if( mxFill.get() ) switch( getCurrentElement() )
103cdf0e10cSrcweir     {
104cdf0e10cSrcweir         case XLS_TOKEN( fill ):
105cdf0e10cSrcweir             switch( nElement )
106cdf0e10cSrcweir             {
107cdf0e10cSrcweir                 case XLS_TOKEN( patternFill ):  mxFill->importPatternFill( rAttribs );  return this;
108cdf0e10cSrcweir                 case XLS_TOKEN( gradientFill ): mxFill->importGradientFill( rAttribs ); return this;
109cdf0e10cSrcweir             }
110cdf0e10cSrcweir         break;
111cdf0e10cSrcweir         case XLS_TOKEN( patternFill ):
112cdf0e10cSrcweir             switch( nElement )
113cdf0e10cSrcweir             {
114cdf0e10cSrcweir                 case XLS_TOKEN( fgColor ):      mxFill->importFgColor( rAttribs );      break;
115cdf0e10cSrcweir                 case XLS_TOKEN( bgColor ):      mxFill->importBgColor( rAttribs );      break;
116cdf0e10cSrcweir             }
117cdf0e10cSrcweir         break;
118cdf0e10cSrcweir         case XLS_TOKEN( gradientFill ):
119cdf0e10cSrcweir             if( nElement == XLS_TOKEN( stop ) )
120cdf0e10cSrcweir             {
121cdf0e10cSrcweir                 mfGradPos = rAttribs.getDouble( XML_position, -1.0 );
122cdf0e10cSrcweir                 return this;
123cdf0e10cSrcweir             }
124cdf0e10cSrcweir         break;
125cdf0e10cSrcweir         case XLS_TOKEN( stop ):
126cdf0e10cSrcweir             if( nElement == XLS_TOKEN( color ) )
127cdf0e10cSrcweir                 mxFill->importColor( rAttribs, mfGradPos );
128cdf0e10cSrcweir         break;
129cdf0e10cSrcweir     }
130cdf0e10cSrcweir     return 0;
131cdf0e10cSrcweir }
132cdf0e10cSrcweir 
133cdf0e10cSrcweir // ============================================================================
134cdf0e10cSrcweir 
onStartElement(const AttributeList & rAttribs)135cdf0e10cSrcweir void XfContext::onStartElement( const AttributeList& rAttribs )
136cdf0e10cSrcweir {
137cdf0e10cSrcweir     if( mxXf.get() && (getCurrentElement() == XLS_TOKEN( xf )) )
138cdf0e10cSrcweir         mxXf->importXf( rAttribs, mbCellXf );
139cdf0e10cSrcweir }
140cdf0e10cSrcweir 
onCreateContext(sal_Int32 nElement,const AttributeList & rAttribs)141cdf0e10cSrcweir ContextHandlerRef XfContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs )
142cdf0e10cSrcweir {
143cdf0e10cSrcweir     if( mxXf.get() ) switch( getCurrentElement() )
144cdf0e10cSrcweir     {
145cdf0e10cSrcweir         case XLS_TOKEN( xf ):
146cdf0e10cSrcweir             switch( nElement )
147cdf0e10cSrcweir             {
148cdf0e10cSrcweir                 case XLS_TOKEN( alignment ):    mxXf->importAlignment( rAttribs );  break;
149cdf0e10cSrcweir                 case XLS_TOKEN( protection ):   mxXf->importProtection( rAttribs ); break;
150cdf0e10cSrcweir             }
151cdf0e10cSrcweir         break;
152cdf0e10cSrcweir     }
153cdf0e10cSrcweir     return 0;
154cdf0e10cSrcweir }
155cdf0e10cSrcweir 
156cdf0e10cSrcweir // ============================================================================
157cdf0e10cSrcweir 
onCreateContext(sal_Int32 nElement,const AttributeList & rAttribs)158cdf0e10cSrcweir ContextHandlerRef DxfContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs )
159cdf0e10cSrcweir {
160cdf0e10cSrcweir     if( mxDxf.get() ) switch( getCurrentElement() )
161cdf0e10cSrcweir     {
162cdf0e10cSrcweir         case XLS_TOKEN( dxf ):
163cdf0e10cSrcweir             switch( nElement )
164cdf0e10cSrcweir             {
165cdf0e10cSrcweir                 case XLS_TOKEN( font ):         return new FontContext( *this, mxDxf->createFont() );
166cdf0e10cSrcweir                 case XLS_TOKEN( border ):       return new BorderContext( *this, mxDxf->createBorder() );
167cdf0e10cSrcweir                 case XLS_TOKEN( fill ):         return new FillContext( *this, mxDxf->createFill() );
168cdf0e10cSrcweir 
169cdf0e10cSrcweir                 case XLS_TOKEN( numFmt ):       mxDxf->importNumFmt( rAttribs );        break;
170cdf0e10cSrcweir #if 0
171cdf0e10cSrcweir                 case XLS_TOKEN( alignment ):    mxDxf->importAlignment( rAttribs );     break;
172cdf0e10cSrcweir                 case XLS_TOKEN( protection ):   mxDxf->importProtection( rAttribs );    break;
173cdf0e10cSrcweir #endif
174cdf0e10cSrcweir             }
175cdf0e10cSrcweir         break;
176cdf0e10cSrcweir     }
177cdf0e10cSrcweir     return 0;
178cdf0e10cSrcweir }
179cdf0e10cSrcweir 
180cdf0e10cSrcweir // ============================================================================
181cdf0e10cSrcweir 
StylesFragment(const WorkbookHelper & rHelper,const OUString & rFragmentPath)182cdf0e10cSrcweir StylesFragment::StylesFragment( const WorkbookHelper& rHelper, const OUString& rFragmentPath ) :
183cdf0e10cSrcweir     WorkbookFragmentBase( rHelper, rFragmentPath )
184cdf0e10cSrcweir {
185cdf0e10cSrcweir }
186cdf0e10cSrcweir 
onCreateContext(sal_Int32 nElement,const AttributeList & rAttribs)187cdf0e10cSrcweir ContextHandlerRef StylesFragment::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs )
188cdf0e10cSrcweir {
189cdf0e10cSrcweir     switch( getCurrentElement() )
190cdf0e10cSrcweir     {
191cdf0e10cSrcweir         case XML_ROOT_CONTEXT:
192cdf0e10cSrcweir             if( nElement == XLS_TOKEN( styleSheet ) ) return this;
193cdf0e10cSrcweir         break;
194cdf0e10cSrcweir 
195cdf0e10cSrcweir         case XLS_TOKEN( styleSheet ):
196cdf0e10cSrcweir             switch( nElement )
197cdf0e10cSrcweir             {
198cdf0e10cSrcweir                 case XLS_TOKEN( colors ):
199cdf0e10cSrcweir                 case XLS_TOKEN( numFmts ):
200cdf0e10cSrcweir                 case XLS_TOKEN( fonts ):
201cdf0e10cSrcweir                 case XLS_TOKEN( borders ):
202cdf0e10cSrcweir                 case XLS_TOKEN( fills ):
203cdf0e10cSrcweir                 case XLS_TOKEN( cellXfs ):
204cdf0e10cSrcweir                 case XLS_TOKEN( cellStyleXfs ):
205cdf0e10cSrcweir                 case XLS_TOKEN( dxfs ):
206cdf0e10cSrcweir                 case XLS_TOKEN( cellStyles ):   return this;
207cdf0e10cSrcweir             }
208cdf0e10cSrcweir         break;
209cdf0e10cSrcweir 
210cdf0e10cSrcweir         case XLS_TOKEN( colors ):
211cdf0e10cSrcweir             if( nElement == XLS_TOKEN( indexedColors ) ) return new IndexedColorsContext( *this );
212cdf0e10cSrcweir         break;
213cdf0e10cSrcweir         case XLS_TOKEN( numFmts ):
214cdf0e10cSrcweir             if( nElement == XLS_TOKEN( numFmt ) ) getStyles().importNumFmt( rAttribs );
215cdf0e10cSrcweir         break;
216cdf0e10cSrcweir         case XLS_TOKEN( fonts ):
217cdf0e10cSrcweir             if( nElement == XLS_TOKEN( font ) ) return new FontContext( *this, getStyles().createFont() );
218cdf0e10cSrcweir         break;
219cdf0e10cSrcweir         case XLS_TOKEN( borders ):
220cdf0e10cSrcweir             if( nElement == XLS_TOKEN( border ) ) return new BorderContext( *this, getStyles().createBorder() );
221cdf0e10cSrcweir         break;
222cdf0e10cSrcweir         case XLS_TOKEN( fills ):
223cdf0e10cSrcweir             if( nElement == XLS_TOKEN( fill ) ) return new FillContext( *this, getStyles().createFill() );
224cdf0e10cSrcweir         break;
225cdf0e10cSrcweir         case XLS_TOKEN( cellXfs ):
226cdf0e10cSrcweir             if( nElement == XLS_TOKEN( xf ) ) return new XfContext( *this, getStyles().createCellXf(), true );
227cdf0e10cSrcweir         break;
228cdf0e10cSrcweir         case XLS_TOKEN( cellStyleXfs ):
229cdf0e10cSrcweir             if( nElement == XLS_TOKEN( xf ) ) return new XfContext( *this, getStyles().createStyleXf(), false );
230cdf0e10cSrcweir         break;
231cdf0e10cSrcweir         case XLS_TOKEN( dxfs ):
232cdf0e10cSrcweir             if( nElement == XLS_TOKEN( dxf ) ) return new DxfContext( *this, getStyles().createDxf() );
233cdf0e10cSrcweir         break;
234cdf0e10cSrcweir         case XLS_TOKEN( cellStyles ):
235cdf0e10cSrcweir             if( nElement == XLS_TOKEN( cellStyle ) ) getStyles().importCellStyle( rAttribs );
236cdf0e10cSrcweir         break;
237cdf0e10cSrcweir     }
238cdf0e10cSrcweir     return 0;
239cdf0e10cSrcweir }
240cdf0e10cSrcweir 
onCreateRecordContext(sal_Int32 nRecId,SequenceInputStream & rStrm)241cdf0e10cSrcweir ContextHandlerRef StylesFragment::onCreateRecordContext( sal_Int32 nRecId, SequenceInputStream& rStrm )
242cdf0e10cSrcweir {
243cdf0e10cSrcweir     switch( getCurrentElement() )
244cdf0e10cSrcweir     {
245cdf0e10cSrcweir         case XML_ROOT_CONTEXT:
246cdf0e10cSrcweir             if( nRecId == BIFF12_ID_STYLESHEET ) return this;
247cdf0e10cSrcweir         break;
248cdf0e10cSrcweir 
249cdf0e10cSrcweir         case BIFF12_ID_STYLESHEET:
250cdf0e10cSrcweir             switch( nRecId )
251cdf0e10cSrcweir             {
252cdf0e10cSrcweir                 case BIFF12_ID_COLORS:
253cdf0e10cSrcweir                 case BIFF12_ID_NUMFMTS:
254cdf0e10cSrcweir                 case BIFF12_ID_FONTS:
255cdf0e10cSrcweir                 case BIFF12_ID_BORDERS:
256cdf0e10cSrcweir                 case BIFF12_ID_FILLS:
257cdf0e10cSrcweir                 case BIFF12_ID_CELLXFS:
258cdf0e10cSrcweir                 case BIFF12_ID_CELLSTYLEXFS:
259cdf0e10cSrcweir                 case BIFF12_ID_DXFS:
260cdf0e10cSrcweir                 case BIFF12_ID_CELLSTYLES:      return this;
261cdf0e10cSrcweir             }
262cdf0e10cSrcweir         break;
263cdf0e10cSrcweir 
264cdf0e10cSrcweir         case BIFF12_ID_COLORS:
265cdf0e10cSrcweir             if( nRecId == BIFF12_ID_INDEXEDCOLORS ) return new IndexedColorsContext( *this );
266cdf0e10cSrcweir         break;
267cdf0e10cSrcweir         case BIFF12_ID_NUMFMTS:
268cdf0e10cSrcweir             if( nRecId == BIFF12_ID_NUMFMT ) getStyles().importNumFmt( rStrm );
269cdf0e10cSrcweir         break;
270cdf0e10cSrcweir         case BIFF12_ID_FONTS:
271cdf0e10cSrcweir             if( nRecId == BIFF12_ID_FONT ) getStyles().createFont()->importFont( rStrm );
272cdf0e10cSrcweir         break;
273cdf0e10cSrcweir         case BIFF12_ID_BORDERS:
274cdf0e10cSrcweir             if( nRecId == BIFF12_ID_BORDER ) getStyles().createBorder()->importBorder( rStrm );
275cdf0e10cSrcweir         break;
276cdf0e10cSrcweir         case BIFF12_ID_FILLS:
277cdf0e10cSrcweir             if( nRecId == BIFF12_ID_FILL ) getStyles().createFill()->importFill( rStrm );
278cdf0e10cSrcweir         break;
279cdf0e10cSrcweir         case BIFF12_ID_CELLXFS:
280cdf0e10cSrcweir             if( nRecId == BIFF12_ID_XF ) getStyles().createCellXf()->importXf( rStrm, true );
281cdf0e10cSrcweir         break;
282cdf0e10cSrcweir         case BIFF12_ID_CELLSTYLEXFS:
283cdf0e10cSrcweir             if( nRecId == BIFF12_ID_XF ) getStyles().createStyleXf()->importXf( rStrm, false );
284cdf0e10cSrcweir         break;
285cdf0e10cSrcweir         case BIFF12_ID_DXFS:
286cdf0e10cSrcweir             if( nRecId == BIFF12_ID_DXF ) getStyles().createDxf()->importDxf( rStrm );
287cdf0e10cSrcweir         break;
288cdf0e10cSrcweir         case BIFF12_ID_CELLSTYLES:
289cdf0e10cSrcweir             if( nRecId == BIFF12_ID_CELLSTYLE ) getStyles().importCellStyle( rStrm );
290cdf0e10cSrcweir         break;
291cdf0e10cSrcweir     }
292cdf0e10cSrcweir     return 0;
293cdf0e10cSrcweir }
294cdf0e10cSrcweir 
getRecordInfos() const295cdf0e10cSrcweir const RecordInfo* StylesFragment::getRecordInfos() const
296cdf0e10cSrcweir {
297cdf0e10cSrcweir     static const RecordInfo spRecInfos[] =
298cdf0e10cSrcweir     {
299cdf0e10cSrcweir         { BIFF12_ID_BORDERS,        BIFF12_ID_BORDERS + 1       },
300cdf0e10cSrcweir         { BIFF12_ID_CELLSTYLES,     BIFF12_ID_CELLSTYLES + 1    },
301cdf0e10cSrcweir         { BIFF12_ID_CELLSTYLEXFS,   BIFF12_ID_CELLSTYLEXFS + 1  },
302cdf0e10cSrcweir         { BIFF12_ID_CELLXFS,        BIFF12_ID_CELLXFS + 1       },
303cdf0e10cSrcweir         { BIFF12_ID_COLORS,         BIFF12_ID_COLORS + 1        },
304cdf0e10cSrcweir         { BIFF12_ID_DXFS,           BIFF12_ID_DXFS + 1          },
305cdf0e10cSrcweir         { BIFF12_ID_FILLS,          BIFF12_ID_FILLS + 1         },
306cdf0e10cSrcweir         { BIFF12_ID_FONTS,          BIFF12_ID_FONTS + 1         },
307cdf0e10cSrcweir         { BIFF12_ID_INDEXEDCOLORS,  BIFF12_ID_INDEXEDCOLORS + 1 },
308cdf0e10cSrcweir         { BIFF12_ID_MRUCOLORS,      BIFF12_ID_MRUCOLORS + 1     },
309cdf0e10cSrcweir         { BIFF12_ID_NUMFMTS,        BIFF12_ID_NUMFMTS + 1       },
310cdf0e10cSrcweir         { BIFF12_ID_STYLESHEET,     BIFF12_ID_STYLESHEET + 1    },
311cdf0e10cSrcweir         { BIFF12_ID_TABLESTYLES,    BIFF12_ID_TABLESTYLES + 1   },
312cdf0e10cSrcweir         { -1,                       -1                          }
313cdf0e10cSrcweir     };
314cdf0e10cSrcweir     return spRecInfos;
315cdf0e10cSrcweir }
316cdf0e10cSrcweir 
finalizeImport()317cdf0e10cSrcweir void StylesFragment::finalizeImport()
318cdf0e10cSrcweir {
319cdf0e10cSrcweir     getStyles().finalizeImport();
320cdf0e10cSrcweir }
321cdf0e10cSrcweir 
322cdf0e10cSrcweir // ============================================================================
323cdf0e10cSrcweir 
324cdf0e10cSrcweir } // namespace xls
325cdf0e10cSrcweir } // namespace oox
326