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>
29 using namespace ::com::sun::star
;
30 using ::com::sun::star::uno::Reference
;
31 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 //------------------------------------------------------------------------
50 static const SfxItemPropertyMapEntry
* lcl_GetNamedRangeMap()
52 static SfxItemPropertyMapEntry aNamedRangeMap_Impl
[] =
54 {MAP_CHAR_LEN(SC_UNO_LINKDISPBIT
), 0, &getCppuType((uno::Reference
<awt::XBitmap
>*)0), beans::PropertyAttribute::READONLY
, 0 },
55 {MAP_CHAR_LEN(SC_UNO_LINKDISPNAME
), 0, &getCppuType((OUString
*)0), beans::PropertyAttribute::READONLY
, 0 },
56 {MAP_CHAR_LEN(SC_UNONAME_TOKENINDEX
), 0, &getCppuType((sal_Int32
*)0), beans::PropertyAttribute::READONLY
, 0 },
57 {MAP_CHAR_LEN(SC_UNONAME_ISSHAREDFMLA
), 0, &getBooleanCppuType(), 0, 0 },
60 return aNamedRangeMap_Impl
;
63 static const SfxItemPropertyMapEntry
* lcl_GetNamedRangesMap()
65 static SfxItemPropertyMapEntry aNamedRangesMap_Impl
[] =
67 {MAP_CHAR_LEN(SC_UNO_MODIFY_BROADCAST
), 0, &getBooleanCppuType(), 0, 0 },
70 return aNamedRangesMap_Impl
;
73 //------------------------------------------------------------------------
75 #define SCNAMEDRANGEOBJ_SERVICE "com.sun.star.sheet.NamedRange"
77 SC_SIMPLE_SERVICE_INFO( ScLabelRangeObj
, "ScLabelRangeObj", "com.sun.star.sheet.LabelRange" )
78 SC_SIMPLE_SERVICE_INFO( ScLabelRangesObj
, "ScLabelRangesObj", "com.sun.star.sheet.LabelRanges" )
79 SC_SIMPLE_SERVICE_INFO( ScNamedRangesObj
, "ScNamedRangesObj", "com.sun.star.sheet.NamedRanges" )
81 static bool lcl_UserVisibleName(const ScRangeData
& rData
)
83 //! als Methode an ScRangeData
85 return !rData
.HasType(RT_DATABASE
) && !rData
.HasType(RT_SHARED
);
88 ScNamedRangeObj::ScNamedRangeObj( rtl::Reference
< ScNamedRangesObj
> xParent
, ScDocShell
* pDocSh
, const String
& rNm
, Reference
<container::XNamed
> xSheet
):
94 pDocShell
->GetDocument()->AddUnoObject(*this);
97 ScNamedRangeObj::~ScNamedRangeObj()
100 pDocShell
->GetDocument()->RemoveUnoObject(*this);
103 void ScNamedRangeObj::Notify( SfxBroadcaster
&, const SfxHint
& rHint
)
105 // Ref-Update interessiert nicht
107 if ( rHint
.ISA( SfxSimpleHint
) && ((const SfxSimpleHint
&)rHint
).GetId() == SFX_HINT_DYING
)
108 pDocShell
= NULL
; // ungueltig geworden
113 ScRangeData
* ScNamedRangeObj::GetRangeData_Impl()
115 ScRangeData
* pRet
= NULL
;
119 SCTAB nTab
= GetTab_Impl();
121 pNames
= pDocShell
->GetDocument()->GetRangeName(nTab
);
123 pNames
= pDocShell
->GetDocument()->GetRangeName();
126 pRet
= pNames
->findByUpperName(ScGlobal::pCharClass
->uppercase(aName
));
128 pRet
->ValidateTabRefs(); // adjust relative tab refs to valid tables
134 SCTAB
ScNamedRangeObj::GetTab_Impl()
140 ScDocument
* pDoc
= pDocShell
->GetDocument();
142 OUString sName
= mxSheet
->getName();
143 pDoc
->GetTable(sName
, nTab
);
147 return -1;//global range name
150 // sheet::XNamedRange
152 void ScNamedRangeObj::Modify_Impl( const String
* pNewName
, const ScTokenArray
* pNewTokens
, const String
* pNewContent
,
153 const ScAddress
* pNewPos
, const sal_uInt16
* pNewType
,
154 const formula::FormulaGrammar::Grammar eGrammar
)
159 ScDocument
* pDoc
= pDocShell
->GetDocument();
161 SCTAB nTab
= GetTab_Impl();
163 pNames
= pDoc
->GetRangeName(nTab
);
165 pNames
= pDoc
->GetRangeName();
169 const ScRangeData
* pOld
= pNames
->findByUpperName(ScGlobal::pCharClass
->uppercase(aName
));
173 ScRangeName
* pNewRanges
= new ScRangeName(*pNames
);
175 String aInsName
= pOld
->GetName();
177 aInsName
= *pNewName
;
179 String 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( pDoc
, aInsName
, *pNewTokens
, aPos
, nType
);
196 pNew
= new ScRangeData( pDoc
, 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/Fehler oder so
215 OUString SAL_CALL
ScNamedRangeObj::getName() throw(uno::RuntimeException
)
217 SolarMutexGuard aGuard
;
221 void SAL_CALL
ScNamedRangeObj::setName( const OUString
& aNewName
)
222 throw(uno::RuntimeException
)
224 SolarMutexGuard aGuard
;
225 //! Formeln anpassen ?????
227 String
aNewStr(aNewName
);
228 // GRAM_PODF_A1 for API compatibility.
229 Modify_Impl( &aNewStr
, NULL
, NULL
, NULL
, NULL
,formula::FormulaGrammar::GRAM_PODF_A1
);
231 if ( aName
!= aNewStr
) // some error occurred...
232 throw uno::RuntimeException(); // no other exceptions specified
235 OUString SAL_CALL
ScNamedRangeObj::getContent() throw(uno::RuntimeException
)
237 SolarMutexGuard aGuard
;
239 ScRangeData
* pData
= GetRangeData_Impl();
241 // GRAM_PODF_A1 for API compatibility.
242 pData
->GetSymbol( aContent
,formula::FormulaGrammar::GRAM_PODF_A1
);
246 void SAL_CALL
ScNamedRangeObj::setContent( const OUString
& aContent
)
247 throw(uno::RuntimeException
)
249 SolarMutexGuard aGuard
;
250 String
aContStr(aContent
);
251 // GRAM_PODF_A1 for API compatibility.
252 Modify_Impl( NULL
, NULL
, &aContStr
, NULL
, NULL
,formula::FormulaGrammar::GRAM_PODF_A1
);
255 table::CellAddress SAL_CALL
ScNamedRangeObj::getReferencePosition()
256 throw(uno::RuntimeException
)
258 SolarMutexGuard aGuard
;
260 ScRangeData
* pData
= GetRangeData_Impl();
262 aPos
= pData
->GetPos();
263 table::CellAddress aAddress
;
264 aAddress
.Column
= aPos
.Col();
265 aAddress
.Row
= aPos
.Row();
266 aAddress
.Sheet
= aPos
.Tab();
269 SCTAB nDocTabs
= pDocShell
->GetDocument()->GetTableCount();
270 if ( aAddress
.Sheet
>= nDocTabs
&& nDocTabs
> 0 )
272 // Even after ValidateTabRefs, the position can be invalid if
273 // the content points to preceding tables. The resulting string
274 // is invalid in any case, so the position is just shifted.
275 aAddress
.Sheet
= nDocTabs
- 1;
281 void SAL_CALL
ScNamedRangeObj::setReferencePosition( const table::CellAddress
& aReferencePosition
)
282 throw(uno::RuntimeException
)
284 SolarMutexGuard aGuard
;
285 ScAddress
aPos( (SCCOL
)aReferencePosition
.Column
, (SCROW
)aReferencePosition
.Row
, aReferencePosition
.Sheet
);
286 // GRAM_PODF_A1 for API compatibility.
287 Modify_Impl( NULL
, NULL
, NULL
, &aPos
, NULL
,formula::FormulaGrammar::GRAM_PODF_A1
);
290 sal_Int32 SAL_CALL
ScNamedRangeObj::getType() throw(uno::RuntimeException
)
292 SolarMutexGuard aGuard
;
294 ScRangeData
* pData
= GetRangeData_Impl();
297 // do not return internal RT_* flags
298 // see property 'IsSharedFormula' for RT_SHARED
299 if ( pData
->HasType(RT_CRITERIA
) ) nType
|= sheet::NamedRangeFlag::FILTER_CRITERIA
;
300 if ( pData
->HasType(RT_PRINTAREA
) ) nType
|= sheet::NamedRangeFlag::PRINT_AREA
;
301 if ( pData
->HasType(RT_COLHEADER
) ) nType
|= sheet::NamedRangeFlag::COLUMN_HEADER
;
302 if ( pData
->HasType(RT_ROWHEADER
) ) nType
|= sheet::NamedRangeFlag::ROW_HEADER
;
307 void SAL_CALL
ScNamedRangeObj::setType( sal_Int32 nUnoType
) throw(uno::RuntimeException
)
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() throw(uno::RuntimeException
)
325 SolarMutexGuard aGuard
;
326 uno::Sequence
<sheet::FormulaToken
> aSequence
;
327 ScRangeData
* pData
= GetRangeData_Impl();
328 if (pData
&& pDocShell
)
330 ScTokenArray
* pTokenArray
= pData
->GetCode();
332 (void)ScTokenConversion::ConvertToTokenSequence( *pDocShell
->GetDocument(), aSequence
, *pTokenArray
);
337 void SAL_CALL
ScNamedRangeObj::setTokens( const uno::Sequence
<sheet::FormulaToken
>& rTokens
) throw(uno::RuntimeException
)
339 SolarMutexGuard aGuard
;
342 ScTokenArray aTokenArray
;
343 (void)ScTokenConversion::ConvertToTokenArray( *pDocShell
->GetDocument(), aTokenArray
, rTokens
);
344 // GRAM_PODF_A1 for API compatibility.
345 Modify_Impl( NULL
, &aTokenArray
, NULL
, NULL
, NULL
, formula::FormulaGrammar::GRAM_PODF_A1
);
352 uno::Reference
<table::XCellRange
> SAL_CALL
ScNamedRangeObj::getReferredCells()
353 throw(uno::RuntimeException
)
355 SolarMutexGuard aGuard
;
357 ScRangeData
* pData
= GetRangeData_Impl();
358 if ( pData
&& pData
->IsValidReference( aRange
) )
360 //! static Funktion um ScCellObj/ScCellRangeObj zu erzeugen am ScCellRangeObj ???
362 if ( aRange
.aStart
== aRange
.aEnd
)
363 return new ScCellObj( pDocShell
, aRange
.aStart
);
365 return new ScCellRangeObj( pDocShell
, aRange
);
370 // beans::XPropertySet
372 uno::Reference
<beans::XPropertySetInfo
> SAL_CALL
ScNamedRangeObj::getPropertySetInfo()
373 throw(uno::RuntimeException
)
375 SolarMutexGuard aGuard
;
376 static uno::Reference
< beans::XPropertySetInfo
> aRef(new SfxItemPropertySetInfo( lcl_GetNamedRangeMap() ));
380 void SAL_CALL
ScNamedRangeObj::setPropertyValue(
381 const OUString
& rPropertyName
, const uno::Any
& aValue
)
382 throw(beans::UnknownPropertyException
, beans::PropertyVetoException
,
383 lang::IllegalArgumentException
, lang::WrappedTargetException
,
384 uno::RuntimeException
)
386 SolarMutexGuard aGuard
;
387 if ( rPropertyName
== SC_UNONAME_ISSHAREDFMLA
)
389 bool bIsShared
= false;
390 if( aValue
>>= bIsShared
)
392 sal_uInt16 nNewType
= bIsShared
? RT_SHARED
: RT_NAME
;
393 Modify_Impl( NULL
, NULL
, NULL
, NULL
, &nNewType
,formula::FormulaGrammar::GRAM_PODF_A1
);
398 uno::Any SAL_CALL
ScNamedRangeObj::getPropertyValue( const OUString
& rPropertyName
)
399 throw(beans::UnknownPropertyException
, lang::WrappedTargetException
,
400 uno::RuntimeException
)
402 SolarMutexGuard aGuard
;
404 if ( rPropertyName
== SC_UNO_LINKDISPBIT
)
406 // no target bitmaps for individual entries (would be all equal)
407 // ScLinkTargetTypeObj::SetLinkTargetBitmap( aRet, SC_LINKTARGETTYPE_RANGENAME );
409 else if ( rPropertyName
== SC_UNO_LINKDISPNAME
)
410 aRet
<<= OUString( aName
);
411 else if ( rPropertyName
== SC_UNONAME_TOKENINDEX
)
413 // get index for use in formula tokens (read-only)
414 ScRangeData
* pData
= GetRangeData_Impl();
416 aRet
<<= static_cast<sal_Int32
>(pData
->GetIndex());
418 else if ( rPropertyName
== SC_UNONAME_ISSHAREDFMLA
)
420 if( ScRangeData
* pData
= GetRangeData_Impl() )
421 aRet
<<= static_cast< bool >( pData
->HasType( RT_SHARED
) );
426 SC_IMPL_DUMMY_PROPERTY_LISTENER( ScNamedRangeObj
)
428 // lang::XServiceInfo
430 OUString SAL_CALL
ScNamedRangeObj::getImplementationName() throw(uno::RuntimeException
)
432 return OUString( "ScNamedRangeObj" );
435 sal_Bool SAL_CALL
ScNamedRangeObj::supportsService( const OUString
& rServiceName
)
436 throw(uno::RuntimeException
)
438 return rServiceName
.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( SCNAMEDRANGEOBJ_SERVICE
) ) ||
439 rServiceName
.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( SCLINKTARGET_SERVICE
) );
442 uno::Sequence
<OUString
> SAL_CALL
ScNamedRangeObj::getSupportedServiceNames()
443 throw(uno::RuntimeException
)
445 uno::Sequence
<OUString
> aRet(2);
446 aRet
[0] = OUString( SCNAMEDRANGEOBJ_SERVICE
);
447 aRet
[1] = OUString( SCLINKTARGET_SERVICE
);
454 sal_Int64 SAL_CALL
ScNamedRangeObj::getSomething(
455 const uno::Sequence
<sal_Int8
>& rId
) throw(uno::RuntimeException
)
457 if ( rId
.getLength() == 16 &&
458 0 == memcmp( getUnoTunnelId().getConstArray(),
459 rId
.getConstArray(), 16 ) )
461 return sal::static_int_cast
<sal_Int64
>(reinterpret_cast<sal_IntPtr
>(this));
468 class theScNamedRangeObjUnoTunnelId
: public rtl::Static
< UnoTunnelIdInit
, theScNamedRangeObjUnoTunnelId
> {};
471 const uno::Sequence
<sal_Int8
>& ScNamedRangeObj::getUnoTunnelId()
473 return theScNamedRangeObjUnoTunnelId::get().getSeq();
476 //------------------------------------------------------------------------
478 ScNamedRangesObj::ScNamedRangesObj(ScDocShell
* pDocSh
) :
479 mbModifyAndBroadcast(true),
482 pDocShell
->GetDocument()->AddUnoObject(*this);
485 ScNamedRangesObj::~ScNamedRangesObj()
488 pDocShell
->GetDocument()->RemoveUnoObject(*this);
491 void ScNamedRangesObj::Notify( SfxBroadcaster
&, const SfxHint
& rHint
)
493 // Referenz-Update interessiert hier nicht
495 if ( rHint
.ISA( SfxSimpleHint
) &&
496 ((const SfxSimpleHint
&)rHint
).GetId() == SFX_HINT_DYING
)
498 pDocShell
= NULL
; // ungueltig geworden
502 bool ScNamedRangesObj::IsModifyAndBroadcast() const
504 return mbModifyAndBroadcast
;
507 // sheet::XNamedRanges
509 void SAL_CALL
ScNamedRangesObj::addNewByName( const OUString
& aName
,
510 const OUString
& aContent
, const table::CellAddress
& aPosition
,
511 sal_Int32 nUnoType
) throw(uno::RuntimeException
)
513 SolarMutexGuard aGuard
;
514 ScAddress
aPos( (SCCOL
)aPosition
.Column
, (SCROW
)aPosition
.Row
, aPosition
.Sheet
);
516 sal_uInt16 nNewType
= RT_NAME
;
517 if ( nUnoType
& sheet::NamedRangeFlag::FILTER_CRITERIA
) nNewType
|= RT_CRITERIA
;
518 if ( nUnoType
& sheet::NamedRangeFlag::PRINT_AREA
) nNewType
|= RT_PRINTAREA
;
519 if ( nUnoType
& sheet::NamedRangeFlag::COLUMN_HEADER
) nNewType
|= RT_COLHEADER
;
520 if ( nUnoType
& sheet::NamedRangeFlag::ROW_HEADER
) nNewType
|= RT_ROWHEADER
;
522 sal_Bool bDone
= false;
525 ScDocument
* pDoc
= pDocShell
->GetDocument();
526 ScRangeName
* pNames
= GetRangeName_Impl();
527 if (pNames
&& !pNames
->findByUpperName(ScGlobal::pCharClass
->uppercase(aName
)))
529 ScRangeName
* pNewRanges
= new ScRangeName( *pNames
);
530 // GRAM_PODF_A1 for API compatibility.
531 ScRangeData
* pNew
= new ScRangeData( pDoc
, aName
, aContent
,
532 aPos
, nNewType
,formula::FormulaGrammar::GRAM_PODF_A1
);
533 if ( pNewRanges
->insert(pNew
) )
535 pDocShell
->GetDocFunc().SetNewRangeNames(pNewRanges
, mbModifyAndBroadcast
, GetTab_Impl());
547 throw uno::RuntimeException(); // no other exceptions specified
550 void SAL_CALL
ScNamedRangesObj::addNewFromTitles( const table::CellRangeAddress
& aSource
,
551 sheet::Border aBorder
) throw(uno::RuntimeException
)
553 SolarMutexGuard aGuard
;
554 //! das darf kein enum sein, weil mehrere Bits gesetzt sein koennen !!!
556 sal_Bool bTop
= ( aBorder
== sheet::Border_TOP
);
557 sal_Bool bLeft
= ( aBorder
== sheet::Border_LEFT
);
558 sal_Bool bBottom
= ( aBorder
== sheet::Border_BOTTOM
);
559 sal_Bool bRight
= ( aBorder
== sheet::Border_RIGHT
);
562 ScUnoConversion::FillScRange( aRange
, aSource
);
564 sal_uInt16 nFlags
= 0;
565 if (bTop
) nFlags
|= NAME_TOP
;
566 if (bLeft
) nFlags
|= NAME_LEFT
;
567 if (bBottom
) nFlags
|= NAME_BOTTOM
;
568 if (bRight
) nFlags
|= NAME_RIGHT
;
571 pDocShell
->GetDocFunc().CreateNames( aRange
, nFlags
, sal_True
, GetTab_Impl() );
574 void SAL_CALL
ScNamedRangesObj::removeByName( const OUString
& aName
)
575 throw(uno::RuntimeException
)
577 SolarMutexGuard aGuard
;
581 ScRangeName
* pNames
= GetRangeName_Impl();
584 const ScRangeData
* pData
= pNames
->findByUpperName(ScGlobal::pCharClass
->uppercase(aName
));
585 if (pData
&& lcl_UserVisibleName(*pData
))
587 ScRangeName
* pNewRanges
= new ScRangeName(*pNames
);
588 pNewRanges
->erase(*pData
);
589 pDocShell
->GetDocFunc().SetNewRangeNames( pNewRanges
, mbModifyAndBroadcast
, GetTab_Impl());
596 throw uno::RuntimeException(); // no other exceptions specified
599 void SAL_CALL
ScNamedRangesObj::outputList( const table::CellAddress
& aOutputPosition
)
600 throw(uno::RuntimeException
)
602 SolarMutexGuard aGuard
;
603 ScAddress
aPos( (SCCOL
)aOutputPosition
.Column
, (SCROW
)aOutputPosition
.Row
, aOutputPosition
.Sheet
);
605 pDocShell
->GetDocFunc().InsertNameList( aPos
, sal_True
);
608 // container::XEnumerationAccess
610 uno::Reference
<container::XEnumeration
> SAL_CALL
ScNamedRangesObj::createEnumeration()
611 throw(uno::RuntimeException
)
613 SolarMutexGuard aGuard
;
614 return new ScIndexEnumeration(this, OUString("com.sun.star.sheet.NamedRangesEnumeration"));
617 // container::XIndexAccess
619 sal_Int32 SAL_CALL
ScNamedRangesObj::getCount() throw(uno::RuntimeException
)
621 SolarMutexGuard aGuard
;
625 ScRangeName
* pNames
= GetRangeName_Impl();
628 ScRangeName::const_iterator itr
= pNames
->begin(), itrEnd
= pNames
->end();
629 for (; itr
!= itrEnd
; ++itr
)
630 if (lcl_UserVisibleName(*itr
->second
))
637 uno::Any SAL_CALL
ScNamedRangesObj::getByIndex( sal_Int32 nIndex
)
638 throw(lang::IndexOutOfBoundsException
,
639 lang::WrappedTargetException
, uno::RuntimeException
)
641 SolarMutexGuard aGuard
;
642 uno::Reference
< sheet::XNamedRange
> xRange(GetObjectByIndex_Impl((sal_uInt16
)nIndex
));
644 return uno::makeAny(xRange
);
646 throw lang::IndexOutOfBoundsException();
649 uno::Type SAL_CALL
ScNamedRangesObj::getElementType() throw(uno::RuntimeException
)
651 SolarMutexGuard aGuard
;
652 return ::getCppuType((const uno::Reference
< sheet::XNamedRange
>*)0); // muss zu getByIndex passen
655 sal_Bool SAL_CALL
ScNamedRangesObj::hasElements() throw(uno::RuntimeException
)
657 SolarMutexGuard aGuard
;
658 return ( getCount() != 0 );
661 Reference
<beans::XPropertySetInfo
> SAL_CALL
ScNamedRangesObj::getPropertySetInfo()
662 throw(uno::RuntimeException
)
664 static Reference
<beans::XPropertySetInfo
> aRef(
665 new SfxItemPropertySetInfo(lcl_GetNamedRangesMap()));
669 void SAL_CALL
ScNamedRangesObj::setPropertyValue(
670 const OUString
& rPropertyName
, const uno::Any
& aValue
)
671 throw(beans::UnknownPropertyException
, beans::PropertyVetoException
,
672 lang::IllegalArgumentException
, lang::WrappedTargetException
,
673 uno::RuntimeException
)
675 if ( rPropertyName
== SC_UNO_MODIFY_BROADCAST
)
677 aValue
>>= mbModifyAndBroadcast
;
681 Any SAL_CALL
ScNamedRangesObj::getPropertyValue( const OUString
& rPropertyName
)
682 throw(beans::UnknownPropertyException
, lang::WrappedTargetException
,
683 uno::RuntimeException
)
686 if ( rPropertyName
== SC_UNO_MODIFY_BROADCAST
)
688 aRet
<<= mbModifyAndBroadcast
;
694 SC_IMPL_DUMMY_PROPERTY_LISTENER( ScNamedRangesObj
)
696 uno::Any SAL_CALL
ScNamedRangesObj::getByName( const OUString
& aName
)
697 throw(container::NoSuchElementException
,
698 lang::WrappedTargetException
, uno::RuntimeException
)
700 SolarMutexGuard aGuard
;
701 uno::Reference
< sheet::XNamedRange
> xRange(GetObjectByName_Impl(aName
));
703 return uno::makeAny(xRange
);
705 throw container::NoSuchElementException();
708 uno::Sequence
<OUString
> SAL_CALL
ScNamedRangesObj::getElementNames()
709 throw(uno::RuntimeException
)
711 SolarMutexGuard aGuard
;
714 ScRangeName
* pNames
= GetRangeName_Impl();
717 long nVisCount
= getCount(); // Namen mit lcl_UserVisibleName
718 uno::Sequence
<OUString
> aSeq(nVisCount
);
719 OUString
* pAry
= aSeq
.getArray();
720 sal_uInt16 nVisPos
= 0;
721 ScRangeName::const_iterator itr
= pNames
->begin(), itrEnd
= pNames
->end();
722 for (; itr
!= itrEnd
; ++itr
)
724 if (lcl_UserVisibleName(*itr
->second
))
725 pAry
[nVisPos
++] = itr
->second
->GetName();
730 return uno::Sequence
<OUString
>(0);
733 sal_Bool SAL_CALL
ScNamedRangesObj::hasByName( const OUString
& aName
)
734 throw(uno::RuntimeException
)
736 SolarMutexGuard aGuard
;
739 ScRangeName
* pNames
= GetRangeName_Impl();
742 const ScRangeData
* pData
= pNames
->findByUpperName(ScGlobal::pCharClass
->uppercase(aName
));
743 if (pData
&& lcl_UserVisibleName(*pData
))
750 /** called from the XActionLockable interface methods on initial locking */
751 void ScNamedRangesObj::lock()
753 pDocShell
->GetDocument()->CompileNameFormula( sal_True
); // CreateFormulaString
756 /** called from the XActionLockable interface methods on final unlock */
757 void ScNamedRangesObj::unlock()
759 pDocShell
->GetDocument()->CompileNameFormula( false ); // CompileFormulaString
762 // document::XActionLockable
764 sal_Bool
ScNamedRangesObj::isActionLocked() throw(uno::RuntimeException
)
766 SolarMutexGuard aGuard
;
767 return pDocShell
->GetDocument()->GetNamedRangesLockCount() != 0;
770 void ScNamedRangesObj::addActionLock() throw(uno::RuntimeException
)
772 SolarMutexGuard aGuard
;
773 ScDocument
* pDoc
= pDocShell
->GetDocument();
774 sal_Int16 nLockCount
= pDoc
->GetNamedRangesLockCount();
776 if ( nLockCount
== 1 )
780 pDoc
->SetNamedRangesLockCount( nLockCount
);
783 void ScNamedRangesObj::removeActionLock() throw(uno::RuntimeException
)
785 SolarMutexGuard aGuard
;
786 ScDocument
* pDoc
= pDocShell
->GetDocument();
787 sal_Int16 nLockCount
= pDoc
->GetNamedRangesLockCount();
788 if ( nLockCount
> 0 )
791 if ( nLockCount
== 0 )
795 pDoc
->SetNamedRangesLockCount( nLockCount
);
799 void ScNamedRangesObj::setActionLocks( sal_Int16 nLock
) throw(uno::RuntimeException
)
801 SolarMutexGuard aGuard
;
804 ScDocument
* pDoc
= pDocShell
->GetDocument();
805 sal_Int16 nLockCount
= pDoc
->GetNamedRangesLockCount();
806 if ( nLock
== 0 && nLockCount
> 0 )
810 if ( nLock
> 0 && nLockCount
== 0 )
814 pDoc
->SetNamedRangesLockCount( nLock
);
818 sal_Int16
ScNamedRangesObj::resetActionLocks() throw(uno::RuntimeException
)
820 SolarMutexGuard aGuard
;
821 ScDocument
* pDoc
= pDocShell
->GetDocument();
822 sal_Int16 nLockCount
= pDoc
->GetNamedRangesLockCount();
823 if ( nLockCount
> 0 )
827 pDoc
->SetNamedRangesLockCount( 0 );
831 //------------------------------------------------------------------------
833 ScGlobalNamedRangesObj::ScGlobalNamedRangesObj(ScDocShell
* pDocSh
)
834 : ScNamedRangesObj(pDocSh
)
839 ScGlobalNamedRangesObj::~ScGlobalNamedRangesObj()
844 ScNamedRangeObj
* ScGlobalNamedRangesObj::GetObjectByIndex_Impl(sal_uInt16 nIndex
)
849 ScRangeName
* pNames
= pDocShell
->GetDocument()->GetRangeName();
853 ScRangeName::const_iterator itr
= pNames
->begin(), itrEnd
= pNames
->end();
855 for (; itr
!= itrEnd
; ++itr
)
857 if (lcl_UserVisibleName(*itr
->second
))
860 return new ScNamedRangeObj(this, pDocShell
, itr
->second
->GetName());
867 ScNamedRangeObj
* ScGlobalNamedRangesObj::GetObjectByName_Impl(const OUString
& aName
)
869 if ( pDocShell
&& hasByName(aName
) )
870 return new ScNamedRangeObj(this, pDocShell
, String(aName
));
874 ScRangeName
* ScGlobalNamedRangesObj::GetRangeName_Impl()
876 return pDocShell
->GetDocument()->GetRangeName();
879 SCTAB
ScGlobalNamedRangesObj::GetTab_Impl()
884 //------------------------------------------------------------------------
886 ScLocalNamedRangesObj::ScLocalNamedRangesObj( ScDocShell
* pDocSh
, uno::Reference
<container::XNamed
> xSheet
)
887 : ScNamedRangesObj(pDocSh
),
893 ScLocalNamedRangesObj::~ScLocalNamedRangesObj()
898 ScNamedRangeObj
* ScLocalNamedRangesObj::GetObjectByName_Impl(const OUString
& aName
)
900 if ( pDocShell
&& hasByName( aName
) )
901 return new ScNamedRangeObj( this, pDocShell
, String(aName
), mxSheet
);
906 ScNamedRangeObj
* ScLocalNamedRangesObj::GetObjectByIndex_Impl( sal_uInt16 nIndex
)
911 OUString aName
= mxSheet
->getName();
912 ScDocument
* pDoc
= pDocShell
->GetDocument();
914 pDoc
->GetTable( aName
, nTab
);
916 ScRangeName
* pNames
= pDoc
->GetRangeName( nTab
);
920 ScRangeName::const_iterator itr
= pNames
->begin(), itrEnd
= pNames
->end();
922 for (; itr
!= itrEnd
; ++itr
)
924 if (lcl_UserVisibleName(*itr
->second
))
927 return new ScNamedRangeObj(this, pDocShell
, itr
->second
->GetName(), mxSheet
);
934 ScRangeName
* ScLocalNamedRangesObj::GetRangeName_Impl()
936 SCTAB nTab
= GetTab_Impl();
937 return pDocShell
->GetDocument()->GetRangeName( nTab
);
940 SCTAB
ScLocalNamedRangesObj::GetTab_Impl()
943 pDocShell
->GetDocument()->GetTable(mxSheet
->getName(), nTab
);
947 //------------------------------------------------------------------------
949 ScLabelRangeObj::ScLabelRangeObj(ScDocShell
* pDocSh
, sal_Bool bCol
, const ScRange
& rR
) :
954 pDocShell
->GetDocument()->AddUnoObject(*this);
957 ScLabelRangeObj::~ScLabelRangeObj()
960 pDocShell
->GetDocument()->RemoveUnoObject(*this);
963 void ScLabelRangeObj::Notify( SfxBroadcaster
&, const SfxHint
& rHint
)
967 if ( rHint
.ISA( SfxSimpleHint
) && ((const SfxSimpleHint
&)rHint
).GetId() == SFX_HINT_DYING
)
968 pDocShell
= NULL
; // ungueltig geworden
973 ScRangePair
* ScLabelRangeObj::GetData_Impl()
975 ScRangePair
* pRet
= NULL
;
978 ScDocument
* pDoc
= pDocShell
->GetDocument();
979 ScRangePairList
* pList
= bColumn
? pDoc
->GetColNameRanges() : pDoc
->GetRowNameRanges();
981 pRet
= pList
->Find( aRange
);
986 void ScLabelRangeObj::Modify_Impl( const ScRange
* pLabel
, const ScRange
* pData
)
990 ScDocument
* pDoc
= pDocShell
->GetDocument();
991 ScRangePairList
* pOldList
= bColumn
? pDoc
->GetColNameRanges() : pDoc
->GetRowNameRanges();
994 ScRangePairListRef
xNewList(pOldList
->Clone());
995 ScRangePair
* pEntry
= xNewList
->Find( aRange
);
998 xNewList
->Remove( pEntry
); // nur aus der Liste entfernt, nicht geloescht
1001 pEntry
->GetRange(0) = *pLabel
;
1003 pEntry
->GetRange(1) = *pData
;
1005 xNewList
->Join( *pEntry
);
1009 pDoc
->GetColNameRangesRef() = xNewList
;
1011 pDoc
->GetRowNameRangesRef() = xNewList
;
1013 pDoc
->CompileColRowNameFormula();
1014 pDocShell
->PostPaint( 0,0,0, MAXCOL
,MAXROW
,MAXTAB
, PAINT_GRID
);
1015 pDocShell
->SetDocumentModified();
1017 //! Undo ?!?! (hier und aus Dialog)
1020 aRange
= *pLabel
; // Objekt anpassen, um Range wiederzufinden
1026 // sheet::XLabelRange
1028 table::CellRangeAddress SAL_CALL
ScLabelRangeObj::getLabelArea()
1029 throw(uno::RuntimeException
)
1031 SolarMutexGuard aGuard
;
1032 table::CellRangeAddress aRet
;
1033 ScRangePair
* pData
= GetData_Impl();
1035 ScUnoConversion::FillApiRange( aRet
, pData
->GetRange(0) );
1039 void SAL_CALL
ScLabelRangeObj::setLabelArea( const table::CellRangeAddress
& aLabelArea
)
1040 throw(uno::RuntimeException
)
1042 SolarMutexGuard aGuard
;
1043 ScRange aLabelRange
;
1044 ScUnoConversion::FillScRange( aLabelRange
, aLabelArea
);
1045 Modify_Impl( &aLabelRange
, NULL
);
1048 table::CellRangeAddress SAL_CALL
ScLabelRangeObj::getDataArea()
1049 throw(uno::RuntimeException
)
1051 SolarMutexGuard aGuard
;
1052 table::CellRangeAddress aRet
;
1053 ScRangePair
* pData
= GetData_Impl();
1055 ScUnoConversion::FillApiRange( aRet
, pData
->GetRange(1) );
1059 void SAL_CALL
ScLabelRangeObj::setDataArea( const table::CellRangeAddress
& aDataArea
)
1060 throw(uno::RuntimeException
)
1062 SolarMutexGuard aGuard
;
1064 ScUnoConversion::FillScRange( aDataRange
, aDataArea
);
1065 Modify_Impl( NULL
, &aDataRange
);
1068 //------------------------------------------------------------------------
1070 ScLabelRangesObj::ScLabelRangesObj(ScDocShell
* pDocSh
, sal_Bool bCol
) :
1071 pDocShell( pDocSh
),
1074 pDocShell
->GetDocument()->AddUnoObject(*this);
1077 ScLabelRangesObj::~ScLabelRangesObj()
1080 pDocShell
->GetDocument()->RemoveUnoObject(*this);
1083 void ScLabelRangesObj::Notify( SfxBroadcaster
&, const SfxHint
& rHint
)
1085 // Referenz-Update interessiert hier nicht
1087 if ( rHint
.ISA( SfxSimpleHint
) &&
1088 ((const SfxSimpleHint
&)rHint
).GetId() == SFX_HINT_DYING
)
1090 pDocShell
= NULL
; // ungueltig geworden
1094 // sheet::XLabelRanges
1096 ScLabelRangeObj
* ScLabelRangesObj::GetObjectByIndex_Impl(size_t nIndex
)
1100 ScDocument
* pDoc
= pDocShell
->GetDocument();
1101 ScRangePairList
* pList
= bColumn
? pDoc
->GetColNameRanges() : pDoc
->GetRowNameRanges();
1102 if ( pList
&& nIndex
< pList
->size() )
1104 ScRangePair
* pData
= (*pList
)[nIndex
];
1106 return new ScLabelRangeObj( pDocShell
, bColumn
, pData
->GetRange(0) );
1112 void SAL_CALL
ScLabelRangesObj::addNew( const table::CellRangeAddress
& aLabelArea
,
1113 const table::CellRangeAddress
& aDataArea
)
1114 throw(uno::RuntimeException
)
1116 SolarMutexGuard aGuard
;
1119 ScDocument
* pDoc
= pDocShell
->GetDocument();
1120 ScRangePairList
* pOldList
= bColumn
? pDoc
->GetColNameRanges() : pDoc
->GetRowNameRanges();
1123 ScRangePairListRef
xNewList(pOldList
->Clone());
1125 ScRange aLabelRange
;
1127 ScUnoConversion::FillScRange( aLabelRange
, aLabelArea
);
1128 ScUnoConversion::FillScRange( aDataRange
, aDataArea
);
1129 xNewList
->Join( ScRangePair( aLabelRange
, aDataRange
) );
1132 pDoc
->GetColNameRangesRef() = xNewList
;
1134 pDoc
->GetRowNameRangesRef() = xNewList
;
1136 pDoc
->CompileColRowNameFormula();
1137 pDocShell
->PostPaint( 0,0,0, MAXCOL
,MAXROW
,MAXTAB
, PAINT_GRID
);
1138 pDocShell
->SetDocumentModified();
1140 //! Undo ?!?! (hier und aus Dialog)
1145 void SAL_CALL
ScLabelRangesObj::removeByIndex( sal_Int32 nIndex
)
1146 throw(uno::RuntimeException
)
1148 SolarMutexGuard aGuard
;
1149 sal_Bool bDone
= false;
1152 ScDocument
* pDoc
= pDocShell
->GetDocument();
1153 ScRangePairList
* pOldList
= bColumn
? pDoc
->GetColNameRanges() : pDoc
->GetRowNameRanges();
1155 if ( pOldList
&& nIndex
>= 0 && nIndex
< (sal_Int32
)pOldList
->size() )
1157 ScRangePairListRef
xNewList(pOldList
->Clone());
1159 ScRangePair
* pEntry
= (*xNewList
)[nIndex
];
1162 xNewList
->Remove( pEntry
);
1166 pDoc
->GetColNameRangesRef() = xNewList
;
1168 pDoc
->GetRowNameRangesRef() = xNewList
;
1170 pDoc
->CompileColRowNameFormula();
1171 pDocShell
->PostPaint( 0,0,0, MAXCOL
,MAXROW
,MAXTAB
, PAINT_GRID
);
1172 pDocShell
->SetDocumentModified();
1175 //! Undo ?!?! (hier und aus Dialog)
1180 throw uno::RuntimeException(); // no other exceptions specified
1183 // container::XEnumerationAccess
1185 uno::Reference
<container::XEnumeration
> SAL_CALL
ScLabelRangesObj::createEnumeration()
1186 throw(uno::RuntimeException
)
1188 SolarMutexGuard aGuard
;
1189 return new ScIndexEnumeration(this, OUString("com.sun.star.sheet.LabelRangesEnumeration"));
1192 // container::XIndexAccess
1194 sal_Int32 SAL_CALL
ScLabelRangesObj::getCount() throw(uno::RuntimeException
)
1196 SolarMutexGuard aGuard
;
1199 ScDocument
* pDoc
= pDocShell
->GetDocument();
1200 ScRangePairList
* pList
= bColumn
? pDoc
->GetColNameRanges() : pDoc
->GetRowNameRanges();
1202 return pList
->size();
1207 uno::Any SAL_CALL
ScLabelRangesObj::getByIndex( sal_Int32 nIndex
)
1208 throw(lang::IndexOutOfBoundsException
,
1209 lang::WrappedTargetException
, uno::RuntimeException
)
1211 SolarMutexGuard aGuard
;
1212 uno::Reference
< sheet::XLabelRange
> xRange(GetObjectByIndex_Impl((sal_uInt16
)nIndex
));
1214 return uno::makeAny(xRange
);
1216 throw lang::IndexOutOfBoundsException();
1219 uno::Type SAL_CALL
ScLabelRangesObj::getElementType() throw(uno::RuntimeException
)
1221 SolarMutexGuard aGuard
;
1222 return ::getCppuType((const uno::Reference
< sheet::XLabelRange
>*)0); // muss zu getByIndex passen
1226 sal_Bool SAL_CALL
ScLabelRangesObj::hasElements() throw(uno::RuntimeException
)
1228 SolarMutexGuard aGuard
;
1229 return ( getCount() != 0 );
1232 //------------------------------------------------------------------------
1236 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */