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