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