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  return comphelper::getFromUnoTunnel<ScDrawTransferObj>(xTransferable);
234 }
235 
236 static bool lcl_HasOnlyControls( SdrModel* pModel )
237 {
238  bool bOnlyControls = false; // default if there are no objects
239 
240  if ( pModel )
241  {
242  SdrPage* pPage = pModel->GetPage(0);
243  if (pPage)
244  {
245  SdrObjListIter aIter( pPage, SdrIterMode::DeepNoGroups );
246  SdrObject* pObj = aIter.Next();
247  if ( pObj )
248  {
249  bOnlyControls = true; // only set if there are any objects at all
250  while ( pObj )
251  {
252  if (dynamic_cast<const SdrUnoObj*>( pObj) == nullptr)
253  {
254  bOnlyControls = false;
255  break;
256  }
257  pObj = aIter.Next();
258  }
259  }
260  }
261  }
262 
263  return bOnlyControls;
264 }
265 
267 {
268  if ( m_bGrIsBit ) // single bitmap graphic
269  {
270  AddFormat( SotClipboardFormatId::OBJECTDESCRIPTOR );
271  AddFormat( SotClipboardFormatId::SVXB );
272  AddFormat( SotClipboardFormatId::PNG );
273  AddFormat( SotClipboardFormatId::BITMAP );
274  AddFormat( SotClipboardFormatId::GDIMETAFILE );
275  }
276  else if ( m_bGraphic ) // other graphic
277  {
278  // #i25616#
279  AddFormat( SotClipboardFormatId::DRAWING );
280 
281  AddFormat( SotClipboardFormatId::OBJECTDESCRIPTOR );
282  AddFormat( SotClipboardFormatId::SVXB );
283  AddFormat( SotClipboardFormatId::GDIMETAFILE );
284  AddFormat( SotClipboardFormatId::PNG );
285  AddFormat( SotClipboardFormatId::BITMAP );
286  }
287  else if ( m_pBookmark ) // url button
288  {
289 // AddFormat( SotClipboardFormatId::EMBED_SOURCE );
290  AddFormat( SotClipboardFormatId::OBJECTDESCRIPTOR );
291  AddFormat( SotClipboardFormatId::SOLK );
292  AddFormat( SotClipboardFormatId::STRING );
293  AddFormat( SotClipboardFormatId::UNIFORMRESOURCELOCATOR );
294  AddFormat( SotClipboardFormatId::NETSCAPE_BOOKMARK );
295  AddFormat( SotClipboardFormatId::DRAWING );
296  }
297  else if ( m_bOleObj ) // single OLE object
298  {
299  AddFormat( SotClipboardFormatId::EMBED_SOURCE );
300  AddFormat( SotClipboardFormatId::OBJECTDESCRIPTOR );
301  AddFormat( SotClipboardFormatId::GDIMETAFILE );
302 
303  CreateOLEData();
304 
305  if ( m_aOleData.GetTransferable().is() )
306  {
307  // get format list from object snapshot
308  // (this must be after inserting the default formats!)
309 
311 
312  for( const auto& rItem : aVector )
313  AddFormat( rItem );
314  }
315  }
316  else // any drawing objects
317  {
318  AddFormat( SotClipboardFormatId::EMBED_SOURCE );
319  AddFormat( SotClipboardFormatId::OBJECTDESCRIPTOR );
320  AddFormat( SotClipboardFormatId::DRAWING );
321 
322  // leave out bitmap and metafile if there are only controls
323  if ( !lcl_HasOnlyControls( m_pModel.get() ) )
324  {
325  AddFormat( SotClipboardFormatId::PNG );
326  AddFormat( SotClipboardFormatId::BITMAP );
327  AddFormat( SotClipboardFormatId::GDIMETAFILE );
328  }
329  }
330 
331 // if( pImageMap )
332 // AddFormat( SotClipboardFormatId::SVIM );
333 }
334 
335 bool ScDrawTransferObj::GetData( const css::datatransfer::DataFlavor& rFlavor, const OUString& rDestDoc )
336 {
337  bool bOK = false;
338  SotClipboardFormatId nFormat = SotExchange::GetFormat( rFlavor );
339 
340  if ( m_bOleObj && nFormat != SotClipboardFormatId::GDIMETAFILE )
341  {
342  CreateOLEData();
343 
344  if( m_aOleData.GetTransferable().is() && m_aOleData.HasFormat( rFlavor ) )
345  {
346  bOK = SetAny( m_aOleData.GetAny(rFlavor, rDestDoc) );
347 
348  return bOK;
349  }
350  }
351 
352  if( HasFormat( nFormat ) )
353  {
354  if ( nFormat == SotClipboardFormatId::LINKSRCDESCRIPTOR || nFormat == SotClipboardFormatId::OBJECTDESCRIPTOR )
355  {
357  }
358  else if ( nFormat == SotClipboardFormatId::DRAWING )
359  {
360  bOK = SetObject( m_pModel.get(), SCDRAWTRANS_TYPE_DRAWMODEL, rFlavor );
361  }
362  else if ( nFormat == SotClipboardFormatId::BITMAP
363  || nFormat == SotClipboardFormatId::PNG
364  || nFormat == SotClipboardFormatId::GDIMETAFILE )
365  {
366  // #i71538# use complete SdrViews
367  // SdrExchangeView aView( pModel );
368  SdrView aView(*m_pModel);
369  SdrPageView* pPv = aView.ShowSdrPage(aView.GetModel()->GetPage(0));
370  OSL_ENSURE( pPv, "pPv not there..." );
371  aView.MarkAllObj( pPv );
372  if ( nFormat == SotClipboardFormatId::GDIMETAFILE )
373  bOK = SetGDIMetaFile( aView.GetMarkedObjMetaFile(true) );
374  else
375  bOK = SetBitmapEx( aView.GetMarkedObjBitmapEx(true), rFlavor );
376  }
377  else if ( nFormat == SotClipboardFormatId::SVXB )
378  {
379  // only enabled for single graphics object
380 
381  SdrPage* pPage = m_pModel->GetPage(0);
382  if (pPage)
383  {
384  SdrObjListIter aIter( pPage, SdrIterMode::Flat );
385  SdrObject* pObject = aIter.Next();
386  if (pObject && pObject->GetObjIdentifier() == OBJ_GRAF)
387  {
388  SdrGrafObj* pGraphObj = static_cast<SdrGrafObj*>(pObject);
389  bOK = SetGraphic( pGraphObj->GetGraphic() );
390  }
391  }
392  }
393  else if ( nFormat == SotClipboardFormatId::EMBED_SOURCE )
394  {
395  if ( m_bOleObj ) // single OLE object
396  {
397  SdrOle2Obj* pObj = GetSingleObject();
398  if ( pObj && pObj->GetObjRef().is() )
399  {
400  bOK = SetObject( pObj->GetObjRef().get(), SCDRAWTRANS_TYPE_EMBOBJ, rFlavor );
401  }
402  }
403  else // create object from contents
404  {
405  //TODO/LATER: needs new Format, because now single OLE and "this" are different
406  InitDocShell(); // set aDocShellRef
407 
408  SfxObjectShell* pEmbObj = m_aDocShellRef.get();
409  bOK = SetObject( pEmbObj, SCDRAWTRANS_TYPE_DOCUMENT, rFlavor );
410  }
411  }
412  else if( m_pBookmark )
413  {
414  bOK = SetINetBookmark( *m_pBookmark, rFlavor );
415  }
416  }
417  return bOK;
418 }
419 
420 bool ScDrawTransferObj::WriteObject( tools::SvRef<SotTempStream>& rxOStm, void* pUserObject, sal_uInt32 nUserObjectId,
421  const css::datatransfer::DataFlavor& /* rFlavor */ )
422 {
423  // called from SetObject, put data into stream
424 
425  bool bRet = false;
426  switch (nUserObjectId)
427  {
429  {
430  SdrModel* pDrawModel = static_cast<SdrModel*>(pUserObject);
431  rxOStm->SetBufferSize( 0xff00 );
432 
433  // for the changed pool defaults from drawing layer pool set those
434  // attributes as hard attributes to preserve them for saving
435  const SfxItemPool& rItemPool = m_pModel->GetItemPool();
436  const SvxFontHeightItem& rDefaultFontHeight = rItemPool.GetDefaultItem(EE_CHAR_FONTHEIGHT);
437 
438  // SW should have no MasterPages
439  OSL_ENSURE(0 == m_pModel->GetMasterPageCount(), "SW with MasterPages (!)");
440 
441  for(sal_uInt16 a(0); a < m_pModel->GetPageCount(); a++)
442  {
443  const SdrPage* pPage(m_pModel->GetPage(a));
444  SdrObjListIter aIter(pPage, SdrIterMode::DeepNoGroups);
445 
446  while(aIter.IsMore())
447  {
448  SdrObject* pObj = aIter.Next();
449  const SvxFontHeightItem& rItem = pObj->GetMergedItem(EE_CHAR_FONTHEIGHT);
450 
451  if(rItem.GetHeight() == rDefaultFontHeight.GetHeight())
452  {
453  pObj->SetMergedItem(rDefaultFontHeight);
454  }
455  }
456  }
457 
458  {
459  css::uno::Reference<css::io::XOutputStream> xDocOut( new utl::OOutputStreamWrapper( *rxOStm ) );
460  SvxDrawingLayerExport( pDrawModel, xDocOut );
461  }
462 
463  bRet = ( rxOStm->GetError() == ERRCODE_NONE );
464  }
465  break;
466 
468  {
469  // impl. for "single OLE"
470  embed::XEmbeddedObject* pEmbObj = static_cast<embed::XEmbeddedObject*>(pUserObject);
471 
472  ::utl::TempFile aTempFile;
473  aTempFile.EnableKillingFile();
474  uno::Reference< embed::XStorage > xWorkStore =
475  ::comphelper::OStorageHelper::GetStorageFromURL( aTempFile.GetURL(), embed::ElementModes::READWRITE );
476 
477  uno::Reference < embed::XEmbedPersist > xPers( static_cast<embed::XVisualObject*>(pEmbObj), uno::UNO_QUERY );
478  if ( xPers.is() )
479  {
480  try
481  {
482  uno::Sequence < beans::PropertyValue > aSeq;
483  OUString aDummyName("Dummy");
484  xPers->storeToEntry( xWorkStore, aDummyName, aSeq, aSeq );
485  if ( xWorkStore->isStreamElement( aDummyName ) )
486  {
487  uno::Reference < io::XOutputStream > xDocOut( new utl::OOutputStreamWrapper( *rxOStm ) );
488  uno::Reference < io::XStream > xNewStream = xWorkStore->openStreamElement( aDummyName, embed::ElementModes::READ );
489  ::comphelper::OStorageHelper::CopyInputToOutput( xNewStream->getInputStream(), xDocOut );
490  }
491  else
492  {
493  uno::Reference < io::XStream > xDocStr( new utl::OStreamWrapper( *rxOStm ) );
494  uno::Reference< embed::XStorage > xDocStg = ::comphelper::OStorageHelper::GetStorageFromStream( xDocStr );
495  uno::Reference < embed::XStorage > xNewStg = xWorkStore->openStorageElement( aDummyName, embed::ElementModes::READ );
496  xNewStg->copyToStorage( xDocStg );
497  uno::Reference < embed::XTransactedObject > xTrans( xDocStg, uno::UNO_QUERY );
498  if ( xTrans.is() )
499  xTrans->commit();
500  }
501  }
502  catch ( uno::Exception& )
503  {
504  }
505  }
506 
507  break;
508  }
510  {
511  // impl. for "DocShell"
512  SfxObjectShell* pEmbObj = static_cast<SfxObjectShell*>(pUserObject);
513 
514  try
515  {
516  ::utl::TempFile aTempFile;
517  aTempFile.EnableKillingFile();
518  uno::Reference< embed::XStorage > xWorkStore =
519  ::comphelper::OStorageHelper::GetStorageFromURL( aTempFile.GetURL(), embed::ElementModes::READWRITE );
520 
521  // write document storage
522  pEmbObj->SetupStorage( xWorkStore, SOFFICE_FILEFORMAT_CURRENT, false );
523 
524  // mba: no relative URLs for clipboard!
525  SfxMedium aMedium( xWorkStore, OUString() );
526  pEmbObj->DoSaveObjectAs( aMedium, false );
527  pEmbObj->DoSaveCompleted();
528 
529  uno::Reference< embed::XTransactedObject > xTransact( xWorkStore, uno::UNO_QUERY );
530  if ( xTransact.is() )
531  xTransact->commit();
532 
533  std::unique_ptr<SvStream> pSrcStm = ::utl::UcbStreamHelper::CreateStream( aTempFile.GetURL(), StreamMode::READ );
534  if( pSrcStm )
535  {
536  rxOStm->SetBufferSize( 0xff00 );
537  rxOStm->WriteStream( *pSrcStm );
538  pSrcStm.reset();
539  }
540 
541  xWorkStore->dispose();
542  xWorkStore.clear();
543  }
544  catch ( uno::Exception& )
545  {}
546 
547  bRet = ( rxOStm->GetError() == ERRCODE_NONE );
548  }
549  break;
550 
551  default:
552  OSL_FAIL("unknown object id");
553  }
554  return bRet;
555 }
556 
558 {
560  {
561  // move: delete source objects
562 
563  if ( m_pDragSourceView )
564  m_pDragSourceView->DeleteMarked();
565  }
566 
567  ScModule* pScMod = SC_MOD();
568  if ( pScMod->GetDragData().pDrawTransfer == this )
569  pScMod->ResetDragObject();
570 
571  m_pDragSourceView.reset();
572 
574 }
575 
577 {
578  m_aDrawPersistRef = rRef;
579 }
580 
581 static void lcl_InitMarks( SdrMarkView& rDest, const SdrMarkView& rSource, SCTAB nTab )
582 {
583  rDest.ShowSdrPage(rDest.GetModel()->GetPage(nTab));
584  SdrPageView* pDestPV = rDest.GetSdrPageView();
585  OSL_ENSURE(pDestPV,"PageView ?");
586 
587  const SdrMarkList& rMarkList = rSource.GetMarkedObjectList();
588  const size_t nCount = rMarkList.GetMarkCount();
589  for (size_t i=0; i<nCount; ++i)
590  {
591  SdrMark* pMark = rMarkList.GetMark(i);
592  SdrObject* pObj = pMark->GetMarkedSdrObj();
593 
594  rDest.MarkObj(pObj, pDestPV);
595  }
596 }
597 
599 {
600  m_pDragSourceView.reset(new SdrView(pView->getSdrModelFromSdrView())); // TTTT pView should be reference
601  lcl_InitMarks( *m_pDragSourceView, *pView, pView->GetTab() );
602 
604 }
605 
607 {
609  m_pDragSourceView->ShowSdrPage(m_pDragSourceView->GetModel()->GetPage(nTab));
610  SdrPageView* pPV = m_pDragSourceView->GetSdrPageView();
611  m_pDragSourceView->MarkObj(&rObj, pPV); // TTTT MarkObj should take SdrObject&
612 
614 }
615 
617 {
618  m_nDragSourceFlags = nFlags;
619 }
620 
622 {
623  m_bDragWasInternal = true;
624 }
625 
626 const OUString& ScDrawTransferObj::GetShellID() const
627 {
628  return maShellID;
629 }
630 
632 {
633  // if single OLE object was copied, get its object
634 
635  SdrPage* pPage = m_pModel->GetPage(0);
636  if (pPage)
637  {
638  SdrObjListIter aIter( pPage, SdrIterMode::Flat );
639  SdrObject* pObject = aIter.Next();
640  if (pObject && pObject->GetObjIdentifier() == OBJ_OLE2)
641  {
642  return static_cast<SdrOle2Obj*>(pObject);
643  }
644  }
645 
646  return nullptr;
647 }
648 
650 {
651  if (m_aOleData.GetTransferable().is())
652  // Already created.
653  return;
654 
655  SdrOle2Obj* pObj = GetSingleObject();
656  if (!pObj || !pObj->GetObjRef().is())
657  // No OLE object present.
658  return;
659 
662  pObj->GetObjRef(), pObj->GetGraphic(), pObj->GetAspect());
663 
664  pEmbedTransfer->SetParentShellID(maShellID);
665 
666  m_aOleData = TransferableDataHelper(pEmbedTransfer);
667 }
668 
669 // initialize aDocShellRef with a live document from the ClipDoc
670 
672 {
673  if ( m_aDocShellRef.is() )
674  return;
675 
676  ScDocShell* pDocSh = new ScDocShell;
677  m_aDocShellRef = pDocSh; // ref must be there before InitNew
678 
679  pDocSh->DoInitNew();
680 
681  ScDocument& rDestDoc = pDocSh->GetDocument();
682  rDestDoc.InitDrawLayer( pDocSh );
683 
684  SdrModel* pDestModel = rDestDoc.GetDrawLayer();
685  // #i71538# use complete SdrViews
686  // SdrExchangeView aDestView( pDestModel );
687  SdrView aDestView(*pDestModel);
688  aDestView.ShowSdrPage(aDestView.GetModel()->GetPage(0));
689  aDestView.Paste(
690  *m_pModel,
692  nullptr, SdrInsertFlags::NONE);
693 
694  // put objects to right layer (see ScViewFunc::PasteDataFormat for SotClipboardFormatId::DRAWING)
695 
696  SdrPage* pPage = pDestModel->GetPage(0);
697  if (pPage)
698  {
699  SdrObjListIter aIter( pPage, SdrIterMode::DeepWithGroups );
700  SdrObject* pObject = aIter.Next();
701  while (pObject)
702  {
703  if ( dynamic_cast<const SdrUnoObj*>( pObject) != nullptr )
704  pObject->NbcSetLayer(SC_LAYER_CONTROLS);
705  else
706  pObject->NbcSetLayer(SC_LAYER_FRONT);
707  pObject = aIter.Next();
708  }
709  }
710 
711  tools::Rectangle aDestArea( Point(), m_aSrcSize );
712  pDocSh->SetVisArea( aDestArea );
713 
714  ScViewOptions aViewOpt( rDestDoc.GetViewOptions() );
715  aViewOpt.SetOption( VOPT_GRID, false );
716  rDestDoc.SetViewOptions( aViewOpt );
717 
718  ScViewData aViewData( *pDocSh, nullptr );
719  aViewData.SetTabNo( 0 );
720  aViewData.SetScreen( aDestArea );
721  aViewData.SetCurX( 0 );
722  aViewData.SetCurY( 0 );
723  pDocSh->UpdateOle(aViewData, true);
724 }
725 
726 const css::uno::Sequence< sal_Int8 >& ScDrawTransferObj::getUnoTunnelId()
727 {
728  static const comphelper::UnoIdInit theScDrawTransferObjUnoTunnelId;
729  return theScDrawTransferObjUnoTunnelId.getSeq();
730 }
731 
732 sal_Int64 SAL_CALL ScDrawTransferObj::getSomething( const css::uno::Sequence< sal_Int8 >& rId )
733 {
736 }
737 
738 /* 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:87
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:266
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:621
virtual SdrObjKind GetObjIdentifier() const
const ScDragData & GetDragData() const
Definition: scmod.hxx:141
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:236
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
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:616
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:420
static void lcl_InitMarks(SdrMarkView &rDest, const SdrMarkView &rSource, SCTAB nTab)
Definition: drwtrans.cxx:581
int nCount
virtual void DragFinished(sal_Int8 nDropAction) override
Definition: drwtrans.cxx:557
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:335
SotClipboardFormatId
GDIMetaFile GetMarkedObjMetaFile(bool bNoVDevIfOneMtfMarked=false) const
virtual sal_Int64 SAL_CALL getSomething(const css::uno::Sequence< sal_Int8 > &rId) override
Definition: drwtrans.cxx:732
const css::uno::Sequence< sal_Int8 > & getSeq() const
SdrObject * GetMarkedSdrObj() const
void SetTabNo(SCTAB nNewTab)
Definition: viewdata.cxx:2315
void MarkAllObj(SdrPageView *pPV=nullptr)
bool SetGraphic(const Graphic &rGraphic)
SC_DLLPUBLIC ScDrawLayer * GetDrawLayer()
Definition: document.hxx:1058
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:250
void CreateOLEData()
Definition: drwtrans.cxx:649
SC_DLLPUBLIC void SetViewOptions(const ScViewOptions &rOpt)
Definition: documen3.cxx:1963
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
virtual SdrInventor GetObjInventor() const
SC_DLLPUBLIC const ScViewOptions & GetViewOptions() const
Definition: documen3.cxx:1957
SdrObject * Next()
static SotClipboardFormatId GetFormat(const css::datatransfer::DataFlavor &rFlavor)
void UpdateOle(const ScViewData &rViewData, bool bSnapSize=false)
Definition: docsh6.cxx:152
constexpr Size GetSize() const
std::unique_ptr< SdrView > m_pDragSourceView
Definition: drwtrans.hxx:54
sal_uInt32 GetHeight() const
const OUString & GetShellID() const
Definition: drwtrans.cxx:626
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:606
#define ERRCODE_NONE
constexpr tools::Long Height() const
std::unique_ptr< INetBookmark > m_pBookmark
Definition: drwtrans.hxx:48
sal_Int64 getSomethingImpl(const css::uno::Sequence< sal_Int8 > &rId, T *pThis, FallbackToGetSomethingOf< Base >={})
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:726
Sequence< sal_Int8 > aSeq
const ScDocument & GetDocument() const
Definition: docsh.hxx:220
SfxObjectShellRef m_aDocShellRef
Definition: drwtrans.hxx:43
BitmapEx GetMarkedObjBitmapEx(bool bNoVDevIfOneBmpMarked=false, const sal_uInt32 nMaximumQuadraticPixels=500000, const std::optional< Size > &rTargetDPI=std::nullopt) const
void SetDrawPersist(const SfxObjectShellRef &rRef)
Definition: drwtrans.cxx:576
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:2996
bool SetAny(const css::uno::Any &rAny)
void ResetDragObject()
Definition: scmod.cxx:578
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
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:598
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:631
virtual void NbcSetLayer(SdrLayerID nLayer)
const DataFlavorExVector & GetDataFlavorExVector() const
SfxMedium * GetMedium() const