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 "autofiltercontext.hxx"
21 :
22 : #include "autofilterbuffer.hxx"
23 : #include "biffinputstream.hxx"
24 :
25 : namespace oox {
26 : namespace xls {
27 :
28 : using ::oox::core::ContextHandlerRef;
29 :
30 1 : FilterSettingsContext::FilterSettingsContext( WorksheetContextBase& rParent, FilterSettingsBase& rFilterSettings ) :
31 : WorksheetContextBase( rParent ),
32 1 : mrFilterSettings( rFilterSettings )
33 : {
34 1 : }
35 :
36 1 : ContextHandlerRef FilterSettingsContext::onCreateContext( sal_Int32 nElement, const AttributeList& /*rAttribs*/ )
37 : {
38 1 : switch( getCurrentElement() )
39 : {
40 : case XLS_TOKEN( filters ):
41 0 : if( nElement == XLS_TOKEN( filter ) ) return this;
42 0 : break;
43 : case XLS_TOKEN( customFilters ):
44 1 : if( nElement == XLS_TOKEN( customFilter ) ) return this;
45 0 : break;
46 : }
47 0 : return 0;
48 : }
49 :
50 2 : void FilterSettingsContext::onStartElement( const AttributeList& rAttribs )
51 : {
52 2 : mrFilterSettings.importAttribs( getCurrentElement(), rAttribs );
53 2 : }
54 :
55 0 : ContextHandlerRef FilterSettingsContext::onCreateRecordContext( sal_Int32 nRecId, SequenceInputStream& /*rStrm*/ )
56 : {
57 0 : switch( getCurrentElement() )
58 : {
59 : case BIFF12_ID_DISCRETEFILTERS:
60 0 : if( nRecId == BIFF12_ID_DISCRETEFILTER ) return this;
61 0 : break;
62 : case BIFF12_ID_CUSTOMFILTERS:
63 0 : if( nRecId == BIFF12_ID_CUSTOMFILTER ) return this;
64 0 : break;
65 : }
66 0 : return 0;
67 : }
68 :
69 0 : void FilterSettingsContext::onStartRecord( SequenceInputStream& rStrm )
70 : {
71 0 : mrFilterSettings.importRecord( getCurrentElement(), rStrm );
72 0 : }
73 :
74 1 : FilterColumnContext::FilterColumnContext( WorksheetContextBase& rParent, FilterColumn& rFilterColumn ) :
75 : WorksheetContextBase( rParent ),
76 1 : mrFilterColumn( rFilterColumn )
77 : {
78 1 : }
79 :
80 1 : ContextHandlerRef FilterColumnContext::onCreateContext( sal_Int32 nElement, const AttributeList& /*rAttribs*/ )
81 : {
82 1 : if( getCurrentElement() == XLS_TOKEN( filterColumn ) ) switch( nElement )
83 : {
84 : case XLS_TOKEN( filters ):
85 0 : return new FilterSettingsContext( *this, mrFilterColumn.createFilterSettings< DiscreteFilter >() );
86 : case XLS_TOKEN( top10 ):
87 0 : return new FilterSettingsContext( *this, mrFilterColumn.createFilterSettings< Top10Filter >() );
88 : case XLS_TOKEN( customFilters ):
89 1 : return new FilterSettingsContext( *this, mrFilterColumn.createFilterSettings< CustomFilter >() );
90 : }
91 0 : return 0;
92 : }
93 :
94 1 : void FilterColumnContext::onStartElement( const AttributeList& rAttribs )
95 : {
96 1 : mrFilterColumn.importFilterColumn( rAttribs );
97 1 : }
98 :
99 0 : ContextHandlerRef FilterColumnContext::onCreateRecordContext( sal_Int32 nRecId, SequenceInputStream& /*rStrm*/ )
100 : {
101 0 : if( getCurrentElement() == BIFF12_ID_FILTERCOLUMN ) switch( nRecId )
102 : {
103 : case BIFF12_ID_DISCRETEFILTERS:
104 0 : return new FilterSettingsContext( *this, mrFilterColumn.createFilterSettings< DiscreteFilter >() );
105 : case BIFF12_ID_TOP10FILTER:
106 0 : return new FilterSettingsContext( *this, mrFilterColumn.createFilterSettings< Top10Filter >() );
107 : case BIFF12_ID_CUSTOMFILTERS:
108 0 : return new FilterSettingsContext( *this, mrFilterColumn.createFilterSettings< CustomFilter >() );
109 : }
110 0 : return 0;
111 : }
112 :
113 0 : void FilterColumnContext::onStartRecord( SequenceInputStream& rStrm )
114 : {
115 0 : mrFilterColumn.importFilterColumn( rStrm );
116 0 : }
117 :
118 1 : AutoFilterContext::AutoFilterContext( WorksheetFragmentBase& rFragment, AutoFilter& rAutoFilter ) :
119 : WorksheetContextBase( rFragment ),
120 1 : mrAutoFilter( rAutoFilter )
121 : {
122 1 : }
123 :
124 1 : ContextHandlerRef AutoFilterContext::onCreateContext( sal_Int32 nElement, const AttributeList& /*rAttribs*/ )
125 : {
126 1 : if( (getCurrentElement() == XLS_TOKEN( autoFilter )) && (nElement == XLS_TOKEN( filterColumn )) )
127 1 : return new FilterColumnContext( *this, mrAutoFilter.createFilterColumn() );
128 0 : return 0;
129 : }
130 :
131 1 : void AutoFilterContext::onStartElement( const AttributeList& rAttribs )
132 : {
133 1 : mrAutoFilter.importAutoFilter( rAttribs, getSheetIndex() );
134 1 : }
135 :
136 0 : ContextHandlerRef AutoFilterContext::onCreateRecordContext( sal_Int32 nRecId, SequenceInputStream& /*rStrm*/ )
137 : {
138 0 : if( (getCurrentElement() == BIFF12_ID_AUTOFILTER) && (nRecId == BIFF12_ID_FILTERCOLUMN) )
139 0 : return new FilterColumnContext( *this, mrAutoFilter.createFilterColumn() );
140 0 : return 0;
141 : }
142 :
143 0 : void AutoFilterContext::onStartRecord( SequenceInputStream& rStrm )
144 : {
145 0 : mrAutoFilter.importAutoFilter( rStrm, getSheetIndex() );
146 0 : }
147 :
148 : } // namespace xls
149 18 : } // namespace oox
150 :
151 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|