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