1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <svl/smplhint.hxx>
21 #include <vcl/svapp.hxx>
23 #include <com/sun/star/sheet/NamedRangeFlag.hpp>
24 #include <com/sun/star/awt/XBitmap.hpp>
25 #include <com/sun/star/beans/PropertyAttribute.hpp>
27 #include <comphelper/servicehelper.hxx>
28 #include <cppuhelper/supportsservice.hxx>
30 using namespace ::com::sun::star
;
31 using ::com::sun::star::uno::Reference
;
32 using ::com::sun::star::uno::Any
;
34 #include "nameuno.hxx"
35 #include "miscuno.hxx"
36 #include "cellsuno.hxx"
37 #include "convuno.hxx"
38 #include "targuno.hxx"
39 #include "tokenuno.hxx"
40 #include "tokenarray.hxx"
42 #include "docfunc.hxx"
43 #include "rangenam.hxx"
44 #include "unonames.hxx"
46 #include "scui_def.hxx"
48 static const SfxItemPropertyMapEntry
* lcl_GetNamedRangeMap()
50 static const SfxItemPropertyMapEntry aNamedRangeMap_Impl
[] =
52 {OUString(SC_UNO_LINKDISPBIT
), 0, cppu::UnoType
<awt::XBitmap
>::get(), beans::PropertyAttribute::READONLY
, 0 },
53 {OUString(SC_UNO_LINKDISPNAME
), 0, cppu::UnoType
<OUString
>::get(), beans::PropertyAttribute::READONLY
, 0 },
54 {OUString(SC_UNONAME_TOKENINDEX
), 0, cppu::UnoType
<sal_Int32
>::get(), beans::PropertyAttribute::READONLY
, 0 },
55 {OUString(SC_UNONAME_ISSHAREDFMLA
), 0, cppu::UnoType
<bool>::get(), 0, 0 },
56 { OUString(), 0, css::uno::Type(), 0, 0 }
58 return aNamedRangeMap_Impl
;
61 static const SfxItemPropertyMapEntry
* lcl_GetNamedRangesMap()
63 static const SfxItemPropertyMapEntry aNamedRangesMap_Impl
[] =
65 {OUString(SC_UNO_MODIFY_BROADCAST
), 0, cppu::UnoType
<bool>::get(), 0, 0 },
66 { OUString(), 0, css::uno::Type(), 0, 0 }
68 return aNamedRangesMap_Impl
;
71 #define SCNAMEDRANGEOBJ_SERVICE "com.sun.star.sheet.NamedRange"
73 SC_SIMPLE_SERVICE_INFO( ScLabelRangeObj
, "ScLabelRangeObj", "com.sun.star.sheet.LabelRange" )
74 SC_SIMPLE_SERVICE_INFO( ScLabelRangesObj
, "ScLabelRangesObj", "com.sun.star.sheet.LabelRanges" )
75 SC_SIMPLE_SERVICE_INFO( ScNamedRangesObj
, "ScNamedRangesObj", "com.sun.star.sheet.NamedRanges" )
77 static bool lcl_UserVisibleName(const ScRangeData
& rData
)
79 //! as method to ScRangeData
81 return !rData
.HasType(RT_DATABASE
);
84 ScNamedRangeObj::ScNamedRangeObj( rtl::Reference
< ScNamedRangesObj
> xParent
, ScDocShell
* pDocSh
, const OUString
& rNm
, Reference
<container::XNamed
> xSheet
):
90 pDocShell
->GetDocument().AddUnoObject(*this);
93 ScNamedRangeObj::~ScNamedRangeObj()
98 pDocShell
->GetDocument().RemoveUnoObject(*this);
101 void ScNamedRangeObj::Notify( SfxBroadcaster
&, const SfxHint
& rHint
)
103 // reference update is of no interest
105 const SfxSimpleHint
* pSimpleHint
= dynamic_cast<const SfxSimpleHint
*>(&rHint
);
106 if ( pSimpleHint
&& pSimpleHint
->GetId() == SFX_HINT_DYING
)
107 pDocShell
= NULL
; // became invalid
112 ScRangeData
* ScNamedRangeObj::GetRangeData_Impl()
114 ScRangeData
* pRet
= NULL
;
118 SCTAB nTab
= GetTab_Impl();
120 pNames
= pDocShell
->GetDocument().GetRangeName(nTab
);
122 pNames
= pDocShell
->GetDocument().GetRangeName();
125 pRet
= pNames
->findByUpperName(ScGlobal::pCharClass
->uppercase(aName
));
127 pRet
->ValidateTabRefs(); // adjust relative tab refs to valid tables
133 SCTAB
ScNamedRangeObj::GetTab_Impl()
139 ScDocument
& rDoc
= pDocShell
->GetDocument();
141 OUString sName
= mxSheet
->getName();
142 bool bFound
= rDoc
.GetTable(sName
, nTab
);
143 assert(bFound
); (void)bFound
; // fouled up?
147 return -1;//global range name
150 // sheet::XNamedRange
152 void ScNamedRangeObj::Modify_Impl( const OUString
* pNewName
, const ScTokenArray
* pNewTokens
, const OUString
* pNewContent
,
153 const ScAddress
* pNewPos
, const sal_uInt16
* pNewType
,
154 const formula::FormulaGrammar::Grammar eGrammar
)
159 ScDocument
& rDoc
= pDocShell
->GetDocument();
161 SCTAB nTab
= GetTab_Impl();
163 pNames
= rDoc
.GetRangeName(nTab
);
165 pNames
= rDoc
.GetRangeName();
169 const ScRangeData
* pOld
= pNames
->findByUpperName(ScGlobal::pCharClass
->uppercase(aName
));
173 ScRangeName
* pNewRanges
= new ScRangeName(*pNames
);
175 OUString aInsName
= pOld
->GetName();
177 aInsName
= *pNewName
;
179 OUString aContent
; // Content string based =>
180 pOld
->GetSymbol( aContent
, eGrammar
); // no problems with changed positions and such.
182 aContent
= *pNewContent
;
184 ScAddress aPos
= pOld
->GetPos();
188 sal_uInt16 nType
= pOld
->GetType();
192 ScRangeData
* pNew
= NULL
;
194 pNew
= new ScRangeData( &rDoc
, aInsName
, *pNewTokens
, aPos
, nType
);
196 pNew
= new ScRangeData( &rDoc
, aInsName
, aContent
, aPos
, nType
, eGrammar
);
198 pNew
->SetIndex( pOld
->GetIndex() );
200 pNewRanges
->erase(*pOld
);
201 if (pNewRanges
->insert(pNew
))
203 pDocShell
->GetDocFunc().SetNewRangeNames(pNewRanges
, mxParent
->IsModifyAndBroadcast(), nTab
);
205 aName
= aInsName
; //! broadcast?
209 pNew
= NULL
; //! uno::Exception/Error or something
214 OUString SAL_CALL
ScNamedRangeObj::getName() throw(uno::RuntimeException
, std::exception
)
216 SolarMutexGuard aGuard
;
220 void SAL_CALL
ScNamedRangeObj::setName( const OUString
& aNewName
)
221 throw (uno::RuntimeException
, std::exception
)
223 SolarMutexGuard aGuard
;
224 //! adapt formulas ?????
226 OUString
aNewStr(aNewName
);
227 // GRAM_PODF_A1 for API compatibility.
228 Modify_Impl( &aNewStr
, NULL
, NULL
, NULL
, NULL
,formula::FormulaGrammar::GRAM_PODF_A1
);
230 if ( aName
!= aNewStr
) // some error occurred...
231 throw uno::RuntimeException(); // no other exceptions specified
234 OUString SAL_CALL
ScNamedRangeObj::getContent() throw(uno::RuntimeException
, std::exception
)
236 SolarMutexGuard aGuard
;
238 ScRangeData
* pData
= GetRangeData_Impl();
240 // GRAM_PODF_A1 for API compatibility.
241 pData
->GetSymbol( aContent
,formula::FormulaGrammar::GRAM_PODF_A1
);
245 void SAL_CALL
ScNamedRangeObj::setContent( const OUString
& aContent
)
246 throw (uno::RuntimeException
, std::exception
)
248 SolarMutexGuard aGuard
;
249 OUString
aContStr(aContent
);
250 // GRAM_PODF_A1 for API compatibility.
251 Modify_Impl( NULL
, NULL
, &aContStr
, NULL
, NULL
,formula::FormulaGrammar::GRAM_PODF_A1
);
254 table::CellAddress SAL_CALL
ScNamedRangeObj::getReferencePosition()
255 throw(uno::RuntimeException
, std::exception
)
257 SolarMutexGuard aGuard
;
259 ScRangeData
* pData
= GetRangeData_Impl();
261 aPos
= pData
->GetPos();
262 table::CellAddress aAddress
;
263 aAddress
.Column
= aPos
.Col();
264 aAddress
.Row
= aPos
.Row();
265 aAddress
.Sheet
= aPos
.Tab();
268 SCTAB nDocTabs
= pDocShell
->GetDocument().GetTableCount();
269 if ( aAddress
.Sheet
>= nDocTabs
&& nDocTabs
> 0 )
271 // Even after ValidateTabRefs, the position can be invalid if
272 // the content points to preceding tables. The resulting string
273 // is invalid in any case, so the position is just shifted.
274 aAddress
.Sheet
= nDocTabs
- 1;
280 void SAL_CALL
ScNamedRangeObj::setReferencePosition( const table::CellAddress
& aReferencePosition
)
281 throw (uno::RuntimeException
, std::exception
)
283 SolarMutexGuard aGuard
;
284 ScAddress
aPos( (SCCOL
)aReferencePosition
.Column
, (SCROW
)aReferencePosition
.Row
, aReferencePosition
.Sheet
);
285 // GRAM_PODF_A1 for API compatibility.
286 Modify_Impl( NULL
, NULL
, NULL
, &aPos
, NULL
,formula::FormulaGrammar::GRAM_PODF_A1
);
289 sal_Int32 SAL_CALL
ScNamedRangeObj::getType() throw(uno::RuntimeException
, std::exception
)
291 SolarMutexGuard aGuard
;
293 ScRangeData
* pData
= GetRangeData_Impl();
296 // do not return internal RT_* flags
297 // see property 'IsSharedFormula' for RT_SHARED
298 if ( pData
->HasType(RT_CRITERIA
) ) nType
|= sheet::NamedRangeFlag::FILTER_CRITERIA
;
299 if ( pData
->HasType(RT_PRINTAREA
) ) nType
|= sheet::NamedRangeFlag::PRINT_AREA
;
300 if ( pData
->HasType(RT_COLHEADER
) ) nType
|= sheet::NamedRangeFlag::COLUMN_HEADER
;
301 if ( pData
->HasType(RT_ROWHEADER
) ) nType
|= sheet::NamedRangeFlag::ROW_HEADER
;
306 void SAL_CALL
ScNamedRangeObj::setType( sal_Int32 nUnoType
)
307 throw (uno::RuntimeException
, std::exception
)
309 // see property 'IsSharedFormula' for RT_SHARED
310 SolarMutexGuard aGuard
;
311 sal_uInt16 nNewType
= RT_NAME
;
312 if ( nUnoType
& sheet::NamedRangeFlag::FILTER_CRITERIA
) nNewType
|= RT_CRITERIA
;
313 if ( nUnoType
& sheet::NamedRangeFlag::PRINT_AREA
) nNewType
|= RT_PRINTAREA
;
314 if ( nUnoType
& sheet::NamedRangeFlag::COLUMN_HEADER
) nNewType
|= RT_COLHEADER
;
315 if ( nUnoType
& sheet::NamedRangeFlag::ROW_HEADER
) nNewType
|= RT_ROWHEADER
;
317 // GRAM_PODF_A1 for API compatibility.
318 Modify_Impl( NULL
, NULL
, NULL
, NULL
, &nNewType
,formula::FormulaGrammar::GRAM_PODF_A1
);
323 uno::Sequence
<sheet::FormulaToken
> SAL_CALL
ScNamedRangeObj::getTokens()
324 throw (uno::RuntimeException
, std::exception
)
326 SolarMutexGuard aGuard
;
327 uno::Sequence
<sheet::FormulaToken
> aSequence
;
328 ScRangeData
* pData
= GetRangeData_Impl();
329 if (pData
&& pDocShell
)
331 ScTokenArray
* pTokenArray
= pData
->GetCode();
333 (void)ScTokenConversion::ConvertToTokenSequence( pDocShell
->GetDocument(), aSequence
, *pTokenArray
);
338 void SAL_CALL
ScNamedRangeObj::setTokens( const uno::Sequence
<sheet::FormulaToken
>& rTokens
)
339 throw (uno::RuntimeException
, std::exception
)
341 SolarMutexGuard aGuard
;
344 ScTokenArray aTokenArray
;
345 (void)ScTokenConversion::ConvertToTokenArray( pDocShell
->GetDocument(), aTokenArray
, rTokens
);
346 // GRAM_PODF_A1 for API compatibility.
347 Modify_Impl( NULL
, &aTokenArray
, NULL
, NULL
, NULL
, formula::FormulaGrammar::GRAM_PODF_A1
);
353 uno::Reference
<table::XCellRange
> SAL_CALL
ScNamedRangeObj::getReferredCells()
354 throw(uno::RuntimeException
, std::exception
)
356 SolarMutexGuard aGuard
;
358 ScRangeData
* pData
= GetRangeData_Impl();
359 if ( pData
&& pData
->IsValidReference( aRange
) )
361 //! static function to create ScCellObj/ScCellRangeObj at ScCellRangeObj ???
363 if ( aRange
.aStart
== aRange
.aEnd
)
364 return new ScCellObj( pDocShell
, aRange
.aStart
);
366 return new ScCellRangeObj( pDocShell
, aRange
);
371 // beans::XPropertySet
373 uno::Reference
<beans::XPropertySetInfo
> SAL_CALL
ScNamedRangeObj::getPropertySetInfo()
374 throw(uno::RuntimeException
, std::exception
)
376 SolarMutexGuard aGuard
;
377 static uno::Reference
< beans::XPropertySetInfo
> aRef(new SfxItemPropertySetInfo( lcl_GetNamedRangeMap() ));
381 void SAL_CALL
ScNamedRangeObj::setPropertyValue(
382 const OUString
& rPropertyName
, const uno::Any
& /*aValue*/ )
383 throw(beans::UnknownPropertyException
, beans::PropertyVetoException
,
384 lang::IllegalArgumentException
, lang::WrappedTargetException
,
385 uno::RuntimeException
, std::exception
)
387 SolarMutexGuard aGuard
;
388 if ( rPropertyName
== SC_UNONAME_ISSHAREDFMLA
)
394 uno::Any SAL_CALL
ScNamedRangeObj::getPropertyValue( const OUString
& rPropertyName
)
395 throw(beans::UnknownPropertyException
, lang::WrappedTargetException
,
396 uno::RuntimeException
, std::exception
)
398 SolarMutexGuard aGuard
;
400 if ( rPropertyName
== SC_UNO_LINKDISPBIT
)
402 // no target bitmaps for individual entries (would be all equal)
403 // ScLinkTargetTypeObj::SetLinkTargetBitmap( aRet, SC_LINKTARGETTYPE_RANGENAME );
405 else if ( rPropertyName
== SC_UNO_LINKDISPNAME
)
406 aRet
<<= OUString( aName
);
407 else if ( rPropertyName
== SC_UNONAME_TOKENINDEX
)
409 // get index for use in formula tokens (read-only)
410 ScRangeData
* pData
= GetRangeData_Impl();
412 aRet
<<= static_cast<sal_Int32
>(pData
->GetIndex());
414 else if ( rPropertyName
== SC_UNONAME_ISSHAREDFMLA
)
416 if (GetRangeData_Impl())
422 SC_IMPL_DUMMY_PROPERTY_LISTENER( ScNamedRangeObj
)
424 // lang::XServiceInfo
426 OUString SAL_CALL
ScNamedRangeObj::getImplementationName() throw(uno::RuntimeException
, std::exception
)
428 return OUString( "ScNamedRangeObj" );
431 sal_Bool SAL_CALL
ScNamedRangeObj::supportsService( const OUString
& rServiceName
)
432 throw(uno::RuntimeException
, std::exception
)
434 return cppu::supportsService(this, rServiceName
);
437 uno::Sequence
<OUString
> SAL_CALL
ScNamedRangeObj::getSupportedServiceNames()
438 throw(uno::RuntimeException
, std::exception
)
440 uno::Sequence
<OUString
> aRet(2);
441 aRet
[0] = SCNAMEDRANGEOBJ_SERVICE
;
442 aRet
[1] = SCLINKTARGET_SERVICE
;
448 sal_Int64 SAL_CALL
ScNamedRangeObj::getSomething(
449 const uno::Sequence
<sal_Int8
>& rId
) throw(uno::RuntimeException
, std::exception
)
451 if ( rId
.getLength() == 16 &&
452 0 == memcmp( getUnoTunnelId().getConstArray(),
453 rId
.getConstArray(), 16 ) )
455 return sal::static_int_cast
<sal_Int64
>(reinterpret_cast<sal_IntPtr
>(this));
462 class theScNamedRangeObjUnoTunnelId
: public rtl::Static
< UnoTunnelIdInit
, theScNamedRangeObjUnoTunnelId
> {};
465 const uno::Sequence
<sal_Int8
>& ScNamedRangeObj::getUnoTunnelId()
467 return theScNamedRangeObjUnoTunnelId::get().getSeq();
470 ScNamedRangesObj::ScNamedRangesObj(ScDocShell
* pDocSh
) :
471 mbModifyAndBroadcast(true),
474 pDocShell
->GetDocument().AddUnoObject(*this);
477 ScNamedRangesObj::~ScNamedRangesObj()
482 pDocShell
->GetDocument().RemoveUnoObject(*this);
485 void ScNamedRangesObj::Notify( SfxBroadcaster
&, const SfxHint
& rHint
)
487 // reference update is of no interest
489 const SfxSimpleHint
* pSimpleHint
= dynamic_cast<const SfxSimpleHint
*>(&rHint
);
490 if ( pSimpleHint
&& pSimpleHint
->GetId() == SFX_HINT_DYING
)
492 pDocShell
= NULL
; // became invalid
496 // sheet::XNamedRanges
498 void SAL_CALL
ScNamedRangesObj::addNewByName( const OUString
& aName
,
499 const OUString
& aContent
, const table::CellAddress
& aPosition
,
501 throw (uno::RuntimeException
, std::exception
)
503 SolarMutexGuard aGuard
;
504 ScAddress
aPos( (SCCOL
)aPosition
.Column
, (SCROW
)aPosition
.Row
, aPosition
.Sheet
);
506 sal_uInt16 nNewType
= RT_NAME
;
507 if ( nUnoType
& sheet::NamedRangeFlag::FILTER_CRITERIA
) nNewType
|= RT_CRITERIA
;
508 if ( nUnoType
& sheet::NamedRangeFlag::PRINT_AREA
) nNewType
|= RT_PRINTAREA
;
509 if ( nUnoType
& sheet::NamedRangeFlag::COLUMN_HEADER
) nNewType
|= RT_COLHEADER
;
510 if ( nUnoType
& sheet::NamedRangeFlag::ROW_HEADER
) nNewType
|= RT_ROWHEADER
;
515 ScDocument
& rDoc
= pDocShell
->GetDocument();
516 ScRangeName
* pNames
= GetRangeName_Impl();
517 if (pNames
&& !pNames
->findByUpperName(ScGlobal::pCharClass
->uppercase(aName
)))
519 ScRangeName
* pNewRanges
= new ScRangeName( *pNames
);
520 // GRAM_PODF_A1 for API compatibility.
521 ScRangeData
* pNew
= new ScRangeData( &rDoc
, aName
, aContent
,
522 aPos
, nNewType
,formula::FormulaGrammar::GRAM_PODF_A1
);
523 if ( pNewRanges
->insert(pNew
) )
525 pDocShell
->GetDocFunc().SetNewRangeNames(pNewRanges
, mbModifyAndBroadcast
, GetTab_Impl());
537 throw uno::RuntimeException(); // no other exceptions specified
540 void SAL_CALL
ScNamedRangesObj::addNewFromTitles( const table::CellRangeAddress
& aSource
,
541 sheet::Border aBorder
) throw(uno::RuntimeException
, std::exception
)
543 SolarMutexGuard aGuard
;
544 //! this cannot be an enum, because multiple bits can be set !!!
546 bool bTop
= ( aBorder
== sheet::Border_TOP
);
547 bool bLeft
= ( aBorder
== sheet::Border_LEFT
);
548 bool bBottom
= ( aBorder
== sheet::Border_BOTTOM
);
549 bool bRight
= ( aBorder
== sheet::Border_RIGHT
);
552 ScUnoConversion::FillScRange( aRange
, aSource
);
554 sal_uInt16 nFlags
= 0;
555 if (bTop
) nFlags
|= NAME_TOP
;
556 if (bLeft
) nFlags
|= NAME_LEFT
;
557 if (bBottom
) nFlags
|= NAME_BOTTOM
;
558 if (bRight
) nFlags
|= NAME_RIGHT
;
561 pDocShell
->GetDocFunc().CreateNames( aRange
, nFlags
, true, GetTab_Impl() );
564 void SAL_CALL
ScNamedRangesObj::removeByName( const OUString
& aName
)
565 throw(uno::RuntimeException
, std::exception
)
567 SolarMutexGuard aGuard
;
571 ScRangeName
* pNames
= GetRangeName_Impl();
574 const ScRangeData
* pData
= pNames
->findByUpperName(ScGlobal::pCharClass
->uppercase(aName
));
575 if (pData
&& lcl_UserVisibleName(*pData
))
577 ScRangeName
* pNewRanges
= new ScRangeName(*pNames
);
578 pNewRanges
->erase(*pData
);
579 pDocShell
->GetDocFunc().SetNewRangeNames( pNewRanges
, mbModifyAndBroadcast
, GetTab_Impl());
586 throw uno::RuntimeException(); // no other exceptions specified
589 void SAL_CALL
ScNamedRangesObj::outputList( const table::CellAddress
& aOutputPosition
)
590 throw(uno::RuntimeException
, std::exception
)
592 SolarMutexGuard aGuard
;
593 ScAddress
aPos( (SCCOL
)aOutputPosition
.Column
, (SCROW
)aOutputPosition
.Row
, aOutputPosition
.Sheet
);
595 pDocShell
->GetDocFunc().InsertNameList( aPos
, true );
598 // container::XEnumerationAccess
600 uno::Reference
<container::XEnumeration
> SAL_CALL
ScNamedRangesObj::createEnumeration()
601 throw(uno::RuntimeException
, std::exception
)
603 SolarMutexGuard aGuard
;
604 return new ScIndexEnumeration(this, OUString("com.sun.star.sheet.NamedRangesEnumeration"));
607 // container::XIndexAccess
609 sal_Int32 SAL_CALL
ScNamedRangesObj::getCount() throw(uno::RuntimeException
, std::exception
)
611 SolarMutexGuard aGuard
;
615 ScRangeName
* pNames
= GetRangeName_Impl();
618 ScRangeName::const_iterator itr
= pNames
->begin(), itrEnd
= pNames
->end();
619 for (; itr
!= itrEnd
; ++itr
)
620 if (lcl_UserVisibleName(*itr
->second
))
627 uno::Any SAL_CALL
ScNamedRangesObj::getByIndex( sal_Int32 nIndex
)
628 throw(lang::IndexOutOfBoundsException
,
629 lang::WrappedTargetException
, uno::RuntimeException
, std::exception
)
631 SolarMutexGuard aGuard
;
632 uno::Reference
< sheet::XNamedRange
> xRange(GetObjectByIndex_Impl((sal_uInt16
)nIndex
));
634 return uno::makeAny(xRange
);
636 throw lang::IndexOutOfBoundsException();
639 uno::Type SAL_CALL
ScNamedRangesObj::getElementType() throw(uno::RuntimeException
, std::exception
)
641 SolarMutexGuard aGuard
;
642 return cppu::UnoType
<sheet::XNamedRange
>::get(); // must be suitable for getByIndex
645 sal_Bool SAL_CALL
ScNamedRangesObj::hasElements() throw(uno::RuntimeException
, std::exception
)
647 SolarMutexGuard aGuard
;
648 return ( getCount() != 0 );
651 Reference
<beans::XPropertySetInfo
> SAL_CALL
ScNamedRangesObj::getPropertySetInfo()
652 throw(uno::RuntimeException
, std::exception
)
654 static Reference
<beans::XPropertySetInfo
> aRef(
655 new SfxItemPropertySetInfo(lcl_GetNamedRangesMap()));
659 void SAL_CALL
ScNamedRangesObj::setPropertyValue(
660 const OUString
& rPropertyName
, const uno::Any
& aValue
)
661 throw(beans::UnknownPropertyException
, beans::PropertyVetoException
,
662 lang::IllegalArgumentException
, lang::WrappedTargetException
,
663 uno::RuntimeException
, std::exception
)
665 if ( rPropertyName
== SC_UNO_MODIFY_BROADCAST
)
667 aValue
>>= mbModifyAndBroadcast
;
671 Any SAL_CALL
ScNamedRangesObj::getPropertyValue( const OUString
& rPropertyName
)
672 throw(beans::UnknownPropertyException
, lang::WrappedTargetException
,
673 uno::RuntimeException
, std::exception
)
676 if ( rPropertyName
== SC_UNO_MODIFY_BROADCAST
)
678 aRet
<<= mbModifyAndBroadcast
;
684 SC_IMPL_DUMMY_PROPERTY_LISTENER( ScNamedRangesObj
)
686 uno::Any SAL_CALL
ScNamedRangesObj::getByName( const OUString
& aName
)
687 throw(container::NoSuchElementException
,
688 lang::WrappedTargetException
, uno::RuntimeException
, std::exception
)
690 SolarMutexGuard aGuard
;
691 uno::Reference
< sheet::XNamedRange
> xRange(GetObjectByName_Impl(aName
));
693 return uno::makeAny(xRange
);
695 throw container::NoSuchElementException();
698 uno::Sequence
<OUString
> SAL_CALL
ScNamedRangesObj::getElementNames()
699 throw(uno::RuntimeException
, std::exception
)
701 SolarMutexGuard aGuard
;
704 ScRangeName
* pNames
= GetRangeName_Impl();
707 long nVisCount
= getCount(); // names with lcl_UserVisibleName
708 uno::Sequence
<OUString
> aSeq(nVisCount
);
709 OUString
* pAry
= aSeq
.getArray();
710 sal_uInt16 nVisPos
= 0;
711 ScRangeName::const_iterator itr
= pNames
->begin(), itrEnd
= pNames
->end();
712 for (; itr
!= itrEnd
; ++itr
)
714 if (lcl_UserVisibleName(*itr
->second
))
715 pAry
[nVisPos
++] = itr
->second
->GetName();
720 return uno::Sequence
<OUString
>(0);
723 sal_Bool SAL_CALL
ScNamedRangesObj::hasByName( const OUString
& aName
)
724 throw(uno::RuntimeException
, std::exception
)
726 SolarMutexGuard aGuard
;
729 ScRangeName
* pNames
= GetRangeName_Impl();
732 const ScRangeData
* pData
= pNames
->findByUpperName(ScGlobal::pCharClass
->uppercase(aName
));
733 if (pData
&& lcl_UserVisibleName(*pData
))
740 /** called from the XActionLockable interface methods on initial locking */
741 void ScNamedRangesObj::lock()
743 pDocShell
->GetDocument().PreprocessRangeNameUpdate();
746 /** called from the XActionLockable interface methods on final unlock */
747 void ScNamedRangesObj::unlock()
749 pDocShell
->GetDocument().CompileHybridFormula();
752 // document::XActionLockable
754 sal_Bool
ScNamedRangesObj::isActionLocked() throw(uno::RuntimeException
, std::exception
)
756 SolarMutexGuard aGuard
;
757 return pDocShell
->GetDocument().GetNamedRangesLockCount() != 0;
760 void ScNamedRangesObj::addActionLock() throw(uno::RuntimeException
, std::exception
)
762 SolarMutexGuard aGuard
;
763 ScDocument
& rDoc
= pDocShell
->GetDocument();
764 sal_Int16 nLockCount
= rDoc
.GetNamedRangesLockCount();
766 if ( nLockCount
== 1 )
770 rDoc
.SetNamedRangesLockCount( nLockCount
);
773 void ScNamedRangesObj::removeActionLock() throw(uno::RuntimeException
, std::exception
)
775 SolarMutexGuard aGuard
;
776 ScDocument
& rDoc
= pDocShell
->GetDocument();
777 sal_Int16 nLockCount
= rDoc
.GetNamedRangesLockCount();
778 if ( nLockCount
> 0 )
781 if ( nLockCount
== 0 )
785 rDoc
.SetNamedRangesLockCount( nLockCount
);
789 void ScNamedRangesObj::setActionLocks( sal_Int16 nLock
) throw(uno::RuntimeException
, std::exception
)
791 SolarMutexGuard aGuard
;
794 ScDocument
& rDoc
= pDocShell
->GetDocument();
795 sal_Int16 nLockCount
= rDoc
.GetNamedRangesLockCount();
796 if ( nLock
== 0 && nLockCount
> 0 )
800 if ( nLock
> 0 && nLockCount
== 0 )
804 rDoc
.SetNamedRangesLockCount( nLock
);
808 sal_Int16
ScNamedRangesObj::resetActionLocks() throw(uno::RuntimeException
, std::exception
)
810 SolarMutexGuard aGuard
;
811 ScDocument
& rDoc
= pDocShell
->GetDocument();
812 sal_Int16 nLockCount
= rDoc
.GetNamedRangesLockCount();
813 if ( nLockCount
> 0 )
817 rDoc
.SetNamedRangesLockCount( 0 );
821 ScGlobalNamedRangesObj::ScGlobalNamedRangesObj(ScDocShell
* pDocSh
)
822 : ScNamedRangesObj(pDocSh
)
827 ScGlobalNamedRangesObj::~ScGlobalNamedRangesObj()
832 ScNamedRangeObj
* ScGlobalNamedRangesObj::GetObjectByIndex_Impl(sal_uInt16 nIndex
)
837 ScRangeName
* pNames
= pDocShell
->GetDocument().GetRangeName();
841 ScRangeName::const_iterator itr
= pNames
->begin(), itrEnd
= pNames
->end();
843 for (; itr
!= itrEnd
; ++itr
)
845 if (lcl_UserVisibleName(*itr
->second
))
848 return new ScNamedRangeObj(this, pDocShell
, itr
->second
->GetName());
855 ScNamedRangeObj
* ScGlobalNamedRangesObj::GetObjectByName_Impl(const OUString
& aName
)
857 if ( pDocShell
&& hasByName(aName
) )
858 return new ScNamedRangeObj(this, pDocShell
, aName
);
862 ScRangeName
* ScGlobalNamedRangesObj::GetRangeName_Impl()
864 return pDocShell
->GetDocument().GetRangeName();
867 SCTAB
ScGlobalNamedRangesObj::GetTab_Impl()
872 ScLocalNamedRangesObj::ScLocalNamedRangesObj( ScDocShell
* pDocSh
, uno::Reference
<container::XNamed
> xSheet
)
873 : ScNamedRangesObj(pDocSh
),
879 ScLocalNamedRangesObj::~ScLocalNamedRangesObj()
884 ScNamedRangeObj
* ScLocalNamedRangesObj::GetObjectByName_Impl(const OUString
& aName
)
886 if ( pDocShell
&& hasByName( aName
) )
887 return new ScNamedRangeObj( this, pDocShell
, aName
, mxSheet
);
892 ScNamedRangeObj
* ScLocalNamedRangesObj::GetObjectByIndex_Impl( sal_uInt16 nIndex
)
897 OUString aName
= mxSheet
->getName();
898 ScDocument
& rDoc
= pDocShell
->GetDocument();
900 if (!rDoc
.GetTable(aName
, nTab
))
903 ScRangeName
* pNames
= rDoc
.GetRangeName( nTab
);
907 ScRangeName::const_iterator itr
= pNames
->begin(), itrEnd
= pNames
->end();
909 for (; itr
!= itrEnd
; ++itr
)
911 if (lcl_UserVisibleName(*itr
->second
))
914 return new ScNamedRangeObj(this, pDocShell
, itr
->second
->GetName(), mxSheet
);
921 ScRangeName
* ScLocalNamedRangesObj::GetRangeName_Impl()
923 SCTAB nTab
= GetTab_Impl();
924 return pDocShell
->GetDocument().GetRangeName( nTab
);
927 SCTAB
ScLocalNamedRangesObj::GetTab_Impl()
930 (void)pDocShell
->GetDocument().GetTable(mxSheet
->getName(), nTab
);
934 ScLabelRangeObj::ScLabelRangeObj(ScDocShell
* pDocSh
, bool bCol
, const ScRange
& rR
) :
939 pDocShell
->GetDocument().AddUnoObject(*this);
942 ScLabelRangeObj::~ScLabelRangeObj()
947 pDocShell
->GetDocument().RemoveUnoObject(*this);
950 void ScLabelRangeObj::Notify( SfxBroadcaster
&, const SfxHint
& rHint
)
954 const SfxSimpleHint
* pSimpleHint
= dynamic_cast<const SfxSimpleHint
*>(&rHint
);
955 if ( pSimpleHint
&& pSimpleHint
->GetId() == SFX_HINT_DYING
)
956 pDocShell
= NULL
; // became invalid
961 ScRangePair
* ScLabelRangeObj::GetData_Impl()
963 ScRangePair
* pRet
= NULL
;
966 ScDocument
& rDoc
= pDocShell
->GetDocument();
967 ScRangePairList
* pList
= bColumn
? rDoc
.GetColNameRanges() : rDoc
.GetRowNameRanges();
969 pRet
= pList
->Find( aRange
);
974 void ScLabelRangeObj::Modify_Impl( const ScRange
* pLabel
, const ScRange
* pData
)
978 ScDocument
& rDoc
= pDocShell
->GetDocument();
979 ScRangePairList
* pOldList
= bColumn
? rDoc
.GetColNameRanges() : rDoc
.GetRowNameRanges();
982 ScRangePairListRef
xNewList(pOldList
->Clone());
983 ScRangePair
* pEntry
= xNewList
->Find( aRange
);
986 xNewList
->Remove( pEntry
); // only removed from list, not deleted
989 pEntry
->GetRange(0) = *pLabel
;
991 pEntry
->GetRange(1) = *pData
;
993 xNewList
->Join( *pEntry
);
997 rDoc
.GetColNameRangesRef() = xNewList
;
999 rDoc
.GetRowNameRangesRef() = xNewList
;
1001 rDoc
.CompileColRowNameFormula();
1002 pDocShell
->PostPaint( 0,0,0, MAXCOL
,MAXROW
,MAXTAB
, PAINT_GRID
);
1003 pDocShell
->SetDocumentModified();
1005 //! Undo ?!?! (here and from dialog)
1008 aRange
= *pLabel
; // adapt object to find range again
1014 // sheet::XLabelRange
1016 table::CellRangeAddress SAL_CALL
ScLabelRangeObj::getLabelArea()
1017 throw(uno::RuntimeException
, std::exception
)
1019 SolarMutexGuard aGuard
;
1020 table::CellRangeAddress aRet
;
1021 ScRangePair
* pData
= GetData_Impl();
1023 ScUnoConversion::FillApiRange( aRet
, pData
->GetRange(0) );
1027 void SAL_CALL
ScLabelRangeObj::setLabelArea( const table::CellRangeAddress
& aLabelArea
)
1028 throw(uno::RuntimeException
, std::exception
)
1030 SolarMutexGuard aGuard
;
1031 ScRange aLabelRange
;
1032 ScUnoConversion::FillScRange( aLabelRange
, aLabelArea
);
1033 Modify_Impl( &aLabelRange
, NULL
);
1036 table::CellRangeAddress SAL_CALL
ScLabelRangeObj::getDataArea()
1037 throw(uno::RuntimeException
, std::exception
)
1039 SolarMutexGuard aGuard
;
1040 table::CellRangeAddress aRet
;
1041 ScRangePair
* pData
= GetData_Impl();
1043 ScUnoConversion::FillApiRange( aRet
, pData
->GetRange(1) );
1047 void SAL_CALL
ScLabelRangeObj::setDataArea( const table::CellRangeAddress
& aDataArea
)
1048 throw(uno::RuntimeException
, std::exception
)
1050 SolarMutexGuard aGuard
;
1052 ScUnoConversion::FillScRange( aDataRange
, aDataArea
);
1053 Modify_Impl( NULL
, &aDataRange
);
1056 ScLabelRangesObj::ScLabelRangesObj(ScDocShell
* pDocSh
, bool bCol
) :
1057 pDocShell( pDocSh
),
1060 pDocShell
->GetDocument().AddUnoObject(*this);
1063 ScLabelRangesObj::~ScLabelRangesObj()
1068 pDocShell
->GetDocument().RemoveUnoObject(*this);
1071 void ScLabelRangesObj::Notify( SfxBroadcaster
&, const SfxHint
& rHint
)
1073 // reference update is of no interest
1075 const SfxSimpleHint
* pSimpleHint
= dynamic_cast<const SfxSimpleHint
*>(&rHint
);
1076 if ( pSimpleHint
&& pSimpleHint
->GetId() == SFX_HINT_DYING
)
1078 pDocShell
= NULL
; // became invalid
1082 // sheet::XLabelRanges
1084 ScLabelRangeObj
* ScLabelRangesObj::GetObjectByIndex_Impl(size_t nIndex
)
1088 ScDocument
& rDoc
= pDocShell
->GetDocument();
1089 ScRangePairList
* pList
= bColumn
? rDoc
.GetColNameRanges() : rDoc
.GetRowNameRanges();
1090 if ( pList
&& nIndex
< pList
->size() )
1092 ScRangePair
* pData
= (*pList
)[nIndex
];
1094 return new ScLabelRangeObj( pDocShell
, bColumn
, pData
->GetRange(0) );
1100 void SAL_CALL
ScLabelRangesObj::addNew( const table::CellRangeAddress
& aLabelArea
,
1101 const table::CellRangeAddress
& aDataArea
)
1102 throw(uno::RuntimeException
, std::exception
)
1104 SolarMutexGuard aGuard
;
1107 ScDocument
& rDoc
= pDocShell
->GetDocument();
1108 ScRangePairList
* pOldList
= bColumn
? rDoc
.GetColNameRanges() : rDoc
.GetRowNameRanges();
1111 ScRangePairListRef
xNewList(pOldList
->Clone());
1113 ScRange aLabelRange
;
1115 ScUnoConversion::FillScRange( aLabelRange
, aLabelArea
);
1116 ScUnoConversion::FillScRange( aDataRange
, aDataArea
);
1117 xNewList
->Join( ScRangePair( aLabelRange
, aDataRange
) );
1120 rDoc
.GetColNameRangesRef() = xNewList
;
1122 rDoc
.GetRowNameRangesRef() = xNewList
;
1124 rDoc
.CompileColRowNameFormula();
1125 pDocShell
->PostPaint( 0,0,0, MAXCOL
,MAXROW
,MAXTAB
, PAINT_GRID
);
1126 pDocShell
->SetDocumentModified();
1128 //! Undo ?!?! (here and from dialog)
1133 void SAL_CALL
ScLabelRangesObj::removeByIndex( sal_Int32 nIndex
)
1134 throw(uno::RuntimeException
, std::exception
)
1136 SolarMutexGuard aGuard
;
1140 ScDocument
& rDoc
= pDocShell
->GetDocument();
1141 ScRangePairList
* pOldList
= bColumn
? rDoc
.GetColNameRanges() : rDoc
.GetRowNameRanges();
1143 if ( pOldList
&& nIndex
>= 0 && nIndex
< (sal_Int32
)pOldList
->size() )
1145 ScRangePairListRef
xNewList(pOldList
->Clone());
1147 ScRangePair
* pEntry
= (*xNewList
)[nIndex
];
1150 xNewList
->Remove( pEntry
);
1154 rDoc
.GetColNameRangesRef() = xNewList
;
1156 rDoc
.GetRowNameRangesRef() = xNewList
;
1158 rDoc
.CompileColRowNameFormula();
1159 pDocShell
->PostPaint( 0,0,0, MAXCOL
,MAXROW
,MAXTAB
, PAINT_GRID
);
1160 pDocShell
->SetDocumentModified();
1163 //! Undo ?!?! (here and from dialog)
1168 throw uno::RuntimeException(); // no other exceptions specified
1171 // container::XEnumerationAccess
1173 uno::Reference
<container::XEnumeration
> SAL_CALL
ScLabelRangesObj::createEnumeration()
1174 throw(uno::RuntimeException
, std::exception
)
1176 SolarMutexGuard aGuard
;
1177 return new ScIndexEnumeration(this, OUString("com.sun.star.sheet.LabelRangesEnumeration"));
1180 // container::XIndexAccess
1182 sal_Int32 SAL_CALL
ScLabelRangesObj::getCount() throw(uno::RuntimeException
, std::exception
)
1184 SolarMutexGuard aGuard
;
1187 ScDocument
& rDoc
= pDocShell
->GetDocument();
1188 ScRangePairList
* pList
= bColumn
? rDoc
.GetColNameRanges() : rDoc
.GetRowNameRanges();
1190 return pList
->size();
1195 uno::Any SAL_CALL
ScLabelRangesObj::getByIndex( sal_Int32 nIndex
)
1196 throw(lang::IndexOutOfBoundsException
,
1197 lang::WrappedTargetException
, uno::RuntimeException
, std::exception
)
1199 SolarMutexGuard aGuard
;
1200 uno::Reference
< sheet::XLabelRange
> xRange(GetObjectByIndex_Impl((sal_uInt16
)nIndex
));
1202 return uno::makeAny(xRange
);
1204 throw lang::IndexOutOfBoundsException();
1207 uno::Type SAL_CALL
ScLabelRangesObj::getElementType() throw(uno::RuntimeException
, std::exception
)
1209 SolarMutexGuard aGuard
;
1210 return cppu::UnoType
<sheet::XLabelRange
>::get(); // must be suitable for getByIndex
1214 sal_Bool SAL_CALL
ScLabelRangesObj::hasElements() throw(uno::RuntimeException
, std::exception
)
1216 SolarMutexGuard aGuard
;
1217 return ( getCount() != 0 );
1220 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */