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