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"
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
;
52 namespace com
{ namespace sun
{ namespace star
{ namespace sheet
{
53 struct DataPilotFieldFilter
;
61 class ScPivotCollection
;
63 struct ScImportSourceDesc
;
64 struct ScSheetSourceDesc
;
65 class ScStrCollection
;
66 class TypedScStrCollection
;
71 struct ScDPServiceDesc
79 ScDPServiceDesc( const String
& rServ
, const String
& rSrc
, const String
& rNam
,
80 const String
& rUser
, const String
& rPass
) :
81 aServiceName( rServ
), aParSource( rSrc
), aParName( rNam
),
82 aParUser( rUser
), aParPass( rPass
) { }
84 BOOL
operator== ( const ScDPServiceDesc
& rOther
) const
85 { return aServiceName
== rOther
.aServiceName
&&
86 aParSource
== rOther
.aParSource
&&
87 aParName
== rOther
.aParName
&&
88 aParUser
== rOther
.aParUser
&&
89 aParPass
== rOther
.aParPass
; }
93 class SC_DLLPUBLIC ScDPObject
: public ScDataObject
98 ScDPSaveData
* pSaveData
;
102 ScSheetSourceDesc
* pSheetDesc
; // for sheet data
103 ScImportSourceDesc
* pImpDesc
; // for database data
104 ScDPServiceDesc
* pServDesc
; // for external service
105 ::boost::shared_ptr
<ScDPTableData
> mpTableData
;
107 com::sun::star::uno::Reference
<com::sun::star::sheet::XDimensionsSupplier
> xSource
;
109 BOOL bSettingsChanged
;
110 BOOL bAlive
; // FALSE if only used to hold settings
111 USHORT nAutoFormatIndex
;
113 long nHeaderRows
; // page fields plus filter button
114 bool bHeaderLayout
; // TRUE : grid, FALSE : standard
117 SC_DLLPRIVATE ScDPTableData
* GetTableData();
118 SC_DLLPRIVATE
void CreateObjects();
119 SC_DLLPRIVATE
void CreateOutput();
122 ScDPObject( ScDocument
* pD
);
123 ScDPObject(const ScDPObject
& r
);
124 virtual ~ScDPObject();
126 virtual ScDataObject
* Clone() const;
128 void SetAlive(BOOL bSet
);
129 void SetAllowMove(BOOL bSet
);
131 void InvalidateData();
132 void InvalidateSource();
135 void Output( const ScAddress
& rPos
);
136 ScRange
GetNewOutputRange( BOOL
& rOverflow
);
137 const ScRange
GetOutputRangeByType( sal_Int32 nType
);
139 void SetSaveData(const ScDPSaveData
& rData
);
140 ScDPSaveData
* GetSaveData() const { return pSaveData
; }
142 void SetOutRange(const ScRange
& rRange
);
143 const ScRange
& GetOutRange() const { return aOutRange
; }
145 void SetAutoFormatIndex (const USHORT nIndex
);
146 USHORT
GetAutoFormatIndex () { if (this == NULL
) return 65535; else return nAutoFormatIndex
; }
148 void SetHeaderLayout (bool bUseGrid
);
149 bool GetHeaderLayout () const { return bHeaderLayout
; }
151 void SetSheetDesc(const ScSheetSourceDesc
& rDesc
);
152 void SetImportDesc(const ScImportSourceDesc
& rDesc
);
153 void SetServiceData(const ScDPServiceDesc
& rDesc
);
155 void WriteSourceDataTo( ScDPObject
& rDest
) const;
156 void WriteTempDataTo( ScDPObject
& rDest
) const;
158 const ScSheetSourceDesc
* GetSheetDesc() const { return pSheetDesc
; }
159 const ScImportSourceDesc
* GetImportSourceDesc() const { return pImpDesc
; }
160 const ScDPServiceDesc
* GetDPServiceDesc() const { return pServDesc
; }
162 com::sun::star::uno::Reference
<com::sun::star::sheet::XDimensionsSupplier
> GetSource();
164 BOOL
IsSheetData() const;
165 BOOL
IsImportData() const { return(pImpDesc
!= NULL
); }
166 BOOL
IsServiceData() const { return(pServDesc
!= NULL
); }
168 void SetName(const String
& rNew
);
169 const String
& GetName() const { return aTableName
; }
170 void SetTag(const String
& rNew
);
171 const String
& GetTag() const { return aTableTag
; }
174 * Data description cell displays the description of a data dimension if
175 * and only if there is only one data dimension. It's usually located at
176 * the upper-left corner of the table output.
178 bool IsDataDescriptionCell(const ScAddress
& rPos
);
180 bool IsDimNameInUse(const ::rtl::OUString
& rName
) const;
181 String
GetDimName( long nDim
, BOOL
& rIsDataLayout
);
182 BOOL
IsDuplicated( long nDim
);
184 void GetHeaderPositionData(const ScAddress
& rPos
, ::com::sun::star::sheet::DataPilotTableHeaderData
& rData
);
185 long GetHeaderDim( const ScAddress
& rPos
, USHORT
& rOrient
);
186 BOOL
GetHeaderDrag( const ScAddress
& rPos
, BOOL bMouseLeft
, BOOL bMouseTop
,
188 Rectangle
& rPosRect
, USHORT
& rOrient
, long& rDimPos
);
189 BOOL
IsFilterButton( const ScAddress
& rPos
);
191 BOOL
GetPivotData( ScDPGetPivotDataField
& rTarget
, /* returns result */
192 const std::vector
< ScDPGetPivotDataField
>& rFilters
);
193 BOOL
ParseFilters( ScDPGetPivotDataField
& rTarget
,
194 std::vector
< ScDPGetPivotDataField
>& rFilters
,
195 const String
& rFilterList
);
197 void GetMemberResultNames( ScStrCollection
& rNames
, long nDimension
);
199 void FillPageList( TypedScStrCollection
& rStrings
, long nField
);
201 void ToggleDetails(const ::com::sun::star::sheet::DataPilotTableHeaderData
& rElemDesc
, ScDPObject
* pDestObj
);
203 BOOL
FillOldParam(ScPivotParam
& rParam
, BOOL bForFile
) const;
204 BOOL
FillLabelData(ScPivotParam
& rParam
);
205 void InitFromOldPivot(const ScPivot
& rOld
, ScDocument
* pDoc
, BOOL bSetSource
);
207 BOOL
GetHierarchiesNA( sal_Int32 nDim
, com::sun::star::uno::Reference
< com::sun::star::container::XNameAccess
>& xHiers
);
208 BOOL
GetHierarchies( sal_Int32 nDim
, com::sun::star::uno::Sequence
< rtl::OUString
>& rHiers
);
210 sal_Int32
GetUsedHierarchy( sal_Int32 nDim
);
212 BOOL
GetMembersNA( sal_Int32 nDim
, com::sun::star::uno::Reference
< com::sun::star::container::XNameAccess
>& xMembers
);
213 BOOL
GetMembers( sal_Int32 nDim
,
214 com::sun::star::uno::Sequence
< rtl::OUString
>& rMembers
,
215 com::sun::star::uno::Sequence
< sal_Bool
>* pVisible
= 0,
216 com::sun::star::uno::Sequence
< sal_Bool
>* pShowDet
= 0 );
218 BOOL
GetMembersNA( sal_Int32 nDim
, sal_Int32 nHier
, com::sun::star::uno::Reference
< com::sun::star::container::XNameAccess
>& xMembers
);
219 BOOL
GetMembers( sal_Int32 nDim
, sal_Int32 nHier
,
220 com::sun::star::uno::Sequence
< rtl::OUString
>& rMembers
,
221 com::sun::star::uno::Sequence
< sal_Bool
>* pVisible
= 0,
222 com::sun::star::uno::Sequence
< sal_Bool
>* pShowDet
= 0 );
224 void UpdateReference( UpdateRefMode eUpdateRefMode
,
225 const ScRange
& r
, SCsCOL nDx
, SCsROW nDy
, SCsTAB nDz
);
226 BOOL
RefsEqual( const ScDPObject
& r
) const;
227 void WriteRefsTo( ScDPObject
& r
) const;
229 void GetPositionData(const ScAddress
& rPos
, ::com::sun::star::sheet::DataPilotTablePositionData
& rPosData
);
231 bool GetDataFieldPositionData(const ScAddress
& rPos
,
232 ::com::sun::star::uno::Sequence
<
233 ::com::sun::star::sheet::DataPilotFieldFilter
>& rFilters
);
235 void GetDrillDownData(const ScAddress
& rPos
,
236 ::com::sun::star::uno::Sequence
<
237 ::com::sun::star::uno::Sequence
<
238 ::com::sun::star::uno::Any
> >& rTableData
);
240 // apply drop-down attribute, initialize nHeaderRows, without accessing the source
241 // (button attribute must be present)
242 void RefreshAfterLoad();
244 void BuildAllDimensionMembers();
246 static BOOL
HasRegisteredSources();
247 static com::sun::star::uno::Sequence
<rtl::OUString
> GetRegisteredSources();
248 static com::sun::star::uno::Reference
<com::sun::star::sheet::XDimensionsSupplier
>
249 CreateSource( const ScDPServiceDesc
& rDesc
);
251 static void ConvertOrientation( ScDPSaveData
& rSaveData
,
252 PivotField
* pFields
, SCSIZE nCount
, USHORT nOrient
,
253 ScDocument
* pDoc
, SCROW nRow
, SCTAB nTab
,
254 const com::sun::star::uno::Reference
<
255 com::sun::star::sheet::XDimensionsSupplier
>& xSource
,
257 PivotField
* pRefColFields
= NULL
, SCSIZE nRefColCount
= 0,
258 PivotField
* pRefRowFields
= NULL
, SCSIZE nRefRowCount
= 0,
259 PivotField
* pRefPageFields
= NULL
, SCSIZE nRefPageCount
= 0 );
262 // ============================================================================
272 ScDPCacheCell(const ScDPCacheCell
& r
);
276 // ============================================================================
278 class ScDPCollection
: public ScCollection
282 ScSimpleSharedString maSharedString
;
286 size_t operator()(const ScDPCacheCell
* pCell
) const;
288 struct CacheCellEqual
290 bool operator()(const ScDPCacheCell
* p1
, const ScDPCacheCell
* p2
) const;
292 typedef ::std::hash_set
<ScDPCacheCell
*, CacheCellHash
, CacheCellEqual
> CacheCellPoolType
;
294 CacheCellPoolType maCacheCellPool
;
297 ScDPCollection(ScDocument
* pDocument
);
298 ScDPCollection(const ScDPCollection
& r
);
299 virtual ~ScDPCollection();
301 virtual ScDataObject
* Clone() const;
303 ScDPObject
* operator[](USHORT nIndex
) const {return (ScDPObject
*)At(nIndex
);}
305 void DeleteOnTab( SCTAB nTab
);
306 void UpdateReference( UpdateRefMode eUpdateRefMode
,
307 const ScRange
& r
, SCsCOL nDx
, SCsROW nDy
, SCsTAB nDz
);
309 BOOL
RefsEqual( const ScDPCollection
& r
) const;
310 void WriteRefsTo( ScDPCollection
& r
) const;
312 String
CreateNewName( USHORT nMin
= 1 ) const;
314 ScSimpleSharedString
& GetSharedString();
316 ScDPCacheCell
* getCacheCellFromPool(const ScDPCacheCell
& rCell
);
317 void clearCacheCellPool();