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