LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/sc/source/ui/unoobj - datauno.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 1118 1428 78.3 %
Date: 2013-07-09 Functions: 135 178 75.8 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10