1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: dpobject.hxx,v $
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
36 #include "address.hxx"
37 #include "collect.hxx"
38 #include "dpoutput.hxx"
40 #include <com/sun/star/sheet/XDimensionsSupplier.hpp>
42 #include <boost/shared_ptr.hpp>
44 //------------------------------------------------------------------
46 namespace com
{ namespace sun
{ namespace star
{ namespace sheet
{
48 struct DataPilotTablePositionData
;
49 struct DataPilotTableHeaderData
;
53 namespace com
{ namespace sun
{ namespace star
{ namespace sheet
{
54 struct DataPilotFieldFilter
;
62 class ScPivotCollection
;
64 struct ScImportSourceDesc
;
65 struct ScSheetSourceDesc
;
66 class ScStrCollection
;
67 class TypedScStrCollection
;
72 struct ScDPServiceDesc
80 ScDPServiceDesc( const String
& rServ
, const String
& rSrc
, const String
& rNam
,
81 const String
& rUser
, const String
& rPass
) :
82 aServiceName( rServ
), aParSource( rSrc
), aParName( rNam
),
83 aParUser( rUser
), aParPass( rPass
) { }
85 BOOL
operator== ( const ScDPServiceDesc
& rOther
) const
86 { return aServiceName
== rOther
.aServiceName
&&
87 aParSource
== rOther
.aParSource
&&
88 aParName
== rOther
.aParName
&&
89 aParUser
== rOther
.aParUser
&&
90 aParPass
== rOther
.aParPass
; }
94 class SC_DLLPUBLIC ScDPObject
: public ScDataObject
99 ScDPSaveData
* pSaveData
;
103 ScSheetSourceDesc
* pSheetDesc
; // for sheet data
104 ScImportSourceDesc
* pImpDesc
; // for database data
105 ScDPServiceDesc
* pServDesc
; // for external service
106 ::boost::shared_ptr
<ScDPTableData
> mpTableData
;
108 com::sun::star::uno::Reference
<com::sun::star::sheet::XDimensionsSupplier
> xSource
;
110 BOOL bSettingsChanged
;
111 BOOL bAlive
; // FALSE if only used to hold settings
112 sal_uInt16 mnAutoFormatIndex
;
114 long nHeaderRows
; // page fields plus filter button
115 bool mbHeaderLayout
; // TRUE : grid, FALSE : standard
118 SC_DLLPRIVATE ScDPTableData
* GetTableData();
119 SC_DLLPRIVATE
void CreateObjects();
120 SC_DLLPRIVATE
void CreateOutput();
123 ScDPObject( ScDocument
* pD
);
124 ScDPObject(const ScDPObject
& r
);
125 virtual ~ScDPObject();
127 virtual ScDataObject
* Clone() const;
129 void SetAlive(BOOL bSet
);
130 void SetAllowMove(BOOL bSet
);
132 void InvalidateData();
133 void InvalidateSource();
136 void Output( const ScAddress
& rPos
);
137 ScRange
GetNewOutputRange( BOOL
& rOverflow
);
138 const ScRange
GetOutputRangeByType( sal_Int32 nType
);
140 void SetSaveData(const ScDPSaveData
& rData
);
141 ScDPSaveData
* GetSaveData() const { return pSaveData
; }
143 void SetOutRange(const ScRange
& rRange
);
144 const ScRange
& GetOutRange() const { return aOutRange
; }
146 void SetAutoFormatIndex (const sal_uInt16 nIndex
);
147 sal_uInt16
GetAutoFormatIndex() const;
149 void SetHeaderLayout(bool bUseGrid
);
150 bool GetHeaderLayout() const;
152 void SetSheetDesc(const ScSheetSourceDesc
& rDesc
);
153 void SetImportDesc(const ScImportSourceDesc
& rDesc
);
154 void SetServiceData(const ScDPServiceDesc
& rDesc
);
156 void WriteSourceDataTo( ScDPObject
& rDest
) const;
157 void WriteTempDataTo( ScDPObject
& rDest
) const;
159 const ScSheetSourceDesc
* GetSheetDesc() const { return pSheetDesc
; }
160 const ScImportSourceDesc
* GetImportSourceDesc() const { return pImpDesc
; }
161 const ScDPServiceDesc
* GetDPServiceDesc() const { return pServDesc
; }
163 com::sun::star::uno::Reference
<com::sun::star::sheet::XDimensionsSupplier
> GetSource();
165 BOOL
IsSheetData() const;
166 BOOL
IsImportData() const { return(pImpDesc
!= NULL
); }
167 BOOL
IsServiceData() const { return(pServDesc
!= NULL
); }
169 void SetName(const String
& rNew
);
170 const String
& GetName() const { return aTableName
; }
171 void SetTag(const String
& rNew
);
172 const String
& GetTag() const { return aTableTag
; }
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.
179 bool IsDataDescriptionCell(const ScAddress
& rPos
);
181 bool IsDimNameInUse(const ::rtl::OUString
& rName
) const;
182 String
GetDimName( long nDim
, BOOL
& rIsDataLayout
);
183 BOOL
IsDuplicated( long nDim
);
185 void GetHeaderPositionData(const ScAddress
& rPos
, ::com::sun::star::sheet::DataPilotTableHeaderData
& rData
);
186 long GetHeaderDim( const ScAddress
& rPos
, USHORT
& rOrient
);
187 BOOL
GetHeaderDrag( const ScAddress
& rPos
, BOOL bMouseLeft
, BOOL bMouseTop
,
189 Rectangle
& rPosRect
, USHORT
& rOrient
, long& rDimPos
);
190 BOOL
IsFilterButton( const ScAddress
& rPos
);
192 BOOL
GetPivotData( ScDPGetPivotDataField
& rTarget
, /* returns result */
193 const std::vector
< ScDPGetPivotDataField
>& rFilters
);
194 BOOL
ParseFilters( ScDPGetPivotDataField
& rTarget
,
195 std::vector
< ScDPGetPivotDataField
>& rFilters
,
196 const String
& rFilterList
);
198 void GetMemberResultNames( ScStrCollection
& rNames
, long nDimension
);
200 void FillPageList( TypedScStrCollection
& rStrings
, long nField
);
202 void ToggleDetails(const ::com::sun::star::sheet::DataPilotTableHeaderData
& rElemDesc
, ScDPObject
* pDestObj
);
204 BOOL
FillOldParam(ScPivotParam
& rParam
, BOOL bForFile
) const;
205 BOOL
FillLabelData(ScPivotParam
& rParam
);
206 void InitFromOldPivot(const ScPivot
& rOld
, ScDocument
* pDoc
, BOOL bSetSource
);
208 BOOL
GetHierarchiesNA( sal_Int32 nDim
, com::sun::star::uno::Reference
< com::sun::star::container::XNameAccess
>& xHiers
);
209 BOOL
GetHierarchies( sal_Int32 nDim
, com::sun::star::uno::Sequence
< rtl::OUString
>& rHiers
);
211 sal_Int32
GetUsedHierarchy( sal_Int32 nDim
);
213 BOOL
GetMembersNA( sal_Int32 nDim
, com::sun::star::uno::Reference
< com::sun::star::container::XNameAccess
>& xMembers
);
214 BOOL
GetMembersNA( sal_Int32 nDim
, sal_Int32 nHier
, com::sun::star::uno::Reference
< com::sun::star::container::XNameAccess
>& xMembers
);
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
);
219 void UpdateReference( UpdateRefMode eUpdateRefMode
,
220 const ScRange
& r
, SCsCOL nDx
, SCsROW nDy
, SCsTAB nDz
);
221 BOOL
RefsEqual( const ScDPObject
& r
) const;
222 void WriteRefsTo( ScDPObject
& r
) const;
224 void GetPositionData(const ScAddress
& rPos
, ::com::sun::star::sheet::DataPilotTablePositionData
& rPosData
);
226 bool GetDataFieldPositionData(const ScAddress
& rPos
,
227 ::com::sun::star::uno::Sequence
<
228 ::com::sun::star::sheet::DataPilotFieldFilter
>& rFilters
);
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
);
235 // apply drop-down attribute, initialize nHeaderRows, without accessing the source
236 // (button attribute must be present)
237 void RefreshAfterLoad();
239 void BuildAllDimensionMembers();
241 static 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
);
246 static void ConvertOrientation( ScDPSaveData
& rSaveData
,
247 PivotField
* pFields
, SCSIZE nCount
, USHORT nOrient
,
248 ScDocument
* pDoc
, SCROW nRow
, SCTAB nTab
,
249 const com::sun::star::uno::Reference
<
250 com::sun::star::sheet::XDimensionsSupplier
>& xSource
,
252 PivotField
* pRefColFields
= NULL
, SCSIZE nRefColCount
= 0,
253 PivotField
* pRefRowFields
= NULL
, SCSIZE nRefRowCount
= 0,
254 PivotField
* pRefPageFields
= NULL
, SCSIZE nRefPageCount
= 0 );
257 // ============================================================================
267 ScDPCacheCell(const ScDPCacheCell
& r
);
271 // ============================================================================
273 class ScDPCollection
: public ScCollection
277 ScSimpleSharedString maSharedString
;
281 size_t operator()(const ScDPCacheCell
* pCell
) const;
283 struct CacheCellEqual
285 bool operator()(const ScDPCacheCell
* p1
, const ScDPCacheCell
* p2
) const;
287 typedef ::std::hash_set
<ScDPCacheCell
*, CacheCellHash
, CacheCellEqual
> CacheCellPoolType
;
289 CacheCellPoolType maCacheCellPool
;
292 ScDPCollection(ScDocument
* pDocument
);
293 ScDPCollection(const ScDPCollection
& r
);
294 virtual ~ScDPCollection();
296 virtual ScDataObject
* Clone() const;
298 ScDPObject
* operator[](USHORT nIndex
) const {return (ScDPObject
*)At(nIndex
);}
300 void DeleteOnTab( SCTAB nTab
);
301 void UpdateReference( UpdateRefMode eUpdateRefMode
,
302 const ScRange
& r
, SCsCOL nDx
, SCsROW nDy
, SCsTAB nDz
);
304 BOOL
RefsEqual( const ScDPCollection
& r
) const;
305 void WriteRefsTo( ScDPCollection
& r
) const;
307 String
CreateNewName( USHORT nMin
= 1 ) const;
309 ScSimpleSharedString
& GetSharedString();
311 void FreeTable(ScDPObject
* pDPObj
);
312 SC_DLLPUBLIC
bool InsertNewTable(ScDPObject
* pDPObj
);
314 bool HasDPTable(SCCOL nCol
, SCROW nRow
, SCTAB nTab
) const;
316 ScDPCacheCell
* getCacheCellFromPool(const ScDPCacheCell
& rCell
);
317 void clearCacheCellPool();