1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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"
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 // ============================================================================
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
;
57 void XclPCItem::SetText( const OUString
& rText
)
59 meType
= EXC_PCITEM_TEXT
;
63 void XclPCItem::SetDouble( double fValue
)
65 meType
= EXC_PCITEM_DOUBLE
;
66 //! TODO convert double to string
71 void XclPCItem::SetDateTime( const DateTime
& rDateTime
)
73 meType
= EXC_PCITEM_DATETIME
;
74 //! TODO convert date to string
76 maDateTime
= rDateTime
;
79 void XclPCItem::SetInteger( sal_Int16 nValue
)
81 meType
= EXC_PCITEM_INTEGER
;
82 maText
= OUString::number(nValue
);
86 void XclPCItem::SetError( sal_uInt16 nError
)
88 meType
= EXC_PCITEM_ERROR
;
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;
104 void XclPCItem::SetBool( bool bValue
)
106 meType
= EXC_PCITEM_BOOL
;
107 //! TODO convert boolean to string
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" );
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() :
179 XclImpStream
& operator>>( XclImpStream
& rStrm
, XclPCFieldInfo
& rInfo
)
181 rStrm
>> rInfo
.mnFlags
182 >> rInfo
.mnGroupChild
185 >> rInfo
.mnGroupItems
187 >> rInfo
.mnOrigItems
;
188 if( rStrm
.GetRecLeft() >= 3 )
189 rInfo
.maName
= rStrm
.ReadUniString();
191 rInfo
.maName
= OUString();
195 XclExpStream
& operator<<( XclExpStream
& rStrm
, const XclPCFieldInfo
& rInfo
)
199 << rInfo
.mnGroupChild
202 << rInfo
.mnGroupItems
205 << XclExpString( rInfo
.maName
);
208 // Numeric grouping field settings ============================================
210 XclPCNumGroupInfo::XclPCNumGroupInfo() :
211 mnFlags( EXC_SXNUMGROUP_AUTOMIN
| EXC_SXNUMGROUP_AUTOMAX
)
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() );
238 void XclPCNumGroupInfo::SetScDateType( sal_Int32 nScType
)
240 sal_uInt16 nXclType
= EXC_SXNUMGROUP_TYPE_NUM
;
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() :
353 mnFlags( EXC_SXDB_DEFAULTFLAGS
),
354 mnBlockRecs( EXC_SXDB_BLOCKRECS
),
357 mnSrcType( EXC_SXDB_SRC_SHEET
)
361 XclImpStream
& operator>>( XclImpStream
& rStrm
, XclPCInfo
& rInfo
)
363 rStrm
>> rInfo
.mnSrcRecs
368 >> rInfo
.mnTotalFields
;
370 rStrm
>> rInfo
.mnSrcType
;
371 rInfo
.maUserName
= rStrm
.ReadUniString();
375 XclExpStream
& operator<<( XclExpStream
& rStrm
, const XclPCInfo
& rInfo
)
383 << rInfo
.mnTotalFields
386 << XclExpString( rInfo
.maUserName
);
389 // ============================================================================
391 // ============================================================================
393 // cached name ================================================================
395 XclImpStream
& operator>>( XclImpStream
& rStrm
, XclPTCachedName
& rCachedName
)
399 rCachedName
.mbUseCache
= nStrLen
== EXC_PT_NOSTRING
;
400 if( rCachedName
.mbUseCache
)
401 rCachedName
.maName
= OUString();
403 rCachedName
.maName
= rStrm
.ReadUniString( nStrLen
);
407 XclExpStream
& operator<<( XclExpStream
& rStrm
, const XclPTCachedName
& rCachedName
)
409 if( rCachedName
.mbUseCache
)
410 rStrm
<< EXC_PT_NOSTRING
;
412 rStrm
<< XclExpString( rCachedName
.maName
, EXC_STR_DEFAULT
, EXC_PT_MAXSTRLEN
);
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
)
447 XclExpStream
& operator<<( XclExpStream
& rStrm
, const XclPTItemInfo
& rInfo
)
456 // General field settings =====================================================
458 XclPTFieldInfo::XclPTFieldInfo() :
459 mnAxes( EXC_SXVD_AXIS_NONE
),
461 mnSubtotals( EXC_SXVD_SUBT_DEFAULT
),
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
;
483 void XclPTFieldInfo::AddApiOrient( DataPilotFieldOrientation eOrient
)
485 using namespace ::com::sun::star::sheet
;
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;
496 //! TODO: should be a Sequence<GeneralFunction> in ScDPSaveData
497 void XclPTFieldInfo::GetSubtotals( XclPTSubtotalVec
& rSubtotals
) const
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
)
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;
541 for( sal_uInt16 nMask
= 0x8000; nMask
; nMask
>>= 1 )
542 if( mnSubtotals
& nMask
)
546 XclImpStream
& operator>>( XclImpStream
& rStrm
, XclPTFieldInfo
& rInfo
)
548 // rInfo.mnCacheIdx is not part of the SXVD record
557 XclExpStream
& operator<<( XclExpStream
& rStrm
, const XclPTFieldInfo
& rInfo
)
559 // rInfo.mnCacheIdx is not part of the SXVD record
568 // Extended field settings ====================================================
570 XclPTFieldExtInfo::XclPTFieldExtInfo() :
571 mnFlags( EXC_SXVDEX_DEFAULTFLAGS
),
572 mnSortField( EXC_SXVDEX_SORT_OWN
),
573 mnShowField( EXC_SXVDEX_SHOW_NONE
),
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
;
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
;
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
641 if (nNameLen
!= 0xFF)
642 // Custom field total name is used. Pick it up.
643 rInfo
.mpFieldTotalName
.reset(new OUString(rStrm
.ReadUniString(nNameLen
, 0)));
648 XclExpStream
& operator<<( XclExpStream
& rStrm
, const XclPTFieldExtInfo
& rInfo
)
650 rStrm
<< rInfo
.mnFlags
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());
662 rStrm
.WriteZeroBytes(10);
663 rStrm
<< XclExpString(aFinalName
, EXC_STR_NOHEADER
);
667 rStrm
<< sal_uInt16(0xFFFF);
668 rStrm
.WriteZeroBytes(8);
673 // Page field settings ========================================================
675 XclPTPageFieldInfo::XclPTPageFieldInfo() :
677 mnSelItem( EXC_SXPI_ALLITEMS
),
682 XclImpStream
& operator>>( XclImpStream
& rStrm
, XclPTPageFieldInfo
& rInfo
)
690 XclExpStream
& operator<<( XclExpStream
& rStrm
, const XclPTPageFieldInfo
& rInfo
)
698 // Data field settings ========================================================
700 XclPTDataFieldInfo::XclPTDataFieldInfo() :
702 mnAggFunc( EXC_SXDI_FUNC_SUM
),
703 mnRefType( EXC_SXDI_REF_NORMAL
),
710 GeneralFunction
XclPTDataFieldInfo::GetApiAggFunc() const
712 using namespace ::com::sun::star::sheet
;
713 GeneralFunction eAggFunc
;
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
;
732 void XclPTDataFieldInfo::SetApiAggFunc( GeneralFunction eAggFunc
)
734 using namespace ::com::sun::star::sheet
;
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
;
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
;
771 void XclPTDataFieldInfo::SetApiRefType( sal_Int32 nRefType
)
773 namespace ScDPRefType
= ::com::sun::star::sheet::DataPilotFieldReferenceType
;
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
;
793 case EXC_SXDI_PREVITEM
: nRefItemType
= ScDPRefItemType::PREVIOUS
; break;
794 case EXC_SXDI_NEXTITEM
: nRefItemType
= ScDPRefItemType::NEXT
; break;
795 default: nRefItemType
= ScDPRefItemType::NAMED
;
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
)
822 XclExpStream
& operator<<( XclExpStream
& rStrm
, const XclPTDataFieldInfo
& rInfo
)
834 // Pivot table settings =======================================================
836 XclPTInfo::XclPTInfo() :
838 mnCacheIdx( 0xFFFF ),
839 mnDataAxis( EXC_SXVD_AXIS_NONE
),
840 mnDataPos( EXC_SXVIEW_DATALAST
),
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
862 rStrm
>> rInfo
.mnDataAxis
>> rInfo
.mnDataPos
864 >> rInfo
.mnRowFields
>> rInfo
.mnColFields
865 >> rInfo
.mnPageFields
>> rInfo
.mnDataFields
866 >> rInfo
.mnDataRows
>> rInfo
.mnDataCols
868 >> rInfo
.mnAutoFmtIdx
869 >> nTabLen
>> nDataLen
;
870 rInfo
.maTableName
= rStrm
.ReadUniString( nTabLen
);
871 rInfo
.maDataName
= rStrm
.ReadUniString( nDataLen
);
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
885 << rInfo
.mnDataAxis
<< rInfo
.mnDataPos
887 << rInfo
.mnRowFields
<< rInfo
.mnColFields
888 << rInfo
.mnPageFields
<< rInfo
.mnDataFields
889 << rInfo
.mnDataRows
<< rInfo
.mnDataCols
891 << rInfo
.mnAutoFmtIdx
892 << aXclTableName
.Len() << aXclDataName
.Len();
893 aXclTableName
.WriteFlagField( rStrm
);
894 aXclTableName
.WriteBuffer( rStrm
);
895 aXclDataName
.WriteFlagField( rStrm
);
896 aXclDataName
.WriteBuffer( rStrm
);
900 // Extended pivot table settings ==============================================
902 XclPTExtInfo::XclPTExtInfo() :
903 mnSxformulaRecs( 0 ),
907 mnFlags( EXC_SXEX_DEFAULTFLAGS
)
911 XclImpStream
& operator>>( XclImpStream
& rStrm
, XclPTExtInfo
& rInfo
)
913 rStrm
>> rInfo
.mnSxformulaRecs
;
916 >> rInfo
.mnSxselectRecs
917 >> rInfo
.mnPagePerRow
918 >> rInfo
.mnPagePerCol
922 XclExpStream
& operator<<( XclExpStream
& rStrm
, const XclPTExtInfo
& rInfo
)
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
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() :
975 void XclPTViewEx9Info::Init( const ScDPObject
& rDPObj
)
977 if( rDPObj
.GetHeaderLayout() )
986 // TODO : sync with autoformat indicies
992 const ScDPSaveData
* pData
= rDPObj
.GetSaveData();
995 const OUString
* pGrandTotal
= pData
->GetGrandTotalName();
997 maGrandTotalName
= *pGrandTotal
;
1001 XclImpStream
& operator>>( XclImpStream
& rStrm
, XclPTViewEx9Info
& rInfo
)
1004 rStrm
>> rInfo
.mbReport
; /// 2 for report* fmts ?
1006 rStrm
>> rInfo
.mnAutoFormat
>> rInfo
.mnGridLayout
;
1007 rInfo
.maGrandTotalName
= rStrm
.ReadUniString();
1011 XclExpStream
& operator<<( XclExpStream
& rStrm
, const XclPTViewEx9Info
& rInfo
)
1014 << EXC_PT_AUTOFMT_HEADER
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: */