fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / sc / source / ui / unoobj / datauno.cxx
blobf5da6d170932c495c56f6f684c8c3bca7efc25b0
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"
54 #include <sortparam.hxx>
56 #include <comphelper/extract.hxx>
57 #include <comphelper/servicehelper.hxx>
58 #include <cppuhelper/supportsservice.hxx>
59 #include <svx/dataaccessdescriptor.hxx>
61 #include <limits>
62 #include <boost/scoped_array.hpp>
64 using namespace com::sun::star;
66 // alles ohne Which-ID, Map nur fuer PropertySetInfo
68 static const SfxItemPropertyMapEntry* lcl_GetSubTotalPropertyMap()
70 // some old property names are for 5.2 compatibility
72 static const SfxItemPropertyMapEntry aSubTotalPropertyMap_Impl[] =
74 {OUString(SC_UNONAME_BINDFMT), 0, cppu::UnoType<bool>::get(), 0, 0},
75 {OUString(SC_UNONAME_CASE), 0, cppu::UnoType<bool>::get(), 0, 0},
76 {OUString(SC_UNONAME_ENABSORT), 0, cppu::UnoType<bool>::get(), 0, 0},
77 {OUString(SC_UNONAME_ENUSLIST), 0, cppu::UnoType<bool>::get(), 0, 0},
78 {OUString(SC_UNONAME_FORMATS), 0, cppu::UnoType<bool>::get(), 0, 0},
79 {OUString(SC_UNONAME_INSBRK), 0, cppu::UnoType<bool>::get(), 0, 0},
80 {OUString(SC_UNONAME_ISCASE), 0, cppu::UnoType<bool>::get(), 0, 0},
81 {OUString(SC_UNONAME_MAXFLD), 0, cppu::UnoType<sal_Int32>::get(), beans::PropertyAttribute::READONLY, 0},
82 {OUString(SC_UNONAME_SORTASC), 0, cppu::UnoType<bool>::get(), 0, 0},
83 {OUString(SC_UNONAME_ULIST), 0, cppu::UnoType<bool>::get(), 0, 0},
84 {OUString(SC_UNONAME_UINDEX), 0, cppu::UnoType<sal_Int32>::get(), 0, 0},
85 {OUString(SC_UNONAME_USINDEX), 0, cppu::UnoType<sal_Int32>::get(), 0, 0},
86 { OUString(), 0, css::uno::Type(), 0, 0 }
88 return aSubTotalPropertyMap_Impl;
91 static const SfxItemPropertyMapEntry* lcl_GetFilterPropertyMap()
93 static const SfxItemPropertyMapEntry aFilterPropertyMap_Impl[] =
95 {OUString(SC_UNONAME_CONTHDR), 0, cppu::UnoType<bool>::get(), 0, 0},
96 {OUString(SC_UNONAME_COPYOUT), 0, cppu::UnoType<bool>::get(), 0, 0},
97 {OUString(SC_UNONAME_ISCASE), 0, cppu::UnoType<bool>::get(), 0, 0},
98 {OUString(SC_UNONAME_MAXFLD), 0, cppu::UnoType<sal_Int32>::get(), beans::PropertyAttribute::READONLY, 0},
99 {OUString(SC_UNONAME_ORIENT), 0, cppu::UnoType<table::TableOrientation>::get(), 0, 0},
100 {OUString(SC_UNONAME_OUTPOS), 0, cppu::UnoType<table::CellAddress>::get(), 0, 0},
101 {OUString(SC_UNONAME_SAVEOUT), 0, cppu::UnoType<bool>::get(), 0, 0},
102 {OUString(SC_UNONAME_SKIPDUP), 0, cppu::UnoType<bool>::get(), 0, 0},
103 {OUString(SC_UNONAME_USEREGEX), 0, cppu::UnoType<bool>::get(), 0, 0},
104 { OUString(), 0, css::uno::Type(), 0, 0 }
106 return aFilterPropertyMap_Impl;
109 static const SfxItemPropertyMapEntry* lcl_GetDBRangePropertyMap()
111 static const SfxItemPropertyMapEntry aDBRangePropertyMap_Impl[] =
113 {OUString(SC_UNONAME_AUTOFLT), 0, cppu::UnoType<bool>::get(), 0, 0},
114 {OUString(SC_UNONAME_FLTCRT), 0, cppu::UnoType<table::CellRangeAddress>::get(), 0, 0},
115 {OUString(SC_UNONAME_FROMSELECT),0, cppu::UnoType<bool>::get(), 0, 0},
116 {OUString(SC_UNONAME_ISUSER), 0, cppu::UnoType<bool>::get(), beans::PropertyAttribute::READONLY, 0 },
117 {OUString(SC_UNONAME_KEEPFORM), 0, cppu::UnoType<bool>::get(), 0, 0},
118 {OUString(SC_UNO_LINKDISPBIT), 0, cppu::UnoType<awt::XBitmap>::get(), beans::PropertyAttribute::READONLY, 0 },
119 {OUString(SC_UNO_LINKDISPNAME), 0, cppu::UnoType<OUString>::get(), beans::PropertyAttribute::READONLY, 0 },
120 {OUString(SC_UNONAME_MOVCELLS), 0, cppu::UnoType<bool>::get(), 0, 0},
121 {OUString(SC_UNONAME_REFPERIOD), 0, cppu::UnoType<sal_Int32>::get(), 0, 0},
122 {OUString(SC_UNONAME_STRIPDAT), 0, cppu::UnoType<bool>::get(), 0, 0},
123 {OUString(SC_UNONAME_TOKENINDEX),0, cppu::UnoType<sal_Int32>::get(), beans::PropertyAttribute::READONLY, 0 },
124 {OUString(SC_UNONAME_USEFLTCRT),0, cppu::UnoType<bool>::get(), 0, 0},
125 {OUString(SC_UNONAME_TOTALSROW),0, cppu::UnoType<bool>::get(), 0, 0},
126 {OUString(SC_UNONAME_CONTHDR) ,0, cppu::UnoType<bool>::get(), 0, 0},
127 { OUString(), 0, css::uno::Type(), 0, 0 }
129 return aDBRangePropertyMap_Impl;
132 SC_SIMPLE_SERVICE_INFO( ScConsolidationDescriptor, "ScConsolidationDescriptor", "com.sun.star.sheet.ConsolidationDescriptor" )
133 SC_SIMPLE_SERVICE_INFO( ScDatabaseRangesObj, "ScDatabaseRangesObj", "com.sun.star.sheet.DatabaseRanges" )
134 SC_SIMPLE_SERVICE_INFO( ScFilterDescriptorBase, "ScFilterDescriptorBase", "com.sun.star.sheet.SheetFilterDescriptor" )
135 SC_SIMPLE_SERVICE_INFO( ScSubTotalDescriptorBase, "ScSubTotalDescriptorBase", "com.sun.star.sheet.SubTotalDescriptor" )
136 SC_SIMPLE_SERVICE_INFO( ScSubTotalFieldObj, "ScSubTotalFieldObj", "com.sun.star.sheet.SubTotalField" )
138 sheet::GeneralFunction ScDataUnoConversion::SubTotalToGeneral( ScSubTotalFunc eSubTotal )
140 sheet::GeneralFunction eGeneral;
141 switch (eSubTotal)
143 case SUBTOTAL_FUNC_NONE: eGeneral = sheet::GeneralFunction_NONE; break;
144 case SUBTOTAL_FUNC_AVE: eGeneral = sheet::GeneralFunction_AVERAGE; break;
145 case SUBTOTAL_FUNC_CNT: eGeneral = sheet::GeneralFunction_COUNTNUMS; break;
146 case SUBTOTAL_FUNC_CNT2: eGeneral = sheet::GeneralFunction_COUNT; break;
147 case SUBTOTAL_FUNC_MAX: eGeneral = sheet::GeneralFunction_MAX; break;
148 case SUBTOTAL_FUNC_MIN: eGeneral = sheet::GeneralFunction_MIN; break;
149 case SUBTOTAL_FUNC_PROD: eGeneral = sheet::GeneralFunction_PRODUCT; break;
150 case SUBTOTAL_FUNC_STD: eGeneral = sheet::GeneralFunction_STDEV; break;
151 case SUBTOTAL_FUNC_STDP: eGeneral = sheet::GeneralFunction_STDEVP; break;
152 case SUBTOTAL_FUNC_SUM: eGeneral = sheet::GeneralFunction_SUM; break;
153 case SUBTOTAL_FUNC_VAR: eGeneral = sheet::GeneralFunction_VAR; break;
154 case SUBTOTAL_FUNC_VARP: eGeneral = sheet::GeneralFunction_VARP; break;
155 default:
156 OSL_FAIL("SubTotalToGeneral: falscher enum");
157 eGeneral = sheet::GeneralFunction_NONE;
158 break;
160 return eGeneral;
163 void ScImportDescriptor::FillProperties( uno::Sequence<beans::PropertyValue>& rSeq, const ScImportParam& rParam )
165 OSL_ENSURE( rSeq.getLength() == GetPropertyCount(), "falscher Count" );
167 beans::PropertyValue* pArray = rSeq.getArray();
169 sheet::DataImportMode eMode = sheet::DataImportMode_NONE;
170 if ( rParam.bImport )
172 if ( rParam.bSql )
173 eMode = sheet::DataImportMode_SQL;
174 else if ( rParam.nType == ScDbQuery )
175 eMode = sheet::DataImportMode_QUERY;
176 else
177 eMode = sheet::DataImportMode_TABLE; // Type ist immer ScDbQuery oder ScDbTable
180 svx::ODataAccessDescriptor aDescriptor;
181 aDescriptor.setDataSource(rParam.aDBName);
182 if (aDescriptor.has( svx::daDataSource ))
184 pArray[0].Name = SC_UNONAME_DBNAME;
185 pArray[0].Value <<= rParam.aDBName;
187 else if (aDescriptor.has( svx::daConnectionResource ))
189 pArray[0].Name = SC_UNONAME_CONRES;
190 pArray[0].Value <<= rParam.aDBName;
193 pArray[1].Name = SC_UNONAME_SRCTYPE;
194 pArray[1].Value <<= eMode;
196 pArray[2].Name = SC_UNONAME_SRCOBJ;
197 pArray[2].Value <<= rParam.aStatement;
199 pArray[3].Name = SC_UNONAME_ISNATIVE;
200 ScUnoHelpFunctions::SetBoolInAny( pArray[3].Value, rParam.bNative );
203 void ScImportDescriptor::FillImportParam( ScImportParam& rParam, const uno::Sequence<beans::PropertyValue>& rSeq )
205 OUString aStrVal;
206 const beans::PropertyValue* pPropArray = rSeq.getConstArray();
207 long nPropCount = rSeq.getLength();
208 for (long i = 0; i < nPropCount; i++)
210 const beans::PropertyValue& rProp = pPropArray[i];
211 OUString aPropName(rProp.Name);
213 if (aPropName == SC_UNONAME_ISNATIVE)
214 rParam.bNative = ScUnoHelpFunctions::GetBoolFromAny( rProp.Value );
215 else if (aPropName == SC_UNONAME_DBNAME)
217 if ( rProp.Value >>= aStrVal )
218 rParam.aDBName = aStrVal;
220 else if (aPropName == SC_UNONAME_CONRES)
222 if ( rProp.Value >>= aStrVal )
223 rParam.aDBName = aStrVal;
225 else if (aPropName == SC_UNONAME_SRCOBJ)
227 if ( rProp.Value >>= aStrVal )
228 rParam.aStatement = aStrVal;
230 else if (aPropName == SC_UNONAME_SRCTYPE)
232 //! test for correct enum type?
233 sheet::DataImportMode eMode = (sheet::DataImportMode)
234 ScUnoHelpFunctions::GetEnumFromAny( rProp.Value );
235 switch (eMode)
237 case sheet::DataImportMode_NONE:
238 rParam.bImport = false;
239 break;
240 case sheet::DataImportMode_SQL:
241 rParam.bImport = true;
242 rParam.bSql = true;
243 break;
244 case sheet::DataImportMode_TABLE:
245 rParam.bImport = true;
246 rParam.bSql = false;
247 rParam.nType = ScDbTable;
248 break;
249 case sheet::DataImportMode_QUERY:
250 rParam.bImport = true;
251 rParam.bSql = false;
252 rParam.nType = ScDbQuery;
253 break;
254 default:
255 OSL_FAIL("falscher Mode");
256 rParam.bImport = false;
262 void ScSortDescriptor::FillProperties( uno::Sequence<beans::PropertyValue>& rSeq, const ScSortParam& rParam )
264 OSL_ENSURE( rSeq.getLength() == GetPropertyCount(), "falscher Count" );
266 beans::PropertyValue* pArray = rSeq.getArray();
268 // Uno-Werte zusammensuchen
270 table::CellAddress aOutPos;
271 aOutPos.Sheet = rParam.nDestTab;
272 aOutPos.Column = rParam.nDestCol;
273 aOutPos.Row = rParam.nDestRow;
275 sal_uInt16 nSortCount = 0;
276 while ( nSortCount < rParam.GetSortKeyCount() && rParam.maKeyState[nSortCount].bDoSort )
277 ++nSortCount;
279 uno::Sequence<table::TableSortField> aFields(nSortCount);
280 if (nSortCount)
282 table::TableSortField* pFieldArray = aFields.getArray();
283 for (sal_uInt16 i=0; i<nSortCount; i++)
285 pFieldArray[i].Field = rParam.maKeyState[i].nField;
286 pFieldArray[i].IsAscending = rParam.maKeyState[i].bAscending;
287 pFieldArray[i].FieldType = table::TableSortFieldType_AUTOMATIC; // immer Automatic
288 pFieldArray[i].IsCaseSensitive = rParam.bCaseSens;
289 pFieldArray[i].CollatorLocale = rParam.aCollatorLocale;
290 pFieldArray[i].CollatorAlgorithm = rParam.aCollatorAlgorithm;
294 // Sequence fuellen
296 pArray[0].Name = SC_UNONAME_ISSORTCOLUMNS;
297 pArray[0].Value <<= !rParam.bByRow;
299 pArray[1].Name = SC_UNONAME_CONTHDR;
300 ScUnoHelpFunctions::SetBoolInAny( pArray[1].Value, rParam.bHasHeader );
302 pArray[2].Name = SC_UNONAME_MAXFLD;
303 pArray[2].Value <<= static_cast<sal_Int32>( rParam.GetSortKeyCount() );
305 pArray[3].Name = SC_UNONAME_SORTFLD;
306 pArray[3].Value <<= aFields;
308 pArray[4].Name = SC_UNONAME_BINDFMT;
309 ScUnoHelpFunctions::SetBoolInAny( pArray[4].Value, rParam.bIncludePattern );
311 pArray[5].Name = SC_UNONAME_COPYOUT;
312 ScUnoHelpFunctions::SetBoolInAny( pArray[5].Value, !rParam.bInplace );
314 pArray[6].Name = SC_UNONAME_OUTPOS;
315 pArray[6].Value <<= aOutPos;
317 pArray[7].Name = SC_UNONAME_ISULIST;
318 ScUnoHelpFunctions::SetBoolInAny( pArray[7].Value, rParam.bUserDef );
320 pArray[8].Name = SC_UNONAME_UINDEX;
321 pArray[8].Value <<= static_cast<sal_Int32>( rParam.nUserIndex );
324 void ScSortDescriptor::FillSortParam( ScSortParam& rParam, const uno::Sequence<beans::PropertyValue>& rSeq )
326 const beans::PropertyValue* pPropArray = rSeq.getConstArray();
327 long nPropCount = rSeq.getLength();
328 sal_Int16 nSortSize = rParam.GetSortKeyCount();
330 for (long nProp = 0; nProp < nPropCount; nProp++)
332 const beans::PropertyValue& rProp = pPropArray[nProp];
333 OUString aPropName(rProp.Name);
335 if (aPropName == SC_UNONAME_ORIENT)
337 //! test for correct enum type?
338 table::TableOrientation eOrient = (table::TableOrientation)
339 ScUnoHelpFunctions::GetEnumFromAny( rProp.Value );
340 rParam.bByRow = ( eOrient != table::TableOrientation_COLUMNS );
342 else if (aPropName == SC_UNONAME_ISSORTCOLUMNS)
344 rParam.bByRow = !::cppu::any2bool(rProp.Value);
346 else if (aPropName == SC_UNONAME_CONTHDR)
347 rParam.bHasHeader = ScUnoHelpFunctions::GetBoolFromAny( rProp.Value );
348 else if (aPropName == SC_UNONAME_MAXFLD)
350 sal_Int32 nVal;
351 if ( (rProp.Value >>= nVal) && nVal > nSortSize )
353 //! specify exceptions
354 //! throw lang::IllegalArgumentException();
357 else if (aPropName == SC_UNONAME_SORTFLD)
359 uno::Sequence<util::SortField> aSeq;
360 uno::Sequence<table::TableSortField> aNewSeq;
361 if ( rProp.Value >>= aSeq )
363 sal_Int32 nCount = aSeq.getLength();
364 sal_Int32 i;
365 if ( nCount > static_cast<sal_Int32>( rParam.GetSortKeyCount() ) )
367 nCount = nSortSize;
368 rParam.maKeyState.resize(nCount);
370 const util::SortField* pFieldArray = aSeq.getConstArray();
371 for (i=0; i<nCount; i++)
373 rParam.maKeyState[i].nField = static_cast<SCCOLROW>( pFieldArray[i].Field );
374 rParam.maKeyState[i].bAscending = pFieldArray[i].SortAscending;
376 // FieldType wird ignoriert
377 rParam.maKeyState[i].bDoSort = true;
379 for (i=nCount; i<nSortSize; i++)
380 rParam.maKeyState[i].bDoSort = false;
382 else if ( rProp.Value >>= aNewSeq )
384 sal_Int32 nCount = aNewSeq.getLength();
385 sal_Int32 i;
386 if ( nCount > nSortSize )
388 nCount = nSortSize;
389 rParam.maKeyState.resize(nCount);
391 const table::TableSortField* pFieldArray = aNewSeq.getConstArray();
392 for (i=0; i<nCount; i++)
394 rParam.maKeyState[i].nField = static_cast<SCCOLROW>( pFieldArray[i].Field );
395 rParam.maKeyState[i].bAscending = pFieldArray[i].IsAscending;
397 // only one is possible, sometime we should make it possible to have different for every entry
398 rParam.bCaseSens = pFieldArray[i].IsCaseSensitive;
399 rParam.aCollatorLocale = pFieldArray[i].CollatorLocale;
400 rParam.aCollatorAlgorithm = pFieldArray[i].CollatorAlgorithm;
402 // FieldType wird ignoriert
403 rParam.maKeyState[i].bDoSort = true;
405 for (i=nCount; i<nSortSize; i++)
406 rParam.maKeyState[i].bDoSort = false;
409 else if (aPropName == SC_UNONAME_ISCASE)
411 rParam.bCaseSens = ScUnoHelpFunctions::GetBoolFromAny( rProp.Value );
413 else if (aPropName == SC_UNONAME_BINDFMT)
414 rParam.bIncludePattern = ScUnoHelpFunctions::GetBoolFromAny( rProp.Value );
415 else if (aPropName == SC_UNONAME_COPYOUT)
416 rParam.bInplace = !ScUnoHelpFunctions::GetBoolFromAny( rProp.Value );
417 else if (aPropName == SC_UNONAME_OUTPOS)
419 table::CellAddress aAddress;
420 if ( rProp.Value >>= aAddress )
422 rParam.nDestTab = aAddress.Sheet;
423 rParam.nDestCol = (SCCOL)aAddress.Column;
424 rParam.nDestRow = (SCROW)aAddress.Row;
427 else if (aPropName == SC_UNONAME_ISULIST)
428 rParam.bUserDef = ScUnoHelpFunctions::GetBoolFromAny( rProp.Value );
429 else if (aPropName == SC_UNONAME_UINDEX)
431 sal_Int32 nVal = 0;
432 if ( rProp.Value >>= nVal )
433 rParam.nUserIndex = (sal_uInt16)nVal;
435 else if (aPropName == SC_UNONAME_COLLLOC)
437 rProp.Value >>= rParam.aCollatorLocale;
439 else if (aPropName == SC_UNONAME_COLLALG)
441 OUString sStr;
442 if ( rProp.Value >>= sStr )
443 rParam.aCollatorAlgorithm = sStr;
448 ScSubTotalFieldObj::ScSubTotalFieldObj( ScSubTotalDescriptorBase* pDesc, sal_uInt16 nP ) :
449 xRef( pDesc ), // Objekt festhalten
450 rParent( *pDesc ),
451 nPos( nP )
453 OSL_ENSURE(pDesc, "ScSubTotalFieldObj: Parent ist 0");
456 ScSubTotalFieldObj::~ScSubTotalFieldObj()
460 // XSubTotalField
462 sal_Int32 SAL_CALL ScSubTotalFieldObj::getGroupColumn() throw(uno::RuntimeException, std::exception)
464 SolarMutexGuard aGuard;
465 ScSubTotalParam aParam;
466 rParent.GetData(aParam);
468 return aParam.nField[nPos];
471 void SAL_CALL ScSubTotalFieldObj::setGroupColumn( sal_Int32 nGroupColumn ) throw(uno::RuntimeException, std::exception)
473 SolarMutexGuard aGuard;
474 ScSubTotalParam aParam;
475 rParent.GetData(aParam);
477 aParam.nField[nPos] = (SCCOL)nGroupColumn;
479 rParent.PutData(aParam);
482 uno::Sequence<sheet::SubTotalColumn> SAL_CALL ScSubTotalFieldObj::getSubTotalColumns()
483 throw(uno::RuntimeException, std::exception)
485 SolarMutexGuard aGuard;
486 ScSubTotalParam aParam;
487 rParent.GetData(aParam);
489 SCCOL nCount = aParam.nSubTotals[nPos];
490 uno::Sequence<sheet::SubTotalColumn> aSeq(nCount);
491 sheet::SubTotalColumn* pAry = aSeq.getArray();
492 for (SCCOL i=0; i<nCount; i++)
494 pAry[i].Column = aParam.pSubTotals[nPos][i];
495 pAry[i].Function = ScDataUnoConversion::SubTotalToGeneral(
496 aParam.pFunctions[nPos][i] );
498 return aSeq;
501 void SAL_CALL ScSubTotalFieldObj::setSubTotalColumns(
502 const uno::Sequence<sheet::SubTotalColumn>& aSubTotalColumns )
503 throw(uno::RuntimeException, std::exception)
505 SolarMutexGuard aGuard;
506 ScSubTotalParam aParam;
507 rParent.GetData(aParam);
509 sal_uInt32 nColCount = aSubTotalColumns.getLength();
510 if ( nColCount <= sal::static_int_cast<sal_uInt32>(SCCOL_MAX) )
512 SCCOL nCount = static_cast<SCCOL>(nColCount);
513 aParam.nSubTotals[nPos] = nCount;
514 if (nCount != 0)
516 aParam.pSubTotals[nPos] = new SCCOL[nCount];
517 aParam.pFunctions[nPos] = new ScSubTotalFunc[nCount];
519 const sheet::SubTotalColumn* pAry = aSubTotalColumns.getConstArray();
520 for (SCCOL i=0; i<nCount; i++)
522 aParam.pSubTotals[nPos][i] = static_cast<SCCOL>(pAry[i].Column);
523 aParam.pFunctions[nPos][i] = ScDPUtil::toSubTotalFunc(pAry[i].Function);
526 else
528 aParam.pSubTotals[nPos] = NULL;
529 aParam.pFunctions[nPos] = NULL;
532 //! sonst Exception oder so? (zuviele Spalten)
534 rParent.PutData(aParam);
537 ScSubTotalDescriptorBase::ScSubTotalDescriptorBase() :
538 aPropSet( lcl_GetSubTotalPropertyMap() )
542 ScSubTotalDescriptorBase::~ScSubTotalDescriptorBase()
546 // XSubTotalDesctiptor
548 ScSubTotalFieldObj* ScSubTotalDescriptorBase::GetObjectByIndex_Impl(sal_uInt16 nIndex)
550 if ( nIndex < getCount() )
551 return new ScSubTotalFieldObj( this, nIndex );
552 return NULL;
555 void SAL_CALL ScSubTotalDescriptorBase::clear() throw(uno::RuntimeException, std::exception)
557 SolarMutexGuard aGuard;
558 ScSubTotalParam aParam;
559 GetData(aParam);
561 for (sal_uInt16 i=0; i<MAXSUBTOTAL; i++)
562 aParam.bGroupActive[i] = false;
564 //! Notify oder so fuer die Field-Objekte???
566 PutData(aParam);
569 void SAL_CALL ScSubTotalDescriptorBase::addNew(
570 const uno::Sequence<sheet::SubTotalColumn>& aSubTotalColumns,
571 sal_Int32 nGroupColumn ) throw(uno::RuntimeException, std::exception)
573 SolarMutexGuard aGuard;
574 ScSubTotalParam aParam;
575 GetData(aParam);
577 sal_uInt16 nPos = 0;
578 while ( nPos < MAXSUBTOTAL && aParam.bGroupActive[nPos] )
579 ++nPos;
581 sal_uInt32 nColCount = aSubTotalColumns.getLength();
583 if ( nPos < MAXSUBTOTAL && nColCount <= sal::static_int_cast<sal_uInt32>(SCCOL_MAX) )
585 aParam.bGroupActive[nPos] = true;
586 aParam.nField[nPos] = static_cast<SCCOL>(nGroupColumn);
588 delete aParam.pSubTotals[nPos];
589 delete aParam.pFunctions[nPos];
591 SCCOL nCount = static_cast<SCCOL>(nColCount);
592 aParam.nSubTotals[nPos] = nCount;
593 if (nCount != 0)
595 aParam.pSubTotals[nPos] = new SCCOL[nCount];
596 aParam.pFunctions[nPos] = new ScSubTotalFunc[nCount];
598 const sheet::SubTotalColumn* pAry = aSubTotalColumns.getConstArray();
599 for (SCCOL i=0; i<nCount; i++)
601 aParam.pSubTotals[nPos][i] = static_cast<SCCOL>(pAry[i].Column);
602 aParam.pFunctions[nPos][i] = ScDPUtil::toSubTotalFunc(pAry[i].Function);
605 else
607 aParam.pSubTotals[nPos] = NULL;
608 aParam.pFunctions[nPos] = NULL;
611 else // too many fields / columns
612 throw uno::RuntimeException(); // no other exceptions specified
614 PutData(aParam);
617 // Flags/Einstellungen als Properties
619 // XEnumerationAccess
621 uno::Reference<container::XEnumeration> SAL_CALL ScSubTotalDescriptorBase::createEnumeration()
622 throw(uno::RuntimeException, std::exception)
624 SolarMutexGuard aGuard;
625 return new ScIndexEnumeration(this, OUString("com.sun.star.sheet.SubTotalFieldsEnumeration"));
628 // XIndexAccess
630 sal_Int32 SAL_CALL ScSubTotalDescriptorBase::getCount() throw(uno::RuntimeException, std::exception)
632 SolarMutexGuard aGuard;
633 ScSubTotalParam aParam;
634 GetData(aParam);
636 sal_uInt16 nCount = 0;
637 while ( nCount < MAXSUBTOTAL && aParam.bGroupActive[nCount] )
638 ++nCount;
639 return nCount;
642 uno::Any SAL_CALL ScSubTotalDescriptorBase::getByIndex( sal_Int32 nIndex )
643 throw(lang::IndexOutOfBoundsException,
644 lang::WrappedTargetException, uno::RuntimeException, std::exception)
646 SolarMutexGuard aGuard;
647 uno::Reference<sheet::XSubTotalField> xField(GetObjectByIndex_Impl((sal_uInt16)nIndex));
648 if (xField.is())
649 return uno::makeAny(xField);
650 else
651 throw lang::IndexOutOfBoundsException();
654 uno::Type SAL_CALL ScSubTotalDescriptorBase::getElementType() throw(uno::RuntimeException, std::exception)
656 SolarMutexGuard aGuard;
657 return cppu::UnoType<sheet::XSubTotalField>::get();
660 sal_Bool SAL_CALL ScSubTotalDescriptorBase::hasElements() throw(uno::RuntimeException, std::exception)
662 SolarMutexGuard aGuard;
663 return ( getCount() != 0 );
666 // XPropertySet
668 uno::Reference<beans::XPropertySetInfo> SAL_CALL ScSubTotalDescriptorBase::getPropertySetInfo()
669 throw(uno::RuntimeException, std::exception)
671 SolarMutexGuard aGuard;
672 static uno::Reference<beans::XPropertySetInfo> aRef(
673 new SfxItemPropertySetInfo( aPropSet.getPropertyMap() ));
674 return aRef;
677 void SAL_CALL ScSubTotalDescriptorBase::setPropertyValue(
678 const OUString& aPropertyName, const uno::Any& aValue )
679 throw(beans::UnknownPropertyException, beans::PropertyVetoException,
680 lang::IllegalArgumentException, lang::WrappedTargetException,
681 uno::RuntimeException, std::exception)
683 SolarMutexGuard aGuard;
684 ScSubTotalParam aParam;
685 GetData(aParam);
687 OUString aString(aPropertyName);
689 // some old property names are for 5.2 compatibility
691 if (aString == SC_UNONAME_CASE || aString == SC_UNONAME_ISCASE )
692 aParam.bCaseSens = ScUnoHelpFunctions::GetBoolFromAny( aValue );
693 else if (aString == SC_UNONAME_FORMATS || aString == SC_UNONAME_BINDFMT )
694 aParam.bIncludePattern = ScUnoHelpFunctions::GetBoolFromAny( aValue );
695 else if (aString == SC_UNONAME_ENABSORT )
696 aParam.bDoSort = ScUnoHelpFunctions::GetBoolFromAny( aValue );
697 else if (aString == SC_UNONAME_SORTASC )
698 aParam.bAscending = ScUnoHelpFunctions::GetBoolFromAny( aValue );
699 else if (aString == SC_UNONAME_INSBRK )
700 aParam.bPagebreak = ScUnoHelpFunctions::GetBoolFromAny( aValue );
701 else if (aString == SC_UNONAME_ULIST || aString == SC_UNONAME_ENUSLIST )
702 aParam.bUserDef = ScUnoHelpFunctions::GetBoolFromAny( aValue );
703 else if (aString == SC_UNONAME_UINDEX || aString == SC_UNONAME_USINDEX )
705 sal_Int32 nVal = 0;
706 if ( aValue >>= nVal )
707 aParam.nUserIndex = (sal_uInt16)nVal;
709 else if (aString == SC_UNONAME_MAXFLD )
711 sal_Int32 nVal = 0;
712 if ( (aValue >>= nVal) && nVal > sal::static_int_cast<sal_Int32>(MAXSUBTOTAL) )
714 throw lang::IllegalArgumentException();
718 PutData(aParam);
721 uno::Any SAL_CALL ScSubTotalDescriptorBase::getPropertyValue( const OUString& aPropertyName )
722 throw(beans::UnknownPropertyException, lang::WrappedTargetException,
723 uno::RuntimeException, std::exception)
725 SolarMutexGuard aGuard;
726 ScSubTotalParam aParam;
727 GetData(aParam);
729 OUString aString(aPropertyName);
730 uno::Any aRet;
732 // some old property names are for 5.2 compatibility
734 if (aString == SC_UNONAME_CASE || aString == SC_UNONAME_ISCASE )
735 ScUnoHelpFunctions::SetBoolInAny( aRet, aParam.bCaseSens );
736 else if (aString == SC_UNONAME_FORMATS || aString == SC_UNONAME_BINDFMT )
737 ScUnoHelpFunctions::SetBoolInAny( aRet, aParam.bIncludePattern );
738 else if (aString == SC_UNONAME_ENABSORT )
739 ScUnoHelpFunctions::SetBoolInAny( aRet, aParam.bDoSort );
740 else if (aString == SC_UNONAME_SORTASC )
741 ScUnoHelpFunctions::SetBoolInAny( aRet, aParam.bAscending );
742 else if (aString == SC_UNONAME_INSBRK )
743 ScUnoHelpFunctions::SetBoolInAny( aRet, aParam.bPagebreak );
744 else if (aString == SC_UNONAME_ULIST || aString == SC_UNONAME_ENUSLIST )
745 ScUnoHelpFunctions::SetBoolInAny( aRet, aParam.bUserDef );
746 else if (aString == SC_UNONAME_UINDEX || aString == SC_UNONAME_USINDEX )
747 aRet <<= (sal_Int32) aParam.nUserIndex;
748 else if (aString == SC_UNONAME_MAXFLD )
749 aRet <<= (sal_Int32) MAXSUBTOTAL;
751 return aRet;
754 SC_IMPL_DUMMY_PROPERTY_LISTENER( ScSubTotalDescriptorBase )
756 // XUnoTunnel
758 sal_Int64 SAL_CALL ScSubTotalDescriptorBase::getSomething(
759 const uno::Sequence<sal_Int8 >& rId ) throw(uno::RuntimeException, std::exception)
761 if ( rId.getLength() == 16 &&
762 0 == memcmp( getUnoTunnelId().getConstArray(),
763 rId.getConstArray(), 16 ) )
765 return sal::static_int_cast<sal_Int64>(reinterpret_cast<sal_IntPtr>(this));
767 return 0;
770 namespace
772 class theScSubTotalDescriptorBaseUnoTunnelId : public rtl::Static< UnoTunnelIdInit, theScSubTotalDescriptorBaseUnoTunnelId> {};
775 const uno::Sequence<sal_Int8>& ScSubTotalDescriptorBase::getUnoTunnelId()
777 return theScSubTotalDescriptorBaseUnoTunnelId::get().getSeq();
780 ScSubTotalDescriptorBase* ScSubTotalDescriptorBase::getImplementation(const uno::Reference<sheet::XSubTotalDescriptor>& rObj)
782 ScSubTotalDescriptorBase* pRet = NULL;
783 uno::Reference<lang::XUnoTunnel> xUT(rObj, uno::UNO_QUERY);
784 if (xUT.is())
785 pRet = reinterpret_cast<ScSubTotalDescriptorBase*>(sal::static_int_cast<sal_IntPtr>(xUT->getSomething(getUnoTunnelId())));
786 return pRet;
789 ScSubTotalDescriptor::ScSubTotalDescriptor()
793 ScSubTotalDescriptor::~ScSubTotalDescriptor()
797 void ScSubTotalDescriptor::GetData( ScSubTotalParam& rParam ) const
799 rParam = aStoredParam; // Abfrage fuer Interface
802 void ScSubTotalDescriptor::PutData( const ScSubTotalParam& rParam )
804 aStoredParam = rParam; // vom Interface gesetzt
807 void ScSubTotalDescriptor::SetParam( const ScSubTotalParam& rNew )
809 aStoredParam = rNew; // von aussen gesetzt
812 ScRangeSubTotalDescriptor::ScRangeSubTotalDescriptor(ScDatabaseRangeObj* pPar) :
813 pParent(pPar)
815 if (pParent)
816 pParent->acquire();
819 ScRangeSubTotalDescriptor::~ScRangeSubTotalDescriptor()
821 if (pParent)
822 pParent->release();
825 void ScRangeSubTotalDescriptor::GetData( ScSubTotalParam& rParam ) const
827 if (pParent)
828 pParent->GetSubTotalParam( rParam );
831 void ScRangeSubTotalDescriptor::PutData( const ScSubTotalParam& rParam )
833 if (pParent)
834 pParent->SetSubTotalParam( rParam );
837 ScConsolidationDescriptor::ScConsolidationDescriptor()
841 ScConsolidationDescriptor::~ScConsolidationDescriptor()
845 void ScConsolidationDescriptor::SetParam( const ScConsolidateParam& rNew )
847 aParam = rNew;
850 // XConsolidationDescriptor
852 sheet::GeneralFunction SAL_CALL ScConsolidationDescriptor::getFunction() throw(uno::RuntimeException, std::exception)
854 SolarMutexGuard aGuard;
855 return ScDataUnoConversion::SubTotalToGeneral(aParam.eFunction);
858 void SAL_CALL ScConsolidationDescriptor::setFunction( sheet::GeneralFunction nFunction )
859 throw(uno::RuntimeException, std::exception)
861 SolarMutexGuard aGuard;
862 aParam.eFunction = ScDPUtil::toSubTotalFunc(nFunction);
865 uno::Sequence<table::CellRangeAddress> SAL_CALL ScConsolidationDescriptor::getSources()
866 throw(uno::RuntimeException, std::exception)
868 SolarMutexGuard aGuard;
869 sal_uInt16 nCount = aParam.nDataAreaCount;
870 if (!aParam.ppDataAreas)
871 nCount = 0;
872 table::CellRangeAddress aRange;
873 uno::Sequence<table::CellRangeAddress> aSeq(nCount);
874 table::CellRangeAddress* pAry = aSeq.getArray();
875 for (sal_uInt16 i=0; i<nCount; i++)
877 ScArea* pArea = aParam.ppDataAreas[i];
878 if (pArea)
880 aRange.Sheet = pArea->nTab;
881 aRange.StartColumn = pArea->nColStart;
882 aRange.StartRow = pArea->nRowStart;
883 aRange.EndColumn = pArea->nColEnd;
884 aRange.EndRow = pArea->nRowEnd;
886 pAry[i] = aRange;
888 return aSeq;
891 void SAL_CALL ScConsolidationDescriptor::setSources(
892 const uno::Sequence<table::CellRangeAddress>& aSources )
893 throw(uno::RuntimeException, std::exception)
895 SolarMutexGuard aGuard;
896 sal_uInt16 nCount = (sal_uInt16)aSources.getLength();
897 if (nCount)
899 const table::CellRangeAddress* pAry = aSources.getConstArray();
900 boost::scoped_array<ScArea*> pNew(new ScArea*[nCount]);
901 sal_uInt16 i;
902 for (i=0; i<nCount; i++)
903 pNew[i] = new ScArea( pAry[i].Sheet,
904 static_cast<SCCOL>(pAry[i].StartColumn), pAry[i].StartRow,
905 static_cast<SCCOL>(pAry[i].EndColumn), pAry[i].EndRow );
907 aParam.SetAreas( pNew.get(), nCount ); // kopiert alles
909 for (i=0; i<nCount; i++)
910 delete pNew[i];
912 else
913 aParam.ClearDataAreas();
916 table::CellAddress SAL_CALL ScConsolidationDescriptor::getStartOutputPosition()
917 throw(uno::RuntimeException, std::exception)
919 SolarMutexGuard aGuard;
920 table::CellAddress aPos;
921 aPos.Column = aParam.nCol;
922 aPos.Row = aParam.nRow;
923 aPos.Sheet = aParam.nTab;
924 return aPos;
927 void SAL_CALL ScConsolidationDescriptor::setStartOutputPosition(
928 const table::CellAddress& aStartOutputPosition )
929 throw(uno::RuntimeException, std::exception)
931 SolarMutexGuard aGuard;
932 aParam.nCol = (SCCOL)aStartOutputPosition.Column;
933 aParam.nRow = (SCROW)aStartOutputPosition.Row;
934 aParam.nTab = aStartOutputPosition.Sheet;
937 sal_Bool SAL_CALL ScConsolidationDescriptor::getUseColumnHeaders() throw(uno::RuntimeException, std::exception)
939 SolarMutexGuard aGuard;
940 return aParam.bByCol;
943 void SAL_CALL ScConsolidationDescriptor::setUseColumnHeaders( sal_Bool bUseColumnHeaders )
944 throw(uno::RuntimeException, std::exception)
946 SolarMutexGuard aGuard;
947 aParam.bByCol = bUseColumnHeaders;
950 sal_Bool SAL_CALL ScConsolidationDescriptor::getUseRowHeaders() throw(uno::RuntimeException, std::exception)
952 SolarMutexGuard aGuard;
953 return aParam.bByRow;
956 void SAL_CALL ScConsolidationDescriptor::setUseRowHeaders( sal_Bool bUseRowHeaders )
957 throw(uno::RuntimeException, std::exception)
959 SolarMutexGuard aGuard;
960 aParam.bByRow = bUseRowHeaders;
963 sal_Bool SAL_CALL ScConsolidationDescriptor::getInsertLinks() throw(uno::RuntimeException, std::exception)
965 SolarMutexGuard aGuard;
966 return aParam.bReferenceData;
969 void SAL_CALL ScConsolidationDescriptor::setInsertLinks( sal_Bool bInsertLinks )
970 throw(uno::RuntimeException, std::exception)
972 SolarMutexGuard aGuard;
973 aParam.bReferenceData = bInsertLinks;
976 ScFilterDescriptorBase::ScFilterDescriptorBase(ScDocShell* pDocShell) :
977 aPropSet( lcl_GetFilterPropertyMap() ),
978 pDocSh(pDocShell)
980 if (pDocSh)
981 pDocSh->GetDocument().AddUnoObject(*this);
984 ScFilterDescriptorBase::~ScFilterDescriptorBase()
986 SolarMutexGuard g;
988 if (pDocSh)
989 pDocSh->GetDocument().RemoveUnoObject(*this);
992 void ScFilterDescriptorBase::Notify( SfxBroadcaster&, const SfxHint& rHint )
994 const SfxSimpleHint* pSimpleHint = dynamic_cast<const SfxSimpleHint*>(&rHint);
995 if ( pSimpleHint )
997 sal_uLong nId = pSimpleHint->GetId();
998 if ( nId == SFX_HINT_DYING )
1000 pDocSh = NULL; // invalid
1005 // XSheetFilterDescriptor and XSheetFilterDescriptor2
1007 uno::Sequence<sheet::TableFilterField> SAL_CALL ScFilterDescriptorBase::getFilterFields()
1008 throw(uno::RuntimeException, std::exception)
1010 SolarMutexGuard aGuard;
1011 ScQueryParam aParam;
1012 GetData(aParam);
1014 SCSIZE nEntries = aParam.GetEntryCount(); // allozierte Eintraege im Param
1015 SCSIZE nCount = 0; // aktive
1016 while ( nCount < nEntries &&
1017 aParam.GetEntry(nCount).bDoQuery )
1018 ++nCount;
1020 sheet::TableFilterField aField;
1021 uno::Sequence<sheet::TableFilterField> aSeq(static_cast<sal_Int32>(nCount));
1022 sheet::TableFilterField* pAry = aSeq.getArray();
1023 for (SCSIZE i=0; i<nCount; i++)
1025 const ScQueryEntry& rEntry = aParam.GetEntry(i);
1026 if (rEntry.GetQueryItems().empty())
1027 continue;
1029 const ScQueryEntry::Item& rItem = rEntry.GetQueryItems().front();
1031 aField.Connection = (rEntry.eConnect == SC_AND) ? sheet::FilterConnection_AND :
1032 sheet::FilterConnection_OR;
1033 aField.Field = rEntry.nField;
1034 aField.IsNumeric = rItem.meType != ScQueryEntry::ByString;
1035 aField.StringValue = rItem.maString.getString();
1036 aField.NumericValue = rItem.mfVal;
1038 switch (rEntry.eOp) // ScQueryOp
1040 case SC_EQUAL:
1042 aField.Operator = sheet::FilterOperator_EQUAL;
1043 if (rEntry.IsQueryByEmpty())
1045 aField.Operator = sheet::FilterOperator_EMPTY;
1046 aField.NumericValue = 0;
1048 else if (rEntry.IsQueryByNonEmpty())
1050 aField.Operator = sheet::FilterOperator_NOT_EMPTY;
1051 aField.NumericValue = 0;
1054 break;
1055 case SC_LESS: aField.Operator = sheet::FilterOperator_LESS; break;
1056 case SC_GREATER: aField.Operator = sheet::FilterOperator_GREATER; break;
1057 case SC_LESS_EQUAL: aField.Operator = sheet::FilterOperator_LESS_EQUAL; break;
1058 case SC_GREATER_EQUAL: aField.Operator = sheet::FilterOperator_GREATER_EQUAL; break;
1059 case SC_NOT_EQUAL: aField.Operator = sheet::FilterOperator_NOT_EQUAL; break;
1060 case SC_TOPVAL: aField.Operator = sheet::FilterOperator_TOP_VALUES; break;
1061 case SC_BOTVAL: aField.Operator = sheet::FilterOperator_BOTTOM_VALUES; break;
1062 case SC_TOPPERC: aField.Operator = sheet::FilterOperator_TOP_PERCENT; break;
1063 case SC_BOTPERC: aField.Operator = sheet::FilterOperator_BOTTOM_PERCENT; break;
1064 default:
1065 OSL_FAIL("Falscher Filter-enum");
1066 aField.Operator = sheet::FilterOperator_EMPTY;
1068 pAry[i] = aField;
1070 return aSeq;
1073 namespace {
1075 template<typename T>
1076 void convertQueryEntryToUno(const ScQueryEntry& rEntry, T& rField)
1078 rField.Connection = (rEntry.eConnect == SC_AND) ? sheet::FilterConnection_AND : sheet::FilterConnection_OR;
1079 rField.Field = rEntry.nField;
1081 switch (rEntry.eOp) // ScQueryOp
1083 case SC_EQUAL: rField.Operator = sheet::FilterOperator2::EQUAL; break;
1084 case SC_LESS: rField.Operator = sheet::FilterOperator2::LESS; break;
1085 case SC_GREATER: rField.Operator = sheet::FilterOperator2::GREATER; break;
1086 case SC_LESS_EQUAL: rField.Operator = sheet::FilterOperator2::LESS_EQUAL; break;
1087 case SC_GREATER_EQUAL: rField.Operator = sheet::FilterOperator2::GREATER_EQUAL; break;
1088 case SC_NOT_EQUAL: rField.Operator = sheet::FilterOperator2::NOT_EQUAL; break;
1089 case SC_TOPVAL: rField.Operator = sheet::FilterOperator2::TOP_VALUES; break;
1090 case SC_BOTVAL: rField.Operator = sheet::FilterOperator2::BOTTOM_VALUES; break;
1091 case SC_TOPPERC: rField.Operator = sheet::FilterOperator2::TOP_PERCENT; break;
1092 case SC_BOTPERC: rField.Operator = sheet::FilterOperator2::BOTTOM_PERCENT; break;
1093 case SC_CONTAINS: rField.Operator = sheet::FilterOperator2::CONTAINS; break;
1094 case SC_DOES_NOT_CONTAIN: rField.Operator = sheet::FilterOperator2::DOES_NOT_CONTAIN; break;
1095 case SC_BEGINS_WITH: rField.Operator = sheet::FilterOperator2::BEGINS_WITH; break;
1096 case SC_DOES_NOT_BEGIN_WITH: rField.Operator = sheet::FilterOperator2::DOES_NOT_BEGIN_WITH; break;
1097 case SC_ENDS_WITH: rField.Operator = sheet::FilterOperator2::ENDS_WITH; break;
1098 case SC_DOES_NOT_END_WITH: rField.Operator = sheet::FilterOperator2::DOES_NOT_END_WITH; break;
1099 default:
1100 OSL_FAIL("Unknown filter operator value.");
1101 rField.Operator = sheet::FilterOperator2::EMPTY;
1105 template<typename T>
1106 void convertUnoToQueryEntry(const T& rField, ScQueryEntry& rEntry)
1108 rEntry.bDoQuery = true;
1109 rEntry.eConnect = (rField.Connection == sheet::FilterConnection_AND) ? SC_AND : SC_OR;
1110 rEntry.nField = rField.Field;
1112 switch (rField.Operator) // FilterOperator
1114 case sheet::FilterOperator2::EQUAL: rEntry.eOp = SC_EQUAL; break;
1115 case sheet::FilterOperator2::LESS: rEntry.eOp = SC_LESS; break;
1116 case sheet::FilterOperator2::GREATER: rEntry.eOp = SC_GREATER; break;
1117 case sheet::FilterOperator2::LESS_EQUAL: rEntry.eOp = SC_LESS_EQUAL; break;
1118 case sheet::FilterOperator2::GREATER_EQUAL: rEntry.eOp = SC_GREATER_EQUAL; break;
1119 case sheet::FilterOperator2::NOT_EQUAL: rEntry.eOp = SC_NOT_EQUAL; break;
1120 case sheet::FilterOperator2::TOP_VALUES: rEntry.eOp = SC_TOPVAL; break;
1121 case sheet::FilterOperator2::BOTTOM_VALUES: rEntry.eOp = SC_BOTVAL; break;
1122 case sheet::FilterOperator2::TOP_PERCENT: rEntry.eOp = SC_TOPPERC; break;
1123 case sheet::FilterOperator2::BOTTOM_PERCENT: rEntry.eOp = SC_BOTPERC; break;
1124 case sheet::FilterOperator2::CONTAINS: rEntry.eOp = SC_CONTAINS; break;
1125 case sheet::FilterOperator2::DOES_NOT_CONTAIN: rEntry.eOp = SC_DOES_NOT_CONTAIN; break;
1126 case sheet::FilterOperator2::BEGINS_WITH: rEntry.eOp = SC_BEGINS_WITH; break;
1127 case sheet::FilterOperator2::DOES_NOT_BEGIN_WITH: rEntry.eOp = SC_DOES_NOT_BEGIN_WITH;break;
1128 case sheet::FilterOperator2::ENDS_WITH: rEntry.eOp = SC_ENDS_WITH; break;
1129 case sheet::FilterOperator2::DOES_NOT_END_WITH: rEntry.eOp = SC_DOES_NOT_END_WITH; break;
1130 case sheet::FilterOperator2::EMPTY:
1131 rEntry.SetQueryByEmpty();
1132 break;
1133 case sheet::FilterOperator2::NOT_EMPTY:
1134 rEntry.SetQueryByNonEmpty();
1135 break;
1136 default:
1137 OSL_FAIL("Unknown filter operator type.");
1138 rEntry.eOp = SC_EQUAL;
1142 void fillQueryParam(
1143 ScQueryParam& rParam, ScDocument* pDoc,
1144 const uno::Sequence<sheet::TableFilterField2>& aFilterFields)
1146 size_t nCount = static_cast<size_t>(aFilterFields.getLength());
1147 rParam.Resize(nCount);
1149 const sheet::TableFilterField2* pAry = aFilterFields.getConstArray();
1150 svl::SharedStringPool& rPool = pDoc->GetSharedStringPool();
1151 for (size_t i = 0; i < nCount; ++i)
1153 ScQueryEntry& rEntry = rParam.GetEntry(i);
1154 convertUnoToQueryEntry(pAry[i], rEntry);
1156 if (pAry[i].Operator != sheet::FilterOperator2::EMPTY && pAry[i].Operator != sheet::FilterOperator2::NOT_EMPTY)
1158 ScQueryEntry::QueryItemsType& rItems = rEntry.GetQueryItems();
1159 rItems.resize(1);
1160 ScQueryEntry::Item& rItem = rItems.front();
1161 rItem.meType = pAry[i].IsNumeric ? ScQueryEntry::ByValue : ScQueryEntry::ByString;
1162 rItem.mfVal = pAry[i].NumericValue;
1163 rItem.maString = rPool.intern(pAry[i].StringValue);
1165 if (rItem.meType == ScQueryEntry::ByValue)
1167 OUString aStr;
1168 pDoc->GetFormatTable()->GetInputLineString(rItem.mfVal, 0, aStr);
1169 rItem.maString = rPool.intern(aStr);
1174 size_t nParamCount = rParam.GetEntryCount(); // Param wird nicht unter 8 resized
1175 for (size_t i = nCount; i < nParamCount; ++i)
1176 rParam.GetEntry(i).bDoQuery = false; // ueberzaehlige Felder zuruecksetzen
1179 void fillQueryParam(
1180 ScQueryParam& rParam, ScDocument* pDoc,
1181 const uno::Sequence<sheet::TableFilterField3>& aFilterFields)
1183 size_t nCount = static_cast<size_t>(aFilterFields.getLength());
1184 rParam.Resize(nCount);
1186 svl::SharedStringPool& rPool = pDoc->GetSharedStringPool();
1187 const sheet::TableFilterField3* pAry = aFilterFields.getConstArray();
1188 for (size_t i = 0; i < nCount; ++i)
1190 ScQueryEntry& rEntry = rParam.GetEntry(i);
1191 convertUnoToQueryEntry(pAry[i], rEntry);
1193 if (pAry[i].Operator != sheet::FilterOperator2::EMPTY && pAry[i].Operator != sheet::FilterOperator2::NOT_EMPTY)
1195 ScQueryEntry::QueryItemsType& rItems = rEntry.GetQueryItems();
1196 rItems.clear();
1197 const uno::Sequence<sheet::FilterFieldValue>& rVals = pAry[i].Values;
1198 for (sal_Int32 j = 0, n = rVals.getLength(); j < n; ++j)
1200 ScQueryEntry::Item aItem;
1201 aItem.meType = rVals[j].IsNumeric ? ScQueryEntry::ByValue : ScQueryEntry::ByString;
1202 aItem.mfVal = rVals[j].NumericValue;
1203 aItem.maString = rPool.intern(rVals[j].StringValue);
1205 if (aItem.meType == ScQueryEntry::ByValue)
1207 OUString aStr;
1208 pDoc->GetFormatTable()->GetInputLineString(aItem.mfVal, 0, aStr);
1209 aItem.maString = rPool.intern(aStr);
1212 rItems.push_back(aItem);
1217 size_t nParamCount = rParam.GetEntryCount(); // Param wird nicht unter 8 resized
1218 for (size_t i = nCount; i < nParamCount; ++i)
1219 rParam.GetEntry(i).bDoQuery = false; // ueberzaehlige Felder zuruecksetzen
1224 uno::Sequence<sheet::TableFilterField2> SAL_CALL ScFilterDescriptorBase::getFilterFields2()
1225 throw(uno::RuntimeException, std::exception)
1227 SolarMutexGuard aGuard;
1228 ScQueryParam aParam;
1229 GetData(aParam);
1231 SCSIZE nEntries = aParam.GetEntryCount(); // allozierte Eintraege im Param
1232 SCSIZE nCount = 0; // aktive
1233 while ( nCount < nEntries &&
1234 aParam.GetEntry(nCount).bDoQuery )
1235 ++nCount;
1237 sheet::TableFilterField2 aField;
1238 uno::Sequence<sheet::TableFilterField2> aSeq(static_cast<sal_Int32>(nCount));
1239 sheet::TableFilterField2* pAry = aSeq.getArray();
1240 for (SCSIZE i=0; i<nCount; i++)
1242 const ScQueryEntry& rEntry = aParam.GetEntry(i);
1243 convertQueryEntryToUno(rEntry, aField);
1245 bool bByEmpty = false;
1246 if (aField.Operator == sheet::FilterOperator2::EQUAL)
1248 if (rEntry.IsQueryByEmpty())
1250 aField.Operator = sheet::FilterOperator2::EMPTY;
1251 aField.NumericValue = 0;
1252 bByEmpty = true;
1254 else if (rEntry.IsQueryByNonEmpty())
1256 aField.Operator = sheet::FilterOperator2::NOT_EMPTY;
1257 aField.NumericValue = 0;
1258 bByEmpty = true;
1262 if (!bByEmpty && !rEntry.GetQueryItems().empty())
1264 const ScQueryEntry::Item& rItem = rEntry.GetQueryItems().front();
1265 aField.IsNumeric = rItem.meType != ScQueryEntry::ByString;
1266 aField.StringValue = rItem.maString.getString();
1267 aField.NumericValue = rItem.mfVal;
1270 pAry[i] = aField;
1272 return aSeq;
1275 uno::Sequence<sheet::TableFilterField3> SAL_CALL ScFilterDescriptorBase::getFilterFields3()
1276 throw(uno::RuntimeException, std::exception)
1278 SolarMutexGuard aGuard;
1279 ScQueryParam aParam;
1280 GetData(aParam);
1282 SCSIZE nEntries = aParam.GetEntryCount(); // allozierte Eintraege im Param
1283 SCSIZE nCount = 0; // aktive
1284 while ( nCount < nEntries &&
1285 aParam.GetEntry(nCount).bDoQuery )
1286 ++nCount;
1288 sheet::TableFilterField3 aField;
1289 uno::Sequence<sheet::TableFilterField3> aSeq(static_cast<sal_Int32>(nCount));
1290 sheet::TableFilterField3* pAry = aSeq.getArray();
1291 for (SCSIZE i = 0; i < nCount; ++i)
1293 const ScQueryEntry& rEntry = aParam.GetEntry(i);
1294 convertQueryEntryToUno(rEntry, aField);
1296 bool bByEmpty = false;
1297 if (aField.Operator == sheet::FilterOperator2::EQUAL)
1299 if (rEntry.IsQueryByEmpty())
1301 aField.Operator = sheet::FilterOperator2::EMPTY;
1302 aField.Values.realloc(1);
1303 aField.Values[0].NumericValue = 0;
1304 bByEmpty = true;
1306 else if (rEntry.IsQueryByNonEmpty())
1308 aField.Operator = sheet::FilterOperator2::NOT_EMPTY;
1309 aField.Values.realloc(1);
1310 aField.Values[0].NumericValue = 0;
1311 bByEmpty = true;
1315 if (!bByEmpty)
1317 const ScQueryEntry::QueryItemsType& rItems = rEntry.GetQueryItems();
1318 size_t nItemCount = rItems.size();
1319 aField.Values.realloc(nItemCount);
1320 ScQueryEntry::QueryItemsType::const_iterator itr = rItems.begin(), itrEnd = rItems.end();
1321 for (size_t j = 0; itr != itrEnd; ++itr, ++j)
1323 aField.Values[j].IsNumeric = itr->meType != ScQueryEntry::ByString;
1324 aField.Values[j].StringValue = itr->maString.getString();
1325 aField.Values[j].NumericValue = itr->mfVal;
1330 pAry[i] = aField;
1332 return aSeq;
1335 void SAL_CALL ScFilterDescriptorBase::setFilterFields(
1336 const uno::Sequence<sheet::TableFilterField>& aFilterFields )
1337 throw(uno::RuntimeException, std::exception)
1339 SolarMutexGuard aGuard;
1340 ScQueryParam aParam;
1341 GetData(aParam);
1343 SCSIZE nCount = static_cast<SCSIZE>(aFilterFields.getLength());
1344 aParam.Resize( nCount );
1346 ScDocument& rDoc = pDocSh->GetDocument();
1347 svl::SharedStringPool& rPool = rDoc.GetSharedStringPool();
1348 const sheet::TableFilterField* pAry = aFilterFields.getConstArray();
1349 SCSIZE i;
1350 for (i=0; i<nCount; i++)
1352 ScQueryEntry& rEntry = aParam.GetEntry(i);
1353 ScQueryEntry::QueryItemsType& rItems = rEntry.GetQueryItems();
1354 rItems.resize(1);
1355 ScQueryEntry::Item& rItem = rItems.front();
1356 rEntry.bDoQuery = true;
1357 rEntry.eConnect = (pAry[i].Connection == sheet::FilterConnection_AND) ? SC_AND : SC_OR;
1358 rEntry.nField = pAry[i].Field;
1359 rItem.meType = pAry[i].IsNumeric ? ScQueryEntry::ByValue : ScQueryEntry::ByString;
1360 rItem.mfVal = pAry[i].NumericValue;
1361 rItem.maString = rPool.intern(pAry[i].StringValue);
1363 if (rItem.meType != ScQueryEntry::ByString)
1365 OUString aStr;
1366 rDoc.GetFormatTable()->GetInputLineString(rItem.mfVal, 0, aStr);
1367 rItem.maString = rPool.intern(aStr);
1370 switch (pAry[i].Operator) // FilterOperator
1372 case sheet::FilterOperator_EQUAL: rEntry.eOp = SC_EQUAL; break;
1373 case sheet::FilterOperator_LESS: rEntry.eOp = SC_LESS; break;
1374 case sheet::FilterOperator_GREATER: rEntry.eOp = SC_GREATER; break;
1375 case sheet::FilterOperator_LESS_EQUAL: rEntry.eOp = SC_LESS_EQUAL; break;
1376 case sheet::FilterOperator_GREATER_EQUAL: rEntry.eOp = SC_GREATER_EQUAL; break;
1377 case sheet::FilterOperator_NOT_EQUAL: rEntry.eOp = SC_NOT_EQUAL; break;
1378 case sheet::FilterOperator_TOP_VALUES: rEntry.eOp = SC_TOPVAL; break;
1379 case sheet::FilterOperator_BOTTOM_VALUES: rEntry.eOp = SC_BOTVAL; break;
1380 case sheet::FilterOperator_TOP_PERCENT: rEntry.eOp = SC_TOPPERC; break;
1381 case sheet::FilterOperator_BOTTOM_PERCENT: rEntry.eOp = SC_BOTPERC; break;
1382 case sheet::FilterOperator_EMPTY:
1383 rEntry.SetQueryByEmpty();
1384 break;
1385 case sheet::FilterOperator_NOT_EMPTY:
1386 rEntry.SetQueryByNonEmpty();
1387 break;
1388 default:
1389 OSL_FAIL("Falscher Query-enum");
1390 rEntry.eOp = SC_EQUAL;
1394 SCSIZE nParamCount = aParam.GetEntryCount(); // Param wird nicht unter 8 resized
1395 for (i=nCount; i<nParamCount; i++)
1396 aParam.GetEntry(i).bDoQuery = false; // ueberzaehlige Felder zuruecksetzen
1398 PutData(aParam);
1401 void SAL_CALL ScFilterDescriptorBase::setFilterFields2(
1402 const uno::Sequence<sheet::TableFilterField2>& aFilterFields )
1403 throw(uno::RuntimeException, std::exception)
1405 SolarMutexGuard aGuard;
1406 ScQueryParam aParam;
1407 GetData(aParam);
1408 fillQueryParam(aParam, &pDocSh->GetDocument(), aFilterFields);
1409 PutData(aParam);
1412 void SAL_CALL ScFilterDescriptorBase::setFilterFields3(
1413 const uno::Sequence<sheet::TableFilterField3>& aFilterFields )
1414 throw(uno::RuntimeException, std::exception)
1416 SolarMutexGuard aGuard;
1417 ScQueryParam aParam;
1418 GetData(aParam);
1419 fillQueryParam(aParam, &pDocSh->GetDocument(), aFilterFields);
1420 PutData(aParam);
1423 // Rest sind Properties
1425 // XPropertySet
1427 uno::Reference<beans::XPropertySetInfo> SAL_CALL ScFilterDescriptorBase::getPropertySetInfo()
1428 throw(uno::RuntimeException, std::exception)
1430 SolarMutexGuard aGuard;
1431 static uno::Reference<beans::XPropertySetInfo> aRef(
1432 new SfxItemPropertySetInfo( aPropSet.getPropertyMap() ));
1433 return aRef;
1436 void SAL_CALL ScFilterDescriptorBase::setPropertyValue(
1437 const OUString& aPropertyName, const uno::Any& aValue )
1438 throw(beans::UnknownPropertyException, beans::PropertyVetoException,
1439 lang::IllegalArgumentException, lang::WrappedTargetException,
1440 uno::RuntimeException, std::exception)
1442 SolarMutexGuard aGuard;
1443 ScQueryParam aParam;
1444 GetData(aParam);
1446 OUString aString(aPropertyName);
1447 if (aString == SC_UNONAME_CONTHDR)
1448 aParam.bHasHeader = ScUnoHelpFunctions::GetBoolFromAny( aValue );
1449 else if (aString == SC_UNONAME_COPYOUT)
1450 aParam.bInplace = !(ScUnoHelpFunctions::GetBoolFromAny( aValue ));
1451 else if (aString == SC_UNONAME_ISCASE)
1452 aParam.bCaseSens = ScUnoHelpFunctions::GetBoolFromAny( aValue );
1453 else if (aString == SC_UNONAME_MAXFLD)
1455 // silently ignored
1457 else if (aString == SC_UNONAME_ORIENT)
1459 //! test for correct enum type?
1460 table::TableOrientation eOrient = (table::TableOrientation)
1461 ScUnoHelpFunctions::GetEnumFromAny( aValue );
1462 aParam.bByRow = ( eOrient != table::TableOrientation_COLUMNS );
1464 else if (aString == SC_UNONAME_OUTPOS)
1466 table::CellAddress aAddress;
1467 if ( aValue >>= aAddress )
1469 aParam.nDestTab = aAddress.Sheet;
1470 aParam.nDestCol = (SCCOL)aAddress.Column;
1471 aParam.nDestRow = (SCROW)aAddress.Row;
1474 else if (aString == SC_UNONAME_SAVEOUT)
1475 aParam.bDestPers = ScUnoHelpFunctions::GetBoolFromAny( aValue );
1476 else if (aString == SC_UNONAME_SKIPDUP)
1477 aParam.bDuplicate = !(ScUnoHelpFunctions::GetBoolFromAny( aValue ));
1478 else if (aString == SC_UNONAME_USEREGEX)
1479 aParam.bRegExp = ScUnoHelpFunctions::GetBoolFromAny( aValue );
1481 PutData(aParam);
1484 uno::Any SAL_CALL ScFilterDescriptorBase::getPropertyValue( const OUString& aPropertyName )
1485 throw(beans::UnknownPropertyException, lang::WrappedTargetException,
1486 uno::RuntimeException, std::exception)
1488 SolarMutexGuard aGuard;
1489 ScQueryParam aParam;
1490 GetData(aParam);
1492 OUString aString(aPropertyName);
1493 uno::Any aRet;
1495 if (aString == SC_UNONAME_CONTHDR )
1496 ScUnoHelpFunctions::SetBoolInAny( aRet, aParam.bHasHeader );
1497 else if (aString == SC_UNONAME_COPYOUT )
1498 ScUnoHelpFunctions::SetBoolInAny( aRet, !(aParam.bInplace) );
1499 else if (aString == SC_UNONAME_ISCASE )
1500 ScUnoHelpFunctions::SetBoolInAny( aRet, aParam.bCaseSens );
1501 else if (aString == SC_UNONAME_MAXFLD )
1502 aRet <<= (sal_Int32) aParam.GetEntryCount();
1503 else if (aString == SC_UNONAME_ORIENT )
1505 table::TableOrientation eOrient = aParam.bByRow ? table::TableOrientation_ROWS :
1506 table::TableOrientation_COLUMNS;
1507 aRet <<= eOrient;
1509 else if (aString == SC_UNONAME_OUTPOS )
1511 table::CellAddress aOutPos;
1512 aOutPos.Sheet = aParam.nDestTab;
1513 aOutPos.Column = aParam.nDestCol;
1514 aOutPos.Row = aParam.nDestRow;
1515 aRet <<= aOutPos;
1517 else if (aString == SC_UNONAME_SAVEOUT )
1518 ScUnoHelpFunctions::SetBoolInAny( aRet, aParam.bDestPers );
1519 else if (aString == SC_UNONAME_SKIPDUP )
1520 ScUnoHelpFunctions::SetBoolInAny( aRet, !(aParam.bDuplicate) );
1521 else if (aString == SC_UNONAME_USEREGEX )
1522 ScUnoHelpFunctions::SetBoolInAny( aRet, aParam.bRegExp );
1524 return aRet;
1527 SC_IMPL_DUMMY_PROPERTY_LISTENER( ScFilterDescriptorBase )
1529 ScFilterDescriptor::ScFilterDescriptor(ScDocShell* pDocShell)
1531 ScFilterDescriptorBase(pDocShell)
1535 ScFilterDescriptor::~ScFilterDescriptor()
1539 void ScFilterDescriptor::GetData( ScQueryParam& rParam ) const
1541 rParam = aStoredParam; // Abfrage fuer Interface
1544 void ScFilterDescriptor::PutData( const ScQueryParam& rParam )
1546 aStoredParam = rParam; // vom Interface gesetzt
1549 void ScFilterDescriptor::SetParam( const ScQueryParam& rNew )
1551 aStoredParam = rNew; // von aussen gesetzt
1554 ScRangeFilterDescriptor::ScRangeFilterDescriptor(ScDocShell* pDocShell, ScDatabaseRangeObj* pPar) :
1555 ScFilterDescriptorBase(pDocShell),
1556 pParent(pPar)
1558 if (pParent)
1559 pParent->acquire();
1562 ScRangeFilterDescriptor::~ScRangeFilterDescriptor()
1564 if (pParent)
1565 pParent->release();
1568 void ScRangeFilterDescriptor::GetData( ScQueryParam& rParam ) const
1570 if (pParent)
1571 pParent->GetQueryParam( rParam );
1574 void ScRangeFilterDescriptor::PutData( const ScQueryParam& rParam )
1576 if (pParent)
1577 pParent->SetQueryParam( rParam );
1580 ScDataPilotFilterDescriptor::ScDataPilotFilterDescriptor(ScDocShell* pDocShell, ScDataPilotDescriptorBase* pPar) :
1581 ScFilterDescriptorBase(pDocShell),
1582 pParent(pPar)
1584 if (pParent)
1585 pParent->acquire();
1588 ScDataPilotFilterDescriptor::~ScDataPilotFilterDescriptor()
1590 if (pParent)
1591 pParent->release();
1594 void ScDataPilotFilterDescriptor::GetData( ScQueryParam& rParam ) const
1596 if (pParent)
1598 ScDPObject* pDPObj = pParent->GetDPObject();
1599 if (pDPObj && pDPObj->IsSheetData())
1600 rParam = pDPObj->GetSheetDesc()->GetQueryParam();
1604 void ScDataPilotFilterDescriptor::PutData( const ScQueryParam& rParam )
1606 if (pParent)
1608 ScDPObject* pDPObj = pParent->GetDPObject();
1609 if (pDPObj)
1611 ScSheetSourceDesc aSheetDesc(&pParent->GetDocShell()->GetDocument());
1612 if (pDPObj->IsSheetData())
1613 aSheetDesc = *pDPObj->GetSheetDesc();
1614 aSheetDesc.SetQueryParam(rParam);
1615 pDPObj->SetSheetDesc(aSheetDesc);
1616 pParent->SetDPObject(pDPObj);
1621 ScDatabaseRangeObj::ScDatabaseRangeObj(ScDocShell* pDocSh, const OUString& rNm) :
1622 pDocShell( pDocSh ),
1623 aName( rNm ),
1624 aPropSet( lcl_GetDBRangePropertyMap() ),
1625 bIsUnnamed(false),
1626 aTab( 0 )
1628 pDocShell->GetDocument().AddUnoObject(*this);
1631 ScDatabaseRangeObj::ScDatabaseRangeObj(ScDocShell* pDocSh, const SCTAB nTab) :
1632 pDocShell( pDocSh ),
1633 aName(STR_DB_LOCAL_NONAME),
1634 aPropSet( lcl_GetDBRangePropertyMap() ),
1635 bIsUnnamed(true),
1636 aTab( nTab )
1638 pDocShell->GetDocument().AddUnoObject(*this);
1641 ScDatabaseRangeObj::~ScDatabaseRangeObj()
1643 SolarMutexGuard g;
1645 if (pDocShell)
1646 pDocShell->GetDocument().RemoveUnoObject(*this);
1649 void ScDatabaseRangeObj::Notify( SfxBroadcaster&, const SfxHint& rHint )
1652 const SfxSimpleHint* pSimpleHint = dynamic_cast<const SfxSimpleHint*>(&rHint);
1653 if ( pSimpleHint && pSimpleHint->GetId() == SFX_HINT_DYING )
1654 pDocShell = NULL; // ungueltig geworden
1655 else if ( dynamic_cast<const ScDBRangeRefreshedHint*>(&rHint) )
1657 ScDBData* pDBData = GetDBData_Impl();
1658 const ScDBRangeRefreshedHint& rRef = static_cast<const ScDBRangeRefreshedHint&>(rHint);
1659 ScImportParam aParam;
1660 pDBData->GetImportParam(aParam);
1661 if (aParam == rRef.GetImportParam())
1662 Refreshed_Impl();
1666 // Hilfsfuntionen
1668 ScDBData* ScDatabaseRangeObj::GetDBData_Impl() const
1670 ScDBData* pRet = NULL;
1671 if (pDocShell)
1673 if (bIsUnnamed)
1675 pRet = pDocShell->GetDocument().GetAnonymousDBData(aTab);
1677 else
1679 ScDBCollection* pNames = pDocShell->GetDocument().GetDBCollection();
1680 if (pNames)
1682 ScDBData* p = pNames->getNamedDBs().findByUpperName(ScGlobal::pCharClass->uppercase(aName));
1683 if (p)
1684 pRet = p;
1688 return pRet;
1691 // XNamed
1693 OUString SAL_CALL ScDatabaseRangeObj::getName() throw(uno::RuntimeException, std::exception)
1695 SolarMutexGuard aGuard;
1696 return aName;
1699 void SAL_CALL ScDatabaseRangeObj::setName( const OUString& aNewName )
1700 throw(uno::RuntimeException, std::exception)
1702 SolarMutexGuard aGuard;
1703 if (pDocShell)
1705 ScDBDocFunc aFunc(*pDocShell);
1706 OUString aNewStr(aNewName);
1707 bool bOk = aFunc.RenameDBRange( aName, aNewStr );
1708 if (bOk)
1709 aName = aNewStr;
1713 // XDatabaseRange
1715 table::CellRangeAddress SAL_CALL ScDatabaseRangeObj::getDataArea() throw(uno::RuntimeException, std::exception)
1717 SolarMutexGuard aGuard;
1718 table::CellRangeAddress aAddress;
1719 ScDBData* pData = GetDBData_Impl();
1720 if (pData)
1722 ScRange aRange;
1723 pData->GetArea(aRange);
1724 aAddress.Sheet = aRange.aStart.Tab();
1725 aAddress.StartColumn = aRange.aStart.Col();
1726 aAddress.StartRow = aRange.aStart.Row();
1727 aAddress.EndColumn = aRange.aEnd.Col();
1728 aAddress.EndRow = aRange.aEnd.Row();
1730 return aAddress;
1733 void SAL_CALL ScDatabaseRangeObj::setDataArea( const table::CellRangeAddress& aDataArea )
1734 throw(uno::RuntimeException, std::exception)
1736 SolarMutexGuard aGuard;
1737 ScDBData* pData = GetDBData_Impl();
1738 if ( pDocShell && pData )
1740 ScDBData aNewData( *pData );
1741 //! MoveTo ???
1742 aNewData.SetArea( aDataArea.Sheet, (SCCOL)aDataArea.StartColumn, (SCROW)aDataArea.StartRow,
1743 (SCCOL)aDataArea.EndColumn, (SCROW)aDataArea.EndRow );
1744 ScDBDocFunc aFunc(*pDocShell);
1745 aFunc.ModifyDBData(aNewData);
1749 uno::Sequence<beans::PropertyValue> SAL_CALL ScDatabaseRangeObj::getSortDescriptor()
1750 throw(uno::RuntimeException, std::exception)
1752 SolarMutexGuard aGuard;
1753 ScSortParam aParam;
1754 const ScDBData* pData = GetDBData_Impl();
1755 if (pData)
1757 pData->GetSortParam(aParam);
1759 // im SortDescriptor sind die Fields innerhalb des Bereichs gezaehlt
1760 ScRange aDBRange;
1761 pData->GetArea(aDBRange);
1762 SCCOLROW nFieldStart = aParam.bByRow ? static_cast<SCCOLROW>(aDBRange.aStart.Col()) : static_cast<SCCOLROW>(aDBRange.aStart.Row());
1763 for (sal_uInt16 i=0; i<aParam.GetSortKeyCount(); i++)
1764 if ( aParam.maKeyState[i].bDoSort && aParam.maKeyState[i].nField >= nFieldStart )
1765 aParam.maKeyState[i].nField -= nFieldStart;
1768 uno::Sequence<beans::PropertyValue> aSeq( ScSortDescriptor::GetPropertyCount() );
1769 ScSortDescriptor::FillProperties( aSeq, aParam );
1770 return aSeq;
1773 void ScDatabaseRangeObj::GetQueryParam(ScQueryParam& rQueryParam) const
1775 const ScDBData* pData = GetDBData_Impl();
1776 if (pData)
1778 pData->GetQueryParam(rQueryParam);
1780 // im FilterDescriptor sind die Fields innerhalb des Bereichs gezaehlt
1781 ScRange aDBRange;
1782 pData->GetArea(aDBRange);
1783 SCCOLROW nFieldStart = rQueryParam.bByRow ? static_cast<SCCOLROW>(aDBRange.aStart.Col()) : static_cast<SCCOLROW>(aDBRange.aStart.Row());
1784 SCSIZE nCount = rQueryParam.GetEntryCount();
1785 for (SCSIZE i=0; i<nCount; i++)
1787 ScQueryEntry& rEntry = rQueryParam.GetEntry(i);
1788 if (rEntry.bDoQuery && rEntry.nField >= nFieldStart)
1789 rEntry.nField -= nFieldStart;
1794 void ScDatabaseRangeObj::SetQueryParam(const ScQueryParam& rQueryParam)
1796 const ScDBData* pData = GetDBData_Impl();
1797 if (pData)
1799 // im FilterDescriptor sind die Fields innerhalb des Bereichs gezaehlt
1800 ScQueryParam aParam(rQueryParam);
1801 ScRange aDBRange;
1802 pData->GetArea(aDBRange);
1803 SCCOLROW nFieldStart = aParam.bByRow ? static_cast<SCCOLROW>(aDBRange.aStart.Col()) : static_cast<SCCOLROW>(aDBRange.aStart.Row());
1805 SCSIZE nCount = aParam.GetEntryCount();
1806 for (SCSIZE i=0; i<nCount; i++)
1808 ScQueryEntry& rEntry = aParam.GetEntry(i);
1809 if (rEntry.bDoQuery)
1810 rEntry.nField += nFieldStart;
1813 ScDBData aNewData( *pData );
1814 aNewData.SetQueryParam(aParam);
1815 aNewData.SetHeader(aParam.bHasHeader); // not in ScDBData::SetQueryParam
1816 ScDBDocFunc aFunc(*pDocShell);
1817 aFunc.ModifyDBData(aNewData);
1821 uno::Reference<sheet::XSheetFilterDescriptor> SAL_CALL ScDatabaseRangeObj::getFilterDescriptor()
1822 throw(uno::RuntimeException, std::exception)
1824 SolarMutexGuard aGuard;
1825 return new ScRangeFilterDescriptor(pDocShell, this);
1828 void ScDatabaseRangeObj::GetSubTotalParam(ScSubTotalParam& rSubTotalParam) const
1830 const ScDBData* pData = GetDBData_Impl();
1831 if (pData)
1833 pData->GetSubTotalParam(rSubTotalParam);
1835 // im FilterDescriptor sind die Fields innerhalb des Bereichs gezaehlt
1836 ScRange aDBRange;
1837 pData->GetArea(aDBRange);
1838 SCCOL nFieldStart = aDBRange.aStart.Col();
1839 for (sal_uInt16 i=0; i<MAXSUBTOTAL; i++)
1841 if ( rSubTotalParam.bGroupActive[i] )
1843 if ( rSubTotalParam.nField[i] >= nFieldStart )
1844 rSubTotalParam.nField[i] = sal::static_int_cast<SCCOL>( rSubTotalParam.nField[i] - nFieldStart );
1845 for (SCCOL j=0; j<rSubTotalParam.nSubTotals[i]; j++)
1846 if ( rSubTotalParam.pSubTotals[i][j] >= nFieldStart )
1847 rSubTotalParam.pSubTotals[i][j] =
1848 sal::static_int_cast<SCCOL>( rSubTotalParam.pSubTotals[i][j] - nFieldStart );
1854 void ScDatabaseRangeObj::SetSubTotalParam(const ScSubTotalParam& rSubTotalParam)
1856 const ScDBData* pData = GetDBData_Impl();
1857 if (pData)
1859 // im FilterDescriptor sind die Fields innerhalb des Bereichs gezaehlt
1860 ScSubTotalParam aParam(rSubTotalParam);
1861 ScRange aDBRange;
1862 pData->GetArea(aDBRange);
1863 SCCOL nFieldStart = aDBRange.aStart.Col();
1864 for (sal_uInt16 i=0; i<MAXSUBTOTAL; i++)
1866 if ( aParam.bGroupActive[i] )
1868 aParam.nField[i] = sal::static_int_cast<SCCOL>( aParam.nField[i] + nFieldStart );
1869 for (SCCOL j=0; j<aParam.nSubTotals[i]; j++)
1870 aParam.pSubTotals[i][j] = sal::static_int_cast<SCCOL>( aParam.pSubTotals[i][j] + nFieldStart );
1874 ScDBData aNewData( *pData );
1875 aNewData.SetSubTotalParam(aParam);
1876 ScDBDocFunc aFunc(*pDocShell);
1877 aFunc.ModifyDBData(aNewData);
1881 uno::Reference<sheet::XSubTotalDescriptor> SAL_CALL ScDatabaseRangeObj::getSubTotalDescriptor()
1882 throw(uno::RuntimeException, std::exception)
1884 SolarMutexGuard aGuard;
1885 return new ScRangeSubTotalDescriptor(this);
1888 uno::Sequence<beans::PropertyValue> SAL_CALL ScDatabaseRangeObj::getImportDescriptor()
1889 throw(uno::RuntimeException, std::exception)
1891 SolarMutexGuard aGuard;
1892 ScImportParam aParam;
1893 const ScDBData* pData = GetDBData_Impl();
1894 if (pData)
1895 pData->GetImportParam(aParam);
1897 uno::Sequence<beans::PropertyValue> aSeq( ScImportDescriptor::GetPropertyCount() );
1898 ScImportDescriptor::FillProperties( aSeq, aParam );
1899 return aSeq;
1902 // XRefreshable
1904 void SAL_CALL ScDatabaseRangeObj::refresh() throw(uno::RuntimeException, std::exception)
1906 SolarMutexGuard aGuard;
1907 ScDBData* pData = GetDBData_Impl();
1908 if ( pDocShell && pData )
1910 ScDBDocFunc aFunc(*pDocShell);
1912 // Import zu wiederholen?
1913 bool bContinue = true;
1914 ScImportParam aImportParam;
1915 pData->GetImportParam( aImportParam );
1916 if (aImportParam.bImport && !pData->HasImportSelection())
1918 SCTAB nTab;
1919 SCCOL nDummyCol;
1920 SCROW nDummyRow;
1921 pData->GetArea( nTab, nDummyCol,nDummyRow,nDummyCol,nDummyRow );
1922 bContinue = aFunc.DoImport( nTab, aImportParam, NULL, true ); //! Api-Flag as parameter
1925 // interne Operationen (sort, query, subtotal) nur, wenn kein Fehler
1926 if (bContinue)
1927 aFunc.RepeatDB( pData->GetName(), true, true, bIsUnnamed, aTab );
1931 void SAL_CALL ScDatabaseRangeObj::addRefreshListener(
1932 const uno::Reference<util::XRefreshListener >& xListener )
1933 throw(uno::RuntimeException, std::exception)
1935 SolarMutexGuard aGuard;
1936 uno::Reference<util::XRefreshListener>* pObj =
1937 new uno::Reference<util::XRefreshListener>( xListener );
1938 aRefreshListeners.push_back( pObj );
1940 // hold one additional ref to keep this object alive as long as there are listeners
1941 if ( aRefreshListeners.size() == 1 )
1942 acquire();
1945 void SAL_CALL ScDatabaseRangeObj::removeRefreshListener(
1946 const uno::Reference<util::XRefreshListener >& xListener )
1947 throw(uno::RuntimeException, std::exception)
1949 SolarMutexGuard aGuard;
1950 sal_uInt16 nCount = aRefreshListeners.size();
1951 for ( sal_uInt16 n=nCount; n--; )
1953 uno::Reference<util::XRefreshListener>& rObj = aRefreshListeners[n];
1954 if ( rObj == xListener )
1956 aRefreshListeners.erase( aRefreshListeners.begin() + n );
1957 if ( aRefreshListeners.empty() )
1958 release(); // release ref for listeners
1959 break;
1964 void ScDatabaseRangeObj::Refreshed_Impl()
1966 lang::EventObject aEvent;
1967 aEvent.Source = (cppu::OWeakObject*)this;
1968 for ( sal_uInt16 n=0; n<aRefreshListeners.size(); n++ )
1969 aRefreshListeners[n]->refreshed( aEvent );
1972 // XCellRangeSource
1974 uno::Reference<table::XCellRange> SAL_CALL ScDatabaseRangeObj::getReferredCells()
1975 throw(uno::RuntimeException, std::exception)
1977 SolarMutexGuard aGuard;
1978 ScRange aRange;
1979 ScDBData* pData = GetDBData_Impl();
1980 if ( pData )
1982 //! static Funktion um ScCellObj/ScCellRangeObj zu erzeugen am ScCellRangeObj ???
1984 pData->GetArea(aRange);
1985 if ( aRange.aStart == aRange.aEnd )
1986 return new ScCellObj( pDocShell, aRange.aStart );
1987 else
1988 return new ScCellRangeObj( pDocShell, aRange );
1990 return NULL;
1993 // XPropertySet
1995 uno::Reference<beans::XPropertySetInfo> SAL_CALL ScDatabaseRangeObj::getPropertySetInfo()
1996 throw(uno::RuntimeException, std::exception)
1998 SolarMutexGuard aGuard;
1999 static uno::Reference<beans::XPropertySetInfo> aRef(
2000 new SfxItemPropertySetInfo( aPropSet.getPropertyMap() ));
2001 return aRef;
2004 void SAL_CALL ScDatabaseRangeObj::setPropertyValue(
2005 const OUString& aPropertyName, const uno::Any& aValue )
2006 throw(beans::UnknownPropertyException, beans::PropertyVetoException,
2007 lang::IllegalArgumentException, lang::WrappedTargetException,
2008 uno::RuntimeException, std::exception)
2010 SolarMutexGuard aGuard;
2011 ScDBData* pData = GetDBData_Impl();
2012 if ( pDocShell && pData )
2014 ScDBData aNewData( *pData );
2015 bool bDo = true;
2017 OUString aString(aPropertyName);
2018 if ( aString == SC_UNONAME_KEEPFORM )
2019 aNewData.SetKeepFmt( ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
2020 else if ( aString == SC_UNONAME_MOVCELLS )
2021 aNewData.SetDoSize( ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
2022 else if ( aString == SC_UNONAME_STRIPDAT )
2023 aNewData.SetStripData( ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
2024 else if (aString == SC_UNONAME_AUTOFLT )
2026 bool bAutoFilter(ScUnoHelpFunctions::GetBoolFromAny( aValue ));
2027 aNewData.SetAutoFilter(bAutoFilter);
2028 ScRange aRange;
2029 aNewData.GetArea(aRange);
2030 ScDocument& rDoc = pDocShell->GetDocument();
2031 if (bAutoFilter)
2032 rDoc.ApplyFlagsTab( aRange.aStart.Col(), aRange.aStart.Row(),
2033 aRange.aEnd.Col(), aRange.aStart.Row(),
2034 aRange.aStart.Tab(), SC_MF_AUTO );
2035 else if (!bAutoFilter)
2036 rDoc.RemoveFlagsTab(aRange.aStart.Col(), aRange.aStart.Row(),
2037 aRange.aEnd.Col(), aRange.aStart.Row(),
2038 aRange.aStart.Tab(), SC_MF_AUTO );
2039 ScRange aPaintRange(aRange.aStart, aRange.aEnd);
2040 aPaintRange.aEnd.SetRow(aPaintRange.aStart.Row());
2041 pDocShell->PostPaint(aPaintRange, PAINT_GRID);
2043 else if (aString == SC_UNONAME_USEFLTCRT )
2045 if (ScUnoHelpFunctions::GetBoolFromAny( aValue ))
2047 // only here to set bIsAdvanced in ScDBData
2048 ScRange aRange;
2049 (void)aNewData.GetAdvancedQuerySource(aRange);
2050 aNewData.SetAdvancedQuerySource(&aRange);
2052 else
2053 aNewData.SetAdvancedQuerySource(NULL);
2055 else if (aString == SC_UNONAME_FLTCRT )
2057 table::CellRangeAddress aRange;
2058 if (aValue >>= aRange)
2060 ScRange aCoreRange;
2061 ScUnoConversion::FillScRange(aCoreRange, aRange);
2063 aNewData.SetAdvancedQuerySource(&aCoreRange);
2066 else if (aString == SC_UNONAME_FROMSELECT )
2068 aNewData.SetImportSelection(::cppu::any2bool(aValue));
2070 else if (aString == SC_UNONAME_REFPERIOD )
2072 sal_Int32 nRefresh = 0;
2073 if (aValue >>= nRefresh)
2075 ScDocument& rDoc = pDocShell->GetDocument();
2076 aNewData.SetRefreshDelay(nRefresh);
2077 if (rDoc.GetDBCollection())
2079 aNewData.SetRefreshHandler( rDoc.GetDBCollection()->GetRefreshHandler() );
2080 aNewData.SetRefreshControl( &rDoc.GetRefreshTimerControlAddress() );
2084 else if (aString == SC_UNONAME_CONRES )
2087 else if ( aString == SC_UNONAME_TOTALSROW )
2088 aNewData.SetTotals( ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
2089 else if ( aString == SC_UNONAME_CONTHDR )
2090 aNewData.SetHeader( ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
2091 else
2092 bDo = false;
2094 if (bDo)
2096 ScDBDocFunc aFunc(*pDocShell);
2097 aFunc.ModifyDBData(aNewData);
2102 uno::Any SAL_CALL ScDatabaseRangeObj::getPropertyValue( const OUString& aPropertyName )
2103 throw(beans::UnknownPropertyException, lang::WrappedTargetException,
2104 uno::RuntimeException, std::exception)
2106 SolarMutexGuard aGuard;
2107 uno::Any aRet;
2108 ScDBData* pData = GetDBData_Impl();
2109 if ( pData )
2111 OUString aString(aPropertyName);
2112 if ( aString == SC_UNONAME_KEEPFORM )
2113 ScUnoHelpFunctions::SetBoolInAny( aRet, pData->IsKeepFmt() );
2114 else if ( aString == SC_UNONAME_MOVCELLS )
2115 ScUnoHelpFunctions::SetBoolInAny( aRet, pData->IsDoSize() );
2116 else if ( aString == SC_UNONAME_STRIPDAT )
2117 ScUnoHelpFunctions::SetBoolInAny( aRet, pData->IsStripData() );
2118 else if ( aString == SC_UNONAME_ISUSER )
2120 // all database ranges except "unnamed" are user defined
2121 ScUnoHelpFunctions::SetBoolInAny(
2122 aRet, pData->GetName() != STR_DB_LOCAL_NONAME);
2124 else if ( aString == SC_UNO_LINKDISPBIT )
2126 // no target bitmaps for individual entries (would be all equal)
2127 // ScLinkTargetTypeObj::SetLinkTargetBitmap( aRet, SC_LINKTARGETTYPE_DBAREA );
2129 else if ( aString == SC_UNO_LINKDISPNAME )
2130 aRet <<= OUString( aName );
2131 else if (aString == SC_UNONAME_AUTOFLT )
2133 bool bAutoFilter(GetDBData_Impl()->HasAutoFilter());
2135 ScUnoHelpFunctions::SetBoolInAny( aRet, bAutoFilter );
2137 else if (aString == SC_UNONAME_USEFLTCRT )
2139 ScRange aRange;
2140 bool bIsAdvancedSource(GetDBData_Impl()->GetAdvancedQuerySource(aRange));
2142 ScUnoHelpFunctions::SetBoolInAny( aRet, bIsAdvancedSource );
2144 else if (aString == SC_UNONAME_FLTCRT )
2146 table::CellRangeAddress aRange;
2147 ScRange aCoreRange;
2148 if (GetDBData_Impl()->GetAdvancedQuerySource(aCoreRange))
2149 ScUnoConversion::FillApiRange(aRange, aCoreRange);
2151 aRet <<= aRange;
2153 else if (aString == SC_UNONAME_FROMSELECT )
2155 ScUnoHelpFunctions::SetBoolInAny( aRet, GetDBData_Impl()->HasImportSelection() );
2157 else if (aString == SC_UNONAME_REFPERIOD )
2159 sal_Int32 nRefresh(GetDBData_Impl()->GetRefreshDelay());
2160 aRet <<= nRefresh;
2162 else if (aString == SC_UNONAME_CONRES )
2165 else if (aString == SC_UNONAME_TOKENINDEX )
2167 // get index for use in formula tokens (read-only)
2168 aRet <<= static_cast<sal_Int32>(GetDBData_Impl()->GetIndex());
2170 else if (aString == SC_UNONAME_TOTALSROW )
2172 bool bTotals(GetDBData_Impl()->HasTotals());
2174 ScUnoHelpFunctions::SetBoolInAny( aRet, bTotals );
2176 else if (aString == SC_UNONAME_CONTHDR )
2178 bool bHeader(GetDBData_Impl()->HasHeader());
2180 ScUnoHelpFunctions::SetBoolInAny( aRet, bHeader );
2183 return aRet;
2186 SC_IMPL_DUMMY_PROPERTY_LISTENER( ScDatabaseRangeObj )
2188 // XServiceInfo
2189 OUString SAL_CALL ScDatabaseRangeObj::getImplementationName() throw(uno::RuntimeException, std::exception)
2191 return OUString( "ScDatabaseRangeObj" );
2194 sal_Bool SAL_CALL ScDatabaseRangeObj::supportsService( const OUString& rServiceName )
2195 throw(uno::RuntimeException, std::exception)
2197 return cppu::supportsService(this, rServiceName);
2200 uno::Sequence<OUString> SAL_CALL ScDatabaseRangeObj::getSupportedServiceNames()
2201 throw(uno::RuntimeException, std::exception)
2203 uno::Sequence<OUString> aRet(2);
2204 OUString* pArray = aRet.getArray();
2205 pArray[0] = "com.sun.star.sheet.DatabaseRange";
2206 pArray[1] = SCLINKTARGET_SERVICE;
2207 return aRet;
2210 ScDatabaseRangesObj::ScDatabaseRangesObj(ScDocShell* pDocSh) :
2211 pDocShell( pDocSh )
2213 pDocShell->GetDocument().AddUnoObject(*this);
2216 ScDatabaseRangesObj::~ScDatabaseRangesObj()
2218 SolarMutexGuard g;
2220 if (pDocShell)
2221 pDocShell->GetDocument().RemoveUnoObject(*this);
2224 void ScDatabaseRangesObj::Notify( SfxBroadcaster&, const SfxHint& rHint )
2226 // Referenz-Update interessiert hier nicht
2228 const SfxSimpleHint* pSimpleHint = dynamic_cast<const SfxSimpleHint*>(&rHint);
2229 if ( pSimpleHint && pSimpleHint->GetId() == SFX_HINT_DYING )
2231 pDocShell = NULL; // ungueltig geworden
2235 // XDatabaseRanges
2237 ScDatabaseRangeObj* ScDatabaseRangesObj::GetObjectByIndex_Impl(size_t nIndex)
2239 if (!pDocShell)
2240 return NULL;
2242 ScDBCollection* pNames = pDocShell->GetDocument().GetDBCollection();
2243 if (!pNames)
2244 return NULL;
2246 const ScDBCollection::NamedDBs& rDBs = pNames->getNamedDBs();
2247 if (rDBs.empty() || nIndex >= rDBs.size())
2248 return NULL;
2250 ScDBCollection::NamedDBs::const_iterator itr = rDBs.begin();
2251 ::std::advance(itr, nIndex); // boundary check is done above.
2252 return new ScDatabaseRangeObj(pDocShell, itr->GetName());
2255 ScDatabaseRangeObj* ScDatabaseRangesObj::GetObjectByName_Impl(const OUString& aName)
2257 if ( pDocShell && hasByName(aName) )
2259 OUString aString(aName);
2260 return new ScDatabaseRangeObj( pDocShell, aString );
2262 return NULL;
2265 void SAL_CALL ScDatabaseRangesObj::addNewByName( const OUString& aName,
2266 const table::CellRangeAddress& aRange )
2267 throw(uno::RuntimeException, std::exception)
2269 SolarMutexGuard aGuard;
2270 bool bDone = false;
2271 if (pDocShell)
2273 ScDBDocFunc aFunc(*pDocShell);
2275 OUString aString(aName);
2276 ScRange aNameRange( (SCCOL)aRange.StartColumn, (SCROW)aRange.StartRow, aRange.Sheet,
2277 (SCCOL)aRange.EndColumn, (SCROW)aRange.EndRow, aRange.Sheet );
2278 bDone = aFunc.AddDBRange( aString, aNameRange, true );
2280 if (!bDone)
2281 throw uno::RuntimeException(); // no other exceptions specified
2284 void SAL_CALL ScDatabaseRangesObj::removeByName( const OUString& aName )
2285 throw(uno::RuntimeException, std::exception)
2287 SolarMutexGuard aGuard;
2288 bool bDone = false;
2289 if (pDocShell)
2291 ScDBDocFunc aFunc(*pDocShell);
2292 OUString aString(aName);
2293 bDone = aFunc.DeleteDBRange( aString );
2295 if (!bDone)
2296 throw uno::RuntimeException(); // no other exceptions specified
2299 // XEnumerationAccess
2301 uno::Reference<container::XEnumeration> SAL_CALL ScDatabaseRangesObj::createEnumeration()
2302 throw(uno::RuntimeException, std::exception)
2304 SolarMutexGuard aGuard;
2305 return new ScIndexEnumeration(this, OUString("com.sun.star.sheet.DatabaseRangesEnumeration"));
2308 // XIndexAccess
2310 sal_Int32 SAL_CALL ScDatabaseRangesObj::getCount() throw(uno::RuntimeException, std::exception)
2312 SolarMutexGuard aGuard;
2314 //! "unbenannt" weglassen ?
2316 if (pDocShell)
2318 ScDBCollection* pNames = pDocShell->GetDocument().GetDBCollection();
2319 if (pNames)
2320 return static_cast<sal_Int32>(pNames->getNamedDBs().size());
2322 return 0;
2325 uno::Any SAL_CALL ScDatabaseRangesObj::getByIndex( sal_Int32 nIndex )
2326 throw(lang::IndexOutOfBoundsException,
2327 lang::WrappedTargetException, uno::RuntimeException, std::exception)
2329 SolarMutexGuard aGuard;
2330 if (nIndex < 0)
2331 throw lang::IndexOutOfBoundsException();
2333 uno::Reference<sheet::XDatabaseRange> xRange(GetObjectByIndex_Impl(static_cast<size_t>(nIndex)));
2334 if (xRange.is())
2335 return uno::makeAny(xRange);
2336 else
2337 throw lang::IndexOutOfBoundsException();
2340 uno::Type SAL_CALL ScDatabaseRangesObj::getElementType() throw(uno::RuntimeException, std::exception)
2342 SolarMutexGuard aGuard;
2343 return cppu::UnoType<sheet::XDatabaseRange>::get();
2346 sal_Bool SAL_CALL ScDatabaseRangesObj::hasElements() throw(uno::RuntimeException, std::exception)
2348 SolarMutexGuard aGuard;
2349 return ( getCount() != 0 );
2352 // XNameAccess
2354 uno::Any SAL_CALL ScDatabaseRangesObj::getByName( const OUString& aName )
2355 throw(container::NoSuchElementException,
2356 lang::WrappedTargetException, uno::RuntimeException, std::exception)
2358 SolarMutexGuard aGuard;
2359 uno::Reference<sheet::XDatabaseRange> xRange(GetObjectByName_Impl(aName));
2360 if (xRange.is())
2361 return uno::makeAny(xRange);
2362 else
2363 throw container::NoSuchElementException();
2364 // return uno::Any();
2367 uno::Sequence<OUString> SAL_CALL ScDatabaseRangesObj::getElementNames()
2368 throw(uno::RuntimeException, std::exception)
2370 SolarMutexGuard aGuard;
2372 //! "unbenannt" weglassen ?
2374 if (pDocShell)
2376 ScDBCollection* pNames = pDocShell->GetDocument().GetDBCollection();
2377 if (pNames)
2379 const ScDBCollection::NamedDBs& rDBs = pNames->getNamedDBs();
2380 uno::Sequence<OUString> aSeq(rDBs.size());
2381 ScDBCollection::NamedDBs::const_iterator itr = rDBs.begin(), itrEnd = rDBs.end();
2382 for (size_t i = 0; itr != itrEnd; ++itr, ++i)
2383 aSeq[i] = itr->GetName();
2385 return aSeq;
2388 return uno::Sequence<OUString>(0);
2391 sal_Bool SAL_CALL ScDatabaseRangesObj::hasByName( const OUString& aName )
2392 throw(uno::RuntimeException, std::exception)
2394 SolarMutexGuard aGuard;
2396 //! "unbenannt" weglassen ?
2398 if (pDocShell)
2400 ScDBCollection* pNames = pDocShell->GetDocument().GetDBCollection();
2401 if (pNames)
2402 return pNames->getNamedDBs().findByUpperName(ScGlobal::pCharClass->uppercase(aName)) != NULL;
2404 return false;
2407 ScUnnamedDatabaseRangesObj::ScUnnamedDatabaseRangesObj(ScDocShell* pDocSh) :
2408 pDocShell( pDocSh )
2410 pDocShell->GetDocument().AddUnoObject(*this);
2413 ScUnnamedDatabaseRangesObj::~ScUnnamedDatabaseRangesObj()
2415 SolarMutexGuard g;
2417 if (pDocShell)
2418 pDocShell->GetDocument().RemoveUnoObject(*this);
2421 void ScUnnamedDatabaseRangesObj::Notify( SfxBroadcaster&, const SfxHint& rHint )
2423 // Referenz-Update interessiert hier nicht
2425 const SfxSimpleHint* pSimpleHint = dynamic_cast<const SfxSimpleHint*>(&rHint);
2426 if ( pSimpleHint && pSimpleHint->GetId() == SFX_HINT_DYING )
2428 pDocShell = NULL; // ungueltig geworden
2432 // XUnnamedDatabaseRanges
2434 void ScUnnamedDatabaseRangesObj::setByTable( const table::CellRangeAddress& aRange )
2435 throw( uno::RuntimeException,
2436 lang::IndexOutOfBoundsException, std::exception )
2438 SolarMutexGuard aGuard;
2439 bool bDone = false;
2440 if (pDocShell)
2442 if ( pDocShell->GetDocument().GetTableCount() <= aRange.Sheet )
2443 throw lang::IndexOutOfBoundsException();
2445 ScDBDocFunc aFunc(*pDocShell);
2446 OUString aString(STR_DB_LOCAL_NONAME);
2447 ScRange aUnnamedRange( (SCCOL)aRange.StartColumn, (SCROW)aRange.StartRow, aRange.Sheet,
2448 (SCCOL)aRange.EndColumn, (SCROW)aRange.EndRow, aRange.Sheet );
2449 bDone = aFunc.AddDBRange( aString, aUnnamedRange, true );
2451 if (!bDone)
2452 throw uno::RuntimeException(); // no other exceptions specified
2455 uno::Any ScUnnamedDatabaseRangesObj::getByTable( sal_Int32 nTab )
2456 throw(uno::RuntimeException,
2457 lang::IndexOutOfBoundsException,
2458 container::NoSuchElementException, std::exception)
2460 SolarMutexGuard aGuard;
2461 if (pDocShell)
2463 if ( pDocShell->GetDocument().GetTableCount() <= nTab )
2464 throw lang::IndexOutOfBoundsException();
2465 uno::Reference<sheet::XDatabaseRange> xRange(
2466 new ScDatabaseRangeObj(pDocShell, static_cast<SCTAB>(nTab)));
2467 if (xRange.is())
2468 return uno::makeAny(xRange);
2469 else
2470 throw container::NoSuchElementException();
2472 else
2473 throw uno::RuntimeException();
2476 sal_Bool ScUnnamedDatabaseRangesObj::hasByTable( sal_Int32 nTab )
2477 throw (uno::RuntimeException,
2478 lang::IndexOutOfBoundsException, std::exception)
2480 SolarMutexGuard aGuard;
2481 if (pDocShell)
2483 if (pDocShell->GetDocument().GetTableCount() <= nTab)
2484 throw lang::IndexOutOfBoundsException();
2485 if (pDocShell->GetDocument().GetAnonymousDBData((SCTAB) nTab))
2486 return true;
2487 return false;
2489 else
2490 return false;
2493 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */