update ooo310-m15
[ooovba.git] / sc / inc / dpobject.hxx
blob715121be8ab2a559ed5085191003b7e7889cf8ab
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: dpobject.hxx,v $
10 * $Revision: 1.15 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef SC_DPOBJECT_HXX
32 #define SC_DPOBJECT_HXX
34 #include "scdllapi.h"
35 #include "global.hxx"
36 #include "address.hxx"
37 #include "collect.hxx"
38 #include "dpoutput.hxx"
39 #include <com/sun/star/sheet/XDimensionsSupplier.hpp>
41 #include <boost/shared_ptr.hpp>
43 //------------------------------------------------------------------
45 namespace com { namespace sun { namespace star { namespace sheet {
47 struct DataPilotTablePositionData;
48 struct DataPilotTableHeaderData;
50 }}}}
52 namespace com { namespace sun { namespace star { namespace sheet {
53 struct DataPilotFieldFilter;
54 }}}}
56 class Rectangle;
57 class SvStream;
58 class ScDPSaveData;
59 class ScDPOutput;
60 class ScMultipleReadHeader;
61 class ScMultipleWriteHeader;
62 class ScPivot;
63 class ScPivotCollection;
64 struct ScPivotParam;
65 struct ScImportSourceDesc;
66 struct ScSheetSourceDesc;
67 class ScStrCollection;
68 class TypedScStrCollection;
69 struct PivotField;
70 class ScDPCacheTable;
71 class ScDPTableData;
73 struct ScDPServiceDesc
75 String aServiceName;
76 String aParSource;
77 String aParName;
78 String aParUser;
79 String aParPass;
81 ScDPServiceDesc( const String& rServ, const String& rSrc, const String& rNam,
82 const String& rUser, const String& rPass ) :
83 aServiceName( rServ ), aParSource( rSrc ), aParName( rNam ),
84 aParUser( rUser ), aParPass( rPass ) { }
86 BOOL operator== ( const ScDPServiceDesc& rOther ) const
87 { return aServiceName == rOther.aServiceName &&
88 aParSource == rOther.aParSource &&
89 aParName == rOther.aParName &&
90 aParUser == rOther.aParUser &&
91 aParPass == rOther.aParPass; }
95 class SC_DLLPUBLIC ScDPObject : public ScDataObject
97 private:
98 ScDocument* pDoc;
99 // settings
100 ScDPSaveData* pSaveData;
101 String aTableName;
102 String aTableTag;
103 ScRange aOutRange;
104 ScSheetSourceDesc* pSheetDesc; // for sheet data
105 ScImportSourceDesc* pImpDesc; // for database data
106 ScDPServiceDesc* pServDesc; // for external service
107 ::boost::shared_ptr<ScDPTableData> mpTableData;
108 // cached data
109 com::sun::star::uno::Reference<com::sun::star::sheet::XDimensionsSupplier> xSource;
110 ScDPOutput* pOutput;
111 BOOL bSettingsChanged;
112 BOOL bAlive; // FALSE if only used to hold settings
113 USHORT nAutoFormatIndex;
114 BOOL bAllowMove;
115 BOOL bInfoValid; // affects: nHeaderRows
116 long nHeaderRows; // page fields plus filter button
117 bool bHeaderLayout; // TRUE : grid, FALSE : standard
120 SC_DLLPRIVATE ScDPTableData* GetTableData();
121 SC_DLLPRIVATE void CreateObjects();
122 SC_DLLPRIVATE void CreateOutput();
124 public:
125 ScDPObject( ScDocument* pD );
126 ScDPObject(const ScDPObject& r);
127 virtual ~ScDPObject();
129 virtual ScDataObject* Clone() const;
131 void SetAlive(BOOL bSet);
132 void SetAllowMove(BOOL bSet);
134 void InvalidateData();
135 void InvalidateSource();
137 void Output();
138 ScRange GetNewOutputRange( BOOL& rOverflow );
139 const ScRange GetOutputRangeByType( sal_Int32 nType );
141 void SetSaveData(const ScDPSaveData& rData);
142 ScDPSaveData* GetSaveData() const { return pSaveData; }
144 void SetOutRange(const ScRange& rRange);
145 const ScRange& GetOutRange() const { return aOutRange; }
147 void SetAutoFormatIndex (const USHORT nIndex);
148 USHORT GetAutoFormatIndex () { if (this == NULL) return 65535; else return nAutoFormatIndex; }
150 void SetHeaderLayout (bool bUseGrid);
151 bool GetHeaderLayout () const { return bHeaderLayout; }
153 void SetSheetDesc(const ScSheetSourceDesc& rDesc);
154 void SetImportDesc(const ScImportSourceDesc& rDesc);
155 void SetServiceData(const ScDPServiceDesc& rDesc);
157 void WriteSourceDataTo( ScDPObject& rDest ) const;
158 void WriteTempDataTo( ScDPObject& rDest ) const;
160 const ScSheetSourceDesc* GetSheetDesc() const { return pSheetDesc; }
161 const ScImportSourceDesc* GetImportSourceDesc() const { return pImpDesc; }
162 const ScDPServiceDesc* GetDPServiceDesc() const { return pServDesc; }
164 com::sun::star::uno::Reference<com::sun::star::sheet::XDimensionsSupplier> GetSource();
166 BOOL IsSheetData() const;
167 BOOL IsImportData() const { return(pImpDesc != NULL); }
168 BOOL IsServiceData() const { return(pServDesc != NULL); }
170 void SetName(const String& rNew);
171 const String& GetName() const { return aTableName; }
172 void SetTag(const String& rNew);
173 const String& GetTag() const { return aTableTag; }
175 /**
176 * Data description cell displays the description of a data dimension if
177 * and only if there is only one data dimension. It's usually located at
178 * the upper-left corner of the table output.
180 bool IsDataDescriptionCell(const ScAddress& rPos);
182 bool IsDimNameInUse(const ::rtl::OUString& rName) const;
183 String GetDimName( long nDim, BOOL& rIsDataLayout );
184 BOOL IsDuplicated( long nDim );
185 long GetDimCount();
186 void GetHeaderPositionData(const ScAddress& rPos, ::com::sun::star::sheet::DataPilotTableHeaderData& rData);
187 long GetHeaderDim( const ScAddress& rPos, USHORT& rOrient );
188 BOOL GetHeaderDrag( const ScAddress& rPos, BOOL bMouseLeft, BOOL bMouseTop,
189 long nDragDim,
190 Rectangle& rPosRect, USHORT& rOrient, long& rDimPos );
191 BOOL IsFilterButton( const ScAddress& rPos );
193 BOOL GetPivotData( ScDPGetPivotDataField& rTarget, /* returns result */
194 const std::vector< ScDPGetPivotDataField >& rFilters );
195 BOOL ParseFilters( ScDPGetPivotDataField& rTarget,
196 std::vector< ScDPGetPivotDataField >& rFilters,
197 const String& rFilterList );
199 void GetMemberResultNames( ScStrCollection& rNames, long nDimension );
201 void FillPageList( TypedScStrCollection& rStrings, long nField );
203 void ToggleDetails(const ::com::sun::star::sheet::DataPilotTableHeaderData& rElemDesc, ScDPObject* pDestObj);
205 BOOL FillOldParam(ScPivotParam& rParam, BOOL bForFile) const;
206 BOOL FillLabelData(ScPivotParam& rParam);
207 void InitFromOldPivot(const ScPivot& rOld, ScDocument* pDoc, BOOL bSetSource);
209 BOOL GetHierarchiesNA( sal_Int32 nDim, com::sun::star::uno::Reference< com::sun::star::container::XNameAccess >& xHiers );
210 BOOL GetHierarchies( sal_Int32 nDim, com::sun::star::uno::Sequence< rtl::OUString >& rHiers );
212 sal_Int32 GetUsedHierarchy( sal_Int32 nDim );
214 BOOL GetMembersNA( sal_Int32 nDim, com::sun::star::uno::Reference< com::sun::star::container::XNameAccess >& xMembers );
215 BOOL GetMembers( sal_Int32 nDim,
216 com::sun::star::uno::Sequence< rtl::OUString >& rMembers,
217 com::sun::star::uno::Sequence< sal_Bool >* pVisible = 0,
218 com::sun::star::uno::Sequence< sal_Bool >* pShowDet = 0 );
220 BOOL GetMembersNA( sal_Int32 nDim, sal_Int32 nHier, com::sun::star::uno::Reference< com::sun::star::container::XNameAccess >& xMembers );
221 BOOL GetMembers( sal_Int32 nDim, sal_Int32 nHier,
222 com::sun::star::uno::Sequence< rtl::OUString >& rMembers,
223 com::sun::star::uno::Sequence< sal_Bool >* pVisible = 0,
224 com::sun::star::uno::Sequence< sal_Bool >* pShowDet = 0 );
226 void UpdateReference( UpdateRefMode eUpdateRefMode,
227 const ScRange& r, SCsCOL nDx, SCsROW nDy, SCsTAB nDz );
228 BOOL RefsEqual( const ScDPObject& r ) const;
229 void WriteRefsTo( ScDPObject& r ) const;
231 void GetPositionData(const ScAddress& rPos, ::com::sun::star::sheet::DataPilotTablePositionData& rPosData);
233 bool GetDataFieldPositionData(const ScAddress& rPos,
234 ::com::sun::star::uno::Sequence<
235 ::com::sun::star::sheet::DataPilotFieldFilter >& rFilters);
237 void GetDrillDownData(const ScAddress& rPos,
238 ::com::sun::star::uno::Sequence<
239 ::com::sun::star::uno::Sequence<
240 ::com::sun::star::uno::Any > >& rTableData);
242 // apply drop-down attribute, initialize nHeaderRows, without accessing the source
243 // (button attribute must be present)
244 void RefreshAfterLoad();
246 void BuildAllDimensionMembers();
248 static BOOL HasRegisteredSources();
249 static com::sun::star::uno::Sequence<rtl::OUString> GetRegisteredSources();
250 static com::sun::star::uno::Reference<com::sun::star::sheet::XDimensionsSupplier>
251 CreateSource( const ScDPServiceDesc& rDesc );
253 static void ConvertOrientation( ScDPSaveData& rSaveData,
254 PivotField* pFields, SCSIZE nCount, USHORT nOrient,
255 ScDocument* pDoc, SCROW nRow, SCTAB nTab,
256 const com::sun::star::uno::Reference<
257 com::sun::star::sheet::XDimensionsSupplier>& xSource,
258 BOOL bOldDefaults,
259 PivotField* pRefColFields = NULL, SCSIZE nRefColCount = 0,
260 PivotField* pRefRowFields = NULL, SCSIZE nRefRowCount = 0,
261 PivotField* pRefPageFields = NULL, SCSIZE nRefPageCount = 0 );
264 // ============================================================================
266 struct ScDPCacheCell
268 sal_Int32 mnStrId;
269 sal_uInt8 mnType;
270 double mfValue;
271 bool mbNumeric;
273 ScDPCacheCell();
274 ScDPCacheCell(const ScDPCacheCell& r);
275 ~ScDPCacheCell();
278 // ============================================================================
280 class ScDPCollection : public ScCollection
282 private:
283 ScDocument* pDoc;
284 ScSimpleSharedString maSharedString;
286 struct CacheCellHash
288 size_t operator()(const ScDPCacheCell* pCell) const;
290 struct CacheCellEqual
292 bool operator()(const ScDPCacheCell* p1, const ScDPCacheCell* p2) const;
294 typedef ::std::hash_set<ScDPCacheCell*, CacheCellHash, CacheCellEqual> CacheCellPoolType;
296 CacheCellPoolType maCacheCellPool;
298 public:
299 ScDPCollection(ScDocument* pDocument);
300 ScDPCollection(const ScDPCollection& r);
301 virtual ~ScDPCollection();
303 virtual ScDataObject* Clone() const;
305 ScDPObject* operator[](USHORT nIndex) const {return (ScDPObject*)At(nIndex);}
306 #if OLD_PIVOT_IMPLEMENTATION
307 void ConvertOldTables( ScPivotCollection& rOldColl );
308 #endif
309 void DeleteOnTab( SCTAB nTab );
310 void UpdateReference( UpdateRefMode eUpdateRefMode,
311 const ScRange& r, SCsCOL nDx, SCsROW nDy, SCsTAB nDz );
313 BOOL RefsEqual( const ScDPCollection& r ) const;
314 void WriteRefsTo( ScDPCollection& r ) const;
316 String CreateNewName( USHORT nMin = 1 ) const;
318 ScSimpleSharedString& GetSharedString();
320 void FreeTable(ScDPObject* pDPObj);
321 SC_DLLPUBLIC bool InsertNewTable(ScDPObject* pDPObj);
323 bool HasDPTable(SCCOL nCol, SCROW nRow, SCTAB nTab) const;
325 ScDPCacheCell* getCacheCellFromPool(const ScDPCacheCell& rCell);
326 void clearCacheCellPool();
330 #endif