xref: /aoo42x/main/sc/inc/dpglobal.hxx (revision fd44edf3)
1ebfcd9afSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3ebfcd9afSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4ebfcd9afSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5ebfcd9afSAndrew Rist  * distributed with this work for additional information
6ebfcd9afSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7ebfcd9afSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8ebfcd9afSAndrew Rist  * "License"); you may not use this file except in compliance
9ebfcd9afSAndrew Rist  * with the License.  You may obtain a copy of the License at
10ebfcd9afSAndrew Rist  *
11ebfcd9afSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12ebfcd9afSAndrew Rist  *
13ebfcd9afSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14ebfcd9afSAndrew Rist  * software distributed under the License is distributed on an
15ebfcd9afSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16ebfcd9afSAndrew Rist  * KIND, either express or implied.  See the License for the
17ebfcd9afSAndrew Rist  * specific language governing permissions and limitations
18ebfcd9afSAndrew Rist  * under the License.
19ebfcd9afSAndrew Rist  *
20ebfcd9afSAndrew Rist  *************************************************************/
21ebfcd9afSAndrew Rist 
22ebfcd9afSAndrew Rist 
23cdf0e10cSrcweir // Wang Xu Ming - DataPilot migration
24cdf0e10cSrcweir // Buffer&&Performance
25cdf0e10cSrcweir //
26cdf0e10cSrcweir #ifndef _SC_DPGLOBAL_HXX
27cdf0e10cSrcweir #define _SC_DPGLOBAL_HXX
28cdf0e10cSrcweir 
29cdf0e10cSrcweir #include <algorithm>
30cdf0e10cSrcweir #include <list>
31*fd44edf3SHerbert Dürr #include <vector>
32cdf0e10cSrcweir #include <tools/gen.hxx>
33cdf0e10cSrcweir #include <tools/debug.hxx>
34cdf0e10cSrcweir #include <global.hxx>
35cdf0e10cSrcweir 
36cdf0e10cSrcweir #include <com/sun/star/container/XNamed.hpp>
37cdf0e10cSrcweir #include <com/sun/star/sheet/XDimensionsSupplier.hpp>
38cdf0e10cSrcweir 
39cdf0e10cSrcweir #include <com/sun/star/sheet/DataPilotFieldFilter.hpp>
40cdf0e10cSrcweir #include <com/sun/star/sheet/DataPilotFieldOrientation.hpp>
41cdf0e10cSrcweir #include <com/sun/star/sheet/DataPilotTableHeaderData.hpp>
42cdf0e10cSrcweir #include <com/sun/star/sheet/DataPilotTablePositionData.hpp>
43cdf0e10cSrcweir #include <com/sun/star/sheet/DataPilotTablePositionType.hpp>
44cdf0e10cSrcweir #include <com/sun/star/sheet/DataPilotTableResultData.hpp>
45cdf0e10cSrcweir #include <com/sun/star/sheet/DataResultFlags.hpp>
46cdf0e10cSrcweir #include <com/sun/star/sheet/GeneralFunction.hpp>
47cdf0e10cSrcweir #include <com/sun/star/sheet/MemberResultFlags.hpp>
48cdf0e10cSrcweir #include <com/sun/star/sheet/TableFilterField.hpp>
49cdf0e10cSrcweir #include <com/sun/star/sheet/XDataPilotMemberResults.hpp>
50cdf0e10cSrcweir #include <com/sun/star/sheet/XDataPilotResults.hpp>
51cdf0e10cSrcweir #include <com/sun/star/sheet/XHierarchiesSupplier.hpp>
52cdf0e10cSrcweir #include <com/sun/star/sheet/XLevelsSupplier.hpp>
53cdf0e10cSrcweir 
54cdf0e10cSrcweir 
55cdf0e10cSrcweir // moved from fieldwnd.hxx, see also SC_DAPI_MAXFIELDS
56cdf0e10cSrcweir #define MAX_LABELS  256
57cdf0e10cSrcweir 
58cdf0e10cSrcweir #define		PIVOT_MAXFUNC			11
59cdf0e10cSrcweir #define		PIVOT_FUNC_NONE			0x0000
60cdf0e10cSrcweir #define     PIVOT_FUNC_SUM			0x0001
61cdf0e10cSrcweir #define		PIVOT_FUNC_COUNT		0x0002
62cdf0e10cSrcweir #define		PIVOT_FUNC_AVERAGE		0x0004
63cdf0e10cSrcweir #define		PIVOT_FUNC_MAX			0x0008
64cdf0e10cSrcweir #define		PIVOT_FUNC_MIN			0x0010
65cdf0e10cSrcweir #define		PIVOT_FUNC_PRODUCT		0x0020
66cdf0e10cSrcweir #define		PIVOT_FUNC_COUNT_NUM	0x0040
67cdf0e10cSrcweir #define		PIVOT_FUNC_STD_DEV		0x0080
68cdf0e10cSrcweir #define		PIVOT_FUNC_STD_DEVP		0x0100
69cdf0e10cSrcweir #define		PIVOT_FUNC_STD_VAR		0x0200
70cdf0e10cSrcweir #define		PIVOT_FUNC_STD_VARP		0x0400
71cdf0e10cSrcweir #define		PIVOT_FUNC_AUTO			0x1000
72cdf0e10cSrcweir 
73cdf0e10cSrcweir #define DATA_RENAME_SEPARATOR		"_"
74cdf0e10cSrcweir #define __MAX_NUM_LEN 64
75cdf0e10cSrcweir #define __DECIMALPLACE	18
76cdf0e10cSrcweir 
77cdf0e10cSrcweir #define DP_PROP_COLUMNGRAND			"ColumnGrand"
78cdf0e10cSrcweir #define DP_PROP_FUNCTION			"Function"
79cdf0e10cSrcweir #define DP_PROP_IGNOREEMPTY			"IgnoreEmptyRows"
80cdf0e10cSrcweir #define DP_PROP_ISDATALAYOUT		"IsDataLayoutDimension"
81cdf0e10cSrcweir #define DP_PROP_ISVISIBLE			"IsVisible"
82cdf0e10cSrcweir #define DP_PROP_ORIENTATION			"Orientation"
83cdf0e10cSrcweir #define DP_PROP_REPEATIFEMPTY		"RepeatIfEmpty"
84cdf0e10cSrcweir #define DP_PROP_ROWGRAND			"RowGrand"
85cdf0e10cSrcweir #define DP_PROP_SHOWDETAILS			"ShowDetails"
86cdf0e10cSrcweir #define DP_PROP_SHOWEMPTY			"ShowEmpty"
87cdf0e10cSrcweir #define DP_PROP_SUBTOTALS			"SubTotals"
88cdf0e10cSrcweir #define DP_PROP_USEDHIERARCHY		"UsedHierarchy"
89cdf0e10cSrcweir #define DP_PROP_FILTER				"Filter"
90cdf0e10cSrcweir #define DP_PROP_POSITION            "Position"
91cdf0e10cSrcweir 
92cdf0e10cSrcweir #define DBG_TRACESTR( x )  \
93cdf0e10cSrcweir 	{\
94cdf0e10cSrcweir 		ByteString aTemp( x , RTL_TEXTENCODING_UTF8 ); \
95cdf0e10cSrcweir 		DBG_TRACE( aTemp.GetBuffer() );\
96cdf0e10cSrcweir 	}
97cdf0e10cSrcweir 
98cdf0e10cSrcweir class TypedStrData;
99cdf0e10cSrcweir class ScDPObject;
100cdf0e10cSrcweir 
101cdf0e10cSrcweir class SC_DLLPUBLIC ScDPItemData
102cdf0e10cSrcweir {
103cdf0e10cSrcweir public:
104cdf0e10cSrcweir 	enum { MK_VAL = 0x01, MK_DATA = MK_VAL<<1, MK_ERR = MK_DATA<<1, MK_DATE = MK_ERR<<1, MK_DATEPART = MK_DATE<<1 };
105cdf0e10cSrcweir private:
106cdf0e10cSrcweir 	union
107cdf0e10cSrcweir 	{
108cdf0e10cSrcweir 		sal_uLong	nNumFormat;
109cdf0e10cSrcweir 		sal_Int32 mnDatePart;
110cdf0e10cSrcweir 	};
111cdf0e10cSrcweir 
112cdf0e10cSrcweir 	String	aString;
113cdf0e10cSrcweir 	double	fValue;
114cdf0e10cSrcweir 	sal_uInt8	mbFlag;
115cdf0e10cSrcweir 	//sal_Bool	bHasValue: 1 ;
116cdf0e10cSrcweir 	//sal_Bool	bHasData: 1;
117cdf0e10cSrcweir 	//sal_Bool	bErr: 1;
118cdf0e10cSrcweir 
119cdf0e10cSrcweir 	friend class ScDPTableDataCache;
120cdf0e10cSrcweir public:
ScDPItemData()121cdf0e10cSrcweir 	ScDPItemData() : nNumFormat( 0 ), fValue(0.0), mbFlag( 0 ){}
ScDPItemData(sal_uLong nNF,const String & rS,double fV,sal_uInt8 bF)122cdf0e10cSrcweir 	ScDPItemData( sal_uLong nNF, const String & rS, double fV, sal_uInt8 bF ):nNumFormat(nNF), aString(rS), fValue(fV), mbFlag( bF ){}
123cdf0e10cSrcweir 	ScDPItemData( const String& rS, double fV = 0.0, sal_Bool bHV = sal_False, const sal_uLong nNumFormat = 0 , sal_Bool bData = sal_True) ;
124cdf0e10cSrcweir 	ScDPItemData( ScDocument* pDoc, SCROW nRow, sal_uInt16 nCol, sal_uInt16 nDocTab );
125cdf0e10cSrcweir 
SetString(const String & rS)126cdf0e10cSrcweir 	void		SetString( const String& rS ) { aString = rS; mbFlag &= ~(MK_VAL|MK_DATE); nNumFormat = 0; mbFlag |= MK_DATA; }
127cdf0e10cSrcweir //	void		SetValue ( double value , sal_uLong nNumFormat = 0 ) { bHasValue = sal_True; nNumFormat = 0;bHasData = sal_True; bDate = sal_False; fValue = value ;}
128cdf0e10cSrcweir 	sal_Bool		IsCaseInsEqual( const ScDPItemData& r ) const;
129cdf0e10cSrcweir 
130cdf0e10cSrcweir 	size_t		Hash() const;
131cdf0e10cSrcweir 
132cdf0e10cSrcweir 	// exact equality
133cdf0e10cSrcweir 	sal_Bool		operator==( const ScDPItemData& r ) const;
134cdf0e10cSrcweir 	// case insensitive equality
135cdf0e10cSrcweir 	static sal_Int32	Compare( const ScDPItemData& rA, const ScDPItemData& rB );
136cdf0e10cSrcweir 
137cdf0e10cSrcweir #ifdef DEBUG
138cdf0e10cSrcweir 	void	dump() const;
139cdf0e10cSrcweir #endif
140cdf0e10cSrcweir 
141cdf0e10cSrcweir public:
142cdf0e10cSrcweir 	sal_Bool IsHasData() const ;
143cdf0e10cSrcweir 	sal_Bool IsHasErr() const ;
144cdf0e10cSrcweir 	sal_Bool IsValue() const;
145cdf0e10cSrcweir 	String	GetString() const ;
146cdf0e10cSrcweir 	double	GetValue() const ;
147cdf0e10cSrcweir 	sal_uLong    GetNumFormat() const ;
148cdf0e10cSrcweir 	sal_Bool HasStringData() const ;
149cdf0e10cSrcweir 	sal_Bool IsDate() const;
150cdf0e10cSrcweir 	sal_Bool HasDatePart() const;
151cdf0e10cSrcweir 	void SetDate( sal_Bool b ) ;
152cdf0e10cSrcweir 
153cdf0e10cSrcweir 	TypedStrData*  CreateTypeString( );
154cdf0e10cSrcweir 	sal_uInt8	 GetType() const;
GetFlag()155cdf0e10cSrcweir 	sal_uInt8 & GetFlag() throw() { return mbFlag; }
GetFlag() const156cdf0e10cSrcweir 	const sal_uInt8 & GetFlag() const throw() { return const_cast<ScDPItemData*>(this)->GetFlag(); }
157cdf0e10cSrcweir };
158cdf0e10cSrcweir 
159cdf0e10cSrcweir class SC_DLLPUBLIC ScDPItemDataPool
160cdf0e10cSrcweir {
161cdf0e10cSrcweir public:
162cdf0e10cSrcweir 	// construct
163cdf0e10cSrcweir 	ScDPItemDataPool(void);
164cdf0e10cSrcweir 	ScDPItemDataPool(const ScDPItemDataPool& r);
165cdf0e10cSrcweir 
166cdf0e10cSrcweir 	virtual ~ScDPItemDataPool(void);
167cdf0e10cSrcweir 	virtual const ScDPItemData* getData( sal_Int32 nId  );
168cdf0e10cSrcweir 	virtual sal_Int32 getDataId( const ScDPItemData& aData );
169cdf0e10cSrcweir 	virtual sal_Int32 insertData( const ScDPItemData& aData );
170cdf0e10cSrcweir protected:
171cdf0e10cSrcweir 	struct DataHashFunc : public std::unary_function< const ScDPItemData &, size_t >
172cdf0e10cSrcweir 	{
operator ()ScDPItemDataPool::DataHashFunc173cdf0e10cSrcweir 		size_t operator() (const ScDPItemData &rData) const { return rData.Hash(); }
174cdf0e10cSrcweir 	};
175cdf0e10cSrcweir 
176cdf0e10cSrcweir 	typedef ::std::hash_multimap< ScDPItemData, sal_Int32, DataHashFunc > DataHash;
177cdf0e10cSrcweir 
178cdf0e10cSrcweir 	::std::vector< ScDPItemData > maItems;
179cdf0e10cSrcweir 	DataHash  maItemIds;
180cdf0e10cSrcweir };
181cdf0e10cSrcweir 
182cdf0e10cSrcweir class ScDPInfoWnd;
183cdf0e10cSrcweir class ScDocShell;
184cdf0e10cSrcweir class ScTabViewShell;
185cdf0e10cSrcweir namespace ScDPGlobal
186cdf0e10cSrcweir {
187cdf0e10cSrcweir // used for core data
188cdf0e10cSrcweir 	String GetFieldFuncString( const String& rSourceName, sal_uInt16 &rFuncMask, sal_Bool bIsValue );
189cdf0e10cSrcweir 	String GetFuncString( const String &rString, const sal_uInt16 nIndex );
190cdf0e10cSrcweir 	com::sun::star::uno::Reference<com::sun::star::container::XNameAccess> DP_GetMembers( const com::sun::star::uno::Reference<
191cdf0e10cSrcweir 																					  com::sun::star::sheet::XDimensionsSupplier>&rSrc, long nField );
192cdf0e10cSrcweir // common operation
193cdf0e10cSrcweir 	String operator + ( const String & rL, const String &rR );
194cdf0e10cSrcweir 	Rectangle operator *( const Rectangle &rLeft, const std::pair<double,double> & rRight );
195cdf0e10cSrcweir // used for  DataPilot Panel
196cdf0e10cSrcweir     ScDPInfoWnd* GetDPInfoWnd( ScTabViewShell *pViewShell );
197cdf0e10cSrcweir    bool ChkDPTableOverlap( ScDocument *pDestDoc, std::list<ScDPObject> & rClipboard, SCCOL nClipStartCol, SCROW nClipStartRow, SCCOL nStartCol, SCROW nStartRow, SCTAB nStartTab, sal_uInt16 nEndTab, sal_Bool bExcludeClip = sal_False );
198cdf0e10cSrcweir 
199cdf0e10cSrcweir }
200b4df81e3SWang Lei #define isDateFormat( nNumType ) (!!((nNumType) & NUMBERFORMAT_DATE) )
201b4df81e3SWang Lei 
202cdf0e10cSrcweir #endif
203