xref: /aoo42x/main/sc/inc/dpglobal.hxx (revision b4df81e3)
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>
31cdf0e10cSrcweir #include <tools/gen.hxx>
32cdf0e10cSrcweir #include <tools/debug.hxx>
33cdf0e10cSrcweir #include <global.hxx>
34cdf0e10cSrcweir 
35cdf0e10cSrcweir #include <com/sun/star/container/XNamed.hpp>
36cdf0e10cSrcweir #include <com/sun/star/sheet/XDimensionsSupplier.hpp>
37cdf0e10cSrcweir 
38cdf0e10cSrcweir #include <com/sun/star/sheet/DataPilotFieldFilter.hpp>
39cdf0e10cSrcweir #include <com/sun/star/sheet/DataPilotFieldOrientation.hpp>
40cdf0e10cSrcweir #include <com/sun/star/sheet/DataPilotTableHeaderData.hpp>
41cdf0e10cSrcweir #include <com/sun/star/sheet/DataPilotTablePositionData.hpp>
42cdf0e10cSrcweir #include <com/sun/star/sheet/DataPilotTablePositionType.hpp>
43cdf0e10cSrcweir #include <com/sun/star/sheet/DataPilotTableResultData.hpp>
44cdf0e10cSrcweir #include <com/sun/star/sheet/DataResultFlags.hpp>
45cdf0e10cSrcweir #include <com/sun/star/sheet/GeneralFunction.hpp>
46cdf0e10cSrcweir #include <com/sun/star/sheet/MemberResultFlags.hpp>
47cdf0e10cSrcweir #include <com/sun/star/sheet/TableFilterField.hpp>
48cdf0e10cSrcweir #include <com/sun/star/sheet/XDataPilotMemberResults.hpp>
49cdf0e10cSrcweir #include <com/sun/star/sheet/XDataPilotResults.hpp>
50cdf0e10cSrcweir #include <com/sun/star/sheet/XHierarchiesSupplier.hpp>
51cdf0e10cSrcweir #include <com/sun/star/sheet/XLevelsSupplier.hpp>
52cdf0e10cSrcweir 
53cdf0e10cSrcweir 
54cdf0e10cSrcweir // moved from fieldwnd.hxx, see also SC_DAPI_MAXFIELDS
55cdf0e10cSrcweir #define MAX_LABELS  256
56cdf0e10cSrcweir 
57cdf0e10cSrcweir #define		PIVOT_MAXFUNC			11
58cdf0e10cSrcweir #define		PIVOT_FUNC_NONE			0x0000
59cdf0e10cSrcweir #define     PIVOT_FUNC_SUM			0x0001
60cdf0e10cSrcweir #define		PIVOT_FUNC_COUNT		0x0002
61cdf0e10cSrcweir #define		PIVOT_FUNC_AVERAGE		0x0004
62cdf0e10cSrcweir #define		PIVOT_FUNC_MAX			0x0008
63cdf0e10cSrcweir #define		PIVOT_FUNC_MIN			0x0010
64cdf0e10cSrcweir #define		PIVOT_FUNC_PRODUCT		0x0020
65cdf0e10cSrcweir #define		PIVOT_FUNC_COUNT_NUM	0x0040
66cdf0e10cSrcweir #define		PIVOT_FUNC_STD_DEV		0x0080
67cdf0e10cSrcweir #define		PIVOT_FUNC_STD_DEVP		0x0100
68cdf0e10cSrcweir #define		PIVOT_FUNC_STD_VAR		0x0200
69cdf0e10cSrcweir #define		PIVOT_FUNC_STD_VARP		0x0400
70cdf0e10cSrcweir #define		PIVOT_FUNC_AUTO			0x1000
71cdf0e10cSrcweir 
72cdf0e10cSrcweir #define DATA_RENAME_SEPARATOR		"_"
73cdf0e10cSrcweir #define __MAX_NUM_LEN 64
74cdf0e10cSrcweir #define __DECIMALPLACE	18
75cdf0e10cSrcweir 
76cdf0e10cSrcweir #define DP_PROP_COLUMNGRAND			"ColumnGrand"
77cdf0e10cSrcweir #define DP_PROP_FUNCTION			"Function"
78cdf0e10cSrcweir #define DP_PROP_IGNOREEMPTY			"IgnoreEmptyRows"
79cdf0e10cSrcweir #define DP_PROP_ISDATALAYOUT		"IsDataLayoutDimension"
80cdf0e10cSrcweir #define DP_PROP_ISVISIBLE			"IsVisible"
81cdf0e10cSrcweir #define DP_PROP_ORIENTATION			"Orientation"
82cdf0e10cSrcweir #define DP_PROP_REPEATIFEMPTY		"RepeatIfEmpty"
83cdf0e10cSrcweir #define DP_PROP_ROWGRAND			"RowGrand"
84cdf0e10cSrcweir #define DP_PROP_SHOWDETAILS			"ShowDetails"
85cdf0e10cSrcweir #define DP_PROP_SHOWEMPTY			"ShowEmpty"
86cdf0e10cSrcweir #define DP_PROP_SUBTOTALS			"SubTotals"
87cdf0e10cSrcweir #define DP_PROP_USEDHIERARCHY		"UsedHierarchy"
88cdf0e10cSrcweir #define DP_PROP_FILTER				"Filter"
89cdf0e10cSrcweir #define DP_PROP_POSITION            "Position"
90cdf0e10cSrcweir 
91cdf0e10cSrcweir #define DBG_TRACESTR( x )  \
92cdf0e10cSrcweir 	{\
93cdf0e10cSrcweir 		ByteString aTemp( x , RTL_TEXTENCODING_UTF8 ); \
94cdf0e10cSrcweir 		DBG_TRACE( aTemp.GetBuffer() );\
95cdf0e10cSrcweir 	}
96cdf0e10cSrcweir 
97cdf0e10cSrcweir class TypedStrData;
98cdf0e10cSrcweir class ScDPObject;
99cdf0e10cSrcweir 
100cdf0e10cSrcweir class SC_DLLPUBLIC ScDPItemData
101cdf0e10cSrcweir {
102cdf0e10cSrcweir public:
103cdf0e10cSrcweir 	enum { MK_VAL = 0x01, MK_DATA = MK_VAL<<1, MK_ERR = MK_DATA<<1, MK_DATE = MK_ERR<<1, MK_DATEPART = MK_DATE<<1 };
104cdf0e10cSrcweir private:
105cdf0e10cSrcweir 	union
106cdf0e10cSrcweir 	{
107cdf0e10cSrcweir 		sal_uLong	nNumFormat;
108cdf0e10cSrcweir 		sal_Int32 mnDatePart;
109cdf0e10cSrcweir 	};
110cdf0e10cSrcweir 
111cdf0e10cSrcweir 	String	aString;
112cdf0e10cSrcweir 	double	fValue;
113cdf0e10cSrcweir 	sal_uInt8	mbFlag;
114cdf0e10cSrcweir 	//sal_Bool	bHasValue: 1 ;
115cdf0e10cSrcweir 	//sal_Bool	bHasData: 1;
116cdf0e10cSrcweir 	//sal_Bool	bErr: 1;
117cdf0e10cSrcweir 
118cdf0e10cSrcweir 	friend class ScDPTableDataCache;
119cdf0e10cSrcweir public:
120cdf0e10cSrcweir 	ScDPItemData() : nNumFormat( 0 ), fValue(0.0), mbFlag( 0 ){}
121cdf0e10cSrcweir 	ScDPItemData( sal_uLong nNF, const String & rS, double fV, sal_uInt8 bF ):nNumFormat(nNF), aString(rS), fValue(fV), mbFlag( bF ){}
122cdf0e10cSrcweir 	ScDPItemData( const String& rS, double fV = 0.0, sal_Bool bHV = sal_False, const sal_uLong nNumFormat = 0 , sal_Bool bData = sal_True) ;
123cdf0e10cSrcweir 	ScDPItemData( ScDocument* pDoc, SCROW nRow, sal_uInt16 nCol, sal_uInt16 nDocTab );
124cdf0e10cSrcweir 
125cdf0e10cSrcweir 	void		SetString( const String& rS ) { aString = rS; mbFlag &= ~(MK_VAL|MK_DATE); nNumFormat = 0; mbFlag |= MK_DATA; }
126cdf0e10cSrcweir //	void		SetValue ( double value , sal_uLong nNumFormat = 0 ) { bHasValue = sal_True; nNumFormat = 0;bHasData = sal_True; bDate = sal_False; fValue = value ;}
127cdf0e10cSrcweir 	sal_Bool		IsCaseInsEqual( const ScDPItemData& r ) const;
128cdf0e10cSrcweir 
129cdf0e10cSrcweir 	size_t		Hash() const;
130cdf0e10cSrcweir 
131cdf0e10cSrcweir 	// exact equality
132cdf0e10cSrcweir 	sal_Bool		operator==( const ScDPItemData& r ) const;
133cdf0e10cSrcweir 	// case insensitive equality
134cdf0e10cSrcweir 	static sal_Int32	Compare( const ScDPItemData& rA, const ScDPItemData& rB );
135cdf0e10cSrcweir 
136cdf0e10cSrcweir #ifdef DEBUG
137cdf0e10cSrcweir 	void	dump() const;
138cdf0e10cSrcweir #endif
139cdf0e10cSrcweir 
140cdf0e10cSrcweir public:
141cdf0e10cSrcweir 	sal_Bool IsHasData() const ;
142cdf0e10cSrcweir 	sal_Bool IsHasErr() const ;
143cdf0e10cSrcweir 	sal_Bool IsValue() const;
144cdf0e10cSrcweir 	String	GetString() const ;
145cdf0e10cSrcweir 	double	GetValue() const ;
146cdf0e10cSrcweir 	sal_uLong    GetNumFormat() const ;
147cdf0e10cSrcweir 	sal_Bool HasStringData() const ;
148cdf0e10cSrcweir 	sal_Bool IsDate() const;
149cdf0e10cSrcweir 	sal_Bool HasDatePart() const;
150cdf0e10cSrcweir 	void SetDate( sal_Bool b ) ;
151cdf0e10cSrcweir 
152cdf0e10cSrcweir 	TypedStrData*  CreateTypeString( );
153cdf0e10cSrcweir 	sal_uInt8	 GetType() const;
154cdf0e10cSrcweir 	sal_uInt8 & GetFlag() throw() { return mbFlag; }
155cdf0e10cSrcweir 	const sal_uInt8 & GetFlag() const throw() { return const_cast<ScDPItemData*>(this)->GetFlag(); }
156cdf0e10cSrcweir };
157cdf0e10cSrcweir 
158cdf0e10cSrcweir class SC_DLLPUBLIC ScDPItemDataPool
159cdf0e10cSrcweir {
160cdf0e10cSrcweir public:
161cdf0e10cSrcweir 	// construct
162cdf0e10cSrcweir 	ScDPItemDataPool(void);
163cdf0e10cSrcweir 	ScDPItemDataPool(const ScDPItemDataPool& r);
164cdf0e10cSrcweir 
165cdf0e10cSrcweir 	virtual ~ScDPItemDataPool(void);
166cdf0e10cSrcweir 	virtual const ScDPItemData* getData( sal_Int32 nId  );
167cdf0e10cSrcweir 	virtual sal_Int32 getDataId( const ScDPItemData& aData );
168cdf0e10cSrcweir 	virtual sal_Int32 insertData( const ScDPItemData& aData );
169cdf0e10cSrcweir protected:
170cdf0e10cSrcweir 	struct DataHashFunc : public std::unary_function< const ScDPItemData &, size_t >
171cdf0e10cSrcweir 	{
172cdf0e10cSrcweir 		size_t operator() (const ScDPItemData &rData) const { return rData.Hash(); }
173cdf0e10cSrcweir 	};
174cdf0e10cSrcweir 
175cdf0e10cSrcweir 	typedef ::std::hash_multimap< ScDPItemData, sal_Int32, DataHashFunc > DataHash;
176cdf0e10cSrcweir 
177cdf0e10cSrcweir 	::std::vector< ScDPItemData > maItems;
178cdf0e10cSrcweir 	DataHash  maItemIds;
179cdf0e10cSrcweir };
180cdf0e10cSrcweir 
181cdf0e10cSrcweir class ScDPInfoWnd;
182cdf0e10cSrcweir class ScDocShell;
183cdf0e10cSrcweir class ScTabViewShell;
184cdf0e10cSrcweir namespace ScDPGlobal
185cdf0e10cSrcweir {
186cdf0e10cSrcweir // used for core data
187cdf0e10cSrcweir 	String GetFieldFuncString( const String& rSourceName, sal_uInt16 &rFuncMask, sal_Bool bIsValue );
188cdf0e10cSrcweir 	String GetFuncString( const String &rString, const sal_uInt16 nIndex );
189cdf0e10cSrcweir 	com::sun::star::uno::Reference<com::sun::star::container::XNameAccess> DP_GetMembers( const com::sun::star::uno::Reference<
190cdf0e10cSrcweir 																					  com::sun::star::sheet::XDimensionsSupplier>&rSrc, long nField );
191cdf0e10cSrcweir // common operation
192cdf0e10cSrcweir 	String operator + ( const String & rL, const String &rR );
193cdf0e10cSrcweir 	Rectangle operator *( const Rectangle &rLeft, const std::pair<double,double> & rRight );
194cdf0e10cSrcweir // used for  DataPilot Panel
195cdf0e10cSrcweir     ScDPInfoWnd* GetDPInfoWnd( ScTabViewShell *pViewShell );
196cdf0e10cSrcweir    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 );
197cdf0e10cSrcweir 
198cdf0e10cSrcweir }
199*b4df81e3SWang Lei #define isDateFormat( nNumType ) (!!((nNumType) & NUMBERFORMAT_DATE) )
200*b4df81e3SWang Lei 
201cdf0e10cSrcweir #endif
202