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

Generated by: LCOV version 1.10