xref: /trunk/main/sw/source/ui/app/docstyle.cxx (revision 870262e3)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 // MARKER(update_precomp.py): autogen include statement, do not remove
23 #include "precompiled_sw.hxx"
24 
25 #define _SVSTDARR_USHORTS
26 #include <svl/smplhint.hxx>
27 #include <hintids.hxx>
28 #include <svl/itemiter.hxx>
29 #include <svl/eitem.hxx>
30 #include <svx/xdef.hxx>
31 #include <unotools/syslocale.hxx>
32 #include <editeng/boxitem.hxx>
33 #include <editeng/numitem.hxx>
34 #include <editeng/lrspitem.hxx>
35 #include <fmtcol.hxx>
36 #include <uitool.hxx>
37 #include <swmodule.hxx>
38 #include <wrtsh.hxx>
39 #include <docsh.hxx>
40 #include <errhdl.hxx>
41 #include <frmfmt.hxx>
42 #include <charfmt.hxx>
43 #include <poolfmt.hxx>
44 #include <pagedesc.hxx>
45 #include <docstyle.hxx>
46 #include <docary.hxx>
47 #include <ccoll.hxx>
48 #include <doc.hxx>
49 #include <IDocumentUndoRedo.hxx>
50 #include <cmdid.h>
51 #include <swstyle.h>
52 #include <app.hrc>
53 #include <paratr.hxx>
54 #include <SwStyleNameMapper.hxx>
55 #include <svl/cjkoptions.hxx>
56 #include <comphelper/processfactory.hxx>
57 #include <unotools/localedatawrapper.hxx>
58 #include <unotools/intlwrapper.hxx>
59 #include <numrule.hxx>
60 #include <fmthdft.hxx>
61 #include <svx/svxids.hrc>
62 #include <SwRewriter.hxx>
63 #include <svx/xfillit0.hxx>
64 #include <svx/xflftrit.hxx>
65 #include <svx/svdmodel.hxx>
66 #include <svx/drawitem.hxx>
67 #include <drawdoc.hxx>
68 
69 // MD 06.02.95: Die Formatnamen in der Liste aller Namen haben als
70 // erstes Zeichen die Familie:
71 
72 #define	cCHAR		(sal_Unicode)'c'
73 #define	cPARA		(sal_Unicode)'p'
74 #define	cFRAME		(sal_Unicode)'f'
75 #define	cPAGE		(sal_Unicode)'g'
76 #define cNUMRULE	(sal_Unicode)'n'
77 
78 // Dieses Zeichen wird bei der Herausgabe der Namen wieder entfernt und
79 // die Familie wird neu generiert.
80 
81 // Ausserdem gibt es jetzt zusaetzlich das Bit bPhysical. Ist dieses Bit
82 // sal_True, werden die Pool-Formatnamen NICHT mit eingetragen.
83 
84 class SwImplShellAction
85 {
86 	SwWrtShell* pSh;
87 	CurrShell* pCurrSh;
88 public:
89 	SwImplShellAction( SwDoc& rDoc );
90 	~SwImplShellAction();
91 
GetSh()92 	SwWrtShell* GetSh() { return pSh; }
93 };
94 
SwImplShellAction(SwDoc & rDoc)95 SwImplShellAction::SwImplShellAction( SwDoc& rDoc )
96 	: pCurrSh( 0 )
97 {
98 	if( rDoc.GetDocShell() )
99 		pSh = rDoc.GetDocShell()->GetWrtShell();
100 	else
101 		pSh = 0;
102 
103 	if( pSh )
104 	{
105 		pCurrSh = new CurrShell( pSh );
106 		pSh->StartAllAction();
107 	}
108 }
109 
~SwImplShellAction()110 SwImplShellAction::~SwImplShellAction()
111 {
112 	if( pCurrSh )
113 	{
114 		pSh->EndAllAction();
115 		delete pCurrSh;
116 	}
117 }
118 
119 /*--------------------------------------------------------------------
120 	Beschreibung:	SwCharFormate finden/anlegen
121 					evtl. Style fuellen
122  --------------------------------------------------------------------*/
123 
lcl_FindCharFmt(SwDoc & rDoc,const String & rName,SwDocStyleSheet * pStyle=0,sal_Bool bCreate=sal_True)124 SwCharFmt* lcl_FindCharFmt(	SwDoc& rDoc,
125 							const String& rName,
126 							SwDocStyleSheet* pStyle = 0,
127 							sal_Bool bCreate = sal_True )
128 {
129 	SwCharFmt* 	pFmt = 0;
130 	if( rName.Len() )
131 	{
132 		pFmt = rDoc.FindCharFmtByName( rName );
133 		if( !pFmt && rName == *SwStyleNameMapper::GetTextUINameArray()[ RES_POOLCOLL_STANDARD -
134 												RES_POOLCOLL_TEXT_BEGIN ] )
135 		{
136 			// Standard-Zeichenvorlage
137 			pFmt = (SwCharFmt*)rDoc.GetDfltCharFmt();
138 		}
139 
140 		if( !pFmt && bCreate )
141 		{	// Pool abklappern
142 			const sal_uInt16 nId = SwStyleNameMapper::GetPoolIdFromUIName(rName, nsSwGetPoolIdFromName::GET_POOLID_CHRFMT);
143 			if(nId != USHRT_MAX)
144 				pFmt = rDoc.GetCharFmtFromPool(nId);
145 		}
146 	}
147 	if(pStyle)
148 	{
149 		if(pFmt)
150 		{
151 			pStyle->SetPhysical(sal_True);
152 			SwFmt* p = pFmt->DerivedFrom();
153 			if( p && !p->IsDefault() )
154 				pStyle->PresetParent( p->GetName() );
155 			else
156 				pStyle->PresetParent( aEmptyStr );
157 		}
158 		else
159 			pStyle->SetPhysical(sal_False);
160 	}
161 	return pFmt;
162 }
163 
164 
165 /*--------------------------------------------------------------------
166 	Beschreibung: 	ParaFormate finden/erzeugen
167 					Style fuellen
168  --------------------------------------------------------------------*/
169 
lcl_FindParaFmt(SwDoc & rDoc,const String & rName,SwDocStyleSheet * pStyle=0,sal_Bool bCreate=sal_True)170 SwTxtFmtColl* lcl_FindParaFmt(	SwDoc& rDoc,
171 								const String& rName,
172 								SwDocStyleSheet* pStyle = 0,
173 								sal_Bool bCreate = sal_True )
174 {
175 	SwTxtFmtColl* 	pColl = 0;
176 
177 	if( rName.Len() )
178 	{
179 		pColl = rDoc.FindTxtFmtCollByName( rName );
180 		if( !pColl && bCreate )
181 		{	// Pool abklappern
182 			const sal_uInt16 nId = SwStyleNameMapper::GetPoolIdFromUIName(rName, nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL);
183 			if(nId != USHRT_MAX)
184 				pColl = rDoc.GetTxtCollFromPool(nId);
185 		}
186 	}
187 
188 	if(pStyle)
189 	{
190 		if(pColl)
191 		{
192 			pStyle->SetPhysical(sal_True);
193 			if( pColl->DerivedFrom() && !pColl->DerivedFrom()->IsDefault() )
194 				pStyle->PresetParent( pColl->DerivedFrom()->GetName() );
195 			else
196 				pStyle->PresetParent( aEmptyStr );
197 
198 			SwTxtFmtColl& rNext = pColl->GetNextTxtFmtColl();
199 			pStyle->PresetFollow(rNext.GetName());
200 		}
201 		else
202 			pStyle->SetPhysical(sal_False);
203 	}
204 	return pColl;
205 }
206 
207 
208 /*--------------------------------------------------------------------
209 	Beschreibung:	Rahmenformate
210  --------------------------------------------------------------------*/
211 
212 
lcl_FindFrmFmt(SwDoc & rDoc,const String & rName,SwDocStyleSheet * pStyle=0,sal_Bool bCreate=sal_True)213 SwFrmFmt* lcl_FindFrmFmt(	SwDoc& rDoc,
214 							const String& rName,
215 							SwDocStyleSheet* pStyle = 0,
216 							sal_Bool bCreate = sal_True )
217 {
218 	SwFrmFmt* pFmt = 0;
219 	if( rName.Len() )
220 	{
221 		pFmt = rDoc.FindFrmFmtByName( rName );
222 		if( !pFmt && bCreate )
223 		{	// Pool abklappern
224 			const sal_uInt16 nId = SwStyleNameMapper::GetPoolIdFromUIName(rName, nsSwGetPoolIdFromName::GET_POOLID_FRMFMT);
225 			if(nId != USHRT_MAX)
226 				pFmt = rDoc.GetFrmFmtFromPool(nId);
227 		}
228 	}
229 
230 	if(pStyle)
231 	{
232 		if(pFmt)
233 		{
234 			pStyle->SetPhysical(sal_True);
235 			if( pFmt->DerivedFrom() && !pFmt->DerivedFrom()->IsDefault() )
236 				pStyle->PresetParent( pFmt->DerivedFrom()->GetName() );
237 			else
238 				pStyle->PresetParent( aEmptyStr );
239 		}
240 		else
241 			pStyle->SetPhysical(sal_False);
242 	}
243 	return pFmt;
244 }
245 
246 /*--------------------------------------------------------------------
247 	Beschreibung:	Seitendescriptoren
248  --------------------------------------------------------------------*/
249 
250 
lcl_FindPageDesc(SwDoc & rDoc,const String & rName,SwDocStyleSheet * pStyle=0,sal_Bool bCreate=sal_True)251 const SwPageDesc* lcl_FindPageDesc(	SwDoc&	rDoc,
252 									const String& 	 rName,
253 									SwDocStyleSheet* pStyle = 0,
254 									sal_Bool bCreate = sal_True )
255 {
256 	const SwPageDesc* pDesc = 0;
257 
258 	if( rName.Len() )
259 	{
260 		pDesc = rDoc.FindPageDescByName( rName );
261 		if( !pDesc && bCreate )
262 		{
263 			sal_uInt16 nId = SwStyleNameMapper::GetPoolIdFromUIName(rName, nsSwGetPoolIdFromName::GET_POOLID_PAGEDESC);
264 			if(nId != USHRT_MAX)
265 				pDesc = rDoc.GetPageDescFromPool(nId);
266 		}
267 	}
268 
269 	if(pStyle)
270 	{
271 		if(pDesc)
272 		{
273 			pStyle->SetPhysical(sal_True);
274 			if(pDesc->GetFollow())
275 				pStyle->PresetFollow(pDesc->GetFollow()->GetName());
276 			else
277 				pStyle->PresetParent( aEmptyStr );
278 		}
279 		else
280 			pStyle->SetPhysical(sal_False);
281 	}
282 	return pDesc;
283 }
284 
lcl_FindNumRule(SwDoc & rDoc,const String & rName,SwDocStyleSheet * pStyle=0,sal_Bool bCreate=sal_True)285 const SwNumRule* lcl_FindNumRule(	SwDoc&	rDoc,
286 									const String& 	 rName,
287 									SwDocStyleSheet* pStyle = 0,
288 									sal_Bool bCreate = sal_True )
289 {
290 	const SwNumRule* pRule = 0;
291 
292 	if( rName.Len() )
293 	{
294 		pRule = rDoc.FindNumRulePtr( rName );
295 		if( !pRule && bCreate )
296 		{
297 			sal_uInt16 nId = SwStyleNameMapper::GetPoolIdFromUIName(rName, nsSwGetPoolIdFromName::GET_POOLID_NUMRULE);
298 			if(nId != USHRT_MAX)
299 				pRule = rDoc.GetNumRuleFromPool(nId);
300 		}
301 	}
302 
303 	if(pStyle)
304 	{
305 		if(pRule)
306 		{
307 			pStyle->SetPhysical(sal_True);
308 			pStyle->PresetParent( aEmptyStr );
309 		}
310 		else
311 			pStyle->SetPhysical(sal_False);
312 	}
313 	return pRule;
314 }
315 
316 
lcl_FindName(const SwPoolFmtList & rLst,SfxStyleFamily eFam,const String & rName)317 sal_uInt16 lcl_FindName( const SwPoolFmtList& rLst, SfxStyleFamily eFam,
318 						const String& rName )
319 {
320 	if( rLst.Count() )
321 	{
322 		// suchen
323 		String sSrch( ' ' );
324 		switch( eFam )
325 		{
326 		case SFX_STYLE_FAMILY_CHAR:  sSrch = cCHAR;		break;
327 		case SFX_STYLE_FAMILY_PARA:  sSrch = cPARA;		break;
328 		case SFX_STYLE_FAMILY_FRAME: sSrch = cFRAME;	break;
329 		case SFX_STYLE_FAMILY_PAGE:  sSrch = cPAGE;		break;
330 		case SFX_STYLE_FAMILY_PSEUDO: sSrch = cNUMRULE;	break;
331         default:; //prevent warning
332 		}
333 		sSrch += rName;
334 		for( sal_uInt16 i=0; i < rLst.Count(); ++i )
335 			if( *rLst[i] == sSrch )
336 				return i;
337 	}
338 	return USHRT_MAX;
339 }
340 
FindPhyStyle(SwDoc & rDoc,const String & rName,SfxStyleFamily eFam)341 sal_Bool FindPhyStyle( SwDoc& rDoc, const String& rName, SfxStyleFamily eFam )
342 {
343 	switch( eFam )
344 	{
345 	case SFX_STYLE_FAMILY_CHAR :
346 		return 0 != lcl_FindCharFmt( rDoc, rName, 0, sal_False );
347 	case SFX_STYLE_FAMILY_PARA :
348 		return 0 != lcl_FindParaFmt( rDoc, rName, 0, sal_False );
349 	case SFX_STYLE_FAMILY_FRAME:
350 		return 0 != lcl_FindFrmFmt( rDoc, rName, 0, sal_False );
351 	case SFX_STYLE_FAMILY_PAGE :
352 		return 0 != lcl_FindPageDesc( rDoc, rName, 0, sal_False );
353 	case SFX_STYLE_FAMILY_PSEUDO:
354 		return 0 != lcl_FindNumRule( rDoc, rName, 0, sal_False );
355     default:; //prevent warning
356 	}
357 	return sal_False;
358 }
359 
360 
361 /*--------------------------------------------------------------------
362 	Beschreibung:	Einfuegen von Strings in die Liste der Vorlagen
363  --------------------------------------------------------------------*/
364 
365 
Append(char cChar,const String & rStr)366 void SwPoolFmtList::Append( char cChar, const String& rStr )
367 {
368 	String* pStr = new String( cChar );
369 	*pStr += rStr;
370 	for ( sal_uInt16 i=0; i < Count(); ++i )
371 	{
372 		if( *operator[](i) == *pStr )
373 		{
374 			delete pStr;
375 			return;
376 		}
377 	}
378 	Insert( pStr, Count() );
379 }
380 
381 /*--------------------------------------------------------------------
382 	Beschreibung:	Liste kompletti loeschen
383  --------------------------------------------------------------------*/
384 
385 
Erase()386 void SwPoolFmtList::Erase()
387 {
388 	DeleteAndDestroy( 0, Count() );
389 }
390 
391 /*  */
392 
393 /*--------------------------------------------------------------------
394 	Beschreibung:  UI-seitige implementierung von StyleSheets
395 				   greift auf die Core-Engine zu
396  --------------------------------------------------------------------*/
397 
SwDocStyleSheet(SwDoc & rDocument,const String & rName,SwDocStyleSheetPool & _rPool,SfxStyleFamily eFam,sal_uInt16 _nMask)398 SwDocStyleSheet::SwDocStyleSheet(	SwDoc&			rDocument,
399                                     const String& 			rName,
400                                     SwDocStyleSheetPool&    _rPool,
401                                     SfxStyleFamily 			eFam,
402                                     sal_uInt16                  _nMask) :
403 
404     SfxStyleSheetBase( rName, _rPool, eFam, _nMask ),
405     pCharFmt(0),
406     pColl(0),
407     pFrmFmt(0),
408     pDesc(0),
409     pNumRule(0),
410 
411     rDoc(rDocument),
412     aCoreSet(GetPool().GetPool(),   //UUUU sorted by indices, one double removed
413             RES_CHRATR_BEGIN,		RES_CHRATR_END - 1,             // [1
414             RES_PARATR_BEGIN,       RES_PARATR_END - 1,             // [60
415             // --> OD 2008-02-25 #refactorlists#
416             RES_PARATR_LIST_BEGIN,  RES_PARATR_LIST_END - 1,        // [77
417             // <--
418             RES_FRMATR_BEGIN, 		RES_FRMATR_END - 1,             // [82
419             RES_UNKNOWNATR_BEGIN, 	RES_UNKNOWNATR_END-1,           // [143
420 
421             //UUUU FillAttribute support
422             XATTR_FILL_FIRST, XATTR_FILL_LAST,                      // [1014
423 
424             SID_ATTR_BORDER_INNER, 	SID_ATTR_BORDER_INNER,          // [10023
425             SID_ATTR_PAGE, 			SID_ATTR_PAGE_EXT1,             // [10050
426             SID_ATTR_PAGE_HEADERSET,SID_ATTR_PAGE_FOOTERSET,        // [10058
427             SID_ATTR_PARA_MODEL,	SID_ATTR_PARA_MODEL,            // [10065
428 
429             //UUUU items to hand over XPropertyList things like
430             // XColorList, XHatchList, XGradientList and XBitmapList
431             // to the Area TabPage
432             SID_COLOR_TABLE,        SID_BITMAP_LIST,                // [10179
433 
434             SID_SWREGISTER_COLLECTION, SID_SWREGISTER_COLLECTION,   // [10451
435             SID_ATTR_PARA_PAGENUM, SID_ATTR_PARA_PAGENUM,           // [10457
436             SID_SWREGISTER_MODE,    SID_SWREGISTER_MODE,            // [10467
437             SID_PARA_BACKGRND_DESTINATION,	SID_ATTR_BRUSH_CHAR,    // [10590
438             SID_ATTR_NUMBERING_RULE,	SID_ATTR_NUMBERING_RULE,    // [10855
439             SID_ATTR_AUTO_STYLE_UPDATE,	SID_ATTR_AUTO_STYLE_UPDATE, // [12065
440             FN_PARAM_FTN_INFO, 		FN_PARAM_FTN_INFO,              // [21123
441             FN_COND_COLL,			FN_COND_COLL,                   // [22401
442             0),
443     bPhysical(sal_False)
444 {
445 	nHelpId = UCHAR_MAX;
446 }
447 
448 
SwDocStyleSheet(const SwDocStyleSheet & rOrg)449 SwDocStyleSheet::SwDocStyleSheet( const SwDocStyleSheet& rOrg) :
450 	SfxStyleSheetBase(rOrg),
451 	pCharFmt(rOrg.pCharFmt),
452 	pColl(rOrg.pColl),
453     pFrmFmt(rOrg.pFrmFmt),
454 	pDesc(rOrg.pDesc),
455 	pNumRule(rOrg.pNumRule),
456 	rDoc(rOrg.rDoc),
457     aCoreSet(rOrg.aCoreSet),
458     bPhysical(rOrg.bPhysical)
459 {
460 }
461 
462 
~SwDocStyleSheet()463  SwDocStyleSheet::~SwDocStyleSheet()
464 {
465 }
466 
467 /*--------------------------------------------------------------------
468 	Beschreibung:	Zuruecksetzen
469  --------------------------------------------------------------------*/
470 
471 
Reset()472 void  SwDocStyleSheet::Reset()
473 {
474 	aName.Erase();
475 	aFollow.Erase();
476 	aParent.Erase();
477 	SetPhysical(sal_False);
478 }
479 
480 /*--------------------------------------------------------------------
481 	Beschreibung:	virtuelle Methoden
482  --------------------------------------------------------------------*/
483 
484 
GetParent() const485 const String&  SwDocStyleSheet::GetParent() const
486 {
487 	if( !bPhysical )
488 	{
489 		// dann pruefe, ob schon im Doc vorhanden
490 		SwFmt* pFmt = 0;
491 		SwGetPoolIdFromName eGetType;
492 		switch(nFamily)
493 		{
494 		case SFX_STYLE_FAMILY_CHAR:
495 			pFmt = rDoc.FindCharFmtByName( aName );
496 			eGetType = nsSwGetPoolIdFromName::GET_POOLID_CHRFMT;
497 			break;
498 
499 		case SFX_STYLE_FAMILY_PARA:
500 			pFmt = rDoc.FindTxtFmtCollByName( aName );
501 			eGetType = nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL;
502 			break;
503 
504 		case SFX_STYLE_FAMILY_FRAME:
505 			pFmt = rDoc.FindFrmFmtByName( aName );
506 			eGetType = nsSwGetPoolIdFromName::GET_POOLID_FRMFMT;
507 			break;
508 
509 		case SFX_STYLE_FAMILY_PAGE:
510 		case SFX_STYLE_FAMILY_PSEUDO:
511 		default:
512 			return aEmptyStr;		// es gibt keinen Parent
513 		}
514 
515 		String sTmp;
516 		if( !pFmt )			// noch nicht vorhanden, also dflt. Parent
517 		{
518 			sal_uInt16 i = SwStyleNameMapper::GetPoolIdFromUIName( aName, eGetType );
519 			i = ::GetPoolParent( i );
520 			if( i && USHRT_MAX != i )
521 				SwStyleNameMapper::FillUIName( i, sTmp );
522 		}
523 		else
524 		{
525 			SwFmt* p = pFmt->DerivedFrom();
526 			if( p && !p->IsDefault() )
527 				sTmp = p->GetName();
528 		}
529 		SwDocStyleSheet* pThis = (SwDocStyleSheet*)this;
530 		pThis->aParent = sTmp;
531 	}
532 	return aParent;
533 }
534 
535 /*--------------------------------------------------------------------
536    Beschreibung:	Nachfolger
537  --------------------------------------------------------------------*/
538 
539 
GetFollow() const540 const String&  SwDocStyleSheet::GetFollow() const
541 {
542 	if( !bPhysical )
543 	{
544 		SwDocStyleSheet* pThis = (SwDocStyleSheet*)this;
545 		pThis->FillStyleSheet( FillAllInfo );
546 	}
547 	return aFollow;
548 }
549 
550 /*--------------------------------------------------------------------
551 	Beschreibung:	Welche Verkettung ist moeglich
552  --------------------------------------------------------------------*/
553 
554 
HasFollowSupport() const555 sal_Bool  SwDocStyleSheet::HasFollowSupport() const
556 {
557 	switch(nFamily)
558 	{
559 		case SFX_STYLE_FAMILY_PARA :
560 		case SFX_STYLE_FAMILY_PAGE : return sal_True;
561 		case SFX_STYLE_FAMILY_FRAME:
562 		case SFX_STYLE_FAMILY_CHAR :
563 		case SFX_STYLE_FAMILY_PSEUDO: return sal_False;
564 		default:
565 			ASSERT(sal_False, "unknown style family");
566 	}
567 	return sal_False;
568 }
569 
570 /*--------------------------------------------------------------------
571 	Beschreibung:	Parent ?
572  --------------------------------------------------------------------*/
573 
574 
HasParentSupport() const575 sal_Bool  SwDocStyleSheet::HasParentSupport() const
576 {
577 	sal_Bool bRet = sal_False;
578 	switch(nFamily)
579 	{
580 		case SFX_STYLE_FAMILY_CHAR :
581 		case SFX_STYLE_FAMILY_PARA :
582 		case SFX_STYLE_FAMILY_FRAME: bRet = sal_True;
583         default:; //prevent warning
584 	}
585 	return bRet;
586 }
587 
588 
HasClearParentSupport() const589 sal_Bool  SwDocStyleSheet::HasClearParentSupport() const
590 {
591 	sal_Bool bRet = sal_False;
592 	switch(nFamily)
593 	{
594 		case SFX_STYLE_FAMILY_PARA :
595 		case SFX_STYLE_FAMILY_CHAR :
596 		case SFX_STYLE_FAMILY_FRAME: bRet = sal_True;
597         default:; //prevent warning
598 	}
599 	return bRet;
600 }
601 
602 /*--------------------------------------------------------------------
603 	Beschreibung:	textuelle Beschreibung ermitteln
604  --------------------------------------------------------------------*/
GetDescription(SfxMapUnit eUnit)605 String  SwDocStyleSheet::GetDescription(SfxMapUnit eUnit)
606 {
607     IntlWrapper aIntlWrapper(
608         ::comphelper::getProcessServiceFactory(),
609         SvtSysLocale().GetLocaleData().getLocale());
610 
611     String sPlus(String::CreateFromAscii(" + "));
612 	if ( SFX_STYLE_FAMILY_PAGE == nFamily )
613 	{
614 		if( !pSet )
615 			GetItemSet();
616 
617 		SfxItemIter aIter( *pSet );
618 		String aDesc;
619 		const SfxPoolItem* pItem = aIter.FirstItem();
620 
621 		while ( pItem )
622 		{
623 			if(!IsInvalidItem(pItem))
624 				switch ( pItem->Which() )
625 				{
626 					case RES_LR_SPACE:
627 					case SID_ATTR_PAGE_SIZE:
628 					case SID_ATTR_PAGE_MAXSIZE:
629 					case SID_ATTR_PAGE_PAPERBIN:
630 					case SID_ATTR_PAGE_APP:
631 					case SID_ATTR_BORDER_INNER:
632 						break;
633 					default:
634 					{
635 						String aItemPresentation;
636 						if ( !IsInvalidItem( pItem ) &&
637                              rPool.GetPool().GetPresentation(
638 								*pItem, SFX_ITEM_PRESENTATION_COMPLETE,
639                                 eUnit, aItemPresentation, &aIntlWrapper ) )
640 						{
641 							if ( aDesc.Len() && aItemPresentation.Len() )
642 								aDesc += sPlus;
643 							aDesc += aItemPresentation;
644 						}
645 					}
646 				}
647 			pItem = aIter.NextItem();
648 		}
649 		return aDesc;
650 	}
651 	else if ( SFX_STYLE_FAMILY_FRAME == nFamily ||
652 					SFX_STYLE_FAMILY_PARA == nFamily)
653 	{
654 		if( !pSet )
655 			GetItemSet();
656 
657 		SfxItemIter aIter( *pSet );
658 		String aDesc;
659 		const SfxPoolItem* pItem = aIter.FirstItem();
660 
661 		String sPageNum, sModel, sBreak;
662         sal_Bool bHasWesternFontPrefix = sal_False;
663         sal_Bool bHasCJKFontPrefix = sal_False;
664         SvtCJKOptions aCJKOptions;
665 
666         //UUUU Get currently used FillStyle and remember, also need the XFillFloatTransparenceItem
667         // to decide if gradient transparence is used
668         const XFillStyle eFillStyle(static_cast< const XFillStyleItem& >(pSet->Get(XATTR_FILLSTYLE)).GetValue());
669         const bool bUseFloatTransparence(static_cast< const XFillFloatTransparenceItem& >(pSet->Get(XATTR_FILLFLOATTRANSPARENCE)).IsEnabled());
670 
671 		while ( pItem )
672 		{
673 			if(!IsInvalidItem(pItem))
674 				switch ( pItem->Which() )
675 				{
676 					case SID_ATTR_AUTO_STYLE_UPDATE:
677 					case SID_PARA_BACKGRND_DESTINATION:
678 					case RES_PAGEDESC:
679                     //CTL no yet supported
680                     case RES_CHRATR_CTL_FONT:
681                     case RES_CHRATR_CTL_FONTSIZE:
682                     case RES_CHRATR_CTL_LANGUAGE:
683                     case RES_CHRATR_CTL_POSTURE:
684                     case RES_CHRATR_CTL_WEIGHT:
685                         break;
686                     default:
687 					{
688 						String aItemPresentation;
689 						if ( !IsInvalidItem( pItem ) &&
690                              rPool.GetPool().GetPresentation(
691 								*pItem, SFX_ITEM_PRESENTATION_COMPLETE,
692                                 eUnit, aItemPresentation, &aIntlWrapper ) )
693 						{
694                             sal_Bool bIsDefault = sal_False;
695 							switch ( pItem->Which() )
696 							{
697                                 //UUUU
698                                 case XATTR_FILLCOLOR:
699                                 {
700                                     // only use active FillStyle information
701                                     bIsDefault = (XFILL_SOLID == eFillStyle);
702                                     break;
703                                 }
704                                 case XATTR_FILLGRADIENT:
705                                 {
706                                     // only use active FillStyle information
707                                     bIsDefault = (XFILL_GRADIENT == eFillStyle);
708                                     break;
709                                 }
710                                 case XATTR_FILLHATCH:
711                                 {
712                                     // only use active FillStyle information
713                                     bIsDefault = (XFILL_HATCH == eFillStyle);
714                                     break;
715                                 }
716                                 case XATTR_FILLBITMAP:
717                                 {
718                                     // only use active FillStyle information
719                                     bIsDefault = (XFILL_BITMAP == eFillStyle);
720                                     break;
721                                 }
722                                 case XATTR_FILLTRANSPARENCE:
723                                 {
724                                     // only active when not FloatTransparence
725                                     bIsDefault = !bUseFloatTransparence;
726                                     break;
727                                 }
728                                 case XATTR_FILLFLOATTRANSPARENCE:
729                                 {
730                                     // only active when FloatTransparence
731                                     bIsDefault = bUseFloatTransparence;
732                                     break;
733                                 }
734 
735                                 case SID_ATTR_PARA_PAGENUM:
736 									sPageNum = aItemPresentation;
737 									break;
738 								case SID_ATTR_PARA_MODEL:
739 									sModel = aItemPresentation;
740 									break;
741 								case RES_BREAK:
742 									sBreak = aItemPresentation;
743 									break;
744                                 case RES_CHRATR_CJK_FONT:
745                                 case RES_CHRATR_CJK_FONTSIZE:
746                                 case RES_CHRATR_CJK_LANGUAGE:
747                                 case RES_CHRATR_CJK_POSTURE:
748                                 case RES_CHRATR_CJK_WEIGHT:
749                                 if(aCJKOptions.IsCJKFontEnabled())
750                                     bIsDefault = sal_True;
751                                 if(!bHasCJKFontPrefix)
752                                 {
753                                     aItemPresentation.Insert(SW_RESSTR(STR_CJK_FONT), 0);
754                                     bHasCJKFontPrefix = sal_True;
755                                 }
756                                 break;
757                                 case RES_CHRATR_FONT:
758                                 case RES_CHRATR_FONTSIZE:
759                                 case RES_CHRATR_LANGUAGE:
760                                 case RES_CHRATR_POSTURE:
761                                 case RES_CHRATR_WEIGHT:
762                                 if(!bHasWesternFontPrefix)
763                                 {
764                                     aItemPresentation.Insert(SW_RESSTR(STR_WESTERN_FONT), 0);
765                                     bHasWesternFontPrefix = sal_True;
766                                     bIsDefault = sal_True;
767                                 }
768                                 // no break;
769                                 default:
770                                     bIsDefault = sal_True;
771                             }
772                             if(bIsDefault)
773                             {
774                                 if ( aDesc.Len() && aItemPresentation.Len() )
775 									aDesc += sPlus;
776 								aDesc += aItemPresentation;
777                             }
778                         }
779 					}
780 				}
781 			pItem = aIter.NextItem();
782 		}
783 		//Sonderbehandlung fuer Umburch, Seitenvorlage und Seitenoffset
784 		if(sBreak.Len() && !sModel.Len())  // wemm Model. dann ist Break ungueltig
785 		{
786 			if(aDesc.Len())
787 				aDesc += sPlus;
788 			aDesc += sBreak;
789 		}
790 		if(sModel.Len())
791 		{
792 			if(aDesc.Len())
793 				aDesc += sPlus;
794 			aDesc += SW_RESSTR(STR_PAGEBREAK);
795 			aDesc += sPlus;
796 			aDesc += sModel;
797 			if(sPageNum != String(UniString::CreateFromInt32(0)))
798 			{
799 				aDesc += sPlus;
800 				aDesc += SW_RESSTR(STR_PAGEOFFSET);
801 				aDesc += sPageNum;
802 			}
803 		}
804 		return aDesc;
805 	}
806 	else if( SFX_STYLE_FAMILY_PSEUDO == nFamily )
807 	{
808 //		if( pNumRule )
809 //			return pNumRule->GetName();
810 		//os: was sollte man bei Numerierungen schon anzeigen?
811 		return aEmptyStr;
812 	}
813 
814 	return SfxStyleSheetBase::GetDescription(eUnit);
815 }
816 
817 
GetDescription()818 String  SwDocStyleSheet::GetDescription()
819 {
820 	return GetDescription(SFX_MAPUNIT_CM);
821 }
822 
823 /*--------------------------------------------------------------------
824 	Beschreibung:	Namen setzen
825  --------------------------------------------------------------------*/
826 
827 
SetName(const String & rStr)828 sal_Bool  SwDocStyleSheet::SetName( const String& rStr)
829 {
830 	if( !rStr.Len() )
831 		return sal_False;
832 
833 	if( aName != rStr )
834 	{
835 		if( !SfxStyleSheetBase::SetName( rStr ))
836 			return sal_False;
837 	}
838 	else if(!bPhysical)
839 		FillStyleSheet( FillPhysical );
840 
841 	int bChg = sal_False;
842 	switch(nFamily)
843 	{
844 		case SFX_STYLE_FAMILY_CHAR :
845 		{
846 			ASSERT(pCharFmt, "SwCharFormat fehlt!");
847 			if( pCharFmt && pCharFmt->GetName() != rStr )
848 			{
849 				pCharFmt->SetName( rStr );
850 				bChg = sal_True;
851 			}
852 			break;
853 		}
854 		case SFX_STYLE_FAMILY_PARA :
855 		{
856 			ASSERT(pColl, "Collektion fehlt!");
857 			if( pColl && pColl->GetName() != rStr )
858 			{
859                 if (pColl->GetName().Len() > 0)
860                     rDoc.RenameFmt(*pColl, rStr);
861                 else
862                     pColl->SetName(rStr);
863 
864 				bChg = sal_True;
865 			}
866 			break;
867 		}
868 		case SFX_STYLE_FAMILY_FRAME:
869 		{
870 			ASSERT(pFrmFmt, "FrmFmt fehlt!");
871 			if( pFrmFmt && pFrmFmt->GetName() != rStr )
872 			{
873                 if (pFrmFmt->GetName().Len() > 0)
874                     rDoc.RenameFmt(*pFrmFmt, rStr);
875                 else
876                     pFrmFmt->SetName( rStr );
877 
878 				bChg = sal_True;
879 			}
880 			break;
881 		}
882 		case SFX_STYLE_FAMILY_PAGE :
883 			ASSERT(pDesc, "PageDesc fehlt!");
884 			if( pDesc && pDesc->GetName() != rStr )
885 			{
886 				//PageDesc setzen - mit vorherigem kopieren - ist fuer das
887 				//setzen des Namens wohl nicht notwendig. Deshalb erlauben
888 				//wir hier mal einen cast.
889                 // -> #116530#
890                 SwPageDesc aPageDesc(*((SwPageDesc*)pDesc));
891                 String aOldName(aPageDesc.GetName());
892 
893                 aPageDesc.SetName( rStr );
894                 bool const bDoesUndo = rDoc.GetIDocumentUndoRedo().DoesUndo();
895 
896                 rDoc.GetIDocumentUndoRedo().DoUndo(aOldName.Len() > 0);
897                 rDoc.ChgPageDesc(aOldName, aPageDesc);
898                 rDoc.GetIDocumentUndoRedo().DoUndo(bDoesUndo);
899                 // <- #116530#
900 
901                 rDoc.SetModified();
902 				bChg = sal_True;
903 			}
904 			break;
905 		case SFX_STYLE_FAMILY_PSEUDO:
906             ASSERT(pNumRule, "NumRule fehlt!");
907 
908             // -> #106897#
909             if (pNumRule)
910             {
911                 String aOldName = pNumRule->GetName();
912 
913                 if (aOldName.Len() > 0)
914                 {
915                     if ( aOldName != rStr &&
916                          rDoc.RenameNumRule(aOldName, rStr))
917                     {
918                         pNumRule = rDoc.FindNumRulePtr(rStr);
919                         rDoc.SetModified();
920 
921                         bChg = sal_True;
922                     }
923                 }
924                 else
925                 {
926                     // --> OD 2008-07-08 #i91400#
927                     ((SwNumRule*)pNumRule)->SetName( rStr, rDoc );
928                     // <--
929                     rDoc.SetModified();
930 
931                     bChg = sal_True;
932                 }
933             }
934             // <- #106897#
935 
936 			break;
937 
938 		default:
939 			ASSERT(sal_False, "unknown style family");
940 	}
941 
942 	if( bChg )
943 	{
944 		rPool.First();		// interne Liste muss geupdatet werden
945 		rPool.Broadcast( SfxStyleSheetHint( SFX_STYLESHEET_MODIFIED, *this ) );
946 		SwEditShell* pSh = rDoc.GetEditShell();
947 		if( pSh )
948 			pSh->CallChgLnk();
949 	}
950 	return sal_True;
951 }
952 
953 /*--------------------------------------------------------------------
954 	Beschreibung:	Ableitungshirachie
955  --------------------------------------------------------------------*/
956 
957 
SetParent(const String & rStr)958 sal_Bool   SwDocStyleSheet::SetParent( const String& rStr)
959 {
960 	SwFmt* pFmt = 0, *pParent = 0;
961 	switch(nFamily)
962 	{
963 		case SFX_STYLE_FAMILY_CHAR :
964 			ASSERT( pCharFmt, "SwCharFormat fehlt!" )
965 			if( 0 != ( pFmt = pCharFmt ) && rStr.Len() )
966 				pParent = lcl_FindCharFmt(rDoc, rStr);
967 			break;
968 
969 		case SFX_STYLE_FAMILY_PARA :
970 			ASSERT( pColl, "Collektion fehlt!")
971 			if( 0 != ( pFmt = pColl ) && rStr.Len() )
972 				pParent = lcl_FindParaFmt( rDoc, rStr );
973 			break;
974 
975 		case SFX_STYLE_FAMILY_FRAME:
976 			ASSERT(pFrmFmt, "FrameFormat fehlt!");
977 			if( 0 != ( pFmt = pFrmFmt ) && rStr.Len() )
978 				pParent = lcl_FindFrmFmt( rDoc, rStr );
979 			break;
980 
981 		case SFX_STYLE_FAMILY_PAGE:
982 		case SFX_STYLE_FAMILY_PSEUDO:
983 			break;
984 		default:
985 			ASSERT(sal_False, "unknown style family");
986 	}
987 
988 	sal_Bool bRet = sal_False;
989 	if( pFmt && pFmt->DerivedFrom() &&
990 		pFmt->DerivedFrom()->GetName() != rStr )
991 	{
992 		{
993 			SwImplShellAction aTmp( rDoc );
994 			bRet = pFmt->SetDerivedFrom( pParent );
995 		}
996 
997 		if( bRet )
998 		{
999 			aParent = rStr;
1000 			rPool.Broadcast( SfxStyleSheetHint( SFX_STYLESHEET_MODIFIED,
1001 							*this ) );
1002 		}
1003 	}
1004 
1005 	return bRet;
1006 }
1007 
1008 /*--------------------------------------------------------------------
1009 	Beschreibung:	Nachfolger detzen
1010  --------------------------------------------------------------------*/
1011 
1012 
SetFollow(const String & rStr)1013 sal_Bool   SwDocStyleSheet::SetFollow( const String& rStr)
1014 {
1015 	if( rStr.Len() && !SfxStyleSheetBase::SetFollow( rStr ))
1016 		return sal_False;
1017 
1018 	SwImplShellAction aTmpSh( rDoc );
1019 	switch(nFamily)
1020 	{
1021 	case SFX_STYLE_FAMILY_PARA :
1022 	{
1023 		ASSERT(pColl, "Collection fehlt!");
1024 		if( pColl )
1025 		{
1026 			SwTxtFmtColl* pFollow = pColl;
1027 			if( rStr.Len() && 0 == (pFollow = lcl_FindParaFmt(rDoc, rStr) ))
1028 				pFollow = pColl;
1029 
1030 			pColl->SetNextTxtFmtColl(*pFollow);
1031 		}
1032 		break;
1033 	}
1034 	case SFX_STYLE_FAMILY_PAGE :
1035 	{
1036 		ASSERT(pDesc, "PageDesc fehlt!");
1037 		if( pDesc )
1038 		{
1039 			const SwPageDesc* pFollowDesc = rStr.Len()
1040 											? lcl_FindPageDesc(rDoc, rStr)
1041 											: 0;
1042 			sal_uInt16 nId;
1043 			if( pFollowDesc != pDesc->GetFollow() &&
1044                 rDoc.FindPageDescByName( pDesc->GetName(), &nId ) )
1045 			{
1046 				SwPageDesc aDesc( *pDesc );
1047 				aDesc.SetFollow( pFollowDesc );
1048 				rDoc.ChgPageDesc( nId, aDesc );
1049 				pDesc = &const_cast<const SwDoc &>(rDoc).GetPageDesc( nId );
1050 			}
1051 		}
1052 		break;
1053 	}
1054 	case SFX_STYLE_FAMILY_CHAR:
1055 	case SFX_STYLE_FAMILY_FRAME:
1056 	case SFX_STYLE_FAMILY_PSEUDO:
1057 		break;
1058 	default:
1059 		ASSERT(sal_False, "unknown style family");
1060 	}
1061 
1062 	return sal_True;
1063 }
1064 
1065 /*--------------------------------------------------------------------
1066 	Beschreibung:	ueber Name und Family, Mask den ItemSet rausholen
1067  --------------------------------------------------------------------*/
1068 
GetItemSet()1069 SfxItemSet&   SwDocStyleSheet::GetItemSet()
1070 {
1071 	if(!bPhysical)
1072 		FillStyleSheet( FillPhysical );
1073 
1074 	switch(nFamily)
1075 	{
1076 		case SFX_STYLE_FAMILY_CHAR:
1077 			{
1078 				ASSERT(pCharFmt, "Wo ist das SwCharFmt");
1079 				aCoreSet.Put(pCharFmt->GetAttrSet());
1080 				if(pCharFmt->DerivedFrom())
1081 					aCoreSet.SetParent(&pCharFmt->DerivedFrom()->GetAttrSet());
1082 			}
1083 			break;
1084 		case SFX_STYLE_FAMILY_PARA :
1085 		case SFX_STYLE_FAMILY_FRAME:
1086 			{
1087                 SvxBoxInfoItem aBoxInfo( SID_ATTR_BORDER_INNER );
1088 				aBoxInfo.SetTable( sal_False );
1089 				aBoxInfo.SetDist( sal_True);	// Abstandsfeld immer anzeigen
1090 				aBoxInfo.SetMinDist( sal_True );// Minimalgroesse in Tabellen und Absaetzen setzen
1091 				aBoxInfo.SetDefDist( MIN_BORDER_DIST );// Default-Abstand immer setzen
1092 					// Einzelne Linien koennen nur in Tabellen DontCare-Status haben
1093 				aBoxInfo.SetValid( VALID_DISABLE, sal_True );
1094 				if ( nFamily == SFX_STYLE_FAMILY_PARA )
1095 				{
1096 					ASSERT(pColl, "Wo ist die Collektion");
1097 					aCoreSet.Put(pColl->GetAttrSet());
1098 					aCoreSet.Put( aBoxInfo );
1099 					aCoreSet.Put(SfxBoolItem(SID_ATTR_AUTO_STYLE_UPDATE, pColl->IsAutoUpdateFmt()));
1100 					if(pColl->DerivedFrom())
1101 						aCoreSet.SetParent(&pColl->DerivedFrom()->GetAttrSet());
1102 				}
1103 				else
1104 				{
1105 					ASSERT(pFrmFmt, "Wo ist das FrmFmt");
1106 					aCoreSet.Put(pFrmFmt->GetAttrSet());
1107 					aCoreSet.Put( aBoxInfo );
1108 					aCoreSet.Put(SfxBoolItem(SID_ATTR_AUTO_STYLE_UPDATE, pFrmFmt->IsAutoUpdateFmt()));
1109 					if(pFrmFmt->DerivedFrom())
1110 						aCoreSet.SetParent(&pFrmFmt->DerivedFrom()->GetAttrSet());
1111 
1112                     //UUUU create needed items for XPropertyList entries from the DrawModel so that
1113                     // the Area TabPage can access them
1114                     const SwDrawModel* pDrawModel = rDoc.GetDrawModel();
1115 
1116                     aCoreSet.Put(SvxColorTableItem(pDrawModel->GetColorTableFromSdrModel(), SID_COLOR_TABLE));
1117                     aCoreSet.Put(SvxGradientListItem(pDrawModel->GetGradientListFromSdrModel(), SID_GRADIENT_LIST));
1118                     aCoreSet.Put(SvxHatchListItem(pDrawModel->GetHatchListFromSdrModel(), SID_HATCH_LIST));
1119                     aCoreSet.Put(SvxBitmapListItem(pDrawModel->GetBitmapListFromSdrModel(), SID_BITMAP_LIST));
1120                 }
1121 			}
1122 			break;
1123 
1124 		case SFX_STYLE_FAMILY_PAGE :
1125 			{
1126                 //UUUU set correct parent to get the XFILL_NONE FillStyle as needed
1127                 if(!aCoreSet.GetParent())
1128                 {
1129                     aCoreSet.SetParent(&rDoc.GetDfltFrmFmt()->GetAttrSet());
1130                 }
1131 
1132 				ASSERT(pDesc, "Kein PageDescriptor");
1133 				::PageDescToItemSet(*((SwPageDesc*)pDesc), aCoreSet);
1134 			}
1135 			break;
1136 
1137 		case SFX_STYLE_FAMILY_PSEUDO:
1138 			{
1139 				ASSERT(pNumRule, "Keine NumRule");
1140 				SvxNumRule aRule = pNumRule->MakeSvxNumRule();
1141 				aCoreSet.Put(SvxNumBulletItem(aRule));
1142 			}
1143 			break;
1144 
1145 		default:
1146 			ASSERT(sal_False, "unknown style family");
1147 	}
1148 	// Member der Basisklasse
1149 	pSet = &aCoreSet;
1150 
1151 	return aCoreSet;
1152 }
1153 
1154 // --> OD 2008-02-13 #newlistlevelattrs#
MergeIndentAttrsOfListStyle(SfxItemSet & rSet)1155 void SwDocStyleSheet::MergeIndentAttrsOfListStyle( SfxItemSet& rSet )
1156 {
1157     if ( nFamily != SFX_STYLE_FAMILY_PARA )
1158     {
1159         return;
1160     }
1161 
1162     ASSERT( pColl, "<SwDocStyleSheet::MergeIndentAttrsOfListStyle(..)> - missing paragraph style");
1163     if ( pColl->AreListLevelIndentsApplicable() )
1164     {
1165         ASSERT( pColl->GetItemState( RES_PARATR_NUMRULE ) == SFX_ITEM_SET,
1166                 "<SwDocStyleSheet::MergeIndentAttrsOfListStyle(..)> - list level indents are applicable at paragraph style, but no list style found. Serious defect -> please inform OD." );
1167         const String sNumRule = pColl->GetNumRule().GetValue();
1168         if( sNumRule.Len() )
1169         {
1170             const SwNumRule* pRule = rDoc.FindNumRulePtr( sNumRule );
1171             if( pRule )
1172             {
1173                 const SwNumFmt& rFmt = pRule->Get( 0 );
1174                 if ( rFmt.GetPositionAndSpaceMode() == SvxNumberFormat::LABEL_ALIGNMENT )
1175                 {
1176                     SvxLRSpaceItem aLR( RES_LR_SPACE );
1177                     aLR.SetTxtLeft( rFmt.GetIndentAt() );
1178                     aLR.SetTxtFirstLineOfst( static_cast<short>(rFmt.GetFirstLineIndent()) );
1179                     rSet.Put( aLR );
1180                 }
1181             }
1182         }
1183     }
1184 }
1185 // <--
1186 
1187 /*--------------------------------------------------------------------
1188 	Beschreibung:	ItemSet setzen
1189  --------------------------------------------------------------------*/
1190 
1191 // --> OD 2008-02-12 #newlistlevelattrs#
1192 // handling of parameter <bResetIndentAttrsAtParagraphStyle>
SetItemSet(const SfxItemSet & rSet,const bool bResetIndentAttrsAtParagraphStyle)1193 void SwDocStyleSheet::SetItemSet( const SfxItemSet& rSet,
1194                                   const bool bResetIndentAttrsAtParagraphStyle )
1195 {
1196 	// gegebenenfalls Format erst ermitteln
1197 	if(!bPhysical)
1198 		FillStyleSheet( FillPhysical );
1199 
1200 	SwImplShellAction aTmpSh( rDoc );
1201 
1202 	ASSERT( &rSet != &aCoreSet, "SetItemSet mit eigenem Set ist nicht erlaubt" );
1203 
1204     // --> OD 2008-02-12 #newlistlevelattrs#
1205     if (rDoc.GetIDocumentUndoRedo().DoesUndo())
1206     {
1207         SwRewriter aRewriter;
1208         aRewriter.AddRule( UNDO_ARG1, GetName() );
1209         rDoc.GetIDocumentUndoRedo().StartUndo( UNDO_INSFMTATTR, &aRewriter );
1210     }
1211     // <--
1212 
1213 	SwFmt* pFmt = 0;
1214 	SwPageDesc* pNewDsc = 0;
1215     sal_uInt16 nPgDscPos = 0;
1216 
1217 	switch(nFamily)
1218 	{
1219 		case SFX_STYLE_FAMILY_CHAR :
1220 			{
1221 				ASSERT(pCharFmt, "Wo ist das CharFormat");
1222 				pFmt = pCharFmt;
1223 			}
1224 			break;
1225 
1226 		case SFX_STYLE_FAMILY_PARA :
1227 		{
1228 			ASSERT(pColl, "Wo ist die Collection");
1229 			const SfxPoolItem* pAutoUpdate;
1230 			if(SFX_ITEM_SET == rSet.GetItemState(SID_ATTR_AUTO_STYLE_UPDATE,sal_False, &pAutoUpdate ))
1231 			{
1232 				pColl->SetAutoUpdateFmt(((const SfxBoolItem*)pAutoUpdate)->GetValue());
1233 			}
1234 
1235 			const SwCondCollItem* pCondItem;
1236 			if( SFX_ITEM_SET != rSet.GetItemState( FN_COND_COLL, sal_False,
1237 				(const SfxPoolItem**)&pCondItem ))
1238 				pCondItem = 0;
1239 
1240 			if( RES_CONDTXTFMTCOLL == pColl->Which() && pCondItem )
1241 			{
1242 				SwFmt* pFindFmt;
1243 				const CommandStruct* pCmds = SwCondCollItem::GetCmds();
1244 				for(sal_uInt16 i = 0; i < COND_COMMAND_COUNT; i++)
1245 				{
1246 					SwCollCondition aCond( 0, pCmds[ i ].nCnd, pCmds[ i ].nSubCond );
1247 					((SwConditionTxtFmtColl*)pColl)->RemoveCondition( aCond );
1248 					const String& rStyle = pCondItem->GetStyle( i );
1249 					if( rStyle.Len() &&
1250 						0 != ( pFindFmt = lcl_FindParaFmt( rDoc, rStyle, 0, sal_True )))
1251 					{
1252                         aCond.RegisterToFormat( *pFindFmt );
1253 						((SwConditionTxtFmtColl*)pColl)->InsertCondition( aCond );
1254 					}
1255 				}
1256 
1257 				// Document auf die neue Bedingungen updaten
1258 				SwCondCollCondChg aMsg( pColl );
1259 				pColl->ModifyNotification( &aMsg, &aMsg );
1260 			}
1261 			else if( pCondItem && !pColl->GetDepends() )
1262 			{
1263 				// keine bedingte Vorlage, dann erstmal erzeugen und
1264 				// alle wichtigen Werte uebernehmen
1265 				SwConditionTxtFmtColl* pCColl = rDoc.MakeCondTxtFmtColl(
1266 						pColl->GetName(), (SwTxtFmtColl*)pColl->DerivedFrom() );
1267 				if( pColl != &pColl->GetNextTxtFmtColl() )
1268 					pCColl->SetNextTxtFmtColl( pColl->GetNextTxtFmtColl() );
1269 
1270 				if( pColl->IsAssignedToListLevelOfOutlineStyle())
1271 					pCColl->AssignToListLevelOfOutlineStyle(pColl->GetAssignedOutlineStyleLevel());
1272 				else
1273 					pCColl->DeleteAssignmentToListLevelOfOutlineStyle();
1274 
1275 
1276 
1277 				SwTxtFmtColl* pFindFmt;
1278 				const CommandStruct* pCmds = SwCondCollItem::GetCmds();
1279 				for( sal_uInt16 i = 0; i < COND_COMMAND_COUNT; ++i )
1280 				{
1281 					const String& rStyle = pCondItem->GetStyle( i );
1282 					if( rStyle.Len() &&
1283 						0 != ( pFindFmt = lcl_FindParaFmt( rDoc, rStyle, 0, sal_True )))
1284 					{
1285 						pCColl->InsertCondition( SwCollCondition( pFindFmt,
1286 									pCmds[ i ].nCnd, pCmds[ i ].nSubCond ) );
1287 					}
1288 				}
1289 
1290 				rDoc.DelTxtFmtColl( pColl );
1291 				pColl = pCColl;
1292 			}
1293             // --> OD 2008-02-12 #newlistlevelattrs#
1294             if ( bResetIndentAttrsAtParagraphStyle &&
1295                  rSet.GetItemState( RES_PARATR_NUMRULE, sal_False, 0 ) == SFX_ITEM_SET &&
1296                  rSet.GetItemState( RES_LR_SPACE, sal_False, 0 ) != SFX_ITEM_SET &&
1297                  pColl->GetItemState( RES_LR_SPACE, sal_False, 0 ) == SFX_ITEM_SET )
1298             {
1299                 rDoc.ResetAttrAtFormat( RES_LR_SPACE, *pColl );
1300             }
1301             // <--
1302 
1303             // #i56252: If a standard numbering style is assigned to a standard paragraph style
1304             // we have to create a physical instance of the numbering style. If we do not and
1305             // neither the paragraph style nor the numbering style is used in the document
1306             // the numbering style will not be saved with the document and the assignment got lost.
1307             const SfxPoolItem* pNumRuleItem = 0;
1308             if( SFX_ITEM_SET == rSet.GetItemState( RES_PARATR_NUMRULE, sal_False, &pNumRuleItem ) )
1309             {   // Setting a numbering rule?
1310                 String sNumRule = ((SwNumRuleItem*)pNumRuleItem)->GetValue();
1311                 if( sNumRule.Len() )
1312                 {
1313                     SwNumRule* pRule = rDoc.FindNumRulePtr( sNumRule );
1314                     if( !pRule )
1315                     {   // Numbering rule not in use yet.
1316                         sal_uInt16 nPoolId = SwStyleNameMapper::GetPoolIdFromUIName( sNumRule, nsSwGetPoolIdFromName::GET_POOLID_NUMRULE );
1317                         if( USHRT_MAX != nPoolId ) // It's a standard numbering rule
1318                         {
1319                             pRule = rDoc.GetNumRuleFromPool( nPoolId ); // Create numbering rule (physical)
1320                         }
1321                     }
1322                 }
1323             }
1324 
1325 			pFmt = pColl;
1326 
1327 			sal_uInt16 nId = pColl->GetPoolFmtId() &
1328 							~ ( COLL_GET_RANGE_BITS | POOLGRP_NOCOLLID );
1329 			switch( GetMask() & ( 0x0fff & ~SWSTYLEBIT_CONDCOLL ) )
1330 			{
1331 				case SWSTYLEBIT_TEXT:
1332 					nId |= COLL_TEXT_BITS;
1333 					break;
1334 				case SWSTYLEBIT_CHAPTER:
1335 					nId |= COLL_DOC_BITS;
1336 					break;
1337 				case SWSTYLEBIT_LIST:
1338 					nId |= COLL_LISTS_BITS;
1339 					break;
1340 				case SWSTYLEBIT_IDX:
1341 					nId |= COLL_REGISTER_BITS;
1342 					break;
1343 				case SWSTYLEBIT_EXTRA:
1344 					nId |= COLL_EXTRA_BITS;
1345 					break;
1346 				case SWSTYLEBIT_HTML:
1347 					nId |= COLL_HTML_BITS;
1348 					break;
1349 			}
1350 			pColl->SetPoolFmtId( nId );
1351 			break;
1352 		}
1353 		case SFX_STYLE_FAMILY_FRAME:
1354 		{
1355 			ASSERT(pFrmFmt, "Wo ist das FrmFmt");
1356 			const SfxPoolItem* pAutoUpdate;
1357 			if(SFX_ITEM_SET == rSet.GetItemState(SID_ATTR_AUTO_STYLE_UPDATE,sal_False, &pAutoUpdate ))
1358 			{
1359 				pFrmFmt->SetAutoUpdateFmt(((const SfxBoolItem*)pAutoUpdate)->GetValue());
1360 			}
1361 			pFmt = pFrmFmt;
1362 		}
1363 		break;
1364 
1365 		case SFX_STYLE_FAMILY_PAGE :
1366 			{
1367 				ASSERT(pDesc, "Wo ist der PageDescriptor");
1368 
1369 				if( rDoc.FindPageDescByName( pDesc->GetName(), &nPgDscPos ))
1370 				{
1371                     pNewDsc = new SwPageDesc( *pDesc );
1372                     // --> OD 2005-05-09 #i48949# - no undo actions for the
1373                     // copy of the page style
1374                     ::sw::UndoGuard const ug(rDoc.GetIDocumentUndoRedo());
1375                     rDoc.CopyPageDesc(*pDesc, *pNewDsc); // #i7983#
1376                     // <--
1377 
1378 					pFmt = &pNewDsc->GetMaster();
1379 				}
1380 			}
1381 			break;
1382 
1383 		case SFX_STYLE_FAMILY_PSEUDO:
1384 			{
1385 				ASSERT(pNumRule, "Wo ist die NumRule");
1386 
1387                 if (!pNumRule)
1388                     break;
1389 
1390 				const SfxPoolItem* pItem;
1391 				switch( rSet.GetItemState( SID_ATTR_NUMBERING_RULE, sal_False, &pItem ))
1392 				{
1393 				case SFX_ITEM_SET:
1394 				{
1395 					SvxNumRule* pSetRule = ((SvxNumBulletItem*)pItem)->GetNumRule();
1396 					pSetRule->UnLinkGraphics();
1397 					//SwNumRule aSetRule(rDoc.GetUniqueNumRuleName());
1398 					SwNumRule aSetRule(*pNumRule);
1399 					aSetRule.SetSvxRule(*pSetRule, &rDoc);
1400 					rDoc.ChgNumRuleFmts( aSetRule );
1401 				}
1402 				break;
1403 				case SFX_ITEM_DONTCARE:
1404 					// NumRule auf default Werte
1405 					// was sind die default Werte?
1406 					{
1407                         // --> OD 2008-02-11 #newlistlevelattrs#
1408                         SwNumRule aRule( pNumRule->GetName(),
1409                                          // --> OD 2008-06-06 #i89178#
1410                                          numfunc::GetDefaultPositionAndSpaceMode() );
1411                                          // <--
1412                         // <--
1413 						rDoc.ChgNumRuleFmts( aRule );
1414 					}
1415 					break;
1416 				}
1417 			}
1418 			break;
1419 
1420 		default:
1421 			ASSERT(sal_False, "unknown style family");
1422 	}
1423 
1424 	if( pFmt && rSet.Count())
1425 	{
1426 		SfxItemIter aIter( rSet );
1427 		const SfxPoolItem* pItem = aIter.GetCurItem();
1428 		while( sal_True )
1429 		{
1430 			if( IsInvalidItem( pItem ) )			// Clearen
1431             {
1432                 // --> OD 2008-02-12 #newlistlevelattrs#
1433                 // use method <SwDoc::ResetAttrAtFormat(..)> in order to
1434                 // create an Undo object for the attribute reset.
1435 //                pFmt->ResetAttr( rSet.GetWhichByPos(aIter.GetCurPos()));
1436                 rDoc.ResetAttrAtFormat( rSet.GetWhichByPos(aIter.GetCurPos()),
1437                                         *pFmt );
1438             }
1439 
1440 			if( aIter.IsAtEnd() )
1441 				break;
1442 			pItem = aIter.NextItem();
1443 		}
1444 		SfxItemSet aSet(rSet);
1445 		aSet.ClearInvalidItems();
1446 
1447         if(SFX_STYLE_FAMILY_FRAME == nFamily)
1448         {
1449             //UUUU Need to check for unique item for DrawingLayer items of type NameOrIndex
1450             // and evtl. correct that item to ensure unique names for that type. This call may
1451             // modify/correct entries inside of the given SfxItemSet
1452             rDoc.CheckForUniqueItemForLineFillNameOrIndex(aSet);
1453         }
1454 
1455 		aCoreSet.ClearItem();
1456 
1457 		if( pNewDsc )
1458 		{
1459 			::ItemSetToPageDesc( aSet, *pNewDsc );
1460 			rDoc.ChgPageDesc( nPgDscPos, *pNewDsc );
1461 			pDesc = &const_cast<const SwDoc &>(rDoc).GetPageDesc( nPgDscPos );
1462             rDoc.PreDelPageDesc(pNewDsc); // #i7983#
1463 			delete pNewDsc;
1464 		}
1465 		else
1466 			rDoc.ChgFmt(*pFmt, aSet);		// alles gesetzten Putten
1467 	}
1468 	else
1469 	{
1470 		aCoreSet.ClearItem();
1471 		if( pNewDsc ) 			// den muessen wir noch vernichten!!
1472         {
1473             rDoc.PreDelPageDesc(pNewDsc); // #i7983#
1474 			delete pNewDsc;
1475         }
1476 	}
1477 
1478     // --> OD 2008-02-12 #newlistlevelattrs#
1479     if (rDoc.GetIDocumentUndoRedo().DoesUndo())
1480     {
1481         rDoc.GetIDocumentUndoRedo().EndUndo(UNDO_END, 0);
1482     }
1483     // <--
1484 }
1485 
lcl_SaveStyles(sal_uInt16 nFamily,SvPtrarr & rArr,SwDoc & rDoc)1486 void lcl_SaveStyles( sal_uInt16 nFamily, SvPtrarr& rArr, SwDoc& rDoc )
1487 {
1488 	switch( nFamily )
1489 	{
1490 	case SFX_STYLE_FAMILY_CHAR:
1491 		{
1492 			const SwCharFmts& rTbl = *rDoc.GetCharFmts();
1493 			for( sal_uInt16 n = 0, nCnt = rTbl.Count(); n < nCnt; ++n )
1494 			{
1495 				void* p = (void*)rTbl[ n ];
1496 				rArr.Insert( p, n );
1497 			}
1498 		}
1499 		break;
1500 	case SFX_STYLE_FAMILY_PARA:
1501 		{
1502 			const SwTxtFmtColls& rTbl = *rDoc.GetTxtFmtColls();
1503 			for( sal_uInt16 n = 0, nCnt = rTbl.Count(); n < nCnt; ++n )
1504 			{
1505 				void* p = (void*)rTbl[ n ];
1506 				rArr.Insert( p, n );
1507 			}
1508 		}
1509 		break;
1510 	case SFX_STYLE_FAMILY_FRAME:
1511 		{
1512 			const SwFrmFmts& rTbl = *rDoc.GetFrmFmts();
1513 			for( sal_uInt16 n = 0, nCnt = rTbl.Count(); n < nCnt; ++n )
1514 			{
1515 				void* p = (void*)rTbl[ n ];
1516 				rArr.Insert( p, n );
1517 			}
1518 		}
1519 		break;
1520 
1521 	case SFX_STYLE_FAMILY_PAGE:
1522 		{
1523 			for( sal_uInt16 n = 0, nCnt = rDoc.GetPageDescCnt(); n < nCnt; ++n )
1524 			{
1525 				void* p =
1526                     (void*)&const_cast<const SwDoc &>(rDoc).GetPageDesc( n );
1527 				rArr.Insert( p, n );
1528 			}
1529 		}
1530 		break;
1531 
1532 	case SFX_STYLE_FAMILY_PSEUDO:
1533 		{
1534 			const SwNumRuleTbl& rTbl = rDoc.GetNumRuleTbl();
1535 			for( sal_uInt16 n = 0, nCnt = rTbl.Count(); n < nCnt; ++n )
1536 			{
1537 				void* p = (void*)rTbl[ n ];
1538 				rArr.Insert( p, n );
1539 			}
1540 		}
1541 		break;
1542 	}
1543 }
1544 
lcl_DeleteInfoStyles(sal_uInt16 nFamily,SvPtrarr & rArr,SwDoc & rDoc)1545 void lcl_DeleteInfoStyles( sal_uInt16 nFamily, SvPtrarr& rArr, SwDoc& rDoc )
1546 {
1547 	sal_uInt16 n, nCnt;
1548 	switch( nFamily )
1549 	{
1550 	case SFX_STYLE_FAMILY_CHAR:
1551 		{
1552 			SvUShorts aDelArr;
1553 			const SwCharFmts& rTbl = *rDoc.GetCharFmts();
1554 			for( n = 0, nCnt = rTbl.Count(); n < nCnt; ++n )
1555 			{
1556 				void* p = (void*)rTbl[ n ];
1557 				if( USHRT_MAX == rArr.GetPos( p ))
1558 					aDelArr.Insert( n, 0 );
1559 			}
1560 			for( n = 0, nCnt = aDelArr.Count(); n < nCnt; ++n )
1561 				rDoc.DelCharFmt( aDelArr[ n ] );
1562 		}
1563 		break;
1564 
1565 	case SFX_STYLE_FAMILY_PARA :
1566 		{
1567 			SvUShorts aDelArr;
1568 			const SwTxtFmtColls& rTbl = *rDoc.GetTxtFmtColls();
1569 			for( n = 0, nCnt = rTbl.Count(); n < nCnt; ++n )
1570 			{
1571 				void* p = (void*)rTbl[ n ];
1572 				if( USHRT_MAX == rArr.GetPos( p ))
1573 					aDelArr.Insert( n, 0 );
1574 			}
1575 			for( n = 0, nCnt = aDelArr.Count(); n < nCnt; ++n )
1576 				rDoc.DelTxtFmtColl( aDelArr[ n ] );
1577 		}
1578 		break;
1579 
1580 	case SFX_STYLE_FAMILY_FRAME:
1581 		{
1582 			SvPtrarr aDelArr;
1583 			const SwFrmFmts& rTbl = *rDoc.GetFrmFmts();
1584 			for( n = 0, nCnt = rTbl.Count(); n < nCnt; ++n )
1585 			{
1586 				void* p = (void*)rTbl[ n ];
1587 				if( USHRT_MAX == rArr.GetPos( p ))
1588 					aDelArr.Insert( p, 0 );
1589 			}
1590 			for( n = 0, nCnt = aDelArr.Count(); n < nCnt; ++n )
1591 				rDoc.DelFrmFmt( (SwFrmFmt*)aDelArr[ n ] );
1592 		}
1593 		break;
1594 
1595 	case SFX_STYLE_FAMILY_PAGE:
1596 		{
1597 			SvUShorts aDelArr;
1598 			for( n = 0, nCnt = rDoc.GetPageDescCnt(); n < nCnt; ++n )
1599 			{
1600 				void* p =
1601                     (void*)&const_cast<const SwDoc &>(rDoc).GetPageDesc( n );
1602 				if( USHRT_MAX == rArr.GetPos( p ))
1603 					aDelArr.Insert( n, 0 );
1604 			}
1605 			for( n = 0, nCnt = aDelArr.Count(); n < nCnt; ++n )
1606 				rDoc.DelPageDesc( aDelArr[ n ] );
1607 		}
1608 		break;
1609 
1610 
1611 	case SFX_STYLE_FAMILY_PSEUDO:
1612 		{
1613 			SvPtrarr aDelArr;
1614 			const SwNumRuleTbl& rTbl = rDoc.GetNumRuleTbl();
1615 			for( n = 0, nCnt = rTbl.Count(); n < nCnt; ++n )
1616 			{
1617 				void* p = (void*)rTbl[ n ];
1618 				if( USHRT_MAX == rArr.GetPos( p ))
1619 					aDelArr.Insert( p, 0 );
1620 			}
1621 			for( n = 0, nCnt = aDelArr.Count(); n < nCnt; ++n )
1622 				rDoc.DelNumRule( ((SwNumRule*)aDelArr[ n ])->GetName() );
1623 		}
1624 		break;
1625 	}
1626 }
1627 
1628 /*--------------------------------------------------------------------
1629 	Beschreibung:	Das Format ermitteln
1630  --------------------------------------------------------------------*/
1631 
FillStyleSheet(FillStyleType eFType)1632 sal_Bool SwDocStyleSheet::FillStyleSheet( FillStyleType eFType )
1633 {
1634 	sal_Bool bRet = sal_False;
1635 	sal_uInt16 nPoolId = USHRT_MAX;
1636 	SwFmt* pFmt = 0;
1637 
1638 	sal_Bool bCreate = FillPhysical == eFType;
1639 	sal_Bool bDeleteInfo = sal_False;
1640 	sal_Bool bFillOnlyInfo = FillAllInfo == eFType;
1641 	SvPtrarr aDelArr;
1642 
1643 	switch(nFamily)
1644 	{
1645 	case SFX_STYLE_FAMILY_CHAR:
1646 		pCharFmt = lcl_FindCharFmt(rDoc, aName, this, bCreate );
1647 		bPhysical = 0 != pCharFmt;
1648 		if( bFillOnlyInfo && !bPhysical )
1649 		{
1650 			bDeleteInfo = sal_True;
1651             ::lcl_SaveStyles( static_cast< sal_uInt16 >(nFamily), aDelArr, rDoc );
1652 			pCharFmt = lcl_FindCharFmt(rDoc, aName, this, sal_True );
1653 		}
1654 
1655 		pFmt = pCharFmt;
1656 		if( !bCreate && !pFmt )
1657 		{
1658 			if( aName == *SwStyleNameMapper::GetTextUINameArray()[ RES_POOLCOLL_STANDARD -
1659 											RES_POOLCOLL_TEXT_BEGIN ] )
1660 				nPoolId = 0;
1661 			else
1662 				nPoolId = SwStyleNameMapper::GetPoolIdFromUIName( aName, nsSwGetPoolIdFromName::GET_POOLID_CHRFMT );
1663 		}
1664 
1665 		bRet = 0 != pCharFmt || USHRT_MAX != nPoolId;
1666 
1667 		if( bDeleteInfo )
1668 			pCharFmt = 0;
1669 		break;
1670 
1671 	case SFX_STYLE_FAMILY_PARA:
1672 		{
1673 			pColl = lcl_FindParaFmt(rDoc, aName, this, bCreate);
1674 			bPhysical = 0 != pColl;
1675 			if( bFillOnlyInfo && !bPhysical )
1676 			{
1677 				bDeleteInfo = sal_True;
1678                 ::lcl_SaveStyles( static_cast< sal_uInt16 >(nFamily), aDelArr, rDoc );
1679 				pColl = lcl_FindParaFmt(rDoc, aName, this, sal_True );
1680 			}
1681 
1682 			pFmt = pColl;
1683 			if( pColl )
1684 				PresetFollow( pColl->GetNextTxtFmtColl().GetName() );
1685 			else if( !bCreate )
1686 				nPoolId = SwStyleNameMapper::GetPoolIdFromUIName( aName, nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL );
1687 
1688 			bRet = 0 != pColl || USHRT_MAX != nPoolId;
1689 
1690 			if( bDeleteInfo )
1691 				pColl = 0;
1692 		}
1693 		break;
1694 
1695 	case SFX_STYLE_FAMILY_FRAME:
1696 		pFrmFmt = lcl_FindFrmFmt(rDoc,  aName, this, bCreate);
1697 		bPhysical = 0 != pFrmFmt;
1698 		if( bFillOnlyInfo && bPhysical )
1699 		{
1700 			bDeleteInfo = sal_True;
1701             ::lcl_SaveStyles( static_cast< sal_uInt16 >(nFamily), aDelArr, rDoc );
1702 			pFrmFmt = lcl_FindFrmFmt(rDoc, aName, this, sal_True );
1703 		}
1704 		pFmt = pFrmFmt;
1705 		if( !bCreate && !pFmt )
1706 			nPoolId = SwStyleNameMapper::GetPoolIdFromUIName( aName, nsSwGetPoolIdFromName::GET_POOLID_FRMFMT );
1707 
1708 		bRet = 0 != pFrmFmt || USHRT_MAX != nPoolId;
1709 
1710 		if( bDeleteInfo )
1711 			pFrmFmt = 0;
1712 		break;
1713 
1714 	case SFX_STYLE_FAMILY_PAGE:
1715 		pDesc = lcl_FindPageDesc(rDoc, aName, this, bCreate);
1716 		bPhysical = 0 != pDesc;
1717 		if( bFillOnlyInfo && !pDesc )
1718 		{
1719 			bDeleteInfo = sal_True;
1720             ::lcl_SaveStyles( static_cast< sal_uInt16 >(nFamily), aDelArr, rDoc );
1721 			pDesc = lcl_FindPageDesc( rDoc, aName, this, sal_True );
1722 		}
1723 
1724 		if( pDesc )
1725 		{
1726 			nPoolId = pDesc->GetPoolFmtId();
1727 			nHelpId = pDesc->GetPoolHelpId();
1728 			if( pDesc->GetPoolHlpFileId() != UCHAR_MAX )
1729 				aHelpFile = *rDoc.GetDocPattern( pDesc->GetPoolHlpFileId() );
1730 			else
1731 				aHelpFile.Erase();
1732 		}
1733 		else if( !bCreate )
1734 			nPoolId = SwStyleNameMapper::GetPoolIdFromUIName( aName, nsSwGetPoolIdFromName::GET_POOLID_PAGEDESC );
1735 		SetMask( USER_FMT & nPoolId ? SFXSTYLEBIT_USERDEF : 0 );
1736 
1737 		bRet = 0 != pDesc || USHRT_MAX != nPoolId;
1738 		if( bDeleteInfo )
1739 			pDesc = 0;
1740 		break;
1741 
1742 	case SFX_STYLE_FAMILY_PSEUDO:
1743 		pNumRule = lcl_FindNumRule(rDoc, aName, this, bCreate);
1744 		bPhysical = 0 != pNumRule;
1745 		if( bFillOnlyInfo && !pNumRule )
1746 		{
1747 			bDeleteInfo = sal_True;
1748             ::lcl_SaveStyles( static_cast< sal_uInt16 >(nFamily), aDelArr, rDoc );
1749 			pNumRule = lcl_FindNumRule( rDoc, aName, this, sal_True );
1750 		}
1751 
1752 		if( pNumRule )
1753 		{
1754 			nPoolId = pNumRule->GetPoolFmtId();
1755 			nHelpId = pNumRule->GetPoolHelpId();
1756 			if( pNumRule->GetPoolHlpFileId() != UCHAR_MAX )
1757 				aHelpFile = *rDoc.GetDocPattern( pNumRule->GetPoolHlpFileId() );
1758 			else
1759 				aHelpFile.Erase();
1760 		}
1761 		else if( !bCreate )
1762 			nPoolId = SwStyleNameMapper::GetPoolIdFromUIName( aName, nsSwGetPoolIdFromName::GET_POOLID_NUMRULE );
1763 		SetMask( USER_FMT & nPoolId ? SFXSTYLEBIT_USERDEF : 0 );
1764 
1765 		bRet = 0 != pNumRule || USHRT_MAX != nPoolId;
1766 
1767 		if( bDeleteInfo )
1768 			pNumRule = 0;
1769 		break;
1770         default:; //prevent warning
1771 	}
1772 
1773 	if( SFX_STYLE_FAMILY_CHAR == nFamily ||
1774 		SFX_STYLE_FAMILY_PARA == nFamily ||
1775 		SFX_STYLE_FAMILY_FRAME == nFamily )
1776 	{
1777 		if( pFmt )
1778 			nPoolId = pFmt->GetPoolFmtId();
1779 
1780         sal_uInt16 _nMask = 0;
1781 		if( pFmt == rDoc.GetDfltCharFmt() )
1782             _nMask |= SFXSTYLEBIT_READONLY;
1783 		else if( USER_FMT & nPoolId )
1784             _nMask |= SFXSTYLEBIT_USERDEF;
1785 
1786 		switch ( COLL_GET_RANGE_BITS & nPoolId )
1787 		{
1788         case COLL_TEXT_BITS:     _nMask |= SWSTYLEBIT_TEXT;   break;
1789         case COLL_DOC_BITS :     _nMask |= SWSTYLEBIT_CHAPTER; break;
1790         case COLL_LISTS_BITS:    _nMask |= SWSTYLEBIT_LIST;   break;
1791         case COLL_REGISTER_BITS: _nMask |= SWSTYLEBIT_IDX;    break;
1792         case COLL_EXTRA_BITS:    _nMask |= SWSTYLEBIT_EXTRA;      break;
1793         case COLL_HTML_BITS:     _nMask |= SWSTYLEBIT_HTML;   break;
1794 		}
1795 
1796 		if( pFmt )
1797 		{
1798 			ASSERT( bPhysical, "Format nicht gefunden" );
1799 
1800 			nHelpId = pFmt->GetPoolHelpId();
1801 			if( pFmt->GetPoolHlpFileId() != UCHAR_MAX )
1802 				aHelpFile = *rDoc.GetDocPattern( pFmt->GetPoolHlpFileId() );
1803 			else
1804 				aHelpFile.Erase();
1805 
1806 			if( RES_CONDTXTFMTCOLL == pFmt->Which() )
1807                 _nMask |= SWSTYLEBIT_CONDCOLL;
1808 		}
1809 
1810         SetMask( _nMask );
1811 	}
1812 	if( bDeleteInfo && bFillOnlyInfo )
1813         ::lcl_DeleteInfoStyles( static_cast< sal_uInt16 >(nFamily), aDelArr, rDoc );
1814 	return bRet;
1815 }
1816 
1817 /*--------------------------------------------------------------------
1818 	Beschreibung:	Neues Format in der Core anlegen
1819  --------------------------------------------------------------------*/
1820 
1821 
Create()1822 void SwDocStyleSheet::Create()
1823 {
1824 	switch(nFamily)
1825 	{
1826 		case SFX_STYLE_FAMILY_CHAR :
1827 			pCharFmt = lcl_FindCharFmt( rDoc, aName );
1828 			if( !pCharFmt )
1829 				pCharFmt = rDoc.MakeCharFmt(aName,
1830 											rDoc.GetDfltCharFmt());
1831 			pCharFmt->SetAuto( sal_False );
1832 			break;
1833 
1834 		case SFX_STYLE_FAMILY_PARA :
1835 			pColl = lcl_FindParaFmt( rDoc, aName );
1836 			if( !pColl )
1837 			{
1838 				SwTxtFmtColl *pPar = (*rDoc.GetTxtFmtColls())[0];
1839 				if( nMask & SWSTYLEBIT_CONDCOLL )
1840 					pColl = rDoc.MakeCondTxtFmtColl( aName, pPar );
1841 				else
1842 					pColl = rDoc.MakeTxtFmtColl( aName, pPar );
1843 			}
1844 			break;
1845 
1846 		case SFX_STYLE_FAMILY_FRAME:
1847 			pFrmFmt = lcl_FindFrmFmt( rDoc, aName );
1848 			if( !pFrmFmt )
1849 				pFrmFmt = rDoc.MakeFrmFmt(aName, rDoc.GetDfltFrmFmt(), sal_False, sal_False);
1850 
1851 			break;
1852 
1853 		case SFX_STYLE_FAMILY_PAGE :
1854 			pDesc = lcl_FindPageDesc( rDoc, aName );
1855 			if( !pDesc )
1856 			{
1857 				sal_uInt16 nId = rDoc.MakePageDesc(aName);
1858 				pDesc = &const_cast<const SwDoc &>(rDoc).GetPageDesc(nId);
1859 			}
1860 			break;
1861 
1862 		case SFX_STYLE_FAMILY_PSEUDO:
1863 			pNumRule = lcl_FindNumRule( rDoc, aName );
1864 			if( !pNumRule )
1865 			{
1866 				//JP 05.02.99: temp Namen erzeugen, damit kein ASSERT kommt
1867 				String sTmpNm( aName );
1868 				if( !aName.Len() )
1869 					sTmpNm = rDoc.GetUniqueNumRuleName();
1870 
1871                 // --> OD 2008-02-11 #newlistlevelattrs#
1872                 SwNumRule* pRule = rDoc.GetNumRuleTbl()[
1873                     rDoc.MakeNumRule( sTmpNm, 0, sal_False,
1874                                       // --> OD 2008-06-06 #i89178#
1875                                       numfunc::GetDefaultPositionAndSpaceMode() ) ];
1876                                       // <--
1877                 // <--
1878 				pRule->SetAutoRule( sal_False );
1879 				if( !aName.Len() )
1880                 {
1881                     // --> OD 2008-07-08 #i91400#
1882                     pRule->SetName( aName, rDoc );
1883                     // <--
1884                 }
1885 				pNumRule = pRule;
1886 			}
1887 			break;
1888         default:; //prevent warning
1889 	}
1890 	bPhysical = sal_True;
1891 	aCoreSet.ClearItem();
1892 }
1893 
1894 /*--------------------------------------------------------------------
1895 	Beschreibung:	Konkrete Formate rausholen
1896  --------------------------------------------------------------------*/
1897 
1898 
1899 
GetCharFmt()1900 SwCharFmt* SwDocStyleSheet::GetCharFmt()
1901 {
1902 	if(!bPhysical)
1903 		FillStyleSheet( FillPhysical );
1904 	return pCharFmt;
1905 }
1906 
1907 
GetCollection()1908 SwTxtFmtColl* SwDocStyleSheet::GetCollection()
1909 {
1910 	if(!bPhysical)
1911 		FillStyleSheet( FillPhysical );
1912 	return pColl;
1913 }
1914 
1915 
GetPageDesc()1916 const SwPageDesc* SwDocStyleSheet::GetPageDesc()
1917 {
1918 	if(!bPhysical)
1919 		FillStyleSheet( FillPhysical );
1920 	return pDesc;
1921 }
1922 
GetNumRule()1923 const SwNumRule * SwDocStyleSheet::GetNumRule()
1924 {
1925 	if(!bPhysical)
1926 		FillStyleSheet( FillPhysical );
1927 	return pNumRule;
1928 }
1929 
SetNumRule(const SwNumRule & rRule)1930 void SwDocStyleSheet::SetNumRule(const SwNumRule& rRule)
1931 {
1932 	DBG_ASSERT(pNumRule, "Wo ist die NumRule");
1933 	rDoc.ChgNumRuleFmts( rRule );
1934 }
1935 
1936 // Namen UND Familie aus String re-generieren
1937 // First() und Next() (s.u.) fuegen einen Kennbuchstaben an Pos.1 ein
1938 
PresetNameAndFamily(const String & rName)1939 void SwDocStyleSheet::PresetNameAndFamily(const String& rName)
1940 {
1941 	switch( rName.GetChar(0) )
1942 	{
1943 		case cPARA:		nFamily = SFX_STYLE_FAMILY_PARA; break;
1944 		case cFRAME:	nFamily = SFX_STYLE_FAMILY_FRAME; break;
1945 		case cPAGE:		nFamily = SFX_STYLE_FAMILY_PAGE; break;
1946 		case cNUMRULE:	nFamily = SFX_STYLE_FAMILY_PSEUDO; break;
1947 		default:   		nFamily = SFX_STYLE_FAMILY_CHAR; break;
1948 	}
1949 	aName = rName;
1950 	aName.Erase( 0, 1 );
1951 }
1952 
1953 /*--------------------------------------------------------------------
1954 	Beschreibung:	Ist das Format physikalisch schon vorhanden
1955  --------------------------------------------------------------------*/
1956 
1957 
SetPhysical(sal_Bool bPhys)1958 void SwDocStyleSheet::SetPhysical(sal_Bool bPhys)
1959 {
1960 	bPhysical = bPhys;
1961 
1962 	if(!bPhys)
1963 	{
1964 		pCharFmt = 0;
1965 		pColl 	 = 0;
1966 		pFrmFmt  = 0;
1967 		pDesc 	 = 0;
1968 	}
1969 }
1970 
GetFrmFmt()1971 SwFrmFmt* SwDocStyleSheet::GetFrmFmt()
1972 {
1973 	if(!bPhysical)
1974 		FillStyleSheet( FillPhysical );
1975 	return pFrmFmt;
1976 }
1977 
1978 
IsUsed() const1979 sal_Bool  SwDocStyleSheet::IsUsed() const
1980 {
1981 	if( !bPhysical )
1982 	{
1983 		SwDocStyleSheet* pThis = (SwDocStyleSheet*)this;
1984 		pThis->FillStyleSheet( FillOnlyName );
1985 	}
1986 
1987 	// immer noch nicht ?
1988 	if( !bPhysical )
1989 		return sal_False;
1990 
1991 	const SwModify* pMod;
1992 	switch( nFamily )
1993 	{
1994 	case SFX_STYLE_FAMILY_CHAR : pMod = pCharFmt;	break;
1995 	case SFX_STYLE_FAMILY_PARA : pMod = pColl;		break;
1996 	case SFX_STYLE_FAMILY_FRAME: pMod = pFrmFmt;	break;
1997 	case SFX_STYLE_FAMILY_PAGE : pMod = pDesc;		break;
1998 
1999 	case SFX_STYLE_FAMILY_PSEUDO:
2000 			return pNumRule ? rDoc.IsUsed( *pNumRule ) : sal_False;
2001 
2002 	default:
2003 		ASSERT(sal_False, "unknown style family");
2004 		return sal_False;
2005 	}
2006 	return rDoc.IsUsed( *pMod );
2007 }
2008 
2009 
GetHelpId(String & rFile)2010 sal_uLong  SwDocStyleSheet::GetHelpId( String& rFile )
2011 {
2012 static String sTemplateHelpFile = String::CreateFromAscii("swrhlppi.hlp");
2013 
2014     sal_uInt16 nId = 0;
2015     sal_uInt16 nPoolId = 0;
2016 	unsigned char nFileId = UCHAR_MAX;
2017 
2018 	rFile = sTemplateHelpFile;
2019 
2020 	const SwFmt* pTmpFmt = 0;
2021 	switch( nFamily )
2022 	{
2023 	case SFX_STYLE_FAMILY_CHAR :
2024 		if( !pCharFmt &&
2025 			0 == (pCharFmt = lcl_FindCharFmt( rDoc, aName, 0, sal_False )) )
2026 		{
2027 			nId = SwStyleNameMapper::GetPoolIdFromUIName( aName, nsSwGetPoolIdFromName::GET_POOLID_CHRFMT );
2028 			return USHRT_MAX == nId ? 0 : nId;
2029 		}
2030 		pTmpFmt = pCharFmt;
2031 		break;
2032 
2033 	case SFX_STYLE_FAMILY_PARA:
2034 		if( !pColl &&
2035 			0 == ( pColl = lcl_FindParaFmt( rDoc, aName, 0, sal_False )) )
2036 		{
2037 			nId = SwStyleNameMapper::GetPoolIdFromUIName( aName, nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL );
2038 			return USHRT_MAX == nId ? 0 : nId;
2039 		}
2040 		pTmpFmt = pColl;
2041 		break;
2042 
2043 	case SFX_STYLE_FAMILY_FRAME:
2044 		if( !pFrmFmt &&
2045 			0 == ( pFrmFmt = lcl_FindFrmFmt( rDoc, aName, 0, sal_False ) ) )
2046 		{
2047 			nId = SwStyleNameMapper::GetPoolIdFromUIName( aName, nsSwGetPoolIdFromName::GET_POOLID_FRMFMT );
2048 			return USHRT_MAX == nId ? 0 : nId;
2049 		}
2050 		pTmpFmt = pFrmFmt;
2051 		break;
2052 
2053 	case SFX_STYLE_FAMILY_PAGE:
2054 		if( !pDesc &&
2055 			0 == ( pDesc = lcl_FindPageDesc( rDoc, aName, 0, sal_False ) ) )
2056 		{
2057 			nId = SwStyleNameMapper::GetPoolIdFromUIName( aName, nsSwGetPoolIdFromName::GET_POOLID_PAGEDESC );
2058 			return USHRT_MAX == nId ? 0 : nId;
2059 		}
2060 
2061 		nId = pDesc->GetPoolHelpId();
2062 		nFileId = pDesc->GetPoolHlpFileId();
2063 		nPoolId = pDesc->GetPoolFmtId();
2064 		break;
2065 
2066 	case SFX_STYLE_FAMILY_PSEUDO:
2067 		if( !pNumRule &&
2068 			0 == ( pNumRule = lcl_FindNumRule( rDoc, aName, 0, sal_False ) ) )
2069 		{
2070 			nId = SwStyleNameMapper::GetPoolIdFromUIName( aName, nsSwGetPoolIdFromName::GET_POOLID_NUMRULE );
2071 			return USHRT_MAX == nId ? 0 : nId;
2072 		}
2073 
2074 		nId = pNumRule->GetPoolHelpId();
2075 		nFileId = pNumRule->GetPoolHlpFileId();
2076 		nPoolId = pNumRule->GetPoolFmtId();
2077 		break;
2078 
2079 	default:
2080 		ASSERT(sal_False, "unknown style family");
2081 		return 0;
2082 	}
2083 
2084 	if( pTmpFmt )
2085 	{
2086 		nId = pTmpFmt->GetPoolHelpId();
2087 		nFileId = pTmpFmt->GetPoolHlpFileId();
2088 		nPoolId = pTmpFmt->GetPoolFmtId();
2089 	}
2090 
2091 	if( UCHAR_MAX != nFileId )
2092 	{
2093 		const String *pTemplate = rDoc.GetDocPattern( nFileId );
2094 		if( pTemplate )
2095 		{
2096 //			const String aHelpPath(MakeHelpPath(*pTemplate));
2097 			rFile = *pTemplate;
2098 		}
2099 	}
2100 	else if( !IsPoolUserFmt( nPoolId ) )
2101 	{
2102 		nId = nPoolId;
2103 	}
2104 
2105 	// weil sich der SFX so anstellt mit der HilfeId:
2106 	if( USHRT_MAX == nId )
2107 		nId = 0;		// entsp. keine Hilfe anzeigen
2108 
2109 	return nId;
2110 }
2111 
2112 
SetHelpId(const String & r,sal_uLong nId)2113 void  SwDocStyleSheet::SetHelpId( const String& r, sal_uLong nId )
2114 {
2115     sal_uInt8 nFileId = static_cast< sal_uInt8 >(rDoc.SetDocPattern( r ));
2116     sal_uInt16 nHId = static_cast< sal_uInt16 >(nId);     //!! SFX hat eigenmaechtig auf sal_uLong umgestellt!
2117 
2118 	SwFmt* pTmpFmt = 0;
2119 	switch( nFamily )
2120 	{
2121 	case SFX_STYLE_FAMILY_CHAR : pTmpFmt = pCharFmt;	break;
2122 	case SFX_STYLE_FAMILY_PARA : pTmpFmt = pColl;		break;
2123 	case SFX_STYLE_FAMILY_FRAME: pTmpFmt = pFrmFmt;		break;
2124 	case SFX_STYLE_FAMILY_PAGE :
2125 		((SwPageDesc*)pDesc)->SetPoolHelpId( nHId );
2126 		((SwPageDesc*)pDesc)->SetPoolHlpFileId( nFileId );
2127 		break;
2128 
2129 	case SFX_STYLE_FAMILY_PSEUDO:
2130 		((SwNumRule*)pNumRule)->SetPoolHelpId( nHId );
2131 		((SwNumRule*)pNumRule)->SetPoolHlpFileId( nFileId );
2132 		break;
2133 
2134 	default:
2135 		ASSERT(sal_False, "unknown style family");
2136 		return ;
2137 	}
2138 	if( pTmpFmt )
2139 	{
2140 		pTmpFmt->SetPoolHelpId( nHId );
2141 		pTmpFmt->SetPoolHlpFileId( nFileId );
2142 	}
2143 }
2144 
2145 
2146 /*  */
2147 
2148 /*--------------------------------------------------------------------
2149 	Beschreibung:	Methoden fuer den DocStyleSheetPool
2150  --------------------------------------------------------------------*/
2151 
SwDocStyleSheetPool(SwDoc & rDocument,sal_Bool bOrg)2152 SwDocStyleSheetPool::SwDocStyleSheetPool( SwDoc& rDocument, sal_Bool bOrg )
2153 : SfxStyleSheetBasePool( rDocument.GetAttrPool() )
2154 , mxStyleSheet( new SwDocStyleSheet( rDocument, aEmptyStr, *this, SFX_STYLE_FAMILY_CHAR, 0 ) )
2155 , rDoc( rDocument )
2156 {
2157 	bOrganizer = bOrg;
2158 }
2159 
~SwDocStyleSheetPool()2160  SwDocStyleSheetPool::~SwDocStyleSheetPool()
2161 {
2162 }
2163 
acquire()2164 void SAL_CALL SwDocStyleSheetPool::acquire(  ) throw ()
2165 {
2166 	comphelper::OWeakTypeObject::acquire();
2167 }
2168 
release()2169 void SAL_CALL SwDocStyleSheetPool::release(  ) throw ()
2170 {
2171 	comphelper::OWeakTypeObject::release();
2172 }
2173 
Make(const String & rName,SfxStyleFamily eFam,sal_uInt16 _nMask,sal_uInt16)2174 SfxStyleSheetBase&	 SwDocStyleSheetPool::Make(
2175 		const String& 	rName,
2176 		SfxStyleFamily	eFam,
2177         sal_uInt16          _nMask,
2178         sal_uInt16          /*nPos*/ )
2179 {
2180 	mxStyleSheet->PresetName(rName);
2181 	mxStyleSheet->PresetParent(aEmptyStr);
2182 	mxStyleSheet->PresetFollow(aEmptyStr);
2183     mxStyleSheet->SetMask(_nMask) ;
2184 	mxStyleSheet->SetFamily(eFam);
2185 	mxStyleSheet->SetPhysical(sal_True);
2186 	mxStyleSheet->Create();
2187 
2188 	return *mxStyleSheet.get();
2189 }
2190 
2191 
Create(const SfxStyleSheetBase &)2192 SfxStyleSheetBase*   SwDocStyleSheetPool::Create( const SfxStyleSheetBase& /*rOrg*/)
2193 {
2194 	ASSERT(sal_False, "Create in the SW style sheet pool is not working" );
2195 	return NULL;
2196 }
2197 
2198 
Create(const String &,SfxStyleFamily,sal_uInt16)2199 SfxStyleSheetBase*	 SwDocStyleSheetPool::Create( const String &,
2200 												SfxStyleFamily, sal_uInt16 )
2201 {
2202 	ASSERT( sal_False, "Create in the SW style sheet pool is not working" );
2203 	return NULL;
2204 }
2205 
Replace(SfxStyleSheetBase & rSource,SfxStyleSheetBase & rTarget)2206 void  SwDocStyleSheetPool::Replace( SfxStyleSheetBase& rSource,
2207 											SfxStyleSheetBase& rTarget )
2208 {
2209 	SfxStyleFamily eFamily( rSource.GetFamily() );
2210 	if( rSource.HasParentSupport())
2211 	{
2212 		const String& rParentName = rSource.GetParent();
2213 		if( 0 != rParentName.Len() )
2214 		{
2215 			SfxStyleSheetBase* pParentOfNew = Find( rParentName, eFamily );
2216 			if( pParentOfNew )
2217 				rTarget.SetParent( rParentName );
2218 		}
2219 	}
2220 	if( rSource.HasFollowSupport())
2221 	{
2222 		const String& rFollowName = rSource.GetFollow();
2223 		if( 0 != rFollowName.Len() )
2224 		{
2225 			SfxStyleSheetBase* pFollowOfNew = Find( rFollowName, eFamily );
2226 			if( pFollowOfNew )
2227 				rTarget.SetFollow( rFollowName );
2228 		}
2229 	}
2230 
2231 	SwImplShellAction aTmpSh( rDoc );
2232 
2233 	sal_Bool bSwSrcPool = GetAppName() == rSource.GetPool().GetAppName();
2234 	if( SFX_STYLE_FAMILY_PAGE == eFamily && bSwSrcPool )
2235 	{
2236 		// gesondert behandeln!!
2237 		SwPageDesc* pDestDsc =
2238 			(SwPageDesc*)((SwDocStyleSheet&)rTarget).GetPageDesc();
2239 		SwPageDesc* pCpyDsc =
2240 			(SwPageDesc*)((SwDocStyleSheet&)rSource).GetPageDesc();
2241 		rDoc.CopyPageDesc( *pCpyDsc, *pDestDsc );
2242 	}
2243 	else
2244 	{
2245 		const SwFmt *pSourceFmt = 0;
2246 		SwFmt *pTargetFmt = 0;
2247 		sal_uInt16 nPgDscPos = USHRT_MAX;
2248 		switch( eFamily )
2249 		{
2250 		case SFX_STYLE_FAMILY_CHAR :
2251 			if( bSwSrcPool )
2252 				pSourceFmt = ((SwDocStyleSheet&)rSource).GetCharFmt();
2253 			pTargetFmt = ((SwDocStyleSheet&)rTarget).GetCharFmt();
2254 			break;
2255 		case SFX_STYLE_FAMILY_PARA :
2256 			if( bSwSrcPool )
2257 				pSourceFmt = ((SwDocStyleSheet&)rSource).GetCollection();
2258 			pTargetFmt = ((SwDocStyleSheet&)rTarget).GetCollection();
2259 			break;
2260 		case SFX_STYLE_FAMILY_FRAME:
2261 			if( bSwSrcPool )
2262 				pSourceFmt = ((SwDocStyleSheet&)rSource).GetFrmFmt();
2263 			pTargetFmt = ((SwDocStyleSheet&)rTarget).GetFrmFmt();
2264 			break;
2265 		case SFX_STYLE_FAMILY_PAGE:
2266 			if( bSwSrcPool )
2267 				pSourceFmt = &((SwDocStyleSheet&)rSource).GetPageDesc()
2268 								->GetMaster();
2269 			{
2270 				SwPageDesc *pDesc = rDoc.FindPageDescByName(
2271 					((SwDocStyleSheet&)rTarget).GetPageDesc()->GetName(),
2272 					&nPgDscPos );
2273 
2274 				if( pDesc )
2275 					pTargetFmt = &pDesc->GetMaster();
2276 			}
2277 			break;
2278 		case SFX_STYLE_FAMILY_PSEUDO:
2279 			// Eine NumRule besteht nur aus einem Item, also muss man
2280 			// hier nichts loeschen.
2281 			break;
2282         default:; //prevent warning
2283 		}
2284 		if( pTargetFmt )
2285 		{
2286 			if( pSourceFmt )
2287 				pTargetFmt->DelDiffs( *pSourceFmt );
2288 			else if( USHRT_MAX != nPgDscPos )
2289                 pTargetFmt->ResetFmtAttr( RES_PAGEDESC, RES_FRMATR_END-1 );
2290 			else
2291             {
2292                 // --> OD 2007-01-25 #i73790# - method renamed
2293                 pTargetFmt->ResetAllFmtAttr();
2294                 // <--
2295             }
2296 
2297 			if( USHRT_MAX != nPgDscPos )
2298 				rDoc.ChgPageDesc( nPgDscPos,
2299                                   const_cast<const SwDoc &>(rDoc).
2300                                   GetPageDesc(nPgDscPos) );
2301 		}
2302 		((SwDocStyleSheet&)rTarget).SetItemSet( rSource.GetItemSet() );
2303 	}
2304 }
2305 
CreateIterator(SfxStyleFamily eFam,sal_uInt16 _nMask)2306 SfxStyleSheetIteratorPtr SwDocStyleSheetPool::CreateIterator( SfxStyleFamily eFam, sal_uInt16 _nMask )
2307 {
2308     return SfxStyleSheetIteratorPtr(new SwStyleSheetIterator( this, eFam, _nMask ));
2309 }
2310 
dispose()2311 void SwDocStyleSheetPool::dispose()
2312 {
2313 	mxStyleSheet.clear();
2314 }
2315 
Remove(SfxStyleSheetBase * pStyle)2316 void SwDocStyleSheetPool::Remove( SfxStyleSheetBase* pStyle)
2317 {
2318 	if( !pStyle )
2319 		return;
2320 
2321 	sal_Bool bBroadcast = sal_True;
2322 	SwImplShellAction aTmpSh( rDoc );
2323 	const String& rName = pStyle->GetName();
2324 	switch( pStyle->GetFamily() )
2325 	{
2326 	case SFX_STYLE_FAMILY_CHAR:
2327 		{
2328 			SwCharFmt* pFmt = lcl_FindCharFmt(rDoc, rName, 0, sal_False );
2329 			if(pFmt)
2330 				rDoc.DelCharFmt(pFmt);
2331 		}
2332 		break;
2333 	case SFX_STYLE_FAMILY_PARA:
2334 		{
2335 			SwTxtFmtColl* pColl = lcl_FindParaFmt(rDoc, rName, 0, sal_False );
2336 			if(pColl)
2337 				rDoc.DelTxtFmtColl(pColl);
2338 		}
2339 		break;
2340 	case SFX_STYLE_FAMILY_FRAME:
2341 		{
2342 			SwFrmFmt* pFmt = lcl_FindFrmFmt(rDoc, rName, 0, sal_False );
2343 			if(pFmt)
2344 				rDoc.DelFrmFmt(pFmt);
2345 		}
2346 		break;
2347 	case SFX_STYLE_FAMILY_PAGE :
2348 		{
2349 			sal_uInt16 nPos;
2350 			if( rDoc.FindPageDescByName( rName, &nPos ))
2351 				rDoc.DelPageDesc( nPos );
2352 		}
2353 		break;
2354 
2355 	case SFX_STYLE_FAMILY_PSEUDO:
2356 		{
2357 			if( !rDoc.DelNumRule( rName ) )
2358 				// Broadcast nur versenden, wenn etwas geloescht wurde
2359 				bBroadcast = sal_False;
2360 		}
2361 		break;
2362 
2363 	default:
2364 		ASSERT(sal_False, "unknown style family");
2365 		bBroadcast = sal_False;
2366 	}
2367 
2368 	if( bBroadcast )
2369 		Broadcast( SfxStyleSheetHint( SFX_STYLESHEET_ERASED, *pStyle ) );
2370 }
2371 
2372 
2373 
SetParent(SfxStyleFamily eFam,const String & rStyle,const String & rParent)2374 sal_Bool  SwDocStyleSheetPool::SetParent( SfxStyleFamily eFam,
2375 								const String &rStyle, const String &rParent )
2376 {
2377 	SwFmt* pFmt = 0, *pParent = 0;
2378 	switch( eFam )
2379 	{
2380 	case SFX_STYLE_FAMILY_CHAR :
2381 		if( 0 != ( pFmt = lcl_FindCharFmt( rDoc, rStyle ) ) && rParent.Len() )
2382 			pParent = lcl_FindCharFmt(rDoc, rParent );
2383 		break;
2384 
2385 	case SFX_STYLE_FAMILY_PARA :
2386 		if( 0 != ( pFmt = lcl_FindParaFmt( rDoc, rStyle ) ) && rParent.Len() )
2387 			pParent = lcl_FindParaFmt( rDoc, rParent );
2388 		break;
2389 
2390 	case SFX_STYLE_FAMILY_FRAME:
2391 		if( 0 != ( pFmt = lcl_FindFrmFmt( rDoc, rStyle ) ) && rParent.Len() )
2392 			pParent = lcl_FindFrmFmt( rDoc, rParent );
2393 		break;
2394 
2395 	case SFX_STYLE_FAMILY_PAGE:
2396 	case SFX_STYLE_FAMILY_PSEUDO:
2397 		break;
2398 
2399 	default:
2400 		ASSERT(sal_False, "unknown style family");
2401 	}
2402 
2403 	sal_Bool bRet = sal_False;
2404 	if( pFmt && pFmt->DerivedFrom() &&
2405 		pFmt->DerivedFrom()->GetName() != rParent )
2406 	{
2407 		{
2408 			SwImplShellAction aTmpSh( rDoc );
2409 			bRet = pFmt->SetDerivedFrom( pParent );
2410 		}
2411 
2412 		if( bRet )
2413 		{
2414 			// nur fuer das Broadcasting
2415 			mxStyleSheet->PresetName( rStyle );
2416 			mxStyleSheet->PresetParent( rParent );
2417 			if( SFX_STYLE_FAMILY_PARA == eFam )
2418 				mxStyleSheet->PresetFollow( ((SwTxtFmtColl*)pFmt)->
2419 						GetNextTxtFmtColl().GetName() );
2420 			else
2421 				mxStyleSheet->PresetFollow( aEmptyStr );
2422 
2423 			Broadcast( SfxStyleSheetHint( SFX_STYLESHEET_MODIFIED,
2424 											*(mxStyleSheet.get()) ) );
2425 		}
2426 	}
2427 
2428 	return bRet;
2429 }
2430 
Find(const String & rName,SfxStyleFamily eFam,sal_uInt16 n)2431 SfxStyleSheetBase* SwDocStyleSheetPool::Find( const String& rName,
2432 											SfxStyleFamily eFam, sal_uInt16 n )
2433 {
2434 	sal_uInt16 nSMask = n;
2435 	if( SFX_STYLE_FAMILY_PARA == eFam && rDoc.get(IDocumentSettingAccess::HTML_MODE) )
2436 	{
2437 		// dann sind nur HTML-Vorlagen von Interesse
2438 		if( USHRT_MAX == nSMask )
2439 			nSMask = SWSTYLEBIT_HTML | SFXSTYLEBIT_USERDEF | SFXSTYLEBIT_USED;
2440 		else
2441 			nSMask &= SFXSTYLEBIT_USED | SFXSTYLEBIT_USERDEF |
2442 								SWSTYLEBIT_CONDCOLL | SWSTYLEBIT_HTML;
2443 		if( !nSMask )
2444 			nSMask = SWSTYLEBIT_HTML;
2445 	}
2446 
2447 	const sal_Bool bSearchUsed = ( n != SFXSTYLEBIT_ALL &&
2448 							 n & SFXSTYLEBIT_USED ) ? sal_True : sal_False;
2449 	const SwModify* pMod = 0;
2450 
2451 	mxStyleSheet->SetPhysical( sal_False );
2452 	mxStyleSheet->PresetName( rName );
2453 	mxStyleSheet->SetFamily( eFam );
2454 	sal_Bool bFnd = mxStyleSheet->FillStyleSheet( SwDocStyleSheet::FillOnlyName );
2455 
2456 	if( mxStyleSheet->IsPhysical() )
2457 	{
2458 		switch( eFam )
2459 		{
2460 		case SFX_STYLE_FAMILY_CHAR:
2461 			pMod = mxStyleSheet->GetCharFmt();
2462 			break;
2463 
2464 		case SFX_STYLE_FAMILY_PARA:
2465 			pMod = mxStyleSheet->GetCollection();
2466 			break;
2467 
2468 		case SFX_STYLE_FAMILY_FRAME:
2469 			pMod = mxStyleSheet->GetFrmFmt();
2470 			break;
2471 
2472 		case SFX_STYLE_FAMILY_PAGE:
2473 			pMod = mxStyleSheet->GetPageDesc();
2474 			break;
2475 
2476 		case SFX_STYLE_FAMILY_PSEUDO:
2477 			{
2478 				const SwNumRule* pRule = mxStyleSheet->GetNumRule();
2479 				if( pRule &&
2480 					!(bSearchUsed && (bOrganizer || rDoc.IsUsed(*pRule)) ) &&
2481 					(( nSMask & ~SFXSTYLEBIT_USED) == SFXSTYLEBIT_USERDEF
2482 							? !(pRule->GetPoolFmtId() & USER_FMT)
2483 								// benutzte gesucht und keine gefunden
2484 							: bSearchUsed ))
2485 					bFnd = sal_False;
2486 			}
2487 			break;
2488 
2489 		default:
2490 			ASSERT(sal_False, "unknown style family");
2491 		}
2492 	}
2493 
2494 	// dann noch die Maske auswerten:
2495 	if( pMod && !(bSearchUsed && (bOrganizer || rDoc.IsUsed(*pMod)) ) )
2496 	{
2497 		const sal_uInt16 nId = SFX_STYLE_FAMILY_PAGE == eFam
2498 						? ((SwPageDesc*)pMod)->GetPoolFmtId()
2499 						: ((SwFmt*)pMod)->GetPoolFmtId();
2500 
2501 		if( ( nSMask & ~SFXSTYLEBIT_USED) == SFXSTYLEBIT_USERDEF
2502 			? !(nId & USER_FMT)
2503 				// benutzte gesucht und keine gefunden
2504 			: bSearchUsed )
2505 			bFnd = sal_False;
2506 	}
2507 	return bFnd ? mxStyleSheet.get() : 0;
2508 }
2509 
2510 /*  */
2511 
SwStyleSheetIterator(SwDocStyleSheetPool * pBase,SfxStyleFamily eFam,sal_uInt16 n)2512 SwStyleSheetIterator::SwStyleSheetIterator( SwDocStyleSheetPool* pBase,
2513 								SfxStyleFamily eFam, sal_uInt16 n )
2514 	: SfxStyleSheetIterator( pBase, eFam, n ),
2515 	mxIterSheet( new SwDocStyleSheet( pBase->GetDoc(), aEmptyStr, *pBase, SFX_STYLE_FAMILY_CHAR, 0 ) ),
2516 	mxStyleSheet( new SwDocStyleSheet( pBase->GetDoc(), aEmptyStr, *pBase, SFX_STYLE_FAMILY_CHAR, 0 ) )
2517 {
2518 	bFirstCalled = sal_False;
2519 	nLastPos = 0;
2520 	StartListening( *pBase );
2521 }
2522 
~SwStyleSheetIterator()2523  SwStyleSheetIterator::~SwStyleSheetIterator()
2524 {
2525 	EndListening( mxIterSheet->GetPool() );
2526 }
2527 
Count()2528 sal_uInt16  SwStyleSheetIterator::Count()
2529 {
2530 	// Liste richtig fuellen lassen !!
2531 	if( !bFirstCalled )
2532 		First();
2533 	return aLst.Count();
2534 }
2535 
operator [](sal_uInt16 nIdx)2536 SfxStyleSheetBase*  SwStyleSheetIterator::operator[]( sal_uInt16 nIdx )
2537 {
2538 	// gefunden
2539 	if( !bFirstCalled )
2540 		First();
2541 	mxStyleSheet->PresetNameAndFamily( *aLst[ nIdx ] );
2542 	mxStyleSheet->SetPhysical( sal_False );
2543 	mxStyleSheet->FillStyleSheet( SwDocStyleSheet::FillOnlyName );
2544 
2545 	return mxStyleSheet.get();
2546 }
2547 
First()2548 SfxStyleSheetBase*  SwStyleSheetIterator::First()
2549 {
2550 	// Alte Liste loeschen
2551 	bFirstCalled = sal_True;
2552 	nLastPos = 0;
2553 	aLst.Erase();
2554 
2555 	// aktuellen loeschen
2556 	mxIterSheet->Reset();
2557 
2558 	SwDoc& rDoc = ((SwDocStyleSheetPool*)pBasePool)->GetDoc();
2559 	const sal_uInt16 nSrchMask = nMask;
2560     const sal_Bool bIsSearchUsed = SearchUsed();
2561 
2562 	const sal_Bool bOrganizer = ((SwDocStyleSheetPool*)pBasePool)->IsOrganizerMode();
2563 
2564 	if( nSearchFamily == SFX_STYLE_FAMILY_CHAR
2565 	 || nSearchFamily == SFX_STYLE_FAMILY_ALL )
2566 	{
2567 		const sal_uInt16 nArrLen = rDoc.GetCharFmts()->Count();
2568 		for( sal_uInt16 i = 0; i < nArrLen; i++ )
2569 		{
2570 			SwCharFmt* pFmt = (*rDoc.GetCharFmts())[ i ];
2571 			if( pFmt->IsDefault() && pFmt != rDoc.GetDfltCharFmt() )
2572 				continue;
2573 
2574             const sal_Bool  bUsed = bIsSearchUsed && (bOrganizer || rDoc.IsUsed(*pFmt));
2575 			if( !bUsed )
2576 			{
2577 				// Standard ist keine Benutzervorlage #46181#
2578 				const sal_uInt16 nId = rDoc.GetDfltCharFmt() == pFmt ?
2579                         sal_uInt16( RES_POOLCHR_INET_NORMAL ):
2580 								pFmt->GetPoolFmtId();
2581 				if( (nSrchMask & ~SFXSTYLEBIT_USED) == SFXSTYLEBIT_USERDEF
2582 					? !(nId & USER_FMT)
2583 						// benutzte gesucht und keine gefunden
2584                     : bIsSearchUsed )
2585 				continue;
2586 
2587 				if( rDoc.get(IDocumentSettingAccess::HTML_MODE) && !(nId & USER_FMT) &&
2588 					!( RES_POOLCHR_HTML_BEGIN <= nId &&
2589 						  nId < RES_POOLCHR_HTML_END ) &&
2590 					RES_POOLCHR_INET_NORMAL != nId &&
2591 					RES_POOLCHR_INET_VISIT != nId &&
2592 					RES_POOLCHR_FOOTNOTE  != nId &&
2593 					RES_POOLCHR_ENDNOTE != nId )
2594 					continue;
2595 			}
2596 
2597 			aLst.Append( cCHAR, pFmt == rDoc.GetDfltCharFmt()
2598 						? (const String&) *SwStyleNameMapper::GetTextUINameArray()[ RES_POOLCOLL_STANDARD -
2599 												RES_POOLCOLL_TEXT_BEGIN ]
2600 						: pFmt->GetName() );
2601 		}
2602 
2603 		// PoolFormate
2604 		//
2605 		if( nSrchMask == SFXSTYLEBIT_ALL )
2606 		{
2607 			if( !rDoc.get(IDocumentSettingAccess::HTML_MODE) )
2608 				AppendStyleList(SwStyleNameMapper::GetChrFmtUINameArray(),
2609                                 bIsSearchUsed, nsSwGetPoolIdFromName::GET_POOLID_CHRFMT, cCHAR);
2610 			else
2611 			{
2612 				aLst.Append( cCHAR, *SwStyleNameMapper::GetChrFmtUINameArray()[
2613 						RES_POOLCHR_INET_NORMAL - RES_POOLCHR_BEGIN ] );
2614 				aLst.Append( cCHAR, *SwStyleNameMapper::GetChrFmtUINameArray()[
2615 						RES_POOLCHR_INET_VISIT - RES_POOLCHR_BEGIN ] );
2616 				aLst.Append( cCHAR, *SwStyleNameMapper::GetChrFmtUINameArray()[
2617 						RES_POOLCHR_ENDNOTE - RES_POOLCHR_BEGIN ] );
2618 				aLst.Append( cCHAR, *SwStyleNameMapper::GetChrFmtUINameArray()[
2619 						RES_POOLCHR_FOOTNOTE - RES_POOLCHR_BEGIN ] );
2620 			}
2621 			AppendStyleList(SwStyleNameMapper::GetHTMLChrFmtUINameArray(),
2622                                 bIsSearchUsed, nsSwGetPoolIdFromName::GET_POOLID_CHRFMT, cCHAR);
2623 		}
2624 	}
2625 
2626 	if( nSearchFamily == SFX_STYLE_FAMILY_PARA ||
2627 		nSearchFamily == SFX_STYLE_FAMILY_ALL )
2628 	{
2629 		sal_uInt16 nSMask = nSrchMask;
2630 		if( rDoc.get(IDocumentSettingAccess::HTML_MODE) )
2631 		{
2632 			// dann sind nur HTML-Vorlagen von Interesse
2633 			if( USHRT_MAX == nSMask )
2634 				nSMask = SWSTYLEBIT_HTML | SFXSTYLEBIT_USERDEF |
2635 							SFXSTYLEBIT_USED;
2636 			else
2637 				nSMask &= SFXSTYLEBIT_USED | SFXSTYLEBIT_USERDEF |
2638 								SWSTYLEBIT_CONDCOLL | SWSTYLEBIT_HTML;
2639 			if( !nSMask )
2640 				nSMask = SWSTYLEBIT_HTML;
2641 		}
2642 
2643 		const sal_uInt16 nArrLen = rDoc.GetTxtFmtColls()->Count();
2644 		for( sal_uInt16 i = 0; i < nArrLen; i++ )
2645 		{
2646 			SwTxtFmtColl* pColl = (*rDoc.GetTxtFmtColls())[ i ];
2647 
2648 			if(pColl->IsDefault())
2649 				continue;
2650 
2651 			const sal_Bool bUsed = bOrganizer || rDoc.IsUsed(*pColl);
2652             if( !(bIsSearchUsed && bUsed ))
2653 			{
2654 				const sal_uInt16 nId = pColl->GetPoolFmtId();
2655 				switch ( (nSMask & ~SFXSTYLEBIT_USED) )
2656 				{
2657 				case SFXSTYLEBIT_USERDEF:
2658 					if(!IsPoolUserFmt(nId)) continue;
2659 					break;
2660 				case SWSTYLEBIT_TEXT:
2661 					if((nId & COLL_GET_RANGE_BITS) != COLL_TEXT_BITS) continue;
2662 					break;
2663 				case SWSTYLEBIT_CHAPTER:
2664 					if((nId  & COLL_GET_RANGE_BITS) != COLL_DOC_BITS) continue;
2665 					break;
2666 				case SWSTYLEBIT_LIST:
2667 					if((nId  & COLL_GET_RANGE_BITS) != COLL_LISTS_BITS) continue;
2668 					break;
2669 				case SWSTYLEBIT_IDX:
2670 					if((nId  & COLL_GET_RANGE_BITS) != COLL_REGISTER_BITS) continue;
2671 					break;
2672 				case SWSTYLEBIT_EXTRA:
2673 					if((nId  & COLL_GET_RANGE_BITS) != COLL_EXTRA_BITS) continue;
2674 					break;
2675 
2676 				case SWSTYLEBIT_HTML | SFXSTYLEBIT_USERDEF:
2677 					if(IsPoolUserFmt(nId))
2678 						break;
2679 					// ansonten weiter
2680 				case SWSTYLEBIT_HTML:
2681 					if( (nId  & COLL_GET_RANGE_BITS) != COLL_HTML_BITS)
2682 					{
2683 						// einige wollen wir aber auch in dieser Section sehen
2684 						sal_Bool bWeiter = sal_True;
2685 						switch( nId )
2686 						{
2687 						case RES_POOLCOLL_SENDADRESS:	//	--> ADDRESS
2688 						case RES_POOLCOLL_TABLE_HDLN:	//	--> TH
2689 						case RES_POOLCOLL_TABLE:		//	--> TD
2690 						case RES_POOLCOLL_TEXT:			// 	--> P
2691 						case RES_POOLCOLL_HEADLINE_BASE://	--> H
2692 						case RES_POOLCOLL_HEADLINE1:	//	--> H1
2693 						case RES_POOLCOLL_HEADLINE2:	//	--> H2
2694 						case RES_POOLCOLL_HEADLINE3:	//	--> H3
2695 						case RES_POOLCOLL_HEADLINE4:	//	--> H4
2696 						case RES_POOLCOLL_HEADLINE5:	//	--> H5
2697 						case RES_POOLCOLL_HEADLINE6:	//	--> H6
2698 						case RES_POOLCOLL_STANDARD:		//	--> P
2699 						case RES_POOLCOLL_FOOTNOTE:
2700 						case RES_POOLCOLL_ENDNOTE:
2701 							bWeiter = sal_False;
2702 							break;
2703 						}
2704 						if( bWeiter )
2705 							continue;
2706 					}
2707 					break;
2708 				case SWSTYLEBIT_CONDCOLL:
2709 					if( RES_CONDTXTFMTCOLL != pColl->Which() ) continue;
2710 					break;
2711 				default:
2712 					// benutzte gesucht und keine gefunden
2713                     if( bIsSearchUsed )
2714 						continue;
2715 				}
2716 			}
2717 			aLst.Append( cPARA, pColl->GetName() );
2718 		}
2719 
2720 		const sal_Bool bAll = nSMask == SFXSTYLEBIT_ALL;
2721 		if ( bAll || (nSMask & ~SFXSTYLEBIT_USED) == SWSTYLEBIT_TEXT )
2722 			AppendStyleList(SwStyleNameMapper::GetTextUINameArray(),
2723                             bIsSearchUsed, nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL, cPARA );
2724 		if ( bAll || (nSMask & ~SFXSTYLEBIT_USED) == SWSTYLEBIT_CHAPTER )
2725 			AppendStyleList(SwStyleNameMapper::GetDocUINameArray(),
2726                             bIsSearchUsed, nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL, cPARA ) ;
2727 		if ( bAll || (nSMask & ~SFXSTYLEBIT_USED) == SWSTYLEBIT_LIST )
2728 			AppendStyleList(SwStyleNameMapper::GetListsUINameArray(),
2729                             bIsSearchUsed, nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL, cPARA ) ;
2730 		if ( bAll || (nSMask & ~SFXSTYLEBIT_USED) == SWSTYLEBIT_IDX )
2731 			AppendStyleList(SwStyleNameMapper::GetRegisterUINameArray(),
2732                             bIsSearchUsed, nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL, cPARA ) ;
2733 		if ( bAll || (nSMask & ~SFXSTYLEBIT_USED) == SWSTYLEBIT_EXTRA )
2734 			AppendStyleList(SwStyleNameMapper::GetExtraUINameArray(),
2735                             bIsSearchUsed, nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL, cPARA ) ;
2736 		if ( bAll || (nSMask & ~SFXSTYLEBIT_USED) == SWSTYLEBIT_CONDCOLL )
2737 		{
2738             if( !bIsSearchUsed ||
2739 				rDoc.IsPoolTxtCollUsed( RES_POOLCOLL_TEXT ))
2740 				aLst.Append( cPARA, *SwStyleNameMapper::GetTextUINameArray()[
2741 						RES_POOLCOLL_TEXT - RES_POOLCOLL_TEXT_BEGIN ] );
2742 		}
2743 		if ( bAll ||
2744 			(nSMask & ~SFXSTYLEBIT_USED) == SWSTYLEBIT_HTML ||
2745 			(nSMask & ~SFXSTYLEBIT_USED) ==
2746 						(SWSTYLEBIT_HTML | SFXSTYLEBIT_USERDEF) )
2747 		{
2748 			AppendStyleList(SwStyleNameMapper::GetHTMLUINameArray(),
2749                             bIsSearchUsed, nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL, cPARA ) ;
2750 			if( !bAll )
2751 			{
2752 				// dann auch die, die wir mappen:
2753 				static sal_uInt16 aPoolIds[] = {
2754 					RES_POOLCOLL_SENDADRESS,	//	--> ADDRESS
2755 					RES_POOLCOLL_TABLE_HDLN,	//	--> TH
2756 					RES_POOLCOLL_TABLE,		//	--> TD
2757 					RES_POOLCOLL_STANDARD,		//	--> P
2758 					RES_POOLCOLL_TEXT,			// 	--> P
2759 					RES_POOLCOLL_HEADLINE_BASE,	//	--> H
2760 					RES_POOLCOLL_HEADLINE1,	//	--> H1
2761 					RES_POOLCOLL_HEADLINE2,	//	--> H2
2762 					RES_POOLCOLL_HEADLINE3,	//	--> H3
2763 					RES_POOLCOLL_HEADLINE4,	//	--> H4
2764 					RES_POOLCOLL_HEADLINE5,	//	--> H5
2765 					RES_POOLCOLL_HEADLINE6,	//	--> H6
2766 					RES_POOLCOLL_FOOTNOTE,
2767 					RES_POOLCOLL_ENDNOTE,
2768 					0
2769 					};
2770 
2771 				sal_uInt16* pPoolIds = aPoolIds;
2772 				String s;
2773 				while( *pPoolIds )
2774 				{
2775                     if( !bIsSearchUsed || rDoc.IsPoolTxtCollUsed( *pPoolIds ) )
2776 						aLst.Append( cPARA,
2777 							s = SwStyleNameMapper::GetUIName( *pPoolIds, s ));
2778 					++pPoolIds;
2779 				}
2780 			}
2781 		}
2782 	}
2783 
2784 	if( nSearchFamily == SFX_STYLE_FAMILY_FRAME ||
2785 		nSearchFamily == SFX_STYLE_FAMILY_ALL )
2786 	{
2787 		const sal_uInt16 nArrLen = rDoc.GetFrmFmts()->Count();
2788 		for( sal_uInt16 i = 0; i < nArrLen; i++ )
2789 		{
2790 			SwFrmFmt* pFmt = (*rDoc.GetFrmFmts())[ i ];
2791 
2792 			if(pFmt->IsDefault() || pFmt->IsAuto())
2793             {
2794 				continue;
2795             }
2796 
2797 			const sal_uInt16 nId = pFmt->GetPoolFmtId();
2798             sal_Bool bUsed = bIsSearchUsed && ( bOrganizer || rDoc.IsUsed(*pFmt));
2799 			if( !bUsed )
2800 			{
2801 				if( (nSrchMask & ~SFXSTYLEBIT_USED) == SFXSTYLEBIT_USERDEF
2802 					? !(nId & USER_FMT)
2803 					// benutzte gesucht und keine gefunden
2804                     : bIsSearchUsed )
2805                 {
2806 					continue;
2807                 }
2808 			}
2809 
2810 			aLst.Append( cFRAME, pFmt->GetName() );
2811 		}
2812 
2813 		// PoolFormate
2814 		//
2815 		if ( nSrchMask == SFXSTYLEBIT_ALL )
2816 			AppendStyleList(SwStyleNameMapper::GetFrmFmtUINameArray(),
2817                                     bIsSearchUsed, nsSwGetPoolIdFromName::GET_POOLID_FRMFMT, cFRAME);
2818 	}
2819 
2820 	if( nSearchFamily == SFX_STYLE_FAMILY_PAGE ||
2821 		nSearchFamily == SFX_STYLE_FAMILY_ALL )
2822 	{
2823 		const sal_uInt16 nCount = rDoc.GetPageDescCnt();
2824 		for(sal_uInt16 i = 0; i < nCount; ++i)
2825 		{
2826 			const SwPageDesc& rDesc =
2827                 const_cast<const SwDoc &>(rDoc).GetPageDesc(i);
2828 			const sal_uInt16 nId = rDesc.GetPoolFmtId();
2829             sal_Bool bUsed = bIsSearchUsed && ( bOrganizer || rDoc.IsUsed(rDesc));
2830 			if( !bUsed )
2831 			{
2832 				if( (nSrchMask & ~SFXSTYLEBIT_USED) == SFXSTYLEBIT_USERDEF
2833 					? !(nId & USER_FMT)
2834 					// benutzte gesucht und keine gefunden
2835                     : bIsSearchUsed )
2836 					continue;
2837 			}
2838 
2839 			aLst.Append( cPAGE, rDesc.GetName() );
2840 		}
2841 		if ( nSrchMask == SFXSTYLEBIT_ALL )
2842 			AppendStyleList(SwStyleNameMapper::GetPageDescUINameArray(),
2843                             bIsSearchUsed, nsSwGetPoolIdFromName::GET_POOLID_PAGEDESC, cPAGE);
2844 	}
2845 
2846 	if( nSearchFamily == SFX_STYLE_FAMILY_PSEUDO ||
2847 		nSearchFamily == SFX_STYLE_FAMILY_ALL )
2848 	{
2849 		const SwNumRuleTbl& rNumTbl = rDoc.GetNumRuleTbl();
2850 		for(sal_uInt16 i = 0; i < rNumTbl.Count(); ++i)
2851 		{
2852 			const SwNumRule& rRule = *rNumTbl[ i ];
2853 			if( !rRule.IsAutoRule() )
2854 			{
2855                 sal_Bool bUsed = bIsSearchUsed && ( bOrganizer || rDoc.IsUsed(rRule) );
2856 				if( !bUsed )
2857 				{
2858 					if( (nSrchMask & ~SFXSTYLEBIT_USED) == SFXSTYLEBIT_USERDEF
2859 						? !(rRule.GetPoolFmtId() & USER_FMT)
2860 						// benutzte gesucht und keine gefunden
2861                         : bIsSearchUsed )
2862 						continue;
2863 				}
2864 
2865 				aLst.Append( cNUMRULE, rRule.GetName() );
2866 			}
2867 		}
2868 		if ( nSrchMask == SFXSTYLEBIT_ALL )
2869 			AppendStyleList(SwStyleNameMapper::GetNumRuleUINameArray(),
2870                             bIsSearchUsed, nsSwGetPoolIdFromName::GET_POOLID_NUMRULE, cNUMRULE);
2871 	}
2872 
2873 	if(aLst.Count() > 0)
2874 	{
2875 		nLastPos = USHRT_MAX;
2876 		return Next();
2877 	}
2878 	return 0;
2879 }
2880 
Next()2881 SfxStyleSheetBase*  SwStyleSheetIterator::Next()
2882 {
2883 	nLastPos++;
2884 	if(aLst.Count() > 0 && nLastPos < aLst.Count())
2885 	{
2886 		mxIterSheet->PresetNameAndFamily(*aLst[nLastPos]);
2887 		mxIterSheet->SetPhysical( sal_False );
2888 		mxIterSheet->SetMask( nMask );
2889 		if(mxIterSheet->pSet)
2890 		{
2891 			mxIterSheet->pSet->ClearItem(0);
2892 			mxIterSheet->pSet= 0;
2893 		}
2894 		return mxIterSheet.get();
2895 	}
2896 	return 0;
2897 }
2898 
Find(const UniString & rName)2899 SfxStyleSheetBase*  SwStyleSheetIterator::Find( const UniString& rName )
2900 {
2901 	// suchen
2902 	if( !bFirstCalled )
2903 		First();
2904 
2905 	nLastPos = lcl_FindName( aLst, nSearchFamily, rName );
2906 	if( USHRT_MAX != nLastPos )
2907 	{
2908 		// gefunden
2909 		mxStyleSheet->PresetNameAndFamily(*aLst[nLastPos]);
2910 		// neuer Name gesetzt, also bestimme seine Daten
2911 		mxStyleSheet->FillStyleSheet( SwDocStyleSheet::FillOnlyName );
2912 		if( !mxStyleSheet->IsPhysical() )
2913 			mxStyleSheet->SetPhysical( sal_False );
2914 
2915 		return mxStyleSheet.get();
2916 	}
2917 	return 0;
2918 }
2919 
AppendStyleList(const SvStringsDtor & rList,sal_Bool bTestUsed,sal_uInt16 nSection,char cType)2920 void SwStyleSheetIterator::AppendStyleList(const SvStringsDtor& rList,
2921 											sal_Bool 	bTestUsed,
2922 											sal_uInt16 nSection, char cType )
2923 {
2924 	if( bTestUsed )
2925 	{
2926 		SwDoc& rDoc = ((SwDocStyleSheetPool*)pBasePool)->GetDoc();
2927 		for ( sal_uInt16 i=0; i < rList.Count(); ++i )
2928 		{
2929 			sal_Bool bUsed = sal_False;
2930 			sal_uInt16 nId = SwStyleNameMapper::GetPoolIdFromUIName(*rList[i], (SwGetPoolIdFromName)nSection);
2931 			switch ( nSection )
2932 			{
2933 				case nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL:
2934 						bUsed = rDoc.IsPoolTxtCollUsed( nId );
2935 						break;
2936 				case nsSwGetPoolIdFromName::GET_POOLID_CHRFMT:
2937 						bUsed = rDoc.IsPoolFmtUsed( nId );
2938 						break;
2939 				case nsSwGetPoolIdFromName::GET_POOLID_FRMFMT:
2940 						bUsed = rDoc.IsPoolFmtUsed( nId );
2941 				case nsSwGetPoolIdFromName::GET_POOLID_PAGEDESC:
2942 						bUsed = rDoc.IsPoolPageDescUsed( nId );
2943 						break;
2944 				default:
2945 					ASSERT( sal_False, "unknown PoolFmt-Id" );
2946 			}
2947 			if ( bUsed )
2948 				aLst.Append( cType, *rList[i] );
2949 		}
2950 	}
2951 	else
2952 		for ( sal_uInt16 i=0; i < rList.Count(); ++i )
2953 			aLst.Append( cType, *rList[i] );
2954 }
2955 
Notify(SfxBroadcaster &,const SfxHint & rHint)2956 void  SwStyleSheetIterator::Notify( SfxBroadcaster&, const SfxHint& rHint )
2957 {
2958 	// suchen und aus der Anzeige-Liste entfernen !!
2959 	if( rHint.ISA( SfxStyleSheetHint ) &&
2960 		SFX_STYLESHEET_ERASED == ((SfxStyleSheetHint&) rHint).GetHint() )
2961 	{
2962 		SfxStyleSheetBase* pStyle = ((SfxStyleSheetHint&)rHint).GetStyleSheet();
2963 
2964         if (pStyle)
2965         {
2966             sal_uInt16 nTmpPos = lcl_FindName( aLst, pStyle->GetFamily(),
2967                                            pStyle->GetName() );
2968             if( nTmpPos < aLst.Count() )
2969                 aLst.DeleteAndDestroy( nTmpPos );
2970         }
2971 	}
2972 }
2973 
2974 
2975