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