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