update dev300-m58
[ooovba.git] / sc / source / filter / excel / xlpivot.cxx
blobc9159035085c399d1a65d64373c1d8d9ff05d3ad
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: xlpivot.cxx,v $
10 * $Revision: 1.12.32.2 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sc.hxx"
33 #include "dpgroup.hxx"
34 #include "dpsave.hxx"
35 #include "xestream.hxx"
36 #include "xistream.hxx"
37 #include "xestring.hxx"
38 #include "xlpivot.hxx"
39 #include <com/sun/star/sheet/DataPilotFieldGroupBy.hpp>
41 using ::com::sun::star::sheet::GeneralFunction;
42 using ::com::sun::star::sheet::DataPilotFieldOrientation;
44 namespace ScDPSortMode = ::com::sun::star::sheet::DataPilotFieldSortMode;
45 namespace ScDPShowItemsMode = ::com::sun::star::sheet::DataPilotFieldShowItemsMode;
46 namespace ScDPLayoutMode = ::com::sun::star::sheet::DataPilotFieldLayoutMode;
47 namespace ScDPRefItemType = ::com::sun::star::sheet::DataPilotFieldReferenceItemType;
48 namespace ScDPGroupBy = ::com::sun::star::sheet::DataPilotFieldGroupBy;
50 // ============================================================================
51 // Pivot cache
52 // ============================================================================
54 XclPCItem::XclPCItem() :
55 meType( EXC_PCITEM_INVALID )
59 XclPCItem::~XclPCItem()
63 void XclPCItem::SetEmpty()
65 meType = EXC_PCITEM_EMPTY;
66 maText.Erase();
69 void XclPCItem::SetText( const String& rText )
71 meType = EXC_PCITEM_TEXT;
72 maText = rText;
75 void XclPCItem::SetDouble( double fValue )
77 meType = EXC_PCITEM_DOUBLE;
78 //! TODO convert double to string
79 maText.Erase();
80 mfValue = fValue;
83 void XclPCItem::SetDateTime( const DateTime& rDateTime )
85 meType = EXC_PCITEM_DATETIME;
86 //! TODO convert date to string
87 maText.Erase();
88 maDateTime = rDateTime;
91 void XclPCItem::SetInteger( sal_Int16 nValue )
93 meType = EXC_PCITEM_INTEGER;
94 maText = String::CreateFromInt32( nValue );
95 mnValue = nValue;
98 void XclPCItem::SetError( sal_uInt16 nError )
100 meType = EXC_PCITEM_ERROR;
101 //! TODO convert error to string
102 maText.Erase();
103 mnError = nError;
106 void XclPCItem::SetBool( bool bValue )
108 meType = EXC_PCITEM_BOOL;
109 //! TODO convert boolean to string
110 maText.Erase();
111 mbValue = bValue;
114 // ----------------------------------------------------------------------------
116 bool XclPCItem::IsEqual( const XclPCItem& rItem ) const
118 if( meType == rItem.meType ) switch( meType )
120 case EXC_PCITEM_INVALID: return true;
121 case EXC_PCITEM_EMPTY: return true;
122 case EXC_PCITEM_TEXT: return maText == rItem.maText;
123 case EXC_PCITEM_DOUBLE: return mfValue == rItem.mfValue;
124 case EXC_PCITEM_DATETIME: return maDateTime == rItem.maDateTime;
125 case EXC_PCITEM_INTEGER: return mnValue == rItem.mnValue;
126 case EXC_PCITEM_BOOL: return mbValue == rItem.mbValue;
127 case EXC_PCITEM_ERROR: return mnError == rItem.mnError;
128 default: DBG_ERRORFILE( "XclPCItem::IsEqual - unknown pivot cache item type" );
130 return false;
133 bool XclPCItem::IsEmpty() const
135 return meType == EXC_PCITEM_EMPTY;
138 const String* XclPCItem::GetText() const
140 return (meType == EXC_PCITEM_TEXT) ? &maText : 0;
143 const double* XclPCItem::GetDouble() const
145 return (meType == EXC_PCITEM_DOUBLE) ? &mfValue : 0;
148 const DateTime* XclPCItem::GetDateTime() const
150 return (meType == EXC_PCITEM_DATETIME) ? &maDateTime : 0;
153 const sal_Int16* XclPCItem::GetInteger() const
155 return (meType == EXC_PCITEM_INTEGER) ? &mnValue : 0;
158 const sal_uInt16* XclPCItem::GetError() const
160 return (meType == EXC_PCITEM_ERROR) ? &mnError : 0;
163 const bool* XclPCItem::GetBool() const
165 return (meType == EXC_PCITEM_BOOL) ? &mbValue : 0;
168 // Field settings =============================================================
170 XclPCFieldInfo::XclPCFieldInfo() :
171 mnFlags( 0 ),
172 mnGroupChild( 0 ),
173 mnGroupBase( 0 ),
174 mnVisItems( 0 ),
175 mnGroupItems( 0 ),
176 mnBaseItems( 0 ),
177 mnOrigItems( 0 )
181 XclImpStream& operator>>( XclImpStream& rStrm, XclPCFieldInfo& rInfo )
183 rStrm >> rInfo.mnFlags
184 >> rInfo.mnGroupChild
185 >> rInfo.mnGroupBase
186 >> rInfo.mnVisItems
187 >> rInfo.mnGroupItems
188 >> rInfo.mnBaseItems
189 >> rInfo.mnOrigItems;
190 if( rStrm.GetRecLeft() >= 3 )
191 rInfo.maName = rStrm.ReadUniString();
192 else
193 rInfo.maName.Erase();
194 return rStrm;
197 XclExpStream& operator<<( XclExpStream& rStrm, const XclPCFieldInfo& rInfo )
199 return rStrm
200 << rInfo.mnFlags
201 << rInfo.mnGroupChild
202 << rInfo.mnGroupBase
203 << rInfo.mnVisItems
204 << rInfo.mnGroupItems
205 << rInfo.mnBaseItems
206 << rInfo.mnOrigItems
207 << XclExpString( rInfo.maName );
210 // Numeric grouping field settings ============================================
212 XclPCNumGroupInfo::XclPCNumGroupInfo() :
213 mnFlags( EXC_SXNUMGROUP_AUTOMIN | EXC_SXNUMGROUP_AUTOMAX )
215 SetNumType();
218 void XclPCNumGroupInfo::SetNumType()
220 SetXclDataType( EXC_SXNUMGROUP_TYPE_NUM );
223 sal_Int32 XclPCNumGroupInfo::GetScDateType() const
225 sal_Int32 nScType = 0;
226 switch( GetXclDataType() )
228 case EXC_SXNUMGROUP_TYPE_SEC: nScType = ScDPGroupBy::SECONDS; break;
229 case EXC_SXNUMGROUP_TYPE_MIN: nScType = ScDPGroupBy::MINUTES; break;
230 case EXC_SXNUMGROUP_TYPE_HOUR: nScType = ScDPGroupBy::HOURS; break;
231 case EXC_SXNUMGROUP_TYPE_DAY: nScType = ScDPGroupBy::DAYS; break;
232 case EXC_SXNUMGROUP_TYPE_MONTH: nScType = ScDPGroupBy::MONTHS; break;
233 case EXC_SXNUMGROUP_TYPE_QUART: nScType = ScDPGroupBy::QUARTERS; break;
234 case EXC_SXNUMGROUP_TYPE_YEAR: nScType = ScDPGroupBy::YEARS; break;
235 default: DBG_ERROR1( "XclPCNumGroupInfo::GetScDateType - unexpected date type %d", GetXclDataType() );
237 return nScType;
240 void XclPCNumGroupInfo::SetScDateType( sal_Int32 nScType )
242 sal_uInt16 nXclType = EXC_SXNUMGROUP_TYPE_NUM;
243 switch( nScType )
245 case ScDPGroupBy::SECONDS: nXclType = EXC_SXNUMGROUP_TYPE_SEC; break;
246 case ScDPGroupBy::MINUTES: nXclType = EXC_SXNUMGROUP_TYPE_MIN; break;
247 case ScDPGroupBy::HOURS: nXclType = EXC_SXNUMGROUP_TYPE_HOUR; break;
248 case ScDPGroupBy::DAYS: nXclType = EXC_SXNUMGROUP_TYPE_DAY; break;
249 case ScDPGroupBy::MONTHS: nXclType = EXC_SXNUMGROUP_TYPE_MONTH; break;
250 case ScDPGroupBy::QUARTERS: nXclType = EXC_SXNUMGROUP_TYPE_QUART; break;
251 case ScDPGroupBy::YEARS: nXclType = EXC_SXNUMGROUP_TYPE_YEAR; break;
252 default: DBG_ERROR1( "XclPCNumGroupInfo::SetScDateType - unexpected date type %d", nScType );
254 SetXclDataType( nXclType );
257 sal_uInt16 XclPCNumGroupInfo::GetXclDataType() const
259 return ::extract_value< sal_uInt16 >( mnFlags, 2, 4 );
262 void XclPCNumGroupInfo::SetXclDataType( sal_uInt16 nXclType )
264 ::insert_value( mnFlags, nXclType, 2, 4 );
267 XclImpStream& operator>>( XclImpStream& rStrm, XclPCNumGroupInfo& rInfo )
269 return rStrm >> rInfo.mnFlags;
272 XclExpStream& operator<<( XclExpStream& rStrm, const XclPCNumGroupInfo& rInfo )
274 return rStrm << rInfo.mnFlags;
277 // Base class for pivot cache fields ==========================================
279 XclPCField::XclPCField( XclPCFieldType eFieldType, sal_uInt16 nFieldIdx ) :
280 meFieldType( eFieldType ),
281 mnFieldIdx( nFieldIdx )
285 XclPCField::~XclPCField()
289 bool XclPCField::IsSupportedField() const
291 return (meFieldType != EXC_PCFIELD_CALCED) && (meFieldType != EXC_PCFIELD_UNKNOWN);
294 bool XclPCField::IsStandardField() const
296 return meFieldType == EXC_PCFIELD_STANDARD;
299 //UNUSED2008-05 bool XclPCField::IsCalculatedField() const
300 //UNUSED2008-05 {
301 //UNUSED2008-05 return meFieldType == EXC_PCFIELD_CALCED;
302 //UNUSED2008-05 }
304 bool XclPCField::IsStdGroupField() const
306 return meFieldType == EXC_PCFIELD_STDGROUP;
309 bool XclPCField::IsNumGroupField() const
311 return meFieldType == EXC_PCFIELD_NUMGROUP;
314 bool XclPCField::IsDateGroupField() const
316 return (meFieldType == EXC_PCFIELD_DATEGROUP) || (meFieldType == EXC_PCFIELD_DATECHILD);
319 bool XclPCField::IsGroupField() const
321 return IsStdGroupField() || IsNumGroupField() || IsDateGroupField();
324 bool XclPCField::IsGroupBaseField() const
326 return ::get_flag( maFieldInfo.mnFlags, EXC_SXFIELD_HASCHILD );
329 bool XclPCField::IsGroupChildField() const
331 return (meFieldType == EXC_PCFIELD_STDGROUP) || (meFieldType == EXC_PCFIELD_DATECHILD);
334 sal_uInt16 XclPCField::GetBaseFieldIndex() const
336 return IsGroupChildField() ? maFieldInfo.mnGroupBase : mnFieldIdx;
339 bool XclPCField::HasOrigItems() const
341 return IsSupportedField() && ((maFieldInfo.mnOrigItems > 0) || HasPostponedItems());
344 bool XclPCField::HasInlineItems() const
346 return (IsStandardField() || IsGroupField()) && ((maFieldInfo.mnGroupItems > 0) || (maFieldInfo.mnOrigItems > 0));
349 bool XclPCField::HasPostponedItems() const
351 return IsStandardField() && ::get_flag( maFieldInfo.mnFlags, EXC_SXFIELD_POSTPONE );
354 bool XclPCField::Has16BitIndexes() const
356 return IsStandardField() && ::get_flag( maFieldInfo.mnFlags, EXC_SXFIELD_16BIT );
359 // Pivot cache settings =======================================================
361 /** Contains data for a pivot cache (SXDB record). */
362 XclPCInfo::XclPCInfo() :
363 mnSrcRecs( 0 ),
364 mnStrmId( 0xFFFF ),
365 mnFlags( EXC_SXDB_DEFAULTFLAGS ),
366 mnBlockRecs( EXC_SXDB_BLOCKRECS ),
367 mnStdFields( 0 ),
368 mnTotalFields( 0 ),
369 mnSrcType( EXC_SXDB_SRC_SHEET )
373 XclImpStream& operator>>( XclImpStream& rStrm, XclPCInfo& rInfo )
375 rStrm >> rInfo.mnSrcRecs
376 >> rInfo.mnStrmId
377 >> rInfo.mnFlags
378 >> rInfo.mnBlockRecs
379 >> rInfo.mnStdFields
380 >> rInfo.mnTotalFields;
381 rStrm.Ignore( 2 );
382 rStrm >> rInfo.mnSrcType;
383 rInfo.maUserName = rStrm.ReadUniString();
384 return rStrm;
387 XclExpStream& operator<<( XclExpStream& rStrm, const XclPCInfo& rInfo )
389 return rStrm
390 << rInfo.mnSrcRecs
391 << rInfo.mnStrmId
392 << rInfo.mnFlags
393 << rInfo.mnBlockRecs
394 << rInfo.mnStdFields
395 << rInfo.mnTotalFields
396 << sal_uInt16( 0 )
397 << rInfo.mnSrcType
398 << XclExpString( rInfo.maUserName );
401 // ============================================================================
402 // Pivot table
403 // ============================================================================
405 // cached name ================================================================
407 XclImpStream& operator>>( XclImpStream& rStrm, XclPTCachedName& rCachedName )
409 sal_uInt16 nStrLen;
410 rStrm >> nStrLen;
411 rCachedName.mbUseCache = nStrLen == EXC_PT_NOSTRING;
412 if( rCachedName.mbUseCache )
413 rCachedName.maName.Erase();
414 else
415 rCachedName.maName = rStrm.ReadUniString( nStrLen );
416 return rStrm;
419 XclExpStream& operator<<( XclExpStream& rStrm, const XclPTCachedName& rCachedName )
421 if( rCachedName.mbUseCache )
422 rStrm << EXC_PT_NOSTRING;
423 else
424 rStrm << XclExpString( rCachedName.maName, EXC_STR_DEFAULT, EXC_PT_MAXSTRLEN );
425 return rStrm;
428 // ----------------------------------------------------------------------------
430 const String* XclPTVisNameInfo::GetVisName() const
432 return HasVisName() ? &maVisName.maName : 0;
435 void XclPTVisNameInfo::SetVisName( const String& rName )
437 maVisName.maName = rName;
438 maVisName.mbUseCache = rName.Len() == 0;
441 // Field item settings ========================================================
443 XclPTItemInfo::XclPTItemInfo() :
444 mnType( EXC_SXVI_TYPE_DATA ),
445 mnFlags( EXC_SXVI_DEFAULTFLAGS ),
446 mnCacheIdx( EXC_SXVI_DEFAULT_CACHE )
450 XclImpStream& operator>>( XclImpStream& rStrm, XclPTItemInfo& rInfo )
452 return rStrm
453 >> rInfo.mnType
454 >> rInfo.mnFlags
455 >> rInfo.mnCacheIdx
456 >> rInfo.maVisName;
459 XclExpStream& operator<<( XclExpStream& rStrm, const XclPTItemInfo& rInfo )
461 return rStrm
462 << rInfo.mnType
463 << rInfo.mnFlags
464 << rInfo.mnCacheIdx
465 << rInfo.maVisName;
468 // General field settings =====================================================
470 XclPTFieldInfo::XclPTFieldInfo() :
471 mnAxes( EXC_SXVD_AXIS_NONE ),
472 mnSubtCount( 1 ),
473 mnSubtotals( EXC_SXVD_SUBT_DEFAULT ),
474 mnItemCount( 0 ),
475 mnCacheIdx( EXC_SXVD_DEFAULT_CACHE )
479 DataPilotFieldOrientation XclPTFieldInfo::GetApiOrient( sal_uInt16 nMask ) const
481 using namespace ::com::sun::star::sheet;
482 DataPilotFieldOrientation eOrient = DataPilotFieldOrientation_HIDDEN;
483 sal_uInt16 nUsedAxes = mnAxes & nMask;
484 if( nUsedAxes & EXC_SXVD_AXIS_ROW )
485 eOrient = DataPilotFieldOrientation_ROW;
486 else if( nUsedAxes & EXC_SXVD_AXIS_COL )
487 eOrient = DataPilotFieldOrientation_COLUMN;
488 else if( nUsedAxes & EXC_SXVD_AXIS_PAGE )
489 eOrient = DataPilotFieldOrientation_PAGE;
490 else if( nUsedAxes & EXC_SXVD_AXIS_DATA )
491 eOrient = DataPilotFieldOrientation_DATA;
492 return eOrient;
495 void XclPTFieldInfo::AddApiOrient( DataPilotFieldOrientation eOrient )
497 using namespace ::com::sun::star::sheet;
498 switch( eOrient )
500 case DataPilotFieldOrientation_ROW: mnAxes |= EXC_SXVD_AXIS_ROW; break;
501 case DataPilotFieldOrientation_COLUMN: mnAxes |= EXC_SXVD_AXIS_COL; break;
502 case DataPilotFieldOrientation_PAGE: mnAxes |= EXC_SXVD_AXIS_PAGE; break;
503 case DataPilotFieldOrientation_DATA: mnAxes |= EXC_SXVD_AXIS_DATA; break;
504 default:;
508 //! TODO: should be a Sequence<GeneralFunction> in ScDPSaveData
509 void XclPTFieldInfo::GetSubtotals( XclPTSubtotalVec& rSubtotals ) const
511 rSubtotals.clear();
512 rSubtotals.reserve( 16 );
514 using namespace ::com::sun::star::sheet;
515 if( mnSubtotals & EXC_SXVD_SUBT_DEFAULT ) rSubtotals.push_back( GeneralFunction_AUTO );
516 if( mnSubtotals & EXC_SXVD_SUBT_SUM ) rSubtotals.push_back( GeneralFunction_SUM );
517 if( mnSubtotals & EXC_SXVD_SUBT_COUNT ) rSubtotals.push_back( GeneralFunction_COUNT );
518 if( mnSubtotals & EXC_SXVD_SUBT_AVERAGE ) rSubtotals.push_back( GeneralFunction_AVERAGE );
519 if( mnSubtotals & EXC_SXVD_SUBT_MAX ) rSubtotals.push_back( GeneralFunction_MAX );
520 if( mnSubtotals & EXC_SXVD_SUBT_MIN ) rSubtotals.push_back( GeneralFunction_MIN );
521 if( mnSubtotals & EXC_SXVD_SUBT_PROD ) rSubtotals.push_back( GeneralFunction_PRODUCT );
522 if( mnSubtotals & EXC_SXVD_SUBT_COUNTNUM ) rSubtotals.push_back( GeneralFunction_COUNTNUMS );
523 if( mnSubtotals & EXC_SXVD_SUBT_STDDEV ) rSubtotals.push_back( GeneralFunction_STDEV );
524 if( mnSubtotals & EXC_SXVD_SUBT_STDDEVP ) rSubtotals.push_back( GeneralFunction_STDEVP );
525 if( mnSubtotals & EXC_SXVD_SUBT_VAR ) rSubtotals.push_back( GeneralFunction_VAR );
526 if( mnSubtotals & EXC_SXVD_SUBT_VARP ) rSubtotals.push_back( GeneralFunction_VARP );
529 void XclPTFieldInfo::SetSubtotals( const XclPTSubtotalVec& rSubtotals )
531 mnSubtotals = EXC_SXVD_SUBT_NONE;
532 using namespace ::com::sun::star::sheet;
533 for( XclPTSubtotalVec::const_iterator aIt = rSubtotals.begin(), aEnd = rSubtotals.end(); aIt != aEnd; ++aIt )
535 switch( *aIt )
537 case GeneralFunction_AUTO: mnSubtotals |= EXC_SXVD_SUBT_DEFAULT; break;
538 case GeneralFunction_SUM: mnSubtotals |= EXC_SXVD_SUBT_SUM; break;
539 case GeneralFunction_COUNT: mnSubtotals |= EXC_SXVD_SUBT_COUNT; break;
540 case GeneralFunction_AVERAGE: mnSubtotals |= EXC_SXVD_SUBT_AVERAGE; break;
541 case GeneralFunction_MAX: mnSubtotals |= EXC_SXVD_SUBT_MAX; break;
542 case GeneralFunction_MIN: mnSubtotals |= EXC_SXVD_SUBT_MIN; break;
543 case GeneralFunction_PRODUCT: mnSubtotals |= EXC_SXVD_SUBT_PROD; break;
544 case GeneralFunction_COUNTNUMS: mnSubtotals |= EXC_SXVD_SUBT_COUNTNUM; break;
545 case GeneralFunction_STDEV: mnSubtotals |= EXC_SXVD_SUBT_STDDEV; break;
546 case GeneralFunction_STDEVP: mnSubtotals |= EXC_SXVD_SUBT_STDDEVP; break;
547 case GeneralFunction_VAR: mnSubtotals |= EXC_SXVD_SUBT_VAR; break;
548 case GeneralFunction_VARP: mnSubtotals |= EXC_SXVD_SUBT_VARP; break;
552 mnSubtCount = 0;
553 for( sal_uInt16 nMask = 0x8000; nMask; nMask >>= 1 )
554 if( mnSubtotals & nMask )
555 ++mnSubtCount;
558 XclImpStream& operator>>( XclImpStream& rStrm, XclPTFieldInfo& rInfo )
560 // rInfo.mnCacheIdx is not part of the SXVD record
561 return rStrm
562 >> rInfo.mnAxes
563 >> rInfo.mnSubtCount
564 >> rInfo.mnSubtotals
565 >> rInfo.mnItemCount
566 >> rInfo.maVisName;
569 XclExpStream& operator<<( XclExpStream& rStrm, const XclPTFieldInfo& rInfo )
571 // rInfo.mnCacheIdx is not part of the SXVD record
572 return rStrm
573 << rInfo.mnAxes
574 << rInfo.mnSubtCount
575 << rInfo.mnSubtotals
576 << rInfo.mnItemCount
577 << rInfo.maVisName;
580 // Extended field settings ====================================================
582 XclPTFieldExtInfo::XclPTFieldExtInfo() :
583 mnFlags( EXC_SXVDEX_DEFAULTFLAGS ),
584 mnSortField( EXC_SXVDEX_SORT_OWN ),
585 mnShowField( EXC_SXVDEX_SHOW_NONE ),
586 mnNumFmt(0),
587 mpFieldTotalName(NULL)
591 sal_Int32 XclPTFieldExtInfo::GetApiSortMode() const
593 sal_Int32 nSortMode = ScDPSortMode::MANUAL;
594 if( ::get_flag( mnFlags, EXC_SXVDEX_SORT ) )
595 nSortMode = (mnSortField == EXC_SXVDEX_SORT_OWN) ? ScDPSortMode::NAME : ScDPSortMode::DATA;
596 return nSortMode;
599 void XclPTFieldExtInfo::SetApiSortMode( sal_Int32 nSortMode )
601 bool bSort = (nSortMode == ScDPSortMode::NAME) || (nSortMode == ScDPSortMode::DATA);
602 ::set_flag( mnFlags, EXC_SXVDEX_SORT, bSort );
603 if( nSortMode == ScDPSortMode::NAME )
604 mnSortField = EXC_SXVDEX_SORT_OWN; // otherwise sort field has to be set by caller
607 sal_Int32 XclPTFieldExtInfo::GetApiAutoShowMode() const
609 return ::get_flagvalue( mnFlags, EXC_SXVDEX_AUTOSHOW_ASC,
610 ScDPShowItemsMode::FROM_TOP, ScDPShowItemsMode::FROM_BOTTOM );
613 void XclPTFieldExtInfo::SetApiAutoShowMode( sal_Int32 nShowMode )
615 ::set_flag( mnFlags, EXC_SXVDEX_AUTOSHOW_ASC, nShowMode == ScDPShowItemsMode::FROM_TOP );
618 sal_Int32 XclPTFieldExtInfo::GetApiAutoShowCount() const
620 return ::extract_value< sal_Int32 >( mnFlags, 24, 8 );
623 void XclPTFieldExtInfo::SetApiAutoShowCount( sal_Int32 nShowCount )
625 ::insert_value( mnFlags, limit_cast< sal_uInt8 >( nShowCount ), 24, 8 );
628 sal_Int32 XclPTFieldExtInfo::GetApiLayoutMode() const
630 sal_Int32 nLayoutMode = ScDPLayoutMode::TABULAR_LAYOUT;
631 if( ::get_flag( mnFlags, EXC_SXVDEX_LAYOUT_REPORT ) )
632 nLayoutMode = ::get_flag( mnFlags, EXC_SXVDEX_LAYOUT_TOP ) ?
633 ScDPLayoutMode::OUTLINE_SUBTOTALS_TOP : ScDPLayoutMode::OUTLINE_SUBTOTALS_BOTTOM;
634 return nLayoutMode;
637 void XclPTFieldExtInfo::SetApiLayoutMode( sal_Int32 nLayoutMode )
639 ::set_flag( mnFlags, EXC_SXVDEX_LAYOUT_REPORT, nLayoutMode != ScDPLayoutMode::TABULAR_LAYOUT );
640 ::set_flag( mnFlags, EXC_SXVDEX_LAYOUT_TOP, nLayoutMode == ScDPLayoutMode::OUTLINE_SUBTOTALS_TOP );
643 XclImpStream& operator>>( XclImpStream& rStrm, XclPTFieldExtInfo& rInfo )
645 sal_uInt8 nNameLen = 0;
646 rStrm >> rInfo.mnFlags
647 >> rInfo.mnSortField
648 >> rInfo.mnShowField
649 >> rInfo.mnNumFmt
650 >> nNameLen;
652 rStrm.Ignore(10);
653 if (nNameLen != 0xFF)
654 // Custom field total name is used. Pick it up.
655 rInfo.mpFieldTotalName.reset(new rtl::OUString(rStrm.ReadUniString(nNameLen, 0)));
657 return rStrm;
660 XclExpStream& operator<<( XclExpStream& rStrm, const XclPTFieldExtInfo& rInfo )
662 rStrm << rInfo.mnFlags
663 << rInfo.mnSortField
664 << rInfo.mnShowField
665 << EXC_SXVDEX_FORMAT_NONE;
667 if (rInfo.mpFieldTotalName.get() && rInfo.mpFieldTotalName->getLength() > 0)
669 rtl::OUString aFinalName = *rInfo.mpFieldTotalName;
670 if (aFinalName.getLength() >= 254)
671 aFinalName = aFinalName.copy(0, 254);
672 sal_uInt8 nNameLen = static_cast<sal_uInt8>(aFinalName.getLength());
673 rStrm << nNameLen;
674 rStrm.WriteZeroBytes(10);
675 rStrm << XclExpString(aFinalName, EXC_STR_NOHEADER);
677 else
679 rStrm << sal_uInt16(0xFFFF);
680 rStrm.WriteZeroBytes(8);
682 return rStrm;
685 // Page field settings ========================================================
687 XclPTPageFieldInfo::XclPTPageFieldInfo() :
688 mnField( 0 ),
689 mnSelItem( EXC_SXPI_ALLITEMS ),
690 mnObjId( 0xFFFF )
694 XclImpStream& operator>>( XclImpStream& rStrm, XclPTPageFieldInfo& rInfo )
696 return rStrm
697 >> rInfo.mnField
698 >> rInfo.mnSelItem
699 >> rInfo.mnObjId;
702 XclExpStream& operator<<( XclExpStream& rStrm, const XclPTPageFieldInfo& rInfo )
704 return rStrm
705 << rInfo.mnField
706 << rInfo.mnSelItem
707 << rInfo.mnObjId;
710 // Data field settings ========================================================
712 XclPTDataFieldInfo::XclPTDataFieldInfo() :
713 mnField( 0 ),
714 mnAggFunc( EXC_SXDI_FUNC_SUM ),
715 mnRefType( EXC_SXDI_REF_NORMAL ),
716 mnRefField( 0 ),
717 mnRefItem( 0 ),
718 mnNumFmt( 0 )
722 GeneralFunction XclPTDataFieldInfo::GetApiAggFunc() const
724 using namespace ::com::sun::star::sheet;
725 GeneralFunction eAggFunc;
726 switch( mnAggFunc )
728 case EXC_SXDI_FUNC_SUM: eAggFunc = GeneralFunction_SUM; break;
729 case EXC_SXDI_FUNC_COUNT: eAggFunc = GeneralFunction_COUNT; break;
730 case EXC_SXDI_FUNC_AVERAGE: eAggFunc = GeneralFunction_AVERAGE; break;
731 case EXC_SXDI_FUNC_MAX: eAggFunc = GeneralFunction_MAX; break;
732 case EXC_SXDI_FUNC_MIN: eAggFunc = GeneralFunction_MIN; break;
733 case EXC_SXDI_FUNC_PRODUCT: eAggFunc = GeneralFunction_PRODUCT; break;
734 case EXC_SXDI_FUNC_COUNTNUM: eAggFunc = GeneralFunction_COUNTNUMS; break;
735 case EXC_SXDI_FUNC_STDDEV: eAggFunc = GeneralFunction_STDEV; break;
736 case EXC_SXDI_FUNC_STDDEVP: eAggFunc = GeneralFunction_STDEVP; break;
737 case EXC_SXDI_FUNC_VAR: eAggFunc = GeneralFunction_VAR; break;
738 case EXC_SXDI_FUNC_VARP: eAggFunc = GeneralFunction_VARP; break;
739 default: eAggFunc = GeneralFunction_SUM;
741 return eAggFunc;
744 void XclPTDataFieldInfo::SetApiAggFunc( GeneralFunction eAggFunc )
746 using namespace ::com::sun::star::sheet;
747 switch( eAggFunc )
749 case GeneralFunction_SUM: mnAggFunc = EXC_SXDI_FUNC_SUM; break;
750 case GeneralFunction_COUNT: mnAggFunc = EXC_SXDI_FUNC_COUNT; break;
751 case GeneralFunction_AVERAGE: mnAggFunc = EXC_SXDI_FUNC_AVERAGE; break;
752 case GeneralFunction_MAX: mnAggFunc = EXC_SXDI_FUNC_MAX; break;
753 case GeneralFunction_MIN: mnAggFunc = EXC_SXDI_FUNC_MIN; break;
754 case GeneralFunction_PRODUCT: mnAggFunc = EXC_SXDI_FUNC_PRODUCT; break;
755 case GeneralFunction_COUNTNUMS: mnAggFunc = EXC_SXDI_FUNC_COUNTNUM; break;
756 case GeneralFunction_STDEV: mnAggFunc = EXC_SXDI_FUNC_STDDEV; break;
757 case GeneralFunction_STDEVP: mnAggFunc = EXC_SXDI_FUNC_STDDEVP; break;
758 case GeneralFunction_VAR: mnAggFunc = EXC_SXDI_FUNC_VAR; break;
759 case GeneralFunction_VARP: mnAggFunc = EXC_SXDI_FUNC_VARP; break;
760 default: mnAggFunc = EXC_SXDI_FUNC_SUM;
764 sal_Int32 XclPTDataFieldInfo::GetApiRefType() const
766 namespace ScDPRefType = ::com::sun::star::sheet::DataPilotFieldReferenceType;
767 sal_Int32 nRefType;
768 switch( mnRefType )
770 case EXC_SXDI_REF_DIFF: nRefType = ScDPRefType::ITEM_DIFFERENCE; break;
771 case EXC_SXDI_REF_PERC: nRefType = ScDPRefType::ITEM_PERCENTAGE; break;
772 case EXC_SXDI_REF_PERC_DIFF: nRefType = ScDPRefType::ITEM_PERCENTAGE_DIFFERENCE; break;
773 case EXC_SXDI_REF_RUN_TOTAL: nRefType = ScDPRefType::RUNNING_TOTAL; break;
774 case EXC_SXDI_REF_PERC_ROW: nRefType = ScDPRefType::ROW_PERCENTAGE; break;
775 case EXC_SXDI_REF_PERC_COL: nRefType = ScDPRefType::COLUMN_PERCENTAGE; break;
776 case EXC_SXDI_REF_PERC_TOTAL: nRefType = ScDPRefType::TOTAL_PERCENTAGE; break;
777 case EXC_SXDI_REF_INDEX: nRefType = ScDPRefType::INDEX; break;
778 default: nRefType = ScDPRefType::NONE;
780 return nRefType;
783 void XclPTDataFieldInfo::SetApiRefType( sal_Int32 nRefType )
785 namespace ScDPRefType = ::com::sun::star::sheet::DataPilotFieldReferenceType;
786 switch( nRefType )
788 case ScDPRefType::ITEM_DIFFERENCE: mnRefType = EXC_SXDI_REF_DIFF; break;
789 case ScDPRefType::ITEM_PERCENTAGE: mnRefType = EXC_SXDI_REF_PERC; break;
790 case ScDPRefType::ITEM_PERCENTAGE_DIFFERENCE: mnRefType = EXC_SXDI_REF_PERC_DIFF; break;
791 case ScDPRefType::RUNNING_TOTAL: mnRefType = EXC_SXDI_REF_RUN_TOTAL; break;
792 case ScDPRefType::ROW_PERCENTAGE: mnRefType = EXC_SXDI_REF_PERC_ROW; break;
793 case ScDPRefType::COLUMN_PERCENTAGE: mnRefType = EXC_SXDI_REF_PERC_COL; break;
794 case ScDPRefType::TOTAL_PERCENTAGE: mnRefType = EXC_SXDI_REF_PERC_TOTAL;break;
795 case ScDPRefType::INDEX: mnRefType = EXC_SXDI_REF_INDEX; break;
796 default: mnRefType = EXC_SXDI_REF_NORMAL;
800 sal_Int32 XclPTDataFieldInfo::GetApiRefItemType() const
802 sal_Int32 nRefItemType;
803 switch( mnRefItem )
805 case EXC_SXDI_PREVITEM: nRefItemType = ScDPRefItemType::PREVIOUS; break;
806 case EXC_SXDI_NEXTITEM: nRefItemType = ScDPRefItemType::NEXT; break;
807 default: nRefItemType = ScDPRefItemType::NAMED;
809 return nRefItemType;
812 void XclPTDataFieldInfo::SetApiRefItemType( sal_Int32 nRefItemType )
814 switch( nRefItemType )
816 case ScDPRefItemType::PREVIOUS: mnRefItem = EXC_SXDI_PREVITEM; break;
817 case ScDPRefItemType::NEXT: mnRefItem = EXC_SXDI_NEXTITEM; break;
818 // nothing for named item reference
822 XclImpStream& operator>>( XclImpStream& rStrm, 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 XclExpStream& operator<<( XclExpStream& rStrm, const XclPTDataFieldInfo& rInfo )
836 return rStrm
837 << rInfo.mnField
838 << rInfo.mnAggFunc
839 << rInfo.mnRefType
840 << rInfo.mnRefField
841 << rInfo.mnRefItem
842 << rInfo.mnNumFmt
843 << rInfo.maVisName;
846 // Pivot table settings =======================================================
848 XclPTInfo::XclPTInfo() :
849 mnFirstHeadRow( 0 ),
850 mnCacheIdx( 0xFFFF ),
851 mnDataAxis( EXC_SXVD_AXIS_NONE ),
852 mnDataPos( EXC_SXVIEW_DATALAST ),
853 mnFields( 0 ),
854 mnRowFields( 0 ),
855 mnColFields( 0 ),
856 mnPageFields( 0 ),
857 mnDataFields( 0 ),
858 mnDataRows( 0 ),
859 mnDataCols( 0 ),
860 mnFlags( EXC_SXVIEW_DEFAULTFLAGS ),
861 mnAutoFmtIdx( EXC_SXVIEW_AUTOFMT )
865 XclImpStream& operator>>( XclImpStream& rStrm, XclPTInfo& rInfo )
867 sal_uInt16 nTabLen, nDataLen;
869 rStrm >> rInfo.maOutXclRange
870 >> rInfo.mnFirstHeadRow
871 >> rInfo.maDataXclPos
872 >> rInfo.mnCacheIdx;
873 rStrm.Ignore( 2 );
874 rStrm >> rInfo.mnDataAxis >> rInfo.mnDataPos
875 >> rInfo.mnFields
876 >> rInfo.mnRowFields >> rInfo.mnColFields
877 >> rInfo.mnPageFields >> rInfo.mnDataFields
878 >> rInfo.mnDataRows >> rInfo.mnDataCols
879 >> rInfo.mnFlags
880 >> rInfo.mnAutoFmtIdx
881 >> nTabLen >> nDataLen;
882 rInfo.maTableName = rStrm.ReadUniString( nTabLen );
883 rInfo.maDataName = rStrm.ReadUniString( nDataLen );
884 return rStrm;
887 XclExpStream& operator<<( XclExpStream& rStrm, const XclPTInfo& rInfo )
889 XclExpString aXclTableName( rInfo.maTableName );
890 XclExpString aXclDataName( rInfo.maDataName );
892 rStrm << rInfo.maOutXclRange
893 << rInfo.mnFirstHeadRow
894 << rInfo.maDataXclPos
895 << rInfo.mnCacheIdx
896 << sal_uInt16( 0 )
897 << rInfo.mnDataAxis << rInfo.mnDataPos
898 << rInfo.mnFields
899 << rInfo.mnRowFields << rInfo.mnColFields
900 << rInfo.mnPageFields << rInfo.mnDataFields
901 << rInfo.mnDataRows << rInfo.mnDataCols
902 << rInfo.mnFlags
903 << rInfo.mnAutoFmtIdx
904 << aXclTableName.Len() << aXclDataName.Len();
905 aXclTableName.WriteFlagField( rStrm );
906 aXclTableName.WriteBuffer( rStrm );
907 aXclDataName.WriteFlagField( rStrm );
908 aXclDataName.WriteBuffer( rStrm );
909 return rStrm;
912 // Extended pivot table settings ==============================================
914 XclPTExtInfo::XclPTExtInfo() :
915 mnSxformulaRecs( 0 ),
916 mnSxselectRecs( 0 ),
917 mnPagePerRow( 0 ),
918 mnPagePerCol( 0 ),
919 mnFlags( EXC_SXEX_DEFAULTFLAGS )
923 XclImpStream& operator>>( XclImpStream& rStrm, XclPTExtInfo& rInfo )
925 rStrm >> rInfo.mnSxformulaRecs;
926 rStrm.Ignore( 6 );
927 return rStrm
928 >> rInfo.mnSxselectRecs
929 >> rInfo.mnPagePerRow
930 >> rInfo.mnPagePerCol
931 >> rInfo.mnFlags;
934 XclExpStream& operator<<( XclExpStream& rStrm, const XclPTExtInfo& rInfo )
936 return rStrm
937 << rInfo.mnSxformulaRecs
938 << EXC_PT_NOSTRING // length of alt. error text
939 << EXC_PT_NOSTRING // length of alt. empty text
940 << EXC_PT_NOSTRING // length of tag
941 << rInfo.mnSxselectRecs
942 << rInfo.mnPagePerRow
943 << rInfo.mnPagePerCol
944 << rInfo.mnFlags
945 << EXC_PT_NOSTRING // length of page field style name
946 << EXC_PT_NOSTRING // length of table style name
947 << EXC_PT_NOSTRING; // length of vacate style name
950 // ============================================================================
952 // Pivot table autoformat settings ============================================
955 classic : 10 08 00 00 00 00 00 00 20 00 00 00 01 00 00 00 00
956 default : 10 08 00 00 00 00 00 00 20 00 00 00 01 00 00 00 00
957 report01 : 10 08 02 00 00 00 00 00 20 00 00 00 00 10 00 00 00
958 report02 : 10 08 02 00 00 00 00 00 20 00 00 00 01 10 00 00 00
959 report03 : 10 08 02 00 00 00 00 00 20 00 00 00 02 10 00 00 00
960 report04 : 10 08 02 00 00 00 00 00 20 00 00 00 03 10 00 00 00
961 report05 : 10 08 02 00 00 00 00 00 20 00 00 00 04 10 00 00 00
962 report06 : 10 08 02 00 00 00 00 00 20 00 00 00 05 10 00 00 00
963 report07 : 10 08 02 00 00 00 00 00 20 00 00 00 06 10 00 00 00
964 report08 : 10 08 02 00 00 00 00 00 20 00 00 00 07 10 00 00 00
965 report09 : 10 08 02 00 00 00 00 00 20 00 00 00 08 10 00 00 00
966 report10 : 10 08 02 00 00 00 00 00 20 00 00 00 09 10 00 00 00
967 table01 : 10 08 00 00 00 00 00 00 20 00 00 00 0a 10 00 00 00
968 table02 : 10 08 00 00 00 00 00 00 20 00 00 00 0b 10 00 00 00
969 table03 : 10 08 00 00 00 00 00 00 20 00 00 00 0c 10 00 00 00
970 table04 : 10 08 00 00 00 00 00 00 20 00 00 00 0d 10 00 00 00
971 table05 : 10 08 00 00 00 00 00 00 20 00 00 00 0e 10 00 00 00
972 table06 : 10 08 00 00 00 00 00 00 20 00 00 00 0f 10 00 00 00
973 table07 : 10 08 00 00 00 00 00 00 20 00 00 00 10 10 00 00 00
974 table08 : 10 08 00 00 00 00 00 00 20 00 00 00 11 10 00 00 00
975 table09 : 10 08 00 00 00 00 00 00 20 00 00 00 12 10 00 00 00
976 table10 : 10 08 00 00 00 00 00 00 20 00 00 00 13 10 00 00 00
977 none : 10 08 00 00 00 00 00 00 20 00 00 00 15 10 00 00 00
980 XclPTViewEx9Info::XclPTViewEx9Info() :
981 mbReport( 0 ),
982 mnAutoFormat( 0 ),
983 mnGridLayout( 0x10 )
987 void XclPTViewEx9Info::Init( const ScDPObject& rDPObj )
989 if( rDPObj.GetHeaderLayout() )
991 mbReport = 0;
992 mnAutoFormat = 1;
993 mnGridLayout = 0;
995 else
997 // Report1 for now
998 // TODO : sync with autoformat indicies
999 mbReport = 2;
1000 mnAutoFormat = 1;
1001 mnGridLayout = 0x10;
1004 const ScDPSaveData* pData = rDPObj.GetSaveData();
1005 if (pData)
1007 const rtl::OUString* pGrandTotal = pData->GetGrandTotalName();
1008 if (pGrandTotal)
1009 maGrandTotalName = *pGrandTotal;
1013 XclImpStream& operator>>( XclImpStream& rStrm, XclPTViewEx9Info& rInfo )
1015 rStrm.Ignore( 2 );
1016 rStrm >> rInfo.mbReport; /// 2 for report* fmts ?
1017 rStrm.Ignore( 6 );
1018 rStrm >> rInfo.mnAutoFormat >> rInfo.mnGridLayout;
1019 rInfo.maGrandTotalName = rStrm.ReadUniString();
1020 return rStrm;
1023 XclExpStream& operator<<( XclExpStream& rStrm, const XclPTViewEx9Info& rInfo )
1025 return rStrm
1026 << EXC_PT_AUTOFMT_HEADER
1027 << rInfo.mbReport
1028 << EXC_PT_AUTOFMT_ZERO
1029 << EXC_PT_AUTOFMT_FLAGS
1030 << rInfo.mnAutoFormat
1031 << rInfo.mnGridLayout
1032 << XclExpString(rInfo.maGrandTotalName, EXC_STR_DEFAULT, EXC_PT_MAXSTRLEN);