sync master with lastest vba changes
[ooovba.git] / sc / source / ui / unoobj / dapiuno.cxx
blob7a72040df578630be6a75da362736fe41a45c156
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: dapiuno.cxx,v $
10 * $Revision: 1.21.30.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"
36 #include <svtools/smplhint.hxx>
37 #include <rtl/uuid.h>
39 #include "dapiuno.hxx"
40 #include "datauno.hxx"
41 #include "miscuno.hxx"
42 #include "docsh.hxx"
43 #include "tabvwsh.hxx"
44 #include "pivot.hxx"
45 #include "rangeutl.hxx"
46 #include "unoguard.hxx"
47 #include "dpobject.hxx"
48 #include "dpshttab.hxx"
49 #include "dpsave.hxx"
50 #include "dbdocfun.hxx"
51 #include "unonames.hxx"
52 #include "dpgroup.hxx"
53 #include "dpdimsave.hxx"
54 #include <com/sun/star/sheet/XHierarchiesSupplier.hpp>
55 #include <com/sun/star/sheet/XLevelsSupplier.hpp>
56 #include <com/sun/star/sheet/XMembersSupplier.hpp>
57 #include <com/sun/star/beans/PropertyAttribute.hpp>
58 #include <com/sun/star/sheet/DataPilotFieldGroupBy.hpp>
59 #include <com/sun/star/sheet/DataPilotFieldFilter.hpp>
60 #include <com/sun/star/sheet/DataPilotOutputRangeType.hpp>
61 #include <com/sun/star/sheet/DataPilotTablePositionData.hpp>
63 #include <comphelper/extract.hxx>
65 using namespace com::sun::star;
67 using ::com::sun::star::lang::IllegalArgumentException;
68 using ::com::sun::star::sheet::DataPilotFieldFilter;
69 using ::com::sun::star::sheet::DataPilotTablePositionData;
70 using ::com::sun::star::uno::Sequence;
71 using ::com::sun::star::table::CellAddress;
72 using ::com::sun::star::table::CellRangeAddress;
73 using ::com::sun::star::uno::RuntimeException;
74 using ::com::sun::star::uno::Any;
76 //------------------------------------------------------------------------
78 const SfxItemPropertyMap* lcl_GetDataPilotDescriptorBaseMap()
80 static SfxItemPropertyMap aDataPilotDescriptorBaseMap_Impl[] =
82 {MAP_CHAR_LEN(SC_UNO_COLGRAND), 0, &getBooleanCppuType(), 0, 0 },
83 {MAP_CHAR_LEN(SC_UNO_DRILLDOWN),0, &getBooleanCppuType(), 0, 0 },
84 {MAP_CHAR_LEN(SC_UNO_IGNEMPROWS),0, &getBooleanCppuType(), 0, 0 },
85 {MAP_CHAR_LEN(SC_UNO_RPTEMPTY), 0, &getBooleanCppuType(), 0, 0 },
86 {MAP_CHAR_LEN(SC_UNO_ROWGRAND), 0, &getBooleanCppuType(), 0, 0 },
87 {MAP_CHAR_LEN(SC_UNO_SHOWFILT), 0, &getBooleanCppuType(), 0, 0 },
88 {0,0,0,0,0,0}
90 return aDataPilotDescriptorBaseMap_Impl;
93 //------------------------------------------------------------------------
95 const SfxItemPropertyMap* lcl_GetDataPilotFieldMap()
97 static SfxItemPropertyMap aDataPilotFieldMap_Impl[] =
99 {MAP_CHAR_LEN(SC_UNONAME_AUTOSHOW), 0, &getCppuType((sheet::DataPilotFieldAutoShowInfo*)0),0 | beans::PropertyAttribute::MAYBEVOID, 0 },
100 {MAP_CHAR_LEN(SC_UNONAME_FUNCTION), 0, &getCppuType((sheet::GeneralFunction*)0), 0, 0 },
101 {MAP_CHAR_LEN(SC_UNONAME_GROUPINFO), 0, &getCppuType((sheet::DataPilotFieldGroupInfo*)0), 0 | beans::PropertyAttribute::MAYBEVOID, 0 },
102 {MAP_CHAR_LEN(SC_UNONAME_HASAUTOSHOW), 0, &getBooleanCppuType(), 0, 0 },
103 {MAP_CHAR_LEN(SC_UNONAME_HASLAYOUTINFO),0, &getBooleanCppuType(), 0, 0 },
104 {MAP_CHAR_LEN(SC_UNONAME_HASREFERENCE), 0, &getBooleanCppuType(), 0, 0 },
105 {MAP_CHAR_LEN(SC_UNONAME_HASSORTINFO), 0, &getBooleanCppuType(), 0, 0 },
106 {MAP_CHAR_LEN(SC_UNONAME_ISGROUP), 0, &getBooleanCppuType(), 0, 0 },
107 {MAP_CHAR_LEN(SC_UNONAME_LAYOUTINFO), 0, &getCppuType((sheet::DataPilotFieldLayoutInfo*)0), 0 | beans::PropertyAttribute::MAYBEVOID, 0 },
108 {MAP_CHAR_LEN(SC_UNONAME_ORIENT), 0, &getCppuType((sheet::DataPilotFieldOrientation*)0), 0 | beans::PropertyAttribute::MAYBEVOID, 0 },
109 {MAP_CHAR_LEN(SC_UNONAME_REFERENCE), 0, &getCppuType((sheet::DataPilotFieldReference*)0), 0 | beans::PropertyAttribute::MAYBEVOID, 0 },
110 {MAP_CHAR_LEN(SC_UNONAME_SELPAGE), 0, &getCppuType((rtl::OUString*)0), 0, 0 },
111 {MAP_CHAR_LEN(SC_UNONAME_SHOWEMPTY), 0, &getBooleanCppuType(), 0, 0 },
112 {MAP_CHAR_LEN(SC_UNONAME_SORTINFO), 0, &getCppuType((sheet::DataPilotFieldSortInfo*)0), 0 | beans::PropertyAttribute::MAYBEVOID, 0 },
113 {MAP_CHAR_LEN(SC_UNONAME_USESELPAGE), 0, &getBooleanCppuType(), 0, 0 },
114 {0,0,0,0,0,0}
116 return aDataPilotFieldMap_Impl;
119 const SfxItemPropertyMap* lcl_GetDataPilotItemMap()
121 static SfxItemPropertyMap aDataPilotItemMap_Impl[] =
123 {MAP_CHAR_LEN(SC_UNONAME_ISHIDDEN), 0, &getBooleanCppuType(), 0, 0 },
124 {MAP_CHAR_LEN(SC_UNONAME_POS), 0, &getCppuType((sal_Int32*)0), 0, 0 },
125 {MAP_CHAR_LEN(SC_UNONAME_SHOWDETAIL), 0, &getBooleanCppuType(), 0, 0 },
126 {0,0,0,0,0,0}
128 return aDataPilotItemMap_Impl;
131 //------------------------------------------------------------------------
133 SC_SIMPLE_SERVICE_INFO( ScDataPilotDescriptor, "ScDataPilotDescriptor", "stardiv::one::sheet::DataPilotDescriptor" )
134 SC_SIMPLE_SERVICE_INFO( ScDataPilotFieldObj, "ScDataPilotFieldObj", "com.sun.star.sheet.DataPilotField" )
135 SC_SIMPLE_SERVICE_INFO( ScDataPilotFieldsObj, "ScDataPilotFieldsObj", "com.sun.star.sheet.DataPilotFields" )
136 SC_SIMPLE_SERVICE_INFO( ScDataPilotTableObj, "ScDataPilotTableObj", "com.sun.star.sheet.DataPilotTable" )
137 SC_SIMPLE_SERVICE_INFO( ScDataPilotTablesObj, "ScDataPilotTablesObj", "com.sun.star.sheet.DataPilotTables" )
138 SC_SIMPLE_SERVICE_INFO( ScDataPilotItemsObj, "ScDataPilotItemsObj", "com.sun.star.sheet.DataPilotItems" )
139 SC_SIMPLE_SERVICE_INFO( ScDataPilotItemObj, "ScDataPilotItemObj", "com.sun.star.sheet.DataPilotItem" )
141 SC_SIMPLE_SERVICE_INFO( ScDataPilotFieldGroupsObj, "ScDataPilotFieldGroupsObj", "com.sun.star.sheet.DataPilotFieldGroups" )
142 SC_SIMPLE_SERVICE_INFO( ScDataPilotFieldGroupObj, "ScDataPilotFieldGroupObj", "com.sun.star.sheet.DataPilotFieldGroup" )
143 SC_SIMPLE_SERVICE_INFO( ScDataPilotFieldGroupItemObj, "ScDataPilotFieldGroupItemObj", "com.sun.star.sheet.DataPilotFieldGroupItem" )
145 //------------------------------------------------------------------------
147 //! irgendwann ueberall die neuen enum-Werte benutzen
148 #define DATA_PILOT_HIDDEN sheet::DataPilotFieldOrientation_HIDDEN
149 #define DATA_PILOT_COLUMN sheet::DataPilotFieldOrientation_COLUMN
150 #define DATA_PILOT_ROW sheet::DataPilotFieldOrientation_ROW
151 #define DATA_PILOT_PAGE sheet::DataPilotFieldOrientation_PAGE
152 #define DATA_PILOT_DATA sheet::DataPilotFieldOrientation_DATA
154 //------------------------------------------------------------------------
156 // name that is used in the API for the data layout field
157 #define SC_DATALAYOUT_NAME "Data"
159 //------------------------------------------------------------------------
161 sheet::GeneralFunction ScDataPilotConversion::FirstFunc( USHORT nBits )
163 if ( nBits & PIVOT_FUNC_SUM ) return sheet::GeneralFunction_SUM;
164 if ( nBits & PIVOT_FUNC_COUNT ) return sheet::GeneralFunction_COUNT;
165 if ( nBits & PIVOT_FUNC_AVERAGE ) return sheet::GeneralFunction_AVERAGE;
166 if ( nBits & PIVOT_FUNC_MAX ) return sheet::GeneralFunction_MAX;
167 if ( nBits & PIVOT_FUNC_MIN ) return sheet::GeneralFunction_MIN;
168 if ( nBits & PIVOT_FUNC_PRODUCT ) return sheet::GeneralFunction_PRODUCT;
169 if ( nBits & PIVOT_FUNC_COUNT_NUM ) return sheet::GeneralFunction_COUNTNUMS;
170 if ( nBits & PIVOT_FUNC_STD_DEV ) return sheet::GeneralFunction_STDEV;
171 if ( nBits & PIVOT_FUNC_STD_DEVP ) return sheet::GeneralFunction_STDEVP;
172 if ( nBits & PIVOT_FUNC_STD_VAR ) return sheet::GeneralFunction_VAR;
173 if ( nBits & PIVOT_FUNC_STD_VARP ) return sheet::GeneralFunction_VARP;
174 if ( nBits & PIVOT_FUNC_AUTO ) return sheet::GeneralFunction_AUTO;
175 return sheet::GeneralFunction_NONE;
178 USHORT ScDataPilotConversion::FunctionBit( sheet::GeneralFunction eFunc )
180 USHORT nRet = PIVOT_FUNC_NONE; // 0
181 switch (eFunc)
183 case sheet::GeneralFunction_SUM: nRet = PIVOT_FUNC_SUM; break;
184 case sheet::GeneralFunction_COUNT: nRet = PIVOT_FUNC_COUNT; break;
185 case sheet::GeneralFunction_AVERAGE: nRet = PIVOT_FUNC_AVERAGE; break;
186 case sheet::GeneralFunction_MAX: nRet = PIVOT_FUNC_MAX; break;
187 case sheet::GeneralFunction_MIN: nRet = PIVOT_FUNC_MIN; break;
188 case sheet::GeneralFunction_PRODUCT: nRet = PIVOT_FUNC_PRODUCT; break;
189 case sheet::GeneralFunction_COUNTNUMS: nRet = PIVOT_FUNC_COUNT_NUM; break;
190 case sheet::GeneralFunction_STDEV: nRet = PIVOT_FUNC_STD_DEV; break;
191 case sheet::GeneralFunction_STDEVP: nRet = PIVOT_FUNC_STD_DEVP; break;
192 case sheet::GeneralFunction_VAR: nRet = PIVOT_FUNC_STD_VAR; break;
193 case sheet::GeneralFunction_VARP: nRet = PIVOT_FUNC_STD_VARP; break;
194 case sheet::GeneralFunction_AUTO: nRet = PIVOT_FUNC_AUTO; break;
195 default:
197 // added to avoid warnings
200 return nRet;
203 //------------------------------------------------------------------------
205 ScDPObject* lcl_GetDPObject( ScDocShell* pDocShell, SCTAB nTab, const String& rName )
207 if (pDocShell)
209 ScDocument* pDoc = pDocShell->GetDocument();
210 ScDPCollection* pColl = pDoc->GetDPCollection();
211 if ( pColl )
213 USHORT nCount = pColl->GetCount();
214 for (USHORT i=0; i<nCount; i++)
216 ScDPObject* pDPObj = (*pColl)[i];
217 if ( pDPObj->IsSheetData() &&
218 pDPObj->GetOutRange().aStart.Tab() == nTab &&
219 pDPObj->GetName() == rName )
220 return pDPObj;
224 return NULL; // nicht gefunden
227 String lcl_CreatePivotName( ScDocShell* pDocShell )
229 if (pDocShell)
231 ScDocument* pDoc = pDocShell->GetDocument();
232 ScDPCollection* pColl = pDoc->GetDPCollection();
233 if ( pColl )
234 return pColl->CreateNewName();
236 return String(); // sollte nicht vorkommen
239 sal_Int32 lcl_GetObjectIndex( ScDPObject* pDPObj, const ScFieldIdentifier& rIdent )
241 // used for items - nRepeat in identifier can be ignored
243 if ( pDPObj )
245 sal_Int32 nCount = pDPObj->GetDimCount();
246 for ( sal_Int32 nDim = 0; nDim < nCount; nDim++ )
248 BOOL bIsDataLayout = FALSE;
249 String aDimName( pDPObj->GetDimName( nDim, bIsDataLayout ) );
250 if ( rIdent.bDataLayoutField ? bIsDataLayout : ( aDimName == rIdent.sFieldName ) )
251 return nDim;
254 return -1; // none
257 BOOL lcl_GetMembers( ScDataPilotDescriptorBase* pParent, const ScFieldIdentifier& rIdent, uno::Reference<container::XNameAccess>& xMembers )
259 ScDPObject* pDPObj(pParent->GetDPObject());
260 sal_Int32 nObjIndex = lcl_GetObjectIndex( pDPObj, rIdent );
261 return pDPObj && pDPObj->GetMembersNA( nObjIndex, xMembers );
264 //------------------------------------------------------------------------
266 ScDataPilotTablesObj::ScDataPilotTablesObj(ScDocShell* pDocSh, SCTAB nT) :
267 pDocShell( pDocSh ),
268 nTab( nT )
270 pDocShell->GetDocument()->AddUnoObject(*this);
273 ScDataPilotTablesObj::~ScDataPilotTablesObj()
275 if (pDocShell)
276 pDocShell->GetDocument()->RemoveUnoObject(*this);
279 void ScDataPilotTablesObj::Notify( SfxBroadcaster&, const SfxHint& rHint )
281 //! Referenz-Update
283 if ( rHint.ISA( SfxSimpleHint ) &&
284 ((const SfxSimpleHint&)rHint).GetId() == SFX_HINT_DYING )
286 pDocShell = NULL; // ungueltig geworden
290 // XDataPilotTables
292 ScDataPilotTableObj* ScDataPilotTablesObj::GetObjectByIndex_Impl(SCSIZE nIndex)
294 if (pDocShell)
296 ScDocument* pDoc = pDocShell->GetDocument();
297 ScDPCollection* pColl = pDoc->GetDPCollection();
298 if ( pColl )
300 // count tables on this sheet
301 // api only handles sheet data at this time
302 //! allow all data sources!!!
303 SCSIZE nFound = 0;
304 USHORT nCount = pColl->GetCount();
305 for (USHORT i=0; i<nCount; i++)
307 ScDPObject* pDPObj = (*pColl)[i];
308 if ( pDPObj->IsSheetData() && pDPObj->GetOutRange().aStart.Tab() == nTab )
310 if ( nFound == nIndex )
312 String aName = pDPObj->GetName();
313 return new ScDataPilotTableObj( pDocShell, nTab, aName );
315 ++nFound;
320 return NULL;
323 ScDataPilotTableObj* ScDataPilotTablesObj::GetObjectByName_Impl(const rtl::OUString& aName)
325 if (hasByName(aName))
327 String aNamStr(aName);
328 return new ScDataPilotTableObj( pDocShell, nTab, aNamStr );
330 return NULL;
333 uno::Reference<sheet::XDataPilotDescriptor> SAL_CALL ScDataPilotTablesObj::createDataPilotDescriptor()
334 throw(uno::RuntimeException)
336 ScUnoGuard aGuard;
337 if (pDocShell)
338 return new ScDataPilotDescriptor(pDocShell);
339 return NULL;
342 bool lcl_IsDuplicated( const uno::Reference<beans::XPropertySet> xDimProps )
344 bool bRet = false;
348 uno::Any aAny = xDimProps->getPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNO_ORIGINAL)));
349 uno::Reference<container::XNamed> xOriginal( aAny, uno::UNO_QUERY );
350 if ( xOriginal.is() )
351 bRet = true;
353 catch(uno::Exception&)
357 return bRet;
360 rtl::OUString lcl_GetOriginalName( const uno::Reference<container::XNamed> xDim )
362 uno::Reference<container::XNamed> xOriginal;
364 uno::Reference<beans::XPropertySet> xDimProps( xDim, uno::UNO_QUERY );
365 if ( xDimProps.is() )
369 uno::Any aAny = xDimProps->getPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNO_ORIGINAL)));
370 aAny >>= xOriginal;
372 catch(uno::Exception&)
377 if ( !xOriginal.is() )
378 xOriginal = xDim;
380 return xOriginal->getName();
383 void SAL_CALL ScDataPilotTablesObj::insertNewByName( const rtl::OUString& aNewName,
384 const table::CellAddress& aOutputAddress,
385 const uno::Reference<sheet::XDataPilotDescriptor>& xDescriptor )
386 throw(uno::RuntimeException)
388 ScUnoGuard aGuard;
389 if (!xDescriptor.is()) return;
391 // inserting with already existing name?
392 if ( aNewName.getLength() && hasByName( aNewName ) )
393 throw uno::RuntimeException(); // no other exceptions specified
395 BOOL bDone = FALSE;
396 ScDataPilotDescriptorBase* pImp = ScDataPilotDescriptorBase::getImplementation( xDescriptor );
397 if ( pDocShell && pImp )
399 ScDPObject* pNewObj = pImp->GetDPObject();
401 if (pNewObj)
403 ScRange aOutputRange((SCCOL)aOutputAddress.Column, (SCROW)aOutputAddress.Row, (SCTAB)aOutputAddress.Sheet,
404 (SCCOL)aOutputAddress.Column, (SCROW)aOutputAddress.Row, (SCTAB)aOutputAddress.Sheet);
405 pNewObj->SetOutRange(aOutputRange);
406 String aName = aNewName;
407 if (!aName.Len())
408 aName = lcl_CreatePivotName( pDocShell );
409 pNewObj->SetName(aName);
410 String aTag = xDescriptor->getTag();
411 pNewObj->SetTag(aTag);
413 // todo: handle double fields (for more information see ScDPObject
415 ScDBDocFunc aFunc(*pDocShell);
416 bDone = aFunc.DataPilotUpdate( NULL, pNewObj, TRUE, TRUE );
420 if (!bDone)
421 throw uno::RuntimeException(); // no other exceptions specified
424 void SAL_CALL ScDataPilotTablesObj::removeByName( const rtl::OUString& aName )
425 throw(uno::RuntimeException)
427 ScUnoGuard aGuard;
428 String aNameStr(aName);
429 ScDPObject* pDPObj = lcl_GetDPObject( pDocShell, nTab, aNameStr );
430 if (pDPObj && pDocShell)
432 ScDBDocFunc aFunc(*pDocShell);
433 aFunc.DataPilotUpdate( pDPObj, NULL, TRUE, TRUE ); // remove - incl. undo etc.
435 else
436 throw uno::RuntimeException(); // no other exceptions specified
439 // XEnumerationAccess
441 uno::Reference<container::XEnumeration> SAL_CALL ScDataPilotTablesObj::createEnumeration()
442 throw(uno::RuntimeException)
444 ScUnoGuard aGuard;
445 return new ScIndexEnumeration(this, rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.sheet.DataPilotTablesEnumeration")));
448 // XIndexAccess
450 sal_Int32 SAL_CALL ScDataPilotTablesObj::getCount() throw(uno::RuntimeException)
452 ScUnoGuard aGuard;
453 if ( pDocShell )
455 ScDocument* pDoc = pDocShell->GetDocument();
456 ScDPCollection* pColl = pDoc->GetDPCollection();
457 if ( pColl )
459 // count tables on this sheet
460 // api only handles sheet data at this time
461 //! allow all data sources!!!
463 USHORT nFound = 0;
464 USHORT nCount = pColl->GetCount();
465 for (USHORT i=0; i<nCount; i++)
467 ScDPObject* pDPObj = (*pColl)[i];
468 if ( pDPObj->IsSheetData() && pDPObj->GetOutRange().aStart.Tab() == nTab )
469 ++nFound;
471 return nFound;
475 return 0;
478 uno::Any SAL_CALL ScDataPilotTablesObj::getByIndex( sal_Int32 nIndex )
479 throw(lang::IndexOutOfBoundsException,
480 lang::WrappedTargetException, uno::RuntimeException)
482 ScUnoGuard aGuard;
483 uno::Reference<sheet::XDataPilotTable2> xTable(GetObjectByIndex_Impl(static_cast<SCSIZE>(nIndex)));
484 if (xTable.is())
485 return uno::makeAny(xTable);
486 else
487 throw lang::IndexOutOfBoundsException();
488 // return uno::Any();
491 uno::Type SAL_CALL ScDataPilotTablesObj::getElementType() throw(uno::RuntimeException)
493 ScUnoGuard aGuard;
494 return getCppuType((uno::Reference<sheet::XDataPilotTable2>*)0);
497 sal_Bool SAL_CALL ScDataPilotTablesObj::hasElements() throw(uno::RuntimeException)
499 ScUnoGuard aGuard;
500 return ( getCount() != 0 );
503 // XNameAccess
505 uno::Any SAL_CALL ScDataPilotTablesObj::getByName( const rtl::OUString& aName )
506 throw(container::NoSuchElementException,
507 lang::WrappedTargetException, uno::RuntimeException)
509 ScUnoGuard aGuard;
510 uno::Reference<sheet::XDataPilotTable2> xTable(GetObjectByName_Impl(aName));
511 if (xTable.is())
512 return uno::makeAny(xTable);
513 else
514 throw container::NoSuchElementException();
515 // return uno::Any();
518 uno::Sequence<rtl::OUString> SAL_CALL ScDataPilotTablesObj::getElementNames()
519 throw(uno::RuntimeException)
521 ScUnoGuard aGuard;
522 if (pDocShell)
524 ScDocument* pDoc = pDocShell->GetDocument();
525 ScDPCollection* pColl = pDoc->GetDPCollection();
526 if ( pColl )
528 // count tables on this sheet
529 // api only handles sheet data at this time
530 //! allow all data sources!!!
532 USHORT nFound = 0;
533 USHORT nCount = pColl->GetCount();
534 USHORT i;
535 for (i=0; i<nCount; i++)
537 ScDPObject* pDPObj = (*pColl)[i];
538 if ( pDPObj->IsSheetData() && pDPObj->GetOutRange().aStart.Tab() == nTab )
539 ++nFound;
542 USHORT nPos = 0;
543 uno::Sequence<rtl::OUString> aSeq(nFound);
544 rtl::OUString* pAry = aSeq.getArray();
545 for (i=0; i<nCount; i++)
547 ScDPObject* pDPObj = (*pColl)[i];
548 if ( pDPObj->IsSheetData() && pDPObj->GetOutRange().aStart.Tab() == nTab )
549 pAry[nPos++] = pDPObj->GetName();
552 return aSeq;
555 return uno::Sequence<rtl::OUString>(0);
558 sal_Bool SAL_CALL ScDataPilotTablesObj::hasByName( const rtl::OUString& aName )
559 throw(uno::RuntimeException)
561 ScUnoGuard aGuard;
562 if (pDocShell)
564 ScDocument* pDoc = pDocShell->GetDocument();
565 ScDPCollection* pColl = pDoc->GetDPCollection();
566 if ( pColl )
568 String aNamStr(aName);
569 USHORT nCount = pColl->GetCount();
570 for (USHORT i=0; i<nCount; i++)
572 // api only handles sheet data at this time
573 //! allow all data sources!!!
575 ScDPObject* pDPObj = (*pColl)[i];
576 if ( pDPObj->IsSheetData() &&
577 pDPObj->GetOutRange().aStart.Tab() == nTab &&
578 pDPObj->GetName() == aNamStr )
579 return TRUE;
583 return FALSE;
586 //------------------------------------------------------------------------
588 ScDataPilotDescriptorBase::ScDataPilotDescriptorBase(ScDocShell* pDocSh) :
589 aPropSet( lcl_GetDataPilotDescriptorBaseMap() ),
590 pDocShell( pDocSh )
592 pDocShell->GetDocument()->AddUnoObject(*this);
595 ScDataPilotDescriptorBase::~ScDataPilotDescriptorBase()
597 if (pDocShell)
598 pDocShell->GetDocument()->RemoveUnoObject(*this);
601 uno::Any SAL_CALL ScDataPilotDescriptorBase::queryInterface( const uno::Type& rType )
602 throw(uno::RuntimeException)
604 SC_QUERYINTERFACE( sheet::XDataPilotDescriptor )
605 SC_QUERYINTERFACE( beans::XPropertySet )
606 SC_QUERYINTERFACE( container::XNamed ) // base of XDataPilotDescriptor
607 SC_QUERYINTERFACE( lang::XUnoTunnel )
608 SC_QUERYINTERFACE( lang::XTypeProvider )
609 SC_QUERYINTERFACE( lang::XServiceInfo )
611 return OWeakObject::queryInterface( rType );
614 void SAL_CALL ScDataPilotDescriptorBase::acquire() throw()
616 OWeakObject::acquire();
619 void SAL_CALL ScDataPilotDescriptorBase::release() throw()
621 OWeakObject::release();
624 uno::Sequence<uno::Type> SAL_CALL ScDataPilotDescriptorBase::getTypes()
625 throw(uno::RuntimeException)
627 static uno::Sequence<uno::Type> aTypes;
628 if ( aTypes.getLength() == 0 )
630 aTypes.realloc(5);
631 uno::Type* pPtr = aTypes.getArray();
632 pPtr[0] = getCppuType((const uno::Reference<sheet::XDataPilotDescriptor>*)0);
633 pPtr[1] = getCppuType((const uno::Reference<beans::XPropertySet>*)0);
634 pPtr[2] = getCppuType((const uno::Reference<lang::XUnoTunnel>*)0);
635 pPtr[3] = getCppuType((const uno::Reference<lang::XTypeProvider>*)0);
636 pPtr[4] = getCppuType((const uno::Reference<lang::XServiceInfo>*)0);
638 return aTypes;
641 uno::Sequence<sal_Int8> SAL_CALL ScDataPilotDescriptorBase::getImplementationId()
642 throw(uno::RuntimeException)
644 static uno::Sequence< sal_Int8 > aId;
645 if( aId.getLength() == 0 )
647 aId.realloc( 16 );
648 rtl_createUuid( (sal_uInt8 *)aId.getArray(), 0, sal_True );
650 return aId;
653 void ScDataPilotDescriptorBase::Notify( SfxBroadcaster&, const SfxHint& rHint )
655 //! Referenz-Update?
657 if ( rHint.ISA( SfxSimpleHint ) &&
658 ((const SfxSimpleHint&)rHint).GetId() == SFX_HINT_DYING )
660 pDocShell = NULL; // ungueltig geworden
664 // XDataPilotDescriptor
666 table::CellRangeAddress SAL_CALL ScDataPilotDescriptorBase::getSourceRange()
667 throw(uno::RuntimeException)
669 ScUnoGuard aGuard;
671 table::CellRangeAddress aRet;
673 ScDPObject* pDPObject(GetDPObject());
674 if (pDPObject && pDPObject->IsSheetData())
676 const ScSheetSourceDesc* pSheetDesc = pDPObject->GetSheetDesc();
677 aRet.StartColumn = pSheetDesc->aSourceRange.aStart.Col();
678 aRet.EndColumn = pSheetDesc->aSourceRange.aEnd.Col();
679 aRet.StartRow = pSheetDesc->aSourceRange.aStart.Row();
680 aRet.EndRow = pSheetDesc->aSourceRange.aEnd.Row();
681 aRet.Sheet = pSheetDesc->aSourceRange.aStart.Tab();
683 else
684 throw uno::RuntimeException();
686 return aRet;
689 void SAL_CALL ScDataPilotDescriptorBase::setSourceRange(
690 const table::CellRangeAddress& aSourceRange )
691 throw(uno::RuntimeException)
693 ScUnoGuard aGuard;
695 ScDPObject* pDPObject = GetDPObject();
696 if (pDPObject)
698 ScSheetSourceDesc aSheetDesc;
699 if (pDPObject->IsSheetData())
700 aSheetDesc = *(pDPObject->GetSheetDesc());
701 aSheetDesc.aSourceRange.aStart.SetCol((SCCOL)aSourceRange.StartColumn);
702 aSheetDesc.aSourceRange.aEnd.SetCol((SCCOL)aSourceRange.EndColumn);
703 aSheetDesc.aSourceRange.aStart.SetRow((SCROW)aSourceRange.StartRow);
704 aSheetDesc.aSourceRange.aEnd.SetRow((SCROW)aSourceRange.EndRow);
705 aSheetDesc.aSourceRange.aStart.SetTab((SCTAB)aSourceRange.Sheet);
706 pDPObject->SetSheetDesc(aSheetDesc);
707 SetDPObject(pDPObject);
709 else
710 throw uno::RuntimeException();
713 uno::Reference<sheet::XSheetFilterDescriptor> SAL_CALL ScDataPilotDescriptorBase::getFilterDescriptor()
714 throw(uno::RuntimeException)
716 ScUnoGuard aGuard;
717 return new ScDataPilotFilterDescriptor( pDocShell, this );
720 uno::Reference<container::XIndexAccess> SAL_CALL ScDataPilotDescriptorBase::getDataPilotFields()
721 throw(uno::RuntimeException)
723 ScUnoGuard aGuard;
724 return new ScDataPilotFieldsObj( this, SC_FIELDORIENT_ALL );
727 uno::Reference<container::XIndexAccess> SAL_CALL ScDataPilotDescriptorBase::getColumnFields()
728 throw(uno::RuntimeException)
730 ScUnoGuard aGuard;
731 return new ScDataPilotFieldsObj( this, DATA_PILOT_COLUMN );
734 uno::Reference<container::XIndexAccess> SAL_CALL ScDataPilotDescriptorBase::getRowFields()
735 throw(uno::RuntimeException)
737 ScUnoGuard aGuard;
738 return new ScDataPilotFieldsObj( this, DATA_PILOT_ROW );
741 uno::Reference<container::XIndexAccess> SAL_CALL ScDataPilotDescriptorBase::getPageFields()
742 throw(uno::RuntimeException)
744 ScUnoGuard aGuard;
745 return new ScDataPilotFieldsObj( this, DATA_PILOT_PAGE );
748 uno::Reference<container::XIndexAccess> SAL_CALL ScDataPilotDescriptorBase::getDataFields()
749 throw(uno::RuntimeException)
751 ScUnoGuard aGuard;
752 return new ScDataPilotFieldsObj( this, DATA_PILOT_DATA );
755 uno::Reference<container::XIndexAccess> SAL_CALL ScDataPilotDescriptorBase::getHiddenFields()
756 throw(uno::RuntimeException)
758 ScUnoGuard aGuard;
759 return new ScDataPilotFieldsObj( this, DATA_PILOT_HIDDEN );
762 // XPropertySet
763 uno::Reference< beans::XPropertySetInfo > SAL_CALL ScDataPilotDescriptorBase::getPropertySetInfo( )
764 throw(uno::RuntimeException)
766 ScUnoGuard aGuard;
767 static uno::Reference<beans::XPropertySetInfo> aRef =
768 new SfxItemPropertySetInfo( aPropSet.getPropertyMap() );
769 return aRef;
772 void SAL_CALL ScDataPilotDescriptorBase::setPropertyValue( const ::rtl::OUString& aPropertyName,
773 const ::com::sun::star::uno::Any& aValue )
774 throw(beans::UnknownPropertyException,
775 beans::PropertyVetoException,
776 lang::IllegalArgumentException,
777 lang::WrappedTargetException,
778 uno::RuntimeException)
780 ScUnoGuard aGuard;
781 ScDPObject* pDPObject = GetDPObject();
782 if (pDPObject)
784 ScDPSaveData* pOldData = pDPObject->GetSaveData();
785 DBG_ASSERT(pOldData, "Here should be a SaveData");
786 if ( pOldData )
788 ScDPSaveData aNewData( *pOldData );
790 String aNameString = aPropertyName;
791 if ( aNameString.EqualsAscii( SC_UNO_COLGRAND ) )
793 aNewData.SetColumnGrand(::cppu::any2bool( aValue ));
795 else if ( aNameString.EqualsAscii( SC_UNO_IGNEMPROWS ) )
797 aNewData.SetIgnoreEmptyRows(::cppu::any2bool( aValue ));
799 else if ( aNameString.EqualsAscii( SC_UNO_RPTEMPTY ) )
801 aNewData.SetRepeatIfEmpty(::cppu::any2bool( aValue ));
803 else if ( aNameString.EqualsAscii( SC_UNO_ROWGRAND ) )
805 aNewData.SetRowGrand(::cppu::any2bool( aValue ));
807 else if ( aNameString.EqualsAscii( SC_UNO_SHOWFILT ) )
809 aNewData.SetFilterButton(::cppu::any2bool( aValue ));
811 else if ( aNameString.EqualsAscii( SC_UNO_DRILLDOWN ) )
813 aNewData.SetDrillDown(::cppu::any2bool( aValue ));
815 else
816 throw beans::UnknownPropertyException();
818 pDPObject->SetSaveData( aNewData );
821 SetDPObject(pDPObject);
825 uno::Any SAL_CALL ScDataPilotDescriptorBase::getPropertyValue(const ::rtl::OUString& aPropertyName )
826 throw(beans::UnknownPropertyException,
827 lang::WrappedTargetException,
828 uno::RuntimeException)
830 ScUnoGuard aGuard;
831 uno::Any aRet;
833 ScDPObject* pDPObject(GetDPObject());
834 if (pDPObject)
836 ScDPSaveData* pOldData = pDPObject->GetSaveData();
837 DBG_ASSERT(pOldData, "Here should be a SaveData");
838 if ( pOldData )
840 ScDPSaveData aNewData( *pOldData );
842 String aNameString = aPropertyName;
843 if ( aNameString.EqualsAscii( SC_UNO_COLGRAND ) )
845 aRet = ::cppu::bool2any( aNewData.GetColumnGrand() );
847 else if ( aNameString.EqualsAscii( SC_UNO_IGNEMPROWS ) )
849 aRet = ::cppu::bool2any( aNewData.GetIgnoreEmptyRows() );
851 else if ( aNameString.EqualsAscii( SC_UNO_RPTEMPTY ) )
853 aRet = ::cppu::bool2any( aNewData.GetRepeatIfEmpty() );
855 else if ( aNameString.EqualsAscii( SC_UNO_ROWGRAND ) )
857 aRet = ::cppu::bool2any( aNewData.GetRowGrand() );
859 else if ( aNameString.EqualsAscii( SC_UNO_SHOWFILT ) )
861 aRet = ::cppu::bool2any( aNewData.GetFilterButton() );
863 else if ( aNameString.EqualsAscii( SC_UNO_DRILLDOWN ) )
865 aRet = ::cppu::bool2any( aNewData.GetDrillDown() );
867 else
868 throw beans::UnknownPropertyException();
872 return aRet;
875 void SAL_CALL ScDataPilotDescriptorBase::addPropertyChangeListener( const ::rtl::OUString& /* aPropertyName */,
876 const uno::Reference<beans::XPropertyChangeListener >& /* xListener */ )
877 throw(beans::UnknownPropertyException,
878 lang::WrappedTargetException,
879 uno::RuntimeException)
883 void SAL_CALL ScDataPilotDescriptorBase::removePropertyChangeListener( const ::rtl::OUString& /* aPropertyName */,
884 const uno::Reference<beans::XPropertyChangeListener >& /* aListener */ )
885 throw(beans::UnknownPropertyException,
886 lang::WrappedTargetException,
887 uno::RuntimeException)
891 void SAL_CALL ScDataPilotDescriptorBase::addVetoableChangeListener( const ::rtl::OUString& /* PropertyName */,
892 const uno::Reference<beans::XVetoableChangeListener >& /* aListener */ )
893 throw(beans::UnknownPropertyException,
894 lang::WrappedTargetException,
895 uno::RuntimeException)
899 void SAL_CALL ScDataPilotDescriptorBase::removeVetoableChangeListener( const ::rtl::OUString& /* PropertyName */,
900 const uno::Reference<beans::XVetoableChangeListener >& /* aListener */ )
901 throw(beans::UnknownPropertyException,
902 lang::WrappedTargetException,
903 uno::RuntimeException)
907 // XUnoTunnel
909 sal_Int64 SAL_CALL ScDataPilotDescriptorBase::getSomething(
910 const uno::Sequence<sal_Int8 >& rId ) throw(uno::RuntimeException)
912 if ( rId.getLength() == 16 &&
913 0 == rtl_compareMemory( getUnoTunnelId().getConstArray(),
914 rId.getConstArray(), 16 ) )
916 return sal::static_int_cast<sal_Int64>(reinterpret_cast<sal_IntPtr>(this));
918 return 0;
921 // static
922 const uno::Sequence<sal_Int8>& ScDataPilotDescriptorBase::getUnoTunnelId()
924 static uno::Sequence<sal_Int8> * pSeq = 0;
925 if( !pSeq )
927 osl::Guard< osl::Mutex > aGuard( osl::Mutex::getGlobalMutex() );
928 if( !pSeq )
930 static uno::Sequence< sal_Int8 > aSeq( 16 );
931 rtl_createUuid( (sal_uInt8*)aSeq.getArray(), 0, sal_True );
932 pSeq = &aSeq;
935 return *pSeq;
938 // static
939 ScDataPilotDescriptorBase* ScDataPilotDescriptorBase::getImplementation(
940 const uno::Reference<sheet::XDataPilotDescriptor> xObj )
942 ScDataPilotDescriptorBase* pRet = NULL;
943 uno::Reference<lang::XUnoTunnel> xUT( xObj, uno::UNO_QUERY );
944 if (xUT.is())
945 pRet = reinterpret_cast<ScDataPilotDescriptorBase*>(sal::static_int_cast<sal_IntPtr>(xUT->getSomething(getUnoTunnelId())));
946 return pRet;
949 //------------------------------------------------------------------------
951 ScDataPilotTableObj::ScDataPilotTableObj(ScDocShell* pDocSh, SCTAB nT, const String& rN) :
952 ScDataPilotDescriptorBase( pDocSh ),
953 nTab( nT ),
954 aName( rN )
958 ScDataPilotTableObj::~ScDataPilotTableObj()
962 uno::Any SAL_CALL ScDataPilotTableObj::queryInterface( const uno::Type& rType )
963 throw(uno::RuntimeException)
965 // since we manually do resolve the query for XDataPilotTable2
966 // we also need to do the same for XDataPilotTable
967 SC_QUERYINTERFACE( sheet::XDataPilotTable )
968 SC_QUERYINTERFACE( sheet::XDataPilotTable2 )
970 return ScDataPilotDescriptorBase::queryInterface( rType );
973 void SAL_CALL ScDataPilotTableObj::acquire() throw()
975 ScDataPilotDescriptorBase::acquire();
978 void SAL_CALL ScDataPilotTableObj::release() throw()
980 ScDataPilotDescriptorBase::release();
983 uno::Sequence<uno::Type> SAL_CALL ScDataPilotTableObj::getTypes()
984 throw(uno::RuntimeException)
986 static uno::Sequence<uno::Type> aTypes;
987 if ( aTypes.getLength() == 0 )
989 uno::Sequence<uno::Type> aParentTypes(ScDataPilotDescriptorBase::getTypes());
990 long nParentLen = aParentTypes.getLength();
991 const uno::Type* pParentPtr = aParentTypes.getConstArray();
993 aTypes.realloc( nParentLen + 1 );
994 uno::Type* pPtr = aTypes.getArray();
995 pPtr[nParentLen + 0] = getCppuType((const uno::Reference<sheet::XDataPilotTable2>*)0);
997 for (long i=0; i<nParentLen; i++)
998 pPtr[i] = pParentPtr[i]; // parent types first
1000 return aTypes;
1003 uno::Sequence<sal_Int8> SAL_CALL ScDataPilotTableObj::getImplementationId()
1004 throw(uno::RuntimeException)
1006 static uno::Sequence< sal_Int8 > aId;
1007 if( aId.getLength() == 0 )
1009 aId.realloc( 16 );
1010 rtl_createUuid( (sal_uInt8 *)aId.getArray(), 0, sal_True );
1012 return aId;
1015 // ---
1016 ScDPObject* ScDataPilotTableObj::GetDPObject() const
1018 return lcl_GetDPObject(GetDocShell(), nTab, aName);
1021 void ScDataPilotTableObj::SetDPObject( ScDPObject* pDPObject )
1023 ScDocShell* pDocSh = GetDocShell();
1024 ScDPObject* pDPObj = lcl_GetDPObject(pDocSh, nTab, aName);
1025 if ( pDPObj && pDocSh )
1027 ScDBDocFunc aFunc(*pDocSh);
1028 aFunc.DataPilotUpdate( pDPObj, pDPObject, TRUE, TRUE );
1032 // "rest of XDataPilotDescriptor"
1034 rtl::OUString SAL_CALL ScDataPilotTableObj::getName() throw(uno::RuntimeException)
1036 ScUnoGuard aGuard;
1037 ScDPObject* pDPObj = lcl_GetDPObject(GetDocShell(), nTab, aName);
1038 if (pDPObj)
1039 return pDPObj->GetName();
1040 return rtl::OUString();
1043 void SAL_CALL ScDataPilotTableObj::setName( const rtl::OUString& aNewName )
1044 throw(uno::RuntimeException)
1046 ScUnoGuard aGuard;
1047 ScDPObject* pDPObj = lcl_GetDPObject(GetDocShell(), nTab, aName);
1048 if (pDPObj)
1050 //! test for existing names !!!
1052 String aString(aNewName);
1053 pDPObj->SetName( aString ); //! Undo - DBDocFunc ???
1054 aName = aString;
1056 // DataPilotUpdate would do too much (output table is not changed)
1057 GetDocShell()->SetDocumentModified();
1061 rtl::OUString SAL_CALL ScDataPilotTableObj::getTag() throw(uno::RuntimeException)
1063 ScUnoGuard aGuard;
1064 ScDPObject* pDPObj = lcl_GetDPObject(GetDocShell(), nTab, aName);
1065 if (pDPObj)
1066 return pDPObj->GetTag();
1067 return rtl::OUString();
1070 void SAL_CALL ScDataPilotTableObj::setTag( const ::rtl::OUString& aNewTag )
1071 throw(uno::RuntimeException)
1073 ScUnoGuard aGuard;
1074 ScDPObject* pDPObj = lcl_GetDPObject(GetDocShell(), nTab, aName);
1075 if (pDPObj)
1077 String aString(aNewTag);
1078 pDPObj->SetTag( aString ); //! Undo - DBDocFunc ???
1080 // DataPilotUpdate would do too much (output table is not changed)
1081 GetDocShell()->SetDocumentModified();
1085 // XDataPilotTable
1087 table::CellRangeAddress SAL_CALL ScDataPilotTableObj::getOutputRange()
1088 throw(uno::RuntimeException)
1090 ScUnoGuard aGuard;
1091 table::CellRangeAddress aRet;
1092 ScDPObject* pDPObj = lcl_GetDPObject(GetDocShell(), nTab, aName);
1093 if (pDPObj)
1095 ScRange aRange(pDPObj->GetOutRange());
1096 aRet.Sheet = aRange.aStart.Tab();
1097 aRet.StartColumn = aRange.aStart.Col();
1098 aRet.StartRow = aRange.aStart.Row();
1099 aRet.EndColumn = aRange.aEnd.Col();
1100 aRet.EndRow = aRange.aEnd.Row();
1102 return aRet;
1105 void SAL_CALL ScDataPilotTableObj::refresh() throw(uno::RuntimeException)
1107 ScUnoGuard aGuard;
1108 ScDPObject* pDPObj = lcl_GetDPObject(GetDocShell(), nTab, aName);
1109 if (pDPObj)
1111 ScDPObject* pNew = new ScDPObject(*pDPObj);
1112 ScDBDocFunc aFunc(*GetDocShell());
1113 aFunc.DataPilotUpdate( pDPObj, pNew, TRUE, TRUE );
1114 delete pNew; // DataPilotUpdate copies settings from "new" object
1118 Sequence< Sequence<Any> > SAL_CALL ScDataPilotTableObj::getDrillDownData(const CellAddress& aAddr)
1119 throw (RuntimeException)
1121 ScUnoGuard aGuard;
1122 Sequence< Sequence<Any> > aTabData;
1123 ScAddress aAddr2(static_cast<SCCOL>(aAddr.Column), static_cast<SCROW>(aAddr.Row), aAddr.Sheet);
1124 ScDPObject* pObj = GetDPObject();
1125 if (!pObj)
1126 throw RuntimeException();
1128 pObj->GetDrillDownData(aAddr2, aTabData);
1129 return aTabData;
1132 DataPilotTablePositionData SAL_CALL ScDataPilotTableObj::getPositionData(const CellAddress& aAddr)
1133 throw (RuntimeException)
1135 ScUnoGuard aGuard;
1136 DataPilotTablePositionData aPosData;
1137 ScAddress aAddr2(static_cast<SCCOL>(aAddr.Column), static_cast<SCROW>(aAddr.Row), aAddr.Sheet);
1138 ScDPObject* pObj = GetDPObject();
1139 if (!pObj)
1140 throw RuntimeException();
1142 pObj->GetPositionData(aAddr2, aPosData);
1143 return aPosData;
1146 void SAL_CALL ScDataPilotTableObj::insertDrillDownSheet(const CellAddress& aAddr)
1147 throw (RuntimeException)
1149 ScUnoGuard aGuard;
1150 ScDPObject* pDPObj = GetDPObject();
1151 if (!pDPObj)
1152 throw RuntimeException();
1154 Sequence<DataPilotFieldFilter> aFilters;
1155 pDPObj->GetDataFieldPositionData(
1156 ScAddress(static_cast<SCCOL>(aAddr.Column), static_cast<SCROW>(aAddr.Row), aAddr.Sheet), aFilters);
1157 GetDocShell()->GetBestViewShell()->ShowDataPilotSourceData(*pDPObj, aFilters);
1160 CellRangeAddress SAL_CALL ScDataPilotTableObj::getOutputRangeByType( sal_Int32 nType )
1161 throw (IllegalArgumentException, RuntimeException)
1163 ScUnoGuard aGuard;
1164 if (nType < 0 || nType > ::com::sun::star::sheet::DataPilotOutputRangeType::RESULT)
1165 throw IllegalArgumentException();
1167 table::CellRangeAddress aRet;
1168 ScDPObject* pDPObj = lcl_GetDPObject(GetDocShell(), nTab, aName);
1169 if (!pDPObj)
1170 return aRet;
1172 const ScRange aRange = pDPObj->GetOutputRangeByType(nType);
1173 aRet.Sheet = aRange.aStart.Tab();
1174 aRet.StartColumn = aRange.aStart.Col();
1175 aRet.StartRow = aRange.aStart.Row();
1176 aRet.EndColumn = aRange.aEnd.Col();
1177 aRet.EndRow = aRange.aEnd.Row();
1179 return aRet;
1182 //------------------------------------------------------------------------
1184 ScDataPilotDescriptor::ScDataPilotDescriptor(ScDocShell* pDocSh) :
1185 ScDataPilotDescriptorBase( pDocSh ),
1186 mpDPObject(new ScDPObject(pDocSh ? pDocSh->GetDocument() : NULL) )
1188 mpDPObject->SetAlive(sal_True);
1189 ScDPSaveData aSaveData;
1190 // set defaults like in ScPivotParam constructor
1191 aSaveData.SetColumnGrand( sal_True );
1192 aSaveData.SetRowGrand( sal_True );
1193 aSaveData.SetIgnoreEmptyRows( sal_False );
1194 aSaveData.SetRepeatIfEmpty( sal_False );
1195 mpDPObject->SetSaveData(aSaveData);
1196 ScSheetSourceDesc aSheetDesc;
1197 mpDPObject->SetSheetDesc(aSheetDesc);
1198 mpDPObject->GetSource();
1201 ScDataPilotDescriptor::~ScDataPilotDescriptor()
1203 delete mpDPObject;
1206 ScDPObject* ScDataPilotDescriptor::GetDPObject() const
1208 return mpDPObject;
1211 void ScDataPilotDescriptor::SetDPObject( ScDPObject* pDPObject )
1213 if (mpDPObject != pDPObject)
1215 delete mpDPObject;
1216 mpDPObject = pDPObject;
1217 DBG_ERROR("replace DPObject should not happen");
1221 // "rest of XDataPilotDescriptor"
1223 rtl::OUString SAL_CALL ScDataPilotDescriptor::getName() throw(uno::RuntimeException)
1225 ScUnoGuard aGuard;
1226 return mpDPObject->GetName();
1229 void SAL_CALL ScDataPilotDescriptor::setName( const rtl::OUString& aNewName )
1230 throw(uno::RuntimeException)
1232 ScUnoGuard aGuard;
1233 mpDPObject->SetName( aNewName );
1236 rtl::OUString SAL_CALL ScDataPilotDescriptor::getTag() throw(uno::RuntimeException)
1238 ScUnoGuard aGuard;
1239 return mpDPObject->GetTag();
1242 void SAL_CALL ScDataPilotDescriptor::setTag( const ::rtl::OUString& aNewTag )
1243 throw(uno::RuntimeException)
1245 ScUnoGuard aGuard;
1246 mpDPObject->SetTag( aNewTag );
1249 //------------------------------------------------------------------------
1251 ScDataPilotFieldsObj::ScDataPilotFieldsObj(ScDataPilotDescriptorBase* pPar, USHORT nTy) :
1252 pParent( pPar ),
1253 nType( nTy )
1255 pParent->acquire();
1258 ScDataPilotFieldsObj::~ScDataPilotFieldsObj()
1260 pParent->release();
1263 BOOL lcl_GetDim(ScDPObject* pDPObj, const ScFieldIdentifier& rIdent, ScDPSaveDimension*& rpDim)
1265 BOOL bRet = FALSE;
1266 ScDPSaveData* pSave = pDPObj->GetSaveData();
1267 if ( pSave )
1269 if ( rIdent.bDataLayoutField )
1271 rpDim = pSave->GetDataLayoutDimension();
1272 bRet = TRUE;
1274 else if ( rIdent.nRepeat == 0 )
1276 rpDim = pSave->GetDimensionByName( rIdent.sFieldName );
1277 bRet = TRUE;
1279 else
1281 // count all dimensions with the given name
1283 String aNameStr( rIdent.sFieldName );
1284 const List& rDimensions = pSave->GetDimensions();
1285 sal_Int32 nDimCount = rDimensions.Count();
1286 sal_Int32 nFound = 0;
1287 for ( sal_Int32 nDim = 0; nDim < nDimCount && !bRet; nDim++ )
1289 ScDPSaveDimension* pOneDim = static_cast<ScDPSaveDimension*>(rDimensions.GetObject(nDim));
1290 if ( !pOneDim->IsDataLayout() && pOneDim->GetName() == aNameStr )
1292 if ( nFound == rIdent.nRepeat )
1294 rpDim = pOneDim;
1295 bRet = TRUE;
1297 else
1298 ++nFound;
1303 return bRet;
1306 SCSIZE lcl_GetFieldCount( const com::sun::star::uno::Reference<com::sun::star::sheet::XDimensionsSupplier>& rSource, USHORT nType )
1308 SCSIZE nRet = 0;
1310 uno::Reference<container::XNameAccess> xDimsName(rSource->getDimensions());
1311 uno::Reference<container::XIndexAccess> xIntDims(new ScNameToIndexAccess( xDimsName ));
1312 sal_Int32 nIntCount = xIntDims->getCount();
1313 if (nType != SC_FIELDORIENT_ALL)
1315 // all fields of the specified orientation, including duplicated
1317 uno::Reference<beans::XPropertySet> xDim;
1318 sheet::DataPilotFieldOrientation aOrient;
1319 for (sal_Int32 i = 0; i < nIntCount; ++i)
1321 xDim.set(xIntDims->getByIndex(i), uno::UNO_QUERY);
1322 if (xDim.is())
1324 xDim->getPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNO_ORIENTAT))) >>= aOrient;
1325 if (aOrient == nType)
1326 ++nRet;
1330 else
1332 // count all non-duplicated fields
1334 uno::Reference<beans::XPropertySet> xDim;
1335 for (sal_Int32 i = 0; i < nIntCount; ++i)
1337 xDim.set(xIntDims->getByIndex(i), uno::UNO_QUERY);
1338 if ( xDim.is() && !lcl_IsDuplicated( xDim ) )
1339 ++nRet;
1343 return nRet;
1346 BOOL lcl_GetFieldDataByIndex( const com::sun::star::uno::Reference<com::sun::star::sheet::XDimensionsSupplier>& rSource,
1347 USHORT nType, SCSIZE nIndex, ScFieldIdentifier& rField )
1349 BOOL bOk = FALSE;
1350 SCSIZE nPos = 0;
1351 sal_Int32 nDimIndex = 0;
1353 uno::Reference<container::XNameAccess> xDimsName(rSource->getDimensions());
1354 uno::Reference<container::XIndexAccess> xIntDims(new ScNameToIndexAccess( xDimsName ));
1355 sal_Int32 nIntCount = xIntDims->getCount();
1356 uno::Reference<beans::XPropertySet> xDim;
1357 if (nType != SC_FIELDORIENT_ALL)
1359 sheet::DataPilotFieldOrientation aOrient;
1360 sal_Int32 i = 0;
1361 while (i < nIntCount && !bOk)
1363 xDim.set(xIntDims->getByIndex(i), uno::UNO_QUERY);
1364 if (xDim.is())
1366 xDim->getPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNO_ORIENTAT))) >>= aOrient;
1367 if (aOrient == nType)
1369 if (nPos == nIndex)
1371 bOk = sal_True;
1372 nDimIndex = i;
1374 else
1375 ++nPos;
1378 ++i;
1381 else
1383 sal_Int32 i = 0;
1384 while (i < nIntCount && !bOk)
1386 xDim.set(xIntDims->getByIndex(i), uno::UNO_QUERY);
1387 if ( xDim.is() && !lcl_IsDuplicated( xDim ) )
1389 if (nPos == nIndex)
1391 bOk = sal_True;
1392 nDimIndex = i;
1394 else
1395 ++nPos;
1397 ++i;
1401 if ( bOk )
1403 xDim.set( xIntDims->getByIndex(nDimIndex), uno::UNO_QUERY );
1404 uno::Reference<container::XNamed> xDimName( xDim, uno::UNO_QUERY );
1405 if ( xDimName.is() )
1407 rtl::OUString sOriginalName( lcl_GetOriginalName( xDimName ) );
1408 rField.sFieldName = sOriginalName;
1409 rField.bDataLayoutField = ScUnoHelpFunctions::GetBoolProperty( xDim,
1410 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNO_ISDATALA)) );
1412 sal_Int32 nRepeat = 0;
1413 if ( nType != SC_FIELDORIENT_ALL && lcl_IsDuplicated( xDim ) )
1415 // find the repeat count
1416 // (this relies on the original dimension always being before the duplicates)
1418 uno::Reference<container::XNamed> xPrevName;
1419 for (sal_Int32 i = 0; i < nDimIndex; ++i)
1421 xPrevName.set( xIntDims->getByIndex(i), uno::UNO_QUERY );
1422 if ( xPrevName.is() && lcl_GetOriginalName( xPrevName ) == sOriginalName )
1423 ++nRepeat;
1426 rField.nRepeat = nRepeat;
1428 else
1429 bOk = sal_False;
1432 return bOk;
1435 BOOL lcl_GetFieldDataByName( ScDPObject* pDPObj, USHORT /* nType */, const rtl::OUString& sName, ScFieldIdentifier& rField )
1437 // "By name" is always the first match.
1438 // The name "Data" always refers to the data layout field.
1439 rField.sFieldName = sName;
1440 rField.bDataLayoutField = sName.equalsAscii( SC_DATALAYOUT_NAME );
1441 rField.nRepeat = 0;
1443 pDPObj->GetSource(); // IsDimNameInUse doesn't update source data
1445 // check if the named field exists (not for data layout)
1446 return ( rField.bDataLayoutField || pDPObj->IsDimNameInUse( sName ) );
1449 // XDataPilotFields
1451 ScDataPilotFieldObj* ScDataPilotFieldsObj::GetObjectByIndex_Impl(SCSIZE nIndex) const
1453 ScDPObject* pObj = pParent->GetDPObject();
1455 // TODO
1456 if (pObj)
1458 ScFieldIdentifier aSourceIdent;
1459 BOOL bOk = lcl_GetFieldDataByIndex( pObj->GetSource(), nType, nIndex, aSourceIdent );
1461 if (bOk)
1462 return new ScDataPilotFieldObj( pParent, nType, aSourceIdent );
1465 return NULL;
1468 ScDataPilotFieldObj* ScDataPilotFieldsObj::GetObjectByName_Impl(const rtl::OUString& aName) const
1470 ScDPObject* pDPObj(pParent->GetDPObject());
1471 if (pDPObj)
1473 ScFieldIdentifier aSourceIdent;
1474 if (lcl_GetFieldDataByName( pDPObj, nType, aName, aSourceIdent ))
1476 return new ScDataPilotFieldObj( pParent, nType, aSourceIdent );
1479 return NULL;
1482 // XEnumerationAccess
1484 uno::Reference<container::XEnumeration> SAL_CALL ScDataPilotFieldsObj::createEnumeration()
1485 throw(uno::RuntimeException)
1487 ScUnoGuard aGuard;
1488 return new ScIndexEnumeration(this, rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.sheet.DataPilotFieldsEnumeration")));
1491 // XIndexAccess
1493 sal_Int32 SAL_CALL ScDataPilotFieldsObj::getCount() throw(uno::RuntimeException)
1495 ScUnoGuard aGuard;
1496 // TODO
1497 ScDPObject* pDPObj(pParent->GetDPObject());
1499 return pDPObj ? static_cast<sal_Int32>(lcl_GetFieldCount( pDPObj->GetSource(), nType )) : 0;
1502 uno::Any SAL_CALL ScDataPilotFieldsObj::getByIndex( sal_Int32 nIndex )
1503 throw(lang::IndexOutOfBoundsException,
1504 lang::WrappedTargetException, uno::RuntimeException)
1506 ScUnoGuard aGuard;
1507 uno::Reference<beans::XPropertySet> xField(GetObjectByIndex_Impl(static_cast<SCSIZE>(nIndex)));
1508 if (xField.is())
1509 return uno::makeAny(xField);
1510 else
1511 throw lang::IndexOutOfBoundsException();
1514 uno::Type SAL_CALL ScDataPilotFieldsObj::getElementType() throw(uno::RuntimeException)
1516 ScUnoGuard aGuard;
1517 return getCppuType((uno::Reference<beans::XPropertySet>*)0);
1520 sal_Bool SAL_CALL ScDataPilotFieldsObj::hasElements() throw(uno::RuntimeException)
1522 ScUnoGuard aGuard;
1523 return ( getCount() != 0 );
1526 uno::Any SAL_CALL ScDataPilotFieldsObj::getByName( const rtl::OUString& aName )
1527 throw(container::NoSuchElementException,
1528 lang::WrappedTargetException, uno::RuntimeException)
1530 ScUnoGuard aGuard;
1531 uno::Reference<beans::XPropertySet> xField(GetObjectByName_Impl(aName));
1532 if (xField.is())
1533 return uno::makeAny(xField);
1534 else
1535 throw container::NoSuchElementException();
1538 uno::Sequence<rtl::OUString> SAL_CALL ScDataPilotFieldsObj::getElementNames()
1539 throw(uno::RuntimeException)
1541 ScUnoGuard aGuard;
1542 // TODO
1544 ScDPObject* pDPObj(pParent->GetDPObject());
1546 if (pDPObj)
1548 uno::Sequence<rtl::OUString> aSeq(static_cast<sal_Int32>(lcl_GetFieldCount(pDPObj->GetSource(), nType)));
1549 rtl::OUString* pAry = aSeq.getArray();
1550 const List& rDimensions = pDPObj->GetSaveData()->GetDimensions();
1551 sal_Int32 nDimCount = rDimensions.Count();
1552 for (sal_Int32 nDim = 0; nDim < nDimCount; nDim++)
1554 ScDPSaveDimension* pDim = (ScDPSaveDimension*)rDimensions.GetObject(nDim);
1555 if(pDim->GetOrientation() == nType)
1557 *pAry = pDim->GetName();
1558 ++pAry;
1561 return aSeq;
1563 return uno::Sequence<rtl::OUString>();
1566 sal_Bool SAL_CALL ScDataPilotFieldsObj::hasByName( const rtl::OUString& aName )
1567 throw(uno::RuntimeException)
1569 ScUnoGuard aGuard;
1571 return GetObjectByName_Impl(aName) != NULL;
1574 //------------------------------------------------------------------------
1576 ScDataPilotFieldObj::ScDataPilotFieldObj( ScDataPilotDescriptorBase* pPar,
1577 USHORT nST, const ScFieldIdentifier& rIdent ) :
1578 aPropSet( lcl_GetDataPilotFieldMap() ),
1579 pParent( pPar ),
1580 nSourceType( nST ),
1581 aSourceIdent( rIdent ),
1582 nLastFunc( sheet::GeneralFunction_NONE )
1584 pParent->acquire();
1587 ScDataPilotFieldObj::~ScDataPilotFieldObj()
1589 pParent->release();
1592 // XNamed
1594 rtl::OUString SAL_CALL ScDataPilotFieldObj::getName() throw(uno::RuntimeException)
1596 ScUnoGuard aGuard;
1597 // TODO
1598 rtl::OUString sRet;
1599 ScDPObject* pDPObj(pParent->GetDPObject());
1600 if (pDPObj)
1602 ScDPSaveDimension* pDim = NULL;
1603 if (lcl_GetDim(pDPObj, aSourceIdent, pDim))
1605 if (pDim->IsDataLayout())
1606 return String::CreateFromAscii(RTL_CONSTASCII_STRINGPARAM(SC_DATALAYOUT_NAME));
1607 else
1609 const rtl::OUString* pLayoutName = pDim->GetLayoutName();
1610 if (pLayoutName)
1611 sRet = *pLayoutName;
1612 else
1613 sRet = pDim->GetName();
1617 return sRet;
1620 void SAL_CALL ScDataPilotFieldObj::setName( const rtl::OUString& aNewName )
1621 throw(uno::RuntimeException)
1623 ScUnoGuard aGuard;
1624 // TODO
1625 ScDPObject* pDPObj(pParent->GetDPObject());
1626 if (pDPObj)
1628 ScDPSaveDimension* pDim = NULL;
1629 if (lcl_GetDim(pDPObj, aSourceIdent, pDim))
1631 if (!pDim->IsDataLayout())
1633 String aName(aNewName);
1634 pDim->SetLayoutName(aName);
1635 pParent->SetDPObject(pDPObj);
1641 // XPropertySet
1643 uno::Reference<beans::XPropertySetInfo> SAL_CALL ScDataPilotFieldObj::getPropertySetInfo()
1644 throw(uno::RuntimeException)
1646 ScUnoGuard aGuard;
1647 static uno::Reference<beans::XPropertySetInfo> aRef(
1648 new SfxItemPropertySetInfo( aPropSet.getPropertyMap() ));
1649 return aRef;
1652 void SAL_CALL ScDataPilotFieldObj::setPropertyValue(
1653 const rtl::OUString& aPropertyName, const uno::Any& aValue )
1654 throw(beans::UnknownPropertyException, beans::PropertyVetoException,
1655 lang::IllegalArgumentException, lang::WrappedTargetException,
1656 uno::RuntimeException)
1658 ScUnoGuard aGuard;
1659 String aNameString(aPropertyName);
1660 if ( aNameString.EqualsAscii( SC_UNONAME_FUNCTION ) )
1662 //! test for correct enum type?
1663 sheet::GeneralFunction eFunction = (sheet::GeneralFunction)
1664 ScUnoHelpFunctions::GetEnumFromAny( aValue );
1665 setFunction( eFunction );
1667 else if ( aNameString.EqualsAscii( SC_UNONAME_ORIENT ) )
1669 //! test for correct enum type?
1670 sheet::DataPilotFieldOrientation eOrient = (sheet::DataPilotFieldOrientation)
1671 ScUnoHelpFunctions::GetEnumFromAny( aValue );
1672 setOrientation( eOrient );
1674 else if ( aNameString.EqualsAscii( SC_UNONAME_SELPAGE ) )
1676 rtl::OUString sCurrentPage;
1677 if (aValue >>= sCurrentPage)
1678 setCurrentPage(sCurrentPage);
1680 else if ( aNameString.EqualsAscii( SC_UNONAME_USESELPAGE ) )
1682 setUseCurrentPage(cppu::any2bool(aValue));
1684 else if ( aNameString.EqualsAscii( SC_UNONAME_HASAUTOSHOW ) )
1686 if (!cppu::any2bool(aValue))
1687 setAutoShowInfo(NULL);
1689 else if ( aNameString.EqualsAscii( SC_UNONAME_AUTOSHOW ) )
1691 sheet::DataPilotFieldAutoShowInfo aInfo;
1692 if (aValue >>= aInfo)
1693 setAutoShowInfo(&aInfo);
1695 else if ( aNameString.EqualsAscii( SC_UNONAME_HASLAYOUTINFO ) )
1697 if (!cppu::any2bool(aValue))
1698 setLayoutInfo(NULL);
1700 else if ( aNameString.EqualsAscii( SC_UNONAME_LAYOUTINFO ) )
1702 sheet::DataPilotFieldLayoutInfo aInfo;
1703 if (aValue >>= aInfo)
1704 setLayoutInfo(&aInfo);
1706 else if ( aNameString.EqualsAscii( SC_UNONAME_HASREFERENCE ) )
1708 if (!cppu::any2bool(aValue))
1709 setReference(NULL);
1711 else if ( aNameString.EqualsAscii( SC_UNONAME_REFERENCE ) )
1713 sheet::DataPilotFieldReference aRef;
1714 if (aValue >>= aRef)
1715 setReference(&aRef);
1717 else if ( aNameString.EqualsAscii( SC_UNONAME_HASSORTINFO ) )
1719 if (!cppu::any2bool(aValue))
1720 setSortInfo(NULL);
1722 else if ( aNameString.EqualsAscii( SC_UNONAME_SORTINFO ) )
1724 sheet::DataPilotFieldSortInfo aInfo;
1725 if (aValue >>= aInfo)
1726 setSortInfo(&aInfo);
1728 else if ( aNameString.EqualsAscii( SC_UNONAME_ISGROUP ) )
1730 if (!cppu::any2bool(aValue))
1731 setGroupInfo(NULL);
1733 else if ( aNameString.EqualsAscii( SC_UNONAME_GROUPINFO ) )
1735 sheet::DataPilotFieldGroupInfo aInfo;
1736 if (aValue >>= aInfo)
1737 setGroupInfo(&aInfo);
1739 else if ( aNameString.EqualsAscii( SC_UNONAME_SHOWEMPTY ) )
1741 setShowEmpty(cppu::any2bool(aValue));
1745 uno::Any SAL_CALL ScDataPilotFieldObj::getPropertyValue( const rtl::OUString& aPropertyName )
1746 throw(beans::UnknownPropertyException, lang::WrappedTargetException,
1747 uno::RuntimeException)
1749 ScUnoGuard aGuard;
1750 String aNameString(aPropertyName);
1751 uno::Any aRet;
1753 if ( aNameString.EqualsAscii( SC_UNONAME_FUNCTION ) )
1754 aRet <<= getFunction();
1755 else if ( aNameString.EqualsAscii( SC_UNONAME_ORIENT ) )
1756 aRet <<= getOrientation();
1757 else if ( aNameString.EqualsAscii( SC_UNONAME_SELPAGE ) )
1758 aRet <<= getCurrentPage();
1759 else if ( aNameString.EqualsAscii( SC_UNONAME_USESELPAGE ) )
1760 aRet <<= getUseCurrentPage();
1761 else if ( aNameString.EqualsAscii( SC_UNONAME_HASAUTOSHOW ) )
1762 aRet = ::cppu::bool2any(getAutoShowInfo() != NULL);
1763 else if ( aNameString.EqualsAscii( SC_UNONAME_AUTOSHOW ) )
1765 const sheet::DataPilotFieldAutoShowInfo* pInfo = getAutoShowInfo();
1766 if (pInfo)
1767 aRet <<= sheet::DataPilotFieldAutoShowInfo(*pInfo);
1769 else if ( aNameString.EqualsAscii( SC_UNONAME_HASLAYOUTINFO ) )
1770 aRet = ::cppu::bool2any(getLayoutInfo() != NULL);
1771 else if ( aNameString.EqualsAscii( SC_UNONAME_LAYOUTINFO ) )
1773 const sheet::DataPilotFieldLayoutInfo* pInfo = getLayoutInfo();
1774 if (pInfo)
1775 aRet <<= sheet::DataPilotFieldLayoutInfo(*pInfo);
1777 else if ( aNameString.EqualsAscii( SC_UNONAME_HASREFERENCE ) )
1778 aRet = ::cppu::bool2any(getReference() != NULL);
1779 else if ( aNameString.EqualsAscii( SC_UNONAME_REFERENCE ) )
1781 const sheet::DataPilotFieldReference* pRef = getReference();
1782 if (pRef)
1783 aRet <<= sheet::DataPilotFieldReference(*pRef);
1785 else if ( aNameString.EqualsAscii( SC_UNONAME_HASSORTINFO ) )
1786 aRet = ::cppu::bool2any(getSortInfo() != NULL);
1787 else if ( aNameString.EqualsAscii( SC_UNONAME_SORTINFO ) )
1789 const sheet::DataPilotFieldSortInfo* pInfo = getSortInfo();
1790 if (pInfo)
1791 aRet <<= sheet::DataPilotFieldSortInfo(*pInfo);
1793 else if ( aNameString.EqualsAscii( SC_UNONAME_ISGROUP ) )
1794 aRet = ::cppu::bool2any(hasGroupInfo());
1795 else if ( aNameString.EqualsAscii( SC_UNONAME_GROUPINFO ) )
1797 aRet <<= getGroupInfo();
1799 else if ( aNameString.EqualsAscii( SC_UNONAME_SHOWEMPTY ) )
1800 aRet <<= getShowEmpty();
1802 return aRet;
1805 // XDatePilotField
1807 uno::Reference<container::XIndexAccess> SAL_CALL ScDataPilotFieldObj::getItems()
1808 throw (uno::RuntimeException)
1810 if (!xItems.is())
1811 xItems.set(new ScDataPilotItemsObj(pParent, aSourceIdent));
1812 return xItems;
1815 SC_IMPL_DUMMY_PROPERTY_LISTENER( ScDataPilotFieldObj )
1817 sheet::DataPilotFieldOrientation ScDataPilotFieldObj::getOrientation(void) const
1819 sheet::DataPilotFieldOrientation eOrient = DATA_PILOT_HIDDEN;
1820 // TODO
1821 ScDPObject* pDPObj(pParent->GetDPObject());
1822 if (pDPObj)
1824 ScDPSaveDimension* pDim = NULL;
1825 if (lcl_GetDim(pDPObj, aSourceIdent, pDim))
1826 eOrient = (sheet::DataPilotFieldOrientation)pDim->GetOrientation();
1829 return eOrient;
1832 void ScDataPilotFieldObj::setOrientation(sheet::DataPilotFieldOrientation eNew)
1834 if ( eNew == nSourceType )
1835 return; // nix
1837 ScDPObject* pDPObj(pParent->GetDPObject());
1838 if (pDPObj)
1840 ScDPSaveDimension* pDim = NULL;
1841 if (lcl_GetDim(pDPObj, aSourceIdent, pDim))
1843 if ( nSourceType == SC_FIELDORIENT_ALL && pDim->GetOrientation() != DATA_PILOT_HIDDEN &&
1844 !aSourceIdent.bDataLayoutField && eNew == DATA_PILOT_DATA )
1846 // If the field was taken from getDataPilotFields, don't reset the orientation
1847 // for an existing use, create a duplicated field instead (for "Data" orientation only)
1849 ScDPSaveDimension* pNewDim = NULL;
1850 ScDPSaveData* pSave = pDPObj->GetSaveData();
1852 // look for existing duplicate with orientation "hidden"
1854 String aNameStr( aSourceIdent.sFieldName );
1855 const List& rDimensions = pSave->GetDimensions();
1856 sal_Int32 nDimCount = rDimensions.Count();
1857 sal_Int32 nFound = 0;
1858 for ( sal_Int32 nDim = 0; nDim < nDimCount && !pNewDim; nDim++ )
1860 ScDPSaveDimension* pOneDim = static_cast<ScDPSaveDimension*>(rDimensions.GetObject(nDim));
1861 if ( !pOneDim->IsDataLayout() && pOneDim->GetName() == aNameStr )
1863 if ( pOneDim->GetOrientation() == DATA_PILOT_HIDDEN )
1864 pNewDim = pOneDim; // use this one
1865 else
1866 ++nFound; // count existing non-hidden occurences
1870 if ( !pNewDim ) // if none found, create a new duplicated dimension
1871 pNewDim = &pSave->DuplicateDimension( *pDim );
1873 aSourceIdent.nRepeat = nFound; // keep accessing the new one
1874 pDim = pNewDim;
1877 pDim->SetOrientation(sal::static_int_cast<USHORT>(eNew));
1878 pParent->SetDPObject(pDPObj);
1880 nSourceType = sal::static_int_cast<USHORT>(eNew); // modifying the same object's orientation again doesn't create another duplicate
1885 sheet::GeneralFunction ScDataPilotFieldObj::getFunction(void) const
1887 sheet::GeneralFunction eRet = sheet::GeneralFunction_NONE;
1889 // TODO
1891 ScDPObject* pDPObj(pParent->GetDPObject());
1892 if (pDPObj)
1894 ScDPSaveDimension* pDim = NULL;
1895 if (lcl_GetDim(pDPObj, aSourceIdent, pDim))
1897 if ( pDim->GetOrientation() != DATA_PILOT_DATA )
1899 // for non-data fields, property Function is the subtotals
1900 long nSubCount = pDim->GetSubTotalsCount();
1901 if ( nSubCount > 0 )
1902 eRet = (sheet::GeneralFunction)pDim->GetSubTotalFunc(0); // always use the first one
1903 // else keep NONE
1905 else
1906 eRet = (sheet::GeneralFunction)pDim->GetFunction();
1910 return eRet;
1913 void ScDataPilotFieldObj::setFunction(sheet::GeneralFunction eNewFunc)
1915 // TODO
1916 ScDPObject* pDPObj(pParent->GetDPObject());
1917 if (pDPObj)
1919 ScDPSaveDimension* pDim = NULL;
1920 if (lcl_GetDim(pDPObj, aSourceIdent, pDim))
1922 if ( pDim->GetOrientation() != DATA_PILOT_DATA )
1924 // for non-data fields, property Function is the subtotals
1925 if ( eNewFunc == sheet::GeneralFunction_NONE )
1926 pDim->SetSubTotals( 0, NULL );
1927 else
1929 USHORT nFunc = sal::static_int_cast<USHORT>( eNewFunc );
1930 pDim->SetSubTotals( 1, &nFunc );
1933 else
1934 pDim->SetFunction( sal::static_int_cast<USHORT>( eNewFunc ) );
1935 pParent->SetDPObject(pDPObj);
1940 rtl::OUString ScDataPilotFieldObj::getCurrentPage() const
1942 rtl::OUString sRet;
1944 ScDPObject* pDPObj(pParent->GetDPObject());
1945 if (pDPObj)
1947 ScDPSaveDimension* pDim = NULL;
1948 if (lcl_GetDim(pDPObj, aSourceIdent, pDim))
1949 if (pDim->HasCurrentPage())
1950 sRet = pDim->GetCurrentPage();
1953 return sRet;
1956 void ScDataPilotFieldObj::setCurrentPage(const rtl::OUString& sPage)
1958 ScDPObject* pDPObj(pParent->GetDPObject());
1959 if (pDPObj)
1961 ScDPSaveDimension* pDim = NULL;
1962 if (lcl_GetDim(pDPObj, aSourceIdent, pDim))
1964 String sCur(sPage);
1965 pDim->SetCurrentPage(&sCur);
1966 pParent->SetDPObject(pDPObj);
1971 sal_Bool ScDataPilotFieldObj::getUseCurrentPage() const
1973 sal_Bool bRet = sal_False;
1975 ScDPObject* pDPObj(pParent->GetDPObject());
1976 if (pDPObj)
1978 ScDPSaveDimension* pDim = NULL;
1979 if (lcl_GetDim(pDPObj, aSourceIdent, pDim))
1980 bRet = pDim->HasCurrentPage();
1983 return bRet;
1986 void ScDataPilotFieldObj::setUseCurrentPage(sal_Bool bUse)
1988 ScDPObject* pDPObj(pParent->GetDPObject());
1989 if (pDPObj)
1991 ScDPSaveDimension* pDim = NULL;
1992 if (lcl_GetDim(pDPObj, aSourceIdent, pDim))
1994 if (bUse)
1996 String sCur;
1997 pDim->SetCurrentPage(&sCur);
1999 else
2000 pDim->SetCurrentPage(NULL);
2001 pParent->SetDPObject(pDPObj);
2006 const sheet::DataPilotFieldAutoShowInfo* ScDataPilotFieldObj::getAutoShowInfo()
2008 ScDPObject* pDPObj(pParent->GetDPObject());
2009 if (pDPObj)
2011 ScDPSaveDimension* pDim = NULL;
2012 if (lcl_GetDim(pDPObj, aSourceIdent, pDim))
2013 return pDim->GetAutoShowInfo();
2015 return NULL;
2018 void ScDataPilotFieldObj::setAutoShowInfo(const sheet::DataPilotFieldAutoShowInfo* pInfo)
2020 ScDPObject* pDPObj(pParent->GetDPObject());
2021 if (pDPObj)
2023 ScDPSaveDimension* pDim = NULL;
2024 if (lcl_GetDim(pDPObj, aSourceIdent, pDim))
2026 pDim->SetAutoShowInfo(pInfo);
2027 pParent->SetDPObject(pDPObj);
2032 const sheet::DataPilotFieldLayoutInfo* ScDataPilotFieldObj::getLayoutInfo()
2034 ScDPObject* pDPObj(pParent->GetDPObject());
2035 if (pDPObj)
2037 ScDPSaveDimension* pDim = NULL;
2038 if (lcl_GetDim(pDPObj, aSourceIdent, pDim))
2039 return pDim->GetLayoutInfo();
2042 return NULL;
2045 void ScDataPilotFieldObj::setLayoutInfo(const sheet::DataPilotFieldLayoutInfo* pInfo)
2047 ScDPObject* pDPObj(pParent->GetDPObject());
2048 if (pDPObj)
2050 ScDPSaveDimension* pDim = NULL;
2051 if (lcl_GetDim(pDPObj, aSourceIdent, pDim))
2053 pDim->SetLayoutInfo(pInfo);
2054 pParent->SetDPObject(pDPObj);
2059 const sheet::DataPilotFieldReference* ScDataPilotFieldObj::getReference()
2061 ScDPObject* pDPObj(pParent->GetDPObject());
2062 if (pDPObj)
2064 ScDPSaveDimension* pDim = NULL;
2065 if (lcl_GetDim(pDPObj, aSourceIdent, pDim))
2066 return pDim->GetReferenceValue();
2069 return NULL;
2072 void ScDataPilotFieldObj::setReference(const sheet::DataPilotFieldReference* pInfo)
2074 ScDPObject* pDPObj(pParent->GetDPObject());
2075 if (pDPObj)
2077 ScDPSaveDimension* pDim = NULL;
2078 if (lcl_GetDim(pDPObj, aSourceIdent, pDim))
2080 pDim->SetReferenceValue(pInfo);
2081 pParent->SetDPObject(pDPObj);
2086 const sheet::DataPilotFieldSortInfo* ScDataPilotFieldObj::getSortInfo()
2088 ScDPObject* pDPObj(pParent->GetDPObject());
2089 if (pDPObj)
2091 ScDPSaveDimension* pDim = NULL;
2092 if (lcl_GetDim(pDPObj, aSourceIdent, pDim))
2093 return pDim->GetSortInfo();
2096 return NULL;
2099 void ScDataPilotFieldObj::setSortInfo(const sheet::DataPilotFieldSortInfo* pInfo)
2101 ScDPObject* pDPObj(pParent->GetDPObject());
2102 if (pDPObj)
2104 ScDPSaveDimension* pDim = NULL;
2105 if (lcl_GetDim(pDPObj, aSourceIdent, pDim))
2107 pDim->SetSortInfo(pInfo);
2108 pParent->SetDPObject(pDPObj);
2113 sal_Bool ScDataPilotFieldObj::getShowEmpty() const
2115 sal_Bool bRet = sal_False;
2117 ScDPObject* pDPObj(pParent->GetDPObject());
2118 if (pDPObj)
2120 ScDPSaveDimension* pDim = NULL;
2121 if (lcl_GetDim(pDPObj, aSourceIdent, pDim))
2122 bRet = pDim->GetShowEmpty();
2125 return bRet;
2128 void ScDataPilotFieldObj::setShowEmpty(sal_Bool bShow)
2130 ScDPObject* pDPObj(pParent->GetDPObject());
2131 if (pDPObj)
2133 ScDPSaveDimension* pDim = NULL;
2134 if (lcl_GetDim(pDPObj, aSourceIdent, pDim))
2136 pDim->SetShowEmpty(bShow);
2137 pParent->SetDPObject(pDPObj);
2142 void ScDataPilotFieldObj::SetGroupInfo(const ScDPNumGroupInfo& rGroupInfo,
2143 sheet::DataPilotFieldGroupInfo& rInfo)
2145 rInfo.HasDateValues = rGroupInfo.DateValues;
2146 rInfo.HasAutoStart = rGroupInfo.AutoStart;
2147 rInfo.Start = rGroupInfo.Start;
2148 rInfo.HasAutoEnd = rGroupInfo.AutoEnd;
2149 rInfo.End = rGroupInfo.End;
2150 rInfo.Step = rGroupInfo.Step;
2153 void ScDataPilotFieldObj::FillGroupInfo(const ScDPSaveGroupDimension* pGroupDim,
2154 const ScDPSaveNumGroupDimension* pNumGroupDim, sheet::DataPilotFieldGroupInfo& rInfo)
2156 if (pGroupDim || pNumGroupDim)
2158 if (pGroupDim)
2160 rInfo.GroupBy = pGroupDim->GetDatePart();
2161 if (pParent)
2163 uno::Reference<container::XNameAccess> xFields(pParent->getDataPilotFields(), uno::UNO_QUERY);
2164 if (xFields.is())
2166 rInfo.SourceField.set(xFields->getByName(pGroupDim->GetSourceDimName()), uno::UNO_QUERY);
2169 SetGroupInfo(pGroupDim->GetDateInfo(), rInfo);
2170 if (!pGroupDim->GetDatePart())
2172 ScFieldGroups aGroups;
2173 sal_Int32 nCount = pGroupDim->GetGroupCount();
2174 for (sal_Int32 i = 0; i < nCount; ++i)
2176 const ScDPSaveGroupItem* pGroup = pGroupDim->GetGroupByIndex( i );
2177 if (pGroup)
2179 ScFieldGroup aGroup;
2180 aGroup.sName = pGroup->GetGroupName();
2181 sal_Int32 nElemCount = pGroup->GetElementCount();
2182 for(sal_Int32 j = 0; j < nElemCount; ++j)
2184 const String* pElem = pGroup->GetElementByIndex( j );
2185 if (pElem)
2187 aGroup.aMembers.push_back(*pElem);
2190 aGroups.push_back(aGroup);
2193 rInfo.Groups = new ScDataPilotFieldGroupsObj(aGroups);
2196 else
2198 if (pNumGroupDim->GetDatePart())
2200 rInfo.GroupBy = pNumGroupDim->GetDatePart();
2201 SetGroupInfo(pNumGroupDim->GetDateInfo(), rInfo);
2203 else
2205 SetGroupInfo(pNumGroupDim->GetInfo(), rInfo);
2211 sal_Bool ScDataPilotFieldObj::hasGroupInfo()
2213 sal_Bool bRet = sal_False;
2214 ScDPObject* pDPObj(pParent->GetDPObject());
2215 if (pDPObj)
2217 ScDPSaveDimension* pDim = NULL;
2218 if (lcl_GetDim(pDPObj, aSourceIdent, pDim))
2220 const ScDPSaveData* pDPSave = pDPObj->GetSaveData();
2221 const ScDPDimensionSaveData* pDimData = pDPSave->GetExistingDimensionData();
2222 if (pDimData)
2224 bRet = (pDimData->GetNamedGroupDim(pDim->GetName()) || pDimData->GetNumGroupDim(pDim->GetName()));
2228 return bRet;
2231 sheet::DataPilotFieldGroupInfo ScDataPilotFieldObj::getGroupInfo()
2233 sheet::DataPilotFieldGroupInfo aInfo;
2235 ScDPObject* pDPObj(pParent->GetDPObject());
2236 if (pDPObj)
2238 ScDPSaveDimension* pDim = NULL;
2239 if (lcl_GetDim(pDPObj, aSourceIdent, pDim))
2241 const ScDPSaveData* pDPSave = pDPObj->GetSaveData();
2242 const ScDPDimensionSaveData* pDimData = pDPSave->GetExistingDimensionData();
2243 if (pDimData)
2245 FillGroupInfo(pDimData->GetNamedGroupDim(pDim->GetName()),
2246 pDimData->GetNumGroupDim(pDim->GetName()), aInfo);
2251 return aInfo;
2254 void ScDataPilotFieldObj::setGroupInfo(const sheet::DataPilotFieldGroupInfo* pInfo)
2256 ScDPObject* pDPObj(pParent->GetDPObject());
2257 if (pDPObj)
2259 ScDPSaveDimension* pDim = NULL;
2260 if (lcl_GetDim(pDPObj, aSourceIdent, pDim))
2262 ScDPSaveData* pSaveData = pDPObj->GetSaveData();
2263 if (pInfo)
2265 ScDPNumGroupInfo aInfo;
2266 aInfo.Enable = sal_True;
2267 aInfo.DateValues = pInfo->HasDateValues;
2268 aInfo.AutoStart = pInfo->HasAutoStart;
2269 aInfo.AutoEnd = pInfo->HasAutoEnd;
2270 aInfo.Start = pInfo->Start;
2271 aInfo.End = pInfo->End;
2272 aInfo.Step = pInfo->Step;
2273 uno::Reference<container::XNamed> xNamed(pInfo->SourceField, uno::UNO_QUERY);
2274 if (xNamed.is())
2276 ScDPSaveGroupDimension aGroupDim(xNamed->getName(), getName());
2277 if (pInfo->GroupBy)
2278 aGroupDim.SetDateInfo(aInfo, pInfo->GroupBy);
2279 else
2281 uno::Reference<container::XIndexAccess> xIndex(pInfo->Groups, uno::UNO_QUERY);
2282 if (xIndex.is())
2284 sal_Int32 nCount(xIndex->getCount());
2285 for(sal_Int32 i = 0; i < nCount; i++)
2287 uno::Reference<container::XNamed> xGroupNamed(xIndex->getByIndex(i), uno::UNO_QUERY);
2288 if (xGroupNamed.is())
2290 ScDPSaveGroupItem aItem(xGroupNamed->getName());
2291 uno::Reference<container::XIndexAccess> xGroupIndex(xGroupNamed, uno::UNO_QUERY);
2292 if (xGroupIndex.is())
2294 sal_Int32 nItemCount(xGroupIndex->getCount());
2295 for (sal_Int32 j = 0; j < nItemCount; ++j)
2297 uno::Reference<container::XNamed> xItemNamed(xGroupIndex->getByIndex(j), uno::UNO_QUERY);
2298 if (xItemNamed.is())
2299 aItem.AddElement(xItemNamed->getName());
2302 aGroupDim.AddGroupItem(aItem);
2307 ScDPDimensionSaveData aDimSaveData;
2309 aDimSaveData.AddGroupDimension(aGroupDim);
2310 pSaveData->SetDimensionData(&aDimSaveData);
2312 else //NumGroup
2314 ScDPDimensionSaveData* pDimData = pSaveData->GetDimensionData(); // created if not there
2316 ScDPSaveNumGroupDimension* pExisting = pDimData->GetNumGroupDimAcc( getName() );
2317 if ( pExisting )
2319 if (pInfo->GroupBy)
2320 pExisting->SetDateInfo(aInfo, pInfo->GroupBy);
2321 // modify existing group dimension
2322 pExisting->SetGroupInfo( aInfo );
2324 else
2326 // create new group dimension
2327 ScDPSaveNumGroupDimension aNumGroupDim( getName(), aInfo );
2328 if (pInfo->GroupBy)
2329 aNumGroupDim.SetDateInfo(aInfo, pInfo->GroupBy);
2330 pDimData->AddNumGroupDimension( aNumGroupDim );
2333 // pSaveData->SetDimensionData(pDimData); not neccessary
2336 else
2338 pSaveData->SetDimensionData(NULL);
2340 pDPObj->SetSaveData(*pSaveData);
2341 pParent->SetDPObject(pDPObj);
2346 sal_Bool ScDataPilotFieldObj::HasString(const uno::Sequence< ::rtl::OUString >& rItems, const rtl::OUString& aString)
2348 sal_Bool bRet = sal_False;
2350 sal_Int32 nCount(rItems.getLength());
2351 sal_Int32 nItem(0);
2352 while (nItem < nCount && !bRet)
2354 bRet = rItems[nItem] == aString;
2355 ++nItem;
2358 return bRet;
2361 // XDataPilotFieldGrouping
2362 uno::Reference < sheet::XDataPilotField > SAL_CALL
2363 ScDataPilotFieldObj::createNameGroup(const uno::Sequence< rtl::OUString >& rItems)
2364 throw (::com::sun::star::uno::RuntimeException, lang::IllegalArgumentException)
2366 ScUnoGuard aGuard;
2368 uno::Reference < sheet::XDataPilotField > xRet;
2369 rtl::OUString sNewDim;
2371 if (!rItems.getLength())
2372 throw lang::IllegalArgumentException();
2374 ScDPObject* pDPObj(pParent->GetDPObject());
2375 if ( pDPObj )
2377 ScDPSaveDimension* pDim = NULL;
2378 if ( rItems.getLength() > 0 && lcl_GetDim(pDPObj, aSourceIdent, pDim))
2380 String aDimName (pDim->GetName());
2382 ScDPSaveData aSaveData(*pDPObj->GetSaveData());
2383 ScDPDimensionSaveData* pDimData = aSaveData.GetDimensionData(); // created if not there
2385 // find original base
2386 String aBaseDimName( aDimName );
2387 const ScDPSaveGroupDimension* pBaseGroupDim = pDimData->GetNamedGroupDim( aDimName );
2388 if ( pBaseGroupDim )
2390 // any entry's SourceDimName is the original base
2391 aBaseDimName = pBaseGroupDim->GetSourceDimName();
2394 // find existing group dimension
2395 // (using the selected dim, can be intermediate group dim)
2396 ScDPSaveGroupDimension* pGroupDimension = pDimData->GetGroupDimAccForBase( aDimName );
2398 // remove the selected items from their groups
2399 // (empty groups are removed, too)
2400 sal_Int32 nEntryCount = rItems.getLength();
2401 sal_Int32 nEntry;
2402 if ( pGroupDimension )
2404 for (nEntry=0; nEntry<nEntryCount; nEntry++)
2406 String aEntryName(rItems[nEntry]);
2407 if ( pBaseGroupDim )
2409 // for each selected (intermediate) group, remove all its items
2410 // (same logic as for adding, below)
2411 const ScDPSaveGroupItem* pBaseGroup = pBaseGroupDim->GetNamedGroup( aEntryName );
2412 if ( pBaseGroup )
2413 pBaseGroup->RemoveElementsFromGroups( *pGroupDimension ); // remove all elements
2414 else
2415 pGroupDimension->RemoveFromGroups( aEntryName );
2417 else
2418 pGroupDimension->RemoveFromGroups( aEntryName );
2422 ScDPSaveGroupDimension* pNewGroupDim = NULL;
2423 if ( !pGroupDimension )
2425 // create a new group dimension
2426 String aGroupDimName = pDimData->CreateGroupDimName( aBaseDimName, *pDPObj, false, NULL );
2427 pNewGroupDim = new ScDPSaveGroupDimension( aBaseDimName, aGroupDimName );
2428 sNewDim = aGroupDimName;
2430 pGroupDimension = pNewGroupDim; // make changes to the new dim if none existed
2432 if ( pBaseGroupDim )
2434 // If it's a higher-order group dimension, pre-allocate groups for all
2435 // non-selected original groups, so the individual base members aren't
2436 // used for automatic groups (this would make the original groups hard
2437 // to find).
2438 //! Also do this when removing groups?
2439 //! Handle this case dynamically with automatic groups?
2441 long nGroupCount = pBaseGroupDim->GetGroupCount();
2442 for ( long nGroup = 0; nGroup < nGroupCount; nGroup++ )
2444 const ScDPSaveGroupItem* pBaseGroup = pBaseGroupDim->GetGroupByIndex( nGroup );
2446 StrData aStrData( pBaseGroup->GetGroupName() );
2447 if ( !HasString(rItems, aStrData.GetString()) ) //! ignore case?
2449 // add an additional group for each item that is not in the selection
2450 ScDPSaveGroupItem aGroup( pBaseGroup->GetGroupName() );
2451 aGroup.AddElementsFromGroup( *pBaseGroup );
2452 pGroupDimension->AddGroupItem( aGroup );
2457 String aGroupDimName = pGroupDimension->GetGroupDimName();
2459 //! localized prefix string
2460 String aGroupName = pGroupDimension->CreateGroupName( String::CreateFromAscii("Group") );
2461 ScDPSaveGroupItem aGroup( aGroupName );
2462 uno::Reference<container::XNameAccess> xMembers;
2463 if (!lcl_GetMembers(pParent, aSourceIdent, xMembers))
2465 delete pNewGroupDim;
2466 throw uno::RuntimeException();
2469 for (nEntry=0; nEntry<nEntryCount; nEntry++)
2471 String aEntryName(rItems[nEntry]);
2473 if (!xMembers->hasByName(aEntryName))
2475 delete pNewGroupDim;
2476 throw lang::IllegalArgumentException();
2479 if ( pBaseGroupDim )
2481 // for each selected (intermediate) group, add all its items
2482 const ScDPSaveGroupItem* pBaseGroup = pBaseGroupDim->GetNamedGroup( aEntryName );
2483 if ( pBaseGroup )
2484 aGroup.AddElementsFromGroup( *pBaseGroup );
2485 else
2486 aGroup.AddElement( aEntryName ); // no group found -> automatic group, add the item itself
2488 else
2489 aGroup.AddElement( aEntryName ); // no group dimension, add all items directly
2492 pGroupDimension->AddGroupItem( aGroup );
2494 if ( pNewGroupDim )
2496 pDimData->AddGroupDimension( *pNewGroupDim );
2497 delete pNewGroupDim; // AddGroupDimension copies the object
2498 // don't access pGroupDimension after here
2500 pGroupDimension = pNewGroupDim = NULL;
2502 // set orientation
2503 ScDPSaveDimension* pSaveDimension = aSaveData.GetDimensionByName( aGroupDimName );
2504 if ( pSaveDimension->GetOrientation() == sheet::DataPilotFieldOrientation_HIDDEN )
2506 ScDPSaveDimension* pOldDimension = aSaveData.GetDimensionByName( aDimName );
2507 pSaveDimension->SetOrientation( pOldDimension->GetOrientation() );
2508 long nPosition = 0; //! before (immediate) base
2509 aSaveData.SetPosition( pSaveDimension, nPosition );
2512 // apply changes
2513 pDPObj->SetSaveData( aSaveData );
2514 pParent->SetDPObject(pDPObj);
2518 if (sNewDim.getLength())
2520 uno::Reference< container::XNameAccess > xFields(pParent->getDataPilotFields(), uno::UNO_QUERY);
2521 if (xFields.is())
2523 xRet.set(xFields->getByName(sNewDim), uno::UNO_QUERY);
2524 DBG_ASSERT(xRet.is(), "there is a name, so there should be also a field");
2528 return xRet;
2531 String lcl_GetDateByName( sal_Int32 nGroupBy )
2533 String aRet; //! globstr-ID
2534 switch (nGroupBy)
2536 //! use translated strings from globstr.src
2537 case com::sun::star::sheet::DataPilotFieldGroupBy::SECONDS: aRet = String::CreateFromAscii("Seconds"); break;
2538 case com::sun::star::sheet::DataPilotFieldGroupBy::MINUTES: aRet = String::CreateFromAscii("Minutes"); break;
2539 case com::sun::star::sheet::DataPilotFieldGroupBy::HOURS: aRet = String::CreateFromAscii("Hours"); break;
2540 case com::sun::star::sheet::DataPilotFieldGroupBy::DAYS: aRet = String::CreateFromAscii("Days"); break;
2541 case com::sun::star::sheet::DataPilotFieldGroupBy::MONTHS: aRet = String::CreateFromAscii("Months"); break;
2542 case com::sun::star::sheet::DataPilotFieldGroupBy::QUARTERS: aRet = String::CreateFromAscii("Quarters"); break;
2543 case com::sun::star::sheet::DataPilotFieldGroupBy::YEARS: aRet = String::CreateFromAscii("Years"); break;
2544 default:
2545 DBG_ERROR("invalid date part");
2547 return aRet;
2550 uno::Reference < sheet::XDataPilotField > SAL_CALL
2551 ScDataPilotFieldObj::createDateGroup(const sheet::DataPilotFieldGroupInfo& rInfo)
2552 throw (::com::sun::star::uno::RuntimeException, lang::IllegalArgumentException)
2554 ScUnoGuard aGuard;
2556 if (!rInfo.HasDateValues)
2557 throw lang::IllegalArgumentException();
2559 uno::Reference < sheet::XDataPilotField > xRet;
2561 ScDPObject* pDPObj(pParent->GetDPObject());
2562 if ( pDPObj )
2564 ScDPSaveDimension* pDim = NULL;
2565 if ( lcl_GetDim(pDPObj, aSourceIdent, pDim))
2567 ScDPNumGroupInfo aInfo;
2568 aInfo.DateValues = rInfo.HasDateValues;
2569 aInfo.AutoStart = rInfo.HasAutoStart;
2570 aInfo.Start = rInfo.Start;
2571 aInfo.AutoEnd = rInfo.HasAutoEnd;
2572 aInfo.End = rInfo.End;
2573 aInfo.Step = rInfo.Step;
2575 String aDimName (pDim->GetName());
2577 ScDPSaveData aData( *pDPObj->GetSaveData() );
2578 ScDPDimensionSaveData* pDimData = aData.GetDimensionData(); // created if not there
2580 // find original base
2581 String aBaseDimName( aDimName );
2582 const ScDPSaveGroupDimension* pBaseGroupDim = pDimData->GetNamedGroupDim( aDimName );
2583 if ( pBaseGroupDim )
2585 // any entry's SourceDimName is the original base
2586 aBaseDimName = pBaseGroupDim->GetSourceDimName();
2589 if ( rInfo.GroupBy )
2591 // create date group dimensions
2593 sal_Bool bFirst(sal_False);
2594 if (!pBaseGroupDim) // it's the base Dim
2596 // test whether there is already grouping
2597 const ScDPSaveNumGroupDimension* pNumGroupDim = pDimData->GetNumGroupDim(pDim->GetName());
2598 if (pNumGroupDim)
2600 if (!pNumGroupDim->GetDateInfo().DateValues)
2601 bFirst = sal_True;
2603 else
2604 bFirst = sal_True;
2607 ScDPNumGroupInfo aEmpty;
2608 if ( bFirst )
2610 // innermost part: create NumGroupDimension (replacing original values)
2611 // Dimension name is left unchanged
2613 if ( rInfo.GroupBy == com::sun::star::sheet::DataPilotFieldGroupBy::DAYS && rInfo.Step != 0.0 )
2615 // only days, and a step value specified: use numerical grouping
2616 // with DateValues flag, not date grouping
2618 ScDPNumGroupInfo aNumInfo( aInfo );
2619 aNumInfo.DateValues = sal_True;
2621 ScDPSaveNumGroupDimension aNumGroupDim( aBaseDimName, aNumInfo );
2622 pDimData->AddNumGroupDimension( aNumGroupDim );
2624 else
2626 ScDPSaveNumGroupDimension aNumGroupDim( aBaseDimName, aEmpty );
2627 aNumGroupDim.SetDateInfo( aInfo, rInfo.GroupBy );
2628 pDimData->AddNumGroupDimension( aNumGroupDim );
2631 else
2633 // additional parts: create GroupDimension (shown as additional dimensions)
2635 String aPartName = lcl_GetDateByName( rInfo.GroupBy );
2637 String aGroupDimName = pDimData->CreateGroupDimName(
2638 aPartName, *pDPObj, true, NULL );
2639 ScDPSaveGroupDimension aGroupDim( aBaseDimName, aGroupDimName );
2640 aGroupDim.SetDateInfo( aInfo, rInfo.GroupBy );
2641 pDimData->AddGroupDimension( aGroupDim );
2643 // set orientation
2644 ScDPSaveDimension* pSaveDimension = aData.GetDimensionByName( aGroupDimName );
2645 if ( pSaveDimension->GetOrientation() == sheet::DataPilotFieldOrientation_HIDDEN )
2647 ScDPSaveDimension* pOldDimension = aData.GetDimensionByName( aBaseDimName );
2648 pSaveDimension->SetOrientation( pOldDimension->GetOrientation() );
2649 long nPosition = 0; //! before (immediate) base
2650 aData.SetPosition( pSaveDimension, nPosition );
2655 // apply changes
2656 pDPObj->SetSaveData( aData );
2657 pParent->SetDPObject(pDPObj);
2661 return xRet;
2663 //------------------------------------------------------------------------
2665 ScDataPilotFieldGroupsObj::ScDataPilotFieldGroupsObj(const ScFieldGroups& rGroups) :
2666 aGroups(rGroups)
2670 ScDataPilotFieldGroupsObj::~ScDataPilotFieldGroupsObj()
2674 // XNameAccess
2676 uno::Any SAL_CALL ScDataPilotFieldGroupsObj::getByName( const rtl::OUString& aName )
2677 throw(container::NoSuchElementException,
2678 lang::WrappedTargetException, uno::RuntimeException)
2680 ScUnoGuard aGuard;
2682 ScFieldGroups::const_iterator aItr(aGroups.begin());
2683 ScFieldGroups::const_iterator aEndItr(aGroups.end());
2684 sal_Bool bFound(sal_False);
2685 while (!bFound && aItr != aEndItr)
2687 if (aItr->sName == aName)
2688 bFound = sal_True;
2689 else
2690 ++aItr;
2692 if (bFound)
2693 return uno::makeAny(uno::Reference < container::XNameAccess > (new ScDataPilotFieldGroupObj(*aItr)));
2694 else
2695 throw container::NoSuchElementException();
2697 // return uno::Any();
2700 uno::Sequence<rtl::OUString> SAL_CALL ScDataPilotFieldGroupsObj::getElementNames()
2701 throw(uno::RuntimeException)
2703 ScUnoGuard aGuard;
2704 // TODO
2706 uno::Sequence<rtl::OUString> aSeq(aGroups.size());
2707 ScFieldGroups::const_iterator aItr(aGroups.begin());
2708 ScFieldGroups::const_iterator aEndItr(aGroups.end());
2709 sal_Int32 i(0);
2710 while (aItr != aEndItr)
2712 aSeq[i] = aItr->sName;
2713 ++aItr;
2714 ++i;
2716 return aSeq;
2719 sal_Bool SAL_CALL ScDataPilotFieldGroupsObj::hasByName( const rtl::OUString& aName )
2720 throw(uno::RuntimeException)
2722 ScUnoGuard aGuard;
2724 ScFieldGroups::const_iterator aItr(aGroups.begin());
2725 ScFieldGroups::const_iterator aEndItr(aGroups.end());
2726 sal_Bool bFound(sal_False);
2727 while (!bFound && aItr != aEndItr)
2729 if (aItr->sName == aName)
2730 bFound = sal_True;
2731 else
2732 ++aItr;
2735 return bFound;
2738 // XNameReplace
2739 void SAL_CALL ScDataPilotFieldGroupsObj::replaceByName( const ::rtl::OUString& aName,
2740 const uno::Any& aElement )
2741 throw (lang::IllegalArgumentException,
2742 container::NoSuchElementException,
2743 lang::WrappedTargetException,
2744 uno::RuntimeException)
2746 ScUnoGuard aGuard;
2748 ScFieldGroups::iterator aItr(aGroups.begin());
2749 ScFieldGroups::iterator aEndItr(aGroups.end());
2750 sal_Bool bFound(sal_False);
2751 while (!bFound && aItr != aEndItr)
2753 if (aItr->sName == aName)
2754 bFound = sal_True;
2755 else
2756 ++aItr;
2758 if (bFound)
2760 uno::Reference<container::XNamed> xNamed(aElement, uno::UNO_QUERY);
2761 if (xNamed.is())
2763 ScFieldGroup aGroup;
2764 aGroup.sName = xNamed->getName();
2765 uno::Reference<container::XIndexAccess> xIndex(xNamed, uno::UNO_QUERY);
2766 if (xIndex.is())
2768 sal_Int32 nCount(xIndex->getCount());
2769 for (sal_Int32 i = 0; i < nCount; ++i)
2771 uno::Reference<container::XNamed> xItem(xIndex->getByIndex(i), uno::UNO_QUERY);
2772 if (xItem.is())
2773 aGroup.aMembers.push_back(xNamed->getName());
2774 else
2775 throw lang::IllegalArgumentException();
2778 else
2779 throw lang::IllegalArgumentException();
2781 aGroups.erase(aItr);
2782 aGroups.push_back(aGroup);
2784 else
2785 throw lang::IllegalArgumentException();
2787 else
2788 throw container::NoSuchElementException();
2791 // XNameContainer
2792 void SAL_CALL ScDataPilotFieldGroupsObj::insertByName( const ::rtl::OUString& aName,
2793 const uno::Any& aElement )
2794 throw (lang::IllegalArgumentException,
2795 container::ElementExistException,
2796 lang::WrappedTargetException,
2797 uno::RuntimeException)
2799 ScUnoGuard aGuard;
2801 ScFieldGroups::const_iterator aItr(aGroups.begin());
2802 ScFieldGroups::const_iterator aEndItr(aGroups.end());
2803 sal_Bool bFound(sal_False);
2804 while (!bFound && aItr != aEndItr)
2806 if (aItr->sName == aName)
2807 bFound = sal_True;
2808 else
2809 ++aItr;
2811 if (!bFound)
2813 uno::Reference<container::XNamed> xNamed(aElement, uno::UNO_QUERY);
2814 if (xNamed.is())
2816 ScFieldGroup aGroup;
2817 aGroup.sName = xNamed->getName();
2818 uno::Reference<container::XIndexAccess> xIndex(xNamed, uno::UNO_QUERY);
2819 if (xIndex.is())
2821 sal_Int32 nCount(xIndex->getCount());
2822 for (sal_Int32 i = 0; i < nCount; ++i)
2824 uno::Reference<container::XNamed> xItem(xIndex->getByIndex(i), uno::UNO_QUERY);
2825 if (xItem.is())
2826 aGroup.aMembers.push_back(xNamed->getName());
2827 else
2828 throw lang::IllegalArgumentException();
2831 else
2832 throw lang::IllegalArgumentException();
2834 aGroups.push_back(aGroup);
2836 else
2837 throw lang::IllegalArgumentException();
2839 else
2840 throw container::ElementExistException();
2843 void SAL_CALL ScDataPilotFieldGroupsObj::removeByName( const ::rtl::OUString& aName )
2844 throw (container::NoSuchElementException,
2845 lang::WrappedTargetException,
2846 uno::RuntimeException)
2848 ScUnoGuard aGuard;
2850 ScFieldGroups::iterator aItr(aGroups.begin());
2851 ScFieldGroups::iterator aEndItr(aGroups.end());
2852 sal_Bool bFound(sal_False);
2853 while (!bFound && aItr != aEndItr)
2855 if (aItr->sName == aName)
2856 bFound = sal_True;
2857 else
2858 ++aItr;
2860 if (bFound)
2861 aGroups.erase(aItr);
2862 else
2863 throw container::NoSuchElementException();
2866 // XEnumerationAccess
2868 uno::Reference<container::XEnumeration> SAL_CALL ScDataPilotFieldGroupsObj::createEnumeration()
2869 throw(uno::RuntimeException)
2871 ScUnoGuard aGuard;
2872 return new ScIndexEnumeration(this, rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.sheet.DataPilotFieldGroupsEnumeration")));
2875 // XIndexAccess
2877 sal_Int32 SAL_CALL ScDataPilotFieldGroupsObj::getCount() throw(uno::RuntimeException)
2879 ScUnoGuard aGuard;
2880 return aGroups.size();
2883 uno::Any SAL_CALL ScDataPilotFieldGroupsObj::getByIndex( sal_Int32 nIndex )
2884 throw(lang::IndexOutOfBoundsException,
2885 lang::WrappedTargetException, uno::RuntimeException)
2887 ScUnoGuard aGuard;
2888 if (nIndex >= 0 && nIndex < sal::static_int_cast<sal_Int32>(aGroups.size()))
2889 return uno::makeAny(uno::Reference < container::XNameAccess > (new ScDataPilotFieldGroupObj(aGroups[nIndex])));
2890 else
2891 throw lang::IndexOutOfBoundsException();
2894 uno::Type SAL_CALL ScDataPilotFieldGroupsObj::getElementType() throw(uno::RuntimeException)
2896 ScUnoGuard aGuard;
2897 return getCppuType((uno::Reference<container::XNameAccess>*)0);
2900 sal_Bool SAL_CALL ScDataPilotFieldGroupsObj::hasElements() throw(uno::RuntimeException)
2902 ScUnoGuard aGuard;
2903 return ( !aGroups.empty() );
2906 //------------------------------------------------------------------------
2908 ScDataPilotFieldGroupObj::ScDataPilotFieldGroupObj(const ScFieldGroup& rGroup) :
2909 aGroup(rGroup)
2913 ScDataPilotFieldGroupObj::~ScDataPilotFieldGroupObj()
2917 // XNameAccess
2919 uno::Any SAL_CALL ScDataPilotFieldGroupObj::getByName( const rtl::OUString& aName )
2920 throw(container::NoSuchElementException,
2921 lang::WrappedTargetException, uno::RuntimeException)
2923 ScUnoGuard aGuard;
2925 std::vector< rtl::OUString >::const_iterator aItr(aGroup.aMembers.begin());
2926 std::vector< rtl::OUString >::const_iterator aEndItr(aGroup.aMembers.end());
2927 sal_Bool bFound(sal_False);
2928 while (!bFound && aItr != aEndItr)
2930 if (*aItr == aName)
2931 bFound = sal_True;
2932 else
2933 ++aItr;
2935 if (bFound)
2936 return uno::makeAny(uno::Reference < container::XNamed > (new ScDataPilotFieldGroupItemObj(*aItr)));
2938 return uno::Any();
2941 uno::Sequence<rtl::OUString> SAL_CALL ScDataPilotFieldGroupObj::getElementNames()
2942 throw(uno::RuntimeException)
2944 ScUnoGuard aGuard;
2945 // TODO
2947 uno::Sequence<rtl::OUString> aSeq(aGroup.aMembers.size());
2948 std::vector< rtl::OUString >::const_iterator aItr(aGroup.aMembers.begin());
2949 std::vector< rtl::OUString >::const_iterator aEndItr(aGroup.aMembers.end());
2950 sal_Int32 i(0);
2951 while (aItr != aEndItr)
2953 aSeq[i] = *aItr;
2954 ++aItr;
2955 ++i;
2957 return aSeq;
2960 sal_Bool SAL_CALL ScDataPilotFieldGroupObj::hasByName( const rtl::OUString& aName )
2961 throw(uno::RuntimeException)
2963 ScUnoGuard aGuard;
2965 std::vector< rtl::OUString >::const_iterator aItr(aGroup.aMembers.begin());
2966 std::vector< rtl::OUString >::const_iterator aEndItr(aGroup.aMembers.end());
2967 sal_Bool bFound(sal_False);
2968 while (!bFound && aItr != aEndItr)
2970 if (*aItr == aName)
2971 bFound = sal_True;
2972 else
2973 ++aItr;
2976 return bFound;
2979 // XNameReplace
2980 void SAL_CALL ScDataPilotFieldGroupObj::replaceByName( const ::rtl::OUString& aName,
2981 const uno::Any& aElement )
2982 throw (lang::IllegalArgumentException,
2983 container::NoSuchElementException,
2984 lang::WrappedTargetException,
2985 uno::RuntimeException)
2987 ScUnoGuard aGuard;
2989 std::vector<rtl::OUString>::iterator aItr(aGroup.aMembers.begin());
2990 std::vector<rtl::OUString>::iterator aEndItr(aGroup.aMembers.end());
2991 sal_Bool bFound(sal_False);
2992 while (!bFound && aItr != aEndItr)
2994 if (*aItr == aName)
2995 bFound = sal_True;
2996 else
2997 ++aItr;
2999 if (bFound)
3001 uno::Reference<container::XNamed> xNamed(aElement, uno::UNO_QUERY);
3002 if (xNamed.is())
3004 aGroup.aMembers.erase(aItr);
3005 aGroup.aMembers.push_back(xNamed->getName());
3007 else
3008 throw lang::IllegalArgumentException();
3010 else
3011 throw container::NoSuchElementException();
3014 // XNameContainer
3015 void SAL_CALL ScDataPilotFieldGroupObj::insertByName( const ::rtl::OUString& aName,
3016 const uno::Any& aElement )
3017 throw (lang::IllegalArgumentException,
3018 container::ElementExistException,
3019 lang::WrappedTargetException,
3020 uno::RuntimeException)
3022 ScUnoGuard aGuard;
3024 std::vector<rtl::OUString>::iterator aItr(aGroup.aMembers.begin());
3025 std::vector<rtl::OUString>::iterator aEndItr(aGroup.aMembers.end());
3026 sal_Bool bFound(sal_False);
3027 while (!bFound && aItr != aEndItr)
3029 if (*aItr == aName)
3030 bFound = sal_True;
3031 else
3032 ++aItr;
3034 if (!bFound)
3036 uno::Reference<container::XNamed> xNamed(aElement, uno::UNO_QUERY);
3037 if (xNamed.is())
3039 if (aName == xNamed->getName())
3040 aGroup.aMembers.push_back(aName);
3041 else
3042 throw lang::IllegalArgumentException();
3044 else
3045 throw lang::IllegalArgumentException();
3047 else
3048 throw container::ElementExistException();
3051 void SAL_CALL ScDataPilotFieldGroupObj::removeByName( const ::rtl::OUString& aName )
3052 throw (container::NoSuchElementException,
3053 lang::WrappedTargetException,
3054 uno::RuntimeException)
3056 ScUnoGuard aGuard;
3058 std::vector<rtl::OUString>::iterator aItr(aGroup.aMembers.begin());
3059 std::vector<rtl::OUString>::iterator aEndItr(aGroup.aMembers.end());
3060 sal_Bool bFound(sal_False);
3061 while (!bFound && aItr != aEndItr)
3063 if (*aItr == aName)
3064 bFound = sal_True;
3065 else
3066 ++aItr;
3068 if (bFound)
3069 aGroup.aMembers.erase(aItr);
3070 else
3071 throw container::NoSuchElementException();
3074 // XEnumerationAccess
3076 uno::Reference<container::XEnumeration> SAL_CALL ScDataPilotFieldGroupObj::createEnumeration()
3077 throw(uno::RuntimeException)
3079 ScUnoGuard aGuard;
3080 return new ScIndexEnumeration(this, rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.sheet.DataPilotFieldGroupEnumeration")));
3083 // XIndexAccess
3085 sal_Int32 SAL_CALL ScDataPilotFieldGroupObj::getCount() throw(uno::RuntimeException)
3087 ScUnoGuard aGuard;
3088 return aGroup.aMembers.size();
3091 uno::Any SAL_CALL ScDataPilotFieldGroupObj::getByIndex( sal_Int32 nIndex )
3092 throw(lang::IndexOutOfBoundsException,
3093 lang::WrappedTargetException, uno::RuntimeException)
3095 ScUnoGuard aGuard;
3096 if (nIndex >= 0 && nIndex < sal::static_int_cast<sal_Int32>(aGroup.aMembers.size()))
3097 return uno::makeAny(uno::Reference < container::XNamed > (new ScDataPilotFieldGroupItemObj(aGroup.aMembers[nIndex])));
3098 else
3099 throw lang::IndexOutOfBoundsException();
3102 uno::Type SAL_CALL ScDataPilotFieldGroupObj::getElementType() throw(uno::RuntimeException)
3104 ScUnoGuard aGuard;
3105 return getCppuType((uno::Reference<container::XNamed>*)0);
3108 sal_Bool SAL_CALL ScDataPilotFieldGroupObj::hasElements() throw(uno::RuntimeException)
3110 ScUnoGuard aGuard;
3111 return ( !aGroup.aMembers.empty() );
3114 // XNamed
3115 ::rtl::OUString SAL_CALL ScDataPilotFieldGroupObj::getName() throw(::com::sun::star::uno::RuntimeException)
3117 ScUnoGuard aGuard;
3119 return aGroup.sName;
3122 void SAL_CALL ScDataPilotFieldGroupObj::setName( const ::rtl::OUString& aName )
3123 throw(::com::sun::star::uno::RuntimeException)
3125 ScUnoGuard aGuard;
3127 aGroup.sName = aName;
3130 //------------------------------------------------------------------------
3132 ScDataPilotFieldGroupItemObj::ScDataPilotFieldGroupItemObj(const rtl::OUString& rName)
3133 : sName(rName)
3137 ScDataPilotFieldGroupItemObj::~ScDataPilotFieldGroupItemObj()
3141 // XNamed
3142 ::rtl::OUString SAL_CALL ScDataPilotFieldGroupItemObj::getName() throw(::com::sun::star::uno::RuntimeException)
3144 ScUnoGuard aGuard;
3146 return sName;
3149 void SAL_CALL ScDataPilotFieldGroupItemObj::setName( const ::rtl::OUString& aName )
3150 throw(::com::sun::star::uno::RuntimeException)
3152 ScUnoGuard aGuard;
3154 sName = aName;
3157 //------------------------------------------------------------------------
3159 ScDataPilotItemsObj::ScDataPilotItemsObj(ScDataPilotDescriptorBase* pPar, const ScFieldIdentifier& rIdent) :
3160 pParent( pPar ),
3161 aSourceIdent( rIdent )
3163 pParent->acquire();
3166 ScDataPilotItemsObj::~ScDataPilotItemsObj()
3168 pParent->release();
3171 SCSIZE lcl_GetItemCount( ScDataPilotDescriptorBase* pParent, const ScFieldIdentifier& rIdent )
3173 SCSIZE nRet = 0;
3175 uno::Reference<container::XNameAccess> xMembers;
3176 if (lcl_GetMembers(pParent, rIdent, xMembers))
3178 uno::Reference<container::XIndexAccess> xMembersIndex(new ScNameToIndexAccess( xMembers ));
3179 nRet = static_cast<SCSIZE>(xMembersIndex->getCount());
3182 return nRet;
3185 // XDataPilotItemss
3187 ScDataPilotItemObj* ScDataPilotItemsObj::GetObjectByIndex_Impl(SCSIZE nIndex) const
3189 // TODO
3190 if (nIndex < lcl_GetItemCount(pParent, aSourceIdent))
3191 return new ScDataPilotItemObj( pParent, aSourceIdent, nIndex );
3193 return NULL;
3196 // XNameAccess
3198 uno::Any SAL_CALL ScDataPilotItemsObj::getByName( const rtl::OUString& aName )
3199 throw(container::NoSuchElementException,
3200 lang::WrappedTargetException, uno::RuntimeException)
3202 ScUnoGuard aGuard;
3205 uno::Reference<container::XNameAccess> xMembers;
3206 if (lcl_GetMembers(pParent, aSourceIdent, xMembers))
3208 uno::Reference<container::XIndexAccess> xMembersIndex(new ScNameToIndexAccess( xMembers ));
3209 sal_Int32 nCount = xMembersIndex->getCount();
3210 sal_Bool bFound(sal_False);
3211 sal_Int32 nItem = 0;
3212 while (nItem < nCount && !bFound )
3214 uno::Reference<container::XNamed> xMember(xMembersIndex->getByIndex(nItem), uno::UNO_QUERY);
3215 if (xMember.is() && aName == xMember->getName())
3216 return uno::makeAny(uno::Reference<beans::XPropertySet> (GetObjectByIndex_Impl(static_cast<SCSIZE>(nItem))));
3217 else
3218 nItem++;
3220 if (!bFound)
3221 throw container::NoSuchElementException();
3225 return uno::Any();
3228 uno::Sequence<rtl::OUString> SAL_CALL ScDataPilotItemsObj::getElementNames()
3229 throw(uno::RuntimeException)
3231 ScUnoGuard aGuard;
3232 // TODO
3234 uno::Sequence<rtl::OUString> aSeq;
3235 if( ScDPObject* pDPObj = pParent->GetDPObject() )
3237 sal_Int32 nObjIndex = lcl_GetObjectIndex( pDPObj, aSourceIdent );
3238 pDPObj->GetMembers( nObjIndex, aSeq );
3240 return aSeq;
3243 sal_Bool SAL_CALL ScDataPilotItemsObj::hasByName( const rtl::OUString& aName )
3244 throw(uno::RuntimeException)
3246 ScUnoGuard aGuard;
3248 sal_Bool bFound(sal_False);
3250 uno::Reference<container::XNameAccess> xMembers;
3251 if (lcl_GetMembers(pParent, aSourceIdent, xMembers))
3253 uno::Reference<container::XIndexAccess> xMembersIndex(new ScNameToIndexAccess( xMembers ));
3254 sal_Int32 nCount = xMembersIndex->getCount();
3255 sal_Int32 nItem = 0;
3256 while (nItem < nCount && !bFound )
3258 uno::Reference<container::XNamed> xMember(xMembersIndex->getByIndex(nItem), uno::UNO_QUERY);
3259 if (xMember.is() && aName == xMember->getName())
3260 bFound = sal_True;
3261 else
3262 nItem++;
3267 return bFound;
3270 // XEnumerationAccess
3272 uno::Reference<container::XEnumeration> SAL_CALL ScDataPilotItemsObj::createEnumeration()
3273 throw(uno::RuntimeException)
3275 ScUnoGuard aGuard;
3276 return new ScIndexEnumeration(this, rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.sheet.DataPilotItemsEnumeration")));
3279 // XIndexAccess
3281 sal_Int32 SAL_CALL ScDataPilotItemsObj::getCount() throw(uno::RuntimeException)
3283 ScUnoGuard aGuard;
3284 // TODO
3285 return static_cast<sal_Int32>(lcl_GetItemCount( pParent, aSourceIdent ));
3288 uno::Any SAL_CALL ScDataPilotItemsObj::getByIndex( sal_Int32 nIndex )
3289 throw(lang::IndexOutOfBoundsException,
3290 lang::WrappedTargetException, uno::RuntimeException)
3292 ScUnoGuard aGuard;
3293 uno::Reference<beans::XPropertySet> xItem(GetObjectByIndex_Impl(static_cast<SCSIZE>(nIndex)));
3294 if (xItem.is())
3295 return uno::makeAny(xItem);
3296 else
3297 throw lang::IndexOutOfBoundsException();
3300 uno::Type SAL_CALL ScDataPilotItemsObj::getElementType() throw(uno::RuntimeException)
3302 ScUnoGuard aGuard;
3303 return getCppuType((uno::Reference<beans::XPropertySet>*)0);
3306 sal_Bool SAL_CALL ScDataPilotItemsObj::hasElements() throw(uno::RuntimeException)
3308 ScUnoGuard aGuard;
3309 return ( getCount() != 0 );
3312 //------------------------------------------------------------------------
3314 ScDataPilotItemObj::ScDataPilotItemObj(ScDataPilotDescriptorBase* pPar, const ScFieldIdentifier& rIdent, SCSIZE nI)
3315 : aPropSet( lcl_GetDataPilotItemMap() ),
3316 pParent(pPar),
3317 aSourceIdent(rIdent),
3318 nIndex(nI)
3320 pParent->acquire();
3323 ScDataPilotItemObj::~ScDataPilotItemObj()
3325 pParent->release();
3328 // XNamed
3329 ::rtl::OUString SAL_CALL ScDataPilotItemObj::getName() throw(::com::sun::star::uno::RuntimeException)
3331 ScUnoGuard aGuard;
3332 rtl::OUString sRet;
3333 ScDPObject* pDPObj(pParent->GetDPObject());
3334 if (pDPObj)
3336 uno::Reference<container::XNameAccess> xMembers;
3337 if (lcl_GetMembers(pParent, aSourceIdent, xMembers))
3339 uno::Reference<container::XIndexAccess> xMembersIndex(new ScNameToIndexAccess( xMembers ));
3340 sal_Int32 nCount = xMembersIndex->getCount();
3341 if (nIndex < static_cast<SCSIZE>(nCount))
3343 uno::Reference<container::XNamed> xMember(xMembersIndex->getByIndex(static_cast<sal_Int32>(nIndex)), uno::UNO_QUERY);
3344 sRet = xMember->getName();
3348 return sRet;
3351 void SAL_CALL ScDataPilotItemObj::setName( const ::rtl::OUString& /* aName */ )
3352 throw(::com::sun::star::uno::RuntimeException)
3356 // XPropertySet
3357 ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo >
3358 SAL_CALL ScDataPilotItemObj::getPropertySetInfo( )
3359 throw(::com::sun::star::uno::RuntimeException)
3361 ScUnoGuard aGuard;
3362 static uno::Reference<beans::XPropertySetInfo> aRef =
3363 new SfxItemPropertySetInfo( aPropSet.getPropertyMap() );
3364 return aRef;
3367 void SAL_CALL ScDataPilotItemObj::setPropertyValue( const ::rtl::OUString& aPropertyName,
3368 const ::com::sun::star::uno::Any& aValue )
3369 throw(::com::sun::star::beans::UnknownPropertyException,
3370 ::com::sun::star::beans::PropertyVetoException,
3371 ::com::sun::star::lang::IllegalArgumentException,
3372 ::com::sun::star::lang::WrappedTargetException,
3373 ::com::sun::star::uno::RuntimeException)
3375 ScUnoGuard aGuard;
3376 String aNameString = aPropertyName;
3378 ScDPObject* pDPObj(pParent->GetDPObject());
3379 if (pDPObj)
3381 uno::Reference<container::XNameAccess> xMembers;
3382 ScDPSaveDimension* pDim = NULL;
3383 if (lcl_GetMembers(pParent, aSourceIdent, xMembers) && lcl_GetDim(pDPObj, aSourceIdent, pDim))
3385 uno::Reference<container::XIndexAccess> xMembersIndex(new ScNameToIndexAccess( xMembers ));
3386 sal_Int32 nCount = xMembersIndex->getCount();
3387 if (nIndex < static_cast<SCSIZE>(nCount) )
3389 uno::Reference<container::XNamed> xMember(xMembersIndex->getByIndex(static_cast<sal_Int32>(nIndex)), uno::UNO_QUERY);
3390 String sName(xMember->getName());
3391 ScDPSaveMember* pMember = pDim->GetMemberByName(sName);
3392 if (pMember)
3394 bool bGetNewIndex = false;
3395 if ( aNameString.EqualsAscii( SC_UNONAME_SHOWDETAIL ) )
3396 pMember->SetShowDetails(cppu::any2bool(aValue));
3397 else if ( aNameString.EqualsAscii( SC_UNONAME_ISHIDDEN ) )
3398 pMember->SetIsVisible(!cppu::any2bool(aValue));
3399 else if ( aNameString.EqualsAscii( SC_UNONAME_POS ) )
3401 sal_Int32 nNewPos = 0;
3402 if ( ( aValue >>= nNewPos ) && nNewPos >= 0 && nNewPos < nCount )
3404 pDim->SetMemberPosition( sName, nNewPos );
3405 // get new effective index (depends on sorting mode, which isn't modified)
3406 bGetNewIndex = true;
3408 else
3409 throw lang::IllegalArgumentException();
3411 pParent->SetDPObject(pDPObj);
3413 if ( bGetNewIndex ) // after SetDPObject, get the new index
3415 rtl::OUString aOUName( sName );
3416 uno::Sequence<rtl::OUString> aItemNames = xMembers->getElementNames();
3417 sal_Int32 nItemCount = aItemNames.getLength();
3418 for (sal_Int32 nItem=0; nItem<nItemCount; ++nItem)
3419 if (aItemNames[nItem] == aOUName)
3420 nIndex = nItem;
3428 ::com::sun::star::uno::Any SAL_CALL ScDataPilotItemObj::getPropertyValue(
3429 const ::rtl::OUString& aPropertyName )
3430 throw(::com::sun::star::beans::UnknownPropertyException,
3431 ::com::sun::star::lang::WrappedTargetException,
3432 ::com::sun::star::uno::RuntimeException)
3434 ScUnoGuard aGuard;
3435 uno::Any aRet;
3436 String aNameString = aPropertyName;
3438 ScDPObject* pDPObj(pParent->GetDPObject());
3439 if (pDPObj)
3441 uno::Reference<container::XNameAccess> xMembers;
3442 ScDPSaveDimension* pDim = NULL;
3443 if (lcl_GetMembers(pParent, aSourceIdent, xMembers) && lcl_GetDim(pDPObj, aSourceIdent, pDim))
3445 uno::Reference<container::XIndexAccess> xMembersIndex(new ScNameToIndexAccess( xMembers ));
3446 sal_Int32 nCount = xMembersIndex->getCount();
3447 if (nIndex < static_cast<SCSIZE>(nCount) )
3449 uno::Reference<container::XNamed> xMember(xMembersIndex->getByIndex(static_cast<sal_Int32>(nIndex)), uno::UNO_QUERY);
3450 String sName(xMember->getName());
3451 ScDPSaveMember* pMember = pDim->GetExistingMemberByName(sName);
3452 if ( aNameString.EqualsAscii( SC_UNONAME_SHOWDETAIL ) )
3454 if (pMember && pMember->HasShowDetails())
3456 aRet = cppu::bool2any(pMember->GetShowDetails());
3458 else
3460 uno::Reference<beans::XPropertySet> xMemberProps(xMember, uno::UNO_QUERY);
3461 if(xMemberProps.is())
3463 aRet = xMemberProps->getPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNO_SHOWDETA)));
3465 else
3466 aRet = cppu::bool2any(sal_True);
3469 else if ( aNameString.EqualsAscii( SC_UNONAME_ISHIDDEN ) )
3471 if (pMember && pMember->HasIsVisible())
3473 aRet = cppu::bool2any(!pMember->GetIsVisible());
3475 else
3477 uno::Reference<beans::XPropertySet> xMemberProps(xMember, uno::UNO_QUERY);
3478 if(xMemberProps.is())
3480 aRet = cppu::bool2any(!cppu::any2bool(xMemberProps->getPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNO_ISVISIBL)))));
3482 else
3483 aRet = cppu::bool2any(sal_False);
3486 else if ( aNameString.EqualsAscii( SC_UNONAME_POS ) )
3488 aRet <<= static_cast<sal_Int32>( nIndex );
3493 return aRet;
3496 void SAL_CALL ScDataPilotItemObj::addPropertyChangeListener( const ::rtl::OUString& /* aPropertyName */,
3497 const ::com::sun::star::uno::Reference<
3498 ::com::sun::star::beans::XPropertyChangeListener >& /* xListener */ )
3499 throw(::com::sun::star::beans::UnknownPropertyException,
3500 ::com::sun::star::lang::WrappedTargetException,
3501 ::com::sun::star::uno::RuntimeException)
3505 void SAL_CALL ScDataPilotItemObj::removePropertyChangeListener( const ::rtl::OUString& /* aPropertyName */,
3506 const ::com::sun::star::uno::Reference<
3507 ::com::sun::star::beans::XPropertyChangeListener >& /* aListener */ )
3508 throw(::com::sun::star::beans::UnknownPropertyException,
3509 ::com::sun::star::lang::WrappedTargetException,
3510 ::com::sun::star::uno::RuntimeException)
3514 void SAL_CALL ScDataPilotItemObj::addVetoableChangeListener( const ::rtl::OUString& /* PropertyName */,
3515 const ::com::sun::star::uno::Reference<
3516 ::com::sun::star::beans::XVetoableChangeListener >& /* aListener */ )
3517 throw(::com::sun::star::beans::UnknownPropertyException,
3518 ::com::sun::star::lang::WrappedTargetException,
3519 ::com::sun::star::uno::RuntimeException)
3523 void SAL_CALL ScDataPilotItemObj::removeVetoableChangeListener( const ::rtl::OUString& /* PropertyName */,
3524 const ::com::sun::star::uno::Reference<
3525 ::com::sun::star::beans::XVetoableChangeListener >& /* aListener */ )
3526 throw(::com::sun::star::beans::UnknownPropertyException,
3527 ::com::sun::star::lang::WrappedTargetException,
3528 ::com::sun::star::uno::RuntimeException)
3532 //------------------------------------------------------------------------