LCOV - code coverage report
Current view: top level - sw/source/core/uibase/app - docst.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 572 0.0 %
Date: 2014-04-14 Functions: 0 20 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
      21             : #include <com/sun/star/beans/XPropertySet.hpp>
      22             : #include <com/sun/star/container/XNameAccess.hpp>
      23             : 
      24             : #include <comphelper/flagguard.hxx>
      25             : 
      26             : #include <hintids.hxx>
      27             : #include <sfx2/app.hxx>
      28             : #include <svl/whiter.hxx>
      29             : #include <sfx2/templdlg.hxx>
      30             : #include <sfx2/tplpitem.hxx>
      31             : #include <sfx2/request.hxx>
      32             : #include <sfx2/dispatch.hxx>
      33             : #include <sfx2/newstyle.hxx>
      34             : #include <sfx2/printer.hxx>
      35             : #include <svl/macitem.hxx>
      36             : #include <svl/stritem.hxx>
      37             : #include <svl/languageoptions.hxx>
      38             : #include <editeng/eeitem.hxx>
      39             : #include <sfx2/htmlmode.hxx>
      40             : #include <swmodule.hxx>
      41             : #include <wdocsh.hxx>
      42             : #include <fmtfsize.hxx>
      43             : #include <fchrfmt.hxx>
      44             : #include <svtools/htmlcfg.hxx>
      45             : #include <svx/xdef.hxx>
      46             : #include <SwStyleNameMapper.hxx>
      47             : #include <SwRewriter.hxx>
      48             : #include <numrule.hxx>
      49             : #include <swundo.hxx>
      50             : 
      51             : #include "view.hxx"
      52             : #include "wrtsh.hxx"
      53             : #include "docsh.hxx"
      54             : #include "uitool.hxx"
      55             : #include "cmdid.h"
      56             : #include "globals.hrc"
      57             : #include "viewopt.hxx"
      58             : #include <doc.hxx>
      59             : #include <IDocumentUndoRedo.hxx>
      60             : #include "swstyle.h"
      61             : #include "frmfmt.hxx"
      62             : #include "charfmt.hxx"
      63             : #include "poolfmt.hxx"
      64             : #include "pagedesc.hxx"
      65             : #include "docstyle.hxx"
      66             : #include "uiitems.hxx"
      67             : #include "fmtcol.hxx"
      68             : #include "frmmgr.hxx"
      69             : #include "swevent.hxx"
      70             : #include "edtwin.hxx"
      71             : #include "unochart.hxx"
      72             : 
      73             : #include "app.hrc"
      74             : #include "swabstdlg.hxx"
      75             : 
      76             : #include <list.hxx>
      77             : 
      78             : #include <paratr.hxx>
      79             : 
      80             : extern bool bNoInterrupt;       // in mainwn.cxx
      81             : 
      82             : using namespace ::com::sun::star;
      83             : 
      84           0 : void  SwDocShell::StateStyleSheet(SfxItemSet& rSet, SwWrtShell* pSh)
      85             : {
      86           0 :     SfxWhichIter aIter(rSet);
      87           0 :     sal_uInt16  nWhich  = aIter.FirstWhich();
      88           0 :     sal_uInt16 nActualFamily = USHRT_MAX;
      89             : 
      90           0 :     SwWrtShell* pShell = pSh ? pSh : GetWrtShell();
      91           0 :     if(!pShell)
      92             :     {
      93           0 :         while (nWhich)
      94             :         {
      95           0 :             rSet.DisableItem(nWhich);
      96           0 :             nWhich = aIter.NextWhich();
      97             :         }
      98           0 :         return;
      99             :     }
     100             :     else
     101             :     {
     102           0 :         SfxViewFrame* pFrame = pShell->GetView().GetViewFrame();
     103           0 :         const ISfxTemplateCommon* pCommon = SFX_APP()->GetCurrentTemplateCommon(pFrame->GetBindings());
     104           0 :         if( pCommon )
     105           0 :             nActualFamily = static_cast< sal_uInt16 >(pCommon->GetActualFamily());
     106             :     }
     107             : 
     108           0 :     while (nWhich)
     109             :     {
     110             :         // determine current template to every family
     111           0 :         OUString aName;
     112           0 :         switch (nWhich)
     113             :         {
     114             :             case SID_STYLE_APPLY:
     115             :             {// here the template and its family are passed to the StyleBox
     116             :              // so that this family is being showed
     117           0 :                 if(pShell->IsFrmSelected())
     118             :                 {
     119           0 :                     SwFrmFmt* pFmt = pShell->GetCurFrmFmt();
     120           0 :                     if( pFmt )
     121           0 :                         aName = pFmt->GetName();
     122             :                 }
     123             :                 else
     124             :                 {
     125           0 :                     SwTxtFmtColl* pColl = pShell->GetCurTxtFmtColl();
     126           0 :                     if(pColl)
     127           0 :                         aName = pColl->GetName();
     128             :                 }
     129           0 :                 rSet.Put(SfxTemplateItem(nWhich, aName));
     130             :             }
     131           0 :             break;
     132             :             case SID_STYLE_FAMILY1:
     133           0 :                 if( !pShell->IsFrmSelected() )
     134             :                 {
     135           0 :                     SwCharFmt* pFmt = pShell->GetCurCharFmt();
     136           0 :                     if(pFmt)
     137           0 :                         aName = pFmt->GetName();
     138             :                     else
     139           0 :                         aName = SwStyleNameMapper::GetTextUINameArray()[
     140           0 :                             RES_POOLCOLL_STANDARD - RES_POOLCOLL_TEXT_BEGIN ];
     141           0 :                     rSet.Put(SfxTemplateItem(nWhich, aName));
     142             :                 }
     143           0 :                 break;
     144             : 
     145             :             case SID_STYLE_FAMILY2:
     146           0 :                 if(!pShell->IsFrmSelected())
     147             :                 {
     148           0 :                     SwTxtFmtColl* pColl = pShell->GetCurTxtFmtColl();
     149           0 :                     if(pColl)
     150           0 :                         aName = pColl->GetName();
     151             : 
     152           0 :                     SfxTemplateItem aItem(nWhich, aName);
     153             : 
     154           0 :                     sal_uInt16 nMask = 0;
     155           0 :                     if( pDoc->get(IDocumentSettingAccess::HTML_MODE) )
     156           0 :                         nMask = SWSTYLEBIT_HTML;
     157             :                     else
     158             :                     {
     159           0 :                         const int nSelection = pShell->GetFrmType(0,sal_True);
     160           0 :                         if(pShell->GetCurTOX())
     161           0 :                             nMask = SWSTYLEBIT_IDX  ;
     162           0 :                         else if(nSelection & FRMTYPE_HEADER     ||
     163           0 :                                 nSelection & FRMTYPE_FOOTER     ||
     164           0 :                                 nSelection & FRMTYPE_TABLE      ||
     165           0 :                                 nSelection & FRMTYPE_FLY_ANY    ||
     166           0 :                                 nSelection & FRMTYPE_FOOTNOTE   ||
     167           0 :                                 nSelection & FRMTYPE_FTNPAGE)
     168           0 :                             nMask = SWSTYLEBIT_EXTRA;
     169             :                         else
     170           0 :                             nMask = SWSTYLEBIT_TEXT;
     171             :                     }
     172             : 
     173           0 :                     aItem.SetValue(nMask);
     174           0 :                     rSet.Put(aItem);
     175             :                 }
     176             : 
     177           0 :                 break;
     178             : 
     179             :             case SID_STYLE_FAMILY3:
     180             : 
     181           0 :                 if( pDoc->get(IDocumentSettingAccess::HTML_MODE) )
     182           0 :                     rSet.DisableItem( nWhich );
     183             :                 else
     184             :                 {
     185           0 :                     SwFrmFmt* pFmt = pShell->GetCurFrmFmt();
     186           0 :                     if(pFmt && pShell->IsFrmSelected())
     187             :                     {
     188           0 :                         aName = pFmt->GetName();
     189           0 :                         rSet.Put(SfxTemplateItem(nWhich, aName));
     190             :                     }
     191             :                 }
     192           0 :                 break;
     193             : 
     194             :             case SID_STYLE_FAMILY4:
     195             :             {
     196           0 :                 SvxHtmlOptions& rHtmlOpt = SvxHtmlOptions::Get();
     197           0 :                 if( pDoc->get(IDocumentSettingAccess::HTML_MODE) && !rHtmlOpt.IsPrintLayoutExtension())
     198           0 :                     rSet.DisableItem( nWhich );
     199             :                 else
     200             :                 {
     201           0 :                     sal_uInt16 n = pShell->GetCurPageDesc( sal_False );
     202           0 :                     if( n < pShell->GetPageDescCnt() )
     203           0 :                         aName = pShell->GetPageDesc( n ).GetName();
     204             : 
     205           0 :                     rSet.Put(SfxTemplateItem(nWhich, aName));
     206             :                 }
     207             :             }
     208           0 :             break;
     209             :             case SID_STYLE_FAMILY5:
     210             :                 {
     211           0 :                     const SwNumRule* pRule = pShell->GetNumRuleAtCurrCrsrPos();
     212           0 :                     if( pRule )
     213           0 :                         aName = pRule->GetName();
     214             : 
     215           0 :                     rSet.Put(SfxTemplateItem(nWhich, aName));
     216             :                 }
     217           0 :                 break;
     218             : 
     219             :             case SID_STYLE_WATERCAN:
     220             :             {
     221           0 :                 SwEditWin& rEdtWin = pShell->GetView().GetEditWin();
     222           0 :                 SwApplyTemplate* pApply = rEdtWin.GetApplyTemplate();
     223           0 :                 rSet.Put(SfxBoolItem(nWhich, pApply && pApply->eType != 0));
     224             :             }
     225           0 :             break;
     226             :             case SID_STYLE_UPDATE_BY_EXAMPLE:
     227           0 :                 if( pShell->IsFrmSelected()
     228             :                         ? SFX_STYLE_FAMILY_FRAME != nActualFamily
     229           0 :                         : ( SFX_STYLE_FAMILY_FRAME == nActualFamily ||
     230           0 :                             SFX_STYLE_FAMILY_PAGE == nActualFamily ||
     231           0 :                             (SFX_STYLE_FAMILY_PSEUDO == nActualFamily && !pShell->GetNumRuleAtCurrCrsrPos())) )
     232             :                 {
     233           0 :                     rSet.DisableItem( nWhich );
     234             :                 }
     235           0 :                 break;
     236             : 
     237             :             case SID_STYLE_NEW_BY_EXAMPLE:
     238           0 :                 if( (pShell->IsFrmSelected()
     239             :                         ? SFX_STYLE_FAMILY_FRAME != nActualFamily
     240           0 :                         : SFX_STYLE_FAMILY_FRAME == nActualFamily) ||
     241           0 :                     (SFX_STYLE_FAMILY_PSEUDO == nActualFamily && !pShell->GetNumRuleAtCurrCrsrPos()) )
     242             :                 {
     243           0 :                     rSet.DisableItem( nWhich );
     244             :                 }
     245           0 :                 break;
     246             : 
     247             :             default:
     248             :                 OSL_FAIL("Invalid SlotId");
     249             :         }
     250           0 :         nWhich = aIter.NextWhich();
     251           0 :     }
     252             : }
     253             : 
     254             : // evaluate StyleSheet-Requests
     255           0 : void SwDocShell::ExecStyleSheet( SfxRequest& rReq )
     256             : {
     257           0 :     sal_uInt16  nSlot   = rReq.GetSlot();
     258           0 :     sal_uInt16  nRet    = SFXSTYLEBIT_ALL;
     259             : 
     260           0 :     const SfxItemSet* pArgs = rReq.GetArgs();
     261             :     const SfxPoolItem* pItem;
     262           0 :     SwWrtShell* pActShell = 0;
     263           0 :     switch (nSlot)
     264             :     {
     265             :     case SID_STYLE_NEW:
     266           0 :         if( pArgs && SFX_ITEM_SET == pArgs->GetItemState( SID_STYLE_FAMILY,
     267           0 :             false, &pItem ))
     268             :         {
     269           0 :             const sal_uInt16 nFamily = ((const SfxUInt16Item*)pItem)->GetValue();
     270             : 
     271           0 :             OUString sName;
     272           0 :             sal_uInt16 nMask = 0;
     273           0 :             if( SFX_ITEM_SET == pArgs->GetItemState( SID_STYLE_NEW,
     274           0 :                 false, &pItem ))
     275           0 :                 sName = ((const SfxStringItem*)pItem)->GetValue();
     276           0 :             if( SFX_ITEM_SET == pArgs->GetItemState( SID_STYLE_MASK,
     277           0 :                 false, &pItem ))
     278           0 :                 nMask = ((const SfxUInt16Item*)pItem)->GetValue();
     279           0 :             OUString sParent;
     280           0 :             if( SFX_ITEM_SET == pArgs->GetItemState( SID_STYLE_REFERENCE,
     281           0 :                 false, &pItem ))
     282           0 :                 sParent = ((const SfxStringItem*)pItem)->GetValue();
     283             : 
     284           0 :             nRet = Edit( sName, sParent, nFamily, nMask, sal_True, OString(), 0, rReq.IsAPI() );
     285             :         }
     286           0 :         break;
     287             : 
     288             :         case SID_STYLE_APPLY:
     289           0 :             if( !pArgs )
     290             :             {
     291           0 :                 GetView()->GetViewFrame()->GetDispatcher()->Execute(SID_STYLE_DESIGNER, sal_False);
     292           0 :                 break;
     293             :             }
     294             :             else
     295             :             {
     296             :                 // convert internal StyleName to DisplayName (slot implementation uses the latter)
     297           0 :                 SFX_REQUEST_ARG( rReq, pNameItem, SfxStringItem, SID_APPLY_STYLE, false );
     298           0 :                 SFX_REQUEST_ARG( rReq, pFamilyItem, SfxStringItem, SID_STYLE_FAMILYNAME, false );
     299           0 :                 if ( pFamilyItem && pNameItem )
     300             :                 {
     301           0 :                     uno::Reference< style::XStyleFamiliesSupplier > xModel(GetModel(), uno::UNO_QUERY);
     302             :                     try
     303             :                     {
     304           0 :                         uno::Reference< container::XNameAccess > xStyles;
     305           0 :                         uno::Reference< container::XNameAccess > xCont = xModel->getStyleFamilies();
     306           0 :                         xCont->getByName(pFamilyItem->GetValue()) >>= xStyles;
     307           0 :                         uno::Reference< beans::XPropertySet > xInfo;
     308           0 :                         xStyles->getByName( pNameItem->GetValue() ) >>= xInfo;
     309           0 :                         OUString aUIName;
     310           0 :                         xInfo->getPropertyValue("DisplayName") >>= aUIName;
     311           0 :                         if ( !aUIName.isEmpty() )
     312           0 :                             rReq.AppendItem( SfxStringItem( SID_STYLE_APPLY, aUIName ) );
     313             :                     }
     314           0 :                     catch (const uno::Exception&)
     315             :                     {
     316           0 :                     }
     317             :                 }
     318             :             }
     319             : 
     320             :             // intentionally no break
     321             : 
     322             :         case SID_STYLE_EDIT:
     323             :         case SID_STYLE_DELETE:
     324             :         case SID_STYLE_HIDE:
     325             :         case SID_STYLE_SHOW:
     326             :         case SID_STYLE_WATERCAN:
     327             :         case SID_STYLE_FAMILY:
     328             :         case SID_STYLE_UPDATE_BY_EXAMPLE:
     329             :         case SID_STYLE_NEW_BY_EXAMPLE:
     330             :         {
     331           0 :             OUString aParam;
     332           0 :             sal_uInt16 nFamily = SFX_STYLE_FAMILY_PARA;
     333           0 :             sal_uInt16 nMask = 0;
     334             : 
     335           0 :             if( !pArgs )
     336             :             {
     337           0 :                 nFamily = SFX_STYLE_FAMILY_PARA;
     338             : 
     339           0 :                 switch (nSlot)
     340             :                 {
     341             :                     case SID_STYLE_NEW_BY_EXAMPLE:
     342             :                     {
     343             :                         boost::scoped_ptr<SfxNewStyleDlg> pDlg(new SfxNewStyleDlg( 0,
     344           0 :                                                     *GetStyleSheetPool()));
     345           0 :                         if(RET_OK == pDlg->Execute())
     346             :                         {
     347           0 :                             aParam = pDlg->GetName();
     348           0 :                             rReq.AppendItem(SfxStringItem(nSlot, aParam));
     349           0 :                         }
     350             :                     }
     351           0 :                     break;
     352             : 
     353             :                     case SID_STYLE_UPDATE_BY_EXAMPLE:
     354             :                     case SID_STYLE_EDIT:
     355             :                     {
     356           0 :                         SwTxtFmtColl* pColl = GetWrtShell()->GetCurTxtFmtColl();
     357           0 :                         if(pColl)
     358             :                         {
     359           0 :                             aParam = pColl->GetName();
     360           0 :                             rReq.AppendItem(SfxStringItem(nSlot, aParam));
     361             :                         }
     362             :                     }
     363           0 :                     break;
     364             :                 }
     365             :             }
     366             :             else
     367             :             {
     368             :                 SAL_WARN_IF( !pArgs->Count(), "sw.ui", "SfxBug ItemSet is empty" );
     369             : 
     370           0 :                 SwWrtShell* pShell = GetWrtShell();
     371           0 :                 if( SFX_ITEM_SET == pArgs->GetItemState(nSlot, false, &pItem ))
     372           0 :                     aParam = ((const SfxStringItem*)pItem)->GetValue();
     373             : 
     374           0 :                 if( SFX_ITEM_SET == pArgs->GetItemState(SID_STYLE_FAMILY,
     375           0 :                     false, &pItem ))
     376           0 :                     nFamily = ((const SfxUInt16Item*)pItem)->GetValue();
     377             : 
     378           0 :                 if( SFX_ITEM_SET == pArgs->GetItemState(SID_STYLE_FAMILYNAME, false, &pItem ))
     379             :                 {
     380           0 :                     OUString aFamily = ((const SfxStringItem*)pItem)->GetValue();
     381           0 :                     if(aFamily.equalsAscii("CharacterStyles"))
     382           0 :                         nFamily = SFX_STYLE_FAMILY_CHAR;
     383             :                     else
     384           0 :                     if(aFamily.equalsAscii("ParagraphStyles"))
     385           0 :                         nFamily = SFX_STYLE_FAMILY_PARA;
     386             :                     else
     387           0 :                     if(aFamily.equalsAscii("PageStyles"))
     388           0 :                         nFamily = SFX_STYLE_FAMILY_PAGE;
     389             :                     else
     390           0 :                     if(aFamily.equalsAscii("FrameStyles"))
     391           0 :                         nFamily = SFX_STYLE_FAMILY_FRAME;
     392             :                     else
     393           0 :                     if(aFamily.equalsAscii("NumberingStyles"))
     394           0 :                         nFamily = SFX_STYLE_FAMILY_PSEUDO;
     395             :                 }
     396             : 
     397           0 :                 if( SFX_ITEM_SET == pArgs->GetItemState(SID_STYLE_MASK,
     398           0 :                     false, &pItem ))
     399           0 :                     nMask = ((const SfxUInt16Item*)pItem)->GetValue();
     400           0 :                 if( SFX_ITEM_SET == pArgs->GetItemState(FN_PARAM_WRTSHELL,
     401           0 :                     false, &pItem ))
     402           0 :                     pActShell = pShell = (SwWrtShell*)((SwPtrItem*)pItem)->GetValue();
     403             : 
     404           0 :                 if( nSlot == SID_STYLE_UPDATE_BY_EXAMPLE )
     405             :                 {
     406           0 :                     switch( nFamily )
     407             :                     {
     408             :                         case SFX_STYLE_FAMILY_PARA:
     409             :                         {
     410           0 :                             SwTxtFmtColl* pColl = pShell->GetCurTxtFmtColl();
     411           0 :                             if(pColl)
     412           0 :                                 aParam = pColl->GetName();
     413             :                         }
     414           0 :                         break;
     415             :                         case SFX_STYLE_FAMILY_FRAME:
     416             :                         {
     417           0 :                             SwFrmFmt* pFrm = pWrtShell->GetCurFrmFmt();
     418           0 :                             if( pFrm )
     419           0 :                                 aParam = pFrm->GetName();
     420             :                         }
     421           0 :                         break;
     422             :                         case SFX_STYLE_FAMILY_CHAR:
     423             :                         {
     424           0 :                             SwCharFmt* pChar = pWrtShell->GetCurCharFmt();
     425           0 :                             if( pChar )
     426           0 :                                 aParam = pChar->GetName();
     427             :                         }
     428           0 :                         break;
     429             :                         case SFX_STYLE_FAMILY_PSEUDO:
     430           0 :                         if(SFX_ITEM_SET == pArgs->GetItemState(SID_STYLE_UPD_BY_EX_NAME, false, &pItem))
     431             :                         {
     432           0 :                             aParam = ((const SfxStringItem*)pItem)->GetValue();
     433             :                         }
     434           0 :                         break;
     435             :                     }
     436           0 :                     rReq.AppendItem(SfxStringItem(nSlot, aParam));
     437             :                 }
     438             :             }
     439           0 :             if (!aParam.isEmpty() || nSlot == SID_STYLE_WATERCAN )
     440             :             {
     441           0 :                 switch(nSlot)
     442             :                 {
     443             :                     case SID_STYLE_EDIT:
     444           0 :                         nRet = Edit(aParam, aEmptyOUStr, nFamily, nMask, sal_False, OString(), pActShell );
     445           0 :                         break;
     446             :                     case SID_STYLE_DELETE:
     447           0 :                         nRet = Delete(aParam, nFamily);
     448           0 :                         break;
     449             :                     case SID_STYLE_HIDE:
     450             :                     case SID_STYLE_SHOW:
     451           0 :                         nRet = Hide(aParam, nFamily, nSlot == SID_STYLE_HIDE);
     452           0 :                         break;
     453             :                     case SID_STYLE_APPLY:
     454             :                         // Shell-switch in ApplyStyles
     455           0 :                         nRet = ApplyStyles(aParam, nFamily, pActShell, rReq.GetModifier() );
     456           0 :                         break;
     457             :                     case SID_STYLE_WATERCAN:
     458           0 :                         nRet = DoWaterCan(aParam, nFamily);
     459           0 :                         break;
     460             :                     case SID_STYLE_UPDATE_BY_EXAMPLE:
     461           0 :                         nRet = UpdateStyle(aParam, nFamily, pActShell);
     462           0 :                         break;
     463             :                     case SID_STYLE_NEW_BY_EXAMPLE:
     464             :                     {
     465           0 :                         nRet = MakeByExample(aParam, nFamily, nMask, pActShell );
     466           0 :                         SfxTemplateDialog* pDlg = SFX_APP()->GetTemplateDialog();
     467             : 
     468           0 :                         if(pDlg && pDlg->IsVisible())
     469           0 :                             pDlg->Update();
     470             :                     }
     471           0 :                     break;
     472             : 
     473             :                     default:
     474             :                         OSL_FAIL("Invalid SlotId");
     475             :                 }
     476             : 
     477           0 :                 rReq.Done();
     478             :             }
     479             : 
     480           0 :             break;
     481             :         }
     482             :     }
     483             : 
     484           0 :         if(rReq.IsAPI()) // Basic only gets TRUE or FALSE
     485           0 :             rReq.SetReturnValue(SfxUInt16Item(nSlot, sal_uInt16(nRet !=0)));
     486             :         else
     487           0 :             rReq.SetReturnValue(SfxUInt16Item(nSlot, nRet));
     488           0 : }
     489             : 
     490           0 : class ApplyStyle
     491             : {
     492             : public:
     493           0 :     ApplyStyle(SwDocShell &rDocSh, bool bNew, SfxStyleSheetBase* pStyle,
     494             :         sal_uInt16 nRet, rtl::Reference< SwDocStyleSheet > xTmp,
     495             :         sal_uInt16 nFamily, SfxAbstractApplyTabDialog *pDlg,
     496             :         rtl::Reference< SfxStyleSheetBasePool > xBasePool,
     497             :         bool bModified)
     498             :         : m_rDocSh(rDocSh)
     499             :         , m_bNew(bNew)
     500             :         , m_pStyle(pStyle)
     501             :         , m_nRet(nRet)
     502             :         , m_xTmp(xTmp)
     503             :         , m_nFamily(nFamily)
     504             :         , m_pDlg(pDlg)
     505             :         , m_xBasePool(xBasePool)
     506           0 :         , m_bModified(bModified)
     507             :     {
     508           0 :     }
     509             :     DECL_LINK( ApplyHdl, void* );
     510           0 :     void apply()
     511             :     {
     512           0 :         ApplyHdl(NULL);
     513           0 :     }
     514           0 :     sal_uInt16 getRet() const { return m_nRet; }
     515             : private:
     516             :     SwDocShell &m_rDocSh;
     517             :     bool m_bNew;
     518             :     SfxStyleSheetBase* m_pStyle;
     519             :     sal_uInt16 m_nRet;
     520             :     rtl::Reference< SwDocStyleSheet > m_xTmp;
     521             :     sal_uInt16 m_nFamily;
     522             :     SfxAbstractApplyTabDialog *m_pDlg;
     523             :     rtl::Reference< SfxStyleSheetBasePool > m_xBasePool;
     524             :     bool m_bModified;
     525             : };
     526             : 
     527           0 : IMPL_LINK_NOARG(ApplyStyle, ApplyHdl)
     528             : {
     529           0 :     SwWrtShell* pWrtShell = m_rDocSh.GetWrtShell();
     530           0 :     SwDoc* pDoc = m_rDocSh.GetDoc();
     531           0 :     SwView* pView = m_rDocSh.GetView();
     532             : 
     533           0 :     pWrtShell->StartAllAction();
     534             : 
     535             :     // newly set the mask only with paragraph-templates
     536           0 :     if( m_bNew )
     537             :     {
     538           0 :         m_nRet = SFX_STYLE_FAMILY_PARA == m_pStyle->GetFamily()
     539           0 :                 ? m_xTmp->GetMask()
     540           0 :                 : SFXSTYLEBIT_USERDEF;
     541             :     }
     542           0 :     else if( m_pStyle->GetMask() != m_xTmp->GetMask() )
     543           0 :         m_nRet = m_xTmp->GetMask();
     544             : 
     545           0 :     if( SFX_STYLE_FAMILY_PARA == m_nFamily )
     546             :     {
     547           0 :         SfxItemSet aSet( *m_pDlg->GetOutputItemSet() );
     548           0 :         ::SfxToSwPageDescAttr( *pWrtShell, aSet  );
     549             :         // reset indent attributes at paragraph style, if a list style
     550             :         // will be applied and no indent attributes will be applied.
     551           0 :         m_xTmp->SetItemSet( aSet, true );
     552             :     }
     553             :     else
     554             :     {
     555           0 :         if(SFX_STYLE_FAMILY_PAGE == m_nFamily)
     556             :         {
     557             :             static const sal_uInt16 aInval[] = {
     558             :                 SID_IMAGE_ORIENTATION,
     559             :                 SID_ATTR_CHAR_FONT,
     560             :                 FN_INSERT_CTRL, FN_INSERT_OBJ_CTRL, 0};
     561           0 :             pView->GetViewFrame()->GetBindings().Invalidate(aInval);
     562             :         }
     563           0 :         SfxItemSet aTmpSet( *m_pDlg->GetOutputItemSet() );
     564           0 :         if( SFX_STYLE_FAMILY_CHAR == m_nFamily )
     565             :         {
     566           0 :             ::ConvertAttrGenToChar(aTmpSet, CONV_ATTR_STD);
     567             :         }
     568             : 
     569             :         //UUUU
     570           0 :         if(m_bNew && SFX_STYLE_FAMILY_FRAME == m_nFamily)
     571             :         {
     572             :             // clear FillStyle so that it works as a derived attribute
     573           0 :             aTmpSet.ClearItem(XATTR_FILLSTYLE);
     574             :         }
     575             : 
     576           0 :         m_xTmp->SetItemSet( aTmpSet );
     577             : 
     578           0 :         if( SFX_STYLE_FAMILY_PAGE == m_nFamily && SvtLanguageOptions().IsCTLFontEnabled() )
     579             :         {
     580           0 :             const SfxPoolItem *pItem = NULL;
     581           0 :             if( aTmpSet.GetItemState( m_rDocSh.GetPool().GetTrueWhich( SID_ATTR_FRAMEDIRECTION, false ) , true, &pItem ) == SFX_ITEM_SET )
     582           0 :                 SwChartHelper::DoUpdateAllCharts( pDoc );
     583           0 :         }
     584             :     }
     585           0 :     if(SFX_STYLE_FAMILY_PAGE == m_nFamily)
     586           0 :         pView->InvalidateRulerPos();
     587             : 
     588           0 :     if( m_bNew )
     589           0 :         m_xBasePool->Broadcast( SfxStyleSheetHint( SFX_STYLESHEET_CREATED, *m_xTmp.get() ) );
     590             : 
     591           0 :     pDoc->SetModified();
     592           0 :     if( !m_bModified )
     593             :     {
     594           0 :         pDoc->GetIDocumentUndoRedo().SetUndoNoResetModified();
     595             :     }
     596             : 
     597           0 :     pWrtShell->EndAllAction();
     598             : 
     599           0 :     return m_nRet;
     600             : }
     601             : 
     602             : //UUUU
     603             : //#include <svx/svdmodel.hxx>
     604             : //#include <svx/drawitem.hxx>
     605             : 
     606           0 : sal_uInt16 SwDocShell::Edit(
     607             :     const OUString &rName,
     608             :     const OUString &rParent,
     609             :     const sal_uInt16 nFamily,
     610             :     sal_uInt16 nMask,
     611             :     const sal_Bool bNew,
     612             :     const OString& sPage,
     613             :     SwWrtShell* pActShell,
     614             :     const sal_Bool bBasic )
     615             : {
     616             :     assert( GetWrtShell() );
     617           0 :     SfxStyleSheetBase *pStyle = 0;
     618             : 
     619           0 :     sal_uInt16 nRet = nMask;
     620           0 :     sal_Bool bModified = pDoc->IsModified();
     621             : 
     622           0 :     if( bNew )
     623             :     {
     624           0 :         if( SFXSTYLEBIT_ALL != nMask && SFXSTYLEBIT_USED != nMask )
     625           0 :             nMask |= SFXSTYLEBIT_USERDEF;
     626             :         else
     627           0 :             nMask = SFXSTYLEBIT_USERDEF;
     628             : 
     629           0 :         pStyle = &mxBasePool->Make( rName, (SfxStyleFamily)nFamily, nMask );
     630             : 
     631             :         // set the current one as Parent
     632           0 :         SwDocStyleSheet* pDStyle = (SwDocStyleSheet*)pStyle;
     633           0 :         switch( nFamily )
     634             :         {
     635             :             case SFX_STYLE_FAMILY_PARA:
     636             :             {
     637           0 :                 if(!rParent.isEmpty())
     638             :                 {
     639           0 :                     SwTxtFmtColl* pColl = pWrtShell->FindTxtFmtCollByName( rParent );
     640           0 :                     if(!pColl)
     641             :                     {
     642           0 :                         sal_uInt16 nId = SwStyleNameMapper::GetPoolIdFromUIName(rParent, nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL);
     643           0 :                         if(USHRT_MAX != nId)
     644           0 :                             pColl =  pWrtShell->GetTxtCollFromPool( nId );
     645             :                     }
     646           0 :                     pDStyle->GetCollection()->SetDerivedFrom( pColl );
     647           0 :                     pDStyle->PresetParent( rParent );
     648             : 
     649             :                      /*When a new paragraph style is created based on a "to outline style
     650             :                         assigned" paragraph style, the outline level attribute and the list
     651             :                         style attribute of the new paragraph style have to be set to 0
     652             :                         respectively "".*/
     653           0 :                     if (pColl && pColl->IsAssignedToListLevelOfOutlineStyle())
     654             :                     {
     655           0 :                         SwNumRuleItem aItem(aEmptyOUStr);
     656           0 :                         pDStyle->GetCollection()->SetFmtAttr( aItem );
     657           0 :                         pDStyle->GetCollection()->SetAttrOutlineLevel( 0 );
     658             :                     }
     659             :                 }
     660             :                 else
     661             :                 {
     662           0 :                     SwTxtFmtColl* pColl = pWrtShell->GetCurTxtFmtColl();
     663           0 :                     pDStyle->GetCollection()->SetDerivedFrom( pColl );
     664           0 :                     if( pColl )
     665           0 :                         pDStyle->PresetParent( pColl->GetName() );
     666             :                 }
     667             :             }
     668           0 :             break;
     669             :             case SFX_STYLE_FAMILY_CHAR:
     670             :             {
     671           0 :                 if(!rParent.isEmpty())
     672             :                 {
     673           0 :                     SwCharFmt* pCFmt = pWrtShell->FindCharFmtByName( rParent );
     674           0 :                     if(!pCFmt)
     675             :                     {
     676           0 :                         sal_uInt16 nId = SwStyleNameMapper::GetPoolIdFromUIName(rParent, nsSwGetPoolIdFromName::GET_POOLID_CHRFMT);
     677           0 :                         if(USHRT_MAX != nId)
     678           0 :                             pCFmt =  pWrtShell->GetCharFmtFromPool( nId );
     679             :                     }
     680             : 
     681           0 :                     pDStyle->GetCharFmt()->SetDerivedFrom( pCFmt );
     682           0 :                     pDStyle->PresetParent( rParent );
     683             :                 }
     684             :                 else
     685             :                 {
     686           0 :                     SwCharFmt* pCFmt = pWrtShell->GetCurCharFmt();
     687           0 :                     pDStyle->GetCharFmt()->SetDerivedFrom( pCFmt );
     688           0 :                         if( pCFmt )
     689           0 :                             pDStyle->PresetParent( pCFmt->GetName() );
     690             :                 }
     691             :             }
     692           0 :             break;
     693             :             case SFX_STYLE_FAMILY_FRAME :
     694             :             {
     695           0 :                 if(!rParent.isEmpty())
     696             :                 {
     697           0 :                     SwFrmFmt* pFFmt = pWrtShell->GetDoc()->FindFrmFmtByName( rParent );
     698           0 :                     if(!pFFmt)
     699             :                     {
     700           0 :                         sal_uInt16 nId = SwStyleNameMapper::GetPoolIdFromUIName(rParent, nsSwGetPoolIdFromName::GET_POOLID_FRMFMT);
     701           0 :                         if(USHRT_MAX != nId)
     702           0 :                             pFFmt =  pWrtShell->GetFrmFmtFromPool( nId );
     703             :                     }
     704           0 :                     pDStyle->GetFrmFmt()->SetDerivedFrom( pFFmt );
     705           0 :                     pDStyle->PresetParent( rParent );
     706             :                 }
     707             :             }
     708           0 :             break;
     709             :         }
     710             :     }
     711             :     else
     712             :     {
     713           0 :         pStyle = mxBasePool->Find( rName, (SfxStyleFamily)nFamily );
     714             :         SAL_WARN_IF( !pStyle, "sw.ui", "Style not found" );
     715             :     }
     716             : 
     717           0 :     if(!pStyle)
     718           0 :         return sal_False;
     719             : 
     720             :     // put dialogues together
     721           0 :     rtl::Reference< SwDocStyleSheet > xTmp( new SwDocStyleSheet( *(SwDocStyleSheet*)pStyle ) );
     722           0 :     if( SFX_STYLE_FAMILY_PARA == nFamily )
     723             :     {
     724           0 :         SfxItemSet& rSet = xTmp->GetItemSet();
     725           0 :         ::SwToSfxPageDescAttr( rSet );
     726             :         // firstly only a Zero
     727           0 :         rSet.Put(SwBackgroundDestinationItem(SID_PARA_BACKGRND_DESTINATION, 0));
     728             :         // merge list level indent attributes into the item set if needed
     729           0 :         xTmp->MergeIndentAttrsOfListStyle( rSet );
     730             :     }
     731           0 :     else if( SFX_STYLE_FAMILY_CHAR == nFamily )
     732             :     {
     733           0 :         ::ConvertAttrCharToGen(xTmp->GetItemSet(), CONV_ATTR_STD);
     734             :     }
     735           0 :     if (!bBasic)
     736             :     {
     737             :         //UUUU
     738             :         //if(SFX_STYLE_FAMILY_FRAME == nFamily)
     739             :         //{
     740             :         //    //UUUU create needed items for XPropertyList entries from the DrawModel so that
     741             :         //    // the Area TabPage can access them
     742             :         //    SfxItemSet& rSet = xTmp->GetItemSet();
     743             :         //    const SdrModel* pDrawModel = GetDoc()->GetDrawModel();
     744             :         //
     745             :         //    rSet.Put(SvxColorTableItem(pDrawModel->GetColorTableFromSdrModel(), SID_COLOR_TABLE));
     746             :         //    rSet.Put(SvxGradientListItem(pDrawModel->GetGradientListFromSdrModel(), SID_GRADIENT_LIST));
     747             :         //    rSet.Put(SvxHatchListItem(pDrawModel->GetHatchListFromSdrModel(), SID_HATCH_LIST));
     748             :         //    rSet.Put(SvxBitmapListItem(pDrawModel->GetBitmapListFromSdrModel(), SID_BITMAP_LIST));
     749             :         //}
     750             : 
     751             :         // prior to the dialog the HtmlMode at the DocShell is being sunk
     752           0 :         sal_uInt16 nHtmlMode = ::GetHtmlMode(this);
     753             : 
     754             :         // In HTML mode, we do not always have a printer. In order to show
     755             :         // the correct page size in the Format - Page dialog, we have to
     756             :         // get one here.
     757           0 :         SwWrtShell* pCurrShell = ( pActShell ? pActShell : pWrtShell );
     758           0 :         if( ( HTMLMODE_ON & nHtmlMode ) &&
     759           0 :             !pCurrShell->getIDocumentDeviceAccess()->getPrinter( false ) )
     760           0 :             pCurrShell->InitPrt( pCurrShell->getIDocumentDeviceAccess()->getPrinter( true ) );
     761             : 
     762           0 :         PutItem(SfxUInt16Item(SID_HTML_MODE, nHtmlMode));
     763           0 :         FieldUnit eMetric = ::GetDfltMetric(0 != (HTMLMODE_ON&nHtmlMode));
     764           0 :         SW_MOD()->PutItem(SfxUInt16Item(SID_ATTR_METRIC, static_cast< sal_uInt16 >(eMetric)));
     765           0 :         SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
     766             :         assert( pFact );
     767             :         boost::scoped_ptr<SfxAbstractApplyTabDialog> pDlg(pFact->CreateTemplateDialog(
     768           0 :                                                     0, *(xTmp.get()), nFamily, sPage,
     769           0 :                                                     pActShell ? pActShell : pWrtShell, bNew));
     770             :         assert( pDlg );
     771           0 :         ApplyStyle aApplyStyleHelper(*this, bNew, pStyle, nRet, xTmp, nFamily, pDlg.get(), mxBasePool, bModified);
     772           0 :         pDlg->SetApplyHdl(LINK(&aApplyStyleHelper, ApplyStyle, ApplyHdl));
     773             : 
     774           0 :         if (RET_OK == pDlg->Execute())
     775             :         {
     776           0 :             aApplyStyleHelper.apply();
     777             :         }
     778             :         else
     779             :         {
     780           0 :             if( bNew )
     781             :             {
     782           0 :                 GetWrtShell()->Undo(1);
     783           0 :                 pDoc->GetIDocumentUndoRedo().ClearRedo();
     784             :             }
     785             : 
     786           0 :             if( !bModified )
     787           0 :                 pDoc->ResetModified();
     788             :         }
     789             : 
     790           0 :         nRet = aApplyStyleHelper.getRet();
     791             :     }
     792             :     else
     793             :     {
     794             :         // prior to the dialog the HtmlMode at the DocShell is being sunk
     795           0 :         PutItem(SfxUInt16Item(SID_HTML_MODE, ::GetHtmlMode(this)));
     796             : 
     797           0 :         GetWrtShell()->StartAllAction();
     798             : 
     799             :         // newly set the mask only with paragraph-templates
     800           0 :         if( bNew )
     801             :         {
     802           0 :             nRet = SFX_STYLE_FAMILY_PARA == pStyle->GetFamily()
     803           0 :                     ? xTmp->GetMask()
     804           0 :                     : SFXSTYLEBIT_USERDEF;
     805             :         }
     806           0 :         else if( pStyle->GetMask() != xTmp->GetMask() )
     807           0 :             nRet = xTmp->GetMask();
     808             : 
     809           0 :         if( SFX_STYLE_FAMILY_PARA == nFamily )
     810           0 :             ::SfxToSwPageDescAttr( *GetWrtShell(), xTmp->GetItemSet() );
     811             :         else
     812             :         {
     813           0 :             ::ConvertAttrGenToChar(xTmp->GetItemSet(), CONV_ATTR_STD);
     814             :         }
     815           0 :         if(SFX_STYLE_FAMILY_PAGE == nFamily)
     816           0 :             pView->InvalidateRulerPos();
     817             : 
     818           0 :         if( bNew )
     819           0 :             mxBasePool->Broadcast( SfxStyleSheetHint( SFX_STYLESHEET_CREATED, *xTmp.get() ) );
     820             : 
     821           0 :         pDoc->SetModified();
     822           0 :         if( !bModified )        // Bug 57028
     823             :         {
     824           0 :             pDoc->GetIDocumentUndoRedo().SetUndoNoResetModified();
     825             :         }
     826           0 :         GetWrtShell()->EndAllAction();
     827             :     }
     828             : 
     829           0 :     return nRet;
     830             : }
     831             : 
     832             : // Delete
     833           0 : sal_uInt16 SwDocShell::Delete(const OUString &rName, sal_uInt16 nFamily)
     834             : {
     835           0 :     SfxStyleSheetBase *pStyle = mxBasePool->Find(rName, (SfxStyleFamily)nFamily);
     836             : 
     837           0 :     if(pStyle)
     838             :     {
     839             :         assert( GetWrtShell() );
     840             : 
     841           0 :         GetWrtShell()->StartAllAction();
     842           0 :         mxBasePool->Remove(pStyle);
     843           0 :         GetWrtShell()->EndAllAction();
     844             : 
     845           0 :         return sal_True;
     846             :     }
     847           0 :     return sal_False;
     848             : }
     849             : 
     850           0 : sal_uInt16 SwDocShell::Hide(const OUString &rName, sal_uInt16 nFamily, bool bHidden)
     851             : {
     852           0 :     SfxStyleSheetBase *pStyle = mxBasePool->Find(rName, (SfxStyleFamily)nFamily);
     853             : 
     854           0 :     if(pStyle)
     855             :     {
     856             :         assert( GetWrtShell() );
     857             : 
     858           0 :         GetWrtShell()->StartAllAction();
     859           0 :         rtl::Reference< SwDocStyleSheet > xTmp( new SwDocStyleSheet( *(SwDocStyleSheet*)pStyle ) );
     860           0 :         xTmp->SetHidden( bHidden );
     861           0 :         GetWrtShell()->EndAllAction();
     862             : 
     863           0 :         return sal_True;
     864             :     }
     865           0 :     return sal_False;
     866             : }
     867             : 
     868             : // apply template
     869           0 : sal_uInt16 SwDocShell::ApplyStyles(const OUString &rName, sal_uInt16 nFamily,
     870             :                                SwWrtShell* pShell, const sal_uInt16 nMode )
     871             : {
     872           0 :     SwDocStyleSheet* pStyle = (SwDocStyleSheet*) mxBasePool->Find( rName, (SfxStyleFamily) nFamily );
     873             : 
     874             :     SAL_WARN_IF( !pStyle, "sw.ui", "Style not found" );
     875             : 
     876           0 :     if(!pStyle)
     877           0 :         return sal_False;
     878             : 
     879           0 :     SwWrtShell *pSh = pShell ? pShell : GetWrtShell();
     880             : 
     881             :     assert( pSh );
     882             : 
     883           0 :     pSh->StartAllAction();
     884             : 
     885           0 :     switch (nFamily)
     886             :     {
     887             :         case SFX_STYLE_FAMILY_CHAR:
     888             :         {
     889           0 :             SwFmtCharFmt aFmt(pStyle->GetCharFmt());
     890           0 :             pSh->SetAttrItem( aFmt, (nMode & KEY_SHIFT) ?
     891           0 :                 nsSetAttrMode::SETATTR_DONTREPLACE : nsSetAttrMode::SETATTR_DEFAULT );
     892           0 :             break;
     893             :         }
     894             :         case SFX_STYLE_FAMILY_PARA:
     895             :         {
     896             :             // #i62675#
     897             :             // clear also list attributes at affected text nodes, if paragraph
     898             :             // style has the list style attribute set.
     899           0 :             pSh->SetTxtFmtColl( pStyle->GetCollection(), true );
     900           0 :             break;
     901             :         }
     902             :         case SFX_STYLE_FAMILY_FRAME:
     903             :         {
     904           0 :             if ( pSh->IsFrmSelected() )
     905           0 :                 pSh->SetFrmFmt( pStyle->GetFrmFmt() );
     906           0 :             break;
     907             :         }
     908             :         case SFX_STYLE_FAMILY_PAGE:
     909             :         {
     910           0 :             pSh->SetPageStyle(pStyle->GetPageDesc()->GetName());
     911           0 :             break;
     912             :         }
     913             :         case SFX_STYLE_FAMILY_PSEUDO:
     914             :         {
     915             :             // reset indent attribute on applying list style
     916             :             // continue list of list style
     917           0 :             const SwNumRule* pNumRule = pStyle->GetNumRule();
     918           0 :             const OUString sListIdForStyle =pNumRule->GetDefaultListId();
     919           0 :             pSh->SetCurNumRule( *pNumRule, false, sListIdForStyle, true );
     920           0 :             break;
     921             :         }
     922             :         default:
     923             :             OSL_FAIL("Unknown family");
     924             :     }
     925           0 :     pSh->EndAllAction();
     926             : 
     927           0 :     return nFamily;
     928             : }
     929             : 
     930             : // start watering-can
     931           0 : sal_uInt16 SwDocShell::DoWaterCan(const OUString &rName, sal_uInt16 nFamily)
     932             : {
     933             :     assert( GetWrtShell() );
     934             : 
     935           0 :     SwEditWin& rEdtWin = pView->GetEditWin();
     936           0 :     SwApplyTemplate* pApply = rEdtWin.GetApplyTemplate();
     937           0 :     bool bWaterCan = !(pApply && pApply->eType != 0);
     938             : 
     939           0 :     if( rName.isEmpty() )
     940           0 :         bWaterCan = false;
     941             : 
     942           0 :     SwApplyTemplate aTemplate;
     943           0 :     aTemplate.eType = nFamily;
     944             : 
     945           0 :     if(bWaterCan)
     946             :     {
     947             :         SwDocStyleSheet* pStyle =
     948           0 :             (SwDocStyleSheet*)mxBasePool->Find(rName, (SfxStyleFamily)nFamily);
     949             : 
     950             :         SAL_WARN_IF( !pStyle, "sw.ui", "Where's the StyleSheet" );
     951             : 
     952           0 :         if(!pStyle) return nFamily;
     953             : 
     954           0 :         switch(nFamily)
     955             :         {
     956             :             case SFX_STYLE_FAMILY_CHAR:
     957           0 :                 aTemplate.aColl.pCharFmt = pStyle->GetCharFmt();
     958           0 :                 break;
     959             :             case SFX_STYLE_FAMILY_PARA:
     960           0 :                 aTemplate.aColl.pTxtColl = pStyle->GetCollection();
     961           0 :                 break;
     962             :             case SFX_STYLE_FAMILY_FRAME:
     963           0 :                 aTemplate.aColl.pFrmFmt = pStyle->GetFrmFmt();
     964           0 :                 break;
     965             :             case SFX_STYLE_FAMILY_PAGE:
     966           0 :                 aTemplate.aColl.pPageDesc = (SwPageDesc*)pStyle->GetPageDesc();
     967           0 :                 break;
     968             :             case SFX_STYLE_FAMILY_PSEUDO:
     969           0 :                 aTemplate.aColl.pNumRule = (SwNumRule*)pStyle->GetNumRule();
     970           0 :                 break;
     971             : 
     972             :             default:
     973             :                 OSL_FAIL("Unknown family");
     974             :         }
     975             :     }
     976             :     else
     977           0 :         aTemplate.eType = 0;
     978             : 
     979           0 :     pView->GetEditWin().SetApplyTemplate(aTemplate);
     980             : 
     981           0 :     return nFamily;
     982             : }
     983             : 
     984             : // update template
     985           0 : sal_uInt16 SwDocShell::UpdateStyle(const OUString &rName, sal_uInt16 nFamily, SwWrtShell* pShell)
     986             : {
     987           0 :     SwWrtShell* pCurrWrtShell = pShell ? pShell : GetWrtShell();
     988             :     assert( pCurrWrtShell );
     989             : 
     990             :     SwDocStyleSheet* pStyle =
     991           0 :         (SwDocStyleSheet*)mxBasePool->Find(rName, (SfxStyleFamily)nFamily);
     992             : 
     993           0 :     if(!pStyle)
     994           0 :         return nFamily;
     995             : 
     996           0 :     switch(nFamily)
     997             :     {
     998             :         case SFX_STYLE_FAMILY_PARA:
     999             :         {
    1000           0 :             SwTxtFmtColl* pColl = pStyle->GetCollection();
    1001           0 :             if(pColl && !pColl->IsDefault())
    1002             :             {
    1003           0 :                 GetWrtShell()->StartAllAction();
    1004             : 
    1005           0 :                 SwRewriter aRewriter;
    1006           0 :                 aRewriter.AddRule(UndoArg1, pColl->GetName());
    1007             : 
    1008           0 :                 GetWrtShell()->StartUndo(UNDO_INSFMTATTR, &aRewriter);
    1009           0 :                 GetWrtShell()->FillByEx(pColl);
    1010             :                     // also apply template to remove hard set attributes
    1011           0 :                 GetWrtShell()->SetTxtFmtColl( pColl );
    1012           0 :                 GetWrtShell()->EndUndo();
    1013           0 :                 GetWrtShell()->EndAllAction();
    1014             :             }
    1015           0 :             break;
    1016             :         }
    1017             :         case SFX_STYLE_FAMILY_FRAME:
    1018             :         {
    1019           0 :             SwFrmFmt* pFrm = pStyle->GetFrmFmt();
    1020           0 :             if( pCurrWrtShell->IsFrmSelected() && pFrm && !pFrm->IsDefault() )
    1021             :             {
    1022           0 :                 SfxItemSet aSet( GetPool(), aFrmFmtSetRange );
    1023           0 :                 pCurrWrtShell->StartAllAction();
    1024           0 :                 pCurrWrtShell->GetFlyFrmAttr( aSet );
    1025             : 
    1026             :                 // #i105535#
    1027             :                 // no update of anchor attribute
    1028           0 :                 aSet.ClearItem( RES_ANCHOR );
    1029             : 
    1030           0 :                 pFrm->SetFmtAttr( aSet );
    1031             : 
    1032             :                     // also apply template to remove hard set attributes
    1033           0 :                 pCurrWrtShell->SetFrmFmt( pFrm, true );
    1034           0 :                 pCurrWrtShell->EndAllAction();
    1035             :             }
    1036             :         }
    1037           0 :         break;
    1038             :         case SFX_STYLE_FAMILY_CHAR:
    1039             :         {
    1040           0 :             SwCharFmt* pChar = pStyle->GetCharFmt();
    1041           0 :             if( pChar && !pChar->IsDefault() )
    1042             :             {
    1043           0 :                 pCurrWrtShell->StartAllAction();
    1044           0 :                 pCurrWrtShell->FillByEx(pChar);
    1045             :                 // also apply template to remove hard set attributes
    1046           0 :                 pCurrWrtShell->EndAllAction();
    1047             :             }
    1048             : 
    1049             :         }
    1050           0 :         break;
    1051             :         case SFX_STYLE_FAMILY_PSEUDO:
    1052             :         {
    1053             :             const SwNumRule* pCurRule;
    1054           0 :             if( pStyle->GetNumRule() &&
    1055           0 :                 0 != ( pCurRule = pCurrWrtShell->GetNumRuleAtCurrCrsrPos() ))
    1056             :             {
    1057           0 :                 SwNumRule aRule( *pCurRule );
    1058             :                 // #i91400#
    1059             :                 aRule.SetName( pStyle->GetNumRule()->GetName(),
    1060           0 :                                *(pCurrWrtShell->GetDoc()) );
    1061           0 :                 pCurrWrtShell->ChgNumRuleFmts( aRule );
    1062             :             }
    1063             :         }
    1064           0 :         break;
    1065             :     }
    1066           0 :     return nFamily;
    1067             : }
    1068             : 
    1069             : // NewByExample
    1070           0 : sal_uInt16 SwDocShell::MakeByExample( const OUString &rName, sal_uInt16 nFamily,
    1071             :                                     sal_uInt16 nMask, SwWrtShell* pShell )
    1072             : {
    1073           0 :     SwWrtShell* pCurrWrtShell = pShell ? pShell : GetWrtShell();
    1074           0 :     SwDocStyleSheet* pStyle = (SwDocStyleSheet*)mxBasePool->Find(
    1075           0 :                                             rName, (SfxStyleFamily)nFamily );
    1076           0 :     if(!pStyle)
    1077             :     {
    1078             :         // preserve the current mask of PI, then the new one is
    1079             :         // immediately merged with the viewable area
    1080           0 :         if( SFXSTYLEBIT_ALL == nMask || SFXSTYLEBIT_USED == nMask )
    1081           0 :             nMask = SFXSTYLEBIT_USERDEF;
    1082             :         else
    1083           0 :             nMask |= SFXSTYLEBIT_USERDEF;
    1084             : 
    1085           0 :         pStyle = (SwDocStyleSheet*)&mxBasePool->Make(rName,
    1086           0 :                                 (SfxStyleFamily)nFamily, nMask );
    1087             :     }
    1088             : 
    1089           0 :     switch(nFamily)
    1090             :     {
    1091             :         case  SFX_STYLE_FAMILY_PARA:
    1092             :         {
    1093           0 :             SwTxtFmtColl* pColl = pStyle->GetCollection();
    1094           0 :             if(pColl && !pColl->IsDefault())
    1095             :             {
    1096           0 :                 pCurrWrtShell->StartAllAction();
    1097           0 :                 pCurrWrtShell->FillByEx(pColl);
    1098             :                     // also apply template to remove hard set attributes
    1099           0 :                 pColl->SetDerivedFrom(pCurrWrtShell->GetCurTxtFmtColl());
    1100             : 
    1101             :                     // set the mask at the Collection:
    1102           0 :                 sal_uInt16 nId = pColl->GetPoolFmtId() & 0x87ff;
    1103           0 :                 switch( nMask & 0x0fff )
    1104             :                 {
    1105             :                     case SWSTYLEBIT_TEXT:
    1106           0 :                         nId |= COLL_TEXT_BITS;
    1107           0 :                         break;
    1108             :                     case SWSTYLEBIT_CHAPTER:
    1109           0 :                         nId |= COLL_DOC_BITS;
    1110           0 :                         break;
    1111             :                     case SWSTYLEBIT_LIST:
    1112           0 :                         nId |= COLL_LISTS_BITS;
    1113           0 :                         break;
    1114             :                     case SWSTYLEBIT_IDX:
    1115           0 :                         nId |= COLL_REGISTER_BITS;
    1116           0 :                         break;
    1117             :                     case SWSTYLEBIT_EXTRA:
    1118           0 :                         nId |= COLL_EXTRA_BITS;
    1119           0 :                         break;
    1120             :                     case SWSTYLEBIT_HTML:
    1121           0 :                         nId |= COLL_HTML_BITS;
    1122           0 :                         break;
    1123             :                 }
    1124           0 :                 pColl->SetPoolFmtId(nId);
    1125             : 
    1126           0 :                 pCurrWrtShell->SetTxtFmtColl(pColl);
    1127           0 :                 pCurrWrtShell->EndAllAction();
    1128             :             }
    1129             :         }
    1130           0 :         break;
    1131             :         case SFX_STYLE_FAMILY_FRAME:
    1132             :         {
    1133           0 :             SwFrmFmt* pFrm = pStyle->GetFrmFmt();
    1134           0 :             if(pCurrWrtShell->IsFrmSelected() && pFrm && !pFrm->IsDefault())
    1135             :             {
    1136           0 :                 pCurrWrtShell->StartAllAction();
    1137             : 
    1138           0 :                 SfxItemSet aSet(GetPool(), aFrmFmtSetRange );
    1139           0 :                 pCurrWrtShell->GetFlyFrmAttr( aSet );
    1140             : 
    1141           0 :                 SwFrmFmt* pFFmt = pCurrWrtShell->GetCurFrmFmt();
    1142           0 :                 pFrm->SetDerivedFrom( pFFmt );
    1143             : 
    1144           0 :                 pFrm->SetFmtAttr( aSet );
    1145             :                     // also apply template to remove hard set attributes
    1146           0 :                 pCurrWrtShell->SetFrmFmt( pFrm );
    1147           0 :                 pCurrWrtShell->EndAllAction();
    1148             :             }
    1149             :         }
    1150           0 :         break;
    1151             :         case SFX_STYLE_FAMILY_CHAR:
    1152             :         {
    1153           0 :             SwCharFmt* pChar = pStyle->GetCharFmt();
    1154           0 :             if(pChar && !pChar->IsDefault())
    1155             :             {
    1156           0 :                 pCurrWrtShell->StartAllAction();
    1157           0 :                 pCurrWrtShell->FillByEx( pChar );
    1158           0 :                 pChar->SetDerivedFrom( pCurrWrtShell->GetCurCharFmt() );
    1159           0 :                 SwFmtCharFmt aFmt( pChar );
    1160           0 :                 pCurrWrtShell->SetAttrItem( aFmt );
    1161           0 :                 pCurrWrtShell->EndAllAction();
    1162             :             }
    1163             :         }
    1164           0 :         break;
    1165             : 
    1166             :         case SFX_STYLE_FAMILY_PAGE:
    1167             :         {
    1168           0 :             pCurrWrtShell->StartAllAction();
    1169           0 :             sal_uInt16 nPgDsc = pCurrWrtShell->GetCurPageDesc();
    1170           0 :             SwPageDesc& rSrc = (SwPageDesc&)pCurrWrtShell->GetPageDesc( nPgDsc );
    1171           0 :             SwPageDesc& rDest = *(SwPageDesc*)pStyle->GetPageDesc();
    1172             : 
    1173           0 :             sal_uInt16 nPoolId = rDest.GetPoolFmtId();
    1174           0 :             sal_uInt16 nHId = rDest.GetPoolHelpId();
    1175           0 :             sal_uInt8 nHFId = rDest.GetPoolHlpFileId();
    1176             : 
    1177           0 :             pCurrWrtShell->GetDoc()->CopyPageDesc( rSrc, rDest );
    1178             : 
    1179             :             // PoolId must NEVER be copied!
    1180           0 :             rDest.SetPoolFmtId( nPoolId );
    1181           0 :             rDest.SetPoolHelpId( nHId );
    1182           0 :             rDest.SetPoolHlpFileId( nHFId );
    1183             : 
    1184             :             // when Headers/Footers are created, there is no Undo anymore!
    1185           0 :             pCurrWrtShell->GetDoc()->GetIDocumentUndoRedo().DelAllUndoObj();
    1186             : 
    1187           0 :             pCurrWrtShell->EndAllAction();
    1188             :         }
    1189           0 :         break;
    1190             : 
    1191             :         case SFX_STYLE_FAMILY_PSEUDO:
    1192             :         {
    1193           0 :             const SwNumRule* pCurRule = pCurrWrtShell->GetNumRuleAtCurrCrsrPos();
    1194             : 
    1195           0 :             if (pCurRule)
    1196             :             {
    1197           0 :                 pCurrWrtShell->StartAllAction();
    1198             : 
    1199           0 :                 SwNumRule aRule( *pCurRule );
    1200           0 :                 OUString sOrigRule( aRule.GetName() );
    1201             :                 // #i91400#
    1202             :                 aRule.SetName( pStyle->GetNumRule()->GetName(),
    1203           0 :                                *(pCurrWrtShell->GetDoc()) );
    1204           0 :                 pCurrWrtShell->ChgNumRuleFmts( aRule );
    1205             : 
    1206           0 :                 pCurrWrtShell->ReplaceNumRule( sOrigRule, aRule.GetName() );
    1207             : 
    1208           0 :                 pCurrWrtShell->EndAllAction();
    1209             :             }
    1210             :         }
    1211           0 :         break;
    1212             :     }
    1213           0 :     return nFamily;
    1214             : }
    1215             : 
    1216           0 : void  SwDocShell::LoadStyles( SfxObjectShell& rSource )
    1217             : {
    1218           0 :     _LoadStyles(rSource, sal_False);
    1219           0 : }
    1220             : /* --------------------------------------------------
    1221             :     bPreserveCurrentDocument determines whether SetFixFields() is called
    1222             :     This call modifies the source document. This mustn't happen when the source
    1223             :     is a document the user is working on.
    1224             :     Calls of ::LoadStyles() normally use files especially loaded for the purpose
    1225             :     of importing styles.
    1226             :  --------------------------------------------------*/
    1227           0 : void SwDocShell::_LoadStyles( SfxObjectShell& rSource, sal_Bool bPreserveCurrentDocument )
    1228             : {
    1229             : /*  [Description]
    1230             : 
    1231             :     This method is called by SFx if Styles have to be reloaded from a
    1232             :     document-template. Existing Styles should be overwritten by that.
    1233             :     That's why the document has to be reformatted. Therefore applications
    1234             :     will usually overload this method and call the baseclass' implementation
    1235             :     in their implementation.
    1236             : */
    1237             :     // When the source is our document, we do the checking ourselves
    1238             :     // (much quicker and doesn't use the crutch StxStylePool).
    1239           0 :     if( rSource.ISA( SwDocShell ))
    1240             :     {
    1241             :         // in order for the Headers/Footers not to get the fixed content
    1242             :         // of the template, update all the Source's
    1243             :         // FixFields once.
    1244           0 :         if(!bPreserveCurrentDocument)
    1245           0 :             ((SwDocShell&)rSource).pDoc->SetFixFields(false, NULL);
    1246           0 :         if( pWrtShell )
    1247             :         {
    1248             :             // rhbz#818557, fdo#58893: EndAllAction will call SelectShell(),
    1249             :             // which pushes a bunch of SfxShells that are not cleared
    1250             :             // (for unknown reasons) when closing the document, causing crash;
    1251             :             // setting bNoInterrupt appears to avoid the problem.
    1252           0 :             ::comphelper::FlagRestorationGuard g(bNoInterrupt, true);
    1253           0 :             pWrtShell->StartAllAction();
    1254           0 :             pDoc->ReplaceStyles( *((SwDocShell&)rSource).pDoc );
    1255           0 :             pWrtShell->EndAllAction();
    1256             :         }
    1257             :         else
    1258             :         {
    1259           0 :             sal_Bool bModified = pDoc->IsModified();
    1260           0 :             pDoc->ReplaceStyles( *((SwDocShell&)rSource).pDoc );
    1261           0 :             if( !bModified && pDoc->IsModified() && !pView )
    1262             :             {
    1263             :                 // the View is created later, but overwrites the Modify-Flag.
    1264             :                 // Undo doesn't work anymore anyways.
    1265           0 :                 pDoc->GetIDocumentUndoRedo().SetUndoNoResetModified();
    1266             :             }
    1267             :         }
    1268             :     }
    1269             :     else
    1270           0 :         SfxObjectShell::LoadStyles( rSource );
    1271           0 : }
    1272             : 
    1273           0 : void SwDocShell::FormatPage(
    1274             :     const OUString& rPage,
    1275             :     const OString& rPageId,
    1276             :     SwWrtShell& rActShell )
    1277             : {
    1278           0 :     Edit( rPage, aEmptyOUStr, SFX_STYLE_FAMILY_PAGE, 0, sal_False, rPageId, &rActShell);
    1279           0 : }
    1280             : 
    1281             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10