xref: /AOO41X/main/sc/source/ui/unoobj/datauno.cxx (revision b3f79822e811ac3493b185030a72c3c5a51f32d8)
1*b3f79822SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*b3f79822SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*b3f79822SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*b3f79822SAndrew Rist  * distributed with this work for additional information
6*b3f79822SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*b3f79822SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*b3f79822SAndrew Rist  * "License"); you may not use this file except in compliance
9*b3f79822SAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11*b3f79822SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13*b3f79822SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*b3f79822SAndrew Rist  * software distributed under the License is distributed on an
15*b3f79822SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*b3f79822SAndrew Rist  * KIND, either express or implied.  See the License for the
17*b3f79822SAndrew Rist  * specific language governing permissions and limitations
18*b3f79822SAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20*b3f79822SAndrew Rist  *************************************************************/
21*b3f79822SAndrew Rist 
22*b3f79822SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sc.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir 
28cdf0e10cSrcweir 
29cdf0e10cSrcweir #include <tools/debug.hxx>
30cdf0e10cSrcweir #include <svl/smplhint.hxx>
31cdf0e10cSrcweir #include <svl/zforlist.hxx>
32cdf0e10cSrcweir #include <rtl/uuid.h>
33cdf0e10cSrcweir 
34cdf0e10cSrcweir #include <com/sun/star/awt/XBitmap.hpp>
35cdf0e10cSrcweir #include <com/sun/star/util/SortField.hpp>
36cdf0e10cSrcweir #include <com/sun/star/table/TableSortField.hpp>
37cdf0e10cSrcweir #include <com/sun/star/beans/PropertyAttribute.hpp>
38cdf0e10cSrcweir #include <com/sun/star/table/TableOrientation.hpp>
39cdf0e10cSrcweir #include <com/sun/star/table/CellRangeAddress.hpp>
40cdf0e10cSrcweir #include <com/sun/star/sheet/DataImportMode.hpp>
41cdf0e10cSrcweir #include <com/sun/star/sheet/FilterOperator2.hpp>
42cdf0e10cSrcweir #include <com/sun/star/sheet/TableFilterField2.hpp>
43cdf0e10cSrcweir 
44cdf0e10cSrcweir #include "datauno.hxx"
45cdf0e10cSrcweir #include "dapiuno.hxx"
46cdf0e10cSrcweir #include "cellsuno.hxx"
47cdf0e10cSrcweir #include "miscuno.hxx"
48cdf0e10cSrcweir #include "targuno.hxx"
49cdf0e10cSrcweir #include "rangeutl.hxx"
50cdf0e10cSrcweir #include "dbcolect.hxx"
51cdf0e10cSrcweir #include "docsh.hxx"
52cdf0e10cSrcweir #include "dbdocfun.hxx"
53cdf0e10cSrcweir #include "unoguard.hxx"
54cdf0e10cSrcweir #include "unonames.hxx"
55cdf0e10cSrcweir #include "globstr.hrc"
56cdf0e10cSrcweir #ifndef SC_CONVUNO_HXX
57cdf0e10cSrcweir #include "convuno.hxx"
58cdf0e10cSrcweir #include "hints.hxx"
59cdf0e10cSrcweir #endif
60cdf0e10cSrcweir #include "attrib.hxx"
61cdf0e10cSrcweir #include "dpshttab.hxx"
62cdf0e10cSrcweir #include <comphelper/extract.hxx>
63cdf0e10cSrcweir #include <svx/dataaccessdescriptor.hxx>
64cdf0e10cSrcweir 
65cdf0e10cSrcweir using namespace com::sun::star;
66cdf0e10cSrcweir 
67cdf0e10cSrcweir SV_IMPL_PTRARR( XDBRefreshListenerArr_Impl, XDBRefreshListenerPtr );
68cdf0e10cSrcweir 
69cdf0e10cSrcweir //------------------------------------------------------------------------
70cdf0e10cSrcweir 
71cdf0e10cSrcweir //	alles ohne Which-ID, Map nur fuer PropertySetInfo
72cdf0e10cSrcweir 
lcl_GetSubTotalPropertyMap()73cdf0e10cSrcweir const SfxItemPropertyMapEntry* lcl_GetSubTotalPropertyMap()
74cdf0e10cSrcweir {
75cdf0e10cSrcweir 	// some old property names are for 5.2 compatibility
76cdf0e10cSrcweir 
77cdf0e10cSrcweir     static SfxItemPropertyMapEntry aSubTotalPropertyMap_Impl[] =
78cdf0e10cSrcweir 	{
79cdf0e10cSrcweir         {MAP_CHAR_LEN(SC_UNONAME_BINDFMT),  0,  &getBooleanCppuType(),       0, 0},
80cdf0e10cSrcweir         {MAP_CHAR_LEN(SC_UNONAME_CASE),     0,  &getBooleanCppuType(),       0, 0},
81cdf0e10cSrcweir         {MAP_CHAR_LEN(SC_UNONAME_ENABSORT), 0,  &getBooleanCppuType(),       0, 0},
82cdf0e10cSrcweir         {MAP_CHAR_LEN(SC_UNONAME_ENUSLIST), 0,  &getBooleanCppuType(),       0, 0},
83cdf0e10cSrcweir         {MAP_CHAR_LEN(SC_UNONAME_FORMATS),  0,  &getBooleanCppuType(),       0, 0},
84cdf0e10cSrcweir         {MAP_CHAR_LEN(SC_UNONAME_INSBRK),   0,  &getBooleanCppuType(),       0, 0},
85cdf0e10cSrcweir         {MAP_CHAR_LEN(SC_UNONAME_ISCASE),   0,  &getBooleanCppuType(),       0, 0},
86cdf0e10cSrcweir         {MAP_CHAR_LEN(SC_UNONAME_MAXFLD),   0,  &getCppuType((sal_Int32*)0), beans::PropertyAttribute::READONLY, 0},
87cdf0e10cSrcweir         {MAP_CHAR_LEN(SC_UNONAME_SORTASC),  0,  &getBooleanCppuType(),       0, 0},
88cdf0e10cSrcweir         {MAP_CHAR_LEN(SC_UNONAME_ULIST),    0,  &getBooleanCppuType(),       0, 0},
89cdf0e10cSrcweir         {MAP_CHAR_LEN(SC_UNONAME_UINDEX),   0,  &getCppuType((sal_Int32*)0), 0, 0},
90cdf0e10cSrcweir         {MAP_CHAR_LEN(SC_UNONAME_USINDEX),  0,  &getCppuType((sal_Int32*)0), 0, 0},
91cdf0e10cSrcweir         {0,0,0,0,0,0}
92cdf0e10cSrcweir 	};
93cdf0e10cSrcweir 	return aSubTotalPropertyMap_Impl;
94cdf0e10cSrcweir }
95cdf0e10cSrcweir 
lcl_GetFilterPropertyMap()96cdf0e10cSrcweir const SfxItemPropertyMapEntry* lcl_GetFilterPropertyMap()
97cdf0e10cSrcweir {
98cdf0e10cSrcweir     static SfxItemPropertyMapEntry aFilterPropertyMap_Impl[] =
99cdf0e10cSrcweir 	{
100cdf0e10cSrcweir         {MAP_CHAR_LEN(SC_UNONAME_CONTHDR),  0,  &getBooleanCppuType(),                      0, 0},
101cdf0e10cSrcweir         {MAP_CHAR_LEN(SC_UNONAME_COPYOUT),  0,  &getBooleanCppuType(),                      0, 0},
102cdf0e10cSrcweir         {MAP_CHAR_LEN(SC_UNONAME_ISCASE),   0,  &getBooleanCppuType(),                      0, 0},
103cdf0e10cSrcweir         {MAP_CHAR_LEN(SC_UNONAME_MAXFLD),   0,  &getCppuType((sal_Int32*)0),                beans::PropertyAttribute::READONLY, 0},
104cdf0e10cSrcweir         {MAP_CHAR_LEN(SC_UNONAME_ORIENT),   0,  &getCppuType((table::TableOrientation*)0),  0, 0},
105cdf0e10cSrcweir         {MAP_CHAR_LEN(SC_UNONAME_OUTPOS),   0,  &getCppuType((table::CellAddress*)0),       0, 0},
106cdf0e10cSrcweir         {MAP_CHAR_LEN(SC_UNONAME_SAVEOUT),  0,  &getBooleanCppuType(),                      0, 0},
107cdf0e10cSrcweir         {MAP_CHAR_LEN(SC_UNONAME_SKIPDUP),  0,  &getBooleanCppuType(),                      0, 0},
108cdf0e10cSrcweir         {MAP_CHAR_LEN(SC_UNONAME_USEREGEX), 0,  &getBooleanCppuType(),                      0, 0},
109cdf0e10cSrcweir         {0,0,0,0,0,0}
110cdf0e10cSrcweir 	};
111cdf0e10cSrcweir 	return aFilterPropertyMap_Impl;
112cdf0e10cSrcweir }
113cdf0e10cSrcweir 
lcl_GetDBRangePropertyMap()114cdf0e10cSrcweir const SfxItemPropertyMapEntry* lcl_GetDBRangePropertyMap()
115cdf0e10cSrcweir {
116cdf0e10cSrcweir     static SfxItemPropertyMapEntry aDBRangePropertyMap_Impl[] =
117cdf0e10cSrcweir 	{
118cdf0e10cSrcweir         {MAP_CHAR_LEN(SC_UNONAME_AUTOFLT),  0,  &getBooleanCppuType(),                      0, 0},
119cdf0e10cSrcweir         {MAP_CHAR_LEN(SC_UNONAME_FLTCRT),   0,  &getCppuType((table::CellRangeAddress*)0),  0, 0},
120cdf0e10cSrcweir         {MAP_CHAR_LEN(SC_UNONAME_FROMSELECT),0, &getBooleanCppuType(),                      0, 0},
121cdf0e10cSrcweir         {MAP_CHAR_LEN(SC_UNONAME_ISUSER),   0,  &getBooleanCppuType(),           beans::PropertyAttribute::READONLY, 0 },
122cdf0e10cSrcweir         {MAP_CHAR_LEN(SC_UNONAME_KEEPFORM), 0,  &getBooleanCppuType(),                      0, 0},
123cdf0e10cSrcweir         {MAP_CHAR_LEN(SC_UNO_LINKDISPBIT),  0,  &getCppuType((uno::Reference<awt::XBitmap>*)0), beans::PropertyAttribute::READONLY, 0 },
124cdf0e10cSrcweir         {MAP_CHAR_LEN(SC_UNO_LINKDISPNAME), 0,  &getCppuType((rtl::OUString*)0), beans::PropertyAttribute::READONLY, 0 },
125cdf0e10cSrcweir         {MAP_CHAR_LEN(SC_UNONAME_MOVCELLS), 0,  &getBooleanCppuType(),                      0, 0},
126cdf0e10cSrcweir         {MAP_CHAR_LEN(SC_UNONAME_REFPERIOD), 0, &getCppuType((sal_Int32*)0),                0, 0},
127cdf0e10cSrcweir         {MAP_CHAR_LEN(SC_UNONAME_STRIPDAT), 0,  &getBooleanCppuType(),                      0, 0},
128cdf0e10cSrcweir         {MAP_CHAR_LEN(SC_UNONAME_TOKENINDEX),0, &getCppuType((sal_Int32*)0),     beans::PropertyAttribute::READONLY, 0 },
129cdf0e10cSrcweir         {MAP_CHAR_LEN(SC_UNONAME_USEFLTCRT),0,  &getBooleanCppuType(),                      0, 0},
130cdf0e10cSrcweir         {0,0,0,0,0,0}
131cdf0e10cSrcweir 	};
132cdf0e10cSrcweir 	return aDBRangePropertyMap_Impl;
133cdf0e10cSrcweir }
134cdf0e10cSrcweir 
135cdf0e10cSrcweir 
136cdf0e10cSrcweir //------------------------------------------------------------------------
137cdf0e10cSrcweir 
138cdf0e10cSrcweir #define SCDATABASERANGEOBJ_SERVICE		"com.sun.star.sheet.DatabaseRange"
139cdf0e10cSrcweir 
140cdf0e10cSrcweir SC_SIMPLE_SERVICE_INFO( ScConsolidationDescriptor, "ScConsolidationDescriptor", "com.sun.star.sheet.ConsolidationDescriptor" )
141cdf0e10cSrcweir SC_SIMPLE_SERVICE_INFO( ScDatabaseRangesObj, "ScDatabaseRangesObj", "com.sun.star.sheet.DatabaseRanges" )
142cdf0e10cSrcweir SC_SIMPLE_SERVICE_INFO( ScFilterDescriptorBase, "ScFilterDescriptorBase", "com.sun.star.sheet.SheetFilterDescriptor" )
143cdf0e10cSrcweir SC_SIMPLE_SERVICE_INFO( ScSubTotalDescriptorBase, "ScSubTotalDescriptorBase", "com.sun.star.sheet.SubTotalDescriptor" )
144cdf0e10cSrcweir SC_SIMPLE_SERVICE_INFO( ScSubTotalFieldObj, "ScSubTotalFieldObj", "com.sun.star.sheet.SubTotalField" )
145cdf0e10cSrcweir 
146cdf0e10cSrcweir 
147cdf0e10cSrcweir //------------------------------------------------------------------------
148cdf0e10cSrcweir 
149cdf0e10cSrcweir // static
GeneralToSubTotal(sheet::GeneralFunction eSummary)150cdf0e10cSrcweir ScSubTotalFunc ScDataUnoConversion::GeneralToSubTotal( sheet::GeneralFunction eSummary )
151cdf0e10cSrcweir {
152cdf0e10cSrcweir 	ScSubTotalFunc eSubTotal;
153cdf0e10cSrcweir 	switch (eSummary)
154cdf0e10cSrcweir 	{
155cdf0e10cSrcweir 		case sheet::GeneralFunction_NONE:		eSubTotal = SUBTOTAL_FUNC_NONE;	break;
156cdf0e10cSrcweir 		case sheet::GeneralFunction_SUM:		eSubTotal = SUBTOTAL_FUNC_SUM;	break;
157cdf0e10cSrcweir 		case sheet::GeneralFunction_COUNT:		eSubTotal = SUBTOTAL_FUNC_CNT2;	break;
158cdf0e10cSrcweir 		case sheet::GeneralFunction_AVERAGE:	eSubTotal = SUBTOTAL_FUNC_AVE;	break;
159cdf0e10cSrcweir 		case sheet::GeneralFunction_MAX:		eSubTotal = SUBTOTAL_FUNC_MAX;	break;
160cdf0e10cSrcweir 		case sheet::GeneralFunction_MIN:		eSubTotal = SUBTOTAL_FUNC_MIN;	break;
161cdf0e10cSrcweir 		case sheet::GeneralFunction_PRODUCT:	eSubTotal = SUBTOTAL_FUNC_PROD;	break;
162cdf0e10cSrcweir 		case sheet::GeneralFunction_COUNTNUMS:	eSubTotal = SUBTOTAL_FUNC_CNT;	break;
163cdf0e10cSrcweir 		case sheet::GeneralFunction_STDEV:		eSubTotal = SUBTOTAL_FUNC_STD;	break;
164cdf0e10cSrcweir 		case sheet::GeneralFunction_STDEVP:		eSubTotal = SUBTOTAL_FUNC_STDP;	break;
165cdf0e10cSrcweir 		case sheet::GeneralFunction_VAR:		eSubTotal = SUBTOTAL_FUNC_VAR;	break;
166cdf0e10cSrcweir 		case sheet::GeneralFunction_VARP:		eSubTotal = SUBTOTAL_FUNC_VARP;	break;
167cdf0e10cSrcweir 		case sheet::GeneralFunction_AUTO:
168cdf0e10cSrcweir 		default:
169cdf0e10cSrcweir 			DBG_ERROR("GeneralToSubTotal: falscher enum");
170cdf0e10cSrcweir 			eSubTotal = SUBTOTAL_FUNC_NONE;
171cdf0e10cSrcweir 	}
172cdf0e10cSrcweir 	return eSubTotal;
173cdf0e10cSrcweir }
174cdf0e10cSrcweir 
175cdf0e10cSrcweir // static
SubTotalToGeneral(ScSubTotalFunc eSubTotal)176cdf0e10cSrcweir sheet::GeneralFunction	ScDataUnoConversion::SubTotalToGeneral( ScSubTotalFunc eSubTotal )
177cdf0e10cSrcweir {
178cdf0e10cSrcweir 	sheet::GeneralFunction eGeneral;
179cdf0e10cSrcweir 	switch (eSubTotal)
180cdf0e10cSrcweir 	{
181cdf0e10cSrcweir 		case SUBTOTAL_FUNC_NONE: eGeneral = sheet::GeneralFunction_NONE;	  break;
182cdf0e10cSrcweir 		case SUBTOTAL_FUNC_AVE:  eGeneral = sheet::GeneralFunction_AVERAGE;	  break;
183cdf0e10cSrcweir 		case SUBTOTAL_FUNC_CNT:  eGeneral = sheet::GeneralFunction_COUNTNUMS; break;
184cdf0e10cSrcweir 		case SUBTOTAL_FUNC_CNT2: eGeneral = sheet::GeneralFunction_COUNT;	  break;
185cdf0e10cSrcweir 		case SUBTOTAL_FUNC_MAX:  eGeneral = sheet::GeneralFunction_MAX;		  break;
186cdf0e10cSrcweir 		case SUBTOTAL_FUNC_MIN:  eGeneral = sheet::GeneralFunction_MIN;		  break;
187cdf0e10cSrcweir 		case SUBTOTAL_FUNC_PROD: eGeneral = sheet::GeneralFunction_PRODUCT;	  break;
188cdf0e10cSrcweir 		case SUBTOTAL_FUNC_STD:  eGeneral = sheet::GeneralFunction_STDEV;	  break;
189cdf0e10cSrcweir 		case SUBTOTAL_FUNC_STDP: eGeneral = sheet::GeneralFunction_STDEVP;	  break;
190cdf0e10cSrcweir 		case SUBTOTAL_FUNC_SUM:  eGeneral = sheet::GeneralFunction_SUM;		  break;
191cdf0e10cSrcweir 		case SUBTOTAL_FUNC_VAR:  eGeneral = sheet::GeneralFunction_VAR;		  break;
192cdf0e10cSrcweir 		case SUBTOTAL_FUNC_VARP: eGeneral = sheet::GeneralFunction_VARP;	  break;
193cdf0e10cSrcweir 		default:
194cdf0e10cSrcweir 			DBG_ERROR("SubTotalToGeneral: falscher enum");
195cdf0e10cSrcweir 			eGeneral = sheet::GeneralFunction_NONE;
196cdf0e10cSrcweir 			break;
197cdf0e10cSrcweir 	}
198cdf0e10cSrcweir 	return eGeneral;
199cdf0e10cSrcweir }
200cdf0e10cSrcweir 
201cdf0e10cSrcweir //------------------------------------------------------------------------
202cdf0e10cSrcweir 
203cdf0e10cSrcweir //	ScImportDescriptor: alles static
204cdf0e10cSrcweir 
GetPropertyCount()205cdf0e10cSrcweir long ScImportDescriptor::GetPropertyCount()
206cdf0e10cSrcweir {
207cdf0e10cSrcweir 	return 4;
208cdf0e10cSrcweir }
209cdf0e10cSrcweir 
FillProperties(uno::Sequence<beans::PropertyValue> & rSeq,const ScImportParam & rParam)210cdf0e10cSrcweir void ScImportDescriptor::FillProperties( uno::Sequence<beans::PropertyValue>& rSeq, const ScImportParam& rParam )
211cdf0e10cSrcweir {
212cdf0e10cSrcweir 	DBG_ASSERT( rSeq.getLength() == GetPropertyCount(), "falscher Count" );
213cdf0e10cSrcweir 
214cdf0e10cSrcweir 	beans::PropertyValue* pArray = rSeq.getArray();
215cdf0e10cSrcweir 
216cdf0e10cSrcweir 	sheet::DataImportMode eMode = sheet::DataImportMode_NONE;
217cdf0e10cSrcweir 	if ( rParam.bImport )
218cdf0e10cSrcweir 	{
219cdf0e10cSrcweir 		if ( rParam.bSql )
220cdf0e10cSrcweir 			eMode = sheet::DataImportMode_SQL;
221cdf0e10cSrcweir 		else if ( rParam.nType == ScDbQuery )
222cdf0e10cSrcweir 			eMode = sheet::DataImportMode_QUERY;
223cdf0e10cSrcweir 		else
224cdf0e10cSrcweir 			eMode = sheet::DataImportMode_TABLE;		// Type ist immer ScDbQuery oder ScDbTable
225cdf0e10cSrcweir 	}
226cdf0e10cSrcweir 
227cdf0e10cSrcweir     ::svx::ODataAccessDescriptor aDescriptor;
228cdf0e10cSrcweir 	aDescriptor.setDataSource(rParam.aDBName);
229cdf0e10cSrcweir     if (aDescriptor.has( svx::daDataSource ))
230cdf0e10cSrcweir     {
231cdf0e10cSrcweir 	    pArray[0].Name = rtl::OUString::createFromAscii( SC_UNONAME_DBNAME );
232cdf0e10cSrcweir 	    pArray[0].Value <<= rtl::OUString( rParam.aDBName );
233cdf0e10cSrcweir     }
234cdf0e10cSrcweir     else if (aDescriptor.has( svx::daConnectionResource ))
235cdf0e10cSrcweir     {
236cdf0e10cSrcweir 	    pArray[0].Name = rtl::OUString::createFromAscii( SC_UNONAME_CONRES );
237cdf0e10cSrcweir 	    pArray[0].Value <<= rtl::OUString( rParam.aDBName );
238cdf0e10cSrcweir     }
239cdf0e10cSrcweir 
240cdf0e10cSrcweir 	pArray[1].Name = rtl::OUString::createFromAscii( SC_UNONAME_SRCTYPE );
241cdf0e10cSrcweir 	pArray[1].Value <<= eMode;
242cdf0e10cSrcweir 
243cdf0e10cSrcweir 	pArray[2].Name = rtl::OUString::createFromAscii( SC_UNONAME_SRCOBJ );
244cdf0e10cSrcweir 	pArray[2].Value <<= rtl::OUString( rParam.aStatement );
245cdf0e10cSrcweir 
246cdf0e10cSrcweir 	pArray[3].Name = rtl::OUString::createFromAscii( SC_UNONAME_ISNATIVE );
247cdf0e10cSrcweir 	ScUnoHelpFunctions::SetBoolInAny( pArray[3].Value, rParam.bNative );
248cdf0e10cSrcweir }
249cdf0e10cSrcweir 
FillImportParam(ScImportParam & rParam,const uno::Sequence<beans::PropertyValue> & rSeq)250cdf0e10cSrcweir void ScImportDescriptor::FillImportParam( ScImportParam& rParam, const uno::Sequence<beans::PropertyValue>& rSeq )
251cdf0e10cSrcweir {
252cdf0e10cSrcweir 	rtl::OUString aStrVal;
253cdf0e10cSrcweir 	const beans::PropertyValue* pPropArray = rSeq.getConstArray();
254cdf0e10cSrcweir 	long nPropCount = rSeq.getLength();
255cdf0e10cSrcweir 	for (long i = 0; i < nPropCount; i++)
256cdf0e10cSrcweir 	{
257cdf0e10cSrcweir 		const beans::PropertyValue& rProp = pPropArray[i];
258cdf0e10cSrcweir 		String aPropName(rProp.Name);
259cdf0e10cSrcweir 
260cdf0e10cSrcweir 		if (aPropName.EqualsAscii( SC_UNONAME_ISNATIVE ))
261cdf0e10cSrcweir 			rParam.bNative = ScUnoHelpFunctions::GetBoolFromAny( rProp.Value );
262cdf0e10cSrcweir 		else if (aPropName.EqualsAscii( SC_UNONAME_DBNAME ))
263cdf0e10cSrcweir 		{
264cdf0e10cSrcweir 			if ( rProp.Value >>= aStrVal )
265cdf0e10cSrcweir 				rParam.aDBName = String( aStrVal );
266cdf0e10cSrcweir 		}
267cdf0e10cSrcweir 		else if (aPropName.EqualsAscii( SC_UNONAME_CONRES ))
268cdf0e10cSrcweir 		{
269cdf0e10cSrcweir 			if ( rProp.Value >>= aStrVal )
270cdf0e10cSrcweir 				rParam.aDBName = String( aStrVal );
271cdf0e10cSrcweir 		}
272cdf0e10cSrcweir 		else if (aPropName.EqualsAscii( SC_UNONAME_SRCOBJ ))
273cdf0e10cSrcweir 		{
274cdf0e10cSrcweir 			if ( rProp.Value >>= aStrVal )
275cdf0e10cSrcweir 				rParam.aStatement = String( aStrVal );
276cdf0e10cSrcweir 		}
277cdf0e10cSrcweir 		else if (aPropName.EqualsAscii( SC_UNONAME_SRCTYPE ))
278cdf0e10cSrcweir 		{
279cdf0e10cSrcweir 			//!	test for correct enum type?
280cdf0e10cSrcweir 			sheet::DataImportMode eMode = (sheet::DataImportMode)
281cdf0e10cSrcweir 								ScUnoHelpFunctions::GetEnumFromAny( rProp.Value );
282cdf0e10cSrcweir 			switch (eMode)
283cdf0e10cSrcweir 			{
284cdf0e10cSrcweir 				case sheet::DataImportMode_NONE:
285cdf0e10cSrcweir 					rParam.bImport = sal_False;
286cdf0e10cSrcweir 					break;
287cdf0e10cSrcweir 				case sheet::DataImportMode_SQL:
288cdf0e10cSrcweir 					rParam.bImport = sal_True;
289cdf0e10cSrcweir 					rParam.bSql    = sal_True;
290cdf0e10cSrcweir 					break;
291cdf0e10cSrcweir 				case sheet::DataImportMode_TABLE:
292cdf0e10cSrcweir 					rParam.bImport = sal_True;
293cdf0e10cSrcweir 					rParam.bSql    = sal_False;
294cdf0e10cSrcweir 					rParam.nType   = ScDbTable;
295cdf0e10cSrcweir 					break;
296cdf0e10cSrcweir 				case sheet::DataImportMode_QUERY:
297cdf0e10cSrcweir 					rParam.bImport = sal_True;
298cdf0e10cSrcweir 					rParam.bSql    = sal_False;
299cdf0e10cSrcweir 					rParam.nType   = ScDbQuery;
300cdf0e10cSrcweir 					break;
301cdf0e10cSrcweir 				default:
302cdf0e10cSrcweir 					DBG_ERROR("falscher Mode");
303cdf0e10cSrcweir 					rParam.bImport = sal_False;
304cdf0e10cSrcweir 			}
305cdf0e10cSrcweir 		}
306cdf0e10cSrcweir 	}
307cdf0e10cSrcweir }
308cdf0e10cSrcweir 
309cdf0e10cSrcweir //------------------------------------------------------------------------
310cdf0e10cSrcweir 
311cdf0e10cSrcweir //	ScSortDescriptor: alles static
312cdf0e10cSrcweir 
313cdf0e10cSrcweir //!	SortAscending muss aus der SheetSortDescriptor service-Beschreibung raus
314cdf0e10cSrcweir 
GetPropertyCount()315cdf0e10cSrcweir long ScSortDescriptor::GetPropertyCount()
316cdf0e10cSrcweir {
317cdf0e10cSrcweir 	return 9;		// TableSortDescriptor and SheetSortDescriptor
318cdf0e10cSrcweir }
319cdf0e10cSrcweir 
FillProperties(uno::Sequence<beans::PropertyValue> & rSeq,const ScSortParam & rParam)320cdf0e10cSrcweir void ScSortDescriptor::FillProperties( uno::Sequence<beans::PropertyValue>& rSeq, const ScSortParam& rParam )
321cdf0e10cSrcweir {
322cdf0e10cSrcweir 	DBG_ASSERT( rSeq.getLength() == GetPropertyCount(), "falscher Count" );
323cdf0e10cSrcweir 
324cdf0e10cSrcweir 	beans::PropertyValue* pArray = rSeq.getArray();
325cdf0e10cSrcweir 
326cdf0e10cSrcweir 	//	Uno-Werte zusammensuchen
327cdf0e10cSrcweir 
328cdf0e10cSrcweir 	table::CellAddress aOutPos;
329cdf0e10cSrcweir 	aOutPos.Sheet  = rParam.nDestTab;
330cdf0e10cSrcweir 	aOutPos.Column = rParam.nDestCol;
331cdf0e10cSrcweir 	aOutPos.Row    = rParam.nDestRow;
332cdf0e10cSrcweir 
333cdf0e10cSrcweir 	sal_uInt16 nSortCount = 0;
334cdf0e10cSrcweir 	while ( nSortCount < MAXSORT && rParam.bDoSort[nSortCount] )
335cdf0e10cSrcweir 		++nSortCount;
336cdf0e10cSrcweir 
337cdf0e10cSrcweir 	uno::Sequence<table::TableSortField> aFields(nSortCount);
338cdf0e10cSrcweir 	if (nSortCount)
339cdf0e10cSrcweir 	{
340cdf0e10cSrcweir 		table::TableSortField* pFieldArray = aFields.getArray();
341cdf0e10cSrcweir 		for (sal_uInt16 i=0; i<nSortCount; i++)
342cdf0e10cSrcweir 		{
343cdf0e10cSrcweir 			pFieldArray[i].Field		 = rParam.nField[i];
344cdf0e10cSrcweir 			pFieldArray[i].IsAscending   = rParam.bAscending[i];
345cdf0e10cSrcweir 			pFieldArray[i].FieldType	 = table::TableSortFieldType_AUTOMATIC;		// immer Automatic
346cdf0e10cSrcweir             pFieldArray[i].IsCaseSensitive = rParam.bCaseSens;
347cdf0e10cSrcweir             pFieldArray[i].CollatorLocale = rParam.aCollatorLocale;
348cdf0e10cSrcweir             pFieldArray[i].CollatorAlgorithm = rtl::OUString( rParam.aCollatorAlgorithm );
349cdf0e10cSrcweir 		}
350cdf0e10cSrcweir 	}
351cdf0e10cSrcweir 
352cdf0e10cSrcweir 	//	Sequence fuellen
353cdf0e10cSrcweir 
354cdf0e10cSrcweir 	pArray[0].Name = rtl::OUString::createFromAscii( SC_UNONAME_ISSORTCOLUMNS );
355cdf0e10cSrcweir     pArray[0].Value = ::cppu::bool2any(!rParam.bByRow);
356cdf0e10cSrcweir 
357cdf0e10cSrcweir 	pArray[1].Name = rtl::OUString::createFromAscii( SC_UNONAME_CONTHDR );
358cdf0e10cSrcweir 	ScUnoHelpFunctions::SetBoolInAny( pArray[1].Value, rParam.bHasHeader );
359cdf0e10cSrcweir 
360cdf0e10cSrcweir 	pArray[2].Name = rtl::OUString::createFromAscii( SC_UNONAME_MAXFLD );
361cdf0e10cSrcweir 	pArray[2].Value <<= (sal_Int32) MAXSORT;
362cdf0e10cSrcweir 
363cdf0e10cSrcweir 	pArray[3].Name = rtl::OUString::createFromAscii( SC_UNONAME_SORTFLD );
364cdf0e10cSrcweir 	pArray[3].Value <<= aFields;
365cdf0e10cSrcweir 
366cdf0e10cSrcweir 	pArray[4].Name = rtl::OUString::createFromAscii( SC_UNONAME_BINDFMT );
367cdf0e10cSrcweir 	ScUnoHelpFunctions::SetBoolInAny( pArray[4].Value, rParam.bIncludePattern );
368cdf0e10cSrcweir 
369cdf0e10cSrcweir 	pArray[5].Name = rtl::OUString::createFromAscii( SC_UNONAME_COPYOUT );
370cdf0e10cSrcweir 	ScUnoHelpFunctions::SetBoolInAny( pArray[5].Value, !rParam.bInplace );
371cdf0e10cSrcweir 
372cdf0e10cSrcweir 	pArray[6].Name = rtl::OUString::createFromAscii( SC_UNONAME_OUTPOS );
373cdf0e10cSrcweir 	pArray[6].Value <<= aOutPos;
374cdf0e10cSrcweir 
375cdf0e10cSrcweir 	pArray[7].Name = rtl::OUString::createFromAscii( SC_UNONAME_ISULIST );
376cdf0e10cSrcweir 	ScUnoHelpFunctions::SetBoolInAny( pArray[7].Value, rParam.bUserDef );
377cdf0e10cSrcweir 
378cdf0e10cSrcweir 	pArray[8].Name = rtl::OUString::createFromAscii( SC_UNONAME_UINDEX );
379cdf0e10cSrcweir 	pArray[8].Value <<= (sal_Int32) rParam.nUserIndex;
380cdf0e10cSrcweir }
381cdf0e10cSrcweir 
FillSortParam(ScSortParam & rParam,const uno::Sequence<beans::PropertyValue> & rSeq)382cdf0e10cSrcweir void ScSortDescriptor::FillSortParam( ScSortParam& rParam, const uno::Sequence<beans::PropertyValue>& rSeq )
383cdf0e10cSrcweir {
384cdf0e10cSrcweir     sal_Bool bOldSortDescriptor(sal_False);
385cdf0e10cSrcweir     sal_Bool bNewSortDescriptor(sal_False);
386cdf0e10cSrcweir 	const beans::PropertyValue* pPropArray = rSeq.getConstArray();
387cdf0e10cSrcweir 	long nPropCount = rSeq.getLength();
388cdf0e10cSrcweir     for (long nProp = 0; nProp < nPropCount; nProp++)
389cdf0e10cSrcweir 	{
390cdf0e10cSrcweir         const beans::PropertyValue& rProp = pPropArray[nProp];
391cdf0e10cSrcweir 		String aPropName(rProp.Name);
392cdf0e10cSrcweir 
393cdf0e10cSrcweir 		if (aPropName.EqualsAscii( SC_UNONAME_ORIENT ))
394cdf0e10cSrcweir 		{
395cdf0e10cSrcweir             bOldSortDescriptor = sal_True;
396cdf0e10cSrcweir 			//!	test for correct enum type?
397cdf0e10cSrcweir 			table::TableOrientation eOrient = (table::TableOrientation)
398cdf0e10cSrcweir 								ScUnoHelpFunctions::GetEnumFromAny( rProp.Value );
399cdf0e10cSrcweir 			rParam.bByRow = ( eOrient != table::TableOrientation_COLUMNS );
400cdf0e10cSrcweir 		}
401cdf0e10cSrcweir         else if (aPropName.EqualsAscii( SC_UNONAME_ISSORTCOLUMNS ))
402cdf0e10cSrcweir         {
403cdf0e10cSrcweir             bNewSortDescriptor = sal_True;
404cdf0e10cSrcweir             rParam.bByRow = !::cppu::any2bool(rProp.Value);
405cdf0e10cSrcweir         }
406cdf0e10cSrcweir 		else if (aPropName.EqualsAscii( SC_UNONAME_CONTHDR ))
407cdf0e10cSrcweir 			rParam.bHasHeader = ScUnoHelpFunctions::GetBoolFromAny( rProp.Value );
408cdf0e10cSrcweir 		else if (aPropName.EqualsAscii( SC_UNONAME_MAXFLD ))
409cdf0e10cSrcweir 		{
410cdf0e10cSrcweir 			sal_Int32 nVal;
411cdf0e10cSrcweir 			if ( (rProp.Value >>= nVal) && nVal > MAXSORT )
412cdf0e10cSrcweir 			{
413cdf0e10cSrcweir 				//!	specify exceptions
414cdf0e10cSrcweir 				//! throw lang::IllegalArgumentException();
415cdf0e10cSrcweir 			}
416cdf0e10cSrcweir 		}
417cdf0e10cSrcweir 		else if (aPropName.EqualsAscii( SC_UNONAME_SORTFLD ))
418cdf0e10cSrcweir 		{
419cdf0e10cSrcweir 			uno::Sequence<util::SortField> aSeq;
420cdf0e10cSrcweir             uno::Sequence<table::TableSortField> aNewSeq;
421cdf0e10cSrcweir 			if ( rProp.Value >>= aSeq )
422cdf0e10cSrcweir 			{
423cdf0e10cSrcweir                 bOldSortDescriptor = sal_True;
424cdf0e10cSrcweir 				sal_Int32 nCount = aSeq.getLength();
425cdf0e10cSrcweir 				sal_Int32 i;
426cdf0e10cSrcweir 				if ( nCount > MAXSORT )
427cdf0e10cSrcweir 				{
428cdf0e10cSrcweir 					DBG_ERROR("Zu viele Sortierfelder");
429cdf0e10cSrcweir 					nCount = MAXSORT;
430cdf0e10cSrcweir 				}
431cdf0e10cSrcweir 				const util::SortField* pFieldArray = aSeq.getConstArray();
432cdf0e10cSrcweir 				for (i=0; i<nCount; i++)
433cdf0e10cSrcweir 				{
434cdf0e10cSrcweir 					rParam.nField[i]	 = (SCCOLROW)pFieldArray[i].Field;
435cdf0e10cSrcweir 					rParam.bAscending[i] = pFieldArray[i].SortAscending;
436cdf0e10cSrcweir 
437cdf0e10cSrcweir                     // FieldType wird ignoriert
438cdf0e10cSrcweir 					rParam.bDoSort[i] = sal_True;
439cdf0e10cSrcweir 				}
440cdf0e10cSrcweir 				for (i=nCount; i<MAXSORT; i++)
441cdf0e10cSrcweir 					rParam.bDoSort[i] = sal_False;
442cdf0e10cSrcweir 			}
443cdf0e10cSrcweir 			else if ( rProp.Value >>= aNewSeq )
444cdf0e10cSrcweir             {
445cdf0e10cSrcweir                 bNewSortDescriptor = sal_True;
446cdf0e10cSrcweir 				sal_Int32 nCount = aNewSeq.getLength();
447cdf0e10cSrcweir 				sal_Int32 i;
448cdf0e10cSrcweir 				if ( nCount > MAXSORT )
449cdf0e10cSrcweir 				{
450cdf0e10cSrcweir 					DBG_ERROR("Zu viele Sortierfelder");
451cdf0e10cSrcweir 					nCount = MAXSORT;
452cdf0e10cSrcweir 				}
453cdf0e10cSrcweir 				const table::TableSortField* pFieldArray = aNewSeq.getConstArray();
454cdf0e10cSrcweir 				for (i=0; i<nCount; i++)
455cdf0e10cSrcweir 				{
456cdf0e10cSrcweir 					rParam.nField[i]	 = (SCCOLROW)pFieldArray[i].Field;
457cdf0e10cSrcweir 					rParam.bAscending[i] = pFieldArray[i].IsAscending;
458cdf0e10cSrcweir 
459cdf0e10cSrcweir                     // only one is possible, sometime we should make it possible to have different for every entry
460cdf0e10cSrcweir 			        rParam.bCaseSens = pFieldArray[i].IsCaseSensitive;
461cdf0e10cSrcweir 			        rParam.aCollatorLocale = pFieldArray[i].CollatorLocale;
462cdf0e10cSrcweir 				    rParam.aCollatorAlgorithm = pFieldArray[i].CollatorAlgorithm;
463cdf0e10cSrcweir 
464cdf0e10cSrcweir                     // FieldType wird ignoriert
465cdf0e10cSrcweir 					rParam.bDoSort[i] = sal_True;
466cdf0e10cSrcweir 				}
467cdf0e10cSrcweir 				for (i=nCount; i<MAXSORT; i++)
468cdf0e10cSrcweir 					rParam.bDoSort[i] = sal_False;
469cdf0e10cSrcweir             }
470cdf0e10cSrcweir 		}
471cdf0e10cSrcweir 		else if (aPropName.EqualsAscii( SC_UNONAME_ISCASE ))
472cdf0e10cSrcweir         {
473cdf0e10cSrcweir             bOldSortDescriptor = sal_True;
474cdf0e10cSrcweir 			rParam.bCaseSens = ScUnoHelpFunctions::GetBoolFromAny( rProp.Value );
475cdf0e10cSrcweir         }
476cdf0e10cSrcweir 		else if (aPropName.EqualsAscii( SC_UNONAME_BINDFMT ))
477cdf0e10cSrcweir 			rParam.bIncludePattern = ScUnoHelpFunctions::GetBoolFromAny( rProp.Value );
478cdf0e10cSrcweir 		else if (aPropName.EqualsAscii( SC_UNONAME_COPYOUT ))
479cdf0e10cSrcweir 			rParam.bInplace = !ScUnoHelpFunctions::GetBoolFromAny( rProp.Value );
480cdf0e10cSrcweir 		else if (aPropName.EqualsAscii( SC_UNONAME_OUTPOS ))
481cdf0e10cSrcweir 		{
482cdf0e10cSrcweir 			table::CellAddress aAddress;
483cdf0e10cSrcweir 			if ( rProp.Value >>= aAddress )
484cdf0e10cSrcweir 			{
485cdf0e10cSrcweir 				rParam.nDestTab = aAddress.Sheet;
486cdf0e10cSrcweir 				rParam.nDestCol = (SCCOL)aAddress.Column;
487cdf0e10cSrcweir 				rParam.nDestRow = (SCROW)aAddress.Row;
488cdf0e10cSrcweir 			}
489cdf0e10cSrcweir 		}
490cdf0e10cSrcweir 		else if (aPropName.EqualsAscii( SC_UNONAME_ISULIST ))
491cdf0e10cSrcweir 			rParam.bUserDef = ScUnoHelpFunctions::GetBoolFromAny( rProp.Value );
492cdf0e10cSrcweir 		else if (aPropName.EqualsAscii( SC_UNONAME_UINDEX ))
493cdf0e10cSrcweir 		{
494cdf0e10cSrcweir 			sal_Int32 nVal = 0;
495cdf0e10cSrcweir 			if ( rProp.Value >>= nVal )
496cdf0e10cSrcweir 				rParam.nUserIndex = (sal_uInt16)nVal;
497cdf0e10cSrcweir 		}
498cdf0e10cSrcweir 		else if (aPropName.EqualsAscii( SC_UNONAME_COLLLOC ))
499cdf0e10cSrcweir 		{
500cdf0e10cSrcweir             bOldSortDescriptor = sal_True;
501cdf0e10cSrcweir 			rProp.Value >>= rParam.aCollatorLocale;
502cdf0e10cSrcweir 		}
503cdf0e10cSrcweir 		else if (aPropName.EqualsAscii( SC_UNONAME_COLLALG ))
504cdf0e10cSrcweir 		{
505cdf0e10cSrcweir             bOldSortDescriptor = sal_True;
506cdf0e10cSrcweir 			rtl::OUString sStr;
507cdf0e10cSrcweir 			if ( rProp.Value >>= sStr )
508cdf0e10cSrcweir 				rParam.aCollatorAlgorithm = sStr;
509cdf0e10cSrcweir 		}
510cdf0e10cSrcweir 	}
511cdf0e10cSrcweir }
512cdf0e10cSrcweir 
513cdf0e10cSrcweir //------------------------------------------------------------------------
514cdf0e10cSrcweir 
ScSubTotalFieldObj(ScSubTotalDescriptorBase * pDesc,sal_uInt16 nP)515cdf0e10cSrcweir ScSubTotalFieldObj::ScSubTotalFieldObj( ScSubTotalDescriptorBase* pDesc, sal_uInt16 nP ) :
516cdf0e10cSrcweir 	xRef( pDesc ),			// Objekt festhalten
517cdf0e10cSrcweir 	rParent( *pDesc ),
518cdf0e10cSrcweir 	nPos( nP )
519cdf0e10cSrcweir {
520cdf0e10cSrcweir 	DBG_ASSERT(pDesc, "ScSubTotalFieldObj: Parent ist 0");
521cdf0e10cSrcweir }
522cdf0e10cSrcweir 
~ScSubTotalFieldObj()523cdf0e10cSrcweir ScSubTotalFieldObj::~ScSubTotalFieldObj()
524cdf0e10cSrcweir {
525cdf0e10cSrcweir }
526cdf0e10cSrcweir 
527cdf0e10cSrcweir // XSubTotalField
528cdf0e10cSrcweir 
getGroupColumn()529cdf0e10cSrcweir sal_Int32 SAL_CALL ScSubTotalFieldObj::getGroupColumn() throw(uno::RuntimeException)
530cdf0e10cSrcweir {
531cdf0e10cSrcweir 	ScUnoGuard aGuard;
532cdf0e10cSrcweir 	ScSubTotalParam aParam;
533cdf0e10cSrcweir 	rParent.GetData(aParam);
534cdf0e10cSrcweir 
535cdf0e10cSrcweir 	return aParam.nField[nPos];
536cdf0e10cSrcweir }
537cdf0e10cSrcweir 
setGroupColumn(sal_Int32 nGroupColumn)538cdf0e10cSrcweir void SAL_CALL ScSubTotalFieldObj::setGroupColumn( sal_Int32 nGroupColumn ) throw(uno::RuntimeException)
539cdf0e10cSrcweir {
540cdf0e10cSrcweir 	ScUnoGuard aGuard;
541cdf0e10cSrcweir 	ScSubTotalParam aParam;
542cdf0e10cSrcweir 	rParent.GetData(aParam);
543cdf0e10cSrcweir 
544cdf0e10cSrcweir 	aParam.nField[nPos] = (SCCOL)nGroupColumn;
545cdf0e10cSrcweir 
546cdf0e10cSrcweir 	rParent.PutData(aParam);
547cdf0e10cSrcweir }
548cdf0e10cSrcweir 
getSubTotalColumns()549cdf0e10cSrcweir uno::Sequence<sheet::SubTotalColumn> SAL_CALL ScSubTotalFieldObj::getSubTotalColumns()
550cdf0e10cSrcweir 												throw(uno::RuntimeException)
551cdf0e10cSrcweir {
552cdf0e10cSrcweir 	ScUnoGuard aGuard;
553cdf0e10cSrcweir 	ScSubTotalParam aParam;
554cdf0e10cSrcweir 	rParent.GetData(aParam);
555cdf0e10cSrcweir 
556cdf0e10cSrcweir 	SCCOL nCount = aParam.nSubTotals[nPos];
557cdf0e10cSrcweir 	uno::Sequence<sheet::SubTotalColumn> aSeq(nCount);
558cdf0e10cSrcweir 	sheet::SubTotalColumn* pAry = aSeq.getArray();
559cdf0e10cSrcweir 	for (SCCOL i=0; i<nCount; i++)
560cdf0e10cSrcweir 	{
561cdf0e10cSrcweir 		pAry[i].Column = aParam.pSubTotals[nPos][i];
562cdf0e10cSrcweir 		pAry[i].Function = ScDataUnoConversion::SubTotalToGeneral(
563cdf0e10cSrcweir 										aParam.pFunctions[nPos][i] );
564cdf0e10cSrcweir 	}
565cdf0e10cSrcweir 	return aSeq;
566cdf0e10cSrcweir }
567cdf0e10cSrcweir 
setSubTotalColumns(const uno::Sequence<sheet::SubTotalColumn> & aSubTotalColumns)568cdf0e10cSrcweir void SAL_CALL ScSubTotalFieldObj::setSubTotalColumns(
569cdf0e10cSrcweir 							const uno::Sequence<sheet::SubTotalColumn>& aSubTotalColumns )
570cdf0e10cSrcweir 									throw(uno::RuntimeException)
571cdf0e10cSrcweir {
572cdf0e10cSrcweir 	ScUnoGuard aGuard;
573cdf0e10cSrcweir 	ScSubTotalParam aParam;
574cdf0e10cSrcweir 	rParent.GetData(aParam);
575cdf0e10cSrcweir 
576cdf0e10cSrcweir 	sal_uInt32 nColCount = aSubTotalColumns.getLength();
577cdf0e10cSrcweir     if ( nColCount <= sal::static_int_cast<sal_uInt32>(SCCOL_MAX) )
578cdf0e10cSrcweir 	{
579cdf0e10cSrcweir 		SCCOL nCount = static_cast<SCCOL>(nColCount);
580cdf0e10cSrcweir 		aParam.nSubTotals[nPos] = nCount;
581cdf0e10cSrcweir 		if (nCount != 0)
582cdf0e10cSrcweir 		{
583cdf0e10cSrcweir 			aParam.pSubTotals[nPos] = new SCCOL[nCount];
584cdf0e10cSrcweir 			aParam.pFunctions[nPos] = new ScSubTotalFunc[nCount];
585cdf0e10cSrcweir 
586cdf0e10cSrcweir 			const sheet::SubTotalColumn* pAry = aSubTotalColumns.getConstArray();
587cdf0e10cSrcweir 			for (SCCOL i=0; i<nCount; i++)
588cdf0e10cSrcweir 			{
589cdf0e10cSrcweir 				aParam.pSubTotals[nPos][i] = static_cast<SCCOL>(pAry[i].Column);
590cdf0e10cSrcweir 				aParam.pFunctions[nPos][i] =
591cdf0e10cSrcweir 							ScDataUnoConversion::GeneralToSubTotal( pAry[i].Function );
592cdf0e10cSrcweir 			}
593cdf0e10cSrcweir 		}
594cdf0e10cSrcweir 		else
595cdf0e10cSrcweir 		{
596cdf0e10cSrcweir 			aParam.pSubTotals[nPos] = NULL;
597cdf0e10cSrcweir 			aParam.pFunctions[nPos] = NULL;
598cdf0e10cSrcweir 		}
599cdf0e10cSrcweir 	}
600cdf0e10cSrcweir 	//!	sonst Exception oder so? (zuviele Spalten)
601cdf0e10cSrcweir 
602cdf0e10cSrcweir 	rParent.PutData(aParam);
603cdf0e10cSrcweir }
604cdf0e10cSrcweir 
605cdf0e10cSrcweir //------------------------------------------------------------------------
606cdf0e10cSrcweir 
ScSubTotalDescriptorBase()607cdf0e10cSrcweir ScSubTotalDescriptorBase::ScSubTotalDescriptorBase() :
608cdf0e10cSrcweir 	aPropSet( lcl_GetSubTotalPropertyMap() )
609cdf0e10cSrcweir {
610cdf0e10cSrcweir }
611cdf0e10cSrcweir 
~ScSubTotalDescriptorBase()612cdf0e10cSrcweir ScSubTotalDescriptorBase::~ScSubTotalDescriptorBase()
613cdf0e10cSrcweir {
614cdf0e10cSrcweir }
615cdf0e10cSrcweir 
616cdf0e10cSrcweir // GetData/PutData hier nur wegen NewInstance-Krempel implementiert...
617cdf0e10cSrcweir 
GetData(ScSubTotalParam &) const618cdf0e10cSrcweir void ScSubTotalDescriptorBase::GetData( ScSubTotalParam& /* rParam */ ) const
619cdf0e10cSrcweir {
620cdf0e10cSrcweir 	DBG_ERROR("ScSubTotalDescriptorBase::GetData soll nicht gerufen werden");
621cdf0e10cSrcweir }
622cdf0e10cSrcweir 
PutData(const ScSubTotalParam &)623cdf0e10cSrcweir void ScSubTotalDescriptorBase::PutData( const ScSubTotalParam& /* rParam */ )
624cdf0e10cSrcweir {
625cdf0e10cSrcweir 	DBG_ERROR("ScSubTotalDescriptorBase::PutData soll nicht gerufen werden");
626cdf0e10cSrcweir }
627cdf0e10cSrcweir 
628cdf0e10cSrcweir // XSubTotalDesctiptor
629cdf0e10cSrcweir 
GetObjectByIndex_Impl(sal_uInt16 nIndex)630cdf0e10cSrcweir ScSubTotalFieldObj* ScSubTotalDescriptorBase::GetObjectByIndex_Impl(sal_uInt16 nIndex)
631cdf0e10cSrcweir {
632cdf0e10cSrcweir 	if ( nIndex < getCount() )
633cdf0e10cSrcweir 		return new ScSubTotalFieldObj( this, nIndex );
634cdf0e10cSrcweir 	return NULL;
635cdf0e10cSrcweir }
636cdf0e10cSrcweir 
clear()637cdf0e10cSrcweir void SAL_CALL ScSubTotalDescriptorBase::clear() throw(uno::RuntimeException)
638cdf0e10cSrcweir {
639cdf0e10cSrcweir 	ScUnoGuard aGuard;
640cdf0e10cSrcweir 	ScSubTotalParam aParam;
641cdf0e10cSrcweir 	GetData(aParam);
642cdf0e10cSrcweir 
643cdf0e10cSrcweir 	for (sal_uInt16 i=0; i<MAXSUBTOTAL; i++)
644cdf0e10cSrcweir 		aParam.bGroupActive[i] = sal_False;
645cdf0e10cSrcweir 
646cdf0e10cSrcweir 	//!	Notify oder so fuer die Field-Objekte???
647cdf0e10cSrcweir 
648cdf0e10cSrcweir 	PutData(aParam);
649cdf0e10cSrcweir }
650cdf0e10cSrcweir 
addNew(const uno::Sequence<sheet::SubTotalColumn> & aSubTotalColumns,sal_Int32 nGroupColumn)651cdf0e10cSrcweir void SAL_CALL ScSubTotalDescriptorBase::addNew(
652cdf0e10cSrcweir 						const uno::Sequence<sheet::SubTotalColumn>& aSubTotalColumns,
653cdf0e10cSrcweir 						sal_Int32 nGroupColumn ) throw(uno::RuntimeException)
654cdf0e10cSrcweir {
655cdf0e10cSrcweir 	ScUnoGuard aGuard;
656cdf0e10cSrcweir 	ScSubTotalParam aParam;
657cdf0e10cSrcweir 	GetData(aParam);
658cdf0e10cSrcweir 
659cdf0e10cSrcweir 	sal_uInt16 nPos = 0;
660cdf0e10cSrcweir 	while ( nPos < MAXSUBTOTAL && aParam.bGroupActive[nPos] )
661cdf0e10cSrcweir 		++nPos;
662cdf0e10cSrcweir 
663cdf0e10cSrcweir 	sal_uInt32 nColCount = aSubTotalColumns.getLength();
664cdf0e10cSrcweir 
665cdf0e10cSrcweir     if ( nPos < MAXSUBTOTAL && nColCount <= sal::static_int_cast<sal_uInt32>(SCCOL_MAX) )
666cdf0e10cSrcweir 	{
667cdf0e10cSrcweir 		aParam.bGroupActive[nPos] = sal_True;
668cdf0e10cSrcweir 		aParam.nField[nPos] = static_cast<SCCOL>(nGroupColumn);
669cdf0e10cSrcweir 
670cdf0e10cSrcweir 		delete aParam.pSubTotals[nPos];
671cdf0e10cSrcweir 		delete aParam.pFunctions[nPos];
672cdf0e10cSrcweir 
673cdf0e10cSrcweir 		SCCOL nCount = static_cast<SCCOL>(nColCount);
674cdf0e10cSrcweir 		aParam.nSubTotals[nPos] = nCount;
675cdf0e10cSrcweir 		if (nCount != 0)
676cdf0e10cSrcweir 		{
677cdf0e10cSrcweir 			aParam.pSubTotals[nPos] = new SCCOL[nCount];
678cdf0e10cSrcweir 			aParam.pFunctions[nPos] = new ScSubTotalFunc[nCount];
679cdf0e10cSrcweir 
680cdf0e10cSrcweir 			const sheet::SubTotalColumn* pAry = aSubTotalColumns.getConstArray();
681cdf0e10cSrcweir 			for (SCCOL i=0; i<nCount; i++)
682cdf0e10cSrcweir 			{
683cdf0e10cSrcweir 				aParam.pSubTotals[nPos][i] = static_cast<SCCOL>(pAry[i].Column);
684cdf0e10cSrcweir 				aParam.pFunctions[nPos][i] =
685cdf0e10cSrcweir 							ScDataUnoConversion::GeneralToSubTotal( pAry[i].Function );
686cdf0e10cSrcweir 			}
687cdf0e10cSrcweir 		}
688cdf0e10cSrcweir 		else
689cdf0e10cSrcweir 		{
690cdf0e10cSrcweir 			aParam.pSubTotals[nPos] = NULL;
691cdf0e10cSrcweir 			aParam.pFunctions[nPos] = NULL;
692cdf0e10cSrcweir 		}
693cdf0e10cSrcweir 	}
694cdf0e10cSrcweir 	else									// too many fields / columns
695cdf0e10cSrcweir 		throw uno::RuntimeException();		// no other exceptions specified
696cdf0e10cSrcweir 
697cdf0e10cSrcweir 	PutData(aParam);
698cdf0e10cSrcweir }
699cdf0e10cSrcweir 
700cdf0e10cSrcweir //	Flags/Einstellungen als Properties
701cdf0e10cSrcweir 
702cdf0e10cSrcweir // XEnumerationAccess
703cdf0e10cSrcweir 
createEnumeration()704cdf0e10cSrcweir uno::Reference<container::XEnumeration> SAL_CALL ScSubTotalDescriptorBase::createEnumeration()
705cdf0e10cSrcweir 													throw(uno::RuntimeException)
706cdf0e10cSrcweir {
707cdf0e10cSrcweir 	ScUnoGuard aGuard;
708cdf0e10cSrcweir     return new ScIndexEnumeration(this, rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.sheet.SubTotalFieldsEnumeration")));
709cdf0e10cSrcweir }
710cdf0e10cSrcweir 
711cdf0e10cSrcweir // XIndexAccess
712cdf0e10cSrcweir 
getCount()713cdf0e10cSrcweir sal_Int32 SAL_CALL ScSubTotalDescriptorBase::getCount() throw(uno::RuntimeException)
714cdf0e10cSrcweir {
715cdf0e10cSrcweir 	ScUnoGuard aGuard;
716cdf0e10cSrcweir 	ScSubTotalParam aParam;
717cdf0e10cSrcweir 	GetData(aParam);
718cdf0e10cSrcweir 
719cdf0e10cSrcweir 	sal_uInt16 nCount = 0;
720cdf0e10cSrcweir 	while ( nCount < MAXSUBTOTAL && aParam.bGroupActive[nCount] )
721cdf0e10cSrcweir 		++nCount;
722cdf0e10cSrcweir 	return nCount;
723cdf0e10cSrcweir }
724cdf0e10cSrcweir 
getByIndex(sal_Int32 nIndex)725cdf0e10cSrcweir uno::Any SAL_CALL ScSubTotalDescriptorBase::getByIndex( sal_Int32 nIndex )
726cdf0e10cSrcweir 							throw(lang::IndexOutOfBoundsException,
727cdf0e10cSrcweir 									lang::WrappedTargetException, uno::RuntimeException)
728cdf0e10cSrcweir {
729cdf0e10cSrcweir 	ScUnoGuard aGuard;
730cdf0e10cSrcweir 	uno::Reference<sheet::XSubTotalField> xField(GetObjectByIndex_Impl((sal_uInt16)nIndex));
731cdf0e10cSrcweir 	if (xField.is())
732cdf0e10cSrcweir         return uno::makeAny(xField);
733cdf0e10cSrcweir 	else
734cdf0e10cSrcweir 		throw lang::IndexOutOfBoundsException();
735cdf0e10cSrcweir //    return uno::Any();
736cdf0e10cSrcweir }
737cdf0e10cSrcweir 
getElementType()738cdf0e10cSrcweir uno::Type SAL_CALL ScSubTotalDescriptorBase::getElementType() throw(uno::RuntimeException)
739cdf0e10cSrcweir {
740cdf0e10cSrcweir 	ScUnoGuard aGuard;
741cdf0e10cSrcweir 	return getCppuType((uno::Reference<sheet::XSubTotalField>*)0);
742cdf0e10cSrcweir }
743cdf0e10cSrcweir 
hasElements()744cdf0e10cSrcweir sal_Bool SAL_CALL ScSubTotalDescriptorBase::hasElements() throw(uno::RuntimeException)
745cdf0e10cSrcweir {
746cdf0e10cSrcweir 	ScUnoGuard aGuard;
747cdf0e10cSrcweir 	return ( getCount() != 0 );
748cdf0e10cSrcweir }
749cdf0e10cSrcweir 
750cdf0e10cSrcweir // XPropertySet
751cdf0e10cSrcweir 
getPropertySetInfo()752cdf0e10cSrcweir uno::Reference<beans::XPropertySetInfo> SAL_CALL ScSubTotalDescriptorBase::getPropertySetInfo()
753cdf0e10cSrcweir 														throw(uno::RuntimeException)
754cdf0e10cSrcweir {
755cdf0e10cSrcweir 	ScUnoGuard aGuard;
756cdf0e10cSrcweir 	static uno::Reference<beans::XPropertySetInfo> aRef(
757cdf0e10cSrcweir 		new SfxItemPropertySetInfo( aPropSet.getPropertyMap() ));
758cdf0e10cSrcweir 	return aRef;
759cdf0e10cSrcweir }
760cdf0e10cSrcweir 
setPropertyValue(const rtl::OUString & aPropertyName,const uno::Any & aValue)761cdf0e10cSrcweir void SAL_CALL ScSubTotalDescriptorBase::setPropertyValue(
762cdf0e10cSrcweir 						const rtl::OUString& aPropertyName, const uno::Any& aValue )
763cdf0e10cSrcweir 				throw(beans::UnknownPropertyException, beans::PropertyVetoException,
764cdf0e10cSrcweir 						lang::IllegalArgumentException, lang::WrappedTargetException,
765cdf0e10cSrcweir 						uno::RuntimeException)
766cdf0e10cSrcweir {
767cdf0e10cSrcweir 	ScUnoGuard aGuard;
768cdf0e10cSrcweir 	ScSubTotalParam aParam;
769cdf0e10cSrcweir 	GetData(aParam);
770cdf0e10cSrcweir 
771cdf0e10cSrcweir 	String aString(aPropertyName);
772cdf0e10cSrcweir 
773cdf0e10cSrcweir 	// some old property names are for 5.2 compatibility
774cdf0e10cSrcweir 
775cdf0e10cSrcweir 	if (aString.EqualsAscii( SC_UNONAME_CASE ) || aString.EqualsAscii( SC_UNONAME_ISCASE ))
776cdf0e10cSrcweir 		aParam.bCaseSens = ScUnoHelpFunctions::GetBoolFromAny( aValue );
777cdf0e10cSrcweir 	else if (aString.EqualsAscii( SC_UNONAME_FORMATS ) || aString.EqualsAscii( SC_UNONAME_BINDFMT ))
778cdf0e10cSrcweir 		aParam.bIncludePattern = ScUnoHelpFunctions::GetBoolFromAny( aValue );
779cdf0e10cSrcweir 	else if (aString.EqualsAscii( SC_UNONAME_ENABSORT ))
780cdf0e10cSrcweir 		aParam.bDoSort = ScUnoHelpFunctions::GetBoolFromAny( aValue );
781cdf0e10cSrcweir 	else if (aString.EqualsAscii( SC_UNONAME_SORTASC ))
782cdf0e10cSrcweir 		aParam.bAscending = ScUnoHelpFunctions::GetBoolFromAny( aValue );
783cdf0e10cSrcweir 	else if (aString.EqualsAscii( SC_UNONAME_INSBRK ))
784cdf0e10cSrcweir 		aParam.bPagebreak = ScUnoHelpFunctions::GetBoolFromAny( aValue );
785cdf0e10cSrcweir 	else if (aString.EqualsAscii( SC_UNONAME_ULIST ) || aString.EqualsAscii( SC_UNONAME_ENUSLIST ))
786cdf0e10cSrcweir 		aParam.bUserDef = ScUnoHelpFunctions::GetBoolFromAny( aValue );
787cdf0e10cSrcweir 	else if (aString.EqualsAscii( SC_UNONAME_UINDEX ) || aString.EqualsAscii( SC_UNONAME_USINDEX ))
788cdf0e10cSrcweir 	{
789cdf0e10cSrcweir 		sal_Int32 nVal = 0;
790cdf0e10cSrcweir 		if ( aValue >>= nVal )
791cdf0e10cSrcweir 			aParam.nUserIndex = (sal_uInt16)nVal;
792cdf0e10cSrcweir 	}
793cdf0e10cSrcweir 	else if (aString.EqualsAscii( SC_UNONAME_MAXFLD ))
794cdf0e10cSrcweir 	{
795cdf0e10cSrcweir 		sal_Int32 nVal = 0;
796cdf0e10cSrcweir         if ( (aValue >>= nVal) && nVal > sal::static_int_cast<sal_Int32>(MAXSUBTOTAL) )
797cdf0e10cSrcweir 		{
798cdf0e10cSrcweir 			throw lang::IllegalArgumentException();
799cdf0e10cSrcweir 		}
800cdf0e10cSrcweir 	}
801cdf0e10cSrcweir 
802cdf0e10cSrcweir 	PutData(aParam);
803cdf0e10cSrcweir }
804cdf0e10cSrcweir 
getPropertyValue(const rtl::OUString & aPropertyName)805cdf0e10cSrcweir uno::Any SAL_CALL ScSubTotalDescriptorBase::getPropertyValue( const rtl::OUString& aPropertyName )
806cdf0e10cSrcweir 				throw(beans::UnknownPropertyException, lang::WrappedTargetException,
807cdf0e10cSrcweir 						uno::RuntimeException)
808cdf0e10cSrcweir {
809cdf0e10cSrcweir 	ScUnoGuard aGuard;
810cdf0e10cSrcweir 	ScSubTotalParam aParam;
811cdf0e10cSrcweir 	GetData(aParam);
812cdf0e10cSrcweir 
813cdf0e10cSrcweir 	String aString(aPropertyName);
814cdf0e10cSrcweir 	uno::Any aRet;
815cdf0e10cSrcweir 
816cdf0e10cSrcweir 	// some old property names are for 5.2 compatibility
817cdf0e10cSrcweir 
818cdf0e10cSrcweir 	if (aString.EqualsAscii( SC_UNONAME_CASE ) || aString.EqualsAscii( SC_UNONAME_ISCASE ))
819cdf0e10cSrcweir 		ScUnoHelpFunctions::SetBoolInAny( aRet, aParam.bCaseSens );
820cdf0e10cSrcweir 	else if (aString.EqualsAscii( SC_UNONAME_FORMATS ) || aString.EqualsAscii( SC_UNONAME_BINDFMT ))
821cdf0e10cSrcweir 		ScUnoHelpFunctions::SetBoolInAny( aRet, aParam.bIncludePattern );
822cdf0e10cSrcweir 	else if (aString.EqualsAscii( SC_UNONAME_ENABSORT ))
823cdf0e10cSrcweir 		ScUnoHelpFunctions::SetBoolInAny( aRet, aParam.bDoSort );
824cdf0e10cSrcweir 	else if (aString.EqualsAscii( SC_UNONAME_SORTASC ))
825cdf0e10cSrcweir 		ScUnoHelpFunctions::SetBoolInAny( aRet, aParam.bAscending );
826cdf0e10cSrcweir 	else if (aString.EqualsAscii( SC_UNONAME_INSBRK ))
827cdf0e10cSrcweir 		ScUnoHelpFunctions::SetBoolInAny( aRet, aParam.bPagebreak );
828cdf0e10cSrcweir 	else if (aString.EqualsAscii( SC_UNONAME_ULIST ) || aString.EqualsAscii( SC_UNONAME_ENUSLIST ))
829cdf0e10cSrcweir 		ScUnoHelpFunctions::SetBoolInAny( aRet, aParam.bUserDef );
830cdf0e10cSrcweir 	else if (aString.EqualsAscii( SC_UNONAME_UINDEX ) || aString.EqualsAscii( SC_UNONAME_USINDEX ))
831cdf0e10cSrcweir 		aRet <<= (sal_Int32) aParam.nUserIndex;
832cdf0e10cSrcweir 	else if (aString.EqualsAscii( SC_UNONAME_MAXFLD ))
833cdf0e10cSrcweir 		aRet <<= (sal_Int32) MAXSUBTOTAL;
834cdf0e10cSrcweir 
835cdf0e10cSrcweir 	return aRet;
836cdf0e10cSrcweir }
837cdf0e10cSrcweir 
SC_IMPL_DUMMY_PROPERTY_LISTENER(ScSubTotalDescriptorBase)838cdf0e10cSrcweir SC_IMPL_DUMMY_PROPERTY_LISTENER( ScSubTotalDescriptorBase )
839cdf0e10cSrcweir 
840cdf0e10cSrcweir // XUnoTunnel
841cdf0e10cSrcweir 
842cdf0e10cSrcweir sal_Int64 SAL_CALL ScSubTotalDescriptorBase::getSomething(
843cdf0e10cSrcweir 				const uno::Sequence<sal_Int8 >& rId ) throw(uno::RuntimeException)
844cdf0e10cSrcweir {
845cdf0e10cSrcweir 	if ( rId.getLength() == 16 &&
846cdf0e10cSrcweir           0 == rtl_compareMemory( getUnoTunnelId().getConstArray(),
847cdf0e10cSrcweir 									rId.getConstArray(), 16 ) )
848cdf0e10cSrcweir 	{
849cdf0e10cSrcweir         return sal::static_int_cast<sal_Int64>(reinterpret_cast<sal_IntPtr>(this));
850cdf0e10cSrcweir 	}
851cdf0e10cSrcweir 	return 0;
852cdf0e10cSrcweir }
853cdf0e10cSrcweir 
854cdf0e10cSrcweir // static
getUnoTunnelId()855cdf0e10cSrcweir const uno::Sequence<sal_Int8>& ScSubTotalDescriptorBase::getUnoTunnelId()
856cdf0e10cSrcweir {
857cdf0e10cSrcweir 	static uno::Sequence<sal_Int8> * pSeq = 0;
858cdf0e10cSrcweir 	if( !pSeq )
859cdf0e10cSrcweir 	{
860cdf0e10cSrcweir 		osl::Guard< osl::Mutex > aGuard( osl::Mutex::getGlobalMutex() );
861cdf0e10cSrcweir 		if( !pSeq )
862cdf0e10cSrcweir 		{
863cdf0e10cSrcweir 			static uno::Sequence< sal_Int8 > aSeq( 16 );
864cdf0e10cSrcweir 			rtl_createUuid( (sal_uInt8*)aSeq.getArray(), 0, sal_True );
865cdf0e10cSrcweir 			pSeq = &aSeq;
866cdf0e10cSrcweir 		}
867cdf0e10cSrcweir 	}
868cdf0e10cSrcweir 	return *pSeq;
869cdf0e10cSrcweir }
870cdf0e10cSrcweir 
871cdf0e10cSrcweir // static
getImplementation(const uno::Reference<sheet::XSubTotalDescriptor> xObj)872cdf0e10cSrcweir ScSubTotalDescriptorBase* ScSubTotalDescriptorBase::getImplementation(
873cdf0e10cSrcweir 								const uno::Reference<sheet::XSubTotalDescriptor> xObj )
874cdf0e10cSrcweir {
875cdf0e10cSrcweir 	ScSubTotalDescriptorBase* pRet = NULL;
876cdf0e10cSrcweir 	uno::Reference<lang::XUnoTunnel> xUT( xObj, uno::UNO_QUERY );
877cdf0e10cSrcweir 	if (xUT.is())
878cdf0e10cSrcweir         pRet = reinterpret_cast<ScSubTotalDescriptorBase*>(sal::static_int_cast<sal_IntPtr>(xUT->getSomething(getUnoTunnelId())));
879cdf0e10cSrcweir 	return pRet;
880cdf0e10cSrcweir }
881cdf0e10cSrcweir 
882cdf0e10cSrcweir //------------------------------------------------------------------------
883cdf0e10cSrcweir 
ScSubTotalDescriptor()884cdf0e10cSrcweir ScSubTotalDescriptor::ScSubTotalDescriptor()
885cdf0e10cSrcweir {
886cdf0e10cSrcweir }
887cdf0e10cSrcweir 
~ScSubTotalDescriptor()888cdf0e10cSrcweir ScSubTotalDescriptor::~ScSubTotalDescriptor()
889cdf0e10cSrcweir {
890cdf0e10cSrcweir }
891cdf0e10cSrcweir 
GetData(ScSubTotalParam & rParam) const892cdf0e10cSrcweir void ScSubTotalDescriptor::GetData( ScSubTotalParam& rParam ) const
893cdf0e10cSrcweir {
894cdf0e10cSrcweir 	rParam = aStoredParam;			// Abfrage fuer Interface
895cdf0e10cSrcweir }
896cdf0e10cSrcweir 
PutData(const ScSubTotalParam & rParam)897cdf0e10cSrcweir void ScSubTotalDescriptor::PutData( const ScSubTotalParam& rParam )
898cdf0e10cSrcweir {
899cdf0e10cSrcweir 	aStoredParam = rParam;			// vom Interface gesetzt
900cdf0e10cSrcweir }
901cdf0e10cSrcweir 
SetParam(const ScSubTotalParam & rNew)902cdf0e10cSrcweir void ScSubTotalDescriptor::SetParam( const ScSubTotalParam& rNew )
903cdf0e10cSrcweir {
904cdf0e10cSrcweir 	aStoredParam = rNew;			// von aussen gesetzt
905cdf0e10cSrcweir }
906cdf0e10cSrcweir 
907cdf0e10cSrcweir //------------------------------------------------------------------------
908cdf0e10cSrcweir 
ScRangeSubTotalDescriptor(ScDatabaseRangeObj * pPar)909cdf0e10cSrcweir ScRangeSubTotalDescriptor::ScRangeSubTotalDescriptor(ScDatabaseRangeObj* pPar) :
910cdf0e10cSrcweir 	pParent(pPar)
911cdf0e10cSrcweir {
912cdf0e10cSrcweir 	if (pParent)
913cdf0e10cSrcweir 		pParent->acquire();
914cdf0e10cSrcweir }
915cdf0e10cSrcweir 
~ScRangeSubTotalDescriptor()916cdf0e10cSrcweir ScRangeSubTotalDescriptor::~ScRangeSubTotalDescriptor()
917cdf0e10cSrcweir {
918cdf0e10cSrcweir 	if (pParent)
919cdf0e10cSrcweir 		pParent->release();
920cdf0e10cSrcweir }
921cdf0e10cSrcweir 
GetData(ScSubTotalParam & rParam) const922cdf0e10cSrcweir void ScRangeSubTotalDescriptor::GetData( ScSubTotalParam& rParam ) const
923cdf0e10cSrcweir {
924cdf0e10cSrcweir 	if (pParent)
925cdf0e10cSrcweir 		pParent->GetSubTotalParam( rParam );
926cdf0e10cSrcweir }
927cdf0e10cSrcweir 
PutData(const ScSubTotalParam & rParam)928cdf0e10cSrcweir void ScRangeSubTotalDescriptor::PutData( const ScSubTotalParam& rParam )
929cdf0e10cSrcweir {
930cdf0e10cSrcweir 	if (pParent)
931cdf0e10cSrcweir 		pParent->SetSubTotalParam( rParam );
932cdf0e10cSrcweir }
933cdf0e10cSrcweir 
934cdf0e10cSrcweir //------------------------------------------------------------------------
935cdf0e10cSrcweir 
ScConsolidationDescriptor()936cdf0e10cSrcweir ScConsolidationDescriptor::ScConsolidationDescriptor()
937cdf0e10cSrcweir {
938cdf0e10cSrcweir }
939cdf0e10cSrcweir 
~ScConsolidationDescriptor()940cdf0e10cSrcweir ScConsolidationDescriptor::~ScConsolidationDescriptor()
941cdf0e10cSrcweir {
942cdf0e10cSrcweir }
943cdf0e10cSrcweir 
SetParam(const ScConsolidateParam & rNew)944cdf0e10cSrcweir void ScConsolidationDescriptor::SetParam( const ScConsolidateParam& rNew )
945cdf0e10cSrcweir {
946cdf0e10cSrcweir 	aParam = rNew;
947cdf0e10cSrcweir }
948cdf0e10cSrcweir 
949cdf0e10cSrcweir // XConsolidationDescriptor
950cdf0e10cSrcweir 
getFunction()951cdf0e10cSrcweir sheet::GeneralFunction SAL_CALL ScConsolidationDescriptor::getFunction() throw(uno::RuntimeException)
952cdf0e10cSrcweir {
953cdf0e10cSrcweir 	ScUnoGuard aGuard;
954cdf0e10cSrcweir 	return ScDataUnoConversion::SubTotalToGeneral(aParam.eFunction);
955cdf0e10cSrcweir }
956cdf0e10cSrcweir 
setFunction(sheet::GeneralFunction nFunction)957cdf0e10cSrcweir void SAL_CALL ScConsolidationDescriptor::setFunction( sheet::GeneralFunction nFunction )
958cdf0e10cSrcweir 													throw(uno::RuntimeException)
959cdf0e10cSrcweir {
960cdf0e10cSrcweir 	ScUnoGuard aGuard;
961cdf0e10cSrcweir 	aParam.eFunction = ScDataUnoConversion::GeneralToSubTotal(nFunction);
962cdf0e10cSrcweir }
963cdf0e10cSrcweir 
getSources()964cdf0e10cSrcweir uno::Sequence<table::CellRangeAddress> SAL_CALL ScConsolidationDescriptor::getSources()
965cdf0e10cSrcweir 														throw(uno::RuntimeException)
966cdf0e10cSrcweir {
967cdf0e10cSrcweir 	ScUnoGuard aGuard;
968cdf0e10cSrcweir 	sal_uInt16 nCount = aParam.nDataAreaCount;
969cdf0e10cSrcweir 	if (!aParam.ppDataAreas)
970cdf0e10cSrcweir 		nCount = 0;
971cdf0e10cSrcweir 	table::CellRangeAddress aRange;
972cdf0e10cSrcweir 	uno::Sequence<table::CellRangeAddress> aSeq(nCount);
973cdf0e10cSrcweir 	table::CellRangeAddress* pAry = aSeq.getArray();
974cdf0e10cSrcweir 	for (sal_uInt16 i=0; i<nCount; i++)
975cdf0e10cSrcweir 	{
976cdf0e10cSrcweir 		ScArea* pArea = aParam.ppDataAreas[i];
977cdf0e10cSrcweir 		if (pArea)
978cdf0e10cSrcweir 		{
979cdf0e10cSrcweir 			aRange.Sheet		= pArea->nTab;
980cdf0e10cSrcweir 			aRange.StartColumn	= pArea->nColStart;
981cdf0e10cSrcweir 			aRange.StartRow		= pArea->nRowStart;
982cdf0e10cSrcweir 			aRange.EndColumn	= pArea->nColEnd;
983cdf0e10cSrcweir 			aRange.EndRow		= pArea->nRowEnd;
984cdf0e10cSrcweir 		}
985cdf0e10cSrcweir 		pAry[i] = aRange;
986cdf0e10cSrcweir 	}
987cdf0e10cSrcweir 	return aSeq;
988cdf0e10cSrcweir }
989cdf0e10cSrcweir 
setSources(const uno::Sequence<table::CellRangeAddress> & aSources)990cdf0e10cSrcweir void SAL_CALL ScConsolidationDescriptor::setSources(
991cdf0e10cSrcweir 					const uno::Sequence<table::CellRangeAddress>& aSources )
992cdf0e10cSrcweir 												throw(uno::RuntimeException)
993cdf0e10cSrcweir {
994cdf0e10cSrcweir 	ScUnoGuard aGuard;
995cdf0e10cSrcweir 	sal_uInt16 nCount = (sal_uInt16)aSources.getLength();
996cdf0e10cSrcweir 	if (nCount)
997cdf0e10cSrcweir 	{
998cdf0e10cSrcweir 		const table::CellRangeAddress* pAry = aSources.getConstArray();
999cdf0e10cSrcweir 		ScArea** pNew = new ScArea*[nCount];
1000cdf0e10cSrcweir 		sal_uInt16 i;
1001cdf0e10cSrcweir 		for (i=0; i<nCount; i++)
1002cdf0e10cSrcweir 			pNew[i] = new ScArea( pAry[i].Sheet,
1003cdf0e10cSrcweir                     static_cast<SCCOL>(pAry[i].StartColumn), pAry[i].StartRow,
1004cdf0e10cSrcweir                     static_cast<SCCOL>(pAry[i].EndColumn),   pAry[i].EndRow );
1005cdf0e10cSrcweir 
1006cdf0e10cSrcweir 		aParam.SetAreas( pNew, nCount );	// kopiert alles
1007cdf0e10cSrcweir 
1008cdf0e10cSrcweir 		for (i=0; i<nCount; i++)
1009cdf0e10cSrcweir 			delete pNew[i];
1010cdf0e10cSrcweir 		delete[] pNew;
1011cdf0e10cSrcweir 	}
1012cdf0e10cSrcweir 	else
1013cdf0e10cSrcweir 		aParam.ClearDataAreas();
1014cdf0e10cSrcweir }
1015cdf0e10cSrcweir 
getStartOutputPosition()1016cdf0e10cSrcweir table::CellAddress SAL_CALL ScConsolidationDescriptor::getStartOutputPosition()
1017cdf0e10cSrcweir 													throw(uno::RuntimeException)
1018cdf0e10cSrcweir {
1019cdf0e10cSrcweir 	ScUnoGuard aGuard;
1020cdf0e10cSrcweir 	table::CellAddress aPos;
1021cdf0e10cSrcweir 	aPos.Column	= aParam.nCol;
1022cdf0e10cSrcweir 	aPos.Row	= aParam.nRow;
1023cdf0e10cSrcweir 	aPos.Sheet	= aParam.nTab;
1024cdf0e10cSrcweir 	return aPos;
1025cdf0e10cSrcweir }
1026cdf0e10cSrcweir 
setStartOutputPosition(const table::CellAddress & aStartOutputPosition)1027cdf0e10cSrcweir void SAL_CALL ScConsolidationDescriptor::setStartOutputPosition(
1028cdf0e10cSrcweir 								const table::CellAddress& aStartOutputPosition )
1029cdf0e10cSrcweir 									throw(uno::RuntimeException)
1030cdf0e10cSrcweir {
1031cdf0e10cSrcweir 	ScUnoGuard aGuard;
1032cdf0e10cSrcweir 	aParam.nCol = (SCCOL)aStartOutputPosition.Column;
1033cdf0e10cSrcweir 	aParam.nRow = (SCROW)aStartOutputPosition.Row;
1034cdf0e10cSrcweir 	aParam.nTab = aStartOutputPosition.Sheet;
1035cdf0e10cSrcweir }
1036cdf0e10cSrcweir 
getUseColumnHeaders()1037cdf0e10cSrcweir sal_Bool SAL_CALL ScConsolidationDescriptor::getUseColumnHeaders() throw(uno::RuntimeException)
1038cdf0e10cSrcweir {
1039cdf0e10cSrcweir 	ScUnoGuard aGuard;
1040cdf0e10cSrcweir 	return aParam.bByCol;
1041cdf0e10cSrcweir }
1042cdf0e10cSrcweir 
setUseColumnHeaders(sal_Bool bUseColumnHeaders)1043cdf0e10cSrcweir void SAL_CALL ScConsolidationDescriptor::setUseColumnHeaders( sal_Bool bUseColumnHeaders )
1044cdf0e10cSrcweir 													throw(uno::RuntimeException)
1045cdf0e10cSrcweir {
1046cdf0e10cSrcweir 	ScUnoGuard aGuard;
1047cdf0e10cSrcweir 	aParam.bByCol = bUseColumnHeaders;
1048cdf0e10cSrcweir }
1049cdf0e10cSrcweir 
getUseRowHeaders()1050cdf0e10cSrcweir sal_Bool SAL_CALL ScConsolidationDescriptor::getUseRowHeaders() throw(uno::RuntimeException)
1051cdf0e10cSrcweir {
1052cdf0e10cSrcweir 	ScUnoGuard aGuard;
1053cdf0e10cSrcweir 	return aParam.bByRow;
1054cdf0e10cSrcweir }
1055cdf0e10cSrcweir 
setUseRowHeaders(sal_Bool bUseRowHeaders)1056cdf0e10cSrcweir void SAL_CALL ScConsolidationDescriptor::setUseRowHeaders( sal_Bool bUseRowHeaders )
1057cdf0e10cSrcweir 													throw(uno::RuntimeException)
1058cdf0e10cSrcweir {
1059cdf0e10cSrcweir 	ScUnoGuard aGuard;
1060cdf0e10cSrcweir 	aParam.bByRow = bUseRowHeaders;
1061cdf0e10cSrcweir }
1062cdf0e10cSrcweir 
getInsertLinks()1063cdf0e10cSrcweir sal_Bool SAL_CALL ScConsolidationDescriptor::getInsertLinks() throw(uno::RuntimeException)
1064cdf0e10cSrcweir {
1065cdf0e10cSrcweir 	ScUnoGuard aGuard;
1066cdf0e10cSrcweir 	return aParam.bReferenceData;
1067cdf0e10cSrcweir }
1068cdf0e10cSrcweir 
setInsertLinks(sal_Bool bInsertLinks)1069cdf0e10cSrcweir void SAL_CALL ScConsolidationDescriptor::setInsertLinks( sal_Bool bInsertLinks )
1070cdf0e10cSrcweir 													throw(uno::RuntimeException)
1071cdf0e10cSrcweir {
1072cdf0e10cSrcweir 	ScUnoGuard aGuard;
1073cdf0e10cSrcweir 	aParam.bReferenceData = bInsertLinks;
1074cdf0e10cSrcweir }
1075cdf0e10cSrcweir 
1076cdf0e10cSrcweir //------------------------------------------------------------------------
1077cdf0e10cSrcweir 
ScFilterDescriptorBase(ScDocShell * pDocShell)1078cdf0e10cSrcweir ScFilterDescriptorBase::ScFilterDescriptorBase(ScDocShell* pDocShell) :
1079cdf0e10cSrcweir 	aPropSet( lcl_GetFilterPropertyMap() ),
1080cdf0e10cSrcweir     pDocSh(pDocShell)
1081cdf0e10cSrcweir {
1082cdf0e10cSrcweir 	if (pDocSh)
1083cdf0e10cSrcweir 		pDocSh->GetDocument()->AddUnoObject(*this);
1084cdf0e10cSrcweir }
1085cdf0e10cSrcweir 
~ScFilterDescriptorBase()1086cdf0e10cSrcweir ScFilterDescriptorBase::~ScFilterDescriptorBase()
1087cdf0e10cSrcweir {
1088cdf0e10cSrcweir 	if (pDocSh)
1089cdf0e10cSrcweir 		pDocSh->GetDocument()->RemoveUnoObject(*this);
1090cdf0e10cSrcweir }
1091cdf0e10cSrcweir 
Notify(SfxBroadcaster &,const SfxHint & rHint)1092cdf0e10cSrcweir void ScFilterDescriptorBase::Notify( SfxBroadcaster&, const SfxHint& rHint )
1093cdf0e10cSrcweir {
1094cdf0e10cSrcweir 	if ( rHint.ISA( SfxSimpleHint ) )
1095cdf0e10cSrcweir 	{
1096cdf0e10cSrcweir 		sal_uLong nId = ((const SfxSimpleHint&)rHint).GetId();
1097cdf0e10cSrcweir 		if ( nId == SFX_HINT_DYING )
1098cdf0e10cSrcweir 		{
1099cdf0e10cSrcweir 			pDocSh = NULL;			// invalid
1100cdf0e10cSrcweir 		}
1101cdf0e10cSrcweir 	}
1102cdf0e10cSrcweir }
1103cdf0e10cSrcweir 
1104cdf0e10cSrcweir // XSheetFilterDescriptor and XSheetFilterDescriptor2
1105cdf0e10cSrcweir 
getFilterFields()1106cdf0e10cSrcweir uno::Sequence<sheet::TableFilterField> SAL_CALL ScFilterDescriptorBase::getFilterFields()
1107cdf0e10cSrcweir 												throw(uno::RuntimeException)
1108cdf0e10cSrcweir {
1109cdf0e10cSrcweir 	ScUnoGuard aGuard;
1110cdf0e10cSrcweir 	ScQueryParam aParam;
1111cdf0e10cSrcweir 	GetData(aParam);
1112cdf0e10cSrcweir 
1113cdf0e10cSrcweir 	SCSIZE nEntries = aParam.GetEntryCount();	// allozierte Eintraege im Param
1114cdf0e10cSrcweir 	SCSIZE nCount = 0;							// aktive
1115cdf0e10cSrcweir 	while ( nCount < nEntries &&
1116cdf0e10cSrcweir 			aParam.GetEntry(nCount).bDoQuery )
1117cdf0e10cSrcweir 		++nCount;
1118cdf0e10cSrcweir 
1119cdf0e10cSrcweir 	sheet::TableFilterField aField;
1120cdf0e10cSrcweir 	uno::Sequence<sheet::TableFilterField> aSeq(static_cast<sal_Int32>(nCount));
1121cdf0e10cSrcweir 	sheet::TableFilterField* pAry = aSeq.getArray();
1122cdf0e10cSrcweir 	for (SCSIZE i=0; i<nCount; i++)
1123cdf0e10cSrcweir 	{
1124cdf0e10cSrcweir 		const ScQueryEntry& rEntry = aParam.GetEntry(i);
1125cdf0e10cSrcweir 
1126cdf0e10cSrcweir         rtl::OUString aStringValue;
1127cdf0e10cSrcweir 		if (rEntry.pStr)
1128cdf0e10cSrcweir 			aStringValue = *rEntry.pStr;
1129cdf0e10cSrcweir 
1130cdf0e10cSrcweir 		aField.Connection	 = (rEntry.eConnect == SC_AND) ? sheet::FilterConnection_AND :
1131cdf0e10cSrcweir 															 sheet::FilterConnection_OR;
1132cdf0e10cSrcweir 		aField.Field		 = rEntry.nField;
1133cdf0e10cSrcweir 		aField.IsNumeric	 = !rEntry.bQueryByString;
1134cdf0e10cSrcweir 		aField.StringValue	 = aStringValue;
1135cdf0e10cSrcweir 		aField.NumericValue	 = rEntry.nVal;
1136cdf0e10cSrcweir 
1137cdf0e10cSrcweir 		switch (rEntry.eOp)				// ScQueryOp
1138cdf0e10cSrcweir 		{
1139cdf0e10cSrcweir 			case SC_EQUAL:
1140cdf0e10cSrcweir                 {
1141cdf0e10cSrcweir                     aField.Operator = sheet::FilterOperator_EQUAL;
1142cdf0e10cSrcweir                     if (!rEntry.bQueryByString && *rEntry.pStr == EMPTY_STRING)
1143cdf0e10cSrcweir                     {
1144cdf0e10cSrcweir                         if (rEntry.nVal == SC_EMPTYFIELDS)
1145cdf0e10cSrcweir                         {
1146cdf0e10cSrcweir                             aField.Operator = sheet::FilterOperator_EMPTY;
1147cdf0e10cSrcweir                             aField.NumericValue = 0;
1148cdf0e10cSrcweir                         }
1149cdf0e10cSrcweir                         else if (rEntry.nVal == SC_NONEMPTYFIELDS)
1150cdf0e10cSrcweir                         {
1151cdf0e10cSrcweir                             aField.Operator = sheet::FilterOperator_NOT_EMPTY;
1152cdf0e10cSrcweir                             aField.NumericValue = 0;
1153cdf0e10cSrcweir                         }
1154cdf0e10cSrcweir                     }
1155cdf0e10cSrcweir                 }
1156cdf0e10cSrcweir                 break;
1157cdf0e10cSrcweir 			case SC_LESS:			aField.Operator = sheet::FilterOperator_LESS;			  break;
1158cdf0e10cSrcweir 			case SC_GREATER:		aField.Operator = sheet::FilterOperator_GREATER;		  break;
1159cdf0e10cSrcweir 			case SC_LESS_EQUAL:		aField.Operator = sheet::FilterOperator_LESS_EQUAL;	  break;
1160cdf0e10cSrcweir 			case SC_GREATER_EQUAL:	aField.Operator = sheet::FilterOperator_GREATER_EQUAL;  break;
1161cdf0e10cSrcweir 			case SC_NOT_EQUAL:		aField.Operator = sheet::FilterOperator_NOT_EQUAL;	  break;
1162cdf0e10cSrcweir 			case SC_TOPVAL:			aField.Operator = sheet::FilterOperator_TOP_VALUES;	  break;
1163cdf0e10cSrcweir 			case SC_BOTVAL:			aField.Operator = sheet::FilterOperator_BOTTOM_VALUES;  break;
1164cdf0e10cSrcweir 			case SC_TOPPERC:		aField.Operator = sheet::FilterOperator_TOP_PERCENT;	  break;
1165cdf0e10cSrcweir 			case SC_BOTPERC:		aField.Operator = sheet::FilterOperator_BOTTOM_PERCENT; break;
1166cdf0e10cSrcweir 			default:
1167cdf0e10cSrcweir 				DBG_ERROR("Falscher Filter-enum");
1168cdf0e10cSrcweir 				aField.Operator = sheet::FilterOperator_EMPTY;
1169cdf0e10cSrcweir 		}
1170cdf0e10cSrcweir 		pAry[i] = aField;
1171cdf0e10cSrcweir 	}
1172cdf0e10cSrcweir 	return aSeq;
1173cdf0e10cSrcweir }
1174cdf0e10cSrcweir 
getFilterFields2()1175cdf0e10cSrcweir uno::Sequence<sheet::TableFilterField2> SAL_CALL ScFilterDescriptorBase::getFilterFields2()
1176cdf0e10cSrcweir throw(uno::RuntimeException)
1177cdf0e10cSrcweir {
1178cdf0e10cSrcweir     ScUnoGuard aGuard;
1179cdf0e10cSrcweir     ScQueryParam aParam;
1180cdf0e10cSrcweir     GetData(aParam);
1181cdf0e10cSrcweir 
1182cdf0e10cSrcweir     SCSIZE nEntries = aParam.GetEntryCount();	// allozierte Eintraege im Param
1183cdf0e10cSrcweir     SCSIZE nCount = 0;							// aktive
1184cdf0e10cSrcweir     while ( nCount < nEntries &&
1185cdf0e10cSrcweir         aParam.GetEntry(nCount).bDoQuery )
1186cdf0e10cSrcweir         ++nCount;
1187cdf0e10cSrcweir 
1188cdf0e10cSrcweir     sheet::TableFilterField2 aField;
1189cdf0e10cSrcweir     uno::Sequence<sheet::TableFilterField2> aSeq(static_cast<sal_Int32>(nCount));
1190cdf0e10cSrcweir     sheet::TableFilterField2* pAry = aSeq.getArray();
1191cdf0e10cSrcweir     for (SCSIZE i=0; i<nCount; i++)
1192cdf0e10cSrcweir     {
1193cdf0e10cSrcweir         const ScQueryEntry& rEntry = aParam.GetEntry(i);
1194cdf0e10cSrcweir 
1195cdf0e10cSrcweir         rtl::OUString aStringValue;
1196cdf0e10cSrcweir         if (rEntry.pStr)
1197cdf0e10cSrcweir             aStringValue = *rEntry.pStr;
1198cdf0e10cSrcweir 
1199cdf0e10cSrcweir         aField.Connection	 = (rEntry.eConnect == SC_AND) ? sheet::FilterConnection_AND : sheet::FilterConnection_OR;
1200cdf0e10cSrcweir         aField.Field		 = rEntry.nField;
1201cdf0e10cSrcweir         aField.IsNumeric	 = !rEntry.bQueryByString;
1202cdf0e10cSrcweir         aField.StringValue	 = aStringValue;
1203cdf0e10cSrcweir         aField.NumericValue	 = rEntry.nVal;
1204cdf0e10cSrcweir 
1205cdf0e10cSrcweir         switch (rEntry.eOp)				// ScQueryOp
1206cdf0e10cSrcweir         {
1207cdf0e10cSrcweir         case SC_EQUAL:
1208cdf0e10cSrcweir             {
1209cdf0e10cSrcweir                 aField.Operator = sheet::FilterOperator2::EQUAL;
1210cdf0e10cSrcweir                 if (!rEntry.bQueryByString && *rEntry.pStr == EMPTY_STRING)
1211cdf0e10cSrcweir                 {
1212cdf0e10cSrcweir                     if (rEntry.nVal == SC_EMPTYFIELDS)
1213cdf0e10cSrcweir                     {
1214cdf0e10cSrcweir                         aField.Operator = sheet::FilterOperator2::EMPTY;
1215cdf0e10cSrcweir                         aField.NumericValue = 0;
1216cdf0e10cSrcweir                     }
1217cdf0e10cSrcweir                     else if (rEntry.nVal == SC_NONEMPTYFIELDS)
1218cdf0e10cSrcweir                     {
1219cdf0e10cSrcweir                         aField.Operator = sheet::FilterOperator2::NOT_EMPTY;
1220cdf0e10cSrcweir                         aField.NumericValue = 0;
1221cdf0e10cSrcweir                     }
1222cdf0e10cSrcweir                 }
1223cdf0e10cSrcweir             }
1224cdf0e10cSrcweir             break;
1225cdf0e10cSrcweir         case SC_LESS:			        aField.Operator = sheet::FilterOperator2::LESS;			        break;
1226cdf0e10cSrcweir         case SC_GREATER:		        aField.Operator = sheet::FilterOperator2::GREATER;		        break;
1227cdf0e10cSrcweir         case SC_LESS_EQUAL:		        aField.Operator = sheet::FilterOperator2::LESS_EQUAL;	        break;
1228cdf0e10cSrcweir         case SC_GREATER_EQUAL:	        aField.Operator = sheet::FilterOperator2::GREATER_EQUAL;        break;
1229cdf0e10cSrcweir         case SC_NOT_EQUAL:		        aField.Operator = sheet::FilterOperator2::NOT_EQUAL;	        break;
1230cdf0e10cSrcweir         case SC_TOPVAL:			        aField.Operator = sheet::FilterOperator2::TOP_VALUES;	        break;
1231cdf0e10cSrcweir         case SC_BOTVAL:			        aField.Operator = sheet::FilterOperator2::BOTTOM_VALUES;        break;
1232cdf0e10cSrcweir         case SC_TOPPERC:		        aField.Operator = sheet::FilterOperator2::TOP_PERCENT;	        break;
1233cdf0e10cSrcweir         case SC_BOTPERC:		        aField.Operator = sheet::FilterOperator2::BOTTOM_PERCENT;       break;
1234cdf0e10cSrcweir         case SC_CONTAINS:               aField.Operator = sheet::FilterOperator2::CONTAINS;             break;
1235cdf0e10cSrcweir         case SC_DOES_NOT_CONTAIN:       aField.Operator = sheet::FilterOperator2::DOES_NOT_CONTAIN;     break;
1236cdf0e10cSrcweir         case SC_BEGINS_WITH:            aField.Operator = sheet::FilterOperator2::BEGINS_WITH;          break;
1237cdf0e10cSrcweir         case SC_DOES_NOT_BEGIN_WITH:    aField.Operator = sheet::FilterOperator2::DOES_NOT_BEGIN_WITH;  break;
1238cdf0e10cSrcweir         case SC_ENDS_WITH:              aField.Operator = sheet::FilterOperator2::ENDS_WITH;            break;
1239cdf0e10cSrcweir         case SC_DOES_NOT_END_WITH:      aField.Operator = sheet::FilterOperator2::DOES_NOT_END_WITH;    break;
1240cdf0e10cSrcweir         default:
1241cdf0e10cSrcweir             DBG_ERROR("Falscher Filter-enum");
1242cdf0e10cSrcweir             aField.Operator = sheet::FilterOperator2::EMPTY;
1243cdf0e10cSrcweir         }
1244cdf0e10cSrcweir         pAry[i] = aField;
1245cdf0e10cSrcweir     }
1246cdf0e10cSrcweir     return aSeq;
1247cdf0e10cSrcweir }
1248cdf0e10cSrcweir 
setFilterFields(const uno::Sequence<sheet::TableFilterField> & aFilterFields)1249cdf0e10cSrcweir void SAL_CALL ScFilterDescriptorBase::setFilterFields(
1250cdf0e10cSrcweir 				const uno::Sequence<sheet::TableFilterField>& aFilterFields )
1251cdf0e10cSrcweir 												throw(uno::RuntimeException)
1252cdf0e10cSrcweir {
1253cdf0e10cSrcweir 	ScUnoGuard aGuard;
1254cdf0e10cSrcweir 	ScQueryParam aParam;
1255cdf0e10cSrcweir 	GetData(aParam);
1256cdf0e10cSrcweir 
1257cdf0e10cSrcweir 	SCSIZE nCount = static_cast<SCSIZE>(aFilterFields.getLength());
1258cdf0e10cSrcweir 	DBG_ASSERT( nCount <= MAXQUERY, "setFilterFields: zu viele" );
1259cdf0e10cSrcweir 
1260cdf0e10cSrcweir 	aParam.Resize( nCount );
1261cdf0e10cSrcweir 
1262cdf0e10cSrcweir 	const sheet::TableFilterField* pAry = aFilterFields.getConstArray();
1263cdf0e10cSrcweir 	SCSIZE i;
1264cdf0e10cSrcweir 	for (i=0; i<nCount; i++)
1265cdf0e10cSrcweir 	{
1266cdf0e10cSrcweir 		ScQueryEntry& rEntry = aParam.GetEntry(i);
1267cdf0e10cSrcweir 		if (!rEntry.pStr)
1268cdf0e10cSrcweir 			rEntry.pStr = new String;		// sollte nicht sein (soll immer initialisiert sein)
1269cdf0e10cSrcweir 
1270cdf0e10cSrcweir 		rEntry.bDoQuery			= sal_True;
1271cdf0e10cSrcweir 		rEntry.eConnect			= (pAry[i].Connection == sheet::FilterConnection_AND) ? SC_AND : SC_OR;
1272cdf0e10cSrcweir 		rEntry.nField			= pAry[i].Field;
1273cdf0e10cSrcweir 		rEntry.bQueryByString	= !pAry[i].IsNumeric;
1274cdf0e10cSrcweir 		*rEntry.pStr			= String( pAry[i].StringValue );
1275cdf0e10cSrcweir 		rEntry.nVal				= pAry[i].NumericValue;
1276cdf0e10cSrcweir 
1277cdf0e10cSrcweir         if (!rEntry.bQueryByString && pDocSh)
1278cdf0e10cSrcweir         {
1279cdf0e10cSrcweir             pDocSh->GetDocument()->GetFormatTable()->GetInputLineString(rEntry.nVal, 0, *rEntry.pStr);
1280cdf0e10cSrcweir         }
1281cdf0e10cSrcweir 
1282cdf0e10cSrcweir 		switch (pAry[i].Operator)			// FilterOperator
1283cdf0e10cSrcweir 		{
1284cdf0e10cSrcweir 			case sheet::FilterOperator_EQUAL:			rEntry.eOp = SC_EQUAL;		 break;
1285cdf0e10cSrcweir 			case sheet::FilterOperator_LESS:			rEntry.eOp = SC_LESS;			 break;
1286cdf0e10cSrcweir 			case sheet::FilterOperator_GREATER:			rEntry.eOp = SC_GREATER;		 break;
1287cdf0e10cSrcweir 			case sheet::FilterOperator_LESS_EQUAL:		rEntry.eOp = SC_LESS_EQUAL;	 break;
1288cdf0e10cSrcweir 			case sheet::FilterOperator_GREATER_EQUAL:	rEntry.eOp = SC_GREATER_EQUAL; break;
1289cdf0e10cSrcweir 			case sheet::FilterOperator_NOT_EQUAL:		rEntry.eOp = SC_NOT_EQUAL;	 break;
1290cdf0e10cSrcweir 			case sheet::FilterOperator_TOP_VALUES:		rEntry.eOp = SC_TOPVAL;		 break;
1291cdf0e10cSrcweir 			case sheet::FilterOperator_BOTTOM_VALUES:	rEntry.eOp = SC_BOTVAL;		 break;
1292cdf0e10cSrcweir 			case sheet::FilterOperator_TOP_PERCENT:		rEntry.eOp = SC_TOPPERC;		 break;
1293cdf0e10cSrcweir 			case sheet::FilterOperator_BOTTOM_PERCENT:	rEntry.eOp = SC_BOTPERC;		 break;
1294cdf0e10cSrcweir 			case sheet::FilterOperator_EMPTY:
1295cdf0e10cSrcweir                 {
1296cdf0e10cSrcweir                     rEntry.eOp = SC_EQUAL;
1297cdf0e10cSrcweir                     rEntry.nVal = SC_EMPTYFIELDS;
1298cdf0e10cSrcweir                     rEntry.bQueryByString = sal_False;
1299cdf0e10cSrcweir                     *rEntry.pStr = EMPTY_STRING;
1300cdf0e10cSrcweir                 }
1301cdf0e10cSrcweir                 break;
1302cdf0e10cSrcweir 			case sheet::FilterOperator_NOT_EMPTY:
1303cdf0e10cSrcweir                 {
1304cdf0e10cSrcweir                     rEntry.eOp = SC_EQUAL;
1305cdf0e10cSrcweir                     rEntry.nVal = SC_NONEMPTYFIELDS;
1306cdf0e10cSrcweir                     rEntry.bQueryByString = sal_False;
1307cdf0e10cSrcweir                     *rEntry.pStr = EMPTY_STRING;
1308cdf0e10cSrcweir                 }
1309cdf0e10cSrcweir                 break;
1310cdf0e10cSrcweir 			default:
1311cdf0e10cSrcweir 				DBG_ERROR("Falscher Query-enum");
1312cdf0e10cSrcweir 				rEntry.eOp = SC_EQUAL;
1313cdf0e10cSrcweir 		}
1314cdf0e10cSrcweir     }
1315cdf0e10cSrcweir 
1316cdf0e10cSrcweir 	SCSIZE nParamCount = aParam.GetEntryCount();	// Param wird nicht unter 8 resized
1317cdf0e10cSrcweir 	for (i=nCount; i<nParamCount; i++)
1318cdf0e10cSrcweir 		aParam.GetEntry(i).bDoQuery = sal_False;		// ueberzaehlige Felder zuruecksetzen
1319cdf0e10cSrcweir 
1320cdf0e10cSrcweir 	PutData(aParam);
1321cdf0e10cSrcweir }
1322cdf0e10cSrcweir 
setFilterFields2(const uno::Sequence<sheet::TableFilterField2> & aFilterFields)1323cdf0e10cSrcweir void SAL_CALL ScFilterDescriptorBase::setFilterFields2(
1324cdf0e10cSrcweir     const uno::Sequence<sheet::TableFilterField2>& aFilterFields )
1325cdf0e10cSrcweir     throw(uno::RuntimeException)
1326cdf0e10cSrcweir {
1327cdf0e10cSrcweir     ScUnoGuard aGuard;
1328cdf0e10cSrcweir     ScQueryParam aParam;
1329cdf0e10cSrcweir     GetData(aParam);
1330cdf0e10cSrcweir 
1331cdf0e10cSrcweir     SCSIZE nCount = static_cast<SCSIZE>(aFilterFields.getLength());
1332cdf0e10cSrcweir     DBG_ASSERT( nCount <= MAXQUERY, "setFilterFields: zu viele" );
1333cdf0e10cSrcweir 
1334cdf0e10cSrcweir     aParam.Resize( nCount );
1335cdf0e10cSrcweir 
1336cdf0e10cSrcweir     const sheet::TableFilterField2* pAry = aFilterFields.getConstArray();
1337cdf0e10cSrcweir     SCSIZE i;
1338cdf0e10cSrcweir     for (i=0; i<nCount; i++)
1339cdf0e10cSrcweir     {
1340cdf0e10cSrcweir         ScQueryEntry& rEntry = aParam.GetEntry(i);
1341cdf0e10cSrcweir         if (!rEntry.pStr)
1342cdf0e10cSrcweir             rEntry.pStr = new String;		// sollte nicht sein (soll immer initialisiert sein)
1343cdf0e10cSrcweir 
1344cdf0e10cSrcweir         rEntry.bDoQuery			= sal_True;
1345cdf0e10cSrcweir         rEntry.eConnect			= (pAry[i].Connection == sheet::FilterConnection_AND) ? SC_AND : SC_OR;
1346cdf0e10cSrcweir         rEntry.nField			= pAry[i].Field;
1347cdf0e10cSrcweir         rEntry.bQueryByString	= !pAry[i].IsNumeric;
1348cdf0e10cSrcweir         *rEntry.pStr			= String( pAry[i].StringValue );
1349cdf0e10cSrcweir         rEntry.nVal				= pAry[i].NumericValue;
1350cdf0e10cSrcweir 
1351cdf0e10cSrcweir         if (!rEntry.bQueryByString && pDocSh)
1352cdf0e10cSrcweir         {
1353cdf0e10cSrcweir             pDocSh->GetDocument()->GetFormatTable()->GetInputLineString(rEntry.nVal, 0, *rEntry.pStr);
1354cdf0e10cSrcweir         }
1355cdf0e10cSrcweir 
1356cdf0e10cSrcweir         switch (pAry[i].Operator)			// FilterOperator
1357cdf0e10cSrcweir         {
1358cdf0e10cSrcweir         case sheet::FilterOperator2::EQUAL:			        rEntry.eOp = SC_EQUAL;		        break;
1359cdf0e10cSrcweir         case sheet::FilterOperator2::LESS:			        rEntry.eOp = SC_LESS;			    break;
1360cdf0e10cSrcweir         case sheet::FilterOperator2::GREATER:			    rEntry.eOp = SC_GREATER;		    break;
1361cdf0e10cSrcweir         case sheet::FilterOperator2::LESS_EQUAL:		    rEntry.eOp = SC_LESS_EQUAL;	        break;
1362cdf0e10cSrcweir         case sheet::FilterOperator2::GREATER_EQUAL:	        rEntry.eOp = SC_GREATER_EQUAL;      break;
1363cdf0e10cSrcweir         case sheet::FilterOperator2::NOT_EQUAL:		        rEntry.eOp = SC_NOT_EQUAL;	        break;
1364cdf0e10cSrcweir         case sheet::FilterOperator2::TOP_VALUES:	    	rEntry.eOp = SC_TOPVAL;		        break;
1365cdf0e10cSrcweir         case sheet::FilterOperator2::BOTTOM_VALUES:	        rEntry.eOp = SC_BOTVAL;		        break;
1366cdf0e10cSrcweir         case sheet::FilterOperator2::TOP_PERCENT:		    rEntry.eOp = SC_TOPPERC;		    break;
1367cdf0e10cSrcweir         case sheet::FilterOperator2::BOTTOM_PERCENT:	    rEntry.eOp = SC_BOTPERC;		    break;
1368cdf0e10cSrcweir         case sheet::FilterOperator2::CONTAINS:		        rEntry.eOp = SC_CONTAINS;		    break;
1369cdf0e10cSrcweir         case sheet::FilterOperator2::DOES_NOT_CONTAIN:		rEntry.eOp = SC_DOES_NOT_CONTAIN;   break;
1370cdf0e10cSrcweir         case sheet::FilterOperator2::BEGINS_WITH:			rEntry.eOp = SC_BEGINS_WITH;		break;
1371cdf0e10cSrcweir         case sheet::FilterOperator2::DOES_NOT_BEGIN_WITH:	rEntry.eOp = SC_DOES_NOT_BEGIN_WITH;break;
1372cdf0e10cSrcweir         case sheet::FilterOperator2::ENDS_WITH:			    rEntry.eOp = SC_ENDS_WITH;		    break;
1373cdf0e10cSrcweir         case sheet::FilterOperator2::DOES_NOT_END_WITH:		rEntry.eOp = SC_DOES_NOT_END_WITH;	break;
1374cdf0e10cSrcweir         case sheet::FilterOperator2::EMPTY:
1375cdf0e10cSrcweir             {
1376cdf0e10cSrcweir                 rEntry.eOp = SC_EQUAL;
1377cdf0e10cSrcweir                 rEntry.nVal = SC_EMPTYFIELDS;
1378cdf0e10cSrcweir                 rEntry.bQueryByString = sal_False;
1379cdf0e10cSrcweir                 *rEntry.pStr = EMPTY_STRING;
1380cdf0e10cSrcweir             }
1381cdf0e10cSrcweir             break;
1382cdf0e10cSrcweir         case sheet::FilterOperator2::NOT_EMPTY:
1383cdf0e10cSrcweir             {
1384cdf0e10cSrcweir                 rEntry.eOp = SC_EQUAL;
1385cdf0e10cSrcweir                 rEntry.nVal = SC_NONEMPTYFIELDS;
1386cdf0e10cSrcweir                 rEntry.bQueryByString = sal_False;
1387cdf0e10cSrcweir                 *rEntry.pStr = EMPTY_STRING;
1388cdf0e10cSrcweir             }
1389cdf0e10cSrcweir             break;
1390cdf0e10cSrcweir         default:
1391cdf0e10cSrcweir             DBG_ERROR("Falscher Query-enum");
1392cdf0e10cSrcweir             rEntry.eOp = SC_EQUAL;
1393cdf0e10cSrcweir         }
1394cdf0e10cSrcweir     }
1395cdf0e10cSrcweir 
1396cdf0e10cSrcweir     SCSIZE nParamCount = aParam.GetEntryCount();	// Param wird nicht unter 8 resized
1397cdf0e10cSrcweir     for (i=nCount; i<nParamCount; i++)
1398cdf0e10cSrcweir         aParam.GetEntry(i).bDoQuery = sal_False;		// ueberzaehlige Felder zuruecksetzen
1399cdf0e10cSrcweir 
1400cdf0e10cSrcweir     PutData(aParam);
1401cdf0e10cSrcweir }
1402cdf0e10cSrcweir 
1403cdf0e10cSrcweir // Rest sind Properties
1404cdf0e10cSrcweir 
1405cdf0e10cSrcweir // XPropertySet
1406cdf0e10cSrcweir 
getPropertySetInfo()1407cdf0e10cSrcweir uno::Reference<beans::XPropertySetInfo> SAL_CALL ScFilterDescriptorBase::getPropertySetInfo()
1408cdf0e10cSrcweir 														throw(uno::RuntimeException)
1409cdf0e10cSrcweir {
1410cdf0e10cSrcweir 	ScUnoGuard aGuard;
1411cdf0e10cSrcweir 	static uno::Reference<beans::XPropertySetInfo> aRef(
1412cdf0e10cSrcweir 		new SfxItemPropertySetInfo( aPropSet.getPropertyMap() ));
1413cdf0e10cSrcweir 	return aRef;
1414cdf0e10cSrcweir }
1415cdf0e10cSrcweir 
setPropertyValue(const rtl::OUString & aPropertyName,const uno::Any & aValue)1416cdf0e10cSrcweir void SAL_CALL ScFilterDescriptorBase::setPropertyValue(
1417cdf0e10cSrcweir 						const rtl::OUString& aPropertyName, const uno::Any& aValue )
1418cdf0e10cSrcweir 				throw(beans::UnknownPropertyException, beans::PropertyVetoException,
1419cdf0e10cSrcweir 						lang::IllegalArgumentException, lang::WrappedTargetException,
1420cdf0e10cSrcweir 						uno::RuntimeException)
1421cdf0e10cSrcweir {
1422cdf0e10cSrcweir 	ScUnoGuard aGuard;
1423cdf0e10cSrcweir 	ScQueryParam aParam;
1424cdf0e10cSrcweir 	GetData(aParam);
1425cdf0e10cSrcweir 
1426cdf0e10cSrcweir 	String aString(aPropertyName);
1427cdf0e10cSrcweir 	if (aString.EqualsAscii( SC_UNONAME_CONTHDR ))
1428cdf0e10cSrcweir 		aParam.bHasHeader = ScUnoHelpFunctions::GetBoolFromAny( aValue );
1429cdf0e10cSrcweir 	else if (aString.EqualsAscii( SC_UNONAME_COPYOUT ))
1430cdf0e10cSrcweir 		aParam.bInplace = !(ScUnoHelpFunctions::GetBoolFromAny( aValue ));
1431cdf0e10cSrcweir 	else if (aString.EqualsAscii( SC_UNONAME_ISCASE ))
1432cdf0e10cSrcweir 		aParam.bCaseSens = ScUnoHelpFunctions::GetBoolFromAny( aValue );
1433cdf0e10cSrcweir 	else if (aString.EqualsAscii( SC_UNONAME_MAXFLD ))
1434cdf0e10cSrcweir 	{
1435cdf0e10cSrcweir 		sal_Int32 nVal = 0;
1436cdf0e10cSrcweir         if ( (aValue >>= nVal) && nVal > sal::static_int_cast<sal_Int32>(MAXQUERY) )
1437cdf0e10cSrcweir 		{
1438cdf0e10cSrcweir 			throw lang::IllegalArgumentException();
1439cdf0e10cSrcweir 		}
1440cdf0e10cSrcweir 	}
1441cdf0e10cSrcweir 	else if (aString.EqualsAscii( SC_UNONAME_ORIENT ))
1442cdf0e10cSrcweir 	{
1443cdf0e10cSrcweir 		//!	test for correct enum type?
1444cdf0e10cSrcweir 		table::TableOrientation eOrient = (table::TableOrientation)
1445cdf0e10cSrcweir 								ScUnoHelpFunctions::GetEnumFromAny( aValue );
1446cdf0e10cSrcweir 		aParam.bByRow = ( eOrient != table::TableOrientation_COLUMNS );
1447cdf0e10cSrcweir 	}
1448cdf0e10cSrcweir 	else if (aString.EqualsAscii( SC_UNONAME_OUTPOS ))
1449cdf0e10cSrcweir 	{
1450cdf0e10cSrcweir 		table::CellAddress aAddress;
1451cdf0e10cSrcweir 		if ( aValue >>= aAddress )
1452cdf0e10cSrcweir 		{
1453cdf0e10cSrcweir 			aParam.nDestTab = aAddress.Sheet;
1454cdf0e10cSrcweir 			aParam.nDestCol = (SCCOL)aAddress.Column;
1455cdf0e10cSrcweir 			aParam.nDestRow = (SCROW)aAddress.Row;
1456cdf0e10cSrcweir 		}
1457cdf0e10cSrcweir 	}
1458cdf0e10cSrcweir 	else if (aString.EqualsAscii( SC_UNONAME_SAVEOUT ))
1459cdf0e10cSrcweir 		aParam.bDestPers = ScUnoHelpFunctions::GetBoolFromAny( aValue );
1460cdf0e10cSrcweir 	else if (aString.EqualsAscii( SC_UNONAME_SKIPDUP ))
1461cdf0e10cSrcweir 		aParam.bDuplicate = !(ScUnoHelpFunctions::GetBoolFromAny( aValue ));
1462cdf0e10cSrcweir 	else if (aString.EqualsAscii( SC_UNONAME_USEREGEX ))
1463cdf0e10cSrcweir 		aParam.bRegExp = ScUnoHelpFunctions::GetBoolFromAny( aValue );
1464cdf0e10cSrcweir 
1465cdf0e10cSrcweir 	PutData(aParam);
1466cdf0e10cSrcweir }
1467cdf0e10cSrcweir 
getPropertyValue(const rtl::OUString & aPropertyName)1468cdf0e10cSrcweir uno::Any SAL_CALL ScFilterDescriptorBase::getPropertyValue( const rtl::OUString& aPropertyName )
1469cdf0e10cSrcweir 				throw(beans::UnknownPropertyException, lang::WrappedTargetException,
1470cdf0e10cSrcweir 						uno::RuntimeException)
1471cdf0e10cSrcweir {
1472cdf0e10cSrcweir 	ScUnoGuard aGuard;
1473cdf0e10cSrcweir 	ScQueryParam aParam;
1474cdf0e10cSrcweir 	GetData(aParam);
1475cdf0e10cSrcweir 
1476cdf0e10cSrcweir 	String aString(aPropertyName);
1477cdf0e10cSrcweir 	uno::Any aRet;
1478cdf0e10cSrcweir 
1479cdf0e10cSrcweir 	if (aString.EqualsAscii( SC_UNONAME_CONTHDR ))
1480cdf0e10cSrcweir 		ScUnoHelpFunctions::SetBoolInAny( aRet, aParam.bHasHeader );
1481cdf0e10cSrcweir 	else if (aString.EqualsAscii( SC_UNONAME_COPYOUT ))
1482cdf0e10cSrcweir 		ScUnoHelpFunctions::SetBoolInAny( aRet, !(aParam.bInplace) );
1483cdf0e10cSrcweir 	else if (aString.EqualsAscii( SC_UNONAME_ISCASE ))
1484cdf0e10cSrcweir 		ScUnoHelpFunctions::SetBoolInAny( aRet, aParam.bCaseSens );
1485cdf0e10cSrcweir 	else if (aString.EqualsAscii( SC_UNONAME_MAXFLD ))
1486cdf0e10cSrcweir 		aRet <<= (sal_Int32) MAXQUERY;
1487cdf0e10cSrcweir 	else if (aString.EqualsAscii( SC_UNONAME_ORIENT ))
1488cdf0e10cSrcweir 	{
1489cdf0e10cSrcweir 		table::TableOrientation eOrient = aParam.bByRow ? table::TableOrientation_ROWS :
1490cdf0e10cSrcweir 														  table::TableOrientation_COLUMNS;
1491cdf0e10cSrcweir 		aRet <<= eOrient;
1492cdf0e10cSrcweir 	}
1493cdf0e10cSrcweir 	else if (aString.EqualsAscii( SC_UNONAME_OUTPOS ))
1494cdf0e10cSrcweir 	{
1495cdf0e10cSrcweir 		table::CellAddress aOutPos;
1496cdf0e10cSrcweir 		aOutPos.Sheet  = aParam.nDestTab;
1497cdf0e10cSrcweir 		aOutPos.Column = aParam.nDestCol;
1498cdf0e10cSrcweir 		aOutPos.Row    = aParam.nDestRow;
1499cdf0e10cSrcweir 		aRet <<= aOutPos;
1500cdf0e10cSrcweir 	}
1501cdf0e10cSrcweir 	else if (aString.EqualsAscii( SC_UNONAME_SAVEOUT ))
1502cdf0e10cSrcweir 		ScUnoHelpFunctions::SetBoolInAny( aRet, aParam.bDestPers );
1503cdf0e10cSrcweir 	else if (aString.EqualsAscii( SC_UNONAME_SKIPDUP ))
1504cdf0e10cSrcweir 		ScUnoHelpFunctions::SetBoolInAny( aRet, !(aParam.bDuplicate) );
1505cdf0e10cSrcweir 	else if (aString.EqualsAscii( SC_UNONAME_USEREGEX ))
1506cdf0e10cSrcweir 		ScUnoHelpFunctions::SetBoolInAny( aRet, aParam.bRegExp );
1507cdf0e10cSrcweir 
1508cdf0e10cSrcweir 	return aRet;
1509cdf0e10cSrcweir }
1510cdf0e10cSrcweir 
SC_IMPL_DUMMY_PROPERTY_LISTENER(ScFilterDescriptorBase)1511cdf0e10cSrcweir SC_IMPL_DUMMY_PROPERTY_LISTENER( ScFilterDescriptorBase )
1512cdf0e10cSrcweir 
1513cdf0e10cSrcweir //------------------------------------------------------------------------
1514cdf0e10cSrcweir 
1515cdf0e10cSrcweir ScFilterDescriptor::ScFilterDescriptor(ScDocShell* pDocShell)
1516cdf0e10cSrcweir     :
1517cdf0e10cSrcweir     ScFilterDescriptorBase(pDocShell)
1518cdf0e10cSrcweir {
1519cdf0e10cSrcweir }
1520cdf0e10cSrcweir 
~ScFilterDescriptor()1521cdf0e10cSrcweir ScFilterDescriptor::~ScFilterDescriptor()
1522cdf0e10cSrcweir {
1523cdf0e10cSrcweir }
1524cdf0e10cSrcweir 
GetData(ScQueryParam & rParam) const1525cdf0e10cSrcweir void ScFilterDescriptor::GetData( ScQueryParam& rParam ) const
1526cdf0e10cSrcweir {
1527cdf0e10cSrcweir 	rParam = aStoredParam;			// Abfrage fuer Interface
1528cdf0e10cSrcweir }
1529cdf0e10cSrcweir 
PutData(const ScQueryParam & rParam)1530cdf0e10cSrcweir void ScFilterDescriptor::PutData( const ScQueryParam& rParam )
1531cdf0e10cSrcweir {
1532cdf0e10cSrcweir 	aStoredParam = rParam;			// vom Interface gesetzt
1533cdf0e10cSrcweir }
1534cdf0e10cSrcweir 
SetParam(const ScQueryParam & rNew)1535cdf0e10cSrcweir void ScFilterDescriptor::SetParam( const ScQueryParam& rNew )
1536cdf0e10cSrcweir {
1537cdf0e10cSrcweir 	aStoredParam = rNew;			// von aussen gesetzt
1538cdf0e10cSrcweir }
1539cdf0e10cSrcweir 
1540cdf0e10cSrcweir //------------------------------------------------------------------------
1541cdf0e10cSrcweir 
ScRangeFilterDescriptor(ScDocShell * pDocShell,ScDatabaseRangeObj * pPar)1542cdf0e10cSrcweir ScRangeFilterDescriptor::ScRangeFilterDescriptor(ScDocShell* pDocShell, ScDatabaseRangeObj* pPar) :
1543cdf0e10cSrcweir     ScFilterDescriptorBase(pDocShell),
1544cdf0e10cSrcweir 	pParent(pPar)
1545cdf0e10cSrcweir {
1546cdf0e10cSrcweir 	if (pParent)
1547cdf0e10cSrcweir 		pParent->acquire();
1548cdf0e10cSrcweir }
1549cdf0e10cSrcweir 
~ScRangeFilterDescriptor()1550cdf0e10cSrcweir ScRangeFilterDescriptor::~ScRangeFilterDescriptor()
1551cdf0e10cSrcweir {
1552cdf0e10cSrcweir 	if (pParent)
1553cdf0e10cSrcweir 		pParent->release();
1554cdf0e10cSrcweir }
1555cdf0e10cSrcweir 
GetData(ScQueryParam & rParam) const1556cdf0e10cSrcweir void ScRangeFilterDescriptor::GetData( ScQueryParam& rParam ) const
1557cdf0e10cSrcweir {
1558cdf0e10cSrcweir 	if (pParent)
1559cdf0e10cSrcweir 		pParent->GetQueryParam( rParam );
1560cdf0e10cSrcweir }
1561cdf0e10cSrcweir 
PutData(const ScQueryParam & rParam)1562cdf0e10cSrcweir void ScRangeFilterDescriptor::PutData( const ScQueryParam& rParam )
1563cdf0e10cSrcweir {
1564cdf0e10cSrcweir 	if (pParent)
1565cdf0e10cSrcweir 		pParent->SetQueryParam( rParam );
1566cdf0e10cSrcweir }
1567cdf0e10cSrcweir 
1568cdf0e10cSrcweir //------------------------------------------------------------------------
1569cdf0e10cSrcweir 
ScDataPilotFilterDescriptor(ScDocShell * pDocShell,ScDataPilotDescriptorBase * pPar)1570cdf0e10cSrcweir ScDataPilotFilterDescriptor::ScDataPilotFilterDescriptor(ScDocShell* pDocShell, ScDataPilotDescriptorBase* pPar) :
1571cdf0e10cSrcweir     ScFilterDescriptorBase(pDocShell),
1572cdf0e10cSrcweir 	pParent(pPar)
1573cdf0e10cSrcweir {
1574cdf0e10cSrcweir 	if (pParent)
1575cdf0e10cSrcweir 		pParent->acquire();
1576cdf0e10cSrcweir }
1577cdf0e10cSrcweir 
~ScDataPilotFilterDescriptor()1578cdf0e10cSrcweir ScDataPilotFilterDescriptor::~ScDataPilotFilterDescriptor()
1579cdf0e10cSrcweir {
1580cdf0e10cSrcweir 	if (pParent)
1581cdf0e10cSrcweir 		pParent->release();
1582cdf0e10cSrcweir }
1583cdf0e10cSrcweir 
GetData(ScQueryParam & rParam) const1584cdf0e10cSrcweir void ScDataPilotFilterDescriptor::GetData( ScQueryParam& rParam ) const
1585cdf0e10cSrcweir {
1586cdf0e10cSrcweir 	if (pParent)
1587cdf0e10cSrcweir 	{
1588cdf0e10cSrcweir 		ScDPObject* pDPObj = pParent->GetDPObject();
1589cdf0e10cSrcweir 		if (pDPObj && pDPObj->IsSheetData())
1590cdf0e10cSrcweir             rParam = pDPObj->GetSheetDesc()->aQueryParam;
1591cdf0e10cSrcweir 	}
1592cdf0e10cSrcweir }
1593cdf0e10cSrcweir 
PutData(const ScQueryParam & rParam)1594cdf0e10cSrcweir void ScDataPilotFilterDescriptor::PutData( const ScQueryParam& rParam )
1595cdf0e10cSrcweir {
1596cdf0e10cSrcweir 	if (pParent)
1597cdf0e10cSrcweir 	{
1598cdf0e10cSrcweir 		ScDPObject* pDPObj = pParent->GetDPObject();
1599cdf0e10cSrcweir         if (pDPObj)
1600cdf0e10cSrcweir         {
1601cdf0e10cSrcweir             ScSheetSourceDesc aSheetDesc;
1602cdf0e10cSrcweir 	        if (pDPObj->IsSheetData())
1603cdf0e10cSrcweir                 aSheetDesc = *pDPObj->GetSheetDesc();
1604cdf0e10cSrcweir             aSheetDesc.aQueryParam = rParam;
1605cdf0e10cSrcweir             pDPObj->SetSheetDesc(aSheetDesc);
1606cdf0e10cSrcweir             pParent->SetDPObject(pDPObj);
1607cdf0e10cSrcweir         }
1608cdf0e10cSrcweir 	}
1609cdf0e10cSrcweir }
1610cdf0e10cSrcweir 
1611cdf0e10cSrcweir //------------------------------------------------------------------------
1612cdf0e10cSrcweir 
ScDatabaseRangeObj(ScDocShell * pDocSh,const String & rNm)1613cdf0e10cSrcweir ScDatabaseRangeObj::ScDatabaseRangeObj(ScDocShell* pDocSh, const String& rNm) :
1614cdf0e10cSrcweir 	pDocShell( pDocSh ),
1615cdf0e10cSrcweir 	aName( rNm ),
1616cdf0e10cSrcweir 	aPropSet( lcl_GetDBRangePropertyMap() )
1617cdf0e10cSrcweir {
1618cdf0e10cSrcweir 	pDocShell->GetDocument()->AddUnoObject(*this);
1619cdf0e10cSrcweir }
1620cdf0e10cSrcweir 
~ScDatabaseRangeObj()1621cdf0e10cSrcweir ScDatabaseRangeObj::~ScDatabaseRangeObj()
1622cdf0e10cSrcweir {
1623cdf0e10cSrcweir 	if (pDocShell)
1624cdf0e10cSrcweir 		pDocShell->GetDocument()->RemoveUnoObject(*this);
1625cdf0e10cSrcweir }
1626cdf0e10cSrcweir 
Notify(SfxBroadcaster &,const SfxHint & rHint)1627cdf0e10cSrcweir void ScDatabaseRangeObj::Notify( SfxBroadcaster&, const SfxHint& rHint )
1628cdf0e10cSrcweir {
1629cdf0e10cSrcweir 
1630cdf0e10cSrcweir 	if ( rHint.ISA( SfxSimpleHint ) && ((const SfxSimpleHint&)rHint).GetId() == SFX_HINT_DYING )
1631cdf0e10cSrcweir 		pDocShell = NULL;		// ungueltig geworden
1632cdf0e10cSrcweir     else if ( rHint.ISA (ScDBRangeRefreshedHint) )
1633cdf0e10cSrcweir     {
1634cdf0e10cSrcweir         ScDBData* pDBData = GetDBData_Impl();
1635cdf0e10cSrcweir 		const ScDBRangeRefreshedHint& rRef = (const ScDBRangeRefreshedHint&)rHint;
1636cdf0e10cSrcweir         ScImportParam aParam;
1637cdf0e10cSrcweir         pDBData->GetImportParam(aParam);
1638cdf0e10cSrcweir         if (aParam == rRef.GetImportParam())
1639cdf0e10cSrcweir             Refreshed_Impl();
1640cdf0e10cSrcweir     }
1641cdf0e10cSrcweir }
1642cdf0e10cSrcweir 
1643cdf0e10cSrcweir // Hilfsfuntionen
1644cdf0e10cSrcweir 
GetDBData_Impl() const1645cdf0e10cSrcweir ScDBData* ScDatabaseRangeObj::GetDBData_Impl() const
1646cdf0e10cSrcweir {
1647cdf0e10cSrcweir 	ScDBData* pRet = NULL;
1648cdf0e10cSrcweir 	if (pDocShell)
1649cdf0e10cSrcweir 	{
1650cdf0e10cSrcweir 		ScDBCollection* pNames = pDocShell->GetDocument()->GetDBCollection();
1651cdf0e10cSrcweir 		if (pNames)
1652cdf0e10cSrcweir 		{
1653cdf0e10cSrcweir 			sal_uInt16 nPos = 0;
1654cdf0e10cSrcweir 			if (pNames->SearchName( aName, nPos ))
1655cdf0e10cSrcweir 				pRet = (*pNames)[nPos];
1656cdf0e10cSrcweir 		}
1657cdf0e10cSrcweir 	}
1658cdf0e10cSrcweir 	return pRet;
1659cdf0e10cSrcweir }
1660cdf0e10cSrcweir 
1661cdf0e10cSrcweir // XNamed
1662cdf0e10cSrcweir 
getName()1663cdf0e10cSrcweir rtl::OUString SAL_CALL ScDatabaseRangeObj::getName() throw(uno::RuntimeException)
1664cdf0e10cSrcweir {
1665cdf0e10cSrcweir 	ScUnoGuard aGuard;
1666cdf0e10cSrcweir 	return aName;
1667cdf0e10cSrcweir }
1668cdf0e10cSrcweir 
setName(const rtl::OUString & aNewName)1669cdf0e10cSrcweir void SAL_CALL ScDatabaseRangeObj::setName( const rtl::OUString& aNewName )
1670cdf0e10cSrcweir 												throw(uno::RuntimeException)
1671cdf0e10cSrcweir {
1672cdf0e10cSrcweir 	ScUnoGuard aGuard;
1673cdf0e10cSrcweir 	if (pDocShell)
1674cdf0e10cSrcweir 	{
1675cdf0e10cSrcweir 		ScDBDocFunc aFunc(*pDocShell);
1676cdf0e10cSrcweir 		String aNewStr(aNewName);
1677cdf0e10cSrcweir 		sal_Bool bOk = aFunc.RenameDBRange( aName, aNewStr, sal_True );
1678cdf0e10cSrcweir 		if (bOk)
1679cdf0e10cSrcweir 			aName = aNewStr;
1680cdf0e10cSrcweir 	}
1681cdf0e10cSrcweir }
1682cdf0e10cSrcweir 
1683cdf0e10cSrcweir // XDatabaseRange
1684cdf0e10cSrcweir 
getDataArea()1685cdf0e10cSrcweir table::CellRangeAddress SAL_CALL ScDatabaseRangeObj::getDataArea() throw(uno::RuntimeException)
1686cdf0e10cSrcweir {
1687cdf0e10cSrcweir 	ScUnoGuard aGuard;
1688cdf0e10cSrcweir 	table::CellRangeAddress aAddress;
1689cdf0e10cSrcweir 	ScDBData* pData = GetDBData_Impl();
1690cdf0e10cSrcweir 	if (pData)
1691cdf0e10cSrcweir 	{
1692cdf0e10cSrcweir 		ScRange aRange;
1693cdf0e10cSrcweir 		pData->GetArea(aRange);
1694cdf0e10cSrcweir 		aAddress.Sheet		 = aRange.aStart.Tab();
1695cdf0e10cSrcweir 		aAddress.StartColumn = aRange.aStart.Col();
1696cdf0e10cSrcweir 		aAddress.StartRow	 = aRange.aStart.Row();
1697cdf0e10cSrcweir 		aAddress.EndColumn	 = aRange.aEnd.Col();
1698cdf0e10cSrcweir 		aAddress.EndRow		 = aRange.aEnd.Row();
1699cdf0e10cSrcweir 	}
1700cdf0e10cSrcweir 	return aAddress;
1701cdf0e10cSrcweir }
1702cdf0e10cSrcweir 
setDataArea(const table::CellRangeAddress & aDataArea)1703cdf0e10cSrcweir void SAL_CALL ScDatabaseRangeObj::setDataArea( const table::CellRangeAddress& aDataArea )
1704cdf0e10cSrcweir 					    							throw(uno::RuntimeException)
1705cdf0e10cSrcweir {
1706cdf0e10cSrcweir 	ScUnoGuard aGuard;
1707cdf0e10cSrcweir 	ScDBData* pData = GetDBData_Impl();
1708cdf0e10cSrcweir 	if ( pDocShell && pData )
1709cdf0e10cSrcweir 	{
1710cdf0e10cSrcweir 		ScDBData aNewData( *pData );
1711cdf0e10cSrcweir 		//!	MoveTo ???
1712cdf0e10cSrcweir 		aNewData.SetArea( aDataArea.Sheet, (SCCOL)aDataArea.StartColumn, (SCROW)aDataArea.StartRow,
1713cdf0e10cSrcweir 										   (SCCOL)aDataArea.EndColumn, (SCROW)aDataArea.EndRow );
1714cdf0e10cSrcweir 		ScDBDocFunc aFunc(*pDocShell);
1715cdf0e10cSrcweir 		aFunc.ModifyDBData(aNewData, sal_True);
1716cdf0e10cSrcweir 	}
1717cdf0e10cSrcweir }
1718cdf0e10cSrcweir 
getSortDescriptor()1719cdf0e10cSrcweir uno::Sequence<beans::PropertyValue> SAL_CALL ScDatabaseRangeObj::getSortDescriptor()
1720cdf0e10cSrcweir 													throw(uno::RuntimeException)
1721cdf0e10cSrcweir {
1722cdf0e10cSrcweir 	ScUnoGuard aGuard;
1723cdf0e10cSrcweir 	ScSortParam aParam;
1724cdf0e10cSrcweir 	const ScDBData* pData = GetDBData_Impl();
1725cdf0e10cSrcweir 	if (pData)
1726cdf0e10cSrcweir 	{
1727cdf0e10cSrcweir 		pData->GetSortParam(aParam);
1728cdf0e10cSrcweir 
1729cdf0e10cSrcweir 		//	im SortDescriptor sind die Fields innerhalb des Bereichs gezaehlt
1730cdf0e10cSrcweir 		ScRange aDBRange;
1731cdf0e10cSrcweir 		pData->GetArea(aDBRange);
1732cdf0e10cSrcweir 		SCCOLROW nFieldStart = aParam.bByRow ? static_cast<SCCOLROW>(aDBRange.aStart.Col()) : static_cast<SCCOLROW>(aDBRange.aStart.Row());
1733cdf0e10cSrcweir 		for (sal_uInt16 i=0; i<MAXSORT; i++)
1734cdf0e10cSrcweir 			if ( aParam.bDoSort[i] && aParam.nField[i] >= nFieldStart )
1735cdf0e10cSrcweir 				aParam.nField[i] -= nFieldStart;
1736cdf0e10cSrcweir 	}
1737cdf0e10cSrcweir 
1738cdf0e10cSrcweir 	uno::Sequence<beans::PropertyValue> aSeq( ScSortDescriptor::GetPropertyCount() );
1739cdf0e10cSrcweir 	ScSortDescriptor::FillProperties( aSeq, aParam );
1740cdf0e10cSrcweir 	return aSeq;
1741cdf0e10cSrcweir }
1742cdf0e10cSrcweir 
GetQueryParam(ScQueryParam & rQueryParam) const1743cdf0e10cSrcweir void ScDatabaseRangeObj::GetQueryParam(ScQueryParam& rQueryParam) const
1744cdf0e10cSrcweir {
1745cdf0e10cSrcweir 	const ScDBData* pData = GetDBData_Impl();
1746cdf0e10cSrcweir 	if (pData)
1747cdf0e10cSrcweir 	{
1748cdf0e10cSrcweir 		pData->GetQueryParam(rQueryParam);
1749cdf0e10cSrcweir 
1750cdf0e10cSrcweir 		//	im FilterDescriptor sind die Fields innerhalb des Bereichs gezaehlt
1751cdf0e10cSrcweir 		ScRange aDBRange;
1752cdf0e10cSrcweir 		pData->GetArea(aDBRange);
1753cdf0e10cSrcweir 		SCCOLROW nFieldStart = rQueryParam.bByRow ? static_cast<SCCOLROW>(aDBRange.aStart.Col()) : static_cast<SCCOLROW>(aDBRange.aStart.Row());
1754cdf0e10cSrcweir 		SCSIZE nCount = rQueryParam.GetEntryCount();
1755cdf0e10cSrcweir 		for (SCSIZE i=0; i<nCount; i++)
1756cdf0e10cSrcweir 		{
1757cdf0e10cSrcweir 			ScQueryEntry& rEntry = rQueryParam.GetEntry(i);
1758cdf0e10cSrcweir 			if (rEntry.bDoQuery && rEntry.nField >= nFieldStart)
1759cdf0e10cSrcweir 				rEntry.nField -= nFieldStart;
1760cdf0e10cSrcweir 		}
1761cdf0e10cSrcweir 	}
1762cdf0e10cSrcweir }
1763cdf0e10cSrcweir 
SetQueryParam(const ScQueryParam & rQueryParam)1764cdf0e10cSrcweir void ScDatabaseRangeObj::SetQueryParam(const ScQueryParam& rQueryParam)
1765cdf0e10cSrcweir {
1766cdf0e10cSrcweir 	const ScDBData* pData = GetDBData_Impl();
1767cdf0e10cSrcweir 	if (pData)
1768cdf0e10cSrcweir 	{
1769cdf0e10cSrcweir 		//	im FilterDescriptor sind die Fields innerhalb des Bereichs gezaehlt
1770cdf0e10cSrcweir 		ScQueryParam aParam(rQueryParam);
1771cdf0e10cSrcweir 		ScRange aDBRange;
1772cdf0e10cSrcweir 		pData->GetArea(aDBRange);
1773cdf0e10cSrcweir 		SCCOLROW nFieldStart = aParam.bByRow ? static_cast<SCCOLROW>(aDBRange.aStart.Col()) : static_cast<SCCOLROW>(aDBRange.aStart.Row());
1774cdf0e10cSrcweir 
1775cdf0e10cSrcweir         SCSIZE nCount = aParam.GetEntryCount();
1776cdf0e10cSrcweir         for (SCSIZE i=0; i<nCount; i++)
1777cdf0e10cSrcweir         {
1778cdf0e10cSrcweir                ScQueryEntry& rEntry = aParam.GetEntry(i);
1779cdf0e10cSrcweir                if (rEntry.bDoQuery)
1780cdf0e10cSrcweir                        rEntry.nField += nFieldStart;
1781cdf0e10cSrcweir         }
1782cdf0e10cSrcweir 
1783cdf0e10cSrcweir         ScDBData aNewData( *pData );
1784cdf0e10cSrcweir 		aNewData.SetQueryParam(aParam);
1785cdf0e10cSrcweir 		aNewData.SetHeader(aParam.bHasHeader);		// not in ScDBData::SetQueryParam
1786cdf0e10cSrcweir 		ScDBDocFunc aFunc(*pDocShell);
1787cdf0e10cSrcweir 		aFunc.ModifyDBData(aNewData, sal_True);
1788cdf0e10cSrcweir 	}
1789cdf0e10cSrcweir }
1790cdf0e10cSrcweir 
getFilterDescriptor()1791cdf0e10cSrcweir uno::Reference<sheet::XSheetFilterDescriptor> SAL_CALL ScDatabaseRangeObj::getFilterDescriptor()
1792cdf0e10cSrcweir 												throw(uno::RuntimeException)
1793cdf0e10cSrcweir {
1794cdf0e10cSrcweir 	ScUnoGuard aGuard;
1795cdf0e10cSrcweir 	return new ScRangeFilterDescriptor(pDocShell, this);
1796cdf0e10cSrcweir }
1797cdf0e10cSrcweir 
GetSubTotalParam(ScSubTotalParam & rSubTotalParam) const1798cdf0e10cSrcweir void ScDatabaseRangeObj::GetSubTotalParam(ScSubTotalParam& rSubTotalParam) const
1799cdf0e10cSrcweir {
1800cdf0e10cSrcweir 	const ScDBData* pData = GetDBData_Impl();
1801cdf0e10cSrcweir 	if (pData)
1802cdf0e10cSrcweir 	{
1803cdf0e10cSrcweir 		pData->GetSubTotalParam(rSubTotalParam);
1804cdf0e10cSrcweir 
1805cdf0e10cSrcweir 		//	im FilterDescriptor sind die Fields innerhalb des Bereichs gezaehlt
1806cdf0e10cSrcweir 		ScRange aDBRange;
1807cdf0e10cSrcweir 		pData->GetArea(aDBRange);
1808cdf0e10cSrcweir 		SCCOL nFieldStart = aDBRange.aStart.Col();
1809cdf0e10cSrcweir 		for (sal_uInt16 i=0; i<MAXSUBTOTAL; i++)
1810cdf0e10cSrcweir 		{
1811cdf0e10cSrcweir 			if ( rSubTotalParam.bGroupActive[i] )
1812cdf0e10cSrcweir 			{
1813cdf0e10cSrcweir 				if ( rSubTotalParam.nField[i] >= nFieldStart )
1814cdf0e10cSrcweir                     rSubTotalParam.nField[i] = sal::static_int_cast<SCCOL>( rSubTotalParam.nField[i] - nFieldStart );
1815cdf0e10cSrcweir 				for (SCCOL j=0; j<rSubTotalParam.nSubTotals[i]; j++)
1816cdf0e10cSrcweir 					if ( rSubTotalParam.pSubTotals[i][j] >= nFieldStart )
1817cdf0e10cSrcweir                         rSubTotalParam.pSubTotals[i][j] =
1818cdf0e10cSrcweir                             sal::static_int_cast<SCCOL>( rSubTotalParam.pSubTotals[i][j] - nFieldStart );
1819cdf0e10cSrcweir 			}
1820cdf0e10cSrcweir 		}
1821cdf0e10cSrcweir 	}
1822cdf0e10cSrcweir }
1823cdf0e10cSrcweir 
SetSubTotalParam(const ScSubTotalParam & rSubTotalParam)1824cdf0e10cSrcweir void ScDatabaseRangeObj::SetSubTotalParam(const ScSubTotalParam& rSubTotalParam)
1825cdf0e10cSrcweir {
1826cdf0e10cSrcweir 	const ScDBData* pData = GetDBData_Impl();
1827cdf0e10cSrcweir 	if (pData)
1828cdf0e10cSrcweir 	{
1829cdf0e10cSrcweir 		//	im FilterDescriptor sind die Fields innerhalb des Bereichs gezaehlt
1830cdf0e10cSrcweir 		ScSubTotalParam aParam(rSubTotalParam);
1831cdf0e10cSrcweir 		ScRange aDBRange;
1832cdf0e10cSrcweir 		pData->GetArea(aDBRange);
1833cdf0e10cSrcweir 		SCCOL nFieldStart = aDBRange.aStart.Col();
1834cdf0e10cSrcweir 		for (sal_uInt16 i=0; i<MAXSUBTOTAL; i++)
1835cdf0e10cSrcweir 		{
1836cdf0e10cSrcweir 			if ( aParam.bGroupActive[i] )
1837cdf0e10cSrcweir 			{
1838cdf0e10cSrcweir                 aParam.nField[i] = sal::static_int_cast<SCCOL>( aParam.nField[i] + nFieldStart );
1839cdf0e10cSrcweir 				for (SCCOL j=0; j<aParam.nSubTotals[i]; j++)
1840cdf0e10cSrcweir                     aParam.pSubTotals[i][j] = sal::static_int_cast<SCCOL>( aParam.pSubTotals[i][j] + nFieldStart );
1841cdf0e10cSrcweir 			}
1842cdf0e10cSrcweir 		}
1843cdf0e10cSrcweir 
1844cdf0e10cSrcweir 		ScDBData aNewData( *pData );
1845cdf0e10cSrcweir 		aNewData.SetSubTotalParam(aParam);
1846cdf0e10cSrcweir 		ScDBDocFunc aFunc(*pDocShell);
1847cdf0e10cSrcweir 		aFunc.ModifyDBData(aNewData, sal_True);
1848cdf0e10cSrcweir 	}
1849cdf0e10cSrcweir }
1850cdf0e10cSrcweir 
getSubTotalDescriptor()1851cdf0e10cSrcweir uno::Reference<sheet::XSubTotalDescriptor> SAL_CALL ScDatabaseRangeObj::getSubTotalDescriptor()
1852cdf0e10cSrcweir 												throw(uno::RuntimeException)
1853cdf0e10cSrcweir {
1854cdf0e10cSrcweir 	ScUnoGuard aGuard;
1855cdf0e10cSrcweir 	return new ScRangeSubTotalDescriptor(this);
1856cdf0e10cSrcweir }
1857cdf0e10cSrcweir 
getImportDescriptor()1858cdf0e10cSrcweir uno::Sequence<beans::PropertyValue> SAL_CALL ScDatabaseRangeObj::getImportDescriptor()
1859cdf0e10cSrcweir 												throw(uno::RuntimeException)
1860cdf0e10cSrcweir {
1861cdf0e10cSrcweir 	ScUnoGuard aGuard;
1862cdf0e10cSrcweir 	ScImportParam aParam;
1863cdf0e10cSrcweir 	const ScDBData* pData = GetDBData_Impl();
1864cdf0e10cSrcweir 	if (pData)
1865cdf0e10cSrcweir 		pData->GetImportParam(aParam);
1866cdf0e10cSrcweir 
1867cdf0e10cSrcweir 	uno::Sequence<beans::PropertyValue> aSeq( ScImportDescriptor::GetPropertyCount() );
1868cdf0e10cSrcweir 	ScImportDescriptor::FillProperties( aSeq, aParam );
1869cdf0e10cSrcweir 	return aSeq;
1870cdf0e10cSrcweir }
1871cdf0e10cSrcweir 
1872cdf0e10cSrcweir // XRefreshable
1873cdf0e10cSrcweir 
refresh()1874cdf0e10cSrcweir void SAL_CALL ScDatabaseRangeObj::refresh() throw(uno::RuntimeException)
1875cdf0e10cSrcweir {
1876cdf0e10cSrcweir 	ScUnoGuard aGuard;
1877cdf0e10cSrcweir 	ScDBData* pData = GetDBData_Impl();
1878cdf0e10cSrcweir 	if ( pDocShell && pData )
1879cdf0e10cSrcweir 	{
1880cdf0e10cSrcweir 		ScDBDocFunc aFunc(*pDocShell);
1881cdf0e10cSrcweir 
1882cdf0e10cSrcweir 		// Import zu wiederholen?
1883cdf0e10cSrcweir 		sal_Bool bContinue = sal_True;
1884cdf0e10cSrcweir 		ScImportParam aImportParam;
1885cdf0e10cSrcweir 		pData->GetImportParam( aImportParam );
1886cdf0e10cSrcweir 		if (aImportParam.bImport && !pData->HasImportSelection())
1887cdf0e10cSrcweir 		{
1888cdf0e10cSrcweir             SCTAB nTab;
1889cdf0e10cSrcweir             SCCOL nDummyCol;
1890cdf0e10cSrcweir             SCROW nDummyRow;
1891cdf0e10cSrcweir             pData->GetArea( nTab, nDummyCol,nDummyRow,nDummyCol,nDummyRow );
1892cdf0e10cSrcweir             bContinue = aFunc.DoImport( nTab, aImportParam, NULL, sal_True );   //! Api-Flag as parameter
1893cdf0e10cSrcweir 		}
1894cdf0e10cSrcweir 
1895cdf0e10cSrcweir 		// interne Operationen (sort, query, subtotal) nur, wenn kein Fehler
1896cdf0e10cSrcweir 		if (bContinue)
1897cdf0e10cSrcweir 			aFunc.RepeatDB( pData->GetName(), sal_True, sal_True );
1898cdf0e10cSrcweir 	}
1899cdf0e10cSrcweir }
1900cdf0e10cSrcweir 
addRefreshListener(const uno::Reference<util::XRefreshListener> & xListener)1901cdf0e10cSrcweir void SAL_CALL ScDatabaseRangeObj::addRefreshListener(
1902cdf0e10cSrcweir 								const uno::Reference<util::XRefreshListener >& xListener )
1903cdf0e10cSrcweir 												throw(uno::RuntimeException)
1904cdf0e10cSrcweir {
1905cdf0e10cSrcweir 	ScUnoGuard aGuard;
1906cdf0e10cSrcweir 	uno::Reference<util::XRefreshListener>* pObj =
1907cdf0e10cSrcweir 			new uno::Reference<util::XRefreshListener>( xListener );
1908cdf0e10cSrcweir 	aRefreshListeners.Insert( pObj, aRefreshListeners.Count() );
1909cdf0e10cSrcweir 
1910cdf0e10cSrcweir 	//	hold one additional ref to keep this object alive as long as there are listeners
1911cdf0e10cSrcweir 	if ( aRefreshListeners.Count() == 1 )
1912cdf0e10cSrcweir 		acquire();
1913cdf0e10cSrcweir }
1914cdf0e10cSrcweir 
removeRefreshListener(const uno::Reference<util::XRefreshListener> & xListener)1915cdf0e10cSrcweir void SAL_CALL ScDatabaseRangeObj::removeRefreshListener(
1916cdf0e10cSrcweir 								const uno::Reference<util::XRefreshListener >& xListener )
1917cdf0e10cSrcweir 												throw(uno::RuntimeException)
1918cdf0e10cSrcweir {
1919cdf0e10cSrcweir 	ScUnoGuard aGuard;
1920cdf0e10cSrcweir 	sal_uInt16 nCount = aRefreshListeners.Count();
1921cdf0e10cSrcweir 	for ( sal_uInt16 n=nCount; n--; )
1922cdf0e10cSrcweir 	{
1923cdf0e10cSrcweir 		uno::Reference<util::XRefreshListener>* pObj = aRefreshListeners[n];
1924cdf0e10cSrcweir 		if ( *pObj == xListener )
1925cdf0e10cSrcweir 		{
1926cdf0e10cSrcweir 			aRefreshListeners.DeleteAndDestroy( n );
1927cdf0e10cSrcweir 			if ( aRefreshListeners.Count() == 0 )
1928cdf0e10cSrcweir 				release();							// release ref for listeners
1929cdf0e10cSrcweir 			break;
1930cdf0e10cSrcweir 		}
1931cdf0e10cSrcweir 	}
1932cdf0e10cSrcweir }
1933cdf0e10cSrcweir 
Refreshed_Impl()1934cdf0e10cSrcweir void ScDatabaseRangeObj::Refreshed_Impl()
1935cdf0e10cSrcweir {
1936cdf0e10cSrcweir 	lang::EventObject aEvent;
1937cdf0e10cSrcweir 	aEvent.Source = (cppu::OWeakObject*)this;
1938cdf0e10cSrcweir 	for ( sal_uInt16 n=0; n<aRefreshListeners.Count(); n++ )
1939cdf0e10cSrcweir 		(*aRefreshListeners[n])->refreshed( aEvent );
1940cdf0e10cSrcweir }
1941cdf0e10cSrcweir 
1942cdf0e10cSrcweir // XCellRangeSource
1943cdf0e10cSrcweir 
getReferredCells()1944cdf0e10cSrcweir uno::Reference<table::XCellRange> SAL_CALL ScDatabaseRangeObj::getReferredCells()
1945cdf0e10cSrcweir 												throw(uno::RuntimeException)
1946cdf0e10cSrcweir {
1947cdf0e10cSrcweir 	ScUnoGuard aGuard;
1948cdf0e10cSrcweir 	ScRange aRange;
1949cdf0e10cSrcweir 	ScDBData* pData = GetDBData_Impl();
1950cdf0e10cSrcweir 	if ( pData )
1951cdf0e10cSrcweir 	{
1952cdf0e10cSrcweir 		//!	static Funktion um ScCellObj/ScCellRangeObj zu erzeugen am ScCellRangeObj ???
1953cdf0e10cSrcweir 
1954cdf0e10cSrcweir 		pData->GetArea(aRange);
1955cdf0e10cSrcweir 		if ( aRange.aStart == aRange.aEnd )
1956cdf0e10cSrcweir 			return new ScCellObj( pDocShell, aRange.aStart );
1957cdf0e10cSrcweir 		else
1958cdf0e10cSrcweir 			return new ScCellRangeObj( pDocShell, aRange );
1959cdf0e10cSrcweir 	}
1960cdf0e10cSrcweir 	return NULL;
1961cdf0e10cSrcweir }
1962cdf0e10cSrcweir 
1963cdf0e10cSrcweir // XPropertySet
1964cdf0e10cSrcweir 
getPropertySetInfo()1965cdf0e10cSrcweir uno::Reference<beans::XPropertySetInfo> SAL_CALL ScDatabaseRangeObj::getPropertySetInfo()
1966cdf0e10cSrcweir 														throw(uno::RuntimeException)
1967cdf0e10cSrcweir {
1968cdf0e10cSrcweir 	ScUnoGuard aGuard;
1969cdf0e10cSrcweir 	static uno::Reference<beans::XPropertySetInfo> aRef(
1970cdf0e10cSrcweir 		new SfxItemPropertySetInfo( aPropSet.getPropertyMap() ));
1971cdf0e10cSrcweir 	return aRef;
1972cdf0e10cSrcweir }
1973cdf0e10cSrcweir 
setPropertyValue(const rtl::OUString & aPropertyName,const uno::Any & aValue)1974cdf0e10cSrcweir void SAL_CALL ScDatabaseRangeObj::setPropertyValue(
1975cdf0e10cSrcweir 						const rtl::OUString& aPropertyName, const uno::Any& aValue )
1976cdf0e10cSrcweir 				throw(beans::UnknownPropertyException, beans::PropertyVetoException,
1977cdf0e10cSrcweir 						lang::IllegalArgumentException, lang::WrappedTargetException,
1978cdf0e10cSrcweir 						uno::RuntimeException)
1979cdf0e10cSrcweir {
1980cdf0e10cSrcweir 	ScUnoGuard aGuard;
1981cdf0e10cSrcweir 	ScDBData* pData = GetDBData_Impl();
1982cdf0e10cSrcweir 	if ( pDocShell && pData )
1983cdf0e10cSrcweir 	{
1984cdf0e10cSrcweir 		ScDBData aNewData( *pData );
1985cdf0e10cSrcweir 		sal_Bool bDo = sal_True;
1986cdf0e10cSrcweir 
1987cdf0e10cSrcweir 		String aString(aPropertyName);
1988cdf0e10cSrcweir 		if ( aString.EqualsAscii( SC_UNONAME_KEEPFORM ) )
1989cdf0e10cSrcweir 			aNewData.SetKeepFmt( ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
1990cdf0e10cSrcweir 		else if ( aString.EqualsAscii( SC_UNONAME_MOVCELLS ) )
1991cdf0e10cSrcweir 			aNewData.SetDoSize( ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
1992cdf0e10cSrcweir 		else if ( aString.EqualsAscii( SC_UNONAME_STRIPDAT ) )
1993cdf0e10cSrcweir 			aNewData.SetStripData( ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
1994cdf0e10cSrcweir 	    else if (aString.EqualsAscii( SC_UNONAME_AUTOFLT ))
1995cdf0e10cSrcweir         {
1996cdf0e10cSrcweir 		    sal_Bool bAutoFilter(ScUnoHelpFunctions::GetBoolFromAny( aValue ));
1997cdf0e10cSrcweir 	        aNewData.SetAutoFilter(bAutoFilter);
1998cdf0e10cSrcweir             ScRange aRange;
1999cdf0e10cSrcweir             aNewData.GetArea(aRange);
2000cdf0e10cSrcweir             ScDocument* pDoc = pDocShell->GetDocument();
2001cdf0e10cSrcweir 	        if (bAutoFilter && pDoc)
2002cdf0e10cSrcweir 		        pDoc->ApplyFlagsTab( aRange.aStart.Col(), aRange.aStart.Row(),
2003cdf0e10cSrcweir 								     aRange.aEnd.Col(), aRange.aStart.Row(),
2004cdf0e10cSrcweir 								     aRange.aStart.Tab(), SC_MF_AUTO );
2005cdf0e10cSrcweir             else  if (!bAutoFilter && pDoc)
2006cdf0e10cSrcweir                 pDoc->RemoveFlagsTab(aRange.aStart.Col(), aRange.aStart.Row(),
2007cdf0e10cSrcweir 								     aRange.aEnd.Col(), aRange.aStart.Row(),
2008cdf0e10cSrcweir 								     aRange.aStart.Tab(), SC_MF_AUTO );
2009cdf0e10cSrcweir             ScRange aPaintRange(aRange.aStart, aRange.aEnd);
2010cdf0e10cSrcweir             aPaintRange.aEnd.SetRow(aPaintRange.aStart.Row());
2011cdf0e10cSrcweir             pDocShell->PostPaint(aPaintRange, PAINT_GRID);
2012cdf0e10cSrcweir         }
2013cdf0e10cSrcweir 	    else if (aString.EqualsAscii( SC_UNONAME_USEFLTCRT ))
2014cdf0e10cSrcweir         {
2015cdf0e10cSrcweir 		    if (ScUnoHelpFunctions::GetBoolFromAny( aValue ))
2016cdf0e10cSrcweir             {
2017cdf0e10cSrcweir                 ScRange aRange;
2018cdf0e10cSrcweir                 aNewData.GetAdvancedQuerySource(aRange);
2019cdf0e10cSrcweir                 aNewData.SetAdvancedQuerySource(&aRange);
2020cdf0e10cSrcweir             }
2021cdf0e10cSrcweir             else
2022cdf0e10cSrcweir                 aNewData.SetAdvancedQuerySource(NULL);
2023cdf0e10cSrcweir         }
2024cdf0e10cSrcweir 	    else if (aString.EqualsAscii( SC_UNONAME_FLTCRT ))
2025cdf0e10cSrcweir         {
2026cdf0e10cSrcweir             table::CellRangeAddress aRange;
2027cdf0e10cSrcweir             if (aValue >>= aRange)
2028cdf0e10cSrcweir             {
2029cdf0e10cSrcweir                 ScRange aCoreRange;
2030cdf0e10cSrcweir                 ScUnoConversion::FillScRange(aCoreRange, aRange);
2031cdf0e10cSrcweir 
2032cdf0e10cSrcweir                 aNewData.SetAdvancedQuerySource(&aCoreRange);
2033cdf0e10cSrcweir             }
2034cdf0e10cSrcweir         }
2035cdf0e10cSrcweir         else if (aString.EqualsAscii( SC_UNONAME_FROMSELECT ))
2036cdf0e10cSrcweir         {
2037cdf0e10cSrcweir             aNewData.SetImportSelection(::cppu::any2bool(aValue));
2038cdf0e10cSrcweir         }
2039cdf0e10cSrcweir 		else if (aString.EqualsAscii( SC_UNONAME_REFPERIOD ))
2040cdf0e10cSrcweir 		{
2041cdf0e10cSrcweir 		    sal_Int32 nRefresh = 0;
2042cdf0e10cSrcweir 		    if (aValue >>= nRefresh)
2043cdf0e10cSrcweir 		    {
2044cdf0e10cSrcweir                 ScDocument* pDoc = pDocShell->GetDocument();
2045cdf0e10cSrcweir 		        aNewData.SetRefreshDelay(nRefresh);
2046cdf0e10cSrcweir                 if (pDoc && pDoc->GetDBCollection())
2047cdf0e10cSrcweir                 {
2048cdf0e10cSrcweir 				    aNewData.SetRefreshHandler( pDoc->GetDBCollection()->GetRefreshHandler() );
2049cdf0e10cSrcweir 			        aNewData.SetRefreshControl( pDoc->GetRefreshTimerControlAddress() );
2050cdf0e10cSrcweir                 }
2051cdf0e10cSrcweir             }
2052cdf0e10cSrcweir 		}
2053cdf0e10cSrcweir         else if (aString.EqualsAscii( SC_UNONAME_CONRES ))
2054cdf0e10cSrcweir         {
2055cdf0e10cSrcweir         }
2056cdf0e10cSrcweir 		else
2057cdf0e10cSrcweir 			bDo = sal_False;
2058cdf0e10cSrcweir 
2059cdf0e10cSrcweir 		if (bDo)
2060cdf0e10cSrcweir 		{
2061cdf0e10cSrcweir 			ScDBDocFunc aFunc(*pDocShell);
2062cdf0e10cSrcweir 			aFunc.ModifyDBData(aNewData, sal_True);
2063cdf0e10cSrcweir 		}
2064cdf0e10cSrcweir 	}
2065cdf0e10cSrcweir }
2066cdf0e10cSrcweir 
getPropertyValue(const rtl::OUString & aPropertyName)2067cdf0e10cSrcweir uno::Any SAL_CALL ScDatabaseRangeObj::getPropertyValue( const rtl::OUString& aPropertyName )
2068cdf0e10cSrcweir 				throw(beans::UnknownPropertyException, lang::WrappedTargetException,
2069cdf0e10cSrcweir 						uno::RuntimeException)
2070cdf0e10cSrcweir {
2071cdf0e10cSrcweir 	ScUnoGuard aGuard;
2072cdf0e10cSrcweir 	uno::Any aRet;
2073cdf0e10cSrcweir 	ScDBData* pData = GetDBData_Impl();
2074cdf0e10cSrcweir 	if ( pData )
2075cdf0e10cSrcweir 	{
2076cdf0e10cSrcweir 		String aString(aPropertyName);
2077cdf0e10cSrcweir 		if ( aString.EqualsAscii( SC_UNONAME_KEEPFORM ) )
2078cdf0e10cSrcweir 			ScUnoHelpFunctions::SetBoolInAny( aRet, pData->IsKeepFmt() );
2079cdf0e10cSrcweir 		else if ( aString.EqualsAscii( SC_UNONAME_MOVCELLS ) )
2080cdf0e10cSrcweir 			ScUnoHelpFunctions::SetBoolInAny( aRet, pData->IsDoSize() );
2081cdf0e10cSrcweir 		else if ( aString.EqualsAscii( SC_UNONAME_STRIPDAT ) )
2082cdf0e10cSrcweir 			ScUnoHelpFunctions::SetBoolInAny( aRet, pData->IsStripData() );
2083cdf0e10cSrcweir 		else if ( aString.EqualsAscii( SC_UNONAME_ISUSER ) )
2084cdf0e10cSrcweir 		{
2085cdf0e10cSrcweir 			//	all database ranges except "unnamed" are user defined
2086cdf0e10cSrcweir 			ScUnoHelpFunctions::SetBoolInAny( aRet,
2087cdf0e10cSrcweir 						( pData->GetName() != ScGlobal::GetRscString(STR_DB_NONAME) ) );
2088cdf0e10cSrcweir 		}
2089cdf0e10cSrcweir 		else if ( aString.EqualsAscii( SC_UNO_LINKDISPBIT ) )
2090cdf0e10cSrcweir 		{
2091cdf0e10cSrcweir 			//	no target bitmaps for individual entries (would be all equal)
2092cdf0e10cSrcweir 			// ScLinkTargetTypeObj::SetLinkTargetBitmap( aRet, SC_LINKTARGETTYPE_DBAREA );
2093cdf0e10cSrcweir 		}
2094cdf0e10cSrcweir 		else if ( aString.EqualsAscii( SC_UNO_LINKDISPNAME ) )
2095cdf0e10cSrcweir 			aRet <<= rtl::OUString( aName );
2096cdf0e10cSrcweir 	    else if (aString.EqualsAscii( SC_UNONAME_AUTOFLT ))
2097cdf0e10cSrcweir         {
2098cdf0e10cSrcweir             sal_Bool bAutoFilter(GetDBData_Impl()->HasAutoFilter());
2099cdf0e10cSrcweir 
2100cdf0e10cSrcweir 		    ScUnoHelpFunctions::SetBoolInAny( aRet, bAutoFilter );
2101cdf0e10cSrcweir         }
2102cdf0e10cSrcweir 	    else if (aString.EqualsAscii( SC_UNONAME_USEFLTCRT ))
2103cdf0e10cSrcweir         {
2104cdf0e10cSrcweir             ScRange aRange;
2105cdf0e10cSrcweir             sal_Bool bIsAdvancedSource(GetDBData_Impl()->GetAdvancedQuerySource(aRange));
2106cdf0e10cSrcweir 
2107cdf0e10cSrcweir 		    ScUnoHelpFunctions::SetBoolInAny( aRet, bIsAdvancedSource );
2108cdf0e10cSrcweir         }
2109cdf0e10cSrcweir 	    else if (aString.EqualsAscii( SC_UNONAME_FLTCRT ))
2110cdf0e10cSrcweir         {
2111cdf0e10cSrcweir             table::CellRangeAddress aRange;
2112cdf0e10cSrcweir             ScRange aCoreRange;
2113cdf0e10cSrcweir             if (GetDBData_Impl()->GetAdvancedQuerySource(aCoreRange))
2114cdf0e10cSrcweir                 ScUnoConversion::FillApiRange(aRange, aCoreRange);
2115cdf0e10cSrcweir 
2116cdf0e10cSrcweir             aRet <<= aRange;
2117cdf0e10cSrcweir         }
2118cdf0e10cSrcweir         else if (aString.EqualsAscii( SC_UNONAME_FROMSELECT ))
2119cdf0e10cSrcweir         {
2120cdf0e10cSrcweir 		    ScUnoHelpFunctions::SetBoolInAny( aRet, GetDBData_Impl()->HasImportSelection() );
2121cdf0e10cSrcweir         }
2122cdf0e10cSrcweir 		else if (aString.EqualsAscii( SC_UNONAME_REFPERIOD ))
2123cdf0e10cSrcweir 		{
2124cdf0e10cSrcweir 		    sal_Int32 nRefresh(GetDBData_Impl()->GetRefreshDelay());
2125cdf0e10cSrcweir 		    aRet <<= nRefresh;
2126cdf0e10cSrcweir 		}
2127cdf0e10cSrcweir         else if (aString.EqualsAscii( SC_UNONAME_CONRES ))
2128cdf0e10cSrcweir         {
2129cdf0e10cSrcweir         }
2130cdf0e10cSrcweir         else if (aString.EqualsAscii( SC_UNONAME_TOKENINDEX ))
2131cdf0e10cSrcweir         {
2132cdf0e10cSrcweir             // get index for use in formula tokens (read-only)
2133cdf0e10cSrcweir             aRet <<= static_cast<sal_Int32>(GetDBData_Impl()->GetIndex());
2134cdf0e10cSrcweir         }
2135cdf0e10cSrcweir 	}
2136cdf0e10cSrcweir 	return aRet;
2137cdf0e10cSrcweir }
2138cdf0e10cSrcweir 
SC_IMPL_DUMMY_PROPERTY_LISTENER(ScDatabaseRangeObj)2139cdf0e10cSrcweir SC_IMPL_DUMMY_PROPERTY_LISTENER( ScDatabaseRangeObj )
2140cdf0e10cSrcweir 
2141cdf0e10cSrcweir // XServiceInfo
2142cdf0e10cSrcweir 
2143cdf0e10cSrcweir rtl::OUString SAL_CALL ScDatabaseRangeObj::getImplementationName() throw(uno::RuntimeException)
2144cdf0e10cSrcweir {
2145cdf0e10cSrcweir 	return rtl::OUString::createFromAscii( "ScDatabaseRangeObj" );
2146cdf0e10cSrcweir }
2147cdf0e10cSrcweir 
supportsService(const rtl::OUString & rServiceName)2148cdf0e10cSrcweir sal_Bool SAL_CALL ScDatabaseRangeObj::supportsService( const rtl::OUString& rServiceName )
2149cdf0e10cSrcweir 													throw(uno::RuntimeException)
2150cdf0e10cSrcweir {
2151cdf0e10cSrcweir 	String aServiceStr( rServiceName );
2152cdf0e10cSrcweir 	return aServiceStr.EqualsAscii( SCDATABASERANGEOBJ_SERVICE ) ||
2153cdf0e10cSrcweir 		   aServiceStr.EqualsAscii( SCLINKTARGET_SERVICE );
2154cdf0e10cSrcweir }
2155cdf0e10cSrcweir 
getSupportedServiceNames()2156cdf0e10cSrcweir uno::Sequence<rtl::OUString> SAL_CALL ScDatabaseRangeObj::getSupportedServiceNames()
2157cdf0e10cSrcweir 													throw(uno::RuntimeException)
2158cdf0e10cSrcweir {
2159cdf0e10cSrcweir 	uno::Sequence<rtl::OUString> aRet(2);
2160cdf0e10cSrcweir 	rtl::OUString* pArray = aRet.getArray();
2161cdf0e10cSrcweir 	pArray[0] = rtl::OUString::createFromAscii( SCDATABASERANGEOBJ_SERVICE );
2162cdf0e10cSrcweir 	pArray[1] = rtl::OUString::createFromAscii( SCLINKTARGET_SERVICE );
2163cdf0e10cSrcweir 	return aRet;
2164cdf0e10cSrcweir }
2165cdf0e10cSrcweir 
2166cdf0e10cSrcweir //------------------------------------------------------------------------
2167cdf0e10cSrcweir 
ScDatabaseRangesObj(ScDocShell * pDocSh)2168cdf0e10cSrcweir ScDatabaseRangesObj::ScDatabaseRangesObj(ScDocShell* pDocSh) :
2169cdf0e10cSrcweir 	pDocShell( pDocSh )
2170cdf0e10cSrcweir {
2171cdf0e10cSrcweir 	pDocShell->GetDocument()->AddUnoObject(*this);
2172cdf0e10cSrcweir }
2173cdf0e10cSrcweir 
~ScDatabaseRangesObj()2174cdf0e10cSrcweir ScDatabaseRangesObj::~ScDatabaseRangesObj()
2175cdf0e10cSrcweir {
2176cdf0e10cSrcweir 	if (pDocShell)
2177cdf0e10cSrcweir 		pDocShell->GetDocument()->RemoveUnoObject(*this);
2178cdf0e10cSrcweir }
2179cdf0e10cSrcweir 
Notify(SfxBroadcaster &,const SfxHint & rHint)2180cdf0e10cSrcweir void ScDatabaseRangesObj::Notify( SfxBroadcaster&, const SfxHint& rHint )
2181cdf0e10cSrcweir {
2182cdf0e10cSrcweir 	//	Referenz-Update interessiert hier nicht
2183cdf0e10cSrcweir 
2184cdf0e10cSrcweir 	if ( rHint.ISA( SfxSimpleHint ) &&
2185cdf0e10cSrcweir 			((const SfxSimpleHint&)rHint).GetId() == SFX_HINT_DYING )
2186cdf0e10cSrcweir 	{
2187cdf0e10cSrcweir 		pDocShell = NULL;		// ungueltig geworden
2188cdf0e10cSrcweir 	}
2189cdf0e10cSrcweir }
2190cdf0e10cSrcweir 
2191cdf0e10cSrcweir // XDatabaseRanges
2192cdf0e10cSrcweir 
GetObjectByIndex_Impl(sal_uInt16 nIndex)2193cdf0e10cSrcweir ScDatabaseRangeObj* ScDatabaseRangesObj::GetObjectByIndex_Impl(sal_uInt16 nIndex)
2194cdf0e10cSrcweir {
2195cdf0e10cSrcweir 	if (pDocShell)
2196cdf0e10cSrcweir 	{
2197cdf0e10cSrcweir 		ScDBCollection* pNames = pDocShell->GetDocument()->GetDBCollection();
2198cdf0e10cSrcweir 		if (pNames && nIndex < pNames->GetCount())
2199cdf0e10cSrcweir 			return new ScDatabaseRangeObj( pDocShell, (*pNames)[nIndex]->GetName() );
2200cdf0e10cSrcweir 	}
2201cdf0e10cSrcweir 	return NULL;
2202cdf0e10cSrcweir }
2203cdf0e10cSrcweir 
GetObjectByName_Impl(const rtl::OUString & aName)2204cdf0e10cSrcweir ScDatabaseRangeObj* ScDatabaseRangesObj::GetObjectByName_Impl(const rtl::OUString& aName)
2205cdf0e10cSrcweir {
2206cdf0e10cSrcweir 	if ( pDocShell && hasByName(aName) )
2207cdf0e10cSrcweir 	{
2208cdf0e10cSrcweir 		String aString(aName);
2209cdf0e10cSrcweir 		return new ScDatabaseRangeObj( pDocShell, aString );
2210cdf0e10cSrcweir 	}
2211cdf0e10cSrcweir 	return NULL;
2212cdf0e10cSrcweir }
2213cdf0e10cSrcweir 
2214cdf0e10cSrcweir 
addNewByName(const rtl::OUString & aName,const table::CellRangeAddress & aRange)2215cdf0e10cSrcweir void SAL_CALL ScDatabaseRangesObj::addNewByName( const rtl::OUString& aName,
2216cdf0e10cSrcweir 										const table::CellRangeAddress& aRange )
2217cdf0e10cSrcweir 										throw(uno::RuntimeException)
2218cdf0e10cSrcweir {
2219cdf0e10cSrcweir 	ScUnoGuard aGuard;
2220cdf0e10cSrcweir 	sal_Bool bDone = sal_False;
2221cdf0e10cSrcweir 	if (pDocShell)
2222cdf0e10cSrcweir 	{
2223cdf0e10cSrcweir 		ScDBDocFunc aFunc(*pDocShell);
2224cdf0e10cSrcweir 
2225cdf0e10cSrcweir 		String aString(aName);
2226cdf0e10cSrcweir 		ScRange aNameRange( (SCCOL)aRange.StartColumn, (SCROW)aRange.StartRow, aRange.Sheet,
2227cdf0e10cSrcweir 							(SCCOL)aRange.EndColumn,   (SCROW)aRange.EndRow,   aRange.Sheet );
2228cdf0e10cSrcweir 		bDone = aFunc.AddDBRange( aString, aNameRange, sal_True );
2229cdf0e10cSrcweir 	}
2230cdf0e10cSrcweir 	if (!bDone)
2231cdf0e10cSrcweir 		throw uno::RuntimeException();		// no other exceptions specified
2232cdf0e10cSrcweir }
2233cdf0e10cSrcweir 
removeByName(const rtl::OUString & aName)2234cdf0e10cSrcweir void SAL_CALL ScDatabaseRangesObj::removeByName( const rtl::OUString& aName )
2235cdf0e10cSrcweir 										throw(uno::RuntimeException)
2236cdf0e10cSrcweir {
2237cdf0e10cSrcweir 	ScUnoGuard aGuard;
2238cdf0e10cSrcweir 	sal_Bool bDone = sal_False;
2239cdf0e10cSrcweir 	if (pDocShell)
2240cdf0e10cSrcweir 	{
2241cdf0e10cSrcweir 		ScDBDocFunc aFunc(*pDocShell);
2242cdf0e10cSrcweir 		String aString(aName);
2243cdf0e10cSrcweir 		bDone = aFunc.DeleteDBRange( aString, sal_True );
2244cdf0e10cSrcweir 	}
2245cdf0e10cSrcweir 	if (!bDone)
2246cdf0e10cSrcweir 		throw uno::RuntimeException();		// no other exceptions specified
2247cdf0e10cSrcweir }
2248cdf0e10cSrcweir 
2249cdf0e10cSrcweir // XEnumerationAccess
2250cdf0e10cSrcweir 
createEnumeration()2251cdf0e10cSrcweir uno::Reference<container::XEnumeration> SAL_CALL ScDatabaseRangesObj::createEnumeration()
2252cdf0e10cSrcweir 													throw(uno::RuntimeException)
2253cdf0e10cSrcweir {
2254cdf0e10cSrcweir 	ScUnoGuard aGuard;
2255cdf0e10cSrcweir     return new ScIndexEnumeration(this, rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.sheet.DatabaseRangesEnumeration")));
2256cdf0e10cSrcweir }
2257cdf0e10cSrcweir 
2258cdf0e10cSrcweir // XIndexAccess
2259cdf0e10cSrcweir 
getCount()2260cdf0e10cSrcweir sal_Int32 SAL_CALL ScDatabaseRangesObj::getCount() throw(uno::RuntimeException)
2261cdf0e10cSrcweir {
2262cdf0e10cSrcweir 	ScUnoGuard aGuard;
2263cdf0e10cSrcweir 
2264cdf0e10cSrcweir 	//!	"unbenannt" weglassen ?
2265cdf0e10cSrcweir 
2266cdf0e10cSrcweir 	if (pDocShell)
2267cdf0e10cSrcweir 	{
2268cdf0e10cSrcweir 		ScDBCollection* pNames = pDocShell->GetDocument()->GetDBCollection();
2269cdf0e10cSrcweir 		if (pNames)
2270cdf0e10cSrcweir 			return pNames->GetCount();
2271cdf0e10cSrcweir 	}
2272cdf0e10cSrcweir 	return 0;
2273cdf0e10cSrcweir }
2274cdf0e10cSrcweir 
getByIndex(sal_Int32 nIndex)2275cdf0e10cSrcweir uno::Any SAL_CALL ScDatabaseRangesObj::getByIndex( sal_Int32 nIndex )
2276cdf0e10cSrcweir 							throw(lang::IndexOutOfBoundsException,
2277cdf0e10cSrcweir 									lang::WrappedTargetException, uno::RuntimeException)
2278cdf0e10cSrcweir {
2279cdf0e10cSrcweir 	ScUnoGuard aGuard;
2280cdf0e10cSrcweir 	uno::Reference<sheet::XDatabaseRange> xRange(GetObjectByIndex_Impl((sal_uInt16)nIndex));
2281cdf0e10cSrcweir 	if (xRange.is())
2282cdf0e10cSrcweir         return uno::makeAny(xRange);
2283cdf0e10cSrcweir 	else
2284cdf0e10cSrcweir 		throw lang::IndexOutOfBoundsException();
2285cdf0e10cSrcweir //    return uno::Any();
2286cdf0e10cSrcweir }
2287cdf0e10cSrcweir 
getElementType()2288cdf0e10cSrcweir uno::Type SAL_CALL ScDatabaseRangesObj::getElementType() throw(uno::RuntimeException)
2289cdf0e10cSrcweir {
2290cdf0e10cSrcweir 	ScUnoGuard aGuard;
2291cdf0e10cSrcweir 	return getCppuType((uno::Reference<sheet::XDatabaseRange>*)0);
2292cdf0e10cSrcweir }
2293cdf0e10cSrcweir 
hasElements()2294cdf0e10cSrcweir sal_Bool SAL_CALL ScDatabaseRangesObj::hasElements() throw(uno::RuntimeException)
2295cdf0e10cSrcweir {
2296cdf0e10cSrcweir 	ScUnoGuard aGuard;
2297cdf0e10cSrcweir 	return ( getCount() != 0 );
2298cdf0e10cSrcweir }
2299cdf0e10cSrcweir 
2300cdf0e10cSrcweir // XNameAccess
2301cdf0e10cSrcweir 
getByName(const rtl::OUString & aName)2302cdf0e10cSrcweir uno::Any SAL_CALL ScDatabaseRangesObj::getByName( const rtl::OUString& aName )
2303cdf0e10cSrcweir 			throw(container::NoSuchElementException,
2304cdf0e10cSrcweir 					lang::WrappedTargetException, uno::RuntimeException)
2305cdf0e10cSrcweir {
2306cdf0e10cSrcweir 	ScUnoGuard aGuard;
2307cdf0e10cSrcweir 	uno::Reference<sheet::XDatabaseRange> xRange(GetObjectByName_Impl(aName));
2308cdf0e10cSrcweir 	if (xRange.is())
2309cdf0e10cSrcweir         return uno::makeAny(xRange);
2310cdf0e10cSrcweir 	else
2311cdf0e10cSrcweir 		throw container::NoSuchElementException();
2312cdf0e10cSrcweir //    return uno::Any();
2313cdf0e10cSrcweir }
2314cdf0e10cSrcweir 
getElementNames()2315cdf0e10cSrcweir uno::Sequence<rtl::OUString> SAL_CALL ScDatabaseRangesObj::getElementNames()
2316cdf0e10cSrcweir 												throw(uno::RuntimeException)
2317cdf0e10cSrcweir {
2318cdf0e10cSrcweir 	ScUnoGuard aGuard;
2319cdf0e10cSrcweir 
2320cdf0e10cSrcweir 	//!	"unbenannt" weglassen ?
2321cdf0e10cSrcweir 
2322cdf0e10cSrcweir 	if (pDocShell)
2323cdf0e10cSrcweir 	{
2324cdf0e10cSrcweir 		ScDBCollection* pNames = pDocShell->GetDocument()->GetDBCollection();
2325cdf0e10cSrcweir 		if (pNames)
2326cdf0e10cSrcweir 		{
2327cdf0e10cSrcweir 			sal_uInt16 nCount = pNames->GetCount();
2328cdf0e10cSrcweir 			String aName;
2329cdf0e10cSrcweir 			uno::Sequence<rtl::OUString> aSeq(nCount);
2330cdf0e10cSrcweir 			rtl::OUString* pAry = aSeq.getArray();
2331cdf0e10cSrcweir 			for (sal_uInt16 i=0; i<nCount; i++)
2332cdf0e10cSrcweir 				pAry[i] = (*pNames)[i]->GetName();
2333cdf0e10cSrcweir 
2334cdf0e10cSrcweir 			return aSeq;
2335cdf0e10cSrcweir 		}
2336cdf0e10cSrcweir 	}
2337cdf0e10cSrcweir 	return uno::Sequence<rtl::OUString>(0);
2338cdf0e10cSrcweir }
2339cdf0e10cSrcweir 
hasByName(const rtl::OUString & aName)2340cdf0e10cSrcweir sal_Bool SAL_CALL ScDatabaseRangesObj::hasByName( const rtl::OUString& aName )
2341cdf0e10cSrcweir 										throw(uno::RuntimeException)
2342cdf0e10cSrcweir {
2343cdf0e10cSrcweir 	ScUnoGuard aGuard;
2344cdf0e10cSrcweir 
2345cdf0e10cSrcweir 	//!	"unbenannt" weglassen ?
2346cdf0e10cSrcweir 
2347cdf0e10cSrcweir 	if (pDocShell)
2348cdf0e10cSrcweir 	{
2349cdf0e10cSrcweir 		ScDBCollection* pNames = pDocShell->GetDocument()->GetDBCollection();
2350cdf0e10cSrcweir 		if (pNames)
2351cdf0e10cSrcweir 		{
2352cdf0e10cSrcweir 			String aString(aName);
2353cdf0e10cSrcweir 			sal_uInt16 nPos = 0;
2354cdf0e10cSrcweir 			if (pNames->SearchName( aString, nPos ))
2355cdf0e10cSrcweir 				return sal_True;
2356cdf0e10cSrcweir 		}
2357cdf0e10cSrcweir 	}
2358cdf0e10cSrcweir 	return sal_False;
2359cdf0e10cSrcweir }
2360cdf0e10cSrcweir 
2361cdf0e10cSrcweir //------------------------------------------------------------------------
2362cdf0e10cSrcweir 
2363cdf0e10cSrcweir 
2364cdf0e10cSrcweir 
2365cdf0e10cSrcweir 
2366cdf0e10cSrcweir 
2367