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 const 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 const 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
);
88 ScNamedRangeObj::ScNamedRangeObj( rtl::Reference
< ScNamedRangesObj
> xParent
, ScDocShell
* pDocSh
, const OUString
& 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 OUString
* pNewName
, const ScTokenArray
* pNewTokens
, const OUString
* 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 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( 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 OUString
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 OUString
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
)
393 uno::Any SAL_CALL
ScNamedRangeObj::getPropertyValue( const OUString
& rPropertyName
)
394 throw(beans::UnknownPropertyException
, lang::WrappedTargetException
,
395 uno::RuntimeException
)
397 SolarMutexGuard aGuard
;
399 if ( rPropertyName
== SC_UNO_LINKDISPBIT
)
401 // no target bitmaps for individual entries (would be all equal)
402 // ScLinkTargetTypeObj::SetLinkTargetBitmap( aRet, SC_LINKTARGETTYPE_RANGENAME );
404 else if ( rPropertyName
== SC_UNO_LINKDISPNAME
)
405 aRet
<<= OUString( aName
);
406 else if ( rPropertyName
== SC_UNONAME_TOKENINDEX
)
408 // get index for use in formula tokens (read-only)
409 ScRangeData
* pData
= GetRangeData_Impl();
411 aRet
<<= static_cast<sal_Int32
>(pData
->GetIndex());
413 else if ( rPropertyName
== SC_UNONAME_ISSHAREDFMLA
)
415 if (GetRangeData_Impl())
421 SC_IMPL_DUMMY_PROPERTY_LISTENER( ScNamedRangeObj
)
423 // lang::XServiceInfo
425 OUString SAL_CALL
ScNamedRangeObj::getImplementationName() throw(uno::RuntimeException
)
427 return OUString( "ScNamedRangeObj" );
430 sal_Bool SAL_CALL
ScNamedRangeObj::supportsService( const OUString
& rServiceName
)
431 throw(uno::RuntimeException
)
433 return rServiceName
== SCNAMEDRANGEOBJ_SERVICE
||
434 rServiceName
== SCLINKTARGET_SERVICE
;
437 uno::Sequence
<OUString
> SAL_CALL
ScNamedRangeObj::getSupportedServiceNames()
438 throw(uno::RuntimeException
)
440 uno::Sequence
<OUString
> aRet(2);
441 aRet
[0] = OUString( SCNAMEDRANGEOBJ_SERVICE
);
442 aRet
[1] = OUString( SCLINKTARGET_SERVICE
);
449 sal_Int64 SAL_CALL
ScNamedRangeObj::getSomething(
450 const uno::Sequence
<sal_Int8
>& rId
) throw(uno::RuntimeException
)
452 if ( rId
.getLength() == 16 &&
453 0 == memcmp( getUnoTunnelId().getConstArray(),
454 rId
.getConstArray(), 16 ) )
456 return sal::static_int_cast
<sal_Int64
>(reinterpret_cast<sal_IntPtr
>(this));
463 class theScNamedRangeObjUnoTunnelId
: public rtl::Static
< UnoTunnelIdInit
, theScNamedRangeObjUnoTunnelId
> {};
466 const uno::Sequence
<sal_Int8
>& ScNamedRangeObj::getUnoTunnelId()
468 return theScNamedRangeObjUnoTunnelId::get().getSeq();
471 //------------------------------------------------------------------------
473 ScNamedRangesObj::ScNamedRangesObj(ScDocShell
* pDocSh
) :
474 mbModifyAndBroadcast(true),
477 pDocShell
->GetDocument()->AddUnoObject(*this);
480 ScNamedRangesObj::~ScNamedRangesObj()
483 pDocShell
->GetDocument()->RemoveUnoObject(*this);
486 void ScNamedRangesObj::Notify( SfxBroadcaster
&, const SfxHint
& rHint
)
488 // Referenz-Update interessiert hier nicht
490 if ( rHint
.ISA( SfxSimpleHint
) &&
491 ((const SfxSimpleHint
&)rHint
).GetId() == SFX_HINT_DYING
)
493 pDocShell
= NULL
; // ungueltig geworden
497 bool ScNamedRangesObj::IsModifyAndBroadcast() const
499 return mbModifyAndBroadcast
;
502 // sheet::XNamedRanges
504 void SAL_CALL
ScNamedRangesObj::addNewByName( const OUString
& aName
,
505 const OUString
& aContent
, const table::CellAddress
& aPosition
,
506 sal_Int32 nUnoType
) throw(uno::RuntimeException
)
508 SolarMutexGuard aGuard
;
509 ScAddress
aPos( (SCCOL
)aPosition
.Column
, (SCROW
)aPosition
.Row
, aPosition
.Sheet
);
511 sal_uInt16 nNewType
= RT_NAME
;
512 if ( nUnoType
& sheet::NamedRangeFlag::FILTER_CRITERIA
) nNewType
|= RT_CRITERIA
;
513 if ( nUnoType
& sheet::NamedRangeFlag::PRINT_AREA
) nNewType
|= RT_PRINTAREA
;
514 if ( nUnoType
& sheet::NamedRangeFlag::COLUMN_HEADER
) nNewType
|= RT_COLHEADER
;
515 if ( nUnoType
& sheet::NamedRangeFlag::ROW_HEADER
) nNewType
|= RT_ROWHEADER
;
517 sal_Bool bDone
= false;
520 ScDocument
* pDoc
= pDocShell
->GetDocument();
521 ScRangeName
* pNames
= GetRangeName_Impl();
522 if (pNames
&& !pNames
->findByUpperName(ScGlobal::pCharClass
->uppercase(aName
)))
524 ScRangeName
* pNewRanges
= new ScRangeName( *pNames
);
525 // GRAM_PODF_A1 for API compatibility.
526 ScRangeData
* pNew
= new ScRangeData( pDoc
, aName
, aContent
,
527 aPos
, nNewType
,formula::FormulaGrammar::GRAM_PODF_A1
);
528 if ( pNewRanges
->insert(pNew
) )
530 pDocShell
->GetDocFunc().SetNewRangeNames(pNewRanges
, mbModifyAndBroadcast
, GetTab_Impl());
542 throw uno::RuntimeException(); // no other exceptions specified
545 void SAL_CALL
ScNamedRangesObj::addNewFromTitles( const table::CellRangeAddress
& aSource
,
546 sheet::Border aBorder
) throw(uno::RuntimeException
)
548 SolarMutexGuard aGuard
;
549 //! das darf kein enum sein, weil mehrere Bits gesetzt sein koennen !!!
551 sal_Bool bTop
= ( aBorder
== sheet::Border_TOP
);
552 sal_Bool bLeft
= ( aBorder
== sheet::Border_LEFT
);
553 sal_Bool bBottom
= ( aBorder
== sheet::Border_BOTTOM
);
554 sal_Bool bRight
= ( aBorder
== sheet::Border_RIGHT
);
557 ScUnoConversion::FillScRange( aRange
, aSource
);
559 sal_uInt16 nFlags
= 0;
560 if (bTop
) nFlags
|= NAME_TOP
;
561 if (bLeft
) nFlags
|= NAME_LEFT
;
562 if (bBottom
) nFlags
|= NAME_BOTTOM
;
563 if (bRight
) nFlags
|= NAME_RIGHT
;
566 pDocShell
->GetDocFunc().CreateNames( aRange
, nFlags
, sal_True
, GetTab_Impl() );
569 void SAL_CALL
ScNamedRangesObj::removeByName( const OUString
& aName
)
570 throw(uno::RuntimeException
)
572 SolarMutexGuard aGuard
;
576 ScRangeName
* pNames
= GetRangeName_Impl();
579 const ScRangeData
* pData
= pNames
->findByUpperName(ScGlobal::pCharClass
->uppercase(aName
));
580 if (pData
&& lcl_UserVisibleName(*pData
))
582 ScRangeName
* pNewRanges
= new ScRangeName(*pNames
);
583 pNewRanges
->erase(*pData
);
584 pDocShell
->GetDocFunc().SetNewRangeNames( pNewRanges
, mbModifyAndBroadcast
, GetTab_Impl());
591 throw uno::RuntimeException(); // no other exceptions specified
594 void SAL_CALL
ScNamedRangesObj::outputList( const table::CellAddress
& aOutputPosition
)
595 throw(uno::RuntimeException
)
597 SolarMutexGuard aGuard
;
598 ScAddress
aPos( (SCCOL
)aOutputPosition
.Column
, (SCROW
)aOutputPosition
.Row
, aOutputPosition
.Sheet
);
600 pDocShell
->GetDocFunc().InsertNameList( aPos
, sal_True
);
603 // container::XEnumerationAccess
605 uno::Reference
<container::XEnumeration
> SAL_CALL
ScNamedRangesObj::createEnumeration()
606 throw(uno::RuntimeException
)
608 SolarMutexGuard aGuard
;
609 return new ScIndexEnumeration(this, OUString("com.sun.star.sheet.NamedRangesEnumeration"));
612 // container::XIndexAccess
614 sal_Int32 SAL_CALL
ScNamedRangesObj::getCount() throw(uno::RuntimeException
)
616 SolarMutexGuard aGuard
;
620 ScRangeName
* pNames
= GetRangeName_Impl();
623 ScRangeName::const_iterator itr
= pNames
->begin(), itrEnd
= pNames
->end();
624 for (; itr
!= itrEnd
; ++itr
)
625 if (lcl_UserVisibleName(*itr
->second
))
632 uno::Any SAL_CALL
ScNamedRangesObj::getByIndex( sal_Int32 nIndex
)
633 throw(lang::IndexOutOfBoundsException
,
634 lang::WrappedTargetException
, uno::RuntimeException
)
636 SolarMutexGuard aGuard
;
637 uno::Reference
< sheet::XNamedRange
> xRange(GetObjectByIndex_Impl((sal_uInt16
)nIndex
));
639 return uno::makeAny(xRange
);
641 throw lang::IndexOutOfBoundsException();
644 uno::Type SAL_CALL
ScNamedRangesObj::getElementType() throw(uno::RuntimeException
)
646 SolarMutexGuard aGuard
;
647 return ::getCppuType((const uno::Reference
< sheet::XNamedRange
>*)0); // muss zu getByIndex passen
650 sal_Bool SAL_CALL
ScNamedRangesObj::hasElements() throw(uno::RuntimeException
)
652 SolarMutexGuard aGuard
;
653 return ( getCount() != 0 );
656 Reference
<beans::XPropertySetInfo
> SAL_CALL
ScNamedRangesObj::getPropertySetInfo()
657 throw(uno::RuntimeException
)
659 static Reference
<beans::XPropertySetInfo
> aRef(
660 new SfxItemPropertySetInfo(lcl_GetNamedRangesMap()));
664 void SAL_CALL
ScNamedRangesObj::setPropertyValue(
665 const OUString
& rPropertyName
, const uno::Any
& aValue
)
666 throw(beans::UnknownPropertyException
, beans::PropertyVetoException
,
667 lang::IllegalArgumentException
, lang::WrappedTargetException
,
668 uno::RuntimeException
)
670 if ( rPropertyName
== SC_UNO_MODIFY_BROADCAST
)
672 aValue
>>= mbModifyAndBroadcast
;
676 Any SAL_CALL
ScNamedRangesObj::getPropertyValue( const OUString
& rPropertyName
)
677 throw(beans::UnknownPropertyException
, lang::WrappedTargetException
,
678 uno::RuntimeException
)
681 if ( rPropertyName
== SC_UNO_MODIFY_BROADCAST
)
683 aRet
<<= mbModifyAndBroadcast
;
689 SC_IMPL_DUMMY_PROPERTY_LISTENER( ScNamedRangesObj
)
691 uno::Any SAL_CALL
ScNamedRangesObj::getByName( const OUString
& aName
)
692 throw(container::NoSuchElementException
,
693 lang::WrappedTargetException
, uno::RuntimeException
)
695 SolarMutexGuard aGuard
;
696 uno::Reference
< sheet::XNamedRange
> xRange(GetObjectByName_Impl(aName
));
698 return uno::makeAny(xRange
);
700 throw container::NoSuchElementException();
703 uno::Sequence
<OUString
> SAL_CALL
ScNamedRangesObj::getElementNames()
704 throw(uno::RuntimeException
)
706 SolarMutexGuard aGuard
;
709 ScRangeName
* pNames
= GetRangeName_Impl();
712 long nVisCount
= getCount(); // Namen mit lcl_UserVisibleName
713 uno::Sequence
<OUString
> aSeq(nVisCount
);
714 OUString
* pAry
= aSeq
.getArray();
715 sal_uInt16 nVisPos
= 0;
716 ScRangeName::const_iterator itr
= pNames
->begin(), itrEnd
= pNames
->end();
717 for (; itr
!= itrEnd
; ++itr
)
719 if (lcl_UserVisibleName(*itr
->second
))
720 pAry
[nVisPos
++] = itr
->second
->GetName();
725 return uno::Sequence
<OUString
>(0);
728 sal_Bool SAL_CALL
ScNamedRangesObj::hasByName( const OUString
& aName
)
729 throw(uno::RuntimeException
)
731 SolarMutexGuard aGuard
;
734 ScRangeName
* pNames
= GetRangeName_Impl();
737 const ScRangeData
* pData
= pNames
->findByUpperName(ScGlobal::pCharClass
->uppercase(aName
));
738 if (pData
&& lcl_UserVisibleName(*pData
))
745 /** called from the XActionLockable interface methods on initial locking */
746 void ScNamedRangesObj::lock()
748 pDocShell
->GetDocument()->CompileNameFormula( sal_True
); // CreateFormulaString
751 /** called from the XActionLockable interface methods on final unlock */
752 void ScNamedRangesObj::unlock()
754 pDocShell
->GetDocument()->CompileNameFormula( false ); // CompileFormulaString
757 // document::XActionLockable
759 sal_Bool
ScNamedRangesObj::isActionLocked() throw(uno::RuntimeException
)
761 SolarMutexGuard aGuard
;
762 return pDocShell
->GetDocument()->GetNamedRangesLockCount() != 0;
765 void ScNamedRangesObj::addActionLock() throw(uno::RuntimeException
)
767 SolarMutexGuard aGuard
;
768 ScDocument
* pDoc
= pDocShell
->GetDocument();
769 sal_Int16 nLockCount
= pDoc
->GetNamedRangesLockCount();
771 if ( nLockCount
== 1 )
775 pDoc
->SetNamedRangesLockCount( nLockCount
);
778 void ScNamedRangesObj::removeActionLock() throw(uno::RuntimeException
)
780 SolarMutexGuard aGuard
;
781 ScDocument
* pDoc
= pDocShell
->GetDocument();
782 sal_Int16 nLockCount
= pDoc
->GetNamedRangesLockCount();
783 if ( nLockCount
> 0 )
786 if ( nLockCount
== 0 )
790 pDoc
->SetNamedRangesLockCount( nLockCount
);
794 void ScNamedRangesObj::setActionLocks( sal_Int16 nLock
) throw(uno::RuntimeException
)
796 SolarMutexGuard aGuard
;
799 ScDocument
* pDoc
= pDocShell
->GetDocument();
800 sal_Int16 nLockCount
= pDoc
->GetNamedRangesLockCount();
801 if ( nLock
== 0 && nLockCount
> 0 )
805 if ( nLock
> 0 && nLockCount
== 0 )
809 pDoc
->SetNamedRangesLockCount( nLock
);
813 sal_Int16
ScNamedRangesObj::resetActionLocks() throw(uno::RuntimeException
)
815 SolarMutexGuard aGuard
;
816 ScDocument
* pDoc
= pDocShell
->GetDocument();
817 sal_Int16 nLockCount
= pDoc
->GetNamedRangesLockCount();
818 if ( nLockCount
> 0 )
822 pDoc
->SetNamedRangesLockCount( 0 );
826 //------------------------------------------------------------------------
828 ScGlobalNamedRangesObj::ScGlobalNamedRangesObj(ScDocShell
* pDocSh
)
829 : ScNamedRangesObj(pDocSh
)
834 ScGlobalNamedRangesObj::~ScGlobalNamedRangesObj()
839 ScNamedRangeObj
* ScGlobalNamedRangesObj::GetObjectByIndex_Impl(sal_uInt16 nIndex
)
844 ScRangeName
* pNames
= pDocShell
->GetDocument()->GetRangeName();
848 ScRangeName::const_iterator itr
= pNames
->begin(), itrEnd
= pNames
->end();
850 for (; itr
!= itrEnd
; ++itr
)
852 if (lcl_UserVisibleName(*itr
->second
))
855 return new ScNamedRangeObj(this, pDocShell
, itr
->second
->GetName());
862 ScNamedRangeObj
* ScGlobalNamedRangesObj::GetObjectByName_Impl(const OUString
& aName
)
864 if ( pDocShell
&& hasByName(aName
) )
865 return new ScNamedRangeObj(this, pDocShell
, aName
);
869 ScRangeName
* ScGlobalNamedRangesObj::GetRangeName_Impl()
871 return pDocShell
->GetDocument()->GetRangeName();
874 SCTAB
ScGlobalNamedRangesObj::GetTab_Impl()
879 //------------------------------------------------------------------------
881 ScLocalNamedRangesObj::ScLocalNamedRangesObj( ScDocShell
* pDocSh
, uno::Reference
<container::XNamed
> xSheet
)
882 : ScNamedRangesObj(pDocSh
),
888 ScLocalNamedRangesObj::~ScLocalNamedRangesObj()
893 ScNamedRangeObj
* ScLocalNamedRangesObj::GetObjectByName_Impl(const OUString
& aName
)
895 if ( pDocShell
&& hasByName( aName
) )
896 return new ScNamedRangeObj( this, pDocShell
, aName
, mxSheet
);
901 ScNamedRangeObj
* ScLocalNamedRangesObj::GetObjectByIndex_Impl( sal_uInt16 nIndex
)
906 OUString aName
= mxSheet
->getName();
907 ScDocument
* pDoc
= pDocShell
->GetDocument();
909 pDoc
->GetTable( aName
, nTab
);
911 ScRangeName
* pNames
= pDoc
->GetRangeName( nTab
);
915 ScRangeName::const_iterator itr
= pNames
->begin(), itrEnd
= pNames
->end();
917 for (; itr
!= itrEnd
; ++itr
)
919 if (lcl_UserVisibleName(*itr
->second
))
922 return new ScNamedRangeObj(this, pDocShell
, itr
->second
->GetName(), mxSheet
);
929 ScRangeName
* ScLocalNamedRangesObj::GetRangeName_Impl()
931 SCTAB nTab
= GetTab_Impl();
932 return pDocShell
->GetDocument()->GetRangeName( nTab
);
935 SCTAB
ScLocalNamedRangesObj::GetTab_Impl()
938 pDocShell
->GetDocument()->GetTable(mxSheet
->getName(), nTab
);
942 //------------------------------------------------------------------------
944 ScLabelRangeObj::ScLabelRangeObj(ScDocShell
* pDocSh
, sal_Bool bCol
, const ScRange
& rR
) :
949 pDocShell
->GetDocument()->AddUnoObject(*this);
952 ScLabelRangeObj::~ScLabelRangeObj()
955 pDocShell
->GetDocument()->RemoveUnoObject(*this);
958 void ScLabelRangeObj::Notify( SfxBroadcaster
&, const SfxHint
& rHint
)
962 if ( rHint
.ISA( SfxSimpleHint
) && ((const SfxSimpleHint
&)rHint
).GetId() == SFX_HINT_DYING
)
963 pDocShell
= NULL
; // ungueltig geworden
968 ScRangePair
* ScLabelRangeObj::GetData_Impl()
970 ScRangePair
* pRet
= NULL
;
973 ScDocument
* pDoc
= pDocShell
->GetDocument();
974 ScRangePairList
* pList
= bColumn
? pDoc
->GetColNameRanges() : pDoc
->GetRowNameRanges();
976 pRet
= pList
->Find( aRange
);
981 void ScLabelRangeObj::Modify_Impl( const ScRange
* pLabel
, const ScRange
* pData
)
985 ScDocument
* pDoc
= pDocShell
->GetDocument();
986 ScRangePairList
* pOldList
= bColumn
? pDoc
->GetColNameRanges() : pDoc
->GetRowNameRanges();
989 ScRangePairListRef
xNewList(pOldList
->Clone());
990 ScRangePair
* pEntry
= xNewList
->Find( aRange
);
993 xNewList
->Remove( pEntry
); // nur aus der Liste entfernt, nicht geloescht
996 pEntry
->GetRange(0) = *pLabel
;
998 pEntry
->GetRange(1) = *pData
;
1000 xNewList
->Join( *pEntry
);
1004 pDoc
->GetColNameRangesRef() = xNewList
;
1006 pDoc
->GetRowNameRangesRef() = xNewList
;
1008 pDoc
->CompileColRowNameFormula();
1009 pDocShell
->PostPaint( 0,0,0, MAXCOL
,MAXROW
,MAXTAB
, PAINT_GRID
);
1010 pDocShell
->SetDocumentModified();
1012 //! Undo ?!?! (hier und aus Dialog)
1015 aRange
= *pLabel
; // Objekt anpassen, um Range wiederzufinden
1021 // sheet::XLabelRange
1023 table::CellRangeAddress SAL_CALL
ScLabelRangeObj::getLabelArea()
1024 throw(uno::RuntimeException
)
1026 SolarMutexGuard aGuard
;
1027 table::CellRangeAddress aRet
;
1028 ScRangePair
* pData
= GetData_Impl();
1030 ScUnoConversion::FillApiRange( aRet
, pData
->GetRange(0) );
1034 void SAL_CALL
ScLabelRangeObj::setLabelArea( const table::CellRangeAddress
& aLabelArea
)
1035 throw(uno::RuntimeException
)
1037 SolarMutexGuard aGuard
;
1038 ScRange aLabelRange
;
1039 ScUnoConversion::FillScRange( aLabelRange
, aLabelArea
);
1040 Modify_Impl( &aLabelRange
, NULL
);
1043 table::CellRangeAddress SAL_CALL
ScLabelRangeObj::getDataArea()
1044 throw(uno::RuntimeException
)
1046 SolarMutexGuard aGuard
;
1047 table::CellRangeAddress aRet
;
1048 ScRangePair
* pData
= GetData_Impl();
1050 ScUnoConversion::FillApiRange( aRet
, pData
->GetRange(1) );
1054 void SAL_CALL
ScLabelRangeObj::setDataArea( const table::CellRangeAddress
& aDataArea
)
1055 throw(uno::RuntimeException
)
1057 SolarMutexGuard aGuard
;
1059 ScUnoConversion::FillScRange( aDataRange
, aDataArea
);
1060 Modify_Impl( NULL
, &aDataRange
);
1063 //------------------------------------------------------------------------
1065 ScLabelRangesObj::ScLabelRangesObj(ScDocShell
* pDocSh
, sal_Bool bCol
) :
1066 pDocShell( pDocSh
),
1069 pDocShell
->GetDocument()->AddUnoObject(*this);
1072 ScLabelRangesObj::~ScLabelRangesObj()
1075 pDocShell
->GetDocument()->RemoveUnoObject(*this);
1078 void ScLabelRangesObj::Notify( SfxBroadcaster
&, const SfxHint
& rHint
)
1080 // Referenz-Update interessiert hier nicht
1082 if ( rHint
.ISA( SfxSimpleHint
) &&
1083 ((const SfxSimpleHint
&)rHint
).GetId() == SFX_HINT_DYING
)
1085 pDocShell
= NULL
; // ungueltig geworden
1089 // sheet::XLabelRanges
1091 ScLabelRangeObj
* ScLabelRangesObj::GetObjectByIndex_Impl(size_t nIndex
)
1095 ScDocument
* pDoc
= pDocShell
->GetDocument();
1096 ScRangePairList
* pList
= bColumn
? pDoc
->GetColNameRanges() : pDoc
->GetRowNameRanges();
1097 if ( pList
&& nIndex
< pList
->size() )
1099 ScRangePair
* pData
= (*pList
)[nIndex
];
1101 return new ScLabelRangeObj( pDocShell
, bColumn
, pData
->GetRange(0) );
1107 void SAL_CALL
ScLabelRangesObj::addNew( const table::CellRangeAddress
& aLabelArea
,
1108 const table::CellRangeAddress
& aDataArea
)
1109 throw(uno::RuntimeException
)
1111 SolarMutexGuard aGuard
;
1114 ScDocument
* pDoc
= pDocShell
->GetDocument();
1115 ScRangePairList
* pOldList
= bColumn
? pDoc
->GetColNameRanges() : pDoc
->GetRowNameRanges();
1118 ScRangePairListRef
xNewList(pOldList
->Clone());
1120 ScRange aLabelRange
;
1122 ScUnoConversion::FillScRange( aLabelRange
, aLabelArea
);
1123 ScUnoConversion::FillScRange( aDataRange
, aDataArea
);
1124 xNewList
->Join( ScRangePair( aLabelRange
, aDataRange
) );
1127 pDoc
->GetColNameRangesRef() = xNewList
;
1129 pDoc
->GetRowNameRangesRef() = xNewList
;
1131 pDoc
->CompileColRowNameFormula();
1132 pDocShell
->PostPaint( 0,0,0, MAXCOL
,MAXROW
,MAXTAB
, PAINT_GRID
);
1133 pDocShell
->SetDocumentModified();
1135 //! Undo ?!?! (hier und aus Dialog)
1140 void SAL_CALL
ScLabelRangesObj::removeByIndex( sal_Int32 nIndex
)
1141 throw(uno::RuntimeException
)
1143 SolarMutexGuard aGuard
;
1144 sal_Bool bDone
= false;
1147 ScDocument
* pDoc
= pDocShell
->GetDocument();
1148 ScRangePairList
* pOldList
= bColumn
? pDoc
->GetColNameRanges() : pDoc
->GetRowNameRanges();
1150 if ( pOldList
&& nIndex
>= 0 && nIndex
< (sal_Int32
)pOldList
->size() )
1152 ScRangePairListRef
xNewList(pOldList
->Clone());
1154 ScRangePair
* pEntry
= (*xNewList
)[nIndex
];
1157 xNewList
->Remove( pEntry
);
1161 pDoc
->GetColNameRangesRef() = xNewList
;
1163 pDoc
->GetRowNameRangesRef() = xNewList
;
1165 pDoc
->CompileColRowNameFormula();
1166 pDocShell
->PostPaint( 0,0,0, MAXCOL
,MAXROW
,MAXTAB
, PAINT_GRID
);
1167 pDocShell
->SetDocumentModified();
1170 //! Undo ?!?! (hier und aus Dialog)
1175 throw uno::RuntimeException(); // no other exceptions specified
1178 // container::XEnumerationAccess
1180 uno::Reference
<container::XEnumeration
> SAL_CALL
ScLabelRangesObj::createEnumeration()
1181 throw(uno::RuntimeException
)
1183 SolarMutexGuard aGuard
;
1184 return new ScIndexEnumeration(this, OUString("com.sun.star.sheet.LabelRangesEnumeration"));
1187 // container::XIndexAccess
1189 sal_Int32 SAL_CALL
ScLabelRangesObj::getCount() throw(uno::RuntimeException
)
1191 SolarMutexGuard aGuard
;
1194 ScDocument
* pDoc
= pDocShell
->GetDocument();
1195 ScRangePairList
* pList
= bColumn
? pDoc
->GetColNameRanges() : pDoc
->GetRowNameRanges();
1197 return pList
->size();
1202 uno::Any SAL_CALL
ScLabelRangesObj::getByIndex( sal_Int32 nIndex
)
1203 throw(lang::IndexOutOfBoundsException
,
1204 lang::WrappedTargetException
, uno::RuntimeException
)
1206 SolarMutexGuard aGuard
;
1207 uno::Reference
< sheet::XLabelRange
> xRange(GetObjectByIndex_Impl((sal_uInt16
)nIndex
));
1209 return uno::makeAny(xRange
);
1211 throw lang::IndexOutOfBoundsException();
1214 uno::Type SAL_CALL
ScLabelRangesObj::getElementType() throw(uno::RuntimeException
)
1216 SolarMutexGuard aGuard
;
1217 return ::getCppuType((const uno::Reference
< sheet::XLabelRange
>*)0); // muss zu getByIndex passen
1221 sal_Bool SAL_CALL
ScLabelRangesObj::hasElements() throw(uno::RuntimeException
)
1223 SolarMutexGuard aGuard
;
1224 return ( getCount() != 0 );
1227 //------------------------------------------------------------------------
1231 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */