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