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