xref: /trunk/main/sc/inc/dptabsrc.hxx (revision bfbd599d)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #ifndef SC_DPTABSRC_HXX
29 #define SC_DPTABSRC_HXX
30 
31 #include <vector>
32 #include <hash_map>
33 // Wang Xu Ming -- 2009-8-17
34 // DataPilot Migration - Cache&&Performance
35 #include <list>
36 // End Comments
37 #include <memory>
38 #include <tools/string.hxx>
39 #include <tools/list.hxx>
40 #include "global.hxx"		// enum ScSubTotalFunc
41 #include <com/sun/star/sheet/XDimensionsSupplier.hpp>
42 #include <com/sun/star/sheet/XHierarchiesSupplier.hpp>
43 #include <com/sun/star/sheet/XLevelsSupplier.hpp>
44 #include <com/sun/star/sheet/XMembersSupplier.hpp>
45 #include <com/sun/star/sheet/XDataPilotResults.hpp>
46 #include <com/sun/star/sheet/XDataPilotMemberResults.hpp>
47 #include <com/sun/star/sheet/MemberResult.hpp>
48 #include <com/sun/star/sheet/GeneralFunction.hpp>
49 #include <com/sun/star/sheet/DataPilotFieldAutoShowInfo.hpp>
50 #include <com/sun/star/sheet/DataPilotFieldLayoutInfo.hpp>
51 #include <com/sun/star/sheet/DataPilotFieldLayoutMode.hpp>
52 #include <com/sun/star/sheet/DataPilotFieldReference.hpp>
53 #include <com/sun/star/sheet/DataPilotFieldSortInfo.hpp>
54 #include <com/sun/star/util/XRefreshable.hpp>
55 #include <com/sun/star/sheet/XDrillDownDataSupplier.hpp>
56 #include <com/sun/star/util/XCloneable.hpp>
57 #include <com/sun/star/beans/XPropertySet.hpp>
58 #include <com/sun/star/lang/XServiceInfo.hpp>
59 #include <com/sun/star/container/XNamed.hpp>
60 #include <cppuhelper/implbase2.hxx>
61 #include <cppuhelper/implbase3.hxx>
62 #include <cppuhelper/implbase5.hxx>
63 #include <cppuhelper/implbase6.hxx>
64 // Wang Xu Ming -- 2009-8-17
65 // DataPilot Migration - Cache&&Performance
66 #include "dpglobal.hxx"
67 // End Comments
68 #include "dptabdat.hxx"
69 
70 namespace com { namespace sun { namespace star {
71     namespace sheet {
72         struct DataPilotFieldFilter;
73     }
74     namespace table {
75         struct CellAddress;
76     }
77 }}}
78 
79 class ScDPResultMember;
80 class ScDPResultData;
81 // Wang Xu Ming -- 2009-8-17
82 // DataPilot Migration - Cache&&Performance
83 class ScDPItemData;
84 // End Comments
85 class ScDPTableData;
86 
87 // ------------------------------------------------------------------------
88 
89 
90 //	should be dynamic!
91 #define SC_DAPI_MAXFIELDS 	256
92 
93 
94 // --------------------------------------------------------------------
95 //
96 //	implementation of DataPilotSource using ScDPTableData
97 //
98 
99 
100 class ScDPDimensions;
101 class ScDPDimension;
102 class ScDPHierarchies;
103 class ScDPHierarchy;
104 class ScDPLevels;
105 class ScDPLevel;
106 class ScDPMembers;
107 class ScDPMember;
108 
109 
110 class ScDPSource : public cppu::WeakImplHelper6<
111 							com::sun::star::sheet::XDimensionsSupplier,
112 							com::sun::star::sheet::XDataPilotResults,
113 							com::sun::star::util::XRefreshable,
114                             com::sun::star::sheet::XDrillDownDataSupplier,
115 							com::sun::star::beans::XPropertySet,
116 							com::sun::star::lang::XServiceInfo >
117 {
118 private:
119 	ScDPTableData*			pData;				// data source (ScDPObject manages its life time)
120 	ScDPDimensions*			pDimensions;		// api objects
121 												// settings:
122 	long					nColDims[SC_DAPI_MAXFIELDS];
123 	long					nRowDims[SC_DAPI_MAXFIELDS];
124 	long					nDataDims[SC_DAPI_MAXFIELDS];
125 	long					nPageDims[SC_DAPI_MAXFIELDS];
126 	long					nColDimCount;
127 	long					nRowDimCount;
128 	long					nDataDimCount;
129 	long					nPageDimCount;
130 	sal_Bool					bColumnGrand;
131 	sal_Bool					bRowGrand;
132 	sal_Bool					bIgnoreEmptyRows;
133 	sal_Bool					bRepeatIfEmpty;
134 
135 	long					nDupCount;
136 
137 												// results:
138 	ScDPResultData*			pResData;			// keep the rest in this!
139 	ScDPResultMember*		pColResRoot;
140 	ScDPResultMember*		pRowResRoot;
141 	com::sun::star::uno::Sequence<com::sun::star::sheet::MemberResult>* pColResults;
142 	com::sun::star::uno::Sequence<com::sun::star::sheet::MemberResult>* pRowResults;
143 	List					aColLevelList;
144 	List					aRowLevelList;
145 	sal_Bool					bResultOverflow;
146     bool                    bPageFiltered;      // set if page field filters have been applied to cache table
147 
148     ::std::auto_ptr<rtl::OUString> mpGrandTotalName;
149 
150 	void					CreateRes_Impl();
151 	void					FillMemberResults();
152 	void					FillLevelList( sal_uInt16 nOrientation, List& rList );
153     void                    FillCalcInfo(bool bIsRow, ScDPTableData::CalcInfo& rInfo, bool &bHasAutoShow);
154 
155     /**
156      * Compile a list of dimension indices that are either, column, row or
157      * page dimensions (i.e. all but data dimensions).
158      */
159     void                    GetCategoryDimensionIndices(::std::hash_set<sal_Int32>& rCatDims);
160 
161     /**
162      * Set visibilities of individual rows in the cache table based on the
163      * page field data.
164      */
165     void                    FilterCacheTableByPageDimensions();
166 
167 	void					SetDupCount( long nNew );
168 
169 public:
170 								ScDPSource( ScDPTableData* pD );	// TableData is deleted by Source
171 	virtual 					~ScDPSource();
172 
173 	ScDPTableData*			GetData()		{ return pData; }
174 	const ScDPTableData*	GetData() const	{ return pData; }
175 
176     void                    SetGrandTotalName(const ::rtl::OUString& rName);
177     const ::rtl::OUString*  GetGrandTotalName() const;
178 
179 	sal_uInt16					GetOrientation(long nColumn);
180 	void					SetOrientation(long nColumn, sal_uInt16 nNew);
181 	long					GetPosition(long nColumn);
182 
183 	long					GetDataDimensionCount();
184     ScDPDimension*          GetDataDimension(long nIndex);
185 	String					GetDataDimName(long nIndex);
186     // Wang Xu Ming -- 2009-8-17
187     // DataPilot Migration - Cache&&Performance
188     ScDPTableDataCache*         GetCache();
189     const ScDPItemData*            GetItemDataById( long nDim, long nId );
190     long                                       GetDataLayoutDim(){ return pData->GetColumnCount(); }
191     SCROW                                GetMemberId(  long  nDim, const ScDPItemData& rData );
192     // End Comments
193 	sal_Bool					IsDataLayoutDimension(long nDim);
194 	sal_uInt16					GetDataLayoutOrientation();
195 
196 	sal_Bool					IsDateDimension(long nDim);
197 	sal_uInt32					GetNumberFormat(long nDim);
198 
199 	sal_Bool					SubTotalAllowed(long nColumn);		//! move to ScDPResultData
200 
201 	ScDPDimension*			AddDuplicated(long nSource, const String& rNewName);
202 	long					GetDupCount() const	{ return nDupCount; }
203 
204 	long					GetSourceDim(long nDim);
205 
206 	const com::sun::star::uno::Sequence<com::sun::star::sheet::MemberResult>*
207 							GetMemberResults( ScDPLevel* pLevel );
208 
209 	ScDPDimensions*			GetDimensionsObject();
210 
211 //UNUSED2009-05 void					DumpState( ScDocument* pDoc, const ScAddress& rPos );
212 
213 							// XDimensionsSupplier
214 	virtual ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess >
215 							SAL_CALL getDimensions(  )
216 								throw(::com::sun::star::uno::RuntimeException);
217 
218 							// XDataPilotResults
219 	virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence<
220 							::com::sun::star::sheet::DataResult > > SAL_CALL getResults(  )
221 								throw(::com::sun::star::uno::RuntimeException);
222 
223 							// XRefreshable
224 	virtual void SAL_CALL	refresh() throw(::com::sun::star::uno::RuntimeException);
225 	virtual void SAL_CALL	addRefreshListener( const ::com::sun::star::uno::Reference<
226 									::com::sun::star::util::XRefreshListener >& l )
227 								throw(::com::sun::star::uno::RuntimeException);
228 	virtual void SAL_CALL	removeRefreshListener( const ::com::sun::star::uno::Reference<
229 									::com::sun::star::util::XRefreshListener >& l )
230 								throw(::com::sun::star::uno::RuntimeException);
231 
232                             // XDrillDownDataSupplier
233     virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any > >
234         SAL_CALL getDrillDownData(const ::com::sun::star::uno::Sequence<
235                                       ::com::sun::star::sheet::DataPilotFieldFilter >& aFilters )
236                                 throw(::com::sun::star::uno::RuntimeException);
237 
238 							// XPropertySet
239 	virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo >
240 							SAL_CALL getPropertySetInfo(  )
241 								throw(::com::sun::star::uno::RuntimeException);
242 	virtual void SAL_CALL	setPropertyValue( const ::rtl::OUString& aPropertyName,
243 									const ::com::sun::star::uno::Any& aValue )
244 								throw(::com::sun::star::beans::UnknownPropertyException,
245 									::com::sun::star::beans::PropertyVetoException,
246 									::com::sun::star::lang::IllegalArgumentException,
247 									::com::sun::star::lang::WrappedTargetException,
248 									::com::sun::star::uno::RuntimeException);
249 	virtual ::com::sun::star::uno::Any SAL_CALL getPropertyValue(
250 									const ::rtl::OUString& PropertyName )
251 								throw(::com::sun::star::beans::UnknownPropertyException,
252 									::com::sun::star::lang::WrappedTargetException,
253 									::com::sun::star::uno::RuntimeException);
254 	virtual void SAL_CALL	addPropertyChangeListener( const ::rtl::OUString& aPropertyName,
255 									const ::com::sun::star::uno::Reference<
256 										::com::sun::star::beans::XPropertyChangeListener >& xListener )
257 								throw(::com::sun::star::beans::UnknownPropertyException,
258 									::com::sun::star::lang::WrappedTargetException,
259 									::com::sun::star::uno::RuntimeException);
260 	virtual void SAL_CALL	removePropertyChangeListener( const ::rtl::OUString& aPropertyName,
261 									const ::com::sun::star::uno::Reference<
262 										::com::sun::star::beans::XPropertyChangeListener >& aListener )
263 								throw(::com::sun::star::beans::UnknownPropertyException,
264 									::com::sun::star::lang::WrappedTargetException,
265 									::com::sun::star::uno::RuntimeException);
266 	virtual void SAL_CALL	addVetoableChangeListener( const ::rtl::OUString& PropertyName,
267 									const ::com::sun::star::uno::Reference<
268 										::com::sun::star::beans::XVetoableChangeListener >& aListener )
269 								throw(::com::sun::star::beans::UnknownPropertyException,
270 									::com::sun::star::lang::WrappedTargetException,
271 									::com::sun::star::uno::RuntimeException);
272 	virtual void SAL_CALL	removeVetoableChangeListener( const ::rtl::OUString& PropertyName,
273 									const ::com::sun::star::uno::Reference<
274 										::com::sun::star::beans::XVetoableChangeListener >& aListener )
275 								throw(::com::sun::star::beans::UnknownPropertyException,
276 									::com::sun::star::lang::WrappedTargetException,
277 									::com::sun::star::uno::RuntimeException);
278 
279 							// XServiceInfo
280 	virtual ::rtl::OUString SAL_CALL getImplementationName(  )
281 								throw(::com::sun::star::uno::RuntimeException);
282 	virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName )
283 								throw(::com::sun::star::uno::RuntimeException);
284 	virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames()
285 								throw(::com::sun::star::uno::RuntimeException);
286 
287 	virtual String				getDataDescription();		//! ???
288 
289 	virtual sal_Bool				getColumnGrand() const;
290 	virtual void				setColumnGrand(sal_Bool bSet);
291 	virtual sal_Bool				getRowGrand() const;
292 	virtual void				setRowGrand(sal_Bool bSet);
293 
294 	virtual sal_Bool				getIgnoreEmptyRows() const;
295 	virtual void				setIgnoreEmptyRows(sal_Bool bSet);
296 	virtual sal_Bool				getRepeatIfEmpty() const;
297 	virtual void				setRepeatIfEmpty(sal_Bool bSet);
298 
299 	virtual void				validate();		//! ???
300 	virtual void				disposeData();
301 };
302 
303 class ScDPDimensions : public cppu::WeakImplHelper2<
304 							com::sun::star::container::XNameAccess,
305 							com::sun::star::lang::XServiceInfo >
306 {
307 private:
308 	ScDPSource*			pSource;
309 	long				nDimCount;
310 	ScDPDimension**		ppDims;
311 
312 public:
313 							ScDPDimensions( ScDPSource* pSrc );
314 	virtual 				~ScDPDimensions();
315 
316 	void					CountChanged();
317 
318 							// XNameAccess
319 	virtual ::com::sun::star::uno::Any SAL_CALL getByName( const ::rtl::OUString& aName )
320 								throw(::com::sun::star::container::NoSuchElementException,
321 									::com::sun::star::lang::WrappedTargetException,
322 									::com::sun::star::uno::RuntimeException);
323 	virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getElementNames()
324 								throw(::com::sun::star::uno::RuntimeException);
325 	virtual sal_Bool SAL_CALL hasByName( const ::rtl::OUString& aName )
326 								throw(::com::sun::star::uno::RuntimeException);
327 
328 							// XElementAccess
329 	virtual ::com::sun::star::uno::Type SAL_CALL getElementType()
330 								throw(::com::sun::star::uno::RuntimeException);
331 	virtual sal_Bool SAL_CALL hasElements() throw(::com::sun::star::uno::RuntimeException);
332 
333 							// XServiceInfo
334 	virtual ::rtl::OUString SAL_CALL getImplementationName(  )
335 								throw(::com::sun::star::uno::RuntimeException);
336 	virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName )
337 								throw(::com::sun::star::uno::RuntimeException);
338 	virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames()
339 								throw(::com::sun::star::uno::RuntimeException);
340 
341 	virtual	long			getCount() const;
342 	virtual ScDPDimension*	getByIndex(long nIndex) const;
343 };
344 
345 class ScDPDimension : public cppu::WeakImplHelper5<
346 							com::sun::star::sheet::XHierarchiesSupplier,
347 							com::sun::star::container::XNamed,
348 							com::sun::star::util::XCloneable,
349 							com::sun::star::beans::XPropertySet,
350 							com::sun::star::lang::XServiceInfo >
351 {
352 private:
353 	ScDPSource*			pSource;
354 	long				nDim;               // dimension index (== column ID)
355 	ScDPHierarchies*	pHierarchies;
356 	long				nUsedHier;
357 	sal_uInt16				nFunction;			// enum GeneralFunction
358 	String				aName;				// if empty, take from source
359     ::std::auto_ptr<rtl::OUString> mpLayoutName;
360     ::std::auto_ptr<rtl::OUString> mpSubtotalName;
361 	long				nSourceDim;			// >=0 if dup'ed
362     ::com::sun::star::sheet::DataPilotFieldReference
363                         aReferenceValue;    // settings for "show data as" / "displayed value"
364 	sal_Bool				bHasSelectedPage;
365 	String				aSelectedPage;
366 	ScDPItemData*		pSelectedData;		// internal, temporary, created from aSelectedPage
367     sal_Bool            mbHasHiddenMember;
368 
369 public:
370 							ScDPDimension( ScDPSource* pSrc, long nD );
371 	virtual 				~ScDPDimension();
372 
373     long                    GetDimension() const    { return nDim; }        // dimension index in source
374 	long					GetSourceDim() const	{ return nSourceDim; }  // >=0 if dup'ed
375 
376 	ScDPDimension*			CreateCloneObject();
377 	ScDPHierarchies*		GetHierarchiesObject();
378 
379     SC_DLLPUBLIC const ::rtl::OUString*  GetLayoutName() const;
380     const ::rtl::OUString*  GetSubtotalName() const;
381 
382 							// XNamed
383 	virtual ::rtl::OUString SAL_CALL getName() throw(::com::sun::star::uno::RuntimeException);
384 	virtual void SAL_CALL	setName( const ::rtl::OUString& aName )
385 								throw(::com::sun::star::uno::RuntimeException);
386 
387 							// XHierarchiesSupplier
388 	virtual ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess > SAL_CALL
389 							getHierarchies() throw(::com::sun::star::uno::RuntimeException);
390 
391 							// XCloneable
392 	virtual ::com::sun::star::uno::Reference< ::com::sun::star::util::XCloneable > SAL_CALL
393 							createClone() throw(::com::sun::star::uno::RuntimeException);
394 
395 							// XPropertySet
396 	virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo >
397 							SAL_CALL getPropertySetInfo(  )
398 								throw(::com::sun::star::uno::RuntimeException);
399 	virtual void SAL_CALL	setPropertyValue( const ::rtl::OUString& aPropertyName,
400 									const ::com::sun::star::uno::Any& aValue )
401 								throw(::com::sun::star::beans::UnknownPropertyException,
402 									::com::sun::star::beans::PropertyVetoException,
403 									::com::sun::star::lang::IllegalArgumentException,
404 									::com::sun::star::lang::WrappedTargetException,
405 									::com::sun::star::uno::RuntimeException);
406 	virtual ::com::sun::star::uno::Any SAL_CALL getPropertyValue(
407 									const ::rtl::OUString& PropertyName )
408 								throw(::com::sun::star::beans::UnknownPropertyException,
409 									::com::sun::star::lang::WrappedTargetException,
410 									::com::sun::star::uno::RuntimeException);
411 	virtual void SAL_CALL	addPropertyChangeListener( const ::rtl::OUString& aPropertyName,
412 									const ::com::sun::star::uno::Reference<
413 										::com::sun::star::beans::XPropertyChangeListener >& xListener )
414 								throw(::com::sun::star::beans::UnknownPropertyException,
415 									::com::sun::star::lang::WrappedTargetException,
416 									::com::sun::star::uno::RuntimeException);
417 	virtual void SAL_CALL	removePropertyChangeListener( const ::rtl::OUString& aPropertyName,
418 									const ::com::sun::star::uno::Reference<
419 										::com::sun::star::beans::XPropertyChangeListener >& aListener )
420 								throw(::com::sun::star::beans::UnknownPropertyException,
421 									::com::sun::star::lang::WrappedTargetException,
422 									::com::sun::star::uno::RuntimeException);
423 	virtual void SAL_CALL	addVetoableChangeListener( const ::rtl::OUString& PropertyName,
424 									const ::com::sun::star::uno::Reference<
425 										::com::sun::star::beans::XVetoableChangeListener >& aListener )
426 								throw(::com::sun::star::beans::UnknownPropertyException,
427 									::com::sun::star::lang::WrappedTargetException,
428 									::com::sun::star::uno::RuntimeException);
429 	virtual void SAL_CALL	removeVetoableChangeListener( const ::rtl::OUString& PropertyName,
430 									const ::com::sun::star::uno::Reference<
431 										::com::sun::star::beans::XVetoableChangeListener >& aListener )
432 								throw(::com::sun::star::beans::UnknownPropertyException,
433 									::com::sun::star::lang::WrappedTargetException,
434 									::com::sun::star::uno::RuntimeException);
435 
436 							// XServiceInfo
437 	virtual ::rtl::OUString SAL_CALL getImplementationName(  )
438 								throw(::com::sun::star::uno::RuntimeException);
439 	virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName )
440 								throw(::com::sun::star::uno::RuntimeException);
441 	virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames()
442 								throw(::com::sun::star::uno::RuntimeException);
443 
444 	virtual sal_uInt16				getOrientation() const;
445 	virtual void				setOrientation(sal_uInt16 nNew);
446 	virtual long				getPosition() const;
447 	virtual void				setPosition(long nNew);
448 	virtual	sal_Bool				getIsDataLayoutDimension() const;
449 	virtual sal_uInt16				getFunction() const;
450 	virtual void				setFunction(sal_uInt16 nNew);		// for data dimension
451 	virtual long				getUsedHierarchy() const;
452 	virtual void				setUsedHierarchy(long nNew);
453 	virtual sal_Bool				isDuplicated() const;
454 
455     sal_Bool                        HasSelectedPage() const     { return bHasSelectedPage; }
456     const ScDPItemData&         GetSelectedData();
457 
458 	const ::com::sun::star::sheet::DataPilotFieldReference& GetReferenceValue() const;
459 
460 //UNUSED2009-05 sal_Bool						IsValidPage( const ScDPItemData& rData );
461 // Wang Xu Ming -- 2009-8-17
462 // DataPilot Migration - Cache&&Performance
463     sal_Bool                      IsVisible( const ScDPItemData& rData );
464 // End Comments
465 };
466 
467 class ScDPHierarchies : public cppu::WeakImplHelper2<
468 							com::sun::star::container::XNameAccess,
469 							com::sun::star::lang::XServiceInfo >
470 {
471 private:
472 	ScDPSource*			pSource;
473 	long				nDim;
474 	long				nHierCount;
475 	ScDPHierarchy**		ppHiers;
476 
477 public:
478 							ScDPHierarchies( ScDPSource* pSrc, long nD );
479 	virtual 				~ScDPHierarchies();
480 
481 							// XNameAccess
482 	virtual ::com::sun::star::uno::Any SAL_CALL getByName( const ::rtl::OUString& aName )
483 								throw(::com::sun::star::container::NoSuchElementException,
484 									::com::sun::star::lang::WrappedTargetException,
485 									::com::sun::star::uno::RuntimeException);
486 	virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getElementNames()
487 								throw(::com::sun::star::uno::RuntimeException);
488 	virtual sal_Bool SAL_CALL hasByName( const ::rtl::OUString& aName )
489 								throw(::com::sun::star::uno::RuntimeException);
490 
491 							// XElementAccess
492 	virtual ::com::sun::star::uno::Type SAL_CALL getElementType()
493 								throw(::com::sun::star::uno::RuntimeException);
494 	virtual sal_Bool SAL_CALL hasElements() throw(::com::sun::star::uno::RuntimeException);
495 
496 							// XServiceInfo
497 	virtual ::rtl::OUString SAL_CALL getImplementationName(  )
498 								throw(::com::sun::star::uno::RuntimeException);
499 	virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName )
500 								throw(::com::sun::star::uno::RuntimeException);
501 	virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames()
502 								throw(::com::sun::star::uno::RuntimeException);
503 
504 	virtual	long			getCount() const;
505 	virtual ScDPHierarchy*	getByIndex(long nIndex) const;
506 };
507 
508 class ScDPHierarchy : public cppu::WeakImplHelper3<
509 							com::sun::star::sheet::XLevelsSupplier,
510 							com::sun::star::container::XNamed,
511 							com::sun::star::lang::XServiceInfo >
512 {
513 private:
514 	ScDPSource*		pSource;
515 	long			nDim;
516 	long			nHier;
517 	ScDPLevels*		pLevels;
518 
519 public:
520 							ScDPHierarchy( ScDPSource* pSrc, long nD, long nH );
521 	virtual 				~ScDPHierarchy();
522 
523 	ScDPLevels*				GetLevelsObject();
524 
525 							// XNamed
526 	virtual ::rtl::OUString SAL_CALL getName() throw(::com::sun::star::uno::RuntimeException);
527 	virtual void SAL_CALL	setName( const ::rtl::OUString& aName )
528 								throw(::com::sun::star::uno::RuntimeException);
529 
530 							// XLevelsSupplier
531 	virtual ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess > SAL_CALL
532 							getLevels() throw(::com::sun::star::uno::RuntimeException);
533 
534 							// XServiceInfo
535 	virtual ::rtl::OUString SAL_CALL getImplementationName(  )
536 								throw(::com::sun::star::uno::RuntimeException);
537 	virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName )
538 								throw(::com::sun::star::uno::RuntimeException);
539 	virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames()
540 								throw(::com::sun::star::uno::RuntimeException);
541 };
542 
543 class ScDPLevels : public cppu::WeakImplHelper2<
544 							com::sun::star::container::XNameAccess,
545 							com::sun::star::lang::XServiceInfo >
546 {
547 private:
548 	ScDPSource*		pSource;
549 	long			nDim;
550 	long			nHier;
551 	long			nLevCount;
552 	ScDPLevel**		ppLevs;
553 
554 public:
555 							ScDPLevels( ScDPSource* pSrc, long nD, long nH );
556 	virtual 				~ScDPLevels();
557 
558 							// XNameAccess
559 	virtual ::com::sun::star::uno::Any SAL_CALL getByName( const ::rtl::OUString& aName )
560 								throw(::com::sun::star::container::NoSuchElementException,
561 									::com::sun::star::lang::WrappedTargetException,
562 									::com::sun::star::uno::RuntimeException);
563 	virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getElementNames()
564 								throw(::com::sun::star::uno::RuntimeException);
565 	virtual sal_Bool SAL_CALL hasByName( const ::rtl::OUString& aName )
566 								throw(::com::sun::star::uno::RuntimeException);
567 
568 							// XElementAccess
569 	virtual ::com::sun::star::uno::Type SAL_CALL getElementType()
570 								throw(::com::sun::star::uno::RuntimeException);
571 	virtual sal_Bool SAL_CALL hasElements() throw(::com::sun::star::uno::RuntimeException);
572 
573 							// XServiceInfo
574 	virtual ::rtl::OUString SAL_CALL getImplementationName(  )
575 								throw(::com::sun::star::uno::RuntimeException);
576 	virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName )
577 								throw(::com::sun::star::uno::RuntimeException);
578 	virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames()
579 								throw(::com::sun::star::uno::RuntimeException);
580 
581 	virtual	long			getCount() const;
582 	virtual ScDPLevel*		getByIndex(long nIndex) const;
583 };
584 
585 class ScDPLevel : public cppu::WeakImplHelper5<
586 							com::sun::star::sheet::XMembersSupplier,
587 							com::sun::star::container::XNamed,
588 							com::sun::star::sheet::XDataPilotMemberResults,
589 							com::sun::star::beans::XPropertySet,
590 							com::sun::star::lang::XServiceInfo >
591 {
592 private:
593 	ScDPSource*					pSource;
594 	long						nDim;
595 	long						nHier;
596 	long						nLev;
597 	ScDPMembers*				pMembers;
598 	com::sun::star::uno::Sequence<com::sun::star::sheet::GeneralFunction> aSubTotals;
599 	sal_Bool						bShowEmpty;
600     ::com::sun::star::sheet::DataPilotFieldSortInfo     aSortInfo;      // stored user settings
601     ::com::sun::star::sheet::DataPilotFieldAutoShowInfo aAutoShowInfo;  // stored user settings
602 	::com::sun::star::sheet::DataPilotFieldLayoutInfo   aLayoutInfo;    // stored user settings
603 	                                                // valid only from result calculation:
604 	::std::vector<sal_Int32>    aGlobalOrder;       // result of sorting by name or position
605 	long                        nSortMeasure;       // measure (index of data dimension) to sort by
606 	long                        nAutoMeasure;       // measure (index of data dimension) for AutoShow
607 	sal_Bool                        bEnableLayout;      // enabled only for row fields, not for the innermost one
608 
609 public:
610 							ScDPLevel( ScDPSource* pSrc, long nD, long nH, long nL );
611 	virtual 				~ScDPLevel();
612 
613 	ScDPMembers*			GetMembersObject();
614 
615 							// XNamed
616 	virtual ::rtl::OUString SAL_CALL getName() throw(::com::sun::star::uno::RuntimeException);
617 	virtual void SAL_CALL	setName( const ::rtl::OUString& aName )
618 								throw(::com::sun::star::uno::RuntimeException);
619 
620 							// XMembersSupplier
621 	virtual ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess > SAL_CALL
622 							getMembers() throw(::com::sun::star::uno::RuntimeException);
623 
624 							// XDataPilotMemberResults
625 	virtual ::com::sun::star::uno::Sequence< ::com::sun::star::sheet::MemberResult > SAL_CALL
626 							getResults() throw(::com::sun::star::uno::RuntimeException);
627 
628 							// XPropertySet
629 	virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo >
630 							SAL_CALL getPropertySetInfo(  )
631 								throw(::com::sun::star::uno::RuntimeException);
632 	virtual void SAL_CALL	setPropertyValue( const ::rtl::OUString& aPropertyName,
633 									const ::com::sun::star::uno::Any& aValue )
634 								throw(::com::sun::star::beans::UnknownPropertyException,
635 									::com::sun::star::beans::PropertyVetoException,
636 									::com::sun::star::lang::IllegalArgumentException,
637 									::com::sun::star::lang::WrappedTargetException,
638 									::com::sun::star::uno::RuntimeException);
639 	virtual ::com::sun::star::uno::Any SAL_CALL getPropertyValue(
640 									const ::rtl::OUString& PropertyName )
641 								throw(::com::sun::star::beans::UnknownPropertyException,
642 									::com::sun::star::lang::WrappedTargetException,
643 									::com::sun::star::uno::RuntimeException);
644 	virtual void SAL_CALL	addPropertyChangeListener( const ::rtl::OUString& aPropertyName,
645 									const ::com::sun::star::uno::Reference<
646 										::com::sun::star::beans::XPropertyChangeListener >& xListener )
647 								throw(::com::sun::star::beans::UnknownPropertyException,
648 									::com::sun::star::lang::WrappedTargetException,
649 									::com::sun::star::uno::RuntimeException);
650 	virtual void SAL_CALL	removePropertyChangeListener( const ::rtl::OUString& aPropertyName,
651 									const ::com::sun::star::uno::Reference<
652 										::com::sun::star::beans::XPropertyChangeListener >& aListener )
653 								throw(::com::sun::star::beans::UnknownPropertyException,
654 									::com::sun::star::lang::WrappedTargetException,
655 									::com::sun::star::uno::RuntimeException);
656 	virtual void SAL_CALL	addVetoableChangeListener( const ::rtl::OUString& PropertyName,
657 									const ::com::sun::star::uno::Reference<
658 										::com::sun::star::beans::XVetoableChangeListener >& aListener )
659 								throw(::com::sun::star::beans::UnknownPropertyException,
660 									::com::sun::star::lang::WrappedTargetException,
661 									::com::sun::star::uno::RuntimeException);
662 	virtual void SAL_CALL	removeVetoableChangeListener( const ::rtl::OUString& PropertyName,
663 									const ::com::sun::star::uno::Reference<
664 										::com::sun::star::beans::XVetoableChangeListener >& aListener )
665 								throw(::com::sun::star::beans::UnknownPropertyException,
666 									::com::sun::star::lang::WrappedTargetException,
667 									::com::sun::star::uno::RuntimeException);
668 
669 							// XServiceInfo
670 	virtual ::rtl::OUString SAL_CALL getImplementationName(  )
671 								throw(::com::sun::star::uno::RuntimeException);
672 	virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName )
673 								throw(::com::sun::star::uno::RuntimeException);
674 	virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames()
675 								throw(::com::sun::star::uno::RuntimeException);
676 
677 	virtual com::sun::star::uno::Sequence<com::sun::star::sheet::GeneralFunction> getSubTotals() const;
678 	virtual void			setSubTotals(const com::sun::star::uno::Sequence<
679 											com::sun::star::sheet::GeneralFunction>& rNew);
680 	virtual sal_Bool			getShowEmpty() const;
681 	virtual void			setShowEmpty(sal_Bool bSet);
682 
683     const ::com::sun::star::sheet::DataPilotFieldSortInfo& GetSortInfo() const      { return aSortInfo; }
684 	const ::com::sun::star::sheet::DataPilotFieldAutoShowInfo& GetAutoShow() const  { return aAutoShowInfo; }
685 
686     void                    EvaluateSortOrder();
687     void                    SetEnableLayout( sal_Bool bSet );
688 
689 	const ::std::vector<sal_Int32>& GetGlobalOrder() const      { return aGlobalOrder; }
690 	::std::vector<sal_Int32>&  GetGlobalOrder()                 { return aGlobalOrder; }
691     long                    GetSortMeasure() const              { return nSortMeasure; }
692     long                    GetAutoMeasure() const              { return nAutoMeasure; }
693 
694 	sal_Bool                    IsOutlineLayout() const
695 	                        { return bEnableLayout &&
696 	                           aLayoutInfo.LayoutMode !=
697 	                            ::com::sun::star::sheet::DataPilotFieldLayoutMode::TABULAR_LAYOUT; }
698 
699 	sal_Bool                    IsSubtotalsAtTop() const
700 	                        { return bEnableLayout &&
701 	                           aLayoutInfo.LayoutMode ==
702 	                            ::com::sun::star::sheet::DataPilotFieldLayoutMode::OUTLINE_SUBTOTALS_TOP; }
703 
704 	sal_Bool                    IsAddEmpty() const          { return bEnableLayout && aLayoutInfo.AddEmptyLines; }
705 
706 	//!	number format (for data fields and date fields)
707 };
708 
709 // hash map from name to index in the member array, for fast name access
710 typedef ::std::hash_map< ::rtl::OUString, sal_Int32, ::rtl::OUStringHash > ScDPMembersHashMap;
711 
712 class ScDPMembers : public cppu::WeakImplHelper2<
713 							com::sun::star::container::XNameAccess,
714 							com::sun::star::lang::XServiceInfo >
715 {
716 private:
717 	ScDPSource*		pSource;
718 	long			nDim;
719 	long			nHier;
720 	long			nLev;
721 	long			nMbrCount;
722 	ScDPMember**	ppMbrs;
723     mutable ScDPMembersHashMap aHashMap;
724 
725 public:
726 							ScDPMembers( ScDPSource* pSrc, long nD, long nH, long nL );
727 	virtual 				~ScDPMembers();
728 
729 							// XNameAccess
730 	virtual ::com::sun::star::uno::Any SAL_CALL getByName( const ::rtl::OUString& aName )
731 								throw(::com::sun::star::container::NoSuchElementException,
732 									::com::sun::star::lang::WrappedTargetException,
733 									::com::sun::star::uno::RuntimeException);
734 	virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getElementNames()
735 								throw(::com::sun::star::uno::RuntimeException);
736 	virtual sal_Bool SAL_CALL hasByName( const ::rtl::OUString& aName )
737 								throw(::com::sun::star::uno::RuntimeException);
738 
739 							// XElementAccess
740 	virtual ::com::sun::star::uno::Type SAL_CALL getElementType()
741 								throw(::com::sun::star::uno::RuntimeException);
742 	virtual sal_Bool SAL_CALL hasElements() throw(::com::sun::star::uno::RuntimeException);
743 
744 							// XServiceInfo
745 	virtual ::rtl::OUString SAL_CALL getImplementationName(  )
746 								throw(::com::sun::star::uno::RuntimeException);
747 	virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName )
748 								throw(::com::sun::star::uno::RuntimeException);
749 	virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames()
750 								throw(::com::sun::star::uno::RuntimeException);
751 
752 	virtual	long			getCount() const;
753 	virtual ScDPMember*		getByIndex(long nIndex) const;
754 
755 	long					getMinMembers() const;
756 
757     sal_Int32               GetIndexFromName( const ::rtl::OUString& rName ) const;     // <0 if not found
758     // Wang Xu Ming -- 2009-8-17
759     // DataPilot Migration - Cache&&Performance
760     const std::vector<sal_Int32>&    GetGlobalOrder();
761     const ScDPItemData*               GetSrcItemDataByIndex(  SCROW nIndex);
762     SCROW                                   GetSrcItemsCount();
763     // End Comments
764 };
765 
766 class ScDPMember : public cppu::WeakImplHelper3<
767 							com::sun::star::container::XNamed,
768 							com::sun::star::beans::XPropertySet,
769 							com::sun::star::lang::XServiceInfo >
770 {
771 private:
772 	ScDPSource*		pSource;
773 	long			nDim;
774 	long			nHier;
775 	long			nLev;
776 
777     // Wang Xu Ming -- 2009-8-17
778     // DataPilot Migration - Cache&&Performance
779     SCROW       mnDataId;
780     // End Comments
781 //	String			aCaption;			// visible name (changeable by user)
782     ::std::auto_ptr<rtl::OUString> mpLayoutName;
783 
784     sal_Int32       nPosition;          // manual sorting
785 	sal_Bool			bVisible;
786 	sal_Bool			bShowDet;
787 
788 public:
789     // Wang Xu Ming -- 2009-8-17
790     // DataPilot Migration - Cache&&Performance
791     ScDPMember( ScDPSource* pSrc, long nD, long nH, long nL,
792         SCROW nIndex /*const String& rN, double fV, sal_Bool bHV */);
793     // End Comments
794     virtual 				~ScDPMember();
795 
796 	sal_Bool					IsNamedItem( const ScDPItemData& r ) const;
797 	String					GetNameStr() const;
798 	void					FillItemData( ScDPItemData& rData ) const;
799     // Wang Xu Ming -- 2009-8-17
800     // DataPilot Migration - Cache&&Performance
801     //  const ScDPItemData&  GetItemData() const{ return maData; }
802     const ScDPItemData&  GetItemData() const;
803     inline SCROW               GetItemDataId() const { return mnDataId; }
804     sal_Bool                           IsNamedItem( SCROW    nIndex  ) const;
805     // End Comments
806 
807     SC_DLLPUBLIC const ::rtl::OUString*  GetLayoutName() const;
808 
809     sal_Int32               Compare( const ScDPMember& rOther ) const;      // visible order
810 
811 							// XNamed
812 	virtual ::rtl::OUString SAL_CALL getName() throw(::com::sun::star::uno::RuntimeException);
813 	virtual void SAL_CALL	setName( const ::rtl::OUString& aName )
814 								throw(::com::sun::star::uno::RuntimeException);
815 
816 							// XPropertySet
817 	virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo >
818 							SAL_CALL getPropertySetInfo(  )
819 								throw(::com::sun::star::uno::RuntimeException);
820 	virtual void SAL_CALL	setPropertyValue( const ::rtl::OUString& aPropertyName,
821 									const ::com::sun::star::uno::Any& aValue )
822 								throw(::com::sun::star::beans::UnknownPropertyException,
823 									::com::sun::star::beans::PropertyVetoException,
824 									::com::sun::star::lang::IllegalArgumentException,
825 									::com::sun::star::lang::WrappedTargetException,
826 									::com::sun::star::uno::RuntimeException);
827 	virtual ::com::sun::star::uno::Any SAL_CALL getPropertyValue(
828 									const ::rtl::OUString& PropertyName )
829 								throw(::com::sun::star::beans::UnknownPropertyException,
830 									::com::sun::star::lang::WrappedTargetException,
831 									::com::sun::star::uno::RuntimeException);
832 	virtual void SAL_CALL	addPropertyChangeListener( const ::rtl::OUString& aPropertyName,
833 									const ::com::sun::star::uno::Reference<
834 										::com::sun::star::beans::XPropertyChangeListener >& xListener )
835 								throw(::com::sun::star::beans::UnknownPropertyException,
836 									::com::sun::star::lang::WrappedTargetException,
837 									::com::sun::star::uno::RuntimeException);
838 	virtual void SAL_CALL	removePropertyChangeListener( const ::rtl::OUString& aPropertyName,
839 									const ::com::sun::star::uno::Reference<
840 										::com::sun::star::beans::XPropertyChangeListener >& aListener )
841 								throw(::com::sun::star::beans::UnknownPropertyException,
842 									::com::sun::star::lang::WrappedTargetException,
843 									::com::sun::star::uno::RuntimeException);
844 	virtual void SAL_CALL	addVetoableChangeListener( const ::rtl::OUString& PropertyName,
845 									const ::com::sun::star::uno::Reference<
846 										::com::sun::star::beans::XVetoableChangeListener >& aListener )
847 								throw(::com::sun::star::beans::UnknownPropertyException,
848 									::com::sun::star::lang::WrappedTargetException,
849 									::com::sun::star::uno::RuntimeException);
850 	virtual void SAL_CALL	removeVetoableChangeListener( const ::rtl::OUString& PropertyName,
851 									const ::com::sun::star::uno::Reference<
852 										::com::sun::star::beans::XVetoableChangeListener >& aListener )
853 								throw(::com::sun::star::beans::UnknownPropertyException,
854 									::com::sun::star::lang::WrappedTargetException,
855 									::com::sun::star::uno::RuntimeException);
856 
857 							// XServiceInfo
858 	virtual ::rtl::OUString SAL_CALL getImplementationName(  )
859 								throw(::com::sun::star::uno::RuntimeException);
860 	virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName )
861 								throw(::com::sun::star::uno::RuntimeException);
862 	virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames()
863 								throw(::com::sun::star::uno::RuntimeException);
864 
865 	virtual sal_Bool			getIsVisible() const;
866 	virtual void			setIsVisible(sal_Bool bSet);
867 	virtual sal_Bool			getShowDetails() const;
868 	virtual void			setShowDetails(sal_Bool bSet);
869 
870     sal_Int32               getPosition() const;
871     void                    setPosition(sal_Int32 nNew);
872 };
873 
874 
875 #endif
876 
877