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