merge the formfield patch from ooo-build
[ooovba.git] / sd / source / ui / docshell / formatclipboard.cxx
blob0bc6d6fcda789b0b983050b4c4730b27b94b40e4
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: formatclipboard.cxx,v $
10 * $Revision: 1.10 $
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()
47 : m_pItemSet(0)
48 , m_bPersistentCopy(false)
49 , m_nType_Inventor(0)
50 , m_nType_Identifier(0)
53 SdFormatClipboard::~SdFormatClipboard()
55 if(m_pItemSet)
56 delete m_pItemSet;
59 bool SdFormatClipboard::HasContent() const
61 return m_pItemSet!=0;
64 bool SdFormatClipboard::CanCopyThisType( UINT32 nObjectInventor, UINT16 nObjectIdentifier ) const
66 if( nObjectInventor != SdrInventor && nObjectInventor != E3dInventor )
67 return false;
68 switch(nObjectIdentifier)
70 case OBJ_NONE:
71 case OBJ_GRUP:
72 return false;
73 case OBJ_LINE:
74 case OBJ_RECT:
75 case OBJ_CIRC:
76 case OBJ_SECT:
77 case OBJ_CARC:
78 case OBJ_CCUT:
79 case OBJ_POLY:
80 case OBJ_PLIN:
81 case OBJ_PATHLINE:
82 case OBJ_PATHFILL:
83 case OBJ_FREELINE:
84 case OBJ_FREEFILL:
85 case OBJ_SPLNLINE:
86 case OBJ_SPLNFILL:
87 case OBJ_TEXT:
88 case OBJ_TEXTEXT:
89 case OBJ_TITLETEXT:
90 return true;
91 case OBJ_OUTLINETEXT:
92 case OBJ_GRAF:
93 case OBJ_OLE2:
94 case OBJ_EDGE:
95 case OBJ_CAPTION:
96 return false;
97 case OBJ_PATHPOLY:
98 case OBJ_PATHPLIN:
99 return true;
100 case OBJ_PAGE:
101 case OBJ_MEASURE:
102 case OBJ_DUMMY:
103 case OBJ_FRAME:
104 case OBJ_UNO:
105 return false;
106 case OBJ_CUSTOMSHAPE:
107 return true;
108 default:
109 return false;
113 bool SdFormatClipboard::HasContentForThisType( UINT32 nObjectInventor, UINT16 nObjectIdentifier ) const
115 if( !HasContent() )
116 return false;
117 if( !CanCopyThisType( nObjectInventor, nObjectIdentifier ) )
118 return false;
119 return true;
122 void SdFormatClipboard::Copy( ::sd::View& rDrawView, bool bPersistentCopy )
124 this->Erase();
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)
144 this->Erase();
145 return;
148 SdrObject* pObj = 0;
150 bool bWrongTargetType = false;
152 const SdrMarkList& rMarkList = rDrawView.GetMarkedObjectList();
153 if( rMarkList.GetMarkCount() != 1 )
154 bWrongTargetType = true;
155 else
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)
165 this->Erase();
166 return;
168 if(m_pItemSet)
170 //modify source itemset
172 boost::shared_ptr< SfxItemSet > pTargetSet;
174 if( pObj->GetStyleSheet() )
176 pTargetSet.reset( new SfxItemSet( pObj->GetStyleSheet()->GetItemSet() ) );
178 else
180 SdrModel* pModel = pObj->GetModel();
181 if( pModel )
183 pTargetSet.reset( new SfxItemSet( pModel->GetItemPool() ) );
187 if( pTargetSet.get() )
189 USHORT nWhich=0;
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();
201 if(nWhich)
203 nSourceState = m_pItemSet->GetItemState( nWhich );
204 nTargetState = pTargetSet->GetItemState( nWhich );
205 pTargetItem = pTargetSet->GetItem( nWhich );
207 if(!pTargetItem)
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();
217 }//end while
220 BOOL bReplaceAll = TRUE;
221 rDrawView.SetAttrToMarked(*m_pItemSet, bReplaceAll);
223 if(!m_bPersistentCopy)
224 this->Erase();
227 void SdFormatClipboard::Erase()
229 if(m_pItemSet)
231 delete m_pItemSet;
232 m_pItemSet = 0;
234 m_nType_Inventor=0;
235 m_nType_Identifier=0;
236 m_bPersistentCopy = false;