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

Generated by: LCOV version 1.11