xref: /trunk/main/sd/source/ui/app/sdxfer.cxx (revision a206ee71)
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_FORMATSTR_ID_PNG );
444 			    AddFormat( SOT_FORMAT_BITMAP );
445 			    AddFormat( SOT_FORMAT_GDIMETAFILE );
446 		    }
447 		    else
448 		    {
449 			    AddFormat( SOT_FORMAT_GDIMETAFILE );
450 			    AddFormat( SOT_FORMATSTR_ID_PNG );
451 			    AddFormat( SOT_FORMAT_BITMAP );
452 		    }
453 	    }
454 	    else if( mpBookmark )
455 	    {
456 		    AddFormat( SOT_FORMATSTR_ID_NETSCAPE_BOOKMARK );
457 		    AddFormat( FORMAT_STRING );
458 	    }
459 	    else
460 	    {
461 		    AddFormat( SOT_FORMATSTR_ID_EMBED_SOURCE );
462 		    AddFormat( SOT_FORMATSTR_ID_DRAWING );
463 			if( !mpSdDrawDocument || !lcl_HasOnlyControls( mpSdDrawDocument ) )
464 			{
465 				AddFormat( SOT_FORMAT_GDIMETAFILE );
466 				AddFormat( SOT_FORMATSTR_ID_PNG );
467 				AddFormat( SOT_FORMAT_BITMAP );
468 			}
469 
470 			if( lcl_HasOnlyOneTable( mpSdDrawDocument ) )
471 				AddFormat( SOT_FORMAT_RTF );
472 	    }
473 
474 	    if( mpImageMap )
475 		    AddFormat( SOT_FORMATSTR_ID_SVIM );
476     }
477 }
478 
479 // -----------------------------------------------------------------------------
480 
481 sal_Bool SdTransferable::GetData( const DataFlavor& rFlavor )
482 {
483 	if (SD_MOD()==NULL)
484 		return sal_False;
485 
486 	sal_uInt32	nFormat = SotExchange::GetFormat( rFlavor );
487 	sal_Bool	bOK = sal_False;
488 
489     CreateData();
490 
491 	if( nFormat == SOT_FORMAT_RTF && lcl_HasOnlyOneTable( mpSdDrawDocument ) )
492 	{
493 		bOK = SetTableRTF( mpSdDrawDocument, rFlavor );
494 	}
495 	else if( mpOLEDataHelper && mpOLEDataHelper->HasFormat( rFlavor ) )
496 	{
497 		sal_uLong nOldSwapMode = 0;
498 
499 		if( mpSdDrawDocumentIntern )
500 		{
501 			nOldSwapMode = mpSdDrawDocumentIntern->GetSwapGraphicsMode();
502 			mpSdDrawDocumentIntern->SetSwapGraphicsMode( SDR_SWAPGRAPHICSMODE_PURGE );
503 		}
504 
505 		// TODO/LATER: support all the graphical formats, the embedded object scenario should not have separated handling
506 		if( nFormat == FORMAT_GDIMETAFILE && mpGraphic )
507 			bOK = SetGDIMetaFile( mpGraphic->GetGDIMetaFile(), rFlavor );
508 		else
509 			bOK = SetAny( mpOLEDataHelper->GetAny( rFlavor ), rFlavor );
510 
511 		if( mpSdDrawDocumentIntern )
512 			mpSdDrawDocumentIntern->SetSwapGraphicsMode( nOldSwapMode );
513 	}
514 	else if( HasFormat( nFormat ) )
515 	{
516 		if( ( nFormat == SOT_FORMATSTR_ID_LINKSRCDESCRIPTOR || nFormat == SOT_FORMATSTR_ID_OBJECTDESCRIPTOR ) && mpObjDesc )
517 		{
518 			bOK = SetTransferableObjectDescriptor( *mpObjDesc, rFlavor );
519 		}
520 		else if( nFormat == SOT_FORMATSTR_ID_DRAWING )
521 		{
522 			SfxObjectShellRef aOldRef( maDocShellRef );
523 
524 			maDocShellRef.Clear();
525 
526 			if( mpSdViewIntern )
527 			{
528 				SdDrawDocument* pInternDoc = mpSdViewIntern->GetDoc();
529 				if( pInternDoc )
530 					pInternDoc->CreatingDataObj(this);
531 				SdDrawDocument* pDoc = dynamic_cast< SdDrawDocument* >( mpSdViewIntern->GetAllMarkedModel() );
532 				if( pInternDoc )
533 					pInternDoc->CreatingDataObj(0);
534 
535 				bOK = SetObject( pDoc, SDTRANSFER_OBJECTTYPE_DRAWMODEL, rFlavor );
536 
537 				if( maDocShellRef.Is() )
538 				{
539 					maDocShellRef->DoClose();
540 				}
541 				else
542 				{
543 					delete pDoc;
544 				}
545 			}
546 
547 			maDocShellRef = aOldRef;
548 		}
549 		else if( nFormat == FORMAT_GDIMETAFILE )
550 		{
551 			if( mpSdViewIntern )
552 				bOK = SetGDIMetaFile( mpSdViewIntern->GetMarkedObjMetaFile(true), rFlavor );
553 		}
554 		else if( FORMAT_BITMAP == nFormat || SOT_FORMATSTR_ID_PNG == nFormat )
555 		{
556 			if( mpSdViewIntern )
557 				bOK = SetBitmapEx( mpSdViewIntern->GetMarkedObjBitmapEx(true), rFlavor );
558 		}
559 		else if( ( nFormat == FORMAT_STRING ) && mpBookmark )
560 		{
561 			bOK = SetString( mpBookmark->GetURL(), rFlavor );
562 		}
563 		else if( ( nFormat == SOT_FORMATSTR_ID_SVXB ) && mpGraphic )
564 		{
565 			bOK = SetGraphic( *mpGraphic, rFlavor );
566 		}
567 		else if( ( nFormat == SOT_FORMATSTR_ID_SVIM ) && mpImageMap )
568 		{
569 			bOK = SetImageMap( *mpImageMap, rFlavor );
570 		}
571 		else if( mpBookmark )
572 		{
573 			bOK = SetINetBookmark( *mpBookmark, rFlavor );
574 		}
575 		else if( nFormat == SOT_FORMATSTR_ID_EMBED_SOURCE )
576 		{
577 			sal_uLong nOldSwapMode = 0;
578 
579 			if( mpSdDrawDocumentIntern )
580 			{
581 				nOldSwapMode = mpSdDrawDocumentIntern->GetSwapGraphicsMode();
582 				mpSdDrawDocumentIntern->SetSwapGraphicsMode( SDR_SWAPGRAPHICSMODE_PURGE );
583 			}
584 
585 			if( !maDocShellRef.Is() )
586 			{
587 				maDocShellRef = new ::sd::DrawDocShell(
588                     mpSdDrawDocumentIntern,
589                     SFX_CREATE_MODE_EMBEDDED,
590                     sal_True,
591                     mpSdDrawDocumentIntern->GetDocumentType());
592 				mbOwnDocument = sal_False;
593 				maDocShellRef->DoInitNew( NULL );
594 			}
595 
596 			maDocShellRef->SetVisArea( maVisArea );
597 			bOK = SetObject( &maDocShellRef, SDTRANSFER_OBJECTTYPE_DRAWOLE, rFlavor );
598 
599 			if( mpSdDrawDocumentIntern )
600 				mpSdDrawDocumentIntern->SetSwapGraphicsMode( nOldSwapMode );
601 		}
602 	}
603 
604 	return bOK;
605 }
606 
607 // -----------------------------------------------------------------------------
608 
609 /* testcode
610 #include <sfx2/docfile.hxx>
611 */
612 
613 sal_Bool SdTransferable::WriteObject( SotStorageStreamRef& rxOStm, void* pObject, sal_uInt32 nObjectType, const DataFlavor& )
614 {
615 	sal_Bool bRet = sal_False;
616 
617 	switch( nObjectType )
618 	{
619 		case( SDTRANSFER_OBJECTTYPE_DRAWMODEL ):
620 		{
621 			try
622 			{
623 				static const sal_Bool bDontBurnInStyleSheet = ( getenv( "AVOID_BURN_IN_FOR_GALLERY_THEME" ) != NULL );
624 				SdDrawDocument* pDoc = (SdDrawDocument*) pObject;
625 				if ( !bDontBurnInStyleSheet )
626 					pDoc->BurnInStyleSheetAttributes();
627 				rxOStm->SetBufferSize( 16348 );
628 
629 				Reference< XComponent > xComponent( new SdXImpressDocument( pDoc, sal_True ) );
630 				pDoc->setUnoModel( Reference< XInterface >::query( xComponent ) );
631 
632 				{
633 					com::sun::star::uno::Reference<com::sun::star::io::XOutputStream> xDocOut( new utl::OOutputStreamWrapper( *rxOStm ) );
634 					if( SvxDrawingLayerExport( pDoc, xDocOut, xComponent, (pDoc->GetDocumentType() == DOCUMENT_TYPE_IMPRESS) ? "com.sun.star.comp.Impress.XMLClipboardExporter" : "com.sun.star.comp.DrawingLayer.XMLExporter" ) )
635 						rxOStm->Commit();
636 				}
637 
638 	/* testcode
639 				{
640 					const rtl::OUString aURL( RTL_CONSTASCII_USTRINGPARAM( "file:///e:/test.xml" ) );
641 					SfxMedium aMedium( aURL, STREAM_WRITE | STREAM_TRUNC, sal_True );
642 					aMedium.IsRemote();
643 					com::sun::star::uno::Reference<com::sun::star::io::XOutputStream> xDocOut( new utl::OOutputStreamWrapper( *aMedium.GetOutStream() ) );
644 					if( SvxDrawingLayerExport( pDoc, xDocOut, xComponent, (pDoc->GetDocumentType() == DOCUMENT_TYPE_IMPRESS) ? "com.sun.star.comp.Impress.XMLClipboardExporter" : "com.sun.star.comp.DrawingLayer.XMLExporter" ) )
645 						aMedium.Commit();
646 				}
647 	*/
648 
649 				xComponent->dispose();
650 				bRet = ( rxOStm->GetError() == ERRCODE_NONE );
651 			}
652 			catch( Exception& )
653 			{
654 				DBG_ERROR( "sd::SdTransferable::WriteObject(), exception catched!" );
655 				bRet = sal_False;
656 			}
657 		}
658 		break;
659 
660 		case( SDTRANSFER_OBJECTTYPE_DRAWOLE ):
661 		{
662             SfxObjectShell*   pEmbObj = (SfxObjectShell*) pObject;
663             ::utl::TempFile     aTempFile;
664             aTempFile.EnableKillingFile();
665 
666             try
667             {
668                 uno::Reference< embed::XStorage > xWorkStore =
669                     ::comphelper::OStorageHelper::GetStorageFromURL( aTempFile.GetURL(), embed::ElementModes::READWRITE );
670 
671                 // write document storage
672                 pEmbObj->SetupStorage( xWorkStore, SOFFICE_FILEFORMAT_CURRENT, sal_False );
673                 // mba: no relative ULRs for clipboard!
674                 SfxMedium aMedium( xWorkStore, String() );
675                 bRet = pEmbObj->DoSaveObjectAs( aMedium, sal_False );
676                 pEmbObj->DoSaveCompleted();
677 
678                 uno::Reference< embed::XTransactedObject > xTransact( xWorkStore, uno::UNO_QUERY );
679                 if ( xTransact.is() )
680                     xTransact->commit();
681 
682                 SvStream* pSrcStm = ::utl::UcbStreamHelper::CreateStream( aTempFile.GetURL(), STREAM_READ );
683                 if( pSrcStm )
684                 {
685                     rxOStm->SetBufferSize( 0xff00 );
686                     *rxOStm << *pSrcStm;
687                     delete pSrcStm;
688                 }
689 
690                 bRet = sal_True;
691                 rxOStm->Commit();
692             }
693             catch ( Exception& )
694             {}
695 		}
696 
697 		break;
698 
699 		default:
700 		break;
701 	}
702 
703 	return bRet;
704 }
705 
706 // -----------------------------------------------------------------------------
707 
708 void SdTransferable::DragFinished( sal_Int8 nDropAction )
709 {
710 	if( mpSdView )
711 		( (::sd::View*) mpSdView )->DragFinished( nDropAction );
712 }
713 
714 // -----------------------------------------------------------------------------
715 
716 void SdTransferable::ObjectReleased()
717 {
718 	if( this == SD_MOD()->pTransferClip )
719 		SD_MOD()->pTransferClip = NULL;
720 
721 	if( this == SD_MOD()->pTransferDrag )
722 		SD_MOD()->pTransferDrag = NULL;
723 
724 	if( this == SD_MOD()->pTransferSelection )
725 		SD_MOD()->pTransferSelection = NULL;
726 }
727 
728 // -----------------------------------------------------------------------------
729 
730 void SdTransferable::SetObjectDescriptor( const TransferableObjectDescriptor& rObjDesc )
731 {
732 	delete mpObjDesc;
733 	mpObjDesc = new TransferableObjectDescriptor( rObjDesc );
734     PrepareOLE( rObjDesc );
735 }
736 
737 // -----------------------------------------------------------------------------
738 
739 void SdTransferable::SetPageBookmarks( const List& rPageBookmarks, sal_Bool bPersistent )
740 {
741     if( mpSourceDoc )
742     {
743 	    if( mpSdViewIntern )
744 		    mpSdViewIntern->HideSdrPage();
745 
746 		// #116168#
747         mpSdDrawDocument->ClearModel(sal_False);
748 
749 		mpPageDocShell = NULL;
750 
751         for( void* p = maPageBookmarks.First(); p; p = maPageBookmarks.Next() )
752             delete static_cast< String* >( p );
753 
754         if( bPersistent )
755         {
756             mpSdDrawDocument->CreateFirstPages(mpSourceDoc);
757             mpSdDrawDocument->InsertBookmarkAsPage( const_cast< List* >( &rPageBookmarks ), NULL, sal_False, sal_True, 1, sal_True, mpSourceDoc->GetDocSh(), sal_True, sal_True, sal_False );
758         }
759         else
760         {
761             mpPageDocShell = mpSourceDoc->GetDocSh();
762 
763             for( sal_uLong i = 0; i < rPageBookmarks.Count(); i++ )
764                 maPageBookmarks.Insert( new String( *static_cast< String* >( rPageBookmarks.GetObject( i ) ) ), LIST_APPEND );
765         }
766 
767 	    if( mpSdViewIntern && mpSdDrawDocument )
768 	    {
769 		    SdPage* pPage = mpSdDrawDocument->GetSdPage( 0, PK_STANDARD );
770 
771 		    if( pPage )
772             {
773 			    ( (SdrMarkView*) mpSdViewIntern )->MarkAllObj( (SdrPageView*) mpSdViewIntern->ShowSdrPage( pPage ) );
774             }
775 	    }
776 
777         // set flags for page transferable; if ( mbPageTransferablePersistent == sal_False ),
778         // don't offer any formats => it's just for internal puposes
779         mbPageTransferable = sal_True;
780         mbPageTransferablePersistent = bPersistent;
781     }
782 }
783 
784 // -----------------------------------------------------------------------------
785 
786 sal_Int64 SAL_CALL SdTransferable::getSomething( const ::com::sun::star::uno::Sequence< sal_Int8 >& rId ) throw( ::com::sun::star::uno::RuntimeException )
787 {
788     sal_Int64 nRet;
789 
790     if( ( rId.getLength() == 16 ) &&
791         ( 0 == rtl_compareMemory( getUnoTunnelId().getConstArray(), rId.getConstArray(), 16 ) ) )
792     {
793 		nRet = sal::static_int_cast<sal_Int64>(reinterpret_cast<sal_IntPtr>(this));
794     }
795     else
796 	{
797         nRet = 0;
798 	}
799 
800 	return nRet;
801 }
802 
803 
804 
805 
806 SdDrawDocument* SdTransferable::GetSourceDoc (void) const
807 {
808     return mpSourceDoc;
809 }
810 
811 
812 
813 
814 void SdTransferable::AddUserData (const ::boost::shared_ptr<UserData>& rpData)
815 {
816     maUserData.push_back(rpData);
817 }
818 
819 
820 
821 
822 void SdTransferable::RemoveUserData (const ::boost::shared_ptr<UserData>& rpData)
823 {
824     maUserData.erase(::std::find(maUserData.begin(), maUserData.end(), rpData));
825 }
826 
827 
828 
829 
830 sal_Int32 SdTransferable::GetUserDataCount (void) const
831 {
832     return maUserData.size();
833 }
834 
835 
836 
837 
838 ::boost::shared_ptr<SdTransferable::UserData> SdTransferable::GetUserData (const sal_Int32 nIndex) const
839 {
840     if (nIndex>=0 && nIndex<sal_Int32(maUserData.size()))
841         return maUserData[nIndex];
842     else
843         return ::boost::shared_ptr<UserData>();
844 }
845 
846 
847 
848 
849 // -----------------------------------------------------------------------------
850 
851 const ::com::sun::star::uno::Sequence< sal_Int8 >& SdTransferable::getUnoTunnelId()
852 {
853     static ::com::sun::star::uno::Sequence< sal_Int8 > aSeq;
854 
855 	if( !aSeq.getLength() )
856 	{
857 		static osl::Mutex   aCreateMutex;
858     	osl::MutexGuard     aGuard( aCreateMutex );
859 
860 		aSeq.realloc( 16 );
861     	rtl_createUuid( reinterpret_cast< sal_uInt8* >( aSeq.getArray() ), 0, sal_True );
862 	}
863 
864     return aSeq;
865 }
866 
867 // -----------------------------------------------------------------------------
868 
869 SdTransferable* SdTransferable::getImplementation( const Reference< XInterface >& rxData ) throw()
870 {
871     try
872     {
873 		Reference< ::com::sun::star::lang::XUnoTunnel > xUnoTunnel( rxData, UNO_QUERY_THROW );
874 		return reinterpret_cast<SdTransferable*>(sal::static_int_cast<sal_uIntPtr>(xUnoTunnel->getSomething( SdTransferable::getUnoTunnelId()) ) );
875     }
876     catch( const ::com::sun::star::uno::Exception& )
877 	{
878 	}
879 	return NULL;
880 }
881 
882 // -----------------------------------------------------------------------------
883 
884 // SfxListener
885 void SdTransferable::Notify( SfxBroadcaster& rBC, const SfxHint& rHint )
886 {
887 	const SdrHint* pSdrHint = dynamic_cast< const SdrHint* >( &rHint );
888 	if( pSdrHint )
889 	{
890 		if( HINT_MODELCLEARED == pSdrHint->GetKind() )
891 		{
892 			EndListening(*mpSourceDoc);
893 			mpSourceDoc = 0;
894 		}
895 	}
896 	else
897 	{
898 		const SfxSimpleHint* pSimpleHint = dynamic_cast< const SfxSimpleHint * >(&rHint);
899 		if(pSimpleHint && (pSimpleHint->GetId() == SFX_HINT_DYING) )
900 		{
901 			if( &rBC == mpSourceDoc )
902 				mpSourceDoc = 0;
903 			if( &rBC == mpSdViewIntern )
904 				mpSdViewIntern = 0;
905 			if( &rBC == mpSdView )
906 				mpSdView = 0;
907 		}
908 	}
909 }
910 
911 sal_Bool SdTransferable::SetTableRTF( SdDrawDocument* pModel, const DataFlavor& rFlavor)
912 {
913     if ( pModel )
914     {
915         SdrPage* pPage = pModel->GetPage(0);
916         if (pPage && pPage->GetObjCount() == 1 )
917         {
918 			sdr::table::SdrTableObj* pTableObj = dynamic_cast< sdr::table::SdrTableObj* >( pPage->GetObj(0) );
919 			if( pTableObj )
920 			{
921 				SvMemoryStream aMemStm( 65535, 65535 );
922 				sdr::table::SdrTableObj::ExportAsRTF( aMemStm, *pTableObj );
923 				return SetAny( Any( Sequence< sal_Int8 >( reinterpret_cast< const sal_Int8* >( aMemStm.GetData() ), aMemStm.Seek( STREAM_SEEK_TO_END ) ) ), rFlavor );
924 			}
925 		}
926 	}
927 
928 	return sal_False;
929 }
930