140df464eSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 340df464eSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 440df464eSAndrew Rist * or more contributor license agreements. See the NOTICE file 540df464eSAndrew Rist * distributed with this work for additional information 640df464eSAndrew Rist * regarding copyright ownership. The ASF licenses this file 740df464eSAndrew Rist * to you under the Apache License, Version 2.0 (the 840df464eSAndrew Rist * "License"); you may not use this file except in compliance 940df464eSAndrew Rist * with the License. You may obtain a copy of the License at 1040df464eSAndrew Rist * 1140df464eSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 1240df464eSAndrew Rist * 1340df464eSAndrew Rist * Unless required by applicable law or agreed to in writing, 1440df464eSAndrew Rist * software distributed under the License is distributed on an 1540df464eSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 1640df464eSAndrew Rist * KIND, either express or implied. See the License for the 1740df464eSAndrew Rist * specific language governing permissions and limitations 1840df464eSAndrew Rist * under the License. 1940df464eSAndrew Rist * 2040df464eSAndrew Rist *************************************************************/ 2140df464eSAndrew Rist 2240df464eSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_svl.hxx" 26cdf0e10cSrcweir 27cdf0e10cSrcweir #ifndef _COM_SUN_STAR_LANG_XCOMPONENT_HPP_ 28cdf0e10cSrcweir #include <com/sun/star/lang/XComponent.hpp> 29cdf0e10cSrcweir #endif 30cdf0e10cSrcweir 31cdf0e10cSrcweir #define _SVSTDARR_STRINGS 32cdf0e10cSrcweir #define _SVSTDARR_STRINGSSORTDTOR 33cdf0e10cSrcweir #define _SVSTDARR_BYTESTRINGS 34cdf0e10cSrcweir #define _SVSTDARR_BYTESTRINGSSORTDTOR 35cdf0e10cSrcweir 36cdf0e10cSrcweir #include <rtl/uuid.h> 37cdf0e10cSrcweir #include <tools/tenccvt.hxx> 38cdf0e10cSrcweir #include <comphelper/processfactory.hxx> 39cdf0e10cSrcweir #include <unotools/intlwrapper.hxx> 40cdf0e10cSrcweir #include <svl/smplhint.hxx> 41cdf0e10cSrcweir #include <svl/poolitem.hxx> 42cdf0e10cSrcweir #include <svl/itemset.hxx> 43cdf0e10cSrcweir #include <svl/itempool.hxx> 44cdf0e10cSrcweir #include <poolio.hxx> 45cdf0e10cSrcweir #include <svl/filerec.hxx> 46cdf0e10cSrcweir #include <svl/itemiter.hxx> 47cdf0e10cSrcweir #include <svl/style.hxx> 48cdf0e10cSrcweir #include <svl/svstdarr.hxx> 49cdf0e10cSrcweir #include <unotools/syslocale.hxx> 50cdf0e10cSrcweir #include <algorithm> 51cdf0e10cSrcweir 52cdf0e10cSrcweir #define STYLESTREAM "SfxStyleSheets" 53cdf0e10cSrcweir #define STYLESTREAM_VERSION sal_uInt16(50) 54cdf0e10cSrcweir 55cdf0e10cSrcweir #ifdef DBG_UTIL 56cdf0e10cSrcweir class DbgStyleSheetReferences 57cdf0e10cSrcweir { 58cdf0e10cSrcweir public: 59cdf0e10cSrcweir DbgStyleSheetReferences() : mnStyles(0), mnPools(0) {} 60cdf0e10cSrcweir ~DbgStyleSheetReferences() 61cdf0e10cSrcweir { 62cdf0e10cSrcweir OSL_TRACE("DbgStyleSheetReferences\nSfxStyleSheetBase left %ld\nSfxStyleSheetBasePool left %ld\n", mnStyles, mnPools ); 63cdf0e10cSrcweir } 64cdf0e10cSrcweir 65cdf0e10cSrcweir sal_uInt32 mnStyles; 66cdf0e10cSrcweir sal_uInt32 mnPools; 67cdf0e10cSrcweir } 68cdf0e10cSrcweir aDbgStyleSheetReferences; 69cdf0e10cSrcweir 70cdf0e10cSrcweir #endif 71cdf0e10cSrcweir 72cdf0e10cSrcweir TYPEINIT0(SfxStyleSheetBase) 73cdf0e10cSrcweir 74cdf0e10cSrcweir TYPEINIT3(SfxStyleSheet, SfxStyleSheetBase, SfxListener, SfxBroadcaster) 75cdf0e10cSrcweir 76cdf0e10cSrcweir 77cdf0e10cSrcweir //========================================================================= 78cdf0e10cSrcweir 79cdf0e10cSrcweir TYPEINIT1(SfxStyleSheetHint, SfxHint); 80cdf0e10cSrcweir TYPEINIT1(SfxStyleSheetHintExtended, SfxStyleSheetHint); 81cdf0e10cSrcweir TYPEINIT1(SfxStyleSheetPoolHint, SfxHint); 82cdf0e10cSrcweir 83cdf0e10cSrcweir SfxStyleSheetHintExtended::SfxStyleSheetHintExtended 84cdf0e10cSrcweir ( 85cdf0e10cSrcweir sal_uInt16 nAction, // SFX_STYLESHEET_... (s.o.) 86cdf0e10cSrcweir const String& rOldName 87cdf0e10cSrcweir ) 88cdf0e10cSrcweir : SfxStyleSheetHint( nAction ), 89cdf0e10cSrcweir aName( rOldName ) 90cdf0e10cSrcweir {} 91cdf0e10cSrcweir SfxStyleSheetHintExtended::SfxStyleSheetHintExtended 92cdf0e10cSrcweir ( 93cdf0e10cSrcweir sal_uInt16 nAction, // SFX_STYLESHEET_... (s.o.) 94cdf0e10cSrcweir const String& rOldName, 95cdf0e10cSrcweir SfxStyleSheetBase& rStyleSheet // geh"ort weiterhin dem Aufrufer 96cdf0e10cSrcweir ) 97cdf0e10cSrcweir : SfxStyleSheetHint( nAction, rStyleSheet ), 98cdf0e10cSrcweir aName( rOldName ) 99cdf0e10cSrcweir {} 100cdf0e10cSrcweir 101cdf0e10cSrcweir //------------------------------------------------------------------------- 102cdf0e10cSrcweir 103cdf0e10cSrcweir SfxStyleSheetHint::SfxStyleSheetHint 104cdf0e10cSrcweir ( 105cdf0e10cSrcweir sal_uInt16 nAction, // SFX_STYLESHEET_... (s.o.) 106cdf0e10cSrcweir SfxStyleSheetBase& rStyleSheet // geh"ort weiterhin dem Aufrufer 107cdf0e10cSrcweir ) 108cdf0e10cSrcweir : pStyleSh( &rStyleSheet ), 109cdf0e10cSrcweir nHint( nAction ) 110cdf0e10cSrcweir {} 111cdf0e10cSrcweir 112cdf0e10cSrcweir SfxStyleSheetHint::SfxStyleSheetHint 113cdf0e10cSrcweir ( 114cdf0e10cSrcweir sal_uInt16 nAction // SFX_STYLESHEET_... (s.o.) 115cdf0e10cSrcweir ) 116cdf0e10cSrcweir : pStyleSh( NULL ), 117cdf0e10cSrcweir nHint( nAction ) 118cdf0e10cSrcweir {} 119cdf0e10cSrcweir 120cdf0e10cSrcweir //========================================================================= 121cdf0e10cSrcweir 122cdf0e10cSrcweir class SfxStyleSheetBasePool_Impl 123cdf0e10cSrcweir { 124cdf0e10cSrcweir public: 125cdf0e10cSrcweir SfxStyles aStyles; 126cdf0e10cSrcweir SfxStyleSheetIterator *pIter; 127cdf0e10cSrcweir SfxStyleSheetBasePool_Impl() : pIter(0){} 128cdf0e10cSrcweir ~SfxStyleSheetBasePool_Impl(){delete pIter;} 129cdf0e10cSrcweir }; 130cdf0e10cSrcweir 131cdf0e10cSrcweir 132cdf0e10cSrcweir //////////////////////////// SfxStyleSheetBase /////////////////////////////// 133cdf0e10cSrcweir 134cdf0e10cSrcweir // Konstruktoren 135cdf0e10cSrcweir 136cdf0e10cSrcweir SfxStyleSheetBase::SfxStyleSheetBase( const XubString& rName, SfxStyleSheetBasePool& r, SfxStyleFamily eFam, sal_uInt16 mask ) 137cdf0e10cSrcweir : rPool( r ) 138cdf0e10cSrcweir , nFamily( eFam ) 139cdf0e10cSrcweir , aName( rName ) 140cdf0e10cSrcweir , aParent() 141cdf0e10cSrcweir , aFollow( rName ) 142cdf0e10cSrcweir , pSet( NULL ) 143cdf0e10cSrcweir , nMask(mask) 144cdf0e10cSrcweir , nHelpId( 0 ) 145cdf0e10cSrcweir , bMySet( sal_False ) 146cdf0e10cSrcweir { 147cdf0e10cSrcweir #ifdef DBG_UTIL 148cdf0e10cSrcweir aDbgStyleSheetReferences.mnStyles++; 149cdf0e10cSrcweir #endif 150cdf0e10cSrcweir } 151cdf0e10cSrcweir 152cdf0e10cSrcweir SfxStyleSheetBase::SfxStyleSheetBase( const SfxStyleSheetBase& r ) 153cdf0e10cSrcweir : comphelper::OWeakTypeObject() 154cdf0e10cSrcweir , rPool( r.rPool ) 155cdf0e10cSrcweir , nFamily( r.nFamily ) 156cdf0e10cSrcweir , aName( r.aName ) 157cdf0e10cSrcweir , aParent( r.aParent ) 158cdf0e10cSrcweir , aFollow( r.aFollow ) 159cdf0e10cSrcweir , aHelpFile( r.aHelpFile ) 160cdf0e10cSrcweir , nMask( r.nMask ) 161cdf0e10cSrcweir , nHelpId( r.nHelpId ) 162cdf0e10cSrcweir , bMySet( r.bMySet ) 163cdf0e10cSrcweir { 164cdf0e10cSrcweir #ifdef DBG_UTIL 165cdf0e10cSrcweir aDbgStyleSheetReferences.mnStyles++; 166cdf0e10cSrcweir #endif 167cdf0e10cSrcweir if( r.pSet ) 168cdf0e10cSrcweir pSet = bMySet ? new SfxItemSet( *r.pSet ) : r.pSet; 169cdf0e10cSrcweir else 170cdf0e10cSrcweir pSet = NULL; 171cdf0e10cSrcweir } 172cdf0e10cSrcweir 173cdf0e10cSrcweir static SfxStyleSheetBasePool& implGetStaticPool() 174cdf0e10cSrcweir { 175cdf0e10cSrcweir static SfxStyleSheetBasePool* pSheetPool = 0; 176cdf0e10cSrcweir static SfxItemPool* pBasePool = 0; 177cdf0e10cSrcweir if( !pSheetPool ) 178cdf0e10cSrcweir { 179cdf0e10cSrcweir UniString aName; 180cdf0e10cSrcweir pBasePool = new SfxItemPool( aName, 0, 0, 0 ); 181cdf0e10cSrcweir pSheetPool = new SfxStyleSheetBasePool(*pBasePool); 182cdf0e10cSrcweir } 183cdf0e10cSrcweir return *pSheetPool; 184cdf0e10cSrcweir } 185cdf0e10cSrcweir 186cdf0e10cSrcweir SfxStyleSheetBase::SfxStyleSheetBase() 187cdf0e10cSrcweir : comphelper::OWeakTypeObject() 188cdf0e10cSrcweir , rPool( implGetStaticPool() ) 189cdf0e10cSrcweir { 190cdf0e10cSrcweir } 191cdf0e10cSrcweir 192cdf0e10cSrcweir SfxStyleSheetBase::~SfxStyleSheetBase() 193cdf0e10cSrcweir { 194cdf0e10cSrcweir #ifdef DBG_UTIL 195cdf0e10cSrcweir --aDbgStyleSheetReferences.mnStyles; 196cdf0e10cSrcweir #endif 197cdf0e10cSrcweir 198cdf0e10cSrcweir if( bMySet ) 199cdf0e10cSrcweir { 200cdf0e10cSrcweir delete pSet; 201cdf0e10cSrcweir pSet = 0; 202cdf0e10cSrcweir } 203cdf0e10cSrcweir } 204cdf0e10cSrcweir 205cdf0e10cSrcweir sal_uInt16 SfxStyleSheetBase::GetVersion() const 206cdf0e10cSrcweir { 207cdf0e10cSrcweir return 0x0000; 208cdf0e10cSrcweir } 209cdf0e10cSrcweir 210cdf0e10cSrcweir // Namen aendern 211cdf0e10cSrcweir 212cdf0e10cSrcweir const XubString& SfxStyleSheetBase::GetName() const 213cdf0e10cSrcweir { 214cdf0e10cSrcweir return aName; 215cdf0e10cSrcweir } 216cdf0e10cSrcweir 217cdf0e10cSrcweir sal_Bool SfxStyleSheetBase::SetName( const XubString& rName ) 218cdf0e10cSrcweir { 219cdf0e10cSrcweir if(rName.Len() == 0) 220cdf0e10cSrcweir return sal_False; 221cdf0e10cSrcweir if( aName != rName ) 222cdf0e10cSrcweir { 223cdf0e10cSrcweir String aOldName = aName; 224cdf0e10cSrcweir SfxStyleSheetBase *pOther = rPool.Find( rName, nFamily ) ; 225cdf0e10cSrcweir if ( pOther && pOther != this ) 226cdf0e10cSrcweir return sal_False; 227cdf0e10cSrcweir 228cdf0e10cSrcweir SfxStyleFamily eTmpFam=rPool.GetSearchFamily(); 229cdf0e10cSrcweir sal_uInt16 nTmpMask=rPool.GetSearchMask(); 230cdf0e10cSrcweir 231cdf0e10cSrcweir rPool.SetSearchMask(nFamily); 232cdf0e10cSrcweir 233cdf0e10cSrcweir if ( aName.Len() ) 234cdf0e10cSrcweir rPool.ChangeParent( aName, rName, sal_False ); 235cdf0e10cSrcweir if ( aFollow.Equals( aName ) ) 236cdf0e10cSrcweir aFollow = rName; 237cdf0e10cSrcweir aName = rName; 238cdf0e10cSrcweir rPool.SetSearchMask(eTmpFam, nTmpMask); 239cdf0e10cSrcweir rPool.Broadcast( SfxStyleSheetHintExtended( 240cdf0e10cSrcweir SFX_STYLESHEET_MODIFIED, aOldName, *this ) ); 241cdf0e10cSrcweir } 242cdf0e10cSrcweir return sal_True; 243cdf0e10cSrcweir } 244cdf0e10cSrcweir 245cdf0e10cSrcweir rtl::OUString SfxStyleSheetBase::GetDisplayName() const 246cdf0e10cSrcweir { 247cdf0e10cSrcweir if( maDisplayName.getLength() == 0 ) 248cdf0e10cSrcweir { 249cdf0e10cSrcweir return aName; 250cdf0e10cSrcweir } 251cdf0e10cSrcweir else 252cdf0e10cSrcweir { 253cdf0e10cSrcweir return maDisplayName; 254cdf0e10cSrcweir } 255cdf0e10cSrcweir } 256cdf0e10cSrcweir 257cdf0e10cSrcweir void SfxStyleSheetBase::SetDisplayName( const rtl::OUString& rDisplayName ) 258cdf0e10cSrcweir { 259cdf0e10cSrcweir maDisplayName = rDisplayName; 260cdf0e10cSrcweir } 261cdf0e10cSrcweir 262cdf0e10cSrcweir // Parent aendern 263cdf0e10cSrcweir 264cdf0e10cSrcweir const XubString& SfxStyleSheetBase::GetParent() const 265cdf0e10cSrcweir { 266cdf0e10cSrcweir return aParent; 267cdf0e10cSrcweir } 268cdf0e10cSrcweir 269cdf0e10cSrcweir sal_Bool SfxStyleSheetBase::SetParent( const XubString& rName ) 270cdf0e10cSrcweir { 271cdf0e10cSrcweir if ( rName == aName ) 272cdf0e10cSrcweir return sal_False; 273cdf0e10cSrcweir 274cdf0e10cSrcweir if( aParent != rName ) 275cdf0e10cSrcweir { 276cdf0e10cSrcweir SfxStyleSheetBase* pIter = rPool.Find(rName, nFamily); 277cdf0e10cSrcweir if( rName.Len() && !pIter ) 278cdf0e10cSrcweir { 279cdf0e10cSrcweir DBG_ERROR( "StyleSheet-Parent nicht gefunden" ); 280cdf0e10cSrcweir return sal_False; 281cdf0e10cSrcweir } 282cdf0e10cSrcweir // rekursive Verknuepfungen verhindern 283cdf0e10cSrcweir if( aName.Len() ) 284cdf0e10cSrcweir while(pIter) 285cdf0e10cSrcweir { 286cdf0e10cSrcweir if(pIter->GetName() == aName && aName != rName) 287cdf0e10cSrcweir return sal_False; 288cdf0e10cSrcweir pIter = rPool.Find(pIter->GetParent(), nFamily); 289cdf0e10cSrcweir } 290cdf0e10cSrcweir aParent = rName; 291cdf0e10cSrcweir } 292cdf0e10cSrcweir rPool.Broadcast( SfxStyleSheetHint( SFX_STYLESHEET_MODIFIED, *this ) ); 293cdf0e10cSrcweir return sal_True; 294cdf0e10cSrcweir } 295cdf0e10cSrcweir 296cdf0e10cSrcweir // Follow aendern 297cdf0e10cSrcweir 298cdf0e10cSrcweir const XubString& SfxStyleSheetBase::GetFollow() const 299cdf0e10cSrcweir { 300cdf0e10cSrcweir return aFollow; 301cdf0e10cSrcweir } 302cdf0e10cSrcweir 303cdf0e10cSrcweir sal_Bool SfxStyleSheetBase::SetFollow( const XubString& rName ) 304cdf0e10cSrcweir { 305cdf0e10cSrcweir if( aFollow != rName ) 306cdf0e10cSrcweir { 307cdf0e10cSrcweir if( !rPool.Find( rName, nFamily ) ) 308cdf0e10cSrcweir { 309cdf0e10cSrcweir DBG_ERROR( "StyleSheet-Follow nicht gefunden" ); 310cdf0e10cSrcweir return sal_False; 311cdf0e10cSrcweir } 312cdf0e10cSrcweir aFollow = rName; 313cdf0e10cSrcweir } 314cdf0e10cSrcweir rPool.Broadcast( SfxStyleSheetHint( SFX_STYLESHEET_MODIFIED, *this ) ); 315cdf0e10cSrcweir return sal_True; 316cdf0e10cSrcweir } 317cdf0e10cSrcweir 318cdf0e10cSrcweir // Itemset setzen. Die Dflt-Implementation legt ein neues Set an. 319cdf0e10cSrcweir 320cdf0e10cSrcweir SfxItemSet& SfxStyleSheetBase::GetItemSet() 321cdf0e10cSrcweir { 322cdf0e10cSrcweir if( !pSet ) 323cdf0e10cSrcweir { 324cdf0e10cSrcweir pSet = new SfxItemSet( rPool.GetPool() ); 325cdf0e10cSrcweir bMySet = sal_True; 326cdf0e10cSrcweir } 327cdf0e10cSrcweir return *pSet; 328cdf0e10cSrcweir } 329cdf0e10cSrcweir 330cdf0e10cSrcweir // Hilfe-Datei und -ID setzen und abfragen 331cdf0e10cSrcweir 332cdf0e10cSrcweir sal_uLong SfxStyleSheetBase::GetHelpId( String& rFile ) 333cdf0e10cSrcweir { 334cdf0e10cSrcweir rFile = aHelpFile; 335cdf0e10cSrcweir return nHelpId; 336cdf0e10cSrcweir } 337cdf0e10cSrcweir 338cdf0e10cSrcweir void SfxStyleSheetBase::SetHelpId( const String& rFile, sal_uLong nId ) 339cdf0e10cSrcweir { 340cdf0e10cSrcweir aHelpFile = rFile; 341cdf0e10cSrcweir nHelpId = nId; 342cdf0e10cSrcweir } 343cdf0e10cSrcweir 344cdf0e10cSrcweir // Folgevorlage m"oglich? Default: Ja 345cdf0e10cSrcweir 346cdf0e10cSrcweir sal_Bool SfxStyleSheetBase::HasFollowSupport() const 347cdf0e10cSrcweir { 348cdf0e10cSrcweir return sal_True; 349cdf0e10cSrcweir } 350cdf0e10cSrcweir 351cdf0e10cSrcweir // Basisvorlage m"oglich? Default: Ja 352cdf0e10cSrcweir 353cdf0e10cSrcweir sal_Bool SfxStyleSheetBase::HasParentSupport() const 354cdf0e10cSrcweir { 355cdf0e10cSrcweir return sal_True; 356cdf0e10cSrcweir } 357cdf0e10cSrcweir 358cdf0e10cSrcweir // Basisvorlage uf NULL setzen m"oglich? Default: Nein 359cdf0e10cSrcweir 360cdf0e10cSrcweir sal_Bool SfxStyleSheetBase::HasClearParentSupport() const 361cdf0e10cSrcweir { 362cdf0e10cSrcweir return sal_False; 363cdf0e10cSrcweir } 364cdf0e10cSrcweir 365cdf0e10cSrcweir // Defaultmaessig sind alle StyleSheets Used 366cdf0e10cSrcweir 367cdf0e10cSrcweir sal_Bool SfxStyleSheetBase::IsUsed() const 368cdf0e10cSrcweir { 369cdf0e10cSrcweir return sal_True; 370cdf0e10cSrcweir } 371cdf0e10cSrcweir 372cdf0e10cSrcweir // eingestellte Attribute ausgeben 373cdf0e10cSrcweir 374cdf0e10cSrcweir 375cdf0e10cSrcweir XubString SfxStyleSheetBase::GetDescription() 376cdf0e10cSrcweir { 377cdf0e10cSrcweir return GetDescription( SFX_MAPUNIT_CM ); 378cdf0e10cSrcweir } 379cdf0e10cSrcweir 380cdf0e10cSrcweir // eingestellte Attribute ausgeben 381cdf0e10cSrcweir 382cdf0e10cSrcweir XubString SfxStyleSheetBase::GetDescription( SfxMapUnit eMetric ) 383cdf0e10cSrcweir { 384cdf0e10cSrcweir SfxItemIter aIter( GetItemSet() ); 385cdf0e10cSrcweir XubString aDesc; 386cdf0e10cSrcweir const SfxPoolItem* pItem = aIter.FirstItem(); 387cdf0e10cSrcweir 388cdf0e10cSrcweir IntlWrapper aIntlWrapper(comphelper::getProcessServiceFactory(), 389cdf0e10cSrcweir SvtSysLocale().GetLanguage()); 390cdf0e10cSrcweir while ( pItem ) 391cdf0e10cSrcweir { 392cdf0e10cSrcweir XubString aItemPresentation; 393cdf0e10cSrcweir 394cdf0e10cSrcweir if ( !IsInvalidItem( pItem ) && 395cdf0e10cSrcweir rPool.GetPool().GetPresentation( 396cdf0e10cSrcweir *pItem, SFX_ITEM_PRESENTATION_COMPLETE, 397cdf0e10cSrcweir eMetric, aItemPresentation, &aIntlWrapper ) ) 398cdf0e10cSrcweir { 399cdf0e10cSrcweir if ( aDesc.Len() && aItemPresentation.Len() ) 400cdf0e10cSrcweir aDesc.AppendAscii(RTL_CONSTASCII_STRINGPARAM(" + ")); 401cdf0e10cSrcweir if ( aItemPresentation.Len() ) 402cdf0e10cSrcweir aDesc += aItemPresentation; 403cdf0e10cSrcweir } 404cdf0e10cSrcweir pItem = aIter.NextItem(); 405cdf0e10cSrcweir } 406cdf0e10cSrcweir return aDesc; 407cdf0e10cSrcweir } 408cdf0e10cSrcweir 409cdf0e10cSrcweir /////////////////////////// SfxStyleSheetIterator /////////////////////////////// 410cdf0e10cSrcweir 411cdf0e10cSrcweir SfxStyleFamily SfxStyleSheetIterator::GetSearchFamily() const 412cdf0e10cSrcweir { 413cdf0e10cSrcweir return nSearchFamily; 414cdf0e10cSrcweir } 415cdf0e10cSrcweir 416cdf0e10cSrcweir inline sal_Bool SfxStyleSheetIterator::IsTrivialSearch() 417cdf0e10cSrcweir { 418cdf0e10cSrcweir return nMask == 0xFFFF && GetSearchFamily() == SFX_STYLE_FAMILY_ALL; 419cdf0e10cSrcweir } 420cdf0e10cSrcweir 421cdf0e10cSrcweir sal_Bool SfxStyleSheetIterator::DoesStyleMatch(SfxStyleSheetBase *pStyle) 422cdf0e10cSrcweir { 423cdf0e10cSrcweir return ((GetSearchFamily() == SFX_STYLE_FAMILY_ALL) || 424cdf0e10cSrcweir ( pStyle->GetFamily() == GetSearchFamily() )) 425cdf0e10cSrcweir && (( pStyle->GetMask() & ( GetSearchMask() & ~SFXSTYLEBIT_USED )) || 426cdf0e10cSrcweir ( bSearchUsed ? pStyle->IsUsed() : sal_False ) || 427cdf0e10cSrcweir GetSearchMask() == SFXSTYLEBIT_ALL ); 428cdf0e10cSrcweir } 429cdf0e10cSrcweir 430cdf0e10cSrcweir 431cdf0e10cSrcweir SfxStyleSheetIterator::SfxStyleSheetIterator(SfxStyleSheetBasePool *pBase, 432cdf0e10cSrcweir SfxStyleFamily eFam, sal_uInt16 n) 433cdf0e10cSrcweir { 434cdf0e10cSrcweir pBasePool=pBase; 435cdf0e10cSrcweir nSearchFamily=eFam; 436cdf0e10cSrcweir bSearchUsed=sal_False; 437cdf0e10cSrcweir if((n != SFXSTYLEBIT_ALL ) && ((n & SFXSTYLEBIT_USED) == SFXSTYLEBIT_USED)) 438cdf0e10cSrcweir { 439cdf0e10cSrcweir bSearchUsed = sal_True; 440cdf0e10cSrcweir n &= ~SFXSTYLEBIT_USED; 441cdf0e10cSrcweir } 442cdf0e10cSrcweir nMask=n; 443cdf0e10cSrcweir } 444cdf0e10cSrcweir 445cdf0e10cSrcweir SfxStyleSheetIterator::~SfxStyleSheetIterator() 446cdf0e10cSrcweir { 447cdf0e10cSrcweir } 448cdf0e10cSrcweir 449cdf0e10cSrcweir 450cdf0e10cSrcweir sal_uInt16 SfxStyleSheetIterator::Count() 451cdf0e10cSrcweir { 452cdf0e10cSrcweir sal_uInt16 n = 0; 453cdf0e10cSrcweir if( IsTrivialSearch()) 454cdf0e10cSrcweir n = (sal_uInt16) pBasePool->aStyles.size(); 455cdf0e10cSrcweir else 456cdf0e10cSrcweir for(sal_uInt16 i=0; i<pBasePool->aStyles.size(); i++) 457cdf0e10cSrcweir { 458cdf0e10cSrcweir SfxStyleSheetBase* pStyle = pBasePool->aStyles[i].get(); 459cdf0e10cSrcweir if(DoesStyleMatch(pStyle)) 460cdf0e10cSrcweir n++; 461cdf0e10cSrcweir } 462cdf0e10cSrcweir return n; 463cdf0e10cSrcweir } 464cdf0e10cSrcweir 465cdf0e10cSrcweir SfxStyleSheetBase* SfxStyleSheetIterator::operator[](sal_uInt16 nIdx) 466cdf0e10cSrcweir { 467cdf0e10cSrcweir if( IsTrivialSearch()) 468cdf0e10cSrcweir return pBasePool->aStyles[nIdx].get(); 469cdf0e10cSrcweir 470cdf0e10cSrcweir sal_uInt16 z = 0; 471cdf0e10cSrcweir for(sal_uInt16 n=0; n<pBasePool->aStyles.size(); n++) 472cdf0e10cSrcweir { 473cdf0e10cSrcweir SfxStyleSheetBase* pStyle = pBasePool->aStyles[n].get(); 474cdf0e10cSrcweir if( DoesStyleMatch(pStyle)) 475cdf0e10cSrcweir { 476cdf0e10cSrcweir if(z == nIdx) 477cdf0e10cSrcweir { 478cdf0e10cSrcweir nAktPosition=n; 479cdf0e10cSrcweir return pAktStyle=pStyle; 480cdf0e10cSrcweir } 481cdf0e10cSrcweir ++z; 482cdf0e10cSrcweir } 483cdf0e10cSrcweir } 484cdf0e10cSrcweir DBG_ERROR("falscher Index"); 485cdf0e10cSrcweir return 0; 486cdf0e10cSrcweir } 487cdf0e10cSrcweir 488cdf0e10cSrcweir SfxStyleSheetBase* SfxStyleSheetIterator::First() 489cdf0e10cSrcweir { 490cdf0e10cSrcweir sal_Int32 nIdx = -1; 491cdf0e10cSrcweir 492cdf0e10cSrcweir if ( IsTrivialSearch() && pBasePool->aStyles.size() ) 493cdf0e10cSrcweir nIdx = 0; 494cdf0e10cSrcweir else 495cdf0e10cSrcweir for( sal_uInt16 n = 0; n < pBasePool->aStyles.size(); n++ ) 496cdf0e10cSrcweir { 497cdf0e10cSrcweir SfxStyleSheetBase* pStyle = pBasePool->aStyles[n].get(); 498cdf0e10cSrcweir 499cdf0e10cSrcweir if ( DoesStyleMatch( pStyle ) ) 500cdf0e10cSrcweir { 501cdf0e10cSrcweir nIdx = n; 502cdf0e10cSrcweir break; 503cdf0e10cSrcweir } 504cdf0e10cSrcweir } 505cdf0e10cSrcweir 506cdf0e10cSrcweir if ( nIdx != -1 ) 507cdf0e10cSrcweir { 508cdf0e10cSrcweir nAktPosition = (sal_uInt16)nIdx; 509cdf0e10cSrcweir return pAktStyle = pBasePool->aStyles[nIdx].get(); 510cdf0e10cSrcweir } 511cdf0e10cSrcweir return 0; 512cdf0e10cSrcweir } 513cdf0e10cSrcweir 514cdf0e10cSrcweir 515cdf0e10cSrcweir SfxStyleSheetBase* SfxStyleSheetIterator::Next() 516cdf0e10cSrcweir { 517cdf0e10cSrcweir sal_Int32 nIdx = -1; 518cdf0e10cSrcweir 519cdf0e10cSrcweir if ( IsTrivialSearch() && 520cdf0e10cSrcweir (sal_uInt16)pBasePool->aStyles.size() > nAktPosition + 1 ) 521cdf0e10cSrcweir nIdx = nAktPosition + 1; 522cdf0e10cSrcweir else 523cdf0e10cSrcweir for( sal_uInt16 n = nAktPosition + 1; n < pBasePool->aStyles.size(); n++ ) 524cdf0e10cSrcweir { 525cdf0e10cSrcweir SfxStyleSheetBase* pStyle = pBasePool->aStyles[n].get(); 526cdf0e10cSrcweir 527cdf0e10cSrcweir if ( DoesStyleMatch( pStyle ) ) 528cdf0e10cSrcweir { 529cdf0e10cSrcweir nIdx = n; 530cdf0e10cSrcweir break; 531cdf0e10cSrcweir } 532cdf0e10cSrcweir } 533cdf0e10cSrcweir 534cdf0e10cSrcweir if ( nIdx != -1 ) 535cdf0e10cSrcweir { 536cdf0e10cSrcweir nAktPosition = (sal_uInt16)nIdx; 537cdf0e10cSrcweir return pAktStyle = pBasePool->aStyles[nIdx].get(); 538cdf0e10cSrcweir } 539cdf0e10cSrcweir return 0; 540cdf0e10cSrcweir } 541cdf0e10cSrcweir 542cdf0e10cSrcweir 543cdf0e10cSrcweir SfxStyleSheetBase* SfxStyleSheetIterator::Find(const XubString& rStr) 544cdf0e10cSrcweir { 545cdf0e10cSrcweir for ( sal_uInt16 n = 0; n < pBasePool->aStyles.size(); n++ ) 546cdf0e10cSrcweir { 547cdf0e10cSrcweir SfxStyleSheetBase* pStyle = pBasePool->aStyles[n].get(); 548cdf0e10cSrcweir 549cdf0e10cSrcweir // #98454# performance: in case of bSearchUsed==sal_True it may be 550cdf0e10cSrcweir // significant to first compare the name and only if it matches to call 551cdf0e10cSrcweir // the style sheet IsUsed() method in DoesStyleMatch(). 552cdf0e10cSrcweir if ( pStyle->GetName().Equals( rStr ) && DoesStyleMatch( pStyle ) ) 553cdf0e10cSrcweir { 554cdf0e10cSrcweir nAktPosition = n; 555cdf0e10cSrcweir return pAktStyle = pStyle; 556cdf0e10cSrcweir } 557cdf0e10cSrcweir } 558cdf0e10cSrcweir return 0; 559cdf0e10cSrcweir } 560cdf0e10cSrcweir 561cdf0e10cSrcweir 562cdf0e10cSrcweir sal_uInt16 SfxStyleSheetIterator::GetSearchMask() const 563cdf0e10cSrcweir { 564cdf0e10cSrcweir sal_uInt16 mask = nMask; 565cdf0e10cSrcweir 566cdf0e10cSrcweir if ( bSearchUsed ) 567cdf0e10cSrcweir mask |= SFXSTYLEBIT_USED; 568cdf0e10cSrcweir return mask; 569cdf0e10cSrcweir } 570cdf0e10cSrcweir 571cdf0e10cSrcweir /////////////////////////// SfxStyleSheetBasePool /////////////////////////////// 572cdf0e10cSrcweir 573cdf0e10cSrcweir void SfxStyleSheetBasePool::Replace( 574cdf0e10cSrcweir SfxStyleSheetBase& rSource, SfxStyleSheetBase& rTarget ) 575cdf0e10cSrcweir { 576cdf0e10cSrcweir rTarget.SetFollow( rSource.GetFollow() ); 577cdf0e10cSrcweir rTarget.SetParent( rSource.GetParent() ); 578cdf0e10cSrcweir SfxItemSet& rSourceSet = rSource.GetItemSet(); 579cdf0e10cSrcweir SfxItemSet& rTargetSet = rTarget.GetItemSet(); 580cdf0e10cSrcweir rTargetSet.Intersect( rSourceSet ); 581cdf0e10cSrcweir rTargetSet.Put( rSourceSet ); 582cdf0e10cSrcweir } 583cdf0e10cSrcweir 584cdf0e10cSrcweir SfxStyleSheetIterator& SfxStyleSheetBasePool::GetIterator_Impl() 585cdf0e10cSrcweir { 586cdf0e10cSrcweir SfxStyleSheetIterator*& rpIter = pImp->pIter; 587cdf0e10cSrcweir if( !rpIter || (rpIter->GetSearchMask() != nMask) || (rpIter->GetSearchFamily() != nSearchFamily) ) 588cdf0e10cSrcweir { 589cdf0e10cSrcweir delete rpIter; 590cdf0e10cSrcweir rpIter = CreateIterator( nSearchFamily, nMask ); 591cdf0e10cSrcweir } 592cdf0e10cSrcweir return *rpIter; 593cdf0e10cSrcweir } 594cdf0e10cSrcweir 595cdf0e10cSrcweir 596cdf0e10cSrcweir SfxStyleSheetBasePool::SfxStyleSheetBasePool( SfxItemPool& r ) 597cdf0e10cSrcweir : aAppName(r.GetName()) 598cdf0e10cSrcweir , rPool(r) 599cdf0e10cSrcweir , nSearchFamily(SFX_STYLE_FAMILY_PARA) 600cdf0e10cSrcweir , nMask(0xFFFF) 601cdf0e10cSrcweir { 602cdf0e10cSrcweir #ifdef DBG_UTIL 603cdf0e10cSrcweir aDbgStyleSheetReferences.mnPools++; 604cdf0e10cSrcweir #endif 605cdf0e10cSrcweir 606cdf0e10cSrcweir pImp = new SfxStyleSheetBasePool_Impl; 607cdf0e10cSrcweir } 608cdf0e10cSrcweir 609cdf0e10cSrcweir SfxStyleSheetBasePool::SfxStyleSheetBasePool( const SfxStyleSheetBasePool& r ) 610cdf0e10cSrcweir : SfxBroadcaster( r ) 611cdf0e10cSrcweir , comphelper::OWeakTypeObject() 612cdf0e10cSrcweir , aAppName(r.aAppName) 613cdf0e10cSrcweir , rPool(r.rPool) 614cdf0e10cSrcweir , nSearchFamily(r.nSearchFamily) 615cdf0e10cSrcweir , nMask( r.nMask ) 616cdf0e10cSrcweir { 617cdf0e10cSrcweir #ifdef DBG_UTIL 618cdf0e10cSrcweir aDbgStyleSheetReferences.mnPools++; 619cdf0e10cSrcweir #endif 620cdf0e10cSrcweir 621cdf0e10cSrcweir pImp = new SfxStyleSheetBasePool_Impl; 622cdf0e10cSrcweir *this += r; 623cdf0e10cSrcweir } 624cdf0e10cSrcweir 625cdf0e10cSrcweir SfxStyleSheetBasePool::~SfxStyleSheetBasePool() 626cdf0e10cSrcweir { 627cdf0e10cSrcweir #ifdef DBG_UTIL 628cdf0e10cSrcweir aDbgStyleSheetReferences.mnPools--; 629cdf0e10cSrcweir #endif 630cdf0e10cSrcweir 631cdf0e10cSrcweir Broadcast( SfxSimpleHint(SFX_HINT_DYING) ); 632cdf0e10cSrcweir Clear(); 633cdf0e10cSrcweir delete pImp; 634cdf0e10cSrcweir } 635cdf0e10cSrcweir 636cdf0e10cSrcweir sal_Bool SfxStyleSheetBasePool::SetParent(SfxStyleFamily eFam, const XubString& rStyle, const XubString& rParent) 637cdf0e10cSrcweir { 638cdf0e10cSrcweir SfxStyleSheetIterator aIter(this,eFam,SFXSTYLEBIT_ALL); 639cdf0e10cSrcweir SfxStyleSheetBase *pStyle = 640cdf0e10cSrcweir aIter.Find(rStyle); 641cdf0e10cSrcweir DBG_ASSERT(pStyle, "Vorlage nicht gefunden. Writer mit Solar <2541??"); 642cdf0e10cSrcweir if(pStyle) 643cdf0e10cSrcweir return pStyle->SetParent(rParent); 644cdf0e10cSrcweir else 645cdf0e10cSrcweir return sal_False; 646cdf0e10cSrcweir } 647cdf0e10cSrcweir 648cdf0e10cSrcweir 649cdf0e10cSrcweir void SfxStyleSheetBasePool::SetSearchMask(SfxStyleFamily eFam, sal_uInt16 n) 650cdf0e10cSrcweir { 651cdf0e10cSrcweir nSearchFamily = eFam; nMask = n; 652cdf0e10cSrcweir } 653cdf0e10cSrcweir 654cdf0e10cSrcweir sal_uInt16 SfxStyleSheetBasePool::GetSearchMask() const 655cdf0e10cSrcweir { 656cdf0e10cSrcweir return nMask; 657cdf0e10cSrcweir } 658cdf0e10cSrcweir 659cdf0e10cSrcweir 660cdf0e10cSrcweir // Der Name des Streams 661cdf0e10cSrcweir 662cdf0e10cSrcweir String SfxStyleSheetBasePool::GetStreamName() 663cdf0e10cSrcweir { 664cdf0e10cSrcweir return String::CreateFromAscii(RTL_CONSTASCII_STRINGPARAM(STYLESTREAM)); 665cdf0e10cSrcweir } 666cdf0e10cSrcweir 667cdf0e10cSrcweir /////////////////////////////////// Factory //////////////////////////////// 668cdf0e10cSrcweir 669cdf0e10cSrcweir 670cdf0e10cSrcweir 671cdf0e10cSrcweir SfxStyleSheetIterator* SfxStyleSheetBasePool::CreateIterator 672cdf0e10cSrcweir ( 673cdf0e10cSrcweir SfxStyleFamily eFam, 674cdf0e10cSrcweir sal_uInt16 mask 675cdf0e10cSrcweir ) 676cdf0e10cSrcweir { 677cdf0e10cSrcweir return new SfxStyleSheetIterator(this,eFam,mask); 678cdf0e10cSrcweir } 679cdf0e10cSrcweir 680cdf0e10cSrcweir 681cdf0e10cSrcweir SfxStyleSheetBase* SfxStyleSheetBasePool::Create 682cdf0e10cSrcweir ( 683cdf0e10cSrcweir const XubString& rName, 684cdf0e10cSrcweir SfxStyleFamily eFam, 685cdf0e10cSrcweir sal_uInt16 mask 686cdf0e10cSrcweir ) 687cdf0e10cSrcweir { 688cdf0e10cSrcweir return new SfxStyleSheetBase( rName, *this, eFam, mask ); 689cdf0e10cSrcweir } 690cdf0e10cSrcweir 691cdf0e10cSrcweir SfxStyleSheetBase* SfxStyleSheetBasePool::Create( const SfxStyleSheetBase& r ) 692cdf0e10cSrcweir { 693cdf0e10cSrcweir return new SfxStyleSheetBase( r ); 694cdf0e10cSrcweir } 695cdf0e10cSrcweir 696cdf0e10cSrcweir SfxStyleSheetBase& SfxStyleSheetBasePool::Make( const XubString& rName, SfxStyleFamily eFam, sal_uInt16 mask, sal_uInt16 nPos) 697cdf0e10cSrcweir { 698cdf0e10cSrcweir DBG_ASSERT( eFam != SFX_STYLE_FAMILY_ALL, "svl::SfxStyleSheetBasePool::Make(), FamilyAll is not a allowed Familie" ); 699cdf0e10cSrcweir 700cdf0e10cSrcweir SfxStyleSheetIterator aIter(this, eFam, mask); 701cdf0e10cSrcweir rtl::Reference< SfxStyleSheetBase > xStyle( aIter.Find( rName ) ); 702cdf0e10cSrcweir DBG_ASSERT( !xStyle.is(), "svl::SfxStyleSheetBasePool::Make(), StyleSheet already exists" ); 703cdf0e10cSrcweir SfxStyleSheetIterator& rIter = GetIterator_Impl(); 704cdf0e10cSrcweir 705cdf0e10cSrcweir if( !xStyle.is() ) 706cdf0e10cSrcweir { 707cdf0e10cSrcweir xStyle = Create( rName, eFam, mask ); 708cdf0e10cSrcweir if(0xffff == nPos || nPos == aStyles.size() || nPos == rIter.Count()) 709cdf0e10cSrcweir { 710cdf0e10cSrcweir aStyles.push_back( xStyle ); 711cdf0e10cSrcweir } 712cdf0e10cSrcweir else 713cdf0e10cSrcweir { 714cdf0e10cSrcweir rIter[nPos]; 715cdf0e10cSrcweir aStyles.insert( aStyles.begin() + rIter.GetPos(), xStyle ); 716cdf0e10cSrcweir } 717cdf0e10cSrcweir Broadcast( SfxStyleSheetHint( SFX_STYLESHEET_CREATED, *xStyle.get() ) ); 718cdf0e10cSrcweir } 719cdf0e10cSrcweir return *xStyle.get(); 720cdf0e10cSrcweir } 721cdf0e10cSrcweir 722cdf0e10cSrcweir /////////////////////////////// Kopieren /////////////////////////////////// 723cdf0e10cSrcweir 724cdf0e10cSrcweir // Hilfsroutine: Falls eine Vorlage dieses Namens existiert, wird 725cdf0e10cSrcweir // sie neu erzeugt. Alle Vorlagen, die diese Vorlage zum Parent haben, 726cdf0e10cSrcweir // werden umgehaengt. 727cdf0e10cSrcweir 728cdf0e10cSrcweir SfxStyleSheetBase& SfxStyleSheetBasePool::Add( SfxStyleSheetBase& rSheet ) 729cdf0e10cSrcweir { 730cdf0e10cSrcweir SfxStyleSheetIterator aIter(this, rSheet.GetFamily(), nMask); 731cdf0e10cSrcweir SfxStyleSheetBase* pOld = aIter.Find( rSheet.GetName() ); 732cdf0e10cSrcweir Remove( pOld ); 733cdf0e10cSrcweir rtl::Reference< SfxStyleSheetBase > xNew( Create( rSheet ) ); 734cdf0e10cSrcweir aStyles.push_back( xNew ); 735cdf0e10cSrcweir Broadcast( SfxStyleSheetHint( SFX_STYLESHEET_CHANGED, *xNew.get() ) ); 736cdf0e10cSrcweir return *xNew.get(); 737cdf0e10cSrcweir } 738cdf0e10cSrcweir 739cdf0e10cSrcweir SfxStyleSheetBasePool& SfxStyleSheetBasePool::operator=( const SfxStyleSheetBasePool& r ) 740cdf0e10cSrcweir { 741cdf0e10cSrcweir if( &r != this ) 742cdf0e10cSrcweir { 743cdf0e10cSrcweir Clear(); 744cdf0e10cSrcweir *this += r; 745cdf0e10cSrcweir } 746cdf0e10cSrcweir return *this; 747cdf0e10cSrcweir } 748cdf0e10cSrcweir 749cdf0e10cSrcweir SfxStyleSheetBasePool& SfxStyleSheetBasePool::operator+=( const SfxStyleSheetBasePool& r ) 750cdf0e10cSrcweir { 751cdf0e10cSrcweir if( &r != this ) 752cdf0e10cSrcweir { 753cdf0e10cSrcweir SfxStyles::const_iterator aIter( r.aStyles.begin() ); 754cdf0e10cSrcweir while( aIter != r.aStyles.end() ) 755cdf0e10cSrcweir { 756cdf0e10cSrcweir Add(*(*aIter++).get()); 757cdf0e10cSrcweir } 758cdf0e10cSrcweir } 759cdf0e10cSrcweir return *this; 760cdf0e10cSrcweir } 761cdf0e10cSrcweir 762cdf0e10cSrcweir //////////////////////////////// Suchen //////////////////////////////////// 763cdf0e10cSrcweir 764cdf0e10cSrcweir sal_uInt16 SfxStyleSheetBasePool::Count() 765cdf0e10cSrcweir { 766cdf0e10cSrcweir return GetIterator_Impl().Count(); 767cdf0e10cSrcweir } 768cdf0e10cSrcweir 769cdf0e10cSrcweir SfxStyleSheetBase *SfxStyleSheetBasePool::operator[](sal_uInt16 nIdx) 770cdf0e10cSrcweir { 771cdf0e10cSrcweir return GetIterator_Impl()[nIdx]; 772cdf0e10cSrcweir } 773cdf0e10cSrcweir 774cdf0e10cSrcweir SfxStyleSheetBase* SfxStyleSheetBasePool::Find(const XubString& rName, 775cdf0e10cSrcweir SfxStyleFamily eFam, 776cdf0e10cSrcweir sal_uInt16 mask) 777cdf0e10cSrcweir { 778cdf0e10cSrcweir SfxStyleSheetIterator aIter(this,eFam,mask); 779cdf0e10cSrcweir return aIter.Find(rName); 780cdf0e10cSrcweir } 781cdf0e10cSrcweir 782cdf0e10cSrcweir const SfxStyles& SfxStyleSheetBasePool::GetStyles() 783cdf0e10cSrcweir { 784cdf0e10cSrcweir return aStyles; 785cdf0e10cSrcweir } 786cdf0e10cSrcweir 787cdf0e10cSrcweir SfxStyleSheetBase* SfxStyleSheetBasePool::First() 788cdf0e10cSrcweir { 789cdf0e10cSrcweir return GetIterator_Impl().First(); 790cdf0e10cSrcweir } 791cdf0e10cSrcweir 792cdf0e10cSrcweir SfxStyleSheetBase* SfxStyleSheetBasePool::Next() 793cdf0e10cSrcweir { 794cdf0e10cSrcweir return GetIterator_Impl().Next(); 795cdf0e10cSrcweir } 796cdf0e10cSrcweir 797cdf0e10cSrcweir //////////////////////////////// Loeschen ///////////////////////////////// 798cdf0e10cSrcweir 799cdf0e10cSrcweir void SfxStyleSheetBasePool::Remove( SfxStyleSheetBase* p ) 800cdf0e10cSrcweir { 801cdf0e10cSrcweir if( p ) 802cdf0e10cSrcweir { 803cdf0e10cSrcweir SfxStyles::iterator aIter( std::find( aStyles.begin(), aStyles.end(), rtl::Reference< SfxStyleSheetBase >( p ) ) ); 804cdf0e10cSrcweir if( aIter != aStyles.end() ) 805cdf0e10cSrcweir { 806cdf0e10cSrcweir // Alle Styles umsetzen, deren Parent dieser hier ist 807cdf0e10cSrcweir ChangeParent( p->GetName(), p->GetParent() ); 808cdf0e10cSrcweir 809*6b46875cSArmin Le Grand // #120015# Do not dispose, the removed StyleSheet may still be used in 810*6b46875cSArmin Le Grand // existing SdrUndoAttrObj incarnations. Rely on refcounting for disposal, 811*6b46875cSArmin Le Grand // this works well under normal conditions (checked breaking and counting 812*6b46875cSArmin Le Grand // on SfxStyleSheetBase constructors and destructors) 813*6b46875cSArmin Le Grand // 814*6b46875cSArmin Le Grand // com::sun::star::uno::Reference< com::sun::star::lang::XComponent > xComp( static_cast< ::cppu::OWeakObject* >((*aIter).get()), com::sun::star::uno::UNO_QUERY ); 815*6b46875cSArmin Le Grand // if( xComp.is() ) try 816*6b46875cSArmin Le Grand // { 817*6b46875cSArmin Le Grand // xComp->dispose(); 818*6b46875cSArmin Le Grand // } 819*6b46875cSArmin Le Grand // catch( com::sun::star::uno::Exception& ) 820*6b46875cSArmin Le Grand // { 821*6b46875cSArmin Le Grand // } 822cdf0e10cSrcweir 823cdf0e10cSrcweir aStyles.erase(aIter); 824cdf0e10cSrcweir Broadcast( SfxStyleSheetHint( SFX_STYLESHEET_ERASED, *p ) ); 825cdf0e10cSrcweir } 826cdf0e10cSrcweir } 827cdf0e10cSrcweir } 828cdf0e10cSrcweir 829cdf0e10cSrcweir void SfxStyleSheetBasePool::Insert( SfxStyleSheetBase* p ) 830cdf0e10cSrcweir { 831cdf0e10cSrcweir DBG_ASSERT( p, "svl::SfxStyleSheetBasePool::Insert(), no stylesheet?" ); 832cdf0e10cSrcweir 833cdf0e10cSrcweir SfxStyleSheetIterator aIter(this, p->GetFamily(), p->GetMask()); 834cdf0e10cSrcweir SfxStyleSheetBase* pOld = aIter.Find( p->GetName() ); 835cdf0e10cSrcweir DBG_ASSERT( !pOld, "svl::SfxStyleSheetBasePool::Insert(), StyleSheet already inserted" ); 836cdf0e10cSrcweir if( p->GetParent().Len() ) 837cdf0e10cSrcweir { 838cdf0e10cSrcweir pOld = aIter.Find( p->GetParent() ); 839cdf0e10cSrcweir DBG_ASSERT( pOld, "svl::SfxStyleSheetBasePool::Insert(), Parent not found!" ); 840cdf0e10cSrcweir } 841cdf0e10cSrcweir aStyles.push_back( rtl::Reference< SfxStyleSheetBase >( p ) ); 842cdf0e10cSrcweir Broadcast( SfxStyleSheetHint( SFX_STYLESHEET_CREATED, *p ) ); 843cdf0e10cSrcweir } 844cdf0e10cSrcweir 845cdf0e10cSrcweir void SfxStyleSheetBasePool::Clear() 846cdf0e10cSrcweir { 847cdf0e10cSrcweir SfxStyles aClearStyles; 848cdf0e10cSrcweir aClearStyles.swap( aStyles ); 849cdf0e10cSrcweir 850cdf0e10cSrcweir SfxStyles::iterator aIter( aClearStyles.begin() ); 851cdf0e10cSrcweir while( aIter != aClearStyles.end() ) 852cdf0e10cSrcweir { 853cdf0e10cSrcweir com::sun::star::uno::Reference< com::sun::star::lang::XComponent > xComp( static_cast< ::cppu::OWeakObject* >((*aIter).get()), com::sun::star::uno::UNO_QUERY ); 854cdf0e10cSrcweir if( xComp.is() ) try 855cdf0e10cSrcweir { 856cdf0e10cSrcweir xComp->dispose(); 857cdf0e10cSrcweir } 858cdf0e10cSrcweir catch( com::sun::star::uno::Exception& ) 859cdf0e10cSrcweir { 860cdf0e10cSrcweir } 861cdf0e10cSrcweir 862cdf0e10cSrcweir Broadcast( SfxStyleSheetHint( SFX_STYLESHEET_ERASED, *(*aIter++).get() ) ); 863cdf0e10cSrcweir } 864cdf0e10cSrcweir } 865cdf0e10cSrcweir 866cdf0e10cSrcweir /////////////////////////// Parents umsetzen //////////////////////////////// 867cdf0e10cSrcweir 868cdf0e10cSrcweir void SfxStyleSheetBasePool::ChangeParent(const XubString& rOld, 869cdf0e10cSrcweir const XubString& rNew, 870cdf0e10cSrcweir sal_Bool bVirtual) 871cdf0e10cSrcweir { 872cdf0e10cSrcweir const sal_uInt16 nTmpMask = GetSearchMask(); 873cdf0e10cSrcweir SetSearchMask(GetSearchFamily(), 0xffff); 874cdf0e10cSrcweir for( SfxStyleSheetBase* p = First(); p; p = Next() ) 875cdf0e10cSrcweir { 876cdf0e10cSrcweir if( p->GetParent().Equals( rOld ) ) 877cdf0e10cSrcweir { 878cdf0e10cSrcweir if(bVirtual) 879cdf0e10cSrcweir p->SetParent( rNew ); 880cdf0e10cSrcweir else 881cdf0e10cSrcweir p->aParent = rNew; 882cdf0e10cSrcweir } 883cdf0e10cSrcweir } 884cdf0e10cSrcweir SetSearchMask(GetSearchFamily(), nTmpMask); 885cdf0e10cSrcweir } 886cdf0e10cSrcweir 887cdf0e10cSrcweir /////////////////////////// Laden/Speichern ///////////////////////////////// 888cdf0e10cSrcweir 889cdf0e10cSrcweir void SfxStyleSheetBase::Load( SvStream&, sal_uInt16 ) 890cdf0e10cSrcweir { 891cdf0e10cSrcweir } 892cdf0e10cSrcweir 893cdf0e10cSrcweir void SfxStyleSheetBase::Store( SvStream& ) 894cdf0e10cSrcweir { 895cdf0e10cSrcweir } 896cdf0e10cSrcweir 897cdf0e10cSrcweir 898cdf0e10cSrcweir sal_Bool SfxStyleSheetBasePool::Load( SvStream& rStream ) 899cdf0e10cSrcweir { 900cdf0e10cSrcweir // alte Version? 901cdf0e10cSrcweir if ( !rPool.IsVer2_Impl() ) 902cdf0e10cSrcweir return Load1_Impl( rStream ); 903cdf0e10cSrcweir 904cdf0e10cSrcweir // gesamten StyleSheetPool in neuer Version aus einem MiniRecord lesen 905cdf0e10cSrcweir SfxMiniRecordReader aPoolRec( &rStream, SFX_STYLES_REC ); 906cdf0e10cSrcweir 907cdf0e10cSrcweir // Header-Record lesen 908cdf0e10cSrcweir short nCharSet = 0; 909cdf0e10cSrcweir if ( !rStream.GetError() ) 910cdf0e10cSrcweir { 911cdf0e10cSrcweir SfxSingleRecordReader aHeaderRec( &rStream, SFX_STYLES_REC_HEADER ); 912cdf0e10cSrcweir if ( !aHeaderRec.IsValid() ) 913cdf0e10cSrcweir return sal_False; 914cdf0e10cSrcweir 915cdf0e10cSrcweir aAppName = rPool.GetName(); 916cdf0e10cSrcweir rStream >> nCharSet; 917cdf0e10cSrcweir } 918cdf0e10cSrcweir 919cdf0e10cSrcweir // Styles-Record lesen 920cdf0e10cSrcweir if ( !rStream.GetError() ) 921cdf0e10cSrcweir { 922cdf0e10cSrcweir SfxMultiRecordReader aStylesRec( &rStream, SFX_STYLES_REC_STYLES ); 923cdf0e10cSrcweir if ( !aStylesRec.IsValid() ) 924cdf0e10cSrcweir return sal_False; 925cdf0e10cSrcweir 926cdf0e10cSrcweir rtl_TextEncoding eEnc = GetSOLoadTextEncoding( 927cdf0e10cSrcweir (rtl_TextEncoding)nCharSet, 928cdf0e10cSrcweir sal::static_int_cast< sal_uInt16 >(rStream.GetVersion()) ); 929cdf0e10cSrcweir rtl_TextEncoding eOldEnc = rStream.GetStreamCharSet(); 930cdf0e10cSrcweir rStream.SetStreamCharSet( eEnc ); 931cdf0e10cSrcweir 932cdf0e10cSrcweir sal_uInt16 nStyles; 933cdf0e10cSrcweir for ( nStyles = 0; aStylesRec.GetContent(); nStyles++ ) 934cdf0e10cSrcweir { 935cdf0e10cSrcweir // kann nicht mehr weiterlesen? 936cdf0e10cSrcweir if ( rStream.GetError() ) 937cdf0e10cSrcweir break; 938cdf0e10cSrcweir 939cdf0e10cSrcweir // Globale Teile 940cdf0e10cSrcweir XubString aName, aParent, aFollow; 941cdf0e10cSrcweir String aHelpFile; 942cdf0e10cSrcweir sal_uInt16 nFamily, nStyleMask,nCount; 943cdf0e10cSrcweir sal_uInt32 nHelpId; 944cdf0e10cSrcweir rStream.ReadByteString(aName, eEnc ); 945cdf0e10cSrcweir rStream.ReadByteString(aParent, eEnc ); 946cdf0e10cSrcweir rStream.ReadByteString(aFollow, eEnc ); 947cdf0e10cSrcweir rStream >> nFamily >> nStyleMask; 948cdf0e10cSrcweir SfxPoolItem::readByteString(rStream, aHelpFile); 949cdf0e10cSrcweir rStream >> nHelpId; 950cdf0e10cSrcweir 951cdf0e10cSrcweir SfxStyleSheetBase& rSheet = Make( aName, (SfxStyleFamily)nFamily , nStyleMask); 952cdf0e10cSrcweir rSheet.SetHelpId( aHelpFile, nHelpId ); 953cdf0e10cSrcweir // Hier erst einmal Parent und Follow zwischenspeichern 954cdf0e10cSrcweir rSheet.aParent = aParent; 955cdf0e10cSrcweir rSheet.aFollow = aFollow; 956cdf0e10cSrcweir sal_uInt32 nPos = rStream.Tell(); 957cdf0e10cSrcweir rStream >> nCount; 958cdf0e10cSrcweir if(nCount) 959cdf0e10cSrcweir { 960cdf0e10cSrcweir rStream.Seek( nPos ); 961cdf0e10cSrcweir // Das Laden des ItemSets bedient sich der Methode GetItemSet(), 962cdf0e10cSrcweir // damit eigene ItemSets untergeschoben werden koennen 963cdf0e10cSrcweir SfxItemSet& rSet = rSheet.GetItemSet(); 964cdf0e10cSrcweir rSet.ClearItem(); 965cdf0e10cSrcweir //! SfxItemSet aTmpSet( *pTmpPool ); 966cdf0e10cSrcweir /*!aTmpSet*/ rSet.Load( rStream ); 967cdf0e10cSrcweir //! rSet.Put( aTmpSet ); 968cdf0e10cSrcweir } 969cdf0e10cSrcweir // Lokale Teile 970cdf0e10cSrcweir sal_uInt32 nSize; 971cdf0e10cSrcweir sal_uInt16 nVer; 972cdf0e10cSrcweir rStream >> nVer >> nSize; 973cdf0e10cSrcweir nPos = rStream.Tell() + nSize; 974cdf0e10cSrcweir rSheet.Load( rStream, nVer ); 975cdf0e10cSrcweir rStream.Seek( nPos ); 976cdf0e10cSrcweir } 977cdf0e10cSrcweir 978cdf0e10cSrcweir // #72939# only loop through the styles that were really inserted 979cdf0e10cSrcweir sal_uLong n = aStyles.size(); 980cdf0e10cSrcweir 981cdf0e10cSrcweir //! delete pTmpPool; 982cdf0e10cSrcweir // Jetzt Parent und Follow setzen. Alle Sheets sind geladen. 983cdf0e10cSrcweir // Mit Setxxx() noch einmal den String eintragen, da diese 984cdf0e10cSrcweir // virtuellen Methoden evtl. ueberlagert sind. 985cdf0e10cSrcweir for ( sal_uLong i = 0; i < n; i++ ) 986cdf0e10cSrcweir { 987cdf0e10cSrcweir SfxStyleSheetBase* p = aStyles[ i ].get(); 988cdf0e10cSrcweir XubString aText = p->aParent; 989cdf0e10cSrcweir p->aParent.Erase(); 990cdf0e10cSrcweir p->SetParent( aText ); 991cdf0e10cSrcweir aText = p->aFollow; 992cdf0e10cSrcweir p->aFollow.Erase(); 993cdf0e10cSrcweir p->SetFollow( aText ); 994cdf0e10cSrcweir } 995cdf0e10cSrcweir 996cdf0e10cSrcweir rStream.SetStreamCharSet( eOldEnc ); 997cdf0e10cSrcweir } 998cdf0e10cSrcweir 999cdf0e10cSrcweir // alles klar? 1000cdf0e10cSrcweir return sal_Bool( rStream.GetError() == SVSTREAM_OK ); 1001cdf0e10cSrcweir } 1002cdf0e10cSrcweir 1003cdf0e10cSrcweir sal_Bool SfxStyleSheetBasePool::Load1_Impl( SvStream& rStream ) 1004cdf0e10cSrcweir { 1005cdf0e10cSrcweir aAppName = rPool.GetName(); 1006cdf0e10cSrcweir sal_uInt16 nVersion; 1007cdf0e10cSrcweir short nCharSet; 1008cdf0e10cSrcweir rStream >> nVersion; 1009cdf0e10cSrcweir 1010cdf0e10cSrcweir if(nVersion!=STYLESTREAM_VERSION) 1011cdf0e10cSrcweir nCharSet=nVersion; 1012cdf0e10cSrcweir else 1013cdf0e10cSrcweir rStream >> nCharSet; 1014cdf0e10cSrcweir 1015cdf0e10cSrcweir rtl_TextEncoding eEnc = GetSOLoadTextEncoding( 1016cdf0e10cSrcweir (rtl_TextEncoding)nCharSet, 1017cdf0e10cSrcweir sal::static_int_cast< sal_uInt16 >(rStream.GetVersion()) ); 1018cdf0e10cSrcweir rtl_TextEncoding eOldEnc = rStream.GetStreamCharSet(); 1019cdf0e10cSrcweir rStream.SetStreamCharSet( eEnc ); 1020cdf0e10cSrcweir 1021cdf0e10cSrcweir sal_uInt16 nStyles; 1022cdf0e10cSrcweir rStream >> nStyles; 1023cdf0e10cSrcweir sal_uInt16 i; 1024cdf0e10cSrcweir for ( i = 0; i < nStyles; i++ ) 1025cdf0e10cSrcweir { 1026cdf0e10cSrcweir // kann nicht mehr weiterlesen? 1027cdf0e10cSrcweir if ( rStream.GetError() ) 1028cdf0e10cSrcweir { 1029cdf0e10cSrcweir nStyles = i; 1030cdf0e10cSrcweir break; 1031cdf0e10cSrcweir } 1032cdf0e10cSrcweir 1033cdf0e10cSrcweir // Globale Teile 1034cdf0e10cSrcweir XubString aName, aParent, aFollow; 1035cdf0e10cSrcweir String aHelpFile; 1036cdf0e10cSrcweir sal_uInt16 nFamily, nStyleMask,nCount; 1037cdf0e10cSrcweir sal_uInt32 nHelpId; 1038cdf0e10cSrcweir rStream.ReadByteString(aName, eEnc ); 1039cdf0e10cSrcweir rStream.ReadByteString(aParent, eEnc ); 1040cdf0e10cSrcweir rStream.ReadByteString(aFollow, eEnc ); 1041cdf0e10cSrcweir rStream >> nFamily >> nStyleMask; 1042cdf0e10cSrcweir SfxPoolItem::readByteString(rStream, aHelpFile); 1043cdf0e10cSrcweir if(nVersion!=STYLESTREAM_VERSION) 1044cdf0e10cSrcweir { 1045cdf0e10cSrcweir sal_uInt16 nTmpHelpId; 1046cdf0e10cSrcweir rStream >> nTmpHelpId; 1047cdf0e10cSrcweir nHelpId=nTmpHelpId; 1048cdf0e10cSrcweir } 1049cdf0e10cSrcweir else 1050cdf0e10cSrcweir rStream >> nHelpId; 1051cdf0e10cSrcweir 1052cdf0e10cSrcweir SfxStyleSheetBase& rSheet = Make( aName, (SfxStyleFamily)nFamily , nStyleMask); 1053cdf0e10cSrcweir rSheet.SetHelpId( aHelpFile, nHelpId ); 1054cdf0e10cSrcweir // Hier erst einmal Parent und Follow zwischenspeichern 1055cdf0e10cSrcweir rSheet.aParent = aParent; 1056cdf0e10cSrcweir rSheet.aFollow = aFollow; 1057cdf0e10cSrcweir sal_uInt32 nPos = rStream.Tell(); 1058cdf0e10cSrcweir rStream >> nCount; 1059cdf0e10cSrcweir if(nCount) { 1060cdf0e10cSrcweir rStream.Seek( nPos ); 1061cdf0e10cSrcweir // Das Laden des ItemSets bedient sich der Methode GetItemSet(), 1062cdf0e10cSrcweir // damit eigene ItemSets untergeschoben werden koennen 1063cdf0e10cSrcweir SfxItemSet& rSet = rSheet.GetItemSet(); 1064cdf0e10cSrcweir rSet.ClearItem(); 1065cdf0e10cSrcweir //! SfxItemSet aTmpSet( *pTmpPool ); 1066cdf0e10cSrcweir /*!aTmpSet*/ rSet.Load( rStream ); 1067cdf0e10cSrcweir //! rSet.Put( aTmpSet ); 1068cdf0e10cSrcweir } 1069cdf0e10cSrcweir // Lokale Teile 1070cdf0e10cSrcweir sal_uInt32 nSize; 1071cdf0e10cSrcweir sal_uInt16 nVer; 1072cdf0e10cSrcweir rStream >> nVer >> nSize; 1073cdf0e10cSrcweir nPos = rStream.Tell() + nSize; 1074cdf0e10cSrcweir rSheet.Load( rStream, nVer ); 1075cdf0e10cSrcweir rStream.Seek( nPos ); 1076cdf0e10cSrcweir } 1077cdf0e10cSrcweir 1078cdf0e10cSrcweir //! delete pTmpPool; 1079cdf0e10cSrcweir // Jetzt Parent und Follow setzen. Alle Sheets sind geladen. 1080cdf0e10cSrcweir // Mit Setxxx() noch einmal den String eintragen, da diese 1081cdf0e10cSrcweir // virtuellen Methoden evtl. ueberlagert sind. 1082cdf0e10cSrcweir for ( i = 0; i < nStyles; i++ ) 1083cdf0e10cSrcweir { 1084cdf0e10cSrcweir SfxStyleSheetBase* p = aStyles[ i ].get(); 1085cdf0e10cSrcweir XubString aText = p->aParent; 1086cdf0e10cSrcweir p->aParent.Erase(); 1087cdf0e10cSrcweir p->SetParent( aText ); 1088cdf0e10cSrcweir aText = p->aFollow; 1089cdf0e10cSrcweir p->aFollow.Erase(); 1090cdf0e10cSrcweir p->SetFollow( aText ); 1091cdf0e10cSrcweir } 1092cdf0e10cSrcweir 1093cdf0e10cSrcweir rStream.SetStreamCharSet( eOldEnc ); 1094cdf0e10cSrcweir 1095cdf0e10cSrcweir return sal_Bool( rStream.GetError() == SVSTREAM_OK ); 1096cdf0e10cSrcweir } 1097cdf0e10cSrcweir 1098cdf0e10cSrcweir sal_Bool SfxStyleSheetBasePool::Store( SvStream& rStream, sal_Bool bUsed ) 1099cdf0e10cSrcweir { 1100cdf0e10cSrcweir // den ganzen StyleSheet-Pool in einen Mini-Record 1101cdf0e10cSrcweir SfxMiniRecordWriter aPoolRec( &rStream, SFX_STYLES_REC ); 1102cdf0e10cSrcweir 1103cdf0e10cSrcweir // Erst einmal die Dummies rauszaehlen; die werden nicht gespeichert 1104cdf0e10cSrcweir sal_uInt16 nCount = 0; 1105cdf0e10cSrcweir for( SfxStyleSheetBase* p = First(); p; p = Next() ) 1106cdf0e10cSrcweir { 1107cdf0e10cSrcweir if(!bUsed || p->IsUsed()) 1108cdf0e10cSrcweir nCount++; 1109cdf0e10cSrcweir } 1110cdf0e10cSrcweir 1111cdf0e10cSrcweir // einen Header-Record vorweg 1112cdf0e10cSrcweir rtl_TextEncoding eEnc 1113cdf0e10cSrcweir = ::GetSOStoreTextEncoding( 1114cdf0e10cSrcweir rStream.GetStreamCharSet(), 1115cdf0e10cSrcweir sal::static_int_cast< sal_uInt16 >(rStream.GetVersion()) ); 1116cdf0e10cSrcweir rtl_TextEncoding eOldEnc = rStream.GetStreamCharSet(); 1117cdf0e10cSrcweir rStream.SetStreamCharSet( eEnc ); 1118cdf0e10cSrcweir 1119cdf0e10cSrcweir { 1120cdf0e10cSrcweir SfxSingleRecordWriter aHeaderRec( &rStream, 1121cdf0e10cSrcweir SFX_STYLES_REC_HEADER, 1122cdf0e10cSrcweir STYLESTREAM_VERSION ); 1123cdf0e10cSrcweir rStream << (short) eEnc; 1124cdf0e10cSrcweir } 1125cdf0e10cSrcweir 1126cdf0e10cSrcweir // die StyleSheets in einen MultiVarRecord 1127cdf0e10cSrcweir { 1128cdf0e10cSrcweir // Bug 79478: 1129cdf0e10cSrcweir // make a check loop, to be shure, that the converted names are also 1130cdf0e10cSrcweir // unique like the originals! In other cases we get a loop. 1131cdf0e10cSrcweir SvStringsSortDtor aSortOrigNames( 0, 128 ); 1132cdf0e10cSrcweir SvStrings aOrigNames( 0, 128 ); 1133cdf0e10cSrcweir SvByteStringsSortDtor aSortConvNames( 0, 128 ); 1134cdf0e10cSrcweir SvByteStrings aConvNames( 0, 128 ); 1135cdf0e10cSrcweir 1136cdf0e10cSrcweir { 1137cdf0e10cSrcweir 1138cdf0e10cSrcweir for( SfxStyleSheetBase* p = First(); p; p = Next() ) 1139cdf0e10cSrcweir { 1140cdf0e10cSrcweir if(!bUsed || p->IsUsed()) 1141cdf0e10cSrcweir { 1142cdf0e10cSrcweir sal_uInt16 nFamily = (sal_uInt16)p->GetFamily(); 1143cdf0e10cSrcweir String* pName = new String( p->GetName() ); 1144cdf0e10cSrcweir ByteString* pConvName = new ByteString( *pName, eEnc ); 1145cdf0e10cSrcweir 1146cdf0e10cSrcweir pName->Insert( (sal_Unicode)nFamily, 0 ); 1147cdf0e10cSrcweir pConvName->Insert( " ", 0 ); 1148cdf0e10cSrcweir pConvName->SetChar( 1149cdf0e10cSrcweir 0, 1150cdf0e10cSrcweir sal::static_int_cast< char >(0xff & (nFamily >> 8)) ); 1151cdf0e10cSrcweir pConvName->SetChar( 1152cdf0e10cSrcweir 1, sal::static_int_cast< char >(0xff & nFamily) ); 1153cdf0e10cSrcweir 1154cdf0e10cSrcweir sal_uInt16 nInsPos, nAdd = aSortConvNames.Count(); 1155cdf0e10cSrcweir while( !aSortConvNames.Insert( pConvName, nInsPos ) ) 1156cdf0e10cSrcweir (pConvName->Append( '_' )).Append( 1157cdf0e10cSrcweir ByteString::CreateFromInt32( nAdd++ )); 1158cdf0e10cSrcweir aOrigNames.Insert( pName, nInsPos ); 1159cdf0e10cSrcweir } 1160cdf0e10cSrcweir } 1161cdf0e10cSrcweir 1162cdf0e10cSrcweir // now we have the list of the names, sorted by convertede names 1163cdf0e10cSrcweir // But now we need the sorted list of orignames. 1164cdf0e10cSrcweir { 1165cdf0e10cSrcweir sal_uInt16 nInsPos, nEnd = aOrigNames.Count(); 1166cdf0e10cSrcweir const ByteStringPtr* ppB = aSortConvNames.GetData(); 1167cdf0e10cSrcweir for( sal_uInt16 n = 0; n < nEnd; ++n, ++ppB ) 1168cdf0e10cSrcweir { 1169cdf0e10cSrcweir String* p = aOrigNames.GetObject( n ); 1170cdf0e10cSrcweir aSortOrigNames.Insert( p, nInsPos ); 1171cdf0e10cSrcweir aConvNames.Insert( *ppB, nInsPos ); 1172cdf0e10cSrcweir } 1173cdf0e10cSrcweir 1174cdf0e10cSrcweir } 1175cdf0e10cSrcweir } 1176cdf0e10cSrcweir 1177cdf0e10cSrcweir 1178cdf0e10cSrcweir ByteString sEmpty; 1179cdf0e10cSrcweir sal_uInt16 nFndPos; 1180cdf0e10cSrcweir String sNm; 1181cdf0e10cSrcweir SfxMultiVarRecordWriter aStylesRec( &rStream, SFX_STYLES_REC_STYLES, 0 ); 1182cdf0e10cSrcweir for( SfxStyleSheetBase* p = First(); p; p = Next() ) 1183cdf0e10cSrcweir { 1184cdf0e10cSrcweir if(!bUsed || p->IsUsed()) 1185cdf0e10cSrcweir { 1186cdf0e10cSrcweir aStylesRec.NewContent(); 1187cdf0e10cSrcweir 1188cdf0e10cSrcweir // Globale Teile speichern 1189cdf0e10cSrcweir String aHelpFile; 1190cdf0e10cSrcweir sal_uInt32 nHelpId = p->GetHelpId( aHelpFile ); 1191cdf0e10cSrcweir sal_uInt16 nFamily = sal::static_int_cast< sal_uInt16 >(p->GetFamily()); 1192cdf0e10cSrcweir String sFamily( (sal_Unicode)nFamily ); 1193cdf0e10cSrcweir 1194cdf0e10cSrcweir (sNm = sFamily) += p->GetName(); 1195cdf0e10cSrcweir if( aSortOrigNames.Seek_Entry( &sNm, &nFndPos )) 1196cdf0e10cSrcweir rStream.WriteByteString( aConvNames.GetObject( nFndPos )->Copy( 2 )); 1197cdf0e10cSrcweir else 1198cdf0e10cSrcweir rStream.WriteByteString( sEmpty ); 1199cdf0e10cSrcweir 1200cdf0e10cSrcweir (sNm = sFamily) += p->GetParent(); 1201cdf0e10cSrcweir if( aSortOrigNames.Seek_Entry( &sNm, &nFndPos )) 1202cdf0e10cSrcweir rStream.WriteByteString( aConvNames.GetObject( nFndPos )->Copy( 2 )); 1203cdf0e10cSrcweir else 1204cdf0e10cSrcweir rStream.WriteByteString( sEmpty ); 1205cdf0e10cSrcweir 1206cdf0e10cSrcweir (sNm = sFamily) += p->GetFollow(); 1207cdf0e10cSrcweir if( aSortOrigNames.Seek_Entry( &sNm, &nFndPos )) 1208cdf0e10cSrcweir rStream.WriteByteString( aConvNames.GetObject( nFndPos )->Copy( 2 )); 1209cdf0e10cSrcweir else 1210cdf0e10cSrcweir rStream.WriteByteString( sEmpty ); 1211cdf0e10cSrcweir 1212cdf0e10cSrcweir rStream << nFamily << p->GetMask(); 1213cdf0e10cSrcweir SfxPoolItem::writeByteString(rStream, aHelpFile); 1214cdf0e10cSrcweir rStream << nHelpId; 1215cdf0e10cSrcweir if(p->pSet) 1216cdf0e10cSrcweir p->pSet->Store( rStream ); 1217cdf0e10cSrcweir else 1218cdf0e10cSrcweir rStream << (sal_uInt16)0; 1219cdf0e10cSrcweir 1220cdf0e10cSrcweir // Lokale Teile speichern 1221cdf0e10cSrcweir // Vor dem lokalen Teil wird die Laenge der lokalen Daten 1222cdf0e10cSrcweir // als sal_uInt32 sowie die Versionsnummer gespeichert. 1223cdf0e10cSrcweir rStream << (sal_uInt16) p->GetVersion(); 1224cdf0e10cSrcweir sal_uLong nPos1 = rStream.Tell(); 1225cdf0e10cSrcweir rStream << (sal_uInt32) 0; 1226cdf0e10cSrcweir p->Store( rStream ); 1227cdf0e10cSrcweir sal_uLong nPos2 = rStream.Tell(); 1228cdf0e10cSrcweir rStream.Seek( nPos1 ); 1229cdf0e10cSrcweir rStream << (sal_uInt32) ( nPos2 - nPos1 - sizeof( sal_uInt32 ) ); 1230cdf0e10cSrcweir rStream.Seek( nPos2 ); 1231cdf0e10cSrcweir if( rStream.GetError() != SVSTREAM_OK ) 1232cdf0e10cSrcweir break; 1233cdf0e10cSrcweir } 1234cdf0e10cSrcweir } 1235cdf0e10cSrcweir } 1236cdf0e10cSrcweir 1237cdf0e10cSrcweir rStream.SetStreamCharSet( eOldEnc ); 1238cdf0e10cSrcweir 1239cdf0e10cSrcweir return sal_Bool( rStream.GetError() == SVSTREAM_OK ); 1240cdf0e10cSrcweir } 1241cdf0e10cSrcweir 1242cdf0e10cSrcweir SfxItemPool& SfxStyleSheetBasePool::GetPool() 1243cdf0e10cSrcweir { 1244cdf0e10cSrcweir return rPool; 1245cdf0e10cSrcweir } 1246cdf0e10cSrcweir 1247cdf0e10cSrcweir const SfxItemPool& SfxStyleSheetBasePool::GetPool() const 1248cdf0e10cSrcweir { 1249cdf0e10cSrcweir return rPool; 1250cdf0e10cSrcweir } 1251cdf0e10cSrcweir 1252cdf0e10cSrcweir /////////////////////// SfxStyleSheet ///////////////////////////////// 1253cdf0e10cSrcweir 1254cdf0e10cSrcweir SfxStyleSheet::SfxStyleSheet(const XubString &rName, 1255cdf0e10cSrcweir const SfxStyleSheetBasePool& r_Pool, 1256cdf0e10cSrcweir SfxStyleFamily eFam, 1257cdf0e10cSrcweir sal_uInt16 mask ): 1258cdf0e10cSrcweir SfxStyleSheetBase(rName, const_cast< SfxStyleSheetBasePool& >( r_Pool ), eFam, mask) 1259cdf0e10cSrcweir {} 1260cdf0e10cSrcweir 1261cdf0e10cSrcweir SfxStyleSheet::SfxStyleSheet(const SfxStyleSheet& rStyle) : 1262cdf0e10cSrcweir SfxStyleSheetBase(rStyle), 1263cdf0e10cSrcweir SfxListener( rStyle ), 1264cdf0e10cSrcweir SfxBroadcaster( rStyle ) 1265cdf0e10cSrcweir {} 1266cdf0e10cSrcweir 1267cdf0e10cSrcweir SfxStyleSheet::SfxStyleSheet() 1268cdf0e10cSrcweir { 1269cdf0e10cSrcweir } 1270cdf0e10cSrcweir 1271cdf0e10cSrcweir SfxStyleSheet::~SfxStyleSheet() 1272cdf0e10cSrcweir { 1273cdf0e10cSrcweir Broadcast( SfxStyleSheetHint( SFX_STYLESHEET_INDESTRUCTION, *this ) ); 1274cdf0e10cSrcweir } 1275cdf0e10cSrcweir 1276cdf0e10cSrcweir 1277cdf0e10cSrcweir sal_Bool SfxStyleSheet::SetParent( const XubString& rName ) 1278cdf0e10cSrcweir { 1279cdf0e10cSrcweir if(aParent == rName) 1280cdf0e10cSrcweir return sal_True; 1281cdf0e10cSrcweir const XubString aOldParent(aParent); 1282cdf0e10cSrcweir if(SfxStyleSheetBase::SetParent(rName)) { 1283cdf0e10cSrcweir // aus der Benachrichtigungskette des alten 1284cdf0e10cSrcweir // Parents gfs. austragen 1285cdf0e10cSrcweir if(aOldParent.Len()) { 1286cdf0e10cSrcweir SfxStyleSheet *pParent = (SfxStyleSheet *)rPool.Find(aOldParent, nFamily, 0xffff); 1287cdf0e10cSrcweir if(pParent) 1288cdf0e10cSrcweir EndListening(*pParent); 1289cdf0e10cSrcweir } 1290cdf0e10cSrcweir // in die Benachrichtigungskette des neuen 1291cdf0e10cSrcweir // Parents eintragen 1292cdf0e10cSrcweir if(aParent.Len()) { 1293cdf0e10cSrcweir SfxStyleSheet *pParent = (SfxStyleSheet *)rPool.Find(aParent, nFamily, 0xffff); 1294cdf0e10cSrcweir if(pParent) 1295cdf0e10cSrcweir StartListening(*pParent); 1296cdf0e10cSrcweir } 1297cdf0e10cSrcweir return sal_True; 1298cdf0e10cSrcweir } 1299cdf0e10cSrcweir return sal_False; 1300cdf0e10cSrcweir } 1301cdf0e10cSrcweir 1302cdf0e10cSrcweir // alle Zuhoerer benachtichtigen 1303cdf0e10cSrcweir 1304cdf0e10cSrcweir void SfxStyleSheet::Notify(SfxBroadcaster& rBC, const SfxHint& rHint ) 1305cdf0e10cSrcweir { 1306cdf0e10cSrcweir Forward(rBC, rHint); 1307cdf0e10cSrcweir } 1308cdf0e10cSrcweir 1309cdf0e10cSrcweir //////////////////////// SfxStyleSheetPool /////////////////////////////// 1310cdf0e10cSrcweir 1311cdf0e10cSrcweir SfxStyleSheetPool::SfxStyleSheetPool( SfxItemPool const& rSet) 1312cdf0e10cSrcweir : SfxStyleSheetBasePool( const_cast< SfxItemPool& >( rSet ) ) 1313cdf0e10cSrcweir { 1314cdf0e10cSrcweir } 1315cdf0e10cSrcweir 1316cdf0e10cSrcweir /////////////////////////////////// Factory //////////////////////////////// 1317cdf0e10cSrcweir 1318cdf0e10cSrcweir SfxStyleSheetBase* SfxStyleSheetPool::Create( const XubString& rName, 1319cdf0e10cSrcweir SfxStyleFamily eFam, sal_uInt16 mask ) 1320cdf0e10cSrcweir { 1321cdf0e10cSrcweir return new SfxStyleSheet( rName, *this, eFam, mask ); 1322cdf0e10cSrcweir } 1323cdf0e10cSrcweir 1324cdf0e10cSrcweir SfxStyleSheetBase* SfxStyleSheetPool::Create( const SfxStyleSheet& r ) 1325cdf0e10cSrcweir { 1326cdf0e10cSrcweir return new SfxStyleSheet( r ); 1327cdf0e10cSrcweir } 1328cdf0e10cSrcweir /* 1329cdf0e10cSrcweir sal_Bool SfxStyleSheetPool::CopyTo(SfxStyleSheetPool &, const String &) 1330cdf0e10cSrcweir { 1331cdf0e10cSrcweir return sal_False; 1332cdf0e10cSrcweir } 1333cdf0e10cSrcweir */ 1334cdf0e10cSrcweir 1335cdf0e10cSrcweir // -------------------------------------------------------------------- 1336cdf0e10cSrcweir // class SfxUnoStyleSheet 1337cdf0e10cSrcweir // -------------------------------------------------------------------- 1338cdf0e10cSrcweir 1339cdf0e10cSrcweir SfxUnoStyleSheet::SfxUnoStyleSheet( const UniString& _rName, const SfxStyleSheetBasePool& _rPool, SfxStyleFamily _eFamily, sal_uInt16 _nMaske ) 1340cdf0e10cSrcweir : ::cppu::ImplInheritanceHelper2< SfxStyleSheet, ::com::sun::star::style::XStyle, ::com::sun::star::lang::XUnoTunnel >( _rName, _rPool, _eFamily, _nMaske ) 1341cdf0e10cSrcweir { 1342cdf0e10cSrcweir } 1343cdf0e10cSrcweir 1344cdf0e10cSrcweir // -------------------------------------------------------------------- 1345cdf0e10cSrcweir SfxUnoStyleSheet::SfxUnoStyleSheet( const SfxStyleSheet& _rSheet ) 1346cdf0e10cSrcweir : ::cppu::ImplInheritanceHelper2< SfxStyleSheet, ::com::sun::star::style::XStyle, ::com::sun::star::lang::XUnoTunnel >( _rSheet ) 1347cdf0e10cSrcweir { 1348cdf0e10cSrcweir } 1349cdf0e10cSrcweir 1350cdf0e10cSrcweir // -------------------------------------------------------------------- 1351cdf0e10cSrcweir 1352cdf0e10cSrcweir SfxUnoStyleSheet* SfxUnoStyleSheet::getUnoStyleSheet( const ::com::sun::star::uno::Reference< ::com::sun::star::style::XStyle >& xStyle ) 1353cdf0e10cSrcweir { 1354cdf0e10cSrcweir SfxUnoStyleSheet* pRet = dynamic_cast< SfxUnoStyleSheet* >( xStyle.get() ); 1355cdf0e10cSrcweir if( !pRet ) 1356cdf0e10cSrcweir { 1357cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::lang::XUnoTunnel > xUT( xStyle, ::com::sun::star::uno::UNO_QUERY ); 1358cdf0e10cSrcweir if( xUT.is() ) 1359cdf0e10cSrcweir pRet = reinterpret_cast<SfxUnoStyleSheet*>(sal::static_int_cast<sal_uIntPtr>(xUT->getSomething( SfxUnoStyleSheet::getIdentifier()))); 1360cdf0e10cSrcweir } 1361cdf0e10cSrcweir return pRet; 1362cdf0e10cSrcweir } 1363cdf0e10cSrcweir 1364cdf0e10cSrcweir // -------------------------------------------------------------------- 1365cdf0e10cSrcweir // XUnoTunnel 1366cdf0e10cSrcweir // -------------------------------------------------------------------- 1367cdf0e10cSrcweir 1368cdf0e10cSrcweir ::sal_Int64 SAL_CALL SfxUnoStyleSheet::getSomething( const ::com::sun::star::uno::Sequence< ::sal_Int8 >& rId ) throw (::com::sun::star::uno::RuntimeException) 1369cdf0e10cSrcweir { 1370cdf0e10cSrcweir if( rId.getLength() == 16 && 0 == rtl_compareMemory( getIdentifier().getConstArray(), rId.getConstArray(), 16 ) ) 1371cdf0e10cSrcweir { 1372cdf0e10cSrcweir return sal::static_int_cast<sal_Int64>(reinterpret_cast<sal_uIntPtr>(this)); 1373cdf0e10cSrcweir } 1374cdf0e10cSrcweir else 1375cdf0e10cSrcweir { 1376cdf0e10cSrcweir return 0; 1377cdf0e10cSrcweir } 1378cdf0e10cSrcweir } 1379cdf0e10cSrcweir 1380cdf0e10cSrcweir // -------------------------------------------------------------------- 1381cdf0e10cSrcweir 1382cdf0e10cSrcweir const ::com::sun::star::uno::Sequence< ::sal_Int8 >& SfxUnoStyleSheet::getIdentifier() 1383cdf0e10cSrcweir { 1384cdf0e10cSrcweir static ::com::sun::star::uno::Sequence< sal_Int8 > * pSeq = 0; 1385cdf0e10cSrcweir if( !pSeq ) 1386cdf0e10cSrcweir { 1387cdf0e10cSrcweir ::osl::Guard< ::osl::Mutex > aGuard( ::osl::Mutex::getGlobalMutex() ); 1388cdf0e10cSrcweir if( !pSeq ) 1389cdf0e10cSrcweir { 1390cdf0e10cSrcweir static ::com::sun::star::uno::Sequence< sal_Int8 > aSeq( 16 ); 1391cdf0e10cSrcweir rtl_createUuid( (sal_uInt8*)aSeq.getArray(), 0, sal_True ); 1392cdf0e10cSrcweir pSeq = &aSeq; 1393cdf0e10cSrcweir } 1394cdf0e10cSrcweir } 1395cdf0e10cSrcweir return *pSeq; 1396cdf0e10cSrcweir } 1397cdf0e10cSrcweir 1398cdf0e10cSrcweir // -------------------------------------------------------------------- 1399