LibreOffice Module sc (master)  1
drwtrans.cxx
Go to the documentation of this file.
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/XEmbeddedObject.hpp>
23 #include <com/sun/star/uno/Exception.hpp>
24 
25 #include <com/sun/star/beans/XPropertySet.hpp>
26 #include <com/sun/star/beans/XPropertySetInfo.hpp>
27 #include <com/sun/star/form/FormButtonType.hpp>
28 #include <unotools/streamwrap.hxx>
29 
30 #include <svx/unomodel.hxx>
31 #include <unotools/tempfile.hxx>
33 #include <comphelper/fileformat.h>
36 
38 #include <sot/storage.hxx>
39 #include <svx/svditer.hxx>
40 #include <svx/svdograf.hxx>
41 #include <svx/svdoole2.hxx>
42 #include <svx/svdouno.hxx>
43 #include <sfx2/docfile.hxx>
44 #include <svl/itempool.hxx>
45 #include <svl/urlbmk.hxx>
46 #include <tools/urlobj.hxx>
47 
48 #include <drwtrans.hxx>
49 #include <docsh.hxx>
50 #include <drwlayer.hxx>
51 #include <drawview.hxx>
52 #include <viewdata.hxx>
53 #include <scmod.hxx>
54 #include <dragdata.hxx>
55 
56 #include <editeng/eeitem.hxx>
57 
58 #include <editeng/fhgtitem.hxx>
59 #include <vcl/svapp.hxx>
60 
61 using namespace com::sun::star;
62 
63 constexpr sal_uInt32 SCDRAWTRANS_TYPE_EMBOBJ = 1;
64 constexpr sal_uInt32 SCDRAWTRANS_TYPE_DRAWMODEL = 2;
65 constexpr sal_uInt32 SCDRAWTRANS_TYPE_DOCUMENT = 3;
66 
67 ScDrawTransferObj::ScDrawTransferObj( std::unique_ptr<SdrModel> pClipModel, ScDocShell* pContainerShell,
68  const TransferableObjectDescriptor& rDesc ) :
69  m_pModel( std::move(pClipModel) ),
70  m_aObjDesc( rDesc ),
71  m_bGraphic( false ),
72  m_bGrIsBit( false ),
73  m_bOleObj( false ),
74  m_nDragSourceFlags( ScDragSrc::Undefined ),
75  m_bDragWasInternal( false ),
76  maShellID(SfxObjectShell::CreateShellID(pContainerShell))
77 {
78 
79  // check what kind of objects are contained
80 
81  SdrPage* pPage = m_pModel->GetPage(0);
82  if (pPage)
83  {
84  SdrObjListIter aIter( pPage, SdrIterMode::Flat );
85  SdrObject* pObject = aIter.Next();
86  if (pObject && !aIter.Next()) // exactly one object?
87  {
88 
89  // OLE object
90 
91  sal_uInt16 nSdrObjKind = pObject->GetObjIdentifier();
92  if (nSdrObjKind == OBJ_OLE2)
93  {
94  // if object has no persistence it must be copied as a part of document
95  try
96  {
97  uno::Reference< embed::XEmbedPersist > xPersObj( static_cast<SdrOle2Obj*>(pObject)->GetObjRef(), uno::UNO_QUERY );
98  if ( xPersObj.is() && xPersObj->hasEntry() )
99  m_bOleObj = true;
100  }
101  catch( uno::Exception& )
102  {}
103  // aOleData is initialized later
104  }
105 
106  // Graphic object
107 
108  if (nSdrObjKind == OBJ_GRAF)
109  {
110  m_bGraphic = true;
111  if ( static_cast<SdrGrafObj*>(pObject)->GetGraphic().GetType() == GraphicType::Bitmap )
112  m_bGrIsBit = true;
113  }
114 
115  // URL button
116 
117  SdrUnoObj* pUnoCtrl = dynamic_cast<SdrUnoObj*>( pObject );
118  if (pUnoCtrl && SdrInventor::FmForm == pUnoCtrl->GetObjInventor())
119  {
120  const uno::Reference<awt::XControlModel>& xControlModel = pUnoCtrl->GetUnoControlModel();
121  OSL_ENSURE( xControlModel.is(), "uno control without model" );
122  if ( xControlModel.is() )
123  {
124  uno::Reference< beans::XPropertySet > xPropSet( xControlModel, uno::UNO_QUERY );
125  uno::Reference< beans::XPropertySetInfo > xInfo = xPropSet->getPropertySetInfo();
126 
127  OUString sPropButtonType( "ButtonType" );
128 
129  if(xInfo->hasPropertyByName( sPropButtonType ))
130  {
131  uno::Any aAny = xPropSet->getPropertyValue( sPropButtonType );
132  form::FormButtonType eTmp;
133  if ( (aAny >>= eTmp) && eTmp == form::FormButtonType_URL )
134  {
135  // URL
136  OUString sPropTargetURL( "TargetURL" );
137  if(xInfo->hasPropertyByName( sPropTargetURL ))
138  {
139  aAny = xPropSet->getPropertyValue( sPropTargetURL );
140  OUString sTmp;
141  if ( (aAny >>= sTmp) && !sTmp.isEmpty() )
142  {
143  OUString aUrl = sTmp;
144  OUString aAbs = aUrl;
145  if (pContainerShell)
146  {
147  const SfxMedium* pMedium = pContainerShell->GetMedium();
148  if (pMedium)
149  {
150  bool bWasAbs = true;
151  aAbs = pMedium->GetURLObject().smartRel2Abs( aUrl, bWasAbs ).
153  // full path as stored INetBookmark must be encoded
154  }
155  }
156 
157  // Label
158  OUString aLabel;
159  OUString sPropLabel( "Label" );
160  if(xInfo->hasPropertyByName( sPropLabel ))
161  {
162  aAny = xPropSet->getPropertyValue( sPropLabel );
163  if ( (aAny >>= sTmp) && !sTmp.isEmpty() )
164  {
165  aLabel = sTmp;
166  }
167  }
168  m_pBookmark.reset( new INetBookmark( aAbs, aLabel ) );
169  }
170  }
171  }
172  }
173  }
174  }
175  }
176  }
177 
178  // get size for object descriptor
179 
180  // #i71538# use complete SdrViews
181  // SdrExchangeView aView(pModel);
182  SdrView aView(*m_pModel);
183  SdrPageView* pPv = aView.ShowSdrPage(aView.GetModel()->GetPage(0));
184  aView.MarkAllObj(pPv);
185  m_aSrcSize = aView.GetAllMarkedRect().GetSize();
186 
187  if ( m_bOleObj ) // single OLE object
188  {
189  SdrOle2Obj* pObj = GetSingleObject();
190  if ( pObj && pObj->GetObjRef().is() )
192  }
193 
196 
197  // remember a unique ID of the source document
198 
199  if ( pContainerShell )
200  {
201  ScDocument& rDoc = pContainerShell->GetDocument();
202  if ( pPage )
203  {
205  }
206  }
207 }
208 
210 {
211  SolarMutexGuard aSolarGuard;
212 
213  ScModule* pScMod = SC_MOD();
214  if ( pScMod->GetDragData().pDrawTransfer == this )
215  {
216  OSL_FAIL("ScDrawTransferObj wasn't released");
217  pScMod->ResetDragObject();
218  }
219 
220  m_aOleData = TransferableDataHelper(); // clear before releasing the mutex
222 
223  m_pModel.reset();
224  m_aDrawPersistRef.clear(); // after the model
225 
226  m_pBookmark.reset();
227  m_pDragSourceView.reset();
228 }
229 
230 ScDrawTransferObj* ScDrawTransferObj::GetOwnClipboard(const uno::Reference<datatransfer::XTransferable2>& xTransferable)
231 {
232  ScDrawTransferObj* pObj = nullptr;
233  if (xTransferable.is())
234  {
235  uno::Reference<XUnoTunnel> xTunnel( xTransferable, uno::UNO_QUERY );
236  if ( xTunnel.is() )
237  {
238  sal_Int64 nHandle = xTunnel->getSomething( getUnoTunnelId() );
239  if ( nHandle )
240  pObj = dynamic_cast<ScDrawTransferObj*>(reinterpret_cast<TransferableHelper*>( static_cast<sal_IntPtr>(nHandle) ));
241  }
242  }
243 
244  return pObj;
245 }
246 
247 static bool lcl_HasOnlyControls( SdrModel* pModel )
248 {
249  bool bOnlyControls = false; // default if there are no objects
250 
251  if ( pModel )
252  {
253  SdrPage* pPage = pModel->GetPage(0);
254  if (pPage)
255  {
256  SdrObjListIter aIter( pPage, SdrIterMode::DeepNoGroups );
257  SdrObject* pObj = aIter.Next();
258  if ( pObj )
259  {
260  bOnlyControls = true; // only set if there are any objects at all
261  while ( pObj )
262  {
263  if (dynamic_cast<const SdrUnoObj*>( pObj) == nullptr)
264  {
265  bOnlyControls = false;
266  break;
267  }
268  pObj = aIter.Next();
269  }
270  }
271  }
272  }
273 
274  return bOnlyControls;
275 }
276 
278 {
279  if ( m_bGrIsBit ) // single bitmap graphic
280  {
281  AddFormat( SotClipboardFormatId::OBJECTDESCRIPTOR );
282  AddFormat( SotClipboardFormatId::SVXB );
283  AddFormat( SotClipboardFormatId::PNG );
284  AddFormat( SotClipboardFormatId::BITMAP );
285  AddFormat( SotClipboardFormatId::GDIMETAFILE );
286  }
287  else if ( m_bGraphic ) // other graphic
288  {
289  // #i25616#
290  AddFormat( SotClipboardFormatId::DRAWING );
291 
292  AddFormat( SotClipboardFormatId::OBJECTDESCRIPTOR );
293  AddFormat( SotClipboardFormatId::SVXB );
294  AddFormat( SotClipboardFormatId::GDIMETAFILE );
295  AddFormat( SotClipboardFormatId::PNG );
296  AddFormat( SotClipboardFormatId::BITMAP );
297  }
298  else if ( m_pBookmark ) // url button
299  {
300 // AddFormat( SotClipboardFormatId::EMBED_SOURCE );
301  AddFormat( SotClipboardFormatId::OBJECTDESCRIPTOR );
302  AddFormat( SotClipboardFormatId::SOLK );
303  AddFormat( SotClipboardFormatId::STRING );
304  AddFormat( SotClipboardFormatId::UNIFORMRESOURCELOCATOR );
305  AddFormat( SotClipboardFormatId::NETSCAPE_BOOKMARK );
306  AddFormat( SotClipboardFormatId::DRAWING );
307  }
308  else if ( m_bOleObj ) // single OLE object
309  {
310  AddFormat( SotClipboardFormatId::EMBED_SOURCE );
311  AddFormat( SotClipboardFormatId::OBJECTDESCRIPTOR );
312  AddFormat( SotClipboardFormatId::GDIMETAFILE );
313 
314  CreateOLEData();
315 
316  if ( m_aOleData.GetTransferable().is() )
317  {
318  // get format list from object snapshot
319  // (this must be after inserting the default formats!)
320 
322 
323  for( const auto& rItem : aVector )
324  AddFormat( rItem );
325  }
326  }
327  else // any drawing objects
328  {
329  AddFormat( SotClipboardFormatId::EMBED_SOURCE );
330  AddFormat( SotClipboardFormatId::OBJECTDESCRIPTOR );
331  AddFormat( SotClipboardFormatId::DRAWING );
332 
333  // leave out bitmap and metafile if there are only controls
334  if ( !lcl_HasOnlyControls( m_pModel.get() ) )
335  {
336  AddFormat( SotClipboardFormatId::PNG );
337  AddFormat( SotClipboardFormatId::BITMAP );
338  AddFormat( SotClipboardFormatId::GDIMETAFILE );
339  }
340  }
341 
342 // if( pImageMap )
343 // AddFormat( SotClipboardFormatId::SVIM );
344 }
345 
346 bool ScDrawTransferObj::GetData( const css::datatransfer::DataFlavor& rFlavor, const OUString& rDestDoc )
347 {
348  bool bOK = false;
349  SotClipboardFormatId nFormat = SotExchange::GetFormat( rFlavor );
350 
351  if ( m_bOleObj && nFormat != SotClipboardFormatId::GDIMETAFILE )
352  {
353  CreateOLEData();
354 
355  if( m_aOleData.GetTransferable().is() && m_aOleData.HasFormat( rFlavor ) )
356  {
357  bOK = SetAny( m_aOleData.GetAny(rFlavor, rDestDoc) );
358 
359  return bOK;
360  }
361  }
362 
363  if( HasFormat( nFormat ) )
364  {
365  if ( nFormat == SotClipboardFormatId::LINKSRCDESCRIPTOR || nFormat == SotClipboardFormatId::OBJECTDESCRIPTOR )
366  {
368  }
369  else if ( nFormat == SotClipboardFormatId::DRAWING )
370  {
371  bOK = SetObject( m_pModel.get(), SCDRAWTRANS_TYPE_DRAWMODEL, rFlavor );
372  }
373  else if ( nFormat == SotClipboardFormatId::BITMAP
374  || nFormat == SotClipboardFormatId::PNG
375  || nFormat == SotClipboardFormatId::GDIMETAFILE )
376  {
377  // #i71538# use complete SdrViews
378  // SdrExchangeView aView( pModel );
379  SdrView aView(*m_pModel);
380  SdrPageView* pPv = aView.ShowSdrPage(aView.GetModel()->GetPage(0));
381  OSL_ENSURE( pPv, "pPv not there..." );
382  aView.MarkAllObj( pPv );
383  if ( nFormat == SotClipboardFormatId::GDIMETAFILE )
384  bOK = SetGDIMetaFile( aView.GetMarkedObjMetaFile(true) );
385  else
386  bOK = SetBitmapEx( aView.GetMarkedObjBitmapEx(true), rFlavor );
387  }
388  else if ( nFormat == SotClipboardFormatId::SVXB )
389  {
390  // only enabled for single graphics object
391 
392  SdrPage* pPage = m_pModel->GetPage(0);
393  if (pPage)
394  {
395  SdrObjListIter aIter( pPage, SdrIterMode::Flat );
396  SdrObject* pObject = aIter.Next();
397  if (pObject && pObject->GetObjIdentifier() == OBJ_GRAF)
398  {
399  SdrGrafObj* pGraphObj = static_cast<SdrGrafObj*>(pObject);
400  bOK = SetGraphic( pGraphObj->GetGraphic() );
401  }
402  }
403  }
404  else if ( nFormat == SotClipboardFormatId::EMBED_SOURCE )
405  {
406  if ( m_bOleObj ) // single OLE object
407  {
408  SdrOle2Obj* pObj = GetSingleObject();
409  if ( pObj && pObj->GetObjRef().is() )
410  {
411  bOK = SetObject( pObj->GetObjRef().get(), SCDRAWTRANS_TYPE_EMBOBJ, rFlavor );
412  }
413  }
414  else // create object from contents
415  {
416  //TODO/LATER: needs new Format, because now single OLE and "this" are different
417  InitDocShell(); // set aDocShellRef
418 
419  SfxObjectShell* pEmbObj = m_aDocShellRef.get();
420  bOK = SetObject( pEmbObj, SCDRAWTRANS_TYPE_DOCUMENT, rFlavor );
421  }
422  }
423  else if( m_pBookmark )
424  {
425  bOK = SetINetBookmark( *m_pBookmark, rFlavor );
426  }
427  }
428  return bOK;
429 }
430 
431 bool ScDrawTransferObj::WriteObject( tools::SvRef<SotStorageStream>& rxOStm, void* pUserObject, sal_uInt32 nUserObjectId,
432  const css::datatransfer::DataFlavor& /* rFlavor */ )
433 {
434  // called from SetObject, put data into stream
435 
436  bool bRet = false;
437  switch (nUserObjectId)
438  {
440  {
441  SdrModel* pDrawModel = static_cast<SdrModel*>(pUserObject);
442  rxOStm->SetBufferSize( 0xff00 );
443 
444  // for the changed pool defaults from drawing layer pool set those
445  // attributes as hard attributes to preserve them for saving
446  const SfxItemPool& rItemPool = m_pModel->GetItemPool();
447  const SvxFontHeightItem& rDefaultFontHeight = rItemPool.GetDefaultItem(EE_CHAR_FONTHEIGHT);
448 
449  // SW should have no MasterPages
450  OSL_ENSURE(0 == m_pModel->GetMasterPageCount(), "SW with MasterPages (!)");
451 
452  for(sal_uInt16 a(0); a < m_pModel->GetPageCount(); a++)
453  {
454  const SdrPage* pPage(m_pModel->GetPage(a));
455  SdrObjListIter aIter(pPage, SdrIterMode::DeepNoGroups);
456 
457  while(aIter.IsMore())
458  {
459  SdrObject* pObj = aIter.Next();
460  const SvxFontHeightItem& rItem = pObj->GetMergedItem(EE_CHAR_FONTHEIGHT);
461 
462  if(rItem.GetHeight() == rDefaultFontHeight.GetHeight())
463  {
464  pObj->SetMergedItem(rDefaultFontHeight);
465  }
466  }
467  }
468 
469  {
470  css::uno::Reference<css::io::XOutputStream> xDocOut( new utl::OOutputStreamWrapper( *rxOStm ) );
471  if( SvxDrawingLayerExport( pDrawModel, xDocOut ) )
472  rxOStm->Commit();
473  }
474 
475  bRet = ( rxOStm->GetError() == ERRCODE_NONE );
476  }
477  break;
478 
480  {
481  // impl. for "single OLE"
482  embed::XEmbeddedObject* pEmbObj = static_cast<embed::XEmbeddedObject*>(pUserObject);
483 
484  ::utl::TempFile aTempFile;
485  aTempFile.EnableKillingFile();
486  uno::Reference< embed::XStorage > xWorkStore =
487  ::comphelper::OStorageHelper::GetStorageFromURL( aTempFile.GetURL(), embed::ElementModes::READWRITE );
488 
489  uno::Reference < embed::XEmbedPersist > xPers( static_cast<embed::XVisualObject*>(pEmbObj), uno::UNO_QUERY );
490  if ( xPers.is() )
491  {
492  try
493  {
494  uno::Sequence < beans::PropertyValue > aSeq;
495  OUString aDummyName("Dummy");
496  xPers->storeToEntry( xWorkStore, aDummyName, aSeq, aSeq );
497  if ( xWorkStore->isStreamElement( aDummyName ) )
498  {
499  uno::Reference < io::XOutputStream > xDocOut( new utl::OOutputStreamWrapper( *rxOStm ) );
500  uno::Reference < io::XStream > xNewStream = xWorkStore->openStreamElement( aDummyName, embed::ElementModes::READ );
501  ::comphelper::OStorageHelper::CopyInputToOutput( xNewStream->getInputStream(), xDocOut );
502  }
503  else
504  {
505  uno::Reference < io::XStream > xDocStr( new utl::OStreamWrapper( *rxOStm ) );
506  uno::Reference< embed::XStorage > xDocStg = ::comphelper::OStorageHelper::GetStorageFromStream( xDocStr );
507  uno::Reference < embed::XStorage > xNewStg = xWorkStore->openStorageElement( aDummyName, embed::ElementModes::READ );
508  xNewStg->copyToStorage( xDocStg );
509  uno::Reference < embed::XTransactedObject > xTrans( xDocStg, uno::UNO_QUERY );
510  if ( xTrans.is() )
511  xTrans->commit();
512  }
513 
514  rxOStm->Commit();
515  }
516  catch ( uno::Exception& )
517  {
518  }
519  }
520 
521  break;
522  }
524  {
525  // impl. for "DocShell"
526  SfxObjectShell* pEmbObj = static_cast<SfxObjectShell*>(pUserObject);
527 
528  try
529  {
530  ::utl::TempFile aTempFile;
531  aTempFile.EnableKillingFile();
532  uno::Reference< embed::XStorage > xWorkStore =
533  ::comphelper::OStorageHelper::GetStorageFromURL( aTempFile.GetURL(), embed::ElementModes::READWRITE );
534 
535  // write document storage
536  pEmbObj->SetupStorage( xWorkStore, SOFFICE_FILEFORMAT_CURRENT, false );
537 
538  // mba: no relative URLs for clipboard!
539  SfxMedium aMedium( xWorkStore, OUString() );
540  pEmbObj->DoSaveObjectAs( aMedium, false );
541  pEmbObj->DoSaveCompleted();
542 
543  uno::Reference< embed::XTransactedObject > xTransact( xWorkStore, uno::UNO_QUERY );
544  if ( xTransact.is() )
545  xTransact->commit();
546 
547  std::unique_ptr<SvStream> pSrcStm = ::utl::UcbStreamHelper::CreateStream( aTempFile.GetURL(), StreamMode::READ );
548  if( pSrcStm )
549  {
550  rxOStm->SetBufferSize( 0xff00 );
551  rxOStm->WriteStream( *pSrcStm );
552  pSrcStm.reset();
553  }
554 
555  xWorkStore->dispose();
556  xWorkStore.clear();
557  rxOStm->Commit();
558  }
559  catch ( uno::Exception& )
560  {}
561 
562  bRet = ( rxOStm->GetError() == ERRCODE_NONE );
563  }
564  break;
565 
566  default:
567  OSL_FAIL("unknown object id");
568  }
569  return bRet;
570 }
571 
573 {
575  {
576  // move: delete source objects
577 
578  if ( m_pDragSourceView )
579  m_pDragSourceView->DeleteMarked();
580  }
581 
582  ScModule* pScMod = SC_MOD();
583  if ( pScMod->GetDragData().pDrawTransfer == this )
584  pScMod->ResetDragObject();
585 
586  m_pDragSourceView.reset();
587 
589 }
590 
592 {
593  m_aDrawPersistRef = rRef;
594 }
595 
596 static void lcl_InitMarks( SdrMarkView& rDest, const SdrMarkView& rSource, SCTAB nTab )
597 {
598  rDest.ShowSdrPage(rDest.GetModel()->GetPage(nTab));
599  SdrPageView* pDestPV = rDest.GetSdrPageView();
600  OSL_ENSURE(pDestPV,"PageView ?");
601 
602  const SdrMarkList& rMarkList = rSource.GetMarkedObjectList();
603  const size_t nCount = rMarkList.GetMarkCount();
604  for (size_t i=0; i<nCount; ++i)
605  {
606  SdrMark* pMark = rMarkList.GetMark(i);
607  SdrObject* pObj = pMark->GetMarkedSdrObj();
608 
609  rDest.MarkObj(pObj, pDestPV);
610  }
611 }
612 
614 {
615  m_pDragSourceView.reset(new SdrView(pView->getSdrModelFromSdrView())); // TTTT pView should be reference
616  lcl_InitMarks( *m_pDragSourceView, *pView, pView->GetTab() );
617 
619 }
620 
622 {
624  m_pDragSourceView->ShowSdrPage(m_pDragSourceView->GetModel()->GetPage(nTab));
625  SdrPageView* pPV = m_pDragSourceView->GetSdrPageView();
626  m_pDragSourceView->MarkObj(&rObj, pPV); // TTTT MarkObj should take SdrObject&
627 
629 }
630 
632 {
633  m_nDragSourceFlags = nFlags;
634 }
635 
637 {
638  m_bDragWasInternal = true;
639 }
640 
641 const OUString& ScDrawTransferObj::GetShellID() const
642 {
643  return maShellID;
644 }
645 
647 {
648  // if single OLE object was copied, get its object
649 
650  SdrPage* pPage = m_pModel->GetPage(0);
651  if (pPage)
652  {
653  SdrObjListIter aIter( pPage, SdrIterMode::Flat );
654  SdrObject* pObject = aIter.Next();
655  if (pObject && pObject->GetObjIdentifier() == OBJ_OLE2)
656  {
657  return static_cast<SdrOle2Obj*>(pObject);
658  }
659  }
660 
661  return nullptr;
662 }
663 
665 {
666  if (m_aOleData.GetTransferable().is())
667  // Already created.
668  return;
669 
670  SdrOle2Obj* pObj = GetSingleObject();
671  if (!pObj || !pObj->GetObjRef().is())
672  // No OLE object present.
673  return;
674 
675  SvEmbedTransferHelper* pEmbedTransfer =
677  pObj->GetObjRef(), pObj->GetGraphic(), pObj->GetAspect());
678 
679  pEmbedTransfer->SetParentShellID(maShellID);
680 
681  m_aOleData = TransferableDataHelper(pEmbedTransfer);
682 }
683 
684 // initialize aDocShellRef with a live document from the ClipDoc
685 
687 {
688  if ( m_aDocShellRef.is() )
689  return;
690 
691  ScDocShell* pDocSh = new ScDocShell;
692  m_aDocShellRef = pDocSh; // ref must be there before InitNew
693 
694  pDocSh->DoInitNew();
695 
696  ScDocument& rDestDoc = pDocSh->GetDocument();
697  rDestDoc.InitDrawLayer( pDocSh );
698 
699  SdrModel* pDestModel = rDestDoc.GetDrawLayer();
700  // #i71538# use complete SdrViews
701  // SdrExchangeView aDestView( pDestModel );
702  SdrView aDestView(*pDestModel);
703  aDestView.ShowSdrPage(aDestView.GetModel()->GetPage(0));
704  aDestView.Paste(
705  *m_pModel,
707  nullptr, SdrInsertFlags::NONE);
708 
709  // put objects to right layer (see ScViewFunc::PasteDataFormat for SotClipboardFormatId::DRAWING)
710 
711  SdrPage* pPage = pDestModel->GetPage(0);
712  if (pPage)
713  {
714  SdrObjListIter aIter( pPage, SdrIterMode::DeepWithGroups );
715  SdrObject* pObject = aIter.Next();
716  while (pObject)
717  {
718  if ( dynamic_cast<const SdrUnoObj*>( pObject) != nullptr )
719  pObject->NbcSetLayer(SC_LAYER_CONTROLS);
720  else
721  pObject->NbcSetLayer(SC_LAYER_FRONT);
722  pObject = aIter.Next();
723  }
724  }
725 
726  tools::Rectangle aDestArea( Point(), m_aSrcSize );
727  pDocSh->SetVisArea( aDestArea );
728 
729  ScViewOptions aViewOpt( rDestDoc.GetViewOptions() );
730  aViewOpt.SetOption( VOPT_GRID, false );
731  rDestDoc.SetViewOptions( aViewOpt );
732 
733  ScViewData aViewData( *pDocSh, nullptr );
734  aViewData.SetTabNo( 0 );
735  aViewData.SetScreen( aDestArea );
736  aViewData.SetCurX( 0 );
737  aViewData.SetCurY( 0 );
738  pDocSh->UpdateOle(aViewData, true);
739 }
740 
741 namespace
742 {
743  class theScDrawTransferObjUnoTunnelId : public rtl::Static< UnoTunnelIdInit, theScDrawTransferObjUnoTunnelId > {};
744 }
745 
746 const css::uno::Sequence< sal_Int8 >& ScDrawTransferObj::getUnoTunnelId()
747 {
748  return theScDrawTransferObjUnoTunnelId::get().getSeq();
749 }
750 
751 sal_Int64 SAL_CALL ScDrawTransferObj::getSomething( const css::uno::Sequence< sal_Int8 >& rId )
752 {
753  sal_Int64 nRet;
754  if( isUnoTunnelId<ScDrawTransferObj>(rId) )
755  {
756  nRet = reinterpret_cast< sal_Int64 >( this );
757  }
758  else
760  return nRet;
761 }
762 
763 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual bool WriteObject(tools::SvRef< SotStorageStream > &rxOStm, void *pUserObject, sal_uInt32 nUserObjectId, const css::datatransfer::DataFlavor &rFlavor) override
Definition: drwtrans.cxx:431
long Width() const
bool is() const
ScDragSrc m_nDragSourceFlags
Definition: drwtrans.hxx:56
void SetOption(ScViewOption eOpt, bool bNew)
Definition: viewopti.hxx:87
OBJ_GRAF
static ScDrawTransferObj * GetOwnClipboard(const css::uno::Reference< css::datatransfer::XTransferable2 > &)
Definition: drwtrans.cxx:230
static void FillProtectedChartRangesVector(ScRangeListVector &rRangesVector, const ScDocument &rDocument, const SdrPage *pPage)
size_t GetMarkCount() const
void SetCurX(SCCOL nNewCurX)
Definition: viewdata.hxx:431
css::uno::Any GetAny(SotClipboardFormatId nFormat, const OUString &rDestDoc) const
bool SetBitmapEx(const BitmapEx &rBitmap, const css::datatransfer::DataFlavor &rFlavor)
OBJ_OLE2
virtual bool DoSaveCompleted(SfxMedium *pNewStor=nullptr, bool bRegisterRecent=true)
css::uno::Reference< css::embed::XEmbeddedObject > const & GetObjRef() const
static void CopyInputToOutput(const css::uno::Reference< css::io::XInputStream > &xInput, const css::uno::Reference< css::io::XOutputStream > &xOutput)
long Height() const
signed char sal_Int8
virtual bool Paste(const SdrModel &rMod, const Point &rPos, SdrObjList *pLst, SdrInsertFlags nOptions)
::std::vector< DataFlavorEx > DataFlavorExVector
TransferableDataHelper m_aOleData
Definition: drwtrans.hxx:42
bool SetTransferableObjectDescriptor(const TransferableObjectDescriptor &rDesc)
#define SOFFICE_FILEFORMAT_CURRENT
virtual void DragFinished(sal_Int8 nDropAction) override
virtual void AddSupportedFormats() override
Definition: drwtrans.cxx:277
bool HasFormat(SotClipboardFormatId nFormat)
SdrMark * GetMark(size_t nNum) const
ScRangeListVector m_aProtectedChartRangesVector
Definition: drwtrans.hxx:59
constexpr sal_uInt32 SCDRAWTRANS_TYPE_DOCUMENT
Definition: drwtrans.cxx:65
void SetDragWasInternal()
Definition: drwtrans.cxx:636
const ScDragData & GetDragData() const
Definition: scmod.hxx:144
EmbeddedObjectRef * pObject
bool HasFormat(SotClipboardFormatId nFormat) const
constexpr TypedWhichId< SvxFontHeightItem > EE_CHAR_FONTHEIGHT(EE_CHAR_START+2)
static bool lcl_HasOnlyControls(SdrModel *pModel)
Definition: drwtrans.cxx:247
bool SetINetBookmark(const INetBookmark &rBmk, const css::datatransfer::DataFlavor &rFlavor)
bool SetObject(void *pUserObject, sal_uInt32 nUserObjectId, const css::datatransfer::DataFlavor &rFlavor)
#define DND_ACTION_MOVE
void AddFormat(SotClipboardFormatId nFormat)
bool m_bDragWasInternal
Definition: drwtrans.hxx:57
BitmapEx GetMarkedObjBitmapEx(bool bNoVDevIfOneBmpMarked=false) const
static std::unique_ptr< SvStream > CreateStream(const OUString &rFileName, StreamMode eOpenMode, css::uno::Reference< css::awt::XWindow > xParentWin=nullptr)
void SetDragSourceFlags(ScDragSrc nFlags)
Definition: drwtrans.cxx:631
static css::uno::Reference< css::embed::XStorage > GetStorageFromStream(const css::uno::Reference< css::io::XStream > &xStream, sal_Int32 nStorageMode=css::embed::ElementModes::READWRITE, const css::uno::Reference< css::uno::XComponentContext > &rxContext=css::uno::Reference< css::uno::XComponentContext >())
static void lcl_InitMarks(SdrMarkView &rDest, const SdrMarkView &rSource, SCTAB nTab)
Definition: drwtrans.cxx:596
int nCount
virtual void DragFinished(sal_Int8 nDropAction) override
Definition: drwtrans.cxx:572
ScDrawTransferObj * pDrawTransfer
Definition: dragdata.hxx:22
SdrPageView * ShowSdrPage(SdrPage *pPage) override
virtual bool GetData(const css::datatransfer::DataFlavor &rFlavor, const OUString &rDestDoc) override
Definition: drwtrans.cxx:346
SotClipboardFormatId
sal_Int32 nHandle
GDIMetaFile GetMarkedObjMetaFile(bool bNoVDevIfOneMtfMarked=false) const
virtual sal_Int64 SAL_CALL getSomething(const css::uno::Sequence< sal_Int8 > &rId) override
Definition: drwtrans.cxx:751
SdrObject * GetMarkedSdrObj() const
void SetTabNo(SCTAB nNewTab)
Definition: viewdata.cxx:2254
void MarkAllObj(SdrPageView *pPV=nullptr)
bool SetGraphic(const Graphic &rGraphic)
SC_DLLPUBLIC ScDrawLayer * GetDrawLayer()
Definition: document.hxx:1059
T * get() const
ScDragSrc
Definition: viewdata.hxx:92
SC_DLLPUBLIC void InitDrawLayer(SfxObjectShell *pDocShell=nullptr)
Definition: documen9.cxx:96
int i
constexpr sal_uInt32 SCDRAWTRANS_TYPE_EMBOBJ
Definition: drwtrans.cxx:63
uno_Any a
OUString const & GetURL() const
virtual sal_uInt16 GetObjIdentifier() const
const Graphic & GetGraphic() const
OUString maShellID
Definition: drwtrans.hxx:61
std::unique_ptr< SdrModel > m_pModel
Definition: drwtrans.hxx:41
void SetCurY(SCROW nNewCurY)
Definition: viewdata.hxx:432
#define SC_MOD()
Definition: scmod.hxx:253
void CreateOLEData()
Definition: drwtrans.cxx:664
SC_DLLPUBLIC void SetViewOptions(const ScViewOptions &rOpt)
Definition: documen3.cxx:1943
const SdrMarkList & GetMarkedObjectList() const
const SdrPage * GetPage(sal_uInt16 nPgNum) const
SdrModel & getSdrModelFromSdrObject() const
SCTAB GetTab() const
Definition: drawview.hxx:101
void PrepareOLE(const TransferableObjectDescriptor &rObjDesc)
static css::uno::Reference< css::embed::XStorage > GetStorageFromURL(const OUString &aURL, sal_Int32 nStorageMode, const css::uno::Reference< css::uno::XComponentContext > &rxContext=css::uno::Reference< css::uno::XComponentContext >())
virtual SdrPageView * ShowSdrPage(SdrPage *pPage)
void SetMergedItem(const SfxPoolItem &rItem)
const SfxPoolItem & GetMergedItem(const sal_uInt16 nWhich) const
ScDrawTransferObj(std::unique_ptr< SdrModel > pClipModel, ScDocShell *pContainerShell, const TransferableObjectDescriptor &rDesc)
Definition: drwtrans.cxx:67
const SfxPoolItem & GetDefaultItem(sal_uInt16 nWhich) const
const tools::Rectangle & GetAllMarkedRect() const
Size GetSize() const
virtual SdrInventor GetObjInventor() const
SC_DLLPUBLIC const ScViewOptions & GetViewOptions() const
Definition: documen3.cxx:1937
virtual sal_Int64 SAL_CALL getSomething(const css::uno::Sequence< sal_Int8 > &rId) override
SdrObject * Next()
static SotClipboardFormatId GetFormat(const css::datatransfer::DataFlavor &rFlavor)
void UpdateOle(const ScViewData &rViewData, bool bSnapSize=false)
Definition: docsh6.cxx:152
std::unique_ptr< SdrView > m_pDragSourceView
Definition: drwtrans.hxx:55
sal_uInt32 GetHeight() const
const OUString & GetShellID() const
Definition: drwtrans.cxx:641
sal_Int64 GetAspect() const
static void FillTransferableObjectDescriptor(TransferableObjectDescriptor &rDesc, const css::uno::Reference< css::embed::XEmbeddedObject > &xObj, const Graphic *pGraphic, sal_Int64 nAspect)
void SetDragSourceObj(SdrObject &rObj, SCTAB nTab)
Definition: drwtrans.cxx:621
#define ERRCODE_NONE
std::unique_ptr< INetBookmark > m_pBookmark
Definition: drwtrans.hxx:49
constexpr SdrLayerID SC_LAYER_FRONT(0)
bool DoInitNew(SfxMedium *pMedium=nullptr)
const INetURLObject & GetURLObject() const
OUString aLabel
constexpr sal_uInt32 SCDRAWTRANS_TYPE_DRAWMODEL
Definition: drwtrans.cxx:64
static const css::uno::Sequence< sal_Int8 > & getUnoTunnelId()
Definition: drwtrans.cxx:746
Sequence< sal_Int8 > aSeq
const ScDocument & GetDocument() const
Definition: docsh.hxx:216
SfxObjectShellRef m_aDocShellRef
Definition: drwtrans.hxx:44
void SetDrawPersist(const SfxObjectShellRef &rRef)
Definition: drwtrans.cxx:591
SdrPageView * GetSdrPageView() const
const css::uno::Reference< css::awt::XControlModel > & GetUnoControlModel() const
bool DoSaveObjectAs(SfxMedium &rNewStor, bool bCommit)
SVXCORE_DLLPUBLIC bool SvxDrawingLayerExport(SdrModel *pModel, const css::uno::Reference< css::io::XOutputStream > &xOut)
void SetupStorage(const css::uno::Reference< css::embed::XStorage > &xStorage, sal_Int32 nVersion, bool bTemplate) const
SdrModel & getSdrModelFromSdrView() const
bool MarkObj(const Point &rPnt, short nTol=-2, bool bToggle=false, bool bDeep=false)
virtual void SetVisArea(const tools::Rectangle &rVisArea) override
Definition: docsh6.cxx:57
void SetScreen(SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2)
Definition: viewdata.cxx:2933
bool SetAny(const css::uno::Any &rAny)
void ResetDragObject()
Definition: scmod.cxx:583
INetURLObject smartRel2Abs(OUString const &rTheRelURIRef, bool &rWasAbsolute, bool bIgnoreFragment=false, EncodeMechanism eMechanism=EncodeMechanism::WasEncoded, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8, bool bRelativeNonURIs=false, FSysStyle eStyle=FSysStyle::Detect) const
const css::uno::Reference< css::datatransfer::XTransferable > & GetTransferable() const
SdrModel * GetModel() const
TransferableObjectDescriptor m_aObjDesc
Definition: drwtrans.hxx:43
constexpr SdrLayerID SC_LAYER_CONTROLS(3)
void SetDragSource(const ScDrawView *pView)
Definition: drwtrans.cxx:613
void EnableKillingFile(bool bEnable=true)
SfxObjectShellRef m_aDrawPersistRef
Definition: drwtrans.hxx:45
sal_Int16 SCTAB
Definition: types.hxx:23
bool SetGDIMetaFile(const GDIMetaFile &rMtf)
const Graphic * GetGraphic() const
void SetParentShellID(const OUString &rShellID)
virtual ~ScDrawTransferObj() override
Definition: drwtrans.cxx:209
SdrOle2Obj * GetSingleObject()
Definition: drwtrans.cxx:646
virtual void NbcSetLayer(SdrLayerID nLayer)
const DataFlavorExVector & GetDataFlavorExVector() const
SfxMedium * GetMedium() const