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

Generated by: LCOV version 1.10