1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <pivottablefragment.hxx>
21 #include <pivottablebuffer.hxx>
22 #include <biffhelper.hxx>
23 #include <oox/token/namespaces.hxx>
28 using namespace ::oox::core
;
30 PivotTableFieldContext::PivotTableFieldContext( WorksheetFragmentBase
& rFragment
, PivotTableField
& rTableField
) :
31 WorksheetContextBase( rFragment
),
32 mrTableField( rTableField
)
36 ContextHandlerRef
PivotTableFieldContext::onCreateContext( sal_Int32 nElement
, const AttributeList
& rAttribs
)
38 switch( getCurrentElement() )
40 case XLS_TOKEN( pivotField
):
43 case XLS_TOKEN( items
): return this;
44 case XLS_TOKEN( autoSortScope
): return this;
47 case XLS_TOKEN( items
):
48 if( nElement
== XLS_TOKEN( item
) ) mrTableField
.importItem( rAttribs
);
50 case XLS_TOKEN( autoSortScope
):
51 if( nElement
== XLS_TOKEN( pivotArea
) ) return this;
53 case XLS_TOKEN( pivotArea
):
54 if( nElement
== XLS_TOKEN( references
) ) return this;
56 case XLS_TOKEN( references
):
57 if( nElement
== XLS_TOKEN( reference
) ) { mrTableField
.importReference( rAttribs
); return this; }
59 case XLS_TOKEN( reference
):
60 if( nElement
== XLS_TOKEN( x
) ) mrTableField
.importReferenceItem( rAttribs
);
66 void PivotTableFieldContext::onStartElement( const AttributeList
& rAttribs
)
69 mrTableField
.importPivotField( rAttribs
);
72 ContextHandlerRef
PivotTableFieldContext::onCreateRecordContext( sal_Int32 nRecId
, SequenceInputStream
& rStrm
)
74 switch( getCurrentElement() )
76 case BIFF12_ID_PTFIELD
:
79 case BIFF12_ID_PTFITEMS
: return this;
80 case BIFF12_ID_AUTOSORTSCOPE
: return this;
83 case BIFF12_ID_PTFITEMS
:
84 if( nRecId
== BIFF12_ID_PTFITEM
) mrTableField
.importPTFItem( rStrm
);
86 case BIFF12_ID_AUTOSORTSCOPE
:
87 if( nRecId
== BIFF12_ID_PIVOTAREA
) return this;
89 case BIFF12_ID_PIVOTAREA
:
90 if( nRecId
== BIFF12_ID_PTREFERENCES
) return this;
92 case BIFF12_ID_PTREFERENCES
:
93 if( nRecId
== BIFF12_ID_PTREFERENCE
) { mrTableField
.importPTReference( rStrm
); return this; }
95 case BIFF12_ID_PTREFERENCE
:
96 if( nRecId
== BIFF12_ID_PTREFERENCEITEM
) mrTableField
.importPTReferenceItem( rStrm
);
102 void PivotTableFieldContext::onStartRecord( SequenceInputStream
& rStrm
)
104 if( isRootElement() )
105 mrTableField
.importPTField( rStrm
);
108 PivotTableFilterContext::PivotTableFilterContext( WorksheetFragmentBase
& rFragment
, PivotTableFilter
& rTableFilter
) :
109 WorksheetContextBase( rFragment
),
110 mrTableFilter( rTableFilter
)
114 ContextHandlerRef
PivotTableFilterContext::onCreateContext( sal_Int32 nElement
, const AttributeList
& rAttribs
)
116 switch( getCurrentElement() )
118 case XLS_TOKEN( filter
):
119 if( nElement
== XLS_TOKEN( autoFilter
) ) return this;
121 case XLS_TOKEN( autoFilter
):
122 if( nElement
== XLS_TOKEN( filterColumn
) ) return this;
124 case XLS_TOKEN( filterColumn
):
125 if( nElement
== XLS_TOKEN( top10
) ) mrTableFilter
.importTop10( rAttribs
);
131 void PivotTableFilterContext::onStartElement( const AttributeList
& rAttribs
)
133 if( isRootElement() )
134 mrTableFilter
.importFilter( rAttribs
);
137 ContextHandlerRef
PivotTableFilterContext::onCreateRecordContext( sal_Int32 nRecId
, SequenceInputStream
& rStrm
)
139 switch( getCurrentElement() )
141 case BIFF12_ID_PTFILTER
:
142 if( nRecId
== BIFF12_ID_AUTOFILTER
) return this;
144 case BIFF12_ID_AUTOFILTER
:
145 if( nRecId
== BIFF12_ID_FILTERCOLUMN
) return this;
147 case BIFF12_ID_FILTERCOLUMN
:
148 if( nRecId
== BIFF12_ID_TOP10FILTER
) mrTableFilter
.importTop10Filter( rStrm
);
154 void PivotTableFilterContext::onStartRecord( SequenceInputStream
& rStrm
)
156 if( isRootElement() )
157 mrTableFilter
.importPTFilter( rStrm
);
160 PivotTableFragment::PivotTableFragment( const WorksheetHelper
& rHelper
, const OUString
& rFragmentPath
) :
161 WorksheetFragmentBase( rHelper
, rFragmentPath
),
162 mrPivotTable( getPivotTables().createPivotTable() )
166 ContextHandlerRef
PivotTableFragment::onCreateContext( sal_Int32 nElement
, const AttributeList
& rAttribs
)
168 switch( getCurrentElement() )
170 case XML_ROOT_CONTEXT
:
171 if( nElement
== XLS_TOKEN( pivotTableDefinition
) ) { mrPivotTable
.importPivotTableDefinition( rAttribs
); return this; }
174 case XLS_TOKEN( pivotTableDefinition
):
177 case XLS_TOKEN( location
): mrPivotTable
.importLocation( rAttribs
, getSheetIndex() ); break;
178 case XLS_TOKEN( pivotFields
): return this;
179 case XLS_TOKEN( rowFields
): return this;
180 case XLS_TOKEN( colFields
): return this;
181 case XLS_TOKEN( pageFields
): return this;
182 case XLS_TOKEN( dataFields
): return this;
183 case XLS_TOKEN( filters
): return this;
184 case XLS_TOKEN(pivotTableStyleInfo
):
185 mrPivotTable
.putToInteropGrabBag("pivotTableStyleInfo", rAttribs
);
190 case XLS_TOKEN( pivotFields
):
191 if( nElement
== XLS_TOKEN( pivotField
) ) return new PivotTableFieldContext( *this, mrPivotTable
.createTableField() );
193 case XLS_TOKEN( rowFields
):
194 if( nElement
== XLS_TOKEN( field
) ) mrPivotTable
.importRowField( rAttribs
);
196 case XLS_TOKEN( colFields
):
197 if( nElement
== XLS_TOKEN( field
) ) mrPivotTable
.importColField( rAttribs
);
199 case XLS_TOKEN( pageFields
):
200 if( nElement
== XLS_TOKEN( pageField
) ) mrPivotTable
.importPageField( rAttribs
);
202 case XLS_TOKEN( dataFields
):
203 if( nElement
== XLS_TOKEN( dataField
) ) mrPivotTable
.importDataField( rAttribs
);
205 case XLS_TOKEN( filters
):
206 if( nElement
== XLS_TOKEN( filter
) ) return new PivotTableFilterContext( *this, mrPivotTable
.createTableFilter() );
212 ContextHandlerRef
PivotTableFragment::onCreateRecordContext( sal_Int32 nRecId
, SequenceInputStream
& rStrm
)
214 switch( getCurrentElement() )
216 case XML_ROOT_CONTEXT
:
217 if( nRecId
== BIFF12_ID_PTDEFINITION
) { mrPivotTable
.importPTDefinition( rStrm
); return this; }
220 case BIFF12_ID_PTDEFINITION
:
223 case BIFF12_ID_PTLOCATION
: mrPivotTable
.importPTLocation( rStrm
, getSheetIndex() ); break;
224 case BIFF12_ID_PTFIELDS
: return this;
225 case BIFF12_ID_PTROWFIELDS
: mrPivotTable
.importPTRowFields( rStrm
); break;
226 case BIFF12_ID_PTCOLFIELDS
: mrPivotTable
.importPTColFields( rStrm
); break;
227 case BIFF12_ID_PTPAGEFIELDS
: return this;
228 case BIFF12_ID_PTDATAFIELDS
: return this;
229 case BIFF12_ID_PTFILTERS
: return this;
233 case BIFF12_ID_PTFIELDS
:
234 if( nRecId
== BIFF12_ID_PTFIELD
) return new PivotTableFieldContext( *this, mrPivotTable
.createTableField() );
236 case BIFF12_ID_PTPAGEFIELDS
:
237 if( nRecId
== BIFF12_ID_PTPAGEFIELD
) mrPivotTable
.importPTPageField( rStrm
);
239 case BIFF12_ID_PTDATAFIELDS
:
240 if( nRecId
== BIFF12_ID_PTDATAFIELD
) mrPivotTable
.importPTDataField( rStrm
);
242 case BIFF12_ID_PTFILTERS
:
243 if( nRecId
== BIFF12_ID_PTFILTER
) return new PivotTableFilterContext( *this, mrPivotTable
.createTableFilter() );
249 const RecordInfo
* PivotTableFragment::getRecordInfos() const
251 static const RecordInfo spRecInfos
[] =
253 { BIFF12_ID_AUTOFILTER
, BIFF12_ID_AUTOFILTER
+ 1 },
254 { BIFF12_ID_AUTOSORTSCOPE
, BIFF12_ID_AUTOSORTSCOPE
+ 1 },
255 { BIFF12_ID_FILTERCOLUMN
, BIFF12_ID_FILTERCOLUMN
+ 1 },
256 { BIFF12_ID_PIVOTAREA
, BIFF12_ID_PIVOTAREA
+ 1 },
257 { BIFF12_ID_PTCOLFIELDS
, BIFF12_ID_PTCOLFIELDS
+ 1 },
258 { BIFF12_ID_PTDATAFIELD
, BIFF12_ID_PTDATAFIELD
+ 1 },
259 { BIFF12_ID_PTDATAFIELDS
, BIFF12_ID_PTDATAFIELDS
+ 1 },
260 { BIFF12_ID_PTDEFINITION
, BIFF12_ID_PTDEFINITION
+ 35 },
261 { BIFF12_ID_PTFIELD
, BIFF12_ID_PTFIELD
+ 1 },
262 { BIFF12_ID_PTFIELDS
, BIFF12_ID_PTFIELDS
+ 1 },
263 { BIFF12_ID_PTFILTER
, BIFF12_ID_PTFILTER
+ 1 },
264 { BIFF12_ID_PTFILTERS
, BIFF12_ID_PTFILTERS
+ 1 },
265 { BIFF12_ID_PTFITEM
, BIFF12_ID_PTFITEM
- 1 },
266 { BIFF12_ID_PTFITEMS
, BIFF12_ID_PTFITEMS
+ 1 },
267 { BIFF12_ID_PTLOCATION
, BIFF12_ID_PTLOCATION
- 1 },
268 { BIFF12_ID_PTPAGEFIELD
, BIFF12_ID_PTPAGEFIELD
+ 1 },
269 { BIFF12_ID_PTPAGEFIELDS
, BIFF12_ID_PTPAGEFIELDS
+ 1 },
270 { BIFF12_ID_PTREFERENCE
, BIFF12_ID_PTREFERENCE
+ 1 },
271 { BIFF12_ID_PTREFERENCEITEM
, BIFF12_ID_PTREFERENCEITEM
+ 1 },
272 { BIFF12_ID_PTREFERENCES
, BIFF12_ID_PTREFERENCES
+ 1 },
273 { BIFF12_ID_PTROWFIELDS
, BIFF12_ID_PTROWFIELDS
+ 1 },
282 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */