xref: /trunk/main/sc/inc/dpglobal.hxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright IBM Corporation 2009.
6  * Copyright 2009 by Sun Microsystems, Inc.
7  *
8  * OpenOffice.org - a multi-platform office productivity suite
9  *
10  * $RCSfile: dpglobal.hxx,v $
11  * $Revision: 1.0 $
12  *
13  * This file is part of OpenOffice.org.
14  *
15  * OpenOffice.org is free software: you can redistribute it and/or modify
16  * it under the terms of the GNU Lesser General Public License version 3
17  * only, as published by the Free Software Foundation.
18  *
19  * OpenOffice.org is distributed in the hope that it will be useful,
20  * but WITHOUT ANY WARRANTY; without even the implied warranty of
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22  * GNU Lesser General Public License version 3 for more details
23  * (a copy is included in the LICENSE file that accompanied this code).
24  *
25  * You should have received a copy of the GNU Lesser General Public License
26  * version 3 along with OpenOffice.org.  If not, see
27  * <http://www.openoffice.org/license.html>
28  * for a copy of the LGPLv3 License.
29  *
30  ************************************************************************/
31 // Wang Xu Ming - DataPilot migration
32 // Buffer&&Performance
33 //
34 #ifndef _SC_DPGLOBAL_HXX
35 #define _SC_DPGLOBAL_HXX
36 
37 #include <algorithm>
38 #include <list>
39 #include <tools/gen.hxx>
40 #include <tools/debug.hxx>
41 #include <global.hxx>
42 
43 #include <com/sun/star/container/XNamed.hpp>
44 #include <com/sun/star/sheet/XDimensionsSupplier.hpp>
45 
46 #include <com/sun/star/sheet/DataPilotFieldFilter.hpp>
47 #include <com/sun/star/sheet/DataPilotFieldOrientation.hpp>
48 #include <com/sun/star/sheet/DataPilotTableHeaderData.hpp>
49 #include <com/sun/star/sheet/DataPilotTablePositionData.hpp>
50 #include <com/sun/star/sheet/DataPilotTablePositionType.hpp>
51 #include <com/sun/star/sheet/DataPilotTableResultData.hpp>
52 #include <com/sun/star/sheet/DataResultFlags.hpp>
53 #include <com/sun/star/sheet/GeneralFunction.hpp>
54 #include <com/sun/star/sheet/MemberResultFlags.hpp>
55 #include <com/sun/star/sheet/TableFilterField.hpp>
56 #include <com/sun/star/sheet/XDataPilotMemberResults.hpp>
57 #include <com/sun/star/sheet/XDataPilotResults.hpp>
58 #include <com/sun/star/sheet/XHierarchiesSupplier.hpp>
59 #include <com/sun/star/sheet/XLevelsSupplier.hpp>
60 
61 
62 // moved from fieldwnd.hxx, see also SC_DAPI_MAXFIELDS
63 #define MAX_LABELS  256
64 
65 #define		PIVOT_MAXFUNC			11
66 #define		PIVOT_FUNC_NONE			0x0000
67 #define     PIVOT_FUNC_SUM			0x0001
68 #define		PIVOT_FUNC_COUNT		0x0002
69 #define		PIVOT_FUNC_AVERAGE		0x0004
70 #define		PIVOT_FUNC_MAX			0x0008
71 #define		PIVOT_FUNC_MIN			0x0010
72 #define		PIVOT_FUNC_PRODUCT		0x0020
73 #define		PIVOT_FUNC_COUNT_NUM	0x0040
74 #define		PIVOT_FUNC_STD_DEV		0x0080
75 #define		PIVOT_FUNC_STD_DEVP		0x0100
76 #define		PIVOT_FUNC_STD_VAR		0x0200
77 #define		PIVOT_FUNC_STD_VARP		0x0400
78 #define		PIVOT_FUNC_AUTO			0x1000
79 
80 #define DATA_RENAME_SEPARATOR		"_"
81 #define __MAX_NUM_LEN 64
82 #define __DECIMALPLACE	18
83 
84 #define DP_PROP_COLUMNGRAND			"ColumnGrand"
85 #define DP_PROP_FUNCTION			"Function"
86 #define DP_PROP_IGNOREEMPTY			"IgnoreEmptyRows"
87 #define DP_PROP_ISDATALAYOUT		"IsDataLayoutDimension"
88 #define DP_PROP_ISVISIBLE			"IsVisible"
89 #define DP_PROP_ORIENTATION			"Orientation"
90 #define DP_PROP_REPEATIFEMPTY		"RepeatIfEmpty"
91 #define DP_PROP_ROWGRAND			"RowGrand"
92 #define DP_PROP_SHOWDETAILS			"ShowDetails"
93 #define DP_PROP_SHOWEMPTY			"ShowEmpty"
94 #define DP_PROP_SUBTOTALS			"SubTotals"
95 #define DP_PROP_USEDHIERARCHY		"UsedHierarchy"
96 #define DP_PROP_FILTER				"Filter"
97 #define DP_PROP_POSITION            "Position"
98 
99 #define DBG_TRACESTR( x )  \
100 	{\
101 		ByteString aTemp( x , RTL_TEXTENCODING_UTF8 ); \
102 		DBG_TRACE( aTemp.GetBuffer() );\
103 	}
104 
105 class TypedStrData;
106 class ScDPObject;
107 
108 class SC_DLLPUBLIC ScDPItemData
109 {
110 public:
111 	enum { MK_VAL = 0x01, MK_DATA = MK_VAL<<1, MK_ERR = MK_DATA<<1, MK_DATE = MK_ERR<<1, MK_DATEPART = MK_DATE<<1 };
112 private:
113 	union
114 	{
115 		sal_uLong	nNumFormat;
116 		sal_Int32 mnDatePart;
117 	};
118 
119 	String	aString;
120 	double	fValue;
121 	sal_uInt8	mbFlag;
122 	//sal_Bool	bHasValue: 1 ;
123 	//sal_Bool	bHasData: 1;
124 	//sal_Bool	bErr: 1;
125 
126 	friend class ScDPTableDataCache;
127 public:
128 	ScDPItemData() : nNumFormat( 0 ), fValue(0.0), mbFlag( 0 ){}
129 	ScDPItemData( sal_uLong nNF, const String & rS, double fV, sal_uInt8 bF ):nNumFormat(nNF), aString(rS), fValue(fV), mbFlag( bF ){}
130 	ScDPItemData( const String& rS, double fV = 0.0, sal_Bool bHV = sal_False, const sal_uLong nNumFormat = 0 , sal_Bool bData = sal_True) ;
131 	ScDPItemData( ScDocument* pDoc, SCROW nRow, sal_uInt16 nCol, sal_uInt16 nDocTab );
132 
133 	void		SetString( const String& rS ) { aString = rS; mbFlag &= ~(MK_VAL|MK_DATE); nNumFormat = 0; mbFlag |= MK_DATA; }
134 //	void		SetValue ( double value , sal_uLong nNumFormat = 0 ) { bHasValue = sal_True; nNumFormat = 0;bHasData = sal_True; bDate = sal_False; fValue = value ;}
135 	sal_Bool		IsCaseInsEqual( const ScDPItemData& r ) const;
136 
137 	size_t		Hash() const;
138 
139 	// exact equality
140 	sal_Bool		operator==( const ScDPItemData& r ) const;
141 	// case insensitive equality
142 	static sal_Int32	Compare( const ScDPItemData& rA, const ScDPItemData& rB );
143 
144 #ifdef DEBUG
145 	void	dump() const;
146 #endif
147 
148 public:
149 	sal_Bool IsHasData() const ;
150 	sal_Bool IsHasErr() const ;
151 	sal_Bool IsValue() const;
152 	String	GetString() const ;
153 	double	GetValue() const ;
154 	sal_uLong    GetNumFormat() const ;
155 	sal_Bool HasStringData() const ;
156 	sal_Bool IsDate() const;
157 	sal_Bool HasDatePart() const;
158 	void SetDate( sal_Bool b ) ;
159 
160 	TypedStrData*  CreateTypeString( );
161 	sal_uInt8	 GetType() const;
162 	sal_uInt8 & GetFlag() throw() { return mbFlag; }
163 	const sal_uInt8 & GetFlag() const throw() { return const_cast<ScDPItemData*>(this)->GetFlag(); }
164 };
165 
166 class SC_DLLPUBLIC ScDPItemDataPool
167 {
168 public:
169 	// construct
170 	ScDPItemDataPool(void);
171 	ScDPItemDataPool(const ScDPItemDataPool& r);
172 
173 	virtual ~ScDPItemDataPool(void);
174 	virtual const ScDPItemData* getData( sal_Int32 nId  );
175 	virtual sal_Int32 getDataId( const ScDPItemData& aData );
176 	virtual sal_Int32 insertData( const ScDPItemData& aData );
177 protected:
178 	struct DataHashFunc : public std::unary_function< const ScDPItemData &, size_t >
179 	{
180 		size_t operator() (const ScDPItemData &rData) const { return rData.Hash(); }
181 	};
182 
183 	typedef ::std::hash_multimap< ScDPItemData, sal_Int32, DataHashFunc > DataHash;
184 
185 	::std::vector< ScDPItemData > maItems;
186 	DataHash  maItemIds;
187 };
188 
189 class ScDPInfoWnd;
190 class ScDocShell;
191 class ScTabViewShell;
192 namespace ScDPGlobal
193 {
194 // used for core data
195 	String GetFieldFuncString( const String& rSourceName, sal_uInt16 &rFuncMask, sal_Bool bIsValue );
196 	String GetFuncString( const String &rString, const sal_uInt16 nIndex );
197 	com::sun::star::uno::Reference<com::sun::star::container::XNameAccess> DP_GetMembers( const com::sun::star::uno::Reference<
198 																					  com::sun::star::sheet::XDimensionsSupplier>&rSrc, long nField );
199 // common operation
200 	String operator + ( const String & rL, const String &rR );
201 	Rectangle operator *( const Rectangle &rLeft, const std::pair<double,double> & rRight );
202 // used for  DataPilot Panel
203     ScDPInfoWnd* GetDPInfoWnd( ScTabViewShell *pViewShell );
204    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 );
205 
206 }
207 #endif
208