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