LCOV - code coverage report
Current view: top level - sc/source/ui/unoobj - datauno.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 1144 1425 80.3 %
Date: 2015-06-13 12:38:46 Functions: 138 178 77.5 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.11