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 "condformatcontext.hxx"
21 : #include "extlstcontext.hxx"
22 :
23 : #include "condformatbuffer.hxx"
24 :
25 : namespace oox {
26 : namespace xls {
27 :
28 : using ::oox::core::ContextHandlerRef;
29 :
30 19 : ColorScaleContext::ColorScaleContext( CondFormatContext& rFragment, CondFormatRuleRef xRule ) :
31 : WorksheetContextBase( rFragment ),
32 19 : mxRule( xRule )
33 : {
34 19 : }
35 :
36 94 : ContextHandlerRef ColorScaleContext::onCreateContext( sal_Int32 nElement, const AttributeList& )
37 : {
38 94 : switch( getCurrentElement() )
39 : {
40 : case XLS_TOKEN( cfRule ):
41 0 : return (nElement == XLS_TOKEN( colorScale )) ? this : 0;
42 : case XLS_TOKEN( colorScale ):
43 94 : if (nElement == XLS_TOKEN( cfvo ))
44 47 : return this;
45 47 : else if (nElement == XLS_TOKEN( color ))
46 47 : return this;
47 : else
48 0 : return 0;
49 : }
50 0 : return 0;
51 : }
52 :
53 113 : void ColorScaleContext::onStartElement( const AttributeList& rAttribs )
54 : {
55 113 : switch( getCurrentElement() )
56 : {
57 : case XLS_TOKEN( cfvo ):
58 47 : mxRule->getColorScale()->importCfvo( rAttribs );
59 47 : break;
60 : case XLS_TOKEN( color ):
61 47 : mxRule->getColorScale()->importColor( rAttribs );
62 47 : break;
63 : }
64 113 : }
65 :
66 17 : DataBarContext::DataBarContext( CondFormatContext& rFragment, CondFormatRuleRef xRule ) :
67 : WorksheetContextBase( rFragment ),
68 17 : mxRule( xRule )
69 : {
70 17 : }
71 :
72 51 : ContextHandlerRef DataBarContext::onCreateContext( sal_Int32 nElement, const AttributeList& )
73 : {
74 51 : switch( getCurrentElement() )
75 : {
76 : case XLS_TOKEN( cfRule ):
77 0 : return (nElement == XLS_TOKEN( dataBar )) ? this : 0;
78 : case XLS_TOKEN( dataBar ):
79 51 : if (nElement == XLS_TOKEN( cfvo ))
80 34 : return this;
81 17 : else if (nElement == XLS_TOKEN( color ))
82 17 : return this;
83 : else
84 0 : return 0;
85 : }
86 0 : return 0;
87 : }
88 :
89 68 : void DataBarContext::onStartElement( const AttributeList& rAttribs )
90 : {
91 68 : switch( getCurrentElement() )
92 : {
93 : case XLS_TOKEN( dataBar ):
94 17 : mxRule->getDataBar()->importAttribs( rAttribs );
95 17 : break;
96 : case XLS_TOKEN( cfvo ):
97 34 : mxRule->getDataBar()->importCfvo( rAttribs );
98 34 : break;
99 : case XLS_TOKEN( color ):
100 17 : mxRule->getDataBar()->importColor( rAttribs );
101 17 : break;
102 : }
103 68 : }
104 :
105 5 : IconSetContext::IconSetContext(WorksheetContextBase& rParent, IconSetRule* pIconSet) :
106 : WorksheetContextBase(rParent),
107 5 : mpIconSet(pIconSet)
108 : {
109 5 : }
110 :
111 51 : ContextHandlerRef IconSetContext::onCreateContext( sal_Int32 nElement, const AttributeList& )
112 : {
113 51 : switch( getCurrentElement() )
114 : {
115 : case XLS_TOKEN( cfRule ):
116 : case XLS14_TOKEN( cfRule ):
117 5 : return (nElement == XLS_TOKEN( iconSet ) || nElement == XLS14_TOKEN(iconSet)) ? this : 0;
118 : case XLS_TOKEN( iconSet ):
119 : case XLS14_TOKEN(iconSet):
120 27 : if (nElement == XLS_TOKEN( cfvo ) ||
121 8 : nElement == XLS14_TOKEN(cfvo) ||
122 : nElement == XLS14_TOKEN(cfIcon))
123 27 : return this;
124 : else
125 0 : return 0;
126 : case XLS14_TOKEN(cfvo):
127 19 : if (nElement == XM_TOKEN(f))
128 19 : return this;
129 : }
130 0 : return 0;
131 : }
132 :
133 56 : void IconSetContext::onStartElement( const AttributeList& rAttribs )
134 : {
135 56 : switch( getCurrentElement() )
136 : {
137 : case XLS_TOKEN( iconSet ):
138 : case XLS14_TOKEN( iconSet ):
139 5 : mpIconSet->importAttribs( rAttribs );
140 5 : break;
141 : case XLS_TOKEN( cfvo ):
142 : case XLS14_TOKEN( cfvo ):
143 19 : mpIconSet->importCfvo( rAttribs );
144 19 : break;
145 : case XLS14_TOKEN(cfIcon):
146 8 : mpIconSet->importIcon(rAttribs);
147 8 : break;
148 : }
149 56 : }
150 :
151 19 : void IconSetContext::onCharacters(const OUString& rChars)
152 : {
153 19 : maChars = rChars;
154 19 : }
155 :
156 56 : void IconSetContext::onEndElement()
157 : {
158 56 : switch(getCurrentElement())
159 : {
160 : case XM_TOKEN(f):
161 19 : mpIconSet->importFormula(maChars);
162 19 : maChars = OUString();
163 19 : break;
164 : }
165 56 : }
166 :
167 67 : CondFormatContext::CondFormatContext( WorksheetFragmentBase& rFragment ) :
168 67 : WorksheetContextBase( rFragment )
169 : {
170 67 : }
171 :
172 131 : ContextHandlerRef CondFormatContext::onCreateContext( sal_Int32 nElement, const AttributeList& )
173 : {
174 131 : switch( getCurrentElement() )
175 : {
176 : case XLS_TOKEN( conditionalFormatting ):
177 67 : return (nElement == XLS_TOKEN( cfRule )) ? this : 0;
178 : case XLS_TOKEN( cfRule ):
179 64 : if (nElement == XLS_TOKEN( formula ))
180 11 : return this;
181 53 : else if (nElement == XLS_TOKEN( colorScale ) )
182 19 : return new ColorScaleContext( *this, mxRule );
183 34 : else if (nElement == XLS_TOKEN( dataBar ) )
184 17 : return new DataBarContext( *this, mxRule );
185 17 : else if (nElement == XLS_TOKEN( iconSet ) )
186 0 : return new IconSetContext(*this, mxRule->getIconSet());
187 17 : else if (nElement == XLS_TOKEN( extLst ) )
188 17 : return new ExtLstLocalContext( *this, mxRule->getDataBar()->getDataBarFormatData() );
189 : else
190 0 : return 0;
191 : }
192 0 : return 0;
193 : }
194 :
195 145 : void CondFormatContext::onEndElement()
196 : {
197 145 : switch( getCurrentElement() )
198 : {
199 : case XLS_TOKEN( conditionalFormatting ):
200 67 : if(mxCondFmt.get())
201 67 : mxCondFmt->setReadyForFinalize();
202 67 : break;
203 : }
204 145 : }
205 :
206 145 : void CondFormatContext::onStartElement( const AttributeList& rAttribs )
207 : {
208 145 : switch( getCurrentElement() )
209 : {
210 : case XLS_TOKEN( conditionalFormatting ):
211 67 : mxCondFmt = getCondFormats().importConditionalFormatting( rAttribs );
212 67 : break;
213 : case XLS_TOKEN( cfRule ):
214 67 : if( mxCondFmt.get() ) mxRule = mxCondFmt->importCfRule( rAttribs );
215 67 : break;
216 : }
217 145 : }
218 :
219 11 : void CondFormatContext::onCharacters( const OUString& rChars )
220 : {
221 11 : if( isCurrentElement( XLS_TOKEN( formula ) ) && mxCondFmt.get() && mxRule.get() )
222 11 : mxRule->appendFormula( rChars );
223 11 : }
224 :
225 0 : ContextHandlerRef CondFormatContext::onCreateRecordContext( sal_Int32 nRecId, SequenceInputStream& )
226 : {
227 0 : switch( getCurrentElement() )
228 : {
229 : case BIFF12_ID_CONDFORMATTING:
230 0 : return (nRecId == BIFF12_ID_CFRULE) ? this : 0;
231 : }
232 0 : return 0;
233 : }
234 :
235 0 : void CondFormatContext::onStartRecord( SequenceInputStream& rStrm )
236 : {
237 0 : switch( getCurrentElement() )
238 : {
239 : case BIFF12_ID_CONDFORMATTING:
240 0 : mxCondFmt = getCondFormats().importCondFormatting( rStrm );
241 0 : break;
242 : case BIFF12_ID_CFRULE:
243 0 : if( mxCondFmt.get() ) mxCondFmt->importCfRule( rStrm );
244 0 : break;
245 : }
246 0 : }
247 :
248 0 : void CondFormatContext::onEndRecord()
249 : {
250 0 : switch( getCurrentElement() )
251 : {
252 : case BIFF12_ID_CONDFORMATTING:
253 0 : if( mxCondFmt.get() )
254 0 : mxCondFmt->finalizeImport();
255 0 : break;
256 : }
257 0 : }
258 :
259 : } // namespace xls
260 30 : } // namespace oox
261 :
262 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|