1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: nameuno.cxx,v $
10 * $Revision: 1.21.132.2 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sc.hxx"
36 #include <svtools/smplhint.hxx>
38 #include <com/sun/star/sheet/NamedRangeFlag.hpp>
39 #include <com/sun/star/awt/XBitmap.hpp>
40 #include <com/sun/star/beans/PropertyAttribute.hpp>
42 using namespace ::com::sun::star
;
45 #include "nameuno.hxx"
46 #include "miscuno.hxx"
47 #include "cellsuno.hxx"
48 #include "convuno.hxx"
49 #include "targuno.hxx"
50 #include "tokenuno.hxx"
51 #include "tokenarray.hxx"
53 #include "docfunc.hxx"
54 #include "rangenam.hxx"
55 //CHINA001 #include "namecrea.hxx" // NAME_TOP etc.
56 #include "unoguard.hxx"
57 #include "unonames.hxx"
59 #include "scui_def.hxx" //CHINA001
61 //------------------------------------------------------------------------
63 const SfxItemPropertyMapEntry
* lcl_GetNamedRangeMap()
65 static SfxItemPropertyMapEntry aNamedRangeMap_Impl
[] =
67 {MAP_CHAR_LEN(SC_UNO_LINKDISPBIT
), 0, &getCppuType((uno::Reference
<awt::XBitmap
>*)0), beans::PropertyAttribute::READONLY
, 0 },
68 {MAP_CHAR_LEN(SC_UNO_LINKDISPNAME
), 0, &getCppuType((rtl::OUString
*)0), beans::PropertyAttribute::READONLY
, 0 },
69 {MAP_CHAR_LEN(SC_UNONAME_TOKENINDEX
), 0, &getCppuType((sal_Int32
*)0), beans::PropertyAttribute::READONLY
, 0 },
70 {MAP_CHAR_LEN(SC_UNONAME_ISSHAREDFMLA
), 0, &getBooleanCppuType(), 0, 0 },
73 return aNamedRangeMap_Impl
;
76 //------------------------------------------------------------------------
78 #define SCNAMEDRANGEOBJ_SERVICE "com.sun.star.sheet.NamedRange"
80 SC_SIMPLE_SERVICE_INFO( ScLabelRangeObj
, "ScLabelRangeObj", "com.sun.star.sheet.LabelRange" )
81 SC_SIMPLE_SERVICE_INFO( ScLabelRangesObj
, "ScLabelRangesObj", "com.sun.star.sheet.LabelRanges" )
82 SC_SIMPLE_SERVICE_INFO( ScNamedRangesObj
, "ScNamedRangesObj", "com.sun.star.sheet.NamedRanges" )
84 //------------------------------------------------------------------------
86 sal_Bool
lcl_UserVisibleName( const ScRangeData
* pData
)
88 //! als Methode an ScRangeData
90 return ( pData
&& !pData
->HasType( RT_DATABASE
) && !pData
->HasType( RT_SHARED
) );
93 //------------------------------------------------------------------------
95 ScNamedRangeObj::ScNamedRangeObj(ScDocShell
* pDocSh
, const String
& rNm
) :
99 pDocShell
->GetDocument()->AddUnoObject(*this);
102 ScNamedRangeObj::~ScNamedRangeObj()
105 pDocShell
->GetDocument()->RemoveUnoObject(*this);
108 void ScNamedRangeObj::Notify( SfxBroadcaster
&, const SfxHint
& rHint
)
110 // Ref-Update interessiert nicht
112 if ( rHint
.ISA( SfxSimpleHint
) && ((const SfxSimpleHint
&)rHint
).GetId() == SFX_HINT_DYING
)
113 pDocShell
= NULL
; // ungueltig geworden
118 ScRangeData
* ScNamedRangeObj::GetRangeData_Impl()
120 ScRangeData
* pRet
= NULL
;
123 ScRangeName
* pNames
= pDocShell
->GetDocument()->GetRangeName();
127 if (pNames
->SearchName( aName
, nPos
))
129 pRet
= (*pNames
)[nPos
];
130 pRet
->ValidateTabRefs(); // adjust relative tab refs to valid tables
137 // sheet::XNamedRange
139 void ScNamedRangeObj::Modify_Impl( const String
* pNewName
, const ScTokenArray
* pNewTokens
, const String
* pNewContent
,
140 const ScAddress
* pNewPos
, const sal_uInt16
* pNewType
,
141 const formula::FormulaGrammar::Grammar eGrammar
)
145 ScDocument
* pDoc
= pDocShell
->GetDocument();
146 ScRangeName
* pNames
= pDoc
->GetRangeName();
150 if (pNames
->SearchName( aName
, nPos
))
152 ScRangeName
* pNewRanges
= new ScRangeName( *pNames
);
153 ScRangeData
* pOld
= (*pNames
)[nPos
];
155 String
aInsName(pOld
->GetName());
157 aInsName
= *pNewName
;
158 String aContent
; // Content string based =>
159 pOld
->GetSymbol( aContent
, eGrammar
); // no problems with changed positions and such.
161 aContent
= *pNewContent
;
162 ScAddress
aPos(pOld
->GetPos());
165 sal_uInt16 nType
= pOld
->GetType();
169 ScRangeData
* pNew
= NULL
;
171 pNew
= new ScRangeData( pDoc
, aInsName
, *pNewTokens
, aPos
, nType
);
173 pNew
= new ScRangeData( pDoc
, aInsName
, aContent
, aPos
, nType
, eGrammar
);
174 pNew
->SetIndex( pOld
->GetIndex() );
176 pNewRanges
->AtFree( nPos
);
177 if ( pNewRanges
->Insert(pNew
) )
179 ScDocFunc
aFunc(*pDocShell
);
180 aFunc
.SetNewRangeNames( pNewRanges
, sal_True
);
182 aName
= aInsName
; //! broadcast?
186 delete pNew
; //! uno::Exception/Fehler oder so
195 rtl::OUString SAL_CALL
ScNamedRangeObj::getName() throw(uno::RuntimeException
)
201 void SAL_CALL
ScNamedRangeObj::setName( const rtl::OUString
& aNewName
)
202 throw(uno::RuntimeException
)
205 //! Formeln anpassen ?????
207 String
aNewStr(aNewName
);
208 // GRAM_PODF_A1 for API compatibility.
209 Modify_Impl( &aNewStr
, NULL
, NULL
, NULL
, NULL
,formula::FormulaGrammar::GRAM_PODF_A1
);
211 if ( aName
!= aNewStr
) // some error occured...
212 throw uno::RuntimeException(); // no other exceptions specified
215 rtl::OUString SAL_CALL
ScNamedRangeObj::getContent() throw(uno::RuntimeException
)
219 ScRangeData
* pData
= GetRangeData_Impl();
221 // GRAM_PODF_A1 for API compatibility.
222 pData
->GetSymbol( aContent
,formula::FormulaGrammar::GRAM_PODF_A1
);
226 void SAL_CALL
ScNamedRangeObj::setContent( const rtl::OUString
& aContent
)
227 throw(uno::RuntimeException
)
230 String
aContStr(aContent
);
231 // GRAM_PODF_A1 for API compatibility.
232 Modify_Impl( NULL
, NULL
, &aContStr
, NULL
, NULL
,formula::FormulaGrammar::GRAM_PODF_A1
);
235 void ScNamedRangeObj::SetContentWithGrammar( const ::rtl::OUString
& aContent
,
236 const formula::FormulaGrammar::Grammar eGrammar
)
237 throw(::com::sun::star::uno::RuntimeException
)
239 String
aContStr(aContent
);
240 Modify_Impl( NULL
, NULL
, &aContStr
, NULL
, NULL
, eGrammar
);
243 table::CellAddress SAL_CALL
ScNamedRangeObj::getReferencePosition()
244 throw(uno::RuntimeException
)
248 ScRangeData
* pData
= GetRangeData_Impl();
250 aPos
= pData
->GetPos();
251 table::CellAddress aAddress
;
252 aAddress
.Column
= aPos
.Col();
253 aAddress
.Row
= aPos
.Row();
254 aAddress
.Sheet
= aPos
.Tab();
257 SCTAB nDocTabs
= pDocShell
->GetDocument()->GetTableCount();
258 if ( aAddress
.Sheet
>= nDocTabs
&& nDocTabs
> 0 )
260 // Even after ValidateTabRefs, the position can be invalid if
261 // the content points to preceding tables. The resulting string
262 // is invalid in any case, so the position is just shifted.
263 aAddress
.Sheet
= nDocTabs
- 1;
269 void SAL_CALL
ScNamedRangeObj::setReferencePosition( const table::CellAddress
& aReferencePosition
)
270 throw(uno::RuntimeException
)
273 ScAddress
aPos( (SCCOL
)aReferencePosition
.Column
, (SCROW
)aReferencePosition
.Row
, aReferencePosition
.Sheet
);
274 // GRAM_PODF_A1 for API compatibility.
275 Modify_Impl( NULL
, NULL
, NULL
, &aPos
, NULL
,formula::FormulaGrammar::GRAM_PODF_A1
);
278 sal_Int32 SAL_CALL
ScNamedRangeObj::getType() throw(uno::RuntimeException
)
282 ScRangeData
* pData
= GetRangeData_Impl();
285 // do not return internal RT_* flags
286 // see property 'IsSharedFormula' for RT_SHARED
287 if ( pData
->HasType(RT_CRITERIA
) ) nType
|= sheet::NamedRangeFlag::FILTER_CRITERIA
;
288 if ( pData
->HasType(RT_PRINTAREA
) ) nType
|= sheet::NamedRangeFlag::PRINT_AREA
;
289 if ( pData
->HasType(RT_COLHEADER
) ) nType
|= sheet::NamedRangeFlag::COLUMN_HEADER
;
290 if ( pData
->HasType(RT_ROWHEADER
) ) nType
|= sheet::NamedRangeFlag::ROW_HEADER
;
295 void SAL_CALL
ScNamedRangeObj::setType( sal_Int32 nUnoType
) throw(uno::RuntimeException
)
297 // see property 'IsSharedFormula' for RT_SHARED
299 sal_uInt16 nNewType
= RT_NAME
;
300 if ( nUnoType
& sheet::NamedRangeFlag::FILTER_CRITERIA
) nNewType
|= RT_CRITERIA
;
301 if ( nUnoType
& sheet::NamedRangeFlag::PRINT_AREA
) nNewType
|= RT_PRINTAREA
;
302 if ( nUnoType
& sheet::NamedRangeFlag::COLUMN_HEADER
) nNewType
|= RT_COLHEADER
;
303 if ( nUnoType
& sheet::NamedRangeFlag::ROW_HEADER
) nNewType
|= RT_ROWHEADER
;
305 // GRAM_PODF_A1 for API compatibility.
306 Modify_Impl( NULL
, NULL
, NULL
, NULL
, &nNewType
,formula::FormulaGrammar::GRAM_PODF_A1
);
311 uno::Sequence
<sheet::FormulaToken
> SAL_CALL
ScNamedRangeObj::getTokens() throw(uno::RuntimeException
)
314 uno::Sequence
<sheet::FormulaToken
> aSequence
;
315 ScRangeData
* pData
= GetRangeData_Impl();
316 if (pData
&& pDocShell
)
318 ScTokenArray
* pTokenArray
= pData
->GetCode();
320 (void)ScTokenConversion::ConvertToTokenSequence( *pDocShell
->GetDocument(), aSequence
, *pTokenArray
);
325 void SAL_CALL
ScNamedRangeObj::setTokens( const uno::Sequence
<sheet::FormulaToken
>& rTokens
) throw(uno::RuntimeException
)
330 ScTokenArray aTokenArray
;
331 (void)ScTokenConversion::ConvertToTokenArray( *pDocShell
->GetDocument(), aTokenArray
, rTokens
);
332 // GRAM_PODF_A1 for API compatibility.
333 Modify_Impl( NULL
, &aTokenArray
, NULL
, NULL
, NULL
, formula::FormulaGrammar::GRAM_PODF_A1
);
340 uno::Reference
<table::XCellRange
> SAL_CALL
ScNamedRangeObj::getReferredCells()
341 throw(uno::RuntimeException
)
345 ScRangeData
* pData
= GetRangeData_Impl();
346 if ( pData
&& pData
->IsReference( aRange
) )
348 //! static Funktion um ScCellObj/ScCellRangeObj zu erzeugen am ScCellRangeObj ???
350 if ( aRange
.aStart
== aRange
.aEnd
)
351 return new ScCellObj( pDocShell
, aRange
.aStart
);
353 return new ScCellRangeObj( pDocShell
, aRange
);
358 // beans::XPropertySet
360 uno::Reference
<beans::XPropertySetInfo
> SAL_CALL
ScNamedRangeObj::getPropertySetInfo()
361 throw(uno::RuntimeException
)
364 static uno::Reference
< beans::XPropertySetInfo
> aRef(new SfxItemPropertySetInfo( lcl_GetNamedRangeMap() ));
368 void SAL_CALL
ScNamedRangeObj::setPropertyValue(
369 const rtl::OUString
& rPropertyName
, const uno::Any
& aValue
)
370 throw(beans::UnknownPropertyException
, beans::PropertyVetoException
,
371 lang::IllegalArgumentException
, lang::WrappedTargetException
,
372 uno::RuntimeException
)
375 if ( rPropertyName
.equalsAscii( SC_UNONAME_ISSHAREDFMLA
) )
377 bool bIsShared
= false;
378 if( aValue
>>= bIsShared
)
380 sal_uInt16 nNewType
= bIsShared
? RT_SHARED
: RT_NAME
;
381 Modify_Impl( NULL
, NULL
, NULL
, NULL
, &nNewType
,formula::FormulaGrammar::GRAM_PODF_A1
);
386 uno::Any SAL_CALL
ScNamedRangeObj::getPropertyValue( const rtl::OUString
& rPropertyName
)
387 throw(beans::UnknownPropertyException
, lang::WrappedTargetException
,
388 uno::RuntimeException
)
392 if ( rPropertyName
.equalsAscii( SC_UNO_LINKDISPBIT
) )
394 // no target bitmaps for individual entries (would be all equal)
395 // ScLinkTargetTypeObj::SetLinkTargetBitmap( aRet, SC_LINKTARGETTYPE_RANGENAME );
397 else if ( rPropertyName
.equalsAscii( SC_UNO_LINKDISPNAME
) )
398 aRet
<<= rtl::OUString( aName
);
399 else if ( rPropertyName
.equalsAscii( SC_UNONAME_TOKENINDEX
) )
401 // get index for use in formula tokens (read-only)
402 ScRangeData
* pData
= GetRangeData_Impl();
404 aRet
<<= static_cast<sal_Int32
>(pData
->GetIndex());
406 else if ( rPropertyName
.equalsAscii( SC_UNONAME_ISSHAREDFMLA
) )
408 if( ScRangeData
* pData
= GetRangeData_Impl() )
409 aRet
<<= static_cast< bool >( pData
->HasType( RT_SHARED
) );
414 SC_IMPL_DUMMY_PROPERTY_LISTENER( ScNamedRangeObj
)
416 // lang::XServiceInfo
418 rtl::OUString SAL_CALL
ScNamedRangeObj::getImplementationName() throw(uno::RuntimeException
)
420 return rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ScNamedRangeObj" ) );
423 sal_Bool SAL_CALL
ScNamedRangeObj::supportsService( const rtl::OUString
& rServiceName
)
424 throw(uno::RuntimeException
)
426 return rServiceName
.equalsAscii( SCNAMEDRANGEOBJ_SERVICE
) ||
427 rServiceName
.equalsAscii( SCLINKTARGET_SERVICE
);
430 uno::Sequence
<rtl::OUString
> SAL_CALL
ScNamedRangeObj::getSupportedServiceNames()
431 throw(uno::RuntimeException
)
433 uno::Sequence
<rtl::OUString
> aRet(2);
434 aRet
[0] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SCNAMEDRANGEOBJ_SERVICE
) );
435 aRet
[1] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SCLINKTARGET_SERVICE
) );
442 sal_Int64 SAL_CALL
ScNamedRangeObj::getSomething(
443 const uno::Sequence
<sal_Int8
>& rId
) throw(uno::RuntimeException
)
445 if ( rId
.getLength() == 16 &&
446 0 == rtl_compareMemory( getUnoTunnelId().getConstArray(),
447 rId
.getConstArray(), 16 ) )
449 return sal::static_int_cast
<sal_Int64
>(reinterpret_cast<sal_IntPtr
>(this));
455 const uno::Sequence
<sal_Int8
>& ScNamedRangeObj::getUnoTunnelId()
457 static uno::Sequence
<sal_Int8
> * pSeq
= 0;
460 osl::Guard
< osl::Mutex
> aGuard( osl::Mutex::getGlobalMutex() );
463 static uno::Sequence
< sal_Int8
> aSeq( 16 );
464 rtl_createUuid( (sal_uInt8
*)aSeq
.getArray(), 0, sal_True
);
472 ScNamedRangeObj
* ScNamedRangeObj::getImplementation( const uno::Reference
<uno::XInterface
> xObj
)
474 ScNamedRangeObj
* pRet
= NULL
;
475 uno::Reference
<lang::XUnoTunnel
> xUT( xObj
, uno::UNO_QUERY
);
477 pRet
= reinterpret_cast<ScNamedRangeObj
*>(sal::static_int_cast
<sal_IntPtr
>(xUT
->getSomething(getUnoTunnelId())));
481 //------------------------------------------------------------------------
483 ScNamedRangesObj::ScNamedRangesObj(ScDocShell
* pDocSh
) :
486 pDocShell
->GetDocument()->AddUnoObject(*this);
489 ScNamedRangesObj::~ScNamedRangesObj()
492 pDocShell
->GetDocument()->RemoveUnoObject(*this);
495 void ScNamedRangesObj::Notify( SfxBroadcaster
&, const SfxHint
& rHint
)
497 // Referenz-Update interessiert hier nicht
499 if ( rHint
.ISA( SfxSimpleHint
) &&
500 ((const SfxSimpleHint
&)rHint
).GetId() == SFX_HINT_DYING
)
502 pDocShell
= NULL
; // ungueltig geworden
506 // sheet::XNamedRanges
508 ScNamedRangeObj
* ScNamedRangesObj::GetObjectByIndex_Impl(sal_uInt16 nIndex
)
512 ScRangeName
* pNames
= pDocShell
->GetDocument()->GetRangeName();
515 sal_uInt16 nCount
= pNames
->GetCount();
517 for (sal_uInt16 i
=0; i
<nCount
; i
++)
519 ScRangeData
* pData
= (*pNames
)[i
];
520 if (lcl_UserVisibleName(pData
)) // interne weglassen
522 if ( nPos
== nIndex
)
523 return new ScNamedRangeObj( pDocShell
, pData
->GetName() );
532 ScNamedRangeObj
* ScNamedRangesObj::GetObjectByName_Impl(const rtl::OUString
& aName
)
534 if ( pDocShell
&& hasByName(aName
) )
535 return new ScNamedRangeObj( pDocShell
, String(aName
) );
539 void SAL_CALL
ScNamedRangesObj::addNewByName( const rtl::OUString
& aName
,
540 const rtl::OUString
& aContent
, const table::CellAddress
& aPosition
,
541 sal_Int32 nUnoType
) throw(uno::RuntimeException
)
544 String
aNameStr(aName
);
545 String
aContStr(aContent
);
546 ScAddress
aPos( (SCCOL
)aPosition
.Column
, (SCROW
)aPosition
.Row
, aPosition
.Sheet
);
548 sal_uInt16 nNewType
= RT_NAME
;
549 if ( nUnoType
& sheet::NamedRangeFlag::FILTER_CRITERIA
) nNewType
|= RT_CRITERIA
;
550 if ( nUnoType
& sheet::NamedRangeFlag::PRINT_AREA
) nNewType
|= RT_PRINTAREA
;
551 if ( nUnoType
& sheet::NamedRangeFlag::COLUMN_HEADER
) nNewType
|= RT_COLHEADER
;
552 if ( nUnoType
& sheet::NamedRangeFlag::ROW_HEADER
) nNewType
|= RT_ROWHEADER
;
557 ScDocument
* pDoc
= pDocShell
->GetDocument();
558 ScRangeName
* pNames
= pDoc
->GetRangeName();
560 if (pNames
&& !pNames
->SearchName(aNameStr
, nIndex
))
562 ScRangeName
* pNewRanges
= new ScRangeName( *pNames
);
563 // GRAM_PODF_A1 for API compatibility.
564 ScRangeData
* pNew
= new ScRangeData( pDoc
, aNameStr
, aContStr
,
565 aPos
, nNewType
,formula::FormulaGrammar::GRAM_PODF_A1
);
566 if ( pNewRanges
->Insert(pNew
) )
568 ScDocFunc
aFunc(*pDocShell
);
569 aFunc
.SetNewRangeNames( pNewRanges
, sal_True
);
581 throw uno::RuntimeException(); // no other exceptions specified
584 void SAL_CALL
ScNamedRangesObj::addNewFromTitles( const table::CellRangeAddress
& aSource
,
585 sheet::Border aBorder
) throw(uno::RuntimeException
)
588 //! das darf kein enum sein, weil mehrere Bits gesetzt sein koennen !!!
590 sal_Bool bTop
= ( aBorder
== sheet::Border_TOP
);
591 sal_Bool bLeft
= ( aBorder
== sheet::Border_LEFT
);
592 sal_Bool bBottom
= ( aBorder
== sheet::Border_BOTTOM
);
593 sal_Bool bRight
= ( aBorder
== sheet::Border_RIGHT
);
596 ScUnoConversion::FillScRange( aRange
, aSource
);
598 sal_uInt16 nFlags
= 0;
599 if (bTop
) nFlags
|= NAME_TOP
;
600 if (bLeft
) nFlags
|= NAME_LEFT
;
601 if (bBottom
) nFlags
|= NAME_BOTTOM
;
602 if (bRight
) nFlags
|= NAME_RIGHT
;
606 ScDocFunc
aFunc(*pDocShell
);
607 aFunc
.CreateNames( aRange
, nFlags
, sal_True
);
611 void SAL_CALL
ScNamedRangesObj::removeByName( const rtl::OUString
& aName
)
612 throw(uno::RuntimeException
)
618 ScRangeName
* pNames
= pDocShell
->GetDocument()->GetRangeName();
621 String
aString(aName
);
623 if (pNames
->SearchName( aString
, nPos
))
624 if ( lcl_UserVisibleName((*pNames
)[nPos
]) )
626 ScRangeName
* pNewRanges
= new ScRangeName(*pNames
);
627 pNewRanges
->AtFree(nPos
);
628 ScDocFunc
aFunc(*pDocShell
);
629 aFunc
.SetNewRangeNames( pNewRanges
, sal_True
);
636 throw uno::RuntimeException(); // no other exceptions specified
639 void SAL_CALL
ScNamedRangesObj::outputList( const table::CellAddress
& aOutputPosition
)
640 throw(uno::RuntimeException
)
643 ScAddress
aPos( (SCCOL
)aOutputPosition
.Column
, (SCROW
)aOutputPosition
.Row
, aOutputPosition
.Sheet
);
646 ScDocFunc
aFunc(*pDocShell
);
647 aFunc
.InsertNameList( aPos
, sal_True
);
651 // container::XEnumerationAccess
653 uno::Reference
<container::XEnumeration
> SAL_CALL
ScNamedRangesObj::createEnumeration()
654 throw(uno::RuntimeException
)
657 return new ScIndexEnumeration(this, rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.sheet.NamedRangesEnumeration")));
660 // container::XIndexAccess
662 sal_Int32 SAL_CALL
ScNamedRangesObj::getCount() throw(uno::RuntimeException
)
668 ScRangeName
* pNames
= pDocShell
->GetDocument()->GetRangeName();
671 sal_uInt16 nCount
= pNames
->GetCount();
672 for (sal_uInt16 i
=0; i
<nCount
; i
++)
673 if (lcl_UserVisibleName( (*pNames
)[i
] )) // interne weglassen
680 uno::Any SAL_CALL
ScNamedRangesObj::getByIndex( sal_Int32 nIndex
)
681 throw(lang::IndexOutOfBoundsException
,
682 lang::WrappedTargetException
, uno::RuntimeException
)
685 uno::Reference
< sheet::XNamedRange
> xRange(GetObjectByIndex_Impl((sal_uInt16
)nIndex
));
687 return uno::makeAny(xRange
);
689 throw lang::IndexOutOfBoundsException();
690 // return uno::Any();
693 uno::Type SAL_CALL
ScNamedRangesObj::getElementType() throw(uno::RuntimeException
)
696 return ::getCppuType((const uno::Reference
< sheet::XNamedRange
>*)0); // muss zu getByIndex passen
699 sal_Bool SAL_CALL
ScNamedRangesObj::hasElements() throw(uno::RuntimeException
)
702 return ( getCount() != 0 );
705 uno::Any SAL_CALL
ScNamedRangesObj::getByName( const rtl::OUString
& aName
)
706 throw(container::NoSuchElementException
,
707 lang::WrappedTargetException
, uno::RuntimeException
)
710 uno::Reference
< sheet::XNamedRange
> xRange(GetObjectByName_Impl(aName
));
712 return uno::makeAny(xRange
);
714 throw container::NoSuchElementException();
715 // return uno::Any();
718 uno::Sequence
<rtl::OUString
> SAL_CALL
ScNamedRangesObj::getElementNames()
719 throw(uno::RuntimeException
)
724 ScRangeName
* pNames
= pDocShell
->GetDocument()->GetRangeName();
727 long nVisCount
= getCount(); // Namen mit lcl_UserVisibleName
728 uno::Sequence
<rtl::OUString
> aSeq(nVisCount
);
729 rtl::OUString
* pAry
= aSeq
.getArray();
731 sal_uInt16 nCount
= pNames
->GetCount();
732 sal_uInt16 nVisPos
= 0;
733 for (sal_uInt16 i
=0; i
<nCount
; i
++)
735 ScRangeData
* pData
= (*pNames
)[i
];
736 if ( lcl_UserVisibleName(pData
) )
737 pAry
[nVisPos
++] = pData
->GetName();
739 // DBG_ASSERT(nVisPos == nVisCount, "huch, verzaehlt?");
743 return uno::Sequence
<rtl::OUString
>(0);
746 sal_Bool SAL_CALL
ScNamedRangesObj::hasByName( const rtl::OUString
& aName
)
747 throw(uno::RuntimeException
)
752 ScRangeName
* pNames
= pDocShell
->GetDocument()->GetRangeName();
756 if (pNames
->SearchName( String(aName
), nPos
))
757 if ( lcl_UserVisibleName((*pNames
)[nPos
]) )
764 /** called from the XActionLockable interface methods on initial locking */
765 void ScNamedRangesObj::lock()
767 pDocShell
->GetDocument()->CompileNameFormula( TRUE
); // CreateFormulaString
770 /** called from the XActionLockable interface methods on final unlock */
771 void ScNamedRangesObj::unlock()
773 pDocShell
->GetDocument()->CompileNameFormula( FALSE
); // CompileFormulaString
776 // document::XActionLockable
778 sal_Bool
ScNamedRangesObj::isActionLocked() throw(uno::RuntimeException
)
781 return pDocShell
->GetDocument()->GetNamedRangesLockCount() != 0;
784 void ScNamedRangesObj::addActionLock() throw(uno::RuntimeException
)
787 ScDocument
* pDoc
= pDocShell
->GetDocument();
788 sal_Int16 nLockCount
= pDoc
->GetNamedRangesLockCount();
790 if ( nLockCount
== 1 )
794 pDoc
->SetNamedRangesLockCount( nLockCount
);
797 void ScNamedRangesObj::removeActionLock() throw(uno::RuntimeException
)
800 ScDocument
* pDoc
= pDocShell
->GetDocument();
801 sal_Int16 nLockCount
= pDoc
->GetNamedRangesLockCount();
802 if ( nLockCount
> 0 )
805 if ( nLockCount
== 0 )
809 pDoc
->SetNamedRangesLockCount( nLockCount
);
813 void ScNamedRangesObj::setActionLocks( sal_Int16 nLock
) throw(uno::RuntimeException
)
818 ScDocument
* pDoc
= pDocShell
->GetDocument();
819 sal_Int16 nLockCount
= pDoc
->GetNamedRangesLockCount();
820 if ( nLock
== 0 && nLockCount
> 0 )
824 if ( nLock
> 0 && nLockCount
== 0 )
828 pDoc
->SetNamedRangesLockCount( nLock
);
832 sal_Int16
ScNamedRangesObj::resetActionLocks() throw(uno::RuntimeException
)
835 ScDocument
* pDoc
= pDocShell
->GetDocument();
836 sal_Int16 nLockCount
= pDoc
->GetNamedRangesLockCount();
837 if ( nLockCount
> 0 )
841 pDoc
->SetNamedRangesLockCount( 0 );
845 //------------------------------------------------------------------------
847 ScLabelRangeObj::ScLabelRangeObj(ScDocShell
* pDocSh
, sal_Bool bCol
, const ScRange
& rR
) :
852 pDocShell
->GetDocument()->AddUnoObject(*this);
855 ScLabelRangeObj::~ScLabelRangeObj()
858 pDocShell
->GetDocument()->RemoveUnoObject(*this);
861 void ScLabelRangeObj::Notify( SfxBroadcaster
&, const SfxHint
& rHint
)
865 if ( rHint
.ISA( SfxSimpleHint
) && ((const SfxSimpleHint
&)rHint
).GetId() == SFX_HINT_DYING
)
866 pDocShell
= NULL
; // ungueltig geworden
871 ScRangePair
* ScLabelRangeObj::GetData_Impl()
873 ScRangePair
* pRet
= NULL
;
876 ScDocument
* pDoc
= pDocShell
->GetDocument();
877 ScRangePairList
* pList
= bColumn
? pDoc
->GetColNameRanges() : pDoc
->GetRowNameRanges();
879 pRet
= pList
->Find( aRange
);
884 void ScLabelRangeObj::Modify_Impl( const ScRange
* pLabel
, const ScRange
* pData
)
888 ScDocument
* pDoc
= pDocShell
->GetDocument();
889 ScRangePairList
* pOldList
= bColumn
? pDoc
->GetColNameRanges() : pDoc
->GetRowNameRanges();
892 ScRangePairListRef
xNewList(pOldList
->Clone());
893 ScRangePair
* pEntry
= xNewList
->Find( aRange
);
896 xNewList
->Remove( pEntry
); // nur aus der Liste entfernt, nicht geloescht
899 pEntry
->GetRange(0) = *pLabel
;
901 pEntry
->GetRange(1) = *pData
;
903 xNewList
->Join( *pEntry
);
907 pDoc
->GetColNameRangesRef() = xNewList
;
909 pDoc
->GetRowNameRangesRef() = xNewList
;
911 pDoc
->CompileColRowNameFormula();
912 pDocShell
->PostPaint( 0,0,0, MAXCOL
,MAXROW
,MAXTAB
, PAINT_GRID
);
913 pDocShell
->SetDocumentModified();
915 //! Undo ?!?! (hier und aus Dialog)
918 aRange
= *pLabel
; // Objekt anpassen, um Range wiederzufinden
924 // sheet::XLabelRange
926 table::CellRangeAddress SAL_CALL
ScLabelRangeObj::getLabelArea()
927 throw(uno::RuntimeException
)
930 table::CellRangeAddress aRet
;
931 ScRangePair
* pData
= GetData_Impl();
933 ScUnoConversion::FillApiRange( aRet
, pData
->GetRange(0) );
937 void SAL_CALL
ScLabelRangeObj::setLabelArea( const table::CellRangeAddress
& aLabelArea
)
938 throw(uno::RuntimeException
)
942 ScUnoConversion::FillScRange( aLabelRange
, aLabelArea
);
943 Modify_Impl( &aLabelRange
, NULL
);
946 table::CellRangeAddress SAL_CALL
ScLabelRangeObj::getDataArea()
947 throw(uno::RuntimeException
)
950 table::CellRangeAddress aRet
;
951 ScRangePair
* pData
= GetData_Impl();
953 ScUnoConversion::FillApiRange( aRet
, pData
->GetRange(1) );
957 void SAL_CALL
ScLabelRangeObj::setDataArea( const table::CellRangeAddress
& aDataArea
)
958 throw(uno::RuntimeException
)
962 ScUnoConversion::FillScRange( aDataRange
, aDataArea
);
963 Modify_Impl( NULL
, &aDataRange
);
966 //------------------------------------------------------------------------
968 ScLabelRangesObj::ScLabelRangesObj(ScDocShell
* pDocSh
, sal_Bool bCol
) :
972 pDocShell
->GetDocument()->AddUnoObject(*this);
975 ScLabelRangesObj::~ScLabelRangesObj()
978 pDocShell
->GetDocument()->RemoveUnoObject(*this);
981 void ScLabelRangesObj::Notify( SfxBroadcaster
&, const SfxHint
& rHint
)
983 // Referenz-Update interessiert hier nicht
985 if ( rHint
.ISA( SfxSimpleHint
) &&
986 ((const SfxSimpleHint
&)rHint
).GetId() == SFX_HINT_DYING
)
988 pDocShell
= NULL
; // ungueltig geworden
992 // sheet::XLabelRanges
994 ScLabelRangeObj
* ScLabelRangesObj::GetObjectByIndex_Impl(sal_uInt16 nIndex
)
998 ScDocument
* pDoc
= pDocShell
->GetDocument();
999 ScRangePairList
* pList
= bColumn
? pDoc
->GetColNameRanges() : pDoc
->GetRowNameRanges();
1000 if ( pList
&& nIndex
< pList
->Count() )
1002 ScRangePair
* pData
= pList
->GetObject(nIndex
);
1004 return new ScLabelRangeObj( pDocShell
, bColumn
, pData
->GetRange(0) );
1010 void SAL_CALL
ScLabelRangesObj::addNew( const table::CellRangeAddress
& aLabelArea
,
1011 const table::CellRangeAddress
& aDataArea
)
1012 throw(uno::RuntimeException
)
1017 ScDocument
* pDoc
= pDocShell
->GetDocument();
1018 ScRangePairList
* pOldList
= bColumn
? pDoc
->GetColNameRanges() : pDoc
->GetRowNameRanges();
1021 ScRangePairListRef
xNewList(pOldList
->Clone());
1023 ScRange aLabelRange
;
1025 ScUnoConversion::FillScRange( aLabelRange
, aLabelArea
);
1026 ScUnoConversion::FillScRange( aDataRange
, aDataArea
);
1027 xNewList
->Join( ScRangePair( aLabelRange
, aDataRange
) );
1030 pDoc
->GetColNameRangesRef() = xNewList
;
1032 pDoc
->GetRowNameRangesRef() = xNewList
;
1034 pDoc
->CompileColRowNameFormula();
1035 pDocShell
->PostPaint( 0,0,0, MAXCOL
,MAXROW
,MAXTAB
, PAINT_GRID
);
1036 pDocShell
->SetDocumentModified();
1038 //! Undo ?!?! (hier und aus Dialog)
1043 void SAL_CALL
ScLabelRangesObj::removeByIndex( sal_Int32 nIndex
)
1044 throw(uno::RuntimeException
)
1050 ScDocument
* pDoc
= pDocShell
->GetDocument();
1051 ScRangePairList
* pOldList
= bColumn
? pDoc
->GetColNameRanges() : pDoc
->GetRowNameRanges();
1053 if ( pOldList
&& nIndex
>= 0 && nIndex
< (sal_Int32
)pOldList
->Count() )
1055 ScRangePairListRef
xNewList(pOldList
->Clone());
1057 ScRangePair
* pEntry
= xNewList
->GetObject( nIndex
);
1060 xNewList
->Remove( pEntry
);
1064 pDoc
->GetColNameRangesRef() = xNewList
;
1066 pDoc
->GetRowNameRangesRef() = xNewList
;
1068 pDoc
->CompileColRowNameFormula();
1069 pDocShell
->PostPaint( 0,0,0, MAXCOL
,MAXROW
,MAXTAB
, PAINT_GRID
);
1070 pDocShell
->SetDocumentModified();
1073 //! Undo ?!?! (hier und aus Dialog)
1078 throw uno::RuntimeException(); // no other exceptions specified
1081 // container::XEnumerationAccess
1083 uno::Reference
<container::XEnumeration
> SAL_CALL
ScLabelRangesObj::createEnumeration()
1084 throw(uno::RuntimeException
)
1087 return new ScIndexEnumeration(this, rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.sheet.LabelRangesEnumeration")));
1090 // container::XIndexAccess
1092 sal_Int32 SAL_CALL
ScLabelRangesObj::getCount() throw(uno::RuntimeException
)
1097 ScDocument
* pDoc
= pDocShell
->GetDocument();
1098 ScRangePairList
* pList
= bColumn
? pDoc
->GetColNameRanges() : pDoc
->GetRowNameRanges();
1100 return pList
->Count();
1105 uno::Any SAL_CALL
ScLabelRangesObj::getByIndex( sal_Int32 nIndex
)
1106 throw(lang::IndexOutOfBoundsException
,
1107 lang::WrappedTargetException
, uno::RuntimeException
)
1110 uno::Reference
< sheet::XLabelRange
> xRange(GetObjectByIndex_Impl((sal_uInt16
)nIndex
));
1112 return uno::makeAny(xRange
);
1114 throw lang::IndexOutOfBoundsException();
1115 // return uno::Any();
1118 uno::Type SAL_CALL
ScLabelRangesObj::getElementType() throw(uno::RuntimeException
)
1121 return ::getCppuType((const uno::Reference
< sheet::XLabelRange
>*)0); // muss zu getByIndex passen
1125 sal_Bool SAL_CALL
ScLabelRangesObj::hasElements() throw(uno::RuntimeException
)
1128 return ( getCount() != 0 );
1131 //------------------------------------------------------------------------