Update ooo320-m1
[ooovba.git] / binfilter / inc / bf_sc / pivot.hxx
blob4a187b8e71e32a17481ea9ddbdc123d0c56761e4
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.5 $
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 ************************************************************************/
32 WICHTIG:
33 Folgende Reihenfolge beim Aufbau der Pivot-Tabelle unbedingt einzuhalten:
35 pPivot->SetColFields(aColArr, aColCount)
36 pPivot->SetRowFields(aRowArr, aRowCount)
37 pPivot->SetDataFields(aDataArr, aDataCount)
38 if (pPivot->CreateData())
40 pPivotDrawData();
41 pPivotReleaseData();
44 ausserdem ist sicherzustellen, dass entweder das ColArr oder das RowArr
45 einen PivotDataField Eintrag enthalten
50 #ifndef SC_PIVOT_HXX
51 #define SC_PIVOT_HXX
53 #include <global.hxx>
55 //STRIP008 class SubTotal;
57 #ifndef SC_COLLECT_HXX
58 #include "collect.hxx"
59 #endif
61 #define PIVOT_DATA_FIELD (MAXCOL + 1)
62 #define PIVOT_FUNC_REF (MAXCOL + 1)
64 #define PIVOT_STYLE_INNER 0
65 #define PIVOT_STYLE_RESULT 1
66 #define PIVOT_STYLE_CATEGORY 2
67 #define PIVOT_STYLE_TITLE 3
68 #define PIVOT_STYLE_FIELDNAME 4
69 #define PIVOT_STYLE_TOP 5
70 class SvStream;
71 namespace binfilter {
72 class SubTotal;
73 class ScDocument;
74 class ScUserListData;
75 class ScMultipleReadHeader;
76 class ScMultipleWriteHeader;
77 class ScProgress;
79 struct PivotColRef
81 USHORT nDataIndex;
82 USHORT nRecCount;
83 USHORT nFuncMask;
84 USHORT nIndex;
86 PivotColRef()
88 nDataIndex = nRecCount = nIndex = 0;
89 nFuncMask = PIVOT_FUNC_NONE;
93 typedef PivotField PivotFieldArr[PIVOT_MAXFIELD];
95 class PivotStrCollection : public StrCollection
97 ScUserListData* pUserData;
98 public:
99 PivotStrCollection(USHORT nLim = 4, USHORT nDel = 4, BOOL bDup = FALSE) :
100 StrCollection ( nLim, nDel, bDup ),
101 pUserData (NULL) { }
102 PivotStrCollection(const PivotStrCollection& rPivotStrCollection) :
103 StrCollection ( rPivotStrCollection ),
104 pUserData ( rPivotStrCollection.pUserData) {}
106 virtual short Compare(DataObject* pKey1, DataObject* pKey2) const;
108 TypedStrData* operator[]( const USHORT nIndex) const
109 { return (TypedStrData*)At(nIndex); }
110 void SetUserData(ScUserListData* pData)
111 { pUserData = pData; }
112 const String& GetString(USHORT nIndex)
113 { return ((TypedStrData*)At(nIndex))->GetString(); }
114 short GetIndex(TypedStrData* pData) const;
117 class ScPivot : public DataObject
119 ScDocument* pDoc;
120 ScQueryParam aQuery;
121 BOOL bHasHeader;
123 BOOL bIgnoreEmpty; // Flags aus Dialog
124 BOOL bDetectCat;
125 BOOL bMakeTotalCol;
126 BOOL bMakeTotalRow;
128 String aName;
129 String aTag;
130 USHORT nColNameCount;
131 String* pColNames; // Array
133 USHORT nSrcCol1;
134 USHORT nSrcRow1;
135 USHORT nSrcCol2;
136 USHORT nSrcRow2;
137 USHORT nSrcTab;
139 USHORT nDestCol1;
140 USHORT nDestRow1;
141 USHORT nDestCol2;
142 USHORT nDestRow2;
143 USHORT nDestTab;
145 USHORT nDataStartCol;
146 USHORT nDataStartRow;
148 short nColCount;
149 short nRowCount;
150 short nDataCount;
152 PivotFieldArr aColArr;
153 PivotFieldArr aRowArr;
154 PivotFieldArr aDataArr;
156 PivotStrCollection* pColList[PIVOT_MAXFIELD]; // pro Zeile alle Eintraege
157 PivotStrCollection* pRowList[PIVOT_MAXFIELD];
158 PivotStrCollection* pDataList; // Shortcut auf Col/RowList mit Daten
160 SubTotal** ppDataArr;
161 short nDataColCount;
162 short nDataRowCount;
163 short nRowIndex;
164 short nColIndex;
165 short nDataIndex;
166 short nRecCount;
168 PivotColRef* pColRef;
170 BOOL bValidArea;
171 BOOL bDataAtCol;
173 public:
174 ScPivot(ScDocument* pDocument);
175 ScPivot(const ScPivot& rPivot);
176 ~ScPivot();
178 virtual DataObject* Clone() const;
181 BOOL Load(SvStream& rStream, ScMultipleReadHeader& rHdr );
182 BOOL Store(SvStream& rStream, ScMultipleWriteHeader& rHdr ) const;
184 void SetQuery(const ScQueryParam& rQuery);
185 void GetQuery(ScQueryParam& rQuery) const;
187 void SetHeader(BOOL bHeader);
188 void SetIgnoreEmpty(BOOL bIgnore);
189 BOOL GetIgnoreEmpty() const;
190 void SetDetectCat(BOOL bDetect);
191 BOOL GetDetectCat() const;
192 void SetMakeTotalCol(BOOL bSet);
193 BOOL GetMakeTotalCol() const;
194 void SetMakeTotalRow(BOOL bSet);
195 BOOL GetMakeTotalRow() const;
197 void SetName(const String& rNew);
198 const String& GetName() const;
199 void SetTag(const String& rNew);
200 const String& GetTag() const;
202 void SetSrcArea(USHORT nCol1, USHORT nRow1, USHORT nCol2, USHORT nRow2, USHORT nTab);
203 void GetSrcArea(USHORT& rCol1, USHORT& rRow1, USHORT& rCol2, USHORT& rRow2, USHORT& rTab) const;
204 ScRange GetSrcArea() const;
206 void SetDestPos(USHORT nCol, USHORT nRow, USHORT nTab);
207 void GetDestArea(USHORT& rCol1, USHORT& rRow1, USHORT& rCol2, USHORT& rRow2, USHORT& rTab) const;
208 ScRange GetDestArea() const;
210 void SetColFields(const PivotField* pFieldArr, short nCount);
211 void GetColFields(PivotField* pFieldArr, short& rCount) const;
212 short GetColFieldCount() const { return nColCount; }
214 void SetRowFields(const PivotField* pFieldArr, short nCount);
215 void GetRowFields(PivotField* pFieldArr, short& rCount) const;
216 short GetRowFieldCount() const { return nRowCount; }
218 void SetDataFields(const PivotField* pFieldArr, short nCount);
219 void GetDataFields(PivotField* pFieldArr, short& rCount) const;
221 void GetParam( ScPivotParam& rParam, ScQueryParam& rQuery, ScArea& rSrcArea ) const;
222 void SetParam( const ScPivotParam& rParam, const ScQueryParam& rQuery,
223 const ScArea& rSrcArea );
225 BOOL CreateData(BOOL bKeepDest = FALSE);
226 void ReleaseData();
229 // Referenz-Anpassung:
231 void MoveSrcArea( USHORT nNewCol, USHORT nNewRow, USHORT nNewTab );
232 void MoveDestArea( USHORT nNewCol, USHORT nNewRow, USHORT nNewTab );
234 private:
235 BOOL CreateFields();
236 void CreateFieldData();
237 void CalcArea();
239 USHORT GetCategoryRow( USHORT nCol, USHORT nRow );
242 //------------------------------------------------------------------------
243 class ScPivotCollection : public Collection
246 private:
247 ScDocument* pDoc;
248 public:
249 ScPivotCollection(USHORT nLim = 4, USHORT nDel = 4, ScDocument* pDocument = NULL) :
250 Collection ( nLim, nDel),
251 pDoc ( pDocument ) {}
252 ScPivotCollection(const ScPivotCollection& rScPivotCollection) :
253 Collection ( rScPivotCollection ),
254 pDoc ( rScPivotCollection.pDoc ) {}
256 ScPivot* operator[]( const USHORT nIndex) const {return (ScPivot*)At(nIndex);}
258 BOOL Load( SvStream& rStream );
259 BOOL Store( SvStream& rStream ) const;
261 void UpdateReference(UpdateRefMode eUpdateRefMode,
262 USHORT nCol1, USHORT nRow1, USHORT nTab1,
263 USHORT nCol2, USHORT nRow2, USHORT nTab2,
264 short nDx, short nDy, short nDz );
267 String CreateNewName( USHORT nMin = 1 ) const;
270 //------------------------------------------------------------------------
271 struct LabelData
273 String* pStrColName;
274 short nCol;
275 BOOL bIsValue; // Summe oder Anzahl im Data-Feld
276 USHORT nFuncMask;
279 LabelData( const String& rColName,
280 short nColumn,
281 BOOL bVal,
282 USHORT nMask = PIVOT_FUNC_NONE )
283 : nCol (nColumn),
284 bIsValue (bVal),
285 nFuncMask (nMask)
286 { pStrColName = new String( rColName ); }
288 LabelData( const LabelData& rCpy )
289 : nCol (rCpy.nCol),
290 bIsValue (rCpy.bIsValue),
291 nFuncMask (rCpy.nFuncMask)
292 { pStrColName = new String( *(rCpy.pStrColName) ); }
294 ~LabelData()
295 { delete pStrColName; }
297 LabelData& operator=( const LabelData& r )
299 nCol = r.nCol;
300 bIsValue = r.bIsValue;
301 nFuncMask = r.nFuncMask;
302 pStrColName = new String( *(r.pStrColName) );
304 return *this;
309 } //namespace binfilter
310 #endif