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 "pivottablefragment.hxx"
21 :
22 : #include "biffinputstream.hxx"
23 : #include "pivottablebuffer.hxx"
24 :
25 : namespace oox {
26 : namespace xls {
27 :
28 : using namespace ::oox::core;
29 :
30 :
31 0 : PivotTableFieldContext::PivotTableFieldContext( WorksheetFragmentBase& rFragment, PivotTableField& rTableField ) :
32 : WorksheetContextBase( rFragment ),
33 0 : mrTableField( rTableField )
34 : {
35 0 : }
36 :
37 0 : ContextHandlerRef PivotTableFieldContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs )
38 : {
39 0 : switch( getCurrentElement() )
40 : {
41 : case XLS_TOKEN( pivotField ):
42 0 : switch( nElement )
43 : {
44 0 : case XLS_TOKEN( items ): return this;
45 0 : case XLS_TOKEN( autoSortScope ): return this;
46 : }
47 0 : break;
48 : case XLS_TOKEN( items ):
49 0 : if( nElement == XLS_TOKEN( item ) ) mrTableField.importItem( rAttribs );
50 0 : break;
51 : case XLS_TOKEN( autoSortScope ):
52 0 : if( nElement == XLS_TOKEN( pivotArea ) ) return this;
53 0 : break;
54 : case XLS_TOKEN( pivotArea ):
55 0 : if( nElement == XLS_TOKEN( references ) ) return this;
56 0 : break;
57 : case XLS_TOKEN( references ):
58 0 : if( nElement == XLS_TOKEN( reference ) ) { mrTableField.importReference( rAttribs ); return this; }
59 0 : break;
60 : case XLS_TOKEN( reference ):
61 0 : if( nElement == XLS_TOKEN( x ) ) mrTableField.importReferenceItem( rAttribs );
62 0 : break;
63 : }
64 0 : return 0;
65 : }
66 :
67 0 : void PivotTableFieldContext::onStartElement( const AttributeList& rAttribs )
68 : {
69 0 : if( isRootElement() )
70 0 : mrTableField.importPivotField( rAttribs );
71 0 : }
72 :
73 0 : ContextHandlerRef PivotTableFieldContext::onCreateRecordContext( sal_Int32 nRecId, SequenceInputStream& rStrm )
74 : {
75 0 : switch( getCurrentElement() )
76 : {
77 : case BIFF12_ID_PTFIELD:
78 0 : switch( nRecId )
79 : {
80 0 : case BIFF12_ID_PTFITEMS: return this;
81 0 : case BIFF12_ID_AUTOSORTSCOPE: return this;
82 : }
83 0 : break;
84 : case BIFF12_ID_PTFITEMS:
85 0 : if( nRecId == BIFF12_ID_PTFITEM ) mrTableField.importPTFItem( rStrm );
86 0 : break;
87 : case BIFF12_ID_AUTOSORTSCOPE:
88 0 : if( nRecId == BIFF12_ID_PIVOTAREA ) return this;
89 0 : break;
90 : case BIFF12_ID_PIVOTAREA:
91 0 : if( nRecId == BIFF12_ID_PTREFERENCES ) return this;
92 0 : break;
93 : case BIFF12_ID_PTREFERENCES:
94 0 : if( nRecId == BIFF12_ID_PTREFERENCE ) { mrTableField.importPTReference( rStrm ); return this; }
95 0 : break;
96 : case BIFF12_ID_PTREFERENCE:
97 0 : if( nRecId == BIFF12_ID_PTREFERENCEITEM ) mrTableField.importPTReferenceItem( rStrm );
98 0 : break;
99 : }
100 0 : return 0;
101 : }
102 :
103 0 : void PivotTableFieldContext::onStartRecord( SequenceInputStream& rStrm )
104 : {
105 0 : if( isRootElement() )
106 0 : mrTableField.importPTField( rStrm );
107 0 : }
108 :
109 0 : PivotTableFilterContext::PivotTableFilterContext( WorksheetFragmentBase& rFragment, PivotTableFilter& rTableFilter ) :
110 : WorksheetContextBase( rFragment ),
111 0 : mrTableFilter( rTableFilter )
112 : {
113 0 : }
114 :
115 0 : ContextHandlerRef PivotTableFilterContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs )
116 : {
117 0 : switch( getCurrentElement() )
118 : {
119 : case XLS_TOKEN( filter ):
120 0 : if( nElement == XLS_TOKEN( autoFilter ) ) return this;
121 0 : break;
122 : case XLS_TOKEN( autoFilter ):
123 0 : if( nElement == XLS_TOKEN( filterColumn ) ) return this;
124 0 : break;
125 : case XLS_TOKEN( filterColumn ):
126 0 : if( nElement == XLS_TOKEN( top10 ) ) mrTableFilter.importTop10( rAttribs );
127 0 : break;
128 : }
129 0 : return 0;
130 : }
131 :
132 0 : void PivotTableFilterContext::onStartElement( const AttributeList& rAttribs )
133 : {
134 0 : if( isRootElement() )
135 0 : mrTableFilter.importFilter( rAttribs );
136 0 : }
137 :
138 0 : ContextHandlerRef PivotTableFilterContext::onCreateRecordContext( sal_Int32 nRecId, SequenceInputStream& rStrm )
139 : {
140 0 : switch( getCurrentElement() )
141 : {
142 : case BIFF12_ID_PTFILTER:
143 0 : if( nRecId == BIFF12_ID_AUTOFILTER ) return this;
144 0 : break;
145 : case BIFF12_ID_AUTOFILTER:
146 0 : if( nRecId == BIFF12_ID_FILTERCOLUMN ) return this;
147 0 : break;
148 : case BIFF12_ID_FILTERCOLUMN:
149 0 : if( nRecId == BIFF12_ID_TOP10FILTER ) mrTableFilter.importTop10Filter( rStrm );
150 0 : break;
151 : }
152 0 : return 0;
153 : }
154 :
155 0 : void PivotTableFilterContext::onStartRecord( SequenceInputStream& rStrm )
156 : {
157 0 : if( isRootElement() )
158 0 : mrTableFilter.importPTFilter( rStrm );
159 0 : }
160 :
161 0 : PivotTableFragment::PivotTableFragment( const WorksheetHelper& rHelper, const OUString& rFragmentPath ) :
162 : WorksheetFragmentBase( rHelper, rFragmentPath ),
163 0 : mrPivotTable( getPivotTables().createPivotTable() )
164 : {
165 0 : }
166 :
167 0 : ContextHandlerRef PivotTableFragment::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs )
168 : {
169 0 : switch( getCurrentElement() )
170 : {
171 : case XML_ROOT_CONTEXT:
172 0 : if( nElement == XLS_TOKEN( pivotTableDefinition ) ) { mrPivotTable.importPivotTableDefinition( rAttribs ); return this; }
173 0 : break;
174 :
175 : case XLS_TOKEN( pivotTableDefinition ):
176 0 : switch( nElement )
177 : {
178 0 : case XLS_TOKEN( location ): mrPivotTable.importLocation( rAttribs, getSheetIndex() ); break;
179 0 : case XLS_TOKEN( pivotFields ): return this;
180 0 : case XLS_TOKEN( rowFields ): return this;
181 0 : case XLS_TOKEN( colFields ): return this;
182 0 : case XLS_TOKEN( pageFields ): return this;
183 0 : case XLS_TOKEN( dataFields ): return this;
184 0 : case XLS_TOKEN( filters ): return this;
185 : }
186 0 : break;
187 :
188 : case XLS_TOKEN( pivotFields ):
189 0 : if( nElement == XLS_TOKEN( pivotField ) ) return new PivotTableFieldContext( *this, mrPivotTable.createTableField() );
190 0 : break;
191 : case XLS_TOKEN( rowFields ):
192 0 : if( nElement == XLS_TOKEN( field ) ) mrPivotTable.importRowField( rAttribs );
193 0 : break;
194 : case XLS_TOKEN( colFields ):
195 0 : if( nElement == XLS_TOKEN( field ) ) mrPivotTable.importColField( rAttribs );
196 0 : break;
197 : case XLS_TOKEN( pageFields ):
198 0 : if( nElement == XLS_TOKEN( pageField ) ) mrPivotTable.importPageField( rAttribs );
199 0 : break;
200 : case XLS_TOKEN( dataFields ):
201 0 : if( nElement == XLS_TOKEN( dataField ) ) mrPivotTable.importDataField( rAttribs );
202 0 : break;
203 : case XLS_TOKEN( filters ):
204 0 : if( nElement == XLS_TOKEN( filter ) ) return new PivotTableFilterContext( *this, mrPivotTable.createTableFilter() );
205 0 : break;
206 : }
207 0 : return 0;
208 : }
209 :
210 0 : ContextHandlerRef PivotTableFragment::onCreateRecordContext( sal_Int32 nRecId, SequenceInputStream& rStrm )
211 : {
212 0 : switch( getCurrentElement() )
213 : {
214 : case XML_ROOT_CONTEXT:
215 0 : if( nRecId == BIFF12_ID_PTDEFINITION ) { mrPivotTable.importPTDefinition( rStrm ); return this; }
216 0 : break;
217 :
218 : case BIFF12_ID_PTDEFINITION:
219 0 : switch( nRecId )
220 : {
221 0 : case BIFF12_ID_PTLOCATION: mrPivotTable.importPTLocation( rStrm, getSheetIndex() ); break;
222 0 : case BIFF12_ID_PTFIELDS: return this;
223 0 : case BIFF12_ID_PTROWFIELDS: mrPivotTable.importPTRowFields( rStrm ); break;
224 0 : case BIFF12_ID_PTCOLFIELDS: mrPivotTable.importPTColFields( rStrm ); break;
225 0 : case BIFF12_ID_PTPAGEFIELDS: return this;
226 0 : case BIFF12_ID_PTDATAFIELDS: return this;
227 0 : case BIFF12_ID_PTFILTERS: return this;
228 : }
229 0 : break;
230 :
231 : case BIFF12_ID_PTFIELDS:
232 0 : if( nRecId == BIFF12_ID_PTFIELD ) return new PivotTableFieldContext( *this, mrPivotTable.createTableField() );
233 0 : break;
234 : case BIFF12_ID_PTPAGEFIELDS:
235 0 : if( nRecId == BIFF12_ID_PTPAGEFIELD ) mrPivotTable.importPTPageField( rStrm );
236 0 : break;
237 : case BIFF12_ID_PTDATAFIELDS:
238 0 : if( nRecId == BIFF12_ID_PTDATAFIELD ) mrPivotTable.importPTDataField( rStrm );
239 0 : break;
240 : case BIFF12_ID_PTFILTERS:
241 0 : if( nRecId == BIFF12_ID_PTFILTER ) return new PivotTableFilterContext( *this, mrPivotTable.createTableFilter() );
242 0 : break;
243 : }
244 0 : return 0;
245 : }
246 :
247 0 : const RecordInfo* PivotTableFragment::getRecordInfos() const
248 : {
249 : static const RecordInfo spRecInfos[] =
250 : {
251 : { BIFF12_ID_AUTOFILTER, BIFF12_ID_AUTOFILTER + 1 },
252 : { BIFF12_ID_AUTOSORTSCOPE, BIFF12_ID_AUTOSORTSCOPE + 1 },
253 : { BIFF12_ID_FILTERCOLUMN, BIFF12_ID_FILTERCOLUMN + 1 },
254 : { BIFF12_ID_PIVOTAREA, BIFF12_ID_PIVOTAREA + 1 },
255 : { BIFF12_ID_PTCOLFIELDS, BIFF12_ID_PTCOLFIELDS + 1 },
256 : { BIFF12_ID_PTDATAFIELD, BIFF12_ID_PTDATAFIELD + 1 },
257 : { BIFF12_ID_PTDATAFIELDS, BIFF12_ID_PTDATAFIELDS + 1 },
258 : { BIFF12_ID_PTDEFINITION, BIFF12_ID_PTDEFINITION + 35 },
259 : { BIFF12_ID_PTFIELD, BIFF12_ID_PTFIELD + 1 },
260 : { BIFF12_ID_PTFIELDS, BIFF12_ID_PTFIELDS + 1 },
261 : { BIFF12_ID_PTFILTER, BIFF12_ID_PTFILTER + 1 },
262 : { BIFF12_ID_PTFILTERS, BIFF12_ID_PTFILTERS + 1 },
263 : { BIFF12_ID_PTFITEM, BIFF12_ID_PTFITEM - 1 },
264 : { BIFF12_ID_PTFITEMS, BIFF12_ID_PTFITEMS + 1 },
265 : { BIFF12_ID_PTLOCATION, BIFF12_ID_PTLOCATION - 1 },
266 : { BIFF12_ID_PTPAGEFIELD, BIFF12_ID_PTPAGEFIELD + 1 },
267 : { BIFF12_ID_PTPAGEFIELDS, BIFF12_ID_PTPAGEFIELDS + 1 },
268 : { BIFF12_ID_PTREFERENCE, BIFF12_ID_PTREFERENCE + 1 },
269 : { BIFF12_ID_PTREFERENCEITEM, BIFF12_ID_PTREFERENCEITEM + 1 },
270 : { BIFF12_ID_PTREFERENCES, BIFF12_ID_PTREFERENCES + 1 },
271 : { BIFF12_ID_PTROWFIELDS, BIFF12_ID_PTROWFIELDS + 1 },
272 : { -1, -1 }
273 : };
274 0 : return spRecInfos;
275 : }
276 :
277 : } // namespace xls
278 18 : } // namespace oox
279 :
280 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|