xref: /trunk/main/sc/source/filter/inc/xlpivot.hxx (revision fd04a84d)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef SC_XLPIVOT_HXX
25 #define SC_XLPIVOT_HXX
26 
27 #include <com/sun/star/sheet/GeneralFunction.hpp>
28 #include <com/sun/star/sheet/DataPilotFieldOrientation.hpp>
29 #include <com/sun/star/sheet/DataPilotFieldSortMode.hpp>
30 #include <com/sun/star/sheet/DataPilotFieldShowItemsMode.hpp>
31 #include <com/sun/star/sheet/DataPilotFieldLayoutMode.hpp>
32 #include <com/sun/star/sheet/DataPilotFieldReferenceType.hpp>
33 #include <com/sun/star/sheet/DataPilotFieldReferenceItemType.hpp>
34 #include <tools/datetime.hxx>
35 #include "ftools.hxx"
36 #include "xladdress.hxx"
37 #include "dpobject.hxx"
38 
39 #include <memory>
40 
41 class XclImpStream;
42 class XclExpStream;
43 
44 // Constants and Enumerations =================================================
45 
46 // misc -----------------------------------------------------------------------
47 
48 #define EXC_STORAGE_PTCACHE         CREATE_STRING( "_SX_DB_CUR" )
49 
50 // strings
51 const sal_uInt16 EXC_PT_NOSTRING            = 0xFFFF;
52 const sal_uInt16 EXC_PT_MAXSTRLEN           = 0xFFFE;
53 
54 // pivot cache fields
55 const size_t EXC_PC_MAXFIELDCOUNT           = 0xFFFE;
56 const sal_uInt16 EXC_PC_NOFIELD             = 0xFFFF;
57 const xub_StrLen EXC_PC_MAXSTRLEN           = 255;
58 
59 // pivot cache items
60 const size_t EXC_PC_MAXITEMCOUNT            = 32500;
61 const sal_uInt16 EXC_PC_NOITEM              = 0xFFFF;
62 
63 // pivot table fields
64 const sal_uInt16 EXC_PT_MAXFIELDCOUNT       = 0xFFFE;
65 const sal_uInt16 EXC_PT_MAXROWCOLCOUNT      = EXC_PT_MAXFIELDCOUNT;
66 const sal_uInt16 EXC_PT_MAXPAGECOUNT        = 256;
67 const sal_uInt16 EXC_PT_MAXDATACOUNT        = 256;
68 
69 // pivot table items
70 const sal_uInt16 EXC_PT_MAXITEMCOUNT        = 32500;
71 
72 const sal_uInt16 EXC_PT_AUTOFMT_HEADER      = 0x810;
73 const sal_uInt16 EXC_PT_AUTOFMT_ZERO        = 0;
74 const sal_uInt32 EXC_PT_AUTOFMT_FLAGS       = 0x20;
75 
76 /** Data type of a pivot cache item. */
77 enum XclPCItemType
78 {
79     EXC_PCITEM_INVALID,         /// Special state, not used in Excel files.
80     EXC_PCITEM_EMPTY,           /// Empty cell.
81     EXC_PCITEM_TEXT,            /// String data.
82     EXC_PCITEM_DOUBLE,          /// Floating-point value.
83     EXC_PCITEM_DATETIME,        /// Date/time.
84     EXC_PCITEM_INTEGER,         /// 16-bit integer value.
85     EXC_PCITEM_BOOL,            /// Boolean value.
86     EXC_PCITEM_ERROR            /// Error code.
87 };
88 
89 /** Specifies the type of a pivot cache field. */
90 enum XclPCFieldType
91 {
92     EXC_PCFIELD_STANDARD,       /// Standard field without grouping.
93     EXC_PCFIELD_STDGROUP,       /// Standard grouping field.
94     EXC_PCFIELD_NUMGROUP,       /// Numeric grouping field.
95     EXC_PCFIELD_DATEGROUP,      /// First date grouping field (opt. with child grouping field).
96     EXC_PCFIELD_DATECHILD,      /// Additional date grouping field.
97     EXC_PCFIELD_CALCED,         /// Calculated field.
98     EXC_PCFIELD_UNKNOWN         /// Unknown field state, handled like standard field.
99 };
100 
101 // (0x0051,0x0052) DCONREF, DCONNAME ------------------------------------------
102 
103 const sal_uInt16 EXC_ID_DCONREF             = 0x0051;
104 const sal_uInt16 EXC_ID_DCONNAME            = 0x0052;
105 
106 // (0x00B0) SXVIEW ------------------------------------------------------------
107 
108 const sal_uInt16 EXC_ID_SXVIEW              = 0x00B0;
109 
110 const sal_uInt16 EXC_SXVIEW_ROWGRAND        = 0x0001;
111 const sal_uInt16 EXC_SXVIEW_COLGRAND        = 0x0002;
112 const sal_uInt16 EXC_SXVIEW_DEFAULTFLAGS    = 0x0208;
113 
114 const sal_uInt16 EXC_SXVIEW_DATALAST        = 0xFFFF;
115 const sal_uInt16 EXC_SXVIEW_AUTOFMT         = 0x0001;
116 
117 // (0x00B1) SXVD --------------------------------------------------------------
118 
119 const sal_uInt16 EXC_ID_SXVD                = 0x00B1;
120 
121 const sal_uInt16 EXC_SXVD_AXIS_NONE         = 0x0000;
122 const sal_uInt16 EXC_SXVD_AXIS_ROW          = 0x0001;
123 const sal_uInt16 EXC_SXVD_AXIS_COL          = 0x0002;
124 const sal_uInt16 EXC_SXVD_AXIS_PAGE         = 0x0004;
125 const sal_uInt16 EXC_SXVD_AXIS_DATA         = 0x0008;
126 const sal_uInt16 EXC_SXVD_AXIS_ROWCOL       = EXC_SXVD_AXIS_ROW | EXC_SXVD_AXIS_COL;
127 const sal_uInt16 EXC_SXVD_AXIS_ROWCOLPAGE   = EXC_SXVD_AXIS_ROWCOL | EXC_SXVD_AXIS_PAGE;
128 
129 const sal_uInt16 EXC_SXVD_SUBT_NONE         = 0x0000;
130 const sal_uInt16 EXC_SXVD_SUBT_DEFAULT      = 0x0001;
131 const sal_uInt16 EXC_SXVD_SUBT_SUM          = 0x0002;
132 const sal_uInt16 EXC_SXVD_SUBT_COUNT        = 0x0004;
133 const sal_uInt16 EXC_SXVD_SUBT_AVERAGE      = 0x0008;
134 const sal_uInt16 EXC_SXVD_SUBT_MAX          = 0x0010;
135 const sal_uInt16 EXC_SXVD_SUBT_MIN          = 0x0020;
136 const sal_uInt16 EXC_SXVD_SUBT_PROD         = 0x0040;
137 const sal_uInt16 EXC_SXVD_SUBT_COUNTNUM     = 0x0080;
138 const sal_uInt16 EXC_SXVD_SUBT_STDDEV       = 0x0100;
139 const sal_uInt16 EXC_SXVD_SUBT_STDDEVP      = 0x0200;
140 const sal_uInt16 EXC_SXVD_SUBT_VAR          = 0x0400;
141 const sal_uInt16 EXC_SXVD_SUBT_VARP         = 0x0800;
142 
143 const sal_uInt16 EXC_SXVD_DEFAULT_CACHE     = EXC_PC_NOFIELD;
144 
145 // (0x00B2) SXVI --------------------------------------------------------------
146 
147 const sal_uInt16 EXC_ID_SXVI                = 0x00B2;
148 
149 const sal_uInt16 EXC_SXVI_TYPE_PAGE         = 0x00FE;
150 const sal_uInt16 EXC_SXVI_TYPE_NULL         = 0x00FF;
151 const sal_uInt16 EXC_SXVI_TYPE_DATA         = 0x0000;
152 const sal_uInt16 EXC_SXVI_TYPE_DEFAULT      = 0x0001;
153 const sal_uInt16 EXC_SXVI_TYPE_SUM          = 0x0002;
154 const sal_uInt16 EXC_SXVI_TYPE_COUNT        = 0x0003;
155 const sal_uInt16 EXC_SXVI_TYPE_AVERAGE      = 0x0004;
156 const sal_uInt16 EXC_SXVI_TYPE_MAX          = 0x0005;
157 const sal_uInt16 EXC_SXVI_TYPE_MIN          = 0x0006;
158 const sal_uInt16 EXC_SXVI_TYPE_PROD         = 0x0007;
159 const sal_uInt16 EXC_SXVI_TYPE_COUNTNUM     = 0x0008;
160 const sal_uInt16 EXC_SXVI_TYPE_STDDEV       = 0x0009;
161 const sal_uInt16 EXC_SXVI_TYPE_STDDEVP      = 0x000A;
162 const sal_uInt16 EXC_SXVI_TYPE_VAR          = 0x000B;
163 const sal_uInt16 EXC_SXVI_TYPE_VARP         = 0x000C;
164 const sal_uInt16 EXC_SXVI_TYPE_GRAND        = 0x000D;
165 
166 const sal_uInt16 EXC_SXVI_DEFAULTFLAGS      = 0x0000;
167 const sal_uInt16 EXC_SXVI_HIDDEN            = 0x0001;
168 const sal_uInt16 EXC_SXVI_HIDEDETAIL        = 0x0002;
169 const sal_uInt16 EXC_SXVI_FORMULA           = 0x0004;
170 const sal_uInt16 EXC_SXVI_MISSING           = 0x0008;
171 
172 const sal_uInt16 EXC_SXVI_DEFAULT_CACHE     = EXC_PC_NOFIELD;
173 
174 // (0x00B4) SXIVD -------------------------------------------------------------
175 
176 const sal_uInt16 EXC_ID_SXIVD               = 0x00B4;
177 const sal_uInt16 EXC_SXIVD_DATA             = 0xFFFE;
178 
179 // (0x00B5) SXLI --------------------------------------------------------------
180 
181 const sal_uInt16 EXC_ID_SXLI                = 0x00B5;
182 const sal_uInt16 EXC_SXLI_DEFAULTFLAGS      = 0x0000;
183 
184 // (0x00B6) SXPI --------------------------------------------------------------
185 
186 const sal_uInt16 EXC_ID_SXPI                = 0x00B6;
187 const sal_uInt16 EXC_SXPI_ALLITEMS          = 0x7FFD;
188 
189 // (0x00C5) SXDI --------------------------------------------------------------
190 
191 const sal_uInt16 EXC_ID_SXDI                = 0x00C5;
192 
193 const sal_uInt16 EXC_SXDI_FUNC_SUM          = 0x0000;
194 const sal_uInt16 EXC_SXDI_FUNC_COUNT        = 0x0001;
195 const sal_uInt16 EXC_SXDI_FUNC_AVERAGE      = 0x0002;
196 const sal_uInt16 EXC_SXDI_FUNC_MAX          = 0x0003;
197 const sal_uInt16 EXC_SXDI_FUNC_MIN          = 0x0004;
198 const sal_uInt16 EXC_SXDI_FUNC_PRODUCT      = 0x0005;
199 const sal_uInt16 EXC_SXDI_FUNC_COUNTNUM     = 0x0006;
200 const sal_uInt16 EXC_SXDI_FUNC_STDDEV       = 0x0007;
201 const sal_uInt16 EXC_SXDI_FUNC_STDDEVP      = 0x0008;
202 const sal_uInt16 EXC_SXDI_FUNC_VAR          = 0x0009;
203 const sal_uInt16 EXC_SXDI_FUNC_VARP         = 0x000A;
204 
205 const sal_uInt16 EXC_SXDI_REF_NORMAL        = 0x0000;
206 const sal_uInt16 EXC_SXDI_REF_DIFF          = 0x0001;
207 const sal_uInt16 EXC_SXDI_REF_PERC          = 0x0002;
208 const sal_uInt16 EXC_SXDI_REF_PERC_DIFF     = 0x0003;
209 const sal_uInt16 EXC_SXDI_REF_RUN_TOTAL     = 0x0004;
210 const sal_uInt16 EXC_SXDI_REF_PERC_ROW      = 0x0005;
211 const sal_uInt16 EXC_SXDI_REF_PERC_COL      = 0x0006;
212 const sal_uInt16 EXC_SXDI_REF_PERC_TOTAL    = 0x0007;
213 const sal_uInt16 EXC_SXDI_REF_INDEX         = 0x0008;
214 
215 const sal_uInt16 EXC_SXDI_PREVITEM          = 0x7FFB;
216 const sal_uInt16 EXC_SXDI_NEXTITEM          = 0x7FFC;
217 
218 // (0x00C6) SXDB --------------------------------------------------------------
219 
220 const sal_uInt16 EXC_ID_SXDB                = 0x00C6;
221 
222 const sal_uInt16 EXC_SXDB_SAVEDATA          = 0x0001;
223 const sal_uInt16 EXC_SXDB_INVALID           = 0x0002;
224 const sal_uInt16 EXC_SXDB_REFRESH_LOAD      = 0x0004;
225 const sal_uInt16 EXC_SXDB_OPT_CACHE         = 0x0008;
226 const sal_uInt16 EXC_SXDB_BG_QUERY          = 0x0010;
227 const sal_uInt16 EXC_SXDB_ENABLE_REFRESH    = 0x0020;
228 const sal_uInt16 EXC_SXDB_DEFAULTFLAGS      = EXC_SXDB_SAVEDATA | EXC_SXDB_ENABLE_REFRESH;
229 
230 const sal_uInt16 EXC_SXDB_BLOCKRECS         = 0x1FFF;
231 
232 const sal_uInt16 EXC_SXDB_SRC_SHEET         = 0x0001;
233 const sal_uInt16 EXC_SXDB_SRC_EXTERN        = 0x0002;
234 const sal_uInt16 EXC_SXDB_SRC_CONSOLID      = 0x0004;
235 const sal_uInt16 EXC_SXDB_SRC_SCENARIO      = 0x0008;
236 
237 // (0x00C7) SXFIELD -----------------------------------------------------------
238 
239 const sal_uInt16 EXC_ID_SXFIELD             = 0x00C7;
240 
241 const sal_uInt16 EXC_SXFIELD_HASITEMS       = 0x0001;
242 const sal_uInt16 EXC_SXFIELD_POSTPONE       = 0x0002;
243 const sal_uInt16 EXC_SXFIELD_CALCED         = 0x0004;
244 const sal_uInt16 EXC_SXFIELD_HASCHILD       = 0x0008;
245 const sal_uInt16 EXC_SXFIELD_NUMGROUP       = 0x0010;
246 const sal_uInt16 EXC_SXFIELD_16BIT          = 0x0200;
247 
248 const sal_uInt16 EXC_SXFIELD_DATA_MASK      = 0x0DE0;
249 // known data types
250 const sal_uInt16 EXC_SXFIELD_DATA_NONE      = 0x0000;   /// Special state for groupings.
251 const sal_uInt16 EXC_SXFIELD_DATA_STR       = 0x0480;   /// Only strings, nothing else.
252 const sal_uInt16 EXC_SXFIELD_DATA_INT       = 0x0520;   /// Only integers, opt. with doubles.
253 const sal_uInt16 EXC_SXFIELD_DATA_DBL       = 0x0560;   /// Only doubles, nothing else.
254 const sal_uInt16 EXC_SXFIELD_DATA_STR_INT   = 0x05A0;   /// Only strings and integers, opt. with doubles.
255 const sal_uInt16 EXC_SXFIELD_DATA_STR_DBL   = 0x05E0;   /// Only strings and doubles, nothing else.
256 const sal_uInt16 EXC_SXFIELD_DATA_DATE      = 0x0900;   /// Only dates, nothing else.
257 const sal_uInt16 EXC_SXFIELD_DATA_DATE_EMP  = 0x0980;   /// Dates and empty strings, nothing else (?).
258 const sal_uInt16 EXC_SXFIELD_DATA_DATE_NUM  = 0x0D00;   /// Dates with integers or doubles without strings.
259 const sal_uInt16 EXC_SXFIELD_DATA_DATE_STR  = 0x0D80;   /// Dates and strings, opt. with integers or doubles.
260 
261 const sal_uInt16 EXC_SXFIELD_INDEX_MIN      = 0;        /// List index for minimum item in groupings.
262 const sal_uInt16 EXC_SXFIELD_INDEX_MAX      = 1;        /// List index for maximum item in groupings.
263 const sal_uInt16 EXC_SXFIELD_INDEX_STEP     = 2;        /// List index for step item in groupings.
264 
265 // (0x00C8) SXINDEXLIST -------------------------------------------------------
266 
267 const sal_uInt16 EXC_ID_SXINDEXLIST         = 0x00C8;
268 
269 // (0x00C9) SXDOUBLE ----------------------------------------------------------
270 
271 const sal_uInt16 EXC_ID_SXDOUBLE            = 0x00C9;
272 
273 // (0x00CA) SXBOOLEAN ---------------------------------------------------------
274 
275 const sal_uInt16 EXC_ID_SXBOOLEAN           = 0x00CA;
276 
277 // (0x00CB) SXERROR -----------------------------------------------------------
278 
279 const sal_uInt16 EXC_ID_SXERROR             = 0x00CB;
280 
281 // (0x00CC) SXINTEGER ---------------------------------------------------------
282 
283 const sal_uInt16 EXC_ID_SXINTEGER           = 0x00CC;
284 
285 // (0x00CD) SXSTRING ----------------------------------------------------------
286 
287 const sal_uInt16 EXC_ID_SXSTRING            = 0x00CD;
288 
289 // (0x00CE) SXDATETIME --------------------------------------------------------
290 
291 const sal_uInt16 EXC_ID_SXDATETIME          = 0x00CE;
292 
293 // (0x00CF) SXEMPTY -----------------------------------------------------------
294 
295 const sal_uInt16 EXC_ID_SXEMPTY             = 0x00CF;
296 
297 // (0x00D5) SXIDSTM -----------------------------------------------------------
298 
299 const sal_uInt16 EXC_ID_SXIDSTM             = 0x00D5;
300 
301 // (0x00D8) SXNUMGROUP --------------------------------------------------------
302 
303 const sal_uInt16 EXC_ID_SXNUMGROUP          = 0x00D8;
304 
305 const sal_uInt16 EXC_SXNUMGROUP_AUTOMIN     = 0x0001;
306 const sal_uInt16 EXC_SXNUMGROUP_AUTOMAX     = 0x0002;
307 
308 const sal_uInt16 EXC_SXNUMGROUP_TYPE_SEC    = 1;
309 const sal_uInt16 EXC_SXNUMGROUP_TYPE_MIN    = 2;
310 const sal_uInt16 EXC_SXNUMGROUP_TYPE_HOUR   = 3;
311 const sal_uInt16 EXC_SXNUMGROUP_TYPE_DAY    = 4;
312 const sal_uInt16 EXC_SXNUMGROUP_TYPE_MONTH  = 5;
313 const sal_uInt16 EXC_SXNUMGROUP_TYPE_QUART  = 6;
314 const sal_uInt16 EXC_SXNUMGROUP_TYPE_YEAR   = 7;
315 const sal_uInt16 EXC_SXNUMGROUP_TYPE_NUM    = 8;
316 
317 // (0x00D9) SXGROUPINFO -------------------------------------------------------
318 
319 const sal_uInt16 EXC_ID_SXGROUPINFO         = 0x00D9;
320 
321 // (0x00DC) SXEXT -------------------------------------------------------------
322 
323 const sal_uInt16 EXC_ID_SXEXT               = 0x00DC;
324 
325 // (0x00E3) SXVS --------------------------------------------------------------
326 
327 const sal_uInt16 EXC_ID_SXVS                = 0x00E3;
328 
329 const sal_uInt16 EXC_SXVS_UNKNOWN           = 0x0000;
330 const sal_uInt16 EXC_SXVS_SHEET             = 0x0001;
331 const sal_uInt16 EXC_SXVS_EXTERN            = 0x0002;
332 const sal_uInt16 EXC_SXVS_CONSOLID          = 0x0004;
333 const sal_uInt16 EXC_SXVS_PIVOTTAB          = 0x0008;
334 const sal_uInt16 EXC_SXVS_SCENARIO          = 0x0010;
335 
336 // (0x00F0) SXRULE ------------------------------------------------------------
337 
338 const sal_uInt16 EXC_ID_SXRULE              = 0x00F0;
339 
340 // (0x00F1) SXEX --------------------------------------------------------------
341 
342 const sal_uInt16 EXC_ID_SXEX                = 0x00F1;
343 
344 const sal_uInt32 EXC_SXEX_DRILLDOWN         = 0x00020000;
345 const sal_uInt32 EXC_SXEX_DEFAULTFLAGS      = 0x004F0200;
346 
347 // (0x00F2) SXFILT ------------------------------------------------------------
348 
349 const sal_uInt16 EXC_ID_SXFILT              = 0x00F2;
350 
351 // (0x00F5) -------------------------------------------------------------------
352 
353 const sal_uInt16 EXC_ID_00F5                = 0x00F5;   /// Unknown record
354 
355 // (0x00F6) SXNAME ------------------------------------------------------------
356 
357 const sal_uInt16 EXC_ID_SXNAME              = 0x00F6;
358 
359 // (0x00F8) SXPAIR ------------------------------------------------------------
360 
361 const sal_uInt16 EXC_ID_SXPAIR              = 0x00F8;
362 
363 // (0x00F9) SXFMLA ------------------------------------------------------------
364 
365 const sal_uInt16 EXC_ID_SXFMLA              = 0x00F9;
366 
367 // (0x0100) SXVDEX ------------------------------------------------------------
368 
369 const sal_uInt16 EXC_ID_SXVDEX              = 0x0100;
370 
371 const sal_uInt32 EXC_SXVDEX_SHOWALL         = 0x00000001;
372 const sal_uInt32 EXC_SXVDEX_SORT            = 0x00000200;
373 const sal_uInt32 EXC_SXVDEX_SORT_ASC        = 0x00000400;
374 const sal_uInt32 EXC_SXVDEX_AUTOSHOW        = 0x00000800;
375 const sal_uInt32 EXC_SXVDEX_AUTOSHOW_ASC    = 0x00001000;
376 const sal_uInt32 EXC_SXVDEX_LAYOUT_REPORT   = 0x00200000;
377 const sal_uInt32 EXC_SXVDEX_LAYOUT_BLANK    = 0x00400000;
378 const sal_uInt32 EXC_SXVDEX_LAYOUT_TOP      = 0x00800000;
379 const sal_uInt32 EXC_SXVDEX_DEFAULTFLAGS    = 0x0A00001E | EXC_SXVDEX_SORT_ASC | EXC_SXVDEX_AUTOSHOW_ASC;
380 
381 const sal_uInt16 EXC_SXVDEX_SORT_OWN        = 0xFFFF;
382 const sal_uInt16 EXC_SXVDEX_SHOW_NONE       = 0xFFFF;
383 const sal_uInt16 EXC_SXVDEX_FORMAT_NONE     = 0x0000;
384 
385 // (0x0103) SXFORMULA ---------------------------------------------------------
386 
387 const sal_uInt16 EXC_ID_SXFORMULA           = 0x0103;
388 
389 // (0x0122) SXDBEX ------------------------------------------------------------
390 
391 const sal_uInt16 EXC_ID_SXDBEX              = 0x0122;
392 const double EXC_SXDBEX_CREATION_DATE       = 51901.029652778;
393 
394 // (0x01BB) SXFDBTYPE ---------------------------------------------------------
395 
396 const sal_uInt16 EXC_ID_SXFDBTYPE           = 0x01BB;
397 const sal_uInt16 EXC_SXFDBTYPE_DEFAULT      = 0x0000;
398 
399 // (0x0810) SXVIEWEX9 ---------------------------------------------------------
400 const sal_uInt16 EXC_ID_SXVIEWEX9       = 0x0810;
401 
402 // ============================================================================
403 // Pivot cache
404 // ============================================================================
405 
406 /** Represents a data item of any type in a pivot cache. Supposed as base class for import and export. */
407 class XclPCItem
408 {
409 public:
410     explicit            XclPCItem();
411     virtual             ~XclPCItem();
412 
413     /** Sets the item to 'empty' type. */
414     void                SetEmpty();
415     /** Sets the item to 'text' type and adds the passed text. */
416     void                SetText( const String& rText );
417     /** Sets the item to 'double' type and adds the passed value. */
418     void                SetDouble( double fValue );
419     /** Sets the item to 'date/time' type and adds the passed date. */
420     void                SetDateTime( const DateTime& rDateTime );
421     /** Sets the item to 'integer' type and adds the passed value. */
422     void                SetInteger( sal_Int16 nValue );
423     /** Sets the item to 'error' type and adds the passed Excel error code. */
424     void                SetError( sal_uInt16 nError );
425     /** Sets the item to 'boolean' type and adds the passed Boolean value. */
426     void                SetBool( bool bValue );
427 
428     /** Returns the current item type. */
GetType() const429     inline XclPCItemType GetType() const { return meType; }
430     /** Returns the text representation of the item. */
ConvertToText() const431     inline const String& ConvertToText() const { return maText; }
432 
433     /** Returns true, if the passed iterm equals this item. */
434     bool                IsEqual( const XclPCItem& rItem ) const;
435 
436     /** Returns true, if the item type is 'empty'. */
437     bool                IsEmpty() const;
438     /** Returns pointer to text, if the item type is 'text', otherwise 0. */
439     const String*       GetText() const;
440     /** Returns pointer to value, if the item type is 'double', otherwise 0. */
441     const double*       GetDouble() const;
442     /** Returns pointer to date, if the item type is 'date/time', otherwise 0. */
443     const DateTime*     GetDateTime() const;
444     /** Returns pointer to integer, if the item type is 'integer', otherwise 0. */
445     const sal_Int16*    GetInteger() const;
446     /** Returns pointer to error code, if the item type is 'error', otherwise 0. */
447     const sal_uInt16*   GetError() const;
448     /** Returns pointer to Boolean value, if the item type is 'boolean', otherwise 0. */
449     const bool*         GetBool() const;
450     const String *      GetItemName() const;
451 
452 private:
453     XclPCItemType       meType;         /// Type of the item.
454     String              maText;         /// Text representation of the item.
455     DateTime            maDateTime;     /// Value of a date/time item.
456     union
457     {
458         double              mfValue;        /// Value of a floating-point item.
459         sal_Int16           mnValue;        /// Value of an integer item.
460         sal_uInt16          mnError;        /// Error code of an error item.
461         bool                mbValue;        /// Value of a boolean item.
462     };
463 };
464 
operator ==(const XclPCItem & rLeft,const XclPCItem & rRight)465 inline bool operator==( const XclPCItem& rLeft, const XclPCItem& rRight ) { return rLeft.IsEqual( rRight ); }
operator !=(const XclPCItem & rLeft,const XclPCItem & rRight)466 inline bool operator!=( const XclPCItem& rLeft, const XclPCItem& rRight ) { return !(rLeft == rRight); }
467 
468 // Field settings =============================================================
469 
470 /** Contains data for a pivot cache field (SXFIELD record). */
471 struct XclPCFieldInfo
472 {
473     String              maName;         /// Name of the pivot cache field.
474     sal_uInt16          mnFlags;        /// Various flags.
475     sal_uInt16          mnGroupChild;   /// Field containing grouping info for this field.
476     sal_uInt16          mnGroupBase;    /// Base field if this field contains grouping info.
477     sal_uInt16          mnVisItems;     /// Number of visible items for this field.
478     sal_uInt16          mnGroupItems;   /// Number of special items in a grouping field.
479     sal_uInt16          mnBaseItems;    /// Number of items in the base field.
480     sal_uInt16          mnOrigItems;    /// Number of original source data items.
481 
482     explicit            XclPCFieldInfo();
483 };
484 
485 XclImpStream& operator>>( XclImpStream& rStrm, XclPCFieldInfo& rInfo );
486 XclExpStream& operator<<( XclExpStream& rStrm, const XclPCFieldInfo& rInfo );
487 
488 // Numeric grouping field settings ============================================
489 
490 /** Contains data for a numeric grouping field (SXNUMGROUP record). */
491 struct XclPCNumGroupInfo
492 {
493     sal_uInt16          mnFlags;        /// Various flags.
494 
495     explicit            XclPCNumGroupInfo();
496 
497     void                SetNumType();
498 
499     sal_Int32           GetScDateType() const;
500     void                SetScDateType( sal_Int32 nScType );
501 
502     sal_uInt16          GetXclDataType() const;
503     void                SetXclDataType( sal_uInt16 nXclType );
504 };
505 
506 XclImpStream& operator>>( XclImpStream& rStrm, XclPCNumGroupInfo& rInfo );
507 XclExpStream& operator<<( XclExpStream& rStrm, const XclPCNumGroupInfo& rInfo );
508 
509 // Base class for pivot cache fields ==========================================
510 
511 /** Represents a field in a pivot cache. Supposed as base class for import and export. */
512 class XclPCField
513 {
514 public:
515     explicit            XclPCField( XclPCFieldType eFieldType, sal_uInt16 nFieldIdx );
516     virtual             ~XclPCField();
517 
518     /** Returns the index of this field in the containing pivot cache. */
GetFieldIndex() const519     inline sal_uInt16   GetFieldIndex() const { return mnFieldIdx; }
520 
521     /** Returns true, if the type of the field is supported by Calc. */
522     bool                IsSupportedField() const;
523 
524     /** Returns true, if this is a standard field build directly from source data. */
525     bool                IsStandardField() const;
526 
527 //UNUSED2008-05  /** Returns true, if the items of the field are calculated from a formula. */
528 //UNUSED2008-05  bool                IsCalculatedField() const;
529 
530     /** Returns true, if this field is a grouping field. */
531     bool                IsStdGroupField() const;
532     /** Returns true, if this field is a numeric grouping field. */
533     bool                IsNumGroupField() const;
534     /** Returns true, if this field is a date/time grouping field. */
535     bool                IsDateGroupField() const;
536     /** Returns true, if this field is a grouping field of any type. */
537     bool                IsGroupField() const;
538 
539     /** Returns true, if this field has a child field in a grouping. */
540     bool                IsGroupBaseField() const;
541     /** Returns true, if this field is a child field in a grouping (it has a base field). */
542     bool                IsGroupChildField() const;
543     /** Returns the index of the base field, if exists, otherwise the own index. */
544     sal_uInt16          GetBaseFieldIndex() const;
545 
546     /** Returns true, if the field is based on a column in the source data area. */
547     bool                HasOrigItems() const;
548     /** Returns true, if any items are stored after the SXFIELD record. */
549     bool                HasInlineItems() const;
550     /** Returns true, if the items are stored separately after the last field. */
551     bool                HasPostponedItems() const;
552     /** Returns true, if the item indexes in the SXINDEXLIST record are stored as 16-bit values. */
553     bool                Has16BitIndexes() const;
554 
555 protected:
556     XclPCFieldInfo      maFieldInfo;        /// Pivot cache field info (SXFIELD record).
557     XclPCFieldType      meFieldType;        /// Type of this pivot cache field.
558     sal_uInt16          mnFieldIdx;         /// Own field index in pivot cache.
559     ScfUInt16Vec        maGroupOrder;       /// Order of items in a grouping field (SXGROUPINFO record).
560     XclPCNumGroupInfo   maNumGroupInfo;     /// Info for numeric grouping (SXNUMGROUP record).
561 };
562 
563 // Pivot cache settings =======================================================
564 
565 /** Contains data for a pivot cache (SXDB record). */
566 struct XclPCInfo
567 {
568     sal_uInt32          mnSrcRecs;      /// Records in source database.
569     sal_uInt16          mnStrmId;       /// Stream identifier.
570     sal_uInt16          mnFlags;        /// Flags for the cache.
571     sal_uInt16          mnBlockRecs;    /// Records in a source database block.
572     sal_uInt16          mnStdFields;    /// Number of standard pivot cache fields.
573     sal_uInt16          mnTotalFields;  /// Number of all fields (standard, grouped, calculated).
574     sal_uInt16          mnSrcType;      /// Database type.
575     String              maUserName;     /// Name of user who last modified the cache.
576 
577     explicit            XclPCInfo();
578 };
579 
580 XclImpStream& operator>>( XclImpStream& rStrm, XclPCInfo& rInfo );
581 XclExpStream& operator<<( XclExpStream& rStrm, const XclPCInfo& rInfo );
582 
583 // ============================================================================
584 // Pivot table
585 // ============================================================================
586 
587 // cached name ================================================================
588 
589 /** A name for various pivot table info structs. Includes 'use cache' state. */
590 struct XclPTCachedName
591 {
592     String              maName;         /// The visible name, if used.
593     bool                mbUseCache;     /// true = Use name in cache instead of maName.
594 
XclPTCachedNameXclPTCachedName595     inline explicit     XclPTCachedName() : mbUseCache( true ) {}
596 };
597 
598 XclImpStream& operator>>( XclImpStream& rStrm, XclPTCachedName& rCachedName );
599 XclExpStream& operator<<( XclExpStream& rStrm, const XclPTCachedName& rCachedName );
600 
601 // ----------------------------------------------------------------------------
602 
603 /** Base struct for named info structs. Supports explicit naming and using the cache. */
604 struct XclPTVisNameInfo
605 {
606     XclPTCachedName     maVisName;      /// The displayed name of the item.
607 
608     /** Returns true, if the name is set explicitly (maVisName.mbUseCache is false). */
HasVisNameXclPTVisNameInfo609     inline bool         HasVisName() const { return !maVisName.mbUseCache; }
610     /** Returns the name, if set explicitly (maVisName.mbUseCache is false). */
611     const String*       GetVisName() const;
612     /** Sets the visible name and enables usage of cache if name is empty. */
613     void                SetVisName( const String& rName );
614 };
615 
616 // Field item settings ========================================================
617 
618 /** Contains data for a pivot table data item (SXVI record). */
619 struct XclPTItemInfo : public XclPTVisNameInfo
620 {
621     sal_uInt16          mnType;         /// Type of the item (e.g. data, function, grand total).
622     sal_uInt16          mnFlags;        /// Several flags.
623     sal_uInt16          mnCacheIdx;     /// Index into cache for item name.
624 
625     explicit            XclPTItemInfo();
626 };
627 
628 XclImpStream& operator>>( XclImpStream& rStrm, XclPTItemInfo& rInfo );
629 XclExpStream& operator<<( XclExpStream& rStrm, const XclPTItemInfo& rInfo );
630 
631 // General field settings =====================================================
632 
633 typedef ::std::vector< sal_uInt16 > XclPTSubtotalVec;
634 
635 /** Contains data for a pivot table field (SXVD record). */
636 struct XclPTFieldInfo : public XclPTVisNameInfo
637 {
638     sal_uInt16          mnAxes;         /// Flags for axes this field is part of.
639     sal_uInt16          mnSubtCount;    /// Number of subtotal functions.
640     sal_uInt16          mnSubtotals;    /// Bitfield for subtotal functions.
641     sal_uInt16          mnItemCount;    /// Number of items of this field.
642     sal_uInt16          mnCacheIdx;     /// Index into cache for field name (not part of record).
643 
644     explicit            XclPTFieldInfo();
645 
646     /** Returns the API enum representing the orientation (first of row/col/page/data).
647         @param nMask  Restricts the axes taken into account.
648         @return  The first found axis orientation, that is allowed in nMask parameter. */
649     ::com::sun::star::sheet::DataPilotFieldOrientation GetApiOrient( sal_uInt16 nMask ) const;
650     /** Adds the axis orientation represented by the passed API enum. */
651     void                AddApiOrient( ::com::sun::star::sheet::DataPilotFieldOrientation eOrient );
652 
653     /** Returns a vector of all set subtotal functions. */
654     void                GetSubtotals( XclPTSubtotalVec& rSubtotals ) const;
655     /** Sets the subtotal functions contained in the passed sequence. */
656     void                SetSubtotals( const XclPTSubtotalVec& rSubtotals );
657 };
658 
659 XclImpStream& operator>>( XclImpStream& rStrm, XclPTFieldInfo& rInfo );
660 XclExpStream& operator<<( XclExpStream& rStrm, const XclPTFieldInfo& rInfo );
661 
662 // Extended field settings ====================================================
663 
664 /** Contains extended data for a pivot table field (SXVDEX record). */
665 struct XclPTFieldExtInfo
666 {
667     sal_uInt32          mnFlags;        /// Several flags and number of items for AutoShow.
668     sal_uInt16          mnSortField;    /// Index to data field sorting bases on.
669     sal_uInt16          mnShowField;    /// Index to data field AutoShow bases on.
670     sal_uInt16          mnNumFmt;
671     ::std::auto_ptr<rtl::OUString> mpFieldTotalName;
672 
673     explicit            XclPTFieldExtInfo();
674 
675     /** Returns the API constant representing the sorting mode. */
676     sal_Int32           GetApiSortMode() const;
677     /** Sets the sorting mode represented by the passed API constant. */
678     void                SetApiSortMode( sal_Int32 nSortMode );
679 
680     /** Returns the API constant representing the AutoShow mode. */
681     sal_Int32           GetApiAutoShowMode() const;
682     /** Sets the AutoShow mode represented by the passed API constant. */
683     void                SetApiAutoShowMode( sal_Int32 nShowMode );
684 
685     /** Returns the number of items to be shown in AutoShow mode. */
686     sal_Int32           GetApiAutoShowCount() const;
687     /** Sets the number of items to be shown in AutoShow mode. */
688     void                SetApiAutoShowCount( sal_Int32 nShowCount );
689 
690     /** Returns the API constant representing the layout mode. */
691     sal_Int32           GetApiLayoutMode() const;
692     /** Sets the layout mode represented by the passed API constant. */
693     void                SetApiLayoutMode( sal_Int32 nLayoutMode );
694 };
695 
696 XclImpStream& operator>>( XclImpStream& rStrm, XclPTFieldExtInfo& rInfo );
697 XclExpStream& operator<<( XclExpStream& rStrm, const XclPTFieldExtInfo& rInfo );
698 
699 // Page field settings ========================================================
700 
701 /** Contains data for a pivot table page field (part of SXPI record). */
702 struct XclPTPageFieldInfo
703 {
704     sal_uInt16          mnField;        /// Base field for this page info.
705     sal_uInt16          mnSelItem;      /// Index to selected item.
706     sal_uInt16          mnObjId;        /// Escher object ID of dropdown listbox.
707 
708     explicit            XclPTPageFieldInfo();
709 };
710 
711 XclImpStream& operator>>( XclImpStream& rStrm, XclPTPageFieldInfo& rInfo );
712 XclExpStream& operator<<( XclExpStream& rStrm, const XclPTPageFieldInfo& rInfo );
713 
714 // Data field settings ========================================================
715 
716 /** Contains data for a pivot table data field (SXDI record). */
717 struct XclPTDataFieldInfo : public XclPTVisNameInfo
718 {
719     sal_uInt16          mnField;        /// Base field for this data info.
720     sal_uInt16          mnAggFunc;      /// Data aggregation function.
721     sal_uInt16          mnRefType;      /// Result reference type.
722     sal_uInt16          mnRefField;     /// Index to SXVD of referred field used for the results.
723     sal_uInt16          mnRefItem;      /// Index to SXVI of referred item of the used field.
724     sal_uInt16          mnNumFmt;       /// Number format of the results.
725 
726     explicit            XclPTDataFieldInfo();
727 
728     /** Returns the API enum representing the aggregation function. */
729     ::com::sun::star::sheet::GeneralFunction GetApiAggFunc() const;
730     /** Sets the aggregation function represented by the passed API enum. */
731     void                SetApiAggFunc( ::com::sun::star::sheet::GeneralFunction eAggFunc );
732 
733     /** Returns the API constant representing the result reference type. */
734     sal_Int32           GetApiRefType() const;
735     /** Sets the result reference type represented by the passed API constant. */
736     void                SetApiRefType( sal_Int32 nRefType );
737 
738     /** Returns the API constant representing the result reference item type. */
739     sal_Int32           GetApiRefItemType() const;
740     /** Sets the result reference item type represented by the passed API constant. */
741     void                SetApiRefItemType( sal_Int32 nRefItemType );
742 };
743 
744 XclImpStream& operator>>( XclImpStream& rStrm, XclPTDataFieldInfo& rInfo );
745 XclExpStream& operator<<( XclExpStream& rStrm, const XclPTDataFieldInfo& rInfo );
746 
747 // Pivot table settings =======================================================
748 
749 /** Contains data for a pivot table (SXVIEW record). */
750 struct XclPTInfo
751 {
752     String              maTableName;        /// The name of the pivot table.
753     String              maDataName;         /// The visible name of the data field.
754     XclRange            maOutXclRange;      /// Output range.
755     XclAddress          maDataXclPos;       /// First cell containing data.
756     sal_uInt16          mnFirstHeadRow;     /// First heading row.
757     sal_uInt16          mnCacheIdx;         /// 0-based index of the pivot cache.
758     sal_uInt16          mnDataAxis;         /// Orientation of data fields.
759     sal_uInt16          mnDataPos;          /// Position of data fields.
760     sal_uInt16          mnFields;           /// Number of all fields.
761     sal_uInt16          mnRowFields;        /// Number of row fields.
762     sal_uInt16          mnColFields;        /// Number of column fields.
763     sal_uInt16          mnPageFields;       /// Number of page fields.
764     sal_uInt16          mnDataFields;       /// Number of data fields.
765     sal_uInt16          mnDataRows;         /// Number of rows containing data.
766     sal_uInt16          mnDataCols;         /// Number of columns containing data.
767     sal_uInt16          mnFlags;            /// Flags for the entire pivot table.
768     sal_uInt16          mnAutoFmtIdx;       /// Index to pivot table autoformat.
769 
770     explicit            XclPTInfo();
771 };
772 
773 XclImpStream& operator>>( XclImpStream& rStrm, XclPTInfo& rInfo );
774 XclExpStream& operator<<( XclExpStream& rStrm, const XclPTInfo& rInfo );
775 
776 // Extended pivot table settings ==============================================
777 
778 /** Extended information about a pivot table (SXEX record). */
779 struct XclPTExtInfo
780 {
781     sal_uInt16          mnSxformulaRecs;    /// Number of SXFORMULA records.
782     sal_uInt16          mnSxselectRecs;     /// Number of SXSELECT records.
783     sal_uInt16          mnPagePerRow;       /// Number of page fields per row.
784     sal_uInt16          mnPagePerCol;       /// Number of page fields per column.
785     sal_uInt32          mnFlags;            /// Flags for the entire pivot table.
786 
787     explicit            XclPTExtInfo();
788 };
789 
790 XclImpStream& operator>>( XclImpStream& rStrm, XclPTExtInfo& rInfo );
791 XclExpStream& operator<<( XclExpStream& rStrm, const XclPTExtInfo& rInfo );
792 
793 // ============================================================================
794 
795 // Pivot table autoformat settings ==============================================
796 
797 /** Pivot table autoformat settings (SXVIEWEX9 record). */
798 struct XclPTViewEx9Info
799 {
800     sal_uInt32          mbReport;           /// 2 for report* fmts ?
801     sal_uInt8           mnAutoFormat;       /// AutoFormat ID
802     sal_uInt8           mnGridLayout;       /// 0 == gridlayout, 0x10 == modern
803     String              maGrandTotalName;
804 
805     explicit            XclPTViewEx9Info();
806     void                Init( const ScDPObject& rDPObj );
807 };
808 
809 XclImpStream& operator>>( XclImpStream& rStrm, XclPTViewEx9Info& rInfo );
810 XclExpStream& operator<<( XclExpStream& rStrm, const XclPTViewEx9Info& rInfo );
811 
812 // ============================================================================
813 #endif
814 
815