xref: /AOO41X/main/sd/source/ui/app/sdxfer.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
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_sd.hxx"
30*cdf0e10cSrcweir #include <com/sun/star/embed/XTransactedObject.hpp>
31*cdf0e10cSrcweir #include <com/sun/star/embed/XEmbedPersist.hpp>
32*cdf0e10cSrcweir #include <com/sun/star/embed/ElementModes.hpp>
33*cdf0e10cSrcweir #include <com/sun/star/lang/XComponent.hpp>
34*cdf0e10cSrcweir #include <vos/mutex.hxx>
35*cdf0e10cSrcweir #include <unotools/ucbstreamhelper.hxx>
36*cdf0e10cSrcweir #ifndef _UNTOOLS_TEMPFILE_HXX
37*cdf0e10cSrcweir #include <unotools/tempfile.hxx>
38*cdf0e10cSrcweir #endif
39*cdf0e10cSrcweir #include <editeng/eeitem.hxx>
40*cdf0e10cSrcweir #include <editeng/flditem.hxx>
41*cdf0e10cSrcweir #include <svx/svdpagv.hxx>
42*cdf0e10cSrcweir #include <sfx2/app.hxx>
43*cdf0e10cSrcweir #include <vcl/msgbox.hxx>
44*cdf0e10cSrcweir #include <svx/svdoole2.hxx>
45*cdf0e10cSrcweir #include <svx/svdograf.hxx>
46*cdf0e10cSrcweir #include <svx/svdotext.hxx>
47*cdf0e10cSrcweir #include <editeng/outlobj.hxx>
48*cdf0e10cSrcweir #include <sot/storage.hxx>
49*cdf0e10cSrcweir #include <svl/itempool.hxx>
50*cdf0e10cSrcweir #include <editeng/editobj.hxx>
51*cdf0e10cSrcweir #include <svx/fmglob.hxx>
52*cdf0e10cSrcweir #include <svx/svdouno.hxx>
53*cdf0e10cSrcweir #include <tools/urlobj.hxx>
54*cdf0e10cSrcweir #include <sot/formats.hxx>
55*cdf0e10cSrcweir #include <svl/urlbmk.hxx>
56*cdf0e10cSrcweir #include <editeng/outliner.hxx>
57*cdf0e10cSrcweir 
58*cdf0e10cSrcweir //#ifndef _SVDETC_HXX //autogen
59*cdf0e10cSrcweir //#include <svx/svdetc.hxx>
60*cdf0e10cSrcweir //#endif
61*cdf0e10cSrcweir #include <com/sun/star/form/FormButtonType.hpp>
62*cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp>
63*cdf0e10cSrcweir #include <unotools/streamwrap.hxx>
64*cdf0e10cSrcweir 
65*cdf0e10cSrcweir #include <svx/svdotable.hxx>
66*cdf0e10cSrcweir #include <svx/unomodel.hxx>
67*cdf0e10cSrcweir #include <svx/svditer.hxx>
68*cdf0e10cSrcweir #include <sfx2/docfile.hxx>
69*cdf0e10cSrcweir #include <comphelper/storagehelper.hxx>
70*cdf0e10cSrcweir #include <svtools/embedtransfer.hxx>
71*cdf0e10cSrcweir #include "DrawDocShell.hxx"
72*cdf0e10cSrcweir #include "View.hxx"
73*cdf0e10cSrcweir #include "sdpage.hxx"
74*cdf0e10cSrcweir #include "drawview.hxx"
75*cdf0e10cSrcweir #include "drawdoc.hxx"
76*cdf0e10cSrcweir #include "stlpool.hxx"
77*cdf0e10cSrcweir #include "strings.hrc"
78*cdf0e10cSrcweir #include "sdresid.hxx"
79*cdf0e10cSrcweir #include "imapinfo.hxx"
80*cdf0e10cSrcweir #include "sdxfer.hxx"
81*cdf0e10cSrcweir #include "unomodel.hxx"
82*cdf0e10cSrcweir #include <vcl/virdev.hxx>
83*cdf0e10cSrcweir 
84*cdf0e10cSrcweir // --------------
85*cdf0e10cSrcweir // - Namespaces -
86*cdf0e10cSrcweir // --------------
87*cdf0e10cSrcweir 
88*cdf0e10cSrcweir using namespace ::com::sun::star;
89*cdf0e10cSrcweir using namespace ::com::sun::star::lang;
90*cdf0e10cSrcweir using namespace ::com::sun::star::uno;
91*cdf0e10cSrcweir using namespace ::com::sun::star::io;
92*cdf0e10cSrcweir using namespace ::com::sun::star::datatransfer;
93*cdf0e10cSrcweir using namespace ::com::sun::star::datatransfer::clipboard;
94*cdf0e10cSrcweir 
95*cdf0e10cSrcweir // -----------
96*cdf0e10cSrcweir // - Defines -
97*cdf0e10cSrcweir // -----------
98*cdf0e10cSrcweir 
99*cdf0e10cSrcweir #define SDTRANSFER_OBJECTTYPE_DRAWMODEL			0x00000001
100*cdf0e10cSrcweir #define SDTRANSFER_OBJECTTYPE_DRAWOLE			0x00000002
101*cdf0e10cSrcweir 
102*cdf0e10cSrcweir // ------------------
103*cdf0e10cSrcweir // - SdTransferable -
104*cdf0e10cSrcweir // ------------------
105*cdf0e10cSrcweir 
106*cdf0e10cSrcweir SdTransferable::SdTransferable( SdDrawDocument* pSrcDoc, ::sd::View* pWorkView, sal_Bool bInitOnGetData )
107*cdf0e10cSrcweir :	mpPageDocShell( NULL )
108*cdf0e10cSrcweir ,	mpOLEDataHelper( NULL )
109*cdf0e10cSrcweir ,	mpObjDesc( NULL )
110*cdf0e10cSrcweir ,	mpSdView( pWorkView )
111*cdf0e10cSrcweir ,	mpSdViewIntern( pWorkView )
112*cdf0e10cSrcweir ,	mpSdDrawDocument( NULL )
113*cdf0e10cSrcweir ,	mpSdDrawDocumentIntern( NULL )
114*cdf0e10cSrcweir ,	mpSourceDoc( pSrcDoc )
115*cdf0e10cSrcweir ,	mpVDev( NULL )
116*cdf0e10cSrcweir ,	mpBookmark( NULL )
117*cdf0e10cSrcweir ,	mpGraphic( NULL )
118*cdf0e10cSrcweir ,	mpImageMap( NULL )
119*cdf0e10cSrcweir ,	mbInternalMove( sal_False )
120*cdf0e10cSrcweir ,	mbOwnDocument( sal_False )
121*cdf0e10cSrcweir ,	mbOwnView( sal_False )
122*cdf0e10cSrcweir ,	mbLateInit( bInitOnGetData )
123*cdf0e10cSrcweir ,	mbPageTransferable( sal_False )
124*cdf0e10cSrcweir ,	mbPageTransferablePersistent( sal_False )
125*cdf0e10cSrcweir ,	mbIsUnoObj( false )
126*cdf0e10cSrcweir ,   maUserData()
127*cdf0e10cSrcweir {
128*cdf0e10cSrcweir 	if( mpSourceDoc )
129*cdf0e10cSrcweir 		StartListening( *mpSourceDoc );
130*cdf0e10cSrcweir 
131*cdf0e10cSrcweir 	if( pWorkView )
132*cdf0e10cSrcweir 		StartListening( *pWorkView );
133*cdf0e10cSrcweir 
134*cdf0e10cSrcweir     if( !mbLateInit )
135*cdf0e10cSrcweir 	    CreateData();
136*cdf0e10cSrcweir }
137*cdf0e10cSrcweir 
138*cdf0e10cSrcweir // -----------------------------------------------------------------------------
139*cdf0e10cSrcweir 
140*cdf0e10cSrcweir SdTransferable::~SdTransferable()
141*cdf0e10cSrcweir {
142*cdf0e10cSrcweir 	if( mpSourceDoc )
143*cdf0e10cSrcweir 		EndListening( *mpSourceDoc );
144*cdf0e10cSrcweir 
145*cdf0e10cSrcweir 	if( mpSdView )
146*cdf0e10cSrcweir 		EndListening( *const_cast< sd::View *>( mpSdView) );
147*cdf0e10cSrcweir 
148*cdf0e10cSrcweir 	Application::GetSolarMutex().acquire();
149*cdf0e10cSrcweir 
150*cdf0e10cSrcweir     ObjectReleased();
151*cdf0e10cSrcweir 
152*cdf0e10cSrcweir     for( void* p = maPageBookmarks.First(); p; p = maPageBookmarks.Next() )
153*cdf0e10cSrcweir         delete static_cast< String* >( p );
154*cdf0e10cSrcweir 
155*cdf0e10cSrcweir 	if( mbOwnView )
156*cdf0e10cSrcweir 		delete mpSdViewIntern;
157*cdf0e10cSrcweir 
158*cdf0e10cSrcweir     delete mpOLEDataHelper;
159*cdf0e10cSrcweir 
160*cdf0e10cSrcweir 	if( maDocShellRef.Is() )
161*cdf0e10cSrcweir 	{
162*cdf0e10cSrcweir         SfxObjectShell* pObj = maDocShellRef;
163*cdf0e10cSrcweir 		::sd::DrawDocShell* pDocSh = static_cast< ::sd::DrawDocShell*>(pObj);
164*cdf0e10cSrcweir 		pDocSh->DoClose();
165*cdf0e10cSrcweir 	}
166*cdf0e10cSrcweir 
167*cdf0e10cSrcweir 	maDocShellRef.Clear();
168*cdf0e10cSrcweir 
169*cdf0e10cSrcweir 	if( mbOwnDocument )
170*cdf0e10cSrcweir 		delete mpSdDrawDocumentIntern;
171*cdf0e10cSrcweir 
172*cdf0e10cSrcweir 	delete mpGraphic;
173*cdf0e10cSrcweir 	delete mpBookmark;
174*cdf0e10cSrcweir 	delete mpImageMap;
175*cdf0e10cSrcweir 
176*cdf0e10cSrcweir 	delete mpVDev;
177*cdf0e10cSrcweir 	delete mpObjDesc;
178*cdf0e10cSrcweir 
179*cdf0e10cSrcweir 	Application::GetSolarMutex().release();
180*cdf0e10cSrcweir }
181*cdf0e10cSrcweir 
182*cdf0e10cSrcweir // -----------------------------------------------------------------------------
183*cdf0e10cSrcweir 
184*cdf0e10cSrcweir void SdTransferable::CreateObjectReplacement( SdrObject* pObj )
185*cdf0e10cSrcweir {
186*cdf0e10cSrcweir 	if( pObj )
187*cdf0e10cSrcweir 	{
188*cdf0e10cSrcweir         delete mpOLEDataHelper, mpOLEDataHelper = NULL;
189*cdf0e10cSrcweir 		delete mpGraphic, mpGraphic = NULL;
190*cdf0e10cSrcweir 		delete mpBookmark, mpBookmark = NULL;
191*cdf0e10cSrcweir 		delete mpImageMap, mpImageMap = NULL;
192*cdf0e10cSrcweir 
193*cdf0e10cSrcweir 		if( pObj->ISA( SdrOle2Obj ) )
194*cdf0e10cSrcweir 		{
195*cdf0e10cSrcweir 			try
196*cdf0e10cSrcweir 			{
197*cdf0e10cSrcweir             	uno::Reference < embed::XEmbeddedObject > xObj = static_cast< SdrOle2Obj* >( pObj )->GetObjRef();
198*cdf0e10cSrcweir 				uno::Reference < embed::XEmbedPersist > xPersist( xObj, uno::UNO_QUERY );
199*cdf0e10cSrcweir             	if( xObj.is() && xPersist.is() && xPersist->hasEntry() )
200*cdf0e10cSrcweir 				{
201*cdf0e10cSrcweir                 	mpOLEDataHelper = new TransferableDataHelper( new SvEmbedTransferHelper( xObj, static_cast< SdrOle2Obj* >( pObj )->GetGraphic(), static_cast< SdrOle2Obj* >( pObj )->GetAspect() ) );
202*cdf0e10cSrcweir 
203*cdf0e10cSrcweir 					// TODO/LATER: the standalone handling of the graphic should not be used any more in future
204*cdf0e10cSrcweir 					// The EmbedDataHelper should bring the graphic in future
205*cdf0e10cSrcweir 					Graphic* pObjGr = static_cast< SdrOle2Obj* >( pObj )->GetGraphic();
206*cdf0e10cSrcweir 					if ( pObjGr )
207*cdf0e10cSrcweir 						mpGraphic = new Graphic( *pObjGr );
208*cdf0e10cSrcweir 				}
209*cdf0e10cSrcweir 			}
210*cdf0e10cSrcweir 			catch( uno::Exception& )
211*cdf0e10cSrcweir 			{}
212*cdf0e10cSrcweir 		}
213*cdf0e10cSrcweir 		else if( pObj->ISA( SdrGrafObj ) && (mpSourceDoc && !mpSourceDoc->GetAnimationInfo( pObj )) )
214*cdf0e10cSrcweir 		{
215*cdf0e10cSrcweir 			mpGraphic = new Graphic( static_cast< SdrGrafObj* >( pObj )->GetTransformedGraphic() );
216*cdf0e10cSrcweir 		}
217*cdf0e10cSrcweir 		else if( pObj->IsUnoObj() && FmFormInventor == pObj->GetObjInventor() && ( pObj->GetObjIdentifier() == (sal_uInt16) OBJ_FM_BUTTON ) )
218*cdf0e10cSrcweir 		{
219*cdf0e10cSrcweir 			SdrUnoObj* pUnoCtrl = static_cast< SdrUnoObj* >( pObj );
220*cdf0e10cSrcweir 
221*cdf0e10cSrcweir 			if (pUnoCtrl && FmFormInventor == pUnoCtrl->GetObjInventor())
222*cdf0e10cSrcweir 			{
223*cdf0e10cSrcweir 				Reference< ::com::sun::star::awt::XControlModel > xControlModel( pUnoCtrl->GetUnoControlModel() );
224*cdf0e10cSrcweir 
225*cdf0e10cSrcweir 				if( !xControlModel.is() )
226*cdf0e10cSrcweir 					return;
227*cdf0e10cSrcweir 
228*cdf0e10cSrcweir 				Reference< ::com::sun::star::beans::XPropertySet > xPropSet( xControlModel, UNO_QUERY );
229*cdf0e10cSrcweir 
230*cdf0e10cSrcweir 				if( !xPropSet.is() )
231*cdf0e10cSrcweir 					return;
232*cdf0e10cSrcweir 
233*cdf0e10cSrcweir 				::com::sun::star::form::FormButtonType	eButtonType;
234*cdf0e10cSrcweir 				Any										aTmp( xPropSet->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ButtonType" ) ) ) );
235*cdf0e10cSrcweir 
236*cdf0e10cSrcweir 				if( aTmp >>= eButtonType )
237*cdf0e10cSrcweir 				{
238*cdf0e10cSrcweir 					::rtl::OUString aLabel, aURL;
239*cdf0e10cSrcweir 
240*cdf0e10cSrcweir 					xPropSet->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Label" ) ) ) >>= aLabel;
241*cdf0e10cSrcweir 					xPropSet->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("TargetURL") ) ) >>= aURL;
242*cdf0e10cSrcweir 
243*cdf0e10cSrcweir 					mpBookmark = new INetBookmark( String( aURL ), String( aLabel ) );
244*cdf0e10cSrcweir 				}
245*cdf0e10cSrcweir 			}
246*cdf0e10cSrcweir 		}
247*cdf0e10cSrcweir 		else if( pObj->ISA( SdrTextObj ) )
248*cdf0e10cSrcweir 		{
249*cdf0e10cSrcweir 			const OutlinerParaObject* pPara;
250*cdf0e10cSrcweir 
251*cdf0e10cSrcweir 			if( (pPara = static_cast< SdrTextObj* >( pObj )->GetOutlinerParaObject()) != 0 )
252*cdf0e10cSrcweir 			{
253*cdf0e10cSrcweir 				const SvxFieldItem* pField;
254*cdf0e10cSrcweir 
255*cdf0e10cSrcweir 				if( (pField = pPara->GetTextObject().GetField()) != 0 )
256*cdf0e10cSrcweir 				{
257*cdf0e10cSrcweir 					const SvxFieldData* pData = pField->GetField();
258*cdf0e10cSrcweir 
259*cdf0e10cSrcweir 					if( pData && pData->ISA( SvxURLField ) )
260*cdf0e10cSrcweir 					{
261*cdf0e10cSrcweir 						const SvxURLField* pURL = (SvxURLField*) pData;
262*cdf0e10cSrcweir 
263*cdf0e10cSrcweir 						mpBookmark = new INetBookmark( pURL->GetURL(), pURL->GetRepresentation() );
264*cdf0e10cSrcweir 					}
265*cdf0e10cSrcweir 				}
266*cdf0e10cSrcweir 			}
267*cdf0e10cSrcweir 		}
268*cdf0e10cSrcweir 
269*cdf0e10cSrcweir 		SdIMapInfo*	pInfo = static_cast< SdDrawDocument* >( pObj->GetModel() )->GetIMapInfo( static_cast< SdrObject* >( pObj ) );
270*cdf0e10cSrcweir 
271*cdf0e10cSrcweir 		if( pInfo )
272*cdf0e10cSrcweir 			mpImageMap = new ImageMap( pInfo->GetImageMap() );
273*cdf0e10cSrcweir 
274*cdf0e10cSrcweir 		mbIsUnoObj = pObj && pObj->IsUnoObj();
275*cdf0e10cSrcweir 	}
276*cdf0e10cSrcweir }
277*cdf0e10cSrcweir 
278*cdf0e10cSrcweir // -----------------------------------------------------------------------------
279*cdf0e10cSrcweir 
280*cdf0e10cSrcweir void SdTransferable::CreateData()
281*cdf0e10cSrcweir {
282*cdf0e10cSrcweir 	if( mpSdDrawDocument && !mpSdViewIntern )
283*cdf0e10cSrcweir 	{
284*cdf0e10cSrcweir 		mbOwnView = sal_True;
285*cdf0e10cSrcweir 
286*cdf0e10cSrcweir 		SdPage* pPage = mpSdDrawDocument->GetSdPage(0, PK_STANDARD);
287*cdf0e10cSrcweir 
288*cdf0e10cSrcweir 		if( 1 == pPage->GetObjCount() )
289*cdf0e10cSrcweir 			CreateObjectReplacement( pPage->GetObj( 0 ) );
290*cdf0e10cSrcweir 
291*cdf0e10cSrcweir 		mpVDev = new VirtualDevice( *Application::GetDefaultDevice() );
292*cdf0e10cSrcweir 		mpVDev->SetMapMode( MapMode( mpSdDrawDocumentIntern->GetScaleUnit(), Point(), mpSdDrawDocumentIntern->GetScaleFraction(), mpSdDrawDocumentIntern->GetScaleFraction() ) );
293*cdf0e10cSrcweir 		mpSdViewIntern = new ::sd::View( mpSdDrawDocumentIntern, mpVDev );
294*cdf0e10cSrcweir 		mpSdViewIntern->EndListening(*mpSdDrawDocumentIntern );
295*cdf0e10cSrcweir 		mpSdViewIntern->hideMarkHandles();
296*cdf0e10cSrcweir 		SdrPageView* pPageView = mpSdViewIntern->ShowSdrPage(pPage);
297*cdf0e10cSrcweir 		((SdrMarkView*)mpSdViewIntern)->MarkAllObj(pPageView);
298*cdf0e10cSrcweir 	}
299*cdf0e10cSrcweir 	else if( mpSdView && !mpSdDrawDocumentIntern )
300*cdf0e10cSrcweir 	{
301*cdf0e10cSrcweir 		const SdrMarkList& rMarkList = mpSdView->GetMarkedObjectList();
302*cdf0e10cSrcweir 
303*cdf0e10cSrcweir 		if( rMarkList.GetMarkCount() == 1 )
304*cdf0e10cSrcweir 			CreateObjectReplacement( rMarkList.GetMark( 0 )->GetMarkedSdrObj() );
305*cdf0e10cSrcweir 
306*cdf0e10cSrcweir 		if( mpSourceDoc )
307*cdf0e10cSrcweir 			mpSourceDoc->CreatingDataObj(this);
308*cdf0e10cSrcweir 		mpSdDrawDocumentIntern = (SdDrawDocument*) mpSdView->GetAllMarkedModel();
309*cdf0e10cSrcweir 		if( mpSourceDoc )
310*cdf0e10cSrcweir 			mpSourceDoc->CreatingDataObj(0);
311*cdf0e10cSrcweir 
312*cdf0e10cSrcweir 		if( !maDocShellRef.Is() && mpSdDrawDocumentIntern->GetDocSh() )
313*cdf0e10cSrcweir 			maDocShellRef = mpSdDrawDocumentIntern->GetDocSh();
314*cdf0e10cSrcweir 
315*cdf0e10cSrcweir 		if( !maDocShellRef.Is() )
316*cdf0e10cSrcweir 		{
317*cdf0e10cSrcweir 			DBG_ERROR( "SdTransferable::CreateData(), failed to create a model with persist, clipboard operation will fail for OLE objects!" );
318*cdf0e10cSrcweir 			mbOwnDocument = sal_True;
319*cdf0e10cSrcweir 		}
320*cdf0e10cSrcweir 
321*cdf0e10cSrcweir 		// Groesse der Source-Seite uebernehmen
322*cdf0e10cSrcweir 		SdrPageView*		pPgView = mpSdView->GetSdrPageView();
323*cdf0e10cSrcweir 		SdPage*				pOldPage = (SdPage*) pPgView->GetPage();
324*cdf0e10cSrcweir 		SdrModel*			pOldModel = mpSdView->GetModel();
325*cdf0e10cSrcweir 		SdStyleSheetPool*	pOldStylePool = (SdStyleSheetPool*) pOldModel->GetStyleSheetPool();
326*cdf0e10cSrcweir 		SdStyleSheetPool*	pNewStylePool = (SdStyleSheetPool*) mpSdDrawDocumentIntern->GetStyleSheetPool();
327*cdf0e10cSrcweir 		SdPage*				pPage = mpSdDrawDocumentIntern->GetSdPage( 0, PK_STANDARD );
328*cdf0e10cSrcweir 		String				aOldLayoutName( pOldPage->GetLayoutName() );
329*cdf0e10cSrcweir 
330*cdf0e10cSrcweir 		pPage->SetSize( pOldPage->GetSize() );
331*cdf0e10cSrcweir 		pPage->SetLayoutName( aOldLayoutName );
332*cdf0e10cSrcweir 		pNewStylePool->CopyGraphicSheets( *pOldStylePool );
333*cdf0e10cSrcweir 		pNewStylePool->CopyCellSheets( *pOldStylePool );
334*cdf0e10cSrcweir 		pNewStylePool->CopyTableStyles( *pOldStylePool );
335*cdf0e10cSrcweir 		aOldLayoutName.Erase( aOldLayoutName.SearchAscii( SD_LT_SEPARATOR ) );
336*cdf0e10cSrcweir 		SdStyleSheetVector aCreatedSheets;
337*cdf0e10cSrcweir 		pNewStylePool->CopyLayoutSheets( aOldLayoutName, *pOldStylePool, aCreatedSheets );
338*cdf0e10cSrcweir 	}
339*cdf0e10cSrcweir 
340*cdf0e10cSrcweir 	// set VisArea and adjust objects if neccessary
341*cdf0e10cSrcweir 	if( maVisArea.IsEmpty() &&
342*cdf0e10cSrcweir 		mpSdDrawDocumentIntern && mpSdViewIntern &&
343*cdf0e10cSrcweir 		mpSdDrawDocumentIntern->GetPageCount() )
344*cdf0e10cSrcweir 	{
345*cdf0e10cSrcweir 		SdPage*	pPage = mpSdDrawDocumentIntern->GetSdPage( 0, PK_STANDARD );
346*cdf0e10cSrcweir 
347*cdf0e10cSrcweir 		if( 1 == mpSdDrawDocumentIntern->GetPageCount() )
348*cdf0e10cSrcweir 		{
349*cdf0e10cSrcweir 			// #112978# need to use GetAllMarkedBoundRect instead of GetAllMarkedRect to get
350*cdf0e10cSrcweir 			// fat lines correctly
351*cdf0e10cSrcweir 			Point	aOrigin( ( maVisArea = mpSdViewIntern->GetAllMarkedBoundRect() ).TopLeft() );
352*cdf0e10cSrcweir 			Size	aVector( -aOrigin.X(), -aOrigin.Y() );
353*cdf0e10cSrcweir 
354*cdf0e10cSrcweir 			for( sal_uLong nObj = 0, nObjCount = pPage->GetObjCount(); nObj < nObjCount; nObj++ )
355*cdf0e10cSrcweir 			{
356*cdf0e10cSrcweir 				SdrObject* pObj = pPage->GetObj( nObj );
357*cdf0e10cSrcweir 				pObj->NbcMove( aVector );
358*cdf0e10cSrcweir 			}
359*cdf0e10cSrcweir 		}
360*cdf0e10cSrcweir 		else
361*cdf0e10cSrcweir 			maVisArea.SetSize( pPage->GetSize() );
362*cdf0e10cSrcweir 
363*cdf0e10cSrcweir 		// Die Ausgabe soll am Nullpunkt erfolgen
364*cdf0e10cSrcweir 		maVisArea.SetPos( Point() );
365*cdf0e10cSrcweir 	}
366*cdf0e10cSrcweir }
367*cdf0e10cSrcweir 
368*cdf0e10cSrcweir // -----------------------------------------------------------------------------
369*cdf0e10cSrcweir 
370*cdf0e10cSrcweir sal_Bool lcl_HasOnlyControls( SdrModel* pModel )
371*cdf0e10cSrcweir {
372*cdf0e10cSrcweir     sal_Bool bOnlyControls = sal_False;         // default if there are no objects
373*cdf0e10cSrcweir 
374*cdf0e10cSrcweir     if ( pModel )
375*cdf0e10cSrcweir     {
376*cdf0e10cSrcweir         SdrPage* pPage = pModel->GetPage(0);
377*cdf0e10cSrcweir         if (pPage)
378*cdf0e10cSrcweir         {
379*cdf0e10cSrcweir             SdrObjListIter aIter( *pPage, IM_DEEPNOGROUPS );
380*cdf0e10cSrcweir             SdrObject* pObj = aIter.Next();
381*cdf0e10cSrcweir             if ( pObj )
382*cdf0e10cSrcweir             {
383*cdf0e10cSrcweir                 bOnlyControls = sal_True;   // only set if there are any objects at all
384*cdf0e10cSrcweir                 while ( pObj )
385*cdf0e10cSrcweir                 {
386*cdf0e10cSrcweir                     if (!pObj->ISA(SdrUnoObj))
387*cdf0e10cSrcweir                     {
388*cdf0e10cSrcweir                         bOnlyControls = sal_False;
389*cdf0e10cSrcweir                         break;
390*cdf0e10cSrcweir                     }
391*cdf0e10cSrcweir                     pObj = aIter.Next();
392*cdf0e10cSrcweir                 }
393*cdf0e10cSrcweir             }
394*cdf0e10cSrcweir         }
395*cdf0e10cSrcweir     }
396*cdf0e10cSrcweir 
397*cdf0e10cSrcweir     return bOnlyControls;
398*cdf0e10cSrcweir }
399*cdf0e10cSrcweir 
400*cdf0e10cSrcweir // -----------------------------------------------------------------------------
401*cdf0e10cSrcweir 
402*cdf0e10cSrcweir bool lcl_HasOnlyOneTable( SdrModel* pModel )
403*cdf0e10cSrcweir {
404*cdf0e10cSrcweir     if ( pModel )
405*cdf0e10cSrcweir     {
406*cdf0e10cSrcweir         SdrPage* pPage = pModel->GetPage(0);
407*cdf0e10cSrcweir         if (pPage && pPage->GetObjCount() == 1 )
408*cdf0e10cSrcweir         {
409*cdf0e10cSrcweir 			if( dynamic_cast< sdr::table::SdrTableObj* >( pPage->GetObj(0) ) != 0 )
410*cdf0e10cSrcweir 				return true;
411*cdf0e10cSrcweir 		}
412*cdf0e10cSrcweir 	}
413*cdf0e10cSrcweir 	return false;
414*cdf0e10cSrcweir }
415*cdf0e10cSrcweir 
416*cdf0e10cSrcweir // -----------------------------------------------------------------------------
417*cdf0e10cSrcweir 
418*cdf0e10cSrcweir void SdTransferable::AddSupportedFormats()
419*cdf0e10cSrcweir {
420*cdf0e10cSrcweir     if( !mbPageTransferable || mbPageTransferablePersistent )
421*cdf0e10cSrcweir     {
422*cdf0e10cSrcweir         if( !mbLateInit )
423*cdf0e10cSrcweir             CreateData();
424*cdf0e10cSrcweir 
425*cdf0e10cSrcweir 	    if( mpObjDesc )
426*cdf0e10cSrcweir             AddFormat( SOT_FORMATSTR_ID_OBJECTDESCRIPTOR );
427*cdf0e10cSrcweir 
428*cdf0e10cSrcweir         if( mpOLEDataHelper )
429*cdf0e10cSrcweir 	    {
430*cdf0e10cSrcweir 		    AddFormat( SOT_FORMATSTR_ID_EMBED_SOURCE );
431*cdf0e10cSrcweir 
432*cdf0e10cSrcweir 		    DataFlavorExVector				aVector( mpOLEDataHelper->GetDataFlavorExVector() );
433*cdf0e10cSrcweir 		    DataFlavorExVector::iterator	aIter( aVector.begin() ), aEnd( aVector.end() );
434*cdf0e10cSrcweir 
435*cdf0e10cSrcweir 		    while( aIter != aEnd )
436*cdf0e10cSrcweir 			    AddFormat( *aIter++ );
437*cdf0e10cSrcweir 	    }
438*cdf0e10cSrcweir 	    else if( mpGraphic )
439*cdf0e10cSrcweir 	    {
440*cdf0e10cSrcweir 			// #i25616#
441*cdf0e10cSrcweir 		    AddFormat( SOT_FORMATSTR_ID_DRAWING );
442*cdf0e10cSrcweir 
443*cdf0e10cSrcweir 			AddFormat( SOT_FORMATSTR_ID_SVXB );
444*cdf0e10cSrcweir 
445*cdf0e10cSrcweir 		    if( mpGraphic->GetType() == GRAPHIC_BITMAP )
446*cdf0e10cSrcweir 		    {
447*cdf0e10cSrcweir 			    AddFormat( SOT_FORMAT_BITMAP );
448*cdf0e10cSrcweir 			    AddFormat( SOT_FORMAT_GDIMETAFILE );
449*cdf0e10cSrcweir 		    }
450*cdf0e10cSrcweir 		    else
451*cdf0e10cSrcweir 		    {
452*cdf0e10cSrcweir 			    AddFormat( SOT_FORMAT_GDIMETAFILE );
453*cdf0e10cSrcweir 			    AddFormat( SOT_FORMAT_BITMAP );
454*cdf0e10cSrcweir 		    }
455*cdf0e10cSrcweir 	    }
456*cdf0e10cSrcweir 	    else if( mpBookmark )
457*cdf0e10cSrcweir 	    {
458*cdf0e10cSrcweir 		    AddFormat( SOT_FORMATSTR_ID_NETSCAPE_BOOKMARK );
459*cdf0e10cSrcweir 		    AddFormat( FORMAT_STRING );
460*cdf0e10cSrcweir 	    }
461*cdf0e10cSrcweir 	    else
462*cdf0e10cSrcweir 	    {
463*cdf0e10cSrcweir 		    AddFormat( SOT_FORMATSTR_ID_EMBED_SOURCE );
464*cdf0e10cSrcweir 		    AddFormat( SOT_FORMATSTR_ID_DRAWING );
465*cdf0e10cSrcweir 			if( !mpSdDrawDocument || !lcl_HasOnlyControls( mpSdDrawDocument ) )
466*cdf0e10cSrcweir 			{
467*cdf0e10cSrcweir 				AddFormat( SOT_FORMAT_GDIMETAFILE );
468*cdf0e10cSrcweir 				AddFormat( SOT_FORMAT_BITMAP );
469*cdf0e10cSrcweir 			}
470*cdf0e10cSrcweir 
471*cdf0e10cSrcweir 			if( lcl_HasOnlyOneTable( mpSdDrawDocument ) )
472*cdf0e10cSrcweir 				AddFormat( SOT_FORMAT_RTF );
473*cdf0e10cSrcweir 	    }
474*cdf0e10cSrcweir 
475*cdf0e10cSrcweir 	    if( mpImageMap )
476*cdf0e10cSrcweir 		    AddFormat( SOT_FORMATSTR_ID_SVIM );
477*cdf0e10cSrcweir     }
478*cdf0e10cSrcweir }
479*cdf0e10cSrcweir 
480*cdf0e10cSrcweir // -----------------------------------------------------------------------------
481*cdf0e10cSrcweir 
482*cdf0e10cSrcweir sal_Bool SdTransferable::GetData( const DataFlavor& rFlavor )
483*cdf0e10cSrcweir {
484*cdf0e10cSrcweir 	if (SD_MOD()==NULL)
485*cdf0e10cSrcweir 		return sal_False;
486*cdf0e10cSrcweir 
487*cdf0e10cSrcweir 	sal_uInt32	nFormat = SotExchange::GetFormat( rFlavor );
488*cdf0e10cSrcweir 	sal_Bool	bOK = sal_False;
489*cdf0e10cSrcweir 
490*cdf0e10cSrcweir     CreateData();
491*cdf0e10cSrcweir 
492*cdf0e10cSrcweir 	if( nFormat == SOT_FORMAT_RTF && lcl_HasOnlyOneTable( mpSdDrawDocument ) )
493*cdf0e10cSrcweir 	{
494*cdf0e10cSrcweir 		bOK = SetTableRTF( mpSdDrawDocument, rFlavor );
495*cdf0e10cSrcweir 	}
496*cdf0e10cSrcweir 	else if( mpOLEDataHelper && mpOLEDataHelper->HasFormat( rFlavor ) )
497*cdf0e10cSrcweir 	{
498*cdf0e10cSrcweir 		sal_uLong nOldSwapMode = 0;
499*cdf0e10cSrcweir 
500*cdf0e10cSrcweir 		if( mpSdDrawDocumentIntern )
501*cdf0e10cSrcweir 		{
502*cdf0e10cSrcweir 			nOldSwapMode = mpSdDrawDocumentIntern->GetSwapGraphicsMode();
503*cdf0e10cSrcweir 			mpSdDrawDocumentIntern->SetSwapGraphicsMode( SDR_SWAPGRAPHICSMODE_PURGE );
504*cdf0e10cSrcweir 		}
505*cdf0e10cSrcweir 
506*cdf0e10cSrcweir 		// TODO/LATER: support all the graphical formats, the embedded object scenario should not have separated handling
507*cdf0e10cSrcweir 		if( nFormat == FORMAT_GDIMETAFILE && mpGraphic )
508*cdf0e10cSrcweir 			bOK = SetGDIMetaFile( mpGraphic->GetGDIMetaFile(), rFlavor );
509*cdf0e10cSrcweir 		else
510*cdf0e10cSrcweir 			bOK = SetAny( mpOLEDataHelper->GetAny( rFlavor ), rFlavor );
511*cdf0e10cSrcweir 
512*cdf0e10cSrcweir 		if( mpSdDrawDocumentIntern )
513*cdf0e10cSrcweir 			mpSdDrawDocumentIntern->SetSwapGraphicsMode( nOldSwapMode );
514*cdf0e10cSrcweir 	}
515*cdf0e10cSrcweir 	else if( HasFormat( nFormat ) )
516*cdf0e10cSrcweir 	{
517*cdf0e10cSrcweir 		if( ( nFormat == SOT_FORMATSTR_ID_LINKSRCDESCRIPTOR || nFormat == SOT_FORMATSTR_ID_OBJECTDESCRIPTOR ) && mpObjDesc )
518*cdf0e10cSrcweir 		{
519*cdf0e10cSrcweir 			bOK = SetTransferableObjectDescriptor( *mpObjDesc, rFlavor );
520*cdf0e10cSrcweir 		}
521*cdf0e10cSrcweir 		else if( nFormat == SOT_FORMATSTR_ID_DRAWING )
522*cdf0e10cSrcweir 		{
523*cdf0e10cSrcweir 			SfxObjectShellRef aOldRef( maDocShellRef );
524*cdf0e10cSrcweir 
525*cdf0e10cSrcweir 			maDocShellRef.Clear();
526*cdf0e10cSrcweir 
527*cdf0e10cSrcweir 			if( mpSdViewIntern )
528*cdf0e10cSrcweir 			{
529*cdf0e10cSrcweir 				SdDrawDocument* pInternDoc = mpSdViewIntern->GetDoc();
530*cdf0e10cSrcweir 				if( pInternDoc )
531*cdf0e10cSrcweir 					pInternDoc->CreatingDataObj(this);
532*cdf0e10cSrcweir 				SdDrawDocument* pDoc = dynamic_cast< SdDrawDocument* >( mpSdViewIntern->GetAllMarkedModel() );
533*cdf0e10cSrcweir 				if( pInternDoc )
534*cdf0e10cSrcweir 					pInternDoc->CreatingDataObj(0);
535*cdf0e10cSrcweir 
536*cdf0e10cSrcweir 				bOK = SetObject( pDoc, SDTRANSFER_OBJECTTYPE_DRAWMODEL, rFlavor );
537*cdf0e10cSrcweir 
538*cdf0e10cSrcweir 				if( maDocShellRef.Is() )
539*cdf0e10cSrcweir 				{
540*cdf0e10cSrcweir 					maDocShellRef->DoClose();
541*cdf0e10cSrcweir 				}
542*cdf0e10cSrcweir 				else
543*cdf0e10cSrcweir 				{
544*cdf0e10cSrcweir 					delete pDoc;
545*cdf0e10cSrcweir 				}
546*cdf0e10cSrcweir 			}
547*cdf0e10cSrcweir 
548*cdf0e10cSrcweir 			maDocShellRef = aOldRef;
549*cdf0e10cSrcweir 		}
550*cdf0e10cSrcweir 		else if( nFormat == FORMAT_GDIMETAFILE )
551*cdf0e10cSrcweir 		{
552*cdf0e10cSrcweir 			if( mpSdViewIntern )
553*cdf0e10cSrcweir 				bOK = SetGDIMetaFile( mpSdViewIntern->GetAllMarkedMetaFile( sal_True ), rFlavor );
554*cdf0e10cSrcweir 		}
555*cdf0e10cSrcweir 		else if( nFormat == FORMAT_BITMAP )
556*cdf0e10cSrcweir 		{
557*cdf0e10cSrcweir 			if( mpSdViewIntern )
558*cdf0e10cSrcweir 				bOK = SetBitmap( mpSdViewIntern->GetAllMarkedBitmap( sal_True ), rFlavor );
559*cdf0e10cSrcweir 		}
560*cdf0e10cSrcweir 		else if( ( nFormat == FORMAT_STRING ) && mpBookmark )
561*cdf0e10cSrcweir 		{
562*cdf0e10cSrcweir 			bOK = SetString( mpBookmark->GetURL(), rFlavor );
563*cdf0e10cSrcweir 		}
564*cdf0e10cSrcweir 		else if( ( nFormat == SOT_FORMATSTR_ID_SVXB ) && mpGraphic )
565*cdf0e10cSrcweir 		{
566*cdf0e10cSrcweir 			bOK = SetGraphic( *mpGraphic, rFlavor );
567*cdf0e10cSrcweir 		}
568*cdf0e10cSrcweir 		else if( ( nFormat == SOT_FORMATSTR_ID_SVIM ) && mpImageMap )
569*cdf0e10cSrcweir 		{
570*cdf0e10cSrcweir 			bOK = SetImageMap( *mpImageMap, rFlavor );
571*cdf0e10cSrcweir 		}
572*cdf0e10cSrcweir 		else if( mpBookmark )
573*cdf0e10cSrcweir 		{
574*cdf0e10cSrcweir 			bOK = SetINetBookmark( *mpBookmark, rFlavor );
575*cdf0e10cSrcweir 		}
576*cdf0e10cSrcweir 		else if( nFormat == SOT_FORMATSTR_ID_EMBED_SOURCE )
577*cdf0e10cSrcweir 		{
578*cdf0e10cSrcweir 			sal_uLong nOldSwapMode = 0;
579*cdf0e10cSrcweir 
580*cdf0e10cSrcweir 			if( mpSdDrawDocumentIntern )
581*cdf0e10cSrcweir 			{
582*cdf0e10cSrcweir 				nOldSwapMode = mpSdDrawDocumentIntern->GetSwapGraphicsMode();
583*cdf0e10cSrcweir 				mpSdDrawDocumentIntern->SetSwapGraphicsMode( SDR_SWAPGRAPHICSMODE_PURGE );
584*cdf0e10cSrcweir 			}
585*cdf0e10cSrcweir 
586*cdf0e10cSrcweir 			if( !maDocShellRef.Is() )
587*cdf0e10cSrcweir 			{
588*cdf0e10cSrcweir 				maDocShellRef = new ::sd::DrawDocShell(
589*cdf0e10cSrcweir                     mpSdDrawDocumentIntern,
590*cdf0e10cSrcweir                     SFX_CREATE_MODE_EMBEDDED,
591*cdf0e10cSrcweir                     sal_True,
592*cdf0e10cSrcweir                     mpSdDrawDocumentIntern->GetDocumentType());
593*cdf0e10cSrcweir 				mbOwnDocument = sal_False;
594*cdf0e10cSrcweir 				maDocShellRef->DoInitNew( NULL );
595*cdf0e10cSrcweir 			}
596*cdf0e10cSrcweir 
597*cdf0e10cSrcweir 			maDocShellRef->SetVisArea( maVisArea );
598*cdf0e10cSrcweir 			bOK = SetObject( &maDocShellRef, SDTRANSFER_OBJECTTYPE_DRAWOLE, rFlavor );
599*cdf0e10cSrcweir 
600*cdf0e10cSrcweir 			if( mpSdDrawDocumentIntern )
601*cdf0e10cSrcweir 				mpSdDrawDocumentIntern->SetSwapGraphicsMode( nOldSwapMode );
602*cdf0e10cSrcweir 		}
603*cdf0e10cSrcweir 	}
604*cdf0e10cSrcweir 
605*cdf0e10cSrcweir 	return bOK;
606*cdf0e10cSrcweir }
607*cdf0e10cSrcweir 
608*cdf0e10cSrcweir // -----------------------------------------------------------------------------
609*cdf0e10cSrcweir 
610*cdf0e10cSrcweir /* testcode
611*cdf0e10cSrcweir #include <sfx2/docfile.hxx>
612*cdf0e10cSrcweir */
613*cdf0e10cSrcweir 
614*cdf0e10cSrcweir sal_Bool SdTransferable::WriteObject( SotStorageStreamRef& rxOStm, void* pObject, sal_uInt32 nObjectType, const DataFlavor& )
615*cdf0e10cSrcweir {
616*cdf0e10cSrcweir 	sal_Bool bRet = sal_False;
617*cdf0e10cSrcweir 
618*cdf0e10cSrcweir 	switch( nObjectType )
619*cdf0e10cSrcweir 	{
620*cdf0e10cSrcweir 		case( SDTRANSFER_OBJECTTYPE_DRAWMODEL ):
621*cdf0e10cSrcweir 		{
622*cdf0e10cSrcweir 			try
623*cdf0e10cSrcweir 			{
624*cdf0e10cSrcweir 				static const sal_Bool bDontBurnInStyleSheet = ( getenv( "AVOID_BURN_IN_FOR_GALLERY_THEME" ) != NULL );
625*cdf0e10cSrcweir 				SdDrawDocument* pDoc = (SdDrawDocument*) pObject;
626*cdf0e10cSrcweir 				if ( !bDontBurnInStyleSheet )
627*cdf0e10cSrcweir 					pDoc->BurnInStyleSheetAttributes();
628*cdf0e10cSrcweir 				rxOStm->SetBufferSize( 16348 );
629*cdf0e10cSrcweir 
630*cdf0e10cSrcweir 				Reference< XComponent > xComponent( new SdXImpressDocument( pDoc, sal_True ) );
631*cdf0e10cSrcweir 				pDoc->setUnoModel( Reference< XInterface >::query( xComponent ) );
632*cdf0e10cSrcweir 
633*cdf0e10cSrcweir 				{
634*cdf0e10cSrcweir 					com::sun::star::uno::Reference<com::sun::star::io::XOutputStream> xDocOut( new utl::OOutputStreamWrapper( *rxOStm ) );
635*cdf0e10cSrcweir 					if( SvxDrawingLayerExport( pDoc, xDocOut, xComponent, (pDoc->GetDocumentType() == DOCUMENT_TYPE_IMPRESS) ? "com.sun.star.comp.Impress.XMLClipboardExporter" : "com.sun.star.comp.DrawingLayer.XMLExporter" ) )
636*cdf0e10cSrcweir 						rxOStm->Commit();
637*cdf0e10cSrcweir 				}
638*cdf0e10cSrcweir 
639*cdf0e10cSrcweir 	/* testcode
640*cdf0e10cSrcweir 				{
641*cdf0e10cSrcweir 					const rtl::OUString aURL( RTL_CONSTASCII_USTRINGPARAM( "file:///e:/test.xml" ) );
642*cdf0e10cSrcweir 					SfxMedium aMedium( aURL, STREAM_WRITE | STREAM_TRUNC, sal_True );
643*cdf0e10cSrcweir 					aMedium.IsRemote();
644*cdf0e10cSrcweir 					com::sun::star::uno::Reference<com::sun::star::io::XOutputStream> xDocOut( new utl::OOutputStreamWrapper( *aMedium.GetOutStream() ) );
645*cdf0e10cSrcweir 					if( SvxDrawingLayerExport( pDoc, xDocOut, xComponent, (pDoc->GetDocumentType() == DOCUMENT_TYPE_IMPRESS) ? "com.sun.star.comp.Impress.XMLClipboardExporter" : "com.sun.star.comp.DrawingLayer.XMLExporter" ) )
646*cdf0e10cSrcweir 						aMedium.Commit();
647*cdf0e10cSrcweir 				}
648*cdf0e10cSrcweir 	*/
649*cdf0e10cSrcweir 
650*cdf0e10cSrcweir 				xComponent->dispose();
651*cdf0e10cSrcweir 				bRet = ( rxOStm->GetError() == ERRCODE_NONE );
652*cdf0e10cSrcweir 			}
653*cdf0e10cSrcweir 			catch( Exception& )
654*cdf0e10cSrcweir 			{
655*cdf0e10cSrcweir 				DBG_ERROR( "sd::SdTransferable::WriteObject(), exception catched!" );
656*cdf0e10cSrcweir 				bRet = sal_False;
657*cdf0e10cSrcweir 			}
658*cdf0e10cSrcweir 		}
659*cdf0e10cSrcweir 		break;
660*cdf0e10cSrcweir 
661*cdf0e10cSrcweir 		case( SDTRANSFER_OBJECTTYPE_DRAWOLE ):
662*cdf0e10cSrcweir 		{
663*cdf0e10cSrcweir             SfxObjectShell*   pEmbObj = (SfxObjectShell*) pObject;
664*cdf0e10cSrcweir             ::utl::TempFile     aTempFile;
665*cdf0e10cSrcweir             aTempFile.EnableKillingFile();
666*cdf0e10cSrcweir 
667*cdf0e10cSrcweir             try
668*cdf0e10cSrcweir             {
669*cdf0e10cSrcweir                 uno::Reference< embed::XStorage > xWorkStore =
670*cdf0e10cSrcweir                     ::comphelper::OStorageHelper::GetStorageFromURL( aTempFile.GetURL(), embed::ElementModes::READWRITE );
671*cdf0e10cSrcweir 
672*cdf0e10cSrcweir                 // write document storage
673*cdf0e10cSrcweir                 pEmbObj->SetupStorage( xWorkStore, SOFFICE_FILEFORMAT_CURRENT, sal_False );
674*cdf0e10cSrcweir                 // mba: no relative ULRs for clipboard!
675*cdf0e10cSrcweir                 SfxMedium aMedium( xWorkStore, String() );
676*cdf0e10cSrcweir                 bRet = pEmbObj->DoSaveObjectAs( aMedium, sal_False );
677*cdf0e10cSrcweir                 pEmbObj->DoSaveCompleted();
678*cdf0e10cSrcweir 
679*cdf0e10cSrcweir                 uno::Reference< embed::XTransactedObject > xTransact( xWorkStore, uno::UNO_QUERY );
680*cdf0e10cSrcweir                 if ( xTransact.is() )
681*cdf0e10cSrcweir                     xTransact->commit();
682*cdf0e10cSrcweir 
683*cdf0e10cSrcweir                 SvStream* pSrcStm = ::utl::UcbStreamHelper::CreateStream( aTempFile.GetURL(), STREAM_READ );
684*cdf0e10cSrcweir                 if( pSrcStm )
685*cdf0e10cSrcweir                 {
686*cdf0e10cSrcweir                     rxOStm->SetBufferSize( 0xff00 );
687*cdf0e10cSrcweir                     *rxOStm << *pSrcStm;
688*cdf0e10cSrcweir                     delete pSrcStm;
689*cdf0e10cSrcweir                 }
690*cdf0e10cSrcweir 
691*cdf0e10cSrcweir                 bRet = sal_True;
692*cdf0e10cSrcweir                 rxOStm->Commit();
693*cdf0e10cSrcweir             }
694*cdf0e10cSrcweir             catch ( Exception& )
695*cdf0e10cSrcweir             {}
696*cdf0e10cSrcweir 		}
697*cdf0e10cSrcweir 
698*cdf0e10cSrcweir 		break;
699*cdf0e10cSrcweir 
700*cdf0e10cSrcweir 		default:
701*cdf0e10cSrcweir 		break;
702*cdf0e10cSrcweir 	}
703*cdf0e10cSrcweir 
704*cdf0e10cSrcweir 	return bRet;
705*cdf0e10cSrcweir }
706*cdf0e10cSrcweir 
707*cdf0e10cSrcweir // -----------------------------------------------------------------------------
708*cdf0e10cSrcweir 
709*cdf0e10cSrcweir void SdTransferable::DragFinished( sal_Int8 nDropAction )
710*cdf0e10cSrcweir {
711*cdf0e10cSrcweir 	if( mpSdView )
712*cdf0e10cSrcweir 		( (::sd::View*) mpSdView )->DragFinished( nDropAction );
713*cdf0e10cSrcweir }
714*cdf0e10cSrcweir 
715*cdf0e10cSrcweir // -----------------------------------------------------------------------------
716*cdf0e10cSrcweir 
717*cdf0e10cSrcweir void SdTransferable::ObjectReleased()
718*cdf0e10cSrcweir {
719*cdf0e10cSrcweir 	if( this == SD_MOD()->pTransferClip )
720*cdf0e10cSrcweir 		SD_MOD()->pTransferClip = NULL;
721*cdf0e10cSrcweir 
722*cdf0e10cSrcweir 	if( this == SD_MOD()->pTransferDrag )
723*cdf0e10cSrcweir 		SD_MOD()->pTransferDrag = NULL;
724*cdf0e10cSrcweir 
725*cdf0e10cSrcweir 	if( this == SD_MOD()->pTransferSelection )
726*cdf0e10cSrcweir 		SD_MOD()->pTransferSelection = NULL;
727*cdf0e10cSrcweir }
728*cdf0e10cSrcweir 
729*cdf0e10cSrcweir // -----------------------------------------------------------------------------
730*cdf0e10cSrcweir 
731*cdf0e10cSrcweir void SdTransferable::SetObjectDescriptor( const TransferableObjectDescriptor& rObjDesc )
732*cdf0e10cSrcweir {
733*cdf0e10cSrcweir 	delete mpObjDesc;
734*cdf0e10cSrcweir 	mpObjDesc = new TransferableObjectDescriptor( rObjDesc );
735*cdf0e10cSrcweir     PrepareOLE( rObjDesc );
736*cdf0e10cSrcweir }
737*cdf0e10cSrcweir 
738*cdf0e10cSrcweir // -----------------------------------------------------------------------------
739*cdf0e10cSrcweir 
740*cdf0e10cSrcweir void SdTransferable::SetPageBookmarks( const List& rPageBookmarks, sal_Bool bPersistent )
741*cdf0e10cSrcweir {
742*cdf0e10cSrcweir     if( mpSourceDoc )
743*cdf0e10cSrcweir     {
744*cdf0e10cSrcweir 	    if( mpSdViewIntern )
745*cdf0e10cSrcweir 		    mpSdViewIntern->HideSdrPage();
746*cdf0e10cSrcweir 
747*cdf0e10cSrcweir 		// #116168#
748*cdf0e10cSrcweir         mpSdDrawDocument->ClearModel(sal_False);
749*cdf0e10cSrcweir 
750*cdf0e10cSrcweir 		mpPageDocShell = NULL;
751*cdf0e10cSrcweir 
752*cdf0e10cSrcweir         for( void* p = maPageBookmarks.First(); p; p = maPageBookmarks.Next() )
753*cdf0e10cSrcweir             delete static_cast< String* >( p );
754*cdf0e10cSrcweir 
755*cdf0e10cSrcweir         if( bPersistent )
756*cdf0e10cSrcweir         {
757*cdf0e10cSrcweir             mpSdDrawDocument->CreateFirstPages(mpSourceDoc);
758*cdf0e10cSrcweir             mpSdDrawDocument->InsertBookmarkAsPage( const_cast< List* >( &rPageBookmarks ), NULL, sal_False, sal_True, 1, sal_True, mpSourceDoc->GetDocSh(), sal_True, sal_True, sal_False );
759*cdf0e10cSrcweir         }
760*cdf0e10cSrcweir         else
761*cdf0e10cSrcweir         {
762*cdf0e10cSrcweir             mpPageDocShell = mpSourceDoc->GetDocSh();
763*cdf0e10cSrcweir 
764*cdf0e10cSrcweir             for( sal_uLong i = 0; i < rPageBookmarks.Count(); i++ )
765*cdf0e10cSrcweir                 maPageBookmarks.Insert( new String( *static_cast< String* >( rPageBookmarks.GetObject( i ) ) ), LIST_APPEND );
766*cdf0e10cSrcweir         }
767*cdf0e10cSrcweir 
768*cdf0e10cSrcweir 	    if( mpSdViewIntern && mpSdDrawDocument )
769*cdf0e10cSrcweir 	    {
770*cdf0e10cSrcweir 		    SdPage* pPage = mpSdDrawDocument->GetSdPage( 0, PK_STANDARD );
771*cdf0e10cSrcweir 
772*cdf0e10cSrcweir 		    if( pPage )
773*cdf0e10cSrcweir             {
774*cdf0e10cSrcweir 			    ( (SdrMarkView*) mpSdViewIntern )->MarkAllObj( (SdrPageView*) mpSdViewIntern->ShowSdrPage( pPage ) );
775*cdf0e10cSrcweir             }
776*cdf0e10cSrcweir 	    }
777*cdf0e10cSrcweir 
778*cdf0e10cSrcweir         // set flags for page transferable; if ( mbPageTransferablePersistent == sal_False ),
779*cdf0e10cSrcweir         // don't offer any formats => it's just for internal puposes
780*cdf0e10cSrcweir         mbPageTransferable = sal_True;
781*cdf0e10cSrcweir         mbPageTransferablePersistent = bPersistent;
782*cdf0e10cSrcweir     }
783*cdf0e10cSrcweir }
784*cdf0e10cSrcweir 
785*cdf0e10cSrcweir // -----------------------------------------------------------------------------
786*cdf0e10cSrcweir 
787*cdf0e10cSrcweir sal_Int64 SAL_CALL SdTransferable::getSomething( const ::com::sun::star::uno::Sequence< sal_Int8 >& rId ) throw( ::com::sun::star::uno::RuntimeException )
788*cdf0e10cSrcweir {
789*cdf0e10cSrcweir     sal_Int64 nRet;
790*cdf0e10cSrcweir 
791*cdf0e10cSrcweir     if( ( rId.getLength() == 16 ) &&
792*cdf0e10cSrcweir         ( 0 == rtl_compareMemory( getUnoTunnelId().getConstArray(), rId.getConstArray(), 16 ) ) )
793*cdf0e10cSrcweir     {
794*cdf0e10cSrcweir 		nRet = sal::static_int_cast<sal_Int64>(reinterpret_cast<sal_IntPtr>(this));
795*cdf0e10cSrcweir     }
796*cdf0e10cSrcweir     else
797*cdf0e10cSrcweir 	{
798*cdf0e10cSrcweir         nRet = 0;
799*cdf0e10cSrcweir 	}
800*cdf0e10cSrcweir 
801*cdf0e10cSrcweir 	return nRet;
802*cdf0e10cSrcweir }
803*cdf0e10cSrcweir 
804*cdf0e10cSrcweir 
805*cdf0e10cSrcweir 
806*cdf0e10cSrcweir 
807*cdf0e10cSrcweir SdDrawDocument* SdTransferable::GetSourceDoc (void) const
808*cdf0e10cSrcweir {
809*cdf0e10cSrcweir     return mpSourceDoc;
810*cdf0e10cSrcweir }
811*cdf0e10cSrcweir 
812*cdf0e10cSrcweir 
813*cdf0e10cSrcweir 
814*cdf0e10cSrcweir 
815*cdf0e10cSrcweir void SdTransferable::AddUserData (const ::boost::shared_ptr<UserData>& rpData)
816*cdf0e10cSrcweir {
817*cdf0e10cSrcweir     maUserData.push_back(rpData);
818*cdf0e10cSrcweir }
819*cdf0e10cSrcweir 
820*cdf0e10cSrcweir 
821*cdf0e10cSrcweir 
822*cdf0e10cSrcweir 
823*cdf0e10cSrcweir void SdTransferable::RemoveUserData (const ::boost::shared_ptr<UserData>& rpData)
824*cdf0e10cSrcweir {
825*cdf0e10cSrcweir     maUserData.erase(::std::find(maUserData.begin(), maUserData.end(), rpData));
826*cdf0e10cSrcweir }
827*cdf0e10cSrcweir 
828*cdf0e10cSrcweir 
829*cdf0e10cSrcweir 
830*cdf0e10cSrcweir 
831*cdf0e10cSrcweir sal_Int32 SdTransferable::GetUserDataCount (void) const
832*cdf0e10cSrcweir {
833*cdf0e10cSrcweir     return maUserData.size();
834*cdf0e10cSrcweir }
835*cdf0e10cSrcweir 
836*cdf0e10cSrcweir 
837*cdf0e10cSrcweir 
838*cdf0e10cSrcweir 
839*cdf0e10cSrcweir ::boost::shared_ptr<SdTransferable::UserData> SdTransferable::GetUserData (const sal_Int32 nIndex) const
840*cdf0e10cSrcweir {
841*cdf0e10cSrcweir     if (nIndex>=0 && nIndex<sal_Int32(maUserData.size()))
842*cdf0e10cSrcweir         return maUserData[nIndex];
843*cdf0e10cSrcweir     else
844*cdf0e10cSrcweir         return ::boost::shared_ptr<UserData>();
845*cdf0e10cSrcweir }
846*cdf0e10cSrcweir 
847*cdf0e10cSrcweir 
848*cdf0e10cSrcweir 
849*cdf0e10cSrcweir 
850*cdf0e10cSrcweir // -----------------------------------------------------------------------------
851*cdf0e10cSrcweir 
852*cdf0e10cSrcweir const ::com::sun::star::uno::Sequence< sal_Int8 >& SdTransferable::getUnoTunnelId()
853*cdf0e10cSrcweir {
854*cdf0e10cSrcweir     static ::com::sun::star::uno::Sequence< sal_Int8 > aSeq;
855*cdf0e10cSrcweir 
856*cdf0e10cSrcweir 	if( !aSeq.getLength() )
857*cdf0e10cSrcweir 	{
858*cdf0e10cSrcweir 		static osl::Mutex   aCreateMutex;
859*cdf0e10cSrcweir     	osl::MutexGuard     aGuard( aCreateMutex );
860*cdf0e10cSrcweir 
861*cdf0e10cSrcweir 		aSeq.realloc( 16 );
862*cdf0e10cSrcweir     	rtl_createUuid( reinterpret_cast< sal_uInt8* >( aSeq.getArray() ), 0, sal_True );
863*cdf0e10cSrcweir 	}
864*cdf0e10cSrcweir 
865*cdf0e10cSrcweir     return aSeq;
866*cdf0e10cSrcweir }
867*cdf0e10cSrcweir 
868*cdf0e10cSrcweir // -----------------------------------------------------------------------------
869*cdf0e10cSrcweir 
870*cdf0e10cSrcweir SdTransferable* SdTransferable::getImplementation( const Reference< XInterface >& rxData ) throw()
871*cdf0e10cSrcweir {
872*cdf0e10cSrcweir     try
873*cdf0e10cSrcweir     {
874*cdf0e10cSrcweir 		Reference< ::com::sun::star::lang::XUnoTunnel > xUnoTunnel( rxData, UNO_QUERY_THROW );
875*cdf0e10cSrcweir 		return reinterpret_cast<SdTransferable*>(sal::static_int_cast<sal_uIntPtr>(xUnoTunnel->getSomething( SdTransferable::getUnoTunnelId()) ) );
876*cdf0e10cSrcweir     }
877*cdf0e10cSrcweir     catch( const ::com::sun::star::uno::Exception& )
878*cdf0e10cSrcweir 	{
879*cdf0e10cSrcweir 	}
880*cdf0e10cSrcweir 	return NULL;
881*cdf0e10cSrcweir }
882*cdf0e10cSrcweir 
883*cdf0e10cSrcweir // -----------------------------------------------------------------------------
884*cdf0e10cSrcweir 
885*cdf0e10cSrcweir // SfxListener
886*cdf0e10cSrcweir void SdTransferable::Notify( SfxBroadcaster& rBC, const SfxHint& rHint )
887*cdf0e10cSrcweir {
888*cdf0e10cSrcweir 	const SdrHint* pSdrHint = dynamic_cast< const SdrHint* >( &rHint );
889*cdf0e10cSrcweir 	if( pSdrHint )
890*cdf0e10cSrcweir 	{
891*cdf0e10cSrcweir 		if( HINT_MODELCLEARED == pSdrHint->GetKind() )
892*cdf0e10cSrcweir 		{
893*cdf0e10cSrcweir 			EndListening(*mpSourceDoc);
894*cdf0e10cSrcweir 			mpSourceDoc = 0;
895*cdf0e10cSrcweir 		}
896*cdf0e10cSrcweir 	}
897*cdf0e10cSrcweir 	else
898*cdf0e10cSrcweir 	{
899*cdf0e10cSrcweir 		const SfxSimpleHint* pSimpleHint = dynamic_cast< const SfxSimpleHint * >(&rHint);
900*cdf0e10cSrcweir 		if(pSimpleHint && (pSimpleHint->GetId() == SFX_HINT_DYING) )
901*cdf0e10cSrcweir 		{
902*cdf0e10cSrcweir 			if( &rBC == mpSourceDoc )
903*cdf0e10cSrcweir 				mpSourceDoc = 0;
904*cdf0e10cSrcweir 			if( &rBC == mpSdViewIntern )
905*cdf0e10cSrcweir 				mpSdViewIntern = 0;
906*cdf0e10cSrcweir 			if( &rBC == mpSdView )
907*cdf0e10cSrcweir 				mpSdView = 0;
908*cdf0e10cSrcweir 		}
909*cdf0e10cSrcweir 	}
910*cdf0e10cSrcweir }
911*cdf0e10cSrcweir 
912*cdf0e10cSrcweir sal_Bool SdTransferable::SetTableRTF( SdDrawDocument* pModel, const DataFlavor& rFlavor)
913*cdf0e10cSrcweir {
914*cdf0e10cSrcweir     if ( pModel )
915*cdf0e10cSrcweir     {
916*cdf0e10cSrcweir         SdrPage* pPage = pModel->GetPage(0);
917*cdf0e10cSrcweir         if (pPage && pPage->GetObjCount() == 1 )
918*cdf0e10cSrcweir         {
919*cdf0e10cSrcweir 			sdr::table::SdrTableObj* pTableObj = dynamic_cast< sdr::table::SdrTableObj* >( pPage->GetObj(0) );
920*cdf0e10cSrcweir 			if( pTableObj )
921*cdf0e10cSrcweir 			{
922*cdf0e10cSrcweir 				SvMemoryStream aMemStm( 65535, 65535 );
923*cdf0e10cSrcweir 				sdr::table::SdrTableObj::ExportAsRTF( aMemStm, *pTableObj );
924*cdf0e10cSrcweir 				return SetAny( Any( Sequence< sal_Int8 >( reinterpret_cast< const sal_Int8* >( aMemStm.GetData() ), aMemStm.Seek( STREAM_SEEK_TO_END ) ) ), rFlavor );
925*cdf0e10cSrcweir 			}
926*cdf0e10cSrcweir 		}
927*cdf0e10cSrcweir 	}
928*cdf0e10cSrcweir 
929*cdf0e10cSrcweir 	return sal_False;
930*cdf0e10cSrcweir }
931