GPU-Calc: remove Alloc_Host_Ptr for clmem of NAN vector
[LibreOffice.git] / svl / source / items / style.cxx
blob55bca3f0a65d5ebc2ae18b454277affcd6c541cc
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 <com/sun/star/lang/XComponent.hpp>
22 #include <tools/tenccvt.hxx>
23 #include <comphelper/processfactory.hxx>
24 #include <unotools/intlwrapper.hxx>
25 #include <svl/smplhint.hxx>
26 #include <svl/poolitem.hxx>
27 #include <svl/itemset.hxx>
28 #include <svl/itempool.hxx>
29 #include <poolio.hxx>
30 #include <svl/itemiter.hxx>
31 #include <svl/style.hxx>
32 #include <unotools/syslocale.hxx>
33 #include <algorithm>
34 #include <comphelper/servicehelper.hxx>
35 #include <string.h>
37 #ifdef DBG_UTIL
38 class DbgStyleSheetReferences
40 public:
41 DbgStyleSheetReferences() : mnStyles(0), mnPools(0) {}
42 ~DbgStyleSheetReferences()
44 OSL_TRACE("DbgStyleSheetReferences\nSfxStyleSheetBase left %ld\nSfxStyleSheetBasePool left %ld", mnStyles, mnPools );
47 sal_uInt32 mnStyles;
48 sal_uInt32 mnPools;
50 aDbgStyleSheetReferences;
52 #endif
54 TYPEINIT0(SfxStyleSheetBase)
56 TYPEINIT3(SfxStyleSheet, SfxStyleSheetBase, SfxListener, SfxBroadcaster)
58 TYPEINIT1(SfxStyleSheetHint, SfxHint);
59 TYPEINIT1(SfxStyleSheetHintExtended, SfxStyleSheetHint);
60 TYPEINIT1(SfxStyleSheetPoolHint, SfxHint);
62 SfxStyleSheetHintExtended::SfxStyleSheetHintExtended
64 sal_uInt16 nAction, // SFX_STYLESHEET_... (s.o.)
65 const OUString& rOldName,
66 SfxStyleSheetBase& rStyleSheet // geh"ort weiterhin dem Aufrufer
68 : SfxStyleSheetHint( nAction, rStyleSheet ),
69 aName( rOldName )
73 SfxStyleSheetHint::SfxStyleSheetHint
75 sal_uInt16 nAction, // SFX_STYLESHEET_... (s.o.)
76 SfxStyleSheetBase& rStyleSheet // geh"ort weiterhin dem Aufrufer
78 : pStyleSh( &rStyleSheet ),
79 nHint( nAction )
83 class SfxStyleSheetBasePool_Impl
85 public:
86 SfxStyleSheetIteratorPtr pIter;
90 SfxStyleSheetBase::SfxStyleSheetBase( const OUString& rName, SfxStyleSheetBasePool* p, SfxStyleFamily eFam, sal_uInt16 mask )
91 : pPool( p )
92 , nFamily( eFam )
93 , aName( rName )
94 , aParent()
95 , aFollow( rName )
96 , pSet( NULL )
97 , nMask(mask)
98 , nHelpId( 0 )
99 , bMySet( sal_False )
100 , bHidden( sal_False )
102 #ifdef DBG_UTIL
103 aDbgStyleSheetReferences.mnStyles++;
104 #endif
107 SfxStyleSheetBase::SfxStyleSheetBase( const SfxStyleSheetBase& r )
108 : comphelper::OWeakTypeObject()
109 , pPool( r.pPool )
110 , nFamily( r.nFamily )
111 , aName( r.aName )
112 , aParent( r.aParent )
113 , aFollow( r.aFollow )
114 , aHelpFile( r.aHelpFile )
115 , nMask( r.nMask )
116 , nHelpId( r.nHelpId )
117 , bMySet( r.bMySet )
118 , bHidden( r.bHidden )
120 #ifdef DBG_UTIL
121 aDbgStyleSheetReferences.mnStyles++;
122 #endif
123 if( r.pSet )
124 pSet = bMySet ? new SfxItemSet( *r.pSet ) : r.pSet;
125 else
126 pSet = NULL;
129 SfxStyleSheetBase::~SfxStyleSheetBase()
131 #ifdef DBG_UTIL
132 --aDbgStyleSheetReferences.mnStyles;
133 #endif
135 if( bMySet )
137 delete pSet;
138 pSet = 0;
142 sal_uInt16 SfxStyleSheetBase::GetVersion() const
144 return 0x0000;
147 // Change name
149 const OUString& SfxStyleSheetBase::GetName() const
151 return aName;
154 bool SfxStyleSheetBase::SetName( const OUString& rName )
156 if(rName.isEmpty())
157 return false;
159 if( aName != rName )
161 OUString aOldName = aName;
162 SfxStyleSheetBase *pOther = pPool->Find( rName, nFamily ) ;
163 if ( pOther && pOther != this )
164 return sal_False;
166 SfxStyleFamily eTmpFam = pPool->GetSearchFamily();
167 sal_uInt16 nTmpMask = pPool->GetSearchMask();
169 pPool->SetSearchMask(nFamily);
171 if ( !aName.isEmpty() )
172 pPool->ChangeParent( aName, rName, sal_False );
174 if ( aFollow == aName )
175 aFollow = rName;
176 aName = rName;
177 pPool->SetSearchMask(eTmpFam, nTmpMask);
178 pPool->Broadcast( SfxStyleSheetHintExtended(
179 SFX_STYLESHEET_MODIFIED, aOldName, *this ) );
181 return true;
184 OUString SfxStyleSheetBase::GetDisplayName() const
186 if( maDisplayName.isEmpty() )
188 return aName;
190 else
192 return maDisplayName;
196 void SfxStyleSheetBase::SetDisplayName( const OUString& rDisplayName )
198 maDisplayName = rDisplayName;
201 // Change Parent
203 const OUString& SfxStyleSheetBase::GetParent() const
205 return aParent;
208 bool SfxStyleSheetBase::SetParent( const OUString& rName )
210 if ( rName == aName )
211 return false;
213 if( aParent != rName )
215 SfxStyleSheetBase* pIter = pPool->Find(rName, nFamily);
216 if( !rName.isEmpty() && !pIter )
218 OSL_FAIL( "StyleSheet-Parent not found" );
219 return false;
221 // prevent recursive linkages
222 if( !aName.isEmpty() )
224 while(pIter)
226 if(pIter->GetName() == aName)
227 return false;
228 pIter = pPool->Find(pIter->GetParent(), nFamily);
231 aParent = rName;
233 pPool->Broadcast( SfxStyleSheetHint( SFX_STYLESHEET_MODIFIED, *this ) );
234 return true;
237 void SfxStyleSheetBase::SetHidden( sal_Bool hidden )
239 bHidden = hidden;
240 pPool->Broadcast( SfxStyleSheetHint( SFX_STYLESHEET_MODIFIED, *this ) );
243 // Change follow
245 const OUString& SfxStyleSheetBase::GetFollow() const
247 return aFollow;
250 bool SfxStyleSheetBase::SetFollow( const OUString& rName )
252 if( aFollow != rName )
254 if( !pPool->Find( rName, nFamily ) )
256 SAL_WARN( "svl", "StyleSheet-Follow not found" );
257 return false;
259 aFollow = rName;
261 pPool->Broadcast( SfxStyleSheetHint( SFX_STYLESHEET_MODIFIED, *this ) );
262 return true;
265 // Set Itemset. The dflt-implementation creates a new set
267 SfxItemSet& SfxStyleSheetBase::GetItemSet()
269 if( !pSet )
271 pSet = new SfxItemSet( pPool->GetPool() );
272 bMySet = sal_True;
274 return *pSet;
277 // Hilfe-Datei und -ID setzen und abfragen
279 sal_uLong SfxStyleSheetBase::GetHelpId( OUString& rFile )
281 rFile = aHelpFile;
282 return nHelpId;
285 void SfxStyleSheetBase::SetHelpId( const OUString& rFile, sal_uLong nId )
287 aHelpFile = rFile;
288 nHelpId = nId;
291 // Next style possible? Default: Yes
293 bool SfxStyleSheetBase::HasFollowSupport() const
295 return true;
298 // Basisvorlage m"oglich? Default: Ja
300 bool SfxStyleSheetBase::HasParentSupport() const
302 return true;
305 // Basisvorlage uf NULL setzen m"oglich? Default: Nein
307 bool SfxStyleSheetBase::HasClearParentSupport() const
309 return false;
312 // Defaultmaessig sind alle StyleSheets Used
314 bool SfxStyleSheetBase::IsUsed() const
316 return true;
319 // eingestellte Attribute ausgeben
321 OUString SfxStyleSheetBase::GetDescription()
323 return GetDescription( SFX_MAPUNIT_CM );
326 // eingestellte Attribute ausgeben
328 OUString SfxStyleSheetBase::GetDescription( SfxMapUnit eMetric )
330 SfxItemIter aIter( GetItemSet() );
331 OUString aDesc;
332 const SfxPoolItem* pItem = aIter.FirstItem();
334 IntlWrapper aIntlWrapper( SvtSysLocale().GetLanguageTag() );
335 while ( pItem )
337 OUString aItemPresentation;
339 if ( !IsInvalidItem( pItem ) &&
340 pPool->GetPool().GetPresentation(
341 *pItem, SFX_ITEM_PRESENTATION_COMPLETE,
342 eMetric, aItemPresentation, &aIntlWrapper ) )
344 if ( !aDesc.isEmpty() && !aItemPresentation.isEmpty() )
345 aDesc += " + ";
346 if ( !aItemPresentation.isEmpty() )
347 aDesc += aItemPresentation;
349 pItem = aIter.NextItem();
351 return aDesc;
354 SfxStyleFamily SfxStyleSheetIterator::GetSearchFamily() const
356 return nSearchFamily;
359 inline bool SfxStyleSheetIterator::IsTrivialSearch()
361 return (( nMask & SFXSTYLEBIT_ALL_VISIBLE ) == SFXSTYLEBIT_ALL_VISIBLE) &&
362 (GetSearchFamily() == SFX_STYLE_FAMILY_ALL);
365 bool SfxStyleSheetIterator::DoesStyleMatch(SfxStyleSheetBase *pStyle)
367 bool bMatchFamily = ((GetSearchFamily() == SFX_STYLE_FAMILY_ALL) ||
368 ( pStyle->GetFamily() == GetSearchFamily() ));
370 bool bUsed = bSearchUsed ? pStyle->IsUsed( ) : false;
372 bool bSearchHidden = ( GetSearchMask() & SFXSTYLEBIT_HIDDEN );
373 bool bMatchVisibility = !( !bSearchHidden && pStyle->IsHidden() && !bUsed );
374 bool bOnlyHidden = GetSearchMask( ) == SFXSTYLEBIT_HIDDEN && pStyle->IsHidden( );
376 bool bMatches = bMatchFamily && bMatchVisibility
377 && (( pStyle->GetMask() & ( GetSearchMask() & ~SFXSTYLEBIT_USED )) ||
378 bUsed || bOnlyHidden ||
379 ( GetSearchMask() & SFXSTYLEBIT_ALL_VISIBLE ) == SFXSTYLEBIT_ALL_VISIBLE );
380 return bMatches;
383 SfxStyleSheetIterator::SfxStyleSheetIterator(SfxStyleSheetBasePool *pBase,
384 SfxStyleFamily eFam, sal_uInt16 n)
386 pBasePool=pBase;
387 nSearchFamily=eFam;
388 bSearchUsed=sal_False;
389 if( (( n & SFXSTYLEBIT_ALL_VISIBLE ) != SFXSTYLEBIT_ALL_VISIBLE )
390 && ((n & SFXSTYLEBIT_USED) == SFXSTYLEBIT_USED))
392 bSearchUsed = sal_True;
393 n &= ~SFXSTYLEBIT_USED;
395 nMask=n;
398 SfxStyleSheetIterator::~SfxStyleSheetIterator()
402 sal_uInt16 SfxStyleSheetIterator::Count()
404 sal_uInt16 n = 0;
405 if( IsTrivialSearch())
406 n = (sal_uInt16) pBasePool->aStyles.size();
407 else
408 for(sal_uInt16 i=0; i<pBasePool->aStyles.size(); i++)
410 SfxStyleSheetBase* pStyle = pBasePool->aStyles[i].get();
411 if(DoesStyleMatch(pStyle))
412 n++;
414 return n;
417 SfxStyleSheetBase* SfxStyleSheetIterator::operator[](sal_uInt16 nIdx)
419 if( IsTrivialSearch())
420 return pBasePool->aStyles[nIdx].get();
422 sal_uInt16 z = 0;
423 for(sal_uInt16 n=0; n<pBasePool->aStyles.size(); n++)
425 SfxStyleSheetBase* pStyle = pBasePool->aStyles[n].get();
426 if( DoesStyleMatch(pStyle))
428 if(z == nIdx)
430 nAktPosition=n;
431 return pAktStyle=pStyle;
433 ++z;
436 OSL_FAIL("Incorrect index");
437 return 0;
440 SfxStyleSheetBase* SfxStyleSheetIterator::First()
442 sal_Int32 nIdx = -1;
444 if ( IsTrivialSearch() && pBasePool->aStyles.size() )
445 nIdx = 0;
446 else
447 for( sal_uInt16 n = 0; n < pBasePool->aStyles.size(); n++ )
449 SfxStyleSheetBase* pStyle = pBasePool->aStyles[n].get();
451 if ( DoesStyleMatch( pStyle ) )
453 nIdx = n;
454 break;
458 if ( nIdx != -1 )
460 nAktPosition = (sal_uInt16)nIdx;
461 return pAktStyle = pBasePool->aStyles[nIdx].get();
463 return 0;
467 SfxStyleSheetBase* SfxStyleSheetIterator::Next()
469 sal_Int32 nIdx = -1;
471 if ( IsTrivialSearch() &&
472 (sal_uInt16)pBasePool->aStyles.size() > nAktPosition + 1 )
473 nIdx = nAktPosition + 1;
474 else
475 for( sal_uInt16 n = nAktPosition + 1; n < pBasePool->aStyles.size(); n++ )
477 SfxStyleSheetBase* pStyle = pBasePool->aStyles[n].get();
479 if ( DoesStyleMatch( pStyle ) )
481 nIdx = n;
482 break;
486 if ( nIdx != -1 )
488 nAktPosition = (sal_uInt16)nIdx;
489 return pAktStyle = pBasePool->aStyles[nIdx].get();
491 return 0;
495 SfxStyleSheetBase* SfxStyleSheetIterator::Find(const OUString& rStr)
497 for ( sal_uInt16 n = 0; n < pBasePool->aStyles.size(); ++n )
499 SfxStyleSheetBase* pStyle = pBasePool->aStyles[n].get();
501 // #98454# performance: in case of bSearchUsed==sal_True it may be
502 // significant to first compare the name and only if it matches to call
503 // the style sheet IsUsed() method in DoesStyleMatch().
504 if ( pStyle->GetName() == rStr && DoesStyleMatch( pStyle ) )
506 nAktPosition = n;
507 return pAktStyle = pStyle;
510 return 0;
513 sal_uInt16 SfxStyleSheetIterator::GetSearchMask() const
515 sal_uInt16 mask = nMask;
517 if ( bSearchUsed )
518 mask |= SFXSTYLEBIT_USED;
519 return mask;
523 void SfxStyleSheetBasePool::Replace( SfxStyleSheetBase& rSource, SfxStyleSheetBase& rTarget )
525 rTarget.SetFollow( rSource.GetFollow() );
526 rTarget.SetParent( rSource.GetParent() );
527 SfxItemSet& rSourceSet = rSource.GetItemSet();
528 SfxItemSet& rTargetSet = rTarget.GetItemSet();
529 rTargetSet.Intersect( rSourceSet );
530 rTargetSet.Put( rSourceSet );
533 SfxStyleSheetIterator& SfxStyleSheetBasePool::GetIterator_Impl()
535 if( !pImp->pIter || (pImp->pIter->GetSearchMask() != nMask) || (pImp->pIter->GetSearchFamily() != nSearchFamily) )
537 pImp->pIter = CreateIterator( nSearchFamily, nMask );
540 return *pImp->pIter;
543 SfxStyleSheetBasePool::SfxStyleSheetBasePool( SfxItemPool& r )
544 : aAppName(r.GetName())
545 , rPool(r)
546 , nSearchFamily(SFX_STYLE_FAMILY_PARA)
547 , nMask(SFXSTYLEBIT_ALL)
549 #ifdef DBG_UTIL
550 aDbgStyleSheetReferences.mnPools++;
551 #endif
553 pImp = new SfxStyleSheetBasePool_Impl;
556 SfxStyleSheetBasePool::SfxStyleSheetBasePool( const SfxStyleSheetBasePool& r )
557 : SfxBroadcaster( r )
558 , comphelper::OWeakTypeObject()
559 , aAppName(r.aAppName)
560 , rPool(r.rPool)
561 , nSearchFamily(r.nSearchFamily)
562 , nMask( r.nMask )
564 #ifdef DBG_UTIL
565 aDbgStyleSheetReferences.mnPools++;
566 #endif
568 pImp = new SfxStyleSheetBasePool_Impl;
569 *this += r;
572 SfxStyleSheetBasePool::~SfxStyleSheetBasePool()
574 #ifdef DBG_UTIL
575 aDbgStyleSheetReferences.mnPools--;
576 #endif
578 Broadcast( SfxSimpleHint(SFX_HINT_DYING) );
579 Clear();
580 delete pImp;
583 bool SfxStyleSheetBasePool::SetParent(SfxStyleFamily eFam, const OUString& rStyle, const OUString& rParent)
585 SfxStyleSheetIterator aIter(this,eFam,SFXSTYLEBIT_ALL);
586 SfxStyleSheetBase *pStyle = aIter.Find(rStyle);
587 OSL_ENSURE(pStyle, "Template not found. Writer with solar <2541?");
588 if(pStyle)
589 return pStyle->SetParent(rParent);
590 else
591 return false;
595 void SfxStyleSheetBasePool::SetSearchMask(SfxStyleFamily eFam, sal_uInt16 n)
597 nSearchFamily = eFam; nMask = n;
600 sal_uInt16 SfxStyleSheetBasePool::GetSearchMask() const
602 return nMask;
605 SfxStyleSheetIteratorPtr SfxStyleSheetBasePool::CreateIterator
607 SfxStyleFamily eFam,
608 sal_uInt16 mask
611 return SfxStyleSheetIteratorPtr(new SfxStyleSheetIterator(this,eFam,mask));
614 SfxStyleSheetBase* SfxStyleSheetBasePool::Create
616 const OUString& rName,
617 SfxStyleFamily eFam,
618 sal_uInt16 mask
621 return new SfxStyleSheetBase( rName, this, eFam, mask );
624 SfxStyleSheetBase* SfxStyleSheetBasePool::Create( const SfxStyleSheetBase& r )
626 return new SfxStyleSheetBase( r );
629 SfxStyleSheetBase& SfxStyleSheetBasePool::Make( const OUString& rName, SfxStyleFamily eFam, sal_uInt16 mask)
631 OSL_ENSURE( eFam != SFX_STYLE_FAMILY_ALL, "svl::SfxStyleSheetBasePool::Make(), FamilyAll is not a allowed Familie" );
633 SfxStyleSheetIterator aIter(this, eFam, mask);
634 rtl::Reference< SfxStyleSheetBase > xStyle( aIter.Find( rName ) );
635 OSL_ENSURE( !xStyle.is(), "svl::SfxStyleSheetBasePool::Make(), StyleSheet already exists" );
637 if( !xStyle.is() )
639 xStyle = Create( rName, eFam, mask );
640 aStyles.push_back(xStyle);
641 Broadcast( SfxStyleSheetHint( SFX_STYLESHEET_CREATED, *xStyle.get() ) );
643 return *xStyle.get();
646 // Hilfsroutine: Falls eine Vorlage dieses Namens existiert, wird
647 // sie neu erzeugt. Alle Vorlagen, die diese Vorlage zum Parent haben,
648 // werden umgehaengt.
650 SfxStyleSheetBase& SfxStyleSheetBasePool::Add( SfxStyleSheetBase& rSheet )
652 SfxStyleSheetIterator aIter(this, rSheet.GetFamily(), nMask);
653 SfxStyleSheetBase* pOld = aIter.Find( rSheet.GetName() );
654 Remove( pOld );
655 rtl::Reference< SfxStyleSheetBase > xNew( Create( rSheet ) );
656 aStyles.push_back( xNew );
657 Broadcast( SfxStyleSheetHint( SFX_STYLESHEET_CHANGED, *xNew.get() ) );
658 return *xNew.get();
661 SfxStyleSheetBasePool& SfxStyleSheetBasePool::operator=( const SfxStyleSheetBasePool& r )
663 if( &r != this )
665 Clear();
666 *this += r;
668 return *this;
671 SfxStyleSheetBasePool& SfxStyleSheetBasePool::operator+=( const SfxStyleSheetBasePool& r )
673 if( &r != this )
675 SfxStyles::const_iterator aIter( r.aStyles.begin() );
676 while( aIter != r.aStyles.end() )
678 Add(*(*aIter++).get());
681 return *this;
684 sal_uInt16 SfxStyleSheetBasePool::Count()
686 return GetIterator_Impl().Count();
689 SfxStyleSheetBase *SfxStyleSheetBasePool::operator[](sal_uInt16 nIdx)
691 return GetIterator_Impl()[nIdx];
694 SfxStyleSheetBase* SfxStyleSheetBasePool::Find(const OUString& rName,
695 SfxStyleFamily eFam,
696 sal_uInt16 mask)
698 SfxStyleSheetIterator aIter(this,eFam,mask);
699 return aIter.Find(rName);
702 const SfxStyles& SfxStyleSheetBasePool::GetStyles()
704 return aStyles;
707 SfxStyleSheetBase* SfxStyleSheetBasePool::First()
709 return GetIterator_Impl().First();
712 SfxStyleSheetBase* SfxStyleSheetBasePool::Next()
714 return GetIterator_Impl().Next();
717 void SfxStyleSheetBasePool::Remove( SfxStyleSheetBase* p )
719 if( p )
721 // Reference to keep p alive until after Broadcast call!
722 rtl::Reference<SfxStyleSheetBase> xP(p);
723 SfxStyles::iterator const aIter(
724 std::find(aStyles.begin(), aStyles.end(), xP));
725 if( aIter != aStyles.end() )
727 // Alle Styles umsetzen, deren Parent dieser hier ist
728 ChangeParent( p->GetName(), p->GetParent() );
730 // #120015# Do not dispose, the removed StyleSheet may still be used in
731 // existing SdrUndoAttrObj incarnations. Rely on refcounting for disposal,
732 // this works well under normal conditions (checked breaking and counting
733 // on SfxStyleSheetBase constructors and destructors)
735 // com::sun::star::uno::Reference< com::sun::star::lang::XComponent > xComp( static_cast< ::cppu::OWeakObject* >((*aIter).get()), com::sun::star::uno::UNO_QUERY );
736 // if( xComp.is() ) try
737 // {
738 // xComp->dispose();
739 // }
740 // catch( com::sun::star::uno::Exception& )
741 // {
742 // }
744 aStyles.erase(aIter);
745 Broadcast( SfxStyleSheetHint( SFX_STYLESHEET_ERASED, *p ) );
750 void SfxStyleSheetBasePool::Insert( SfxStyleSheetBase* p )
752 #if OSL_DEBUG_LEVEL > 0
753 OSL_ENSURE( p, "svl::SfxStyleSheetBasePool::Insert(), no stylesheet?" );
755 SfxStyleSheetIterator aIter(this, p->GetFamily(), p->GetMask());
756 SfxStyleSheetBase* pOld = aIter.Find( p->GetName() );
757 OSL_ENSURE( !pOld, "svl::SfxStyleSheetBasePool::Insert(), StyleSheet already inserted" );
758 if( !p->GetParent().isEmpty() )
760 pOld = aIter.Find( p->GetParent() );
761 OSL_ENSURE( pOld, "svl::SfxStyleSheetBasePool::Insert(), Parent not found!" );
763 #endif
764 aStyles.push_back( rtl::Reference< SfxStyleSheetBase >( p ) );
765 Broadcast( SfxStyleSheetHint( SFX_STYLESHEET_CREATED, *p ) );
768 void SfxStyleSheetBasePool::Clear()
770 SfxStyles aClearStyles;
771 aClearStyles.swap( aStyles );
773 SfxStyles::iterator aIter( aClearStyles.begin() );
774 while( aIter != aClearStyles.end() )
776 com::sun::star::uno::Reference< com::sun::star::lang::XComponent > xComp( static_cast< ::cppu::OWeakObject* >((*aIter).get()), com::sun::star::uno::UNO_QUERY );
777 if( xComp.is() ) try
779 xComp->dispose();
781 catch( com::sun::star::uno::Exception& )
785 Broadcast( SfxStyleSheetHint( SFX_STYLESHEET_ERASED, *(*aIter++).get() ) );
789 void SfxStyleSheetBasePool::ChangeParent(const OUString& rOld,
790 const OUString& rNew,
791 bool bVirtual)
793 const sal_uInt16 nTmpMask = GetSearchMask();
794 SetSearchMask(GetSearchFamily(), SFXSTYLEBIT_ALL);
795 for( SfxStyleSheetBase* p = First(); p; p = Next() )
797 if( p->GetParent() == rOld )
799 if(bVirtual)
800 p->SetParent( rNew );
801 else
802 p->aParent = rNew;
805 SetSearchMask(GetSearchFamily(), nTmpMask);
808 void SfxStyleSheetBase::Load( SvStream&, sal_uInt16 )
812 void SfxStyleSheetBase::Store( SvStream& )
816 SfxItemPool& SfxStyleSheetBasePool::GetPool()
818 return rPool;
821 const SfxItemPool& SfxStyleSheetBasePool::GetPool() const
823 return rPool;
827 SfxStyleSheet::SfxStyleSheet(const OUString &rName,
828 const SfxStyleSheetBasePool& r_Pool,
829 SfxStyleFamily eFam,
830 sal_uInt16 mask )
831 : SfxStyleSheetBase(rName, const_cast< SfxStyleSheetBasePool* >( &r_Pool ), eFam, mask)
835 SfxStyleSheet::SfxStyleSheet(const SfxStyleSheet& rStyle)
836 : SfxStyleSheetBase(rStyle)
837 , SfxListener( rStyle )
838 , SfxBroadcaster( rStyle )
839 , svl::StyleSheetUser()
843 SfxStyleSheet::~SfxStyleSheet()
845 Broadcast( SfxStyleSheetHint( SFX_STYLESHEET_INDESTRUCTION, *this ) );
849 bool SfxStyleSheet::SetParent( const OUString& rName )
851 if(aParent == rName)
852 return true;
853 const OUString aOldParent(aParent);
854 if(SfxStyleSheetBase::SetParent(rName))
856 // aus der Benachrichtigungskette des alten
857 // Parents gfs. austragen
858 if(!aOldParent.isEmpty())
860 SfxStyleSheet *pParent = (SfxStyleSheet *)pPool->Find(aOldParent, nFamily, SFXSTYLEBIT_ALL);
861 if(pParent)
862 EndListening(*pParent);
864 // in die Benachrichtigungskette des neuen
865 // Parents eintragen
866 if(!aParent.isEmpty())
868 SfxStyleSheet *pParent = (SfxStyleSheet *)pPool->Find(aParent, nFamily, SFXSTYLEBIT_ALL);
869 if(pParent)
870 StartListening(*pParent);
872 return true;
874 return false;
877 // Notify all listeners
878 void SfxStyleSheet::Notify(SfxBroadcaster& rBC, const SfxHint& rHint )
880 Forward(rBC, rHint);
883 bool SfxStyleSheet::isUsedByModel() const
885 return IsUsed();
889 SfxStyleSheetPool::SfxStyleSheetPool( SfxItemPool const& rSet)
890 : SfxStyleSheetBasePool( const_cast< SfxItemPool& >( rSet ) )
894 SfxStyleSheetBase* SfxStyleSheetPool::Create( const OUString& rName,
895 SfxStyleFamily eFam, sal_uInt16 mask )
897 return new SfxStyleSheet( rName, *this, eFam, mask );
900 SfxStyleSheetBase* SfxStyleSheetPool::Create( const SfxStyleSheet& r )
902 return new SfxStyleSheet( r );
905 // class SfxUnoStyleSheet
906 SfxUnoStyleSheet::SfxUnoStyleSheet( const OUString& _rName, const SfxStyleSheetBasePool& _rPool, SfxStyleFamily _eFamily, sal_uInt16 _nMaske )
907 : ::cppu::ImplInheritanceHelper2< SfxStyleSheet, ::com::sun::star::style::XStyle, ::com::sun::star::lang::XUnoTunnel >( _rName, _rPool, _eFamily, _nMaske )
911 SfxUnoStyleSheet* SfxUnoStyleSheet::getUnoStyleSheet( const ::com::sun::star::uno::Reference< ::com::sun::star::style::XStyle >& xStyle )
913 SfxUnoStyleSheet* pRet = dynamic_cast< SfxUnoStyleSheet* >( xStyle.get() );
914 if( !pRet )
916 ::com::sun::star::uno::Reference< ::com::sun::star::lang::XUnoTunnel > xUT( xStyle, ::com::sun::star::uno::UNO_QUERY );
917 if( xUT.is() )
918 pRet = reinterpret_cast<SfxUnoStyleSheet*>(sal::static_int_cast<sal_uIntPtr>(xUT->getSomething( SfxUnoStyleSheet::getIdentifier())));
920 return pRet;
923 // XUnoTunnel
924 ::sal_Int64 SAL_CALL SfxUnoStyleSheet::getSomething( const ::com::sun::star::uno::Sequence< ::sal_Int8 >& rId ) throw (::com::sun::star::uno::RuntimeException)
926 if( rId.getLength() == 16 && 0 == memcmp( getIdentifier().getConstArray(), rId.getConstArray(), 16 ) )
928 return sal::static_int_cast<sal_Int64>(reinterpret_cast<sal_uIntPtr>(this));
930 else
932 return 0;
937 namespace
939 class theSfxUnoStyleSheetIdentifier : public rtl::Static< UnoTunnelIdInit, theSfxUnoStyleSheetIdentifier > {};
942 const ::com::sun::star::uno::Sequence< ::sal_Int8 >& SfxUnoStyleSheet::getIdentifier()
944 return theSfxUnoStyleSheetIdentifier::get().getSeq();
947 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */