xref: /trunk/main/sw/source/ui/app/docst.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_sw.hxx"
30 
31 #include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
32 #include <com/sun/star/beans/XPropertySet.hpp>
33 #include <com/sun/star/container/XNameAccess.hpp>
34 
35 #include <hintids.hxx>
36 #include <sfx2/app.hxx>
37 #include <svl/whiter.hxx>
38 #include <sfx2/templdlg.hxx>
39 #include <sfx2/tplpitem.hxx>
40 #include <sfx2/request.hxx>
41 #include <sfx2/dispatch.hxx>
42 #include <sfx2/newstyle.hxx>
43 #include <sfx2/printer.hxx>
44 #include <svl/macitem.hxx>
45 #include <editeng/brshitem.hxx>
46 #include <svl/stritem.hxx>
47 #include <svl/languageoptions.hxx>
48 #include <editeng/eeitem.hxx>
49 #include <svx/htmlmode.hxx>
50 #include <swmodule.hxx>
51 #include <wdocsh.hxx>
52 #include <fmtfsize.hxx>
53 #include <fchrfmt.hxx>
54 #include <svtools/htmlcfg.hxx>
55 #include <SwStyleNameMapper.hxx>
56 #include <SwRewriter.hxx>
57 #include <numrule.hxx>
58 #include <swundo.hxx>
59 
60 #include "view.hxx"
61 #include "wrtsh.hxx"
62 #include "docsh.hxx"
63 #include "uitool.hxx"
64 #include "cmdid.h"
65 #include "globals.hrc"
66 #include "viewopt.hxx"
67 #include <doc.hxx>
68 #include <IDocumentUndoRedo.hxx>
69 #include "swstyle.h"
70 #include "frmfmt.hxx"
71 #include "charfmt.hxx"
72 #include "poolfmt.hxx"
73 #include "pagedesc.hxx"
74 #include "docstyle.hxx"
75 #include "uiitems.hxx"
76 #include "fmtcol.hxx"
77 #include "frmmgr.hxx"       //SwFrmValid
78 #include "swevent.hxx"
79 #include "edtwin.hxx"
80 #include "unochart.hxx"
81 
82 #include "app.hrc"
83 #include <fmtui.hrc>
84 #include "swabstdlg.hxx"
85 // --> OD 2008-03-27 #refactorlists#
86 #include <list.hxx>
87 // <--
88 
89 #include <paratr.hxx>   //#outline level,add by zhaojianwei
90 
91 using namespace ::com::sun::star;
92 
93 /*--------------------------------------------------------------------
94     Beschreibung:
95  --------------------------------------------------------------------*/
96 
97 
98 void  SwDocShell::StateStyleSheet(SfxItemSet& rSet, SwWrtShell* pSh)
99 {
100     SfxWhichIter aIter(rSet);
101     sal_uInt16  nWhich  = aIter.FirstWhich();
102     sal_uInt16 nActualFamily = USHRT_MAX;
103 
104     SwWrtShell* pShell = pSh ? pSh : GetWrtShell();
105     if(!pShell)
106     {
107         while (nWhich)
108         {
109             rSet.DisableItem(nWhich);
110             nWhich = aIter.NextWhich();
111         }
112         return;
113     }
114     else
115     {
116         SfxViewFrame* pFrame = pShell->GetView().GetViewFrame();
117         const ISfxTemplateCommon* pCommon = SFX_APP()->GetCurrentTemplateCommon(pFrame->GetBindings());
118         if( pCommon )
119             nActualFamily = static_cast< sal_uInt16 >(pCommon->GetActualFamily());
120     }
121 
122     while (nWhich)
123     {
124         // aktuelle Vorlage zu jeder Familie ermitteln
125         //
126         String aName;
127         switch (nWhich)
128         {
129             case SID_STYLE_APPLY:
130             {//hier wird die Vorlage und ihre Familie an die StyleBox
131              //uebergeben, damit diese Familie angezeigt wird
132                 if(pShell->IsFrmSelected())
133                 {
134                     SwFrmFmt* pFmt = pShell->GetCurFrmFmt();
135                     if( pFmt )
136                         aName = pFmt->GetName();
137                 }
138                 else
139                 {
140                     SwTxtFmtColl* pColl = pShell->GetCurTxtFmtColl();
141                     if(pColl)
142                         aName = pColl->GetName();
143                 }
144                 rSet.Put(SfxTemplateItem(nWhich, aName));
145             }
146             break;
147             case SID_STYLE_FAMILY1:
148                 if( !pShell->IsFrmSelected() )
149                 {
150                     SwCharFmt* pFmt = pShell->GetCurCharFmt();
151                     if(pFmt)
152                         aName = pFmt->GetName();
153                     else
154                         aName = *SwStyleNameMapper::GetTextUINameArray()[
155                             RES_POOLCOLL_STANDARD - RES_POOLCOLL_TEXT_BEGIN ];
156                     rSet.Put(SfxTemplateItem(nWhich, aName));
157                 }
158                 break;
159 
160             case SID_STYLE_FAMILY2:
161                 if(!pShell->IsFrmSelected())
162                 {
163                     SwTxtFmtColl* pColl = pShell->GetCurTxtFmtColl();
164                     if(pColl)
165                         aName = pColl->GetName();
166 
167                     SfxTemplateItem aItem(nWhich, aName);
168 
169                     sal_uInt16 nMask = 0;
170                     if( pDoc->get(IDocumentSettingAccess::HTML_MODE) )
171                         nMask = SWSTYLEBIT_HTML;
172                     else
173                     {
174                         const int nSelection = pShell->GetFrmType(0,sal_True);
175                         if(pShell->GetCurTOX())
176                             nMask = SWSTYLEBIT_IDX  ;
177                         else if(nSelection & FRMTYPE_HEADER     ||
178                                 nSelection & FRMTYPE_FOOTER     ||
179                                 nSelection & FRMTYPE_TABLE      ||
180                                 nSelection & FRMTYPE_FLY_ANY    ||
181                                 nSelection & FRMTYPE_FOOTNOTE   ||
182                                 nSelection & FRMTYPE_FTNPAGE)
183                             nMask = SWSTYLEBIT_EXTRA;
184                         else
185                             nMask = SWSTYLEBIT_TEXT;
186                     }
187 
188                     aItem.SetValue(nMask);
189                     rSet.Put(aItem);
190                 }
191 
192                 break;
193 
194             case SID_STYLE_FAMILY3:
195 
196                 if( pDoc->get(IDocumentSettingAccess::HTML_MODE) )
197                     rSet.DisableItem( nWhich );
198                 else
199                 {
200                     SwFrmFmt* pFmt = pShell->GetCurFrmFmt();
201                     if(pFmt && pShell->IsFrmSelected())
202                     {
203                         aName = pFmt->GetName();
204                         rSet.Put(SfxTemplateItem(nWhich, aName));
205                     }
206                 }
207                 break;
208 
209             case SID_STYLE_FAMILY4:
210             {
211                 SvxHtmlOptions* pHtmlOpt = SvxHtmlOptions::Get();
212                 if( pDoc->get(IDocumentSettingAccess::HTML_MODE) && !pHtmlOpt->IsPrintLayoutExtension())
213                     rSet.DisableItem( nWhich );
214                 else
215                 {
216                     sal_uInt16 n = pShell->GetCurPageDesc( sal_False );
217                     if( n < pShell->GetPageDescCnt() )
218                         aName = pShell->GetPageDesc( n ).GetName();
219 
220                     rSet.Put(SfxTemplateItem(nWhich, aName));
221                 }
222             }
223             break;
224             case SID_STYLE_FAMILY5:
225                 {
226                     const SwNumRule* pRule = pShell->GetCurNumRule();
227                     if( pRule )
228                         aName = pRule->GetName();
229 
230                     rSet.Put(SfxTemplateItem(nWhich, aName));
231                 }
232                 break;
233 
234             case SID_STYLE_WATERCAN:
235             {
236                 SwEditWin& rEdtWin = pShell->GetView().GetEditWin();
237                 SwApplyTemplate* pApply = rEdtWin.GetApplyTemplate();
238                 rSet.Put(SfxBoolItem(nWhich, pApply && pApply->eType != 0));
239             }
240             break;
241             case SID_STYLE_UPDATE_BY_EXAMPLE:
242                 if( pShell->IsFrmSelected()
243                         ? SFX_STYLE_FAMILY_FRAME != nActualFamily
244                         : ( SFX_STYLE_FAMILY_FRAME == nActualFamily ||
245                             SFX_STYLE_FAMILY_PAGE == nActualFamily ||
246                             (SFX_STYLE_FAMILY_PSEUDO == nActualFamily && !pShell->GetCurNumRule())) )
247                 {
248                     rSet.DisableItem( nWhich );
249                 }
250                 break;
251 
252             case SID_STYLE_NEW_BY_EXAMPLE:
253                 if( (pShell->IsFrmSelected()
254                         ? SFX_STYLE_FAMILY_FRAME != nActualFamily
255                         : SFX_STYLE_FAMILY_FRAME == nActualFamily) ||
256                     (SFX_STYLE_FAMILY_PSEUDO == nActualFamily && !pShell->GetCurNumRule()) )
257                 {
258                     rSet.DisableItem( nWhich );
259                 }
260                 break;
261 
262             default:
263                 DBG_ERROR( "Invalid SlotId");
264         }
265         nWhich = aIter.NextWhich();
266     }
267 }
268 
269 
270 /*--------------------------------------------------------------------
271     Beschreibung:   StyleSheet-Requeste auswerten
272  --------------------------------------------------------------------*/
273 
274 
275 void SwDocShell::ExecStyleSheet( SfxRequest& rReq )
276 {
277     sal_uInt16  nSlot   = rReq.GetSlot();
278     sal_uInt16  nRet    = 0xffff;
279 
280     const SfxItemSet* pArgs = rReq.GetArgs();
281     const SfxPoolItem* pItem;
282     SwWrtShell* pActShell = 0;
283     sal_Bool bSetReturn = sal_True;
284     switch (nSlot)
285     {
286     case SID_STYLE_NEW:
287         if( pArgs && SFX_ITEM_SET == pArgs->GetItemState( SID_STYLE_FAMILY,
288             sal_False, &pItem ))
289         {
290             sal_uInt16 nFamily = ((const SfxUInt16Item*)pItem)->GetValue();
291 
292             String sName;
293             sal_uInt16 nMask = 0;
294             if( SFX_ITEM_SET == pArgs->GetItemState( SID_STYLE_NEW,
295                 sal_False, &pItem ))
296                 sName = ((const SfxStringItem*)pItem)->GetValue();
297             if( SFX_ITEM_SET == pArgs->GetItemState( SID_STYLE_MASK,
298                 sal_False, &pItem ))
299                 nMask = ((const SfxUInt16Item*)pItem)->GetValue();
300             String sParent;
301             if( SFX_ITEM_SET == pArgs->GetItemState( SID_STYLE_REFERENCE,
302                 sal_False, &pItem ))
303                 sParent = ((const SfxStringItem*)pItem)->GetValue();
304 
305             nRet = Edit( sName, sParent, nFamily, nMask, sal_True, sal_False, 0, rReq.IsAPI() );
306         }
307         break;
308 
309         case SID_STYLE_APPLY:
310             if( !pArgs )
311             {
312                 GetView()->GetViewFrame()->GetDispatcher()->Execute(SID_STYLE_DESIGNER, sal_False);
313                 break;
314             }
315             else
316             {
317                 // convert internal StyleName to DisplayName (slot implementation uses the latter)
318                 SFX_REQUEST_ARG( rReq, pNameItem, SfxStringItem, SID_APPLY_STYLE, sal_False );
319                 SFX_REQUEST_ARG( rReq, pFamilyItem, SfxStringItem, SID_STYLE_FAMILYNAME, sal_False );
320                 if ( pFamilyItem && pNameItem )
321                 {
322                     uno::Reference< style::XStyleFamiliesSupplier > xModel(GetModel(), uno::UNO_QUERY);
323                     try
324                     {
325                         uno::Reference< container::XNameAccess > xStyles;
326                         uno::Reference< container::XNameAccess > xCont = xModel->getStyleFamilies();
327                         xCont->getByName(pFamilyItem->GetValue()) >>= xStyles;
328                         uno::Reference< beans::XPropertySet > xInfo;
329                         xStyles->getByName( pNameItem->GetValue() ) >>= xInfo;
330                         ::rtl::OUString aUIName;
331                         xInfo->getPropertyValue( ::rtl::OUString::createFromAscii("DisplayName") ) >>= aUIName;
332                         if ( aUIName.getLength() )
333                             rReq.AppendItem( SfxStringItem( SID_STYLE_APPLY, aUIName ) );
334                     }
335                     catch( uno::Exception& )
336                     {
337                     }
338                 }
339             }
340 
341             // intentionally no break
342 
343         case SID_STYLE_EDIT:
344         case SID_STYLE_DELETE:
345         case SID_STYLE_WATERCAN:
346         case SID_STYLE_FAMILY:
347         case SID_STYLE_UPDATE_BY_EXAMPLE:
348         case SID_STYLE_NEW_BY_EXAMPLE:
349         {
350             String aParam;
351             sal_uInt16 nFamily = SFX_STYLE_FAMILY_PARA;
352             sal_uInt16 nMask = 0;
353 
354             if( !pArgs )
355             {
356                 nFamily = SFX_STYLE_FAMILY_PARA;
357 
358                 switch (nSlot)
359                 {
360                     case SID_STYLE_NEW_BY_EXAMPLE:
361                     {
362                         SfxNewStyleDlg *pDlg = new SfxNewStyleDlg( 0,
363                                                     *GetStyleSheetPool());
364                         if(RET_OK == pDlg->Execute())
365                         {
366                             aParam = pDlg->GetName();
367                             rReq.AppendItem(SfxStringItem(nSlot, aParam));
368                         }
369 
370                         delete pDlg;
371                     }
372                     break;
373 
374                     case SID_STYLE_UPDATE_BY_EXAMPLE:
375                     case SID_STYLE_EDIT:
376                     {
377                         SwTxtFmtColl* pColl = GetWrtShell()->GetCurTxtFmtColl();
378                         if(pColl)
379                         {
380                             aParam = pColl->GetName();
381                             rReq.AppendItem(SfxStringItem(nSlot, aParam));
382                         }
383                     }
384                     break;
385                 }
386             }
387             else
388             {
389                 ASSERT( pArgs->Count(), "SfxBug ItemSet ist leer");
390 
391                 SwWrtShell* pShell = GetWrtShell();
392                 if( SFX_ITEM_SET == pArgs->GetItemState(nSlot, sal_False, &pItem ))
393                     aParam = ((const SfxStringItem*)pItem)->GetValue();
394 
395                 if( SFX_ITEM_SET == pArgs->GetItemState(SID_STYLE_FAMILY,
396                     sal_False, &pItem ))
397                     nFamily = ((const SfxUInt16Item*)pItem)->GetValue();
398 
399                 if( SFX_ITEM_SET == pArgs->GetItemState(SID_STYLE_FAMILYNAME, sal_False, &pItem ))
400                 {
401                     String aFamily = ((const SfxStringItem*)pItem)->GetValue();
402                     if(aFamily.CompareToAscii("CharacterStyles") == COMPARE_EQUAL)
403                         nFamily = SFX_STYLE_FAMILY_CHAR;
404                     else
405                     if(aFamily.CompareToAscii("ParagraphStyles") == COMPARE_EQUAL)
406                         nFamily = SFX_STYLE_FAMILY_PARA;
407                     else
408                     if(aFamily.CompareToAscii("PageStyles") == COMPARE_EQUAL)
409                         nFamily = SFX_STYLE_FAMILY_PAGE;
410                     else
411                     if(aFamily.CompareToAscii("FrameStyles") == COMPARE_EQUAL)
412                         nFamily = SFX_STYLE_FAMILY_FRAME;
413                     else
414                     if(aFamily.CompareToAscii("NumberingStyles") == COMPARE_EQUAL)
415                         nFamily = SFX_STYLE_FAMILY_PSEUDO;
416                 }
417 
418                 if( SFX_ITEM_SET == pArgs->GetItemState(SID_STYLE_MASK,
419                     sal_False, &pItem ))
420                     nMask = ((const SfxUInt16Item*)pItem)->GetValue();
421                 if( SFX_ITEM_SET == pArgs->GetItemState(FN_PARAM_WRTSHELL,
422                     sal_False, &pItem ))
423                     pActShell = pShell = (SwWrtShell*)((SwPtrItem*)pItem)->GetValue();
424 
425                 if( nSlot == SID_STYLE_UPDATE_BY_EXAMPLE )
426                 {
427                     switch( nFamily )
428                     {
429                         case SFX_STYLE_FAMILY_PARA:
430                         {
431                             SwTxtFmtColl* pColl = pShell->GetCurTxtFmtColl();
432                             if(pColl)
433                                 aParam = pColl->GetName();
434                         }
435                         break;
436                         case SFX_STYLE_FAMILY_FRAME:
437                         {
438                             SwFrmFmt* pFrm = pWrtShell->GetCurFrmFmt();
439                             if( pFrm )
440                                 aParam = pFrm->GetName();
441                         }
442                         break;
443                         case SFX_STYLE_FAMILY_CHAR:
444                         {
445                             SwCharFmt* pChar = pWrtShell->GetCurCharFmt();
446                             if( pChar )
447                                 aParam = pChar->GetName();
448                         }
449                         break;
450                         case SFX_STYLE_FAMILY_PSEUDO:
451                         if(SFX_ITEM_SET == pArgs->GetItemState(SID_STYLE_UPD_BY_EX_NAME, sal_False, &pItem))
452                         {
453                             aParam = ((const SfxStringItem*)pItem)->GetValue();
454                         }
455                         break;
456                     }
457                     rReq.AppendItem(SfxStringItem(nSlot, aParam));
458                 }
459             }
460             if (aParam.Len() || nSlot == SID_STYLE_WATERCAN )
461             {
462                 switch(nSlot)
463                 {
464                     case SID_STYLE_EDIT:
465                         nRet = Edit(aParam, aEmptyStr, nFamily, nMask, sal_False, sal_False, pActShell );
466                         break;
467                     case SID_STYLE_DELETE:
468                         nRet = Delete(aParam, nFamily);
469                         break;
470                     case SID_STYLE_APPLY:
471                         // Shellwechsel in ApplyStyles
472                         nRet = ApplyStyles(aParam, nFamily, pActShell, rReq.GetModifier() );
473                         break;
474                     case SID_STYLE_WATERCAN:
475                         nRet = DoWaterCan(aParam, nFamily);
476                         break;
477                     case SID_STYLE_UPDATE_BY_EXAMPLE:
478                         nRet = UpdateStyle(aParam, nFamily, pActShell);
479                         break;
480                     case SID_STYLE_NEW_BY_EXAMPLE:
481                     {
482                         nRet = MakeByExample(aParam, nFamily, nMask, pActShell );
483                         SfxTemplateDialog* pDlg = SFX_APP()->GetTemplateDialog();
484 
485                         if(pDlg && pDlg->IsVisible())
486                             pDlg->Update();
487                     }
488                     break;
489 
490                     default:
491                         DBG_ERROR( "Falsche Slot-Id");
492                 }
493 
494                 rReq.Done();
495             }
496 
497             break;
498         }
499     }
500 
501     if(bSetReturn)
502     {
503         if(rReq.IsAPI()) // Basic bekommt nur sal_True oder sal_False
504             rReq.SetReturnValue(SfxUInt16Item(nSlot, nRet !=0));
505         else
506             rReq.SetReturnValue(SfxUInt16Item(nSlot, nRet));
507     }
508 
509 }
510 
511 /*--------------------------------------------------------------------
512     Beschreibung:   Edit
513  --------------------------------------------------------------------*/
514 
515 
516 sal_uInt16 SwDocShell::Edit( const String &rName, const String &rParent, sal_uInt16 nFamily, sal_uInt16 nMask,
517                          sal_Bool bNew, sal_Bool bColumn, SwWrtShell* pActShell,
518                          sal_Bool bBasic )
519 {
520     ASSERT(GetWrtShell(), "Keine Shell, keine Styles");
521     SfxStyleSheetBase *pStyle = 0;
522 
523     sal_uInt16 nRet = nMask;
524     sal_Bool bModified = pDoc->IsModified();
525 
526     if( bNew )
527     {
528         if( SFXSTYLEBIT_ALL != nMask && SFXSTYLEBIT_USED != nMask )
529             nMask |= SFXSTYLEBIT_USERDEF;
530         else
531             nMask = SFXSTYLEBIT_USERDEF;
532 
533         pStyle = &mxBasePool->Make( rName, (SfxStyleFamily)nFamily, nMask );
534 
535         // die aktuellen als Parent setzen
536         SwDocStyleSheet* pDStyle = (SwDocStyleSheet*)pStyle;
537         switch( nFamily )
538         {
539             case SFX_STYLE_FAMILY_PARA:
540             {
541                 if(rParent.Len())
542                 {
543                     SwTxtFmtColl* pColl = pWrtShell->FindTxtFmtCollByName( rParent );
544                     if(!pColl)
545                     {
546                         sal_uInt16 nId = SwStyleNameMapper::GetPoolIdFromUIName(rParent, nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL);
547                         if(USHRT_MAX != nId)
548                             pColl =  pWrtShell->GetTxtCollFromPool( nId );
549                     }
550                     pDStyle->GetCollection()->SetDerivedFrom( pColl );
551                     pDStyle->PresetParent( rParent );
552 
553                     //#outline level,add by zhaojianwei
554                      /*When a new paragraph style is created based on a "to outline style
555                         assigned" paragraph style, the outline level attribute and the list
556                         style attribute of the new paragraph style have to be set to 0
557                         respectively "".*/
558                     if( pColl->IsAssignedToListLevelOfOutlineStyle())
559                     {
560                         SwNumRuleItem aItem(aEmptyStr);
561                         pDStyle->GetCollection()->SetFmtAttr( aItem );
562                         pDStyle->GetCollection()->SetAttrOutlineLevel( 0 );
563                     }
564                     //<-end,zhaojianwei
565 
566                 }
567                 else
568                 {
569                     SwTxtFmtColl* pColl = pWrtShell->GetCurTxtFmtColl();
570                     pDStyle->GetCollection()->SetDerivedFrom( pColl );
571                     if( pColl )
572                         pDStyle->PresetParent( pColl->GetName() );
573                 }
574             }
575             break;
576             case SFX_STYLE_FAMILY_CHAR:
577             {
578                 if(rParent.Len())
579                 {
580                     SwCharFmt* pCFmt = pWrtShell->FindCharFmtByName( rParent );
581                     if(!pCFmt)
582                     {
583                         sal_uInt16 nId = SwStyleNameMapper::GetPoolIdFromUIName(rParent, nsSwGetPoolIdFromName::GET_POOLID_CHRFMT);
584                         if(USHRT_MAX != nId)
585                             pCFmt =  pWrtShell->GetCharFmtFromPool( nId );
586                     }
587 
588                     pDStyle->GetCharFmt()->SetDerivedFrom( pCFmt );
589                     pDStyle->PresetParent( rParent );
590                 }
591                 else
592                 {
593                     SwCharFmt* pCFmt = pWrtShell->GetCurCharFmt();
594                     pDStyle->GetCharFmt()->SetDerivedFrom( pCFmt );
595                         if( pCFmt )
596                             pDStyle->PresetParent( pCFmt->GetName() );
597                 }
598             }
599             break;
600             case SFX_STYLE_FAMILY_FRAME :
601             {
602                 if(rParent.Len())
603                 {
604                     SwFrmFmt* pFFmt = pWrtShell->GetDoc()->FindFrmFmtByName( rParent );
605                     if(!pFFmt)
606                     {
607                         sal_uInt16 nId = SwStyleNameMapper::GetPoolIdFromUIName(rParent, nsSwGetPoolIdFromName::GET_POOLID_FRMFMT);
608                         if(USHRT_MAX != nId)
609                             pFFmt =  pWrtShell->GetFrmFmtFromPool( nId );
610                     }
611                     pDStyle->GetFrmFmt()->SetDerivedFrom( pFFmt );
612                     pDStyle->PresetParent( rParent );
613                 }
614             }
615             break;
616         }
617     }
618     else
619     {
620         pStyle = mxBasePool->Find( rName, (SfxStyleFamily)nFamily );
621         ASSERT(pStyle, "Vorlage nicht gefunden");
622     }
623 
624     if(!pStyle)
625         return sal_False;
626 
627     // Dialoge zusammenstoepseln
628     //
629     rtl::Reference< SwDocStyleSheet > xTmp( new SwDocStyleSheet( *(SwDocStyleSheet*)pStyle ) );
630     if( SFX_STYLE_FAMILY_PARA == nFamily )
631     {
632         SfxItemSet& rSet = xTmp->GetItemSet();
633         ::SwToSfxPageDescAttr( rSet );
634         // erstmal nur eine Null
635         rSet.Put(SwBackgroundDestinationItem(SID_PARA_BACKGRND_DESTINATION, 0));
636         // --> OD 2008-02-13 #newlistlevelattrs#
637         // merge list level indent attributes into the item set if needed
638         xTmp->MergeIndentAttrsOfListStyle( rSet );
639         // <--
640     }
641 /*  else if( SFX_STYLE_FAMILY_FRAME == nFamily )
642     {
643         // Auskommentiert wegen Bug #45776 (per default keine Breite&Groesse in Rahmenvorlagen)
644         SfxItemSet& rSet = aTmp.GetItemSet();
645         if( SFX_ITEM_SET != rSet.GetItemState( RES_FRM_SIZE ))
646         {
647             // dann sollten wir spaetesten hier eines anlegen
648             SwFrmValid aFrmDefValues;
649             rSet.Put( SwFmtFrmSize( ATT_VAR_SIZE, aFrmDefValues.nWidth,
650                                     aFrmDefValues.nHeight ));
651         }
652     }*/
653     else if( SFX_STYLE_FAMILY_CHAR == nFamily )
654     {
655         SfxItemSet& rSet = xTmp->GetItemSet();
656         const SfxPoolItem *pTmpBrush;
657         if( SFX_ITEM_SET == rSet.GetItemState( RES_CHRATR_BACKGROUND,
658             sal_True, &pTmpBrush ) )
659         {
660             SvxBrushItem aTmpBrush( *((SvxBrushItem*)pTmpBrush) );
661             aTmpBrush.SetWhich( RES_BACKGROUND );
662             rSet.Put( aTmpBrush );
663         }
664     }
665     if (!bBasic)
666     {
667         // vor dem Dialog wird der HtmlMode an der DocShell versenkt
668         sal_uInt16 nHtmlMode = ::GetHtmlMode(this);
669 
670         // In HTML mode, we do not always have a printer. In order to show
671         // the correct page size in the Format - Page dialog, we have to
672         // get one here.
673         SwWrtShell* pCurrShell = ( pActShell ? pActShell : pWrtShell );
674         if( ( HTMLMODE_ON & nHtmlMode ) &&
675             !pCurrShell->getIDocumentDeviceAccess()->getPrinter( false ) )
676             pCurrShell->InitPrt( pCurrShell->getIDocumentDeviceAccess()->getPrinter( true ) );
677 
678         PutItem(SfxUInt16Item(SID_HTML_MODE, nHtmlMode));
679         FieldUnit eMetric = ::GetDfltMetric(0 != (HTMLMODE_ON&nHtmlMode));
680         SW_MOD()->PutItem(SfxUInt16Item(SID_ATTR_METRIC, static_cast< sal_uInt16 >(eMetric)));
681         SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
682         DBG_ASSERT(pFact, "Dialogdiet fail!");
683         SfxAbstractTabDialog* pDlg = pFact->CreateTemplateDialog( DLG_TEMPLATE_BASE,
684                                                     0, *(xTmp.get()), nFamily, bColumn,
685                                                     pActShell ? pActShell : pWrtShell, bNew);
686         DBG_ASSERT(pDlg, "Dialogdiet fail!");
687         if(RET_OK == pDlg->Execute())
688         {
689             GetWrtShell()->StartAllAction();
690 
691             // nur bei Absatz-Vorlagen die Maske neu setzen
692             if( bNew )
693             {
694                 nRet = SFX_STYLE_FAMILY_PARA == pStyle->GetFamily()
695                         ? xTmp->GetMask()
696                         : SFXSTYLEBIT_USERDEF;
697             }
698             else if( pStyle->GetMask() != xTmp->GetMask() )
699                 nRet = xTmp->GetMask();
700 
701             if( SFX_STYLE_FAMILY_PARA == nFamily )
702             {
703                 SfxItemSet aSet( *pDlg->GetOutputItemSet() );
704                 ::SfxToSwPageDescAttr( *GetWrtShell(), aSet  );
705                 // --> OD 2008-02-12 #newlistlevelattrs#
706                 // reset indent attributes at paragraph style, if a list style
707                 // will be applied and no indent attributes will be applied.
708                 xTmp->SetItemSet( aSet, true );
709                 // <--
710             }
711             else
712             {
713                 if(SFX_STYLE_FAMILY_PAGE == nFamily)
714                 {
715                     static const sal_uInt16 aInval[] = {
716                         SID_IMAGE_ORIENTATION,
717                         SID_ATTR_CHAR_FONT,
718                         FN_INSERT_CTRL, FN_INSERT_OBJ_CTRL, 0};
719                     pView->GetViewFrame()->GetBindings().Invalidate(aInval);
720                 }
721                 SfxItemSet aTmpSet( *pDlg->GetOutputItemSet() );
722                 if( SFX_STYLE_FAMILY_CHAR == nFamily )
723                 {
724                     const SfxPoolItem *pTmpBrush;
725                     if( SFX_ITEM_SET == aTmpSet.GetItemState( RES_BACKGROUND,
726                         sal_False, &pTmpBrush ) )
727                     {
728                         SvxBrushItem aTmpBrush( *((SvxBrushItem*)pTmpBrush) );
729                         aTmpBrush.SetWhich( RES_CHRATR_BACKGROUND );
730                         aTmpSet.Put( aTmpBrush );
731                     }
732                     aTmpSet.ClearItem( RES_BACKGROUND );
733                 }
734                 xTmp->SetItemSet( aTmpSet );
735 
736                 if( SFX_STYLE_FAMILY_PAGE == nFamily && SvtLanguageOptions().IsCTLFontEnabled() )
737                 {
738                     const SfxPoolItem *pItem = NULL;
739                     if( aTmpSet.GetItemState( GetPool().GetTrueWhich( SID_ATTR_FRAMEDIRECTION, sal_False ) , sal_True, &pItem ) == SFX_ITEM_SET )
740                         SwChartHelper::DoUpdateAllCharts( pDoc );
741                 }
742             }
743             if(SFX_STYLE_FAMILY_PAGE == nFamily)
744                 pView->InvalidateRulerPos();
745 
746             if( bNew )
747                 mxBasePool->Broadcast( SfxStyleSheetHint( SFX_STYLESHEET_CREATED, *xTmp.get() ) );
748 
749             // JP 19.09.97:
750             // Dialog vorm EndAction zerstoeren - bei Seitenvorlagen kann
751             // muss der ItemSet zerstoert werden, damit die Cursor aus den
752             // Kopf-/Fusszeilen entfernt werden. Sonst kommts zu GPFs!!!
753             delete pDlg;
754 
755             pDoc->SetModified();
756             if( !bModified )    // Bug 57028
757             {
758                 pDoc->GetIDocumentUndoRedo().SetUndoNoResetModified();
759             }
760 
761             GetWrtShell()->EndAllAction();
762         }
763         else
764         {
765             if( bNew )
766             {
767                 // #116530#
768                 //pBasePool->Erase( &aTmp );
769                 GetWrtShell()->Undo(1);
770                 pDoc->GetIDocumentUndoRedo().ClearRedo();
771             }
772 
773             if( !bModified )
774                 pDoc->ResetModified();
775             delete pDlg;
776         }
777     }
778     else
779     {
780         // vor dem Dialog wird der HtmlMode an der DocShell versenkt
781         PutItem(SfxUInt16Item(SID_HTML_MODE, ::GetHtmlMode(this)));
782 
783         GetWrtShell()->StartAllAction();
784 
785         // nur bei Absatz-Vorlagen die Maske neu setzen
786         if( bNew )
787         {
788             nRet = SFX_STYLE_FAMILY_PARA == pStyle->GetFamily()
789                     ? xTmp->GetMask()
790                     : SFXSTYLEBIT_USERDEF;
791         }
792         else if( pStyle->GetMask() != xTmp->GetMask() )
793             nRet = xTmp->GetMask();
794 
795         if( SFX_STYLE_FAMILY_PARA == nFamily )
796             ::SfxToSwPageDescAttr( *GetWrtShell(), xTmp->GetItemSet() );
797         else
798         {
799             SfxItemSet aTmpSet( xTmp->GetItemSet() );
800             if( SFX_STYLE_FAMILY_CHAR == nFamily )
801             {
802                 const SfxPoolItem *pTmpBrush;
803                 if( SFX_ITEM_SET == aTmpSet.GetItemState( RES_BACKGROUND,
804                     sal_False, &pTmpBrush ) )
805                 {
806                     SvxBrushItem aTmpBrush( *((SvxBrushItem*)pTmpBrush) );
807                     aTmpBrush.SetWhich( RES_CHRATR_BACKGROUND );
808                     aTmpSet.Put( aTmpBrush );
809                 }
810                 aTmpSet.ClearItem( RES_BACKGROUND );
811             }
812             xTmp->SetItemSet( aTmpSet );
813         }
814         if(SFX_STYLE_FAMILY_PAGE == nFamily)
815             pView->InvalidateRulerPos();
816 
817         if( bNew )
818             mxBasePool->Broadcast( SfxStyleSheetHint( SFX_STYLESHEET_CREATED, *xTmp.get() ) );
819 
820         pDoc->SetModified();
821         if( !bModified )        // Bug 57028
822         {
823             pDoc->GetIDocumentUndoRedo().SetUndoNoResetModified();
824         }
825         GetWrtShell()->EndAllAction();
826     }
827 
828     return nRet;
829 }
830 
831 /*--------------------------------------------------------------------
832     Beschreibung:   Delete
833  --------------------------------------------------------------------*/
834 
835 
836 sal_uInt16 SwDocShell::Delete(const String &rName, sal_uInt16 nFamily)
837 {
838     SfxStyleSheetBase *pStyle = mxBasePool->Find(rName, (SfxStyleFamily)nFamily);
839 
840     if(pStyle)
841     {
842         ASSERT(GetWrtShell(), "Keine Shell, keine Styles");
843 
844         GetWrtShell()->StartAllAction();
845         mxBasePool->Remove(pStyle);
846         GetWrtShell()->EndAllAction();
847 
848         return sal_True;
849     }
850     return sal_False;
851 }
852 
853 /*--------------------------------------------------------------------
854     Beschreibung:   Vorlage anwenden
855  --------------------------------------------------------------------*/
856 
857 
858 sal_uInt16 SwDocShell::ApplyStyles(const String &rName, sal_uInt16 nFamily,
859                                SwWrtShell* pShell, sal_uInt16 nMode )
860 {
861     SwDocStyleSheet* pStyle =
862         (SwDocStyleSheet*)mxBasePool->Find(rName, (SfxStyleFamily)nFamily);
863 
864     ASSERT(pStyle, "Wo ist der StyleSheet");
865     if(!pStyle)
866         return sal_False;
867 
868     SwWrtShell *pSh = pShell ? pShell : GetWrtShell();
869 
870     ASSERT( pSh, "Keine Shell, keine Styles");
871 
872     pSh->StartAllAction();
873 
874     switch(nFamily)
875     {
876         case SFX_STYLE_FAMILY_CHAR:
877         {
878             SwFmtCharFmt aFmt(pStyle->GetCharFmt());
879             pSh->SetAttr( aFmt, (nMode & KEY_SHIFT) ?
880                 nsSetAttrMode::SETATTR_DONTREPLACE : nsSetAttrMode::SETATTR_DEFAULT );
881             break;
882         }
883         case SFX_STYLE_FAMILY_PARA:
884         {
885             // --> OD 2007-11-06 #i62675#
886             // clear also list attributes at affected text nodes, if paragraph
887             // style has the list style attribute set.
888             pSh->SetTxtFmtColl( pStyle->GetCollection(), true );
889             // <--
890             break;
891         }
892         case SFX_STYLE_FAMILY_FRAME:
893         {
894             if ( pSh->IsFrmSelected() )
895                 pSh->SetFrmFmt( pStyle->GetFrmFmt() );
896             break;
897         }
898         case SFX_STYLE_FAMILY_PAGE:
899         {
900             pSh->SetPageStyle(pStyle->GetPageDesc()->GetName());
901             break;
902         }
903         case SFX_STYLE_FAMILY_PSEUDO:
904         {
905             // --> OD 2008-02-08 #newlistlevelattrs#
906             // reset indent attribute on applying list style
907             // --> OD 2008-03-17 #refactorlists#
908             // continue list of list style
909             const SwNumRule* pNumRule = pStyle->GetNumRule();
910             const String sListIdForStyle =pNumRule->GetDefaultListId();
911             pSh->SetCurNumRule( *pNumRule, false, sListIdForStyle, true );
912             // <--
913             break;
914         }
915         default:
916             DBG_ERROR("Unbekannte Familie");
917     }
918     pSh->EndAllAction();
919 
920     return nFamily;
921 }
922 
923 /*--------------------------------------------------------------------
924     Beschreibung:   Giesskanne starten
925  --------------------------------------------------------------------*/
926 
927 
928 
929 sal_uInt16 SwDocShell::DoWaterCan(const String &rName, sal_uInt16 nFamily)
930 {
931     ASSERT(GetWrtShell(), "Keine Shell, keine Styles");
932 
933     SwEditWin& rEdtWin = pView->GetEditWin();
934     SwApplyTemplate* pApply = rEdtWin.GetApplyTemplate();
935     sal_Bool bWaterCan = !(pApply && pApply->eType != 0);
936     if( !rName.Len() )
937         bWaterCan = sal_False;
938     SwApplyTemplate aTemplate;
939     aTemplate.eType = nFamily;
940 
941     if(bWaterCan)
942     {
943         SwDocStyleSheet* pStyle =
944             (SwDocStyleSheet*)mxBasePool->Find(rName, (SfxStyleFamily)nFamily);
945 
946         ASSERT(pStyle, "Wo ist der StyleSheet");
947         if(!pStyle) return nFamily;
948 
949         switch(nFamily)
950         {
951             case SFX_STYLE_FAMILY_CHAR:
952                 aTemplate.aColl.pCharFmt = pStyle->GetCharFmt();
953                 break;
954             case SFX_STYLE_FAMILY_PARA:
955                 aTemplate.aColl.pTxtColl = pStyle->GetCollection();
956                 break;
957             case SFX_STYLE_FAMILY_FRAME:
958                 aTemplate.aColl.pFrmFmt = pStyle->GetFrmFmt();
959                 break;
960             case SFX_STYLE_FAMILY_PAGE:
961                 aTemplate.aColl.pPageDesc = (SwPageDesc*)pStyle->GetPageDesc();
962                 break;
963             case SFX_STYLE_FAMILY_PSEUDO:
964                 aTemplate.aColl.pNumRule = (SwNumRule*)pStyle->GetNumRule();
965                 break;
966 
967             default:
968                 DBG_ERROR( "Unbekannte Familie");
969         }
970     }
971     else
972         aTemplate.eType = 0;
973 
974     // Template anwenden
975     pView->GetEditWin().SetApplyTemplate(aTemplate);
976 
977     return nFamily;
978 }
979 
980 /*--------------------------------------------------------------------
981     Beschreibung:   Vorlage Updaten
982  --------------------------------------------------------------------*/
983 
984 
985 sal_uInt16 SwDocShell::UpdateStyle(const String &rName, sal_uInt16 nFamily, SwWrtShell* pShell)
986 {
987     SwWrtShell* pCurrWrtShell = pShell ? pShell : GetWrtShell();
988     ASSERT(GetWrtShell(), "Keine Shell, keine Styles");
989 
990     SwDocStyleSheet* pStyle =
991         (SwDocStyleSheet*)mxBasePool->Find(rName, (SfxStyleFamily)nFamily);
992 
993     if(!pStyle)
994         return nFamily;
995 
996     switch(nFamily)
997     {
998         case SFX_STYLE_FAMILY_PARA:
999         {
1000             SwTxtFmtColl* pColl = pStyle->GetCollection();
1001             if(pColl && !pColl->IsDefault())
1002             {
1003                 GetWrtShell()->StartAllAction();
1004 
1005                 SwRewriter aRewriter;
1006                 aRewriter.AddRule(UNDO_ARG1, pColl->GetName());
1007 
1008                 GetWrtShell()->StartUndo(UNDO_INSFMTATTR, &aRewriter);
1009                 GetWrtShell()->FillByEx(pColl);
1010                     // Vorlage auch anwenden, um harte Attributierung
1011                     // zu entfernen
1012                 GetWrtShell()->SetTxtFmtColl( pColl );
1013                 GetWrtShell()->EndUndo();
1014                 GetWrtShell()->EndAllAction();
1015             }
1016             break;
1017         }
1018         case SFX_STYLE_FAMILY_FRAME:
1019         {
1020             SwFrmFmt* pFrm = pStyle->GetFrmFmt();
1021             if( pCurrWrtShell->IsFrmSelected() && pFrm && !pFrm->IsDefault() )
1022             {
1023                 SfxItemSet aSet( GetPool(), aFrmFmtSetRange );
1024                 pCurrWrtShell->StartAllAction();
1025                 pCurrWrtShell->GetFlyFrmAttr( aSet );
1026 
1027                 // --> OD 2009-12-28 #i105535#
1028                 // no update of anchor attribute
1029                 aSet.ClearItem( RES_ANCHOR );
1030                 // <--
1031 
1032                 pFrm->SetFmtAttr( aSet );
1033 
1034                     // Vorlage auch anwenden, um harte Attributierung
1035                     // zu entfernen
1036                 pCurrWrtShell->SetFrmFmt( pFrm, sal_True );
1037                 pCurrWrtShell->EndAllAction();
1038             }
1039         }
1040         break;
1041         case SFX_STYLE_FAMILY_CHAR:
1042         {
1043             SwCharFmt* pChar = pStyle->GetCharFmt();
1044             if( pChar && !pChar->IsDefault() )
1045             {
1046                 pCurrWrtShell->StartAllAction();
1047                 pCurrWrtShell->FillByEx(pChar);
1048                     // Vorlage auch anwenden, um harte Attributierung
1049                     // zu entfernen
1050                 pCurrWrtShell->EndAllAction();
1051             }
1052 
1053         }
1054         break;
1055         case SFX_STYLE_FAMILY_PSEUDO:
1056         {
1057             const SwNumRule* pCurRule;
1058             if( pStyle->GetNumRule() &&
1059                 0 != ( pCurRule = pCurrWrtShell->GetCurNumRule() ))
1060             {
1061                 SwNumRule aRule( *pCurRule );
1062                 // --> OD 2008-07-08 #i91400#
1063                 aRule.SetName( pStyle->GetNumRule()->GetName(),
1064                                *(pCurrWrtShell->GetDoc()) );
1065                 // <--
1066                 pCurrWrtShell->ChgNumRuleFmts( aRule );
1067             }
1068         }
1069         break;
1070     }
1071     return nFamily;
1072 }
1073 
1074 /*--------------------------------------------------------------------
1075     Beschreibung:   NewByExample
1076  --------------------------------------------------------------------*/
1077 
1078 
1079 sal_uInt16 SwDocShell::MakeByExample( const String &rName, sal_uInt16 nFamily,
1080                                     sal_uInt16 nMask, SwWrtShell* pShell )
1081 {
1082     SwWrtShell* pCurrWrtShell = pShell ? pShell : GetWrtShell();
1083     SwDocStyleSheet* pStyle = (SwDocStyleSheet*)mxBasePool->Find(
1084                                             rName, (SfxStyleFamily)nFamily );
1085     if(!pStyle)
1086     {
1087         // JP 07.07.95: behalte die akt. Maske vom PI bei, dadurch werden
1088         //              neue sofort in den sichtbaren Bereich einsortiert
1089         if( SFXSTYLEBIT_ALL == nMask || SFXSTYLEBIT_USED == nMask )
1090             nMask = SFXSTYLEBIT_USERDEF;
1091         else
1092             nMask |= SFXSTYLEBIT_USERDEF;
1093 
1094         pStyle = (SwDocStyleSheet*)&mxBasePool->Make(rName,
1095                                 (SfxStyleFamily)nFamily, nMask );
1096     }
1097 
1098     switch(nFamily)
1099     {
1100         case  SFX_STYLE_FAMILY_PARA:
1101         {
1102             SwTxtFmtColl* pColl = pStyle->GetCollection();
1103             if(pColl && !pColl->IsDefault())
1104             {
1105                 pCurrWrtShell->StartAllAction();
1106                 pCurrWrtShell->FillByEx(pColl);
1107                     // Vorlage auch anwenden, um harte Attributierung
1108                     // zu entfernen
1109                 pColl->SetDerivedFrom(pCurrWrtShell->GetCurTxtFmtColl());
1110 
1111                     // setze die Maske noch an der Collection:
1112                 sal_uInt16 nId = pColl->GetPoolFmtId() & 0x87ff;
1113                 switch( nMask & 0x0fff )
1114                 {
1115                 case SWSTYLEBIT_TEXT:
1116                     nId |= COLL_TEXT_BITS;
1117                     break;
1118                 case SWSTYLEBIT_CHAPTER:
1119                     nId |= COLL_DOC_BITS;
1120                     break;
1121                 case SWSTYLEBIT_LIST:
1122                     nId |= COLL_LISTS_BITS;
1123                     break;
1124                 case SWSTYLEBIT_IDX:
1125                     nId |= COLL_REGISTER_BITS;
1126                     break;
1127                 case SWSTYLEBIT_EXTRA:
1128                     nId |= COLL_EXTRA_BITS;
1129                     break;
1130                 case SWSTYLEBIT_HTML:
1131                     nId |= COLL_HTML_BITS;
1132                     break;
1133                 }
1134                 pColl->SetPoolFmtId(nId);
1135 
1136                 pCurrWrtShell->SetTxtFmtColl(pColl);
1137                 pCurrWrtShell->EndAllAction();
1138             }
1139         }
1140         break;
1141         case SFX_STYLE_FAMILY_FRAME:
1142         {
1143             SwFrmFmt* pFrm = pStyle->GetFrmFmt();
1144             if(pCurrWrtShell->IsFrmSelected() && pFrm && !pFrm->IsDefault())
1145             {
1146                 pCurrWrtShell->StartAllAction();
1147 
1148                 SfxItemSet aSet(GetPool(), aFrmFmtSetRange );
1149                 pCurrWrtShell->GetFlyFrmAttr( aSet );
1150 
1151                 SwFrmFmt* pFFmt = pCurrWrtShell->GetCurFrmFmt();
1152                 pFrm->SetDerivedFrom( pFFmt );
1153 
1154                 // JP 10.06.98: nur automatische Orientierungen uebernehmen
1155 /*              #61359# jetzt auch wieder alle Orientierungen
1156                 const SfxPoolItem* pItem;
1157                 if( SFX_ITEM_SET == aSet.GetItemState( RES_VERT_ORIENT,
1158                     sal_False, &pItem ) &&
1159                     text::VertOrientation::NONE == ((SwFmtVertOrient*)pItem)->GetVertOrient())
1160                     aSet.ClearItem( RES_VERT_ORIENT );
1161 
1162                 if( SFX_ITEM_SET == aSet.GetItemState( RES_HORI_ORIENT,
1163                     sal_False, &pItem ) &&
1164                     text::HoriOrientation::NONE == ((SwFmtHoriOrient*)pItem)->GetHoriOrient())
1165                     aSet.ClearItem( RES_HORI_ORIENT );
1166  */
1167 
1168                 pFrm->SetFmtAttr( aSet );
1169                     // Vorlage auch anwenden, um harte Attributierung
1170                     // zu entfernen
1171                 pCurrWrtShell->SetFrmFmt( pFrm );
1172                 pCurrWrtShell->EndAllAction();
1173             }
1174         }
1175         break;
1176         case SFX_STYLE_FAMILY_CHAR:
1177         {
1178             SwCharFmt* pChar = pStyle->GetCharFmt();
1179             if(pChar && !pChar->IsDefault())
1180             {
1181                 pCurrWrtShell->StartAllAction();
1182                 pCurrWrtShell->FillByEx( pChar );
1183                 pChar->SetDerivedFrom( pCurrWrtShell->GetCurCharFmt() );
1184                 SwFmtCharFmt aFmt( pChar );
1185                 pCurrWrtShell->SetAttr( aFmt );
1186                 pCurrWrtShell->EndAllAction();
1187             }
1188         }
1189         break;
1190 
1191         case SFX_STYLE_FAMILY_PAGE:
1192         {
1193             pCurrWrtShell->StartAllAction();
1194             sal_uInt16 nPgDsc = pCurrWrtShell->GetCurPageDesc();
1195             SwPageDesc& rSrc = (SwPageDesc&)pCurrWrtShell->GetPageDesc( nPgDsc );
1196             SwPageDesc& rDest = *(SwPageDesc*)pStyle->GetPageDesc();
1197 
1198             sal_uInt16 nPoolId = rDest.GetPoolFmtId();
1199             sal_uInt16 nHId = rDest.GetPoolHelpId();
1200             sal_uInt8 nHFId = rDest.GetPoolHlpFileId();
1201 
1202             pCurrWrtShell->GetDoc()->CopyPageDesc( rSrc, rDest );
1203 
1204             // PoolId darf NIE kopiert werden!
1205             rDest.SetPoolFmtId( nPoolId );
1206             rDest.SetPoolHelpId( nHId );
1207             rDest.SetPoolHlpFileId( nHFId );
1208 
1209             // werden Kopf-/Fusszeilen angelegt, so gibt es kein Undo mehr!
1210             pCurrWrtShell->GetDoc()->GetIDocumentUndoRedo().DelAllUndoObj();
1211 
1212             pCurrWrtShell->EndAllAction();
1213         }
1214         break;
1215 
1216         case SFX_STYLE_FAMILY_PSEUDO:
1217         {
1218             pCurrWrtShell->StartAllAction();
1219 
1220             SwNumRule aRule( *pCurrWrtShell->GetCurNumRule() );
1221             String sOrigRule( aRule.GetName() );
1222             // --> OD 2008-07-08 #i91400#
1223             aRule.SetName( pStyle->GetNumRule()->GetName(),
1224                            *(pCurrWrtShell->GetDoc()) );
1225             // <--
1226             pCurrWrtShell->ChgNumRuleFmts( aRule );
1227 
1228             pCurrWrtShell->ReplaceNumRule( sOrigRule, aRule.GetName() );
1229 
1230 
1231             pCurrWrtShell->EndAllAction();
1232         }
1233         break;
1234     }
1235     return nFamily;
1236 }
1237 
1238 void  SwDocShell::LoadStyles( SfxObjectShell& rSource )
1239 {
1240     _LoadStyles(rSource, sal_False);
1241 }
1242 /* -----------------16.05.2003 15:45-----------------
1243     bPreserveCurrentDocument determines whether SetFixFields() is called
1244     This call modifies the source document. This mustn't happen when the source
1245     is a document the user is working on.
1246     Calls of ::LoadStyles() normally use files especially loaded for the purpose
1247     of importing styles.
1248  --------------------------------------------------*/
1249 void SwDocShell::_LoadStyles( SfxObjectShell& rSource, sal_Bool bPreserveCurrentDocument )
1250 {
1251 /*  [Beschreibung]
1252 
1253     Diese Methode wird vom SFx gerufen, wenn aus einer Dokument-Vorlage
1254     Styles nachgeladen werden sollen. Bestehende Styles soll dabei
1255     "uberschrieben werden. Das Dokument mu"s daher neu formatiert werden.
1256     Daher werden die Applikationen in der Regel diese Methode "uberladen
1257     und in ihrer Implementierung die Implementierung der Basisklasse
1258     rufen.
1259 */
1260     // ist die Source unser Document, dann uebernehmen wir das
1261     // abpruefen selbst (wesentlich schneller und laeuft nicht ueber
1262     // die Kruecke SfxStylePool
1263     if( rSource.ISA( SwDocShell ))
1264     {
1265         //JP 28.05.99: damit die Kopf-/Fusszeilen nicht den fixen Inhalt
1266         //              der Vorlage erhalten, einmal alle FixFelder der
1267         //              Source aktualisieren
1268         if(!bPreserveCurrentDocument)
1269             ((SwDocShell&)rSource).pDoc->SetFixFields(false, NULL);
1270         if( pWrtShell )
1271         {
1272             pWrtShell->StartAllAction();
1273             pDoc->ReplaceStyles( *((SwDocShell&)rSource).pDoc );
1274             pWrtShell->EndAllAction();
1275         }
1276         else
1277         {
1278             sal_Bool bModified = pDoc->IsModified();
1279             pDoc->ReplaceStyles( *((SwDocShell&)rSource).pDoc );
1280             if( !bModified && pDoc->IsModified() && !pView )
1281             {
1282                 // die View wird spaeter angelegt, ueberschreibt aber das
1283                 // Modify-Flag. Per Undo ist sowieso nichts mehr zu machen
1284                 pDoc->GetIDocumentUndoRedo().SetUndoNoResetModified();
1285             }
1286         }
1287     }
1288     else
1289         SfxObjectShell::LoadStyles( rSource );
1290 }
1291 
1292 
1293 void SwDocShell::FormatPage( const String& rPage, sal_Bool bColumn, SwWrtShell*     pActShell )
1294 {
1295     Edit( rPage, aEmptyStr, SFX_STYLE_FAMILY_PAGE, 0, sal_False, bColumn, pActShell);
1296 }
1297 
1298 Bitmap SwDocShell::GetStyleFamilyBitmap( SfxStyleFamily eFamily, BmpColorMode eColorMode )
1299 {
1300     if( SFX_STYLE_FAMILY_PSEUDO == eFamily )
1301     {
1302         if ( eColorMode == BMP_COLOR_NORMAL )
1303             return Bitmap( SW_RES( BMP_STYLES_FAMILY_NUM ));
1304         else
1305             return Bitmap( SW_RES( BMP_STYLES_FAMILY_NUM_HC ));
1306     }
1307 
1308     return SfxObjectShell::GetStyleFamilyBitmap( eFamily, eColorMode );
1309 }
1310 
1311 
1312 
1313