sync master with lastest vba changes
[ooovba.git] / sc / inc / pivot.hxx
blobc548f048c5bfd0ee29479d485b145d75e75bfd93
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: pivot.hxx,v $
10 * $Revision: 1.8.32.3 $
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 WICHTIG:
32 Folgende Reihenfolge beim Aufbau der Pivot-Tabelle unbedingt einzuhalten:
34 pPivot->SetColFields(aColArr, aColCount)
35 pPivot->SetRowFields(aRowArr, aRowCount)
36 pPivot->SetDataFields(aDataArr, aDataCount)
37 if (pPivot->CreateData())
39 pPivotDrawData();
40 pPivotReleaseData();
43 ausserdem ist sicherzustellen, dass entweder das ColArr oder das RowArr
44 einen PivotDataField Eintrag enthalten
49 #ifndef SC_PIVOT_HXX
50 #define SC_PIVOT_HXX
52 #include "global.hxx"
53 #include "address.hxx"
55 #include <vector>
56 #include <boost/shared_ptr.hpp>
58 class SubTotal;
59 #include "collect.hxx"
61 #define PIVOT_DATA_FIELD (MAXCOLCOUNT)
62 #define PIVOT_FUNC_REF (MAXCOLCOUNT)
63 #include <com/sun/star/uno/Sequence.hxx>
64 #include <com/sun/star/sheet/DataPilotFieldReference.hpp>
65 #include <com/sun/star/sheet/DataPilotFieldSortInfo.hpp>
66 #include <com/sun/star/sheet/DataPilotFieldLayoutInfo.hpp>
67 #include <com/sun/star/sheet/DataPilotFieldAutoShowInfo.hpp>
69 #if OLD_PIVOT_IMPLEMENTATION
70 #define PIVOT_STYLE_INNER 0
71 #define PIVOT_STYLE_RESULT 1
72 #define PIVOT_STYLE_CATEGORY 2
73 #define PIVOT_STYLE_TITLE 3
74 #define PIVOT_STYLE_FIELDNAME 4
75 #define PIVOT_STYLE_TOP 5
76 #endif
78 class SvStream;
79 class ScDocument;
80 class ScUserListData;
81 class ScMultipleReadHeader;
82 class ScMultipleWriteHeader;
83 class ScProgress;
84 struct ScDPLabelData;
86 typedef ::boost::shared_ptr<ScDPLabelData> ScDPLabelDataRef;
88 // -----------------------------------------------------------------------
90 struct PivotField
92 SCsCOL nCol;
93 USHORT nFuncMask;
94 USHORT nFuncCount;
95 ::com::sun::star::sheet::DataPilotFieldReference maFieldRef;
97 explicit PivotField( SCsCOL nNewCol = 0, USHORT nNewFuncMask = PIVOT_FUNC_NONE );
99 bool operator==( const PivotField& r ) const;
102 // -----------------------------------------------------------------------
104 // implementation still in global2.cxx
105 struct ScPivotParam
107 SCCOL nCol; // Cursor Position /
108 SCROW nRow; // bzw. Anfang des Zielbereiches
109 SCTAB nTab;
110 ::std::vector<ScDPLabelDataRef> maLabelArray;
111 PivotField aPageArr[PIVOT_MAXPAGEFIELD];
112 PivotField aColArr[PIVOT_MAXFIELD];
113 PivotField aRowArr[PIVOT_MAXFIELD];
114 PivotField aDataArr[PIVOT_MAXFIELD];
115 SCSIZE nPageCount;
116 SCSIZE nColCount;
117 SCSIZE nRowCount;
118 SCSIZE nDataCount;
119 BOOL bIgnoreEmptyRows;
120 BOOL bDetectCategories;
121 BOOL bMakeTotalCol;
122 BOOL bMakeTotalRow;
124 ScPivotParam();
125 ScPivotParam( const ScPivotParam& r );
126 ~ScPivotParam();
128 ScPivotParam& operator= ( const ScPivotParam& r );
129 BOOL operator== ( const ScPivotParam& r ) const;
130 void Clear ();
131 void ClearPivotArrays();
132 void SetLabelData (const ::std::vector<ScDPLabelDataRef>& r);
133 void SetPivotArrays ( const PivotField* pPageArr,
134 const PivotField* pColArr,
135 const PivotField* pRowArr,
136 const PivotField* pDataArr,
137 SCSIZE nPageCnt,
138 SCSIZE nColCnt,
139 SCSIZE nRowCnt,
140 SCSIZE nDataCnt );
143 // -----------------------------------------------------------------------
145 #if OLD_PIVOT_IMPLEMENTATION
146 struct PivotColRef
148 SCSIZE nDataIndex;
149 SCSIZE nRecCount;
150 USHORT nFuncMask;
151 SCSIZE nIndex;
153 PivotColRef()
155 nDataIndex = nRecCount = nIndex = 0;
156 nFuncMask = PIVOT_FUNC_NONE;
159 #endif
161 typedef PivotField PivotFieldArr[PIVOT_MAXFIELD];
162 typedef PivotField PivotPageFieldArr[PIVOT_MAXPAGEFIELD];
164 #if OLD_PIVOT_IMPLEMENTATION
165 class PivotScStrCollection : public ScStrCollection
167 ScUserListData* pUserData;
168 public:
169 PivotScStrCollection(USHORT nLim = 4, USHORT nDel = 4, BOOL bDup = FALSE) :
170 ScStrCollection ( nLim, nDel, bDup ),
171 pUserData (NULL) { }
172 PivotScStrCollection(const PivotScStrCollection& rPivotScStrCollection) :
173 ScStrCollection ( rPivotScStrCollection ),
174 pUserData ( rPivotScStrCollection.pUserData) {}
176 virtual ScDataObject* Clone() const;
177 virtual short Compare(ScDataObject* pKey1, ScDataObject* pKey2) const;
179 TypedStrData* operator[]( const USHORT nIndex) const
180 { return (TypedStrData*)At(nIndex); }
181 void SetUserData(ScUserListData* pData)
182 { pUserData = pData; }
183 const String& GetString(USHORT nIndex)
184 { return ((TypedStrData*)At(nIndex))->GetString(); }
185 USHORT GetIndex(TypedStrData* pData) const;
188 class ScPivot : public ScDataObject
190 ScDocument* pDoc;
191 ScQueryParam aQuery;
192 BOOL bHasHeader;
194 BOOL bIgnoreEmpty; // Flags aus Dialog
195 BOOL bDetectCat;
196 BOOL bMakeTotalCol;
197 BOOL bMakeTotalRow;
199 String aName;
200 String aTag;
201 SCSIZE nColNameCount;
202 String* pColNames; // Array
204 SCCOL nSrcCol1;
205 SCROW nSrcRow1;
206 SCCOL nSrcCol2;
207 SCROW nSrcRow2;
208 SCTAB nSrcTab;
210 SCCOL nDestCol1;
211 SCROW nDestRow1;
212 SCCOL nDestCol2;
213 SCROW nDestRow2;
214 SCTAB nDestTab;
216 SCCOL nDataStartCol;
217 SCROW nDataStartRow;
219 SCSIZE nColCount;
220 SCSIZE nRowCount;
221 SCSIZE nDataCount;
223 PivotFieldArr aColArr;
224 PivotFieldArr aRowArr;
225 PivotFieldArr aDataArr;
227 PivotScStrCollection* pColList[PIVOT_MAXFIELD]; // pro Zeile alle Eintraege
228 PivotScStrCollection* pRowList[PIVOT_MAXFIELD];
229 PivotScStrCollection* pDataList; // Shortcut auf Col/RowList mit Daten
231 SubTotal** ppDataArr;
232 SCSIZE nDataColCount;
233 SCSIZE nDataRowCount;
234 SCSIZE nRowIndex;
235 SCSIZE nColIndex;
236 SCSIZE nDataIndex;
237 SCSIZE nRecCount;
239 PivotColRef* pColRef;
241 BOOL bValidArea;
242 BOOL bDataAtCol;
244 public:
245 ScPivot(ScDocument* pDocument);
246 ScPivot(const ScPivot& rPivot);
247 ~ScPivot();
249 virtual ScDataObject* Clone() const;
251 ScPivot* CreateNew() const;
253 BOOL Load(SvStream& rStream, ScMultipleReadHeader& rHdr );
254 BOOL Store(SvStream& rStream, ScMultipleWriteHeader& rHdr ) const;
256 void SetQuery(const ScQueryParam& rQuery);
257 void GetQuery(ScQueryParam& rQuery) const;
259 void SetHeader(BOOL bHeader);
260 BOOL GetHeader() const;
261 void SetIgnoreEmpty(BOOL bIgnore);
262 BOOL GetIgnoreEmpty() const;
263 void SetDetectCat(BOOL bDetect);
264 BOOL GetDetectCat() const;
265 void SetMakeTotalCol(BOOL bSet);
266 BOOL GetMakeTotalCol() const;
267 void SetMakeTotalRow(BOOL bSet);
268 BOOL GetMakeTotalRow() const;
270 void SetName(const String& rNew);
271 const String& GetName() const;
272 void SetTag(const String& rNew);
273 const String& GetTag() const;
275 void SetSrcArea(SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2, SCTAB nTab);
276 void GetSrcArea(SCCOL& rCol1, SCROW& rRow1, SCCOL& rCol2, SCROW& rRow2, SCTAB& rTab) const;
277 ScRange GetSrcArea() const;
279 void SetDestPos(SCCOL nCol, SCROW nRow, SCTAB nTab);
280 void GetDestArea(SCCOL& rCol1, SCROW& rRow1, SCCOL& rCol2, SCROW& rRow2, SCTAB& rTab) const;
281 ScRange GetDestArea() const;
283 void SetColFields(const PivotField* pFieldArr, SCSIZE nCount);
284 void GetColFields(PivotField* pFieldArr, SCSIZE& rCount) const;
285 SCSIZE GetColFieldCount() const { return nColCount; }
287 void SetRowFields(const PivotField* pFieldArr, SCSIZE nCount);
288 void GetRowFields(PivotField* pFieldArr, SCSIZE& rCount) const;
289 SCSIZE GetRowFieldCount() const { return nRowCount; }
291 void SetDataFields(const PivotField* pFieldArr, SCSIZE nCount);
292 void GetDataFields(PivotField* pFieldArr, SCSIZE& rCount) const;
294 void GetParam( ScPivotParam& rParam, ScQueryParam& rQuery, ScArea& rSrcArea ) const;
295 void SetParam( const ScPivotParam& rParam, const ScQueryParam& rQuery,
296 const ScArea& rSrcArea );
298 BOOL CreateData(BOOL bKeepDest = FALSE);
299 void DrawData();
300 void ReleaseData();
302 BOOL IsPivotAtCursor(SCCOL nCol, SCROW nRow, SCTAB nTab) const;
303 BOOL IsFilterAtCursor(SCCOL nCol, SCROW nRow, SCTAB nTab) const;
304 BOOL GetColFieldAtCursor(SCCOL nCol, SCROW nRow, SCTAB nTab, SCCOL& rField) const;
305 BOOL GetRowFieldAtCursor(SCCOL nCol, SCROW nRow, SCTAB nTab, SCCOL& rField) const;
307 // Referenz-Anpassung:
309 void MoveSrcArea( SCCOL nNewCol, SCROW nNewRow, SCTAB nNewTab );
310 void MoveDestArea( SCCOL nNewCol, SCROW nNewRow, SCTAB nNewTab );
311 void ExtendSrcArea( SCCOL nNewEndCol, SCROW nNewEndRow );
313 private:
314 BOOL CreateFields();
315 void CreateFieldData();
316 void CalcArea();
318 void SetDataLine(SCCOL nCol, SCROW nRow, SCTAB nTab, SCSIZE nRIndex);
319 void SetFuncLine(SCCOL nCol, SCROW nRow, SCTAB nTab, USHORT nFunc, SCSIZE nIndex, SCSIZE nStartRIndex, SCSIZE nEndRIndex);
320 void ColToTable(SCSIZE nField, SCROW& nRow, ScProgress& rProgress);
321 void RowToTable(SCSIZE nField, SCCOL& nCol);
322 void SetFrame(SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2, USHORT nWidth = 20);
323 void SetFrameHor(SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2);
324 void SetFrameVer(SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2);
325 void SetFontBold(SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2);
326 void SetJustifyLeft(SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2);
327 void SetJustifyRight(SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2);
328 void SetStyle(SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2, USHORT nId);
329 void SetButton(SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2);
330 void SetValue(SCCOL nCol, SCROW nRow, const SubTotal& rTotal, USHORT nFunc);
331 SCROW GetCategoryRow( SCCOL nCol, SCROW nRow );
334 //------------------------------------------------------------------------
335 class ScPivotCollection : public ScCollection
338 private:
339 ScDocument* pDoc;
340 public:
341 ScPivotCollection(USHORT nLim = 4, USHORT nDel = 4, ScDocument* pDocument = NULL) :
342 ScCollection ( nLim, nDel),
343 pDoc ( pDocument ) {}
344 ScPivotCollection(const ScPivotCollection& rScPivotCollection) :
345 ScCollection ( rScPivotCollection ),
346 pDoc ( rScPivotCollection.pDoc ) {}
348 virtual ScDataObject* Clone() const;
349 ScPivot* operator[]( const USHORT nIndex) const {return (ScPivot*)At(nIndex);}
350 ScPivot* GetPivotAtCursor(SCCOL nCol, SCROW nRow, SCTAB nTab) const;
352 BOOL Load( SvStream& rStream );
353 BOOL Store( SvStream& rStream ) const;
355 void UpdateReference(UpdateRefMode eUpdateRefMode,
356 SCCOL nCol1, SCROW nRow1, SCTAB nTab1,
357 SCCOL nCol2, SCROW nRow2, SCTAB nTab2,
358 SCsCOL nDx, SCsROW nDy, SCsTAB nDz );
359 void UpdateGrow( const ScRange& rArea, SCCOL nGrowX, SCROW nGrowY );
361 BOOL operator==(const ScPivotCollection& rCmp) const;
363 String CreateNewName( USHORT nMin = 1 ) const;
365 #endif
367 //------------------------------------------------------------------------
369 struct ScDPLabelData
371 String maName; /// Visible name of the dimension.
372 SCsCOL mnCol;
373 USHORT mnFuncMask; /// Page/Column/Row subtotal function.
374 sal_Int32 mnUsedHier; /// Used hierarchy.
375 bool mbShowAll; /// true = Show all (also empty) results.
376 bool mbIsValue; /// true = Sum or count in data field.
378 ::com::sun::star::uno::Sequence< ::rtl::OUString > maHiers; /// Hierarchies.
379 ::com::sun::star::uno::Sequence< ::rtl::OUString > maMembers; /// Members.
380 ::com::sun::star::uno::Sequence< sal_Bool > maVisible; /// Visibility of members.
381 ::com::sun::star::uno::Sequence< sal_Bool > maShowDet; /// Show details of members.
382 ::com::sun::star::sheet::DataPilotFieldSortInfo maSortInfo; /// Sorting info.
383 ::com::sun::star::sheet::DataPilotFieldLayoutInfo maLayoutInfo; /// Layout info.
384 ::com::sun::star::sheet::DataPilotFieldAutoShowInfo maShowInfo; /// AutoShow info.
386 explicit ScDPLabelData( const String& rName, short nCol, bool bIsValue );
389 // ============================================================================
391 struct ScDPFuncData
393 short mnCol;
394 USHORT mnFuncMask;
395 ::com::sun::star::sheet::DataPilotFieldReference maFieldRef;
397 explicit ScDPFuncData( short nNewCol, USHORT nNewFuncMask );
398 explicit ScDPFuncData( short nNewCol, USHORT nNewFuncMask,
399 const ::com::sun::star::sheet::DataPilotFieldReference& rFieldRef );
402 // ============================================================================
404 typedef std::vector< ScDPLabelData > ScDPLabelDataVec;
405 typedef std::vector< String > ScDPNameVec;
407 // ============================================================================
409 #endif