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