xref: /aoo41x/main/sc/inc/dpobject.hxx (revision cdf0e10c)
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 #ifndef SC_DPOBJECT_HXX
29*cdf0e10cSrcweir #define SC_DPOBJECT_HXX
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include "scdllapi.h"
32*cdf0e10cSrcweir #include "global.hxx"
33*cdf0e10cSrcweir #include "address.hxx"
34*cdf0e10cSrcweir #include "collect.hxx"
35*cdf0e10cSrcweir #include "dpoutput.hxx"
36*cdf0e10cSrcweir #include "pivot.hxx"
37*cdf0e10cSrcweir #include <com/sun/star/sheet/XDimensionsSupplier.hpp>
38*cdf0e10cSrcweir 
39*cdf0e10cSrcweir #include <boost/shared_ptr.hpp>
40*cdf0e10cSrcweir 
41*cdf0e10cSrcweir //------------------------------------------------------------------
42*cdf0e10cSrcweir 
43*cdf0e10cSrcweir namespace com { namespace sun { namespace star { namespace sheet {
44*cdf0e10cSrcweir 
45*cdf0e10cSrcweir     struct DataPilotTablePositionData;
46*cdf0e10cSrcweir     struct DataPilotTableHeaderData;
47*cdf0e10cSrcweir 
48*cdf0e10cSrcweir }}}}
49*cdf0e10cSrcweir 
50*cdf0e10cSrcweir namespace com { namespace sun { namespace star { namespace sheet {
51*cdf0e10cSrcweir     struct DataPilotFieldFilter;
52*cdf0e10cSrcweir }}}}
53*cdf0e10cSrcweir 
54*cdf0e10cSrcweir class Rectangle;
55*cdf0e10cSrcweir class SvStream;
56*cdf0e10cSrcweir class ScDPSaveData;
57*cdf0e10cSrcweir class ScDPOutput;
58*cdf0e10cSrcweir class ScPivot;
59*cdf0e10cSrcweir class ScPivotCollection;
60*cdf0e10cSrcweir struct ScPivotParam;
61*cdf0e10cSrcweir struct ScImportSourceDesc;
62*cdf0e10cSrcweir struct ScSheetSourceDesc;
63*cdf0e10cSrcweir class ScStrCollection;
64*cdf0e10cSrcweir class TypedScStrCollection;
65*cdf0e10cSrcweir struct PivotField;
66*cdf0e10cSrcweir class ScDPCacheTable;
67*cdf0e10cSrcweir class ScDPTableData;
68*cdf0e10cSrcweir 
69*cdf0e10cSrcweir struct ScDPServiceDesc
70*cdf0e10cSrcweir {
71*cdf0e10cSrcweir 	String	aServiceName;
72*cdf0e10cSrcweir 	String	aParSource;
73*cdf0e10cSrcweir 	String	aParName;
74*cdf0e10cSrcweir 	String	aParUser;
75*cdf0e10cSrcweir 	String	aParPass;
76*cdf0e10cSrcweir 
77*cdf0e10cSrcweir 	ScDPServiceDesc( const String& rServ, const String& rSrc, const String& rNam,
78*cdf0e10cSrcweir 						const String& rUser, const String& rPass ) :
79*cdf0e10cSrcweir 		aServiceName( rServ ), aParSource( rSrc ), aParName( rNam ),
80*cdf0e10cSrcweir 		aParUser( rUser ), aParPass( rPass ) {	}
81*cdf0e10cSrcweir 
82*cdf0e10cSrcweir 	sal_Bool operator==	( const ScDPServiceDesc& rOther ) const
83*cdf0e10cSrcweir 		{ return aServiceName == rOther.aServiceName &&
84*cdf0e10cSrcweir 				 aParSource   == rOther.aParSource &&
85*cdf0e10cSrcweir 				 aParName     == rOther.aParName &&
86*cdf0e10cSrcweir 				 aParUser     == rOther.aParUser &&
87*cdf0e10cSrcweir 				 aParPass     == rOther.aParPass; }
88*cdf0e10cSrcweir };
89*cdf0e10cSrcweir 
90*cdf0e10cSrcweir 
91*cdf0e10cSrcweir class SC_DLLPUBLIC ScDPObject : public ScDataObject
92*cdf0e10cSrcweir {
93*cdf0e10cSrcweir private:
94*cdf0e10cSrcweir 	ScDocument*				pDoc;
95*cdf0e10cSrcweir 											// settings
96*cdf0e10cSrcweir 	ScDPSaveData*			pSaveData;
97*cdf0e10cSrcweir 	String					aTableName;
98*cdf0e10cSrcweir 	String					aTableTag;
99*cdf0e10cSrcweir 	ScRange					aOutRange;
100*cdf0e10cSrcweir 	ScSheetSourceDesc*		pSheetDesc;		//	for sheet data
101*cdf0e10cSrcweir 	ScImportSourceDesc* 	pImpDesc;		//	for database data
102*cdf0e10cSrcweir 	ScDPServiceDesc*		pServDesc;		//	for external service
103*cdf0e10cSrcweir     ::boost::shared_ptr<ScDPTableData>  mpTableData;
104*cdf0e10cSrcweir 											// cached data
105*cdf0e10cSrcweir 	com::sun::star::uno::Reference<com::sun::star::sheet::XDimensionsSupplier> xSource;
106*cdf0e10cSrcweir 	ScDPOutput*				pOutput;
107*cdf0e10cSrcweir 	sal_Bool					bSettingsChanged;
108*cdf0e10cSrcweir 	sal_Bool					bAlive;			// sal_False if only used to hold settings
109*cdf0e10cSrcweir 	sal_Bool					bAllowMove;
110*cdf0e10cSrcweir 	long					nHeaderRows;	// page fields plus filter button
111*cdf0e10cSrcweir     bool                    mbHeaderLayout;  // sal_True : grid, sal_False : standard
112*cdf0e10cSrcweir 
113*cdf0e10cSrcweir 
114*cdf0e10cSrcweir     SC_DLLPRIVATE ScDPTableData*    GetTableData();
115*cdf0e10cSrcweir 	SC_DLLPRIVATE void				CreateObjects();
116*cdf0e10cSrcweir 	SC_DLLPRIVATE void				CreateOutput();
117*cdf0e10cSrcweir 	sal_Bool					bRefresh;
118*cdf0e10cSrcweir 	long						mnCacheId;
119*cdf0e10cSrcweir     bool                        mbCreatingTableData;
120*cdf0e10cSrcweir 
121*cdf0e10cSrcweir public:
122*cdf0e10cSrcweir     // Wang Xu Ming -- 2009-8-17
123*cdf0e10cSrcweir     // DataPilot Migration - Cache&&Performance
124*cdf0e10cSrcweir     inline void SetRefresh() { bRefresh = sal_True; }
125*cdf0e10cSrcweir     const        ScDPTableDataCache* GetCache() const;
126*cdf0e10cSrcweir     long          GetCacheId() const;
127*cdf0e10cSrcweir     void          SetCacheId( long nCacheId );
128*cdf0e10cSrcweir 	sal_uLong RefreshCache();
129*cdf0e10cSrcweir     // End Comments
130*cdf0e10cSrcweir 				ScDPObject( ScDocument* pD );
131*cdf0e10cSrcweir 				ScDPObject(const ScDPObject& r);
132*cdf0e10cSrcweir 	virtual		~ScDPObject();
133*cdf0e10cSrcweir 
134*cdf0e10cSrcweir 	virtual	ScDataObject*	Clone() const;
135*cdf0e10cSrcweir 
136*cdf0e10cSrcweir 	void				SetAlive(sal_Bool bSet);
137*cdf0e10cSrcweir 	void				SetAllowMove(sal_Bool bSet);
138*cdf0e10cSrcweir 
139*cdf0e10cSrcweir 	void				InvalidateData();
140*cdf0e10cSrcweir 	void				InvalidateSource();
141*cdf0e10cSrcweir 
142*cdf0e10cSrcweir 
143*cdf0e10cSrcweir 	void				Output( const ScAddress& rPos );
144*cdf0e10cSrcweir 	ScRange				GetNewOutputRange( sal_Bool& rOverflow );
145*cdf0e10cSrcweir     const ScRange       GetOutputRangeByType( sal_Int32 nType );
146*cdf0e10cSrcweir 
147*cdf0e10cSrcweir 	void				SetSaveData(const ScDPSaveData& rData);
148*cdf0e10cSrcweir 	ScDPSaveData*		GetSaveData() const		{ return pSaveData; }
149*cdf0e10cSrcweir 
150*cdf0e10cSrcweir 	void				SetOutRange(const ScRange& rRange);
151*cdf0e10cSrcweir 	const ScRange&		GetOutRange() const		{ return aOutRange; }
152*cdf0e10cSrcweir 
153*cdf0e10cSrcweir     void                SetHeaderLayout(bool bUseGrid);
154*cdf0e10cSrcweir     bool                GetHeaderLayout() const;
155*cdf0e10cSrcweir 
156*cdf0e10cSrcweir     void                SetSheetDesc(const ScSheetSourceDesc& rDesc, bool bFromRefUpdate = false);
157*cdf0e10cSrcweir 	void				SetImportDesc(const ScImportSourceDesc& rDesc);
158*cdf0e10cSrcweir 	void				SetServiceData(const ScDPServiceDesc& rDesc);
159*cdf0e10cSrcweir 
160*cdf0e10cSrcweir 	void				WriteSourceDataTo( ScDPObject& rDest ) const;
161*cdf0e10cSrcweir 	void				WriteTempDataTo( ScDPObject& rDest ) const;
162*cdf0e10cSrcweir 
163*cdf0e10cSrcweir 	const ScSheetSourceDesc* GetSheetDesc() const	{ return pSheetDesc; }
164*cdf0e10cSrcweir 	const ScImportSourceDesc* GetImportSourceDesc() const	{ return pImpDesc; }
165*cdf0e10cSrcweir 	const ScDPServiceDesc* GetDPServiceDesc() const	{ return pServDesc; }
166*cdf0e10cSrcweir 
167*cdf0e10cSrcweir 	com::sun::star::uno::Reference<com::sun::star::sheet::XDimensionsSupplier> GetSource();
168*cdf0e10cSrcweir 
169*cdf0e10cSrcweir 	sal_Bool				IsSheetData() const;
170*cdf0e10cSrcweir 	sal_Bool				IsImportData() const { return(pImpDesc != NULL); }
171*cdf0e10cSrcweir 	sal_Bool				IsServiceData() const { return(pServDesc != NULL); }
172*cdf0e10cSrcweir 
173*cdf0e10cSrcweir 	void				SetName(const String& rNew);
174*cdf0e10cSrcweir 	const String&		GetName() const					{ return aTableName; }
175*cdf0e10cSrcweir 	void				SetTag(const String& rNew);
176*cdf0e10cSrcweir 	const String&		GetTag() const					{ return aTableTag; }
177*cdf0e10cSrcweir 
178*cdf0e10cSrcweir     /**
179*cdf0e10cSrcweir      *  Data description cell displays the description of a data dimension if
180*cdf0e10cSrcweir      *  and only if there is only one data dimension.  It's usually located at
181*cdf0e10cSrcweir      *  the upper-left corner of the table output.
182*cdf0e10cSrcweir      */
183*cdf0e10cSrcweir     bool                IsDataDescriptionCell(const ScAddress& rPos);
184*cdf0e10cSrcweir 
185*cdf0e10cSrcweir     bool                IsDimNameInUse(const ::rtl::OUString& rName) const;
186*cdf0e10cSrcweir     String              GetDimName( long nDim, sal_Bool& rIsDataLayout, sal_Int32* pFlags = NULL );
187*cdf0e10cSrcweir     sal_Bool                IsDuplicated( long nDim );
188*cdf0e10cSrcweir     long                GetDimCount();
189*cdf0e10cSrcweir     void                GetHeaderPositionData(const ScAddress& rPos, ::com::sun::star::sheet::DataPilotTableHeaderData& rData);
190*cdf0e10cSrcweir 	long				GetHeaderDim( const ScAddress& rPos, sal_uInt16& rOrient );
191*cdf0e10cSrcweir 	sal_Bool				GetHeaderDrag( const ScAddress& rPos, sal_Bool bMouseLeft, sal_Bool bMouseTop,
192*cdf0e10cSrcweir 										long nDragDim,
193*cdf0e10cSrcweir 										Rectangle& rPosRect, sal_uInt16& rOrient, long& rDimPos );
194*cdf0e10cSrcweir 	sal_Bool				IsFilterButton( const ScAddress& rPos );
195*cdf0e10cSrcweir 
196*cdf0e10cSrcweir     sal_Bool                GetPivotData( ScDPGetPivotDataField& rTarget, /* returns result */
197*cdf0e10cSrcweir                                       const std::vector< ScDPGetPivotDataField >& rFilters );
198*cdf0e10cSrcweir     sal_Bool                ParseFilters( ScDPGetPivotDataField& rTarget,
199*cdf0e10cSrcweir                                       std::vector< ScDPGetPivotDataField >& rFilters,
200*cdf0e10cSrcweir                                       const String& rFilterList );
201*cdf0e10cSrcweir 
202*cdf0e10cSrcweir     void                GetMemberResultNames( ScStrCollection& rNames, long nDimension );
203*cdf0e10cSrcweir 
204*cdf0e10cSrcweir 	void				FillPageList( TypedScStrCollection& rStrings, long nField );
205*cdf0e10cSrcweir 
206*cdf0e10cSrcweir     void                ToggleDetails(const ::com::sun::star::sheet::DataPilotTableHeaderData& rElemDesc, ScDPObject* pDestObj);
207*cdf0e10cSrcweir 
208*cdf0e10cSrcweir 	sal_Bool				FillOldParam(ScPivotParam& rParam) const;
209*cdf0e10cSrcweir 	sal_Bool				FillLabelData(ScPivotParam& rParam);
210*cdf0e10cSrcweir 	void				InitFromOldPivot(const ScPivot& rOld, ScDocument* pDoc, sal_Bool bSetSource);
211*cdf0e10cSrcweir 
212*cdf0e10cSrcweir     sal_Bool                GetHierarchiesNA( sal_Int32 nDim, com::sun::star::uno::Reference< com::sun::star::container::XNameAccess >& xHiers );
213*cdf0e10cSrcweir     sal_Bool                GetHierarchies( sal_Int32 nDim, com::sun::star::uno::Sequence< rtl::OUString >& rHiers );
214*cdf0e10cSrcweir 
215*cdf0e10cSrcweir     sal_Int32           GetUsedHierarchy( sal_Int32 nDim );
216*cdf0e10cSrcweir 
217*cdf0e10cSrcweir     sal_Bool                GetMembersNA( sal_Int32 nDim, com::sun::star::uno::Reference< com::sun::star::container::XNameAccess >& xMembers );
218*cdf0e10cSrcweir     sal_Bool                GetMembersNA( sal_Int32 nDim, sal_Int32 nHier, com::sun::star::uno::Reference< com::sun::star::container::XNameAccess >& xMembers );
219*cdf0e10cSrcweir 
220*cdf0e10cSrcweir     bool                GetMemberNames( sal_Int32 nDim, ::com::sun::star::uno::Sequence< ::rtl::OUString >& rNames );
221*cdf0e10cSrcweir     bool                GetMembers( sal_Int32 nDim, sal_Int32 nHier, ::std::vector<ScDPLabelData::Member>& rMembers );
222*cdf0e10cSrcweir 
223*cdf0e10cSrcweir 	void				UpdateReference( UpdateRefMode eUpdateRefMode,
224*cdf0e10cSrcweir 										 const ScRange& r, SCsCOL nDx, SCsROW nDy, SCsTAB nDz );
225*cdf0e10cSrcweir 	sal_Bool				RefsEqual( const ScDPObject& r ) const;
226*cdf0e10cSrcweir 	void				WriteRefsTo( ScDPObject& r ) const;
227*cdf0e10cSrcweir 
228*cdf0e10cSrcweir     void                GetPositionData(const ScAddress& rPos, ::com::sun::star::sheet::DataPilotTablePositionData& rPosData);
229*cdf0e10cSrcweir 
230*cdf0e10cSrcweir     bool                GetDataFieldPositionData(const ScAddress& rPos,
231*cdf0e10cSrcweir                                                  ::com::sun::star::uno::Sequence<
232*cdf0e10cSrcweir                                                     ::com::sun::star::sheet::DataPilotFieldFilter >& rFilters);
233*cdf0e10cSrcweir 
234*cdf0e10cSrcweir     void                GetDrillDownData(const ScAddress& rPos,
235*cdf0e10cSrcweir                                          ::com::sun::star::uno::Sequence<
236*cdf0e10cSrcweir                                             ::com::sun::star::uno::Sequence<
237*cdf0e10cSrcweir                                                 ::com::sun::star::uno::Any > >& rTableData);
238*cdf0e10cSrcweir 
239*cdf0e10cSrcweir 	// apply drop-down attribute, initialize nHeaderRows, without accessing the source
240*cdf0e10cSrcweir 	// (button attribute must be present)
241*cdf0e10cSrcweir 	void				RefreshAfterLoad();
242*cdf0e10cSrcweir 
243*cdf0e10cSrcweir     void                BuildAllDimensionMembers();
244*cdf0e10cSrcweir 
245*cdf0e10cSrcweir 	static sal_Bool			HasRegisteredSources();
246*cdf0e10cSrcweir 	static com::sun::star::uno::Sequence<rtl::OUString> GetRegisteredSources();
247*cdf0e10cSrcweir 	static com::sun::star::uno::Reference<com::sun::star::sheet::XDimensionsSupplier>
248*cdf0e10cSrcweir 						CreateSource( const ScDPServiceDesc& rDesc );
249*cdf0e10cSrcweir 
250*cdf0e10cSrcweir 	static void			ConvertOrientation( ScDPSaveData& rSaveData,
251*cdf0e10cSrcweir 							const ScPivotFieldVector& rFields, sal_uInt16 nOrient,
252*cdf0e10cSrcweir 							ScDocument* pDoc, SCROW nRow, SCTAB nTab,
253*cdf0e10cSrcweir 							const com::sun::star::uno::Reference<
254*cdf0e10cSrcweir 								com::sun::star::sheet::XDimensionsSupplier>& xSource,
255*cdf0e10cSrcweir 							bool bOldDefaults,
256*cdf0e10cSrcweir 							const ScPivotFieldVector* pRefColFields = 0,
257*cdf0e10cSrcweir                             const ScPivotFieldVector* pRefRowFields = 0,
258*cdf0e10cSrcweir                             const ScPivotFieldVector* pRefPageFields = 0 );
259*cdf0e10cSrcweir 
260*cdf0e10cSrcweir     static bool         IsOrientationAllowed( sal_uInt16 nOrient, sal_Int32 nDimFlags );
261*cdf0e10cSrcweir };
262*cdf0e10cSrcweir 
263*cdf0e10cSrcweir 
264*cdf0e10cSrcweir // ============================================================================
265*cdf0e10cSrcweir 
266*cdf0e10cSrcweir class ScDPCollection : public ScCollection
267*cdf0e10cSrcweir {
268*cdf0e10cSrcweir private:
269*cdf0e10cSrcweir 	ScDocument*	pDoc;
270*cdf0e10cSrcweir public:
271*cdf0e10cSrcweir 				ScDPCollection(ScDocument* pDocument);
272*cdf0e10cSrcweir 				ScDPCollection(const ScDPCollection& r);
273*cdf0e10cSrcweir 	virtual		~ScDPCollection();
274*cdf0e10cSrcweir 
275*cdf0e10cSrcweir 	virtual	ScDataObject*	Clone() const;
276*cdf0e10cSrcweir 
277*cdf0e10cSrcweir 	ScDPObject*	operator[](sal_uInt16 nIndex) const {return (ScDPObject*)At(nIndex);}
278*cdf0e10cSrcweir     ScDPObject*	GetByName(const String& rName) const;
279*cdf0e10cSrcweir 
280*cdf0e10cSrcweir     void        DeleteOnTab( SCTAB nTab );
281*cdf0e10cSrcweir 	void		UpdateReference( UpdateRefMode eUpdateRefMode,
282*cdf0e10cSrcweir 								 const ScRange& r, SCsCOL nDx, SCsROW nDy, SCsTAB nDz );
283*cdf0e10cSrcweir 
284*cdf0e10cSrcweir 	sal_Bool		RefsEqual( const ScDPCollection& r ) const;
285*cdf0e10cSrcweir 	void		WriteRefsTo( ScDPCollection& r ) const;
286*cdf0e10cSrcweir 
287*cdf0e10cSrcweir 	String 		CreateNewName( sal_uInt16 nMin = 1 ) const;
288*cdf0e10cSrcweir 
289*cdf0e10cSrcweir     void FreeTable(ScDPObject* pDPObj);
290*cdf0e10cSrcweir     SC_DLLPUBLIC bool InsertNewTable(ScDPObject* pDPObj);
291*cdf0e10cSrcweir 
292*cdf0e10cSrcweir     bool        HasDPTable(SCCOL nCol, SCROW nRow, SCTAB nTab) const;
293*cdf0e10cSrcweir };
294*cdf0e10cSrcweir 
295*cdf0e10cSrcweir 
296*cdf0e10cSrcweir #endif
297*cdf0e10cSrcweir 
298