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