1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: formatclipboard.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sd.hxx"
34 #include "formatclipboard.hxx"
35 #include <svx/globl3d.hxx>
37 // header for class SfxItemIter
38 #include <svtools/itemiter.hxx>
40 // header for class SfxStyleSheet
41 #include <svtools/style.hxx>
43 /*--------------------------------------------------------------------
44 --------------------------------------------------------------------*/
46 SdFormatClipboard::SdFormatClipboard()
48 , m_bPersistentCopy(false)
50 , m_nType_Identifier(0)
53 SdFormatClipboard::~SdFormatClipboard()
59 bool SdFormatClipboard::HasContent() const
64 bool SdFormatClipboard::CanCopyThisType( UINT32 nObjectInventor
, UINT16 nObjectIdentifier
) const
66 if( nObjectInventor
!= SdrInventor
&& nObjectInventor
!= E3dInventor
)
68 switch(nObjectIdentifier
)
106 case OBJ_CUSTOMSHAPE
:
113 bool SdFormatClipboard::HasContentForThisType( UINT32 nObjectInventor
, UINT16 nObjectIdentifier
) const
117 if( !CanCopyThisType( nObjectInventor
, nObjectIdentifier
) )
122 void SdFormatClipboard::Copy( ::sd::View
& rDrawView
, bool bPersistentCopy
)
125 m_bPersistentCopy
= bPersistentCopy
;
127 const SdrMarkList
& rMarkList
= rDrawView
.GetMarkedObjectList();
128 if( rMarkList
.GetMarkCount() >= 1 )
130 BOOL bOnlyHardAttr
= FALSE
;
131 m_pItemSet
= new SfxItemSet( rDrawView
.GetAttrFromMarked(bOnlyHardAttr
) );
133 SdrObject
* pObj
= rMarkList
.GetMark(0)->GetMarkedSdrObj();
134 m_nType_Inventor
= pObj
->GetObjInventor();
135 m_nType_Identifier
= pObj
->GetObjIdentifier();
139 void SdFormatClipboard::Paste( ::sd::View
& rDrawView
, bool, bool )
141 if( !rDrawView
.AreObjectsMarked() )
143 if(!m_bPersistentCopy
)
150 bool bWrongTargetType
= false;
152 const SdrMarkList
& rMarkList
= rDrawView
.GetMarkedObjectList();
153 if( rMarkList
.GetMarkCount() != 1 )
154 bWrongTargetType
= true;
157 pObj
= rMarkList
.GetMark(0)->GetMarkedSdrObj();
158 if( pObj
&& pObj
->GetStyleSheet() )
159 bWrongTargetType
= !this->HasContentForThisType( pObj
->GetObjInventor(), pObj
->GetObjIdentifier() );
162 if( bWrongTargetType
)
164 if(!m_bPersistentCopy
)
170 //modify source itemset
172 boost::shared_ptr
< SfxItemSet
> pTargetSet
;
174 if( pObj
->GetStyleSheet() )
176 pTargetSet
.reset( new SfxItemSet( pObj
->GetStyleSheet()->GetItemSet() ) );
180 SdrModel
* pModel
= pObj
->GetModel();
183 pTargetSet
.reset( new SfxItemSet( pModel
->GetItemPool() ) );
187 if( pTargetSet
.get() )
190 SfxItemState nSourceState
;
191 SfxItemState nTargetState
;
192 const SfxPoolItem
* pSourceItem
=0;
193 const SfxPoolItem
* pTargetItem
=0;
194 SfxItemIter
aSourceIter(*m_pItemSet
);
195 pSourceItem
= aSourceIter
.FirstItem();
196 while( pSourceItem
!=NULL
)
198 if (!IsInvalidItem(pSourceItem
))
200 nWhich
= pSourceItem
->Which();
203 nSourceState
= m_pItemSet
->GetItemState( nWhich
);
204 nTargetState
= pTargetSet
->GetItemState( nWhich
);
205 pTargetItem
= pTargetSet
->GetItem( nWhich
);
208 m_pItemSet
->ClearItem(nWhich
);
209 else if( (*pSourceItem
) == (*pTargetItem
) )
211 //do not set items which have the same content in source and target
212 m_pItemSet
->ClearItem(nWhich
);
216 pSourceItem
= aSourceIter
.NextItem();
220 BOOL bReplaceAll
= TRUE
;
221 rDrawView
.SetAttrToMarked(*m_pItemSet
, bReplaceAll
);
223 if(!m_bPersistentCopy
)
227 void SdFormatClipboard::Erase()
235 m_nType_Identifier
=0;
236 m_bPersistentCopy
= false;