Stop leaking all ScPostIt instances.
[LibreOffice.git] / sc / source / ui / unoobj / datauno.cxx
blob8886776e76c23ba85f7f15d9cd4a4d90787637ce
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "datauno.hxx"
22 #include <svl/smplhint.hxx>
23 #include <svl/zforlist.hxx>
24 #include "svl/sharedstringpool.hxx"
25 #include <vcl/svapp.hxx>
27 #include <com/sun/star/awt/XBitmap.hpp>
28 #include <com/sun/star/util/SortField.hpp>
29 #include <com/sun/star/table/TableSortField.hpp>
30 #include <com/sun/star/beans/PropertyAttribute.hpp>
31 #include <com/sun/star/table/TableOrientation.hpp>
32 #include <com/sun/star/table/CellRangeAddress.hpp>
33 #include <com/sun/star/sheet/DataImportMode.hpp>
34 #include <com/sun/star/sheet/FilterOperator2.hpp>
35 #include <com/sun/star/sheet/TableFilterField2.hpp>
37 #include "dapiuno.hxx"
38 #include "cellsuno.hxx"
39 #include "miscuno.hxx"
40 #include "targuno.hxx"
41 #include "rangeutl.hxx"
42 #include "dbdata.hxx"
43 #include "docsh.hxx"
44 #include "dbdocfun.hxx"
45 #include "unonames.hxx"
46 #include "globalnames.hxx"
47 #include "globstr.hrc"
48 #include "convuno.hxx"
49 #include "hints.hxx"
50 #include "attrib.hxx"
51 #include "dpshttab.hxx"
52 #include "queryentry.hxx"
53 #include "dputil.hxx"
55 #include <comphelper/extract.hxx>
56 #include <comphelper/servicehelper.hxx>
57 #include <svx/dataaccessdescriptor.hxx>
59 #include <limits>
61 using namespace com::sun::star;
63 //------------------------------------------------------------------------
65 // alles ohne Which-ID, Map nur fuer PropertySetInfo
67 static const SfxItemPropertyMapEntry* lcl_GetSubTotalPropertyMap()
69 // some old property names are for 5.2 compatibility
71 static const SfxItemPropertyMapEntry aSubTotalPropertyMap_Impl[] =
73 {MAP_CHAR_LEN(SC_UNONAME_BINDFMT), 0, &getBooleanCppuType(), 0, 0},
74 {MAP_CHAR_LEN(SC_UNONAME_CASE), 0, &getBooleanCppuType(), 0, 0},
75 {MAP_CHAR_LEN(SC_UNONAME_ENABSORT), 0, &getBooleanCppuType(), 0, 0},
76 {MAP_CHAR_LEN(SC_UNONAME_ENUSLIST), 0, &getBooleanCppuType(), 0, 0},
77 {MAP_CHAR_LEN(SC_UNONAME_FORMATS), 0, &getBooleanCppuType(), 0, 0},
78 {MAP_CHAR_LEN(SC_UNONAME_INSBRK), 0, &getBooleanCppuType(), 0, 0},
79 {MAP_CHAR_LEN(SC_UNONAME_ISCASE), 0, &getBooleanCppuType(), 0, 0},
80 {MAP_CHAR_LEN(SC_UNONAME_MAXFLD), 0, &getCppuType((sal_Int32*)0), beans::PropertyAttribute::READONLY, 0},
81 {MAP_CHAR_LEN(SC_UNONAME_SORTASC), 0, &getBooleanCppuType(), 0, 0},
82 {MAP_CHAR_LEN(SC_UNONAME_ULIST), 0, &getBooleanCppuType(), 0, 0},
83 {MAP_CHAR_LEN(SC_UNONAME_UINDEX), 0, &getCppuType((sal_Int32*)0), 0, 0},
84 {MAP_CHAR_LEN(SC_UNONAME_USINDEX), 0, &getCppuType((sal_Int32*)0), 0, 0},
85 {0,0,0,0,0,0}
87 return aSubTotalPropertyMap_Impl;
90 static const SfxItemPropertyMapEntry* lcl_GetFilterPropertyMap()
92 static const SfxItemPropertyMapEntry aFilterPropertyMap_Impl[] =
94 {MAP_CHAR_LEN(SC_UNONAME_CONTHDR), 0, &getBooleanCppuType(), 0, 0},
95 {MAP_CHAR_LEN(SC_UNONAME_COPYOUT), 0, &getBooleanCppuType(), 0, 0},
96 {MAP_CHAR_LEN(SC_UNONAME_ISCASE), 0, &getBooleanCppuType(), 0, 0},
97 {MAP_CHAR_LEN(SC_UNONAME_MAXFLD), 0, &getCppuType((sal_Int32*)0), beans::PropertyAttribute::READONLY, 0},
98 {MAP_CHAR_LEN(SC_UNONAME_ORIENT), 0, &getCppuType((table::TableOrientation*)0), 0, 0},
99 {MAP_CHAR_LEN(SC_UNONAME_OUTPOS), 0, &getCppuType((table::CellAddress*)0), 0, 0},
100 {MAP_CHAR_LEN(SC_UNONAME_SAVEOUT), 0, &getBooleanCppuType(), 0, 0},
101 {MAP_CHAR_LEN(SC_UNONAME_SKIPDUP), 0, &getBooleanCppuType(), 0, 0},
102 {MAP_CHAR_LEN(SC_UNONAME_USEREGEX), 0, &getBooleanCppuType(), 0, 0},
103 {0,0,0,0,0,0}
105 return aFilterPropertyMap_Impl;
108 static const SfxItemPropertyMapEntry* lcl_GetDBRangePropertyMap()
110 static const SfxItemPropertyMapEntry aDBRangePropertyMap_Impl[] =
112 {MAP_CHAR_LEN(SC_UNONAME_AUTOFLT), 0, &getBooleanCppuType(), 0, 0},
113 {MAP_CHAR_LEN(SC_UNONAME_FLTCRT), 0, &getCppuType((table::CellRangeAddress*)0), 0, 0},
114 {MAP_CHAR_LEN(SC_UNONAME_FROMSELECT),0, &getBooleanCppuType(), 0, 0},
115 {MAP_CHAR_LEN(SC_UNONAME_ISUSER), 0, &getBooleanCppuType(), beans::PropertyAttribute::READONLY, 0 },
116 {MAP_CHAR_LEN(SC_UNONAME_KEEPFORM), 0, &getBooleanCppuType(), 0, 0},
117 {MAP_CHAR_LEN(SC_UNO_LINKDISPBIT), 0, &getCppuType((uno::Reference<awt::XBitmap>*)0), beans::PropertyAttribute::READONLY, 0 },
118 {MAP_CHAR_LEN(SC_UNO_LINKDISPNAME), 0, &getCppuType((OUString*)0), beans::PropertyAttribute::READONLY, 0 },
119 {MAP_CHAR_LEN(SC_UNONAME_MOVCELLS), 0, &getBooleanCppuType(), 0, 0},
120 {MAP_CHAR_LEN(SC_UNONAME_REFPERIOD), 0, &getCppuType((sal_Int32*)0), 0, 0},
121 {MAP_CHAR_LEN(SC_UNONAME_STRIPDAT), 0, &getBooleanCppuType(), 0, 0},
122 {MAP_CHAR_LEN(SC_UNONAME_TOKENINDEX),0, &getCppuType((sal_Int32*)0), beans::PropertyAttribute::READONLY, 0 },
123 {MAP_CHAR_LEN(SC_UNONAME_USEFLTCRT),0, &getBooleanCppuType(), 0, 0},
124 {0,0,0,0,0,0}
126 return aDBRangePropertyMap_Impl;
130 //------------------------------------------------------------------------
132 #define SCDATABASERANGEOBJ_SERVICE "com.sun.star.sheet.DatabaseRange"
134 SC_SIMPLE_SERVICE_INFO( ScConsolidationDescriptor, "ScConsolidationDescriptor", "com.sun.star.sheet.ConsolidationDescriptor" )
135 SC_SIMPLE_SERVICE_INFO( ScDatabaseRangesObj, "ScDatabaseRangesObj", "com.sun.star.sheet.DatabaseRanges" )
136 SC_SIMPLE_SERVICE_INFO( ScFilterDescriptorBase, "ScFilterDescriptorBase", "com.sun.star.sheet.SheetFilterDescriptor" )
137 SC_SIMPLE_SERVICE_INFO( ScSubTotalDescriptorBase, "ScSubTotalDescriptorBase", "com.sun.star.sheet.SubTotalDescriptor" )
138 SC_SIMPLE_SERVICE_INFO( ScSubTotalFieldObj, "ScSubTotalFieldObj", "com.sun.star.sheet.SubTotalField" )
140 sheet::GeneralFunction ScDataUnoConversion::SubTotalToGeneral( ScSubTotalFunc eSubTotal )
142 sheet::GeneralFunction eGeneral;
143 switch (eSubTotal)
145 case SUBTOTAL_FUNC_NONE: eGeneral = sheet::GeneralFunction_NONE; break;
146 case SUBTOTAL_FUNC_AVE: eGeneral = sheet::GeneralFunction_AVERAGE; break;
147 case SUBTOTAL_FUNC_CNT: eGeneral = sheet::GeneralFunction_COUNTNUMS; break;
148 case SUBTOTAL_FUNC_CNT2: eGeneral = sheet::GeneralFunction_COUNT; break;
149 case SUBTOTAL_FUNC_MAX: eGeneral = sheet::GeneralFunction_MAX; break;
150 case SUBTOTAL_FUNC_MIN: eGeneral = sheet::GeneralFunction_MIN; break;
151 case SUBTOTAL_FUNC_PROD: eGeneral = sheet::GeneralFunction_PRODUCT; break;
152 case SUBTOTAL_FUNC_STD: eGeneral = sheet::GeneralFunction_STDEV; break;
153 case SUBTOTAL_FUNC_STDP: eGeneral = sheet::GeneralFunction_STDEVP; break;
154 case SUBTOTAL_FUNC_SUM: eGeneral = sheet::GeneralFunction_SUM; break;
155 case SUBTOTAL_FUNC_VAR: eGeneral = sheet::GeneralFunction_VAR; break;
156 case SUBTOTAL_FUNC_VARP: eGeneral = sheet::GeneralFunction_VARP; break;
157 default:
158 OSL_FAIL("SubTotalToGeneral: falscher enum");
159 eGeneral = sheet::GeneralFunction_NONE;
160 break;
162 return eGeneral;
165 //------------------------------------------------------------------------
167 // ScImportDescriptor: alles static
169 long ScImportDescriptor::GetPropertyCount()
171 return 4;
174 void ScImportDescriptor::FillProperties( uno::Sequence<beans::PropertyValue>& rSeq, const ScImportParam& rParam )
176 OSL_ENSURE( rSeq.getLength() == GetPropertyCount(), "falscher Count" );
178 beans::PropertyValue* pArray = rSeq.getArray();
180 sheet::DataImportMode eMode = sheet::DataImportMode_NONE;
181 if ( rParam.bImport )
183 if ( rParam.bSql )
184 eMode = sheet::DataImportMode_SQL;
185 else if ( rParam.nType == ScDbQuery )
186 eMode = sheet::DataImportMode_QUERY;
187 else
188 eMode = sheet::DataImportMode_TABLE; // Type ist immer ScDbQuery oder ScDbTable
191 ::svx::ODataAccessDescriptor aDescriptor;
192 aDescriptor.setDataSource(rParam.aDBName);
193 if (aDescriptor.has( svx::daDataSource ))
195 pArray[0].Name = OUString( SC_UNONAME_DBNAME );
196 pArray[0].Value <<= rParam.aDBName;
198 else if (aDescriptor.has( svx::daConnectionResource ))
200 pArray[0].Name = OUString( SC_UNONAME_CONRES );
201 pArray[0].Value <<= rParam.aDBName;
204 pArray[1].Name = OUString( SC_UNONAME_SRCTYPE );
205 pArray[1].Value <<= eMode;
207 pArray[2].Name = OUString( SC_UNONAME_SRCOBJ );
208 pArray[2].Value <<= rParam.aStatement;
210 pArray[3].Name = OUString( SC_UNONAME_ISNATIVE );
211 ScUnoHelpFunctions::SetBoolInAny( pArray[3].Value, rParam.bNative );
214 void ScImportDescriptor::FillImportParam( ScImportParam& rParam, const uno::Sequence<beans::PropertyValue>& rSeq )
216 OUString aStrVal;
217 const beans::PropertyValue* pPropArray = rSeq.getConstArray();
218 long nPropCount = rSeq.getLength();
219 for (long i = 0; i < nPropCount; i++)
221 const beans::PropertyValue& rProp = pPropArray[i];
222 OUString aPropName(rProp.Name);
224 if (aPropName.equalsAscii( SC_UNONAME_ISNATIVE ))
225 rParam.bNative = ScUnoHelpFunctions::GetBoolFromAny( rProp.Value );
226 else if (aPropName.equalsAscii( SC_UNONAME_DBNAME ))
228 if ( rProp.Value >>= aStrVal )
229 rParam.aDBName = aStrVal;
231 else if (aPropName.equalsAscii( SC_UNONAME_CONRES ))
233 if ( rProp.Value >>= aStrVal )
234 rParam.aDBName = aStrVal;
236 else if (aPropName.equalsAscii( SC_UNONAME_SRCOBJ ))
238 if ( rProp.Value >>= aStrVal )
239 rParam.aStatement = aStrVal;
241 else if (aPropName.equalsAscii( SC_UNONAME_SRCTYPE ))
243 //! test for correct enum type?
244 sheet::DataImportMode eMode = (sheet::DataImportMode)
245 ScUnoHelpFunctions::GetEnumFromAny( rProp.Value );
246 switch (eMode)
248 case sheet::DataImportMode_NONE:
249 rParam.bImport = false;
250 break;
251 case sheet::DataImportMode_SQL:
252 rParam.bImport = true;
253 rParam.bSql = true;
254 break;
255 case sheet::DataImportMode_TABLE:
256 rParam.bImport = true;
257 rParam.bSql = false;
258 rParam.nType = ScDbTable;
259 break;
260 case sheet::DataImportMode_QUERY:
261 rParam.bImport = true;
262 rParam.bSql = false;
263 rParam.nType = ScDbQuery;
264 break;
265 default:
266 OSL_FAIL("falscher Mode");
267 rParam.bImport = false;
273 //------------------------------------------------------------------------
275 // ScSortDescriptor: alles static
277 //! SortAscending muss aus der SheetSortDescriptor service-Beschreibung raus
279 long ScSortDescriptor::GetPropertyCount()
281 return 9; // TableSortDescriptor and SheetSortDescriptor
284 void ScSortDescriptor::FillProperties( uno::Sequence<beans::PropertyValue>& rSeq, const ScSortParam& rParam )
286 OSL_ENSURE( rSeq.getLength() == GetPropertyCount(), "falscher Count" );
288 beans::PropertyValue* pArray = rSeq.getArray();
290 // Uno-Werte zusammensuchen
292 table::CellAddress aOutPos;
293 aOutPos.Sheet = rParam.nDestTab;
294 aOutPos.Column = rParam.nDestCol;
295 aOutPos.Row = rParam.nDestRow;
297 sal_uInt16 nSortCount = 0;
298 while ( nSortCount < rParam.GetSortKeyCount() && rParam.maKeyState[nSortCount].bDoSort )
299 ++nSortCount;
301 uno::Sequence<table::TableSortField> aFields(nSortCount);
302 if (nSortCount)
304 table::TableSortField* pFieldArray = aFields.getArray();
305 for (sal_uInt16 i=0; i<nSortCount; i++)
307 pFieldArray[i].Field = rParam.maKeyState[i].nField;
308 pFieldArray[i].IsAscending = rParam.maKeyState[i].bAscending;
309 pFieldArray[i].FieldType = table::TableSortFieldType_AUTOMATIC; // immer Automatic
310 pFieldArray[i].IsCaseSensitive = rParam.bCaseSens;
311 pFieldArray[i].CollatorLocale = rParam.aCollatorLocale;
312 pFieldArray[i].CollatorAlgorithm = rParam.aCollatorAlgorithm;
316 // Sequence fuellen
318 pArray[0].Name = OUString( SC_UNONAME_ISSORTCOLUMNS );
319 pArray[0].Value = ::cppu::bool2any(!rParam.bByRow);
321 pArray[1].Name = OUString( SC_UNONAME_CONTHDR );
322 ScUnoHelpFunctions::SetBoolInAny( pArray[1].Value, rParam.bHasHeader );
324 pArray[2].Name = OUString( SC_UNONAME_MAXFLD );
325 pArray[2].Value <<= static_cast<sal_Int32>( rParam.GetSortKeyCount() );
327 pArray[3].Name = OUString( SC_UNONAME_SORTFLD );
328 pArray[3].Value <<= aFields;
330 pArray[4].Name = OUString( SC_UNONAME_BINDFMT );
331 ScUnoHelpFunctions::SetBoolInAny( pArray[4].Value, rParam.bIncludePattern );
333 pArray[5].Name = OUString( SC_UNONAME_COPYOUT );
334 ScUnoHelpFunctions::SetBoolInAny( pArray[5].Value, !rParam.bInplace );
336 pArray[6].Name = OUString( SC_UNONAME_OUTPOS );
337 pArray[6].Value <<= aOutPos;
339 pArray[7].Name = OUString( SC_UNONAME_ISULIST );
340 ScUnoHelpFunctions::SetBoolInAny( pArray[7].Value, rParam.bUserDef );
342 pArray[8].Name = OUString( SC_UNONAME_UINDEX );
343 pArray[8].Value <<= static_cast<sal_Int32>( rParam.nUserIndex );
346 void ScSortDescriptor::FillSortParam( ScSortParam& rParam, const uno::Sequence<beans::PropertyValue>& rSeq )
348 const beans::PropertyValue* pPropArray = rSeq.getConstArray();
349 long nPropCount = rSeq.getLength();
350 sal_Int16 nSortSize = rParam.GetSortKeyCount();
352 for (long nProp = 0; nProp < nPropCount; nProp++)
354 const beans::PropertyValue& rProp = pPropArray[nProp];
355 OUString aPropName(rProp.Name);
357 if (aPropName.equalsAscii( SC_UNONAME_ORIENT ))
359 //! test for correct enum type?
360 table::TableOrientation eOrient = (table::TableOrientation)
361 ScUnoHelpFunctions::GetEnumFromAny( rProp.Value );
362 rParam.bByRow = ( eOrient != table::TableOrientation_COLUMNS );
364 else if (aPropName.equalsAscii( SC_UNONAME_ISSORTCOLUMNS ))
366 rParam.bByRow = !::cppu::any2bool(rProp.Value);
368 else if (aPropName.equalsAscii( SC_UNONAME_CONTHDR ))
369 rParam.bHasHeader = ScUnoHelpFunctions::GetBoolFromAny( rProp.Value );
370 else if (aPropName.equalsAscii( SC_UNONAME_MAXFLD ))
372 sal_Int32 nVal;
373 if ( (rProp.Value >>= nVal) && nVal > nSortSize )
375 //! specify exceptions
376 //! throw lang::IllegalArgumentException();
379 else if (aPropName.equalsAscii( SC_UNONAME_SORTFLD ))
381 uno::Sequence<util::SortField> aSeq;
382 uno::Sequence<table::TableSortField> aNewSeq;
383 if ( rProp.Value >>= aSeq )
385 sal_Int32 nCount = aSeq.getLength();
386 sal_Int32 i;
387 if ( nCount > static_cast<sal_Int32>( rParam.GetSortKeyCount() ) )
389 nCount = nSortSize;
390 rParam.maKeyState.resize(nCount);
392 const util::SortField* pFieldArray = aSeq.getConstArray();
393 for (i=0; i<nCount; i++)
395 rParam.maKeyState[i].nField = static_cast<SCCOLROW>( pFieldArray[i].Field );
396 rParam.maKeyState[i].bAscending = pFieldArray[i].SortAscending;
398 // FieldType wird ignoriert
399 rParam.maKeyState[i].bDoSort = true;
401 for (i=nCount; i<nSortSize; i++)
402 rParam.maKeyState[i].bDoSort = false;
404 else if ( rProp.Value >>= aNewSeq )
406 sal_Int32 nCount = aNewSeq.getLength();
407 sal_Int32 i;
408 if ( nCount > nSortSize )
410 nCount = nSortSize;
411 rParam.maKeyState.resize(nCount);
413 const table::TableSortField* pFieldArray = aNewSeq.getConstArray();
414 for (i=0; i<nCount; i++)
416 rParam.maKeyState[i].nField = static_cast<SCCOLROW>( pFieldArray[i].Field );
417 rParam.maKeyState[i].bAscending = pFieldArray[i].IsAscending;
419 // only one is possible, sometime we should make it possible to have different for every entry
420 rParam.bCaseSens = pFieldArray[i].IsCaseSensitive;
421 rParam.aCollatorLocale = pFieldArray[i].CollatorLocale;
422 rParam.aCollatorAlgorithm = pFieldArray[i].CollatorAlgorithm;
424 // FieldType wird ignoriert
425 rParam.maKeyState[i].bDoSort = true;
427 for (i=nCount; i<nSortSize; i++)
428 rParam.maKeyState[i].bDoSort = false;
431 else if (aPropName.equalsAscii( SC_UNONAME_ISCASE ))
433 rParam.bCaseSens = ScUnoHelpFunctions::GetBoolFromAny( rProp.Value );
435 else if (aPropName.equalsAscii( SC_UNONAME_BINDFMT ))
436 rParam.bIncludePattern = ScUnoHelpFunctions::GetBoolFromAny( rProp.Value );
437 else if (aPropName.equalsAscii( SC_UNONAME_COPYOUT ))
438 rParam.bInplace = !ScUnoHelpFunctions::GetBoolFromAny( rProp.Value );
439 else if (aPropName.equalsAscii( SC_UNONAME_OUTPOS ))
441 table::CellAddress aAddress;
442 if ( rProp.Value >>= aAddress )
444 rParam.nDestTab = aAddress.Sheet;
445 rParam.nDestCol = (SCCOL)aAddress.Column;
446 rParam.nDestRow = (SCROW)aAddress.Row;
449 else if (aPropName.equalsAscii( SC_UNONAME_ISULIST ))
450 rParam.bUserDef = ScUnoHelpFunctions::GetBoolFromAny( rProp.Value );
451 else if (aPropName.equalsAscii( SC_UNONAME_UINDEX ))
453 sal_Int32 nVal = 0;
454 if ( rProp.Value >>= nVal )
455 rParam.nUserIndex = (sal_uInt16)nVal;
457 else if (aPropName.equalsAscii( SC_UNONAME_COLLLOC ))
459 rProp.Value >>= rParam.aCollatorLocale;
461 else if (aPropName.equalsAscii( SC_UNONAME_COLLALG ))
463 OUString sStr;
464 if ( rProp.Value >>= sStr )
465 rParam.aCollatorAlgorithm = sStr;
470 //------------------------------------------------------------------------
472 ScSubTotalFieldObj::ScSubTotalFieldObj( ScSubTotalDescriptorBase* pDesc, sal_uInt16 nP ) :
473 xRef( pDesc ), // Objekt festhalten
474 rParent( *pDesc ),
475 nPos( nP )
477 OSL_ENSURE(pDesc, "ScSubTotalFieldObj: Parent ist 0");
480 ScSubTotalFieldObj::~ScSubTotalFieldObj()
484 // XSubTotalField
486 sal_Int32 SAL_CALL ScSubTotalFieldObj::getGroupColumn() throw(uno::RuntimeException)
488 SolarMutexGuard aGuard;
489 ScSubTotalParam aParam;
490 rParent.GetData(aParam);
492 return aParam.nField[nPos];
495 void SAL_CALL ScSubTotalFieldObj::setGroupColumn( sal_Int32 nGroupColumn ) throw(uno::RuntimeException)
497 SolarMutexGuard aGuard;
498 ScSubTotalParam aParam;
499 rParent.GetData(aParam);
501 aParam.nField[nPos] = (SCCOL)nGroupColumn;
503 rParent.PutData(aParam);
506 uno::Sequence<sheet::SubTotalColumn> SAL_CALL ScSubTotalFieldObj::getSubTotalColumns()
507 throw(uno::RuntimeException)
509 SolarMutexGuard aGuard;
510 ScSubTotalParam aParam;
511 rParent.GetData(aParam);
513 SCCOL nCount = aParam.nSubTotals[nPos];
514 uno::Sequence<sheet::SubTotalColumn> aSeq(nCount);
515 sheet::SubTotalColumn* pAry = aSeq.getArray();
516 for (SCCOL i=0; i<nCount; i++)
518 pAry[i].Column = aParam.pSubTotals[nPos][i];
519 pAry[i].Function = ScDataUnoConversion::SubTotalToGeneral(
520 aParam.pFunctions[nPos][i] );
522 return aSeq;
525 void SAL_CALL ScSubTotalFieldObj::setSubTotalColumns(
526 const uno::Sequence<sheet::SubTotalColumn>& aSubTotalColumns )
527 throw(uno::RuntimeException)
529 SolarMutexGuard aGuard;
530 ScSubTotalParam aParam;
531 rParent.GetData(aParam);
533 sal_uInt32 nColCount = aSubTotalColumns.getLength();
534 if ( nColCount <= sal::static_int_cast<sal_uInt32>(SCCOL_MAX) )
536 SCCOL nCount = static_cast<SCCOL>(nColCount);
537 aParam.nSubTotals[nPos] = nCount;
538 if (nCount != 0)
540 aParam.pSubTotals[nPos] = new SCCOL[nCount];
541 aParam.pFunctions[nPos] = new ScSubTotalFunc[nCount];
543 const sheet::SubTotalColumn* pAry = aSubTotalColumns.getConstArray();
544 for (SCCOL i=0; i<nCount; i++)
546 aParam.pSubTotals[nPos][i] = static_cast<SCCOL>(pAry[i].Column);
547 aParam.pFunctions[nPos][i] = ScDPUtil::toSubTotalFunc(pAry[i].Function);
550 else
552 aParam.pSubTotals[nPos] = NULL;
553 aParam.pFunctions[nPos] = NULL;
556 //! sonst Exception oder so? (zuviele Spalten)
558 rParent.PutData(aParam);
561 //------------------------------------------------------------------------
563 ScSubTotalDescriptorBase::ScSubTotalDescriptorBase() :
564 aPropSet( lcl_GetSubTotalPropertyMap() )
568 ScSubTotalDescriptorBase::~ScSubTotalDescriptorBase()
572 // XSubTotalDesctiptor
574 ScSubTotalFieldObj* ScSubTotalDescriptorBase::GetObjectByIndex_Impl(sal_uInt16 nIndex)
576 if ( nIndex < getCount() )
577 return new ScSubTotalFieldObj( this, nIndex );
578 return NULL;
581 void SAL_CALL ScSubTotalDescriptorBase::clear() throw(uno::RuntimeException)
583 SolarMutexGuard aGuard;
584 ScSubTotalParam aParam;
585 GetData(aParam);
587 for (sal_uInt16 i=0; i<MAXSUBTOTAL; i++)
588 aParam.bGroupActive[i] = false;
590 //! Notify oder so fuer die Field-Objekte???
592 PutData(aParam);
595 void SAL_CALL ScSubTotalDescriptorBase::addNew(
596 const uno::Sequence<sheet::SubTotalColumn>& aSubTotalColumns,
597 sal_Int32 nGroupColumn ) throw(uno::RuntimeException)
599 SolarMutexGuard aGuard;
600 ScSubTotalParam aParam;
601 GetData(aParam);
603 sal_uInt16 nPos = 0;
604 while ( nPos < MAXSUBTOTAL && aParam.bGroupActive[nPos] )
605 ++nPos;
607 sal_uInt32 nColCount = aSubTotalColumns.getLength();
609 if ( nPos < MAXSUBTOTAL && nColCount <= sal::static_int_cast<sal_uInt32>(SCCOL_MAX) )
611 aParam.bGroupActive[nPos] = sal_True;
612 aParam.nField[nPos] = static_cast<SCCOL>(nGroupColumn);
614 delete aParam.pSubTotals[nPos];
615 delete aParam.pFunctions[nPos];
617 SCCOL nCount = static_cast<SCCOL>(nColCount);
618 aParam.nSubTotals[nPos] = nCount;
619 if (nCount != 0)
621 aParam.pSubTotals[nPos] = new SCCOL[nCount];
622 aParam.pFunctions[nPos] = new ScSubTotalFunc[nCount];
624 const sheet::SubTotalColumn* pAry = aSubTotalColumns.getConstArray();
625 for (SCCOL i=0; i<nCount; i++)
627 aParam.pSubTotals[nPos][i] = static_cast<SCCOL>(pAry[i].Column);
628 aParam.pFunctions[nPos][i] = ScDPUtil::toSubTotalFunc(pAry[i].Function);
631 else
633 aParam.pSubTotals[nPos] = NULL;
634 aParam.pFunctions[nPos] = NULL;
637 else // too many fields / columns
638 throw uno::RuntimeException(); // no other exceptions specified
640 PutData(aParam);
643 // Flags/Einstellungen als Properties
645 // XEnumerationAccess
647 uno::Reference<container::XEnumeration> SAL_CALL ScSubTotalDescriptorBase::createEnumeration()
648 throw(uno::RuntimeException)
650 SolarMutexGuard aGuard;
651 return new ScIndexEnumeration(this, OUString("com.sun.star.sheet.SubTotalFieldsEnumeration"));
654 // XIndexAccess
656 sal_Int32 SAL_CALL ScSubTotalDescriptorBase::getCount() throw(uno::RuntimeException)
658 SolarMutexGuard aGuard;
659 ScSubTotalParam aParam;
660 GetData(aParam);
662 sal_uInt16 nCount = 0;
663 while ( nCount < MAXSUBTOTAL && aParam.bGroupActive[nCount] )
664 ++nCount;
665 return nCount;
668 uno::Any SAL_CALL ScSubTotalDescriptorBase::getByIndex( sal_Int32 nIndex )
669 throw(lang::IndexOutOfBoundsException,
670 lang::WrappedTargetException, uno::RuntimeException)
672 SolarMutexGuard aGuard;
673 uno::Reference<sheet::XSubTotalField> xField(GetObjectByIndex_Impl((sal_uInt16)nIndex));
674 if (xField.is())
675 return uno::makeAny(xField);
676 else
677 throw lang::IndexOutOfBoundsException();
680 uno::Type SAL_CALL ScSubTotalDescriptorBase::getElementType() throw(uno::RuntimeException)
682 SolarMutexGuard aGuard;
683 return getCppuType((uno::Reference<sheet::XSubTotalField>*)0);
686 sal_Bool SAL_CALL ScSubTotalDescriptorBase::hasElements() throw(uno::RuntimeException)
688 SolarMutexGuard aGuard;
689 return ( getCount() != 0 );
692 // XPropertySet
694 uno::Reference<beans::XPropertySetInfo> SAL_CALL ScSubTotalDescriptorBase::getPropertySetInfo()
695 throw(uno::RuntimeException)
697 SolarMutexGuard aGuard;
698 static uno::Reference<beans::XPropertySetInfo> aRef(
699 new SfxItemPropertySetInfo( aPropSet.getPropertyMap() ));
700 return aRef;
703 void SAL_CALL ScSubTotalDescriptorBase::setPropertyValue(
704 const OUString& aPropertyName, const uno::Any& aValue )
705 throw(beans::UnknownPropertyException, beans::PropertyVetoException,
706 lang::IllegalArgumentException, lang::WrappedTargetException,
707 uno::RuntimeException)
709 SolarMutexGuard aGuard;
710 ScSubTotalParam aParam;
711 GetData(aParam);
713 OUString aString(aPropertyName);
715 // some old property names are for 5.2 compatibility
717 if (aString.equalsAscii( SC_UNONAME_CASE ) || aString.equalsAscii( SC_UNONAME_ISCASE ))
718 aParam.bCaseSens = ScUnoHelpFunctions::GetBoolFromAny( aValue );
719 else if (aString.equalsAscii( SC_UNONAME_FORMATS ) || aString.equalsAscii( SC_UNONAME_BINDFMT ))
720 aParam.bIncludePattern = ScUnoHelpFunctions::GetBoolFromAny( aValue );
721 else if (aString.equalsAscii( SC_UNONAME_ENABSORT ))
722 aParam.bDoSort = ScUnoHelpFunctions::GetBoolFromAny( aValue );
723 else if (aString.equalsAscii( SC_UNONAME_SORTASC ))
724 aParam.bAscending = ScUnoHelpFunctions::GetBoolFromAny( aValue );
725 else if (aString.equalsAscii( SC_UNONAME_INSBRK ))
726 aParam.bPagebreak = ScUnoHelpFunctions::GetBoolFromAny( aValue );
727 else if (aString.equalsAscii( SC_UNONAME_ULIST ) || aString.equalsAscii( SC_UNONAME_ENUSLIST ))
728 aParam.bUserDef = ScUnoHelpFunctions::GetBoolFromAny( aValue );
729 else if (aString.equalsAscii( SC_UNONAME_UINDEX ) || aString.equalsAscii( SC_UNONAME_USINDEX ))
731 sal_Int32 nVal = 0;
732 if ( aValue >>= nVal )
733 aParam.nUserIndex = (sal_uInt16)nVal;
735 else if (aString.equalsAscii( SC_UNONAME_MAXFLD ))
737 sal_Int32 nVal = 0;
738 if ( (aValue >>= nVal) && nVal > sal::static_int_cast<sal_Int32>(MAXSUBTOTAL) )
740 throw lang::IllegalArgumentException();
744 PutData(aParam);
747 uno::Any SAL_CALL ScSubTotalDescriptorBase::getPropertyValue( const OUString& aPropertyName )
748 throw(beans::UnknownPropertyException, lang::WrappedTargetException,
749 uno::RuntimeException)
751 SolarMutexGuard aGuard;
752 ScSubTotalParam aParam;
753 GetData(aParam);
755 OUString aString(aPropertyName);
756 uno::Any aRet;
758 // some old property names are for 5.2 compatibility
760 if (aString.equalsAscii( SC_UNONAME_CASE ) || aString.equalsAscii( SC_UNONAME_ISCASE ))
761 ScUnoHelpFunctions::SetBoolInAny( aRet, aParam.bCaseSens );
762 else if (aString.equalsAscii( SC_UNONAME_FORMATS ) || aString.equalsAscii( SC_UNONAME_BINDFMT ))
763 ScUnoHelpFunctions::SetBoolInAny( aRet, aParam.bIncludePattern );
764 else if (aString.equalsAscii( SC_UNONAME_ENABSORT ))
765 ScUnoHelpFunctions::SetBoolInAny( aRet, aParam.bDoSort );
766 else if (aString.equalsAscii( SC_UNONAME_SORTASC ))
767 ScUnoHelpFunctions::SetBoolInAny( aRet, aParam.bAscending );
768 else if (aString.equalsAscii( SC_UNONAME_INSBRK ))
769 ScUnoHelpFunctions::SetBoolInAny( aRet, aParam.bPagebreak );
770 else if (aString.equalsAscii( SC_UNONAME_ULIST ) || aString.equalsAscii( SC_UNONAME_ENUSLIST ))
771 ScUnoHelpFunctions::SetBoolInAny( aRet, aParam.bUserDef );
772 else if (aString.equalsAscii( SC_UNONAME_UINDEX ) || aString.equalsAscii( SC_UNONAME_USINDEX ))
773 aRet <<= (sal_Int32) aParam.nUserIndex;
774 else if (aString.equalsAscii( SC_UNONAME_MAXFLD ))
775 aRet <<= (sal_Int32) MAXSUBTOTAL;
777 return aRet;
780 SC_IMPL_DUMMY_PROPERTY_LISTENER( ScSubTotalDescriptorBase )
782 // XUnoTunnel
784 sal_Int64 SAL_CALL ScSubTotalDescriptorBase::getSomething(
785 const uno::Sequence<sal_Int8 >& rId ) throw(uno::RuntimeException)
787 if ( rId.getLength() == 16 &&
788 0 == memcmp( getUnoTunnelId().getConstArray(),
789 rId.getConstArray(), 16 ) )
791 return sal::static_int_cast<sal_Int64>(reinterpret_cast<sal_IntPtr>(this));
793 return 0;
796 namespace
798 class theScSubTotalDescriptorBaseUnoTunnelId : public rtl::Static< UnoTunnelIdInit, theScSubTotalDescriptorBaseUnoTunnelId> {};
801 const uno::Sequence<sal_Int8>& ScSubTotalDescriptorBase::getUnoTunnelId()
803 return theScSubTotalDescriptorBaseUnoTunnelId::get().getSeq();
806 ScSubTotalDescriptorBase* ScSubTotalDescriptorBase::getImplementation(
807 const uno::Reference<sheet::XSubTotalDescriptor> xObj )
809 ScSubTotalDescriptorBase* pRet = NULL;
810 uno::Reference<lang::XUnoTunnel> xUT( xObj, uno::UNO_QUERY );
811 if (xUT.is())
812 pRet = reinterpret_cast<ScSubTotalDescriptorBase*>(sal::static_int_cast<sal_IntPtr>(xUT->getSomething(getUnoTunnelId())));
813 return pRet;
816 //------------------------------------------------------------------------
818 ScSubTotalDescriptor::ScSubTotalDescriptor()
822 ScSubTotalDescriptor::~ScSubTotalDescriptor()
826 void ScSubTotalDescriptor::GetData( ScSubTotalParam& rParam ) const
828 rParam = aStoredParam; // Abfrage fuer Interface
831 void ScSubTotalDescriptor::PutData( const ScSubTotalParam& rParam )
833 aStoredParam = rParam; // vom Interface gesetzt
836 void ScSubTotalDescriptor::SetParam( const ScSubTotalParam& rNew )
838 aStoredParam = rNew; // von aussen gesetzt
841 //------------------------------------------------------------------------
843 ScRangeSubTotalDescriptor::ScRangeSubTotalDescriptor(ScDatabaseRangeObj* pPar) :
844 pParent(pPar)
846 if (pParent)
847 pParent->acquire();
850 ScRangeSubTotalDescriptor::~ScRangeSubTotalDescriptor()
852 if (pParent)
853 pParent->release();
856 void ScRangeSubTotalDescriptor::GetData( ScSubTotalParam& rParam ) const
858 if (pParent)
859 pParent->GetSubTotalParam( rParam );
862 void ScRangeSubTotalDescriptor::PutData( const ScSubTotalParam& rParam )
864 if (pParent)
865 pParent->SetSubTotalParam( rParam );
868 //------------------------------------------------------------------------
870 ScConsolidationDescriptor::ScConsolidationDescriptor()
874 ScConsolidationDescriptor::~ScConsolidationDescriptor()
878 void ScConsolidationDescriptor::SetParam( const ScConsolidateParam& rNew )
880 aParam = rNew;
883 // XConsolidationDescriptor
885 sheet::GeneralFunction SAL_CALL ScConsolidationDescriptor::getFunction() throw(uno::RuntimeException)
887 SolarMutexGuard aGuard;
888 return ScDataUnoConversion::SubTotalToGeneral(aParam.eFunction);
891 void SAL_CALL ScConsolidationDescriptor::setFunction( sheet::GeneralFunction nFunction )
892 throw(uno::RuntimeException)
894 SolarMutexGuard aGuard;
895 aParam.eFunction = ScDPUtil::toSubTotalFunc(nFunction);
898 uno::Sequence<table::CellRangeAddress> SAL_CALL ScConsolidationDescriptor::getSources()
899 throw(uno::RuntimeException)
901 SolarMutexGuard aGuard;
902 sal_uInt16 nCount = aParam.nDataAreaCount;
903 if (!aParam.ppDataAreas)
904 nCount = 0;
905 table::CellRangeAddress aRange;
906 uno::Sequence<table::CellRangeAddress> aSeq(nCount);
907 table::CellRangeAddress* pAry = aSeq.getArray();
908 for (sal_uInt16 i=0; i<nCount; i++)
910 ScArea* pArea = aParam.ppDataAreas[i];
911 if (pArea)
913 aRange.Sheet = pArea->nTab;
914 aRange.StartColumn = pArea->nColStart;
915 aRange.StartRow = pArea->nRowStart;
916 aRange.EndColumn = pArea->nColEnd;
917 aRange.EndRow = pArea->nRowEnd;
919 pAry[i] = aRange;
921 return aSeq;
924 void SAL_CALL ScConsolidationDescriptor::setSources(
925 const uno::Sequence<table::CellRangeAddress>& aSources )
926 throw(uno::RuntimeException)
928 SolarMutexGuard aGuard;
929 sal_uInt16 nCount = (sal_uInt16)aSources.getLength();
930 if (nCount)
932 const table::CellRangeAddress* pAry = aSources.getConstArray();
933 ScArea** pNew = new ScArea*[nCount];
934 sal_uInt16 i;
935 for (i=0; i<nCount; i++)
936 pNew[i] = new ScArea( pAry[i].Sheet,
937 static_cast<SCCOL>(pAry[i].StartColumn), pAry[i].StartRow,
938 static_cast<SCCOL>(pAry[i].EndColumn), pAry[i].EndRow );
940 aParam.SetAreas( pNew, nCount ); // kopiert alles
942 for (i=0; i<nCount; i++)
943 delete pNew[i];
944 delete[] pNew;
946 else
947 aParam.ClearDataAreas();
950 table::CellAddress SAL_CALL ScConsolidationDescriptor::getStartOutputPosition()
951 throw(uno::RuntimeException)
953 SolarMutexGuard aGuard;
954 table::CellAddress aPos;
955 aPos.Column = aParam.nCol;
956 aPos.Row = aParam.nRow;
957 aPos.Sheet = aParam.nTab;
958 return aPos;
961 void SAL_CALL ScConsolidationDescriptor::setStartOutputPosition(
962 const table::CellAddress& aStartOutputPosition )
963 throw(uno::RuntimeException)
965 SolarMutexGuard aGuard;
966 aParam.nCol = (SCCOL)aStartOutputPosition.Column;
967 aParam.nRow = (SCROW)aStartOutputPosition.Row;
968 aParam.nTab = aStartOutputPosition.Sheet;
971 sal_Bool SAL_CALL ScConsolidationDescriptor::getUseColumnHeaders() throw(uno::RuntimeException)
973 SolarMutexGuard aGuard;
974 return aParam.bByCol;
977 void SAL_CALL ScConsolidationDescriptor::setUseColumnHeaders( sal_Bool bUseColumnHeaders )
978 throw(uno::RuntimeException)
980 SolarMutexGuard aGuard;
981 aParam.bByCol = bUseColumnHeaders;
984 sal_Bool SAL_CALL ScConsolidationDescriptor::getUseRowHeaders() throw(uno::RuntimeException)
986 SolarMutexGuard aGuard;
987 return aParam.bByRow;
990 void SAL_CALL ScConsolidationDescriptor::setUseRowHeaders( sal_Bool bUseRowHeaders )
991 throw(uno::RuntimeException)
993 SolarMutexGuard aGuard;
994 aParam.bByRow = bUseRowHeaders;
997 sal_Bool SAL_CALL ScConsolidationDescriptor::getInsertLinks() throw(uno::RuntimeException)
999 SolarMutexGuard aGuard;
1000 return aParam.bReferenceData;
1003 void SAL_CALL ScConsolidationDescriptor::setInsertLinks( sal_Bool bInsertLinks )
1004 throw(uno::RuntimeException)
1006 SolarMutexGuard aGuard;
1007 aParam.bReferenceData = bInsertLinks;
1010 ScFilterDescriptorBase::ScFilterDescriptorBase(ScDocShell* pDocShell) :
1011 aPropSet( lcl_GetFilterPropertyMap() ),
1012 pDocSh(pDocShell)
1014 if (pDocSh)
1015 pDocSh->GetDocument()->AddUnoObject(*this);
1018 ScFilterDescriptorBase::~ScFilterDescriptorBase()
1020 if (pDocSh)
1021 pDocSh->GetDocument()->RemoveUnoObject(*this);
1024 void ScFilterDescriptorBase::Notify( SfxBroadcaster&, const SfxHint& rHint )
1026 if ( rHint.ISA( SfxSimpleHint ) )
1028 sal_uLong nId = ((const SfxSimpleHint&)rHint).GetId();
1029 if ( nId == SFX_HINT_DYING )
1031 pDocSh = NULL; // invalid
1036 // XSheetFilterDescriptor and XSheetFilterDescriptor2
1038 uno::Sequence<sheet::TableFilterField> SAL_CALL ScFilterDescriptorBase::getFilterFields()
1039 throw(uno::RuntimeException)
1041 SolarMutexGuard aGuard;
1042 ScQueryParam aParam;
1043 GetData(aParam);
1045 SCSIZE nEntries = aParam.GetEntryCount(); // allozierte Eintraege im Param
1046 SCSIZE nCount = 0; // aktive
1047 while ( nCount < nEntries &&
1048 aParam.GetEntry(nCount).bDoQuery )
1049 ++nCount;
1051 sheet::TableFilterField aField;
1052 uno::Sequence<sheet::TableFilterField> aSeq(static_cast<sal_Int32>(nCount));
1053 sheet::TableFilterField* pAry = aSeq.getArray();
1054 for (SCSIZE i=0; i<nCount; i++)
1056 const ScQueryEntry& rEntry = aParam.GetEntry(i);
1057 if (rEntry.GetQueryItems().empty())
1058 continue;
1060 const ScQueryEntry::Item& rItem = rEntry.GetQueryItems().front();
1062 aField.Connection = (rEntry.eConnect == SC_AND) ? sheet::FilterConnection_AND :
1063 sheet::FilterConnection_OR;
1064 aField.Field = rEntry.nField;
1065 aField.IsNumeric = rItem.meType != ScQueryEntry::ByString;
1066 aField.StringValue = rItem.maString.getString();
1067 aField.NumericValue = rItem.mfVal;
1069 switch (rEntry.eOp) // ScQueryOp
1071 case SC_EQUAL:
1073 aField.Operator = sheet::FilterOperator_EQUAL;
1074 if (rEntry.IsQueryByEmpty())
1076 aField.Operator = sheet::FilterOperator_EMPTY;
1077 aField.NumericValue = 0;
1079 else if (rEntry.IsQueryByNonEmpty())
1081 aField.Operator = sheet::FilterOperator_NOT_EMPTY;
1082 aField.NumericValue = 0;
1085 break;
1086 case SC_LESS: aField.Operator = sheet::FilterOperator_LESS; break;
1087 case SC_GREATER: aField.Operator = sheet::FilterOperator_GREATER; break;
1088 case SC_LESS_EQUAL: aField.Operator = sheet::FilterOperator_LESS_EQUAL; break;
1089 case SC_GREATER_EQUAL: aField.Operator = sheet::FilterOperator_GREATER_EQUAL; break;
1090 case SC_NOT_EQUAL: aField.Operator = sheet::FilterOperator_NOT_EQUAL; break;
1091 case SC_TOPVAL: aField.Operator = sheet::FilterOperator_TOP_VALUES; break;
1092 case SC_BOTVAL: aField.Operator = sheet::FilterOperator_BOTTOM_VALUES; break;
1093 case SC_TOPPERC: aField.Operator = sheet::FilterOperator_TOP_PERCENT; break;
1094 case SC_BOTPERC: aField.Operator = sheet::FilterOperator_BOTTOM_PERCENT; break;
1095 default:
1096 OSL_FAIL("Falscher Filter-enum");
1097 aField.Operator = sheet::FilterOperator_EMPTY;
1099 pAry[i] = aField;
1101 return aSeq;
1104 namespace {
1106 template<typename T>
1107 void convertQueryEntryToUno(const ScQueryEntry& rEntry, T& rField)
1109 rField.Connection = (rEntry.eConnect == SC_AND) ? sheet::FilterConnection_AND : sheet::FilterConnection_OR;
1110 rField.Field = rEntry.nField;
1112 switch (rEntry.eOp) // ScQueryOp
1114 case SC_EQUAL: rField.Operator = sheet::FilterOperator2::EQUAL; break;
1115 case SC_LESS: rField.Operator = sheet::FilterOperator2::LESS; break;
1116 case SC_GREATER: rField.Operator = sheet::FilterOperator2::GREATER; break;
1117 case SC_LESS_EQUAL: rField.Operator = sheet::FilterOperator2::LESS_EQUAL; break;
1118 case SC_GREATER_EQUAL: rField.Operator = sheet::FilterOperator2::GREATER_EQUAL; break;
1119 case SC_NOT_EQUAL: rField.Operator = sheet::FilterOperator2::NOT_EQUAL; break;
1120 case SC_TOPVAL: rField.Operator = sheet::FilterOperator2::TOP_VALUES; break;
1121 case SC_BOTVAL: rField.Operator = sheet::FilterOperator2::BOTTOM_VALUES; break;
1122 case SC_TOPPERC: rField.Operator = sheet::FilterOperator2::TOP_PERCENT; break;
1123 case SC_BOTPERC: rField.Operator = sheet::FilterOperator2::BOTTOM_PERCENT; break;
1124 case SC_CONTAINS: rField.Operator = sheet::FilterOperator2::CONTAINS; break;
1125 case SC_DOES_NOT_CONTAIN: rField.Operator = sheet::FilterOperator2::DOES_NOT_CONTAIN; break;
1126 case SC_BEGINS_WITH: rField.Operator = sheet::FilterOperator2::BEGINS_WITH; break;
1127 case SC_DOES_NOT_BEGIN_WITH: rField.Operator = sheet::FilterOperator2::DOES_NOT_BEGIN_WITH; break;
1128 case SC_ENDS_WITH: rField.Operator = sheet::FilterOperator2::ENDS_WITH; break;
1129 case SC_DOES_NOT_END_WITH: rField.Operator = sheet::FilterOperator2::DOES_NOT_END_WITH; break;
1130 default:
1131 OSL_FAIL("Unknown filter operator value.");
1132 rField.Operator = sheet::FilterOperator2::EMPTY;
1136 template<typename T>
1137 void convertUnoToQueryEntry(const T& rField, ScQueryEntry& rEntry)
1139 rEntry.bDoQuery = true;
1140 rEntry.eConnect = (rField.Connection == sheet::FilterConnection_AND) ? SC_AND : SC_OR;
1141 rEntry.nField = rField.Field;
1143 switch (rField.Operator) // FilterOperator
1145 case sheet::FilterOperator2::EQUAL: rEntry.eOp = SC_EQUAL; break;
1146 case sheet::FilterOperator2::LESS: rEntry.eOp = SC_LESS; break;
1147 case sheet::FilterOperator2::GREATER: rEntry.eOp = SC_GREATER; break;
1148 case sheet::FilterOperator2::LESS_EQUAL: rEntry.eOp = SC_LESS_EQUAL; break;
1149 case sheet::FilterOperator2::GREATER_EQUAL: rEntry.eOp = SC_GREATER_EQUAL; break;
1150 case sheet::FilterOperator2::NOT_EQUAL: rEntry.eOp = SC_NOT_EQUAL; break;
1151 case sheet::FilterOperator2::TOP_VALUES: rEntry.eOp = SC_TOPVAL; break;
1152 case sheet::FilterOperator2::BOTTOM_VALUES: rEntry.eOp = SC_BOTVAL; break;
1153 case sheet::FilterOperator2::TOP_PERCENT: rEntry.eOp = SC_TOPPERC; break;
1154 case sheet::FilterOperator2::BOTTOM_PERCENT: rEntry.eOp = SC_BOTPERC; break;
1155 case sheet::FilterOperator2::CONTAINS: rEntry.eOp = SC_CONTAINS; break;
1156 case sheet::FilterOperator2::DOES_NOT_CONTAIN: rEntry.eOp = SC_DOES_NOT_CONTAIN; break;
1157 case sheet::FilterOperator2::BEGINS_WITH: rEntry.eOp = SC_BEGINS_WITH; break;
1158 case sheet::FilterOperator2::DOES_NOT_BEGIN_WITH: rEntry.eOp = SC_DOES_NOT_BEGIN_WITH;break;
1159 case sheet::FilterOperator2::ENDS_WITH: rEntry.eOp = SC_ENDS_WITH; break;
1160 case sheet::FilterOperator2::DOES_NOT_END_WITH: rEntry.eOp = SC_DOES_NOT_END_WITH; break;
1161 case sheet::FilterOperator2::EMPTY:
1162 rEntry.SetQueryByEmpty();
1163 break;
1164 case sheet::FilterOperator2::NOT_EMPTY:
1165 rEntry.SetQueryByNonEmpty();
1166 break;
1167 default:
1168 OSL_FAIL("Unknown filter operator type.");
1169 rEntry.eOp = SC_EQUAL;
1173 void fillQueryParam(
1174 ScQueryParam& rParam, ScDocument* pDoc,
1175 const uno::Sequence<sheet::TableFilterField2>& aFilterFields)
1177 size_t nCount = static_cast<size_t>(aFilterFields.getLength());
1178 rParam.Resize(nCount);
1180 const sheet::TableFilterField2* pAry = aFilterFields.getConstArray();
1181 svl::SharedStringPool& rPool = pDoc->GetSharedStringPool();
1182 for (size_t i = 0; i < nCount; ++i)
1184 ScQueryEntry& rEntry = rParam.GetEntry(i);
1185 convertUnoToQueryEntry(pAry[i], rEntry);
1187 if (pAry[i].Operator != sheet::FilterOperator2::EMPTY && pAry[i].Operator != sheet::FilterOperator2::NOT_EMPTY)
1189 ScQueryEntry::QueryItemsType& rItems = rEntry.GetQueryItems();
1190 rItems.resize(1);
1191 ScQueryEntry::Item& rItem = rItems.front();
1192 rItem.meType = pAry[i].IsNumeric ? ScQueryEntry::ByValue : ScQueryEntry::ByString;
1193 rItem.mfVal = pAry[i].NumericValue;
1194 rItem.maString = rPool.intern(pAry[i].StringValue);
1196 if (rItem.meType == ScQueryEntry::ByValue)
1198 OUString aStr;
1199 pDoc->GetFormatTable()->GetInputLineString(rItem.mfVal, 0, aStr);
1200 rItem.maString = rPool.intern(aStr);
1205 size_t nParamCount = rParam.GetEntryCount(); // Param wird nicht unter 8 resized
1206 for (size_t i = nCount; i < nParamCount; ++i)
1207 rParam.GetEntry(i).bDoQuery = false; // ueberzaehlige Felder zuruecksetzen
1210 void fillQueryParam(
1211 ScQueryParam& rParam, ScDocument* pDoc,
1212 const uno::Sequence<sheet::TableFilterField3>& aFilterFields)
1214 size_t nCount = static_cast<size_t>(aFilterFields.getLength());
1215 rParam.Resize(nCount);
1217 svl::SharedStringPool& rPool = pDoc->GetSharedStringPool();
1218 const sheet::TableFilterField3* pAry = aFilterFields.getConstArray();
1219 for (size_t i = 0; i < nCount; ++i)
1221 ScQueryEntry& rEntry = rParam.GetEntry(i);
1222 convertUnoToQueryEntry(pAry[i], rEntry);
1224 if (pAry[i].Operator != sheet::FilterOperator2::EMPTY && pAry[i].Operator != sheet::FilterOperator2::NOT_EMPTY)
1226 ScQueryEntry::QueryItemsType& rItems = rEntry.GetQueryItems();
1227 rItems.clear();
1228 const uno::Sequence<sheet::FilterFieldValue>& rVals = pAry[i].Values;
1229 for (sal_Int32 j = 0, n = rVals.getLength(); j < n; ++j)
1231 ScQueryEntry::Item aItem;
1232 aItem.meType = rVals[j].IsNumeric ? ScQueryEntry::ByValue : ScQueryEntry::ByString;
1233 aItem.mfVal = rVals[j].NumericValue;
1234 aItem.maString = rPool.intern(rVals[j].StringValue);
1236 if (aItem.meType == ScQueryEntry::ByValue)
1238 OUString aStr;
1239 pDoc->GetFormatTable()->GetInputLineString(aItem.mfVal, 0, aStr);
1240 aItem.maString = rPool.intern(aStr);
1243 rItems.push_back(aItem);
1248 size_t nParamCount = rParam.GetEntryCount(); // Param wird nicht unter 8 resized
1249 for (size_t i = nCount; i < nParamCount; ++i)
1250 rParam.GetEntry(i).bDoQuery = false; // ueberzaehlige Felder zuruecksetzen
1255 uno::Sequence<sheet::TableFilterField2> SAL_CALL ScFilterDescriptorBase::getFilterFields2()
1256 throw(uno::RuntimeException)
1258 SolarMutexGuard aGuard;
1259 ScQueryParam aParam;
1260 GetData(aParam);
1262 SCSIZE nEntries = aParam.GetEntryCount(); // allozierte Eintraege im Param
1263 SCSIZE nCount = 0; // aktive
1264 while ( nCount < nEntries &&
1265 aParam.GetEntry(nCount).bDoQuery )
1266 ++nCount;
1268 sheet::TableFilterField2 aField;
1269 uno::Sequence<sheet::TableFilterField2> aSeq(static_cast<sal_Int32>(nCount));
1270 sheet::TableFilterField2* pAry = aSeq.getArray();
1271 for (SCSIZE i=0; i<nCount; i++)
1273 const ScQueryEntry& rEntry = aParam.GetEntry(i);
1274 convertQueryEntryToUno(rEntry, aField);
1276 bool bByEmpty = false;
1277 if (aField.Operator == sheet::FilterOperator2::EQUAL)
1279 if (rEntry.IsQueryByEmpty())
1281 aField.Operator = sheet::FilterOperator2::EMPTY;
1282 aField.NumericValue = 0;
1283 bByEmpty = true;
1285 else if (rEntry.IsQueryByNonEmpty())
1287 aField.Operator = sheet::FilterOperator2::NOT_EMPTY;
1288 aField.NumericValue = 0;
1289 bByEmpty = true;
1293 if (!bByEmpty && !rEntry.GetQueryItems().empty())
1295 const ScQueryEntry::Item& rItem = rEntry.GetQueryItems().front();
1296 aField.IsNumeric = rItem.meType != ScQueryEntry::ByString;
1297 aField.StringValue = rItem.maString.getString();
1298 aField.NumericValue = rItem.mfVal;
1301 pAry[i] = aField;
1303 return aSeq;
1306 uno::Sequence<sheet::TableFilterField3> SAL_CALL ScFilterDescriptorBase::getFilterFields3()
1307 throw(uno::RuntimeException)
1309 SolarMutexGuard aGuard;
1310 ScQueryParam aParam;
1311 GetData(aParam);
1313 SCSIZE nEntries = aParam.GetEntryCount(); // allozierte Eintraege im Param
1314 SCSIZE nCount = 0; // aktive
1315 while ( nCount < nEntries &&
1316 aParam.GetEntry(nCount).bDoQuery )
1317 ++nCount;
1319 sheet::TableFilterField3 aField;
1320 uno::Sequence<sheet::TableFilterField3> aSeq(static_cast<sal_Int32>(nCount));
1321 sheet::TableFilterField3* pAry = aSeq.getArray();
1322 for (SCSIZE i = 0; i < nCount; ++i)
1324 const ScQueryEntry& rEntry = aParam.GetEntry(i);
1325 convertQueryEntryToUno(rEntry, aField);
1327 bool bByEmpty = false;
1328 if (aField.Operator == sheet::FilterOperator2::EQUAL)
1330 if (rEntry.IsQueryByEmpty())
1332 aField.Operator = sheet::FilterOperator2::EMPTY;
1333 aField.Values.realloc(1);
1334 aField.Values[0].NumericValue = 0;
1335 bByEmpty = true;
1337 else if (rEntry.IsQueryByNonEmpty())
1339 aField.Operator = sheet::FilterOperator2::NOT_EMPTY;
1340 aField.Values.realloc(1);
1341 aField.Values[0].NumericValue = 0;
1342 bByEmpty = true;
1346 if (!bByEmpty)
1348 const ScQueryEntry::QueryItemsType& rItems = rEntry.GetQueryItems();
1349 size_t nItemCount = rItems.size();
1350 aField.Values.realloc(nItemCount);
1351 ScQueryEntry::QueryItemsType::const_iterator itr = rItems.begin(), itrEnd = rItems.end();
1352 for (size_t j = 0; itr != itrEnd; ++itr, ++j)
1354 aField.Values[j].IsNumeric = itr->meType != ScQueryEntry::ByString;
1355 aField.Values[j].StringValue = itr->maString.getString();
1356 aField.Values[j].NumericValue = itr->mfVal;
1361 pAry[i] = aField;
1363 return aSeq;
1366 void SAL_CALL ScFilterDescriptorBase::setFilterFields(
1367 const uno::Sequence<sheet::TableFilterField>& aFilterFields )
1368 throw(uno::RuntimeException)
1370 SolarMutexGuard aGuard;
1371 ScQueryParam aParam;
1372 GetData(aParam);
1374 SCSIZE nCount = static_cast<SCSIZE>(aFilterFields.getLength());
1375 aParam.Resize( nCount );
1377 ScDocument* pDoc = pDocSh->GetDocument();
1378 svl::SharedStringPool& rPool = pDoc->GetSharedStringPool();
1379 const sheet::TableFilterField* pAry = aFilterFields.getConstArray();
1380 SCSIZE i;
1381 for (i=0; i<nCount; i++)
1383 ScQueryEntry& rEntry = aParam.GetEntry(i);
1384 ScQueryEntry::QueryItemsType& rItems = rEntry.GetQueryItems();
1385 rItems.resize(1);
1386 ScQueryEntry::Item& rItem = rItems.front();
1387 rEntry.bDoQuery = true;
1388 rEntry.eConnect = (pAry[i].Connection == sheet::FilterConnection_AND) ? SC_AND : SC_OR;
1389 rEntry.nField = pAry[i].Field;
1390 rItem.meType = pAry[i].IsNumeric ? ScQueryEntry::ByValue : ScQueryEntry::ByString;
1391 rItem.mfVal = pAry[i].NumericValue;
1392 rItem.maString = rPool.intern(pAry[i].StringValue);
1394 if (rItem.meType != ScQueryEntry::ByString)
1396 OUString aStr;
1397 pDoc->GetFormatTable()->GetInputLineString(rItem.mfVal, 0, aStr);
1398 rItem.maString = rPool.intern(aStr);
1401 switch (pAry[i].Operator) // FilterOperator
1403 case sheet::FilterOperator_EQUAL: rEntry.eOp = SC_EQUAL; break;
1404 case sheet::FilterOperator_LESS: rEntry.eOp = SC_LESS; break;
1405 case sheet::FilterOperator_GREATER: rEntry.eOp = SC_GREATER; break;
1406 case sheet::FilterOperator_LESS_EQUAL: rEntry.eOp = SC_LESS_EQUAL; break;
1407 case sheet::FilterOperator_GREATER_EQUAL: rEntry.eOp = SC_GREATER_EQUAL; break;
1408 case sheet::FilterOperator_NOT_EQUAL: rEntry.eOp = SC_NOT_EQUAL; break;
1409 case sheet::FilterOperator_TOP_VALUES: rEntry.eOp = SC_TOPVAL; break;
1410 case sheet::FilterOperator_BOTTOM_VALUES: rEntry.eOp = SC_BOTVAL; break;
1411 case sheet::FilterOperator_TOP_PERCENT: rEntry.eOp = SC_TOPPERC; break;
1412 case sheet::FilterOperator_BOTTOM_PERCENT: rEntry.eOp = SC_BOTPERC; break;
1413 case sheet::FilterOperator_EMPTY:
1414 rEntry.SetQueryByEmpty();
1415 break;
1416 case sheet::FilterOperator_NOT_EMPTY:
1417 rEntry.SetQueryByNonEmpty();
1418 break;
1419 default:
1420 OSL_FAIL("Falscher Query-enum");
1421 rEntry.eOp = SC_EQUAL;
1425 SCSIZE nParamCount = aParam.GetEntryCount(); // Param wird nicht unter 8 resized
1426 for (i=nCount; i<nParamCount; i++)
1427 aParam.GetEntry(i).bDoQuery = false; // ueberzaehlige Felder zuruecksetzen
1429 PutData(aParam);
1432 void SAL_CALL ScFilterDescriptorBase::setFilterFields2(
1433 const uno::Sequence<sheet::TableFilterField2>& aFilterFields )
1434 throw(uno::RuntimeException)
1436 SolarMutexGuard aGuard;
1437 ScQueryParam aParam;
1438 GetData(aParam);
1439 fillQueryParam(aParam, pDocSh->GetDocument(), aFilterFields);
1440 PutData(aParam);
1443 void SAL_CALL ScFilterDescriptorBase::setFilterFields3(
1444 const uno::Sequence<sheet::TableFilterField3>& aFilterFields )
1445 throw(uno::RuntimeException)
1447 SolarMutexGuard aGuard;
1448 ScQueryParam aParam;
1449 GetData(aParam);
1450 fillQueryParam(aParam, pDocSh->GetDocument(), aFilterFields);
1451 PutData(aParam);
1454 // Rest sind Properties
1456 // XPropertySet
1458 uno::Reference<beans::XPropertySetInfo> SAL_CALL ScFilterDescriptorBase::getPropertySetInfo()
1459 throw(uno::RuntimeException)
1461 SolarMutexGuard aGuard;
1462 static uno::Reference<beans::XPropertySetInfo> aRef(
1463 new SfxItemPropertySetInfo( aPropSet.getPropertyMap() ));
1464 return aRef;
1467 void SAL_CALL ScFilterDescriptorBase::setPropertyValue(
1468 const OUString& aPropertyName, const uno::Any& aValue )
1469 throw(beans::UnknownPropertyException, beans::PropertyVetoException,
1470 lang::IllegalArgumentException, lang::WrappedTargetException,
1471 uno::RuntimeException)
1473 SolarMutexGuard aGuard;
1474 ScQueryParam aParam;
1475 GetData(aParam);
1477 OUString aString(aPropertyName);
1478 if (aString.equalsAscii( SC_UNONAME_CONTHDR ))
1479 aParam.bHasHeader = ScUnoHelpFunctions::GetBoolFromAny( aValue );
1480 else if (aString.equalsAscii( SC_UNONAME_COPYOUT ))
1481 aParam.bInplace = !(ScUnoHelpFunctions::GetBoolFromAny( aValue ));
1482 else if (aString.equalsAscii( SC_UNONAME_ISCASE ))
1483 aParam.bCaseSens = ScUnoHelpFunctions::GetBoolFromAny( aValue );
1484 else if (aString.equalsAscii( SC_UNONAME_MAXFLD ))
1486 // silently ignored
1488 else if (aString.equalsAscii( SC_UNONAME_ORIENT ))
1490 //! test for correct enum type?
1491 table::TableOrientation eOrient = (table::TableOrientation)
1492 ScUnoHelpFunctions::GetEnumFromAny( aValue );
1493 aParam.bByRow = ( eOrient != table::TableOrientation_COLUMNS );
1495 else if (aString.equalsAscii( SC_UNONAME_OUTPOS ))
1497 table::CellAddress aAddress;
1498 if ( aValue >>= aAddress )
1500 aParam.nDestTab = aAddress.Sheet;
1501 aParam.nDestCol = (SCCOL)aAddress.Column;
1502 aParam.nDestRow = (SCROW)aAddress.Row;
1505 else if (aString.equalsAscii( SC_UNONAME_SAVEOUT ))
1506 aParam.bDestPers = ScUnoHelpFunctions::GetBoolFromAny( aValue );
1507 else if (aString.equalsAscii( SC_UNONAME_SKIPDUP ))
1508 aParam.bDuplicate = !(ScUnoHelpFunctions::GetBoolFromAny( aValue ));
1509 else if (aString.equalsAscii( SC_UNONAME_USEREGEX ))
1510 aParam.bRegExp = ScUnoHelpFunctions::GetBoolFromAny( aValue );
1512 PutData(aParam);
1515 uno::Any SAL_CALL ScFilterDescriptorBase::getPropertyValue( const OUString& aPropertyName )
1516 throw(beans::UnknownPropertyException, lang::WrappedTargetException,
1517 uno::RuntimeException)
1519 SolarMutexGuard aGuard;
1520 ScQueryParam aParam;
1521 GetData(aParam);
1523 OUString aString(aPropertyName);
1524 uno::Any aRet;
1526 if (aString.equalsAscii( SC_UNONAME_CONTHDR ))
1527 ScUnoHelpFunctions::SetBoolInAny( aRet, aParam.bHasHeader );
1528 else if (aString.equalsAscii( SC_UNONAME_COPYOUT ))
1529 ScUnoHelpFunctions::SetBoolInAny( aRet, !(aParam.bInplace) );
1530 else if (aString.equalsAscii( SC_UNONAME_ISCASE ))
1531 ScUnoHelpFunctions::SetBoolInAny( aRet, aParam.bCaseSens );
1532 else if (aString.equalsAscii( SC_UNONAME_MAXFLD ))
1533 aRet <<= (sal_Int32) aParam.GetEntryCount();
1534 else if (aString.equalsAscii( SC_UNONAME_ORIENT ))
1536 table::TableOrientation eOrient = aParam.bByRow ? table::TableOrientation_ROWS :
1537 table::TableOrientation_COLUMNS;
1538 aRet <<= eOrient;
1540 else if (aString.equalsAscii( SC_UNONAME_OUTPOS ))
1542 table::CellAddress aOutPos;
1543 aOutPos.Sheet = aParam.nDestTab;
1544 aOutPos.Column = aParam.nDestCol;
1545 aOutPos.Row = aParam.nDestRow;
1546 aRet <<= aOutPos;
1548 else if (aString.equalsAscii( SC_UNONAME_SAVEOUT ))
1549 ScUnoHelpFunctions::SetBoolInAny( aRet, aParam.bDestPers );
1550 else if (aString.equalsAscii( SC_UNONAME_SKIPDUP ))
1551 ScUnoHelpFunctions::SetBoolInAny( aRet, !(aParam.bDuplicate) );
1552 else if (aString.equalsAscii( SC_UNONAME_USEREGEX ))
1553 ScUnoHelpFunctions::SetBoolInAny( aRet, aParam.bRegExp );
1555 return aRet;
1558 SC_IMPL_DUMMY_PROPERTY_LISTENER( ScFilterDescriptorBase )
1560 //------------------------------------------------------------------------
1562 ScFilterDescriptor::ScFilterDescriptor(ScDocShell* pDocShell)
1564 ScFilterDescriptorBase(pDocShell)
1568 ScFilterDescriptor::~ScFilterDescriptor()
1572 void ScFilterDescriptor::GetData( ScQueryParam& rParam ) const
1574 rParam = aStoredParam; // Abfrage fuer Interface
1577 void ScFilterDescriptor::PutData( const ScQueryParam& rParam )
1579 aStoredParam = rParam; // vom Interface gesetzt
1582 void ScFilterDescriptor::SetParam( const ScQueryParam& rNew )
1584 aStoredParam = rNew; // von aussen gesetzt
1587 //------------------------------------------------------------------------
1589 ScRangeFilterDescriptor::ScRangeFilterDescriptor(ScDocShell* pDocShell, ScDatabaseRangeObj* pPar) :
1590 ScFilterDescriptorBase(pDocShell),
1591 pParent(pPar)
1593 if (pParent)
1594 pParent->acquire();
1597 ScRangeFilterDescriptor::~ScRangeFilterDescriptor()
1599 if (pParent)
1600 pParent->release();
1603 void ScRangeFilterDescriptor::GetData( ScQueryParam& rParam ) const
1605 if (pParent)
1606 pParent->GetQueryParam( rParam );
1609 void ScRangeFilterDescriptor::PutData( const ScQueryParam& rParam )
1611 if (pParent)
1612 pParent->SetQueryParam( rParam );
1615 //------------------------------------------------------------------------
1617 ScDataPilotFilterDescriptor::ScDataPilotFilterDescriptor(ScDocShell* pDocShell, ScDataPilotDescriptorBase* pPar) :
1618 ScFilterDescriptorBase(pDocShell),
1619 pParent(pPar)
1621 if (pParent)
1622 pParent->acquire();
1625 ScDataPilotFilterDescriptor::~ScDataPilotFilterDescriptor()
1627 if (pParent)
1628 pParent->release();
1631 void ScDataPilotFilterDescriptor::GetData( ScQueryParam& rParam ) const
1633 if (pParent)
1635 ScDPObject* pDPObj = pParent->GetDPObject();
1636 if (pDPObj && pDPObj->IsSheetData())
1637 rParam = pDPObj->GetSheetDesc()->GetQueryParam();
1641 void ScDataPilotFilterDescriptor::PutData( const ScQueryParam& rParam )
1643 if (pParent)
1645 ScDPObject* pDPObj = pParent->GetDPObject();
1646 if (pDPObj)
1648 ScSheetSourceDesc aSheetDesc(pParent->GetDocShell()->GetDocument());
1649 if (pDPObj->IsSheetData())
1650 aSheetDesc = *pDPObj->GetSheetDesc();
1651 aSheetDesc.SetQueryParam(rParam);
1652 pDPObj->SetSheetDesc(aSheetDesc);
1653 pParent->SetDPObject(pDPObj);
1658 //------------------------------------------------------------------------
1660 ScDatabaseRangeObj::ScDatabaseRangeObj(ScDocShell* pDocSh, const OUString& rNm) :
1661 pDocShell( pDocSh ),
1662 aName( rNm ),
1663 aPropSet( lcl_GetDBRangePropertyMap() ),
1664 bIsUnnamed(false),
1665 aTab( 0 )
1667 pDocShell->GetDocument()->AddUnoObject(*this);
1670 ScDatabaseRangeObj::ScDatabaseRangeObj(ScDocShell* pDocSh, const SCTAB nTab) :
1671 pDocShell( pDocSh ),
1672 aName(STR_DB_LOCAL_NONAME),
1673 aPropSet( lcl_GetDBRangePropertyMap() ),
1674 bIsUnnamed(true),
1675 aTab( nTab )
1677 pDocShell->GetDocument()->AddUnoObject(*this);
1680 ScDatabaseRangeObj::~ScDatabaseRangeObj()
1682 if (pDocShell)
1683 pDocShell->GetDocument()->RemoveUnoObject(*this);
1686 void ScDatabaseRangeObj::Notify( SfxBroadcaster&, const SfxHint& rHint )
1689 if ( rHint.ISA( SfxSimpleHint ) && ((const SfxSimpleHint&)rHint).GetId() == SFX_HINT_DYING )
1690 pDocShell = NULL; // ungueltig geworden
1691 else if ( rHint.ISA (ScDBRangeRefreshedHint) )
1693 ScDBData* pDBData = GetDBData_Impl();
1694 const ScDBRangeRefreshedHint& rRef = (const ScDBRangeRefreshedHint&)rHint;
1695 ScImportParam aParam;
1696 pDBData->GetImportParam(aParam);
1697 if (aParam == rRef.GetImportParam())
1698 Refreshed_Impl();
1702 // Hilfsfuntionen
1704 ScDBData* ScDatabaseRangeObj::GetDBData_Impl() const
1706 ScDBData* pRet = NULL;
1707 if (pDocShell)
1709 if (bIsUnnamed)
1711 pRet = pDocShell->GetDocument()->GetAnonymousDBData(aTab);
1713 else
1715 ScDBCollection* pNames = pDocShell->GetDocument()->GetDBCollection();
1716 if (pNames)
1718 ScDBData* p = pNames->getNamedDBs().findByUpperName(ScGlobal::pCharClass->uppercase(aName));
1719 if (p)
1720 pRet = p;
1724 return pRet;
1727 // XNamed
1729 OUString SAL_CALL ScDatabaseRangeObj::getName() throw(uno::RuntimeException)
1731 SolarMutexGuard aGuard;
1732 return aName;
1735 void SAL_CALL ScDatabaseRangeObj::setName( const OUString& aNewName )
1736 throw(uno::RuntimeException)
1738 SolarMutexGuard aGuard;
1739 if (pDocShell)
1741 ScDBDocFunc aFunc(*pDocShell);
1742 OUString aNewStr(aNewName);
1743 sal_Bool bOk = aFunc.RenameDBRange( aName, aNewStr );
1744 if (bOk)
1745 aName = aNewStr;
1749 // XDatabaseRange
1751 table::CellRangeAddress SAL_CALL ScDatabaseRangeObj::getDataArea() throw(uno::RuntimeException)
1753 SolarMutexGuard aGuard;
1754 table::CellRangeAddress aAddress;
1755 ScDBData* pData = GetDBData_Impl();
1756 if (pData)
1758 ScRange aRange;
1759 pData->GetArea(aRange);
1760 aAddress.Sheet = aRange.aStart.Tab();
1761 aAddress.StartColumn = aRange.aStart.Col();
1762 aAddress.StartRow = aRange.aStart.Row();
1763 aAddress.EndColumn = aRange.aEnd.Col();
1764 aAddress.EndRow = aRange.aEnd.Row();
1766 return aAddress;
1769 void SAL_CALL ScDatabaseRangeObj::setDataArea( const table::CellRangeAddress& aDataArea )
1770 throw(uno::RuntimeException)
1772 SolarMutexGuard aGuard;
1773 ScDBData* pData = GetDBData_Impl();
1774 if ( pDocShell && pData )
1776 ScDBData aNewData( *pData );
1777 //! MoveTo ???
1778 aNewData.SetArea( aDataArea.Sheet, (SCCOL)aDataArea.StartColumn, (SCROW)aDataArea.StartRow,
1779 (SCCOL)aDataArea.EndColumn, (SCROW)aDataArea.EndRow );
1780 ScDBDocFunc aFunc(*pDocShell);
1781 aFunc.ModifyDBData(aNewData);
1785 uno::Sequence<beans::PropertyValue> SAL_CALL ScDatabaseRangeObj::getSortDescriptor()
1786 throw(uno::RuntimeException)
1788 SolarMutexGuard aGuard;
1789 ScSortParam aParam;
1790 const ScDBData* pData = GetDBData_Impl();
1791 if (pData)
1793 pData->GetSortParam(aParam);
1795 // im SortDescriptor sind die Fields innerhalb des Bereichs gezaehlt
1796 ScRange aDBRange;
1797 pData->GetArea(aDBRange);
1798 SCCOLROW nFieldStart = aParam.bByRow ? static_cast<SCCOLROW>(aDBRange.aStart.Col()) : static_cast<SCCOLROW>(aDBRange.aStart.Row());
1799 for (sal_uInt16 i=0; i<aParam.GetSortKeyCount(); i++)
1800 if ( aParam.maKeyState[i].bDoSort && aParam.maKeyState[i].nField >= nFieldStart )
1801 aParam.maKeyState[i].nField -= nFieldStart;
1804 uno::Sequence<beans::PropertyValue> aSeq( ScSortDescriptor::GetPropertyCount() );
1805 ScSortDescriptor::FillProperties( aSeq, aParam );
1806 return aSeq;
1809 void ScDatabaseRangeObj::GetQueryParam(ScQueryParam& rQueryParam) const
1811 const ScDBData* pData = GetDBData_Impl();
1812 if (pData)
1814 pData->GetQueryParam(rQueryParam);
1816 // im FilterDescriptor sind die Fields innerhalb des Bereichs gezaehlt
1817 ScRange aDBRange;
1818 pData->GetArea(aDBRange);
1819 SCCOLROW nFieldStart = rQueryParam.bByRow ? static_cast<SCCOLROW>(aDBRange.aStart.Col()) : static_cast<SCCOLROW>(aDBRange.aStart.Row());
1820 SCSIZE nCount = rQueryParam.GetEntryCount();
1821 for (SCSIZE i=0; i<nCount; i++)
1823 ScQueryEntry& rEntry = rQueryParam.GetEntry(i);
1824 if (rEntry.bDoQuery && rEntry.nField >= nFieldStart)
1825 rEntry.nField -= nFieldStart;
1830 void ScDatabaseRangeObj::SetQueryParam(const ScQueryParam& rQueryParam)
1832 const ScDBData* pData = GetDBData_Impl();
1833 if (pData)
1835 // im FilterDescriptor sind die Fields innerhalb des Bereichs gezaehlt
1836 ScQueryParam aParam(rQueryParam);
1837 ScRange aDBRange;
1838 pData->GetArea(aDBRange);
1839 SCCOLROW nFieldStart = aParam.bByRow ? static_cast<SCCOLROW>(aDBRange.aStart.Col()) : static_cast<SCCOLROW>(aDBRange.aStart.Row());
1841 SCSIZE nCount = aParam.GetEntryCount();
1842 for (SCSIZE i=0; i<nCount; i++)
1844 ScQueryEntry& rEntry = aParam.GetEntry(i);
1845 if (rEntry.bDoQuery)
1846 rEntry.nField += nFieldStart;
1849 ScDBData aNewData( *pData );
1850 aNewData.SetQueryParam(aParam);
1851 aNewData.SetHeader(aParam.bHasHeader); // not in ScDBData::SetQueryParam
1852 ScDBDocFunc aFunc(*pDocShell);
1853 aFunc.ModifyDBData(aNewData);
1857 uno::Reference<sheet::XSheetFilterDescriptor> SAL_CALL ScDatabaseRangeObj::getFilterDescriptor()
1858 throw(uno::RuntimeException)
1860 SolarMutexGuard aGuard;
1861 return new ScRangeFilterDescriptor(pDocShell, this);
1864 void ScDatabaseRangeObj::GetSubTotalParam(ScSubTotalParam& rSubTotalParam) const
1866 const ScDBData* pData = GetDBData_Impl();
1867 if (pData)
1869 pData->GetSubTotalParam(rSubTotalParam);
1871 // im FilterDescriptor sind die Fields innerhalb des Bereichs gezaehlt
1872 ScRange aDBRange;
1873 pData->GetArea(aDBRange);
1874 SCCOL nFieldStart = aDBRange.aStart.Col();
1875 for (sal_uInt16 i=0; i<MAXSUBTOTAL; i++)
1877 if ( rSubTotalParam.bGroupActive[i] )
1879 if ( rSubTotalParam.nField[i] >= nFieldStart )
1880 rSubTotalParam.nField[i] = sal::static_int_cast<SCCOL>( rSubTotalParam.nField[i] - nFieldStart );
1881 for (SCCOL j=0; j<rSubTotalParam.nSubTotals[i]; j++)
1882 if ( rSubTotalParam.pSubTotals[i][j] >= nFieldStart )
1883 rSubTotalParam.pSubTotals[i][j] =
1884 sal::static_int_cast<SCCOL>( rSubTotalParam.pSubTotals[i][j] - nFieldStart );
1890 void ScDatabaseRangeObj::SetSubTotalParam(const ScSubTotalParam& rSubTotalParam)
1892 const ScDBData* pData = GetDBData_Impl();
1893 if (pData)
1895 // im FilterDescriptor sind die Fields innerhalb des Bereichs gezaehlt
1896 ScSubTotalParam aParam(rSubTotalParam);
1897 ScRange aDBRange;
1898 pData->GetArea(aDBRange);
1899 SCCOL nFieldStart = aDBRange.aStart.Col();
1900 for (sal_uInt16 i=0; i<MAXSUBTOTAL; i++)
1902 if ( aParam.bGroupActive[i] )
1904 aParam.nField[i] = sal::static_int_cast<SCCOL>( aParam.nField[i] + nFieldStart );
1905 for (SCCOL j=0; j<aParam.nSubTotals[i]; j++)
1906 aParam.pSubTotals[i][j] = sal::static_int_cast<SCCOL>( aParam.pSubTotals[i][j] + nFieldStart );
1910 ScDBData aNewData( *pData );
1911 aNewData.SetSubTotalParam(aParam);
1912 ScDBDocFunc aFunc(*pDocShell);
1913 aFunc.ModifyDBData(aNewData);
1917 uno::Reference<sheet::XSubTotalDescriptor> SAL_CALL ScDatabaseRangeObj::getSubTotalDescriptor()
1918 throw(uno::RuntimeException)
1920 SolarMutexGuard aGuard;
1921 return new ScRangeSubTotalDescriptor(this);
1924 uno::Sequence<beans::PropertyValue> SAL_CALL ScDatabaseRangeObj::getImportDescriptor()
1925 throw(uno::RuntimeException)
1927 SolarMutexGuard aGuard;
1928 ScImportParam aParam;
1929 const ScDBData* pData = GetDBData_Impl();
1930 if (pData)
1931 pData->GetImportParam(aParam);
1933 uno::Sequence<beans::PropertyValue> aSeq( ScImportDescriptor::GetPropertyCount() );
1934 ScImportDescriptor::FillProperties( aSeq, aParam );
1935 return aSeq;
1938 // XRefreshable
1940 void SAL_CALL ScDatabaseRangeObj::refresh() throw(uno::RuntimeException)
1942 SolarMutexGuard aGuard;
1943 ScDBData* pData = GetDBData_Impl();
1944 if ( pDocShell && pData )
1946 ScDBDocFunc aFunc(*pDocShell);
1948 // Import zu wiederholen?
1949 sal_Bool bContinue = sal_True;
1950 ScImportParam aImportParam;
1951 pData->GetImportParam( aImportParam );
1952 if (aImportParam.bImport && !pData->HasImportSelection())
1954 SCTAB nTab;
1955 SCCOL nDummyCol;
1956 SCROW nDummyRow;
1957 pData->GetArea( nTab, nDummyCol,nDummyRow,nDummyCol,nDummyRow );
1958 bContinue = aFunc.DoImport( nTab, aImportParam, NULL, true ); //! Api-Flag as parameter
1961 // interne Operationen (sort, query, subtotal) nur, wenn kein Fehler
1962 if (bContinue)
1963 aFunc.RepeatDB( pData->GetName(), true, true, bIsUnnamed, aTab );
1967 void SAL_CALL ScDatabaseRangeObj::addRefreshListener(
1968 const uno::Reference<util::XRefreshListener >& xListener )
1969 throw(uno::RuntimeException)
1971 SolarMutexGuard aGuard;
1972 uno::Reference<util::XRefreshListener>* pObj =
1973 new uno::Reference<util::XRefreshListener>( xListener );
1974 aRefreshListeners.push_back( pObj );
1976 // hold one additional ref to keep this object alive as long as there are listeners
1977 if ( aRefreshListeners.size() == 1 )
1978 acquire();
1981 void SAL_CALL ScDatabaseRangeObj::removeRefreshListener(
1982 const uno::Reference<util::XRefreshListener >& xListener )
1983 throw(uno::RuntimeException)
1985 SolarMutexGuard aGuard;
1986 sal_uInt16 nCount = aRefreshListeners.size();
1987 for ( sal_uInt16 n=nCount; n--; )
1989 uno::Reference<util::XRefreshListener>& rObj = aRefreshListeners[n];
1990 if ( rObj == xListener )
1992 aRefreshListeners.erase( aRefreshListeners.begin() + n );
1993 if ( aRefreshListeners.empty() )
1994 release(); // release ref for listeners
1995 break;
2000 void ScDatabaseRangeObj::Refreshed_Impl()
2002 lang::EventObject aEvent;
2003 aEvent.Source = (cppu::OWeakObject*)this;
2004 for ( sal_uInt16 n=0; n<aRefreshListeners.size(); n++ )
2005 aRefreshListeners[n]->refreshed( aEvent );
2008 // XCellRangeSource
2010 uno::Reference<table::XCellRange> SAL_CALL ScDatabaseRangeObj::getReferredCells()
2011 throw(uno::RuntimeException)
2013 SolarMutexGuard aGuard;
2014 ScRange aRange;
2015 ScDBData* pData = GetDBData_Impl();
2016 if ( pData )
2018 //! static Funktion um ScCellObj/ScCellRangeObj zu erzeugen am ScCellRangeObj ???
2020 pData->GetArea(aRange);
2021 if ( aRange.aStart == aRange.aEnd )
2022 return new ScCellObj( pDocShell, aRange.aStart );
2023 else
2024 return new ScCellRangeObj( pDocShell, aRange );
2026 return NULL;
2029 // XPropertySet
2031 uno::Reference<beans::XPropertySetInfo> SAL_CALL ScDatabaseRangeObj::getPropertySetInfo()
2032 throw(uno::RuntimeException)
2034 SolarMutexGuard aGuard;
2035 static uno::Reference<beans::XPropertySetInfo> aRef(
2036 new SfxItemPropertySetInfo( aPropSet.getPropertyMap() ));
2037 return aRef;
2040 void SAL_CALL ScDatabaseRangeObj::setPropertyValue(
2041 const OUString& aPropertyName, const uno::Any& aValue )
2042 throw(beans::UnknownPropertyException, beans::PropertyVetoException,
2043 lang::IllegalArgumentException, lang::WrappedTargetException,
2044 uno::RuntimeException)
2046 SolarMutexGuard aGuard;
2047 ScDBData* pData = GetDBData_Impl();
2048 if ( pDocShell && pData )
2050 ScDBData aNewData( *pData );
2051 sal_Bool bDo = sal_True;
2053 OUString aString(aPropertyName);
2054 if ( aString.equalsAscii( SC_UNONAME_KEEPFORM ) )
2055 aNewData.SetKeepFmt( ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
2056 else if ( aString.equalsAscii( SC_UNONAME_MOVCELLS ) )
2057 aNewData.SetDoSize( ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
2058 else if ( aString.equalsAscii( SC_UNONAME_STRIPDAT ) )
2059 aNewData.SetStripData( ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
2060 else if (aString.equalsAscii( SC_UNONAME_AUTOFLT ))
2062 sal_Bool bAutoFilter(ScUnoHelpFunctions::GetBoolFromAny( aValue ));
2063 aNewData.SetAutoFilter(bAutoFilter);
2064 ScRange aRange;
2065 aNewData.GetArea(aRange);
2066 ScDocument* pDoc = pDocShell->GetDocument();
2067 if (bAutoFilter && pDoc)
2068 pDoc->ApplyFlagsTab( aRange.aStart.Col(), aRange.aStart.Row(),
2069 aRange.aEnd.Col(), aRange.aStart.Row(),
2070 aRange.aStart.Tab(), SC_MF_AUTO );
2071 else if (!bAutoFilter && pDoc)
2072 pDoc->RemoveFlagsTab(aRange.aStart.Col(), aRange.aStart.Row(),
2073 aRange.aEnd.Col(), aRange.aStart.Row(),
2074 aRange.aStart.Tab(), SC_MF_AUTO );
2075 ScRange aPaintRange(aRange.aStart, aRange.aEnd);
2076 aPaintRange.aEnd.SetRow(aPaintRange.aStart.Row());
2077 pDocShell->PostPaint(aPaintRange, PAINT_GRID);
2079 else if (aString.equalsAscii( SC_UNONAME_USEFLTCRT ))
2081 if (ScUnoHelpFunctions::GetBoolFromAny( aValue ))
2083 ScRange aRange;
2084 aNewData.GetAdvancedQuerySource(aRange);
2085 aNewData.SetAdvancedQuerySource(&aRange);
2087 else
2088 aNewData.SetAdvancedQuerySource(NULL);
2090 else if (aString.equalsAscii( SC_UNONAME_FLTCRT ))
2092 table::CellRangeAddress aRange;
2093 if (aValue >>= aRange)
2095 ScRange aCoreRange;
2096 ScUnoConversion::FillScRange(aCoreRange, aRange);
2098 aNewData.SetAdvancedQuerySource(&aCoreRange);
2101 else if (aString.equalsAscii( SC_UNONAME_FROMSELECT ))
2103 aNewData.SetImportSelection(::cppu::any2bool(aValue));
2105 else if (aString.equalsAscii( SC_UNONAME_REFPERIOD ))
2107 sal_Int32 nRefresh = 0;
2108 if (aValue >>= nRefresh)
2110 ScDocument* pDoc = pDocShell->GetDocument();
2111 aNewData.SetRefreshDelay(nRefresh);
2112 if (pDoc && pDoc->GetDBCollection())
2114 aNewData.SetRefreshHandler( pDoc->GetDBCollection()->GetRefreshHandler() );
2115 aNewData.SetRefreshControl( pDoc->GetRefreshTimerControlAddress() );
2119 else if (aString.equalsAscii( SC_UNONAME_CONRES ))
2122 else
2123 bDo = false;
2125 if (bDo)
2127 ScDBDocFunc aFunc(*pDocShell);
2128 aFunc.ModifyDBData(aNewData);
2133 uno::Any SAL_CALL ScDatabaseRangeObj::getPropertyValue( const OUString& aPropertyName )
2134 throw(beans::UnknownPropertyException, lang::WrappedTargetException,
2135 uno::RuntimeException)
2137 SolarMutexGuard aGuard;
2138 uno::Any aRet;
2139 ScDBData* pData = GetDBData_Impl();
2140 if ( pData )
2142 OUString aString(aPropertyName);
2143 if ( aString.equalsAscii( SC_UNONAME_KEEPFORM ) )
2144 ScUnoHelpFunctions::SetBoolInAny( aRet, pData->IsKeepFmt() );
2145 else if ( aString.equalsAscii( SC_UNONAME_MOVCELLS ) )
2146 ScUnoHelpFunctions::SetBoolInAny( aRet, pData->IsDoSize() );
2147 else if ( aString.equalsAscii( SC_UNONAME_STRIPDAT ) )
2148 ScUnoHelpFunctions::SetBoolInAny( aRet, pData->IsStripData() );
2149 else if ( aString.equalsAscii( SC_UNONAME_ISUSER ) )
2151 // all database ranges except "unnamed" are user defined
2152 ScUnoHelpFunctions::SetBoolInAny(
2153 aRet, !pData->GetName().equalsAscii(STR_DB_LOCAL_NONAME));
2155 else if ( aString.equalsAscii( SC_UNO_LINKDISPBIT ) )
2157 // no target bitmaps for individual entries (would be all equal)
2158 // ScLinkTargetTypeObj::SetLinkTargetBitmap( aRet, SC_LINKTARGETTYPE_DBAREA );
2160 else if ( aString.equalsAscii( SC_UNO_LINKDISPNAME ) )
2161 aRet <<= OUString( aName );
2162 else if (aString.equalsAscii( SC_UNONAME_AUTOFLT ))
2164 sal_Bool bAutoFilter(GetDBData_Impl()->HasAutoFilter());
2166 ScUnoHelpFunctions::SetBoolInAny( aRet, bAutoFilter );
2168 else if (aString.equalsAscii( SC_UNONAME_USEFLTCRT ))
2170 ScRange aRange;
2171 sal_Bool bIsAdvancedSource(GetDBData_Impl()->GetAdvancedQuerySource(aRange));
2173 ScUnoHelpFunctions::SetBoolInAny( aRet, bIsAdvancedSource );
2175 else if (aString.equalsAscii( SC_UNONAME_FLTCRT ))
2177 table::CellRangeAddress aRange;
2178 ScRange aCoreRange;
2179 if (GetDBData_Impl()->GetAdvancedQuerySource(aCoreRange))
2180 ScUnoConversion::FillApiRange(aRange, aCoreRange);
2182 aRet <<= aRange;
2184 else if (aString.equalsAscii( SC_UNONAME_FROMSELECT ))
2186 ScUnoHelpFunctions::SetBoolInAny( aRet, GetDBData_Impl()->HasImportSelection() );
2188 else if (aString.equalsAscii( SC_UNONAME_REFPERIOD ))
2190 sal_Int32 nRefresh(GetDBData_Impl()->GetRefreshDelay());
2191 aRet <<= nRefresh;
2193 else if (aString.equalsAscii( SC_UNONAME_CONRES ))
2196 else if (aString.equalsAscii( SC_UNONAME_TOKENINDEX ))
2198 // get index for use in formula tokens (read-only)
2199 aRet <<= static_cast<sal_Int32>(GetDBData_Impl()->GetIndex());
2202 return aRet;
2205 SC_IMPL_DUMMY_PROPERTY_LISTENER( ScDatabaseRangeObj )
2207 // XServiceInfo
2209 OUString SAL_CALL ScDatabaseRangeObj::getImplementationName() throw(uno::RuntimeException)
2211 return OUString( "ScDatabaseRangeObj" );
2214 sal_Bool SAL_CALL ScDatabaseRangeObj::supportsService( const OUString& rServiceName )
2215 throw(uno::RuntimeException)
2217 return rServiceName.equalsAscii( SCDATABASERANGEOBJ_SERVICE ) ||
2218 rServiceName.equalsAscii( SCLINKTARGET_SERVICE );
2221 uno::Sequence<OUString> SAL_CALL ScDatabaseRangeObj::getSupportedServiceNames()
2222 throw(uno::RuntimeException)
2224 uno::Sequence<OUString> aRet(2);
2225 OUString* pArray = aRet.getArray();
2226 pArray[0] = OUString( SCDATABASERANGEOBJ_SERVICE );
2227 pArray[1] = OUString( SCLINKTARGET_SERVICE );
2228 return aRet;
2231 //------------------------------------------------------------------------
2233 ScDatabaseRangesObj::ScDatabaseRangesObj(ScDocShell* pDocSh) :
2234 pDocShell( pDocSh )
2236 pDocShell->GetDocument()->AddUnoObject(*this);
2239 ScDatabaseRangesObj::~ScDatabaseRangesObj()
2241 if (pDocShell)
2242 pDocShell->GetDocument()->RemoveUnoObject(*this);
2245 void ScDatabaseRangesObj::Notify( SfxBroadcaster&, const SfxHint& rHint )
2247 // Referenz-Update interessiert hier nicht
2249 if ( rHint.ISA( SfxSimpleHint ) &&
2250 ((const SfxSimpleHint&)rHint).GetId() == SFX_HINT_DYING )
2252 pDocShell = NULL; // ungueltig geworden
2256 // XDatabaseRanges
2258 ScDatabaseRangeObj* ScDatabaseRangesObj::GetObjectByIndex_Impl(size_t nIndex)
2260 if (!pDocShell)
2261 return NULL;
2263 ScDBCollection* pNames = pDocShell->GetDocument()->GetDBCollection();
2264 if (!pNames)
2265 return NULL;
2267 const ScDBCollection::NamedDBs& rDBs = pNames->getNamedDBs();
2268 if (rDBs.empty() || nIndex >= rDBs.size())
2269 return NULL;
2271 ScDBCollection::NamedDBs::const_iterator itr = rDBs.begin();
2272 ::std::advance(itr, nIndex); // boundary check is done above.
2273 return new ScDatabaseRangeObj(pDocShell, itr->GetName());
2276 ScDatabaseRangeObj* ScDatabaseRangesObj::GetObjectByName_Impl(const OUString& aName)
2278 if ( pDocShell && hasByName(aName) )
2280 OUString aString(aName);
2281 return new ScDatabaseRangeObj( pDocShell, aString );
2283 return NULL;
2287 void SAL_CALL ScDatabaseRangesObj::addNewByName( const OUString& aName,
2288 const table::CellRangeAddress& aRange )
2289 throw(uno::RuntimeException)
2291 SolarMutexGuard aGuard;
2292 sal_Bool bDone = false;
2293 if (pDocShell)
2295 ScDBDocFunc aFunc(*pDocShell);
2297 OUString aString(aName);
2298 ScRange aNameRange( (SCCOL)aRange.StartColumn, (SCROW)aRange.StartRow, aRange.Sheet,
2299 (SCCOL)aRange.EndColumn, (SCROW)aRange.EndRow, aRange.Sheet );
2300 bDone = aFunc.AddDBRange( aString, aNameRange, sal_True );
2302 if (!bDone)
2303 throw uno::RuntimeException(); // no other exceptions specified
2306 void SAL_CALL ScDatabaseRangesObj::removeByName( const OUString& aName )
2307 throw(uno::RuntimeException)
2309 SolarMutexGuard aGuard;
2310 sal_Bool bDone = false;
2311 if (pDocShell)
2313 ScDBDocFunc aFunc(*pDocShell);
2314 OUString aString(aName);
2315 bDone = aFunc.DeleteDBRange( aString );
2317 if (!bDone)
2318 throw uno::RuntimeException(); // no other exceptions specified
2321 // XEnumerationAccess
2323 uno::Reference<container::XEnumeration> SAL_CALL ScDatabaseRangesObj::createEnumeration()
2324 throw(uno::RuntimeException)
2326 SolarMutexGuard aGuard;
2327 return new ScIndexEnumeration(this, OUString("com.sun.star.sheet.DatabaseRangesEnumeration"));
2330 // XIndexAccess
2332 sal_Int32 SAL_CALL ScDatabaseRangesObj::getCount() throw(uno::RuntimeException)
2334 SolarMutexGuard aGuard;
2336 //! "unbenannt" weglassen ?
2338 if (pDocShell)
2340 ScDBCollection* pNames = pDocShell->GetDocument()->GetDBCollection();
2341 if (pNames)
2342 return static_cast<sal_Int32>(pNames->getNamedDBs().size());
2344 return 0;
2347 uno::Any SAL_CALL ScDatabaseRangesObj::getByIndex( sal_Int32 nIndex )
2348 throw(lang::IndexOutOfBoundsException,
2349 lang::WrappedTargetException, uno::RuntimeException)
2351 SolarMutexGuard aGuard;
2352 if (nIndex < 0)
2353 throw lang::IndexOutOfBoundsException();
2355 uno::Reference<sheet::XDatabaseRange> xRange(GetObjectByIndex_Impl(static_cast<size_t>(nIndex)));
2356 if (xRange.is())
2357 return uno::makeAny(xRange);
2358 else
2359 throw lang::IndexOutOfBoundsException();
2362 uno::Type SAL_CALL ScDatabaseRangesObj::getElementType() throw(uno::RuntimeException)
2364 SolarMutexGuard aGuard;
2365 return getCppuType((uno::Reference<sheet::XDatabaseRange>*)0);
2368 sal_Bool SAL_CALL ScDatabaseRangesObj::hasElements() throw(uno::RuntimeException)
2370 SolarMutexGuard aGuard;
2371 return ( getCount() != 0 );
2374 // XNameAccess
2376 uno::Any SAL_CALL ScDatabaseRangesObj::getByName( const OUString& aName )
2377 throw(container::NoSuchElementException,
2378 lang::WrappedTargetException, uno::RuntimeException)
2380 SolarMutexGuard aGuard;
2381 uno::Reference<sheet::XDatabaseRange> xRange(GetObjectByName_Impl(aName));
2382 if (xRange.is())
2383 return uno::makeAny(xRange);
2384 else
2385 throw container::NoSuchElementException();
2386 // return uno::Any();
2389 uno::Sequence<OUString> SAL_CALL ScDatabaseRangesObj::getElementNames()
2390 throw(uno::RuntimeException)
2392 SolarMutexGuard aGuard;
2394 //! "unbenannt" weglassen ?
2396 if (pDocShell)
2398 ScDBCollection* pNames = pDocShell->GetDocument()->GetDBCollection();
2399 if (pNames)
2401 const ScDBCollection::NamedDBs& rDBs = pNames->getNamedDBs();
2402 uno::Sequence<OUString> aSeq(rDBs.size());
2403 ScDBCollection::NamedDBs::const_iterator itr = rDBs.begin(), itrEnd = rDBs.end();
2404 for (size_t i = 0; itr != itrEnd; ++itr, ++i)
2405 aSeq[i] = itr->GetName();
2407 return aSeq;
2410 return uno::Sequence<OUString>(0);
2413 sal_Bool SAL_CALL ScDatabaseRangesObj::hasByName( const OUString& aName )
2414 throw(uno::RuntimeException)
2416 SolarMutexGuard aGuard;
2418 //! "unbenannt" weglassen ?
2420 if (pDocShell)
2422 ScDBCollection* pNames = pDocShell->GetDocument()->GetDBCollection();
2423 if (pNames)
2424 return pNames->getNamedDBs().findByUpperName(ScGlobal::pCharClass->uppercase(aName)) != NULL;
2426 return false;
2429 //------------------------------------------------------------------------
2431 ScUnnamedDatabaseRangesObj::ScUnnamedDatabaseRangesObj(ScDocShell* pDocSh) :
2432 pDocShell( pDocSh )
2434 pDocShell->GetDocument()->AddUnoObject(*this);
2437 ScUnnamedDatabaseRangesObj::~ScUnnamedDatabaseRangesObj()
2439 if (pDocShell)
2440 pDocShell->GetDocument()->RemoveUnoObject(*this);
2443 void ScUnnamedDatabaseRangesObj::Notify( SfxBroadcaster&, const SfxHint& rHint )
2445 // Referenz-Update interessiert hier nicht
2447 if ( rHint.ISA( SfxSimpleHint ) &&
2448 ((const SfxSimpleHint&)rHint).GetId() == SFX_HINT_DYING )
2450 pDocShell = NULL; // ungueltig geworden
2454 // XUnnamedDatabaseRanges
2456 void ScUnnamedDatabaseRangesObj::setByTable( const table::CellRangeAddress& aRange )
2457 throw( uno::RuntimeException,
2458 lang::IndexOutOfBoundsException )
2460 SolarMutexGuard aGuard;
2461 bool bDone = false;
2462 if (pDocShell)
2464 if ( pDocShell->GetDocument()->GetTableCount() <= aRange.Sheet )
2465 throw lang::IndexOutOfBoundsException();
2467 ScDBDocFunc aFunc(*pDocShell);
2468 OUString aString(STR_DB_LOCAL_NONAME);
2469 ScRange aUnnamedRange( (SCCOL)aRange.StartColumn, (SCROW)aRange.StartRow, aRange.Sheet,
2470 (SCCOL)aRange.EndColumn, (SCROW)aRange.EndRow, aRange.Sheet );
2471 bDone = aFunc.AddDBRange( aString, aUnnamedRange, sal_True );
2473 if (!bDone)
2474 throw uno::RuntimeException(); // no other exceptions specified
2477 uno::Any ScUnnamedDatabaseRangesObj::getByTable( sal_Int32 nTab )
2478 throw(uno::RuntimeException,
2479 lang::IndexOutOfBoundsException,
2480 container::NoSuchElementException)
2482 SolarMutexGuard aGuard;
2483 if (pDocShell)
2485 if ( pDocShell->GetDocument()->GetTableCount() <= nTab )
2486 throw lang::IndexOutOfBoundsException();
2487 uno::Reference<sheet::XDatabaseRange> xRange(
2488 new ScDatabaseRangeObj(pDocShell, static_cast<SCTAB>(nTab)));
2489 if (xRange.is())
2490 return uno::makeAny(xRange);
2491 else
2492 throw container::NoSuchElementException();
2494 else
2495 throw uno::RuntimeException();
2498 sal_Bool ScUnnamedDatabaseRangesObj::hasByTable( sal_Int32 nTab )
2499 throw (uno::RuntimeException,
2500 lang::IndexOutOfBoundsException)
2502 SolarMutexGuard aGuard;
2503 if (pDocShell)
2505 if (pDocShell->GetDocument()->GetTableCount() <= nTab)
2506 throw lang::IndexOutOfBoundsException();
2507 if (pDocShell->GetDocument()->GetAnonymousDBData((SCTAB) nTab))
2508 return true;
2509 return false;
2511 else
2512 return false;
2515 //------------------------------------------------------------------------
2518 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */