xref: /AOO41X/main/sc/source/ui/unoobj/dapiuno.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_sc.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include <algorithm>
32*cdf0e10cSrcweir #include <svl/smplhint.hxx>
33*cdf0e10cSrcweir #include <rtl/uuid.h>
34*cdf0e10cSrcweir 
35*cdf0e10cSrcweir #include "dapiuno.hxx"
36*cdf0e10cSrcweir #include "datauno.hxx"
37*cdf0e10cSrcweir #include "miscuno.hxx"
38*cdf0e10cSrcweir #include "convuno.hxx"
39*cdf0e10cSrcweir #include "docsh.hxx"
40*cdf0e10cSrcweir #include "tabvwsh.hxx"
41*cdf0e10cSrcweir #include "pivot.hxx"
42*cdf0e10cSrcweir #include "rangeutl.hxx"
43*cdf0e10cSrcweir #include "unoguard.hxx"
44*cdf0e10cSrcweir #include "dpobject.hxx"
45*cdf0e10cSrcweir #include "dpshttab.hxx"
46*cdf0e10cSrcweir #include "dpsdbtab.hxx"
47*cdf0e10cSrcweir #include "dpsave.hxx"
48*cdf0e10cSrcweir #include "dbdocfun.hxx"
49*cdf0e10cSrcweir #include "unonames.hxx"
50*cdf0e10cSrcweir #include "dpgroup.hxx"
51*cdf0e10cSrcweir #include "dpdimsave.hxx"
52*cdf0e10cSrcweir #include "hints.hxx"
53*cdf0e10cSrcweir 
54*cdf0e10cSrcweir #include <com/sun/star/sheet/XHierarchiesSupplier.hpp>
55*cdf0e10cSrcweir #include <com/sun/star/sheet/XLevelsSupplier.hpp>
56*cdf0e10cSrcweir #include <com/sun/star/sheet/XMembersSupplier.hpp>
57*cdf0e10cSrcweir #include <com/sun/star/beans/PropertyAttribute.hpp>
58*cdf0e10cSrcweir #include <com/sun/star/sheet/DataImportMode.hpp>
59*cdf0e10cSrcweir #include <com/sun/star/sheet/DataPilotFieldGroupBy.hpp>
60*cdf0e10cSrcweir #include <com/sun/star/sheet/DataPilotFieldFilter.hpp>
61*cdf0e10cSrcweir #include <com/sun/star/sheet/DataPilotOutputRangeType.hpp>
62*cdf0e10cSrcweir #include <com/sun/star/sheet/DataPilotTablePositionData.hpp>
63*cdf0e10cSrcweir 
64*cdf0e10cSrcweir #include <comphelper/extract.hxx>
65*cdf0e10cSrcweir #include <comphelper/sequence.hxx>
66*cdf0e10cSrcweir 
67*cdf0e10cSrcweir using namespace com::sun::star;
68*cdf0e10cSrcweir using namespace com::sun::star::sheet;
69*cdf0e10cSrcweir 
70*cdf0e10cSrcweir using ::rtl::OUString;
71*cdf0e10cSrcweir 
72*cdf0e10cSrcweir using ::com::sun::star::uno::Any;
73*cdf0e10cSrcweir using ::com::sun::star::uno::Exception;
74*cdf0e10cSrcweir using ::com::sun::star::uno::Reference;
75*cdf0e10cSrcweir using ::com::sun::star::uno::RuntimeException;
76*cdf0e10cSrcweir using ::com::sun::star::uno::Sequence;
77*cdf0e10cSrcweir using ::com::sun::star::uno::UNO_QUERY;
78*cdf0e10cSrcweir using ::com::sun::star::uno::UNO_QUERY_THROW;
79*cdf0e10cSrcweir 
80*cdf0e10cSrcweir using ::com::sun::star::container::ElementExistException;
81*cdf0e10cSrcweir using ::com::sun::star::container::NoSuchElementException;
82*cdf0e10cSrcweir using ::com::sun::star::container::XEnumeration;
83*cdf0e10cSrcweir using ::com::sun::star::container::XIndexAccess;
84*cdf0e10cSrcweir using ::com::sun::star::container::XNameAccess;
85*cdf0e10cSrcweir using ::com::sun::star::container::XNamed;
86*cdf0e10cSrcweir 
87*cdf0e10cSrcweir using ::com::sun::star::beans::PropertyVetoException;
88*cdf0e10cSrcweir using ::com::sun::star::beans::UnknownPropertyException;
89*cdf0e10cSrcweir using ::com::sun::star::beans::XPropertyChangeListener;
90*cdf0e10cSrcweir using ::com::sun::star::beans::XPropertySet;
91*cdf0e10cSrcweir using ::com::sun::star::beans::XPropertySetInfo;
92*cdf0e10cSrcweir using ::com::sun::star::beans::XVetoableChangeListener;
93*cdf0e10cSrcweir 
94*cdf0e10cSrcweir using ::com::sun::star::lang::IllegalArgumentException;
95*cdf0e10cSrcweir using ::com::sun::star::lang::IndexOutOfBoundsException;
96*cdf0e10cSrcweir using ::com::sun::star::lang::WrappedTargetException;
97*cdf0e10cSrcweir 
98*cdf0e10cSrcweir using ::com::sun::star::table::CellAddress;
99*cdf0e10cSrcweir using ::com::sun::star::table::CellRangeAddress;
100*cdf0e10cSrcweir 
101*cdf0e10cSrcweir // ============================================================================
102*cdf0e10cSrcweir 
103*cdf0e10cSrcweir namespace {
104*cdf0e10cSrcweir 
105*cdf0e10cSrcweir const SfxItemPropertyMapEntry* lcl_GetDataPilotDescriptorBaseMap()
106*cdf0e10cSrcweir {
107*cdf0e10cSrcweir     static SfxItemPropertyMapEntry aDataPilotDescriptorBaseMap_Impl[] =
108*cdf0e10cSrcweir 	{
109*cdf0e10cSrcweir         {MAP_CHAR_LEN(SC_UNO_COLGRAND),     0,  &getBooleanCppuType(),  0, 0 },
110*cdf0e10cSrcweir         {MAP_CHAR_LEN(SC_UNO_DRILLDOWN),    0,  &getBooleanCppuType(),  0, 0 },
111*cdf0e10cSrcweir         {MAP_CHAR_LEN(SC_UNO_GRANDTOTAL_NAME),0,&getCppuType((rtl::OUString*)0), beans::PropertyAttribute::MAYBEVOID, 0 },
112*cdf0e10cSrcweir         {MAP_CHAR_LEN(SC_UNO_IGNEMPROWS),   0,  &getBooleanCppuType(),  0, 0 },
113*cdf0e10cSrcweir         {MAP_CHAR_LEN(SC_UNO_IMPORTDESC),   0,  &getCppuType((uno::Sequence<beans::PropertyValue>*)0), 0, 0 },
114*cdf0e10cSrcweir         {MAP_CHAR_LEN(SC_UNO_RPTEMPTY),     0,  &getBooleanCppuType(),  0, 0 },
115*cdf0e10cSrcweir         {MAP_CHAR_LEN(SC_UNO_ROWGRAND),     0,  &getBooleanCppuType(),  0, 0 },
116*cdf0e10cSrcweir         {MAP_CHAR_LEN(SC_UNO_SERVICEARG),   0,  &getCppuType((uno::Sequence<beans::PropertyValue>*)0), 0, 0 },
117*cdf0e10cSrcweir         {MAP_CHAR_LEN(SC_UNO_SHOWFILT),     0,  &getBooleanCppuType(),  0, 0 },
118*cdf0e10cSrcweir         {MAP_CHAR_LEN(SC_UNO_SOURCESERV),   0,  &getCppuType((rtl::OUString*)0), 0, 0 },
119*cdf0e10cSrcweir         {0,0,0,0,0,0}
120*cdf0e10cSrcweir 	};
121*cdf0e10cSrcweir 	return aDataPilotDescriptorBaseMap_Impl;
122*cdf0e10cSrcweir }
123*cdf0e10cSrcweir 
124*cdf0e10cSrcweir // ----------------------------------------------------------------------------
125*cdf0e10cSrcweir 
126*cdf0e10cSrcweir const SfxItemPropertyMapEntry* lcl_GetDataPilotFieldMap()
127*cdf0e10cSrcweir {
128*cdf0e10cSrcweir     using namespace ::com::sun::star::beans::PropertyAttribute;
129*cdf0e10cSrcweir     static SfxItemPropertyMapEntry aDataPilotFieldMap_Impl[] =
130*cdf0e10cSrcweir 	{
131*cdf0e10cSrcweir         {MAP_CHAR_LEN(SC_UNONAME_AUTOSHOW),     0,  &getCppuType((DataPilotFieldAutoShowInfo*)0),   MAYBEVOID, 0 },
132*cdf0e10cSrcweir         {MAP_CHAR_LEN(SC_UNONAME_FUNCTION),     0,  &getCppuType((GeneralFunction*)0),              0, 0 },
133*cdf0e10cSrcweir         {MAP_CHAR_LEN(SC_UNONAME_GROUPINFO),    0,  &getCppuType((DataPilotFieldGroupInfo*)0),      MAYBEVOID, 0 },
134*cdf0e10cSrcweir         {MAP_CHAR_LEN(SC_UNONAME_HASAUTOSHOW),  0,  &getBooleanCppuType(),                          0, 0 },
135*cdf0e10cSrcweir         {MAP_CHAR_LEN(SC_UNONAME_HASLAYOUTINFO),0,  &getBooleanCppuType(),                          0, 0 },
136*cdf0e10cSrcweir         {MAP_CHAR_LEN(SC_UNONAME_HASREFERENCE), 0,  &getBooleanCppuType(),                          0, 0 },
137*cdf0e10cSrcweir         {MAP_CHAR_LEN(SC_UNONAME_HASSORTINFO),  0,  &getBooleanCppuType(),                          0, 0 },
138*cdf0e10cSrcweir         {MAP_CHAR_LEN(SC_UNONAME_ISGROUP),      0,  &getBooleanCppuType(),                          0, 0 },
139*cdf0e10cSrcweir         {MAP_CHAR_LEN(SC_UNONAME_LAYOUTINFO),   0,  &getCppuType((DataPilotFieldLayoutInfo*)0),     MAYBEVOID, 0 },
140*cdf0e10cSrcweir         {MAP_CHAR_LEN(SC_UNONAME_ORIENT),       0,  &getCppuType((DataPilotFieldOrientation*)0),    MAYBEVOID, 0 },
141*cdf0e10cSrcweir         {MAP_CHAR_LEN(SC_UNONAME_REFERENCE),    0,  &getCppuType((DataPilotFieldReference*)0),      MAYBEVOID, 0 },
142*cdf0e10cSrcweir         {MAP_CHAR_LEN(SC_UNONAME_SELPAGE),      0,  &getCppuType((OUString*)0),                     0, 0 },
143*cdf0e10cSrcweir         {MAP_CHAR_LEN(SC_UNONAME_SHOWEMPTY),    0,  &getBooleanCppuType(),                          0, 0 },
144*cdf0e10cSrcweir         {MAP_CHAR_LEN(SC_UNONAME_SORTINFO),     0,  &getCppuType((DataPilotFieldSortInfo*)0),       MAYBEVOID, 0 },
145*cdf0e10cSrcweir         {MAP_CHAR_LEN(SC_UNONAME_SUBTOTALS),    0,  &getCppuType((Sequence<GeneralFunction>*)0),    0, 0 },
146*cdf0e10cSrcweir         {MAP_CHAR_LEN(SC_UNONAME_USESELPAGE),   0,  &getBooleanCppuType(),                          0, 0 },
147*cdf0e10cSrcweir         {0,0,0,0,0,0}
148*cdf0e10cSrcweir 	};
149*cdf0e10cSrcweir 	return aDataPilotFieldMap_Impl;
150*cdf0e10cSrcweir }
151*cdf0e10cSrcweir 
152*cdf0e10cSrcweir // ----------------------------------------------------------------------------
153*cdf0e10cSrcweir 
154*cdf0e10cSrcweir const SfxItemPropertyMapEntry* lcl_GetDataPilotItemMap()
155*cdf0e10cSrcweir {
156*cdf0e10cSrcweir     static SfxItemPropertyMapEntry aDataPilotItemMap_Impl[] =
157*cdf0e10cSrcweir 	{
158*cdf0e10cSrcweir         {MAP_CHAR_LEN(SC_UNONAME_ISHIDDEN),     0,  &getBooleanCppuType(),          0, 0 },
159*cdf0e10cSrcweir         {MAP_CHAR_LEN(SC_UNONAME_POS),          0,  &getCppuType((sal_Int32*)0),    0, 0 },
160*cdf0e10cSrcweir         {MAP_CHAR_LEN(SC_UNONAME_SHOWDETAIL),   0,  &getBooleanCppuType(),          0, 0 },
161*cdf0e10cSrcweir         {0,0,0,0,0,0}
162*cdf0e10cSrcweir 	};
163*cdf0e10cSrcweir 	return aDataPilotItemMap_Impl;
164*cdf0e10cSrcweir }
165*cdf0e10cSrcweir 
166*cdf0e10cSrcweir // ----------------------------------------------------------------------------
167*cdf0e10cSrcweir 
168*cdf0e10cSrcweir inline bool lclCheckValidDouble( double fValue, sal_Bool bAuto )
169*cdf0e10cSrcweir {
170*cdf0e10cSrcweir     return bAuto || ::rtl::math::isFinite( fValue );
171*cdf0e10cSrcweir }
172*cdf0e10cSrcweir 
173*cdf0e10cSrcweir bool lclCheckMinMaxStep( const DataPilotFieldGroupInfo& rInfo )
174*cdf0e10cSrcweir {
175*cdf0e10cSrcweir     return
176*cdf0e10cSrcweir         lclCheckValidDouble( rInfo.Start, rInfo.HasAutoStart ) &&
177*cdf0e10cSrcweir         lclCheckValidDouble( rInfo.End, rInfo.HasAutoEnd ) &&
178*cdf0e10cSrcweir         (rInfo.HasAutoStart || rInfo.HasAutoEnd || (rInfo.Start <= rInfo.End)) &&
179*cdf0e10cSrcweir         lclCheckValidDouble( rInfo.Step, sal_False ) &&
180*cdf0e10cSrcweir         (0.0 <= rInfo.Step);
181*cdf0e10cSrcweir }
182*cdf0e10cSrcweir 
183*cdf0e10cSrcweir } // namespace
184*cdf0e10cSrcweir 
185*cdf0e10cSrcweir // ============================================================================
186*cdf0e10cSrcweir 
187*cdf0e10cSrcweir SC_SIMPLE_SERVICE_INFO( ScDataPilotDescriptor, "ScDataPilotDescriptor", "stardiv::one::sheet::DataPilotDescriptor" )
188*cdf0e10cSrcweir SC_SIMPLE_SERVICE_INFO( ScDataPilotFieldObj, "ScDataPilotFieldObj", "com.sun.star.sheet.DataPilotField" )
189*cdf0e10cSrcweir SC_SIMPLE_SERVICE_INFO( ScDataPilotFieldsObj, "ScDataPilotFieldsObj", "com.sun.star.sheet.DataPilotFields" )
190*cdf0e10cSrcweir SC_SIMPLE_SERVICE_INFO( ScDataPilotTableObj, "ScDataPilotTableObj", "com.sun.star.sheet.DataPilotTable" )
191*cdf0e10cSrcweir SC_SIMPLE_SERVICE_INFO( ScDataPilotTablesObj, "ScDataPilotTablesObj", "com.sun.star.sheet.DataPilotTables" )
192*cdf0e10cSrcweir SC_SIMPLE_SERVICE_INFO( ScDataPilotItemsObj, "ScDataPilotItemsObj", "com.sun.star.sheet.DataPilotItems" )
193*cdf0e10cSrcweir SC_SIMPLE_SERVICE_INFO( ScDataPilotItemObj, "ScDataPilotItemObj", "com.sun.star.sheet.DataPilotItem" )
194*cdf0e10cSrcweir 
195*cdf0e10cSrcweir SC_SIMPLE_SERVICE_INFO( ScDataPilotFieldGroupsObj, "ScDataPilotFieldGroupsObj", "com.sun.star.sheet.DataPilotFieldGroups" )
196*cdf0e10cSrcweir SC_SIMPLE_SERVICE_INFO( ScDataPilotFieldGroupObj, "ScDataPilotFieldGroupObj", "com.sun.star.sheet.DataPilotFieldGroup" )
197*cdf0e10cSrcweir SC_SIMPLE_SERVICE_INFO( ScDataPilotFieldGroupItemObj, "ScDataPilotFieldGroupItemObj", "com.sun.star.sheet.DataPilotFieldGroupItem" )
198*cdf0e10cSrcweir 
199*cdf0e10cSrcweir //------------------------------------------------------------------------
200*cdf0e10cSrcweir 
201*cdf0e10cSrcweir // name that is used in the API for the data layout field
202*cdf0e10cSrcweir #define SC_DATALAYOUT_NAME  "Data"
203*cdf0e10cSrcweir 
204*cdf0e10cSrcweir //------------------------------------------------------------------------
205*cdf0e10cSrcweir 
206*cdf0e10cSrcweir GeneralFunction ScDataPilotConversion::FirstFunc( sal_uInt16 nBits )
207*cdf0e10cSrcweir {
208*cdf0e10cSrcweir     if ( nBits & PIVOT_FUNC_SUM )       return GeneralFunction_SUM;
209*cdf0e10cSrcweir     if ( nBits & PIVOT_FUNC_COUNT )     return GeneralFunction_COUNT;
210*cdf0e10cSrcweir     if ( nBits & PIVOT_FUNC_AVERAGE )   return GeneralFunction_AVERAGE;
211*cdf0e10cSrcweir     if ( nBits & PIVOT_FUNC_MAX )       return GeneralFunction_MAX;
212*cdf0e10cSrcweir     if ( nBits & PIVOT_FUNC_MIN )       return GeneralFunction_MIN;
213*cdf0e10cSrcweir     if ( nBits & PIVOT_FUNC_PRODUCT )   return GeneralFunction_PRODUCT;
214*cdf0e10cSrcweir     if ( nBits & PIVOT_FUNC_COUNT_NUM ) return GeneralFunction_COUNTNUMS;
215*cdf0e10cSrcweir     if ( nBits & PIVOT_FUNC_STD_DEV )   return GeneralFunction_STDEV;
216*cdf0e10cSrcweir     if ( nBits & PIVOT_FUNC_STD_DEVP )  return GeneralFunction_STDEVP;
217*cdf0e10cSrcweir     if ( nBits & PIVOT_FUNC_STD_VAR )   return GeneralFunction_VAR;
218*cdf0e10cSrcweir     if ( nBits & PIVOT_FUNC_STD_VARP )  return GeneralFunction_VARP;
219*cdf0e10cSrcweir     if ( nBits & PIVOT_FUNC_AUTO )      return GeneralFunction_AUTO;
220*cdf0e10cSrcweir     return GeneralFunction_NONE;
221*cdf0e10cSrcweir }
222*cdf0e10cSrcweir 
223*cdf0e10cSrcweir sal_uInt16 ScDataPilotConversion::FunctionBit( GeneralFunction eFunc )
224*cdf0e10cSrcweir {
225*cdf0e10cSrcweir 	sal_uInt16 nRet = PIVOT_FUNC_NONE;	// 0
226*cdf0e10cSrcweir 	switch (eFunc)
227*cdf0e10cSrcweir 	{
228*cdf0e10cSrcweir         case GeneralFunction_SUM:       nRet = PIVOT_FUNC_SUM;       break;
229*cdf0e10cSrcweir         case GeneralFunction_COUNT:     nRet = PIVOT_FUNC_COUNT;     break;
230*cdf0e10cSrcweir         case GeneralFunction_AVERAGE:   nRet = PIVOT_FUNC_AVERAGE;   break;
231*cdf0e10cSrcweir         case GeneralFunction_MAX:       nRet = PIVOT_FUNC_MAX;       break;
232*cdf0e10cSrcweir         case GeneralFunction_MIN:       nRet = PIVOT_FUNC_MIN;       break;
233*cdf0e10cSrcweir         case GeneralFunction_PRODUCT:   nRet = PIVOT_FUNC_PRODUCT;   break;
234*cdf0e10cSrcweir         case GeneralFunction_COUNTNUMS: nRet = PIVOT_FUNC_COUNT_NUM; break;
235*cdf0e10cSrcweir         case GeneralFunction_STDEV:     nRet = PIVOT_FUNC_STD_DEV;   break;
236*cdf0e10cSrcweir         case GeneralFunction_STDEVP:    nRet = PIVOT_FUNC_STD_DEVP;  break;
237*cdf0e10cSrcweir         case GeneralFunction_VAR:       nRet = PIVOT_FUNC_STD_VAR;   break;
238*cdf0e10cSrcweir         case GeneralFunction_VARP:      nRet = PIVOT_FUNC_STD_VARP;  break;
239*cdf0e10cSrcweir         case GeneralFunction_AUTO:      nRet = PIVOT_FUNC_AUTO;      break;
240*cdf0e10cSrcweir         default:
241*cdf0e10cSrcweir         {
242*cdf0e10cSrcweir             // added to avoid warnings
243*cdf0e10cSrcweir         }
244*cdf0e10cSrcweir 	}
245*cdf0e10cSrcweir 	return nRet;
246*cdf0e10cSrcweir }
247*cdf0e10cSrcweir 
248*cdf0e10cSrcweir void ScDataPilotConversion::FillGroupInfo( DataPilotFieldGroupInfo& rInfo, const ScDPNumGroupInfo& rGroupInfo )
249*cdf0e10cSrcweir {
250*cdf0e10cSrcweir     rInfo.HasDateValues = rGroupInfo.DateValues;
251*cdf0e10cSrcweir     rInfo.HasAutoStart  = rGroupInfo.AutoStart;
252*cdf0e10cSrcweir     rInfo.Start         = rGroupInfo.Start;
253*cdf0e10cSrcweir     rInfo.HasAutoEnd    = rGroupInfo.AutoEnd;
254*cdf0e10cSrcweir     rInfo.End           = rGroupInfo.End;
255*cdf0e10cSrcweir     rInfo.Step          = rGroupInfo.Step;
256*cdf0e10cSrcweir }
257*cdf0e10cSrcweir 
258*cdf0e10cSrcweir //------------------------------------------------------------------------
259*cdf0e10cSrcweir 
260*cdf0e10cSrcweir ScDPObject* lcl_GetDPObject( ScDocShell* pDocShell, SCTAB nTab, const String& rName )
261*cdf0e10cSrcweir {
262*cdf0e10cSrcweir 	if (pDocShell)
263*cdf0e10cSrcweir 	{
264*cdf0e10cSrcweir 		ScDocument* pDoc = pDocShell->GetDocument();
265*cdf0e10cSrcweir 		ScDPCollection* pColl = pDoc->GetDPCollection();
266*cdf0e10cSrcweir 		if ( pColl )
267*cdf0e10cSrcweir 		{
268*cdf0e10cSrcweir 			sal_uInt16 nCount = pColl->GetCount();
269*cdf0e10cSrcweir 			for (sal_uInt16 i=0; i<nCount; i++)
270*cdf0e10cSrcweir 			{
271*cdf0e10cSrcweir 				ScDPObject* pDPObj = (*pColl)[i];
272*cdf0e10cSrcweir                 if ( pDPObj->GetOutRange().aStart.Tab() == nTab &&
273*cdf0e10cSrcweir 					 pDPObj->GetName() == rName )
274*cdf0e10cSrcweir 					return pDPObj;
275*cdf0e10cSrcweir 			}
276*cdf0e10cSrcweir 		}
277*cdf0e10cSrcweir 	}
278*cdf0e10cSrcweir 	return NULL;	// nicht gefunden
279*cdf0e10cSrcweir }
280*cdf0e10cSrcweir 
281*cdf0e10cSrcweir String lcl_CreatePivotName( ScDocShell* pDocShell )
282*cdf0e10cSrcweir {
283*cdf0e10cSrcweir 	if (pDocShell)
284*cdf0e10cSrcweir 	{
285*cdf0e10cSrcweir 		ScDocument* pDoc = pDocShell->GetDocument();
286*cdf0e10cSrcweir 		ScDPCollection* pColl = pDoc->GetDPCollection();
287*cdf0e10cSrcweir 		if ( pColl )
288*cdf0e10cSrcweir 			return pColl->CreateNewName();
289*cdf0e10cSrcweir 	}
290*cdf0e10cSrcweir 	return String();					// sollte nicht vorkommen
291*cdf0e10cSrcweir }
292*cdf0e10cSrcweir 
293*cdf0e10cSrcweir sal_Int32 lcl_GetObjectIndex( ScDPObject* pDPObj, const ScFieldIdentifier& rFieldId )
294*cdf0e10cSrcweir {
295*cdf0e10cSrcweir     // used for items - nRepeat in identifier can be ignored
296*cdf0e10cSrcweir     if ( pDPObj )
297*cdf0e10cSrcweir     {
298*cdf0e10cSrcweir         sal_Int32 nCount = pDPObj->GetDimCount();
299*cdf0e10cSrcweir         for ( sal_Int32 nDim = 0; nDim < nCount; ++nDim )
300*cdf0e10cSrcweir         {
301*cdf0e10cSrcweir             sal_Bool bIsDataLayout = sal_False;
302*cdf0e10cSrcweir             OUString aDimName( pDPObj->GetDimName( nDim, bIsDataLayout ) );
303*cdf0e10cSrcweir             if ( rFieldId.mbDataLayout ? bIsDataLayout : (aDimName == rFieldId.maFieldName) )
304*cdf0e10cSrcweir                 return nDim;
305*cdf0e10cSrcweir         }
306*cdf0e10cSrcweir     }
307*cdf0e10cSrcweir     return -1;  // none
308*cdf0e10cSrcweir }
309*cdf0e10cSrcweir 
310*cdf0e10cSrcweir //------------------------------------------------------------------------
311*cdf0e10cSrcweir 
312*cdf0e10cSrcweir ScDataPilotTablesObj::ScDataPilotTablesObj(ScDocShell* pDocSh, SCTAB nT) :
313*cdf0e10cSrcweir 	pDocShell( pDocSh ),
314*cdf0e10cSrcweir 	nTab( nT )
315*cdf0e10cSrcweir {
316*cdf0e10cSrcweir 	pDocShell->GetDocument()->AddUnoObject(*this);
317*cdf0e10cSrcweir }
318*cdf0e10cSrcweir 
319*cdf0e10cSrcweir ScDataPilotTablesObj::~ScDataPilotTablesObj()
320*cdf0e10cSrcweir {
321*cdf0e10cSrcweir 	if (pDocShell)
322*cdf0e10cSrcweir 		pDocShell->GetDocument()->RemoveUnoObject(*this);
323*cdf0e10cSrcweir }
324*cdf0e10cSrcweir 
325*cdf0e10cSrcweir void ScDataPilotTablesObj::Notify( SfxBroadcaster&, const SfxHint& rHint )
326*cdf0e10cSrcweir {
327*cdf0e10cSrcweir 	//!	Referenz-Update
328*cdf0e10cSrcweir 
329*cdf0e10cSrcweir 	if ( rHint.ISA( SfxSimpleHint ) &&
330*cdf0e10cSrcweir 			((const SfxSimpleHint&)rHint).GetId() == SFX_HINT_DYING )
331*cdf0e10cSrcweir 	{
332*cdf0e10cSrcweir 		pDocShell = NULL;		// ungueltig geworden
333*cdf0e10cSrcweir 	}
334*cdf0e10cSrcweir }
335*cdf0e10cSrcweir 
336*cdf0e10cSrcweir // XDataPilotTables
337*cdf0e10cSrcweir 
338*cdf0e10cSrcweir ScDataPilotTableObj* ScDataPilotTablesObj::GetObjectByIndex_Impl( sal_Int32 nIndex )
339*cdf0e10cSrcweir {
340*cdf0e10cSrcweir 	if (pDocShell)
341*cdf0e10cSrcweir 	{
342*cdf0e10cSrcweir 		ScDocument* pDoc = pDocShell->GetDocument();
343*cdf0e10cSrcweir 		ScDPCollection* pColl = pDoc->GetDPCollection();
344*cdf0e10cSrcweir 		if ( pColl )
345*cdf0e10cSrcweir 		{
346*cdf0e10cSrcweir 			//	count tables on this sheet
347*cdf0e10cSrcweir             sal_Int32 nFound = 0;
348*cdf0e10cSrcweir 			sal_uInt16 nCount = pColl->GetCount();
349*cdf0e10cSrcweir 			for (sal_uInt16 i=0; i<nCount; i++)
350*cdf0e10cSrcweir 			{
351*cdf0e10cSrcweir 				ScDPObject* pDPObj = (*pColl)[i];
352*cdf0e10cSrcweir                 if ( pDPObj->GetOutRange().aStart.Tab() == nTab )
353*cdf0e10cSrcweir 				{
354*cdf0e10cSrcweir 					if ( nFound == nIndex )
355*cdf0e10cSrcweir 					{
356*cdf0e10cSrcweir 						String aName = pDPObj->GetName();
357*cdf0e10cSrcweir 						return new ScDataPilotTableObj( pDocShell, nTab, aName );
358*cdf0e10cSrcweir 					}
359*cdf0e10cSrcweir 					++nFound;
360*cdf0e10cSrcweir 				}
361*cdf0e10cSrcweir 			}
362*cdf0e10cSrcweir 		}
363*cdf0e10cSrcweir 	}
364*cdf0e10cSrcweir 	return NULL;
365*cdf0e10cSrcweir }
366*cdf0e10cSrcweir 
367*cdf0e10cSrcweir ScDataPilotTableObj* ScDataPilotTablesObj::GetObjectByName_Impl(const OUString& rName)
368*cdf0e10cSrcweir {
369*cdf0e10cSrcweir     if (hasByName(rName))
370*cdf0e10cSrcweir         return new ScDataPilotTableObj( pDocShell, nTab, rName );
371*cdf0e10cSrcweir     return 0;
372*cdf0e10cSrcweir }
373*cdf0e10cSrcweir 
374*cdf0e10cSrcweir Reference<XDataPilotDescriptor> SAL_CALL ScDataPilotTablesObj::createDataPilotDescriptor()
375*cdf0e10cSrcweir                                             throw(RuntimeException)
376*cdf0e10cSrcweir {
377*cdf0e10cSrcweir 	ScUnoGuard aGuard;
378*cdf0e10cSrcweir 	if (pDocShell)
379*cdf0e10cSrcweir 		return new ScDataPilotDescriptor(pDocShell);
380*cdf0e10cSrcweir 	return NULL;
381*cdf0e10cSrcweir }
382*cdf0e10cSrcweir 
383*cdf0e10cSrcweir bool lcl_IsDuplicated( const Reference<XPropertySet> xDimProps )
384*cdf0e10cSrcweir {
385*cdf0e10cSrcweir     try
386*cdf0e10cSrcweir     {
387*cdf0e10cSrcweir         Any aAny = xDimProps->getPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( SC_UNO_ORIGINAL ) ) );
388*cdf0e10cSrcweir         Reference< XNamed > xOriginal( aAny, UNO_QUERY );
389*cdf0e10cSrcweir         return xOriginal.is();
390*cdf0e10cSrcweir     }
391*cdf0e10cSrcweir     catch( Exception& )
392*cdf0e10cSrcweir     {
393*cdf0e10cSrcweir     }
394*cdf0e10cSrcweir     return false;
395*cdf0e10cSrcweir }
396*cdf0e10cSrcweir 
397*cdf0e10cSrcweir OUString lcl_GetOriginalName( const Reference< XNamed > xDim )
398*cdf0e10cSrcweir {
399*cdf0e10cSrcweir     Reference< XNamed > xOriginal;
400*cdf0e10cSrcweir 
401*cdf0e10cSrcweir     Reference< XPropertySet > xDimProps( xDim, UNO_QUERY );
402*cdf0e10cSrcweir     if ( xDimProps.is() )
403*cdf0e10cSrcweir     {
404*cdf0e10cSrcweir         try
405*cdf0e10cSrcweir         {
406*cdf0e10cSrcweir             Any aAny = xDimProps->getPropertyValue(OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNO_ORIGINAL)));
407*cdf0e10cSrcweir             aAny >>= xOriginal;
408*cdf0e10cSrcweir         }
409*cdf0e10cSrcweir         catch( Exception& )
410*cdf0e10cSrcweir         {
411*cdf0e10cSrcweir         }
412*cdf0e10cSrcweir     }
413*cdf0e10cSrcweir 
414*cdf0e10cSrcweir     if ( !xOriginal.is() )
415*cdf0e10cSrcweir         xOriginal = xDim;
416*cdf0e10cSrcweir 
417*cdf0e10cSrcweir     return xOriginal->getName();
418*cdf0e10cSrcweir }
419*cdf0e10cSrcweir 
420*cdf0e10cSrcweir void SAL_CALL ScDataPilotTablesObj::insertNewByName( const OUString& aNewName,
421*cdf0e10cSrcweir                                     const CellAddress& aOutputAddress,
422*cdf0e10cSrcweir                                     const Reference<XDataPilotDescriptor>& xDescriptor )
423*cdf0e10cSrcweir                                 throw(RuntimeException)
424*cdf0e10cSrcweir {
425*cdf0e10cSrcweir 	ScUnoGuard aGuard;
426*cdf0e10cSrcweir 	if (!xDescriptor.is()) return;
427*cdf0e10cSrcweir 
428*cdf0e10cSrcweir 	// inserting with already existing name?
429*cdf0e10cSrcweir 	if ( aNewName.getLength() && hasByName( aNewName ) )
430*cdf0e10cSrcweir         throw RuntimeException();       // no other exceptions specified
431*cdf0e10cSrcweir 
432*cdf0e10cSrcweir 	sal_Bool bDone = sal_False;
433*cdf0e10cSrcweir 	ScDataPilotDescriptorBase* pImp = ScDataPilotDescriptorBase::getImplementation( xDescriptor );
434*cdf0e10cSrcweir 	if ( pDocShell && pImp )
435*cdf0e10cSrcweir 	{
436*cdf0e10cSrcweir         ScDPObject* pNewObj = pImp->GetDPObject();
437*cdf0e10cSrcweir 
438*cdf0e10cSrcweir         if (pNewObj)
439*cdf0e10cSrcweir         {
440*cdf0e10cSrcweir             ScRange aOutputRange((SCCOL)aOutputAddress.Column, (SCROW)aOutputAddress.Row, (SCTAB)aOutputAddress.Sheet,
441*cdf0e10cSrcweir                                 (SCCOL)aOutputAddress.Column, (SCROW)aOutputAddress.Row, (SCTAB)aOutputAddress.Sheet);
442*cdf0e10cSrcweir             pNewObj->SetOutRange(aOutputRange);
443*cdf0e10cSrcweir 		    String aName = aNewName;
444*cdf0e10cSrcweir 		    if (!aName.Len())
445*cdf0e10cSrcweir 			    aName = lcl_CreatePivotName( pDocShell );
446*cdf0e10cSrcweir             pNewObj->SetName(aName);
447*cdf0e10cSrcweir 		    String aTag = xDescriptor->getTag();
448*cdf0e10cSrcweir             pNewObj->SetTag(aTag);
449*cdf0e10cSrcweir 
450*cdf0e10cSrcweir     // todo: handle double fields (for more information see ScDPObject
451*cdf0e10cSrcweir 
452*cdf0e10cSrcweir             ScDBDocFunc aFunc(*pDocShell);
453*cdf0e10cSrcweir 		    bDone = aFunc.DataPilotUpdate( NULL, pNewObj, sal_True, sal_True );
454*cdf0e10cSrcweir         }
455*cdf0e10cSrcweir 	}
456*cdf0e10cSrcweir 
457*cdf0e10cSrcweir 	if (!bDone)
458*cdf0e10cSrcweir         throw RuntimeException();       // no other exceptions specified
459*cdf0e10cSrcweir }
460*cdf0e10cSrcweir 
461*cdf0e10cSrcweir void SAL_CALL ScDataPilotTablesObj::removeByName( const OUString& aName )
462*cdf0e10cSrcweir                                         throw(RuntimeException)
463*cdf0e10cSrcweir {
464*cdf0e10cSrcweir 	ScUnoGuard aGuard;
465*cdf0e10cSrcweir 	String aNameStr(aName);
466*cdf0e10cSrcweir 	ScDPObject* pDPObj = lcl_GetDPObject( pDocShell, nTab, aNameStr );
467*cdf0e10cSrcweir 	if (pDPObj && pDocShell)
468*cdf0e10cSrcweir 	{
469*cdf0e10cSrcweir 		ScDBDocFunc aFunc(*pDocShell);
470*cdf0e10cSrcweir 		aFunc.DataPilotUpdate( pDPObj, NULL, sal_True, sal_True );	// remove - incl. undo etc.
471*cdf0e10cSrcweir 	}
472*cdf0e10cSrcweir 	else
473*cdf0e10cSrcweir         throw RuntimeException();       // no other exceptions specified
474*cdf0e10cSrcweir }
475*cdf0e10cSrcweir 
476*cdf0e10cSrcweir // XEnumerationAccess
477*cdf0e10cSrcweir 
478*cdf0e10cSrcweir Reference< XEnumeration > SAL_CALL ScDataPilotTablesObj::createEnumeration() throw(RuntimeException)
479*cdf0e10cSrcweir {
480*cdf0e10cSrcweir 	ScUnoGuard aGuard;
481*cdf0e10cSrcweir     return new ScIndexEnumeration(this, OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.sheet.DataPilotTablesEnumeration")));
482*cdf0e10cSrcweir }
483*cdf0e10cSrcweir 
484*cdf0e10cSrcweir // XIndexAccess
485*cdf0e10cSrcweir 
486*cdf0e10cSrcweir sal_Int32 SAL_CALL ScDataPilotTablesObj::getCount() throw(RuntimeException)
487*cdf0e10cSrcweir {
488*cdf0e10cSrcweir 	ScUnoGuard aGuard;
489*cdf0e10cSrcweir 	if ( pDocShell )
490*cdf0e10cSrcweir 	{
491*cdf0e10cSrcweir 		ScDocument* pDoc = pDocShell->GetDocument();
492*cdf0e10cSrcweir 		ScDPCollection* pColl = pDoc->GetDPCollection();
493*cdf0e10cSrcweir 		if ( pColl )
494*cdf0e10cSrcweir 		{
495*cdf0e10cSrcweir 			//	count tables on this sheet
496*cdf0e10cSrcweir 
497*cdf0e10cSrcweir 			sal_uInt16 nFound = 0;
498*cdf0e10cSrcweir 			sal_uInt16 nCount = pColl->GetCount();
499*cdf0e10cSrcweir 			for (sal_uInt16 i=0; i<nCount; i++)
500*cdf0e10cSrcweir 			{
501*cdf0e10cSrcweir 				ScDPObject* pDPObj = (*pColl)[i];
502*cdf0e10cSrcweir                 if ( pDPObj->GetOutRange().aStart.Tab() == nTab )
503*cdf0e10cSrcweir 					++nFound;
504*cdf0e10cSrcweir 			}
505*cdf0e10cSrcweir 			return nFound;
506*cdf0e10cSrcweir 		}
507*cdf0e10cSrcweir 	}
508*cdf0e10cSrcweir 
509*cdf0e10cSrcweir 	return 0;
510*cdf0e10cSrcweir }
511*cdf0e10cSrcweir 
512*cdf0e10cSrcweir Any SAL_CALL ScDataPilotTablesObj::getByIndex( sal_Int32 nIndex )
513*cdf0e10cSrcweir         throw(IndexOutOfBoundsException, WrappedTargetException, RuntimeException)
514*cdf0e10cSrcweir {
515*cdf0e10cSrcweir 	ScUnoGuard aGuard;
516*cdf0e10cSrcweir     Reference<XDataPilotTable2> xTable(GetObjectByIndex_Impl(nIndex));
517*cdf0e10cSrcweir     if (!xTable.is())
518*cdf0e10cSrcweir         throw IndexOutOfBoundsException();
519*cdf0e10cSrcweir     return Any( xTable );
520*cdf0e10cSrcweir }
521*cdf0e10cSrcweir 
522*cdf0e10cSrcweir uno::Type SAL_CALL ScDataPilotTablesObj::getElementType() throw(RuntimeException)
523*cdf0e10cSrcweir {
524*cdf0e10cSrcweir 	ScUnoGuard aGuard;
525*cdf0e10cSrcweir     return getCppuType((Reference<XDataPilotTable2>*)0);
526*cdf0e10cSrcweir }
527*cdf0e10cSrcweir 
528*cdf0e10cSrcweir sal_Bool SAL_CALL ScDataPilotTablesObj::hasElements() throw(RuntimeException)
529*cdf0e10cSrcweir {
530*cdf0e10cSrcweir 	ScUnoGuard aGuard;
531*cdf0e10cSrcweir 	return ( getCount() != 0 );
532*cdf0e10cSrcweir }
533*cdf0e10cSrcweir 
534*cdf0e10cSrcweir // XNameAccess
535*cdf0e10cSrcweir 
536*cdf0e10cSrcweir Any SAL_CALL ScDataPilotTablesObj::getByName( const OUString& aName )
537*cdf0e10cSrcweir         throw(NoSuchElementException, WrappedTargetException, RuntimeException)
538*cdf0e10cSrcweir {
539*cdf0e10cSrcweir 	ScUnoGuard aGuard;
540*cdf0e10cSrcweir     Reference<XDataPilotTable2> xTable(GetObjectByName_Impl(aName));
541*cdf0e10cSrcweir     if (!xTable.is())
542*cdf0e10cSrcweir         throw NoSuchElementException();
543*cdf0e10cSrcweir     return Any( xTable );
544*cdf0e10cSrcweir }
545*cdf0e10cSrcweir 
546*cdf0e10cSrcweir Sequence<OUString> SAL_CALL ScDataPilotTablesObj::getElementNames()
547*cdf0e10cSrcweir                                                 throw(RuntimeException)
548*cdf0e10cSrcweir {
549*cdf0e10cSrcweir 	ScUnoGuard aGuard;
550*cdf0e10cSrcweir 	if (pDocShell)
551*cdf0e10cSrcweir 	{
552*cdf0e10cSrcweir 		ScDocument* pDoc = pDocShell->GetDocument();
553*cdf0e10cSrcweir 		ScDPCollection* pColl = pDoc->GetDPCollection();
554*cdf0e10cSrcweir 		if ( pColl )
555*cdf0e10cSrcweir 		{
556*cdf0e10cSrcweir 			//	count tables on this sheet
557*cdf0e10cSrcweir 
558*cdf0e10cSrcweir 			sal_uInt16 nFound = 0;
559*cdf0e10cSrcweir 			sal_uInt16 nCount = pColl->GetCount();
560*cdf0e10cSrcweir 			sal_uInt16 i;
561*cdf0e10cSrcweir 			for (i=0; i<nCount; i++)
562*cdf0e10cSrcweir 			{
563*cdf0e10cSrcweir 				ScDPObject* pDPObj = (*pColl)[i];
564*cdf0e10cSrcweir                 if ( pDPObj->GetOutRange().aStart.Tab() == nTab )
565*cdf0e10cSrcweir 					++nFound;
566*cdf0e10cSrcweir 			}
567*cdf0e10cSrcweir 
568*cdf0e10cSrcweir 			sal_uInt16 nPos = 0;
569*cdf0e10cSrcweir             Sequence<OUString> aSeq(nFound);
570*cdf0e10cSrcweir             OUString* pAry = aSeq.getArray();
571*cdf0e10cSrcweir 			for (i=0; i<nCount; i++)
572*cdf0e10cSrcweir 			{
573*cdf0e10cSrcweir 				ScDPObject* pDPObj = (*pColl)[i];
574*cdf0e10cSrcweir                 if ( pDPObj->GetOutRange().aStart.Tab() == nTab )
575*cdf0e10cSrcweir 					pAry[nPos++] = pDPObj->GetName();
576*cdf0e10cSrcweir 			}
577*cdf0e10cSrcweir 
578*cdf0e10cSrcweir 			return aSeq;
579*cdf0e10cSrcweir 		}
580*cdf0e10cSrcweir 	}
581*cdf0e10cSrcweir     return Sequence<OUString>(0);
582*cdf0e10cSrcweir }
583*cdf0e10cSrcweir 
584*cdf0e10cSrcweir sal_Bool SAL_CALL ScDataPilotTablesObj::hasByName( const OUString& aName )
585*cdf0e10cSrcweir                                         throw(RuntimeException)
586*cdf0e10cSrcweir {
587*cdf0e10cSrcweir 	ScUnoGuard aGuard;
588*cdf0e10cSrcweir 	if (pDocShell)
589*cdf0e10cSrcweir 	{
590*cdf0e10cSrcweir 		ScDocument* pDoc = pDocShell->GetDocument();
591*cdf0e10cSrcweir 		ScDPCollection* pColl = pDoc->GetDPCollection();
592*cdf0e10cSrcweir 		if ( pColl )
593*cdf0e10cSrcweir 		{
594*cdf0e10cSrcweir 			String aNamStr(aName);
595*cdf0e10cSrcweir 			sal_uInt16 nCount = pColl->GetCount();
596*cdf0e10cSrcweir 			for (sal_uInt16 i=0; i<nCount; i++)
597*cdf0e10cSrcweir 			{
598*cdf0e10cSrcweir 				ScDPObject* pDPObj = (*pColl)[i];
599*cdf0e10cSrcweir                 if ( pDPObj->GetOutRange().aStart.Tab() == nTab &&
600*cdf0e10cSrcweir 					 pDPObj->GetName() == aNamStr )
601*cdf0e10cSrcweir 					return sal_True;
602*cdf0e10cSrcweir 			}
603*cdf0e10cSrcweir 		}
604*cdf0e10cSrcweir 	}
605*cdf0e10cSrcweir 	return sal_False;
606*cdf0e10cSrcweir }
607*cdf0e10cSrcweir 
608*cdf0e10cSrcweir //------------------------------------------------------------------------
609*cdf0e10cSrcweir 
610*cdf0e10cSrcweir ScDataPilotDescriptorBase::ScDataPilotDescriptorBase(ScDocShell* pDocSh) :
611*cdf0e10cSrcweir     maPropSet( lcl_GetDataPilotDescriptorBaseMap() ),
612*cdf0e10cSrcweir 	pDocShell( pDocSh )
613*cdf0e10cSrcweir {
614*cdf0e10cSrcweir 	pDocShell->GetDocument()->AddUnoObject(*this);
615*cdf0e10cSrcweir }
616*cdf0e10cSrcweir 
617*cdf0e10cSrcweir ScDataPilotDescriptorBase::~ScDataPilotDescriptorBase()
618*cdf0e10cSrcweir {
619*cdf0e10cSrcweir 	if (pDocShell)
620*cdf0e10cSrcweir 		pDocShell->GetDocument()->RemoveUnoObject(*this);
621*cdf0e10cSrcweir }
622*cdf0e10cSrcweir 
623*cdf0e10cSrcweir Any SAL_CALL ScDataPilotDescriptorBase::queryInterface( const uno::Type& rType )
624*cdf0e10cSrcweir                                                 throw(RuntimeException)
625*cdf0e10cSrcweir {
626*cdf0e10cSrcweir     SC_QUERYINTERFACE( XDataPilotDescriptor )
627*cdf0e10cSrcweir     SC_QUERYINTERFACE( XPropertySet )
628*cdf0e10cSrcweir     SC_QUERYINTERFACE( XDataPilotDataLayoutFieldSupplier )
629*cdf0e10cSrcweir     SC_QUERYINTERFACE( XNamed )                 // base of XDataPilotDescriptor
630*cdf0e10cSrcweir 	SC_QUERYINTERFACE( lang::XUnoTunnel )
631*cdf0e10cSrcweir 	SC_QUERYINTERFACE( lang::XTypeProvider )
632*cdf0e10cSrcweir 	SC_QUERYINTERFACE( lang::XServiceInfo )
633*cdf0e10cSrcweir 
634*cdf0e10cSrcweir 	return OWeakObject::queryInterface( rType );
635*cdf0e10cSrcweir }
636*cdf0e10cSrcweir 
637*cdf0e10cSrcweir void SAL_CALL ScDataPilotDescriptorBase::acquire() throw()
638*cdf0e10cSrcweir {
639*cdf0e10cSrcweir 	OWeakObject::acquire();
640*cdf0e10cSrcweir }
641*cdf0e10cSrcweir 
642*cdf0e10cSrcweir void SAL_CALL ScDataPilotDescriptorBase::release() throw()
643*cdf0e10cSrcweir {
644*cdf0e10cSrcweir 	OWeakObject::release();
645*cdf0e10cSrcweir }
646*cdf0e10cSrcweir 
647*cdf0e10cSrcweir Sequence< uno::Type > SAL_CALL ScDataPilotDescriptorBase::getTypes()
648*cdf0e10cSrcweir                                                     throw(RuntimeException)
649*cdf0e10cSrcweir {
650*cdf0e10cSrcweir     static Sequence< uno::Type > aTypes;
651*cdf0e10cSrcweir 	if ( aTypes.getLength() == 0 )
652*cdf0e10cSrcweir 	{
653*cdf0e10cSrcweir         aTypes.realloc( 6 );
654*cdf0e10cSrcweir         uno::Type* pPtr = aTypes.getArray();
655*cdf0e10cSrcweir         pPtr[ 0 ] = getCppuType( (const Reference< XDataPilotDescriptor >*)0 );
656*cdf0e10cSrcweir         pPtr[ 1 ] = getCppuType( (const Reference< XPropertySet >*)0 );
657*cdf0e10cSrcweir         pPtr[ 2 ] = getCppuType( (const Reference< XDataPilotDataLayoutFieldSupplier >*)0 );
658*cdf0e10cSrcweir         pPtr[ 3 ] = getCppuType( (const Reference< lang::XUnoTunnel >*)0 );
659*cdf0e10cSrcweir         pPtr[ 4 ] = getCppuType( (const Reference< lang::XTypeProvider >*)0 );
660*cdf0e10cSrcweir         pPtr[ 5 ] = getCppuType( (const Reference< lang::XServiceInfo >*)0 );
661*cdf0e10cSrcweir 	}
662*cdf0e10cSrcweir 	return aTypes;
663*cdf0e10cSrcweir }
664*cdf0e10cSrcweir 
665*cdf0e10cSrcweir Sequence<sal_Int8> SAL_CALL ScDataPilotDescriptorBase::getImplementationId()
666*cdf0e10cSrcweir                                                     throw(RuntimeException)
667*cdf0e10cSrcweir {
668*cdf0e10cSrcweir     static Sequence< sal_Int8 > aId;
669*cdf0e10cSrcweir 	if( aId.getLength() == 0 )
670*cdf0e10cSrcweir 	{
671*cdf0e10cSrcweir 		aId.realloc( 16 );
672*cdf0e10cSrcweir 		rtl_createUuid( (sal_uInt8 *)aId.getArray(), 0, sal_True );
673*cdf0e10cSrcweir 	}
674*cdf0e10cSrcweir 	return aId;
675*cdf0e10cSrcweir }
676*cdf0e10cSrcweir 
677*cdf0e10cSrcweir void ScDataPilotDescriptorBase::Notify( SfxBroadcaster&, const SfxHint& rHint )
678*cdf0e10cSrcweir {
679*cdf0e10cSrcweir 	//!	Referenz-Update?
680*cdf0e10cSrcweir 
681*cdf0e10cSrcweir 	if ( rHint.ISA( SfxSimpleHint ) &&
682*cdf0e10cSrcweir 			((const SfxSimpleHint&)rHint).GetId() == SFX_HINT_DYING )
683*cdf0e10cSrcweir 	{
684*cdf0e10cSrcweir 		pDocShell = NULL;		// ungueltig geworden
685*cdf0e10cSrcweir 	}
686*cdf0e10cSrcweir }
687*cdf0e10cSrcweir 
688*cdf0e10cSrcweir // XDataPilotDescriptor
689*cdf0e10cSrcweir 
690*cdf0e10cSrcweir CellRangeAddress SAL_CALL ScDataPilotDescriptorBase::getSourceRange()
691*cdf0e10cSrcweir                                             throw(RuntimeException)
692*cdf0e10cSrcweir {
693*cdf0e10cSrcweir 	ScUnoGuard aGuard;
694*cdf0e10cSrcweir 
695*cdf0e10cSrcweir     ScDPObject* pDPObject(GetDPObject());
696*cdf0e10cSrcweir     if (!pDPObject)
697*cdf0e10cSrcweir         throw RuntimeException();
698*cdf0e10cSrcweir 
699*cdf0e10cSrcweir     CellRangeAddress aRet;
700*cdf0e10cSrcweir     if (pDPObject->IsSheetData())
701*cdf0e10cSrcweir         ScUnoConversion::FillApiRange( aRet, pDPObject->GetSheetDesc()->aSourceRange );
702*cdf0e10cSrcweir     return aRet;
703*cdf0e10cSrcweir }
704*cdf0e10cSrcweir 
705*cdf0e10cSrcweir void SAL_CALL ScDataPilotDescriptorBase::setSourceRange( const CellRangeAddress& aSourceRange ) throw(RuntimeException)
706*cdf0e10cSrcweir {
707*cdf0e10cSrcweir 	ScUnoGuard aGuard;
708*cdf0e10cSrcweir 
709*cdf0e10cSrcweir     ScDPObject* pDPObject = GetDPObject();
710*cdf0e10cSrcweir     if (!pDPObject)
711*cdf0e10cSrcweir         throw RuntimeException();
712*cdf0e10cSrcweir 
713*cdf0e10cSrcweir     ScSheetSourceDesc aSheetDesc;
714*cdf0e10cSrcweir     if (pDPObject->IsSheetData())
715*cdf0e10cSrcweir         aSheetDesc = *pDPObject->GetSheetDesc();
716*cdf0e10cSrcweir     ScUnoConversion::FillScRange( aSheetDesc.aSourceRange, aSourceRange );
717*cdf0e10cSrcweir     pDPObject->SetSheetDesc( aSheetDesc );
718*cdf0e10cSrcweir     SetDPObject( pDPObject );
719*cdf0e10cSrcweir }
720*cdf0e10cSrcweir 
721*cdf0e10cSrcweir Reference<XSheetFilterDescriptor> SAL_CALL ScDataPilotDescriptorBase::getFilterDescriptor()
722*cdf0e10cSrcweir                                                 throw(RuntimeException)
723*cdf0e10cSrcweir {
724*cdf0e10cSrcweir 	ScUnoGuard aGuard;
725*cdf0e10cSrcweir 	return new ScDataPilotFilterDescriptor( pDocShell, this );
726*cdf0e10cSrcweir }
727*cdf0e10cSrcweir 
728*cdf0e10cSrcweir Reference<XIndexAccess> SAL_CALL ScDataPilotDescriptorBase::getDataPilotFields()
729*cdf0e10cSrcweir                                                 throw(RuntimeException)
730*cdf0e10cSrcweir {
731*cdf0e10cSrcweir 	ScUnoGuard aGuard;
732*cdf0e10cSrcweir     return new ScDataPilotFieldsObj( *this );
733*cdf0e10cSrcweir }
734*cdf0e10cSrcweir 
735*cdf0e10cSrcweir Reference<XIndexAccess> SAL_CALL ScDataPilotDescriptorBase::getColumnFields()
736*cdf0e10cSrcweir                                                 throw(RuntimeException)
737*cdf0e10cSrcweir {
738*cdf0e10cSrcweir 	ScUnoGuard aGuard;
739*cdf0e10cSrcweir     return new ScDataPilotFieldsObj( *this, DataPilotFieldOrientation_COLUMN );
740*cdf0e10cSrcweir }
741*cdf0e10cSrcweir 
742*cdf0e10cSrcweir Reference<XIndexAccess> SAL_CALL ScDataPilotDescriptorBase::getRowFields()
743*cdf0e10cSrcweir                                                 throw(RuntimeException)
744*cdf0e10cSrcweir {
745*cdf0e10cSrcweir 	ScUnoGuard aGuard;
746*cdf0e10cSrcweir     return new ScDataPilotFieldsObj( *this, DataPilotFieldOrientation_ROW );
747*cdf0e10cSrcweir }
748*cdf0e10cSrcweir 
749*cdf0e10cSrcweir Reference<XIndexAccess> SAL_CALL ScDataPilotDescriptorBase::getPageFields()
750*cdf0e10cSrcweir                                                 throw(RuntimeException)
751*cdf0e10cSrcweir {
752*cdf0e10cSrcweir 	ScUnoGuard aGuard;
753*cdf0e10cSrcweir     return new ScDataPilotFieldsObj( *this, DataPilotFieldOrientation_PAGE );
754*cdf0e10cSrcweir }
755*cdf0e10cSrcweir 
756*cdf0e10cSrcweir Reference<XIndexAccess> SAL_CALL ScDataPilotDescriptorBase::getDataFields()
757*cdf0e10cSrcweir                                                 throw(RuntimeException)
758*cdf0e10cSrcweir {
759*cdf0e10cSrcweir 	ScUnoGuard aGuard;
760*cdf0e10cSrcweir     return new ScDataPilotFieldsObj( *this, DataPilotFieldOrientation_DATA );
761*cdf0e10cSrcweir }
762*cdf0e10cSrcweir 
763*cdf0e10cSrcweir Reference<XIndexAccess> SAL_CALL ScDataPilotDescriptorBase::getHiddenFields()
764*cdf0e10cSrcweir                                                 throw(RuntimeException)
765*cdf0e10cSrcweir {
766*cdf0e10cSrcweir 	ScUnoGuard aGuard;
767*cdf0e10cSrcweir     return new ScDataPilotFieldsObj( *this, DataPilotFieldOrientation_HIDDEN );
768*cdf0e10cSrcweir }
769*cdf0e10cSrcweir 
770*cdf0e10cSrcweir // XPropertySet
771*cdf0e10cSrcweir Reference< XPropertySetInfo > SAL_CALL ScDataPilotDescriptorBase::getPropertySetInfo(  )
772*cdf0e10cSrcweir                                                 throw(RuntimeException)
773*cdf0e10cSrcweir {
774*cdf0e10cSrcweir 	ScUnoGuard aGuard;
775*cdf0e10cSrcweir     static Reference<XPropertySetInfo> aRef =
776*cdf0e10cSrcweir         new SfxItemPropertySetInfo( maPropSet.getPropertyMap() );
777*cdf0e10cSrcweir 	return aRef;
778*cdf0e10cSrcweir }
779*cdf0e10cSrcweir 
780*cdf0e10cSrcweir void SAL_CALL ScDataPilotDescriptorBase::setPropertyValue( const OUString& aPropertyName, const Any& aValue )
781*cdf0e10cSrcweir         throw(UnknownPropertyException, PropertyVetoException, IllegalArgumentException,
782*cdf0e10cSrcweir                 WrappedTargetException, RuntimeException)
783*cdf0e10cSrcweir {
784*cdf0e10cSrcweir 	ScUnoGuard aGuard;
785*cdf0e10cSrcweir     ScDPObject* pDPObject = GetDPObject();
786*cdf0e10cSrcweir     if (pDPObject)
787*cdf0e10cSrcweir     {
788*cdf0e10cSrcweir 	    ScDPSaveData* pOldData = pDPObject->GetSaveData();
789*cdf0e10cSrcweir         DBG_ASSERT(pOldData, "Here should be a SaveData");
790*cdf0e10cSrcweir 	    if ( pOldData )
791*cdf0e10cSrcweir 	    {
792*cdf0e10cSrcweir 		    ScDPSaveData aNewData( *pOldData );
793*cdf0e10cSrcweir 
794*cdf0e10cSrcweir     	    String aNameString = aPropertyName;
795*cdf0e10cSrcweir     	    if ( aNameString.EqualsAscii( SC_UNO_COLGRAND ) )
796*cdf0e10cSrcweir             {
797*cdf0e10cSrcweir 	            aNewData.SetColumnGrand(::cppu::any2bool( aValue ));
798*cdf0e10cSrcweir             }
799*cdf0e10cSrcweir     	    else if ( aNameString.EqualsAscii( SC_UNO_IGNEMPROWS ) )
800*cdf0e10cSrcweir             {
801*cdf0e10cSrcweir                 aNewData.SetIgnoreEmptyRows(::cppu::any2bool( aValue ));
802*cdf0e10cSrcweir             }
803*cdf0e10cSrcweir     	    else if ( aNameString.EqualsAscii( SC_UNO_RPTEMPTY ) )
804*cdf0e10cSrcweir             {
805*cdf0e10cSrcweir     	        aNewData.SetRepeatIfEmpty(::cppu::any2bool( aValue ));
806*cdf0e10cSrcweir             }
807*cdf0e10cSrcweir     	    else if ( aNameString.EqualsAscii( SC_UNO_ROWGRAND ) )
808*cdf0e10cSrcweir             {
809*cdf0e10cSrcweir 	            aNewData.SetRowGrand(::cppu::any2bool( aValue ));
810*cdf0e10cSrcweir             }
811*cdf0e10cSrcweir             else if ( aNameString.EqualsAscii( SC_UNO_SHOWFILT ) )
812*cdf0e10cSrcweir             {
813*cdf0e10cSrcweir                 aNewData.SetFilterButton(::cppu::any2bool( aValue ));
814*cdf0e10cSrcweir             }
815*cdf0e10cSrcweir             else if ( aNameString.EqualsAscii( SC_UNO_DRILLDOWN ) )
816*cdf0e10cSrcweir             {
817*cdf0e10cSrcweir                 aNewData.SetDrillDown(::cppu::any2bool( aValue ));
818*cdf0e10cSrcweir             }
819*cdf0e10cSrcweir             else if ( aNameString.EqualsAscii( SC_UNO_GRANDTOTAL_NAME ) )
820*cdf0e10cSrcweir             {
821*cdf0e10cSrcweir                 rtl::OUString aStrVal;
822*cdf0e10cSrcweir                 if ( aValue >>= aStrVal )
823*cdf0e10cSrcweir                     aNewData.SetGrandTotalName(aStrVal);
824*cdf0e10cSrcweir             }
825*cdf0e10cSrcweir             else if ( aNameString.EqualsAscii( SC_UNO_IMPORTDESC ) )
826*cdf0e10cSrcweir             {
827*cdf0e10cSrcweir                 uno::Sequence<beans::PropertyValue> aArgSeq;
828*cdf0e10cSrcweir                 if ( aValue >>= aArgSeq )
829*cdf0e10cSrcweir                 {
830*cdf0e10cSrcweir                     ScImportSourceDesc aImportDesc;
831*cdf0e10cSrcweir 
832*cdf0e10cSrcweir                     const ScImportSourceDesc* pOldDesc = pDPObject->GetImportSourceDesc();
833*cdf0e10cSrcweir                     if (pOldDesc)
834*cdf0e10cSrcweir                         aImportDesc = *pOldDesc;
835*cdf0e10cSrcweir 
836*cdf0e10cSrcweir                     ScImportParam aParam;
837*cdf0e10cSrcweir                     ScImportDescriptor::FillImportParam( aParam, aArgSeq );
838*cdf0e10cSrcweir 
839*cdf0e10cSrcweir                     sal_uInt16 nNewType = sheet::DataImportMode_NONE;
840*cdf0e10cSrcweir                     if ( aParam.bImport )
841*cdf0e10cSrcweir                     {
842*cdf0e10cSrcweir                         if ( aParam.bSql )
843*cdf0e10cSrcweir                             nNewType = sheet::DataImportMode_SQL;
844*cdf0e10cSrcweir                         else if ( aParam.nType == ScDbQuery )
845*cdf0e10cSrcweir                             nNewType = sheet::DataImportMode_QUERY;
846*cdf0e10cSrcweir                         else
847*cdf0e10cSrcweir                             nNewType = sheet::DataImportMode_TABLE;
848*cdf0e10cSrcweir                     }
849*cdf0e10cSrcweir                     aImportDesc.nType   = nNewType;
850*cdf0e10cSrcweir                     aImportDesc.aDBName = aParam.aDBName;
851*cdf0e10cSrcweir                     aImportDesc.aObject = aParam.aStatement;
852*cdf0e10cSrcweir                     aImportDesc.bNative = aParam.bNative;
853*cdf0e10cSrcweir 
854*cdf0e10cSrcweir                     pDPObject->SetImportDesc( aImportDesc );
855*cdf0e10cSrcweir                 }
856*cdf0e10cSrcweir             }
857*cdf0e10cSrcweir             else if ( aNameString.EqualsAscii( SC_UNO_SOURCESERV ) )
858*cdf0e10cSrcweir             {
859*cdf0e10cSrcweir                 rtl::OUString aStrVal;
860*cdf0e10cSrcweir                 if ( aValue >>= aStrVal )
861*cdf0e10cSrcweir                 {
862*cdf0e10cSrcweir                     String aEmpty;
863*cdf0e10cSrcweir                     ScDPServiceDesc aServiceDesc(aEmpty, aEmpty, aEmpty, aEmpty, aEmpty);
864*cdf0e10cSrcweir 
865*cdf0e10cSrcweir                     const ScDPServiceDesc* pOldDesc = pDPObject->GetDPServiceDesc();
866*cdf0e10cSrcweir                     if (pOldDesc)
867*cdf0e10cSrcweir                         aServiceDesc = *pOldDesc;
868*cdf0e10cSrcweir 
869*cdf0e10cSrcweir                     aServiceDesc.aServiceName = aStrVal;
870*cdf0e10cSrcweir 
871*cdf0e10cSrcweir                     pDPObject->SetServiceData( aServiceDesc );
872*cdf0e10cSrcweir                 }
873*cdf0e10cSrcweir             }
874*cdf0e10cSrcweir             else if ( aNameString.EqualsAscii( SC_UNO_SERVICEARG ) )
875*cdf0e10cSrcweir             {
876*cdf0e10cSrcweir                 uno::Sequence<beans::PropertyValue> aArgSeq;
877*cdf0e10cSrcweir                 if ( aValue >>= aArgSeq )
878*cdf0e10cSrcweir                 {
879*cdf0e10cSrcweir                     String aEmpty;
880*cdf0e10cSrcweir                     ScDPServiceDesc aServiceDesc(aEmpty, aEmpty, aEmpty, aEmpty, aEmpty);
881*cdf0e10cSrcweir 
882*cdf0e10cSrcweir                     const ScDPServiceDesc* pOldDesc = pDPObject->GetDPServiceDesc();
883*cdf0e10cSrcweir                     if (pOldDesc)
884*cdf0e10cSrcweir                         aServiceDesc = *pOldDesc;
885*cdf0e10cSrcweir 
886*cdf0e10cSrcweir                     rtl::OUString aStrVal;
887*cdf0e10cSrcweir                     sal_Int32 nArgs = aArgSeq.getLength();
888*cdf0e10cSrcweir                     for (sal_Int32 nArgPos=0; nArgPos<nArgs; ++nArgPos)
889*cdf0e10cSrcweir                     {
890*cdf0e10cSrcweir                         const beans::PropertyValue& rProp = aArgSeq[nArgPos];
891*cdf0e10cSrcweir                         String aPropName(rProp.Name);
892*cdf0e10cSrcweir 
893*cdf0e10cSrcweir                         if (aPropName.EqualsAscii( SC_UNO_SOURCENAME ))
894*cdf0e10cSrcweir                         {
895*cdf0e10cSrcweir                             if ( rProp.Value >>= aStrVal )
896*cdf0e10cSrcweir                                 aServiceDesc.aParSource = aStrVal;
897*cdf0e10cSrcweir                         }
898*cdf0e10cSrcweir                         else if (aPropName.EqualsAscii( SC_UNO_OBJECTNAME ))
899*cdf0e10cSrcweir                         {
900*cdf0e10cSrcweir                             if ( rProp.Value >>= aStrVal )
901*cdf0e10cSrcweir                                 aServiceDesc.aParName = aStrVal;
902*cdf0e10cSrcweir                         }
903*cdf0e10cSrcweir                         else if (aPropName.EqualsAscii( SC_UNO_USERNAME ))
904*cdf0e10cSrcweir                         {
905*cdf0e10cSrcweir                             if ( rProp.Value >>= aStrVal )
906*cdf0e10cSrcweir                                 aServiceDesc.aParUser = aStrVal;
907*cdf0e10cSrcweir                         }
908*cdf0e10cSrcweir                         else if (aPropName.EqualsAscii( SC_UNO_PASSWORD ))
909*cdf0e10cSrcweir                         {
910*cdf0e10cSrcweir                             if ( rProp.Value >>= aStrVal )
911*cdf0e10cSrcweir                                 aServiceDesc.aParPass = aStrVal;
912*cdf0e10cSrcweir                         }
913*cdf0e10cSrcweir                     }
914*cdf0e10cSrcweir 
915*cdf0e10cSrcweir                     pDPObject->SetServiceData( aServiceDesc );
916*cdf0e10cSrcweir                 }
917*cdf0e10cSrcweir             }
918*cdf0e10cSrcweir             else
919*cdf0e10cSrcweir                 throw UnknownPropertyException();
920*cdf0e10cSrcweir 
921*cdf0e10cSrcweir             pDPObject->SetSaveData( aNewData );
922*cdf0e10cSrcweir         }
923*cdf0e10cSrcweir 
924*cdf0e10cSrcweir         SetDPObject(pDPObject);
925*cdf0e10cSrcweir     }
926*cdf0e10cSrcweir }
927*cdf0e10cSrcweir 
928*cdf0e10cSrcweir Any SAL_CALL ScDataPilotDescriptorBase::getPropertyValue( const OUString& aPropertyName )
929*cdf0e10cSrcweir         throw(UnknownPropertyException, WrappedTargetException, RuntimeException)
930*cdf0e10cSrcweir {
931*cdf0e10cSrcweir 	ScUnoGuard aGuard;
932*cdf0e10cSrcweir     Any aRet;
933*cdf0e10cSrcweir 
934*cdf0e10cSrcweir     ScDPObject* pDPObject(GetDPObject());
935*cdf0e10cSrcweir     if (pDPObject)
936*cdf0e10cSrcweir     {
937*cdf0e10cSrcweir 	    ScDPSaveData* pOldData = pDPObject->GetSaveData();
938*cdf0e10cSrcweir         DBG_ASSERT(pOldData, "Here should be a SaveData");
939*cdf0e10cSrcweir 	    if ( pOldData )
940*cdf0e10cSrcweir 	    {
941*cdf0e10cSrcweir 		    ScDPSaveData aNewData( *pOldData );
942*cdf0e10cSrcweir 
943*cdf0e10cSrcweir     	    String aNameString = aPropertyName;
944*cdf0e10cSrcweir     	    if ( aNameString.EqualsAscii( SC_UNO_COLGRAND ) )
945*cdf0e10cSrcweir             {
946*cdf0e10cSrcweir 	            aRet = ::cppu::bool2any( aNewData.GetColumnGrand() );
947*cdf0e10cSrcweir             }
948*cdf0e10cSrcweir     	    else if ( aNameString.EqualsAscii( SC_UNO_IGNEMPROWS ) )
949*cdf0e10cSrcweir             {
950*cdf0e10cSrcweir                 aRet = ::cppu::bool2any( aNewData.GetIgnoreEmptyRows() );
951*cdf0e10cSrcweir             }
952*cdf0e10cSrcweir     	    else if ( aNameString.EqualsAscii( SC_UNO_RPTEMPTY ) )
953*cdf0e10cSrcweir             {
954*cdf0e10cSrcweir     	        aRet = ::cppu::bool2any( aNewData.GetRepeatIfEmpty() );
955*cdf0e10cSrcweir             }
956*cdf0e10cSrcweir     	    else if ( aNameString.EqualsAscii( SC_UNO_ROWGRAND ) )
957*cdf0e10cSrcweir             {
958*cdf0e10cSrcweir 	            aRet = ::cppu::bool2any( aNewData.GetRowGrand() );
959*cdf0e10cSrcweir             }
960*cdf0e10cSrcweir             else if ( aNameString.EqualsAscii( SC_UNO_SHOWFILT ) )
961*cdf0e10cSrcweir             {
962*cdf0e10cSrcweir                 aRet = ::cppu::bool2any( aNewData.GetFilterButton() );
963*cdf0e10cSrcweir             }
964*cdf0e10cSrcweir             else if ( aNameString.EqualsAscii( SC_UNO_DRILLDOWN ) )
965*cdf0e10cSrcweir             {
966*cdf0e10cSrcweir                 aRet = ::cppu::bool2any( aNewData.GetDrillDown() );
967*cdf0e10cSrcweir             }
968*cdf0e10cSrcweir             else if ( aNameString.EqualsAscii( SC_UNO_GRANDTOTAL_NAME ) )
969*cdf0e10cSrcweir             {
970*cdf0e10cSrcweir                 const rtl::OUString* pGrandTotalName = aNewData.GetGrandTotalName();
971*cdf0e10cSrcweir                 if (pGrandTotalName)
972*cdf0e10cSrcweir                     aRet <<= *pGrandTotalName;      // same behavior as in ScDPSource
973*cdf0e10cSrcweir             }
974*cdf0e10cSrcweir             else if ( aNameString.EqualsAscii( SC_UNO_IMPORTDESC ) )
975*cdf0e10cSrcweir             {
976*cdf0e10cSrcweir                 const ScImportSourceDesc* pImportDesc = pDPObject->GetImportSourceDesc();
977*cdf0e10cSrcweir                 if ( pImportDesc )
978*cdf0e10cSrcweir                 {
979*cdf0e10cSrcweir                     // fill ScImportParam so ScImportDescriptor::FillProperties can be used
980*cdf0e10cSrcweir                     ScImportParam aParam;
981*cdf0e10cSrcweir                     aParam.bImport    = ( pImportDesc->nType != sheet::DataImportMode_NONE );
982*cdf0e10cSrcweir                     aParam.aDBName    = pImportDesc->aDBName;
983*cdf0e10cSrcweir                     aParam.aStatement = pImportDesc->aObject;
984*cdf0e10cSrcweir                     aParam.bNative    = pImportDesc->bNative;
985*cdf0e10cSrcweir                     aParam.bSql       = ( pImportDesc->nType == sheet::DataImportMode_SQL );
986*cdf0e10cSrcweir                     aParam.nType      = static_cast<sal_uInt8>(( pImportDesc->nType == sheet::DataImportMode_QUERY ) ? ScDbQuery : ScDbTable);
987*cdf0e10cSrcweir 
988*cdf0e10cSrcweir                     uno::Sequence<beans::PropertyValue> aSeq( ScImportDescriptor::GetPropertyCount() );
989*cdf0e10cSrcweir                     ScImportDescriptor::FillProperties( aSeq, aParam );
990*cdf0e10cSrcweir                     aRet <<= aSeq;
991*cdf0e10cSrcweir                 }
992*cdf0e10cSrcweir                 else
993*cdf0e10cSrcweir                 {
994*cdf0e10cSrcweir                     // empty sequence
995*cdf0e10cSrcweir                     uno::Sequence<beans::PropertyValue> aEmpty(0);
996*cdf0e10cSrcweir                     aRet <<= aEmpty;
997*cdf0e10cSrcweir                 }
998*cdf0e10cSrcweir             }
999*cdf0e10cSrcweir             else if ( aNameString.EqualsAscii( SC_UNO_SOURCESERV ) )
1000*cdf0e10cSrcweir             {
1001*cdf0e10cSrcweir                 rtl::OUString aServiceName;
1002*cdf0e10cSrcweir                 const ScDPServiceDesc* pServiceDesc = pDPObject->GetDPServiceDesc();
1003*cdf0e10cSrcweir                 if (pServiceDesc)
1004*cdf0e10cSrcweir                     aServiceName = pServiceDesc->aServiceName;
1005*cdf0e10cSrcweir                 aRet <<= aServiceName;      // empty string if no ServiceDesc set
1006*cdf0e10cSrcweir             }
1007*cdf0e10cSrcweir             else if ( aNameString.EqualsAscii( SC_UNO_SERVICEARG ) )
1008*cdf0e10cSrcweir             {
1009*cdf0e10cSrcweir                 const ScDPServiceDesc* pServiceDesc = pDPObject->GetDPServiceDesc();
1010*cdf0e10cSrcweir                 if (pServiceDesc)
1011*cdf0e10cSrcweir                 {
1012*cdf0e10cSrcweir                     uno::Sequence<beans::PropertyValue> aSeq( 4 );
1013*cdf0e10cSrcweir                     beans::PropertyValue* pArray = aSeq.getArray();
1014*cdf0e10cSrcweir                     pArray[0].Name = rtl::OUString::createFromAscii( SC_UNO_SOURCENAME );
1015*cdf0e10cSrcweir                     pArray[0].Value <<= rtl::OUString( pServiceDesc->aParSource );
1016*cdf0e10cSrcweir                     pArray[1].Name = rtl::OUString::createFromAscii( SC_UNO_OBJECTNAME );
1017*cdf0e10cSrcweir                     pArray[1].Value <<= rtl::OUString( pServiceDesc->aParName );
1018*cdf0e10cSrcweir                     pArray[2].Name = rtl::OUString::createFromAscii( SC_UNO_USERNAME );
1019*cdf0e10cSrcweir                     pArray[2].Value <<= rtl::OUString( pServiceDesc->aParUser );
1020*cdf0e10cSrcweir                     pArray[3].Name = rtl::OUString::createFromAscii( SC_UNO_PASSWORD );
1021*cdf0e10cSrcweir                     pArray[3].Value <<= rtl::OUString( pServiceDesc->aParPass );
1022*cdf0e10cSrcweir                     aRet <<= aSeq;
1023*cdf0e10cSrcweir                 }
1024*cdf0e10cSrcweir                 else
1025*cdf0e10cSrcweir                 {
1026*cdf0e10cSrcweir                     // empty sequence
1027*cdf0e10cSrcweir                     uno::Sequence<beans::PropertyValue> aEmpty(0);
1028*cdf0e10cSrcweir                     aRet <<= aEmpty;
1029*cdf0e10cSrcweir                 }
1030*cdf0e10cSrcweir             }
1031*cdf0e10cSrcweir             else
1032*cdf0e10cSrcweir                 throw UnknownPropertyException();
1033*cdf0e10cSrcweir         }
1034*cdf0e10cSrcweir     }
1035*cdf0e10cSrcweir 
1036*cdf0e10cSrcweir     return aRet;
1037*cdf0e10cSrcweir }
1038*cdf0e10cSrcweir 
1039*cdf0e10cSrcweir void SAL_CALL ScDataPilotDescriptorBase::addPropertyChangeListener(
1040*cdf0e10cSrcweir         const OUString& /* aPropertyName */, const Reference<XPropertyChangeListener >& /* xListener */ )
1041*cdf0e10cSrcweir         throw(UnknownPropertyException, WrappedTargetException, RuntimeException)
1042*cdf0e10cSrcweir {
1043*cdf0e10cSrcweir }
1044*cdf0e10cSrcweir 
1045*cdf0e10cSrcweir void SAL_CALL ScDataPilotDescriptorBase::removePropertyChangeListener(
1046*cdf0e10cSrcweir         const OUString& /* aPropertyName */, const Reference<XPropertyChangeListener >& /* aListener */ )
1047*cdf0e10cSrcweir         throw(UnknownPropertyException, WrappedTargetException, RuntimeException)
1048*cdf0e10cSrcweir {
1049*cdf0e10cSrcweir }
1050*cdf0e10cSrcweir 
1051*cdf0e10cSrcweir void SAL_CALL ScDataPilotDescriptorBase::addVetoableChangeListener(
1052*cdf0e10cSrcweir         const OUString& /* PropertyName */, const Reference<XVetoableChangeListener >& /* aListener */ )
1053*cdf0e10cSrcweir         throw(UnknownPropertyException, WrappedTargetException, RuntimeException)
1054*cdf0e10cSrcweir {
1055*cdf0e10cSrcweir }
1056*cdf0e10cSrcweir 
1057*cdf0e10cSrcweir void SAL_CALL ScDataPilotDescriptorBase::removeVetoableChangeListener(
1058*cdf0e10cSrcweir         const OUString& /* PropertyName */, const Reference<XVetoableChangeListener >& /* aListener */ )
1059*cdf0e10cSrcweir         throw(UnknownPropertyException, WrappedTargetException, RuntimeException)
1060*cdf0e10cSrcweir {
1061*cdf0e10cSrcweir }
1062*cdf0e10cSrcweir 
1063*cdf0e10cSrcweir // XDataPilotDataLayoutFieldSupplier
1064*cdf0e10cSrcweir 
1065*cdf0e10cSrcweir Reference< XDataPilotField > SAL_CALL ScDataPilotDescriptorBase::getDataLayoutField() throw(RuntimeException)
1066*cdf0e10cSrcweir {
1067*cdf0e10cSrcweir     ScUnoGuard aGuard;
1068*cdf0e10cSrcweir     if( ScDPObject* pDPObject = GetDPObject() )
1069*cdf0e10cSrcweir     {
1070*cdf0e10cSrcweir         if( ScDPSaveData* pSaveData = pDPObject->GetSaveData() )
1071*cdf0e10cSrcweir         {
1072*cdf0e10cSrcweir             if( /*ScDPSaveDimension* pDataDim =*/ pSaveData->GetDataLayoutDimension() )
1073*cdf0e10cSrcweir             {
1074*cdf0e10cSrcweir                 ScFieldIdentifier aFieldId( OUString( RTL_CONSTASCII_USTRINGPARAM( SC_DATALAYOUT_NAME ) ), 0, true );
1075*cdf0e10cSrcweir                 return new ScDataPilotFieldObj( *this, aFieldId );
1076*cdf0e10cSrcweir             }
1077*cdf0e10cSrcweir         }
1078*cdf0e10cSrcweir     }
1079*cdf0e10cSrcweir     return 0;
1080*cdf0e10cSrcweir }
1081*cdf0e10cSrcweir 
1082*cdf0e10cSrcweir // XUnoTunnel
1083*cdf0e10cSrcweir 
1084*cdf0e10cSrcweir sal_Int64 SAL_CALL ScDataPilotDescriptorBase::getSomething(
1085*cdf0e10cSrcweir                 const Sequence<sal_Int8 >& rId ) throw(RuntimeException)
1086*cdf0e10cSrcweir {
1087*cdf0e10cSrcweir 	if ( rId.getLength() == 16 &&
1088*cdf0e10cSrcweir           0 == rtl_compareMemory( getUnoTunnelId().getConstArray(),
1089*cdf0e10cSrcweir 									rId.getConstArray(), 16 ) )
1090*cdf0e10cSrcweir 	{
1091*cdf0e10cSrcweir         return sal::static_int_cast<sal_Int64>(reinterpret_cast<sal_IntPtr>(this));
1092*cdf0e10cSrcweir 	}
1093*cdf0e10cSrcweir 	return 0;
1094*cdf0e10cSrcweir }
1095*cdf0e10cSrcweir 
1096*cdf0e10cSrcweir // static
1097*cdf0e10cSrcweir const Sequence<sal_Int8>& ScDataPilotDescriptorBase::getUnoTunnelId()
1098*cdf0e10cSrcweir {
1099*cdf0e10cSrcweir     static Sequence<sal_Int8> * pSeq = 0;
1100*cdf0e10cSrcweir 	if( !pSeq )
1101*cdf0e10cSrcweir 	{
1102*cdf0e10cSrcweir 		osl::Guard< osl::Mutex > aGuard( osl::Mutex::getGlobalMutex() );
1103*cdf0e10cSrcweir 		if( !pSeq )
1104*cdf0e10cSrcweir 		{
1105*cdf0e10cSrcweir             static Sequence< sal_Int8 > aSeq( 16 );
1106*cdf0e10cSrcweir 			rtl_createUuid( (sal_uInt8*)aSeq.getArray(), 0, sal_True );
1107*cdf0e10cSrcweir 			pSeq = &aSeq;
1108*cdf0e10cSrcweir 		}
1109*cdf0e10cSrcweir 	}
1110*cdf0e10cSrcweir 	return *pSeq;
1111*cdf0e10cSrcweir }
1112*cdf0e10cSrcweir 
1113*cdf0e10cSrcweir // static
1114*cdf0e10cSrcweir ScDataPilotDescriptorBase* ScDataPilotDescriptorBase::getImplementation(
1115*cdf0e10cSrcweir                                 const Reference<XDataPilotDescriptor> xObj )
1116*cdf0e10cSrcweir {
1117*cdf0e10cSrcweir 	ScDataPilotDescriptorBase* pRet = NULL;
1118*cdf0e10cSrcweir     Reference<lang::XUnoTunnel> xUT( xObj, UNO_QUERY );
1119*cdf0e10cSrcweir 	if (xUT.is())
1120*cdf0e10cSrcweir         pRet = reinterpret_cast<ScDataPilotDescriptorBase*>(sal::static_int_cast<sal_IntPtr>(xUT->getSomething(getUnoTunnelId())));
1121*cdf0e10cSrcweir 	return pRet;
1122*cdf0e10cSrcweir }
1123*cdf0e10cSrcweir 
1124*cdf0e10cSrcweir //------------------------------------------------------------------------
1125*cdf0e10cSrcweir 
1126*cdf0e10cSrcweir ScDataPilotTableObj::ScDataPilotTableObj(ScDocShell* pDocSh, SCTAB nT, const String& rN) :
1127*cdf0e10cSrcweir 	ScDataPilotDescriptorBase( pDocSh ),
1128*cdf0e10cSrcweir 	nTab( nT ),
1129*cdf0e10cSrcweir     aName( rN ),
1130*cdf0e10cSrcweir     aModifyListeners( 0 )
1131*cdf0e10cSrcweir {
1132*cdf0e10cSrcweir }
1133*cdf0e10cSrcweir 
1134*cdf0e10cSrcweir ScDataPilotTableObj::~ScDataPilotTableObj()
1135*cdf0e10cSrcweir {
1136*cdf0e10cSrcweir }
1137*cdf0e10cSrcweir 
1138*cdf0e10cSrcweir Any SAL_CALL ScDataPilotTableObj::queryInterface( const uno::Type& rType )
1139*cdf0e10cSrcweir                                                 throw(RuntimeException)
1140*cdf0e10cSrcweir {
1141*cdf0e10cSrcweir     // since we manually do resolve the query for XDataPilotTable2
1142*cdf0e10cSrcweir     // we also need to do the same for XDataPilotTable
1143*cdf0e10cSrcweir     SC_QUERYINTERFACE( XDataPilotTable )
1144*cdf0e10cSrcweir     SC_QUERYINTERFACE( XDataPilotTable2 )
1145*cdf0e10cSrcweir     SC_QUERYINTERFACE( XModifyBroadcaster )
1146*cdf0e10cSrcweir 
1147*cdf0e10cSrcweir 	return ScDataPilotDescriptorBase::queryInterface( rType );
1148*cdf0e10cSrcweir }
1149*cdf0e10cSrcweir 
1150*cdf0e10cSrcweir void SAL_CALL ScDataPilotTableObj::acquire() throw()
1151*cdf0e10cSrcweir {
1152*cdf0e10cSrcweir 	ScDataPilotDescriptorBase::acquire();
1153*cdf0e10cSrcweir }
1154*cdf0e10cSrcweir 
1155*cdf0e10cSrcweir void SAL_CALL ScDataPilotTableObj::release() throw()
1156*cdf0e10cSrcweir {
1157*cdf0e10cSrcweir 	ScDataPilotDescriptorBase::release();
1158*cdf0e10cSrcweir }
1159*cdf0e10cSrcweir 
1160*cdf0e10cSrcweir Sequence< uno::Type > SAL_CALL ScDataPilotTableObj::getTypes() throw(RuntimeException)
1161*cdf0e10cSrcweir {
1162*cdf0e10cSrcweir     static Sequence< uno::Type > aTypes;
1163*cdf0e10cSrcweir 	if ( aTypes.getLength() == 0 )
1164*cdf0e10cSrcweir 	{
1165*cdf0e10cSrcweir         Sequence< uno::Type > aParentTypes = ScDataPilotDescriptorBase::getTypes();
1166*cdf0e10cSrcweir         sal_Int32 nParentLen = aParentTypes.getLength();
1167*cdf0e10cSrcweir 		const uno::Type* pParentPtr = aParentTypes.getConstArray();
1168*cdf0e10cSrcweir 
1169*cdf0e10cSrcweir         aTypes.realloc( nParentLen + 2 );
1170*cdf0e10cSrcweir 		uno::Type* pPtr = aTypes.getArray();
1171*cdf0e10cSrcweir         for (sal_Int32 i = 0; i < nParentLen; ++i)
1172*cdf0e10cSrcweir             pPtr[ i ] = pParentPtr[ i ];               // parent types first
1173*cdf0e10cSrcweir 
1174*cdf0e10cSrcweir         pPtr[ nParentLen ] = getCppuType( (const Reference< XDataPilotTable2 >*)0 );
1175*cdf0e10cSrcweir         pPtr[ nParentLen+1 ] = getCppuType( (const Reference< XModifyBroadcaster >*)0 );
1176*cdf0e10cSrcweir 	}
1177*cdf0e10cSrcweir 	return aTypes;
1178*cdf0e10cSrcweir }
1179*cdf0e10cSrcweir 
1180*cdf0e10cSrcweir Sequence<sal_Int8> SAL_CALL ScDataPilotTableObj::getImplementationId()
1181*cdf0e10cSrcweir                                                     throw(RuntimeException)
1182*cdf0e10cSrcweir {
1183*cdf0e10cSrcweir     static Sequence< sal_Int8 > aId;
1184*cdf0e10cSrcweir 	if( aId.getLength() == 0 )
1185*cdf0e10cSrcweir 	{
1186*cdf0e10cSrcweir 		aId.realloc( 16 );
1187*cdf0e10cSrcweir 		rtl_createUuid( (sal_uInt8 *)aId.getArray(), 0, sal_True );
1188*cdf0e10cSrcweir 	}
1189*cdf0e10cSrcweir 	return aId;
1190*cdf0e10cSrcweir }
1191*cdf0e10cSrcweir 
1192*cdf0e10cSrcweir // ---
1193*cdf0e10cSrcweir ScDPObject* ScDataPilotTableObj::GetDPObject() const
1194*cdf0e10cSrcweir {
1195*cdf0e10cSrcweir     return lcl_GetDPObject(GetDocShell(), nTab, aName);
1196*cdf0e10cSrcweir }
1197*cdf0e10cSrcweir 
1198*cdf0e10cSrcweir void ScDataPilotTableObj::SetDPObject( ScDPObject* pDPObject )
1199*cdf0e10cSrcweir {
1200*cdf0e10cSrcweir 	ScDocShell* pDocSh = GetDocShell();
1201*cdf0e10cSrcweir 	ScDPObject* pDPObj = lcl_GetDPObject(pDocSh, nTab, aName);
1202*cdf0e10cSrcweir 	if ( pDPObj && pDocSh )
1203*cdf0e10cSrcweir 	{
1204*cdf0e10cSrcweir         ScDBDocFunc aFunc(*pDocSh);
1205*cdf0e10cSrcweir         aFunc.DataPilotUpdate( pDPObj, pDPObject, sal_True, sal_True );
1206*cdf0e10cSrcweir     }
1207*cdf0e10cSrcweir }
1208*cdf0e10cSrcweir 
1209*cdf0e10cSrcweir // "rest of XDataPilotDescriptor"
1210*cdf0e10cSrcweir 
1211*cdf0e10cSrcweir OUString SAL_CALL ScDataPilotTableObj::getName() throw(RuntimeException)
1212*cdf0e10cSrcweir {
1213*cdf0e10cSrcweir 	ScUnoGuard aGuard;
1214*cdf0e10cSrcweir 	ScDPObject* pDPObj = lcl_GetDPObject(GetDocShell(), nTab, aName);
1215*cdf0e10cSrcweir 	if (pDPObj)
1216*cdf0e10cSrcweir 		return pDPObj->GetName();
1217*cdf0e10cSrcweir     return OUString();
1218*cdf0e10cSrcweir }
1219*cdf0e10cSrcweir 
1220*cdf0e10cSrcweir void SAL_CALL ScDataPilotTableObj::setName( const OUString& aNewName )
1221*cdf0e10cSrcweir                                                 throw(RuntimeException)
1222*cdf0e10cSrcweir {
1223*cdf0e10cSrcweir 	ScUnoGuard aGuard;
1224*cdf0e10cSrcweir 	ScDPObject* pDPObj = lcl_GetDPObject(GetDocShell(), nTab, aName);
1225*cdf0e10cSrcweir 	if (pDPObj)
1226*cdf0e10cSrcweir 	{
1227*cdf0e10cSrcweir 		//!	test for existing names !!!
1228*cdf0e10cSrcweir 
1229*cdf0e10cSrcweir 		String aString(aNewName);
1230*cdf0e10cSrcweir 		pDPObj->SetName( aString );		//! Undo - DBDocFunc ???
1231*cdf0e10cSrcweir 		aName = aString;
1232*cdf0e10cSrcweir 
1233*cdf0e10cSrcweir 		//	DataPilotUpdate would do too much (output table is not changed)
1234*cdf0e10cSrcweir 		GetDocShell()->SetDocumentModified();
1235*cdf0e10cSrcweir 	}
1236*cdf0e10cSrcweir }
1237*cdf0e10cSrcweir 
1238*cdf0e10cSrcweir OUString SAL_CALL ScDataPilotTableObj::getTag() throw(RuntimeException)
1239*cdf0e10cSrcweir {
1240*cdf0e10cSrcweir 	ScUnoGuard aGuard;
1241*cdf0e10cSrcweir 	ScDPObject* pDPObj = lcl_GetDPObject(GetDocShell(), nTab, aName);
1242*cdf0e10cSrcweir 	if (pDPObj)
1243*cdf0e10cSrcweir 		return pDPObj->GetTag();
1244*cdf0e10cSrcweir     return OUString();
1245*cdf0e10cSrcweir }
1246*cdf0e10cSrcweir 
1247*cdf0e10cSrcweir void SAL_CALL ScDataPilotTableObj::setTag( const OUString& aNewTag )
1248*cdf0e10cSrcweir                                                 throw(RuntimeException)
1249*cdf0e10cSrcweir {
1250*cdf0e10cSrcweir 	ScUnoGuard aGuard;
1251*cdf0e10cSrcweir 	ScDPObject* pDPObj = lcl_GetDPObject(GetDocShell(), nTab, aName);
1252*cdf0e10cSrcweir 	if (pDPObj)
1253*cdf0e10cSrcweir 	{
1254*cdf0e10cSrcweir 		String aString(aNewTag);
1255*cdf0e10cSrcweir 		pDPObj->SetTag( aString );		//! Undo - DBDocFunc ???
1256*cdf0e10cSrcweir 
1257*cdf0e10cSrcweir 		//	DataPilotUpdate would do too much (output table is not changed)
1258*cdf0e10cSrcweir 		GetDocShell()->SetDocumentModified();
1259*cdf0e10cSrcweir 	}
1260*cdf0e10cSrcweir }
1261*cdf0e10cSrcweir 
1262*cdf0e10cSrcweir // XDataPilotTable
1263*cdf0e10cSrcweir 
1264*cdf0e10cSrcweir CellRangeAddress SAL_CALL ScDataPilotTableObj::getOutputRange() throw(RuntimeException)
1265*cdf0e10cSrcweir {
1266*cdf0e10cSrcweir 	ScUnoGuard aGuard;
1267*cdf0e10cSrcweir     CellRangeAddress aRet;
1268*cdf0e10cSrcweir 	ScDPObject* pDPObj = lcl_GetDPObject(GetDocShell(), nTab, aName);
1269*cdf0e10cSrcweir 	if (pDPObj)
1270*cdf0e10cSrcweir 	{
1271*cdf0e10cSrcweir 		ScRange aRange(pDPObj->GetOutRange());
1272*cdf0e10cSrcweir 		aRet.Sheet		 = aRange.aStart.Tab();
1273*cdf0e10cSrcweir 		aRet.StartColumn = aRange.aStart.Col();
1274*cdf0e10cSrcweir 		aRet.StartRow	 = aRange.aStart.Row();
1275*cdf0e10cSrcweir 		aRet.EndColumn	 = aRange.aEnd.Col();
1276*cdf0e10cSrcweir 		aRet.EndRow		 = aRange.aEnd.Row();
1277*cdf0e10cSrcweir 	}
1278*cdf0e10cSrcweir 	return aRet;
1279*cdf0e10cSrcweir }
1280*cdf0e10cSrcweir 
1281*cdf0e10cSrcweir sal_uLong RefreshDPObject( ScDPObject *pDPObj, ScDocument *pDoc, ScDocShell *pDocSh, sal_Bool bRecord, sal_Bool bApi );
1282*cdf0e10cSrcweir 
1283*cdf0e10cSrcweir void SAL_CALL ScDataPilotTableObj::refresh() throw(RuntimeException)
1284*cdf0e10cSrcweir {
1285*cdf0e10cSrcweir 	ScUnoGuard aGuard;
1286*cdf0e10cSrcweir 	if( ScDPObject* pDPObj = lcl_GetDPObject(GetDocShell(), nTab, aName) )
1287*cdf0e10cSrcweir 		RefreshDPObject( pDPObj, NULL, GetDocShell(), sal_True, sal_True );
1288*cdf0e10cSrcweir 	//if (pDPObj)
1289*cdf0e10cSrcweir 	//{
1290*cdf0e10cSrcweir 	//	ScDPObject* pNew = new ScDPObject(*pDPObj);
1291*cdf0e10cSrcweir 	//	ScDBDocFunc aFunc(*GetDocShell());
1292*cdf0e10cSrcweir 	//	aFunc.DataPilotUpdate( pDPObj, pNew, sal_True, sal_True );
1293*cdf0e10cSrcweir 	//	delete pNew;		// DataPilotUpdate copies settings from "new" object
1294*cdf0e10cSrcweir 	//}
1295*cdf0e10cSrcweir 
1296*cdf0e10cSrcweir }
1297*cdf0e10cSrcweir 
1298*cdf0e10cSrcweir Sequence< Sequence<Any> > SAL_CALL ScDataPilotTableObj::getDrillDownData(const CellAddress& aAddr)
1299*cdf0e10cSrcweir     throw (RuntimeException)
1300*cdf0e10cSrcweir {
1301*cdf0e10cSrcweir     ScUnoGuard aGuard;
1302*cdf0e10cSrcweir     Sequence< Sequence<Any> > aTabData;
1303*cdf0e10cSrcweir     ScAddress aAddr2(static_cast<SCCOL>(aAddr.Column), static_cast<SCROW>(aAddr.Row), aAddr.Sheet);
1304*cdf0e10cSrcweir     ScDPObject* pObj = GetDPObject();
1305*cdf0e10cSrcweir     if (!pObj)
1306*cdf0e10cSrcweir         throw RuntimeException();
1307*cdf0e10cSrcweir 
1308*cdf0e10cSrcweir     pObj->GetDrillDownData(aAddr2, aTabData);
1309*cdf0e10cSrcweir     return aTabData;
1310*cdf0e10cSrcweir }
1311*cdf0e10cSrcweir 
1312*cdf0e10cSrcweir DataPilotTablePositionData SAL_CALL ScDataPilotTableObj::getPositionData(const CellAddress& aAddr)
1313*cdf0e10cSrcweir     throw (RuntimeException)
1314*cdf0e10cSrcweir {
1315*cdf0e10cSrcweir     ScUnoGuard aGuard;
1316*cdf0e10cSrcweir     DataPilotTablePositionData aPosData;
1317*cdf0e10cSrcweir     ScAddress aAddr2(static_cast<SCCOL>(aAddr.Column), static_cast<SCROW>(aAddr.Row), aAddr.Sheet);
1318*cdf0e10cSrcweir     ScDPObject* pObj = GetDPObject();
1319*cdf0e10cSrcweir     if (!pObj)
1320*cdf0e10cSrcweir         throw RuntimeException();
1321*cdf0e10cSrcweir 
1322*cdf0e10cSrcweir     pObj->GetPositionData(aAddr2, aPosData);
1323*cdf0e10cSrcweir     return aPosData;
1324*cdf0e10cSrcweir }
1325*cdf0e10cSrcweir 
1326*cdf0e10cSrcweir void SAL_CALL ScDataPilotTableObj::insertDrillDownSheet(const CellAddress& aAddr)
1327*cdf0e10cSrcweir     throw (RuntimeException)
1328*cdf0e10cSrcweir {
1329*cdf0e10cSrcweir     ScUnoGuard aGuard;
1330*cdf0e10cSrcweir     ScDPObject* pDPObj = GetDPObject();
1331*cdf0e10cSrcweir     if (!pDPObj)
1332*cdf0e10cSrcweir         throw RuntimeException();
1333*cdf0e10cSrcweir 
1334*cdf0e10cSrcweir     Sequence<DataPilotFieldFilter> aFilters;
1335*cdf0e10cSrcweir     pDPObj->GetDataFieldPositionData(
1336*cdf0e10cSrcweir         ScAddress(static_cast<SCCOL>(aAddr.Column), static_cast<SCROW>(aAddr.Row), aAddr.Sheet), aFilters);
1337*cdf0e10cSrcweir     GetDocShell()->GetBestViewShell()->ShowDataPilotSourceData(*pDPObj, aFilters);
1338*cdf0e10cSrcweir }
1339*cdf0e10cSrcweir 
1340*cdf0e10cSrcweir CellRangeAddress SAL_CALL ScDataPilotTableObj::getOutputRangeByType( sal_Int32 nType )
1341*cdf0e10cSrcweir     throw (IllegalArgumentException, RuntimeException)
1342*cdf0e10cSrcweir {
1343*cdf0e10cSrcweir     ScUnoGuard aGuard;
1344*cdf0e10cSrcweir     if (nType < 0 || nType > DataPilotOutputRangeType::RESULT)
1345*cdf0e10cSrcweir         throw IllegalArgumentException();
1346*cdf0e10cSrcweir 
1347*cdf0e10cSrcweir     CellRangeAddress aRet;
1348*cdf0e10cSrcweir     if (ScDPObject* pDPObj = lcl_GetDPObject(GetDocShell(), nTab, aName))
1349*cdf0e10cSrcweir         ScUnoConversion::FillApiRange( aRet, pDPObj->GetOutputRangeByType( nType ) );
1350*cdf0e10cSrcweir     return aRet;
1351*cdf0e10cSrcweir }
1352*cdf0e10cSrcweir 
1353*cdf0e10cSrcweir void SAL_CALL ScDataPilotTableObj::addModifyListener( const uno::Reference<util::XModifyListener>& aListener )
1354*cdf0e10cSrcweir     throw (uno::RuntimeException)
1355*cdf0e10cSrcweir {
1356*cdf0e10cSrcweir     ScUnoGuard aGuard;
1357*cdf0e10cSrcweir 
1358*cdf0e10cSrcweir     uno::Reference<util::XModifyListener> *pObj = new uno::Reference<util::XModifyListener>( aListener );
1359*cdf0e10cSrcweir     aModifyListeners.Insert( pObj, aModifyListeners.Count() );
1360*cdf0e10cSrcweir 
1361*cdf0e10cSrcweir     if ( aModifyListeners.Count() == 1 )
1362*cdf0e10cSrcweir     {
1363*cdf0e10cSrcweir         acquire();  // don't lose this object (one ref for all listeners)
1364*cdf0e10cSrcweir     }
1365*cdf0e10cSrcweir }
1366*cdf0e10cSrcweir 
1367*cdf0e10cSrcweir void SAL_CALL ScDataPilotTableObj::removeModifyListener( const uno::Reference<util::XModifyListener>& aListener )
1368*cdf0e10cSrcweir     throw (uno::RuntimeException)
1369*cdf0e10cSrcweir {
1370*cdf0e10cSrcweir     ScUnoGuard aGuard;
1371*cdf0e10cSrcweir 
1372*cdf0e10cSrcweir     acquire();      // in case the listeners have the last ref - released below
1373*cdf0e10cSrcweir 
1374*cdf0e10cSrcweir     sal_uInt16 nCount = aModifyListeners.Count();
1375*cdf0e10cSrcweir     for ( sal_uInt16 n=nCount; n--; )
1376*cdf0e10cSrcweir     {
1377*cdf0e10cSrcweir         uno::Reference<util::XModifyListener> *pObj = aModifyListeners[n];
1378*cdf0e10cSrcweir         if ( *pObj == aListener )
1379*cdf0e10cSrcweir         {
1380*cdf0e10cSrcweir             aModifyListeners.DeleteAndDestroy( n );
1381*cdf0e10cSrcweir 
1382*cdf0e10cSrcweir             if ( aModifyListeners.Count() == 0 )
1383*cdf0e10cSrcweir             {
1384*cdf0e10cSrcweir                 release();      // release the ref for the listeners
1385*cdf0e10cSrcweir             }
1386*cdf0e10cSrcweir 
1387*cdf0e10cSrcweir             break;
1388*cdf0e10cSrcweir         }
1389*cdf0e10cSrcweir     }
1390*cdf0e10cSrcweir 
1391*cdf0e10cSrcweir     release();      // might delete this object
1392*cdf0e10cSrcweir }
1393*cdf0e10cSrcweir 
1394*cdf0e10cSrcweir void ScDataPilotTableObj::Notify( SfxBroadcaster& rBC, const SfxHint& rHint )
1395*cdf0e10cSrcweir {
1396*cdf0e10cSrcweir     if ( rHint.ISA(ScDataPilotModifiedHint) &&
1397*cdf0e10cSrcweir          static_cast<const ScDataPilotModifiedHint&>(rHint).GetName() == aName )
1398*cdf0e10cSrcweir     {
1399*cdf0e10cSrcweir         Refreshed_Impl();
1400*cdf0e10cSrcweir     }
1401*cdf0e10cSrcweir     else if ( rHint.ISA( ScUpdateRefHint ) )
1402*cdf0e10cSrcweir     {
1403*cdf0e10cSrcweir         ScRange aRange( 0, 0, nTab );
1404*cdf0e10cSrcweir         ScRangeList aRanges;
1405*cdf0e10cSrcweir         aRanges.Append( aRange );
1406*cdf0e10cSrcweir         const ScUpdateRefHint& rRef = static_cast< const ScUpdateRefHint& >( rHint );
1407*cdf0e10cSrcweir         if ( aRanges.UpdateReference( rRef.GetMode(), GetDocShell()->GetDocument(), rRef.GetRange(),
1408*cdf0e10cSrcweir                  rRef.GetDx(), rRef.GetDy(), rRef.GetDz() ) &&
1409*cdf0e10cSrcweir              aRanges.Count() == 1 )
1410*cdf0e10cSrcweir         {
1411*cdf0e10cSrcweir             const ScRange* pRange = aRanges.GetObject( 0 );
1412*cdf0e10cSrcweir             if ( pRange )
1413*cdf0e10cSrcweir             {
1414*cdf0e10cSrcweir                 nTab = pRange->aStart.Tab();
1415*cdf0e10cSrcweir             }
1416*cdf0e10cSrcweir         }
1417*cdf0e10cSrcweir     }
1418*cdf0e10cSrcweir 
1419*cdf0e10cSrcweir     ScDataPilotDescriptorBase::Notify( rBC, rHint );
1420*cdf0e10cSrcweir }
1421*cdf0e10cSrcweir 
1422*cdf0e10cSrcweir void ScDataPilotTableObj::Refreshed_Impl()
1423*cdf0e10cSrcweir {
1424*cdf0e10cSrcweir     lang::EventObject aEvent;
1425*cdf0e10cSrcweir     aEvent.Source.set((cppu::OWeakObject*)this);
1426*cdf0e10cSrcweir 
1427*cdf0e10cSrcweir     // the EventObject holds a Ref to this object until after the listener calls
1428*cdf0e10cSrcweir 
1429*cdf0e10cSrcweir     ScDocument* pDoc = GetDocShell()->GetDocument();
1430*cdf0e10cSrcweir     for ( sal_uInt16 n=0; n<aModifyListeners.Count(); n++ )
1431*cdf0e10cSrcweir         pDoc->AddUnoListenerCall( *aModifyListeners[n], aEvent );
1432*cdf0e10cSrcweir }
1433*cdf0e10cSrcweir 
1434*cdf0e10cSrcweir // ============================================================================
1435*cdf0e10cSrcweir 
1436*cdf0e10cSrcweir ScDataPilotDescriptor::ScDataPilotDescriptor(ScDocShell* pDocSh) :
1437*cdf0e10cSrcweir 	ScDataPilotDescriptorBase( pDocSh ),
1438*cdf0e10cSrcweir     mpDPObject(new ScDPObject(pDocSh ? pDocSh->GetDocument() : NULL) )
1439*cdf0e10cSrcweir {
1440*cdf0e10cSrcweir     mpDPObject->SetAlive(sal_True);
1441*cdf0e10cSrcweir     ScDPSaveData aSaveData;
1442*cdf0e10cSrcweir     // set defaults like in ScPivotParam constructor
1443*cdf0e10cSrcweir  	aSaveData.SetColumnGrand( sal_True );
1444*cdf0e10cSrcweir 	aSaveData.SetRowGrand( sal_True );
1445*cdf0e10cSrcweir 	aSaveData.SetIgnoreEmptyRows( sal_False );
1446*cdf0e10cSrcweir 	aSaveData.SetRepeatIfEmpty( sal_False );
1447*cdf0e10cSrcweir     mpDPObject->SetSaveData(aSaveData);
1448*cdf0e10cSrcweir     ScSheetSourceDesc aSheetDesc;
1449*cdf0e10cSrcweir     mpDPObject->SetSheetDesc(aSheetDesc);
1450*cdf0e10cSrcweir     mpDPObject->GetSource();
1451*cdf0e10cSrcweir }
1452*cdf0e10cSrcweir 
1453*cdf0e10cSrcweir ScDataPilotDescriptor::~ScDataPilotDescriptor()
1454*cdf0e10cSrcweir {
1455*cdf0e10cSrcweir     delete mpDPObject;
1456*cdf0e10cSrcweir }
1457*cdf0e10cSrcweir 
1458*cdf0e10cSrcweir ScDPObject* ScDataPilotDescriptor::GetDPObject() const
1459*cdf0e10cSrcweir {
1460*cdf0e10cSrcweir     return mpDPObject;
1461*cdf0e10cSrcweir }
1462*cdf0e10cSrcweir 
1463*cdf0e10cSrcweir void ScDataPilotDescriptor::SetDPObject( ScDPObject* pDPObject )
1464*cdf0e10cSrcweir {
1465*cdf0e10cSrcweir     if (mpDPObject != pDPObject)
1466*cdf0e10cSrcweir     {
1467*cdf0e10cSrcweir         delete mpDPObject;
1468*cdf0e10cSrcweir         mpDPObject = pDPObject;
1469*cdf0e10cSrcweir         DBG_ERROR("replace DPObject should not happen");
1470*cdf0e10cSrcweir     }
1471*cdf0e10cSrcweir }
1472*cdf0e10cSrcweir 
1473*cdf0e10cSrcweir // "rest of XDataPilotDescriptor"
1474*cdf0e10cSrcweir 
1475*cdf0e10cSrcweir OUString SAL_CALL ScDataPilotDescriptor::getName() throw(RuntimeException)
1476*cdf0e10cSrcweir {
1477*cdf0e10cSrcweir 	ScUnoGuard aGuard;
1478*cdf0e10cSrcweir 	return mpDPObject->GetName();
1479*cdf0e10cSrcweir }
1480*cdf0e10cSrcweir 
1481*cdf0e10cSrcweir void SAL_CALL ScDataPilotDescriptor::setName( const OUString& aNewName )
1482*cdf0e10cSrcweir                                                 throw(RuntimeException)
1483*cdf0e10cSrcweir {
1484*cdf0e10cSrcweir 	ScUnoGuard aGuard;
1485*cdf0e10cSrcweir 	mpDPObject->SetName( aNewName );
1486*cdf0e10cSrcweir }
1487*cdf0e10cSrcweir 
1488*cdf0e10cSrcweir OUString SAL_CALL ScDataPilotDescriptor::getTag() throw(RuntimeException)
1489*cdf0e10cSrcweir {
1490*cdf0e10cSrcweir 	ScUnoGuard aGuard;
1491*cdf0e10cSrcweir 	return mpDPObject->GetTag();
1492*cdf0e10cSrcweir }
1493*cdf0e10cSrcweir 
1494*cdf0e10cSrcweir void SAL_CALL ScDataPilotDescriptor::setTag( const OUString& aNewTag )
1495*cdf0e10cSrcweir                                                 throw(RuntimeException)
1496*cdf0e10cSrcweir {
1497*cdf0e10cSrcweir 	ScUnoGuard aGuard;
1498*cdf0e10cSrcweir 	mpDPObject->SetTag( aNewTag );
1499*cdf0e10cSrcweir }
1500*cdf0e10cSrcweir 
1501*cdf0e10cSrcweir // ============================================================================
1502*cdf0e10cSrcweir 
1503*cdf0e10cSrcweir ScDataPilotChildObjBase::ScDataPilotChildObjBase( ScDataPilotDescriptorBase& rParent ) :
1504*cdf0e10cSrcweir     mrParent( rParent )
1505*cdf0e10cSrcweir {
1506*cdf0e10cSrcweir     mrParent.acquire();
1507*cdf0e10cSrcweir }
1508*cdf0e10cSrcweir 
1509*cdf0e10cSrcweir ScDataPilotChildObjBase::ScDataPilotChildObjBase( ScDataPilotDescriptorBase& rParent, const ScFieldIdentifier& rFieldId ) :
1510*cdf0e10cSrcweir     mrParent( rParent ),
1511*cdf0e10cSrcweir     maFieldId( rFieldId )
1512*cdf0e10cSrcweir {
1513*cdf0e10cSrcweir     mrParent.acquire();
1514*cdf0e10cSrcweir }
1515*cdf0e10cSrcweir 
1516*cdf0e10cSrcweir ScDataPilotChildObjBase::~ScDataPilotChildObjBase()
1517*cdf0e10cSrcweir {
1518*cdf0e10cSrcweir     mrParent.release();
1519*cdf0e10cSrcweir }
1520*cdf0e10cSrcweir 
1521*cdf0e10cSrcweir ScDPObject* ScDataPilotChildObjBase::GetDPObject() const
1522*cdf0e10cSrcweir {
1523*cdf0e10cSrcweir     return mrParent.GetDPObject();
1524*cdf0e10cSrcweir }
1525*cdf0e10cSrcweir 
1526*cdf0e10cSrcweir void ScDataPilotChildObjBase::SetDPObject( ScDPObject* pDPObject )
1527*cdf0e10cSrcweir {
1528*cdf0e10cSrcweir     mrParent.SetDPObject( pDPObject );
1529*cdf0e10cSrcweir }
1530*cdf0e10cSrcweir 
1531*cdf0e10cSrcweir ScDPSaveDimension* ScDataPilotChildObjBase::GetDPDimension( ScDPObject** ppDPObject ) const
1532*cdf0e10cSrcweir {
1533*cdf0e10cSrcweir     if( ScDPObject* pDPObj = GetDPObject() )
1534*cdf0e10cSrcweir     {
1535*cdf0e10cSrcweir         if( ppDPObject ) *ppDPObject = pDPObj;
1536*cdf0e10cSrcweir         if( ScDPSaveData* pSaveData = pDPObj->GetSaveData() )
1537*cdf0e10cSrcweir         {
1538*cdf0e10cSrcweir             if( maFieldId.mbDataLayout )
1539*cdf0e10cSrcweir                 return pSaveData->GetDataLayoutDimension();
1540*cdf0e10cSrcweir 
1541*cdf0e10cSrcweir             if( maFieldId.mnFieldIdx == 0 )
1542*cdf0e10cSrcweir                 return pSaveData->GetDimensionByName( maFieldId.maFieldName );
1543*cdf0e10cSrcweir 
1544*cdf0e10cSrcweir             // find dimension with specified index (search in duplicated dimensions)
1545*cdf0e10cSrcweir             String aFieldName = maFieldId.maFieldName;  // needed for comparison
1546*cdf0e10cSrcweir             const List& rDimensions = pSaveData->GetDimensions();
1547*cdf0e10cSrcweir             sal_uLong nDimCount = rDimensions.Count();
1548*cdf0e10cSrcweir             sal_Int32 nFoundIdx = 0;
1549*cdf0e10cSrcweir             for( sal_uLong nDim = 0; nDim < nDimCount; ++nDim )
1550*cdf0e10cSrcweir             {
1551*cdf0e10cSrcweir                 ScDPSaveDimension* pDim = static_cast< ScDPSaveDimension* >( rDimensions.GetObject( nDim ) );
1552*cdf0e10cSrcweir                 if( !pDim->IsDataLayout() && (pDim->GetName() == aFieldName) )
1553*cdf0e10cSrcweir                 {
1554*cdf0e10cSrcweir                     if( nFoundIdx == maFieldId.mnFieldIdx )
1555*cdf0e10cSrcweir                         return pDim;
1556*cdf0e10cSrcweir                     ++nFoundIdx;
1557*cdf0e10cSrcweir                 }
1558*cdf0e10cSrcweir             }
1559*cdf0e10cSrcweir         }
1560*cdf0e10cSrcweir     }
1561*cdf0e10cSrcweir     return 0;
1562*cdf0e10cSrcweir }
1563*cdf0e10cSrcweir 
1564*cdf0e10cSrcweir sal_Int32 ScDataPilotChildObjBase::GetMemberCount() const
1565*cdf0e10cSrcweir {
1566*cdf0e10cSrcweir     sal_Int32 nRet = 0;
1567*cdf0e10cSrcweir     Reference<XNameAccess> xMembersNA = GetMembers();
1568*cdf0e10cSrcweir     if (xMembersNA.is())
1569*cdf0e10cSrcweir     {
1570*cdf0e10cSrcweir         Reference< XIndexAccess > xMembersIA( new ScNameToIndexAccess( xMembersNA ) );
1571*cdf0e10cSrcweir         nRet = xMembersIA->getCount();
1572*cdf0e10cSrcweir     }
1573*cdf0e10cSrcweir     return nRet;
1574*cdf0e10cSrcweir }
1575*cdf0e10cSrcweir 
1576*cdf0e10cSrcweir Reference< XNameAccess > ScDataPilotChildObjBase::GetMembers() const
1577*cdf0e10cSrcweir {
1578*cdf0e10cSrcweir     Reference< XNameAccess > xMembersNA;
1579*cdf0e10cSrcweir     if( ScDPObject* pDPObj = GetDPObject() )
1580*cdf0e10cSrcweir         pDPObj->GetMembersNA( lcl_GetObjectIndex( pDPObj, maFieldId ), xMembersNA );
1581*cdf0e10cSrcweir     return xMembersNA;
1582*cdf0e10cSrcweir }
1583*cdf0e10cSrcweir 
1584*cdf0e10cSrcweir // ============================================================================
1585*cdf0e10cSrcweir 
1586*cdf0e10cSrcweir ScDataPilotFieldsObj::ScDataPilotFieldsObj( ScDataPilotDescriptorBase& rParent ) :
1587*cdf0e10cSrcweir     ScDataPilotChildObjBase( rParent )
1588*cdf0e10cSrcweir {
1589*cdf0e10cSrcweir }
1590*cdf0e10cSrcweir 
1591*cdf0e10cSrcweir ScDataPilotFieldsObj::ScDataPilotFieldsObj( ScDataPilotDescriptorBase& rParent, DataPilotFieldOrientation eOrient ) :
1592*cdf0e10cSrcweir     ScDataPilotChildObjBase( rParent ),
1593*cdf0e10cSrcweir     maOrient( eOrient )
1594*cdf0e10cSrcweir {
1595*cdf0e10cSrcweir }
1596*cdf0e10cSrcweir 
1597*cdf0e10cSrcweir ScDataPilotFieldsObj::~ScDataPilotFieldsObj()
1598*cdf0e10cSrcweir {
1599*cdf0e10cSrcweir }
1600*cdf0e10cSrcweir 
1601*cdf0e10cSrcweir sal_Int32 lcl_GetFieldCount( const Reference<XDimensionsSupplier>& rSource, const Any& rOrient )
1602*cdf0e10cSrcweir {
1603*cdf0e10cSrcweir     sal_Int32 nRet = 0;
1604*cdf0e10cSrcweir 
1605*cdf0e10cSrcweir     Reference<XNameAccess> xDimsName(rSource->getDimensions());
1606*cdf0e10cSrcweir     Reference<XIndexAccess> xIntDims(new ScNameToIndexAccess( xDimsName ));
1607*cdf0e10cSrcweir 	sal_Int32 nIntCount = xIntDims->getCount();
1608*cdf0e10cSrcweir     if (rOrient.hasValue())
1609*cdf0e10cSrcweir     {
1610*cdf0e10cSrcweir         // all fields of the specified orientation, including duplicated
1611*cdf0e10cSrcweir         Reference<XPropertySet> xDim;
1612*cdf0e10cSrcweir         for (sal_Int32 i = 0; i < nIntCount; ++i)
1613*cdf0e10cSrcweir         {
1614*cdf0e10cSrcweir             xDim.set(xIntDims->getByIndex(i), UNO_QUERY);
1615*cdf0e10cSrcweir             if (xDim.is() && (xDim->getPropertyValue(OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNO_ORIENTAT))) == rOrient))
1616*cdf0e10cSrcweir                 ++nRet;
1617*cdf0e10cSrcweir         }
1618*cdf0e10cSrcweir     }
1619*cdf0e10cSrcweir     else
1620*cdf0e10cSrcweir     {
1621*cdf0e10cSrcweir         // count all non-duplicated fields
1622*cdf0e10cSrcweir 
1623*cdf0e10cSrcweir         Reference<XPropertySet> xDim;
1624*cdf0e10cSrcweir         for (sal_Int32 i = 0; i < nIntCount; ++i)
1625*cdf0e10cSrcweir         {
1626*cdf0e10cSrcweir             xDim.set(xIntDims->getByIndex(i), UNO_QUERY);
1627*cdf0e10cSrcweir             if ( xDim.is() && !lcl_IsDuplicated( xDim ) )
1628*cdf0e10cSrcweir                 ++nRet;
1629*cdf0e10cSrcweir         }
1630*cdf0e10cSrcweir     }
1631*cdf0e10cSrcweir 
1632*cdf0e10cSrcweir 	return nRet;
1633*cdf0e10cSrcweir }
1634*cdf0e10cSrcweir 
1635*cdf0e10cSrcweir sal_Bool lcl_GetFieldDataByIndex( const Reference<XDimensionsSupplier>& rSource,
1636*cdf0e10cSrcweir                                 const Any& rOrient, SCSIZE nIndex, ScFieldIdentifier& rFieldId )
1637*cdf0e10cSrcweir {
1638*cdf0e10cSrcweir 	sal_Bool bOk = sal_False;
1639*cdf0e10cSrcweir 	SCSIZE nPos = 0;
1640*cdf0e10cSrcweir 	sal_Int32 nDimIndex = 0;
1641*cdf0e10cSrcweir 
1642*cdf0e10cSrcweir     Reference<XNameAccess> xDimsName(rSource->getDimensions());
1643*cdf0e10cSrcweir     Reference<XIndexAccess> xIntDims(new ScNameToIndexAccess( xDimsName ));
1644*cdf0e10cSrcweir 	sal_Int32 nIntCount = xIntDims->getCount();
1645*cdf0e10cSrcweir     Reference<XPropertySet> xDim;
1646*cdf0e10cSrcweir     if (rOrient.hasValue())
1647*cdf0e10cSrcweir     {
1648*cdf0e10cSrcweir         sal_Int32 i = 0;
1649*cdf0e10cSrcweir         while (i < nIntCount && !bOk)
1650*cdf0e10cSrcweir         {
1651*cdf0e10cSrcweir             xDim.set(xIntDims->getByIndex(i), UNO_QUERY);
1652*cdf0e10cSrcweir             if (xDim.is() && (xDim->getPropertyValue(OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNO_ORIENTAT))) == rOrient))
1653*cdf0e10cSrcweir             {
1654*cdf0e10cSrcweir                 if (nPos == nIndex)
1655*cdf0e10cSrcweir                 {
1656*cdf0e10cSrcweir                     bOk = sal_True;
1657*cdf0e10cSrcweir                     nDimIndex = i;
1658*cdf0e10cSrcweir                 }
1659*cdf0e10cSrcweir                 else
1660*cdf0e10cSrcweir                     ++nPos;
1661*cdf0e10cSrcweir             }
1662*cdf0e10cSrcweir             ++i;
1663*cdf0e10cSrcweir         }
1664*cdf0e10cSrcweir     }
1665*cdf0e10cSrcweir     else
1666*cdf0e10cSrcweir     {
1667*cdf0e10cSrcweir         sal_Int32 i = 0;
1668*cdf0e10cSrcweir         while (i < nIntCount && !bOk)
1669*cdf0e10cSrcweir         {
1670*cdf0e10cSrcweir             xDim.set(xIntDims->getByIndex(i), UNO_QUERY);
1671*cdf0e10cSrcweir             if ( xDim.is() && !lcl_IsDuplicated( xDim ) )
1672*cdf0e10cSrcweir             {
1673*cdf0e10cSrcweir                 if (nPos == nIndex)
1674*cdf0e10cSrcweir                 {
1675*cdf0e10cSrcweir                     bOk = sal_True;
1676*cdf0e10cSrcweir                     nDimIndex = i;
1677*cdf0e10cSrcweir                 }
1678*cdf0e10cSrcweir                 else
1679*cdf0e10cSrcweir                     ++nPos;
1680*cdf0e10cSrcweir             }
1681*cdf0e10cSrcweir             ++i;
1682*cdf0e10cSrcweir         }
1683*cdf0e10cSrcweir     }
1684*cdf0e10cSrcweir 
1685*cdf0e10cSrcweir     if ( bOk )
1686*cdf0e10cSrcweir     {
1687*cdf0e10cSrcweir         xDim.set( xIntDims->getByIndex(nDimIndex), UNO_QUERY );
1688*cdf0e10cSrcweir         Reference<XNamed> xDimName( xDim, UNO_QUERY );
1689*cdf0e10cSrcweir         if ( xDimName.is() )
1690*cdf0e10cSrcweir         {
1691*cdf0e10cSrcweir             OUString sOriginalName( lcl_GetOriginalName( xDimName ) );
1692*cdf0e10cSrcweir             rFieldId.maFieldName = sOriginalName;
1693*cdf0e10cSrcweir             rFieldId.mbDataLayout = ScUnoHelpFunctions::GetBoolProperty( xDim,
1694*cdf0e10cSrcweir                         OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNO_ISDATALA)) );
1695*cdf0e10cSrcweir 
1696*cdf0e10cSrcweir             sal_Int32 nRepeat = 0;
1697*cdf0e10cSrcweir             if ( rOrient.hasValue() && lcl_IsDuplicated( xDim ) )
1698*cdf0e10cSrcweir             {
1699*cdf0e10cSrcweir                 // find the repeat count
1700*cdf0e10cSrcweir                 // (this relies on the original dimension always being before the duplicates)
1701*cdf0e10cSrcweir 
1702*cdf0e10cSrcweir                 Reference<XNamed> xPrevName;
1703*cdf0e10cSrcweir                 for (sal_Int32 i = 0; i < nDimIndex; ++i)
1704*cdf0e10cSrcweir                 {
1705*cdf0e10cSrcweir                     xPrevName.set( xIntDims->getByIndex(i), UNO_QUERY );
1706*cdf0e10cSrcweir                     if ( xPrevName.is() && lcl_GetOriginalName( xPrevName ) == sOriginalName )
1707*cdf0e10cSrcweir                         ++nRepeat;
1708*cdf0e10cSrcweir                 }
1709*cdf0e10cSrcweir             }
1710*cdf0e10cSrcweir             rFieldId.mnFieldIdx = nRepeat;
1711*cdf0e10cSrcweir         }
1712*cdf0e10cSrcweir         else
1713*cdf0e10cSrcweir             bOk = sal_False;
1714*cdf0e10cSrcweir     }
1715*cdf0e10cSrcweir 
1716*cdf0e10cSrcweir 	return bOk;
1717*cdf0e10cSrcweir }
1718*cdf0e10cSrcweir 
1719*cdf0e10cSrcweir sal_Bool lcl_GetFieldDataByName( ScDPObject* pDPObj, const OUString& rFieldName, ScFieldIdentifier& rFieldId )
1720*cdf0e10cSrcweir {
1721*cdf0e10cSrcweir     // "By name" is always the first match.
1722*cdf0e10cSrcweir     // The name "Data" always refers to the data layout field.
1723*cdf0e10cSrcweir     rFieldId.maFieldName = rFieldName;
1724*cdf0e10cSrcweir     rFieldId.mnFieldIdx = 0;
1725*cdf0e10cSrcweir     rFieldId.mbDataLayout = rFieldName.equalsAscii( SC_DATALAYOUT_NAME );
1726*cdf0e10cSrcweir 
1727*cdf0e10cSrcweir     pDPObj->GetSource();    // IsDimNameInUse doesn't update source data
1728*cdf0e10cSrcweir 
1729*cdf0e10cSrcweir     // check if the named field exists (not for data layout)
1730*cdf0e10cSrcweir     return rFieldId.mbDataLayout || pDPObj->IsDimNameInUse( rFieldName );
1731*cdf0e10cSrcweir }
1732*cdf0e10cSrcweir 
1733*cdf0e10cSrcweir // XDataPilotFields
1734*cdf0e10cSrcweir 
1735*cdf0e10cSrcweir ScDataPilotFieldObj* ScDataPilotFieldsObj::GetObjectByIndex_Impl( sal_Int32 nIndex ) const
1736*cdf0e10cSrcweir {
1737*cdf0e10cSrcweir // TODO
1738*cdf0e10cSrcweir     if (ScDPObject* pObj = GetDPObject())
1739*cdf0e10cSrcweir     {
1740*cdf0e10cSrcweir         ScFieldIdentifier aFieldId;
1741*cdf0e10cSrcweir         if (lcl_GetFieldDataByIndex( pObj->GetSource(), maOrient, nIndex, aFieldId ))
1742*cdf0e10cSrcweir             return new ScDataPilotFieldObj( mrParent, aFieldId, maOrient );
1743*cdf0e10cSrcweir     }
1744*cdf0e10cSrcweir     return 0;
1745*cdf0e10cSrcweir }
1746*cdf0e10cSrcweir 
1747*cdf0e10cSrcweir ScDataPilotFieldObj* ScDataPilotFieldsObj::GetObjectByName_Impl(const OUString& aName) const
1748*cdf0e10cSrcweir {
1749*cdf0e10cSrcweir     if (ScDPObject* pDPObj = GetDPObject())
1750*cdf0e10cSrcweir     {
1751*cdf0e10cSrcweir         ScFieldIdentifier aFieldId;
1752*cdf0e10cSrcweir         if (lcl_GetFieldDataByName( pDPObj, aName, aFieldId ))
1753*cdf0e10cSrcweir             return new ScDataPilotFieldObj( mrParent, aFieldId, maOrient );
1754*cdf0e10cSrcweir     }
1755*cdf0e10cSrcweir     return 0;
1756*cdf0e10cSrcweir }
1757*cdf0e10cSrcweir 
1758*cdf0e10cSrcweir // XEnumerationAccess
1759*cdf0e10cSrcweir 
1760*cdf0e10cSrcweir Reference<XEnumeration> SAL_CALL ScDataPilotFieldsObj::createEnumeration()
1761*cdf0e10cSrcweir                                                     throw(RuntimeException)
1762*cdf0e10cSrcweir {
1763*cdf0e10cSrcweir 	ScUnoGuard aGuard;
1764*cdf0e10cSrcweir     return new ScIndexEnumeration(this, OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.sheet.DataPilotFieldsEnumeration")));
1765*cdf0e10cSrcweir }
1766*cdf0e10cSrcweir 
1767*cdf0e10cSrcweir // XIndexAccess
1768*cdf0e10cSrcweir 
1769*cdf0e10cSrcweir sal_Int32 SAL_CALL ScDataPilotFieldsObj::getCount() throw(RuntimeException)
1770*cdf0e10cSrcweir {
1771*cdf0e10cSrcweir 	ScUnoGuard aGuard;
1772*cdf0e10cSrcweir // TODO
1773*cdf0e10cSrcweir     ScDPObject* pDPObj = GetDPObject();
1774*cdf0e10cSrcweir     return pDPObj ? lcl_GetFieldCount( pDPObj->GetSource(), maOrient ) : 0;
1775*cdf0e10cSrcweir }
1776*cdf0e10cSrcweir 
1777*cdf0e10cSrcweir Any SAL_CALL ScDataPilotFieldsObj::getByIndex( sal_Int32 nIndex )
1778*cdf0e10cSrcweir         throw(IndexOutOfBoundsException, WrappedTargetException, RuntimeException)
1779*cdf0e10cSrcweir {
1780*cdf0e10cSrcweir 	ScUnoGuard aGuard;
1781*cdf0e10cSrcweir     Reference< XPropertySet > xField( GetObjectByIndex_Impl( nIndex ) );
1782*cdf0e10cSrcweir     if (!xField.is())
1783*cdf0e10cSrcweir         throw IndexOutOfBoundsException();
1784*cdf0e10cSrcweir     return Any( xField );
1785*cdf0e10cSrcweir }
1786*cdf0e10cSrcweir 
1787*cdf0e10cSrcweir uno::Type SAL_CALL ScDataPilotFieldsObj::getElementType() throw(RuntimeException)
1788*cdf0e10cSrcweir {
1789*cdf0e10cSrcweir 	ScUnoGuard aGuard;
1790*cdf0e10cSrcweir     return getCppuType((Reference<XPropertySet>*)0);
1791*cdf0e10cSrcweir }
1792*cdf0e10cSrcweir 
1793*cdf0e10cSrcweir sal_Bool SAL_CALL ScDataPilotFieldsObj::hasElements() throw(RuntimeException)
1794*cdf0e10cSrcweir {
1795*cdf0e10cSrcweir 	ScUnoGuard aGuard;
1796*cdf0e10cSrcweir 	return ( getCount() != 0 );
1797*cdf0e10cSrcweir }
1798*cdf0e10cSrcweir 
1799*cdf0e10cSrcweir Any SAL_CALL ScDataPilotFieldsObj::getByName( const OUString& aName )
1800*cdf0e10cSrcweir         throw(NoSuchElementException, WrappedTargetException, RuntimeException)
1801*cdf0e10cSrcweir {
1802*cdf0e10cSrcweir 	ScUnoGuard aGuard;
1803*cdf0e10cSrcweir     Reference<XPropertySet> xField(GetObjectByName_Impl(aName));
1804*cdf0e10cSrcweir     if (!xField.is())
1805*cdf0e10cSrcweir         throw NoSuchElementException();
1806*cdf0e10cSrcweir     return Any( xField );
1807*cdf0e10cSrcweir }
1808*cdf0e10cSrcweir 
1809*cdf0e10cSrcweir Sequence<OUString> SAL_CALL ScDataPilotFieldsObj::getElementNames()
1810*cdf0e10cSrcweir                                                 throw(RuntimeException)
1811*cdf0e10cSrcweir {
1812*cdf0e10cSrcweir 	ScUnoGuard aGuard;
1813*cdf0e10cSrcweir // TODO
1814*cdf0e10cSrcweir     if (ScDPObject* pDPObj = GetDPObject())
1815*cdf0e10cSrcweir     {
1816*cdf0e10cSrcweir         Sequence< OUString > aSeq( lcl_GetFieldCount( pDPObj->GetSource(), maOrient ) );
1817*cdf0e10cSrcweir         OUString* pAry = aSeq.getArray();
1818*cdf0e10cSrcweir         const List& rDimensions = pDPObj->GetSaveData()->GetDimensions();
1819*cdf0e10cSrcweir         sal_Int32 nDimCount = rDimensions.Count();
1820*cdf0e10cSrcweir 	    for (sal_Int32 nDim = 0; nDim < nDimCount; nDim++)
1821*cdf0e10cSrcweir 	    {
1822*cdf0e10cSrcweir             ScDPSaveDimension* pDim = (ScDPSaveDimension*)rDimensions.GetObject(nDim);
1823*cdf0e10cSrcweir             if(maOrient.hasValue() && (pDim->GetOrientation() == maOrient.get< DataPilotFieldOrientation >()))
1824*cdf0e10cSrcweir             {
1825*cdf0e10cSrcweir                 *pAry = pDim->GetName();
1826*cdf0e10cSrcweir                 ++pAry;
1827*cdf0e10cSrcweir             }
1828*cdf0e10cSrcweir         }
1829*cdf0e10cSrcweir     	return aSeq;
1830*cdf0e10cSrcweir     }
1831*cdf0e10cSrcweir     return Sequence<OUString>();
1832*cdf0e10cSrcweir }
1833*cdf0e10cSrcweir 
1834*cdf0e10cSrcweir sal_Bool SAL_CALL ScDataPilotFieldsObj::hasByName( const OUString& aName )
1835*cdf0e10cSrcweir                                         throw(RuntimeException)
1836*cdf0e10cSrcweir {
1837*cdf0e10cSrcweir 	ScUnoGuard aGuard;
1838*cdf0e10cSrcweir 
1839*cdf0e10cSrcweir 	return GetObjectByName_Impl(aName) != NULL;
1840*cdf0e10cSrcweir }
1841*cdf0e10cSrcweir 
1842*cdf0e10cSrcweir //------------------------------------------------------------------------
1843*cdf0e10cSrcweir 
1844*cdf0e10cSrcweir ScDataPilotFieldObj::ScDataPilotFieldObj(
1845*cdf0e10cSrcweir         ScDataPilotDescriptorBase& rParent, const ScFieldIdentifier& rFieldId ) :
1846*cdf0e10cSrcweir     ScDataPilotChildObjBase( rParent, rFieldId ),
1847*cdf0e10cSrcweir     maPropSet( lcl_GetDataPilotFieldMap() )
1848*cdf0e10cSrcweir {
1849*cdf0e10cSrcweir }
1850*cdf0e10cSrcweir 
1851*cdf0e10cSrcweir ScDataPilotFieldObj::ScDataPilotFieldObj( ScDataPilotDescriptorBase& rParent,
1852*cdf0e10cSrcweir         const ScFieldIdentifier& rFieldId, const Any& rOrient ) :
1853*cdf0e10cSrcweir     ScDataPilotChildObjBase( rParent, rFieldId ),
1854*cdf0e10cSrcweir     maPropSet( lcl_GetDataPilotFieldMap() ),
1855*cdf0e10cSrcweir     maOrient( rOrient )
1856*cdf0e10cSrcweir {
1857*cdf0e10cSrcweir }
1858*cdf0e10cSrcweir 
1859*cdf0e10cSrcweir ScDataPilotFieldObj::~ScDataPilotFieldObj()
1860*cdf0e10cSrcweir {
1861*cdf0e10cSrcweir }
1862*cdf0e10cSrcweir 
1863*cdf0e10cSrcweir // XNamed
1864*cdf0e10cSrcweir 
1865*cdf0e10cSrcweir OUString SAL_CALL ScDataPilotFieldObj::getName() throw(RuntimeException)
1866*cdf0e10cSrcweir {
1867*cdf0e10cSrcweir 	ScUnoGuard aGuard;
1868*cdf0e10cSrcweir     OUString aName;
1869*cdf0e10cSrcweir     if( ScDPSaveDimension* pDim = GetDPDimension() )
1870*cdf0e10cSrcweir     {
1871*cdf0e10cSrcweir         if( pDim->IsDataLayout() )
1872*cdf0e10cSrcweir             aName = OUString( RTL_CONSTASCII_USTRINGPARAM( SC_DATALAYOUT_NAME ) );
1873*cdf0e10cSrcweir         else
1874*cdf0e10cSrcweir         {
1875*cdf0e10cSrcweir             const rtl::OUString* pLayoutName = pDim->GetLayoutName();
1876*cdf0e10cSrcweir             if (pLayoutName)
1877*cdf0e10cSrcweir                 aName = *pLayoutName;
1878*cdf0e10cSrcweir             else
1879*cdf0e10cSrcweir                 aName = pDim->GetName();
1880*cdf0e10cSrcweir         }                                                                }
1881*cdf0e10cSrcweir     return aName;
1882*cdf0e10cSrcweir }
1883*cdf0e10cSrcweir 
1884*cdf0e10cSrcweir void SAL_CALL ScDataPilotFieldObj::setName( const OUString& rName ) throw(RuntimeException)
1885*cdf0e10cSrcweir {
1886*cdf0e10cSrcweir 	ScUnoGuard aGuard;
1887*cdf0e10cSrcweir     ScDPObject* pDPObj = 0;
1888*cdf0e10cSrcweir     ScDPSaveDimension* pDim = GetDPDimension( &pDPObj );
1889*cdf0e10cSrcweir     if( pDim && !pDim->IsDataLayout() )
1890*cdf0e10cSrcweir     {
1891*cdf0e10cSrcweir         String aName( rName );
1892*cdf0e10cSrcweir         pDim->SetLayoutName(aName);
1893*cdf0e10cSrcweir         SetDPObject( pDPObj );
1894*cdf0e10cSrcweir     }
1895*cdf0e10cSrcweir }
1896*cdf0e10cSrcweir 
1897*cdf0e10cSrcweir // XPropertySet
1898*cdf0e10cSrcweir 
1899*cdf0e10cSrcweir Reference<XPropertySetInfo> SAL_CALL ScDataPilotFieldObj::getPropertySetInfo()
1900*cdf0e10cSrcweir                                                         throw(RuntimeException)
1901*cdf0e10cSrcweir {
1902*cdf0e10cSrcweir 	ScUnoGuard aGuard;
1903*cdf0e10cSrcweir     static Reference<XPropertySetInfo> aRef(
1904*cdf0e10cSrcweir         new SfxItemPropertySetInfo( maPropSet.getPropertyMap() ));
1905*cdf0e10cSrcweir 	return aRef;
1906*cdf0e10cSrcweir }
1907*cdf0e10cSrcweir 
1908*cdf0e10cSrcweir void SAL_CALL ScDataPilotFieldObj::setPropertyValue( const OUString& aPropertyName, const Any& aValue )
1909*cdf0e10cSrcweir         throw(UnknownPropertyException, PropertyVetoException, IllegalArgumentException, WrappedTargetException, RuntimeException)
1910*cdf0e10cSrcweir {
1911*cdf0e10cSrcweir 	ScUnoGuard aGuard;
1912*cdf0e10cSrcweir 	String aNameString(aPropertyName);
1913*cdf0e10cSrcweir 	if ( aNameString.EqualsAscii( SC_UNONAME_FUNCTION ) )
1914*cdf0e10cSrcweir 	{
1915*cdf0e10cSrcweir         // #i109350# use GetEnumFromAny because it also allows sal_Int32
1916*cdf0e10cSrcweir         GeneralFunction eFunction = (GeneralFunction)
1917*cdf0e10cSrcweir                             ScUnoHelpFunctions::GetEnumFromAny( aValue );
1918*cdf0e10cSrcweir         setFunction( eFunction );
1919*cdf0e10cSrcweir 	}
1920*cdf0e10cSrcweir     else if ( aNameString.EqualsAscii( SC_UNONAME_SUBTOTALS ) )
1921*cdf0e10cSrcweir     {
1922*cdf0e10cSrcweir         Sequence< GeneralFunction > aSubtotals;
1923*cdf0e10cSrcweir         if( aValue >>= aSubtotals )
1924*cdf0e10cSrcweir             setSubtotals( aSubtotals );
1925*cdf0e10cSrcweir     }
1926*cdf0e10cSrcweir 	else if ( aNameString.EqualsAscii( SC_UNONAME_ORIENT ) )
1927*cdf0e10cSrcweir 	{
1928*cdf0e10cSrcweir 		//!	test for correct enum type?
1929*cdf0e10cSrcweir         DataPilotFieldOrientation eOrient = (DataPilotFieldOrientation)
1930*cdf0e10cSrcweir 							ScUnoHelpFunctions::GetEnumFromAny( aValue );
1931*cdf0e10cSrcweir 		setOrientation( eOrient );
1932*cdf0e10cSrcweir 	}
1933*cdf0e10cSrcweir 	else if ( aNameString.EqualsAscii( SC_UNONAME_SELPAGE ) )
1934*cdf0e10cSrcweir     {
1935*cdf0e10cSrcweir         OUString sCurrentPage;
1936*cdf0e10cSrcweir         if (aValue >>= sCurrentPage)
1937*cdf0e10cSrcweir             setCurrentPage(sCurrentPage);
1938*cdf0e10cSrcweir     }
1939*cdf0e10cSrcweir 	else if ( aNameString.EqualsAscii( SC_UNONAME_USESELPAGE ) )
1940*cdf0e10cSrcweir     {
1941*cdf0e10cSrcweir         setUseCurrentPage(cppu::any2bool(aValue));
1942*cdf0e10cSrcweir     }
1943*cdf0e10cSrcweir 	else if ( aNameString.EqualsAscii( SC_UNONAME_HASAUTOSHOW ) )
1944*cdf0e10cSrcweir     {
1945*cdf0e10cSrcweir         if (!cppu::any2bool(aValue))
1946*cdf0e10cSrcweir             setAutoShowInfo(NULL);
1947*cdf0e10cSrcweir     }
1948*cdf0e10cSrcweir 	else if ( aNameString.EqualsAscii( SC_UNONAME_AUTOSHOW ) )
1949*cdf0e10cSrcweir     {
1950*cdf0e10cSrcweir         DataPilotFieldAutoShowInfo aInfo;
1951*cdf0e10cSrcweir         if (aValue >>= aInfo)
1952*cdf0e10cSrcweir             setAutoShowInfo(&aInfo);
1953*cdf0e10cSrcweir     }
1954*cdf0e10cSrcweir 	else if ( aNameString.EqualsAscii( SC_UNONAME_HASLAYOUTINFO ) )
1955*cdf0e10cSrcweir     {
1956*cdf0e10cSrcweir         if (!cppu::any2bool(aValue))
1957*cdf0e10cSrcweir             setLayoutInfo(NULL);
1958*cdf0e10cSrcweir     }
1959*cdf0e10cSrcweir 	else if ( aNameString.EqualsAscii( SC_UNONAME_LAYOUTINFO ) )
1960*cdf0e10cSrcweir     {
1961*cdf0e10cSrcweir         DataPilotFieldLayoutInfo aInfo;
1962*cdf0e10cSrcweir         if (aValue >>= aInfo)
1963*cdf0e10cSrcweir             setLayoutInfo(&aInfo);
1964*cdf0e10cSrcweir     }
1965*cdf0e10cSrcweir 	else if ( aNameString.EqualsAscii( SC_UNONAME_HASREFERENCE ) )
1966*cdf0e10cSrcweir     {
1967*cdf0e10cSrcweir         if (!cppu::any2bool(aValue))
1968*cdf0e10cSrcweir             setReference(NULL);
1969*cdf0e10cSrcweir     }
1970*cdf0e10cSrcweir 	else if ( aNameString.EqualsAscii( SC_UNONAME_REFERENCE ) )
1971*cdf0e10cSrcweir     {
1972*cdf0e10cSrcweir         DataPilotFieldReference aRef;
1973*cdf0e10cSrcweir         if (aValue >>= aRef)
1974*cdf0e10cSrcweir             setReference(&aRef);
1975*cdf0e10cSrcweir     }
1976*cdf0e10cSrcweir 	else if ( aNameString.EqualsAscii( SC_UNONAME_HASSORTINFO ) )
1977*cdf0e10cSrcweir     {
1978*cdf0e10cSrcweir         if (!cppu::any2bool(aValue))
1979*cdf0e10cSrcweir             setSortInfo(NULL);
1980*cdf0e10cSrcweir     }
1981*cdf0e10cSrcweir 	else if ( aNameString.EqualsAscii( SC_UNONAME_SORTINFO ) )
1982*cdf0e10cSrcweir     {
1983*cdf0e10cSrcweir         DataPilotFieldSortInfo aInfo;
1984*cdf0e10cSrcweir         if (aValue >>= aInfo)
1985*cdf0e10cSrcweir             setSortInfo(&aInfo);
1986*cdf0e10cSrcweir     }
1987*cdf0e10cSrcweir     else if ( aNameString.EqualsAscii( SC_UNONAME_ISGROUP ) )
1988*cdf0e10cSrcweir     {
1989*cdf0e10cSrcweir         if (!cppu::any2bool(aValue))
1990*cdf0e10cSrcweir             setGroupInfo(NULL);
1991*cdf0e10cSrcweir     }
1992*cdf0e10cSrcweir     else if ( aNameString.EqualsAscii( SC_UNONAME_GROUPINFO ) )
1993*cdf0e10cSrcweir     {
1994*cdf0e10cSrcweir         DataPilotFieldGroupInfo aInfo;
1995*cdf0e10cSrcweir         if (aValue >>= aInfo)
1996*cdf0e10cSrcweir             setGroupInfo(&aInfo);
1997*cdf0e10cSrcweir     }
1998*cdf0e10cSrcweir     else if ( aNameString.EqualsAscii( SC_UNONAME_SHOWEMPTY ) )
1999*cdf0e10cSrcweir     {
2000*cdf0e10cSrcweir         setShowEmpty(cppu::any2bool(aValue));
2001*cdf0e10cSrcweir     }
2002*cdf0e10cSrcweir }
2003*cdf0e10cSrcweir 
2004*cdf0e10cSrcweir Any SAL_CALL ScDataPilotFieldObj::getPropertyValue( const OUString& aPropertyName )
2005*cdf0e10cSrcweir         throw(UnknownPropertyException, WrappedTargetException, RuntimeException)
2006*cdf0e10cSrcweir {
2007*cdf0e10cSrcweir 	ScUnoGuard aGuard;
2008*cdf0e10cSrcweir 	String aNameString(aPropertyName);
2009*cdf0e10cSrcweir     Any aRet;
2010*cdf0e10cSrcweir 
2011*cdf0e10cSrcweir 	if ( aNameString.EqualsAscii( SC_UNONAME_FUNCTION ) )
2012*cdf0e10cSrcweir 		aRet <<= getFunction();
2013*cdf0e10cSrcweir     else if ( aNameString.EqualsAscii( SC_UNONAME_SUBTOTALS ) )
2014*cdf0e10cSrcweir         aRet <<= getSubtotals();
2015*cdf0e10cSrcweir 	else if ( aNameString.EqualsAscii( SC_UNONAME_ORIENT ) )
2016*cdf0e10cSrcweir 		aRet <<= getOrientation();
2017*cdf0e10cSrcweir 	else if ( aNameString.EqualsAscii( SC_UNONAME_SELPAGE ) )
2018*cdf0e10cSrcweir         aRet <<= getCurrentPage();
2019*cdf0e10cSrcweir 	else if ( aNameString.EqualsAscii( SC_UNONAME_USESELPAGE ) )
2020*cdf0e10cSrcweir         aRet <<= getUseCurrentPage();
2021*cdf0e10cSrcweir 	else if ( aNameString.EqualsAscii( SC_UNONAME_HASAUTOSHOW ) )
2022*cdf0e10cSrcweir         aRet = ::cppu::bool2any(getAutoShowInfo() != NULL);
2023*cdf0e10cSrcweir 	else if ( aNameString.EqualsAscii( SC_UNONAME_AUTOSHOW ) )
2024*cdf0e10cSrcweir     {
2025*cdf0e10cSrcweir         const DataPilotFieldAutoShowInfo* pInfo = getAutoShowInfo();
2026*cdf0e10cSrcweir         if (pInfo)
2027*cdf0e10cSrcweir             aRet <<= DataPilotFieldAutoShowInfo(*pInfo);
2028*cdf0e10cSrcweir     }
2029*cdf0e10cSrcweir 	else if ( aNameString.EqualsAscii( SC_UNONAME_HASLAYOUTINFO ) )
2030*cdf0e10cSrcweir         aRet = ::cppu::bool2any(getLayoutInfo() != NULL);
2031*cdf0e10cSrcweir 	else if ( aNameString.EqualsAscii( SC_UNONAME_LAYOUTINFO ) )
2032*cdf0e10cSrcweir     {
2033*cdf0e10cSrcweir         const DataPilotFieldLayoutInfo* pInfo = getLayoutInfo();
2034*cdf0e10cSrcweir         if (pInfo)
2035*cdf0e10cSrcweir             aRet <<= DataPilotFieldLayoutInfo(*pInfo);
2036*cdf0e10cSrcweir     }
2037*cdf0e10cSrcweir 	else if ( aNameString.EqualsAscii( SC_UNONAME_HASREFERENCE ) )
2038*cdf0e10cSrcweir         aRet = ::cppu::bool2any(getReference() != NULL);
2039*cdf0e10cSrcweir 	else if ( aNameString.EqualsAscii( SC_UNONAME_REFERENCE ) )
2040*cdf0e10cSrcweir     {
2041*cdf0e10cSrcweir         const DataPilotFieldReference* pRef = getReference();
2042*cdf0e10cSrcweir         if (pRef)
2043*cdf0e10cSrcweir             aRet <<= DataPilotFieldReference(*pRef);
2044*cdf0e10cSrcweir     }
2045*cdf0e10cSrcweir 	else if ( aNameString.EqualsAscii( SC_UNONAME_HASSORTINFO ) )
2046*cdf0e10cSrcweir         aRet = ::cppu::bool2any(getSortInfo() != NULL);
2047*cdf0e10cSrcweir 	else if ( aNameString.EqualsAscii( SC_UNONAME_SORTINFO ) )
2048*cdf0e10cSrcweir     {
2049*cdf0e10cSrcweir         const DataPilotFieldSortInfo* pInfo = getSortInfo();
2050*cdf0e10cSrcweir         if (pInfo)
2051*cdf0e10cSrcweir             aRet <<= DataPilotFieldSortInfo(*pInfo);
2052*cdf0e10cSrcweir     }
2053*cdf0e10cSrcweir 	else if ( aNameString.EqualsAscii( SC_UNONAME_ISGROUP ) )
2054*cdf0e10cSrcweir         aRet = ::cppu::bool2any(hasGroupInfo());
2055*cdf0e10cSrcweir 	else if ( aNameString.EqualsAscii( SC_UNONAME_GROUPINFO ) )
2056*cdf0e10cSrcweir     {
2057*cdf0e10cSrcweir         aRet <<= getGroupInfo();
2058*cdf0e10cSrcweir     }
2059*cdf0e10cSrcweir     else if ( aNameString.EqualsAscii( SC_UNONAME_SHOWEMPTY ) )
2060*cdf0e10cSrcweir         aRet <<= getShowEmpty();
2061*cdf0e10cSrcweir 
2062*cdf0e10cSrcweir 	return aRet;
2063*cdf0e10cSrcweir }
2064*cdf0e10cSrcweir 
2065*cdf0e10cSrcweir // XDatePilotField
2066*cdf0e10cSrcweir 
2067*cdf0e10cSrcweir Reference<XIndexAccess> SAL_CALL ScDataPilotFieldObj::getItems()
2068*cdf0e10cSrcweir                 throw (RuntimeException)
2069*cdf0e10cSrcweir {
2070*cdf0e10cSrcweir     ScUnoGuard aGuard;
2071*cdf0e10cSrcweir     if (!mxItems.is())
2072*cdf0e10cSrcweir         mxItems.set( new ScDataPilotItemsObj( mrParent, maFieldId ) );
2073*cdf0e10cSrcweir     return mxItems;
2074*cdf0e10cSrcweir }
2075*cdf0e10cSrcweir 
2076*cdf0e10cSrcweir SC_IMPL_DUMMY_PROPERTY_LISTENER( ScDataPilotFieldObj )
2077*cdf0e10cSrcweir 
2078*cdf0e10cSrcweir DataPilotFieldOrientation ScDataPilotFieldObj::getOrientation() const
2079*cdf0e10cSrcweir {
2080*cdf0e10cSrcweir     ScUnoGuard aGuard;
2081*cdf0e10cSrcweir     ScDPSaveDimension* pDim = GetDPDimension();
2082*cdf0e10cSrcweir     return pDim ? static_cast< DataPilotFieldOrientation >( pDim->GetOrientation() ) : DataPilotFieldOrientation_HIDDEN;
2083*cdf0e10cSrcweir }
2084*cdf0e10cSrcweir 
2085*cdf0e10cSrcweir void ScDataPilotFieldObj::setOrientation(DataPilotFieldOrientation eNew)
2086*cdf0e10cSrcweir {
2087*cdf0e10cSrcweir     ScUnoGuard aGuard;
2088*cdf0e10cSrcweir     if (maOrient.hasValue() && (eNew == maOrient.get< DataPilotFieldOrientation >()))
2089*cdf0e10cSrcweir         return;
2090*cdf0e10cSrcweir 
2091*cdf0e10cSrcweir     ScDPObject* pDPObj = 0;
2092*cdf0e10cSrcweir     if( ScDPSaveDimension* pDim = GetDPDimension( &pDPObj ) )
2093*cdf0e10cSrcweir     {
2094*cdf0e10cSrcweir         ScDPSaveData* pSaveData = pDPObj->GetSaveData();
2095*cdf0e10cSrcweir 
2096*cdf0e10cSrcweir         /*  If the field was taken from getDataPilotFields(), don't reset the
2097*cdf0e10cSrcweir             orientation for an existing use, but create a duplicated field
2098*cdf0e10cSrcweir             instead (for "Data" orientation only). */
2099*cdf0e10cSrcweir         if ( !maOrient.hasValue() && !maFieldId.mbDataLayout &&
2100*cdf0e10cSrcweir              (pDim->GetOrientation() != DataPilotFieldOrientation_HIDDEN) &&
2101*cdf0e10cSrcweir              (eNew == DataPilotFieldOrientation_DATA) )
2102*cdf0e10cSrcweir         {
2103*cdf0e10cSrcweir 
2104*cdf0e10cSrcweir             ScDPSaveDimension* pNewDim = 0;
2105*cdf0e10cSrcweir 
2106*cdf0e10cSrcweir             // look for existing duplicate with orientation "hidden"
2107*cdf0e10cSrcweir 
2108*cdf0e10cSrcweir             String aNameStr( maFieldId.maFieldName );
2109*cdf0e10cSrcweir             const List& rDimensions = pSaveData->GetDimensions();
2110*cdf0e10cSrcweir             sal_Int32 nDimCount = rDimensions.Count();
2111*cdf0e10cSrcweir             sal_Int32 nFound = 0;
2112*cdf0e10cSrcweir             for ( sal_Int32 nDim = 0; nDim < nDimCount && !pNewDim; nDim++ )
2113*cdf0e10cSrcweir             {
2114*cdf0e10cSrcweir                 ScDPSaveDimension* pOneDim = static_cast<ScDPSaveDimension*>(rDimensions.GetObject(nDim));
2115*cdf0e10cSrcweir                 if ( !pOneDim->IsDataLayout() && (pOneDim->GetName() == aNameStr) )
2116*cdf0e10cSrcweir                 {
2117*cdf0e10cSrcweir                     if ( pOneDim->GetOrientation() == DataPilotFieldOrientation_HIDDEN )
2118*cdf0e10cSrcweir                         pNewDim = pOneDim;      // use this one
2119*cdf0e10cSrcweir                     else
2120*cdf0e10cSrcweir                         ++nFound;               // count existing non-hidden occurences
2121*cdf0e10cSrcweir                 }
2122*cdf0e10cSrcweir             }
2123*cdf0e10cSrcweir 
2124*cdf0e10cSrcweir             if ( !pNewDim )     // if none found, create a new duplicated dimension
2125*cdf0e10cSrcweir                 pNewDim = &pSaveData->DuplicateDimension( *pDim );
2126*cdf0e10cSrcweir 
2127*cdf0e10cSrcweir             maFieldId.mnFieldIdx = nFound;      // keep accessing the new one
2128*cdf0e10cSrcweir             pDim = pNewDim;
2129*cdf0e10cSrcweir         }
2130*cdf0e10cSrcweir 
2131*cdf0e10cSrcweir         pDim->SetOrientation(sal::static_int_cast<sal_uInt16>(eNew));
2132*cdf0e10cSrcweir 
2133*cdf0e10cSrcweir         // move changed field behind all other fields (make it the last field in dimension)
2134*cdf0e10cSrcweir         pSaveData->SetPosition( pDim, pSaveData->GetDimensions().Count() );
2135*cdf0e10cSrcweir 
2136*cdf0e10cSrcweir         SetDPObject( pDPObj );
2137*cdf0e10cSrcweir 
2138*cdf0e10cSrcweir         maOrient <<= eNew;   // modifying the same object's orientation again doesn't create another duplicate
2139*cdf0e10cSrcweir     }
2140*cdf0e10cSrcweir }
2141*cdf0e10cSrcweir 
2142*cdf0e10cSrcweir GeneralFunction ScDataPilotFieldObj::getFunction() const
2143*cdf0e10cSrcweir {
2144*cdf0e10cSrcweir     ScUnoGuard aGuard;
2145*cdf0e10cSrcweir     GeneralFunction eRet = GeneralFunction_NONE;
2146*cdf0e10cSrcweir     if( ScDPSaveDimension* pDim = GetDPDimension() )
2147*cdf0e10cSrcweir     {
2148*cdf0e10cSrcweir         if( pDim->GetOrientation() != DataPilotFieldOrientation_DATA )
2149*cdf0e10cSrcweir         {
2150*cdf0e10cSrcweir             // for non-data fields, property Function is the subtotals
2151*cdf0e10cSrcweir             long nSubCount = pDim->GetSubTotalsCount();
2152*cdf0e10cSrcweir             if ( nSubCount > 0 )
2153*cdf0e10cSrcweir                 eRet = (GeneralFunction)pDim->GetSubTotalFunc(0);    // always use the first one
2154*cdf0e10cSrcweir             // else keep NONE
2155*cdf0e10cSrcweir         }
2156*cdf0e10cSrcweir         else
2157*cdf0e10cSrcweir             eRet = (GeneralFunction)pDim->GetFunction();
2158*cdf0e10cSrcweir     }
2159*cdf0e10cSrcweir     return eRet;
2160*cdf0e10cSrcweir }
2161*cdf0e10cSrcweir 
2162*cdf0e10cSrcweir void ScDataPilotFieldObj::setFunction(GeneralFunction eNewFunc)
2163*cdf0e10cSrcweir {
2164*cdf0e10cSrcweir     ScUnoGuard aGuard;
2165*cdf0e10cSrcweir     ScDPObject* pDPObj = 0;
2166*cdf0e10cSrcweir     if( ScDPSaveDimension* pDim = GetDPDimension( &pDPObj ) )
2167*cdf0e10cSrcweir     {
2168*cdf0e10cSrcweir         if( pDim->GetOrientation() != DataPilotFieldOrientation_DATA )
2169*cdf0e10cSrcweir         {
2170*cdf0e10cSrcweir             // for non-data fields, property Function is the subtotals
2171*cdf0e10cSrcweir             if ( eNewFunc == GeneralFunction_NONE )
2172*cdf0e10cSrcweir                 pDim->SetSubTotals( 0, NULL );
2173*cdf0e10cSrcweir             else
2174*cdf0e10cSrcweir             {
2175*cdf0e10cSrcweir                 sal_uInt16 nFunc = sal::static_int_cast<sal_uInt16>( eNewFunc );
2176*cdf0e10cSrcweir                 pDim->SetSubTotals( 1, &nFunc );
2177*cdf0e10cSrcweir             }
2178*cdf0e10cSrcweir         }
2179*cdf0e10cSrcweir         else
2180*cdf0e10cSrcweir             pDim->SetFunction( sal::static_int_cast<sal_uInt16>( eNewFunc ) );
2181*cdf0e10cSrcweir         SetDPObject( pDPObj );
2182*cdf0e10cSrcweir     }
2183*cdf0e10cSrcweir }
2184*cdf0e10cSrcweir 
2185*cdf0e10cSrcweir Sequence< GeneralFunction > ScDataPilotFieldObj::getSubtotals() const
2186*cdf0e10cSrcweir {
2187*cdf0e10cSrcweir     ScUnoGuard aGuard;
2188*cdf0e10cSrcweir     Sequence< GeneralFunction > aRet;
2189*cdf0e10cSrcweir     if( ScDPSaveDimension* pDim = GetDPDimension() )
2190*cdf0e10cSrcweir     {
2191*cdf0e10cSrcweir         if( pDim->GetOrientation() != DataPilotFieldOrientation_DATA )
2192*cdf0e10cSrcweir         {
2193*cdf0e10cSrcweir             // for non-data fields, property Functions is the sequence of subtotals
2194*cdf0e10cSrcweir             sal_Int32 nCount = static_cast< sal_Int32 >( pDim->GetSubTotalsCount() );
2195*cdf0e10cSrcweir             if ( nCount > 0 )
2196*cdf0e10cSrcweir             {
2197*cdf0e10cSrcweir                 aRet.realloc( nCount );
2198*cdf0e10cSrcweir                 for( sal_Int32 nIdx = 0; nIdx < nCount; ++nIdx )
2199*cdf0e10cSrcweir                     aRet[ nIdx ] = (GeneralFunction)pDim->GetSubTotalFunc( nIdx );
2200*cdf0e10cSrcweir             }
2201*cdf0e10cSrcweir         }
2202*cdf0e10cSrcweir     }
2203*cdf0e10cSrcweir     return aRet;
2204*cdf0e10cSrcweir }
2205*cdf0e10cSrcweir 
2206*cdf0e10cSrcweir void ScDataPilotFieldObj::setSubtotals( const Sequence< GeneralFunction >& rSubtotals )
2207*cdf0e10cSrcweir {
2208*cdf0e10cSrcweir     ScUnoGuard aGuard;
2209*cdf0e10cSrcweir     ScDPObject* pDPObj = 0;
2210*cdf0e10cSrcweir     if( ScDPSaveDimension* pDim = GetDPDimension( &pDPObj ) )
2211*cdf0e10cSrcweir     {
2212*cdf0e10cSrcweir         if( pDim->GetOrientation() != DataPilotFieldOrientation_DATA )
2213*cdf0e10cSrcweir         {
2214*cdf0e10cSrcweir             sal_Int32 nCount = rSubtotals.getLength();
2215*cdf0e10cSrcweir             if( nCount == 1 )
2216*cdf0e10cSrcweir             {
2217*cdf0e10cSrcweir                 // count 1: all values are allowed (including NONE and AUTO)
2218*cdf0e10cSrcweir                 if( rSubtotals[ 0 ] == GeneralFunction_NONE )
2219*cdf0e10cSrcweir                     pDim->SetSubTotals( 0, NULL );
2220*cdf0e10cSrcweir                 else
2221*cdf0e10cSrcweir                 {
2222*cdf0e10cSrcweir                     sal_uInt16 nFunc = sal::static_int_cast<sal_uInt16>( rSubtotals[ 0 ] );
2223*cdf0e10cSrcweir                     pDim->SetSubTotals( 1, &nFunc );
2224*cdf0e10cSrcweir                 }
2225*cdf0e10cSrcweir             }
2226*cdf0e10cSrcweir             else if( nCount > 1 )
2227*cdf0e10cSrcweir             {
2228*cdf0e10cSrcweir                 // set multiple functions, ignore NONE and AUTO in this case
2229*cdf0e10cSrcweir                 ::std::vector< sal_uInt16 > aSubt;
2230*cdf0e10cSrcweir                 for( sal_Int32 nIdx = 0; nIdx < nCount; ++nIdx )
2231*cdf0e10cSrcweir                 {
2232*cdf0e10cSrcweir                     GeneralFunction eFunc = rSubtotals[ nIdx ];
2233*cdf0e10cSrcweir                     if( (eFunc != GeneralFunction_NONE) && (eFunc != GeneralFunction_AUTO) )
2234*cdf0e10cSrcweir                     {
2235*cdf0e10cSrcweir                         // do not insert functions twice
2236*cdf0e10cSrcweir                         sal_uInt16 nFunc = static_cast< sal_uInt16 >( eFunc );
2237*cdf0e10cSrcweir                         if( ::std::find( aSubt.begin(), aSubt.end(), nFunc ) == aSubt.end() )
2238*cdf0e10cSrcweir                             aSubt.push_back( nFunc );
2239*cdf0e10cSrcweir                     }
2240*cdf0e10cSrcweir                 }
2241*cdf0e10cSrcweir                 // set values from vector to ScDPSaveDimension
2242*cdf0e10cSrcweir                 if ( aSubt.empty() )
2243*cdf0e10cSrcweir                     pDim->SetSubTotals( 0, NULL );
2244*cdf0e10cSrcweir                 else
2245*cdf0e10cSrcweir                     pDim->SetSubTotals( static_cast< long >( aSubt.size() ), &aSubt.front() );
2246*cdf0e10cSrcweir             }
2247*cdf0e10cSrcweir         }
2248*cdf0e10cSrcweir         SetDPObject( pDPObj );
2249*cdf0e10cSrcweir     }
2250*cdf0e10cSrcweir }
2251*cdf0e10cSrcweir 
2252*cdf0e10cSrcweir OUString ScDataPilotFieldObj::getCurrentPage() const
2253*cdf0e10cSrcweir {
2254*cdf0e10cSrcweir     ScUnoGuard aGuard;
2255*cdf0e10cSrcweir     ScDPSaveDimension* pDim = GetDPDimension();
2256*cdf0e10cSrcweir     if( pDim && pDim->HasCurrentPage() )
2257*cdf0e10cSrcweir         return pDim->GetCurrentPage();
2258*cdf0e10cSrcweir     return OUString();
2259*cdf0e10cSrcweir }
2260*cdf0e10cSrcweir 
2261*cdf0e10cSrcweir void ScDataPilotFieldObj::setCurrentPage( const OUString& rPage )
2262*cdf0e10cSrcweir {
2263*cdf0e10cSrcweir     ScUnoGuard aGuard;
2264*cdf0e10cSrcweir     ScDPObject* pDPObj = 0;
2265*cdf0e10cSrcweir     if( ScDPSaveDimension* pDim = GetDPDimension( &pDPObj ) )
2266*cdf0e10cSrcweir     {
2267*cdf0e10cSrcweir         String aPage( rPage );
2268*cdf0e10cSrcweir         pDim->SetCurrentPage( &aPage );
2269*cdf0e10cSrcweir         SetDPObject( pDPObj );
2270*cdf0e10cSrcweir     }
2271*cdf0e10cSrcweir }
2272*cdf0e10cSrcweir 
2273*cdf0e10cSrcweir sal_Bool ScDataPilotFieldObj::getUseCurrentPage() const
2274*cdf0e10cSrcweir {
2275*cdf0e10cSrcweir     ScUnoGuard aGuard;
2276*cdf0e10cSrcweir     ScDPSaveDimension* pDim = GetDPDimension();
2277*cdf0e10cSrcweir     return pDim && pDim->HasCurrentPage();
2278*cdf0e10cSrcweir }
2279*cdf0e10cSrcweir 
2280*cdf0e10cSrcweir void ScDataPilotFieldObj::setUseCurrentPage( sal_Bool bUse )
2281*cdf0e10cSrcweir {
2282*cdf0e10cSrcweir     ScUnoGuard aGuard;
2283*cdf0e10cSrcweir     ScDPObject* pDPObj = 0;
2284*cdf0e10cSrcweir     if( ScDPSaveDimension* pDim = GetDPDimension( &pDPObj ) )
2285*cdf0e10cSrcweir     {
2286*cdf0e10cSrcweir         if( bUse )
2287*cdf0e10cSrcweir         {
2288*cdf0e10cSrcweir             /*  It is somehow useless to set the property "HasSelectedPage" to
2289*cdf0e10cSrcweir                 true, because it is still needed to set an explicit page name. */
2290*cdf0e10cSrcweir             if( !pDim->HasCurrentPage() )
2291*cdf0e10cSrcweir             {
2292*cdf0e10cSrcweir                 String aPage;
2293*cdf0e10cSrcweir                 pDim->SetCurrentPage( &aPage );
2294*cdf0e10cSrcweir             }
2295*cdf0e10cSrcweir         }
2296*cdf0e10cSrcweir         else
2297*cdf0e10cSrcweir             pDim->SetCurrentPage( 0 );
2298*cdf0e10cSrcweir         SetDPObject( pDPObj );
2299*cdf0e10cSrcweir     }
2300*cdf0e10cSrcweir }
2301*cdf0e10cSrcweir 
2302*cdf0e10cSrcweir const DataPilotFieldAutoShowInfo* ScDataPilotFieldObj::getAutoShowInfo()
2303*cdf0e10cSrcweir {
2304*cdf0e10cSrcweir     ScUnoGuard aGuard;
2305*cdf0e10cSrcweir     ScDPSaveDimension* pDim = GetDPDimension();
2306*cdf0e10cSrcweir     return pDim ? pDim->GetAutoShowInfo() : 0;
2307*cdf0e10cSrcweir }
2308*cdf0e10cSrcweir 
2309*cdf0e10cSrcweir void ScDataPilotFieldObj::setAutoShowInfo( const DataPilotFieldAutoShowInfo* pInfo )
2310*cdf0e10cSrcweir {
2311*cdf0e10cSrcweir     ScUnoGuard aGuard;
2312*cdf0e10cSrcweir     ScDPObject* pDPObj = 0;
2313*cdf0e10cSrcweir     if( ScDPSaveDimension* pDim = GetDPDimension( &pDPObj ) )
2314*cdf0e10cSrcweir     {
2315*cdf0e10cSrcweir         pDim->SetAutoShowInfo( pInfo );
2316*cdf0e10cSrcweir         SetDPObject( pDPObj );
2317*cdf0e10cSrcweir     }
2318*cdf0e10cSrcweir }
2319*cdf0e10cSrcweir 
2320*cdf0e10cSrcweir const DataPilotFieldLayoutInfo* ScDataPilotFieldObj::getLayoutInfo()
2321*cdf0e10cSrcweir {
2322*cdf0e10cSrcweir     ScUnoGuard aGuard;
2323*cdf0e10cSrcweir     ScDPSaveDimension* pDim = GetDPDimension();
2324*cdf0e10cSrcweir     return pDim ? pDim->GetLayoutInfo() : 0;
2325*cdf0e10cSrcweir }
2326*cdf0e10cSrcweir 
2327*cdf0e10cSrcweir void ScDataPilotFieldObj::setLayoutInfo( const DataPilotFieldLayoutInfo* pInfo )
2328*cdf0e10cSrcweir {
2329*cdf0e10cSrcweir     ScUnoGuard aGuard;
2330*cdf0e10cSrcweir     ScDPObject* pDPObj = 0;
2331*cdf0e10cSrcweir     if( ScDPSaveDimension* pDim = GetDPDimension( &pDPObj ) )
2332*cdf0e10cSrcweir     {
2333*cdf0e10cSrcweir         pDim->SetLayoutInfo( pInfo );
2334*cdf0e10cSrcweir         SetDPObject( pDPObj );
2335*cdf0e10cSrcweir     }
2336*cdf0e10cSrcweir }
2337*cdf0e10cSrcweir 
2338*cdf0e10cSrcweir const DataPilotFieldReference* ScDataPilotFieldObj::getReference()
2339*cdf0e10cSrcweir {
2340*cdf0e10cSrcweir     ScUnoGuard aGuard;
2341*cdf0e10cSrcweir     ScDPSaveDimension* pDim = GetDPDimension();
2342*cdf0e10cSrcweir     return pDim ? pDim->GetReferenceValue() : 0;
2343*cdf0e10cSrcweir }
2344*cdf0e10cSrcweir 
2345*cdf0e10cSrcweir void ScDataPilotFieldObj::setReference( const DataPilotFieldReference* pInfo )
2346*cdf0e10cSrcweir {
2347*cdf0e10cSrcweir     ScUnoGuard aGuard;
2348*cdf0e10cSrcweir     ScDPObject* pDPObj = 0;
2349*cdf0e10cSrcweir     if( ScDPSaveDimension* pDim = GetDPDimension( &pDPObj ) )
2350*cdf0e10cSrcweir     {
2351*cdf0e10cSrcweir         pDim->SetReferenceValue( pInfo );
2352*cdf0e10cSrcweir         SetDPObject( pDPObj );
2353*cdf0e10cSrcweir     }
2354*cdf0e10cSrcweir }
2355*cdf0e10cSrcweir 
2356*cdf0e10cSrcweir const DataPilotFieldSortInfo* ScDataPilotFieldObj::getSortInfo()
2357*cdf0e10cSrcweir {
2358*cdf0e10cSrcweir     ScUnoGuard aGuard;
2359*cdf0e10cSrcweir     ScDPSaveDimension* pDim = GetDPDimension();
2360*cdf0e10cSrcweir     return pDim ? pDim->GetSortInfo() : 0;
2361*cdf0e10cSrcweir }
2362*cdf0e10cSrcweir 
2363*cdf0e10cSrcweir void ScDataPilotFieldObj::setSortInfo( const DataPilotFieldSortInfo* pInfo )
2364*cdf0e10cSrcweir {
2365*cdf0e10cSrcweir     ScUnoGuard aGuard;
2366*cdf0e10cSrcweir     ScDPObject* pDPObj = 0;
2367*cdf0e10cSrcweir     if( ScDPSaveDimension* pDim = GetDPDimension( &pDPObj ) )
2368*cdf0e10cSrcweir     {
2369*cdf0e10cSrcweir         pDim->SetSortInfo( pInfo );
2370*cdf0e10cSrcweir         SetDPObject( pDPObj );
2371*cdf0e10cSrcweir     }
2372*cdf0e10cSrcweir }
2373*cdf0e10cSrcweir 
2374*cdf0e10cSrcweir sal_Bool ScDataPilotFieldObj::getShowEmpty() const
2375*cdf0e10cSrcweir {
2376*cdf0e10cSrcweir     ScUnoGuard aGuard;
2377*cdf0e10cSrcweir     ScDPSaveDimension* pDim = GetDPDimension();
2378*cdf0e10cSrcweir     return pDim && pDim->GetShowEmpty();
2379*cdf0e10cSrcweir }
2380*cdf0e10cSrcweir 
2381*cdf0e10cSrcweir void ScDataPilotFieldObj::setShowEmpty( sal_Bool bShow )
2382*cdf0e10cSrcweir {
2383*cdf0e10cSrcweir     ScUnoGuard aGuard;
2384*cdf0e10cSrcweir     ScDPObject* pDPObj = 0;
2385*cdf0e10cSrcweir     if( ScDPSaveDimension* pDim = GetDPDimension( &pDPObj ) )
2386*cdf0e10cSrcweir     {
2387*cdf0e10cSrcweir         pDim->SetShowEmpty( bShow );
2388*cdf0e10cSrcweir         SetDPObject( pDPObj );
2389*cdf0e10cSrcweir     }
2390*cdf0e10cSrcweir }
2391*cdf0e10cSrcweir 
2392*cdf0e10cSrcweir sal_Bool ScDataPilotFieldObj::hasGroupInfo()
2393*cdf0e10cSrcweir {
2394*cdf0e10cSrcweir     ScUnoGuard aGuard;
2395*cdf0e10cSrcweir     ScDPObject* pDPObj = 0;
2396*cdf0e10cSrcweir     if( ScDPSaveDimension* pDim = GetDPDimension( &pDPObj ) )
2397*cdf0e10cSrcweir         if( const ScDPDimensionSaveData* pDimData = pDPObj->GetSaveData()->GetExistingDimensionData() )
2398*cdf0e10cSrcweir             return pDimData->GetNamedGroupDim( pDim->GetName() ) || pDimData->GetNumGroupDim( pDim->GetName() );
2399*cdf0e10cSrcweir     return sal_False;
2400*cdf0e10cSrcweir }
2401*cdf0e10cSrcweir 
2402*cdf0e10cSrcweir DataPilotFieldGroupInfo ScDataPilotFieldObj::getGroupInfo()
2403*cdf0e10cSrcweir {
2404*cdf0e10cSrcweir     ScUnoGuard aGuard;
2405*cdf0e10cSrcweir     DataPilotFieldGroupInfo aInfo;
2406*cdf0e10cSrcweir     ScDPObject* pDPObj = 0;
2407*cdf0e10cSrcweir     if( ScDPSaveDimension* pDim = GetDPDimension( &pDPObj ) )
2408*cdf0e10cSrcweir     {
2409*cdf0e10cSrcweir         if( const ScDPDimensionSaveData* pDimData = pDPObj->GetSaveData()->GetExistingDimensionData() )
2410*cdf0e10cSrcweir         {
2411*cdf0e10cSrcweir             if( const ScDPSaveGroupDimension* pGroupDim = pDimData->GetNamedGroupDim( pDim->GetName() ) )
2412*cdf0e10cSrcweir             {
2413*cdf0e10cSrcweir                 // grouped by ...
2414*cdf0e10cSrcweir                 aInfo.GroupBy = pGroupDim->GetDatePart();
2415*cdf0e10cSrcweir 
2416*cdf0e10cSrcweir                 // find source field
2417*cdf0e10cSrcweir                 try
2418*cdf0e10cSrcweir                 {
2419*cdf0e10cSrcweir                     Reference< XNameAccess > xFields( mrParent.getDataPilotFields(), UNO_QUERY_THROW );
2420*cdf0e10cSrcweir                     aInfo.SourceField.set( xFields->getByName( pGroupDim->GetSourceDimName() ), UNO_QUERY );
2421*cdf0e10cSrcweir                 }
2422*cdf0e10cSrcweir                 catch( Exception& )
2423*cdf0e10cSrcweir                 {
2424*cdf0e10cSrcweir                 }
2425*cdf0e10cSrcweir 
2426*cdf0e10cSrcweir                 ScDataPilotConversion::FillGroupInfo( aInfo, pGroupDim->GetDateInfo() );
2427*cdf0e10cSrcweir                 if( pGroupDim->GetDatePart() == 0 )
2428*cdf0e10cSrcweir                 {
2429*cdf0e10cSrcweir                     // fill vector of group and group member information
2430*cdf0e10cSrcweir                     ScFieldGroups aGroups;
2431*cdf0e10cSrcweir                     for( sal_Int32 nIdx = 0, nCount = pGroupDim->GetGroupCount(); nIdx < nCount; ++nIdx )
2432*cdf0e10cSrcweir                     {
2433*cdf0e10cSrcweir                         if( const ScDPSaveGroupItem* pGroup = pGroupDim->GetGroupByIndex( nIdx ) )
2434*cdf0e10cSrcweir                         {
2435*cdf0e10cSrcweir                             ScFieldGroup aGroup;
2436*cdf0e10cSrcweir                             aGroup.maName = pGroup->GetGroupName();
2437*cdf0e10cSrcweir                             for( sal_Int32 nMemIdx = 0, nMemCount = pGroup->GetElementCount(); nMemIdx < nMemCount; ++nMemIdx )
2438*cdf0e10cSrcweir                                 if( const String* pMem = pGroup->GetElementByIndex( nMemIdx ) )
2439*cdf0e10cSrcweir                                     aGroup.maMembers.push_back( *pMem );
2440*cdf0e10cSrcweir                             aGroups.push_back( aGroup );
2441*cdf0e10cSrcweir                         }
2442*cdf0e10cSrcweir                     }
2443*cdf0e10cSrcweir                     aInfo.Groups = new ScDataPilotFieldGroupsObj( aGroups );
2444*cdf0e10cSrcweir                 }
2445*cdf0e10cSrcweir             }
2446*cdf0e10cSrcweir             else if( const ScDPSaveNumGroupDimension* pNumGroupDim = pDimData->GetNumGroupDim( pDim->GetName() ) )
2447*cdf0e10cSrcweir             {
2448*cdf0e10cSrcweir                 if (pNumGroupDim->GetDatePart())
2449*cdf0e10cSrcweir                 {
2450*cdf0e10cSrcweir                     ScDataPilotConversion::FillGroupInfo( aInfo, pNumGroupDim->GetDateInfo() );
2451*cdf0e10cSrcweir                     aInfo.GroupBy = pNumGroupDim->GetDatePart();
2452*cdf0e10cSrcweir                 }
2453*cdf0e10cSrcweir                 else
2454*cdf0e10cSrcweir                 {
2455*cdf0e10cSrcweir                     ScDataPilotConversion::FillGroupInfo( aInfo, pNumGroupDim->GetInfo() );
2456*cdf0e10cSrcweir                 }
2457*cdf0e10cSrcweir             }
2458*cdf0e10cSrcweir         }
2459*cdf0e10cSrcweir     }
2460*cdf0e10cSrcweir     return aInfo;
2461*cdf0e10cSrcweir }
2462*cdf0e10cSrcweir 
2463*cdf0e10cSrcweir void ScDataPilotFieldObj::setGroupInfo( const DataPilotFieldGroupInfo* pInfo )
2464*cdf0e10cSrcweir {
2465*cdf0e10cSrcweir     ScUnoGuard aGuard;
2466*cdf0e10cSrcweir     ScDPObject* pDPObj = 0;
2467*cdf0e10cSrcweir     if( /*ScDPSaveDimension* pDim =*/ GetDPDimension( &pDPObj ) )
2468*cdf0e10cSrcweir     {
2469*cdf0e10cSrcweir         ScDPSaveData* pSaveData = pDPObj->GetSaveData();
2470*cdf0e10cSrcweir         if( pInfo && lclCheckMinMaxStep( *pInfo ) )
2471*cdf0e10cSrcweir         {
2472*cdf0e10cSrcweir             ScDPNumGroupInfo aInfo;
2473*cdf0e10cSrcweir             aInfo.Enable = sal_True;
2474*cdf0e10cSrcweir             aInfo.DateValues = pInfo->HasDateValues;
2475*cdf0e10cSrcweir             aInfo.AutoStart = pInfo->HasAutoStart;
2476*cdf0e10cSrcweir             aInfo.AutoEnd = pInfo->HasAutoEnd;
2477*cdf0e10cSrcweir             aInfo.Start = pInfo->Start;
2478*cdf0e10cSrcweir             aInfo.End = pInfo->End;
2479*cdf0e10cSrcweir             aInfo.Step = pInfo->Step;
2480*cdf0e10cSrcweir             Reference< XNamed > xNamed( pInfo->SourceField, UNO_QUERY );
2481*cdf0e10cSrcweir             if( xNamed.is() )
2482*cdf0e10cSrcweir             {
2483*cdf0e10cSrcweir                 ScDPSaveGroupDimension aGroupDim( xNamed->getName(), getName() );
2484*cdf0e10cSrcweir                 if( pInfo->GroupBy )
2485*cdf0e10cSrcweir                     aGroupDim.SetDateInfo(aInfo, pInfo->GroupBy);
2486*cdf0e10cSrcweir                 else
2487*cdf0e10cSrcweir                 {
2488*cdf0e10cSrcweir                     Reference<XIndexAccess> xIndex(pInfo->Groups, UNO_QUERY);
2489*cdf0e10cSrcweir                     if (xIndex.is())
2490*cdf0e10cSrcweir                     {
2491*cdf0e10cSrcweir                         sal_Int32 nCount(xIndex->getCount());
2492*cdf0e10cSrcweir                         for(sal_Int32 i = 0; i < nCount; i++)
2493*cdf0e10cSrcweir                         {
2494*cdf0e10cSrcweir                             Reference<XNamed> xGroupNamed(xIndex->getByIndex(i), UNO_QUERY);
2495*cdf0e10cSrcweir                             if (xGroupNamed.is())
2496*cdf0e10cSrcweir                             {
2497*cdf0e10cSrcweir                                 ScDPSaveGroupItem aItem(xGroupNamed->getName());
2498*cdf0e10cSrcweir                                 Reference<XIndexAccess> xGroupIndex(xGroupNamed, UNO_QUERY);
2499*cdf0e10cSrcweir                                 if (xGroupIndex.is())
2500*cdf0e10cSrcweir                                 {
2501*cdf0e10cSrcweir                                     sal_Int32 nItemCount(xGroupIndex->getCount());
2502*cdf0e10cSrcweir                                     for (sal_Int32 j = 0; j < nItemCount; ++j)
2503*cdf0e10cSrcweir                                     {
2504*cdf0e10cSrcweir                                         Reference<XNamed> xItemNamed(xGroupIndex->getByIndex(j), UNO_QUERY);
2505*cdf0e10cSrcweir                                         if (xItemNamed.is())
2506*cdf0e10cSrcweir                                             aItem.AddElement(xItemNamed->getName());
2507*cdf0e10cSrcweir                                     }
2508*cdf0e10cSrcweir                                 }
2509*cdf0e10cSrcweir                                 aGroupDim.AddGroupItem(aItem);
2510*cdf0e10cSrcweir                             }
2511*cdf0e10cSrcweir                         }
2512*cdf0e10cSrcweir                     }
2513*cdf0e10cSrcweir                 }
2514*cdf0e10cSrcweir 
2515*cdf0e10cSrcweir                 // get dimension savedata or create new if none
2516*cdf0e10cSrcweir                 ScDPDimensionSaveData& rDimSaveData = *pSaveData->GetDimensionData();
2517*cdf0e10cSrcweir                 rDimSaveData.ReplaceGroupDimension( aGroupDim );
2518*cdf0e10cSrcweir             }
2519*cdf0e10cSrcweir             else    // no source field in group info -> numeric group
2520*cdf0e10cSrcweir             {
2521*cdf0e10cSrcweir                 ScDPDimensionSaveData* pDimData = pSaveData->GetDimensionData();     // created if not there
2522*cdf0e10cSrcweir 
2523*cdf0e10cSrcweir                 ScDPSaveNumGroupDimension* pExisting = pDimData->GetNumGroupDimAcc( getName() );
2524*cdf0e10cSrcweir                 if ( pExisting )
2525*cdf0e10cSrcweir                 {
2526*cdf0e10cSrcweir                     if (pInfo->GroupBy)
2527*cdf0e10cSrcweir                         pExisting->SetDateInfo(aInfo, pInfo->GroupBy);
2528*cdf0e10cSrcweir                     // modify existing group dimension
2529*cdf0e10cSrcweir                     pExisting->SetGroupInfo( aInfo );
2530*cdf0e10cSrcweir                 }
2531*cdf0e10cSrcweir                 else if (pInfo->GroupBy)
2532*cdf0e10cSrcweir                 {
2533*cdf0e10cSrcweir                     // create new group dimension
2534*cdf0e10cSrcweir                     ScDPSaveNumGroupDimension aNumGroupDim( getName(), aInfo, pInfo->GroupBy );
2535*cdf0e10cSrcweir                     pDimData->AddNumGroupDimension( aNumGroupDim );
2536*cdf0e10cSrcweir                 }
2537*cdf0e10cSrcweir                 else
2538*cdf0e10cSrcweir                 {
2539*cdf0e10cSrcweir                     // create new group dimension
2540*cdf0e10cSrcweir                     ScDPSaveNumGroupDimension aNumGroupDim( getName(), aInfo );
2541*cdf0e10cSrcweir                     pDimData->AddNumGroupDimension( aNumGroupDim );
2542*cdf0e10cSrcweir                 }
2543*cdf0e10cSrcweir             }
2544*cdf0e10cSrcweir         }
2545*cdf0e10cSrcweir         else    // null passed as argument
2546*cdf0e10cSrcweir         {
2547*cdf0e10cSrcweir             pSaveData->SetDimensionData( 0 );
2548*cdf0e10cSrcweir         }
2549*cdf0e10cSrcweir 
2550*cdf0e10cSrcweir         pDPObj->SetSaveData( *pSaveData );
2551*cdf0e10cSrcweir         SetDPObject( pDPObj );
2552*cdf0e10cSrcweir     }
2553*cdf0e10cSrcweir }
2554*cdf0e10cSrcweir 
2555*cdf0e10cSrcweir sal_Bool ScDataPilotFieldObj::HasString(const Sequence< OUString >& rItems, const OUString& aString)
2556*cdf0e10cSrcweir {
2557*cdf0e10cSrcweir     sal_Bool bRet = sal_False;
2558*cdf0e10cSrcweir 
2559*cdf0e10cSrcweir     sal_Int32 nCount(rItems.getLength());
2560*cdf0e10cSrcweir     sal_Int32 nItem(0);
2561*cdf0e10cSrcweir     while (nItem < nCount && !bRet)
2562*cdf0e10cSrcweir     {
2563*cdf0e10cSrcweir         bRet = rItems[nItem] == aString;
2564*cdf0e10cSrcweir         ++nItem;
2565*cdf0e10cSrcweir     }
2566*cdf0e10cSrcweir 
2567*cdf0e10cSrcweir     return bRet;
2568*cdf0e10cSrcweir }
2569*cdf0e10cSrcweir 
2570*cdf0e10cSrcweir // XDataPilotFieldGrouping
2571*cdf0e10cSrcweir Reference< XDataPilotField > SAL_CALL ScDataPilotFieldObj::createNameGroup( const Sequence< OUString >& rItems )
2572*cdf0e10cSrcweir          throw (RuntimeException, IllegalArgumentException)
2573*cdf0e10cSrcweir {
2574*cdf0e10cSrcweir 	ScUnoGuard aGuard;
2575*cdf0e10cSrcweir 
2576*cdf0e10cSrcweir     Reference< XDataPilotField > xRet;
2577*cdf0e10cSrcweir     OUString sNewDim;
2578*cdf0e10cSrcweir 
2579*cdf0e10cSrcweir     if( !rItems.hasElements() )
2580*cdf0e10cSrcweir         throw IllegalArgumentException();
2581*cdf0e10cSrcweir 
2582*cdf0e10cSrcweir     ScDPObject* pDPObj = 0;
2583*cdf0e10cSrcweir     if( ScDPSaveDimension* pDim = GetDPDimension( &pDPObj ) )
2584*cdf0e10cSrcweir     {
2585*cdf0e10cSrcweir         String aDimName = pDim->GetName();
2586*cdf0e10cSrcweir 
2587*cdf0e10cSrcweir         ScDPSaveData aSaveData = *pDPObj->GetSaveData();
2588*cdf0e10cSrcweir         ScDPDimensionSaveData* pDimData = aSaveData.GetDimensionData();     // created if not there
2589*cdf0e10cSrcweir 
2590*cdf0e10cSrcweir         // find original base
2591*cdf0e10cSrcweir         String aBaseDimName( aDimName );
2592*cdf0e10cSrcweir         const ScDPSaveGroupDimension* pBaseGroupDim = pDimData->GetNamedGroupDim( aDimName );
2593*cdf0e10cSrcweir         if ( pBaseGroupDim )
2594*cdf0e10cSrcweir         {
2595*cdf0e10cSrcweir             // any entry's SourceDimName is the original base
2596*cdf0e10cSrcweir             aBaseDimName = pBaseGroupDim->GetSourceDimName();
2597*cdf0e10cSrcweir         }
2598*cdf0e10cSrcweir 
2599*cdf0e10cSrcweir         // find existing group dimension
2600*cdf0e10cSrcweir         // (using the selected dim, can be intermediate group dim)
2601*cdf0e10cSrcweir         ScDPSaveGroupDimension* pGroupDimension = pDimData->GetGroupDimAccForBase( aDimName );
2602*cdf0e10cSrcweir 
2603*cdf0e10cSrcweir         // remove the selected items from their groups
2604*cdf0e10cSrcweir         // (empty groups are removed, too)
2605*cdf0e10cSrcweir         sal_Int32 nEntryCount = rItems.getLength();
2606*cdf0e10cSrcweir         sal_Int32 nEntry;
2607*cdf0e10cSrcweir         if ( pGroupDimension )
2608*cdf0e10cSrcweir         {
2609*cdf0e10cSrcweir             for (nEntry=0; nEntry<nEntryCount; nEntry++)
2610*cdf0e10cSrcweir             {
2611*cdf0e10cSrcweir                 String aEntryName(rItems[nEntry]);
2612*cdf0e10cSrcweir                 if ( pBaseGroupDim )
2613*cdf0e10cSrcweir                 {
2614*cdf0e10cSrcweir                     // for each selected (intermediate) group, remove all its items
2615*cdf0e10cSrcweir                     // (same logic as for adding, below)
2616*cdf0e10cSrcweir                     const ScDPSaveGroupItem* pBaseGroup = pBaseGroupDim->GetNamedGroup( aEntryName );
2617*cdf0e10cSrcweir                     if ( pBaseGroup )
2618*cdf0e10cSrcweir                         pBaseGroup->RemoveElementsFromGroups( *pGroupDimension );   // remove all elements
2619*cdf0e10cSrcweir                     else
2620*cdf0e10cSrcweir                         pGroupDimension->RemoveFromGroups( aEntryName );
2621*cdf0e10cSrcweir                 }
2622*cdf0e10cSrcweir                 else
2623*cdf0e10cSrcweir                     pGroupDimension->RemoveFromGroups( aEntryName );
2624*cdf0e10cSrcweir             }
2625*cdf0e10cSrcweir         }
2626*cdf0e10cSrcweir 
2627*cdf0e10cSrcweir         ScDPSaveGroupDimension* pNewGroupDim = 0;
2628*cdf0e10cSrcweir         if ( !pGroupDimension )
2629*cdf0e10cSrcweir         {
2630*cdf0e10cSrcweir             // create a new group dimension
2631*cdf0e10cSrcweir             String aGroupDimName = pDimData->CreateGroupDimName( aBaseDimName, *pDPObj, false, NULL );
2632*cdf0e10cSrcweir             pNewGroupDim = new ScDPSaveGroupDimension( aBaseDimName, aGroupDimName );
2633*cdf0e10cSrcweir             sNewDim = aGroupDimName;
2634*cdf0e10cSrcweir 
2635*cdf0e10cSrcweir             pGroupDimension = pNewGroupDim;     // make changes to the new dim if none existed
2636*cdf0e10cSrcweir 
2637*cdf0e10cSrcweir             if ( pBaseGroupDim )
2638*cdf0e10cSrcweir             {
2639*cdf0e10cSrcweir                 // If it's a higher-order group dimension, pre-allocate groups for all
2640*cdf0e10cSrcweir                 // non-selected original groups, so the individual base members aren't
2641*cdf0e10cSrcweir                 // used for automatic groups (this would make the original groups hard
2642*cdf0e10cSrcweir                 // to find).
2643*cdf0e10cSrcweir                 //! Also do this when removing groups?
2644*cdf0e10cSrcweir                 //! Handle this case dynamically with automatic groups?
2645*cdf0e10cSrcweir 
2646*cdf0e10cSrcweir                 long nGroupCount = pBaseGroupDim->GetGroupCount();
2647*cdf0e10cSrcweir                 for ( long nGroup = 0; nGroup < nGroupCount; nGroup++ )
2648*cdf0e10cSrcweir                 {
2649*cdf0e10cSrcweir                     const ScDPSaveGroupItem* pBaseGroup = pBaseGroupDim->GetGroupByIndex( nGroup );
2650*cdf0e10cSrcweir 
2651*cdf0e10cSrcweir                     StrData aStrData( pBaseGroup->GetGroupName() );
2652*cdf0e10cSrcweir                     if ( !HasString(rItems, aStrData.GetString()) )    //! ignore case?
2653*cdf0e10cSrcweir                     {
2654*cdf0e10cSrcweir                         // add an additional group for each item that is not in the selection
2655*cdf0e10cSrcweir                         ScDPSaveGroupItem aGroup( pBaseGroup->GetGroupName() );
2656*cdf0e10cSrcweir                         aGroup.AddElementsFromGroup( *pBaseGroup );
2657*cdf0e10cSrcweir                         pGroupDimension->AddGroupItem( aGroup );
2658*cdf0e10cSrcweir                     }
2659*cdf0e10cSrcweir                 }
2660*cdf0e10cSrcweir             }
2661*cdf0e10cSrcweir         }
2662*cdf0e10cSrcweir         String aGroupDimName = pGroupDimension->GetGroupDimName();
2663*cdf0e10cSrcweir 
2664*cdf0e10cSrcweir         //! localized prefix string
2665*cdf0e10cSrcweir         String aGroupName = pGroupDimension->CreateGroupName( String( RTL_CONSTASCII_USTRINGPARAM( "Group" ) ) );
2666*cdf0e10cSrcweir         ScDPSaveGroupItem aGroup( aGroupName );
2667*cdf0e10cSrcweir         Reference< XNameAccess > xMembers = GetMembers();
2668*cdf0e10cSrcweir         if (!xMembers.is())
2669*cdf0e10cSrcweir         {
2670*cdf0e10cSrcweir             delete pNewGroupDim;
2671*cdf0e10cSrcweir             throw RuntimeException();
2672*cdf0e10cSrcweir         }
2673*cdf0e10cSrcweir 
2674*cdf0e10cSrcweir         for (nEntry=0; nEntry<nEntryCount; nEntry++)
2675*cdf0e10cSrcweir         {
2676*cdf0e10cSrcweir             String aEntryName(rItems[nEntry]);
2677*cdf0e10cSrcweir 
2678*cdf0e10cSrcweir             if (!xMembers->hasByName(aEntryName))
2679*cdf0e10cSrcweir             {
2680*cdf0e10cSrcweir                 delete pNewGroupDim;
2681*cdf0e10cSrcweir                 throw IllegalArgumentException();
2682*cdf0e10cSrcweir             }
2683*cdf0e10cSrcweir 
2684*cdf0e10cSrcweir             if ( pBaseGroupDim )
2685*cdf0e10cSrcweir             {
2686*cdf0e10cSrcweir                 // for each selected (intermediate) group, add all its items
2687*cdf0e10cSrcweir                 const ScDPSaveGroupItem* pBaseGroup = pBaseGroupDim->GetNamedGroup( aEntryName );
2688*cdf0e10cSrcweir                 if ( pBaseGroup )
2689*cdf0e10cSrcweir                     aGroup.AddElementsFromGroup( *pBaseGroup );
2690*cdf0e10cSrcweir                 else
2691*cdf0e10cSrcweir                     aGroup.AddElement( aEntryName );    // no group found -> automatic group, add the item itself
2692*cdf0e10cSrcweir             }
2693*cdf0e10cSrcweir             else
2694*cdf0e10cSrcweir                 aGroup.AddElement( aEntryName );        // no group dimension, add all items directly
2695*cdf0e10cSrcweir         }
2696*cdf0e10cSrcweir 
2697*cdf0e10cSrcweir         pGroupDimension->AddGroupItem( aGroup );
2698*cdf0e10cSrcweir 
2699*cdf0e10cSrcweir         if ( pNewGroupDim )
2700*cdf0e10cSrcweir         {
2701*cdf0e10cSrcweir             pDimData->AddGroupDimension( *pNewGroupDim );
2702*cdf0e10cSrcweir             delete pNewGroupDim;        // AddGroupDimension copies the object
2703*cdf0e10cSrcweir             // don't access pGroupDimension after here
2704*cdf0e10cSrcweir         }
2705*cdf0e10cSrcweir         pGroupDimension = pNewGroupDim = NULL;
2706*cdf0e10cSrcweir 
2707*cdf0e10cSrcweir         // set orientation
2708*cdf0e10cSrcweir         ScDPSaveDimension* pSaveDimension = aSaveData.GetDimensionByName( aGroupDimName );
2709*cdf0e10cSrcweir         if ( pSaveDimension->GetOrientation() == DataPilotFieldOrientation_HIDDEN )
2710*cdf0e10cSrcweir         {
2711*cdf0e10cSrcweir             ScDPSaveDimension* pOldDimension = aSaveData.GetDimensionByName( aDimName );
2712*cdf0e10cSrcweir             pSaveDimension->SetOrientation( pOldDimension->GetOrientation() );
2713*cdf0e10cSrcweir             long nPosition = 0;     //! before (immediate) base
2714*cdf0e10cSrcweir             aSaveData.SetPosition( pSaveDimension, nPosition );
2715*cdf0e10cSrcweir         }
2716*cdf0e10cSrcweir 
2717*cdf0e10cSrcweir         // apply changes
2718*cdf0e10cSrcweir         pDPObj->SetSaveData( aSaveData );
2719*cdf0e10cSrcweir         SetDPObject( pDPObj );
2720*cdf0e10cSrcweir     }
2721*cdf0e10cSrcweir 
2722*cdf0e10cSrcweir     // if new grouping field has been created (on first group), return it
2723*cdf0e10cSrcweir     if( sNewDim.getLength() > 0 )
2724*cdf0e10cSrcweir     {
2725*cdf0e10cSrcweir         Reference< XNameAccess > xFields(mrParent.getDataPilotFields(), UNO_QUERY);
2726*cdf0e10cSrcweir         if (xFields.is())
2727*cdf0e10cSrcweir         {
2728*cdf0e10cSrcweir             xRet.set(xFields->getByName(sNewDim), UNO_QUERY);
2729*cdf0e10cSrcweir             DBG_ASSERT(xRet.is(), "there is a name, so there should be also a field");
2730*cdf0e10cSrcweir         }
2731*cdf0e10cSrcweir     }
2732*cdf0e10cSrcweir     return xRet;
2733*cdf0e10cSrcweir }
2734*cdf0e10cSrcweir 
2735*cdf0e10cSrcweir Reference < XDataPilotField > SAL_CALL ScDataPilotFieldObj::createDateGroup( const DataPilotFieldGroupInfo& rInfo )
2736*cdf0e10cSrcweir         throw (RuntimeException, IllegalArgumentException)
2737*cdf0e10cSrcweir {
2738*cdf0e10cSrcweir 	ScUnoGuard aGuard;
2739*cdf0e10cSrcweir     using namespace ::com::sun::star::sheet::DataPilotFieldGroupBy;
2740*cdf0e10cSrcweir 
2741*cdf0e10cSrcweir     // check min/max/step, HasDateValues must be set always
2742*cdf0e10cSrcweir     if( !rInfo.HasDateValues || !lclCheckMinMaxStep( rInfo ) )
2743*cdf0e10cSrcweir         throw IllegalArgumentException();
2744*cdf0e10cSrcweir     // only a single date flag is allowed
2745*cdf0e10cSrcweir     if( (rInfo.GroupBy == 0) || (rInfo.GroupBy > YEARS) || ((rInfo.GroupBy & (rInfo.GroupBy - 1)) != 0) )
2746*cdf0e10cSrcweir         throw IllegalArgumentException();
2747*cdf0e10cSrcweir     // step must be zero, if something else than DAYS is specified
2748*cdf0e10cSrcweir     if( rInfo.Step >= ((rInfo.GroupBy == DAYS) ? 32768.0 : 1.0) )
2749*cdf0e10cSrcweir         throw IllegalArgumentException();
2750*cdf0e10cSrcweir 
2751*cdf0e10cSrcweir     String aGroupDimName;
2752*cdf0e10cSrcweir     ScDPObject* pDPObj = 0;
2753*cdf0e10cSrcweir     if( ScDPSaveDimension* pDim = GetDPDimension( &pDPObj ) )
2754*cdf0e10cSrcweir     {
2755*cdf0e10cSrcweir         ScDPNumGroupInfo aInfo;
2756*cdf0e10cSrcweir         aInfo.Enable = sal_True;
2757*cdf0e10cSrcweir         aInfo.DateValues = (rInfo.GroupBy == DAYS) && (rInfo.Step >= 1.0);
2758*cdf0e10cSrcweir         aInfo.AutoStart = rInfo.HasAutoStart;
2759*cdf0e10cSrcweir         aInfo.AutoEnd = rInfo.HasAutoEnd;
2760*cdf0e10cSrcweir         aInfo.Start = rInfo.Start;
2761*cdf0e10cSrcweir         aInfo.End = rInfo.End;
2762*cdf0e10cSrcweir         aInfo.Step = static_cast< sal_Int32 >( rInfo.Step );
2763*cdf0e10cSrcweir 
2764*cdf0e10cSrcweir         // create a local copy of the entire save data (will be written back below)
2765*cdf0e10cSrcweir         ScDPSaveData aSaveData = *pDPObj->GetSaveData();
2766*cdf0e10cSrcweir         // get or create dimension save data
2767*cdf0e10cSrcweir         ScDPDimensionSaveData& rDimData = *aSaveData.GetDimensionData();
2768*cdf0e10cSrcweir 
2769*cdf0e10cSrcweir         // find source dimension name
2770*cdf0e10cSrcweir         const String& rDimName = pDim->GetName();
2771*cdf0e10cSrcweir         const ScDPSaveGroupDimension* pGroupDim = rDimData.GetNamedGroupDim( rDimName );
2772*cdf0e10cSrcweir         String aSrcDimName = pGroupDim ? pGroupDim->GetSourceDimName() : rDimName;
2773*cdf0e10cSrcweir 
2774*cdf0e10cSrcweir         // find a group dimension for the base field, or get numeric grouping
2775*cdf0e10cSrcweir         pGroupDim = rDimData.GetFirstNamedGroupDim( aSrcDimName );
2776*cdf0e10cSrcweir         const ScDPSaveNumGroupDimension* pNumGroupDim = rDimData.GetNumGroupDim( aSrcDimName );
2777*cdf0e10cSrcweir 
2778*cdf0e10cSrcweir         // do not group by dates, if named groups or numeric grouping is present
2779*cdf0e10cSrcweir         bool bHasNamedGrouping = pGroupDim && !pGroupDim->GetDateInfo().Enable;
2780*cdf0e10cSrcweir         bool bHasNumGrouping = pNumGroupDim && pNumGroupDim->GetInfo().Enable && !pNumGroupDim->GetInfo().DateValues && !pNumGroupDim->GetDateInfo().Enable;
2781*cdf0e10cSrcweir         if( bHasNamedGrouping || bHasNumGrouping )
2782*cdf0e10cSrcweir             throw IllegalArgumentException();
2783*cdf0e10cSrcweir 
2784*cdf0e10cSrcweir         if( aInfo.DateValues )  // create day ranges grouping
2785*cdf0e10cSrcweir         {
2786*cdf0e10cSrcweir             // first remove all named group dimensions
2787*cdf0e10cSrcweir             while( pGroupDim )
2788*cdf0e10cSrcweir             {
2789*cdf0e10cSrcweir                 String aGroupDimName2 = pGroupDim->GetGroupDimName();
2790*cdf0e10cSrcweir                 // find next group dimension before deleting this group
2791*cdf0e10cSrcweir                 pGroupDim = rDimData.GetNextNamedGroupDim( aGroupDimName2 );
2792*cdf0e10cSrcweir                 // remove from dimension save data
2793*cdf0e10cSrcweir                 rDimData.RemoveGroupDimension( aGroupDimName2 );
2794*cdf0e10cSrcweir                 // also remove save data settings for the dimension that no longer exists
2795*cdf0e10cSrcweir                 aSaveData.RemoveDimensionByName( aGroupDimName2 );
2796*cdf0e10cSrcweir             }
2797*cdf0e10cSrcweir             // create or replace the number grouping dimension
2798*cdf0e10cSrcweir             ScDPSaveNumGroupDimension aNumGroupDim( aSrcDimName, aInfo );
2799*cdf0e10cSrcweir             rDimData.ReplaceNumGroupDimension( aNumGroupDim );
2800*cdf0e10cSrcweir         }
2801*cdf0e10cSrcweir         else    // create date grouping
2802*cdf0e10cSrcweir         {
2803*cdf0e10cSrcweir             // collect all existing date flags
2804*cdf0e10cSrcweir             sal_Int32 nDateParts = rDimData.CollectDateParts( aSrcDimName );
2805*cdf0e10cSrcweir             if( nDateParts == 0 )
2806*cdf0e10cSrcweir             {
2807*cdf0e10cSrcweir                 // insert numeric group dimension, if no date groups exist yet (or replace day range grouping)
2808*cdf0e10cSrcweir                 ScDPSaveNumGroupDimension aNumGroupDim( aSrcDimName, aInfo, rInfo.GroupBy );
2809*cdf0e10cSrcweir                 rDimData.ReplaceNumGroupDimension( aNumGroupDim );
2810*cdf0e10cSrcweir             }
2811*cdf0e10cSrcweir             else if( (nDateParts & rInfo.GroupBy) == 0 )    // do nothing if date field exists already
2812*cdf0e10cSrcweir             {
2813*cdf0e10cSrcweir                 // create new named group dimension for additional date groups
2814*cdf0e10cSrcweir                 aGroupDimName = rDimData.CreateDateGroupDimName( rInfo.GroupBy, *pDPObj, true, 0 );
2815*cdf0e10cSrcweir                 ScDPSaveGroupDimension aGroupDim( aSrcDimName, aGroupDimName, aInfo, rInfo.GroupBy );
2816*cdf0e10cSrcweir                 rDimData.AddGroupDimension( aGroupDim );
2817*cdf0e10cSrcweir 
2818*cdf0e10cSrcweir                 // set orientation of new named group dimension
2819*cdf0e10cSrcweir                 ScDPSaveDimension& rSaveDim = *aSaveData.GetDimensionByName( aGroupDimName );
2820*cdf0e10cSrcweir                 if( rSaveDim.GetOrientation() == DataPilotFieldOrientation_HIDDEN )
2821*cdf0e10cSrcweir                 {
2822*cdf0e10cSrcweir                     ScDPSaveDimension& rOldDim = *aSaveData.GetDimensionByName( aSrcDimName );
2823*cdf0e10cSrcweir                     rSaveDim.SetOrientation( rOldDim.GetOrientation() );
2824*cdf0e10cSrcweir                     aSaveData.SetPosition( &rSaveDim, 0 );  //! before (immediate) base
2825*cdf0e10cSrcweir                 }
2826*cdf0e10cSrcweir             }
2827*cdf0e10cSrcweir         }
2828*cdf0e10cSrcweir 
2829*cdf0e10cSrcweir         // apply changes
2830*cdf0e10cSrcweir         pDPObj->SetSaveData( aSaveData );
2831*cdf0e10cSrcweir         SetDPObject( pDPObj );
2832*cdf0e10cSrcweir     }
2833*cdf0e10cSrcweir 
2834*cdf0e10cSrcweir     // return the UNO object of the new dimension, after writing back saved data
2835*cdf0e10cSrcweir     Reference< XDataPilotField > xRet;
2836*cdf0e10cSrcweir     if( aGroupDimName.Len() > 0 ) try
2837*cdf0e10cSrcweir     {
2838*cdf0e10cSrcweir         Reference< XNameAccess > xFields( mrParent.getDataPilotFields(), UNO_QUERY_THROW );
2839*cdf0e10cSrcweir         xRet.set( xFields->getByName( aGroupDimName ), UNO_QUERY );
2840*cdf0e10cSrcweir     }
2841*cdf0e10cSrcweir     catch( Exception& )
2842*cdf0e10cSrcweir     {
2843*cdf0e10cSrcweir     }
2844*cdf0e10cSrcweir     return xRet;
2845*cdf0e10cSrcweir }
2846*cdf0e10cSrcweir 
2847*cdf0e10cSrcweir // ============================================================================
2848*cdf0e10cSrcweir 
2849*cdf0e10cSrcweir namespace {
2850*cdf0e10cSrcweir 
2851*cdf0e10cSrcweir bool lclExtractGroupMembers( ScFieldGroupMembers& rMembers, const Any& rElement )
2852*cdf0e10cSrcweir {
2853*cdf0e10cSrcweir     // allow empty value to create a new group
2854*cdf0e10cSrcweir     if( !rElement.hasValue() )
2855*cdf0e10cSrcweir         return true;
2856*cdf0e10cSrcweir 
2857*cdf0e10cSrcweir     // try to extract a simple sequence of strings
2858*cdf0e10cSrcweir     Sequence< OUString > aSeq;
2859*cdf0e10cSrcweir     if( rElement >>= aSeq )
2860*cdf0e10cSrcweir     {
2861*cdf0e10cSrcweir         if( aSeq.hasElements() )
2862*cdf0e10cSrcweir             rMembers.insert( rMembers.end(), aSeq.getConstArray(), aSeq.getConstArray() + aSeq.getLength() );
2863*cdf0e10cSrcweir         return true;
2864*cdf0e10cSrcweir     }
2865*cdf0e10cSrcweir 
2866*cdf0e10cSrcweir     // try to use XIndexAccess providing objects that support XNamed
2867*cdf0e10cSrcweir     Reference< XIndexAccess > xItemsIA( rElement, UNO_QUERY );
2868*cdf0e10cSrcweir     if( xItemsIA.is() )
2869*cdf0e10cSrcweir     {
2870*cdf0e10cSrcweir         for( sal_Int32 nIdx = 0, nCount = xItemsIA->getCount(); nIdx < nCount; ++nIdx )
2871*cdf0e10cSrcweir         {
2872*cdf0e10cSrcweir             try // getByIndex() should not throw, but we cannot be sure
2873*cdf0e10cSrcweir             {
2874*cdf0e10cSrcweir                 Reference< XNamed > xItemName( xItemsIA->getByIndex( nIdx ), UNO_QUERY_THROW );
2875*cdf0e10cSrcweir                 rMembers.push_back( xItemName->getName() );
2876*cdf0e10cSrcweir             }
2877*cdf0e10cSrcweir             catch( Exception& )
2878*cdf0e10cSrcweir             {
2879*cdf0e10cSrcweir                 // ignore exceptions, go ahead with next element in the array
2880*cdf0e10cSrcweir             }
2881*cdf0e10cSrcweir         }
2882*cdf0e10cSrcweir         return true;
2883*cdf0e10cSrcweir     }
2884*cdf0e10cSrcweir 
2885*cdf0e10cSrcweir     // nothing valid inside the Any -> return false
2886*cdf0e10cSrcweir     return false;
2887*cdf0e10cSrcweir }
2888*cdf0e10cSrcweir 
2889*cdf0e10cSrcweir } // namespace
2890*cdf0e10cSrcweir 
2891*cdf0e10cSrcweir // ----------------------------------------------------------------------------
2892*cdf0e10cSrcweir 
2893*cdf0e10cSrcweir ScDataPilotFieldGroupsObj::ScDataPilotFieldGroupsObj( const ScFieldGroups& rGroups ) :
2894*cdf0e10cSrcweir     maGroups( rGroups )
2895*cdf0e10cSrcweir {
2896*cdf0e10cSrcweir }
2897*cdf0e10cSrcweir 
2898*cdf0e10cSrcweir ScDataPilotFieldGroupsObj::~ScDataPilotFieldGroupsObj()
2899*cdf0e10cSrcweir {
2900*cdf0e10cSrcweir }
2901*cdf0e10cSrcweir 
2902*cdf0e10cSrcweir // XNameAccess
2903*cdf0e10cSrcweir 
2904*cdf0e10cSrcweir Any SAL_CALL ScDataPilotFieldGroupsObj::getByName( const OUString& rName )
2905*cdf0e10cSrcweir         throw(NoSuchElementException, WrappedTargetException, RuntimeException)
2906*cdf0e10cSrcweir {
2907*cdf0e10cSrcweir 	ScUnoGuard aGuard;
2908*cdf0e10cSrcweir     if( implFindByName( rName ) == maGroups.end() )
2909*cdf0e10cSrcweir         throw NoSuchElementException();
2910*cdf0e10cSrcweir     return Any( Reference< XNameAccess >( new ScDataPilotFieldGroupObj( *this, rName ) ) );
2911*cdf0e10cSrcweir }
2912*cdf0e10cSrcweir 
2913*cdf0e10cSrcweir Sequence< OUString > SAL_CALL ScDataPilotFieldGroupsObj::getElementNames() throw(RuntimeException)
2914*cdf0e10cSrcweir {
2915*cdf0e10cSrcweir 	ScUnoGuard aGuard;
2916*cdf0e10cSrcweir     Sequence< OUString > aSeq;
2917*cdf0e10cSrcweir     if( !maGroups.empty() )
2918*cdf0e10cSrcweir     {
2919*cdf0e10cSrcweir         aSeq.realloc( static_cast< sal_Int32 >( maGroups.size() ) );
2920*cdf0e10cSrcweir         OUString* pName = aSeq.getArray();
2921*cdf0e10cSrcweir         for( ScFieldGroups::iterator aIt = maGroups.begin(), aEnd = maGroups.end(); aIt != aEnd; ++aIt, ++pName )
2922*cdf0e10cSrcweir             *pName = aIt->maName;
2923*cdf0e10cSrcweir     }
2924*cdf0e10cSrcweir     return aSeq;
2925*cdf0e10cSrcweir }
2926*cdf0e10cSrcweir 
2927*cdf0e10cSrcweir sal_Bool SAL_CALL ScDataPilotFieldGroupsObj::hasByName( const OUString& rName ) throw(RuntimeException)
2928*cdf0e10cSrcweir {
2929*cdf0e10cSrcweir 	ScUnoGuard aGuard;
2930*cdf0e10cSrcweir     return implFindByName( rName ) != maGroups.end();
2931*cdf0e10cSrcweir }
2932*cdf0e10cSrcweir 
2933*cdf0e10cSrcweir // XNameReplace
2934*cdf0e10cSrcweir 
2935*cdf0e10cSrcweir void SAL_CALL ScDataPilotFieldGroupsObj::replaceByName( const OUString& rName, const Any& rElement )
2936*cdf0e10cSrcweir         throw (IllegalArgumentException, NoSuchElementException, WrappedTargetException, RuntimeException)
2937*cdf0e10cSrcweir {
2938*cdf0e10cSrcweir     ScUnoGuard aGuard;
2939*cdf0e10cSrcweir 
2940*cdf0e10cSrcweir     if( rName.getLength() == 0 )
2941*cdf0e10cSrcweir         throw IllegalArgumentException();
2942*cdf0e10cSrcweir 
2943*cdf0e10cSrcweir     ScFieldGroups::iterator aIt = implFindByName( rName );
2944*cdf0e10cSrcweir     if( aIt == maGroups.end() )
2945*cdf0e10cSrcweir         throw NoSuchElementException();
2946*cdf0e10cSrcweir 
2947*cdf0e10cSrcweir     // read all item names provided by the passed object
2948*cdf0e10cSrcweir     ScFieldGroupMembers aMembers;
2949*cdf0e10cSrcweir     if( !lclExtractGroupMembers( aMembers, rElement ) )
2950*cdf0e10cSrcweir         throw IllegalArgumentException();
2951*cdf0e10cSrcweir 
2952*cdf0e10cSrcweir     // copy and forget, faster than vector assignment
2953*cdf0e10cSrcweir     aIt->maMembers.swap( aMembers );
2954*cdf0e10cSrcweir }
2955*cdf0e10cSrcweir 
2956*cdf0e10cSrcweir // XNameContainer
2957*cdf0e10cSrcweir 
2958*cdf0e10cSrcweir void SAL_CALL ScDataPilotFieldGroupsObj::insertByName( const OUString& rName, const Any& rElement )
2959*cdf0e10cSrcweir         throw (IllegalArgumentException, ElementExistException, WrappedTargetException, RuntimeException)
2960*cdf0e10cSrcweir {
2961*cdf0e10cSrcweir     ScUnoGuard aGuard;
2962*cdf0e10cSrcweir 
2963*cdf0e10cSrcweir     if( rName.getLength() == 0 )
2964*cdf0e10cSrcweir         throw IllegalArgumentException();
2965*cdf0e10cSrcweir 
2966*cdf0e10cSrcweir     ScFieldGroups::iterator aIt = implFindByName( rName );
2967*cdf0e10cSrcweir     if( aIt != maGroups.end() )
2968*cdf0e10cSrcweir         throw ElementExistException();
2969*cdf0e10cSrcweir 
2970*cdf0e10cSrcweir     // read all item names provided by the passed object
2971*cdf0e10cSrcweir     ScFieldGroupMembers aMembers;
2972*cdf0e10cSrcweir     if( !lclExtractGroupMembers( aMembers, rElement ) )
2973*cdf0e10cSrcweir         throw IllegalArgumentException();
2974*cdf0e10cSrcweir 
2975*cdf0e10cSrcweir     // create the new entry if no error has been occured
2976*cdf0e10cSrcweir     maGroups.resize( maGroups.size() + 1 );
2977*cdf0e10cSrcweir     ScFieldGroup& rGroup = maGroups.back();
2978*cdf0e10cSrcweir     rGroup.maName = rName;
2979*cdf0e10cSrcweir     rGroup.maMembers.swap( aMembers );
2980*cdf0e10cSrcweir }
2981*cdf0e10cSrcweir 
2982*cdf0e10cSrcweir void SAL_CALL ScDataPilotFieldGroupsObj::removeByName( const OUString& rName )
2983*cdf0e10cSrcweir         throw (NoSuchElementException, WrappedTargetException, RuntimeException)
2984*cdf0e10cSrcweir {
2985*cdf0e10cSrcweir     ScUnoGuard aGuard;
2986*cdf0e10cSrcweir 
2987*cdf0e10cSrcweir     if( rName.getLength() == 0 )
2988*cdf0e10cSrcweir         throw IllegalArgumentException();
2989*cdf0e10cSrcweir 
2990*cdf0e10cSrcweir     ScFieldGroups::iterator aIt = implFindByName( rName );
2991*cdf0e10cSrcweir     if( aIt == maGroups.end() )
2992*cdf0e10cSrcweir         throw NoSuchElementException();
2993*cdf0e10cSrcweir 
2994*cdf0e10cSrcweir     maGroups.erase( aIt );
2995*cdf0e10cSrcweir }
2996*cdf0e10cSrcweir 
2997*cdf0e10cSrcweir // XIndexAccess
2998*cdf0e10cSrcweir 
2999*cdf0e10cSrcweir sal_Int32 SAL_CALL ScDataPilotFieldGroupsObj::getCount() throw(RuntimeException)
3000*cdf0e10cSrcweir {
3001*cdf0e10cSrcweir 	ScUnoGuard aGuard;
3002*cdf0e10cSrcweir     return static_cast< sal_Int32 >( maGroups.size() );
3003*cdf0e10cSrcweir }
3004*cdf0e10cSrcweir 
3005*cdf0e10cSrcweir Any SAL_CALL ScDataPilotFieldGroupsObj::getByIndex( sal_Int32 nIndex )
3006*cdf0e10cSrcweir         throw(IndexOutOfBoundsException, WrappedTargetException, RuntimeException)
3007*cdf0e10cSrcweir {
3008*cdf0e10cSrcweir 	ScUnoGuard aGuard;
3009*cdf0e10cSrcweir     if ((nIndex < 0) || (nIndex >= static_cast< sal_Int32 >( maGroups.size() )))
3010*cdf0e10cSrcweir         throw IndexOutOfBoundsException();
3011*cdf0e10cSrcweir     return Any( Reference< XNameAccess >( new ScDataPilotFieldGroupObj( *this, maGroups[ nIndex ].maName ) ) );
3012*cdf0e10cSrcweir }
3013*cdf0e10cSrcweir 
3014*cdf0e10cSrcweir // XEnumerationAccess
3015*cdf0e10cSrcweir 
3016*cdf0e10cSrcweir Reference<XEnumeration> SAL_CALL ScDataPilotFieldGroupsObj::createEnumeration() throw(RuntimeException)
3017*cdf0e10cSrcweir {
3018*cdf0e10cSrcweir     ScUnoGuard aGuard;
3019*cdf0e10cSrcweir     return new ScIndexEnumeration( this, OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.sheet.DataPilotFieldGroupsEnumeration" ) ) );
3020*cdf0e10cSrcweir }
3021*cdf0e10cSrcweir 
3022*cdf0e10cSrcweir // XElementAccess
3023*cdf0e10cSrcweir 
3024*cdf0e10cSrcweir uno::Type SAL_CALL ScDataPilotFieldGroupsObj::getElementType() throw(RuntimeException)
3025*cdf0e10cSrcweir {
3026*cdf0e10cSrcweir 	ScUnoGuard aGuard;
3027*cdf0e10cSrcweir     return getCppuType( (Reference< XNameAccess >*)0 );
3028*cdf0e10cSrcweir }
3029*cdf0e10cSrcweir 
3030*cdf0e10cSrcweir sal_Bool SAL_CALL ScDataPilotFieldGroupsObj::hasElements() throw(RuntimeException)
3031*cdf0e10cSrcweir {
3032*cdf0e10cSrcweir 	ScUnoGuard aGuard;
3033*cdf0e10cSrcweir     return !maGroups.empty();
3034*cdf0e10cSrcweir }
3035*cdf0e10cSrcweir 
3036*cdf0e10cSrcweir // implementation
3037*cdf0e10cSrcweir 
3038*cdf0e10cSrcweir ScFieldGroup& ScDataPilotFieldGroupsObj::getFieldGroup( const OUString& rName ) throw(RuntimeException)
3039*cdf0e10cSrcweir {
3040*cdf0e10cSrcweir     ScUnoGuard aGuard;
3041*cdf0e10cSrcweir     ScFieldGroups::iterator aIt = implFindByName( rName );
3042*cdf0e10cSrcweir     if( aIt == maGroups.end() )
3043*cdf0e10cSrcweir         throw RuntimeException();
3044*cdf0e10cSrcweir      return *aIt;
3045*cdf0e10cSrcweir }
3046*cdf0e10cSrcweir 
3047*cdf0e10cSrcweir void ScDataPilotFieldGroupsObj::renameFieldGroup( const OUString& rOldName, const OUString& rNewName ) throw(RuntimeException)
3048*cdf0e10cSrcweir {
3049*cdf0e10cSrcweir     ScUnoGuard aGuard;
3050*cdf0e10cSrcweir     ScFieldGroups::iterator aOldIt = implFindByName( rOldName );
3051*cdf0e10cSrcweir     ScFieldGroups::iterator aNewIt = implFindByName( rNewName );
3052*cdf0e10cSrcweir     // new name must not exist yet
3053*cdf0e10cSrcweir     if( (aOldIt == maGroups.end()) || ((aNewIt != maGroups.end()) && (aNewIt != aOldIt)) )
3054*cdf0e10cSrcweir         throw RuntimeException();
3055*cdf0e10cSrcweir     aOldIt->maName = rNewName;
3056*cdf0e10cSrcweir }
3057*cdf0e10cSrcweir 
3058*cdf0e10cSrcweir // private
3059*cdf0e10cSrcweir 
3060*cdf0e10cSrcweir ScFieldGroups::iterator ScDataPilotFieldGroupsObj::implFindByName( const OUString& rName )
3061*cdf0e10cSrcweir {
3062*cdf0e10cSrcweir     for( ScFieldGroups::iterator aIt = maGroups.begin(), aEnd = maGroups.end(); aIt != aEnd; ++aIt )
3063*cdf0e10cSrcweir         if( aIt->maName == rName )
3064*cdf0e10cSrcweir             return aIt;
3065*cdf0e10cSrcweir     return maGroups.end();
3066*cdf0e10cSrcweir }
3067*cdf0e10cSrcweir 
3068*cdf0e10cSrcweir // ============================================================================
3069*cdf0e10cSrcweir 
3070*cdf0e10cSrcweir namespace {
3071*cdf0e10cSrcweir 
3072*cdf0e10cSrcweir OUString lclExtractMember( const Any& rElement )
3073*cdf0e10cSrcweir {
3074*cdf0e10cSrcweir     if( rElement.has< OUString >() )
3075*cdf0e10cSrcweir         return rElement.get< OUString >();
3076*cdf0e10cSrcweir 
3077*cdf0e10cSrcweir     Reference< XNamed > xNamed( rElement, UNO_QUERY );
3078*cdf0e10cSrcweir     if( xNamed.is() )
3079*cdf0e10cSrcweir         return xNamed->getName();
3080*cdf0e10cSrcweir 
3081*cdf0e10cSrcweir     return OUString();
3082*cdf0e10cSrcweir }
3083*cdf0e10cSrcweir 
3084*cdf0e10cSrcweir } // namespace
3085*cdf0e10cSrcweir 
3086*cdf0e10cSrcweir // ----------------------------------------------------------------------------
3087*cdf0e10cSrcweir 
3088*cdf0e10cSrcweir ScDataPilotFieldGroupObj::ScDataPilotFieldGroupObj( ScDataPilotFieldGroupsObj& rParent, const OUString& rGroupName ) :
3089*cdf0e10cSrcweir     mrParent( rParent ),
3090*cdf0e10cSrcweir     maGroupName( rGroupName )
3091*cdf0e10cSrcweir {
3092*cdf0e10cSrcweir     mrParent.acquire();
3093*cdf0e10cSrcweir }
3094*cdf0e10cSrcweir 
3095*cdf0e10cSrcweir ScDataPilotFieldGroupObj::~ScDataPilotFieldGroupObj()
3096*cdf0e10cSrcweir {
3097*cdf0e10cSrcweir     mrParent.release();
3098*cdf0e10cSrcweir }
3099*cdf0e10cSrcweir 
3100*cdf0e10cSrcweir // XNameAccess
3101*cdf0e10cSrcweir 
3102*cdf0e10cSrcweir Any SAL_CALL ScDataPilotFieldGroupObj::getByName( const OUString& rName )
3103*cdf0e10cSrcweir         throw(NoSuchElementException, WrappedTargetException, RuntimeException)
3104*cdf0e10cSrcweir {
3105*cdf0e10cSrcweir 	ScUnoGuard aGuard;
3106*cdf0e10cSrcweir     ScFieldGroupMembers& rMembers = mrParent.getFieldGroup( maGroupName ).maMembers;
3107*cdf0e10cSrcweir     ScFieldGroupMembers::iterator aIt = ::std::find( rMembers.begin(), rMembers.end(), rName );
3108*cdf0e10cSrcweir     if( aIt == rMembers.end() )
3109*cdf0e10cSrcweir         throw NoSuchElementException();
3110*cdf0e10cSrcweir     return Any( Reference< XNamed >( new ScDataPilotFieldGroupItemObj( *this, *aIt ) ) );
3111*cdf0e10cSrcweir }
3112*cdf0e10cSrcweir 
3113*cdf0e10cSrcweir Sequence< OUString > SAL_CALL ScDataPilotFieldGroupObj::getElementNames() throw(RuntimeException)
3114*cdf0e10cSrcweir {
3115*cdf0e10cSrcweir 	ScUnoGuard aGuard;
3116*cdf0e10cSrcweir     return ::comphelper::containerToSequence( mrParent.getFieldGroup( maGroupName ).maMembers );
3117*cdf0e10cSrcweir }
3118*cdf0e10cSrcweir 
3119*cdf0e10cSrcweir sal_Bool SAL_CALL ScDataPilotFieldGroupObj::hasByName( const OUString& rName ) throw(RuntimeException)
3120*cdf0e10cSrcweir {
3121*cdf0e10cSrcweir 	ScUnoGuard aGuard;
3122*cdf0e10cSrcweir     ScFieldGroupMembers& rMembers = mrParent.getFieldGroup( maGroupName ).maMembers;
3123*cdf0e10cSrcweir     return ::std::find( rMembers.begin(), rMembers.end(), rName ) != rMembers.end();
3124*cdf0e10cSrcweir }
3125*cdf0e10cSrcweir 
3126*cdf0e10cSrcweir // XNameReplace
3127*cdf0e10cSrcweir 
3128*cdf0e10cSrcweir void SAL_CALL ScDataPilotFieldGroupObj::replaceByName( const OUString& rName, const Any& rElement )
3129*cdf0e10cSrcweir         throw (IllegalArgumentException, NoSuchElementException, WrappedTargetException, RuntimeException)
3130*cdf0e10cSrcweir {
3131*cdf0e10cSrcweir     ScUnoGuard aGuard;
3132*cdf0e10cSrcweir 
3133*cdf0e10cSrcweir     // it should be possible to quickly rename an item -> accept string or XNamed
3134*cdf0e10cSrcweir     OUString aNewName = lclExtractMember( rElement );
3135*cdf0e10cSrcweir     if( (rName.getLength() == 0) || (aNewName.getLength() == 0) )
3136*cdf0e10cSrcweir         throw IllegalArgumentException();
3137*cdf0e10cSrcweir     if( rName == aNewName )
3138*cdf0e10cSrcweir         return;
3139*cdf0e10cSrcweir 
3140*cdf0e10cSrcweir     ScFieldGroupMembers& rMembers = mrParent.getFieldGroup( maGroupName ).maMembers;
3141*cdf0e10cSrcweir     ScFieldGroupMembers::iterator aOldIt = ::std::find( rMembers.begin(), rMembers.end(), rName );
3142*cdf0e10cSrcweir     ScFieldGroupMembers::iterator aNewIt = ::std::find( rMembers.begin(), rMembers.end(), aNewName );
3143*cdf0e10cSrcweir     // throw if passed member name does not exist
3144*cdf0e10cSrcweir     if( aOldIt == rMembers.end() )
3145*cdf0e10cSrcweir         throw NoSuchElementException();
3146*cdf0e10cSrcweir     // throw if new name already exists
3147*cdf0e10cSrcweir     if( aNewIt != rMembers.end() )
3148*cdf0e10cSrcweir         throw IllegalArgumentException();
3149*cdf0e10cSrcweir     *aOldIt = aNewName;
3150*cdf0e10cSrcweir }
3151*cdf0e10cSrcweir 
3152*cdf0e10cSrcweir // XNameContainer
3153*cdf0e10cSrcweir 
3154*cdf0e10cSrcweir void SAL_CALL ScDataPilotFieldGroupObj::insertByName( const OUString& rName, const Any& /*rElement*/ )
3155*cdf0e10cSrcweir         throw (IllegalArgumentException, ElementExistException, WrappedTargetException, RuntimeException)
3156*cdf0e10cSrcweir {
3157*cdf0e10cSrcweir     ScUnoGuard aGuard;
3158*cdf0e10cSrcweir 
3159*cdf0e10cSrcweir     // we will ignore the passed element and just try to insert the name
3160*cdf0e10cSrcweir     if( rName.getLength() == 0 )
3161*cdf0e10cSrcweir         throw IllegalArgumentException();
3162*cdf0e10cSrcweir 
3163*cdf0e10cSrcweir     ScFieldGroupMembers& rMembers = mrParent.getFieldGroup( maGroupName ).maMembers;
3164*cdf0e10cSrcweir     ScFieldGroupMembers::iterator aIt = ::std::find( rMembers.begin(), rMembers.end(), rName );
3165*cdf0e10cSrcweir     // throw if passed name already exists
3166*cdf0e10cSrcweir     if( aIt != rMembers.end() )
3167*cdf0e10cSrcweir         throw IllegalArgumentException();
3168*cdf0e10cSrcweir     rMembers.push_back( rName );
3169*cdf0e10cSrcweir }
3170*cdf0e10cSrcweir 
3171*cdf0e10cSrcweir void SAL_CALL ScDataPilotFieldGroupObj::removeByName( const OUString& rName )
3172*cdf0e10cSrcweir         throw (NoSuchElementException, WrappedTargetException, RuntimeException)
3173*cdf0e10cSrcweir {
3174*cdf0e10cSrcweir     ScUnoGuard aGuard;
3175*cdf0e10cSrcweir 
3176*cdf0e10cSrcweir     if( rName.getLength() == 0 )
3177*cdf0e10cSrcweir         throw IllegalArgumentException();
3178*cdf0e10cSrcweir     ScFieldGroupMembers& rMembers = mrParent.getFieldGroup( maGroupName ).maMembers;
3179*cdf0e10cSrcweir     ScFieldGroupMembers::iterator aIt = ::std::find( rMembers.begin(), rMembers.end(), rName );
3180*cdf0e10cSrcweir     // throw if passed name does not exist
3181*cdf0e10cSrcweir     if( aIt == rMembers.end() )
3182*cdf0e10cSrcweir         throw NoSuchElementException();
3183*cdf0e10cSrcweir     rMembers.erase( aIt );
3184*cdf0e10cSrcweir }
3185*cdf0e10cSrcweir 
3186*cdf0e10cSrcweir // XIndexAccess
3187*cdf0e10cSrcweir 
3188*cdf0e10cSrcweir sal_Int32 SAL_CALL ScDataPilotFieldGroupObj::getCount() throw(RuntimeException)
3189*cdf0e10cSrcweir {
3190*cdf0e10cSrcweir 	ScUnoGuard aGuard;
3191*cdf0e10cSrcweir     return static_cast< sal_Int32 >( mrParent.getFieldGroup( maGroupName ).maMembers.size() );
3192*cdf0e10cSrcweir }
3193*cdf0e10cSrcweir 
3194*cdf0e10cSrcweir Any SAL_CALL ScDataPilotFieldGroupObj::getByIndex( sal_Int32 nIndex )
3195*cdf0e10cSrcweir         throw(IndexOutOfBoundsException, WrappedTargetException, RuntimeException)
3196*cdf0e10cSrcweir {
3197*cdf0e10cSrcweir 	ScUnoGuard aGuard;
3198*cdf0e10cSrcweir     ScFieldGroupMembers& rMembers = mrParent.getFieldGroup( maGroupName ).maMembers;
3199*cdf0e10cSrcweir     if ((nIndex < 0) || (nIndex >= static_cast< sal_Int32 >( rMembers.size() )))
3200*cdf0e10cSrcweir         throw IndexOutOfBoundsException();
3201*cdf0e10cSrcweir     return Any( Reference< XNamed >( new ScDataPilotFieldGroupItemObj( *this, rMembers[ nIndex ] ) ) );
3202*cdf0e10cSrcweir }
3203*cdf0e10cSrcweir 
3204*cdf0e10cSrcweir // XEnumerationAccess
3205*cdf0e10cSrcweir 
3206*cdf0e10cSrcweir Reference< XEnumeration > SAL_CALL ScDataPilotFieldGroupObj::createEnumeration() throw(RuntimeException)
3207*cdf0e10cSrcweir {
3208*cdf0e10cSrcweir     ScUnoGuard aGuard;
3209*cdf0e10cSrcweir     return new ScIndexEnumeration( this, OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.sheet.DataPilotFieldGroupEnumeration" ) ) );
3210*cdf0e10cSrcweir }
3211*cdf0e10cSrcweir 
3212*cdf0e10cSrcweir // XElementAccess
3213*cdf0e10cSrcweir 
3214*cdf0e10cSrcweir uno::Type SAL_CALL ScDataPilotFieldGroupObj::getElementType() throw(RuntimeException)
3215*cdf0e10cSrcweir {
3216*cdf0e10cSrcweir 	ScUnoGuard aGuard;
3217*cdf0e10cSrcweir     return getCppuType( (Reference< XNamed >*)0 );
3218*cdf0e10cSrcweir }
3219*cdf0e10cSrcweir 
3220*cdf0e10cSrcweir sal_Bool SAL_CALL ScDataPilotFieldGroupObj::hasElements() throw(RuntimeException)
3221*cdf0e10cSrcweir {
3222*cdf0e10cSrcweir 	ScUnoGuard aGuard;
3223*cdf0e10cSrcweir     return !mrParent.getFieldGroup( maGroupName ).maMembers.empty();
3224*cdf0e10cSrcweir }
3225*cdf0e10cSrcweir 
3226*cdf0e10cSrcweir // XNamed
3227*cdf0e10cSrcweir 
3228*cdf0e10cSrcweir OUString SAL_CALL ScDataPilotFieldGroupObj::getName() throw(RuntimeException)
3229*cdf0e10cSrcweir {
3230*cdf0e10cSrcweir 	ScUnoGuard aGuard;
3231*cdf0e10cSrcweir     return maGroupName;
3232*cdf0e10cSrcweir }
3233*cdf0e10cSrcweir 
3234*cdf0e10cSrcweir void SAL_CALL ScDataPilotFieldGroupObj::setName( const OUString& rName ) throw(RuntimeException)
3235*cdf0e10cSrcweir {
3236*cdf0e10cSrcweir 	ScUnoGuard aGuard;
3237*cdf0e10cSrcweir     mrParent.renameFieldGroup( maGroupName, rName );
3238*cdf0e10cSrcweir     // if call to renameFieldGroup() did not throw, remember the new name
3239*cdf0e10cSrcweir     maGroupName = rName;
3240*cdf0e10cSrcweir }
3241*cdf0e10cSrcweir 
3242*cdf0e10cSrcweir // ============================================================================
3243*cdf0e10cSrcweir 
3244*cdf0e10cSrcweir ScDataPilotFieldGroupItemObj::ScDataPilotFieldGroupItemObj( ScDataPilotFieldGroupObj& rParent, const OUString& rName ) :
3245*cdf0e10cSrcweir     mrParent( rParent ),
3246*cdf0e10cSrcweir     maName( rName )
3247*cdf0e10cSrcweir {
3248*cdf0e10cSrcweir     mrParent.acquire();
3249*cdf0e10cSrcweir }
3250*cdf0e10cSrcweir 
3251*cdf0e10cSrcweir ScDataPilotFieldGroupItemObj::~ScDataPilotFieldGroupItemObj()
3252*cdf0e10cSrcweir {
3253*cdf0e10cSrcweir     mrParent.release();
3254*cdf0e10cSrcweir }
3255*cdf0e10cSrcweir 
3256*cdf0e10cSrcweir // XNamed
3257*cdf0e10cSrcweir 
3258*cdf0e10cSrcweir OUString SAL_CALL ScDataPilotFieldGroupItemObj::getName() throw(RuntimeException)
3259*cdf0e10cSrcweir {
3260*cdf0e10cSrcweir 	ScUnoGuard aGuard;
3261*cdf0e10cSrcweir     return maName;
3262*cdf0e10cSrcweir }
3263*cdf0e10cSrcweir 
3264*cdf0e10cSrcweir void SAL_CALL ScDataPilotFieldGroupItemObj::setName( const OUString& rName ) throw(RuntimeException)
3265*cdf0e10cSrcweir {
3266*cdf0e10cSrcweir 	ScUnoGuard aGuard;
3267*cdf0e10cSrcweir     mrParent.replaceByName( maName, Any( rName ) );
3268*cdf0e10cSrcweir     // if call to replaceByName() did not throw, remember the new name
3269*cdf0e10cSrcweir     maName = rName;
3270*cdf0e10cSrcweir }
3271*cdf0e10cSrcweir 
3272*cdf0e10cSrcweir // ============================================================================
3273*cdf0e10cSrcweir 
3274*cdf0e10cSrcweir ScDataPilotItemsObj::ScDataPilotItemsObj( ScDataPilotDescriptorBase& rParent, const ScFieldIdentifier& rFieldId ) :
3275*cdf0e10cSrcweir     ScDataPilotChildObjBase( rParent, rFieldId )
3276*cdf0e10cSrcweir {
3277*cdf0e10cSrcweir }
3278*cdf0e10cSrcweir 
3279*cdf0e10cSrcweir ScDataPilotItemsObj::~ScDataPilotItemsObj()
3280*cdf0e10cSrcweir {
3281*cdf0e10cSrcweir }
3282*cdf0e10cSrcweir 
3283*cdf0e10cSrcweir // XDataPilotItems
3284*cdf0e10cSrcweir 
3285*cdf0e10cSrcweir ScDataPilotItemObj* ScDataPilotItemsObj::GetObjectByIndex_Impl( sal_Int32 nIndex ) const
3286*cdf0e10cSrcweir {
3287*cdf0e10cSrcweir     return ((0 <= nIndex) && (nIndex < GetMemberCount())) ?
3288*cdf0e10cSrcweir         new ScDataPilotItemObj( mrParent, maFieldId, nIndex ) : 0;
3289*cdf0e10cSrcweir }
3290*cdf0e10cSrcweir 
3291*cdf0e10cSrcweir // XNameAccess
3292*cdf0e10cSrcweir 
3293*cdf0e10cSrcweir Any SAL_CALL ScDataPilotItemsObj::getByName( const OUString& aName )
3294*cdf0e10cSrcweir         throw(NoSuchElementException, WrappedTargetException, RuntimeException)
3295*cdf0e10cSrcweir {
3296*cdf0e10cSrcweir 	ScUnoGuard aGuard;
3297*cdf0e10cSrcweir     Reference<XNameAccess> xMembers = GetMembers();
3298*cdf0e10cSrcweir     if (xMembers.is())
3299*cdf0e10cSrcweir     {
3300*cdf0e10cSrcweir         Reference<XIndexAccess> xMembersIndex(new ScNameToIndexAccess( xMembers ));
3301*cdf0e10cSrcweir         sal_Int32 nCount = xMembersIndex->getCount();
3302*cdf0e10cSrcweir         sal_Bool bFound(sal_False);
3303*cdf0e10cSrcweir         sal_Int32 nItem = 0;
3304*cdf0e10cSrcweir         while (nItem < nCount && !bFound )
3305*cdf0e10cSrcweir         {
3306*cdf0e10cSrcweir             Reference<XNamed> xMember(xMembersIndex->getByIndex(nItem), UNO_QUERY);
3307*cdf0e10cSrcweir             if (xMember.is() && (aName == xMember->getName()))
3308*cdf0e10cSrcweir                 return Any( Reference< XPropertySet >( GetObjectByIndex_Impl( nItem ) ) );
3309*cdf0e10cSrcweir             ++nItem;
3310*cdf0e10cSrcweir         }
3311*cdf0e10cSrcweir         if (!bFound)
3312*cdf0e10cSrcweir             throw NoSuchElementException();
3313*cdf0e10cSrcweir     }
3314*cdf0e10cSrcweir     return Any();
3315*cdf0e10cSrcweir }
3316*cdf0e10cSrcweir 
3317*cdf0e10cSrcweir Sequence<OUString> SAL_CALL ScDataPilotItemsObj::getElementNames()
3318*cdf0e10cSrcweir                                                 throw(RuntimeException)
3319*cdf0e10cSrcweir {
3320*cdf0e10cSrcweir 	ScUnoGuard aGuard;
3321*cdf0e10cSrcweir     Sequence< OUString > aSeq;
3322*cdf0e10cSrcweir     if( ScDPObject* pDPObj = GetDPObject() )
3323*cdf0e10cSrcweir         pDPObj->GetMemberNames( lcl_GetObjectIndex( pDPObj, maFieldId ), aSeq );
3324*cdf0e10cSrcweir     return aSeq;
3325*cdf0e10cSrcweir }
3326*cdf0e10cSrcweir 
3327*cdf0e10cSrcweir sal_Bool SAL_CALL ScDataPilotItemsObj::hasByName( const OUString& aName )
3328*cdf0e10cSrcweir                                         throw(RuntimeException)
3329*cdf0e10cSrcweir {
3330*cdf0e10cSrcweir 	ScUnoGuard aGuard;
3331*cdf0e10cSrcweir     sal_Bool bFound = sal_False;
3332*cdf0e10cSrcweir     Reference<XNameAccess> xMembers = GetMembers();
3333*cdf0e10cSrcweir     if (xMembers.is())
3334*cdf0e10cSrcweir     {
3335*cdf0e10cSrcweir         Reference<XIndexAccess> xMembersIndex(new ScNameToIndexAccess( xMembers ));
3336*cdf0e10cSrcweir         sal_Int32 nCount = xMembersIndex->getCount();
3337*cdf0e10cSrcweir         sal_Int32 nItem = 0;
3338*cdf0e10cSrcweir         while (nItem < nCount && !bFound )
3339*cdf0e10cSrcweir         {
3340*cdf0e10cSrcweir             Reference<XNamed> xMember(xMembersIndex->getByIndex(nItem), UNO_QUERY);
3341*cdf0e10cSrcweir             if (xMember.is() && aName == xMember->getName())
3342*cdf0e10cSrcweir                 bFound = sal_True;
3343*cdf0e10cSrcweir             else
3344*cdf0e10cSrcweir                 nItem++;
3345*cdf0e10cSrcweir         }
3346*cdf0e10cSrcweir     }
3347*cdf0e10cSrcweir     return bFound;
3348*cdf0e10cSrcweir }
3349*cdf0e10cSrcweir 
3350*cdf0e10cSrcweir // XEnumerationAccess
3351*cdf0e10cSrcweir 
3352*cdf0e10cSrcweir Reference<XEnumeration> SAL_CALL ScDataPilotItemsObj::createEnumeration()
3353*cdf0e10cSrcweir                                                     throw(RuntimeException)
3354*cdf0e10cSrcweir {
3355*cdf0e10cSrcweir 	ScUnoGuard aGuard;
3356*cdf0e10cSrcweir     return new ScIndexEnumeration(this, OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.sheet.DataPilotItemsEnumeration")));
3357*cdf0e10cSrcweir }
3358*cdf0e10cSrcweir 
3359*cdf0e10cSrcweir // XIndexAccess
3360*cdf0e10cSrcweir 
3361*cdf0e10cSrcweir sal_Int32 SAL_CALL ScDataPilotItemsObj::getCount() throw(RuntimeException)
3362*cdf0e10cSrcweir {
3363*cdf0e10cSrcweir 	ScUnoGuard aGuard;
3364*cdf0e10cSrcweir     return GetMemberCount();
3365*cdf0e10cSrcweir }
3366*cdf0e10cSrcweir 
3367*cdf0e10cSrcweir Any SAL_CALL ScDataPilotItemsObj::getByIndex( sal_Int32 nIndex )
3368*cdf0e10cSrcweir         throw(IndexOutOfBoundsException, WrappedTargetException, RuntimeException)
3369*cdf0e10cSrcweir {
3370*cdf0e10cSrcweir 	ScUnoGuard aGuard;
3371*cdf0e10cSrcweir     Reference< XPropertySet > xItem( GetObjectByIndex_Impl( nIndex ) );
3372*cdf0e10cSrcweir     if (!xItem.is())
3373*cdf0e10cSrcweir         throw IndexOutOfBoundsException();
3374*cdf0e10cSrcweir     return Any( xItem );
3375*cdf0e10cSrcweir }
3376*cdf0e10cSrcweir 
3377*cdf0e10cSrcweir uno::Type SAL_CALL ScDataPilotItemsObj::getElementType() throw(RuntimeException)
3378*cdf0e10cSrcweir {
3379*cdf0e10cSrcweir 	ScUnoGuard aGuard;
3380*cdf0e10cSrcweir     return getCppuType((Reference<XPropertySet>*)0);
3381*cdf0e10cSrcweir }
3382*cdf0e10cSrcweir 
3383*cdf0e10cSrcweir sal_Bool SAL_CALL ScDataPilotItemsObj::hasElements() throw(RuntimeException)
3384*cdf0e10cSrcweir {
3385*cdf0e10cSrcweir 	ScUnoGuard aGuard;
3386*cdf0e10cSrcweir 	return ( getCount() != 0 );
3387*cdf0e10cSrcweir }
3388*cdf0e10cSrcweir 
3389*cdf0e10cSrcweir //------------------------------------------------------------------------
3390*cdf0e10cSrcweir 
3391*cdf0e10cSrcweir ScDataPilotItemObj::ScDataPilotItemObj( ScDataPilotDescriptorBase& rParent, const ScFieldIdentifier& rFieldId, sal_Int32 nIndex ) :
3392*cdf0e10cSrcweir     ScDataPilotChildObjBase( rParent, rFieldId ),
3393*cdf0e10cSrcweir     maPropSet( lcl_GetDataPilotItemMap() ),
3394*cdf0e10cSrcweir     mnIndex( nIndex )
3395*cdf0e10cSrcweir {
3396*cdf0e10cSrcweir }
3397*cdf0e10cSrcweir 
3398*cdf0e10cSrcweir ScDataPilotItemObj::~ScDataPilotItemObj()
3399*cdf0e10cSrcweir {
3400*cdf0e10cSrcweir }
3401*cdf0e10cSrcweir 
3402*cdf0e10cSrcweir 							// XNamed
3403*cdf0e10cSrcweir OUString SAL_CALL ScDataPilotItemObj::getName() throw(RuntimeException)
3404*cdf0e10cSrcweir {
3405*cdf0e10cSrcweir 	ScUnoGuard aGuard;
3406*cdf0e10cSrcweir     OUString sRet;
3407*cdf0e10cSrcweir     Reference<XNameAccess> xMembers = GetMembers();
3408*cdf0e10cSrcweir     if (xMembers.is())
3409*cdf0e10cSrcweir     {
3410*cdf0e10cSrcweir         Reference<XIndexAccess> xMembersIndex(new ScNameToIndexAccess( xMembers ));
3411*cdf0e10cSrcweir         sal_Int32 nCount = xMembersIndex->getCount();
3412*cdf0e10cSrcweir         if (mnIndex < nCount)
3413*cdf0e10cSrcweir         {
3414*cdf0e10cSrcweir             Reference<XNamed> xMember(xMembersIndex->getByIndex(mnIndex), UNO_QUERY);
3415*cdf0e10cSrcweir             sRet = xMember->getName();
3416*cdf0e10cSrcweir         }
3417*cdf0e10cSrcweir     }
3418*cdf0e10cSrcweir     return sRet;
3419*cdf0e10cSrcweir }
3420*cdf0e10cSrcweir 
3421*cdf0e10cSrcweir void SAL_CALL ScDataPilotItemObj::setName( const OUString& /* aName */ )
3422*cdf0e10cSrcweir                                 throw(RuntimeException)
3423*cdf0e10cSrcweir {
3424*cdf0e10cSrcweir }
3425*cdf0e10cSrcweir 
3426*cdf0e10cSrcweir 							// XPropertySet
3427*cdf0e10cSrcweir Reference< XPropertySetInfo >
3428*cdf0e10cSrcweir 							SAL_CALL ScDataPilotItemObj::getPropertySetInfo(  )
3429*cdf0e10cSrcweir                                 throw(RuntimeException)
3430*cdf0e10cSrcweir {
3431*cdf0e10cSrcweir 	ScUnoGuard aGuard;
3432*cdf0e10cSrcweir     static Reference<XPropertySetInfo> aRef =
3433*cdf0e10cSrcweir         new SfxItemPropertySetInfo( maPropSet.getPropertyMap() );
3434*cdf0e10cSrcweir 	return aRef;
3435*cdf0e10cSrcweir }
3436*cdf0e10cSrcweir 
3437*cdf0e10cSrcweir void SAL_CALL ScDataPilotItemObj::setPropertyValue( const OUString& aPropertyName, const Any& aValue )
3438*cdf0e10cSrcweir         throw(UnknownPropertyException, PropertyVetoException, IllegalArgumentException, WrappedTargetException, RuntimeException)
3439*cdf0e10cSrcweir {
3440*cdf0e10cSrcweir 	ScUnoGuard aGuard;
3441*cdf0e10cSrcweir     ScDPObject* pDPObj = 0;
3442*cdf0e10cSrcweir     if( ScDPSaveDimension* pDim = GetDPDimension( &pDPObj ) )
3443*cdf0e10cSrcweir     {
3444*cdf0e10cSrcweir         Reference<XNameAccess> xMembers = GetMembers();
3445*cdf0e10cSrcweir         if( xMembers.is() )
3446*cdf0e10cSrcweir         {
3447*cdf0e10cSrcweir             Reference<XIndexAccess> xMembersIndex( new ScNameToIndexAccess( xMembers ) );
3448*cdf0e10cSrcweir             sal_Int32 nCount = xMembersIndex->getCount();
3449*cdf0e10cSrcweir             if( mnIndex < nCount )
3450*cdf0e10cSrcweir 	        {
3451*cdf0e10cSrcweir                 Reference<XNamed> xMember(xMembersIndex->getByIndex(mnIndex), UNO_QUERY);
3452*cdf0e10cSrcweir                 String sName(xMember->getName());
3453*cdf0e10cSrcweir                 ScDPSaveMember* pMember = pDim->GetMemberByName(sName);
3454*cdf0e10cSrcweir                 if (pMember)
3455*cdf0e10cSrcweir                 {
3456*cdf0e10cSrcweir                     bool bGetNewIndex = false;
3457*cdf0e10cSrcweir                     if ( aPropertyName.equalsAscii( SC_UNONAME_SHOWDETAIL ) )
3458*cdf0e10cSrcweir                         pMember->SetShowDetails(cppu::any2bool(aValue));
3459*cdf0e10cSrcweir                     else if ( aPropertyName.equalsAscii( SC_UNONAME_ISHIDDEN ) )
3460*cdf0e10cSrcweir                         pMember->SetIsVisible(!cppu::any2bool(aValue));
3461*cdf0e10cSrcweir                     else if ( aPropertyName.equalsAscii( SC_UNONAME_POS ) )
3462*cdf0e10cSrcweir                     {
3463*cdf0e10cSrcweir                         sal_Int32 nNewPos = 0;
3464*cdf0e10cSrcweir                         if ( ( aValue >>= nNewPos ) && nNewPos >= 0 && nNewPos < nCount )
3465*cdf0e10cSrcweir                         {
3466*cdf0e10cSrcweir                             pDim->SetMemberPosition( sName, nNewPos );
3467*cdf0e10cSrcweir                             // get new effective index (depends on sorting mode, which isn't modified)
3468*cdf0e10cSrcweir                             bGetNewIndex = true;
3469*cdf0e10cSrcweir                         }
3470*cdf0e10cSrcweir                         else
3471*cdf0e10cSrcweir                             throw IllegalArgumentException();
3472*cdf0e10cSrcweir                     }
3473*cdf0e10cSrcweir                     SetDPObject( pDPObj );
3474*cdf0e10cSrcweir 
3475*cdf0e10cSrcweir                     if ( bGetNewIndex )     // after SetDPObject, get the new index
3476*cdf0e10cSrcweir                     {
3477*cdf0e10cSrcweir                         OUString aOUName( sName );
3478*cdf0e10cSrcweir                         Sequence< OUString > aItemNames = xMembers->getElementNames();
3479*cdf0e10cSrcweir                         sal_Int32 nItemCount = aItemNames.getLength();
3480*cdf0e10cSrcweir                         for (sal_Int32 nItem=0; nItem<nItemCount; ++nItem)
3481*cdf0e10cSrcweir                             if (aItemNames[nItem] == aOUName)
3482*cdf0e10cSrcweir                                 mnIndex = nItem;
3483*cdf0e10cSrcweir                     }
3484*cdf0e10cSrcweir                 }
3485*cdf0e10cSrcweir             }
3486*cdf0e10cSrcweir         }
3487*cdf0e10cSrcweir     }
3488*cdf0e10cSrcweir }
3489*cdf0e10cSrcweir 
3490*cdf0e10cSrcweir Any SAL_CALL ScDataPilotItemObj::getPropertyValue( const OUString& aPropertyName )
3491*cdf0e10cSrcweir         throw(UnknownPropertyException, WrappedTargetException, RuntimeException)
3492*cdf0e10cSrcweir {
3493*cdf0e10cSrcweir 	ScUnoGuard aGuard;
3494*cdf0e10cSrcweir     Any aRet;
3495*cdf0e10cSrcweir     if( ScDPSaveDimension* pDim = GetDPDimension() )
3496*cdf0e10cSrcweir     {
3497*cdf0e10cSrcweir         Reference< XNameAccess > xMembers = GetMembers();
3498*cdf0e10cSrcweir         if( xMembers.is() )
3499*cdf0e10cSrcweir         {
3500*cdf0e10cSrcweir             Reference< XIndexAccess > xMembersIndex( new ScNameToIndexAccess( xMembers ) );
3501*cdf0e10cSrcweir             sal_Int32 nCount = xMembersIndex->getCount();
3502*cdf0e10cSrcweir             if( mnIndex < nCount )
3503*cdf0e10cSrcweir 	        {
3504*cdf0e10cSrcweir                 Reference< XNamed > xMember( xMembersIndex->getByIndex( mnIndex ), UNO_QUERY );
3505*cdf0e10cSrcweir                 String sName( xMember->getName() );
3506*cdf0e10cSrcweir                 ScDPSaveMember* pMember = pDim->GetExistingMemberByName( sName );
3507*cdf0e10cSrcweir                 if( aPropertyName.equalsAscii( SC_UNONAME_SHOWDETAIL ) )
3508*cdf0e10cSrcweir                 {
3509*cdf0e10cSrcweir                     if (pMember && pMember->HasShowDetails())
3510*cdf0e10cSrcweir                     {
3511*cdf0e10cSrcweir                         aRet <<= (bool)pMember->GetShowDetails();
3512*cdf0e10cSrcweir                     }
3513*cdf0e10cSrcweir                     else
3514*cdf0e10cSrcweir                     {
3515*cdf0e10cSrcweir                         Reference< XPropertySet > xMemberProps( xMember, UNO_QUERY );
3516*cdf0e10cSrcweir                         if( xMemberProps.is() )
3517*cdf0e10cSrcweir                             aRet = xMemberProps->getPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( SC_UNO_SHOWDETA ) ) );
3518*cdf0e10cSrcweir                         else
3519*cdf0e10cSrcweir                             aRet <<= true;
3520*cdf0e10cSrcweir                     }
3521*cdf0e10cSrcweir                 }
3522*cdf0e10cSrcweir                 else if ( aPropertyName.equalsAscii( SC_UNONAME_ISHIDDEN ) )
3523*cdf0e10cSrcweir                 {
3524*cdf0e10cSrcweir                     if (pMember && pMember->HasIsVisible())
3525*cdf0e10cSrcweir                     {
3526*cdf0e10cSrcweir                         aRet <<= !pMember->GetIsVisible();
3527*cdf0e10cSrcweir                     }
3528*cdf0e10cSrcweir                     else
3529*cdf0e10cSrcweir                     {
3530*cdf0e10cSrcweir                         Reference< XPropertySet > xMemberProps( xMember, UNO_QUERY );
3531*cdf0e10cSrcweir                         if( xMemberProps.is() )
3532*cdf0e10cSrcweir                             aRet <<= !cppu::any2bool( xMemberProps->getPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( SC_UNO_ISVISIBL ) ) ) );
3533*cdf0e10cSrcweir                         else
3534*cdf0e10cSrcweir                             aRet <<= false;
3535*cdf0e10cSrcweir                     }
3536*cdf0e10cSrcweir                 }
3537*cdf0e10cSrcweir                 else if ( aPropertyName.equalsAscii( SC_UNONAME_POS ) )
3538*cdf0e10cSrcweir                 {
3539*cdf0e10cSrcweir                     aRet <<= mnIndex;
3540*cdf0e10cSrcweir                 }
3541*cdf0e10cSrcweir             }
3542*cdf0e10cSrcweir         }
3543*cdf0e10cSrcweir     }
3544*cdf0e10cSrcweir     return aRet;
3545*cdf0e10cSrcweir }
3546*cdf0e10cSrcweir 
3547*cdf0e10cSrcweir void SAL_CALL ScDataPilotItemObj::addPropertyChangeListener(
3548*cdf0e10cSrcweir         const OUString& /* aPropertyName */, const Reference< XPropertyChangeListener >& /* xListener */ )
3549*cdf0e10cSrcweir         throw(UnknownPropertyException, WrappedTargetException, RuntimeException)
3550*cdf0e10cSrcweir {
3551*cdf0e10cSrcweir }
3552*cdf0e10cSrcweir 
3553*cdf0e10cSrcweir void SAL_CALL ScDataPilotItemObj::removePropertyChangeListener(
3554*cdf0e10cSrcweir         const OUString& /* aPropertyName */, const Reference< XPropertyChangeListener >& /* aListener */ )
3555*cdf0e10cSrcweir         throw(UnknownPropertyException, WrappedTargetException, RuntimeException)
3556*cdf0e10cSrcweir {
3557*cdf0e10cSrcweir }
3558*cdf0e10cSrcweir 
3559*cdf0e10cSrcweir void SAL_CALL ScDataPilotItemObj::addVetoableChangeListener(
3560*cdf0e10cSrcweir         const OUString& /* PropertyName */, const Reference< XVetoableChangeListener >& /* aListener */ )
3561*cdf0e10cSrcweir         throw(UnknownPropertyException, WrappedTargetException, RuntimeException)
3562*cdf0e10cSrcweir {
3563*cdf0e10cSrcweir }
3564*cdf0e10cSrcweir 
3565*cdf0e10cSrcweir void SAL_CALL ScDataPilotItemObj::removeVetoableChangeListener(
3566*cdf0e10cSrcweir         const OUString& /* PropertyName */, const Reference< XVetoableChangeListener >& /* aListener */ )
3567*cdf0e10cSrcweir         throw(UnknownPropertyException, WrappedTargetException, RuntimeException)
3568*cdf0e10cSrcweir {
3569*cdf0e10cSrcweir }
3570*cdf0e10cSrcweir 
3571*cdf0e10cSrcweir //------------------------------------------------------------------------
3572*cdf0e10cSrcweir 
3573*cdf0e10cSrcweir 
3574*cdf0e10cSrcweir 
3575*cdf0e10cSrcweir 
3576