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

Generated by: LCOV version 1.11