xref: /trunk/main/sd/source/ui/app/sdxfer.cxx (revision 728936de)
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                         // #63399# This special code identifies TextFrames which have just an URL
260                         // as content and directly add this to the clipboard, probably to avoid adding
261                         // an unnecessary DrawObject to the target where paste may take place. This is
262                         // wanted only for SdrObjects with no fill and no line, else it is necessary to
263                         // use the whole SdrObect. Test here for Line/FillStyle and take shortcut only
264                         // when both are unused
265                         if(!pObj->HasFillStyle() && !pObj->HasLineStyle())
266                         {
267                             mpBookmark = new INetBookmark( pURL->GetURL(), pURL->GetRepresentation() );
268                         }
269 					}
270 				}
271 			}
272 		}
273 
274 		SdIMapInfo*	pInfo = static_cast< SdDrawDocument* >( pObj->GetModel() )->GetIMapInfo( static_cast< SdrObject* >( pObj ) );
275 
276 		if( pInfo )
277 			mpImageMap = new ImageMap( pInfo->GetImageMap() );
278 
279 		mbIsUnoObj = pObj && pObj->IsUnoObj();
280 	}
281 }
282 
283 // -----------------------------------------------------------------------------
284 
285 void SdTransferable::CreateData()
286 {
287 	if( mpSdDrawDocument && !mpSdViewIntern )
288 	{
289 		mbOwnView = sal_True;
290 
291 		SdPage* pPage = mpSdDrawDocument->GetSdPage(0, PK_STANDARD);
292 
293 		if( 1 == pPage->GetObjCount() )
294 			CreateObjectReplacement( pPage->GetObj( 0 ) );
295 
296 		mpVDev = new VirtualDevice( *Application::GetDefaultDevice() );
297 		mpVDev->SetMapMode( MapMode( mpSdDrawDocumentIntern->GetScaleUnit(), Point(), mpSdDrawDocumentIntern->GetScaleFraction(), mpSdDrawDocumentIntern->GetScaleFraction() ) );
298 		mpSdViewIntern = new ::sd::View( mpSdDrawDocumentIntern, mpVDev );
299 		mpSdViewIntern->EndListening(*mpSdDrawDocumentIntern );
300 		mpSdViewIntern->hideMarkHandles();
301 		SdrPageView* pPageView = mpSdViewIntern->ShowSdrPage(pPage);
302 		((SdrMarkView*)mpSdViewIntern)->MarkAllObj(pPageView);
303 	}
304 	else if( mpSdView && !mpSdDrawDocumentIntern )
305 	{
306 		const SdrMarkList& rMarkList = mpSdView->GetMarkedObjectList();
307 
308 		if( rMarkList.GetMarkCount() == 1 )
309 			CreateObjectReplacement( rMarkList.GetMark( 0 )->GetMarkedSdrObj() );
310 
311 		if( mpSourceDoc )
312 			mpSourceDoc->CreatingDataObj(this);
313 		mpSdDrawDocumentIntern = (SdDrawDocument*) mpSdView->GetAllMarkedModel();
314 		if( mpSourceDoc )
315 			mpSourceDoc->CreatingDataObj(0);
316 
317 		if( !maDocShellRef.Is() && mpSdDrawDocumentIntern->GetDocSh() )
318 			maDocShellRef = mpSdDrawDocumentIntern->GetDocSh();
319 
320 		if( !maDocShellRef.Is() )
321 		{
322 			DBG_ERROR( "SdTransferable::CreateData(), failed to create a model with persist, clipboard operation will fail for OLE objects!" );
323 			mbOwnDocument = sal_True;
324 		}
325 
326 		// Groesse der Source-Seite uebernehmen
327 		SdrPageView*		pPgView = mpSdView->GetSdrPageView();
328 		SdPage*				pOldPage = (SdPage*) pPgView->GetPage();
329 		SdrModel*			pOldModel = mpSdView->GetModel();
330 		SdStyleSheetPool*	pOldStylePool = (SdStyleSheetPool*) pOldModel->GetStyleSheetPool();
331 		SdStyleSheetPool*	pNewStylePool = (SdStyleSheetPool*) mpSdDrawDocumentIntern->GetStyleSheetPool();
332 		SdPage*				pPage = mpSdDrawDocumentIntern->GetSdPage( 0, PK_STANDARD );
333 		String				aOldLayoutName( pOldPage->GetLayoutName() );
334 
335 		pPage->SetSize( pOldPage->GetSize() );
336 		pPage->SetLayoutName( aOldLayoutName );
337 		pNewStylePool->CopyGraphicSheets( *pOldStylePool );
338 		pNewStylePool->CopyCellSheets( *pOldStylePool );
339 		pNewStylePool->CopyTableStyles( *pOldStylePool );
340 		aOldLayoutName.Erase( aOldLayoutName.SearchAscii( SD_LT_SEPARATOR ) );
341 		SdStyleSheetVector aCreatedSheets;
342 		pNewStylePool->CopyLayoutSheets( aOldLayoutName, *pOldStylePool, aCreatedSheets );
343 	}
344 
345 	// set VisArea and adjust objects if neccessary
346 	if( maVisArea.IsEmpty() &&
347 		mpSdDrawDocumentIntern && mpSdViewIntern &&
348 		mpSdDrawDocumentIntern->GetPageCount() )
349 	{
350 		SdPage*	pPage = mpSdDrawDocumentIntern->GetSdPage( 0, PK_STANDARD );
351 
352 		if( 1 == mpSdDrawDocumentIntern->GetPageCount() )
353 		{
354 			// #112978# need to use GetAllMarkedBoundRect instead of GetAllMarkedRect to get
355 			// fat lines correctly
356 			Point	aOrigin( ( maVisArea = mpSdViewIntern->GetAllMarkedBoundRect() ).TopLeft() );
357 			Size	aVector( -aOrigin.X(), -aOrigin.Y() );
358 
359 			for( sal_uLong nObj = 0, nObjCount = pPage->GetObjCount(); nObj < nObjCount; nObj++ )
360 			{
361 				SdrObject* pObj = pPage->GetObj( nObj );
362 				pObj->NbcMove( aVector );
363 			}
364 		}
365 		else
366 			maVisArea.SetSize( pPage->GetSize() );
367 
368 		// Die Ausgabe soll am Nullpunkt erfolgen
369 		maVisArea.SetPos( Point() );
370 	}
371 }
372 
373 // -----------------------------------------------------------------------------
374 
375 sal_Bool lcl_HasOnlyControls( SdrModel* pModel )
376 {
377     sal_Bool bOnlyControls = sal_False;         // default if there are no objects
378 
379     if ( pModel )
380     {
381         SdrPage* pPage = pModel->GetPage(0);
382         if (pPage)
383         {
384             SdrObjListIter aIter( *pPage, IM_DEEPNOGROUPS );
385             SdrObject* pObj = aIter.Next();
386             if ( pObj )
387             {
388                 bOnlyControls = sal_True;   // only set if there are any objects at all
389                 while ( pObj )
390                 {
391                     if (!pObj->ISA(SdrUnoObj))
392                     {
393                         bOnlyControls = sal_False;
394                         break;
395                     }
396                     pObj = aIter.Next();
397                 }
398             }
399         }
400     }
401 
402     return bOnlyControls;
403 }
404 
405 // -----------------------------------------------------------------------------
406 
407 bool lcl_HasOnlyOneTable( SdrModel* pModel )
408 {
409     if ( pModel )
410     {
411         SdrPage* pPage = pModel->GetPage(0);
412         if (pPage && pPage->GetObjCount() == 1 )
413         {
414 			if( dynamic_cast< sdr::table::SdrTableObj* >( pPage->GetObj(0) ) != 0 )
415 				return true;
416 		}
417 	}
418 	return false;
419 }
420 
421 // -----------------------------------------------------------------------------
422 
423 void SdTransferable::AddSupportedFormats()
424 {
425     if( !mbPageTransferable || mbPageTransferablePersistent )
426     {
427         if( !mbLateInit )
428             CreateData();
429 
430 	    if( mpObjDesc )
431             AddFormat( SOT_FORMATSTR_ID_OBJECTDESCRIPTOR );
432 
433         if( mpOLEDataHelper )
434 	    {
435 		    AddFormat( SOT_FORMATSTR_ID_EMBED_SOURCE );
436 
437 		    DataFlavorExVector				aVector( mpOLEDataHelper->GetDataFlavorExVector() );
438 		    DataFlavorExVector::iterator	aIter( aVector.begin() ), aEnd( aVector.end() );
439 
440 		    while( aIter != aEnd )
441 			    AddFormat( *aIter++ );
442 	    }
443 	    else if( mpGraphic )
444 	    {
445 			// #i25616#
446 		    AddFormat( SOT_FORMATSTR_ID_DRAWING );
447 
448 			AddFormat( SOT_FORMATSTR_ID_SVXB );
449 
450 		    if( mpGraphic->GetType() == GRAPHIC_BITMAP )
451 		    {
452 			    AddFormat( SOT_FORMATSTR_ID_PNG );
453 			    AddFormat( SOT_FORMAT_BITMAP );
454 			    AddFormat( SOT_FORMAT_GDIMETAFILE );
455 		    }
456 		    else
457 		    {
458 			    AddFormat( SOT_FORMAT_GDIMETAFILE );
459 			    AddFormat( SOT_FORMATSTR_ID_PNG );
460 			    AddFormat( SOT_FORMAT_BITMAP );
461 		    }
462 	    }
463 	    else if( mpBookmark )
464 	    {
465 		    AddFormat( SOT_FORMATSTR_ID_NETSCAPE_BOOKMARK );
466 		    AddFormat( FORMAT_STRING );
467 	    }
468 	    else
469 	    {
470 		    AddFormat( SOT_FORMATSTR_ID_EMBED_SOURCE );
471 		    AddFormat( SOT_FORMATSTR_ID_DRAWING );
472 			if( !mpSdDrawDocument || !lcl_HasOnlyControls( mpSdDrawDocument ) )
473 			{
474 				AddFormat( SOT_FORMAT_GDIMETAFILE );
475 				AddFormat( SOT_FORMATSTR_ID_PNG );
476 				AddFormat( SOT_FORMAT_BITMAP );
477 			}
478 
479 			if( lcl_HasOnlyOneTable( mpSdDrawDocument ) )
480 				AddFormat( SOT_FORMAT_RTF );
481 	    }
482 
483 	    if( mpImageMap )
484 		    AddFormat( SOT_FORMATSTR_ID_SVIM );
485     }
486 }
487 
488 // -----------------------------------------------------------------------------
489 
490 sal_Bool SdTransferable::GetData( const DataFlavor& rFlavor )
491 {
492 	if (SD_MOD()==NULL)
493 		return sal_False;
494 
495 	sal_uInt32	nFormat = SotExchange::GetFormat( rFlavor );
496 	sal_Bool	bOK = sal_False;
497 
498     CreateData();
499 
500 	if( nFormat == SOT_FORMAT_RTF && lcl_HasOnlyOneTable( mpSdDrawDocument ) )
501 	{
502 		bOK = SetTableRTF( mpSdDrawDocument, rFlavor );
503 	}
504 	else if( mpOLEDataHelper && mpOLEDataHelper->HasFormat( rFlavor ) )
505 	{
506 		sal_uLong nOldSwapMode = 0;
507 
508 		if( mpSdDrawDocumentIntern )
509 		{
510 			nOldSwapMode = mpSdDrawDocumentIntern->GetSwapGraphicsMode();
511 			mpSdDrawDocumentIntern->SetSwapGraphicsMode( SDR_SWAPGRAPHICSMODE_PURGE );
512 		}
513 
514 		// TODO/LATER: support all the graphical formats, the embedded object scenario should not have separated handling
515 		if( nFormat == FORMAT_GDIMETAFILE && mpGraphic )
516 			bOK = SetGDIMetaFile( mpGraphic->GetGDIMetaFile(), rFlavor );
517 		else
518 			bOK = SetAny( mpOLEDataHelper->GetAny( rFlavor ), rFlavor );
519 
520 		if( mpSdDrawDocumentIntern )
521 			mpSdDrawDocumentIntern->SetSwapGraphicsMode( nOldSwapMode );
522 	}
523 	else if( HasFormat( nFormat ) )
524 	{
525 		if( ( nFormat == SOT_FORMATSTR_ID_LINKSRCDESCRIPTOR || nFormat == SOT_FORMATSTR_ID_OBJECTDESCRIPTOR ) && mpObjDesc )
526 		{
527 			bOK = SetTransferableObjectDescriptor( *mpObjDesc, rFlavor );
528 		}
529 		else if( nFormat == SOT_FORMATSTR_ID_DRAWING )
530 		{
531 			SfxObjectShellRef aOldRef( maDocShellRef );
532 
533 			maDocShellRef.Clear();
534 
535 			if( mpSdViewIntern )
536 			{
537 				SdDrawDocument* pInternDoc = mpSdViewIntern->GetDoc();
538 				if( pInternDoc )
539 					pInternDoc->CreatingDataObj(this);
540 				SdDrawDocument* pDoc = dynamic_cast< SdDrawDocument* >( mpSdViewIntern->GetAllMarkedModel() );
541 				if( pInternDoc )
542 					pInternDoc->CreatingDataObj(0);
543 
544 				bOK = SetObject( pDoc, SDTRANSFER_OBJECTTYPE_DRAWMODEL, rFlavor );
545 
546 				if( maDocShellRef.Is() )
547 				{
548 					maDocShellRef->DoClose();
549 				}
550 				else
551 				{
552 					delete pDoc;
553 				}
554 			}
555 
556 			maDocShellRef = aOldRef;
557 		}
558 		else if( nFormat == FORMAT_GDIMETAFILE )
559 		{
560 			if( mpSdViewIntern )
561 				bOK = SetGDIMetaFile( mpSdViewIntern->GetMarkedObjMetaFile(true), rFlavor );
562 		}
563 		else if( FORMAT_BITMAP == nFormat || SOT_FORMATSTR_ID_PNG == nFormat )
564 		{
565 			if( mpSdViewIntern )
566 				bOK = SetBitmapEx( mpSdViewIntern->GetMarkedObjBitmapEx(true), rFlavor );
567 		}
568 		else if( ( nFormat == FORMAT_STRING ) && mpBookmark )
569 		{
570 			bOK = SetString( mpBookmark->GetURL(), rFlavor );
571 		}
572 		else if( ( nFormat == SOT_FORMATSTR_ID_SVXB ) && mpGraphic )
573 		{
574 			bOK = SetGraphic( *mpGraphic, rFlavor );
575 		}
576 		else if( ( nFormat == SOT_FORMATSTR_ID_SVIM ) && mpImageMap )
577 		{
578 			bOK = SetImageMap( *mpImageMap, rFlavor );
579 		}
580 		else if( mpBookmark )
581 		{
582 			bOK = SetINetBookmark( *mpBookmark, rFlavor );
583 		}
584 		else if( nFormat == SOT_FORMATSTR_ID_EMBED_SOURCE )
585 		{
586 			sal_uLong nOldSwapMode = 0;
587 
588 			if( mpSdDrawDocumentIntern )
589 			{
590 				nOldSwapMode = mpSdDrawDocumentIntern->GetSwapGraphicsMode();
591 				mpSdDrawDocumentIntern->SetSwapGraphicsMode( SDR_SWAPGRAPHICSMODE_PURGE );
592 			}
593 
594 			if( !maDocShellRef.Is() )
595 			{
596 				maDocShellRef = new ::sd::DrawDocShell(
597                     mpSdDrawDocumentIntern,
598                     SFX_CREATE_MODE_EMBEDDED,
599                     sal_True,
600                     mpSdDrawDocumentIntern->GetDocumentType());
601 				mbOwnDocument = sal_False;
602 				maDocShellRef->DoInitNew( NULL );
603 			}
604 
605 			maDocShellRef->SetVisArea( maVisArea );
606 			bOK = SetObject( &maDocShellRef, SDTRANSFER_OBJECTTYPE_DRAWOLE, rFlavor );
607 
608 			if( mpSdDrawDocumentIntern )
609 				mpSdDrawDocumentIntern->SetSwapGraphicsMode( nOldSwapMode );
610 		}
611 	}
612 
613 	return bOK;
614 }
615 
616 // -----------------------------------------------------------------------------
617 
618 /* testcode
619 #include <sfx2/docfile.hxx>
620 */
621 
622 sal_Bool SdTransferable::WriteObject( SotStorageStreamRef& rxOStm, void* pObject, sal_uInt32 nObjectType, const DataFlavor& )
623 {
624 	sal_Bool bRet = sal_False;
625 
626 	switch( nObjectType )
627 	{
628 		case( SDTRANSFER_OBJECTTYPE_DRAWMODEL ):
629 		{
630 			try
631 			{
632 				static const sal_Bool bDontBurnInStyleSheet = ( getenv( "AVOID_BURN_IN_FOR_GALLERY_THEME" ) != NULL );
633 				SdDrawDocument* pDoc = (SdDrawDocument*) pObject;
634 				if ( !bDontBurnInStyleSheet )
635 					pDoc->BurnInStyleSheetAttributes();
636 				rxOStm->SetBufferSize( 16348 );
637 
638 				Reference< XComponent > xComponent( new SdXImpressDocument( pDoc, sal_True ) );
639 				pDoc->setUnoModel( Reference< XInterface >::query( xComponent ) );
640 
641 				{
642 					com::sun::star::uno::Reference<com::sun::star::io::XOutputStream> xDocOut( new utl::OOutputStreamWrapper( *rxOStm ) );
643 					if( SvxDrawingLayerExport( pDoc, xDocOut, xComponent, (pDoc->GetDocumentType() == DOCUMENT_TYPE_IMPRESS) ? "com.sun.star.comp.Impress.XMLClipboardExporter" : "com.sun.star.comp.DrawingLayer.XMLExporter" ) )
644 						rxOStm->Commit();
645 				}
646 
647 	/* testcode
648 				{
649 					const rtl::OUString aURL( RTL_CONSTASCII_USTRINGPARAM( "file:///e:/test.xml" ) );
650 					SfxMedium aMedium( aURL, STREAM_WRITE | STREAM_TRUNC, sal_True );
651 					aMedium.IsRemote();
652 					com::sun::star::uno::Reference<com::sun::star::io::XOutputStream> xDocOut( new utl::OOutputStreamWrapper( *aMedium.GetOutStream() ) );
653 					if( SvxDrawingLayerExport( pDoc, xDocOut, xComponent, (pDoc->GetDocumentType() == DOCUMENT_TYPE_IMPRESS) ? "com.sun.star.comp.Impress.XMLClipboardExporter" : "com.sun.star.comp.DrawingLayer.XMLExporter" ) )
654 						aMedium.Commit();
655 				}
656 	*/
657 
658 				xComponent->dispose();
659 				bRet = ( rxOStm->GetError() == ERRCODE_NONE );
660 			}
661 			catch( Exception& )
662 			{
663 				DBG_ERROR( "sd::SdTransferable::WriteObject(), exception catched!" );
664 				bRet = sal_False;
665 			}
666 		}
667 		break;
668 
669 		case( SDTRANSFER_OBJECTTYPE_DRAWOLE ):
670 		{
671             SfxObjectShell*   pEmbObj = (SfxObjectShell*) pObject;
672             ::utl::TempFile     aTempFile;
673             aTempFile.EnableKillingFile();
674 
675             try
676             {
677                 uno::Reference< embed::XStorage > xWorkStore =
678                     ::comphelper::OStorageHelper::GetStorageFromURL( aTempFile.GetURL(), embed::ElementModes::READWRITE );
679 
680                 // write document storage
681                 pEmbObj->SetupStorage( xWorkStore, SOFFICE_FILEFORMAT_CURRENT, sal_False );
682                 // mba: no relative ULRs for clipboard!
683                 SfxMedium aMedium( xWorkStore, String() );
684                 bRet = pEmbObj->DoSaveObjectAs( aMedium, sal_False );
685                 pEmbObj->DoSaveCompleted();
686 
687                 uno::Reference< embed::XTransactedObject > xTransact( xWorkStore, uno::UNO_QUERY );
688                 if ( xTransact.is() )
689                     xTransact->commit();
690 
691                 SvStream* pSrcStm = ::utl::UcbStreamHelper::CreateStream( aTempFile.GetURL(), STREAM_READ );
692                 if( pSrcStm )
693                 {
694                     rxOStm->SetBufferSize( 0xff00 );
695                     *rxOStm << *pSrcStm;
696                     delete pSrcStm;
697                 }
698 
699                 bRet = sal_True;
700                 rxOStm->Commit();
701             }
702             catch ( Exception& )
703             {}
704 		}
705 
706 		break;
707 
708 		default:
709 		break;
710 	}
711 
712 	return bRet;
713 }
714 
715 // -----------------------------------------------------------------------------
716 
717 void SdTransferable::DragFinished( sal_Int8 nDropAction )
718 {
719 	if( mpSdView )
720 		( (::sd::View*) mpSdView )->DragFinished( nDropAction );
721 }
722 
723 // -----------------------------------------------------------------------------
724 
725 void SdTransferable::ObjectReleased()
726 {
727 	if( this == SD_MOD()->pTransferClip )
728 		SD_MOD()->pTransferClip = NULL;
729 
730 	if( this == SD_MOD()->pTransferDrag )
731 		SD_MOD()->pTransferDrag = NULL;
732 
733 	if( this == SD_MOD()->pTransferSelection )
734 		SD_MOD()->pTransferSelection = NULL;
735 }
736 
737 // -----------------------------------------------------------------------------
738 
739 void SdTransferable::SetObjectDescriptor( const TransferableObjectDescriptor& rObjDesc )
740 {
741 	delete mpObjDesc;
742 	mpObjDesc = new TransferableObjectDescriptor( rObjDesc );
743     PrepareOLE( rObjDesc );
744 }
745 
746 // -----------------------------------------------------------------------------
747 
748 void SdTransferable::SetPageBookmarks( const List& rPageBookmarks, sal_Bool bPersistent )
749 {
750     if( mpSourceDoc )
751     {
752 	    if( mpSdViewIntern )
753 		    mpSdViewIntern->HideSdrPage();
754 
755 		// #116168#
756         mpSdDrawDocument->ClearModel(sal_False);
757 
758 		mpPageDocShell = NULL;
759 
760         for( void* p = maPageBookmarks.First(); p; p = maPageBookmarks.Next() )
761             delete static_cast< String* >( p );
762 
763         if( bPersistent )
764         {
765             mpSdDrawDocument->CreateFirstPages(mpSourceDoc);
766             mpSdDrawDocument->InsertBookmarkAsPage( const_cast< List* >( &rPageBookmarks ), NULL, sal_False, sal_True, 1, sal_True, mpSourceDoc->GetDocSh(), sal_True, sal_True, sal_False );
767         }
768         else
769         {
770             mpPageDocShell = mpSourceDoc->GetDocSh();
771 
772             for( sal_uLong i = 0; i < rPageBookmarks.Count(); i++ )
773                 maPageBookmarks.Insert( new String( *static_cast< String* >( rPageBookmarks.GetObject( i ) ) ), LIST_APPEND );
774         }
775 
776 	    if( mpSdViewIntern && mpSdDrawDocument )
777 	    {
778 		    SdPage* pPage = mpSdDrawDocument->GetSdPage( 0, PK_STANDARD );
779 
780 		    if( pPage )
781             {
782 			    ( (SdrMarkView*) mpSdViewIntern )->MarkAllObj( (SdrPageView*) mpSdViewIntern->ShowSdrPage( pPage ) );
783             }
784 	    }
785 
786         // set flags for page transferable; if ( mbPageTransferablePersistent == sal_False ),
787         // don't offer any formats => it's just for internal puposes
788         mbPageTransferable = sal_True;
789         mbPageTransferablePersistent = bPersistent;
790     }
791 }
792 
793 // -----------------------------------------------------------------------------
794 
795 sal_Int64 SAL_CALL SdTransferable::getSomething( const ::com::sun::star::uno::Sequence< sal_Int8 >& rId ) throw( ::com::sun::star::uno::RuntimeException )
796 {
797     sal_Int64 nRet;
798 
799     if( ( rId.getLength() == 16 ) &&
800         ( 0 == rtl_compareMemory( getUnoTunnelId().getConstArray(), rId.getConstArray(), 16 ) ) )
801     {
802 		nRet = sal::static_int_cast<sal_Int64>(reinterpret_cast<sal_IntPtr>(this));
803     }
804     else
805 	{
806         nRet = 0;
807 	}
808 
809 	return nRet;
810 }
811 
812 
813 
814 
815 SdDrawDocument* SdTransferable::GetSourceDoc (void) const
816 {
817     return mpSourceDoc;
818 }
819 
820 
821 
822 
823 void SdTransferable::AddUserData (const ::boost::shared_ptr<UserData>& rpData)
824 {
825     maUserData.push_back(rpData);
826 }
827 
828 
829 
830 
831 void SdTransferable::RemoveUserData (const ::boost::shared_ptr<UserData>& rpData)
832 {
833     maUserData.erase(::std::find(maUserData.begin(), maUserData.end(), rpData));
834 }
835 
836 
837 
838 
839 sal_Int32 SdTransferable::GetUserDataCount (void) const
840 {
841     return maUserData.size();
842 }
843 
844 
845 
846 
847 ::boost::shared_ptr<SdTransferable::UserData> SdTransferable::GetUserData (const sal_Int32 nIndex) const
848 {
849     if (nIndex>=0 && nIndex<sal_Int32(maUserData.size()))
850         return maUserData[nIndex];
851     else
852         return ::boost::shared_ptr<UserData>();
853 }
854 
855 
856 
857 
858 // -----------------------------------------------------------------------------
859 
860 const ::com::sun::star::uno::Sequence< sal_Int8 >& SdTransferable::getUnoTunnelId()
861 {
862     static ::com::sun::star::uno::Sequence< sal_Int8 > aSeq;
863 
864 	if( !aSeq.getLength() )
865 	{
866 		static osl::Mutex   aCreateMutex;
867     	osl::MutexGuard     aGuard( aCreateMutex );
868 
869 		aSeq.realloc( 16 );
870     	rtl_createUuid( reinterpret_cast< sal_uInt8* >( aSeq.getArray() ), 0, sal_True );
871 	}
872 
873     return aSeq;
874 }
875 
876 // -----------------------------------------------------------------------------
877 
878 SdTransferable* SdTransferable::getImplementation( const Reference< XInterface >& rxData ) throw()
879 {
880     try
881     {
882 		Reference< ::com::sun::star::lang::XUnoTunnel > xUnoTunnel( rxData, UNO_QUERY_THROW );
883 		return reinterpret_cast<SdTransferable*>(sal::static_int_cast<sal_uIntPtr>(xUnoTunnel->getSomething( SdTransferable::getUnoTunnelId()) ) );
884     }
885     catch( const ::com::sun::star::uno::Exception& )
886 	{
887 	}
888 	return NULL;
889 }
890 
891 // -----------------------------------------------------------------------------
892 
893 // SfxListener
894 void SdTransferable::Notify( SfxBroadcaster& rBC, const SfxHint& rHint )
895 {
896 	const SdrHint* pSdrHint = dynamic_cast< const SdrHint* >( &rHint );
897 	if( pSdrHint )
898 	{
899 		if( HINT_MODELCLEARED == pSdrHint->GetKind() )
900 		{
901 			EndListening(*mpSourceDoc);
902 			mpSourceDoc = 0;
903 		}
904 	}
905 	else
906 	{
907 		const SfxSimpleHint* pSimpleHint = dynamic_cast< const SfxSimpleHint * >(&rHint);
908 		if(pSimpleHint && (pSimpleHint->GetId() == SFX_HINT_DYING) )
909 		{
910 			if( &rBC == mpSourceDoc )
911 				mpSourceDoc = 0;
912 			if( &rBC == mpSdViewIntern )
913 				mpSdViewIntern = 0;
914 			if( &rBC == mpSdView )
915 				mpSdView = 0;
916 		}
917 	}
918 }
919 
920 sal_Bool SdTransferable::SetTableRTF( SdDrawDocument* pModel, const DataFlavor& rFlavor)
921 {
922     if ( pModel )
923     {
924         SdrPage* pPage = pModel->GetPage(0);
925         if (pPage && pPage->GetObjCount() == 1 )
926         {
927 			sdr::table::SdrTableObj* pTableObj = dynamic_cast< sdr::table::SdrTableObj* >( pPage->GetObj(0) );
928 			if( pTableObj )
929 			{
930 				SvMemoryStream aMemStm( 65535, 65535 );
931 				sdr::table::SdrTableObj::ExportAsRTF( aMemStm, *pTableObj );
932 				return SetAny( Any( Sequence< sal_Int8 >( reinterpret_cast< const sal_Int8* >( aMemStm.GetData() ), aMemStm.Seek( STREAM_SEEK_TO_END ) ) ), rFlavor );
933 			}
934 		}
935 	}
936 
937 	return sal_False;
938 }
939