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 <autofiltercontext.hxx>
21 #include <biffhelper.hxx>
23 #include <autofilterbuffer.hxx>
24 #include <oox/token/namespaces.hxx>
28 using ::oox::core::ContextHandlerRef
;
30 FilterSettingsContext::FilterSettingsContext( WorksheetContextBase
& rParent
, FilterSettingsBase
& rFilterSettings
) :
31 WorksheetContextBase( rParent
),
32 mrFilterSettings( rFilterSettings
)
36 ContextHandlerRef
FilterSettingsContext::onCreateContext( sal_Int32 nElement
, const AttributeList
& /*rAttribs*/ )
38 switch( getCurrentElement() )
40 case XLS_TOKEN( filters
):
41 if( nElement
== XLS_TOKEN( filter
) ) return this;
43 case XLS_TOKEN( customFilters
):
44 if( nElement
== XLS_TOKEN( customFilter
) ) return this;
50 void FilterSettingsContext::onStartElement( const AttributeList
& rAttribs
)
52 mrFilterSettings
.importAttribs( getCurrentElement(), rAttribs
);
55 ContextHandlerRef
FilterSettingsContext::onCreateRecordContext( sal_Int32 nRecId
, SequenceInputStream
& /*rStrm*/ )
57 switch( getCurrentElement() )
59 case BIFF12_ID_DISCRETEFILTERS
:
60 if( nRecId
== BIFF12_ID_DISCRETEFILTER
) return this;
62 case BIFF12_ID_CUSTOMFILTERS
:
63 if( nRecId
== BIFF12_ID_CUSTOMFILTER
) return this;
69 void FilterSettingsContext::onStartRecord( SequenceInputStream
& rStrm
)
71 mrFilterSettings
.importRecord( getCurrentElement(), rStrm
);
74 FilterColumnContext::FilterColumnContext( WorksheetContextBase
& rParent
, FilterColumn
& rFilterColumn
) :
75 WorksheetContextBase( rParent
),
76 mrFilterColumn( rFilterColumn
)
80 ContextHandlerRef
FilterColumnContext::onCreateContext( sal_Int32 nElement
, const AttributeList
& /*rAttribs*/ )
82 if( getCurrentElement() == XLS_TOKEN( filterColumn
) ) switch( nElement
)
84 case XLS_TOKEN( filters
):
85 return new FilterSettingsContext( *this, mrFilterColumn
.createFilterSettings
< DiscreteFilter
>() );
86 case XLS_TOKEN( top10
):
87 return new FilterSettingsContext( *this, mrFilterColumn
.createFilterSettings
< Top10Filter
>() );
88 case XLS_TOKEN( customFilters
):
89 return new FilterSettingsContext( *this, mrFilterColumn
.createFilterSettings
< CustomFilter
>() );
94 void FilterColumnContext::onStartElement( const AttributeList
& rAttribs
)
96 mrFilterColumn
.importFilterColumn( rAttribs
);
99 ContextHandlerRef
FilterColumnContext::onCreateRecordContext( sal_Int32 nRecId
, SequenceInputStream
& /*rStrm*/ )
101 if( getCurrentElement() == BIFF12_ID_FILTERCOLUMN
) switch( nRecId
)
103 case BIFF12_ID_DISCRETEFILTERS
:
104 return new FilterSettingsContext( *this, mrFilterColumn
.createFilterSettings
< DiscreteFilter
>() );
105 case BIFF12_ID_TOP10FILTER
:
106 return new FilterSettingsContext( *this, mrFilterColumn
.createFilterSettings
< Top10Filter
>() );
107 case BIFF12_ID_CUSTOMFILTERS
:
108 return new FilterSettingsContext( *this, mrFilterColumn
.createFilterSettings
< CustomFilter
>() );
113 void FilterColumnContext::onStartRecord( SequenceInputStream
& rStrm
)
115 mrFilterColumn
.importFilterColumn( rStrm
);
118 // class SortConditionContext
120 SortConditionContext::SortConditionContext( WorksheetContextBase
& rParent
, SortCondition
& rSortCondition
) :
121 WorksheetContextBase( rParent
),
122 mrSortCondition( rSortCondition
)
126 ContextHandlerRef
SortConditionContext::onCreateContext( sal_Int32
, const AttributeList
& )
131 void SortConditionContext::onStartElement( const AttributeList
& rAttribs
)
133 mrSortCondition
.importSortCondition( rAttribs
, getSheetIndex() );
136 ContextHandlerRef
SortConditionContext::onCreateRecordContext( sal_Int32
, SequenceInputStream
& )
141 void SortConditionContext::onStartRecord( SequenceInputStream
& )
145 // class SortStateContext
147 SortStateContext::SortStateContext( WorksheetContextBase
& rParent
, AutoFilter
& rAutoFilter
) :
148 WorksheetContextBase( rParent
),
149 mrAutoFilter( rAutoFilter
)
153 ContextHandlerRef
SortStateContext::onCreateContext( sal_Int32 nElement
, const AttributeList
& /*rAttribs*/ )
155 if( getCurrentElement() == XLS_TOKEN( sortState
) ) switch( nElement
)
157 case XLS_TOKEN( sortCondition
):
158 return new SortConditionContext( *this, mrAutoFilter
.createSortCondition() );
163 void SortStateContext::onStartElement( const AttributeList
& rAttribs
)
165 mrAutoFilter
.importSortState( rAttribs
, getSheetIndex() );
168 ContextHandlerRef
SortStateContext::onCreateRecordContext( sal_Int32
, SequenceInputStream
& )
173 void SortStateContext::onStartRecord( SequenceInputStream
& )
177 AutoFilterContext::AutoFilterContext( WorksheetFragmentBase
& rFragment
, AutoFilter
& rAutoFilter
) :
178 WorksheetContextBase( rFragment
),
179 mrAutoFilter( rAutoFilter
)
183 ContextHandlerRef
AutoFilterContext::onCreateContext( sal_Int32 nElement
, const AttributeList
& /*rAttribs*/ )
185 if( getCurrentElement() == XLS_TOKEN( autoFilter
) ) switch( nElement
)
187 case XLS_TOKEN( sortState
):
188 return new SortStateContext( *this, mrAutoFilter
);
189 case XLS_TOKEN( filterColumn
):
190 return new FilterColumnContext( *this, mrAutoFilter
.createFilterColumn() );
195 void AutoFilterContext::onStartElement( const AttributeList
& rAttribs
)
197 mrAutoFilter
.importAutoFilter( rAttribs
, getSheetIndex() );
200 ContextHandlerRef
AutoFilterContext::onCreateRecordContext( sal_Int32 nRecId
, SequenceInputStream
& /*rStrm*/ )
202 if( (getCurrentElement() == BIFF12_ID_AUTOFILTER
) && (nRecId
== BIFF12_ID_FILTERCOLUMN
) )
203 return new FilterColumnContext( *this, mrAutoFilter
.createFilterColumn() );
207 void AutoFilterContext::onStartRecord( SequenceInputStream
& rStrm
)
209 mrAutoFilter
.importAutoFilter( rStrm
, getSheetIndex() );
212 } // namespace oox::xls
214 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */