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