1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_sw.hxx"
30 
31 #include "formatclipboard.hxx"
32 
33 
34 #include <hintids.hxx>
35 #ifndef _SVX_SVXIDS_HRC
36 #include <svx/svxids.hrc>
37 #endif
38 #ifndef _CMDID_H
39 #include <cmdid.h>
40 #endif
41 #include <format.hxx>
42 #include <charfmt.hxx>
43 #include <fmtcol.hxx>
44 #include <frmfmt.hxx>
45 #include <docstyle.hxx>
46 #include <fchrfmt.hxx>
47 #include <pam.hxx>
48 // header for class SdrView
49 #include <svx/svdview.hxx>
50 //SvxBrushItem
51 #include <editeng/brshitem.hxx>
52 #include <editeng/shaditem.hxx>
53 #include <frmatr.hxx>
54 // header for class SvxBoxInfoItem
55 #include <editeng/boxitem.hxx>
56 // header for class SvxFmtBreakItem
57 #include <editeng/brkitem.hxx>
58 // header for class SwFmtLayoutSplit
59 #include <fmtlsplt.hxx>
60 // header for class SvxFmtKeepItem
61 #include <editeng/keepitem.hxx>
62 // header for class SvxFrameDirectionItem
63 #include <editeng/frmdiritem.hxx>
64 #include <paratr.hxx>
65 #include <fmtpdsc.hxx>
66 #include <fmtrowsplt.hxx>
67 #include <swundo.hxx>			// fuer die UndoIds
68 #include <boost/shared_ptr.hpp>
69 
70 //#define FORMAT_PAINTBRUSH_ALSO_COPY_NUMBERFORMAT_FOR_TABLES 1
71 
72 #ifdef FORMAT_PAINTBRUSH_ALSO_COPY_NUMBERFORMAT_FOR_TABLES
73 #include <cellatr.hxx>
74 #endif
75 
76 /*--------------------------------------------------------------------
77  --------------------------------------------------------------------*/
78 
79 namespace
80 {
81 #define FORMAT_PAINTBRUSH_FRAME_IDS \
82 RES_FRMATR_BEGIN, RES_FILL_ORDER, \
83 /* no RES_FRM_SIZE */ \
84 RES_PAPER_BIN, RES_SURROUND, \
85 /* no RES_VERT_ORIENT */ \
86 /* no RES_HORI_ORIENT */ \
87 /* no RES_ANCHOR */ \
88 RES_BACKGROUND, RES_SHADOW, \
89 /* no RES_FRMMACRO */ \
90 RES_COL, RES_KEEP, \
91 /* no RES_URL */ \
92 RES_EDIT_IN_READONLY, RES_LAYOUT_SPLIT, \
93 /* no RES_CHAIN */ \
94 RES_TEXTGRID, RES_FRMATR_END-1,
95 
96 #define FORMAT_PAINTBRUSH_PARAGRAPH_IDS \
97 RES_PARATR_BEGIN, RES_PARATR_END -1, \
98 RES_PARATR_LIST_BEGIN, RES_PARATR_LIST_END -1, \
99 FORMAT_PAINTBRUSH_FRAME_IDS \
100 FN_NUMBER_NEWSTART, FN_NUMBER_NEWSTART, \
101 FN_NUMBER_NEWSTART_AT, FN_NUMBER_NEWSTART_AT,
102 
103 SfxItemSet* lcl_CreateEmptyItemSet( int nSelectionType, SfxItemPool& rPool
104             , bool bNoCharacterFormats = false, bool bNoParagraphFormats = false )
105 {
106     SfxItemSet* pItemSet = 0;
107     if( nSelectionType & (nsSelectionType::SEL_FRM | nsSelectionType::SEL_OLE | nsSelectionType::SEL_GRF) )
108     {
109         pItemSet = new SfxItemSet(rPool,
110                         FORMAT_PAINTBRUSH_FRAME_IDS
111                         0);
112     }
113     else if( nSelectionType & nsSelectionType::SEL_DRW )
114     {
115         //is handled different
116     }
117     else if( nSelectionType == nsSelectionType::SEL_TBL )
118     {
119         pItemSet = new SfxItemSet(rPool,
120                         SID_ATTR_BORDER_INNER,	SID_ATTR_BORDER_SHADOW, //SID_ATTR_BORDER_OUTER is inbetween
121 	                    RES_BACKGROUND,         RES_SHADOW, //RES_BOX is inbetween
122 	                    SID_ATTR_BRUSH_ROW, 	SID_ATTR_BRUSH_TABLE,
123                         RES_BREAK,              RES_BREAK,
124                         RES_PAGEDESC,           RES_PAGEDESC,
125                         RES_LAYOUT_SPLIT,       RES_LAYOUT_SPLIT,
126                         RES_ROW_SPLIT,          RES_ROW_SPLIT,
127                         RES_KEEP,               RES_KEEP,
128                         RES_FRAMEDIR,           RES_FRAMEDIR,
129                         FN_PARAM_TABLE_HEADLINE, FN_PARAM_TABLE_HEADLINE,
130                         FN_TABLE_BOX_TEXTDIRECTION, FN_TABLE_BOX_TEXTDIRECTION,
131                         FN_TABLE_SET_VERT_ALIGN, FN_TABLE_SET_VERT_ALIGN,
132 #ifdef FORMAT_PAINTBRUSH_ALSO_COPY_NUMBERFORMAT_FOR_TABLES
133                         RES_BOXATR_FORMAT,      RES_BOXATR_FORMAT,
134 #endif
135                         0);
136     }
137     else if( nSelectionType & nsSelectionType::SEL_TXT )
138     {
139         if( bNoCharacterFormats )
140             pItemSet = new SfxItemSet(rPool,
141                     FORMAT_PAINTBRUSH_PARAGRAPH_IDS
142                     0);
143         else if( bNoParagraphFormats )
144             pItemSet = new SfxItemSet(rPool,
145                     RES_CHRATR_BEGIN, RES_CHRATR_END - 1,
146                     0);
147         else
148             pItemSet = new SfxItemSet(rPool,
149                     RES_CHRATR_BEGIN, RES_CHRATR_END - 1,
150                     FORMAT_PAINTBRUSH_PARAGRAPH_IDS
151                     0);
152     }
153     return pItemSet;
154 }
155 
156 void lcl_getTableAttributes( SfxItemSet& rSet, SwWrtShell &rSh )
157 {
158     SvxBrushItem aBrush( RES_BACKGROUND );
159  	rSh.GetBoxBackground(aBrush);
160 	rSet.Put( aBrush );
161 	if(rSh.GetRowBackground(aBrush))
162 		rSet.Put( aBrush, SID_ATTR_BRUSH_ROW );
163 	else
164 		rSet.InvalidateItem(SID_ATTR_BRUSH_ROW);
165 	rSh.GetTabBackground(aBrush);
166 	rSet.Put( aBrush, SID_ATTR_BRUSH_TABLE );
167 
168     SvxBoxInfoItem aBoxInfo( SID_ATTR_BORDER_INNER );
169     rSet.Put(aBoxInfo);
170     rSh.GetTabBorders( rSet );
171 
172     SvxFrameDirectionItem aBoxDirection( FRMDIR_ENVIRONMENT, RES_FRAMEDIR );
173     if(rSh.GetBoxDirection( aBoxDirection ))
174         rSet.Put(aBoxDirection, FN_TABLE_BOX_TEXTDIRECTION);
175 
176     rSet.Put(SfxUInt16Item(FN_TABLE_SET_VERT_ALIGN, rSh.GetBoxAlign()));
177 
178     rSet.Put( SfxUInt16Item( FN_PARAM_TABLE_HEADLINE, rSh.GetRowsToRepeat() ) );
179 
180     SwFrmFmt *pFrmFmt = rSh.GetTableFmt();
181     if(pFrmFmt)
182     {
183         rSet.Put( pFrmFmt->GetShadow() );
184         rSet.Put( pFrmFmt->GetBreak() );
185         rSet.Put( pFrmFmt->GetPageDesc() );
186         rSet.Put( pFrmFmt->GetLayoutSplit() );
187         rSet.Put( pFrmFmt->GetKeep() );
188         rSet.Put( pFrmFmt->GetFrmDir() );
189     }
190 
191     SwFmtRowSplit* pSplit = 0;
192     rSh.GetRowSplit(pSplit);
193     if(pSplit)
194         rSet.Put(*pSplit);
195 
196     //-- numberformat in cells
197 #ifdef FORMAT_PAINTBRUSH_ALSO_COPY_NUMBERFORMAT_FOR_TABLES
198 	rSh.GetTblBoxFormulaAttrs( rSet ); //RES_BOXATR_FORMAT
199 #endif
200 }
201 
202 void lcl_setTableAttributes( const SfxItemSet& rSet, SwWrtShell &rSh )
203 {
204     const SfxPoolItem* pItem = 0;
205     sal_Bool bBorder = ( SFX_ITEM_SET == rSet.GetItemState( RES_BOX ) ||
206 			SFX_ITEM_SET == rSet.GetItemState( SID_ATTR_BORDER_INNER ) );
207 	pItem = 0;
208 	sal_Bool bBackground = SFX_ITEM_SET == rSet.GetItemState( RES_BACKGROUND, sal_False, &pItem );
209 	const SfxPoolItem* pRowItem = 0, *pTableItem = 0;
210 	bBackground |= SFX_ITEM_SET == rSet.GetItemState( SID_ATTR_BRUSH_ROW, sal_False, &pRowItem );
211 	bBackground |= SFX_ITEM_SET == rSet.GetItemState( SID_ATTR_BRUSH_TABLE, sal_False, &pTableItem );
212 
213     if(bBackground)
214 	{
215 		if(pItem)
216 			rSh.SetBoxBackground( *(const SvxBrushItem*)pItem );
217 		if(pRowItem)
218 		{
219 			SvxBrushItem aBrush(*(const SvxBrushItem*)pRowItem);
220 			aBrush.SetWhich(RES_BACKGROUND);
221 			rSh.SetRowBackground(aBrush);
222 		}
223 		if(pTableItem)
224 		{
225 			SvxBrushItem aBrush(*(const SvxBrushItem*)pTableItem);
226 			aBrush.SetWhich(RES_BACKGROUND);
227 			rSh.SetTabBackground( aBrush );
228 		}
229 	}
230     if(bBorder)
231         rSh.SetTabBorders( rSet );
232 
233     if( SFX_ITEM_SET == rSet.GetItemState( FN_PARAM_TABLE_HEADLINE, sal_False, &pItem) )
234         rSh.SetRowsToRepeat( ((SfxUInt16Item*)pItem)->GetValue() );
235 
236     SwFrmFmt* pFrmFmt = rSh.GetTableFmt();
237     if(pFrmFmt)
238     {
239         //RES_SHADOW
240         pItem=0;
241         rSet.GetItemState(rSet.GetPool()->GetWhich(RES_SHADOW), sal_False, &pItem);
242 	    if(pItem)
243             pFrmFmt->SetFmtAttr( *pItem );
244 
245         //RES_BREAK
246         pItem=0;
247         rSet.GetItemState(rSet.GetPool()->GetWhich(RES_BREAK), sal_False, &pItem);
248 	    if(pItem)
249             pFrmFmt->SetFmtAttr( *pItem );
250 
251         //RES_PAGEDESC
252         pItem=0;
253         rSet.GetItemState(rSet.GetPool()->GetWhich(RES_PAGEDESC), sal_False, &pItem);
254 	    if(pItem)
255             pFrmFmt->SetFmtAttr( *pItem );
256 
257         //RES_LAYOUT_SPLIT
258         pItem=0;
259         rSet.GetItemState(rSet.GetPool()->GetWhich(RES_LAYOUT_SPLIT), sal_False, &pItem);
260 	    if(pItem)
261             pFrmFmt->SetFmtAttr( *pItem );
262 
263         //RES_KEEP
264         pItem=0;
265         rSet.GetItemState(rSet.GetPool()->GetWhich(RES_KEEP), sal_False, &pItem);
266 	    if(pItem)
267             pFrmFmt->SetFmtAttr( *pItem );
268 
269         //RES_FRAMEDIR
270         pItem=0;
271         rSet.GetItemState(rSet.GetPool()->GetWhich(RES_FRAMEDIR), sal_False, &pItem);
272 	    if(pItem)
273             pFrmFmt->SetFmtAttr( *pItem );
274     }
275 
276     if( SFX_ITEM_SET == rSet.GetItemState( FN_TABLE_BOX_TEXTDIRECTION, sal_False, &pItem) )
277     {
278         SvxFrameDirectionItem aDirection( FRMDIR_ENVIRONMENT, RES_FRAMEDIR );
279         aDirection.SetValue(static_cast< const SvxFrameDirectionItem* >(pItem)->GetValue());
280         rSh.SetBoxDirection(aDirection);
281     }
282 
283     if( SFX_ITEM_SET == rSet.GetItemState( FN_TABLE_SET_VERT_ALIGN, sal_False, &pItem))
284 		rSh.SetBoxAlign(((SfxUInt16Item*)(pItem))->GetValue());
285 
286     if( SFX_ITEM_SET == rSet.GetItemState( RES_ROW_SPLIT, sal_False, &pItem) )
287         rSh.SetRowSplit(*static_cast<const SwFmtRowSplit*>(pItem));
288 
289     //-- numberformat in cells
290 #ifdef FORMAT_PAINTBRUSH_ALSO_COPY_NUMBERFORMAT_FOR_TABLES
291     if( SFX_ITEM_SET == rSet.GetItemState( RES_BOXATR_FORMAT, sal_False, &pItem ))
292     {
293 	    SfxItemSet aBoxSet( *rSet.GetPool(), RES_BOXATR_FORMAT, RES_BOXATR_FORMAT );
294 	    aBoxSet.Put( SwTblBoxNumFormat( ((SfxUInt32Item*)pItem)->GetValue() ));
295 	    rSh.SetTblBoxFormulaAttrs( aBoxSet );
296 
297     }
298 #endif
299 }
300 }//end anonymous namespace
301 
302 SwFormatClipboard::SwFormatClipboard()
303         : m_nSelectionType(0)
304         , m_pItemSet(0)
305         , m_pTableItemSet(0)
306         , m_bPersistentCopy(false)
307 {
308 }
309 SwFormatClipboard::~SwFormatClipboard()
310 {
311     if(m_pItemSet)
312         delete m_pItemSet;
313     if(m_pTableItemSet)
314         delete m_pTableItemSet;
315 }
316 
317 bool SwFormatClipboard::HasContent() const
318 {
319     return m_pItemSet!=0
320         || m_pTableItemSet != 0
321         || m_aCharStyle.Len()
322         || m_aParaStyle.Len()
323         ;
324 }
325 bool SwFormatClipboard::HasContentForThisType( int nSelectionType ) const
326 {
327     if( !HasContent() )
328         return false;
329 
330     if( m_nSelectionType == nSelectionType )
331         return true;
332 
333     if(   ( nSelectionType & (nsSelectionType::SEL_FRM | nsSelectionType::SEL_OLE | nsSelectionType::SEL_GRF) )
334         &&
335         ( m_nSelectionType & (nsSelectionType::SEL_FRM | nsSelectionType::SEL_OLE | nsSelectionType::SEL_GRF) )
336         )
337         return true;
338 
339     if( nSelectionType & nsSelectionType::SEL_TXT && m_nSelectionType & nsSelectionType::SEL_TXT )
340         return true;
341 
342     return false;
343 }
344 
345 bool SwFormatClipboard::CanCopyThisType( int nSelectionType ) const
346 {
347     if( nSelectionType & (nsSelectionType::SEL_FRM | nsSelectionType::SEL_OLE | nsSelectionType::SEL_GRF
348          | nsSelectionType::SEL_TXT | nsSelectionType::SEL_DRW | nsSelectionType::SEL_TBL | nsSelectionType::SEL_TBL_CELLS ) )
349          return true;
350     return false;
351 }
352 
353 void SwFormatClipboard::Copy( SwWrtShell& rWrtShell, SfxItemPool& rPool, bool bPersistentCopy )
354 {
355     this->Erase();
356     m_bPersistentCopy = bPersistentCopy;
357 
358     int nSelectionType = rWrtShell.GetSelectionType();
359     SfxItemSet* pItemSet = lcl_CreateEmptyItemSet( nSelectionType, rPool );
360 
361     rWrtShell.StartAction();
362     rWrtShell.Push();
363     if( nSelectionType == nsSelectionType::SEL_TXT )
364     {
365         SwPaM* pCrsr = rWrtShell.GetCrsr();
366         //select one character only to get the attributes of this single character only
367         sal_Bool bHasSelection = pCrsr->HasMark();
368         sal_Bool bForwardSelection = sal_False;
369 
370         if(!bHasSelection) //check for and handle multiselections
371         {
372             if( pCrsr->GetPrev() != pCrsr && pCrsr->GetPrev() != 0)
373             {
374                 pCrsr = (SwPaM*)pCrsr->GetPrev();
375                 bForwardSelection = (*pCrsr->GetPoint()) > (*pCrsr->GetMark());
376                 bHasSelection = true;
377                 pCrsr->DeleteMark();
378                 pCrsr->SetMark();
379                 rWrtShell.KillPams();
380                 pCrsr = rWrtShell.GetCrsr();
381             }
382         }
383         else
384             bForwardSelection = (*pCrsr->GetPoint()) > (*pCrsr->GetMark());
385 	    pCrsr->DeleteMark();
386         pCrsr->SetMark();
387 
388         if( !bHasSelection && rWrtShell.IsInRightToLeftText() )
389             bForwardSelection = !bForwardSelection;
390 
391         if( !( !bHasSelection && rWrtShell.IsEndPara() ) )
392             pCrsr->Move( bForwardSelection ? fnMoveBackward : fnMoveForward );
393     }
394 
395     if(pItemSet)
396     {
397         if( nSelectionType & (nsSelectionType::SEL_FRM | nsSelectionType::SEL_OLE | nsSelectionType::SEL_GRF) )
398             rWrtShell.GetFlyFrmAttr(*pItemSet);
399         else
400         {
401             rWrtShell.GetCurAttr(*pItemSet);
402 
403             // additional numbering properties for paragraph styles
404             if( nSelectionType & nsSelectionType::SEL_TXT && rWrtShell.GetCurNumRule() )
405             {
406                 SfxBoolItem aStart(FN_NUMBER_NEWSTART, rWrtShell.IsNumRuleStart());
407                 pItemSet->Put(aStart);
408                 SfxUInt16Item aStartAt(FN_NUMBER_NEWSTART_AT, rWrtShell.GetNodeNumStart());
409                 pItemSet->Put(aStartAt);
410             }
411         }
412     }
413     else if ( nSelectionType & nsSelectionType::SEL_DRW )
414     {
415         SdrView* pDrawView = rWrtShell.GetDrawView();
416         if(pDrawView)
417         {
418             sal_Bool bOnlyHardAttr = sal_True;
419             if( pDrawView->AreObjectsMarked() )
420             {
421                 pItemSet = new SfxItemSet( pDrawView->GetAttrFromMarked(bOnlyHardAttr) );
422                 //remove attributes defining the type/data of custom shapes
423                 pItemSet->ClearItem(SDRATTR_CUSTOMSHAPE_ENGINE);
424                 pItemSet->ClearItem(SDRATTR_CUSTOMSHAPE_DATA);
425                 pItemSet->ClearItem(SDRATTR_CUSTOMSHAPE_GEOMETRY);
426                 pItemSet->ClearItem(SDRATTR_CUSTOMSHAPE_REPLACEMENT_URL);
427             }
428         }
429     }
430     if( nSelectionType & nsSelectionType::SEL_TBL_CELLS )//only copy table attributes if really cells are selected (not only text in tables)
431     {
432         m_pTableItemSet = lcl_CreateEmptyItemSet( nsSelectionType::SEL_TBL, rPool );
433         lcl_getTableAttributes( *m_pTableItemSet, rWrtShell );
434     }
435 
436     m_nSelectionType = nSelectionType;
437     m_pItemSet = pItemSet;
438 
439     if( nSelectionType & nsSelectionType::SEL_TXT )
440     {
441         SwFmt* pFmt = rWrtShell.GetCurCharFmt();
442         if( pFmt )
443             m_aCharStyle = pFmt->GetName();
444 
445         pFmt = rWrtShell.GetCurTxtFmtColl();
446         if( pFmt )
447             m_aParaStyle = pFmt->GetName();
448     }
449     rWrtShell.Pop(sal_False);
450     rWrtShell.EndAction();
451 }
452 typedef boost::shared_ptr< SfxPoolItem > SfxPoolItemSharedPtr;
453 typedef std::vector< SfxPoolItemSharedPtr > ItemVector;
454 // #144857# collect all PoolItems from the applied styles
455 void lcl_AppendSetItems( ItemVector& rItemVector, const SfxItemSet& rStyleAttrSet )
456 {
457     const sal_uInt16*  pRanges = rStyleAttrSet.GetRanges();
458     while( *pRanges )
459     {
460         for ( sal_uInt16 nWhich = *pRanges; nWhich <= *(pRanges+1); ++nWhich )
461         {
462             const SfxPoolItem* pItem;
463             if( SFX_ITEM_SET == rStyleAttrSet.GetItemState( nWhich, sal_False, &pItem ) )
464             {
465                 rItemVector.push_back( SfxPoolItemSharedPtr( pItem->Clone() ) );
466             }
467         }
468         pRanges += 2;
469     }
470 }
471 // #144857# remove all items that are inherited from the styles
472 void lcl_RemoveEqualItems( SfxItemSet& rTemplateItemSet, ItemVector& rItemVector )
473 {
474     ItemVector::iterator aEnd = rItemVector.end();
475     ItemVector::iterator aIter = rItemVector.begin();
476     while( aIter != aEnd )
477     {
478         const SfxPoolItem* pItem;
479         if( SFX_ITEM_SET == rTemplateItemSet.GetItemState( (*aIter)->Which(), sal_True, &pItem ) &&
480             *pItem == *(*aIter) )
481         {
482             rTemplateItemSet.ClearItem( (*aIter)->Which() );
483         }
484         ++aIter;
485     }
486 }
487 
488 void SwFormatClipboard::Paste( SwWrtShell& rWrtShell, SfxStyleSheetBasePool* pPool
489                               , bool bNoCharacterFormats, bool bNoParagraphFormats )
490 {
491     int nSelectionType = rWrtShell.GetSelectionType();
492     if( !this->HasContentForThisType(nSelectionType) )
493     {
494         if(!m_bPersistentCopy)
495             this->Erase();
496         return;
497     }
498 
499     rWrtShell.StartAction();
500     rWrtShell.StartUndo(UNDO_INSATTR);
501 
502     ItemVector aItemVector;
503     if(pPool) //to find the styles we need the pool
504     {
505         if( nSelectionType & nsSelectionType::SEL_TXT )
506         {
507             if(m_aCharStyle.Len() && !bNoCharacterFormats )
508             {
509                 SwDocStyleSheet* pStyle = (SwDocStyleSheet*)pPool->Find(m_aCharStyle, SFX_STYLE_FAMILY_CHAR);
510                 if( pStyle )
511                 {
512                     SwFmtCharFmt aFmt(pStyle->GetCharFmt());
513                     // #144857# collect items from character style
514                     lcl_AppendSetItems( aItemVector, aFmt.GetCharFmt()->GetAttrSet());
515                     sal_uInt16 nFlags=0; //(nMode & KEY_SHIFT) ? SETATTR_DONTREPLACE : SETATTR_DEFAULT;
516 		            rWrtShell.SetAttr( aFmt, nFlags );
517                 }
518             }
519             if(m_aParaStyle.Len() && !bNoParagraphFormats )
520             {
521                 SwDocStyleSheet* pStyle = (SwDocStyleSheet*)pPool->Find(m_aParaStyle, SFX_STYLE_FAMILY_PARA);
522                 if( pStyle )
523                 {
524                     // #144857# collect items from paragraph style
525                     lcl_AppendSetItems( aItemVector, pStyle->GetCollection()->GetAttrSet());
526 		            rWrtShell.SetTxtFmtColl( pStyle->GetCollection() );
527                 }
528             }
529         }
530     }
531     if(m_pItemSet)
532     {
533         if( nSelectionType & nsSelectionType::SEL_DRW )
534         {
535             SdrView* pDrawView = rWrtShell.GetDrawView();
536             if(pDrawView)
537             {
538                 sal_Bool bReplaceAll = sal_True;
539 	            pDrawView->SetAttrToMarked(*m_pItemSet, bReplaceAll);
540             }
541         }
542         else
543         {
544             SfxItemSet* pTemplateItemSet = lcl_CreateEmptyItemSet(
545                               nSelectionType, *m_pItemSet->GetPool()
546                               , bNoCharacterFormats, bNoParagraphFormats );
547             if(pTemplateItemSet)
548             {
549                 pTemplateItemSet->Put( *m_pItemSet );
550                 // #144857# only _set_ attributes that differ from style attributes should be applied - the style is applied anyway
551                 lcl_RemoveEqualItems( *pTemplateItemSet, aItemVector );
552 
553                 if( nSelectionType & (nsSelectionType::SEL_FRM | nsSelectionType::SEL_OLE | nsSelectionType::SEL_GRF) )
554                     rWrtShell.SetFlyFrmAttr(*pTemplateItemSet);
555                 else
556                 {
557                     rWrtShell.SetAttr(*pTemplateItemSet);
558 
559                     // additional numbering properties for paragraph styles
560                     if( nSelectionType & nsSelectionType::SEL_TXT && rWrtShell.GetCurNumRule() )
561                     {
562                         if( SFX_ITEM_SET == pTemplateItemSet->GetItemState(FN_NUMBER_NEWSTART) )
563                         {
564                             sal_Bool bStart = ((SfxBoolItem&)pTemplateItemSet->Get(FN_NUMBER_NEWSTART)).GetValue();
565                             sal_uInt16 nNumStart = USHRT_MAX;
566 		                    if( SFX_ITEM_SET == pTemplateItemSet->GetItemState(FN_NUMBER_NEWSTART_AT) )
567                             {
568                                 nNumStart = ((SfxUInt16Item&)pTemplateItemSet->Get(FN_NUMBER_NEWSTART_AT)).GetValue();
569                                 if(USHRT_MAX != nNumStart)
570                                     bStart = sal_False;
571                             }
572                             rWrtShell.SetNumRuleStart(bStart);
573                             rWrtShell.SetNodeNumStart(nNumStart);
574                         }
575                         else if( SFX_ITEM_SET == pTemplateItemSet->GetItemState(FN_NUMBER_NEWSTART_AT) )
576                         {
577                             sal_uInt16 nNumStart = ((SfxUInt16Item&)pTemplateItemSet->Get(FN_NUMBER_NEWSTART_AT)).GetValue();
578                             rWrtShell.SetNodeNumStart(nNumStart);
579                             rWrtShell.SetNumRuleStart(sal_False);
580                         }
581                     }
582                 }
583                 delete pTemplateItemSet;
584             }
585         }
586     }
587 
588     if( m_pTableItemSet && nSelectionType & (nsSelectionType::SEL_TBL | nsSelectionType::SEL_TBL_CELLS) )
589         lcl_setTableAttributes( *m_pTableItemSet, rWrtShell );
590 
591     rWrtShell.EndUndo(UNDO_INSATTR);
592     rWrtShell.EndAction();
593 
594     if(!m_bPersistentCopy)
595         this->Erase();
596 }
597 
598 void SwFormatClipboard::Erase()
599 {
600     m_nSelectionType = 0;
601     if(m_pItemSet)
602     {
603         delete m_pItemSet;
604         m_pItemSet = 0;
605     }
606     if(m_pTableItemSet)
607     {
608         delete m_pTableItemSet;
609         m_pTableItemSet = 0;
610     }
611     if( m_aCharStyle.Len() )
612         m_aCharStyle.Erase();
613     if( m_aParaStyle.Len() )
614         m_aParaStyle.Erase();
615 
616     m_bPersistentCopy = false;
617 }
618