Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include <svl/smplhint.hxx>
30 : : #include <vcl/svapp.hxx>
31 : :
32 : : #include <com/sun/star/sheet/NamedRangeFlag.hpp>
33 : : #include <com/sun/star/awt/XBitmap.hpp>
34 : : #include <com/sun/star/beans/PropertyAttribute.hpp>
35 : :
36 : : #include <comphelper/servicehelper.hxx>
37 : :
38 : : using namespace ::com::sun::star;
39 : : using ::com::sun::star::uno::Reference;
40 : : using ::com::sun::star::uno::Any;
41 : :
42 : :
43 : : #include "nameuno.hxx"
44 : : #include "miscuno.hxx"
45 : : #include "cellsuno.hxx"
46 : : #include "convuno.hxx"
47 : : #include "targuno.hxx"
48 : : #include "tokenuno.hxx"
49 : : #include "tokenarray.hxx"
50 : : #include "docsh.hxx"
51 : : #include "docfunc.hxx"
52 : : #include "rangenam.hxx"
53 : : #include "unonames.hxx"
54 : :
55 : : #include "scui_def.hxx"
56 : :
57 : : //------------------------------------------------------------------------
58 : :
59 : 0 : const SfxItemPropertyMapEntry* lcl_GetNamedRangeMap()
60 : : {
61 : : static SfxItemPropertyMapEntry aNamedRangeMap_Impl[] =
62 : : {
63 [ # # ]: 0 : {MAP_CHAR_LEN(SC_UNO_LINKDISPBIT), 0, &getCppuType((uno::Reference<awt::XBitmap>*)0), beans::PropertyAttribute::READONLY, 0 },
64 [ # # ]: 0 : {MAP_CHAR_LEN(SC_UNO_LINKDISPNAME), 0, &getCppuType((rtl::OUString*)0), beans::PropertyAttribute::READONLY, 0 },
65 [ # # ]: 0 : {MAP_CHAR_LEN(SC_UNONAME_TOKENINDEX), 0, &getCppuType((sal_Int32*)0), beans::PropertyAttribute::READONLY, 0 },
66 [ # # ]: 0 : {MAP_CHAR_LEN(SC_UNONAME_ISSHAREDFMLA), 0, &getBooleanCppuType(), 0, 0 },
67 : : {0,0,0,0,0,0}
68 [ # # ][ # # ]: 0 : };
[ # # ]
69 : 0 : return aNamedRangeMap_Impl;
70 : : }
71 : :
72 : 0 : const SfxItemPropertyMapEntry* lcl_GetNamedRangesMap()
73 : : {
74 : : static SfxItemPropertyMapEntry aNamedRangesMap_Impl[] =
75 : : {
76 [ # # ]: 0 : {MAP_CHAR_LEN(SC_UNO_MODIFY_BROADCAST), 0, &getBooleanCppuType(), 0, 0 },
77 : : {0,0,0,0,0,0}
78 [ # # ][ # # ]: 0 : };
[ # # ]
79 : 0 : return aNamedRangesMap_Impl;
80 : : }
81 : :
82 : : //------------------------------------------------------------------------
83 : :
84 : : #define SCNAMEDRANGEOBJ_SERVICE "com.sun.star.sheet.NamedRange"
85 : :
86 [ # # ]: 0 : SC_SIMPLE_SERVICE_INFO( ScLabelRangeObj, "ScLabelRangeObj", "com.sun.star.sheet.LabelRange" )
87 [ # # ]: 0 : SC_SIMPLE_SERVICE_INFO( ScLabelRangesObj, "ScLabelRangesObj", "com.sun.star.sheet.LabelRanges" )
88 [ # # ]: 0 : SC_SIMPLE_SERVICE_INFO( ScNamedRangesObj, "ScNamedRangesObj", "com.sun.star.sheet.NamedRanges" )
89 : :
90 : 141 : bool lcl_UserVisibleName(const ScRangeData& rData)
91 : : {
92 : : //! als Methode an ScRangeData
93 : :
94 [ + - ][ + - ]: 141 : return !rData.HasType(RT_DATABASE) && !rData.HasType(RT_SHARED);
95 : : }
96 : :
97 : 44 : ScNamedRangeObj::ScNamedRangeObj( rtl::Reference< ScNamedRangesObj > xParent, ScDocShell* pDocSh, const String& rNm, Reference<container::XNamed> xSheet):
98 : : mxParent(xParent),
99 : : pDocShell( pDocSh ),
100 : : aName( rNm ),
101 [ + - ][ + - ]: 44 : mxSheet( xSheet )
102 : : {
103 [ + - ]: 44 : pDocShell->GetDocument()->AddUnoObject(*this);
104 : 44 : }
105 : :
106 [ + - ][ + - ]: 44 : ScNamedRangeObj::~ScNamedRangeObj()
107 : : {
108 [ + + ]: 44 : if (pDocShell)
109 [ + - ]: 38 : pDocShell->GetDocument()->RemoveUnoObject(*this);
110 [ - + ]: 88 : }
111 : :
112 : 28 : void ScNamedRangeObj::Notify( SfxBroadcaster&, const SfxHint& rHint )
113 : : {
114 : : // Ref-Update interessiert nicht
115 : :
116 [ + - ][ + + ]: 28 : if ( rHint.ISA( SfxSimpleHint ) && ((const SfxSimpleHint&)rHint).GetId() == SFX_HINT_DYING )
[ + + ]
117 : 6 : pDocShell = NULL; // ungueltig geworden
118 : 28 : }
119 : :
120 : : // Hilfsfuntionen
121 : :
122 : 46 : ScRangeData* ScNamedRangeObj::GetRangeData_Impl()
123 : : {
124 : 46 : ScRangeData* pRet = NULL;
125 [ + - ]: 46 : if (pDocShell)
126 : : {
127 : : ScRangeName* pNames;
128 : 46 : SCTAB nTab = GetTab_Impl();
129 [ - + ]: 46 : if (nTab >= 0)
130 : 0 : pNames = pDocShell->GetDocument()->GetRangeName(nTab);
131 : : else
132 : 46 : pNames = pDocShell->GetDocument()->GetRangeName();
133 [ + - ]: 46 : if (pNames)
134 : : {
135 [ + - ][ + - ]: 46 : pRet = pNames->findByUpperName(ScGlobal::pCharClass->uppercase(aName));
136 [ + - ]: 46 : if (pRet)
137 : 46 : pRet->ValidateTabRefs(); // adjust relative tab refs to valid tables
138 : : }
139 : : }
140 : 46 : return pRet;
141 : : }
142 : :
143 : 68 : SCTAB ScNamedRangeObj::GetTab_Impl()
144 : : {
145 [ - + ]: 68 : if (mxSheet.is())
146 : : {
147 [ # # ]: 0 : if (!pDocShell)
148 : 0 : return -2;
149 : 0 : ScDocument* pDoc = pDocShell->GetDocument();
150 : : SCTAB nTab;
151 [ # # ][ # # ]: 0 : rtl::OUString sName = mxSheet->getName();
152 [ # # ]: 0 : pDoc->GetTable(sName, nTab);
153 : 0 : return nTab;
154 : : }
155 : : else
156 : 68 : return -1;//global range name
157 : : }
158 : :
159 : : // sheet::XNamedRange
160 : :
161 : 22 : void ScNamedRangeObj::Modify_Impl( const String* pNewName, const ScTokenArray* pNewTokens, const String* pNewContent,
162 : : const ScAddress* pNewPos, const sal_uInt16* pNewType,
163 : : const formula::FormulaGrammar::Grammar eGrammar )
164 : : {
165 [ + - ]: 22 : if (!pDocShell)
166 : : return;
167 : :
168 : 22 : ScDocument* pDoc = pDocShell->GetDocument();
169 : : ScRangeName* pNames;
170 [ + - ]: 22 : SCTAB nTab = GetTab_Impl();
171 [ - + ]: 22 : if (nTab >= 0)
172 [ # # ]: 0 : pNames = pDoc->GetRangeName(nTab);
173 : : else
174 [ + - ]: 22 : pNames = pDoc->GetRangeName();
175 [ + - ]: 22 : if (!pNames)
176 : : return;
177 : :
178 [ + - ][ + - ]: 22 : const ScRangeData* pOld = pNames->findByUpperName(ScGlobal::pCharClass->uppercase(aName));
[ + - ]
179 [ + - ]: 22 : if (!pOld)
180 : : return;
181 : :
182 [ + - ][ + - ]: 22 : ScRangeName* pNewRanges = new ScRangeName(*pNames);
183 : :
184 [ + - ]: 22 : String aInsName = pOld->GetName();
185 [ + + ]: 22 : if (pNewName)
186 [ + - ]: 4 : aInsName = *pNewName;
187 : :
188 [ + - ]: 22 : String aContent; // Content string based =>
189 [ + - ]: 22 : pOld->GetSymbol( aContent, eGrammar); // no problems with changed positions and such.
190 [ + + ]: 22 : if (pNewContent)
191 [ + - ]: 6 : aContent = *pNewContent;
192 : :
193 : 22 : ScAddress aPos = pOld->GetPos();
194 [ + + ]: 22 : if (pNewPos)
195 : 2 : aPos = *pNewPos;
196 : :
197 : 22 : sal_uInt16 nType = pOld->GetType();
198 [ + + ]: 22 : if (pNewType)
199 : 10 : nType = *pNewType;
200 : :
201 : 22 : ScRangeData* pNew = NULL;
202 [ - + ]: 22 : if (pNewTokens)
203 [ # # ][ # # ]: 0 : pNew = new ScRangeData( pDoc, aInsName, *pNewTokens, aPos, nType );
[ # # ]
204 : : else
205 [ + - ][ + - ]: 22 : pNew = new ScRangeData( pDoc, aInsName, aContent, aPos, nType, eGrammar );
[ + - ]
206 : :
207 : 22 : pNew->SetIndex( pOld->GetIndex() );
208 : :
209 [ + - ]: 22 : pNewRanges->erase(*pOld);
210 [ + - ][ + - ]: 22 : if (pNewRanges->insert(pNew))
211 : : {
212 [ + - ]: 22 : pDocShell->GetDocFunc().SetNewRangeNames(pNewRanges, mxParent->IsModifyAndBroadcast(), nTab);
213 : :
214 [ + - ]: 22 : aName = aInsName; //! broadcast?
215 : : }
216 : : else
217 : : {
218 : 0 : pNew = NULL; //! uno::Exception/Fehler oder so
219 [ # # ][ # # ]: 0 : delete pNewRanges;
220 [ + - ][ + - ]: 22 : }
221 : : }
222 : :
223 : :
224 : 6 : rtl::OUString SAL_CALL ScNamedRangeObj::getName() throw(uno::RuntimeException)
225 : : {
226 [ + - ]: 6 : SolarMutexGuard aGuard;
227 [ + - ][ + - ]: 6 : return aName;
228 : : }
229 : :
230 : 4 : void SAL_CALL ScNamedRangeObj::setName( const rtl::OUString& aNewName )
231 : : throw(uno::RuntimeException)
232 : : {
233 [ + - ]: 4 : SolarMutexGuard aGuard;
234 : : //! Formeln anpassen ?????
235 : :
236 [ + - ]: 4 : String aNewStr(aNewName);
237 : : // GRAM_PODF_A1 for API compatibility.
238 [ + - ]: 4 : Modify_Impl( &aNewStr, NULL, NULL, NULL, NULL,formula::FormulaGrammar::GRAM_PODF_A1 );
239 : :
240 [ + - ][ - + ]: 4 : if ( aName != aNewStr ) // some error occurred...
241 [ # # ][ + - ]: 4 : throw uno::RuntimeException(); // no other exceptions specified
[ + - ]
242 : 4 : }
243 : :
244 : 16 : rtl::OUString SAL_CALL ScNamedRangeObj::getContent() throw(uno::RuntimeException)
245 : : {
246 [ + - ]: 16 : SolarMutexGuard aGuard;
247 [ + - ]: 16 : String aContent;
248 [ + - ]: 16 : ScRangeData* pData = GetRangeData_Impl();
249 [ + - ]: 16 : if (pData)
250 : : // GRAM_PODF_A1 for API compatibility.
251 [ + - ]: 16 : pData->GetSymbol( aContent,formula::FormulaGrammar::GRAM_PODF_A1);
252 [ + - ][ + - ]: 16 : return aContent;
[ + - ]
253 : : }
254 : :
255 : 6 : void SAL_CALL ScNamedRangeObj::setContent( const rtl::OUString& aContent )
256 : : throw(uno::RuntimeException)
257 : : {
258 [ + - ]: 6 : SolarMutexGuard aGuard;
259 [ + - ]: 6 : String aContStr(aContent);
260 : : // GRAM_PODF_A1 for API compatibility.
261 [ + - ][ + - ]: 6 : Modify_Impl( NULL, NULL, &aContStr, NULL, NULL,formula::FormulaGrammar::GRAM_PODF_A1 );
[ + - ]
262 : 6 : }
263 : :
264 : 4 : table::CellAddress SAL_CALL ScNamedRangeObj::getReferencePosition()
265 : : throw(uno::RuntimeException)
266 : : {
267 [ + - ]: 4 : SolarMutexGuard aGuard;
268 : 4 : ScAddress aPos;
269 [ + - ]: 4 : ScRangeData* pData = GetRangeData_Impl();
270 [ + - ]: 4 : if (pData)
271 : 4 : aPos = pData->GetPos();
272 : 4 : table::CellAddress aAddress;
273 : 4 : aAddress.Column = aPos.Col();
274 : 4 : aAddress.Row = aPos.Row();
275 : 4 : aAddress.Sheet = aPos.Tab();
276 [ + - ]: 4 : if (pDocShell)
277 : : {
278 [ + - ]: 4 : SCTAB nDocTabs = pDocShell->GetDocument()->GetTableCount();
279 [ - + ][ # # ]: 4 : if ( aAddress.Sheet >= nDocTabs && nDocTabs > 0 )
280 : : {
281 : : // Even after ValidateTabRefs, the position can be invalid if
282 : : // the content points to preceding tables. The resulting string
283 : : // is invalid in any case, so the position is just shifted.
284 : 0 : aAddress.Sheet = nDocTabs - 1;
285 : : }
286 : : }
287 [ + - ]: 4 : return aAddress;
288 : : }
289 : :
290 : 2 : void SAL_CALL ScNamedRangeObj::setReferencePosition( const table::CellAddress& aReferencePosition )
291 : : throw(uno::RuntimeException)
292 : : {
293 [ + - ]: 2 : SolarMutexGuard aGuard;
294 : 2 : ScAddress aPos( (SCCOL)aReferencePosition.Column, (SCROW)aReferencePosition.Row, aReferencePosition.Sheet );
295 : : // GRAM_PODF_A1 for API compatibility.
296 [ + - ][ + - ]: 2 : Modify_Impl( NULL, NULL, NULL, &aPos, NULL,formula::FormulaGrammar::GRAM_PODF_A1 );
297 : 2 : }
298 : :
299 : 12 : sal_Int32 SAL_CALL ScNamedRangeObj::getType() throw(uno::RuntimeException)
300 : : {
301 [ + - ]: 12 : SolarMutexGuard aGuard;
302 : 12 : sal_Int32 nType=0;
303 [ + - ]: 12 : ScRangeData* pData = GetRangeData_Impl();
304 [ + - ]: 12 : if (pData)
305 : : {
306 : : // do not return internal RT_* flags
307 : : // see property 'IsSharedFormula' for RT_SHARED
308 [ + + ]: 12 : if ( pData->HasType(RT_CRITERIA) ) nType |= sheet::NamedRangeFlag::FILTER_CRITERIA;
309 [ + + ]: 12 : if ( pData->HasType(RT_PRINTAREA) ) nType |= sheet::NamedRangeFlag::PRINT_AREA;
310 [ + + ]: 12 : if ( pData->HasType(RT_COLHEADER) ) nType |= sheet::NamedRangeFlag::COLUMN_HEADER;
311 [ + + ]: 12 : if ( pData->HasType(RT_ROWHEADER) ) nType |= sheet::NamedRangeFlag::ROW_HEADER;
312 : : }
313 [ + - ]: 12 : return nType;
314 : : }
315 : :
316 : 10 : void SAL_CALL ScNamedRangeObj::setType( sal_Int32 nUnoType ) throw(uno::RuntimeException)
317 : : {
318 : : // see property 'IsSharedFormula' for RT_SHARED
319 [ + - ]: 10 : SolarMutexGuard aGuard;
320 : 10 : sal_uInt16 nNewType = RT_NAME;
321 [ + + ]: 10 : if ( nUnoType & sheet::NamedRangeFlag::FILTER_CRITERIA ) nNewType |= RT_CRITERIA;
322 [ + + ]: 10 : if ( nUnoType & sheet::NamedRangeFlag::PRINT_AREA ) nNewType |= RT_PRINTAREA;
323 [ + + ]: 10 : if ( nUnoType & sheet::NamedRangeFlag::COLUMN_HEADER ) nNewType |= RT_COLHEADER;
324 [ + + ]: 10 : if ( nUnoType & sheet::NamedRangeFlag::ROW_HEADER ) nNewType |= RT_ROWHEADER;
325 : :
326 : : // GRAM_PODF_A1 for API compatibility.
327 [ + - ][ + - ]: 10 : Modify_Impl( NULL, NULL, NULL, NULL, &nNewType,formula::FormulaGrammar::GRAM_PODF_A1 );
328 : 10 : }
329 : :
330 : : // XFormulaTokens
331 : :
332 : 0 : uno::Sequence<sheet::FormulaToken> SAL_CALL ScNamedRangeObj::getTokens() throw(uno::RuntimeException)
333 : : {
334 [ # # ]: 0 : SolarMutexGuard aGuard;
335 [ # # ]: 0 : uno::Sequence<sheet::FormulaToken> aSequence;
336 [ # # ]: 0 : ScRangeData* pData = GetRangeData_Impl();
337 [ # # ][ # # ]: 0 : if (pData && pDocShell)
338 : : {
339 : 0 : ScTokenArray* pTokenArray = pData->GetCode();
340 [ # # ]: 0 : if ( pTokenArray )
341 [ # # ]: 0 : (void)ScTokenConversion::ConvertToTokenSequence( *pDocShell->GetDocument(), aSequence, *pTokenArray );
342 : : }
343 [ # # ]: 0 : return aSequence;
344 : : }
345 : :
346 : 0 : void SAL_CALL ScNamedRangeObj::setTokens( const uno::Sequence<sheet::FormulaToken>& rTokens ) throw(uno::RuntimeException)
347 : : {
348 [ # # ]: 0 : SolarMutexGuard aGuard;
349 [ # # ]: 0 : if( pDocShell )
350 : : {
351 [ # # ]: 0 : ScTokenArray aTokenArray;
352 [ # # ]: 0 : (void)ScTokenConversion::ConvertToTokenArray( *pDocShell->GetDocument(), aTokenArray, rTokens );
353 : : // GRAM_PODF_A1 for API compatibility.
354 [ # # ][ # # ]: 0 : Modify_Impl( NULL, &aTokenArray, NULL, NULL, NULL, formula::FormulaGrammar::GRAM_PODF_A1 );
355 [ # # ]: 0 : }
356 : 0 : }
357 : :
358 : :
359 : : // XCellRangeSource
360 : :
361 : 14 : uno::Reference<table::XCellRange> SAL_CALL ScNamedRangeObj::getReferredCells()
362 : : throw(uno::RuntimeException)
363 : : {
364 [ + - ]: 14 : SolarMutexGuard aGuard;
365 : 14 : ScRange aRange;
366 [ + - ]: 14 : ScRangeData* pData = GetRangeData_Impl();
367 [ + - ][ + - ]: 14 : if ( pData && pData->IsValidReference( aRange ) )
[ + - ][ + - ]
368 : : {
369 : : //! static Funktion um ScCellObj/ScCellRangeObj zu erzeugen am ScCellRangeObj ???
370 : :
371 [ + + ]: 14 : if ( aRange.aStart == aRange.aEnd )
372 [ + - ][ + - ]: 2 : return new ScCellObj( pDocShell, aRange.aStart );
[ + - ]
373 : : else
374 [ + - ][ + - ]: 12 : return new ScCellRangeObj( pDocShell, aRange );
[ + - ]
375 : : }
376 [ # # ][ + - ]: 14 : return NULL;
377 : : }
378 : :
379 : : // beans::XPropertySet
380 : :
381 : 0 : uno::Reference<beans::XPropertySetInfo> SAL_CALL ScNamedRangeObj::getPropertySetInfo()
382 : : throw(uno::RuntimeException)
383 : : {
384 [ # # ]: 0 : SolarMutexGuard aGuard;
385 [ # # ][ # # ]: 0 : static uno::Reference< beans::XPropertySetInfo > aRef(new SfxItemPropertySetInfo( lcl_GetNamedRangeMap() ));
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
386 [ # # ]: 0 : return aRef;
387 : : }
388 : :
389 : 0 : void SAL_CALL ScNamedRangeObj::setPropertyValue(
390 : : const rtl::OUString& rPropertyName, const uno::Any& aValue )
391 : : throw(beans::UnknownPropertyException, beans::PropertyVetoException,
392 : : lang::IllegalArgumentException, lang::WrappedTargetException,
393 : : uno::RuntimeException)
394 : : {
395 [ # # ]: 0 : SolarMutexGuard aGuard;
396 [ # # ]: 0 : if ( rPropertyName == SC_UNONAME_ISSHAREDFMLA )
397 : : {
398 : 0 : bool bIsShared = false;
399 [ # # ]: 0 : if( aValue >>= bIsShared )
400 : : {
401 [ # # ]: 0 : sal_uInt16 nNewType = bIsShared ? RT_SHARED : RT_NAME;
402 [ # # ]: 0 : Modify_Impl( NULL, NULL, NULL, NULL, &nNewType,formula::FormulaGrammar::GRAM_PODF_A1 );
403 : : }
404 [ # # ]: 0 : }
405 : 0 : }
406 : :
407 : 0 : uno::Any SAL_CALL ScNamedRangeObj::getPropertyValue( const rtl::OUString& rPropertyName )
408 : : throw(beans::UnknownPropertyException, lang::WrappedTargetException,
409 : : uno::RuntimeException)
410 : : {
411 [ # # ]: 0 : SolarMutexGuard aGuard;
412 : 0 : uno::Any aRet;
413 [ # # ]: 0 : if ( rPropertyName == SC_UNO_LINKDISPBIT )
414 : : {
415 : : // no target bitmaps for individual entries (would be all equal)
416 : : // ScLinkTargetTypeObj::SetLinkTargetBitmap( aRet, SC_LINKTARGETTYPE_RANGENAME );
417 : : }
418 [ # # ]: 0 : else if ( rPropertyName == SC_UNO_LINKDISPNAME )
419 [ # # ][ # # ]: 0 : aRet <<= rtl::OUString( aName );
420 [ # # ]: 0 : else if ( rPropertyName == SC_UNONAME_TOKENINDEX )
421 : : {
422 : : // get index for use in formula tokens (read-only)
423 [ # # ]: 0 : ScRangeData* pData = GetRangeData_Impl();
424 [ # # ]: 0 : if (pData)
425 [ # # ]: 0 : aRet <<= static_cast<sal_Int32>(pData->GetIndex());
426 : : }
427 [ # # ]: 0 : else if ( rPropertyName == SC_UNONAME_ISSHAREDFMLA )
428 : : {
429 [ # # ][ # # ]: 0 : if( ScRangeData* pData = GetRangeData_Impl() )
430 [ # # ]: 0 : aRet <<= static_cast< bool >( pData->HasType( RT_SHARED ) );
431 : : }
432 [ # # ]: 0 : return aRet;
433 : : }
434 : :
435 : 0 : SC_IMPL_DUMMY_PROPERTY_LISTENER( ScNamedRangeObj )
436 : :
437 : : // lang::XServiceInfo
438 : :
439 : 0 : rtl::OUString SAL_CALL ScNamedRangeObj::getImplementationName() throw(uno::RuntimeException)
440 : : {
441 : 0 : return rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ScNamedRangeObj" ) );
442 : : }
443 : :
444 : 0 : sal_Bool SAL_CALL ScNamedRangeObj::supportsService( const rtl::OUString& rServiceName )
445 : : throw(uno::RuntimeException)
446 : : {
447 : 0 : return rServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( SCNAMEDRANGEOBJ_SERVICE ) ) ||
448 [ # # ][ # # ]: 0 : rServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( SCLINKTARGET_SERVICE ) );
449 : : }
450 : :
451 : 0 : uno::Sequence<rtl::OUString> SAL_CALL ScNamedRangeObj::getSupportedServiceNames()
452 : : throw(uno::RuntimeException)
453 : : {
454 : 0 : uno::Sequence<rtl::OUString> aRet(2);
455 [ # # ][ # # ]: 0 : aRet[0] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SCNAMEDRANGEOBJ_SERVICE ) );
456 [ # # ][ # # ]: 0 : aRet[1] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SCLINKTARGET_SERVICE ) );
457 : 0 : return aRet;
458 : : }
459 : :
460 : :
461 : : // XUnoTunnel
462 : :
463 : 0 : sal_Int64 SAL_CALL ScNamedRangeObj::getSomething(
464 : : const uno::Sequence<sal_Int8 >& rId ) throw(uno::RuntimeException)
465 : : {
466 [ # # # # ]: 0 : if ( rId.getLength() == 16 &&
[ # # ]
467 : 0 : 0 == memcmp( getUnoTunnelId().getConstArray(),
468 : 0 : rId.getConstArray(), 16 ) )
469 : : {
470 : 0 : return sal::static_int_cast<sal_Int64>(reinterpret_cast<sal_IntPtr>(this));
471 : : }
472 : 0 : return 0;
473 : : }
474 : :
475 : : namespace
476 : : {
477 : : class theScNamedRangeObjUnoTunnelId : public rtl::Static< UnoTunnelIdInit, theScNamedRangeObjUnoTunnelId> {};
478 : : }
479 : :
480 : 0 : const uno::Sequence<sal_Int8>& ScNamedRangeObj::getUnoTunnelId()
481 : : {
482 : 0 : return theScNamedRangeObjUnoTunnelId::get().getSeq();
483 : : }
484 : :
485 : : //------------------------------------------------------------------------
486 : :
487 : 207 : ScNamedRangesObj::ScNamedRangesObj(ScDocShell* pDocSh) :
488 : : mbModifyAndBroadcast(true),
489 [ + - ]: 207 : pDocShell( pDocSh )
490 : : {
491 [ + - ]: 207 : pDocShell->GetDocument()->AddUnoObject(*this);
492 : 207 : }
493 : :
494 [ + - ]: 207 : ScNamedRangesObj::~ScNamedRangesObj()
495 : : {
496 [ + + ]: 207 : if (pDocShell)
497 [ + - ]: 200 : pDocShell->GetDocument()->RemoveUnoObject(*this);
498 [ - + ]: 207 : }
499 : :
500 : 227 : void ScNamedRangesObj::Notify( SfxBroadcaster&, const SfxHint& rHint )
501 : : {
502 : : // Referenz-Update interessiert hier nicht
503 : :
504 [ + - + + ]: 454 : if ( rHint.ISA( SfxSimpleHint ) &&
[ + + ]
505 : 227 : ((const SfxSimpleHint&)rHint).GetId() == SFX_HINT_DYING )
506 : : {
507 : 7 : pDocShell = NULL; // ungueltig geworden
508 : : }
509 : 227 : }
510 : :
511 : 22 : bool ScNamedRangesObj::IsModifyAndBroadcast() const
512 : : {
513 : 22 : return mbModifyAndBroadcast;
514 : : }
515 : :
516 : : // sheet::XNamedRanges
517 : :
518 : 13 : void SAL_CALL ScNamedRangesObj::addNewByName( const rtl::OUString& aName,
519 : : const rtl::OUString& aContent, const table::CellAddress& aPosition,
520 : : sal_Int32 nUnoType ) throw(uno::RuntimeException)
521 : : {
522 [ + - ]: 13 : SolarMutexGuard aGuard;
523 : 13 : ScAddress aPos( (SCCOL)aPosition.Column, (SCROW)aPosition.Row, aPosition.Sheet );
524 : :
525 : 13 : sal_uInt16 nNewType = RT_NAME;
526 [ + + ]: 13 : if ( nUnoType & sheet::NamedRangeFlag::FILTER_CRITERIA ) nNewType |= RT_CRITERIA;
527 [ + + ]: 13 : if ( nUnoType & sheet::NamedRangeFlag::PRINT_AREA ) nNewType |= RT_PRINTAREA;
528 [ + + ]: 13 : if ( nUnoType & sheet::NamedRangeFlag::COLUMN_HEADER ) nNewType |= RT_COLHEADER;
529 [ + + ]: 13 : if ( nUnoType & sheet::NamedRangeFlag::ROW_HEADER ) nNewType |= RT_ROWHEADER;
530 : :
531 : 13 : sal_Bool bDone = false;
532 [ + - ]: 13 : if (pDocShell)
533 : : {
534 : 13 : ScDocument* pDoc = pDocShell->GetDocument();
535 [ + - ]: 13 : ScRangeName* pNames = GetRangeName_Impl();
536 [ + - ][ + - ]: 13 : if (pNames && !pNames->findByUpperName(ScGlobal::pCharClass->uppercase(aName)))
[ + - ][ + - ]
[ + - ]
[ + - # # ]
537 : : {
538 [ + - ][ + - ]: 13 : ScRangeName* pNewRanges = new ScRangeName( *pNames );
539 : : // GRAM_PODF_A1 for API compatibility.
540 : : ScRangeData* pNew = new ScRangeData( pDoc, aName, aContent,
541 [ + - ][ + - ]: 13 : aPos, nNewType,formula::FormulaGrammar::GRAM_PODF_A1 );
[ + - ][ + - ]
542 [ + - ][ + - ]: 13 : if ( pNewRanges->insert(pNew) )
543 : : {
544 [ + - ][ + - ]: 13 : pDocShell->GetDocFunc().SetNewRangeNames(pNewRanges, mbModifyAndBroadcast, GetTab_Impl());
545 : 13 : bDone = true;
546 : : }
547 : : else
548 : : {
549 : 0 : pNew = NULL;
550 [ # # ][ # # ]: 0 : delete pNewRanges;
551 : : }
552 : : }
553 : : }
554 : :
555 [ - + ]: 13 : if (!bDone)
556 [ # # ][ + - ]: 13 : throw uno::RuntimeException(); // no other exceptions specified
557 : 13 : }
558 : :
559 : 4 : void SAL_CALL ScNamedRangesObj::addNewFromTitles( const table::CellRangeAddress& aSource,
560 : : sheet::Border aBorder ) throw(uno::RuntimeException)
561 : : {
562 [ + - ]: 4 : SolarMutexGuard aGuard;
563 : : //! das darf kein enum sein, weil mehrere Bits gesetzt sein koennen !!!
564 : :
565 : 4 : sal_Bool bTop = ( aBorder == sheet::Border_TOP );
566 : 4 : sal_Bool bLeft = ( aBorder == sheet::Border_LEFT );
567 : 4 : sal_Bool bBottom = ( aBorder == sheet::Border_BOTTOM );
568 : 4 : sal_Bool bRight = ( aBorder == sheet::Border_RIGHT );
569 : :
570 : 4 : ScRange aRange;
571 : 4 : ScUnoConversion::FillScRange( aRange, aSource );
572 : :
573 : 4 : sal_uInt16 nFlags = 0;
574 [ + + ]: 4 : if (bTop) nFlags |= NAME_TOP;
575 [ + + ]: 4 : if (bLeft) nFlags |= NAME_LEFT;
576 [ - + ]: 4 : if (bBottom) nFlags |= NAME_BOTTOM;
577 [ - + ]: 4 : if (bRight) nFlags |= NAME_RIGHT;
578 : :
579 [ + - ]: 4 : if (nFlags)
580 [ + - ][ + - ]: 4 : pDocShell->GetDocFunc().CreateNames( aRange, nFlags, sal_True, GetTab_Impl() );
[ + - ]
581 : 4 : }
582 : :
583 : 0 : void SAL_CALL ScNamedRangesObj::removeByName( const rtl::OUString& aName )
584 : : throw(uno::RuntimeException)
585 : : {
586 [ # # ]: 0 : SolarMutexGuard aGuard;
587 : 0 : bool bDone = false;
588 [ # # ]: 0 : if (pDocShell)
589 : : {
590 [ # # ]: 0 : ScRangeName* pNames = GetRangeName_Impl();
591 [ # # ]: 0 : if (pNames)
592 : : {
593 [ # # ][ # # ]: 0 : const ScRangeData* pData = pNames->findByUpperName(ScGlobal::pCharClass->uppercase(aName));
594 [ # # ][ # # ]: 0 : if (pData && lcl_UserVisibleName(*pData))
[ # # ]
595 : : {
596 [ # # ][ # # ]: 0 : ScRangeName* pNewRanges = new ScRangeName(*pNames);
597 [ # # ]: 0 : pNewRanges->erase(*pData);
598 [ # # ][ # # ]: 0 : pDocShell->GetDocFunc().SetNewRangeNames( pNewRanges, mbModifyAndBroadcast, GetTab_Impl());
599 : 0 : bDone = true;
600 : : }
601 : : }
602 : : }
603 : :
604 [ # # ]: 0 : if (!bDone)
605 [ # # ][ # # ]: 0 : throw uno::RuntimeException(); // no other exceptions specified
606 : 0 : }
607 : :
608 : 5 : void SAL_CALL ScNamedRangesObj::outputList( const table::CellAddress& aOutputPosition )
609 : : throw(uno::RuntimeException)
610 : : {
611 [ + - ]: 5 : SolarMutexGuard aGuard;
612 : 5 : ScAddress aPos( (SCCOL)aOutputPosition.Column, (SCROW)aOutputPosition.Row, aOutputPosition.Sheet );
613 [ + - ]: 5 : if (pDocShell)
614 [ + - ][ + - ]: 5 : pDocShell->GetDocFunc().InsertNameList( aPos, sal_True );
615 : 5 : }
616 : :
617 : : // container::XEnumerationAccess
618 : :
619 : 2 : uno::Reference<container::XEnumeration> SAL_CALL ScNamedRangesObj::createEnumeration()
620 : : throw(uno::RuntimeException)
621 : : {
622 [ + - ]: 2 : SolarMutexGuard aGuard;
623 [ + - ][ + - ]: 2 : return new ScIndexEnumeration(this, rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.sheet.NamedRangesEnumeration")));
[ + - ][ + - ]
[ + - ][ + - ]
624 : : }
625 : :
626 : : // container::XIndexAccess
627 : :
628 : 7 : sal_Int32 SAL_CALL ScNamedRangesObj::getCount() throw(uno::RuntimeException)
629 : : {
630 [ + - ]: 7 : SolarMutexGuard aGuard;
631 : 7 : long nRet = 0;
632 [ + - ]: 7 : if (pDocShell)
633 : : {
634 [ + - ]: 7 : ScRangeName* pNames = GetRangeName_Impl();
635 [ + - ]: 7 : if (pNames)
636 : : {
637 [ + - ][ + - ]: 7 : ScRangeName::const_iterator itr = pNames->begin(), itrEnd = pNames->end();
[ + - ][ + - ]
638 [ + - ][ + - ]: 42 : for (; itr != itrEnd; ++itr)
[ + + ]
639 [ + - ][ + - ]: 35 : if (lcl_UserVisibleName(*itr->second))
640 : 35 : ++nRet;
641 : : }
642 : : }
643 [ + - ]: 7 : return nRet;
644 : : }
645 : :
646 : 6 : uno::Any SAL_CALL ScNamedRangesObj::getByIndex( sal_Int32 nIndex )
647 : : throw(lang::IndexOutOfBoundsException,
648 : : lang::WrappedTargetException, uno::RuntimeException)
649 : : {
650 [ + - ]: 6 : SolarMutexGuard aGuard;
651 [ + - ][ + + ]: 6 : uno::Reference< sheet::XNamedRange > xRange(GetObjectByIndex_Impl((sal_uInt16)nIndex));
[ + - ]
652 [ + + ]: 6 : if ( xRange.is() )
653 [ + - ]: 8 : return uno::makeAny(xRange);
654 : : else
655 [ + - ][ + - ]: 6 : throw lang::IndexOutOfBoundsException();
656 : : }
657 : :
658 : 1 : uno::Type SAL_CALL ScNamedRangesObj::getElementType() throw(uno::RuntimeException)
659 : : {
660 [ + - ]: 1 : SolarMutexGuard aGuard;
661 [ + - ][ + - ]: 1 : return ::getCppuType((const uno::Reference< sheet::XNamedRange >*)0); // muss zu getByIndex passen
662 : : }
663 : :
664 : 1 : sal_Bool SAL_CALL ScNamedRangesObj::hasElements() throw(uno::RuntimeException)
665 : : {
666 [ + - ]: 1 : SolarMutexGuard aGuard;
667 [ + - ][ + - ]: 1 : return ( getCount() != 0 );
668 : : }
669 : :
670 : 0 : Reference<beans::XPropertySetInfo> SAL_CALL ScNamedRangesObj::getPropertySetInfo()
671 : : throw(uno::RuntimeException)
672 : : {
673 : : static Reference<beans::XPropertySetInfo> aRef(
674 [ # # ][ # # ]: 0 : new SfxItemPropertySetInfo(lcl_GetNamedRangesMap()));
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
675 : 0 : return aRef;
676 : : }
677 : :
678 : 0 : void SAL_CALL ScNamedRangesObj::setPropertyValue(
679 : : const rtl::OUString& rPropertyName, const uno::Any& aValue )
680 : : throw(beans::UnknownPropertyException, beans::PropertyVetoException,
681 : : lang::IllegalArgumentException, lang::WrappedTargetException,
682 : : uno::RuntimeException)
683 : : {
684 [ # # ]: 0 : if ( rPropertyName == SC_UNO_MODIFY_BROADCAST )
685 : : {
686 : 0 : aValue >>= mbModifyAndBroadcast;
687 : : }
688 : 0 : }
689 : :
690 : 0 : Any SAL_CALL ScNamedRangesObj::getPropertyValue( const rtl::OUString& rPropertyName )
691 : : throw(beans::UnknownPropertyException, lang::WrappedTargetException,
692 : : uno::RuntimeException)
693 : : {
694 : 0 : Any aRet;
695 [ # # ]: 0 : if ( rPropertyName == SC_UNO_MODIFY_BROADCAST )
696 : : {
697 [ # # ]: 0 : aRet <<= mbModifyAndBroadcast;
698 : : }
699 : :
700 : 0 : return aRet;
701 : : }
702 : :
703 : 0 : SC_IMPL_DUMMY_PROPERTY_LISTENER( ScNamedRangesObj )
704 : :
705 : 89 : uno::Any SAL_CALL ScNamedRangesObj::getByName( const rtl::OUString& aName )
706 : : throw(container::NoSuchElementException,
707 : : lang::WrappedTargetException, uno::RuntimeException)
708 : : {
709 [ + - ]: 89 : SolarMutexGuard aGuard;
710 [ + - ][ + + ]: 89 : uno::Reference< sheet::XNamedRange > xRange(GetObjectByName_Impl(aName));
[ + - ]
711 [ + + ]: 89 : if ( xRange.is() )
712 [ + - ]: 80 : return uno::makeAny(xRange);
713 : : else
714 [ + - ][ + - ]: 89 : throw container::NoSuchElementException();
715 : : }
716 : :
717 : 1 : uno::Sequence<rtl::OUString> SAL_CALL ScNamedRangesObj::getElementNames()
718 : : throw(uno::RuntimeException)
719 : : {
720 [ + - ]: 1 : SolarMutexGuard aGuard;
721 [ + - ]: 1 : if (pDocShell)
722 : : {
723 [ + - ]: 1 : ScRangeName* pNames = GetRangeName_Impl();
724 [ + - ]: 1 : if (pNames)
725 : : {
726 [ + - ]: 1 : long nVisCount = getCount(); // Namen mit lcl_UserVisibleName
727 [ + - ]: 1 : uno::Sequence<rtl::OUString> aSeq(nVisCount);
728 [ + - ]: 1 : rtl::OUString* pAry = aSeq.getArray();
729 : 1 : sal_uInt16 nVisPos = 0;
730 [ + - ][ + - ]: 1 : ScRangeName::const_iterator itr = pNames->begin(), itrEnd = pNames->end();
[ + - ][ + - ]
731 [ + - ][ + - ]: 2 : for (; itr != itrEnd; ++itr)
[ + + ]
732 : : {
733 [ + - ][ + - ]: 1 : if (lcl_UserVisibleName(*itr->second))
734 [ + - ]: 1 : pAry[nVisPos++] = itr->second->GetName();
735 : : }
736 [ + - ][ + - ]: 1 : return aSeq;
737 : : }
738 : : }
739 [ # # ][ + - ]: 1 : return uno::Sequence<rtl::OUString>(0);
740 : : }
741 : :
742 : 294 : sal_Bool SAL_CALL ScNamedRangesObj::hasByName( const rtl::OUString& aName )
743 : : throw(uno::RuntimeException)
744 : : {
745 [ + - ]: 294 : SolarMutexGuard aGuard;
746 [ + - ]: 294 : if (pDocShell)
747 : : {
748 [ + - ]: 294 : ScRangeName* pNames = GetRangeName_Impl();
749 [ + - ]: 294 : if (pNames)
750 : : {
751 [ + - ][ + - ]: 294 : const ScRangeData* pData = pNames->findByUpperName(ScGlobal::pCharClass->uppercase(aName));
752 [ + - ][ + + ]: 294 : if (pData && lcl_UserVisibleName(*pData))
[ + + ]
753 : 99 : return sal_True;
754 : : }
755 : : }
756 [ + - ]: 294 : return false;
757 : : }
758 : :
759 : : /** called from the XActionLockable interface methods on initial locking */
760 : 24 : void ScNamedRangesObj::lock()
761 : : {
762 : 24 : pDocShell->GetDocument()->CompileNameFormula( sal_True ); // CreateFormulaString
763 : 24 : }
764 : :
765 : : /** called from the XActionLockable interface methods on final unlock */
766 : 24 : void ScNamedRangesObj::unlock()
767 : : {
768 : 24 : pDocShell->GetDocument()->CompileNameFormula( false ); // CompileFormulaString
769 : 24 : }
770 : :
771 : : // document::XActionLockable
772 : :
773 : 0 : sal_Bool ScNamedRangesObj::isActionLocked() throw(uno::RuntimeException)
774 : : {
775 [ # # ]: 0 : SolarMutexGuard aGuard;
776 [ # # ][ # # ]: 0 : return pDocShell->GetDocument()->GetNamedRangesLockCount() != 0;
777 : : }
778 : :
779 : 24 : void ScNamedRangesObj::addActionLock() throw(uno::RuntimeException)
780 : : {
781 [ + - ]: 24 : SolarMutexGuard aGuard;
782 : 24 : ScDocument* pDoc = pDocShell->GetDocument();
783 [ + - ]: 24 : sal_Int16 nLockCount = pDoc->GetNamedRangesLockCount();
784 : 24 : ++nLockCount;
785 [ + - ]: 24 : if ( nLockCount == 1 )
786 : : {
787 [ + - ]: 24 : lock();
788 : : }
789 [ + - ]: 24 : pDoc->SetNamedRangesLockCount( nLockCount );
790 : 24 : }
791 : :
792 : 24 : void ScNamedRangesObj::removeActionLock() throw(uno::RuntimeException)
793 : : {
794 [ + - ]: 24 : SolarMutexGuard aGuard;
795 : 24 : ScDocument* pDoc = pDocShell->GetDocument();
796 [ + - ]: 24 : sal_Int16 nLockCount = pDoc->GetNamedRangesLockCount();
797 [ + - ]: 24 : if ( nLockCount > 0 )
798 : : {
799 : 24 : --nLockCount;
800 [ + - ]: 24 : if ( nLockCount == 0 )
801 : : {
802 [ + - ]: 24 : unlock();
803 : : }
804 : 24 : pDoc->SetNamedRangesLockCount( nLockCount );
805 [ + - ]: 24 : }
806 : 24 : }
807 : :
808 : 0 : void ScNamedRangesObj::setActionLocks( sal_Int16 nLock ) throw(uno::RuntimeException)
809 : : {
810 [ # # ]: 0 : SolarMutexGuard aGuard;
811 [ # # ]: 0 : if ( nLock >= 0 )
812 : : {
813 : 0 : ScDocument* pDoc = pDocShell->GetDocument();
814 [ # # ]: 0 : sal_Int16 nLockCount = pDoc->GetNamedRangesLockCount();
815 [ # # ][ # # ]: 0 : if ( nLock == 0 && nLockCount > 0 )
816 : : {
817 [ # # ]: 0 : unlock();
818 : : }
819 [ # # ][ # # ]: 0 : if ( nLock > 0 && nLockCount == 0 )
820 : : {
821 [ # # ]: 0 : lock();
822 : : }
823 : 0 : pDoc->SetNamedRangesLockCount( nLock );
824 [ # # ]: 0 : }
825 : 0 : }
826 : :
827 : 0 : sal_Int16 ScNamedRangesObj::resetActionLocks() throw(uno::RuntimeException)
828 : : {
829 [ # # ]: 0 : SolarMutexGuard aGuard;
830 : 0 : ScDocument* pDoc = pDocShell->GetDocument();
831 [ # # ]: 0 : sal_Int16 nLockCount = pDoc->GetNamedRangesLockCount();
832 [ # # ]: 0 : if ( nLockCount > 0 )
833 : : {
834 [ # # ]: 0 : unlock();
835 : : }
836 : 0 : pDoc->SetNamedRangesLockCount( 0 );
837 [ # # ]: 0 : return nLockCount;
838 : : }
839 : :
840 : : //------------------------------------------------------------------------
841 : :
842 : 207 : ScGlobalNamedRangesObj::ScGlobalNamedRangesObj(ScDocShell* pDocSh)
843 : 207 : : ScNamedRangesObj(pDocSh)
844 : : {
845 : :
846 : 207 : }
847 : :
848 : 207 : ScGlobalNamedRangesObj::~ScGlobalNamedRangesObj()
849 : : {
850 : :
851 [ - + ]: 414 : }
852 : :
853 : 6 : ScNamedRangeObj* ScGlobalNamedRangesObj::GetObjectByIndex_Impl(sal_uInt16 nIndex)
854 : : {
855 [ - + ]: 6 : if (!pDocShell)
856 : 0 : return NULL;
857 : :
858 [ + - ]: 6 : ScRangeName* pNames = pDocShell->GetDocument()->GetRangeName();
859 [ - + ]: 6 : if (!pNames)
860 : 0 : return NULL;
861 : :
862 [ + - ][ + - ]: 6 : ScRangeName::const_iterator itr = pNames->begin(), itrEnd = pNames->end();
[ + - ][ + - ]
863 : 6 : sal_uInt16 nPos = 0;
864 [ + - ][ + - ]: 8 : for (; itr != itrEnd; ++itr)
[ + + ]
865 : : {
866 [ + - ][ + - ]: 6 : if (lcl_UserVisibleName(*itr->second))
867 : : {
868 [ + + ]: 6 : if (nPos == nIndex)
869 [ + - ][ + - ]: 4 : return new ScNamedRangeObj(this, pDocShell, itr->second->GetName());
[ + - ][ + - ]
870 : : }
871 : 2 : ++nPos;
872 : : }
873 : 6 : return NULL;
874 : : }
875 : :
876 : 89 : ScNamedRangeObj* ScGlobalNamedRangesObj::GetObjectByName_Impl(const ::rtl::OUString& aName)
877 : : {
878 [ + - ][ + + ]: 89 : if ( pDocShell && hasByName(aName) )
[ + + ]
879 [ + - ][ + - ]: 40 : return new ScNamedRangeObj(this, pDocShell, String(aName));
[ + - ]
880 : 89 : return NULL;
881 : : }
882 : :
883 : 315 : ScRangeName* ScGlobalNamedRangesObj::GetRangeName_Impl()
884 : : {
885 : 315 : return pDocShell->GetDocument()->GetRangeName();
886 : : }
887 : :
888 : 17 : SCTAB ScGlobalNamedRangesObj::GetTab_Impl()
889 : : {
890 : 17 : return -1;
891 : : }
892 : :
893 : : //------------------------------------------------------------------------
894 : :
895 : 0 : ScLocalNamedRangesObj::ScLocalNamedRangesObj( ScDocShell* pDocSh, uno::Reference<container::XNamed> xSheet )
896 : : : ScNamedRangesObj(pDocSh),
897 : 0 : mxSheet(xSheet)
898 : : {
899 : :
900 : 0 : }
901 : :
902 : 0 : ScLocalNamedRangesObj::~ScLocalNamedRangesObj()
903 : : {
904 : :
905 [ # # ]: 0 : }
906 : :
907 : 0 : ScNamedRangeObj* ScLocalNamedRangesObj::GetObjectByName_Impl(const ::rtl::OUString& aName)
908 : : {
909 [ # # ][ # # ]: 0 : if ( pDocShell && hasByName( aName ) )
[ # # ]
910 [ # # ][ # # ]: 0 : return new ScNamedRangeObj( this, pDocShell, String(aName), mxSheet);
[ # # ]
911 : 0 : return NULL;
912 : :
913 : : }
914 : :
915 : 0 : ScNamedRangeObj* ScLocalNamedRangesObj::GetObjectByIndex_Impl( sal_uInt16 nIndex )
916 : : {
917 [ # # ]: 0 : if (!pDocShell)
918 : 0 : return NULL;
919 : :
920 [ # # ][ # # ]: 0 : rtl::OUString aName = mxSheet->getName();
921 : 0 : ScDocument* pDoc = pDocShell->GetDocument();
922 : : SCTAB nTab;
923 [ # # ]: 0 : pDoc->GetTable( aName, nTab );
924 : :
925 [ # # ]: 0 : ScRangeName* pNames = pDoc->GetRangeName( nTab );
926 [ # # ]: 0 : if (!pNames)
927 : 0 : return NULL;
928 : :
929 [ # # ][ # # ]: 0 : ScRangeName::const_iterator itr = pNames->begin(), itrEnd = pNames->end();
[ # # ][ # # ]
930 : 0 : sal_uInt16 nPos = 0;
931 [ # # ][ # # ]: 0 : for (; itr != itrEnd; ++itr)
[ # # ]
932 : : {
933 [ # # ][ # # ]: 0 : if (lcl_UserVisibleName(*itr->second))
934 : : {
935 [ # # ]: 0 : if (nPos == nIndex)
936 [ # # ][ # # ]: 0 : return new ScNamedRangeObj(this, pDocShell, itr->second->GetName(), mxSheet);
[ # # ][ # # ]
937 : : }
938 : 0 : ++nPos;
939 : : }
940 : 0 : return NULL;
941 : : }
942 : :
943 : 0 : ScRangeName* ScLocalNamedRangesObj::GetRangeName_Impl()
944 : : {
945 : 0 : SCTAB nTab = GetTab_Impl();
946 : 0 : return pDocShell->GetDocument()->GetRangeName( nTab );
947 : : }
948 : :
949 : 0 : SCTAB ScLocalNamedRangesObj::GetTab_Impl()
950 : : {
951 : : SCTAB nTab;
952 [ # # ][ # # ]: 0 : pDocShell->GetDocument()->GetTable(mxSheet->getName(), nTab);
[ # # ]
953 : 0 : return nTab;
954 : : }
955 : :
956 : : //------------------------------------------------------------------------
957 : :
958 : 5 : ScLabelRangeObj::ScLabelRangeObj(ScDocShell* pDocSh, sal_Bool bCol, const ScRange& rR) :
959 : : pDocShell( pDocSh ),
960 : : bColumn( bCol ),
961 [ + - ]: 5 : aRange( rR )
962 : : {
963 [ + - ]: 5 : pDocShell->GetDocument()->AddUnoObject(*this);
964 : 5 : }
965 : :
966 [ + - ]: 5 : ScLabelRangeObj::~ScLabelRangeObj()
967 : : {
968 [ - + ]: 5 : if (pDocShell)
969 [ # # ]: 0 : pDocShell->GetDocument()->RemoveUnoObject(*this);
970 [ - + ]: 10 : }
971 : :
972 : 13 : void ScLabelRangeObj::Notify( SfxBroadcaster&, const SfxHint& rHint )
973 : : {
974 : : //! Ref-Update !!!
975 : :
976 [ + - ][ + + ]: 13 : if ( rHint.ISA( SfxSimpleHint ) && ((const SfxSimpleHint&)rHint).GetId() == SFX_HINT_DYING )
[ + + ]
977 : 5 : pDocShell = NULL; // ungueltig geworden
978 : 13 : }
979 : :
980 : : // Hilfsfuntionen
981 : :
982 : 2 : ScRangePair* ScLabelRangeObj::GetData_Impl()
983 : : {
984 : 2 : ScRangePair* pRet = NULL;
985 [ + - ]: 2 : if (pDocShell)
986 : : {
987 : 2 : ScDocument* pDoc = pDocShell->GetDocument();
988 [ + - ]: 2 : ScRangePairList* pList = bColumn ? pDoc->GetColNameRanges() : pDoc->GetRowNameRanges();
989 [ + - ]: 2 : if (pList)
990 : 2 : pRet = pList->Find( aRange );
991 : : }
992 : 2 : return pRet;
993 : : }
994 : :
995 : 2 : void ScLabelRangeObj::Modify_Impl( const ScRange* pLabel, const ScRange* pData )
996 : : {
997 [ + - ]: 2 : if (pDocShell)
998 : : {
999 : 2 : ScDocument* pDoc = pDocShell->GetDocument();
1000 [ + - ]: 2 : ScRangePairList* pOldList = bColumn ? pDoc->GetColNameRanges() : pDoc->GetRowNameRanges();
1001 [ + - ]: 2 : if (pOldList)
1002 : : {
1003 [ + - ]: 2 : ScRangePairListRef xNewList(pOldList->Clone());
1004 [ + - ]: 2 : ScRangePair* pEntry = xNewList->Find( aRange );
1005 [ + - ]: 2 : if (pEntry)
1006 : : {
1007 [ + - ]: 2 : xNewList->Remove( pEntry ); // nur aus der Liste entfernt, nicht geloescht
1008 : :
1009 [ + + ]: 2 : if ( pLabel )
1010 : 1 : pEntry->GetRange(0) = *pLabel;
1011 [ + + ]: 2 : if ( pData )
1012 : 1 : pEntry->GetRange(1) = *pData;
1013 : :
1014 [ + - ]: 2 : xNewList->Join( *pEntry );
1015 : 2 : delete pEntry;
1016 : :
1017 [ + - ]: 2 : if (bColumn)
1018 [ + - ]: 2 : pDoc->GetColNameRangesRef() = xNewList;
1019 : : else
1020 [ # # ]: 0 : pDoc->GetRowNameRangesRef() = xNewList;
1021 : :
1022 [ + - ]: 2 : pDoc->CompileColRowNameFormula();
1023 [ + - ]: 2 : pDocShell->PostPaint( 0,0,0, MAXCOL,MAXROW,MAXTAB, PAINT_GRID );
1024 [ + - ]: 2 : pDocShell->SetDocumentModified();
1025 : :
1026 : : //! Undo ?!?! (hier und aus Dialog)
1027 : :
1028 [ + + ]: 2 : if ( pLabel )
1029 : 1 : aRange = *pLabel; // Objekt anpassen, um Range wiederzufinden
1030 [ + - ]: 2 : }
1031 : : }
1032 : : }
1033 : 2 : }
1034 : :
1035 : : // sheet::XLabelRange
1036 : :
1037 : 1 : table::CellRangeAddress SAL_CALL ScLabelRangeObj::getLabelArea()
1038 : : throw(uno::RuntimeException)
1039 : : {
1040 [ + - ]: 1 : SolarMutexGuard aGuard;
1041 : 1 : table::CellRangeAddress aRet;
1042 [ + - ]: 1 : ScRangePair* pData = GetData_Impl();
1043 [ + - ]: 1 : if (pData)
1044 : 1 : ScUnoConversion::FillApiRange( aRet, pData->GetRange(0) );
1045 [ + - ]: 1 : return aRet;
1046 : : }
1047 : :
1048 : 1 : void SAL_CALL ScLabelRangeObj::setLabelArea( const table::CellRangeAddress& aLabelArea )
1049 : : throw(uno::RuntimeException)
1050 : : {
1051 [ + - ]: 1 : SolarMutexGuard aGuard;
1052 : 1 : ScRange aLabelRange;
1053 : 1 : ScUnoConversion::FillScRange( aLabelRange, aLabelArea );
1054 [ + - ][ + - ]: 1 : Modify_Impl( &aLabelRange, NULL );
1055 : 1 : }
1056 : :
1057 : 1 : table::CellRangeAddress SAL_CALL ScLabelRangeObj::getDataArea()
1058 : : throw(uno::RuntimeException)
1059 : : {
1060 [ + - ]: 1 : SolarMutexGuard aGuard;
1061 : 1 : table::CellRangeAddress aRet;
1062 [ + - ]: 1 : ScRangePair* pData = GetData_Impl();
1063 [ + - ]: 1 : if (pData)
1064 : 1 : ScUnoConversion::FillApiRange( aRet, pData->GetRange(1) );
1065 [ + - ]: 1 : return aRet;
1066 : : }
1067 : :
1068 : 1 : void SAL_CALL ScLabelRangeObj::setDataArea( const table::CellRangeAddress& aDataArea )
1069 : : throw(uno::RuntimeException)
1070 : : {
1071 [ + - ]: 1 : SolarMutexGuard aGuard;
1072 : 1 : ScRange aDataRange;
1073 : 1 : ScUnoConversion::FillScRange( aDataRange, aDataArea );
1074 [ + - ][ + - ]: 1 : Modify_Impl( NULL, &aDataRange );
1075 : 1 : }
1076 : :
1077 : : //------------------------------------------------------------------------
1078 : :
1079 : 19 : ScLabelRangesObj::ScLabelRangesObj(ScDocShell* pDocSh, sal_Bool bCol) :
1080 : : pDocShell( pDocSh ),
1081 [ + - ]: 19 : bColumn( bCol )
1082 : : {
1083 [ + - ]: 19 : pDocShell->GetDocument()->AddUnoObject(*this);
1084 : 19 : }
1085 : :
1086 [ + - ]: 19 : ScLabelRangesObj::~ScLabelRangesObj()
1087 : : {
1088 [ + + ]: 19 : if (pDocShell)
1089 [ + - ]: 8 : pDocShell->GetDocument()->RemoveUnoObject(*this);
1090 [ - + ]: 38 : }
1091 : :
1092 : 310 : void ScLabelRangesObj::Notify( SfxBroadcaster&, const SfxHint& rHint )
1093 : : {
1094 : : // Referenz-Update interessiert hier nicht
1095 : :
1096 [ + - + + ]: 620 : if ( rHint.ISA( SfxSimpleHint ) &&
[ + + ]
1097 : 310 : ((const SfxSimpleHint&)rHint).GetId() == SFX_HINT_DYING )
1098 : : {
1099 : 11 : pDocShell = NULL; // ungueltig geworden
1100 : : }
1101 : 310 : }
1102 : :
1103 : : // sheet::XLabelRanges
1104 : :
1105 : 7 : ScLabelRangeObj* ScLabelRangesObj::GetObjectByIndex_Impl(size_t nIndex)
1106 : : {
1107 [ + - ]: 7 : if (pDocShell)
1108 : : {
1109 : 7 : ScDocument* pDoc = pDocShell->GetDocument();
1110 [ + - ]: 7 : ScRangePairList* pList = bColumn ? pDoc->GetColNameRanges() : pDoc->GetRowNameRanges();
1111 [ + - ][ + + ]: 7 : if ( pList && nIndex < pList->size() )
[ + + ]
1112 : : {
1113 : 5 : ScRangePair* pData = (*pList)[nIndex];
1114 [ + - ]: 5 : if (pData)
1115 [ + - ]: 5 : return new ScLabelRangeObj( pDocShell, bColumn, pData->GetRange(0) );
1116 : : }
1117 : : }
1118 : 7 : return NULL;
1119 : : }
1120 : :
1121 : 4 : void SAL_CALL ScLabelRangesObj::addNew( const table::CellRangeAddress& aLabelArea,
1122 : : const table::CellRangeAddress& aDataArea )
1123 : : throw(uno::RuntimeException)
1124 : : {
1125 [ + - ]: 4 : SolarMutexGuard aGuard;
1126 [ + - ]: 4 : if (pDocShell)
1127 : : {
1128 : 4 : ScDocument* pDoc = pDocShell->GetDocument();
1129 [ + - ]: 4 : ScRangePairList* pOldList = bColumn ? pDoc->GetColNameRanges() : pDoc->GetRowNameRanges();
1130 [ + - ]: 4 : if (pOldList)
1131 : : {
1132 [ + - ]: 4 : ScRangePairListRef xNewList(pOldList->Clone());
1133 : :
1134 : 4 : ScRange aLabelRange;
1135 : 4 : ScRange aDataRange;
1136 : 4 : ScUnoConversion::FillScRange( aLabelRange, aLabelArea );
1137 : 4 : ScUnoConversion::FillScRange( aDataRange, aDataArea );
1138 [ + - ]: 4 : xNewList->Join( ScRangePair( aLabelRange, aDataRange ) );
1139 : :
1140 [ + - ]: 4 : if (bColumn)
1141 [ + - ]: 4 : pDoc->GetColNameRangesRef() = xNewList;
1142 : : else
1143 [ # # ]: 0 : pDoc->GetRowNameRangesRef() = xNewList;
1144 : :
1145 [ + - ]: 4 : pDoc->CompileColRowNameFormula();
1146 [ + - ]: 4 : pDocShell->PostPaint( 0,0,0, MAXCOL,MAXROW,MAXTAB, PAINT_GRID );
1147 [ + - ][ + - ]: 4 : pDocShell->SetDocumentModified();
1148 : :
1149 : : //! Undo ?!?! (hier und aus Dialog)
1150 : : }
1151 [ + - ]: 4 : }
1152 : 4 : }
1153 : :
1154 : 2 : void SAL_CALL ScLabelRangesObj::removeByIndex( sal_Int32 nIndex )
1155 : : throw(uno::RuntimeException)
1156 : : {
1157 [ + - ]: 2 : SolarMutexGuard aGuard;
1158 : 2 : sal_Bool bDone = false;
1159 [ + - ]: 2 : if (pDocShell)
1160 : : {
1161 : 2 : ScDocument* pDoc = pDocShell->GetDocument();
1162 [ + - ]: 2 : ScRangePairList* pOldList = bColumn ? pDoc->GetColNameRanges() : pDoc->GetRowNameRanges();
1163 : :
1164 [ + - ][ + - ]: 2 : if ( pOldList && nIndex >= 0 && nIndex < (sal_Int32)pOldList->size() )
[ + - ][ + + ]
[ + + ]
1165 : : {
1166 [ + - ]: 1 : ScRangePairListRef xNewList(pOldList->Clone());
1167 : :
1168 [ + - ]: 1 : ScRangePair* pEntry = (*xNewList)[nIndex];
1169 [ + - ]: 1 : if (pEntry)
1170 : : {
1171 [ + - ]: 1 : xNewList->Remove( pEntry );
1172 : 1 : delete pEntry;
1173 : :
1174 [ + - ]: 1 : if (bColumn)
1175 [ + - ]: 1 : pDoc->GetColNameRangesRef() = xNewList;
1176 : : else
1177 [ # # ]: 0 : pDoc->GetRowNameRangesRef() = xNewList;
1178 : :
1179 [ + - ]: 1 : pDoc->CompileColRowNameFormula();
1180 [ + - ]: 1 : pDocShell->PostPaint( 0,0,0, MAXCOL,MAXROW,MAXTAB, PAINT_GRID );
1181 [ + - ]: 1 : pDocShell->SetDocumentModified();
1182 : 1 : bDone = sal_True;
1183 : :
1184 : : //! Undo ?!?! (hier und aus Dialog)
1185 [ + - ]: 1 : }
1186 : : }
1187 : : }
1188 [ + + ]: 2 : if (!bDone)
1189 [ + - ][ + - ]: 2 : throw uno::RuntimeException(); // no other exceptions specified
1190 : 1 : }
1191 : :
1192 : : // container::XEnumerationAccess
1193 : :
1194 : 2 : uno::Reference<container::XEnumeration> SAL_CALL ScLabelRangesObj::createEnumeration()
1195 : : throw(uno::RuntimeException)
1196 : : {
1197 [ + - ]: 2 : SolarMutexGuard aGuard;
1198 [ + - ][ + - ]: 2 : return new ScIndexEnumeration(this, rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.sheet.LabelRangesEnumeration")));
[ + - ][ + - ]
[ + - ][ + - ]
1199 : : }
1200 : :
1201 : : // container::XIndexAccess
1202 : :
1203 : 16 : sal_Int32 SAL_CALL ScLabelRangesObj::getCount() throw(uno::RuntimeException)
1204 : : {
1205 [ + - ]: 16 : SolarMutexGuard aGuard;
1206 [ + - ]: 16 : if (pDocShell)
1207 : : {
1208 : 16 : ScDocument* pDoc = pDocShell->GetDocument();
1209 [ + + ]: 16 : ScRangePairList* pList = bColumn ? pDoc->GetColNameRanges() : pDoc->GetRowNameRanges();
1210 [ + - ]: 16 : if (pList)
1211 [ + - ]: 16 : return pList->size();
1212 : : }
1213 [ + - ]: 16 : return 0;
1214 : : }
1215 : :
1216 : 7 : uno::Any SAL_CALL ScLabelRangesObj::getByIndex( sal_Int32 nIndex )
1217 : : throw(lang::IndexOutOfBoundsException,
1218 : : lang::WrappedTargetException, uno::RuntimeException)
1219 : : {
1220 [ + - ]: 7 : SolarMutexGuard aGuard;
1221 [ + - ][ + + ]: 7 : uno::Reference< sheet::XLabelRange > xRange(GetObjectByIndex_Impl((sal_uInt16)nIndex));
[ + - ]
1222 [ + + ]: 7 : if ( xRange.is() )
1223 [ + - ]: 10 : return uno::makeAny(xRange);
1224 : : else
1225 [ + - ][ + - ]: 7 : throw lang::IndexOutOfBoundsException();
1226 : : }
1227 : :
1228 : 1 : uno::Type SAL_CALL ScLabelRangesObj::getElementType() throw(uno::RuntimeException)
1229 : : {
1230 [ + - ]: 1 : SolarMutexGuard aGuard;
1231 [ + - ][ + - ]: 1 : return ::getCppuType((const uno::Reference< sheet::XLabelRange >*)0); // muss zu getByIndex passen
1232 : :
1233 : : }
1234 : :
1235 : 1 : sal_Bool SAL_CALL ScLabelRangesObj::hasElements() throw(uno::RuntimeException)
1236 : : {
1237 [ + - ]: 1 : SolarMutexGuard aGuard;
1238 [ + - ][ + - ]: 1 : return ( getCount() != 0 );
1239 : : }
1240 : :
1241 : : //------------------------------------------------------------------------
1242 : :
1243 : :
1244 : :
1245 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|