fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / sc / source / filter / excel / xlpivot.cxx
blob432ff5d3f7d32fd0cde1d0cdf82bb9fc41240a83
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 <osl/diagnose.h>
27 #include <com/sun/star/sheet/DataPilotFieldGroupBy.hpp>
29 using ::com::sun::star::sheet::GeneralFunction;
30 using ::com::sun::star::sheet::DataPilotFieldOrientation;
32 namespace ScDPSortMode = ::com::sun::star::sheet::DataPilotFieldSortMode;
33 namespace ScDPShowItemsMode = ::com::sun::star::sheet::DataPilotFieldShowItemsMode;
34 namespace ScDPLayoutMode = ::com::sun::star::sheet::DataPilotFieldLayoutMode;
35 namespace ScDPRefItemType = ::com::sun::star::sheet::DataPilotFieldReferenceItemType;
36 namespace ScDPGroupBy = ::com::sun::star::sheet::DataPilotFieldGroupBy;
38 // Pivot cache
40 XclPCItem::XclPCItem() :
41 meType( EXC_PCITEM_INVALID ),
42 maDateTime( DateTime::EMPTY )
46 XclPCItem::~XclPCItem()
50 void XclPCItem::SetEmpty()
52 meType = EXC_PCITEM_EMPTY;
53 maText.clear();
56 void XclPCItem::SetText( const OUString& rText )
58 meType = EXC_PCITEM_TEXT;
59 maText = rText;
62 void XclPCItem::SetDouble( double fValue )
64 meType = EXC_PCITEM_DOUBLE;
65 //TODO convert double to string
66 maText.clear();
67 mfValue = fValue;
70 void XclPCItem::SetDateTime( const DateTime& rDateTime )
72 meType = EXC_PCITEM_DATETIME;
73 //TODO convert date to string
74 maText.clear();
75 maDateTime = rDateTime;
78 void XclPCItem::SetInteger( sal_Int16 nValue )
80 meType = EXC_PCITEM_INTEGER;
81 maText = OUString::number(nValue);
82 mnValue = nValue;
85 void XclPCItem::SetError( sal_uInt16 nError )
87 meType = EXC_PCITEM_ERROR;
88 maText.clear();
89 mnError = nError;
90 switch( nError )
92 case 0x00: maText = "#NULL!"; break;
93 case 0x07: maText = "#DIV/0!"; break;
94 case 0x0F: maText = "#VALUE!"; break;
95 case 0x17: maText = "#REF!"; break;
96 case 0x1D: maText = "#NAME?"; break;
97 case 0x24: maText = "#NUM!"; break;
98 case 0x2A: maText = "#N/A"; break;
99 default: break;
103 void XclPCItem::SetBool( bool bValue )
105 meType = EXC_PCITEM_BOOL;
106 //TODO convert boolean to string
107 maText.clear();
108 mbValue = bValue;
111 bool XclPCItem::IsEqual( const XclPCItem& rItem ) const
113 if( meType == rItem.meType ) switch( meType )
115 case EXC_PCITEM_INVALID: return true;
116 case EXC_PCITEM_EMPTY: return true;
117 case EXC_PCITEM_TEXT: return maText == rItem.maText;
118 case EXC_PCITEM_DOUBLE: return mfValue == rItem.mfValue;
119 case EXC_PCITEM_DATETIME: return maDateTime == rItem.maDateTime;
120 case EXC_PCITEM_INTEGER: return mnValue == rItem.mnValue;
121 case EXC_PCITEM_BOOL: return mbValue == rItem.mbValue;
122 case EXC_PCITEM_ERROR: return mnError == rItem.mnError;
123 default: OSL_FAIL( "XclPCItem::IsEqual - unknown pivot cache item type" );
125 return false;
128 bool XclPCItem::IsEmpty() const
130 return meType == EXC_PCITEM_EMPTY;
133 const OUString* XclPCItem::GetText() const
135 return (meType == EXC_PCITEM_TEXT || meType == EXC_PCITEM_ERROR) ? &maText : NULL;
138 const double* XclPCItem::GetDouble() const
140 return (meType == EXC_PCITEM_DOUBLE) ? &mfValue : 0;
143 const DateTime* XclPCItem::GetDateTime() const
145 return (meType == EXC_PCITEM_DATETIME) ? &maDateTime : 0;
148 const sal_Int16* XclPCItem::GetInteger() const
150 return (meType == EXC_PCITEM_INTEGER) ? &mnValue : 0;
153 const sal_uInt16* XclPCItem::GetError() const
155 return (meType == EXC_PCITEM_ERROR) ? &mnError : 0;
158 const bool* XclPCItem::GetBool() const
160 return (meType == EXC_PCITEM_BOOL) ? &mbValue : 0;
163 // Field settings =============================================================
165 XclPCFieldInfo::XclPCFieldInfo() :
166 mnFlags( 0 ),
167 mnGroupChild( 0 ),
168 mnGroupBase( 0 ),
169 mnVisItems( 0 ),
170 mnGroupItems( 0 ),
171 mnBaseItems( 0 ),
172 mnOrigItems( 0 )
176 XclImpStream& operator>>( XclImpStream& rStrm, XclPCFieldInfo& rInfo )
178 rInfo.mnFlags = rStrm.ReaduInt16();
179 rInfo.mnGroupChild = rStrm.ReaduInt16();
180 rInfo.mnGroupBase = rStrm.ReaduInt16();
181 rInfo.mnVisItems = rStrm.ReaduInt16();
182 rInfo.mnGroupItems = rStrm.ReaduInt16();
183 rInfo.mnBaseItems = rStrm.ReaduInt16();
184 rInfo.mnOrigItems = rStrm.ReaduInt16();
185 if( rStrm.GetRecLeft() >= 3 )
186 rInfo.maName = rStrm.ReadUniString();
187 else
188 rInfo.maName.clear();
189 return rStrm;
192 XclExpStream& operator<<( XclExpStream& rStrm, const XclPCFieldInfo& rInfo )
194 return rStrm
195 << rInfo.mnFlags
196 << rInfo.mnGroupChild
197 << rInfo.mnGroupBase
198 << rInfo.mnVisItems
199 << rInfo.mnGroupItems
200 << rInfo.mnBaseItems
201 << rInfo.mnOrigItems
202 << XclExpString( rInfo.maName );
205 // Numeric grouping field settings ============================================
207 XclPCNumGroupInfo::XclPCNumGroupInfo() :
208 mnFlags( EXC_SXNUMGROUP_AUTOMIN | EXC_SXNUMGROUP_AUTOMAX )
210 SetNumType();
213 void XclPCNumGroupInfo::SetNumType()
215 SetXclDataType( EXC_SXNUMGROUP_TYPE_NUM );
218 sal_Int32 XclPCNumGroupInfo::GetScDateType() const
220 sal_Int32 nScType = 0;
221 switch( GetXclDataType() )
223 case EXC_SXNUMGROUP_TYPE_SEC: nScType = ScDPGroupBy::SECONDS; break;
224 case EXC_SXNUMGROUP_TYPE_MIN: nScType = ScDPGroupBy::MINUTES; break;
225 case EXC_SXNUMGROUP_TYPE_HOUR: nScType = ScDPGroupBy::HOURS; break;
226 case EXC_SXNUMGROUP_TYPE_DAY: nScType = ScDPGroupBy::DAYS; break;
227 case EXC_SXNUMGROUP_TYPE_MONTH: nScType = ScDPGroupBy::MONTHS; break;
228 case EXC_SXNUMGROUP_TYPE_QUART: nScType = ScDPGroupBy::QUARTERS; break;
229 case EXC_SXNUMGROUP_TYPE_YEAR: nScType = ScDPGroupBy::YEARS; break;
230 default: OSL_TRACE( "XclPCNumGroupInfo::GetScDateType - unexpected date type %d", GetXclDataType() );
232 return nScType;
235 void XclPCNumGroupInfo::SetScDateType( sal_Int32 nScType )
237 sal_uInt16 nXclType = EXC_SXNUMGROUP_TYPE_NUM;
238 switch( nScType )
240 case ScDPGroupBy::SECONDS: nXclType = EXC_SXNUMGROUP_TYPE_SEC; break;
241 case ScDPGroupBy::MINUTES: nXclType = EXC_SXNUMGROUP_TYPE_MIN; break;
242 case ScDPGroupBy::HOURS: nXclType = EXC_SXNUMGROUP_TYPE_HOUR; break;
243 case ScDPGroupBy::DAYS: nXclType = EXC_SXNUMGROUP_TYPE_DAY; break;
244 case ScDPGroupBy::MONTHS: nXclType = EXC_SXNUMGROUP_TYPE_MONTH; break;
245 case ScDPGroupBy::QUARTERS: nXclType = EXC_SXNUMGROUP_TYPE_QUART; break;
246 case ScDPGroupBy::YEARS: nXclType = EXC_SXNUMGROUP_TYPE_YEAR; break;
247 default:
248 SAL_INFO("sc.filter", "unexpected date type " << nScType);
250 SetXclDataType( nXclType );
253 sal_uInt16 XclPCNumGroupInfo::GetXclDataType() const
255 return ::extract_value< sal_uInt16 >( mnFlags, 2, 4 );
258 void XclPCNumGroupInfo::SetXclDataType( sal_uInt16 nXclType )
260 ::insert_value( mnFlags, nXclType, 2, 4 );
263 XclImpStream& operator>>( XclImpStream& rStrm, XclPCNumGroupInfo& rInfo )
265 rInfo.mnFlags = rStrm.ReaduInt16();
266 return rStrm;;
269 XclExpStream& operator<<( XclExpStream& rStrm, const XclPCNumGroupInfo& rInfo )
271 return rStrm << rInfo.mnFlags;
274 // Base class for pivot cache fields ==========================================
276 XclPCField::XclPCField( XclPCFieldType eFieldType, sal_uInt16 nFieldIdx ) :
277 meFieldType( eFieldType ),
278 mnFieldIdx( nFieldIdx )
282 XclPCField::~XclPCField()
286 bool XclPCField::IsSupportedField() const
288 return (meFieldType != EXC_PCFIELD_CALCED) && (meFieldType != EXC_PCFIELD_UNKNOWN);
291 bool XclPCField::IsStandardField() const
293 return meFieldType == EXC_PCFIELD_STANDARD;
296 bool XclPCField::IsStdGroupField() const
298 return meFieldType == EXC_PCFIELD_STDGROUP;
301 bool XclPCField::IsNumGroupField() const
303 return meFieldType == EXC_PCFIELD_NUMGROUP;
306 bool XclPCField::IsDateGroupField() const
308 return (meFieldType == EXC_PCFIELD_DATEGROUP) || (meFieldType == EXC_PCFIELD_DATECHILD);
311 bool XclPCField::IsGroupField() const
313 return IsStdGroupField() || IsNumGroupField() || IsDateGroupField();
316 bool XclPCField::IsGroupBaseField() const
318 return ::get_flag( maFieldInfo.mnFlags, EXC_SXFIELD_HASCHILD );
321 bool XclPCField::IsGroupChildField() const
323 return (meFieldType == EXC_PCFIELD_STDGROUP) || (meFieldType == EXC_PCFIELD_DATECHILD);
326 bool XclPCField::HasOrigItems() const
328 return IsSupportedField() && ((maFieldInfo.mnOrigItems > 0) || HasPostponedItems());
331 bool XclPCField::HasInlineItems() const
333 return (IsStandardField() || IsGroupField()) && ((maFieldInfo.mnGroupItems > 0) || (maFieldInfo.mnOrigItems > 0));
336 bool XclPCField::HasPostponedItems() const
338 return IsStandardField() && ::get_flag( maFieldInfo.mnFlags, EXC_SXFIELD_POSTPONE );
341 bool XclPCField::Has16BitIndexes() const
343 return IsStandardField() && ::get_flag( maFieldInfo.mnFlags, EXC_SXFIELD_16BIT );
346 // Pivot cache settings =======================================================
348 /** Contains data for a pivot cache (SXDB record). */
349 XclPCInfo::XclPCInfo() :
350 mnSrcRecs( 0 ),
351 mnStrmId( 0xFFFF ),
352 mnFlags( EXC_SXDB_DEFAULTFLAGS ),
353 mnBlockRecs( EXC_SXDB_BLOCKRECS ),
354 mnStdFields( 0 ),
355 mnTotalFields( 0 ),
356 mnSrcType( EXC_SXDB_SRC_SHEET )
360 XclImpStream& operator>>( XclImpStream& rStrm, XclPCInfo& rInfo )
362 rInfo.mnSrcRecs = rStrm.ReaduInt32();
363 rInfo.mnStrmId = rStrm.ReaduInt16();
364 rInfo.mnFlags = rStrm.ReaduInt16();
365 rInfo.mnBlockRecs = rStrm.ReaduInt16();
366 rInfo.mnStdFields = rStrm.ReaduInt16();
367 rInfo.mnTotalFields = rStrm.ReaduInt16();
368 rStrm.Ignore( 2 );
369 rInfo.mnSrcType = rStrm.ReaduInt16();
370 rInfo.maUserName = rStrm.ReadUniString();
371 return rStrm;
374 XclExpStream& operator<<( XclExpStream& rStrm, const XclPCInfo& rInfo )
376 return rStrm
377 << rInfo.mnSrcRecs
378 << rInfo.mnStrmId
379 << rInfo.mnFlags
380 << rInfo.mnBlockRecs
381 << rInfo.mnStdFields
382 << rInfo.mnTotalFields
383 << sal_uInt16( 0 )
384 << rInfo.mnSrcType
385 << XclExpString( rInfo.maUserName );
388 // Pivot table
390 // cached name ================================================================
392 XclImpStream& operator>>( XclImpStream& rStrm, XclPTCachedName& rCachedName )
394 sal_uInt16 nStrLen;
395 nStrLen = rStrm.ReaduInt16();
396 rCachedName.mbUseCache = nStrLen == EXC_PT_NOSTRING;
397 if( rCachedName.mbUseCache )
398 rCachedName.maName.clear();
399 else
400 rCachedName.maName = rStrm.ReadUniString( nStrLen );
401 return rStrm;
404 XclExpStream& operator<<( XclExpStream& rStrm, const XclPTCachedName& rCachedName )
406 if( rCachedName.mbUseCache )
407 rStrm << EXC_PT_NOSTRING;
408 else
409 rStrm << XclExpString( rCachedName.maName, EXC_STR_DEFAULT, EXC_PT_MAXSTRLEN );
410 return rStrm;
413 const OUString* XclPTVisNameInfo::GetVisName() const
415 return HasVisName() ? &maVisName.maName : 0;
418 void XclPTVisNameInfo::SetVisName( const OUString& rName )
420 maVisName.maName = rName;
421 maVisName.mbUseCache = rName.isEmpty();
424 // Field item settings ========================================================
426 XclPTItemInfo::XclPTItemInfo() :
427 mnType( EXC_SXVI_TYPE_DATA ),
428 mnFlags( EXC_SXVI_DEFAULTFLAGS ),
429 mnCacheIdx( EXC_SXVI_DEFAULT_CACHE )
433 XclImpStream& operator>>( XclImpStream& rStrm, XclPTItemInfo& rInfo )
435 rInfo.mnType = rStrm.ReaduInt16();
436 rInfo.mnFlags = rStrm.ReaduInt16();
437 rInfo.mnCacheIdx = rStrm.ReaduInt16();
438 rStrm >> rInfo.maVisName;
439 return rStrm;
442 XclExpStream& operator<<( XclExpStream& rStrm, const XclPTItemInfo& rInfo )
444 return rStrm
445 << rInfo.mnType
446 << rInfo.mnFlags
447 << rInfo.mnCacheIdx
448 << rInfo.maVisName;
451 // General field settings =====================================================
453 XclPTFieldInfo::XclPTFieldInfo() :
454 mnAxes( EXC_SXVD_AXIS_NONE ),
455 mnSubtCount( 1 ),
456 mnSubtotals( EXC_SXVD_SUBT_DEFAULT ),
457 mnItemCount( 0 ),
458 mnCacheIdx( EXC_SXVD_DEFAULT_CACHE )
462 DataPilotFieldOrientation XclPTFieldInfo::GetApiOrient( sal_uInt16 nMask ) const
464 using namespace ::com::sun::star::sheet;
465 DataPilotFieldOrientation eOrient = DataPilotFieldOrientation_HIDDEN;
466 sal_uInt16 nUsedAxes = mnAxes & nMask;
467 if( nUsedAxes & EXC_SXVD_AXIS_ROW )
468 eOrient = DataPilotFieldOrientation_ROW;
469 else if( nUsedAxes & EXC_SXVD_AXIS_COL )
470 eOrient = DataPilotFieldOrientation_COLUMN;
471 else if( nUsedAxes & EXC_SXVD_AXIS_PAGE )
472 eOrient = DataPilotFieldOrientation_PAGE;
473 else if( nUsedAxes & EXC_SXVD_AXIS_DATA )
474 eOrient = DataPilotFieldOrientation_DATA;
475 return eOrient;
478 void XclPTFieldInfo::AddApiOrient( DataPilotFieldOrientation eOrient )
480 using namespace ::com::sun::star::sheet;
481 switch( eOrient )
483 case DataPilotFieldOrientation_ROW: mnAxes |= EXC_SXVD_AXIS_ROW; break;
484 case DataPilotFieldOrientation_COLUMN: mnAxes |= EXC_SXVD_AXIS_COL; break;
485 case DataPilotFieldOrientation_PAGE: mnAxes |= EXC_SXVD_AXIS_PAGE; break;
486 case DataPilotFieldOrientation_DATA: mnAxes |= EXC_SXVD_AXIS_DATA; break;
487 default:;
491 //TODO: should be a Sequence<GeneralFunction> in ScDPSaveData
492 void XclPTFieldInfo::GetSubtotals( XclPTSubtotalVec& rSubtotals ) const
494 rSubtotals.clear();
495 rSubtotals.reserve( 16 );
497 using namespace ::com::sun::star::sheet;
498 if( mnSubtotals & EXC_SXVD_SUBT_DEFAULT ) rSubtotals.push_back( GeneralFunction_AUTO );
499 if( mnSubtotals & EXC_SXVD_SUBT_SUM ) rSubtotals.push_back( GeneralFunction_SUM );
500 if( mnSubtotals & EXC_SXVD_SUBT_COUNT ) rSubtotals.push_back( GeneralFunction_COUNT );
501 if( mnSubtotals & EXC_SXVD_SUBT_AVERAGE ) rSubtotals.push_back( GeneralFunction_AVERAGE );
502 if( mnSubtotals & EXC_SXVD_SUBT_MAX ) rSubtotals.push_back( GeneralFunction_MAX );
503 if( mnSubtotals & EXC_SXVD_SUBT_MIN ) rSubtotals.push_back( GeneralFunction_MIN );
504 if( mnSubtotals & EXC_SXVD_SUBT_PROD ) rSubtotals.push_back( GeneralFunction_PRODUCT );
505 if( mnSubtotals & EXC_SXVD_SUBT_COUNTNUM ) rSubtotals.push_back( GeneralFunction_COUNTNUMS );
506 if( mnSubtotals & EXC_SXVD_SUBT_STDDEV ) rSubtotals.push_back( GeneralFunction_STDEV );
507 if( mnSubtotals & EXC_SXVD_SUBT_STDDEVP ) rSubtotals.push_back( GeneralFunction_STDEVP );
508 if( mnSubtotals & EXC_SXVD_SUBT_VAR ) rSubtotals.push_back( GeneralFunction_VAR );
509 if( mnSubtotals & EXC_SXVD_SUBT_VARP ) rSubtotals.push_back( GeneralFunction_VARP );
512 void XclPTFieldInfo::SetSubtotals( const XclPTSubtotalVec& rSubtotals )
514 mnSubtotals = EXC_SXVD_SUBT_NONE;
515 using namespace ::com::sun::star::sheet;
516 for( XclPTSubtotalVec::const_iterator aIt = rSubtotals.begin(), aEnd = rSubtotals.end(); aIt != aEnd; ++aIt )
518 switch( *aIt )
520 case GeneralFunction_AUTO: mnSubtotals |= EXC_SXVD_SUBT_DEFAULT; break;
521 case GeneralFunction_SUM: mnSubtotals |= EXC_SXVD_SUBT_SUM; break;
522 case GeneralFunction_COUNT: mnSubtotals |= EXC_SXVD_SUBT_COUNT; break;
523 case GeneralFunction_AVERAGE: mnSubtotals |= EXC_SXVD_SUBT_AVERAGE; break;
524 case GeneralFunction_MAX: mnSubtotals |= EXC_SXVD_SUBT_MAX; break;
525 case GeneralFunction_MIN: mnSubtotals |= EXC_SXVD_SUBT_MIN; break;
526 case GeneralFunction_PRODUCT: mnSubtotals |= EXC_SXVD_SUBT_PROD; break;
527 case GeneralFunction_COUNTNUMS: mnSubtotals |= EXC_SXVD_SUBT_COUNTNUM; break;
528 case GeneralFunction_STDEV: mnSubtotals |= EXC_SXVD_SUBT_STDDEV; break;
529 case GeneralFunction_STDEVP: mnSubtotals |= EXC_SXVD_SUBT_STDDEVP; break;
530 case GeneralFunction_VAR: mnSubtotals |= EXC_SXVD_SUBT_VAR; break;
531 case GeneralFunction_VARP: mnSubtotals |= EXC_SXVD_SUBT_VARP; break;
535 mnSubtCount = 0;
536 for( sal_uInt16 nMask = 0x8000; nMask; nMask >>= 1 )
537 if( mnSubtotals & nMask )
538 ++mnSubtCount;
541 XclImpStream& operator>>( XclImpStream& rStrm, XclPTFieldInfo& rInfo )
543 // rInfo.mnCacheIdx is not part of the SXVD record
544 rInfo.mnAxes = rStrm.ReaduInt16();
545 rInfo.mnSubtCount = rStrm.ReaduInt16();
546 rInfo.mnSubtotals = rStrm.ReaduInt16();
547 rInfo.mnItemCount = rStrm.ReaduInt16();
548 rStrm >> rInfo.maVisName;
549 return rStrm;
552 XclExpStream& operator<<( XclExpStream& rStrm, const XclPTFieldInfo& rInfo )
554 // rInfo.mnCacheIdx is not part of the SXVD record
555 return rStrm
556 << rInfo.mnAxes
557 << rInfo.mnSubtCount
558 << rInfo.mnSubtotals
559 << rInfo.mnItemCount
560 << rInfo.maVisName;
563 // Extended field settings ====================================================
565 XclPTFieldExtInfo::XclPTFieldExtInfo() :
566 mnFlags( EXC_SXVDEX_DEFAULTFLAGS ),
567 mnSortField( EXC_SXVDEX_SORT_OWN ),
568 mnShowField( EXC_SXVDEX_SHOW_NONE ),
569 mnNumFmt(0),
570 mpFieldTotalName(NULL)
574 sal_Int32 XclPTFieldExtInfo::GetApiSortMode() const
576 sal_Int32 nSortMode = ScDPSortMode::MANUAL;
577 if( ::get_flag( mnFlags, EXC_SXVDEX_SORT ) )
578 nSortMode = (mnSortField == EXC_SXVDEX_SORT_OWN) ? ScDPSortMode::NAME : ScDPSortMode::DATA;
579 return nSortMode;
582 void XclPTFieldExtInfo::SetApiSortMode( sal_Int32 nSortMode )
584 bool bSort = (nSortMode == ScDPSortMode::NAME) || (nSortMode == ScDPSortMode::DATA);
585 ::set_flag( mnFlags, EXC_SXVDEX_SORT, bSort );
586 if( nSortMode == ScDPSortMode::NAME )
587 mnSortField = EXC_SXVDEX_SORT_OWN; // otherwise sort field has to be set by caller
590 sal_Int32 XclPTFieldExtInfo::GetApiAutoShowMode() const
592 return ::get_flagvalue( mnFlags, EXC_SXVDEX_AUTOSHOW_ASC,
593 ScDPShowItemsMode::FROM_TOP, ScDPShowItemsMode::FROM_BOTTOM );
596 void XclPTFieldExtInfo::SetApiAutoShowMode( sal_Int32 nShowMode )
598 ::set_flag( mnFlags, EXC_SXVDEX_AUTOSHOW_ASC, nShowMode == ScDPShowItemsMode::FROM_TOP );
601 sal_Int32 XclPTFieldExtInfo::GetApiAutoShowCount() const
603 return ::extract_value< sal_Int32 >( mnFlags, 24, 8 );
606 void XclPTFieldExtInfo::SetApiAutoShowCount( sal_Int32 nShowCount )
608 ::insert_value( mnFlags, limit_cast< sal_uInt8 >( nShowCount ), 24, 8 );
611 sal_Int32 XclPTFieldExtInfo::GetApiLayoutMode() const
613 sal_Int32 nLayoutMode = ScDPLayoutMode::TABULAR_LAYOUT;
614 if( ::get_flag( mnFlags, EXC_SXVDEX_LAYOUT_REPORT ) )
615 nLayoutMode = ::get_flag( mnFlags, EXC_SXVDEX_LAYOUT_TOP ) ?
616 ScDPLayoutMode::OUTLINE_SUBTOTALS_TOP : ScDPLayoutMode::OUTLINE_SUBTOTALS_BOTTOM;
617 return nLayoutMode;
620 void XclPTFieldExtInfo::SetApiLayoutMode( sal_Int32 nLayoutMode )
622 ::set_flag( mnFlags, EXC_SXVDEX_LAYOUT_REPORT, nLayoutMode != ScDPLayoutMode::TABULAR_LAYOUT );
623 ::set_flag( mnFlags, EXC_SXVDEX_LAYOUT_TOP, nLayoutMode == ScDPLayoutMode::OUTLINE_SUBTOTALS_TOP );
626 XclImpStream& operator>>( XclImpStream& rStrm, XclPTFieldExtInfo& rInfo )
628 sal_uInt8 nNameLen = 0;
629 rInfo.mnFlags = rStrm.ReaduInt32();
630 rInfo.mnSortField = rStrm.ReaduInt16();
631 rInfo.mnShowField = rStrm.ReaduInt16();
632 rInfo.mnNumFmt = rStrm.ReaduInt16();
633 nNameLen = rStrm.ReaduInt8();
635 rStrm.Ignore(10);
636 if (nNameLen != 0xFF)
637 // Custom field total name is used. Pick it up.
638 rInfo.mpFieldTotalName.reset(new OUString(rStrm.ReadUniString(nNameLen, 0)));
640 return rStrm;
643 XclExpStream& operator<<( XclExpStream& rStrm, const XclPTFieldExtInfo& rInfo )
645 rStrm << rInfo.mnFlags
646 << rInfo.mnSortField
647 << rInfo.mnShowField
648 << EXC_SXVDEX_FORMAT_NONE;
650 if (rInfo.mpFieldTotalName.get() && !rInfo.mpFieldTotalName->isEmpty())
652 OUString aFinalName = *rInfo.mpFieldTotalName;
653 if (aFinalName.getLength() >= 254)
654 aFinalName = aFinalName.copy(0, 254);
655 sal_uInt8 nNameLen = static_cast<sal_uInt8>(aFinalName.getLength());
656 rStrm << nNameLen;
657 rStrm.WriteZeroBytes(10);
658 rStrm << XclExpString(aFinalName, EXC_STR_NOHEADER);
660 else
662 rStrm << sal_uInt16(0xFFFF);
663 rStrm.WriteZeroBytes(8);
665 return rStrm;
668 // Page field settings ========================================================
670 XclPTPageFieldInfo::XclPTPageFieldInfo() :
671 mnField( 0 ),
672 mnSelItem( EXC_SXPI_ALLITEMS ),
673 mnObjId( 0xFFFF )
677 XclImpStream& operator>>( XclImpStream& rStrm, XclPTPageFieldInfo& rInfo )
679 rInfo.mnField = rStrm.ReaduInt16();
680 rInfo.mnSelItem = rStrm.ReaduInt16();
681 rInfo.mnObjId = rStrm.ReaduInt16();
682 return rStrm;
685 XclExpStream& operator<<( XclExpStream& rStrm, const XclPTPageFieldInfo& rInfo )
687 return rStrm
688 << rInfo.mnField
689 << rInfo.mnSelItem
690 << rInfo.mnObjId;
693 // Data field settings ========================================================
695 XclPTDataFieldInfo::XclPTDataFieldInfo() :
696 mnField( 0 ),
697 mnAggFunc( EXC_SXDI_FUNC_SUM ),
698 mnRefType( EXC_SXDI_REF_NORMAL ),
699 mnRefField( 0 ),
700 mnRefItem( 0 ),
701 mnNumFmt( 0 )
705 GeneralFunction XclPTDataFieldInfo::GetApiAggFunc() const
707 using namespace ::com::sun::star::sheet;
708 GeneralFunction eAggFunc;
709 switch( mnAggFunc )
711 case EXC_SXDI_FUNC_SUM: eAggFunc = GeneralFunction_SUM; break;
712 case EXC_SXDI_FUNC_COUNT: eAggFunc = GeneralFunction_COUNT; break;
713 case EXC_SXDI_FUNC_AVERAGE: eAggFunc = GeneralFunction_AVERAGE; break;
714 case EXC_SXDI_FUNC_MAX: eAggFunc = GeneralFunction_MAX; break;
715 case EXC_SXDI_FUNC_MIN: eAggFunc = GeneralFunction_MIN; break;
716 case EXC_SXDI_FUNC_PRODUCT: eAggFunc = GeneralFunction_PRODUCT; break;
717 case EXC_SXDI_FUNC_COUNTNUM: eAggFunc = GeneralFunction_COUNTNUMS; break;
718 case EXC_SXDI_FUNC_STDDEV: eAggFunc = GeneralFunction_STDEV; break;
719 case EXC_SXDI_FUNC_STDDEVP: eAggFunc = GeneralFunction_STDEVP; break;
720 case EXC_SXDI_FUNC_VAR: eAggFunc = GeneralFunction_VAR; break;
721 case EXC_SXDI_FUNC_VARP: eAggFunc = GeneralFunction_VARP; break;
722 default: eAggFunc = GeneralFunction_SUM;
724 return eAggFunc;
727 void XclPTDataFieldInfo::SetApiAggFunc( GeneralFunction eAggFunc )
729 using namespace ::com::sun::star::sheet;
730 switch( eAggFunc )
732 case GeneralFunction_SUM: mnAggFunc = EXC_SXDI_FUNC_SUM; break;
733 case GeneralFunction_COUNT: mnAggFunc = EXC_SXDI_FUNC_COUNT; break;
734 case GeneralFunction_AVERAGE: mnAggFunc = EXC_SXDI_FUNC_AVERAGE; break;
735 case GeneralFunction_MAX: mnAggFunc = EXC_SXDI_FUNC_MAX; break;
736 case GeneralFunction_MIN: mnAggFunc = EXC_SXDI_FUNC_MIN; break;
737 case GeneralFunction_PRODUCT: mnAggFunc = EXC_SXDI_FUNC_PRODUCT; break;
738 case GeneralFunction_COUNTNUMS: mnAggFunc = EXC_SXDI_FUNC_COUNTNUM; break;
739 case GeneralFunction_STDEV: mnAggFunc = EXC_SXDI_FUNC_STDDEV; break;
740 case GeneralFunction_STDEVP: mnAggFunc = EXC_SXDI_FUNC_STDDEVP; break;
741 case GeneralFunction_VAR: mnAggFunc = EXC_SXDI_FUNC_VAR; break;
742 case GeneralFunction_VARP: mnAggFunc = EXC_SXDI_FUNC_VARP; break;
743 default: mnAggFunc = EXC_SXDI_FUNC_SUM;
747 sal_Int32 XclPTDataFieldInfo::GetApiRefType() const
749 namespace ScDPRefType = ::com::sun::star::sheet::DataPilotFieldReferenceType;
750 sal_Int32 nRefType;
751 switch( mnRefType )
753 case EXC_SXDI_REF_DIFF: nRefType = ScDPRefType::ITEM_DIFFERENCE; break;
754 case EXC_SXDI_REF_PERC: nRefType = ScDPRefType::ITEM_PERCENTAGE; break;
755 case EXC_SXDI_REF_PERC_DIFF: nRefType = ScDPRefType::ITEM_PERCENTAGE_DIFFERENCE; break;
756 case EXC_SXDI_REF_RUN_TOTAL: nRefType = ScDPRefType::RUNNING_TOTAL; break;
757 case EXC_SXDI_REF_PERC_ROW: nRefType = ScDPRefType::ROW_PERCENTAGE; break;
758 case EXC_SXDI_REF_PERC_COL: nRefType = ScDPRefType::COLUMN_PERCENTAGE; break;
759 case EXC_SXDI_REF_PERC_TOTAL: nRefType = ScDPRefType::TOTAL_PERCENTAGE; break;
760 case EXC_SXDI_REF_INDEX: nRefType = ScDPRefType::INDEX; break;
761 default: nRefType = ScDPRefType::NONE;
763 return nRefType;
766 void XclPTDataFieldInfo::SetApiRefType( sal_Int32 nRefType )
768 namespace ScDPRefType = ::com::sun::star::sheet::DataPilotFieldReferenceType;
769 switch( nRefType )
771 case ScDPRefType::ITEM_DIFFERENCE: mnRefType = EXC_SXDI_REF_DIFF; break;
772 case ScDPRefType::ITEM_PERCENTAGE: mnRefType = EXC_SXDI_REF_PERC; break;
773 case ScDPRefType::ITEM_PERCENTAGE_DIFFERENCE: mnRefType = EXC_SXDI_REF_PERC_DIFF; break;
774 case ScDPRefType::RUNNING_TOTAL: mnRefType = EXC_SXDI_REF_RUN_TOTAL; break;
775 case ScDPRefType::ROW_PERCENTAGE: mnRefType = EXC_SXDI_REF_PERC_ROW; break;
776 case ScDPRefType::COLUMN_PERCENTAGE: mnRefType = EXC_SXDI_REF_PERC_COL; break;
777 case ScDPRefType::TOTAL_PERCENTAGE: mnRefType = EXC_SXDI_REF_PERC_TOTAL;break;
778 case ScDPRefType::INDEX: mnRefType = EXC_SXDI_REF_INDEX; break;
779 default: mnRefType = EXC_SXDI_REF_NORMAL;
783 sal_Int32 XclPTDataFieldInfo::GetApiRefItemType() const
785 sal_Int32 nRefItemType;
786 switch( mnRefItem )
788 case EXC_SXDI_PREVITEM: nRefItemType = ScDPRefItemType::PREVIOUS; break;
789 case EXC_SXDI_NEXTITEM: nRefItemType = ScDPRefItemType::NEXT; break;
790 default: nRefItemType = ScDPRefItemType::NAMED;
792 return nRefItemType;
795 void XclPTDataFieldInfo::SetApiRefItemType( sal_Int32 nRefItemType )
797 switch( nRefItemType )
799 case ScDPRefItemType::PREVIOUS: mnRefItem = EXC_SXDI_PREVITEM; break;
800 case ScDPRefItemType::NEXT: mnRefItem = EXC_SXDI_NEXTITEM; break;
801 // nothing for named item reference
805 XclImpStream& operator>>( XclImpStream& rStrm, XclPTDataFieldInfo& rInfo )
807 rInfo.mnField = rStrm.ReaduInt16();
808 rInfo.mnAggFunc = rStrm.ReaduInt16();
809 rInfo.mnRefType = rStrm.ReaduInt16();
810 rInfo.mnRefField = rStrm.ReaduInt16();
811 rInfo.mnRefItem = rStrm.ReaduInt16();
812 rInfo.mnNumFmt = rStrm.ReaduInt16();
813 rStrm >> rInfo.maVisName;
814 return rStrm;
817 XclExpStream& operator<<( XclExpStream& rStrm, const XclPTDataFieldInfo& rInfo )
819 return rStrm
820 << rInfo.mnField
821 << rInfo.mnAggFunc
822 << rInfo.mnRefType
823 << rInfo.mnRefField
824 << rInfo.mnRefItem
825 << rInfo.mnNumFmt
826 << rInfo.maVisName;
829 // Pivot table settings =======================================================
831 XclPTInfo::XclPTInfo() :
832 mnFirstHeadRow( 0 ),
833 mnCacheIdx( 0xFFFF ),
834 mnDataAxis( EXC_SXVD_AXIS_NONE ),
835 mnDataPos( EXC_SXVIEW_DATALAST ),
836 mnFields( 0 ),
837 mnRowFields( 0 ),
838 mnColFields( 0 ),
839 mnPageFields( 0 ),
840 mnDataFields( 0 ),
841 mnDataRows( 0 ),
842 mnDataCols( 0 ),
843 mnFlags( EXC_SXVIEW_DEFAULTFLAGS ),
844 mnAutoFmtIdx( EXC_SXVIEW_AUTOFMT )
848 XclImpStream& operator>>( XclImpStream& rStrm, XclPTInfo& rInfo )
850 sal_uInt16 nTabLen, nDataLen;
852 rStrm >> rInfo.maOutXclRange;
853 rInfo.mnFirstHeadRow = rStrm.ReaduInt16();
854 rStrm >> rInfo.maDataXclPos;
855 rInfo.mnCacheIdx = rStrm.ReaduInt16();
856 rStrm.Ignore( 2 );
857 rInfo.mnDataAxis = rStrm.ReaduInt16();
858 rInfo.mnDataPos = rStrm.ReaduInt16();
859 rInfo.mnFields = rStrm.ReaduInt16();
860 rInfo.mnRowFields = rStrm.ReaduInt16();
861 rInfo.mnColFields = rStrm.ReaduInt16();
862 rInfo.mnPageFields = rStrm.ReaduInt16();
863 rInfo.mnDataFields = rStrm.ReaduInt16();
864 rInfo.mnDataRows = rStrm.ReaduInt16();
865 rInfo.mnDataCols = rStrm.ReaduInt16();
866 rInfo.mnFlags = rStrm.ReaduInt16();
867 rInfo.mnAutoFmtIdx = rStrm.ReaduInt16();
868 nTabLen = rStrm.ReaduInt16();
869 nDataLen = rStrm.ReaduInt16();
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 rInfo.mnSxformulaRecs = rStrm.ReaduInt16();
914 rStrm.Ignore( 6 );
915 rInfo.mnSxselectRecs = rStrm.ReaduInt16();
916 rInfo.mnPagePerRow = rStrm.ReaduInt16();
917 rInfo.mnPagePerCol = rStrm.ReaduInt16();
918 rInfo.mnFlags = rStrm.ReaduInt32();
919 return rStrm;
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 // Pivot table autoformat settings ============================================
941 classic : 10 08 00 00 00 00 00 00 20 00 00 00 01 00 00 00 00
942 default : 10 08 00 00 00 00 00 00 20 00 00 00 01 00 00 00 00
943 report01 : 10 08 02 00 00 00 00 00 20 00 00 00 00 10 00 00 00
944 report02 : 10 08 02 00 00 00 00 00 20 00 00 00 01 10 00 00 00
945 report03 : 10 08 02 00 00 00 00 00 20 00 00 00 02 10 00 00 00
946 report04 : 10 08 02 00 00 00 00 00 20 00 00 00 03 10 00 00 00
947 report05 : 10 08 02 00 00 00 00 00 20 00 00 00 04 10 00 00 00
948 report06 : 10 08 02 00 00 00 00 00 20 00 00 00 05 10 00 00 00
949 report07 : 10 08 02 00 00 00 00 00 20 00 00 00 06 10 00 00 00
950 report08 : 10 08 02 00 00 00 00 00 20 00 00 00 07 10 00 00 00
951 report09 : 10 08 02 00 00 00 00 00 20 00 00 00 08 10 00 00 00
952 report10 : 10 08 02 00 00 00 00 00 20 00 00 00 09 10 00 00 00
953 table01 : 10 08 00 00 00 00 00 00 20 00 00 00 0a 10 00 00 00
954 table02 : 10 08 00 00 00 00 00 00 20 00 00 00 0b 10 00 00 00
955 table03 : 10 08 00 00 00 00 00 00 20 00 00 00 0c 10 00 00 00
956 table04 : 10 08 00 00 00 00 00 00 20 00 00 00 0d 10 00 00 00
957 table05 : 10 08 00 00 00 00 00 00 20 00 00 00 0e 10 00 00 00
958 table06 : 10 08 00 00 00 00 00 00 20 00 00 00 0f 10 00 00 00
959 table07 : 10 08 00 00 00 00 00 00 20 00 00 00 10 10 00 00 00
960 table08 : 10 08 00 00 00 00 00 00 20 00 00 00 11 10 00 00 00
961 table09 : 10 08 00 00 00 00 00 00 20 00 00 00 12 10 00 00 00
962 table10 : 10 08 00 00 00 00 00 00 20 00 00 00 13 10 00 00 00
963 none : 10 08 00 00 00 00 00 00 20 00 00 00 15 10 00 00 00
966 XclPTViewEx9Info::XclPTViewEx9Info() :
967 mbReport( 0 ),
968 mnAutoFormat( 0 ),
969 mnGridLayout( 0x10 )
973 void XclPTViewEx9Info::Init( const ScDPObject& rDPObj )
975 if( rDPObj.GetHeaderLayout() )
977 mbReport = 0;
978 mnAutoFormat = 1;
979 mnGridLayout = 0;
981 else
983 // Report1 for now
984 // TODO : sync with autoformat indices
985 mbReport = 2;
986 mnAutoFormat = 1;
987 mnGridLayout = 0x10;
990 const ScDPSaveData* pData = rDPObj.GetSaveData();
991 if (pData)
993 const OUString* pGrandTotal = pData->GetGrandTotalName();
994 if (pGrandTotal)
995 maGrandTotalName = *pGrandTotal;
999 XclImpStream& operator>>( XclImpStream& rStrm, XclPTViewEx9Info& rInfo )
1001 rStrm.Ignore( 2 );
1002 rInfo.mbReport = rStrm.ReaduInt32(); /// 2 for report* fmts ?
1003 rStrm.Ignore( 6 );
1004 rInfo.mnAutoFormat = rStrm.ReaduInt8();
1005 rInfo.mnGridLayout = rStrm.ReaduInt8();
1006 rInfo.maGrandTotalName = rStrm.ReadUniString();
1007 return rStrm;
1010 XclExpStream& operator<<( XclExpStream& rStrm, const XclPTViewEx9Info& rInfo )
1012 return rStrm
1013 << EXC_PT_AUTOFMT_HEADER
1014 << rInfo.mbReport
1015 << EXC_PT_AUTOFMT_ZERO
1016 << EXC_PT_AUTOFMT_FLAGS
1017 << rInfo.mnAutoFormat
1018 << rInfo.mnGridLayout
1019 << XclExpString(rInfo.maGrandTotalName, EXC_STR_DEFAULT, EXC_PT_MAXSTRLEN);
1022 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */