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 : #ifndef OOX_XLS_AUTOFILTERBUFFER_HXX
21 : #define OOX_XLS_AUTOFILTERBUFFER_HXX
22 :
23 : #include <com/sun/star/table/CellRangeAddress.hpp>
24 : #include "oox/helper/refvector.hxx"
25 : #include "workbookhelper.hxx"
26 :
27 : namespace com { namespace sun { namespace star {
28 : namespace sheet { struct TableFilterField3; }
29 : namespace sheet { class XDatabaseRange; }
30 : namespace sheet { class XSheetFilterDescriptor3; }
31 : } } }
32 :
33 : namespace oox {
34 : namespace xls {
35 :
36 : // ============================================================================
37 :
38 : /** Contains UNO API filter settings for a column in a filtered range. */
39 3 : struct ApiFilterSettings
40 : {
41 : typedef ::std::vector<com::sun::star::sheet::TableFilterField3> FilterFieldVector;
42 :
43 : FilterFieldVector maFilterFields; /// List of UNO API filter settings.
44 : OptValue< bool > mobNeedsRegExp; /// If set, requires regular expressions to be enabled/disabled.
45 :
46 : explicit ApiFilterSettings();
47 :
48 : void appendField( bool bAnd, sal_Int32 nOperator, double fValue );
49 : void appendField( bool bAnd, sal_Int32 nOperator, const OUString& rValue );
50 : void appendField( bool bAnd, const std::vector<OUString>& rValues );
51 : };
52 :
53 : // ============================================================================
54 :
55 : /** Base class for specific filter settings for a column in a filtered range.
56 : */
57 1 : class FilterSettingsBase : public WorkbookHelper
58 : {
59 : public:
60 : explicit FilterSettingsBase( const WorkbookHelper& rHelper );
61 :
62 : /** Derived classes import filter settings from the passed attribute list. */
63 : virtual void importAttribs( sal_Int32 nElement, const AttributeList& rAttribs );
64 : /** Derived classes import filter settings from the passed record. */
65 : virtual void importRecord( sal_Int32 nRecId, SequenceInputStream& rStrm );
66 :
67 : /** Derived classes return converted UNO API filter settings representing all filter settings. */
68 : virtual ApiFilterSettings finalizeImport( sal_Int32 nMaxCount );
69 : };
70 :
71 : typedef ::boost::shared_ptr< FilterSettingsBase > FilterSettingsRef;
72 :
73 : // ============================================================================
74 :
75 : /** Settings for a discrete filter, specifying a list of values to be shown in
76 : the filtered range.
77 : */
78 0 : class DiscreteFilter : public FilterSettingsBase
79 : {
80 : public:
81 : explicit DiscreteFilter( const WorkbookHelper& rHelper );
82 :
83 : /** Imports filter settings from the filters and filter elements. */
84 : virtual void importAttribs( sal_Int32 nElement, const AttributeList& rAttribs );
85 : /** Imports filter settings from the FILTERS and FILTER records. */
86 : virtual void importRecord( sal_Int32 nRecId, SequenceInputStream& rStrm );
87 :
88 : /** Returns converted UNO API filter settings representing all filter settings. */
89 : virtual ApiFilterSettings finalizeImport( sal_Int32 nMaxCount );
90 :
91 : private:
92 : typedef ::std::vector< OUString > FilterValueVector;
93 :
94 : FilterValueVector maValues;
95 : sal_Int32 mnCalendarType;
96 : bool mbShowBlank;
97 : };
98 :
99 : // ============================================================================
100 :
101 : /** Settings for a top-10 filter. */
102 0 : class Top10Filter : public FilterSettingsBase
103 : {
104 : public:
105 : explicit Top10Filter( const WorkbookHelper& rHelper );
106 :
107 : /** Imports filter settings from the filters and filter elements. */
108 : virtual void importAttribs( sal_Int32 nElement, const AttributeList& rAttribs );
109 : /** Imports filter settings from the FILTERS and FILTER records. */
110 : virtual void importRecord( sal_Int32 nRecId, SequenceInputStream& rStrm );
111 :
112 : /** Returns converted UNO API filter settings representing all filter settings. */
113 : virtual ApiFilterSettings finalizeImport( sal_Int32 nMaxCount );
114 :
115 : private:
116 : double mfValue; /// Number of items or percentage.
117 : bool mbTop; /// True = show top (greatest) items/percentage.
118 : bool mbPercent; /// True = percentage, false = number of items.
119 : };
120 :
121 : // ============================================================================
122 :
123 : /** A filter criterion for a custom filter. */
124 3 : struct FilterCriterionModel
125 : {
126 : ::com::sun::star::uno::Any maValue; /// Comparison operand.
127 : sal_Int32 mnOperator; /// Comparison operator.
128 : sal_uInt8 mnDataType; /// Operand data type (BIFF only).
129 : sal_uInt8 mnStrLen; /// Length of string operand (BIFF5-BIFF8 only).
130 :
131 : explicit FilterCriterionModel();
132 :
133 : /** Sets the passed BIFF operator constant. */
134 : void setBiffOperator( sal_uInt8 nOperator );
135 :
136 : /** Imports the criterion model from the passed BIFF12 stream. */
137 : void readBiffData( SequenceInputStream& rStrm );
138 : };
139 :
140 : // ----------------------------------------------------------------------------
141 :
142 : /** Settings for a custom filter, specifying one or two comparison operators
143 : associated with some values.
144 : */
145 2 : class CustomFilter : public FilterSettingsBase
146 : {
147 : public:
148 : explicit CustomFilter( const WorkbookHelper& rHelper );
149 :
150 : /** Imports filter settings from the filters and filter elements. */
151 : virtual void importAttribs( sal_Int32 nElement, const AttributeList& rAttribs );
152 : /** Imports filter settings from the FILTERS and FILTER records. */
153 : virtual void importRecord( sal_Int32 nRecId, SequenceInputStream& rStrm );
154 :
155 : /** Returns converted UNO API filter settings representing all filter settings. */
156 : virtual ApiFilterSettings finalizeImport( sal_Int32 nMaxCount );
157 :
158 : private:
159 : /** Apeends the passed filter criteriom, if it contains valid settings. */
160 : void appendCriterion( const FilterCriterionModel& rCriterion );
161 :
162 : private:
163 : typedef ::std::vector< FilterCriterionModel > FilterCriterionVector;
164 :
165 : FilterCriterionVector maCriteria;
166 : bool mbAnd;
167 : };
168 :
169 : // ============================================================================
170 :
171 : /** A column in a filtered range. Contains an object with specific filter
172 : settings for the cells in the column.
173 : */
174 2 : class FilterColumn : public WorkbookHelper
175 : {
176 : public:
177 : explicit FilterColumn( const WorkbookHelper& rHelper );
178 :
179 : /** Imports auto filter column settings from the filterColumn element. */
180 : void importFilterColumn( const AttributeList& rAttribs );
181 : /** Imports auto filter column settings from the FILTERCOLUMN record. */
182 : void importFilterColumn( SequenceInputStream& rStrm );
183 :
184 : /** Creates and returns the specified filter settings object. */
185 : template< typename FilterSettingsType >
186 1 : inline FilterSettingsBase& createFilterSettings()
187 1 : { mxSettings.reset( new FilterSettingsType( *this ) ); return *mxSettings; }
188 :
189 : /** Returns the index of the column in the filtered range this object is related to. */
190 : inline sal_Int32 getColumnId() const { return mnColId; }
191 :
192 : /** Returns converted UNO API filter settings representing all filter
193 : settings of this column. */
194 : ApiFilterSettings finalizeImport( sal_Int32 nMaxCount );
195 :
196 : private:
197 : FilterSettingsRef mxSettings;
198 : sal_Int32 mnColId;
199 : bool mbHiddenButton;
200 : bool mbShowButton;
201 : };
202 :
203 : // ============================================================================
204 :
205 2 : class AutoFilter : public WorkbookHelper
206 : {
207 : public:
208 : explicit AutoFilter( const WorkbookHelper& rHelper );
209 :
210 : /** Imports auto filter settings from the autoFilter element. */
211 : void importAutoFilter( const AttributeList& rAttribs, sal_Int16 nSheet );
212 : /** Imports auto filter settings from the AUTOFILTER record. */
213 : void importAutoFilter( SequenceInputStream& rStrm, sal_Int16 nSheet );
214 :
215 : /** Creates a new auto filter column and stores it internally. */
216 : FilterColumn& createFilterColumn();
217 :
218 : /** Applies the filter to the passed filter descriptor. */
219 : void finalizeImport(
220 : const ::com::sun::star::uno::Reference<
221 : ::com::sun::star::sheet::XSheetFilterDescriptor3>& rxFilterDesc );
222 :
223 : private:
224 : typedef RefVector< FilterColumn > FilterColumnVector;
225 :
226 : FilterColumnVector maFilterColumns;
227 : ::com::sun::star::table::CellRangeAddress maRange;
228 : };
229 :
230 : // ============================================================================
231 :
232 43 : class AutoFilterBuffer : public WorkbookHelper
233 : {
234 : public:
235 : explicit AutoFilterBuffer( const WorkbookHelper& rHelper );
236 :
237 : /** Creates a new auto filter and stores it internally. */
238 : AutoFilter& createAutoFilter();
239 :
240 : /** Applies filter settings to a new database range object (used for sheet
241 : autofilter or advanced filter as specified by built-in defined names). */
242 : void finalizeImport( sal_Int16 nSheet );
243 :
244 : /** Applies the filters to the passed database range object.
245 : @return True = this buffer contains valid auto filter settings. */
246 : bool finalizeImport( const ::com::sun::star::uno::Reference< ::com::sun::star::sheet::XDatabaseRange >& rxDatabaseRange );
247 :
248 : private:
249 : /** Returns the auto filter object used to perform auto filtering. */
250 : AutoFilter* getActiveAutoFilter();
251 :
252 : private:
253 : typedef RefVector< AutoFilter > AutoFilterVector;
254 : AutoFilterVector maAutoFilters;
255 : };
256 :
257 : // ============================================================================
258 :
259 : } // namespace xls
260 : } // namespace oox
261 :
262 : #endif
263 :
264 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|