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"
22 #include "biffinputstream.hxx"
23 #include "pivottablebuffer.hxx"
24 #include <oox/token/namespaces.hxx>
25 #include <oox/token/tokens.hxx>
30 using namespace ::oox::core
;
32 PivotTableFieldContext::PivotTableFieldContext( WorksheetFragmentBase
& rFragment
, PivotTableField
& rTableField
) :
33 WorksheetContextBase( rFragment
),
34 mrTableField( rTableField
)
38 ContextHandlerRef
PivotTableFieldContext::onCreateContext( sal_Int32 nElement
, const AttributeList
& rAttribs
)
40 switch( getCurrentElement() )
42 case XLS_TOKEN( pivotField
):
45 case XLS_TOKEN( items
): return this;
46 case XLS_TOKEN( autoSortScope
): return this;
49 case XLS_TOKEN( items
):
50 if( nElement
== XLS_TOKEN( item
) ) mrTableField
.importItem( rAttribs
);
52 case XLS_TOKEN( autoSortScope
):
53 if( nElement
== XLS_TOKEN( pivotArea
) ) return this;
55 case XLS_TOKEN( pivotArea
):
56 if( nElement
== XLS_TOKEN( references
) ) return this;
58 case XLS_TOKEN( references
):
59 if( nElement
== XLS_TOKEN( reference
) ) { mrTableField
.importReference( rAttribs
); return this; }
61 case XLS_TOKEN( reference
):
62 if( nElement
== XLS_TOKEN( x
) ) mrTableField
.importReferenceItem( rAttribs
);
68 void PivotTableFieldContext::onStartElement( const AttributeList
& rAttribs
)
71 mrTableField
.importPivotField( rAttribs
);
74 ContextHandlerRef
PivotTableFieldContext::onCreateRecordContext( sal_Int32 nRecId
, SequenceInputStream
& rStrm
)
76 switch( getCurrentElement() )
78 case BIFF12_ID_PTFIELD
:
81 case BIFF12_ID_PTFITEMS
: return this;
82 case BIFF12_ID_AUTOSORTSCOPE
: return this;
85 case BIFF12_ID_PTFITEMS
:
86 if( nRecId
== BIFF12_ID_PTFITEM
) mrTableField
.importPTFItem( rStrm
);
88 case BIFF12_ID_AUTOSORTSCOPE
:
89 if( nRecId
== BIFF12_ID_PIVOTAREA
) return this;
91 case BIFF12_ID_PIVOTAREA
:
92 if( nRecId
== BIFF12_ID_PTREFERENCES
) return this;
94 case BIFF12_ID_PTREFERENCES
:
95 if( nRecId
== BIFF12_ID_PTREFERENCE
) { mrTableField
.importPTReference( rStrm
); return this; }
97 case BIFF12_ID_PTREFERENCE
:
98 if( nRecId
== BIFF12_ID_PTREFERENCEITEM
) mrTableField
.importPTReferenceItem( rStrm
);
104 void PivotTableFieldContext::onStartRecord( SequenceInputStream
& rStrm
)
106 if( isRootElement() )
107 mrTableField
.importPTField( rStrm
);
110 PivotTableFilterContext::PivotTableFilterContext( WorksheetFragmentBase
& rFragment
, PivotTableFilter
& rTableFilter
) :
111 WorksheetContextBase( rFragment
),
112 mrTableFilter( rTableFilter
)
116 ContextHandlerRef
PivotTableFilterContext::onCreateContext( sal_Int32 nElement
, const AttributeList
& rAttribs
)
118 switch( getCurrentElement() )
120 case XLS_TOKEN( filter
):
121 if( nElement
== XLS_TOKEN( autoFilter
) ) return this;
123 case XLS_TOKEN( autoFilter
):
124 if( nElement
== XLS_TOKEN( filterColumn
) ) return this;
126 case XLS_TOKEN( filterColumn
):
127 if( nElement
== XLS_TOKEN( top10
) ) mrTableFilter
.importTop10( rAttribs
);
133 void PivotTableFilterContext::onStartElement( const AttributeList
& rAttribs
)
135 if( isRootElement() )
136 mrTableFilter
.importFilter( rAttribs
);
139 ContextHandlerRef
PivotTableFilterContext::onCreateRecordContext( sal_Int32 nRecId
, SequenceInputStream
& rStrm
)
141 switch( getCurrentElement() )
143 case BIFF12_ID_PTFILTER
:
144 if( nRecId
== BIFF12_ID_AUTOFILTER
) return this;
146 case BIFF12_ID_AUTOFILTER
:
147 if( nRecId
== BIFF12_ID_FILTERCOLUMN
) return this;
149 case BIFF12_ID_FILTERCOLUMN
:
150 if( nRecId
== BIFF12_ID_TOP10FILTER
) mrTableFilter
.importTop10Filter( rStrm
);
156 void PivotTableFilterContext::onStartRecord( SequenceInputStream
& rStrm
)
158 if( isRootElement() )
159 mrTableFilter
.importPTFilter( rStrm
);
162 PivotTableFragment::PivotTableFragment( const WorksheetHelper
& rHelper
, const OUString
& rFragmentPath
) :
163 WorksheetFragmentBase( rHelper
, rFragmentPath
),
164 mrPivotTable( getPivotTables().createPivotTable() )
168 ContextHandlerRef
PivotTableFragment::onCreateContext( sal_Int32 nElement
, const AttributeList
& rAttribs
)
170 switch( getCurrentElement() )
172 case XML_ROOT_CONTEXT
:
173 if( nElement
== XLS_TOKEN( pivotTableDefinition
) ) { mrPivotTable
.importPivotTableDefinition( rAttribs
); return this; }
176 case XLS_TOKEN( pivotTableDefinition
):
179 case XLS_TOKEN( location
): mrPivotTable
.importLocation( rAttribs
, getSheetIndex() ); break;
180 case XLS_TOKEN( pivotFields
): return this;
181 case XLS_TOKEN( rowFields
): return this;
182 case XLS_TOKEN( colFields
): return this;
183 case XLS_TOKEN( pageFields
): return this;
184 case XLS_TOKEN( dataFields
): return this;
185 case XLS_TOKEN( filters
): return this;
189 case XLS_TOKEN( pivotFields
):
190 if( nElement
== XLS_TOKEN( pivotField
) ) return new PivotTableFieldContext( *this, mrPivotTable
.createTableField() );
192 case XLS_TOKEN( rowFields
):
193 if( nElement
== XLS_TOKEN( field
) ) mrPivotTable
.importRowField( rAttribs
);
195 case XLS_TOKEN( colFields
):
196 if( nElement
== XLS_TOKEN( field
) ) mrPivotTable
.importColField( rAttribs
);
198 case XLS_TOKEN( pageFields
):
199 if( nElement
== XLS_TOKEN( pageField
) ) mrPivotTable
.importPageField( rAttribs
);
201 case XLS_TOKEN( dataFields
):
202 if( nElement
== XLS_TOKEN( dataField
) ) mrPivotTable
.importDataField( rAttribs
);
204 case XLS_TOKEN( filters
):
205 if( nElement
== XLS_TOKEN( filter
) ) return new PivotTableFilterContext( *this, mrPivotTable
.createTableFilter() );
211 ContextHandlerRef
PivotTableFragment::onCreateRecordContext( sal_Int32 nRecId
, SequenceInputStream
& rStrm
)
213 switch( getCurrentElement() )
215 case XML_ROOT_CONTEXT
:
216 if( nRecId
== BIFF12_ID_PTDEFINITION
) { mrPivotTable
.importPTDefinition( rStrm
); return this; }
219 case BIFF12_ID_PTDEFINITION
:
222 case BIFF12_ID_PTLOCATION
: mrPivotTable
.importPTLocation( rStrm
, getSheetIndex() ); break;
223 case BIFF12_ID_PTFIELDS
: return this;
224 case BIFF12_ID_PTROWFIELDS
: mrPivotTable
.importPTRowFields( rStrm
); break;
225 case BIFF12_ID_PTCOLFIELDS
: mrPivotTable
.importPTColFields( rStrm
); break;
226 case BIFF12_ID_PTPAGEFIELDS
: return this;
227 case BIFF12_ID_PTDATAFIELDS
: return this;
228 case BIFF12_ID_PTFILTERS
: return this;
232 case BIFF12_ID_PTFIELDS
:
233 if( nRecId
== BIFF12_ID_PTFIELD
) return new PivotTableFieldContext( *this, mrPivotTable
.createTableField() );
235 case BIFF12_ID_PTPAGEFIELDS
:
236 if( nRecId
== BIFF12_ID_PTPAGEFIELD
) mrPivotTable
.importPTPageField( rStrm
);
238 case BIFF12_ID_PTDATAFIELDS
:
239 if( nRecId
== BIFF12_ID_PTDATAFIELD
) mrPivotTable
.importPTDataField( rStrm
);
241 case BIFF12_ID_PTFILTERS
:
242 if( nRecId
== BIFF12_ID_PTFILTER
) return new PivotTableFilterContext( *this, mrPivotTable
.createTableFilter() );
248 const RecordInfo
* PivotTableFragment::getRecordInfos() const
250 static const RecordInfo spRecInfos
[] =
252 { BIFF12_ID_AUTOFILTER
, BIFF12_ID_AUTOFILTER
+ 1 },
253 { BIFF12_ID_AUTOSORTSCOPE
, BIFF12_ID_AUTOSORTSCOPE
+ 1 },
254 { BIFF12_ID_FILTERCOLUMN
, BIFF12_ID_FILTERCOLUMN
+ 1 },
255 { BIFF12_ID_PIVOTAREA
, BIFF12_ID_PIVOTAREA
+ 1 },
256 { BIFF12_ID_PTCOLFIELDS
, BIFF12_ID_PTCOLFIELDS
+ 1 },
257 { BIFF12_ID_PTDATAFIELD
, BIFF12_ID_PTDATAFIELD
+ 1 },
258 { BIFF12_ID_PTDATAFIELDS
, BIFF12_ID_PTDATAFIELDS
+ 1 },
259 { BIFF12_ID_PTDEFINITION
, BIFF12_ID_PTDEFINITION
+ 35 },
260 { BIFF12_ID_PTFIELD
, BIFF12_ID_PTFIELD
+ 1 },
261 { BIFF12_ID_PTFIELDS
, BIFF12_ID_PTFIELDS
+ 1 },
262 { BIFF12_ID_PTFILTER
, BIFF12_ID_PTFILTER
+ 1 },
263 { BIFF12_ID_PTFILTERS
, BIFF12_ID_PTFILTERS
+ 1 },
264 { BIFF12_ID_PTFITEM
, BIFF12_ID_PTFITEM
- 1 },
265 { BIFF12_ID_PTFITEMS
, BIFF12_ID_PTFITEMS
+ 1 },
266 { BIFF12_ID_PTLOCATION
, BIFF12_ID_PTLOCATION
- 1 },
267 { BIFF12_ID_PTPAGEFIELD
, BIFF12_ID_PTPAGEFIELD
+ 1 },
268 { BIFF12_ID_PTPAGEFIELDS
, BIFF12_ID_PTPAGEFIELDS
+ 1 },
269 { BIFF12_ID_PTREFERENCE
, BIFF12_ID_PTREFERENCE
+ 1 },
270 { BIFF12_ID_PTREFERENCEITEM
, BIFF12_ID_PTREFERENCEITEM
+ 1 },
271 { BIFF12_ID_PTREFERENCES
, BIFF12_ID_PTREFERENCES
+ 1 },
272 { BIFF12_ID_PTROWFIELDS
, BIFF12_ID_PTROWFIELDS
+ 1 },
281 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */