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