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/style.hxx>
22 #include <com/sun/star/lang/XComponent.hpp>
24 #include <sal/log.hxx>
25 #include <tools/tenccvt.hxx>
26 #include <osl/diagnose.h>
27 #include <comphelper/processfactory.hxx>
28 #include <unotools/intlwrapper.hxx>
29 #include <svl/smplhint.hxx>
30 #include <svl/poolitem.hxx>
31 #include <svl/itemset.hxx>
32 #include <svl/itempool.hxx>
33 #include <svl/IndexedStyleSheets.hxx>
34 #include <svl/itemiter.hxx>
35 #include <unotools/syslocale.hxx>
37 #include <comphelper/servicehelper.hxx>
42 class DbgStyleSheetReferences
45 DbgStyleSheetReferences() : mnStyles(0), mnPools(0) {}
46 ~DbgStyleSheetReferences()
49 mnStyles
!= 0 || mnPools
!= 0, "svl.items",
50 "SfxStyleSheetBase left " << mnStyles
51 << "; SfxStyleSheetBasePool left " << mnPools
);
57 aDbgStyleSheetReferences
;
61 TYPEINIT0(SfxStyleSheetBase
)
63 TYPEINIT3(SfxStyleSheet
, SfxStyleSheetBase
, SfxListener
, SfxBroadcaster
)
65 SfxStyleSheetHintExtended::SfxStyleSheetHintExtended
67 sal_uInt16 nAction
, // SfxStyleSheetHintId::... (see above)
68 const OUString
& rOldName
,
69 SfxStyleSheetBase
& rStyleSheet
// Remains with the caller
71 : SfxStyleSheetHint( nAction
, rStyleSheet
),
76 SfxStyleSheetHint::SfxStyleSheetHint
78 sal_uInt16 nAction
, // SfxStyleSheetHintId::... (see above)
79 SfxStyleSheetBase
& rStyleSheet
// Remains with the caller
81 : pStyleSh( &rStyleSheet
),
86 class SfxStyleSheetBasePool_Impl
89 SfxStyleSheetBasePool_Impl(const SfxStyleSheetBasePool_Impl
&) SAL_DELETED_FUNCTION
;
90 SfxStyleSheetBasePool_Impl
& operator=(const SfxStyleSheetBasePool_Impl
&) SAL_DELETED_FUNCTION
;
92 SfxStyleSheetIteratorPtr pIter
;
94 /** This member holds the indexed style sheets.
97 * This member is private and not protected in order to have more control which style sheets are added
98 * where. Ideally, all calls which add/remove/change style sheets are done in the base class.
100 std::shared_ptr
<svl::IndexedStyleSheets
> mxIndexedStyleSheets
;
102 SfxStyleSheetBasePool_Impl() :
103 mxIndexedStyleSheets(new svl::IndexedStyleSheets
) {}
107 SfxStyleSheetBase::SfxStyleSheetBase( const OUString
& rName
, SfxStyleSheetBasePool
* p
, SfxStyleFamily eFam
, sal_uInt16 mask
)
120 aDbgStyleSheetReferences
.mnStyles
++;
124 SfxStyleSheetBase::SfxStyleSheetBase( const SfxStyleSheetBase
& r
)
125 : comphelper::OWeakTypeObject()
127 , nFamily( r
.nFamily
)
129 , aParent( r
.aParent
)
130 , aFollow( r
.aFollow
)
131 , aHelpFile( r
.aHelpFile
)
133 , nHelpId( r
.nHelpId
)
135 , bHidden( r
.bHidden
)
138 aDbgStyleSheetReferences
.mnStyles
++;
141 pSet
= bMySet
? new SfxItemSet( *r
.pSet
) : r
.pSet
;
146 SfxStyleSheetBase::~SfxStyleSheetBase()
149 --aDbgStyleSheetReferences
.mnStyles
;
160 const OUString
& SfxStyleSheetBase::GetName() const
165 bool SfxStyleSheetBase::SetName(const OUString
& rName
, bool bReIndexNow
)
172 OUString aOldName
= aName
;
173 SfxStyleSheetBase
*pOther
= pPool
->Find( rName
, nFamily
) ;
174 if ( pOther
&& pOther
!= this )
177 SfxStyleFamily eTmpFam
= pPool
->GetSearchFamily();
178 sal_uInt16 nTmpMask
= pPool
->GetSearchMask();
180 pPool
->SetSearchMask(nFamily
);
182 if ( !aName
.isEmpty() )
183 pPool
->ChangeParent( aName
, rName
, false );
185 if ( aFollow
== aName
)
190 pPool
->SetSearchMask(eTmpFam
, nTmpMask
);
191 pPool
->Broadcast( SfxStyleSheetHintExtended(
192 SfxStyleSheetHintId::MODIFIED
, aOldName
, *this ) );
197 OUString
SfxStyleSheetBase::GetDisplayName() const
199 if( maDisplayName
.isEmpty() )
205 return maDisplayName
;
210 const OUString
& SfxStyleSheetBase::GetParent() const
215 bool SfxStyleSheetBase::SetParent( const OUString
& rName
)
217 if ( rName
== aName
)
220 if( aParent
!= rName
)
222 SfxStyleSheetBase
* pIter
= pPool
->Find(rName
, nFamily
);
223 if( !rName
.isEmpty() && !pIter
)
225 OSL_FAIL( "StyleSheet-Parent not found" );
228 // prevent recursive linkages
229 if( !aName
.isEmpty() )
233 if(pIter
->GetName() == aName
)
235 pIter
= pPool
->Find(pIter
->GetParent(), nFamily
);
240 pPool
->Broadcast( SfxStyleSheetHint( SfxStyleSheetHintId::MODIFIED
, *this ) );
244 void SfxStyleSheetBase::SetHidden( bool hidden
)
247 pPool
->Broadcast( SfxStyleSheetHint( SfxStyleSheetHintId::MODIFIED
, *this ) );
253 const OUString
& SfxStyleSheetBase::GetFollow() const
258 bool SfxStyleSheetBase::SetFollow( const OUString
& rName
)
260 if( aFollow
!= rName
)
262 if( !pPool
->Find( rName
, nFamily
) )
264 SAL_WARN( "svl", "StyleSheet-Follow not found" );
269 pPool
->Broadcast( SfxStyleSheetHint( SfxStyleSheetHintId::MODIFIED
, *this ) );
275 * The default implementation creates a new set
277 SfxItemSet
& SfxStyleSheetBase::GetItemSet()
281 pSet
= new SfxItemSet( pPool
->GetPool() );
287 std::unique_ptr
<SfxItemSet
> SfxStyleSheetBase::GetItemSetForPreview()
289 return std::unique_ptr
<SfxItemSet
>(new SfxItemSet(GetItemSet()));
293 * Set help file and ID and return it
295 sal_uLong
SfxStyleSheetBase::GetHelpId( OUString
& rFile
)
301 void SfxStyleSheetBase::SetHelpId( const OUString
& rFile
, sal_uLong nId
)
308 * Next style possible?
311 bool SfxStyleSheetBase::HasFollowSupport() const
317 * Base template possible?
320 bool SfxStyleSheetBase::HasParentSupport() const
326 * Setting base template to NULL possible?
329 bool SfxStyleSheetBase::HasClearParentSupport() const
335 * By default all stylesheets are set to used
337 bool SfxStyleSheetBase::IsUsed() const
343 * Return set attributes
345 OUString
SfxStyleSheetBase::GetDescription()
347 return GetDescription( SFX_MAPUNIT_CM
);
351 * Return set attributes
353 OUString
SfxStyleSheetBase::GetDescription( SfxMapUnit eMetric
)
355 SfxItemIter
aIter( GetItemSet() );
357 const SfxPoolItem
* pItem
= aIter
.FirstItem();
359 IntlWrapper
aIntlWrapper( SvtSysLocale().GetLanguageTag() );
362 OUString aItemPresentation
;
364 if ( !IsInvalidItem( pItem
) &&
365 pPool
->GetPool().GetPresentation(
366 *pItem
, eMetric
, aItemPresentation
, &aIntlWrapper
) )
368 if ( !aDesc
.isEmpty() && !aItemPresentation
.isEmpty() )
370 if ( !aItemPresentation
.isEmpty() )
371 aDesc
+= aItemPresentation
;
373 pItem
= aIter
.NextItem();
378 SfxStyleFamily
SfxStyleSheetIterator::GetSearchFamily() const
380 return nSearchFamily
;
383 inline bool SfxStyleSheetIterator::IsTrivialSearch()
385 return (( nMask
& SFXSTYLEBIT_ALL_VISIBLE
) == SFXSTYLEBIT_ALL_VISIBLE
) &&
386 (GetSearchFamily() == SFX_STYLE_FAMILY_ALL
);
391 struct DoesStyleMatchStyleSheetPredicate SAL_FINAL
: public svl::StyleSheetPredicate
393 DoesStyleMatchStyleSheetPredicate(SfxStyleSheetIterator
*it
)
397 Check(const SfxStyleSheetBase
& styleSheet
) SAL_OVERRIDE
399 bool bMatchFamily
= ((mIterator
->GetSearchFamily() == SFX_STYLE_FAMILY_ALL
) ||
400 ( styleSheet
.GetFamily() == mIterator
->GetSearchFamily() ));
402 bool bUsed
= mIterator
->SearchUsed() && styleSheet
.IsUsed( );
404 bool bSearchHidden
= ( mIterator
->GetSearchMask() & SFXSTYLEBIT_HIDDEN
);
405 bool bMatchVisibility
= !( !bSearchHidden
&& styleSheet
.IsHidden() && !bUsed
);
406 bool bOnlyHidden
= mIterator
->GetSearchMask( ) == SFXSTYLEBIT_HIDDEN
&& styleSheet
.IsHidden( );
408 bool bMatches
= bMatchFamily
&& bMatchVisibility
409 && (( styleSheet
.GetMask() & ( mIterator
->GetSearchMask() & ~SFXSTYLEBIT_USED
)) ||
410 bUsed
|| bOnlyHidden
||
411 ( mIterator
->GetSearchMask() & SFXSTYLEBIT_ALL_VISIBLE
) == SFXSTYLEBIT_ALL_VISIBLE
);
415 SfxStyleSheetIterator
*mIterator
;
420 SfxStyleSheetIterator::SfxStyleSheetIterator(SfxStyleSheetBasePool
*pBase
,
421 SfxStyleFamily eFam
, sal_uInt16 n
)
428 if( (( n
& SFXSTYLEBIT_ALL_VISIBLE
) != SFXSTYLEBIT_ALL_VISIBLE
)
429 && ((n
& SFXSTYLEBIT_USED
) == SFXSTYLEBIT_USED
))
432 n
&= ~SFXSTYLEBIT_USED
;
437 SfxStyleSheetIterator::~SfxStyleSheetIterator()
441 sal_uInt16
SfxStyleSheetIterator::Count()
444 if( IsTrivialSearch())
446 n
= (sal_uInt16
) pBasePool
->pImp
->mxIndexedStyleSheets
->GetNumberOfStyleSheets();
448 else if(nMask
== SFXSTYLEBIT_ALL
)
450 n
= static_cast<sal_uInt16
>(pBasePool
->pImp
->mxIndexedStyleSheets
->GetStyleSheetPositionsByFamily(nSearchFamily
).size());
454 DoesStyleMatchStyleSheetPredicate
predicate(this);
455 n
= pBasePool
->pImp
->mxIndexedStyleSheets
->GetNumberOfStyleSheetsWithPredicate(predicate
);
460 SfxStyleSheetBase
* SfxStyleSheetIterator::operator[](sal_uInt16 nIdx
)
462 SfxStyleSheetBase
* retval
= NULL
;
463 if( IsTrivialSearch())
465 retval
= pBasePool
->pImp
->mxIndexedStyleSheets
->GetStyleSheetByPosition(nIdx
).get();
468 else if(nMask
== SFXSTYLEBIT_ALL
)
470 rtl::Reference
< SfxStyleSheetBase
> ref
=
471 pBasePool
->pImp
->mxIndexedStyleSheets
->GetStyleSheetByPosition(
472 pBasePool
->pImp
->mxIndexedStyleSheets
->GetStyleSheetPositionsByFamily(nSearchFamily
).at(nIdx
))
479 DoesStyleMatchStyleSheetPredicate
predicate(this);
480 rtl::Reference
< SfxStyleSheetBase
> ref
=
481 pBasePool
->pImp
->mxIndexedStyleSheets
->GetNthStyleSheetThatMatchesPredicate(nIdx
, predicate
);
482 if (ref
.get() != NULL
)
484 nAktPosition
= pBasePool
->pImp
->mxIndexedStyleSheets
->FindStyleSheetPosition(*ref
);
491 OSL_FAIL("Incorrect index");
497 SfxStyleSheetBase
* SfxStyleSheetIterator::First()
500 return operator[](0);
508 SfxStyleSheetBase
* SfxStyleSheetIterator::Next()
510 SfxStyleSheetBase
* retval
= NULL
;
512 if ( IsTrivialSearch() )
514 unsigned nStyleSheets
= pBasePool
->pImp
->mxIndexedStyleSheets
->GetNumberOfStyleSheets();
515 unsigned newPosition
= nAktPosition
+1;
516 if (nStyleSheets
> newPosition
)
518 nAktPosition
= newPosition
;
519 retval
= pBasePool
->pImp
->mxIndexedStyleSheets
->GetStyleSheetByPosition(nAktPosition
).get();
522 else if(nMask
== SFXSTYLEBIT_ALL
)
524 unsigned newPosition
= nAktPosition
+1;
525 const std::vector
<unsigned>& familyVector
=
526 pBasePool
->pImp
->mxIndexedStyleSheets
->GetStyleSheetPositionsByFamily(nSearchFamily
);
527 if (familyVector
.size() > newPosition
)
529 nAktPosition
= newPosition
;
530 unsigned stylePosition
= familyVector
.at(newPosition
);
531 retval
= pBasePool
->pImp
->mxIndexedStyleSheets
->GetStyleSheetByPosition(stylePosition
).get();
536 DoesStyleMatchStyleSheetPredicate
predicate(this);
537 rtl::Reference
< SfxStyleSheetBase
> ref
=
538 pBasePool
->pImp
->mxIndexedStyleSheets
->GetNthStyleSheetThatMatchesPredicate(
539 0, predicate
, nAktPosition
+1);
541 if (retval
!= NULL
) {
542 nAktPosition
= pBasePool
->pImp
->mxIndexedStyleSheets
->FindStyleSheetPosition(*ref
);
549 SfxStyleSheetBase
* SfxStyleSheetIterator::Find(const OUString
& rStr
)
551 DoesStyleMatchStyleSheetPredicate
predicate(this);
553 std::vector
<unsigned> positions
=
554 pBasePool
->pImp
->mxIndexedStyleSheets
->FindPositionsByNameAndPredicate(rStr
, predicate
,
555 svl::IndexedStyleSheets::RETURN_FIRST
);
556 if (positions
.empty()) {
560 unsigned pos
= positions
.front();
561 SfxStyleSheetBase
* pStyle
= pBasePool
->pImp
->mxIndexedStyleSheets
->GetStyleSheetByPosition(pos
).get();
567 sal_uInt16
SfxStyleSheetIterator::GetSearchMask() const
569 sal_uInt16 mask
= nMask
;
572 mask
|= SFXSTYLEBIT_USED
;
577 void SfxStyleSheetBasePool::Replace( SfxStyleSheetBase
& rSource
, SfxStyleSheetBase
& rTarget
)
579 rTarget
.SetFollow( rSource
.GetFollow() );
580 rTarget
.SetParent( rSource
.GetParent() );
581 SfxItemSet
& rSourceSet
= rSource
.GetItemSet();
582 SfxItemSet
& rTargetSet
= rTarget
.GetItemSet();
583 rTargetSet
.Intersect( rSourceSet
);
584 rTargetSet
.Put( rSourceSet
);
587 SfxStyleSheetIterator
& SfxStyleSheetBasePool::GetIterator_Impl()
589 if( !pImp
->pIter
|| (pImp
->pIter
->GetSearchMask() != nMask
) || (pImp
->pIter
->GetSearchFamily() != nSearchFamily
) )
591 pImp
->pIter
= CreateIterator( nSearchFamily
, nMask
);
597 SfxStyleSheetBasePool::SfxStyleSheetBasePool( SfxItemPool
& r
) :
598 pImp(new SfxStyleSheetBasePool_Impl
),
599 aAppName(r
.GetName()),
601 nSearchFamily(SFX_STYLE_FAMILY_PARA
),
602 nMask(SFXSTYLEBIT_ALL
)
605 aDbgStyleSheetReferences
.mnPools
++;
609 SfxStyleSheetBasePool::SfxStyleSheetBasePool( const SfxStyleSheetBasePool
& r
) :
611 comphelper::OWeakTypeObject(),
612 pImp(new SfxStyleSheetBasePool_Impl
),
613 aAppName(r
.aAppName
),
615 nSearchFamily(r
.nSearchFamily
),
619 aDbgStyleSheetReferences
.mnPools
++;
625 SfxStyleSheetBasePool::~SfxStyleSheetBasePool()
628 aDbgStyleSheetReferences
.mnPools
--;
631 Broadcast( SfxSimpleHint(SFX_HINT_DYING
) );
636 bool SfxStyleSheetBasePool::SetParent(SfxStyleFamily eFam
, const OUString
& rStyle
, const OUString
& rParent
)
638 SfxStyleSheetIterator
aIter(this,eFam
,SFXSTYLEBIT_ALL
);
639 SfxStyleSheetBase
*pStyle
= aIter
.Find(rStyle
);
640 OSL_ENSURE(pStyle
, "Template not found. Writer with solar <2541?");
642 return pStyle
->SetParent(rParent
);
648 void SfxStyleSheetBasePool::SetSearchMask(SfxStyleFamily eFam
, sal_uInt16 n
)
650 nSearchFamily
= eFam
; nMask
= n
;
654 SfxStyleSheetIteratorPtr
SfxStyleSheetBasePool::CreateIterator
660 return SfxStyleSheetIteratorPtr(new SfxStyleSheetIterator(this,eFam
,mask
));
663 SfxStyleSheetBase
* SfxStyleSheetBasePool::Create
665 const OUString
& rName
,
670 return new SfxStyleSheetBase( rName
, this, eFam
, mask
);
673 SfxStyleSheetBase
* SfxStyleSheetBasePool::Create( const SfxStyleSheetBase
& r
)
675 return new SfxStyleSheetBase( r
);
678 SfxStyleSheetBase
& SfxStyleSheetBasePool::Make( const OUString
& rName
, SfxStyleFamily eFam
, sal_uInt16 mask
)
680 OSL_ENSURE( eFam
!= SFX_STYLE_FAMILY_ALL
, "svl::SfxStyleSheetBasePool::Make(), FamilyAll is not a allowed Familie" );
682 SfxStyleSheetIterator
aIter(this, eFam
, mask
);
683 rtl::Reference
< SfxStyleSheetBase
> xStyle( aIter
.Find( rName
) );
684 OSL_ENSURE( !xStyle
.is(), "svl::SfxStyleSheetBasePool::Make(), StyleSheet already exists" );
688 xStyle
= Create( rName
, eFam
, mask
);
689 StoreStyleSheet(xStyle
);
690 Broadcast( SfxStyleSheetHint( SfxStyleSheetHintId::CREATED
, *xStyle
.get() ) );
692 return *xStyle
.get();
696 * Helper function: If a template with this name exists it is created
697 * anew. All templates that have this template as a parent are reconnected.
699 SfxStyleSheetBase
& SfxStyleSheetBasePool::Add( const SfxStyleSheetBase
& rSheet
)
701 SfxStyleSheetIterator
aIter(this, rSheet
.GetFamily(), nMask
);
702 SfxStyleSheetBase
* pOld
= aIter
.Find( rSheet
.GetName() );
706 rtl::Reference
< SfxStyleSheetBase
> xNew( Create( rSheet
) );
707 pImp
->mxIndexedStyleSheets
->AddStyleSheet(xNew
);
708 Broadcast( SfxStyleSheetHint( SfxStyleSheetHintId::CHANGED
, *xNew
.get() ) );
712 SfxStyleSheetBasePool
& SfxStyleSheetBasePool::operator=( const SfxStyleSheetBasePool
& r
)
723 struct AddStyleSheetCallback
: svl::StyleSheetCallback
725 AddStyleSheetCallback(SfxStyleSheetBasePool
*pool
)
728 void DoIt(const SfxStyleSheetBase
& ssheet
) SAL_OVERRIDE
733 SfxStyleSheetBasePool
*mPool
;
737 SfxStyleSheetBasePool
& SfxStyleSheetBasePool::operator+=( const SfxStyleSheetBasePool
& r
)
741 AddStyleSheetCallback
callback(this);
742 pImp
->mxIndexedStyleSheets
->ApplyToAllStyleSheets(callback
);
747 sal_uInt16
SfxStyleSheetBasePool::Count()
749 return GetIterator_Impl().Count();
752 SfxStyleSheetBase
*SfxStyleSheetBasePool::operator[](sal_uInt16 nIdx
)
754 return GetIterator_Impl()[nIdx
];
757 SfxStyleSheetBase
* SfxStyleSheetBasePool::Find(const OUString
& rName
,
761 SfxStyleSheetIterator
aIter(this,eFam
,mask
);
762 return aIter
.Find(rName
);
765 SfxStyleSheetBase
* SfxStyleSheetBasePool::First()
767 return GetIterator_Impl().First();
770 SfxStyleSheetBase
* SfxStyleSheetBasePool::Next()
772 return GetIterator_Impl().Next();
775 void SfxStyleSheetBasePool::Remove( SfxStyleSheetBase
* p
)
779 // Reference to keep p alive until after Broadcast call!
780 rtl::Reference
<SfxStyleSheetBase
> xP(p
);
781 bool bWasRemoved
= pImp
->mxIndexedStyleSheets
->RemoveStyleSheet(xP
);
784 // Adapt all styles which have this style as parant
785 ChangeParent( p
->GetName(), p
->GetParent() );
787 // #120015# Do not dispose, the removed StyleSheet may still be used in
788 // existing SdrUndoAttrObj incarnations. Rely on refcounting for disposal,
789 // this works well under normal conditions (checked breaking and counting
790 // on SfxStyleSheetBase constructors and destructors)
792 // com::sun::star::uno::Reference< com::sun::star::lang::XComponent > xComp( static_cast< ::cppu::OWeakObject* >((*aIter).get()), com::sun::star::uno::UNO_QUERY );
793 // if( xComp.is() ) try
797 // catch( com::sun::star::uno::Exception& )
800 Broadcast( SfxStyleSheetHint( SfxStyleSheetHintId::ERASED
, *p
) );
805 void SfxStyleSheetBasePool::Insert( SfxStyleSheetBase
* p
)
807 #if OSL_DEBUG_LEVEL > 0
808 OSL_ENSURE( p
, "svl::SfxStyleSheetBasePool::Insert(), no stylesheet?" );
810 SfxStyleSheetIterator
aIter(this, p
->GetFamily(), p
->GetMask());
811 SfxStyleSheetBase
* pOld
= aIter
.Find( p
->GetName() );
812 OSL_ENSURE( !pOld
, "svl::SfxStyleSheetBasePool::Insert(), StyleSheet already inserted" );
813 if( !p
->GetParent().isEmpty() )
815 pOld
= aIter
.Find( p
->GetParent() );
816 OSL_ENSURE( pOld
, "svl::SfxStyleSheetBasePool::Insert(), Parent not found!" );
819 StoreStyleSheet(rtl::Reference
< SfxStyleSheetBase
>( p
) );
820 Broadcast( SfxStyleSheetHint( SfxStyleSheetHintId::CREATED
, *p
) );
826 struct StyleSheetDisposerFunctor SAL_FINAL
: public svl::StyleSheetDisposer
828 StyleSheetDisposerFunctor(SfxStyleSheetBasePool
* pool
)
832 Dispose(rtl::Reference
<SfxStyleSheetBase
> styleSheet
) SAL_OVERRIDE
834 cppu::OWeakObject
* weakObject
= static_cast< ::cppu::OWeakObject
* >(styleSheet
.get());
835 com::sun::star::uno::Reference
< com::sun::star::lang::XComponent
>
836 xComp( weakObject
, com::sun::star::uno::UNO_QUERY
);
841 catch( com::sun::star::uno::Exception
& )
844 mPool
->Broadcast( SfxStyleSheetHint( SfxStyleSheetHintId::ERASED
, *styleSheet
.get() ) );
847 SfxStyleSheetBasePool
* mPool
;
852 void SfxStyleSheetBasePool::Clear()
854 StyleSheetDisposerFunctor
cleanup(this);
855 pImp
->mxIndexedStyleSheets
->Clear(cleanup
);
858 void SfxStyleSheetBasePool::ChangeParent(const OUString
& rOld
,
859 const OUString
& rNew
,
862 const sal_uInt16 nTmpMask
= GetSearchMask();
863 SetSearchMask(GetSearchFamily(), SFXSTYLEBIT_ALL
);
864 for( SfxStyleSheetBase
* p
= First(); p
; p
= Next() )
866 if( p
->GetParent() == rOld
)
869 p
->SetParent( rNew
);
874 SetSearchMask(GetSearchFamily(), nTmpMask
);
877 void SfxStyleSheetBase::Load( SvStream
&, sal_uInt16
)
881 void SfxStyleSheetBase::Store( SvStream
& )
885 SfxStyleSheet::SfxStyleSheet(const OUString
&rName
,
886 const SfxStyleSheetBasePool
& r_Pool
,
889 : SfxStyleSheetBase(rName
, const_cast< SfxStyleSheetBasePool
* >( &r_Pool
), eFam
, mask
)
893 SfxStyleSheet::SfxStyleSheet(const SfxStyleSheet
& rStyle
)
894 : SfxStyleSheetBase(rStyle
)
895 , SfxListener( rStyle
)
896 , SfxBroadcaster( rStyle
)
897 , svl::StyleSheetUser()
901 SfxStyleSheet::~SfxStyleSheet()
903 Broadcast( SfxStyleSheetHint( SfxStyleSheetHintId::INDESTRUCTION
, *this ) );
907 bool SfxStyleSheet::SetParent( const OUString
& rName
)
911 const OUString
aOldParent(aParent
);
912 if(SfxStyleSheetBase::SetParent(rName
))
914 // Remove from notification chain of the old parent if applicable
915 if(!aOldParent
.isEmpty())
917 SfxStyleSheet
*pParent
= static_cast<SfxStyleSheet
*>(pPool
->Find(aOldParent
, nFamily
, SFXSTYLEBIT_ALL
));
919 EndListening(*pParent
);
921 // Add to the notification chain of the new parent
922 if(!aParent
.isEmpty())
924 SfxStyleSheet
*pParent
= static_cast<SfxStyleSheet
*>(pPool
->Find(aParent
, nFamily
, SFXSTYLEBIT_ALL
));
926 StartListening(*pParent
);
934 * Notify all listeners
936 void SfxStyleSheet::Notify(SfxBroadcaster
& rBC
, const SfxHint
& rHint
)
941 bool SfxStyleSheet::isUsedByModel() const
947 SfxStyleSheetPool::SfxStyleSheetPool( SfxItemPool
const& rSet
)
948 : SfxStyleSheetBasePool( const_cast< SfxItemPool
& >( rSet
) )
952 SfxStyleSheetBase
* SfxStyleSheetPool::Create( const OUString
& rName
,
953 SfxStyleFamily eFam
, sal_uInt16 mask
)
955 return new SfxStyleSheet( rName
, *this, eFam
, mask
);
958 SfxUnoStyleSheet::SfxUnoStyleSheet( const OUString
& _rName
, const SfxStyleSheetBasePool
& _rPool
, SfxStyleFamily _eFamily
, sal_uInt16 _nMaske
)
959 : ::cppu::ImplInheritanceHelper2
< SfxStyleSheet
, ::com::sun::star::style::XStyle
, ::com::sun::star::lang::XUnoTunnel
>( _rName
, _rPool
, _eFamily
, _nMaske
)
963 SfxUnoStyleSheet
* SfxUnoStyleSheet::getUnoStyleSheet( const ::com::sun::star::uno::Reference
< ::com::sun::star::style::XStyle
>& xStyle
)
965 SfxUnoStyleSheet
* pRet
= dynamic_cast< SfxUnoStyleSheet
* >( xStyle
.get() );
968 ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XUnoTunnel
> xUT( xStyle
, ::com::sun::star::uno::UNO_QUERY
);
970 pRet
= reinterpret_cast<SfxUnoStyleSheet
*>(sal::static_int_cast
<sal_uIntPtr
>(xUT
->getSomething( SfxUnoStyleSheet::getIdentifier())));
978 ::sal_Int64 SAL_CALL
SfxUnoStyleSheet::getSomething( const ::com::sun::star::uno::Sequence
< ::sal_Int8
>& rId
) throw (::com::sun::star::uno::RuntimeException
, std::exception
)
980 if( rId
.getLength() == 16 && 0 == memcmp( getIdentifier().getConstArray(), rId
.getConstArray(), 16 ) )
982 return sal::static_int_cast
<sal_Int64
>(reinterpret_cast<sal_uIntPtr
>(this));
991 SfxStyleSheetBasePool::StoreStyleSheet(rtl::Reference
< SfxStyleSheetBase
> xStyle
)
993 pImp
->mxIndexedStyleSheets
->AddStyleSheet(xStyle
);
998 class theSfxUnoStyleSheetIdentifier
: public rtl::Static
< UnoTunnelIdInit
, theSfxUnoStyleSheetIdentifier
> {};
1001 const ::com::sun::star::uno::Sequence
< ::sal_Int8
>& SfxUnoStyleSheet::getIdentifier()
1003 return theSfxUnoStyleSheetIdentifier::get().getSeq();
1007 SfxStyleSheetBasePool::Reindex()
1009 pImp
->mxIndexedStyleSheets
->Reindex();
1012 const svl::IndexedStyleSheets
&
1013 SfxStyleSheetBasePool::GetIndexedStyleSheets() const
1015 return *pImp
->mxIndexedStyleSheets
;
1018 rtl::Reference
<SfxStyleSheetBase
>
1019 SfxStyleSheetBasePool::GetStyleSheetByPositionInIndex(unsigned pos
)
1021 return pImp
->mxIndexedStyleSheets
->GetStyleSheetByPosition(pos
);
1024 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */