bump product version to 4.1.6.2
[LibreOffice.git] / sc / source / filter / excel / xlpivot.cxx
blob29d78d8ff5cb07dad99b804a7ad3c5cc95711626
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "dpgroup.hxx"
21 #include "dpsave.hxx"
22 #include "xestream.hxx"
23 #include "xistream.hxx"
24 #include "xestring.hxx"
25 #include "xlpivot.hxx"
26 #include <com/sun/star/sheet/DataPilotFieldGroupBy.hpp>
28 using ::com::sun::star::sheet::GeneralFunction;
29 using ::com::sun::star::sheet::DataPilotFieldOrientation;
31 namespace ScDPSortMode = ::com::sun::star::sheet::DataPilotFieldSortMode;
32 namespace ScDPShowItemsMode = ::com::sun::star::sheet::DataPilotFieldShowItemsMode;
33 namespace ScDPLayoutMode = ::com::sun::star::sheet::DataPilotFieldLayoutMode;
34 namespace ScDPRefItemType = ::com::sun::star::sheet::DataPilotFieldReferenceItemType;
35 namespace ScDPGroupBy = ::com::sun::star::sheet::DataPilotFieldGroupBy;
37 // ============================================================================
38 // Pivot cache
39 // ============================================================================
41 XclPCItem::XclPCItem() :
42 meType( EXC_PCITEM_INVALID ),
43 maDateTime( DateTime::EMPTY )
47 XclPCItem::~XclPCItem()
51 void XclPCItem::SetEmpty()
53 meType = EXC_PCITEM_EMPTY;
54 maText = OUString();
57 void XclPCItem::SetText( const OUString& rText )
59 meType = EXC_PCITEM_TEXT;
60 maText = rText;
63 void XclPCItem::SetDouble( double fValue )
65 meType = EXC_PCITEM_DOUBLE;
66 //! TODO convert double to string
67 maText = OUString();
68 mfValue = fValue;
71 void XclPCItem::SetDateTime( const DateTime& rDateTime )
73 meType = EXC_PCITEM_DATETIME;
74 //! TODO convert date to string
75 maText = OUString();
76 maDateTime = rDateTime;
79 void XclPCItem::SetInteger( sal_Int16 nValue )
81 meType = EXC_PCITEM_INTEGER;
82 maText = OUString::number(nValue);
83 mnValue = nValue;
86 void XclPCItem::SetError( sal_uInt16 nError )
88 meType = EXC_PCITEM_ERROR;
89 maText = OUString();
90 mnError = nError;
91 switch( nError )
93 case 0x00: maText = "#NULL!"; break;
94 case 0x07: maText = "#DIV/0!"; break;
95 case 0x0F: maText = "#VALUE!"; break;
96 case 0x17: maText = "#REF!"; break;
97 case 0x1D: maText = "#NAME?"; break;
98 case 0x24: maText = "#NUM!"; break;
99 case 0x2A: maText = "#N/A"; break;
100 default: break;
104 void XclPCItem::SetBool( bool bValue )
106 meType = EXC_PCITEM_BOOL;
107 //! TODO convert boolean to string
108 maText = OUString();
109 mbValue = bValue;
112 // ----------------------------------------------------------------------------
114 bool XclPCItem::IsEqual( const XclPCItem& rItem ) const
116 if( meType == rItem.meType ) switch( meType )
118 case EXC_PCITEM_INVALID: return true;
119 case EXC_PCITEM_EMPTY: return true;
120 case EXC_PCITEM_TEXT: return maText == rItem.maText;
121 case EXC_PCITEM_DOUBLE: return mfValue == rItem.mfValue;
122 case EXC_PCITEM_DATETIME: return maDateTime == rItem.maDateTime;
123 case EXC_PCITEM_INTEGER: return mnValue == rItem.mnValue;
124 case EXC_PCITEM_BOOL: return mbValue == rItem.mbValue;
125 case EXC_PCITEM_ERROR: return mnError == rItem.mnError;
126 default: OSL_FAIL( "XclPCItem::IsEqual - unknown pivot cache item type" );
128 return false;
131 bool XclPCItem::IsEmpty() const
133 return meType == EXC_PCITEM_EMPTY;
136 const OUString* XclPCItem::GetText() const
138 return (meType == EXC_PCITEM_TEXT || meType == EXC_PCITEM_ERROR) ? &maText : NULL;
141 const double* XclPCItem::GetDouble() const
143 return (meType == EXC_PCITEM_DOUBLE) ? &mfValue : 0;
146 const DateTime* XclPCItem::GetDateTime() const
148 return (meType == EXC_PCITEM_DATETIME) ? &maDateTime : 0;
151 const sal_Int16* XclPCItem::GetInteger() const
153 return (meType == EXC_PCITEM_INTEGER) ? &mnValue : 0;
156 const sal_uInt16* XclPCItem::GetError() const
158 return (meType == EXC_PCITEM_ERROR) ? &mnError : 0;
161 const bool* XclPCItem::GetBool() const
163 return (meType == EXC_PCITEM_BOOL) ? &mbValue : 0;
166 // Field settings =============================================================
168 XclPCFieldInfo::XclPCFieldInfo() :
169 mnFlags( 0 ),
170 mnGroupChild( 0 ),
171 mnGroupBase( 0 ),
172 mnVisItems( 0 ),
173 mnGroupItems( 0 ),
174 mnBaseItems( 0 ),
175 mnOrigItems( 0 )
179 XclImpStream& operator>>( XclImpStream& rStrm, XclPCFieldInfo& rInfo )
181 rStrm >> rInfo.mnFlags
182 >> rInfo.mnGroupChild
183 >> rInfo.mnGroupBase
184 >> rInfo.mnVisItems
185 >> rInfo.mnGroupItems
186 >> rInfo.mnBaseItems
187 >> rInfo.mnOrigItems;
188 if( rStrm.GetRecLeft() >= 3 )
189 rInfo.maName = rStrm.ReadUniString();
190 else
191 rInfo.maName = OUString();
192 return rStrm;
195 XclExpStream& operator<<( XclExpStream& rStrm, const XclPCFieldInfo& rInfo )
197 return rStrm
198 << rInfo.mnFlags
199 << rInfo.mnGroupChild
200 << rInfo.mnGroupBase
201 << rInfo.mnVisItems
202 << rInfo.mnGroupItems
203 << rInfo.mnBaseItems
204 << rInfo.mnOrigItems
205 << XclExpString( rInfo.maName );
208 // Numeric grouping field settings ============================================
210 XclPCNumGroupInfo::XclPCNumGroupInfo() :
211 mnFlags( EXC_SXNUMGROUP_AUTOMIN | EXC_SXNUMGROUP_AUTOMAX )
213 SetNumType();
216 void XclPCNumGroupInfo::SetNumType()
218 SetXclDataType( EXC_SXNUMGROUP_TYPE_NUM );
221 sal_Int32 XclPCNumGroupInfo::GetScDateType() const
223 sal_Int32 nScType = 0;
224 switch( GetXclDataType() )
226 case EXC_SXNUMGROUP_TYPE_SEC: nScType = ScDPGroupBy::SECONDS; break;
227 case EXC_SXNUMGROUP_TYPE_MIN: nScType = ScDPGroupBy::MINUTES; break;
228 case EXC_SXNUMGROUP_TYPE_HOUR: nScType = ScDPGroupBy::HOURS; break;
229 case EXC_SXNUMGROUP_TYPE_DAY: nScType = ScDPGroupBy::DAYS; break;
230 case EXC_SXNUMGROUP_TYPE_MONTH: nScType = ScDPGroupBy::MONTHS; break;
231 case EXC_SXNUMGROUP_TYPE_QUART: nScType = ScDPGroupBy::QUARTERS; break;
232 case EXC_SXNUMGROUP_TYPE_YEAR: nScType = ScDPGroupBy::YEARS; break;
233 default: OSL_TRACE( "XclPCNumGroupInfo::GetScDateType - unexpected date type %d", GetXclDataType() );
235 return nScType;
238 void XclPCNumGroupInfo::SetScDateType( sal_Int32 nScType )
240 sal_uInt16 nXclType = EXC_SXNUMGROUP_TYPE_NUM;
241 switch( nScType )
243 case ScDPGroupBy::SECONDS: nXclType = EXC_SXNUMGROUP_TYPE_SEC; break;
244 case ScDPGroupBy::MINUTES: nXclType = EXC_SXNUMGROUP_TYPE_MIN; break;
245 case ScDPGroupBy::HOURS: nXclType = EXC_SXNUMGROUP_TYPE_HOUR; break;
246 case ScDPGroupBy::DAYS: nXclType = EXC_SXNUMGROUP_TYPE_DAY; break;
247 case ScDPGroupBy::MONTHS: nXclType = EXC_SXNUMGROUP_TYPE_MONTH; break;
248 case ScDPGroupBy::QUARTERS: nXclType = EXC_SXNUMGROUP_TYPE_QUART; break;
249 case ScDPGroupBy::YEARS: nXclType = EXC_SXNUMGROUP_TYPE_YEAR; break;
250 default: OSL_TRACE( "XclPCNumGroupInfo::SetScDateType - unexpected date type %d", nScType );
252 SetXclDataType( nXclType );
255 sal_uInt16 XclPCNumGroupInfo::GetXclDataType() const
257 return ::extract_value< sal_uInt16 >( mnFlags, 2, 4 );
260 void XclPCNumGroupInfo::SetXclDataType( sal_uInt16 nXclType )
262 ::insert_value( mnFlags, nXclType, 2, 4 );
265 XclImpStream& operator>>( XclImpStream& rStrm, XclPCNumGroupInfo& rInfo )
267 return rStrm >> rInfo.mnFlags;
270 XclExpStream& operator<<( XclExpStream& rStrm, const XclPCNumGroupInfo& rInfo )
272 return rStrm << rInfo.mnFlags;
275 // Base class for pivot cache fields ==========================================
277 XclPCField::XclPCField( XclPCFieldType eFieldType, sal_uInt16 nFieldIdx ) :
278 meFieldType( eFieldType ),
279 mnFieldIdx( nFieldIdx )
283 XclPCField::~XclPCField()
287 bool XclPCField::IsSupportedField() const
289 return (meFieldType != EXC_PCFIELD_CALCED) && (meFieldType != EXC_PCFIELD_UNKNOWN);
292 bool XclPCField::IsStandardField() const
294 return meFieldType == EXC_PCFIELD_STANDARD;
297 bool XclPCField::IsStdGroupField() const
299 return meFieldType == EXC_PCFIELD_STDGROUP;
302 bool XclPCField::IsNumGroupField() const
304 return meFieldType == EXC_PCFIELD_NUMGROUP;
307 bool XclPCField::IsDateGroupField() const
309 return (meFieldType == EXC_PCFIELD_DATEGROUP) || (meFieldType == EXC_PCFIELD_DATECHILD);
312 bool XclPCField::IsGroupField() const
314 return IsStdGroupField() || IsNumGroupField() || IsDateGroupField();
317 bool XclPCField::IsGroupBaseField() const
319 return ::get_flag( maFieldInfo.mnFlags, EXC_SXFIELD_HASCHILD );
322 bool XclPCField::IsGroupChildField() const
324 return (meFieldType == EXC_PCFIELD_STDGROUP) || (meFieldType == EXC_PCFIELD_DATECHILD);
327 bool XclPCField::HasOrigItems() const
329 return IsSupportedField() && ((maFieldInfo.mnOrigItems > 0) || HasPostponedItems());
332 bool XclPCField::HasInlineItems() const
334 return (IsStandardField() || IsGroupField()) && ((maFieldInfo.mnGroupItems > 0) || (maFieldInfo.mnOrigItems > 0));
337 bool XclPCField::HasPostponedItems() const
339 return IsStandardField() && ::get_flag( maFieldInfo.mnFlags, EXC_SXFIELD_POSTPONE );
342 bool XclPCField::Has16BitIndexes() const
344 return IsStandardField() && ::get_flag( maFieldInfo.mnFlags, EXC_SXFIELD_16BIT );
347 // Pivot cache settings =======================================================
349 /** Contains data for a pivot cache (SXDB record). */
350 XclPCInfo::XclPCInfo() :
351 mnSrcRecs( 0 ),
352 mnStrmId( 0xFFFF ),
353 mnFlags( EXC_SXDB_DEFAULTFLAGS ),
354 mnBlockRecs( EXC_SXDB_BLOCKRECS ),
355 mnStdFields( 0 ),
356 mnTotalFields( 0 ),
357 mnSrcType( EXC_SXDB_SRC_SHEET )
361 XclImpStream& operator>>( XclImpStream& rStrm, XclPCInfo& rInfo )
363 rStrm >> rInfo.mnSrcRecs
364 >> rInfo.mnStrmId
365 >> rInfo.mnFlags
366 >> rInfo.mnBlockRecs
367 >> rInfo.mnStdFields
368 >> rInfo.mnTotalFields;
369 rStrm.Ignore( 2 );
370 rStrm >> rInfo.mnSrcType;
371 rInfo.maUserName = rStrm.ReadUniString();
372 return rStrm;
375 XclExpStream& operator<<( XclExpStream& rStrm, const XclPCInfo& rInfo )
377 return rStrm
378 << rInfo.mnSrcRecs
379 << rInfo.mnStrmId
380 << rInfo.mnFlags
381 << rInfo.mnBlockRecs
382 << rInfo.mnStdFields
383 << rInfo.mnTotalFields
384 << sal_uInt16( 0 )
385 << rInfo.mnSrcType
386 << XclExpString( rInfo.maUserName );
389 // ============================================================================
390 // Pivot table
391 // ============================================================================
393 // cached name ================================================================
395 XclImpStream& operator>>( XclImpStream& rStrm, XclPTCachedName& rCachedName )
397 sal_uInt16 nStrLen;
398 rStrm >> nStrLen;
399 rCachedName.mbUseCache = nStrLen == EXC_PT_NOSTRING;
400 if( rCachedName.mbUseCache )
401 rCachedName.maName = OUString();
402 else
403 rCachedName.maName = rStrm.ReadUniString( nStrLen );
404 return rStrm;
407 XclExpStream& operator<<( XclExpStream& rStrm, const XclPTCachedName& rCachedName )
409 if( rCachedName.mbUseCache )
410 rStrm << EXC_PT_NOSTRING;
411 else
412 rStrm << XclExpString( rCachedName.maName, EXC_STR_DEFAULT, EXC_PT_MAXSTRLEN );
413 return rStrm;
416 // ----------------------------------------------------------------------------
418 const OUString* XclPTVisNameInfo::GetVisName() const
420 return HasVisName() ? &maVisName.maName : 0;
423 void XclPTVisNameInfo::SetVisName( const OUString& rName )
425 maVisName.maName = rName;
426 maVisName.mbUseCache = rName.isEmpty();
429 // Field item settings ========================================================
431 XclPTItemInfo::XclPTItemInfo() :
432 mnType( EXC_SXVI_TYPE_DATA ),
433 mnFlags( EXC_SXVI_DEFAULTFLAGS ),
434 mnCacheIdx( EXC_SXVI_DEFAULT_CACHE )
438 XclImpStream& operator>>( XclImpStream& rStrm, XclPTItemInfo& rInfo )
440 return rStrm
441 >> rInfo.mnType
442 >> rInfo.mnFlags
443 >> rInfo.mnCacheIdx
444 >> rInfo.maVisName;
447 XclExpStream& operator<<( XclExpStream& rStrm, const XclPTItemInfo& rInfo )
449 return rStrm
450 << rInfo.mnType
451 << rInfo.mnFlags
452 << rInfo.mnCacheIdx
453 << rInfo.maVisName;
456 // General field settings =====================================================
458 XclPTFieldInfo::XclPTFieldInfo() :
459 mnAxes( EXC_SXVD_AXIS_NONE ),
460 mnSubtCount( 1 ),
461 mnSubtotals( EXC_SXVD_SUBT_DEFAULT ),
462 mnItemCount( 0 ),
463 mnCacheIdx( EXC_SXVD_DEFAULT_CACHE )
467 DataPilotFieldOrientation XclPTFieldInfo::GetApiOrient( sal_uInt16 nMask ) const
469 using namespace ::com::sun::star::sheet;
470 DataPilotFieldOrientation eOrient = DataPilotFieldOrientation_HIDDEN;
471 sal_uInt16 nUsedAxes = mnAxes & nMask;
472 if( nUsedAxes & EXC_SXVD_AXIS_ROW )
473 eOrient = DataPilotFieldOrientation_ROW;
474 else if( nUsedAxes & EXC_SXVD_AXIS_COL )
475 eOrient = DataPilotFieldOrientation_COLUMN;
476 else if( nUsedAxes & EXC_SXVD_AXIS_PAGE )
477 eOrient = DataPilotFieldOrientation_PAGE;
478 else if( nUsedAxes & EXC_SXVD_AXIS_DATA )
479 eOrient = DataPilotFieldOrientation_DATA;
480 return eOrient;
483 void XclPTFieldInfo::AddApiOrient( DataPilotFieldOrientation eOrient )
485 using namespace ::com::sun::star::sheet;
486 switch( eOrient )
488 case DataPilotFieldOrientation_ROW: mnAxes |= EXC_SXVD_AXIS_ROW; break;
489 case DataPilotFieldOrientation_COLUMN: mnAxes |= EXC_SXVD_AXIS_COL; break;
490 case DataPilotFieldOrientation_PAGE: mnAxes |= EXC_SXVD_AXIS_PAGE; break;
491 case DataPilotFieldOrientation_DATA: mnAxes |= EXC_SXVD_AXIS_DATA; break;
492 default:;
496 //! TODO: should be a Sequence<GeneralFunction> in ScDPSaveData
497 void XclPTFieldInfo::GetSubtotals( XclPTSubtotalVec& rSubtotals ) const
499 rSubtotals.clear();
500 rSubtotals.reserve( 16 );
502 using namespace ::com::sun::star::sheet;
503 if( mnSubtotals & EXC_SXVD_SUBT_DEFAULT ) rSubtotals.push_back( GeneralFunction_AUTO );
504 if( mnSubtotals & EXC_SXVD_SUBT_SUM ) rSubtotals.push_back( GeneralFunction_SUM );
505 if( mnSubtotals & EXC_SXVD_SUBT_COUNT ) rSubtotals.push_back( GeneralFunction_COUNT );
506 if( mnSubtotals & EXC_SXVD_SUBT_AVERAGE ) rSubtotals.push_back( GeneralFunction_AVERAGE );
507 if( mnSubtotals & EXC_SXVD_SUBT_MAX ) rSubtotals.push_back( GeneralFunction_MAX );
508 if( mnSubtotals & EXC_SXVD_SUBT_MIN ) rSubtotals.push_back( GeneralFunction_MIN );
509 if( mnSubtotals & EXC_SXVD_SUBT_PROD ) rSubtotals.push_back( GeneralFunction_PRODUCT );
510 if( mnSubtotals & EXC_SXVD_SUBT_COUNTNUM ) rSubtotals.push_back( GeneralFunction_COUNTNUMS );
511 if( mnSubtotals & EXC_SXVD_SUBT_STDDEV ) rSubtotals.push_back( GeneralFunction_STDEV );
512 if( mnSubtotals & EXC_SXVD_SUBT_STDDEVP ) rSubtotals.push_back( GeneralFunction_STDEVP );
513 if( mnSubtotals & EXC_SXVD_SUBT_VAR ) rSubtotals.push_back( GeneralFunction_VAR );
514 if( mnSubtotals & EXC_SXVD_SUBT_VARP ) rSubtotals.push_back( GeneralFunction_VARP );
517 void XclPTFieldInfo::SetSubtotals( const XclPTSubtotalVec& rSubtotals )
519 mnSubtotals = EXC_SXVD_SUBT_NONE;
520 using namespace ::com::sun::star::sheet;
521 for( XclPTSubtotalVec::const_iterator aIt = rSubtotals.begin(), aEnd = rSubtotals.end(); aIt != aEnd; ++aIt )
523 switch( *aIt )
525 case GeneralFunction_AUTO: mnSubtotals |= EXC_SXVD_SUBT_DEFAULT; break;
526 case GeneralFunction_SUM: mnSubtotals |= EXC_SXVD_SUBT_SUM; break;
527 case GeneralFunction_COUNT: mnSubtotals |= EXC_SXVD_SUBT_COUNT; break;
528 case GeneralFunction_AVERAGE: mnSubtotals |= EXC_SXVD_SUBT_AVERAGE; break;
529 case GeneralFunction_MAX: mnSubtotals |= EXC_SXVD_SUBT_MAX; break;
530 case GeneralFunction_MIN: mnSubtotals |= EXC_SXVD_SUBT_MIN; break;
531 case GeneralFunction_PRODUCT: mnSubtotals |= EXC_SXVD_SUBT_PROD; break;
532 case GeneralFunction_COUNTNUMS: mnSubtotals |= EXC_SXVD_SUBT_COUNTNUM; break;
533 case GeneralFunction_STDEV: mnSubtotals |= EXC_SXVD_SUBT_STDDEV; break;
534 case GeneralFunction_STDEVP: mnSubtotals |= EXC_SXVD_SUBT_STDDEVP; break;
535 case GeneralFunction_VAR: mnSubtotals |= EXC_SXVD_SUBT_VAR; break;
536 case GeneralFunction_VARP: mnSubtotals |= EXC_SXVD_SUBT_VARP; break;
540 mnSubtCount = 0;
541 for( sal_uInt16 nMask = 0x8000; nMask; nMask >>= 1 )
542 if( mnSubtotals & nMask )
543 ++mnSubtCount;
546 XclImpStream& operator>>( XclImpStream& rStrm, XclPTFieldInfo& rInfo )
548 // rInfo.mnCacheIdx is not part of the SXVD record
549 return rStrm
550 >> rInfo.mnAxes
551 >> rInfo.mnSubtCount
552 >> rInfo.mnSubtotals
553 >> rInfo.mnItemCount
554 >> rInfo.maVisName;
557 XclExpStream& operator<<( XclExpStream& rStrm, const XclPTFieldInfo& rInfo )
559 // rInfo.mnCacheIdx is not part of the SXVD record
560 return rStrm
561 << rInfo.mnAxes
562 << rInfo.mnSubtCount
563 << rInfo.mnSubtotals
564 << rInfo.mnItemCount
565 << rInfo.maVisName;
568 // Extended field settings ====================================================
570 XclPTFieldExtInfo::XclPTFieldExtInfo() :
571 mnFlags( EXC_SXVDEX_DEFAULTFLAGS ),
572 mnSortField( EXC_SXVDEX_SORT_OWN ),
573 mnShowField( EXC_SXVDEX_SHOW_NONE ),
574 mnNumFmt(0),
575 mpFieldTotalName(NULL)
579 sal_Int32 XclPTFieldExtInfo::GetApiSortMode() const
581 sal_Int32 nSortMode = ScDPSortMode::MANUAL;
582 if( ::get_flag( mnFlags, EXC_SXVDEX_SORT ) )
583 nSortMode = (mnSortField == EXC_SXVDEX_SORT_OWN) ? ScDPSortMode::NAME : ScDPSortMode::DATA;
584 return nSortMode;
587 void XclPTFieldExtInfo::SetApiSortMode( sal_Int32 nSortMode )
589 bool bSort = (nSortMode == ScDPSortMode::NAME) || (nSortMode == ScDPSortMode::DATA);
590 ::set_flag( mnFlags, EXC_SXVDEX_SORT, bSort );
591 if( nSortMode == ScDPSortMode::NAME )
592 mnSortField = EXC_SXVDEX_SORT_OWN; // otherwise sort field has to be set by caller
595 sal_Int32 XclPTFieldExtInfo::GetApiAutoShowMode() const
597 return ::get_flagvalue( mnFlags, EXC_SXVDEX_AUTOSHOW_ASC,
598 ScDPShowItemsMode::FROM_TOP, ScDPShowItemsMode::FROM_BOTTOM );
601 void XclPTFieldExtInfo::SetApiAutoShowMode( sal_Int32 nShowMode )
603 ::set_flag( mnFlags, EXC_SXVDEX_AUTOSHOW_ASC, nShowMode == ScDPShowItemsMode::FROM_TOP );
606 sal_Int32 XclPTFieldExtInfo::GetApiAutoShowCount() const
608 return ::extract_value< sal_Int32 >( mnFlags, 24, 8 );
611 void XclPTFieldExtInfo::SetApiAutoShowCount( sal_Int32 nShowCount )
613 ::insert_value( mnFlags, limit_cast< sal_uInt8 >( nShowCount ), 24, 8 );
616 sal_Int32 XclPTFieldExtInfo::GetApiLayoutMode() const
618 sal_Int32 nLayoutMode = ScDPLayoutMode::TABULAR_LAYOUT;
619 if( ::get_flag( mnFlags, EXC_SXVDEX_LAYOUT_REPORT ) )
620 nLayoutMode = ::get_flag( mnFlags, EXC_SXVDEX_LAYOUT_TOP ) ?
621 ScDPLayoutMode::OUTLINE_SUBTOTALS_TOP : ScDPLayoutMode::OUTLINE_SUBTOTALS_BOTTOM;
622 return nLayoutMode;
625 void XclPTFieldExtInfo::SetApiLayoutMode( sal_Int32 nLayoutMode )
627 ::set_flag( mnFlags, EXC_SXVDEX_LAYOUT_REPORT, nLayoutMode != ScDPLayoutMode::TABULAR_LAYOUT );
628 ::set_flag( mnFlags, EXC_SXVDEX_LAYOUT_TOP, nLayoutMode == ScDPLayoutMode::OUTLINE_SUBTOTALS_TOP );
631 XclImpStream& operator>>( XclImpStream& rStrm, XclPTFieldExtInfo& rInfo )
633 sal_uInt8 nNameLen = 0;
634 rStrm >> rInfo.mnFlags
635 >> rInfo.mnSortField
636 >> rInfo.mnShowField
637 >> rInfo.mnNumFmt
638 >> nNameLen;
640 rStrm.Ignore(10);
641 if (nNameLen != 0xFF)
642 // Custom field total name is used. Pick it up.
643 rInfo.mpFieldTotalName.reset(new OUString(rStrm.ReadUniString(nNameLen, 0)));
645 return rStrm;
648 XclExpStream& operator<<( XclExpStream& rStrm, const XclPTFieldExtInfo& rInfo )
650 rStrm << rInfo.mnFlags
651 << rInfo.mnSortField
652 << rInfo.mnShowField
653 << EXC_SXVDEX_FORMAT_NONE;
655 if (rInfo.mpFieldTotalName.get() && !rInfo.mpFieldTotalName->isEmpty())
657 OUString aFinalName = *rInfo.mpFieldTotalName;
658 if (aFinalName.getLength() >= 254)
659 aFinalName = aFinalName.copy(0, 254);
660 sal_uInt8 nNameLen = static_cast<sal_uInt8>(aFinalName.getLength());
661 rStrm << nNameLen;
662 rStrm.WriteZeroBytes(10);
663 rStrm << XclExpString(aFinalName, EXC_STR_NOHEADER);
665 else
667 rStrm << sal_uInt16(0xFFFF);
668 rStrm.WriteZeroBytes(8);
670 return rStrm;
673 // Page field settings ========================================================
675 XclPTPageFieldInfo::XclPTPageFieldInfo() :
676 mnField( 0 ),
677 mnSelItem( EXC_SXPI_ALLITEMS ),
678 mnObjId( 0xFFFF )
682 XclImpStream& operator>>( XclImpStream& rStrm, XclPTPageFieldInfo& rInfo )
684 return rStrm
685 >> rInfo.mnField
686 >> rInfo.mnSelItem
687 >> rInfo.mnObjId;
690 XclExpStream& operator<<( XclExpStream& rStrm, const XclPTPageFieldInfo& rInfo )
692 return rStrm
693 << rInfo.mnField
694 << rInfo.mnSelItem
695 << rInfo.mnObjId;
698 // Data field settings ========================================================
700 XclPTDataFieldInfo::XclPTDataFieldInfo() :
701 mnField( 0 ),
702 mnAggFunc( EXC_SXDI_FUNC_SUM ),
703 mnRefType( EXC_SXDI_REF_NORMAL ),
704 mnRefField( 0 ),
705 mnRefItem( 0 ),
706 mnNumFmt( 0 )
710 GeneralFunction XclPTDataFieldInfo::GetApiAggFunc() const
712 using namespace ::com::sun::star::sheet;
713 GeneralFunction eAggFunc;
714 switch( mnAggFunc )
716 case EXC_SXDI_FUNC_SUM: eAggFunc = GeneralFunction_SUM; break;
717 case EXC_SXDI_FUNC_COUNT: eAggFunc = GeneralFunction_COUNT; break;
718 case EXC_SXDI_FUNC_AVERAGE: eAggFunc = GeneralFunction_AVERAGE; break;
719 case EXC_SXDI_FUNC_MAX: eAggFunc = GeneralFunction_MAX; break;
720 case EXC_SXDI_FUNC_MIN: eAggFunc = GeneralFunction_MIN; break;
721 case EXC_SXDI_FUNC_PRODUCT: eAggFunc = GeneralFunction_PRODUCT; break;
722 case EXC_SXDI_FUNC_COUNTNUM: eAggFunc = GeneralFunction_COUNTNUMS; break;
723 case EXC_SXDI_FUNC_STDDEV: eAggFunc = GeneralFunction_STDEV; break;
724 case EXC_SXDI_FUNC_STDDEVP: eAggFunc = GeneralFunction_STDEVP; break;
725 case EXC_SXDI_FUNC_VAR: eAggFunc = GeneralFunction_VAR; break;
726 case EXC_SXDI_FUNC_VARP: eAggFunc = GeneralFunction_VARP; break;
727 default: eAggFunc = GeneralFunction_SUM;
729 return eAggFunc;
732 void XclPTDataFieldInfo::SetApiAggFunc( GeneralFunction eAggFunc )
734 using namespace ::com::sun::star::sheet;
735 switch( eAggFunc )
737 case GeneralFunction_SUM: mnAggFunc = EXC_SXDI_FUNC_SUM; break;
738 case GeneralFunction_COUNT: mnAggFunc = EXC_SXDI_FUNC_COUNT; break;
739 case GeneralFunction_AVERAGE: mnAggFunc = EXC_SXDI_FUNC_AVERAGE; break;
740 case GeneralFunction_MAX: mnAggFunc = EXC_SXDI_FUNC_MAX; break;
741 case GeneralFunction_MIN: mnAggFunc = EXC_SXDI_FUNC_MIN; break;
742 case GeneralFunction_PRODUCT: mnAggFunc = EXC_SXDI_FUNC_PRODUCT; break;
743 case GeneralFunction_COUNTNUMS: mnAggFunc = EXC_SXDI_FUNC_COUNTNUM; break;
744 case GeneralFunction_STDEV: mnAggFunc = EXC_SXDI_FUNC_STDDEV; break;
745 case GeneralFunction_STDEVP: mnAggFunc = EXC_SXDI_FUNC_STDDEVP; break;
746 case GeneralFunction_VAR: mnAggFunc = EXC_SXDI_FUNC_VAR; break;
747 case GeneralFunction_VARP: mnAggFunc = EXC_SXDI_FUNC_VARP; break;
748 default: mnAggFunc = EXC_SXDI_FUNC_SUM;
752 sal_Int32 XclPTDataFieldInfo::GetApiRefType() const
754 namespace ScDPRefType = ::com::sun::star::sheet::DataPilotFieldReferenceType;
755 sal_Int32 nRefType;
756 switch( mnRefType )
758 case EXC_SXDI_REF_DIFF: nRefType = ScDPRefType::ITEM_DIFFERENCE; break;
759 case EXC_SXDI_REF_PERC: nRefType = ScDPRefType::ITEM_PERCENTAGE; break;
760 case EXC_SXDI_REF_PERC_DIFF: nRefType = ScDPRefType::ITEM_PERCENTAGE_DIFFERENCE; break;
761 case EXC_SXDI_REF_RUN_TOTAL: nRefType = ScDPRefType::RUNNING_TOTAL; break;
762 case EXC_SXDI_REF_PERC_ROW: nRefType = ScDPRefType::ROW_PERCENTAGE; break;
763 case EXC_SXDI_REF_PERC_COL: nRefType = ScDPRefType::COLUMN_PERCENTAGE; break;
764 case EXC_SXDI_REF_PERC_TOTAL: nRefType = ScDPRefType::TOTAL_PERCENTAGE; break;
765 case EXC_SXDI_REF_INDEX: nRefType = ScDPRefType::INDEX; break;
766 default: nRefType = ScDPRefType::NONE;
768 return nRefType;
771 void XclPTDataFieldInfo::SetApiRefType( sal_Int32 nRefType )
773 namespace ScDPRefType = ::com::sun::star::sheet::DataPilotFieldReferenceType;
774 switch( nRefType )
776 case ScDPRefType::ITEM_DIFFERENCE: mnRefType = EXC_SXDI_REF_DIFF; break;
777 case ScDPRefType::ITEM_PERCENTAGE: mnRefType = EXC_SXDI_REF_PERC; break;
778 case ScDPRefType::ITEM_PERCENTAGE_DIFFERENCE: mnRefType = EXC_SXDI_REF_PERC_DIFF; break;
779 case ScDPRefType::RUNNING_TOTAL: mnRefType = EXC_SXDI_REF_RUN_TOTAL; break;
780 case ScDPRefType::ROW_PERCENTAGE: mnRefType = EXC_SXDI_REF_PERC_ROW; break;
781 case ScDPRefType::COLUMN_PERCENTAGE: mnRefType = EXC_SXDI_REF_PERC_COL; break;
782 case ScDPRefType::TOTAL_PERCENTAGE: mnRefType = EXC_SXDI_REF_PERC_TOTAL;break;
783 case ScDPRefType::INDEX: mnRefType = EXC_SXDI_REF_INDEX; break;
784 default: mnRefType = EXC_SXDI_REF_NORMAL;
788 sal_Int32 XclPTDataFieldInfo::GetApiRefItemType() const
790 sal_Int32 nRefItemType;
791 switch( mnRefItem )
793 case EXC_SXDI_PREVITEM: nRefItemType = ScDPRefItemType::PREVIOUS; break;
794 case EXC_SXDI_NEXTITEM: nRefItemType = ScDPRefItemType::NEXT; break;
795 default: nRefItemType = ScDPRefItemType::NAMED;
797 return nRefItemType;
800 void XclPTDataFieldInfo::SetApiRefItemType( sal_Int32 nRefItemType )
802 switch( nRefItemType )
804 case ScDPRefItemType::PREVIOUS: mnRefItem = EXC_SXDI_PREVITEM; break;
805 case ScDPRefItemType::NEXT: mnRefItem = EXC_SXDI_NEXTITEM; break;
806 // nothing for named item reference
810 XclImpStream& operator>>( XclImpStream& rStrm, XclPTDataFieldInfo& rInfo )
812 return rStrm
813 >> rInfo.mnField
814 >> rInfo.mnAggFunc
815 >> rInfo.mnRefType
816 >> rInfo.mnRefField
817 >> rInfo.mnRefItem
818 >> rInfo.mnNumFmt
819 >> rInfo.maVisName;
822 XclExpStream& operator<<( XclExpStream& rStrm, const XclPTDataFieldInfo& rInfo )
824 return rStrm
825 << rInfo.mnField
826 << rInfo.mnAggFunc
827 << rInfo.mnRefType
828 << rInfo.mnRefField
829 << rInfo.mnRefItem
830 << rInfo.mnNumFmt
831 << rInfo.maVisName;
834 // Pivot table settings =======================================================
836 XclPTInfo::XclPTInfo() :
837 mnFirstHeadRow( 0 ),
838 mnCacheIdx( 0xFFFF ),
839 mnDataAxis( EXC_SXVD_AXIS_NONE ),
840 mnDataPos( EXC_SXVIEW_DATALAST ),
841 mnFields( 0 ),
842 mnRowFields( 0 ),
843 mnColFields( 0 ),
844 mnPageFields( 0 ),
845 mnDataFields( 0 ),
846 mnDataRows( 0 ),
847 mnDataCols( 0 ),
848 mnFlags( EXC_SXVIEW_DEFAULTFLAGS ),
849 mnAutoFmtIdx( EXC_SXVIEW_AUTOFMT )
853 XclImpStream& operator>>( XclImpStream& rStrm, XclPTInfo& rInfo )
855 sal_uInt16 nTabLen, nDataLen;
857 rStrm >> rInfo.maOutXclRange
858 >> rInfo.mnFirstHeadRow
859 >> rInfo.maDataXclPos
860 >> rInfo.mnCacheIdx;
861 rStrm.Ignore( 2 );
862 rStrm >> rInfo.mnDataAxis >> rInfo.mnDataPos
863 >> rInfo.mnFields
864 >> rInfo.mnRowFields >> rInfo.mnColFields
865 >> rInfo.mnPageFields >> rInfo.mnDataFields
866 >> rInfo.mnDataRows >> rInfo.mnDataCols
867 >> rInfo.mnFlags
868 >> rInfo.mnAutoFmtIdx
869 >> nTabLen >> nDataLen;
870 rInfo.maTableName = rStrm.ReadUniString( nTabLen );
871 rInfo.maDataName = rStrm.ReadUniString( nDataLen );
872 return rStrm;
875 XclExpStream& operator<<( XclExpStream& rStrm, const XclPTInfo& rInfo )
877 XclExpString aXclTableName( rInfo.maTableName );
878 XclExpString aXclDataName( rInfo.maDataName );
880 rStrm << rInfo.maOutXclRange
881 << rInfo.mnFirstHeadRow
882 << rInfo.maDataXclPos
883 << rInfo.mnCacheIdx
884 << sal_uInt16( 0 )
885 << rInfo.mnDataAxis << rInfo.mnDataPos
886 << rInfo.mnFields
887 << rInfo.mnRowFields << rInfo.mnColFields
888 << rInfo.mnPageFields << rInfo.mnDataFields
889 << rInfo.mnDataRows << rInfo.mnDataCols
890 << rInfo.mnFlags
891 << rInfo.mnAutoFmtIdx
892 << aXclTableName.Len() << aXclDataName.Len();
893 aXclTableName.WriteFlagField( rStrm );
894 aXclTableName.WriteBuffer( rStrm );
895 aXclDataName.WriteFlagField( rStrm );
896 aXclDataName.WriteBuffer( rStrm );
897 return rStrm;
900 // Extended pivot table settings ==============================================
902 XclPTExtInfo::XclPTExtInfo() :
903 mnSxformulaRecs( 0 ),
904 mnSxselectRecs( 0 ),
905 mnPagePerRow( 0 ),
906 mnPagePerCol( 0 ),
907 mnFlags( EXC_SXEX_DEFAULTFLAGS )
911 XclImpStream& operator>>( XclImpStream& rStrm, XclPTExtInfo& rInfo )
913 rStrm >> rInfo.mnSxformulaRecs;
914 rStrm.Ignore( 6 );
915 return rStrm
916 >> rInfo.mnSxselectRecs
917 >> rInfo.mnPagePerRow
918 >> rInfo.mnPagePerCol
919 >> rInfo.mnFlags;
922 XclExpStream& operator<<( XclExpStream& rStrm, const XclPTExtInfo& rInfo )
924 return rStrm
925 << rInfo.mnSxformulaRecs
926 << EXC_PT_NOSTRING // length of alt. error text
927 << EXC_PT_NOSTRING // length of alt. empty text
928 << EXC_PT_NOSTRING // length of tag
929 << rInfo.mnSxselectRecs
930 << rInfo.mnPagePerRow
931 << rInfo.mnPagePerCol
932 << rInfo.mnFlags
933 << EXC_PT_NOSTRING // length of page field style name
934 << EXC_PT_NOSTRING // length of table style name
935 << EXC_PT_NOSTRING; // length of vacate style name
938 // ============================================================================
940 // Pivot table autoformat settings ============================================
943 classic : 10 08 00 00 00 00 00 00 20 00 00 00 01 00 00 00 00
944 default : 10 08 00 00 00 00 00 00 20 00 00 00 01 00 00 00 00
945 report01 : 10 08 02 00 00 00 00 00 20 00 00 00 00 10 00 00 00
946 report02 : 10 08 02 00 00 00 00 00 20 00 00 00 01 10 00 00 00
947 report03 : 10 08 02 00 00 00 00 00 20 00 00 00 02 10 00 00 00
948 report04 : 10 08 02 00 00 00 00 00 20 00 00 00 03 10 00 00 00
949 report05 : 10 08 02 00 00 00 00 00 20 00 00 00 04 10 00 00 00
950 report06 : 10 08 02 00 00 00 00 00 20 00 00 00 05 10 00 00 00
951 report07 : 10 08 02 00 00 00 00 00 20 00 00 00 06 10 00 00 00
952 report08 : 10 08 02 00 00 00 00 00 20 00 00 00 07 10 00 00 00
953 report09 : 10 08 02 00 00 00 00 00 20 00 00 00 08 10 00 00 00
954 report10 : 10 08 02 00 00 00 00 00 20 00 00 00 09 10 00 00 00
955 table01 : 10 08 00 00 00 00 00 00 20 00 00 00 0a 10 00 00 00
956 table02 : 10 08 00 00 00 00 00 00 20 00 00 00 0b 10 00 00 00
957 table03 : 10 08 00 00 00 00 00 00 20 00 00 00 0c 10 00 00 00
958 table04 : 10 08 00 00 00 00 00 00 20 00 00 00 0d 10 00 00 00
959 table05 : 10 08 00 00 00 00 00 00 20 00 00 00 0e 10 00 00 00
960 table06 : 10 08 00 00 00 00 00 00 20 00 00 00 0f 10 00 00 00
961 table07 : 10 08 00 00 00 00 00 00 20 00 00 00 10 10 00 00 00
962 table08 : 10 08 00 00 00 00 00 00 20 00 00 00 11 10 00 00 00
963 table09 : 10 08 00 00 00 00 00 00 20 00 00 00 12 10 00 00 00
964 table10 : 10 08 00 00 00 00 00 00 20 00 00 00 13 10 00 00 00
965 none : 10 08 00 00 00 00 00 00 20 00 00 00 15 10 00 00 00
968 XclPTViewEx9Info::XclPTViewEx9Info() :
969 mbReport( 0 ),
970 mnAutoFormat( 0 ),
971 mnGridLayout( 0x10 )
975 void XclPTViewEx9Info::Init( const ScDPObject& rDPObj )
977 if( rDPObj.GetHeaderLayout() )
979 mbReport = 0;
980 mnAutoFormat = 1;
981 mnGridLayout = 0;
983 else
985 // Report1 for now
986 // TODO : sync with autoformat indicies
987 mbReport = 2;
988 mnAutoFormat = 1;
989 mnGridLayout = 0x10;
992 const ScDPSaveData* pData = rDPObj.GetSaveData();
993 if (pData)
995 const OUString* pGrandTotal = pData->GetGrandTotalName();
996 if (pGrandTotal)
997 maGrandTotalName = *pGrandTotal;
1001 XclImpStream& operator>>( XclImpStream& rStrm, XclPTViewEx9Info& rInfo )
1003 rStrm.Ignore( 2 );
1004 rStrm >> rInfo.mbReport; /// 2 for report* fmts ?
1005 rStrm.Ignore( 6 );
1006 rStrm >> rInfo.mnAutoFormat >> rInfo.mnGridLayout;
1007 rInfo.maGrandTotalName = rStrm.ReadUniString();
1008 return rStrm;
1011 XclExpStream& operator<<( XclExpStream& rStrm, const XclPTViewEx9Info& rInfo )
1013 return rStrm
1014 << EXC_PT_AUTOFMT_HEADER
1015 << rInfo.mbReport
1016 << EXC_PT_AUTOFMT_ZERO
1017 << EXC_PT_AUTOFMT_FLAGS
1018 << rInfo.mnAutoFormat
1019 << rInfo.mnGridLayout
1020 << XclExpString(rInfo.maGrandTotalName, EXC_STR_DEFAULT, EXC_PT_MAXSTRLEN);
1023 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */