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

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include "formatclipboard.hxx"
      21             : 
      22             : #include <svx/svxids.hrc>
      23             : #include <cmdid.h>
      24             : #include <charfmt.hxx>
      25             : #include <frmfmt.hxx>
      26             : #include <docstyle.hxx>
      27             : #include <fchrfmt.hxx>
      28             : // header for class SdrView
      29             : #include <svx/svdview.hxx>
      30             : //SvxBrushItem
      31             : #include <editeng/brushitem.hxx>
      32             : #include <editeng/shaditem.hxx>
      33             : // header for class SvxBoxInfoItem
      34             : #include <editeng/boxitem.hxx>
      35             : // header for class SvxFmtBreakItem
      36             : #include <editeng/formatbreakitem.hxx>
      37             : // header for class SwFmtLayoutSplit
      38             : #include <fmtlsplt.hxx>
      39             : // header for class SvxFmtKeepItem
      40             : #include <editeng/keepitem.hxx>
      41             : // header for class SvxFrameDirectionItem
      42             : #include <editeng/frmdiritem.hxx>
      43             : #include <fmtpdsc.hxx>
      44             : #include <fmtrowsplt.hxx>
      45             : 
      46             : namespace
      47             : {
      48             : #define FORMAT_PAINTBRUSH_FRAME_IDS \
      49             : RES_FRMATR_BEGIN, RES_FILL_ORDER, \
      50             : /* no RES_FRM_SIZE */ \
      51             : RES_PAPER_BIN, RES_SURROUND, \
      52             : /* no RES_VERT_ORIENT */ \
      53             : /* no RES_HORI_ORIENT */ \
      54             : /* no RES_ANCHOR */ \
      55             : RES_BACKGROUND, RES_SHADOW, \
      56             : /* no RES_FRMMACRO */ \
      57             : RES_COL, RES_KEEP, \
      58             : /* no RES_URL */ \
      59             : RES_EDIT_IN_READONLY, RES_LAYOUT_SPLIT, \
      60             : /* no RES_CHAIN */ \
      61             : RES_TEXTGRID, RES_FRMATR_END-1,
      62             : 
      63             : #define FORMAT_PAINTBRUSH_PARAGRAPH_IDS \
      64             : RES_PARATR_BEGIN, RES_PARATR_END -1, \
      65             : RES_PARATR_LIST_BEGIN, RES_PARATR_LIST_END -1, \
      66             : FORMAT_PAINTBRUSH_FRAME_IDS
      67             : 
      68           0 : SfxItemSet* lcl_CreateEmptyItemSet( int nSelectionType, SfxItemPool& rPool, bool bNoParagraphFormats = false )
      69             : {
      70           0 :     SfxItemSet* pItemSet = 0;
      71           0 :     if( nSelectionType & (nsSelectionType::SEL_FRM | nsSelectionType::SEL_OLE | nsSelectionType::SEL_GRF) )
      72             :     {
      73             :         pItemSet = new SfxItemSet(rPool,
      74             :                         FORMAT_PAINTBRUSH_FRAME_IDS
      75           0 :                         0);
      76             :     }
      77           0 :     else if( nSelectionType & nsSelectionType::SEL_DRW )
      78             :     {
      79             :         //is handled different
      80             :     }
      81           0 :     else if( nSelectionType & nsSelectionType::SEL_TXT )
      82             :     {
      83           0 :         if( bNoParagraphFormats )
      84             :             pItemSet = new SfxItemSet(rPool,
      85             :                     RES_CHRATR_BEGIN, RES_CHRATR_END - 1,
      86           0 :                     0);
      87             :         else
      88             :             pItemSet = new SfxItemSet(rPool,
      89             :                     RES_CHRATR_BEGIN, RES_CHRATR_END - 1,
      90             :                     FORMAT_PAINTBRUSH_PARAGRAPH_IDS
      91           0 :                     0);
      92             :     }
      93           0 :     return pItemSet;
      94             : }
      95             : 
      96           0 : void lcl_getTableAttributes( SfxItemSet& rSet, SwWrtShell &rSh )
      97             : {
      98           0 :     SvxBrushItem aBrush( RES_BACKGROUND );
      99           0 :      rSh.GetBoxBackground(aBrush);
     100           0 :     rSet.Put( aBrush );
     101           0 :     if(rSh.GetRowBackground(aBrush))
     102           0 :         rSet.Put( aBrush, SID_ATTR_BRUSH_ROW );
     103             :     else
     104           0 :         rSet.InvalidateItem(SID_ATTR_BRUSH_ROW);
     105           0 :     rSh.GetTabBackground(aBrush);
     106           0 :     rSet.Put( aBrush, SID_ATTR_BRUSH_TABLE );
     107             : 
     108           0 :     SvxBoxInfoItem aBoxInfo( SID_ATTR_BORDER_INNER );
     109           0 :     rSet.Put(aBoxInfo);
     110           0 :     rSh.GetTabBorders( rSet );
     111             : 
     112           0 :     SvxFrameDirectionItem aBoxDirection( FRMDIR_ENVIRONMENT, RES_FRAMEDIR );
     113           0 :     if(rSh.GetBoxDirection( aBoxDirection ))
     114           0 :         rSet.Put(aBoxDirection, FN_TABLE_BOX_TEXTORIENTATION);
     115             : 
     116           0 :     rSet.Put(SfxUInt16Item(FN_TABLE_SET_VERT_ALIGN, rSh.GetBoxAlign()));
     117             : 
     118           0 :     rSet.Put( SfxUInt16Item( FN_PARAM_TABLE_HEADLINE, rSh.GetRowsToRepeat() ) );
     119             : 
     120           0 :     SwFrmFmt *pFrmFmt = rSh.GetTableFmt();
     121           0 :     if(pFrmFmt)
     122             :     {
     123           0 :         rSet.Put( pFrmFmt->GetShadow() );
     124           0 :         rSet.Put( pFrmFmt->GetBreak() );
     125           0 :         rSet.Put( pFrmFmt->GetPageDesc() );
     126           0 :         rSet.Put( pFrmFmt->GetLayoutSplit() );
     127           0 :         rSet.Put( pFrmFmt->GetKeep() );
     128           0 :         rSet.Put( pFrmFmt->GetFrmDir() );
     129             :     }
     130             : 
     131           0 :     SwFmtRowSplit* pSplit = 0;
     132           0 :     rSh.GetRowSplit(pSplit);
     133           0 :     if(pSplit)
     134           0 :         rSet.Put(*pSplit);
     135           0 : }
     136             : 
     137           0 : void lcl_setTableAttributes( const SfxItemSet& rSet, SwWrtShell &rSh )
     138             : {
     139           0 :     const SfxPoolItem* pItem = 0;
     140           0 :     bool bBorder = ( SFX_ITEM_SET == rSet.GetItemState( RES_BOX ) ||
     141           0 :             SFX_ITEM_SET == rSet.GetItemState( SID_ATTR_BORDER_INNER ) );
     142           0 :     bool bBackground = SFX_ITEM_SET == rSet.GetItemState( RES_BACKGROUND, false, &pItem );
     143           0 :     const SfxPoolItem* pRowItem = 0, *pTableItem = 0;
     144           0 :     bBackground |= SFX_ITEM_SET == rSet.GetItemState( SID_ATTR_BRUSH_ROW, false, &pRowItem );
     145           0 :     bBackground |= SFX_ITEM_SET == rSet.GetItemState( SID_ATTR_BRUSH_TABLE, false, &pTableItem );
     146             : 
     147           0 :     if(bBackground)
     148             :     {
     149           0 :         if(pItem)
     150           0 :             rSh.SetBoxBackground( *(const SvxBrushItem*)pItem );
     151           0 :         if(pRowItem)
     152             :         {
     153           0 :             SvxBrushItem aBrush(*(const SvxBrushItem*)pRowItem);
     154           0 :             aBrush.SetWhich(RES_BACKGROUND);
     155           0 :             rSh.SetRowBackground(aBrush);
     156             :         }
     157           0 :         if(pTableItem)
     158             :         {
     159           0 :             SvxBrushItem aBrush(*(const SvxBrushItem*)pTableItem);
     160           0 :             aBrush.SetWhich(RES_BACKGROUND);
     161           0 :             rSh.SetTabBackground( aBrush );
     162             :         }
     163             :     }
     164           0 :     if(bBorder)
     165           0 :         rSh.SetTabBorders( rSet );
     166             : 
     167           0 :     if( SFX_ITEM_SET == rSet.GetItemState( FN_PARAM_TABLE_HEADLINE, false, &pItem) )
     168           0 :         rSh.SetRowsToRepeat( ((SfxUInt16Item*)pItem)->GetValue() );
     169             : 
     170           0 :     SwFrmFmt* pFrmFmt = rSh.GetTableFmt();
     171           0 :     if(pFrmFmt)
     172             :     {
     173             :         //RES_SHADOW
     174           0 :         pItem=0;
     175           0 :         rSet.GetItemState(rSet.GetPool()->GetWhich(RES_SHADOW), false, &pItem);
     176           0 :         if(pItem)
     177           0 :             pFrmFmt->SetFmtAttr( *pItem );
     178             : 
     179             :         //RES_BREAK
     180           0 :         pItem=0;
     181           0 :         rSet.GetItemState(rSet.GetPool()->GetWhich(RES_BREAK), false, &pItem);
     182           0 :         if(pItem)
     183           0 :             pFrmFmt->SetFmtAttr( *pItem );
     184             : 
     185             :         //RES_PAGEDESC
     186           0 :         pItem=0;
     187           0 :         rSet.GetItemState(rSet.GetPool()->GetWhich(RES_PAGEDESC), false, &pItem);
     188           0 :         if(pItem)
     189           0 :             pFrmFmt->SetFmtAttr( *pItem );
     190             : 
     191             :         //RES_LAYOUT_SPLIT
     192           0 :         pItem=0;
     193           0 :         rSet.GetItemState(rSet.GetPool()->GetWhich(RES_LAYOUT_SPLIT), false, &pItem);
     194           0 :         if(pItem)
     195           0 :             pFrmFmt->SetFmtAttr( *pItem );
     196             : 
     197             :         //RES_KEEP
     198           0 :         pItem=0;
     199           0 :         rSet.GetItemState(rSet.GetPool()->GetWhich(RES_KEEP), false, &pItem);
     200           0 :         if(pItem)
     201           0 :             pFrmFmt->SetFmtAttr( *pItem );
     202             : 
     203             :         //RES_FRAMEDIR
     204           0 :         pItem=0;
     205           0 :         rSet.GetItemState(rSet.GetPool()->GetWhich(RES_FRAMEDIR), false, &pItem);
     206           0 :         if(pItem)
     207           0 :             pFrmFmt->SetFmtAttr( *pItem );
     208             :     }
     209             : 
     210           0 :     if( SFX_ITEM_SET == rSet.GetItemState( FN_TABLE_BOX_TEXTORIENTATION, false, &pItem) )
     211             :     {
     212           0 :         SvxFrameDirectionItem aDirection( FRMDIR_ENVIRONMENT, RES_FRAMEDIR );
     213           0 :         aDirection.SetValue(static_cast< const SvxFrameDirectionItem* >(pItem)->GetValue());
     214           0 :         rSh.SetBoxDirection(aDirection);
     215             :     }
     216             : 
     217           0 :     if( SFX_ITEM_SET == rSet.GetItemState( FN_TABLE_SET_VERT_ALIGN, false, &pItem))
     218           0 :         rSh.SetBoxAlign(((SfxUInt16Item*)(pItem))->GetValue());
     219             : 
     220           0 :     if( SFX_ITEM_SET == rSet.GetItemState( RES_ROW_SPLIT, false, &pItem) )
     221           0 :         rSh.SetRowSplit(*static_cast<const SwFmtRowSplit*>(pItem));
     222           0 : }
     223             : }//end anonymous namespace
     224             : 
     225           0 : SwFormatClipboard::SwFormatClipboard()
     226             :         : m_nSelectionType(0)
     227             :         , m_pItemSet_TxtAttr(0)
     228             :         , m_pItemSet_ParAttr(0)
     229             :         , m_pTableItemSet(0)
     230           0 :         , m_bPersistentCopy(false)
     231             : {
     232           0 : }
     233           0 : SwFormatClipboard::~SwFormatClipboard()
     234             : {
     235           0 :     delete m_pItemSet_TxtAttr;
     236           0 :     delete m_pItemSet_ParAttr;
     237           0 :     delete m_pTableItemSet;
     238           0 : }
     239             : 
     240           0 : bool SwFormatClipboard::HasContent() const
     241             : {
     242           0 :     return m_pItemSet_TxtAttr!=0
     243           0 :         || m_pItemSet_ParAttr!=0
     244           0 :         || m_pTableItemSet != 0
     245           0 :         || !m_aCharStyle.isEmpty()
     246           0 :         || !m_aParaStyle.isEmpty()
     247             :         ;
     248             : }
     249           0 : bool SwFormatClipboard::HasContentForThisType( int nSelectionType ) const
     250             : {
     251           0 :     if( !HasContent() )
     252           0 :         return false;
     253             : 
     254           0 :     if( m_nSelectionType == nSelectionType )
     255           0 :         return true;
     256             : 
     257           0 :     if(   ( nSelectionType & (nsSelectionType::SEL_FRM | nsSelectionType::SEL_OLE | nsSelectionType::SEL_GRF) )
     258           0 :         &&
     259           0 :         ( m_nSelectionType & (nsSelectionType::SEL_FRM | nsSelectionType::SEL_OLE | nsSelectionType::SEL_GRF) )
     260             :         )
     261           0 :         return true;
     262             : 
     263           0 :     if( nSelectionType & nsSelectionType::SEL_TXT && m_nSelectionType & nsSelectionType::SEL_TXT )
     264           0 :         return true;
     265             : 
     266           0 :     return false;
     267             : }
     268             : 
     269           0 : bool SwFormatClipboard::CanCopyThisType( int nSelectionType ) const
     270             : {
     271           0 :     if( nSelectionType & (nsSelectionType::SEL_FRM | nsSelectionType::SEL_OLE | nsSelectionType::SEL_GRF
     272             :          | nsSelectionType::SEL_TXT | nsSelectionType::SEL_DRW | nsSelectionType::SEL_TBL | nsSelectionType::SEL_TBL_CELLS ) )
     273           0 :          return true;
     274           0 :     return false;
     275             : }
     276             : 
     277           0 : void SwFormatClipboard::Copy( SwWrtShell& rWrtShell, SfxItemPool& rPool, bool bPersistentCopy )
     278             : {
     279             :     // first clear the previously stored attributes
     280           0 :     this->Erase();
     281           0 :     m_bPersistentCopy = bPersistentCopy;
     282             : 
     283           0 :     int nSelectionType = rWrtShell.GetSelectionType();
     284           0 :     SfxItemSet* pItemSet_TxtAttr = lcl_CreateEmptyItemSet( nSelectionType, rPool, true );
     285           0 :     SfxItemSet* pItemSet_ParAttr = lcl_CreateEmptyItemSet( nSelectionType, rPool, false );
     286             : 
     287           0 :     rWrtShell.StartAction();
     288           0 :     rWrtShell.Push();
     289             : 
     290             :     // modify the "Point and Mark" of the cursor
     291             :     // in order to select only the last character of the
     292             :     // selection(s) and then to get the attributes of this single character
     293           0 :     if( nSelectionType == nsSelectionType::SEL_TXT )
     294             :     {
     295             :         // get the current PaM, the cursor
     296             :         // if there several selection it curently point
     297             :         // on the last (sort by there creation time) selection
     298           0 :         SwPaM* pCrsr = rWrtShell.GetCrsr();
     299             : 
     300           0 :         sal_Bool bHasSelection = pCrsr->HasMark();
     301           0 :         bool bForwardSelection = false;
     302             : 
     303           0 :         if(!bHasSelection && pCrsr->GetPrev() != pCrsr && pCrsr->GetPrev() != 0)
     304             :         {
     305             :             // if cursor has multiple selections
     306             : 
     307             :             // clear all the selections except the last
     308           0 :             rWrtShell.KillPams();
     309             : 
     310             :             // reset the cursor to the remaining selection
     311           0 :             pCrsr = rWrtShell.GetCrsr();
     312           0 :             bHasSelection = true;
     313             :         }
     314             : 
     315           0 :         bool dontMove = false;
     316           0 :         if (bHasSelection)
     317             :         {
     318           0 :             bForwardSelection = (*pCrsr->GetPoint()) > (*pCrsr->GetMark());
     319             : 
     320             :             // clear the selection leaving just the cursor
     321           0 :             pCrsr->DeleteMark();
     322           0 :             pCrsr->SetMark();
     323             :         }
     324             :         else
     325             :         {
     326           0 :             bool rightToLeft = rWrtShell.IsInRightToLeftText();
     327             :             // if there were no selection (only a cursor) and the cursor was at
     328             :             // the end of the paragraph then don't move
     329           0 :             if ( rWrtShell.IsEndPara() && !rightToLeft )
     330           0 :                 dontMove = true;
     331             : 
     332             :             // revert left and right
     333           0 :             if ( rightToLeft )
     334             :             {
     335           0 :                 if (pCrsr->GetPoint()->nContent == 0)
     336           0 :                     dontMove = true;
     337             :                 else
     338           0 :                     bForwardSelection = !bForwardSelection;
     339             :             }
     340             :         }
     341             : 
     342             :         // move the cursor in order to select one character
     343           0 :         if (!dontMove)
     344           0 :             pCrsr->Move( bForwardSelection ? fnMoveBackward : fnMoveForward );
     345             :     }
     346             : 
     347           0 :     if(pItemSet_TxtAttr)
     348             :     {
     349           0 :         if( nSelectionType & (nsSelectionType::SEL_FRM | nsSelectionType::SEL_OLE | nsSelectionType::SEL_GRF) )
     350           0 :             rWrtShell.GetFlyFrmAttr(*pItemSet_TxtAttr);
     351             :         else
     352             :         {
     353             :             // get the text attributes from named and automatic formatting
     354           0 :             rWrtShell.GetCurAttr(*pItemSet_TxtAttr);
     355             : 
     356           0 :             if( nSelectionType & nsSelectionType::SEL_TXT )
     357             :             {
     358             :                 // get the paragraph attributes (could be character properties)
     359             :                 // from named and automatic formatting
     360           0 :                 rWrtShell.GetCurParAttr(*pItemSet_ParAttr);
     361             :             }
     362             :         }
     363             :     }
     364           0 :     else if ( nSelectionType & nsSelectionType::SEL_DRW )
     365             :     {
     366           0 :         SdrView* pDrawView = rWrtShell.GetDrawView();
     367           0 :         if(pDrawView)
     368             :         {
     369           0 :             sal_Bool bOnlyHardAttr = sal_True;
     370           0 :             if( pDrawView->AreObjectsMarked() )
     371             :             {
     372           0 :                 pItemSet_TxtAttr = new SfxItemSet( pDrawView->GetAttrFromMarked(bOnlyHardAttr) );
     373             :                 //remove attributes defining the type/data of custom shapes
     374           0 :                 pItemSet_TxtAttr->ClearItem(SDRATTR_CUSTOMSHAPE_ENGINE);
     375           0 :                 pItemSet_TxtAttr->ClearItem(SDRATTR_CUSTOMSHAPE_DATA);
     376           0 :                 pItemSet_TxtAttr->ClearItem(SDRATTR_CUSTOMSHAPE_GEOMETRY);
     377           0 :                 pItemSet_TxtAttr->ClearItem(SDRATTR_CUSTOMSHAPE_REPLACEMENT_URL);
     378             :             }
     379             :         }
     380             :     }
     381             : 
     382           0 :     if( nSelectionType & nsSelectionType::SEL_TBL_CELLS )//only copy table attributes if really cells are selected (not only text in tables)
     383             :     {
     384             :         m_pTableItemSet = new SfxItemSet(rPool,
     385             :                         SID_ATTR_BORDER_INNER,  SID_ATTR_BORDER_SHADOW, //SID_ATTR_BORDER_OUTER is inbetween
     386             :                         RES_BACKGROUND,         RES_SHADOW, //RES_BOX is inbetween
     387             :                         SID_ATTR_BRUSH_ROW,     SID_ATTR_BRUSH_TABLE,
     388             :                         RES_BREAK,              RES_BREAK,
     389             :                         RES_PAGEDESC,           RES_PAGEDESC,
     390             :                         RES_LAYOUT_SPLIT,       RES_LAYOUT_SPLIT,
     391             :                         RES_ROW_SPLIT,          RES_ROW_SPLIT,
     392             :                         RES_KEEP,               RES_KEEP,
     393             :                         RES_FRAMEDIR,           RES_FRAMEDIR,
     394             :                         FN_PARAM_TABLE_HEADLINE, FN_PARAM_TABLE_HEADLINE,
     395             :                         FN_TABLE_BOX_TEXTORIENTATION, FN_TABLE_BOX_TEXTORIENTATION,
     396             :                         FN_TABLE_SET_VERT_ALIGN, FN_TABLE_SET_VERT_ALIGN,
     397           0 :                         0);
     398           0 :         lcl_getTableAttributes( *m_pTableItemSet, rWrtShell );
     399             :     }
     400             : 
     401           0 :     m_nSelectionType = nSelectionType;
     402           0 :     m_pItemSet_TxtAttr = pItemSet_TxtAttr;
     403           0 :     m_pItemSet_ParAttr = pItemSet_ParAttr;
     404             : 
     405           0 :     if( nSelectionType & nsSelectionType::SEL_TXT )
     406             :     {
     407             :         // if text is selected save the named character format
     408           0 :         SwFmt* pFmt = rWrtShell.GetCurCharFmt();
     409           0 :         if( pFmt )
     410           0 :             m_aCharStyle = pFmt->GetName();
     411             : 
     412             :         // and the named paragraph format
     413           0 :         pFmt = rWrtShell.GetCurTxtFmtColl();
     414           0 :         if( pFmt )
     415           0 :             m_aParaStyle = pFmt->GetName();
     416             :     }
     417             : 
     418           0 :     rWrtShell.Pop(sal_False);
     419           0 :     rWrtShell.EndAction();
     420           0 : }
     421             : 
     422             : typedef boost::shared_ptr< SfxPoolItem > SfxPoolItemSharedPtr;
     423             : typedef std::vector< SfxPoolItemSharedPtr > ItemVector;
     424             : // collect all PoolItems from the applied styles
     425           0 : static void lcl_AppendSetItems( ItemVector& rItemVector, const SfxItemSet& rStyleAttrSet )
     426             : {
     427           0 :     const sal_uInt16*  pRanges = rStyleAttrSet.GetRanges();
     428           0 :     while( *pRanges )
     429             :     {
     430           0 :         for ( sal_uInt16 nWhich = *pRanges; nWhich <= *(pRanges+1); ++nWhich )
     431             :         {
     432             :             const SfxPoolItem* pItem;
     433           0 :             if( SFX_ITEM_SET == rStyleAttrSet.GetItemState( nWhich, false, &pItem ) )
     434             :             {
     435           0 :                 rItemVector.push_back( SfxPoolItemSharedPtr( pItem->Clone() ) );
     436             :             }
     437             :         }
     438           0 :         pRanges += 2;
     439             :     }
     440           0 : }
     441             : // remove all items that are inherited from the styles
     442           0 : static void lcl_RemoveEqualItems( SfxItemSet& rTemplateItemSet, const ItemVector& rItemVector )
     443             : {
     444           0 :     ItemVector::const_iterator aEnd = rItemVector.end();
     445           0 :     ItemVector::const_iterator aIter = rItemVector.begin();
     446           0 :     while( aIter != aEnd )
     447             :     {
     448             :         const SfxPoolItem* pItem;
     449           0 :         if( SFX_ITEM_SET == rTemplateItemSet.GetItemState( (*aIter)->Which(), true, &pItem ) &&
     450           0 :             *pItem == *(*aIter) )
     451             :         {
     452           0 :             rTemplateItemSet.ClearItem( (*aIter)->Which() );
     453             :         }
     454           0 :         ++aIter;
     455             :     }
     456           0 : }
     457             : 
     458           0 : void SwFormatClipboard::Paste( SwWrtShell& rWrtShell, SfxStyleSheetBasePool* pPool
     459             :                               , bool bNoCharacterFormats, bool bNoParagraphFormats )
     460             : {
     461           0 :     int nSelectionType = rWrtShell.GetSelectionType();
     462           0 :     if( !this->HasContentForThisType(nSelectionType) )
     463             :     {
     464           0 :         if(!m_bPersistentCopy)
     465           0 :             this->Erase();
     466           0 :         return;
     467             :     }
     468             : 
     469           0 :     rWrtShell.StartAction();
     470           0 :     rWrtShell.StartUndo(UNDO_INSATTR);
     471             : 
     472           0 :     ItemVector aItemVector;
     473             : 
     474           0 :     if( nSelectionType & nsSelectionType::SEL_TXT )
     475             :     {
     476             :         // apply the named text and paragraph formatting
     477           0 :         if( pPool )
     478             :         {
     479             :             // if there is a named text format recorded and the user wants to apply it
     480           0 :             if(!m_aCharStyle.isEmpty() && !bNoCharacterFormats )
     481             :             {
     482             :                 // look for the named text format in the pool
     483           0 :                 SwDocStyleSheet* pStyle = static_cast<SwDocStyleSheet*>(pPool->Find(m_aCharStyle, SFX_STYLE_FAMILY_CHAR));
     484             : 
     485             :                 // if the style is found
     486           0 :                 if( pStyle )
     487             :                 {
     488           0 :                     SwFmtCharFmt aFmt(pStyle->GetCharFmt());
     489             :                     // store the attributes from this style in aItemVector in order
     490             :                     // not to apply them as automatic formatting attributes later in the code
     491           0 :                     lcl_AppendSetItems( aItemVector, aFmt.GetCharFmt()->GetAttrSet());
     492             : 
     493             :                     // apply the named format
     494           0 :                     rWrtShell.SetAttrItem( aFmt );
     495             :                 }
     496             :             }
     497             : 
     498             :             // if there is a named paragraph format recorded and the user wants to apply it
     499           0 :             if(!m_aParaStyle.isEmpty() && !bNoParagraphFormats )
     500             :             {
     501             :                 // look for the named pragraph format in the pool
     502           0 :                 SwDocStyleSheet* pStyle = static_cast<SwDocStyleSheet*>(pPool->Find(m_aParaStyle, SFX_STYLE_FAMILY_PARA));
     503           0 :                 if( pStyle )
     504             :                 {
     505             :                     // store the attributes from this style in aItemVector in order
     506             :                     // not to apply them as automatic formatting attributes later in the code
     507           0 :                     lcl_AppendSetItems( aItemVector, pStyle->GetCollection()->GetAttrSet());
     508             : 
     509             :                     // apply the named format
     510           0 :                     rWrtShell.SetTxtFmtColl( pStyle->GetCollection() );
     511             :                 }
     512             :             }
     513             :         }
     514             : 
     515             :         // apply the paragraph automatic attributes
     516           0 :         if ( m_pItemSet_ParAttr && m_pItemSet_ParAttr->Count() != 0 && !bNoParagraphFormats )
     517             :         {
     518             :             // temporary SfxItemSet
     519             :             SfxItemSet* pTemplateItemSet = lcl_CreateEmptyItemSet(
     520           0 :                     nSelectionType, *m_pItemSet_ParAttr->GetPool(), false);
     521             :             // no need to verify the existance of pTemplateItemSet as we
     522             :             // know that here the selection type is SEL_TXT
     523             : 
     524           0 :             pTemplateItemSet->Put( *m_pItemSet_ParAttr );
     525             : 
     526             :             // remove attribute that were applied by named text and paragraph formatting
     527           0 :             lcl_RemoveEqualItems( *pTemplateItemSet, aItemVector );
     528             : 
     529             :             // apply the paragraph automatic attributes to all the nodes in the selection
     530           0 :             rWrtShell.SetAttrSet(*pTemplateItemSet);
     531             : 
     532             :             // store the attributes in aItemVector in order not to apply them as
     533             :             // text automatic formatting attributes later in the code
     534           0 :             lcl_AppendSetItems( aItemVector, *pTemplateItemSet);
     535             : 
     536           0 :             delete pTemplateItemSet;
     537             :         }
     538             :     }
     539             : 
     540           0 :     if(m_pItemSet_TxtAttr)
     541             :     {
     542           0 :         if( nSelectionType & nsSelectionType::SEL_DRW )
     543             :         {
     544           0 :             SdrView* pDrawView = rWrtShell.GetDrawView();
     545           0 :             if(pDrawView)
     546             :             {
     547           0 :                 sal_Bool bReplaceAll = sal_True;
     548           0 :                 pDrawView->SetAttrToMarked(*m_pItemSet_TxtAttr, bReplaceAll);
     549             :             }
     550             :         }
     551             :         else
     552             :         {
     553             :             // temporary SfxItemSet
     554             :             SfxItemSet* pTemplateItemSet = lcl_CreateEmptyItemSet(
     555           0 :                     nSelectionType, *m_pItemSet_TxtAttr->GetPool(), true );
     556             : 
     557           0 :             if(pTemplateItemSet)
     558             :             {
     559             :                 // copy the stored automatic text attributes in a temporary SfxItemSet
     560           0 :                 pTemplateItemSet->Put( *m_pItemSet_TxtAttr );
     561             : 
     562             :                 // only attributes that were not apply by named style attributes and automatic
     563             :                 // paragraph attributes should be applied
     564           0 :                 lcl_RemoveEqualItems( *pTemplateItemSet, aItemVector );
     565             : 
     566             :                 // apply the character automatic attributes
     567           0 :                 if( nSelectionType & (nsSelectionType::SEL_FRM | nsSelectionType::SEL_OLE | nsSelectionType::SEL_GRF) )
     568           0 :                     rWrtShell.SetFlyFrmAttr(*pTemplateItemSet);
     569           0 :                 else if ( !bNoCharacterFormats )
     570           0 :                     rWrtShell.SetAttrSet(*pTemplateItemSet);
     571             : 
     572           0 :                 delete pTemplateItemSet;
     573             :             }
     574             :         }
     575             :     }
     576             : 
     577           0 :     if( m_pTableItemSet && nSelectionType & (nsSelectionType::SEL_TBL | nsSelectionType::SEL_TBL_CELLS) )
     578           0 :         lcl_setTableAttributes( *m_pTableItemSet, rWrtShell );
     579             : 
     580           0 :     rWrtShell.EndUndo(UNDO_INSATTR);
     581           0 :     rWrtShell.EndAction();
     582             : 
     583           0 :     if(!m_bPersistentCopy)
     584           0 :         this->Erase();
     585             : }
     586             : 
     587           0 : void SwFormatClipboard::Erase()
     588             : {
     589           0 :     m_nSelectionType = 0;
     590             : 
     591           0 :     delete m_pItemSet_TxtAttr;
     592           0 :     m_pItemSet_TxtAttr = 0;
     593             : 
     594           0 :     delete m_pItemSet_ParAttr;
     595           0 :     m_pItemSet_ParAttr = 0;
     596             : 
     597           0 :     delete m_pTableItemSet;
     598           0 :     m_pTableItemSet = 0;
     599             : 
     600           0 :     if( !m_aCharStyle.isEmpty() )
     601           0 :         m_aCharStyle = "";
     602           0 :     if( !m_aParaStyle.isEmpty() )
     603           0 :         m_aParaStyle = "";
     604             : 
     605           0 :     m_bPersistentCopy = false;
     606           0 : }
     607             : 
     608             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10