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