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

Generated by: LCOV version 1.10