Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include <com/sun/star/lang/XComponent.hpp>
21 :
22 : #include <tools/tenccvt.hxx>
23 : #include <comphelper/processfactory.hxx>
24 : #include <unotools/intlwrapper.hxx>
25 : #include <svl/smplhint.hxx>
26 : #include <svl/poolitem.hxx>
27 : #include <svl/itemset.hxx>
28 : #include <svl/itempool.hxx>
29 : #include <poolio.hxx>
30 : #include <svl/filerec.hxx>
31 : #include <svl/itemiter.hxx>
32 : #include <svl/style.hxx>
33 : #include <unotools/syslocale.hxx>
34 : #include <algorithm>
35 : #include <comphelper/servicehelper.hxx>
36 : #include <string.h>
37 :
38 : #ifdef DBG_UTIL
39 : class DbgStyleSheetReferences
40 : {
41 : public:
42 : DbgStyleSheetReferences() : mnStyles(0), mnPools(0) {}
43 : ~DbgStyleSheetReferences()
44 : {
45 : OSL_TRACE("DbgStyleSheetReferences\nSfxStyleSheetBase left %ld\nSfxStyleSheetBasePool left %ld", mnStyles, mnPools );
46 : }
47 :
48 : sal_uInt32 mnStyles;
49 : sal_uInt32 mnPools;
50 : }
51 : aDbgStyleSheetReferences;
52 :
53 : #endif
54 :
55 0 : TYPEINIT0(SfxStyleSheetBase)
56 :
57 19600 : TYPEINIT3(SfxStyleSheet, SfxStyleSheetBase, SfxListener, SfxBroadcaster)
58 :
59 :
60 : //=========================================================================
61 :
62 242189 : TYPEINIT1(SfxStyleSheetHint, SfxHint);
63 22789 : TYPEINIT1(SfxStyleSheetHintExtended, SfxStyleSheetHint);
64 0 : TYPEINIT1(SfxStyleSheetPoolHint, SfxHint);
65 :
66 70 : SfxStyleSheetHintExtended::SfxStyleSheetHintExtended
67 : (
68 : sal_uInt16 nAction, // SFX_STYLESHEET_... (s.o.)
69 : const String& rOldName,
70 : SfxStyleSheetBase& rStyleSheet // geh"ort weiterhin dem Aufrufer
71 : )
72 : : SfxStyleSheetHint( nAction, rStyleSheet ),
73 70 : aName( rOldName )
74 70 : {}
75 :
76 : //-------------------------------------------------------------------------
77 :
78 7314 : SfxStyleSheetHint::SfxStyleSheetHint
79 : (
80 : sal_uInt16 nAction, // SFX_STYLESHEET_... (s.o.)
81 : SfxStyleSheetBase& rStyleSheet // geh"ort weiterhin dem Aufrufer
82 : )
83 : : pStyleSh( &rStyleSheet ),
84 7314 : nHint( nAction )
85 7314 : {}
86 :
87 : //=========================================================================
88 :
89 : class SfxStyleSheetBasePool_Impl
90 : {
91 : public:
92 : SfxStyleSheetIterator *pIter;
93 484 : SfxStyleSheetBasePool_Impl() : pIter(0){}
94 220 : ~SfxStyleSheetBasePool_Impl(){delete pIter;}
95 : };
96 :
97 :
98 : //////////////////////////// SfxStyleSheetBase ///////////////////////////////
99 :
100 : // Konstruktoren
101 :
102 2264 : SfxStyleSheetBase::SfxStyleSheetBase( const XubString& rName, SfxStyleSheetBasePool* p, SfxStyleFamily eFam, sal_uInt16 mask )
103 : : pPool( p )
104 : , nFamily( eFam )
105 : , aName( rName )
106 : , aParent()
107 : , aFollow( rName )
108 : , pSet( NULL )
109 : , nMask(mask)
110 : , nHelpId( 0 )
111 : , bMySet( sal_False )
112 2264 : , bHidden( sal_False )
113 : {
114 : #ifdef DBG_UTIL
115 : aDbgStyleSheetReferences.mnStyles++;
116 : #endif
117 2264 : }
118 :
119 5287 : SfxStyleSheetBase::SfxStyleSheetBase( const SfxStyleSheetBase& r )
120 : : comphelper::OWeakTypeObject()
121 : , pPool( r.pPool )
122 : , nFamily( r.nFamily )
123 : , aName( r.aName )
124 : , aParent( r.aParent )
125 : , aFollow( r.aFollow )
126 : , aHelpFile( r.aHelpFile )
127 : , nMask( r.nMask )
128 : , nHelpId( r.nHelpId )
129 : , bMySet( r.bMySet )
130 5287 : , bHidden( r.bHidden )
131 : {
132 : #ifdef DBG_UTIL
133 : aDbgStyleSheetReferences.mnStyles++;
134 : #endif
135 5287 : if( r.pSet )
136 0 : pSet = bMySet ? new SfxItemSet( *r.pSet ) : r.pSet;
137 : else
138 5287 : pSet = NULL;
139 5287 : }
140 :
141 14110 : SfxStyleSheetBase::~SfxStyleSheetBase()
142 : {
143 : #ifdef DBG_UTIL
144 : --aDbgStyleSheetReferences.mnStyles;
145 : #endif
146 :
147 7055 : if( bMySet )
148 : {
149 685 : delete pSet;
150 685 : pSet = 0;
151 : }
152 7055 : }
153 :
154 0 : sal_uInt16 SfxStyleSheetBase::GetVersion() const
155 : {
156 0 : return 0x0000;
157 : }
158 :
159 : // Namen aendern
160 :
161 854147 : const XubString& SfxStyleSheetBase::GetName() const
162 : {
163 854147 : return aName;
164 : }
165 :
166 70 : bool SfxStyleSheetBase::SetName( const XubString& rName )
167 : {
168 70 : if(rName.Len() == 0)
169 0 : return sal_False;
170 70 : if( aName != rName )
171 : {
172 70 : String aOldName = aName;
173 70 : SfxStyleSheetBase *pOther = pPool->Find( rName, nFamily ) ;
174 70 : if ( pOther && pOther != this )
175 0 : return sal_False;
176 :
177 70 : SfxStyleFamily eTmpFam = pPool->GetSearchFamily();
178 70 : sal_uInt16 nTmpMask = pPool->GetSearchMask();
179 :
180 70 : pPool->SetSearchMask(nFamily);
181 :
182 70 : if ( aName.Len() )
183 70 : pPool->ChangeParent( aName, rName, sal_False );
184 70 : if ( aFollow.Equals( aName ) )
185 70 : aFollow = rName;
186 70 : aName = rName;
187 70 : pPool->SetSearchMask(eTmpFam, nTmpMask);
188 : pPool->Broadcast( SfxStyleSheetHintExtended(
189 70 : SFX_STYLESHEET_MODIFIED, aOldName, *this ) );
190 : }
191 70 : return sal_True;
192 : }
193 :
194 0 : rtl::OUString SfxStyleSheetBase::GetDisplayName() const
195 : {
196 0 : if( maDisplayName.isEmpty() )
197 : {
198 0 : return aName;
199 : }
200 : else
201 : {
202 0 : return maDisplayName;
203 : }
204 : }
205 :
206 0 : void SfxStyleSheetBase::SetDisplayName( const rtl::OUString& rDisplayName )
207 : {
208 0 : maDisplayName = rDisplayName;
209 0 : }
210 :
211 : // Parent aendern
212 :
213 3518 : const XubString& SfxStyleSheetBase::GetParent() const
214 : {
215 3518 : return aParent;
216 : }
217 :
218 1545 : bool SfxStyleSheetBase::SetParent( const XubString& rName )
219 : {
220 1545 : if ( rName == aName )
221 0 : return false;
222 :
223 1545 : if( aParent != rName )
224 : {
225 1545 : SfxStyleSheetBase* pIter = pPool->Find(rName, nFamily);
226 1545 : if( rName.Len() && !pIter )
227 : {
228 : OSL_FAIL( "StyleSheet-Parent nicht gefunden" );
229 0 : return false;
230 : }
231 : // rekursive Verknuepfungen verhindern
232 1545 : if( aName.Len() )
233 5493 : while(pIter)
234 : {
235 2403 : if(pIter->GetName() == aName)
236 0 : return false;
237 2403 : pIter = pPool->Find(pIter->GetParent(), nFamily);
238 : }
239 1545 : aParent = rName;
240 : }
241 1545 : pPool->Broadcast( SfxStyleSheetHint( SFX_STYLESHEET_MODIFIED, *this ) );
242 1545 : return true;
243 : }
244 :
245 169 : void SfxStyleSheetBase::SetHidden( sal_Bool hidden )
246 : {
247 169 : bHidden = hidden;
248 169 : pPool->Broadcast( SfxStyleSheetHint( SFX_STYLESHEET_MODIFIED, *this ) );
249 169 : }
250 :
251 : // Follow aendern
252 :
253 412 : const XubString& SfxStyleSheetBase::GetFollow() const
254 : {
255 412 : return aFollow;
256 : }
257 :
258 6 : bool SfxStyleSheetBase::SetFollow( const XubString& rName )
259 : {
260 6 : if( aFollow != rName )
261 : {
262 6 : if( !pPool->Find( rName, nFamily ) )
263 : {
264 : OSL_FAIL( "StyleSheet-Follow nicht gefunden" );
265 0 : return false;
266 : }
267 6 : aFollow = rName;
268 : }
269 6 : pPool->Broadcast( SfxStyleSheetHint( SFX_STYLESHEET_MODIFIED, *this ) );
270 6 : return true;
271 : }
272 :
273 : // Itemset setzen. Die Dflt-Implementation legt ein neues Set an.
274 :
275 0 : SfxItemSet& SfxStyleSheetBase::GetItemSet()
276 : {
277 0 : if( !pSet )
278 : {
279 0 : pSet = new SfxItemSet( pPool->GetPool() );
280 0 : bMySet = sal_True;
281 : }
282 0 : return *pSet;
283 : }
284 :
285 : // Hilfe-Datei und -ID setzen und abfragen
286 :
287 59 : sal_uLong SfxStyleSheetBase::GetHelpId( String& rFile )
288 : {
289 59 : rFile = aHelpFile;
290 59 : return nHelpId;
291 : }
292 :
293 1055 : void SfxStyleSheetBase::SetHelpId( const String& rFile, sal_uLong nId )
294 : {
295 1055 : aHelpFile = rFile;
296 1055 : nHelpId = nId;
297 1055 : }
298 :
299 : // Folgevorlage m"oglich? Default: Ja
300 :
301 0 : bool SfxStyleSheetBase::HasFollowSupport() const
302 : {
303 0 : return true;
304 : }
305 :
306 : // Basisvorlage m"oglich? Default: Ja
307 :
308 0 : bool SfxStyleSheetBase::HasParentSupport() const
309 : {
310 0 : return true;
311 : }
312 :
313 : // Basisvorlage uf NULL setzen m"oglich? Default: Nein
314 :
315 0 : bool SfxStyleSheetBase::HasClearParentSupport() const
316 : {
317 0 : return false;
318 : }
319 :
320 : // Defaultmaessig sind alle StyleSheets Used
321 :
322 0 : bool SfxStyleSheetBase::IsUsed() const
323 : {
324 0 : return true;
325 : }
326 :
327 : // eingestellte Attribute ausgeben
328 :
329 :
330 0 : XubString SfxStyleSheetBase::GetDescription()
331 : {
332 0 : return GetDescription( SFX_MAPUNIT_CM );
333 : }
334 :
335 : // eingestellte Attribute ausgeben
336 :
337 0 : XubString SfxStyleSheetBase::GetDescription( SfxMapUnit eMetric )
338 : {
339 0 : SfxItemIter aIter( GetItemSet() );
340 0 : XubString aDesc;
341 0 : const SfxPoolItem* pItem = aIter.FirstItem();
342 :
343 0 : IntlWrapper aIntlWrapper( SvtSysLocale().GetLanguageTag() );
344 0 : while ( pItem )
345 : {
346 0 : XubString aItemPresentation;
347 :
348 0 : if ( !IsInvalidItem( pItem ) &&
349 0 : pPool->GetPool().GetPresentation(
350 : *pItem, SFX_ITEM_PRESENTATION_COMPLETE,
351 0 : eMetric, aItemPresentation, &aIntlWrapper ) )
352 : {
353 0 : if ( aDesc.Len() && aItemPresentation.Len() )
354 0 : aDesc.AppendAscii(RTL_CONSTASCII_STRINGPARAM(" + "));
355 0 : if ( aItemPresentation.Len() )
356 0 : aDesc += aItemPresentation;
357 : }
358 0 : pItem = aIter.NextItem();
359 0 : }
360 0 : return aDesc;
361 : }
362 :
363 : /////////////////////////// SfxStyleSheetIterator ///////////////////////////////
364 :
365 99062 : SfxStyleFamily SfxStyleSheetIterator::GetSearchFamily() const
366 : {
367 99062 : return nSearchFamily;
368 : }
369 :
370 2689 : inline bool SfxStyleSheetIterator::IsTrivialSearch()
371 : {
372 : return ( nMask & SFXSTYLEBIT_ALL_VISIBLE ) == SFXSTYLEBIT_ALL_VISIBLE
373 2689 : && GetSearchFamily() == SFX_STYLE_FAMILY_ALL;
374 : }
375 :
376 46703 : bool SfxStyleSheetIterator::DoesStyleMatch(SfxStyleSheetBase *pStyle)
377 : {
378 46703 : bool bMatchFamily = ((GetSearchFamily() == SFX_STYLE_FAMILY_ALL) ||
379 46703 : ( pStyle->GetFamily() == GetSearchFamily() ));
380 :
381 46703 : bool bUsed = bSearchUsed ? pStyle->IsUsed( ) : false;
382 :
383 46703 : bool bSearchHidden = ( GetSearchMask() & SFXSTYLEBIT_HIDDEN );
384 46703 : bool bMatchVisibility = !( !bSearchHidden && pStyle->IsHidden() && !bUsed );
385 46703 : bool bOnlyHidden = GetSearchMask( ) == SFXSTYLEBIT_HIDDEN && pStyle->IsHidden( );
386 :
387 : bool bMatches = bMatchFamily && bMatchVisibility
388 50280 : && (( pStyle->GetMask() & ( GetSearchMask() & ~SFXSTYLEBIT_USED )) ||
389 : bUsed || bOnlyHidden ||
390 96983 : ( GetSearchMask() & SFXSTYLEBIT_ALL_VISIBLE ) == SFXSTYLEBIT_ALL_VISIBLE );
391 46703 : return bMatches;
392 : }
393 :
394 :
395 29829 : SfxStyleSheetIterator::SfxStyleSheetIterator(SfxStyleSheetBasePool *pBase,
396 29829 : SfxStyleFamily eFam, sal_uInt16 n)
397 : {
398 29829 : pBasePool=pBase;
399 29829 : nSearchFamily=eFam;
400 29829 : bSearchUsed=sal_False;
401 29829 : if( (( n & SFXSTYLEBIT_ALL_VISIBLE ) != SFXSTYLEBIT_ALL_VISIBLE )
402 : && ((n & SFXSTYLEBIT_USED) == SFXSTYLEBIT_USED))
403 : {
404 336 : bSearchUsed = sal_True;
405 336 : n &= ~SFXSTYLEBIT_USED;
406 : }
407 29829 : nMask=n;
408 29829 : }
409 :
410 29611 : SfxStyleSheetIterator::~SfxStyleSheetIterator()
411 : {
412 29611 : }
413 :
414 :
415 84 : sal_uInt16 SfxStyleSheetIterator::Count()
416 : {
417 84 : sal_uInt16 n = 0;
418 84 : if( IsTrivialSearch())
419 0 : n = (sal_uInt16) pBasePool->aStyles.size();
420 : else
421 672 : for(sal_uInt16 i=0; i<pBasePool->aStyles.size(); i++)
422 : {
423 588 : SfxStyleSheetBase* pStyle = pBasePool->aStyles[i].get();
424 588 : if(DoesStyleMatch(pStyle))
425 408 : n++;
426 : }
427 84 : return n;
428 : }
429 :
430 65 : SfxStyleSheetBase* SfxStyleSheetIterator::operator[](sal_uInt16 nIdx)
431 : {
432 65 : if( IsTrivialSearch())
433 0 : return pBasePool->aStyles[nIdx].get();
434 :
435 65 : sal_uInt16 z = 0;
436 195 : for(sal_uInt16 n=0; n<pBasePool->aStyles.size(); n++)
437 : {
438 195 : SfxStyleSheetBase* pStyle = pBasePool->aStyles[n].get();
439 195 : if( DoesStyleMatch(pStyle))
440 : {
441 195 : if(z == nIdx)
442 : {
443 65 : nAktPosition=n;
444 65 : return pAktStyle=pStyle;
445 : }
446 130 : ++z;
447 : }
448 : }
449 : OSL_FAIL("falscher Index");
450 0 : return 0;
451 : }
452 :
453 1356 : SfxStyleSheetBase* SfxStyleSheetIterator::First()
454 : {
455 1356 : sal_Int32 nIdx = -1;
456 :
457 1356 : if ( IsTrivialSearch() && pBasePool->aStyles.size() )
458 0 : nIdx = 0;
459 : else
460 17131 : for( sal_uInt16 n = 0; n < pBasePool->aStyles.size(); n++ )
461 : {
462 17118 : SfxStyleSheetBase* pStyle = pBasePool->aStyles[n].get();
463 :
464 17118 : if ( DoesStyleMatch( pStyle ) )
465 : {
466 1343 : nIdx = n;
467 1343 : break;
468 : }
469 : }
470 :
471 1356 : if ( nIdx != -1 )
472 : {
473 1343 : nAktPosition = (sal_uInt16)nIdx;
474 1343 : return pAktStyle = pBasePool->aStyles[nIdx].get();
475 : }
476 13 : return 0;
477 : }
478 :
479 :
480 1184 : SfxStyleSheetBase* SfxStyleSheetIterator::Next()
481 : {
482 1184 : sal_Int32 nIdx = -1;
483 :
484 1184 : if ( IsTrivialSearch() &&
485 0 : (sal_uInt16)pBasePool->aStyles.size() > nAktPosition + 1 )
486 0 : nIdx = nAktPosition + 1;
487 : else
488 5564 : for( sal_uInt16 n = nAktPosition + 1; n < pBasePool->aStyles.size(); n++ )
489 : {
490 5459 : SfxStyleSheetBase* pStyle = pBasePool->aStyles[n].get();
491 :
492 5459 : if ( DoesStyleMatch( pStyle ) )
493 : {
494 1079 : nIdx = n;
495 1079 : break;
496 : }
497 : }
498 :
499 1184 : if ( nIdx != -1 )
500 : {
501 1079 : nAktPosition = (sal_uInt16)nIdx;
502 1079 : return pAktStyle = pBasePool->aStyles[nIdx].get();
503 : }
504 105 : return 0;
505 : }
506 :
507 :
508 28263 : SfxStyleSheetBase* SfxStyleSheetIterator::Find(const rtl::OUString& rStr)
509 : {
510 497616 : for ( sal_uInt16 n = 0; n < pBasePool->aStyles.size(); ++n )
511 : {
512 491419 : SfxStyleSheetBase* pStyle = pBasePool->aStyles[n].get();
513 :
514 : // #98454# performance: in case of bSearchUsed==sal_True it may be
515 : // significant to first compare the name and only if it matches to call
516 : // the style sheet IsUsed() method in DoesStyleMatch().
517 491419 : if ( pStyle->GetName().Equals( rStr ) && DoesStyleMatch( pStyle ) )
518 : {
519 22066 : nAktPosition = n;
520 22066 : return pAktStyle = pStyle;
521 : }
522 : }
523 6197 : return 0;
524 : }
525 :
526 :
527 128960 : sal_uInt16 SfxStyleSheetIterator::GetSearchMask() const
528 : {
529 128960 : sal_uInt16 mask = nMask;
530 :
531 128960 : if ( bSearchUsed )
532 24 : mask |= SFXSTYLEBIT_USED;
533 128960 : return mask;
534 : }
535 :
536 : /////////////////////////// SfxStyleSheetBasePool ///////////////////////////////
537 :
538 0 : void SfxStyleSheetBasePool::Replace(
539 : SfxStyleSheetBase& rSource, SfxStyleSheetBase& rTarget )
540 : {
541 0 : rTarget.SetFollow( rSource.GetFollow() );
542 0 : rTarget.SetParent( rSource.GetParent() );
543 0 : SfxItemSet& rSourceSet = rSource.GetItemSet();
544 0 : SfxItemSet& rTargetSet = rTarget.GetItemSet();
545 0 : rTargetSet.Intersect( rSourceSet );
546 0 : rTargetSet.Put( rSourceSet );
547 0 : }
548 :
549 3080 : SfxStyleSheetIterator& SfxStyleSheetBasePool::GetIterator_Impl()
550 : {
551 3080 : SfxStyleSheetIterator*& rpIter = pImp->pIter;
552 3080 : if( !rpIter || (rpIter->GetSearchMask() != nMask) || (rpIter->GetSearchFamily() != nSearchFamily) )
553 : {
554 159 : delete rpIter;
555 159 : rpIter = CreateIterator( nSearchFamily, nMask );
556 : }
557 3080 : return *rpIter;
558 : }
559 :
560 :
561 484 : SfxStyleSheetBasePool::SfxStyleSheetBasePool( SfxItemPool& r )
562 484 : : aAppName(r.GetName())
563 : , rPool(r)
564 : , nSearchFamily(SFX_STYLE_FAMILY_PARA)
565 968 : , nMask(SFXSTYLEBIT_ALL)
566 : {
567 : #ifdef DBG_UTIL
568 : aDbgStyleSheetReferences.mnPools++;
569 : #endif
570 :
571 484 : pImp = new SfxStyleSheetBasePool_Impl;
572 484 : }
573 :
574 0 : SfxStyleSheetBasePool::SfxStyleSheetBasePool( const SfxStyleSheetBasePool& r )
575 : : SfxBroadcaster( r )
576 : , comphelper::OWeakTypeObject()
577 : , aAppName(r.aAppName)
578 : , rPool(r.rPool)
579 : , nSearchFamily(r.nSearchFamily)
580 0 : , nMask( r.nMask )
581 : {
582 : #ifdef DBG_UTIL
583 : aDbgStyleSheetReferences.mnPools++;
584 : #endif
585 :
586 0 : pImp = new SfxStyleSheetBasePool_Impl;
587 0 : *this += r;
588 0 : }
589 :
590 440 : SfxStyleSheetBasePool::~SfxStyleSheetBasePool()
591 : {
592 : #ifdef DBG_UTIL
593 : aDbgStyleSheetReferences.mnPools--;
594 : #endif
595 :
596 220 : Broadcast( SfxSimpleHint(SFX_HINT_DYING) );
597 220 : Clear();
598 220 : delete pImp;
599 220 : }
600 :
601 0 : bool SfxStyleSheetBasePool::SetParent(SfxStyleFamily eFam, const XubString& rStyle, const XubString& rParent)
602 : {
603 0 : SfxStyleSheetIterator aIter(this,eFam,SFXSTYLEBIT_ALL);
604 0 : SfxStyleSheetBase *pStyle = aIter.Find(rStyle);
605 : OSL_ENSURE(pStyle, "Vorlage nicht gefunden. Writer mit Solar <2541??");
606 0 : if(pStyle)
607 0 : return pStyle->SetParent(rParent);
608 : else
609 0 : return false;
610 : }
611 :
612 :
613 17318 : void SfxStyleSheetBasePool::SetSearchMask(SfxStyleFamily eFam, sal_uInt16 n)
614 : {
615 17318 : nSearchFamily = eFam; nMask = n;
616 17318 : }
617 :
618 4601 : sal_uInt16 SfxStyleSheetBasePool::GetSearchMask() const
619 : {
620 4601 : return nMask;
621 : }
622 :
623 : /////////////////////////////////// Factory ////////////////////////////////
624 :
625 :
626 :
627 394 : SfxStyleSheetIterator* SfxStyleSheetBasePool::CreateIterator
628 : (
629 : SfxStyleFamily eFam,
630 : sal_uInt16 mask
631 : )
632 : {
633 394 : return new SfxStyleSheetIterator(this,eFam,mask);
634 : }
635 :
636 :
637 0 : SfxStyleSheetBase* SfxStyleSheetBasePool::Create
638 : (
639 : const XubString& rName,
640 : SfxStyleFamily eFam,
641 : sal_uInt16 mask
642 : )
643 : {
644 0 : return new SfxStyleSheetBase( rName, this, eFam, mask );
645 : }
646 :
647 0 : SfxStyleSheetBase* SfxStyleSheetBasePool::Create( const SfxStyleSheetBase& r )
648 : {
649 0 : return new SfxStyleSheetBase( r );
650 : }
651 :
652 1811 : SfxStyleSheetBase& SfxStyleSheetBasePool::Make( const XubString& rName, SfxStyleFamily eFam, sal_uInt16 mask, sal_uInt16 nPos)
653 : {
654 : OSL_ENSURE( eFam != SFX_STYLE_FAMILY_ALL, "svl::SfxStyleSheetBasePool::Make(), FamilyAll is not a allowed Familie" );
655 :
656 1811 : SfxStyleSheetIterator aIter(this, eFam, mask);
657 1811 : rtl::Reference< SfxStyleSheetBase > xStyle( aIter.Find( rName ) );
658 : OSL_ENSURE( !xStyle.is(), "svl::SfxStyleSheetBasePool::Make(), StyleSheet already exists" );
659 1811 : SfxStyleSheetIterator& rIter = GetIterator_Impl();
660 :
661 1811 : if( !xStyle.is() )
662 : {
663 1811 : xStyle = Create( rName, eFam, mask );
664 1811 : if(0xffff == nPos || nPos == aStyles.size() || nPos == rIter.Count())
665 : {
666 1811 : aStyles.push_back( xStyle );
667 : }
668 : else
669 : {
670 0 : rIter[nPos];
671 0 : aStyles.insert( aStyles.begin() + rIter.GetPos(), xStyle );
672 : }
673 1811 : Broadcast( SfxStyleSheetHint( SFX_STYLESHEET_CREATED, *xStyle.get() ) );
674 : }
675 1811 : return *xStyle.get();
676 : }
677 :
678 : /////////////////////////////// Kopieren ///////////////////////////////////
679 :
680 : // Hilfsroutine: Falls eine Vorlage dieses Namens existiert, wird
681 : // sie neu erzeugt. Alle Vorlagen, die diese Vorlage zum Parent haben,
682 : // werden umgehaengt.
683 :
684 0 : SfxStyleSheetBase& SfxStyleSheetBasePool::Add( SfxStyleSheetBase& rSheet )
685 : {
686 0 : SfxStyleSheetIterator aIter(this, rSheet.GetFamily(), nMask);
687 0 : SfxStyleSheetBase* pOld = aIter.Find( rSheet.GetName() );
688 0 : Remove( pOld );
689 0 : rtl::Reference< SfxStyleSheetBase > xNew( Create( rSheet ) );
690 0 : aStyles.push_back( xNew );
691 0 : Broadcast( SfxStyleSheetHint( SFX_STYLESHEET_CHANGED, *xNew.get() ) );
692 0 : return *xNew.get();
693 : }
694 :
695 0 : SfxStyleSheetBasePool& SfxStyleSheetBasePool::operator=( const SfxStyleSheetBasePool& r )
696 : {
697 0 : if( &r != this )
698 : {
699 0 : Clear();
700 0 : *this += r;
701 : }
702 0 : return *this;
703 : }
704 :
705 0 : SfxStyleSheetBasePool& SfxStyleSheetBasePool::operator+=( const SfxStyleSheetBasePool& r )
706 : {
707 0 : if( &r != this )
708 : {
709 0 : SfxStyles::const_iterator aIter( r.aStyles.begin() );
710 0 : while( aIter != r.aStyles.end() )
711 : {
712 0 : Add(*(*aIter++).get());
713 : }
714 : }
715 0 : return *this;
716 : }
717 :
718 : //////////////////////////////// Suchen ////////////////////////////////////
719 :
720 0 : sal_uInt16 SfxStyleSheetBasePool::Count()
721 : {
722 0 : return GetIterator_Impl().Count();
723 : }
724 :
725 0 : SfxStyleSheetBase *SfxStyleSheetBasePool::operator[](sal_uInt16 nIdx)
726 : {
727 0 : return GetIterator_Impl()[nIdx];
728 : }
729 :
730 26452 : SfxStyleSheetBase* SfxStyleSheetBasePool::Find(const XubString& rName,
731 : SfxStyleFamily eFam,
732 : sal_uInt16 mask)
733 : {
734 26452 : SfxStyleSheetIterator aIter(this,eFam,mask);
735 26452 : return aIter.Find(rName);
736 : }
737 :
738 710 : const SfxStyles& SfxStyleSheetBasePool::GetStyles()
739 : {
740 710 : return aStyles;
741 : }
742 :
743 289 : SfxStyleSheetBase* SfxStyleSheetBasePool::First()
744 : {
745 289 : return GetIterator_Impl().First();
746 : }
747 :
748 980 : SfxStyleSheetBase* SfxStyleSheetBasePool::Next()
749 : {
750 980 : return GetIterator_Impl().Next();
751 : }
752 :
753 : //////////////////////////////// Loeschen /////////////////////////////////
754 :
755 0 : void SfxStyleSheetBasePool::Remove( SfxStyleSheetBase* p )
756 : {
757 0 : if( p )
758 : {
759 : // Reference to keep p alive until after Broadcast call!
760 0 : rtl::Reference<SfxStyleSheetBase> xP(p);
761 : SfxStyles::iterator const aIter(
762 0 : std::find(aStyles.begin(), aStyles.end(), xP));
763 0 : if( aIter != aStyles.end() )
764 : {
765 : // Alle Styles umsetzen, deren Parent dieser hier ist
766 0 : ChangeParent( p->GetName(), p->GetParent() );
767 :
768 0 : com::sun::star::uno::Reference< com::sun::star::lang::XComponent > xComp( static_cast< ::cppu::OWeakObject* >((*aIter).get()), com::sun::star::uno::UNO_QUERY );
769 0 : if( xComp.is() ) try
770 : {
771 0 : xComp->dispose();
772 : }
773 0 : catch( com::sun::star::uno::Exception& )
774 : {
775 : }
776 :
777 0 : aStyles.erase(aIter);
778 0 : Broadcast( SfxStyleSheetHint( SFX_STYLESHEET_ERASED, *p ) );
779 0 : }
780 : }
781 0 : }
782 :
783 0 : void SfxStyleSheetBasePool::Insert( SfxStyleSheetBase* p )
784 : {
785 : #if OSL_DEBUG_LEVEL > 0
786 : OSL_ENSURE( p, "svl::SfxStyleSheetBasePool::Insert(), no stylesheet?" );
787 :
788 : SfxStyleSheetIterator aIter(this, p->GetFamily(), p->GetMask());
789 : SfxStyleSheetBase* pOld = aIter.Find( p->GetName() );
790 : OSL_ENSURE( !pOld, "svl::SfxStyleSheetBasePool::Insert(), StyleSheet already inserted" );
791 : if( p->GetParent().Len() )
792 : {
793 : pOld = aIter.Find( p->GetParent() );
794 : OSL_ENSURE( pOld, "svl::SfxStyleSheetBasePool::Insert(), Parent not found!" );
795 : }
796 : #endif
797 0 : aStyles.push_back( rtl::Reference< SfxStyleSheetBase >( p ) );
798 0 : Broadcast( SfxStyleSheetHint( SFX_STYLESHEET_CREATED, *p ) );
799 0 : }
800 :
801 238 : void SfxStyleSheetBasePool::Clear()
802 : {
803 238 : SfxStyles aClearStyles;
804 238 : aClearStyles.swap( aStyles );
805 :
806 238 : SfxStyles::iterator aIter( aClearStyles.begin() );
807 1980 : while( aIter != aClearStyles.end() )
808 : {
809 1504 : com::sun::star::uno::Reference< com::sun::star::lang::XComponent > xComp( static_cast< ::cppu::OWeakObject* >((*aIter).get()), com::sun::star::uno::UNO_QUERY );
810 1504 : if( xComp.is() ) try
811 : {
812 819 : xComp->dispose();
813 : }
814 0 : catch( com::sun::star::uno::Exception& )
815 : {
816 : }
817 :
818 1504 : Broadcast( SfxStyleSheetHint( SFX_STYLESHEET_ERASED, *(*aIter++).get() ) );
819 1742 : }
820 238 : }
821 :
822 : /////////////////////////// Parents umsetzen ////////////////////////////////
823 :
824 70 : void SfxStyleSheetBasePool::ChangeParent(const XubString& rOld,
825 : const XubString& rNew,
826 : bool bVirtual)
827 : {
828 70 : const sal_uInt16 nTmpMask = GetSearchMask();
829 70 : SetSearchMask(GetSearchFamily(), SFXSTYLEBIT_ALL);
830 1050 : for( SfxStyleSheetBase* p = First(); p; p = Next() )
831 : {
832 980 : if( p->GetParent().Equals( rOld ) )
833 : {
834 40 : if(bVirtual)
835 0 : p->SetParent( rNew );
836 : else
837 40 : p->aParent = rNew;
838 : }
839 : }
840 70 : SetSearchMask(GetSearchFamily(), nTmpMask);
841 70 : }
842 :
843 : /////////////////////////// Laden/Speichern /////////////////////////////////
844 :
845 0 : void SfxStyleSheetBase::Load( SvStream&, sal_uInt16 )
846 : {
847 0 : }
848 :
849 0 : void SfxStyleSheetBase::Store( SvStream& )
850 : {
851 0 : }
852 :
853 4469 : SfxItemPool& SfxStyleSheetBasePool::GetPool()
854 : {
855 4469 : return rPool;
856 : }
857 :
858 0 : const SfxItemPool& SfxStyleSheetBasePool::GetPool() const
859 : {
860 0 : return rPool;
861 : }
862 :
863 : /////////////////////// SfxStyleSheet /////////////////////////////////
864 :
865 1811 : SfxStyleSheet::SfxStyleSheet(const XubString &rName,
866 : const SfxStyleSheetBasePool& r_Pool,
867 : SfxStyleFamily eFam,
868 : sal_uInt16 mask ):
869 1811 : SfxStyleSheetBase(rName, const_cast< SfxStyleSheetBasePool* >( &r_Pool ), eFam, mask)
870 1811 : {}
871 :
872 0 : SfxStyleSheet::SfxStyleSheet(const SfxStyleSheet& rStyle) :
873 : SfxStyleSheetBase(rStyle),
874 : SfxListener( rStyle ),
875 0 : SfxBroadcaster( rStyle )
876 0 : {}
877 :
878 3008 : SfxStyleSheet::~SfxStyleSheet()
879 : {
880 1504 : Broadcast( SfxStyleSheetHint( SFX_STYLESHEET_INDESTRUCTION, *this ) );
881 1504 : }
882 :
883 :
884 2079 : bool SfxStyleSheet::SetParent( const XubString& rName )
885 : {
886 2079 : if(aParent == rName)
887 534 : return true;
888 1545 : const XubString aOldParent(aParent);
889 1545 : if(SfxStyleSheetBase::SetParent(rName)) {
890 : // aus der Benachrichtigungskette des alten
891 : // Parents gfs. austragen
892 1545 : if(aOldParent.Len()) {
893 230 : SfxStyleSheet *pParent = (SfxStyleSheet *)pPool->Find(aOldParent, nFamily, SFXSTYLEBIT_ALL);
894 230 : if(pParent)
895 230 : EndListening(*pParent);
896 : }
897 : // in die Benachrichtigungskette des neuen
898 : // Parents eintragen
899 1545 : if(aParent.Len()) {
900 1545 : SfxStyleSheet *pParent = (SfxStyleSheet *)pPool->Find(aParent, nFamily, SFXSTYLEBIT_ALL);
901 1545 : if(pParent)
902 1545 : StartListening(*pParent);
903 : }
904 1545 : return true;
905 : }
906 0 : return false;
907 : }
908 :
909 : // alle Zuhoerer benachtichtigen
910 :
911 68382 : void SfxStyleSheet::Notify(SfxBroadcaster& rBC, const SfxHint& rHint )
912 : {
913 68382 : Forward(rBC, rHint);
914 68382 : }
915 :
916 : //////////////////////// SfxStyleSheetPool ///////////////////////////////
917 :
918 209 : SfxStyleSheetPool::SfxStyleSheetPool( SfxItemPool const& rSet)
919 209 : : SfxStyleSheetBasePool( const_cast< SfxItemPool& >( rSet ) )
920 : {
921 209 : }
922 :
923 : /////////////////////////////////// Factory ////////////////////////////////
924 :
925 0 : SfxStyleSheetBase* SfxStyleSheetPool::Create( const XubString& rName,
926 : SfxStyleFamily eFam, sal_uInt16 mask )
927 : {
928 0 : return new SfxStyleSheet( rName, *this, eFam, mask );
929 : }
930 :
931 0 : SfxStyleSheetBase* SfxStyleSheetPool::Create( const SfxStyleSheet& r )
932 : {
933 0 : return new SfxStyleSheet( r );
934 : }
935 :
936 : // --------------------------------------------------------------------
937 : // class SfxUnoStyleSheet
938 : // --------------------------------------------------------------------
939 :
940 973 : SfxUnoStyleSheet::SfxUnoStyleSheet( const UniString& _rName, const SfxStyleSheetBasePool& _rPool, SfxStyleFamily _eFamily, sal_uInt16 _nMaske )
941 973 : : ::cppu::ImplInheritanceHelper2< SfxStyleSheet, ::com::sun::star::style::XStyle, ::com::sun::star::lang::XUnoTunnel >( _rName, _rPool, _eFamily, _nMaske )
942 : {
943 973 : }
944 :
945 : // --------------------------------------------------------------------
946 :
947 153 : SfxUnoStyleSheet* SfxUnoStyleSheet::getUnoStyleSheet( const ::com::sun::star::uno::Reference< ::com::sun::star::style::XStyle >& xStyle )
948 : {
949 153 : SfxUnoStyleSheet* pRet = dynamic_cast< SfxUnoStyleSheet* >( xStyle.get() );
950 153 : if( !pRet )
951 : {
952 0 : ::com::sun::star::uno::Reference< ::com::sun::star::lang::XUnoTunnel > xUT( xStyle, ::com::sun::star::uno::UNO_QUERY );
953 0 : if( xUT.is() )
954 0 : pRet = reinterpret_cast<SfxUnoStyleSheet*>(sal::static_int_cast<sal_uIntPtr>(xUT->getSomething( SfxUnoStyleSheet::getIdentifier())));
955 : }
956 153 : return pRet;
957 : }
958 :
959 : // --------------------------------------------------------------------
960 : // XUnoTunnel
961 : // --------------------------------------------------------------------
962 :
963 0 : ::sal_Int64 SAL_CALL SfxUnoStyleSheet::getSomething( const ::com::sun::star::uno::Sequence< ::sal_Int8 >& rId ) throw (::com::sun::star::uno::RuntimeException)
964 : {
965 0 : if( rId.getLength() == 16 && 0 == memcmp( getIdentifier().getConstArray(), rId.getConstArray(), 16 ) )
966 : {
967 0 : return sal::static_int_cast<sal_Int64>(reinterpret_cast<sal_uIntPtr>(this));
968 : }
969 : else
970 : {
971 0 : return 0;
972 : }
973 : }
974 :
975 : // --------------------------------------------------------------------
976 :
977 : namespace
978 : {
979 : class theSfxUnoStyleSheetIdentifier : public rtl::Static< UnoTunnelIdInit, theSfxUnoStyleSheetIdentifier > {};
980 : }
981 :
982 0 : const ::com::sun::star::uno::Sequence< ::sal_Int8 >& SfxUnoStyleSheet::getIdentifier()
983 : {
984 0 : return theSfxUnoStyleSheetIdentifier::get().getSeq();
985 : }
986 :
987 : // --------------------------------------------------------------------
988 :
989 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|