merge the formfield patch from ooo-build
[ooovba.git] / sc / inc / dpgroup.hxx
blob07be6322aabbc04b5498f9699f7edab93877943f
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: dpgroup.hxx,v $
10 * $Revision: 1.7 $
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_DPGROUP_HXX
32 #define SC_DPGROUP_HXX
34 #include <vector>
35 #include <hash_set>
36 #include <boost/shared_ptr.hpp>
38 #include "dptabdat.hxx"
39 #include "scdllapi.h"
41 class ScDocument;
42 class SvNumberFormatter;
44 // --------------------------------------------------------------------
46 //! API struct?
47 struct ScDPNumGroupInfo
49 sal_Bool Enable;
50 sal_Bool DateValues;
51 sal_Bool AutoStart;
52 sal_Bool AutoEnd;
53 double Start;
54 double End;
55 double Step;
57 ScDPNumGroupInfo() : Enable(sal_False), DateValues(sal_False), AutoStart(sal_False), AutoEnd(sal_False),
58 Start(0.0), End(0.0), Step(0.0) {}
61 // --------------------------------------------------------------------
63 // ScDPDateGroupHelper is used as part of ScDPGroupDimension (additional dim.)
64 // or ScDPNumGroupDimension (innermost, replaces the original dim.).
65 // Source index, name and result collection are stored at the parent.
67 class ScDPDateGroupHelper
69 ScDPNumGroupInfo aNumInfo; // only start and end (incl. auto flags) are used
70 sal_Int32 nDatePart; // single part
72 public:
73 ScDPDateGroupHelper( const ScDPNumGroupInfo& rInfo, sal_Int32 nPart );
74 ~ScDPDateGroupHelper();
76 sal_Int32 GetDatePart() const { return nDatePart; }
77 const ScDPNumGroupInfo& GetNumInfo() const { return aNumInfo; }
79 void FillColumnEntries( TypedScStrCollection& rEntries, const TypedScStrCollection& rOriginal,
80 SvNumberFormatter* pFormatter ) const;
83 // --------------------------------------------------------------------
85 typedef ::std::vector<ScDPItemData> ScDPItemDataVec;
87 class ScDPGroupItem
89 ScDPItemData aGroupName; // name of group item
90 ScDPItemDataVec aElements; // names of items in original dimension
92 public:
93 ScDPGroupItem( const ScDPItemData& rName );
94 ~ScDPGroupItem();
96 void AddElement( const ScDPItemData& rName );
98 const ScDPItemData& GetName() const { return aGroupName; }
99 bool HasElement( const ScDPItemData& rData ) const;
100 bool HasCommonElement( const ScDPGroupItem& rOther ) const;
102 void FillGroupFilter( ScDPCacheTable::GroupFilter& rFilter ) const;
105 typedef ::std::vector<ScDPGroupItem> ScDPGroupItemVec;
107 class ScDPGroupDimension
109 long nSourceDim;
110 long nGroupDim;
111 String aGroupName;
112 ScDPDateGroupHelper* pDateHelper;
113 ScDPGroupItemVec aItems;
114 mutable TypedScStrCollection* pCollection; // collection of item names (cached)
116 public:
117 ScDPGroupDimension( long nSource, const String& rNewName );
118 ScDPGroupDimension( const ScDPGroupDimension& rOther );
119 ~ScDPGroupDimension();
121 ScDPGroupDimension& operator=( const ScDPGroupDimension& rOther );
123 void AddItem( const ScDPGroupItem& rItem );
124 void SetGroupDim( long nDim ); // called from AddGroupDimension
126 long GetSourceDim() const { return nSourceDim; }
127 long GetGroupDim() const { return nGroupDim; }
128 const String& GetName() const { return aGroupName; }
130 const TypedScStrCollection& GetColumnEntries( const TypedScStrCollection& rOriginal, ScDocument* pDoc ) const;
131 const ScDPGroupItem* GetGroupForData( const ScDPItemData& rData ) const; // rData = entry in original dim.
132 const ScDPGroupItem* GetGroupForName( const ScDPItemData& rName ) const; // rName = entry in group dim.
133 const ScDPGroupItem* GetGroupByIndex( size_t nIndex ) const;
135 const ScDPDateGroupHelper* GetDateHelper() const { return pDateHelper; }
137 void MakeDateHelper( const ScDPNumGroupInfo& rInfo, sal_Int32 nPart );
139 void DisposeData();
141 size_t GetItemCount() const { return aItems.size(); }
144 typedef ::std::vector<ScDPGroupDimension> ScDPGroupDimensionVec;
146 // --------------------------------------------------------------------
148 class SC_DLLPUBLIC ScDPNumGroupDimension
150 ScDPNumGroupInfo aGroupInfo; // settings
151 ScDPDateGroupHelper* pDateHelper;
152 mutable TypedScStrCollection* pCollection; // collection of item names (cached)
153 mutable bool bHasNonInteger; // initialized in GetNumEntries
154 mutable sal_Unicode cDecSeparator; // initialized in GetNumEntries
156 public:
157 ScDPNumGroupDimension();
158 ScDPNumGroupDimension( const ScDPNumGroupInfo& rInfo );
159 ScDPNumGroupDimension( const ScDPNumGroupDimension& rOther );
160 ~ScDPNumGroupDimension();
162 ScDPNumGroupDimension& operator=( const ScDPNumGroupDimension& rOther );
164 const TypedScStrCollection& GetNumEntries( const TypedScStrCollection& rOriginal, ScDocument* pDoc ) const;
166 const ScDPNumGroupInfo& GetInfo() const { return aGroupInfo; }
167 bool HasNonInteger() const { return bHasNonInteger; }
168 sal_Unicode GetDecSeparator() const { return cDecSeparator; }
170 const ScDPDateGroupHelper* GetDateHelper() const { return pDateHelper; }
172 void MakeDateHelper( const ScDPNumGroupInfo& rInfo, sal_Int32 nPart );
174 void DisposeData();
177 // --------------------------------------------------------------------
179 // proxy implementation of ScDPTableData to add grouped items
182 class ScDPGroupTableData : public ScDPTableData
184 typedef ::std::hash_set< ::rtl::OUString, ::rtl::OUStringHash, ::std::equal_to< ::rtl::OUString > > StringHashSet;
186 ::boost::shared_ptr<ScDPTableData> pSourceData;
187 long nSourceCount;
188 ScDPGroupDimensionVec aGroups;
189 ScDPNumGroupDimension* pNumGroups; // array[nSourceCount]
190 ScDocument* pDoc;
191 StringHashSet aGroupNames;
193 void FillGroupValues( ScDPItemData* pItemData, long nCount, const long* pDims );
194 void CopyFields(const ::std::vector<long>& rFieldDims, ::std::vector<long>& rNewFieldDims);
196 bool IsNumGroupDimension( long nDimension ) const;
197 void GetNumGroupInfo( long nDimension, ScDPNumGroupInfo& rInfo,
198 bool& rNonInteger, sal_Unicode& rDecimal );
200 void ModifyFilterCriteria(::std::vector<ScDPCacheTable::Criterion>& rCriteria);
202 public:
203 // takes ownership of pSource
204 ScDPGroupTableData( const ::boost::shared_ptr<ScDPTableData>& pSource, ScDocument* pDocument );
205 virtual ~ScDPGroupTableData();
207 void AddGroupDimension( const ScDPGroupDimension& rGroup );
208 void SetNumGroupDimension( long nIndex, const ScDPNumGroupDimension& rGroup );
209 long GetDimensionIndex( const String& rName );
211 ScDocument* GetDocument() { return pDoc; }
213 virtual long GetColumnCount();
214 virtual const TypedScStrCollection& GetColumnEntries(long nColumn);
215 virtual String getDimensionName(long nColumn);
216 virtual BOOL getIsDataLayoutDimension(long nColumn);
217 virtual BOOL IsDateDimension(long nDim);
218 virtual UINT32 GetNumberFormat(long nDim);
219 virtual void DisposeData();
220 virtual void SetEmptyFlags( BOOL bIgnoreEmptyRows, BOOL bRepeatIfEmpty );
222 virtual bool IsRepeatIfEmpty();
224 virtual void CreateCacheTable();
225 virtual void FilterCacheTable(const ::std::vector<ScDPCacheTable::Criterion>& rCriteria, const ::std::hash_set<sal_Int32>& rDataDims);
226 virtual void GetDrillDownData(const ::std::vector<ScDPCacheTable::Criterion>& rCriteria,
227 const ::std::hash_set<sal_Int32>& rCatDims,
228 ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any > >& rData);
229 virtual void CalcResults(CalcInfo& rInfo, bool bAutoShow);
230 virtual const ScDPCacheTable& GetCacheTable() const;
232 virtual BOOL IsBaseForGroup(long nDim) const;
233 virtual long GetGroupBase(long nGroupDim) const;
234 virtual BOOL IsNumOrDateGroup(long nDim) const;
235 virtual BOOL IsInGroup( const ScDPItemData& rGroupData, long nGroupIndex,
236 const ScDPItemData& rBaseData, long nBaseIndex ) const;
237 virtual BOOL HasCommonElement( const ScDPItemData& rFirstData, long nFirstIndex,
238 const ScDPItemData& rSecondData, long nSecondIndex ) const;
242 #endif