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