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