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