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