LibreOffice Module svx (master)  1
svdxcgv.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 <vector>
21 #include <unordered_set>
22 #include <editeng/editdata.hxx>
23 #include <rtl/strbuf.hxx>
24 #include <svx/xfillit0.hxx>
25 #include <svx/xlineit0.hxx>
26 #include <svx/svdxcgv.hxx>
27 #include <svx/svdoutl.hxx>
28 #include <svx/svdundo.hxx>
29 #include <svx/svdograf.hxx>
30 #include <svx/svdoole2.hxx>
31 #include <svx/svdorect.hxx>
32 #include <svx/svdopage.hxx>
33 #include <svx/svdpage.hxx>
34 #include <svx/svdpagv.hxx>
35 #include <svx/svdtrans.hxx>
36 #include <svx/strings.hrc>
37 #include <svx/dialmgr.hxx>
38 #include <tools/bigint.hxx>
39 #include <clonelist.hxx>
40 #include <vcl/virdev.hxx>
41 #include <svl/style.hxx>
42 #include <fmobj.hxx>
50 #include <svx/svdotable.hxx>
51 #include <sal/log.hxx>
52 #include <osl/diagnose.h>
53 #include <comphelper/lok.hxx>
54 
55 using namespace com::sun::star;
56 
58  SdrModel& rSdrModel,
59  OutputDevice* pOut)
60 : SdrObjEditView(rSdrModel, pOut)
61 {
62 }
63 
65 {
66  bool bRet(false);
67 
68  if(!maMaxWorkArea.IsEmpty())
69  {
70  if(rPt.X()<maMaxWorkArea.Left())
71  {
72  rPt.setX( maMaxWorkArea.Left() );
73  bRet = true;
74  }
75 
76  if(rPt.X()>maMaxWorkArea.Right())
77  {
78  rPt.setX( maMaxWorkArea.Right() );
79  bRet = true;
80  }
81 
82  if(rPt.Y()<maMaxWorkArea.Top())
83  {
84  rPt.setY( maMaxWorkArea.Top() );
85  bRet = true;
86  }
87 
88  if(rPt.Y()>maMaxWorkArea.Bottom())
89  {
90  rPt.setY( maMaxWorkArea.Bottom() );
91  bRet = true;
92  }
93  }
94  return bRet;
95 }
96 
97 void SdrExchangeView::ImpGetPasteObjList(Point& /*rPos*/, SdrObjList*& rpLst)
98 {
99  if (rpLst==nullptr)
100  {
101  SdrPageView* pPV = GetSdrPageView();
102 
103  if (pPV!=nullptr) {
104  rpLst=pPV->GetObjList();
105  }
106  }
107 }
108 
109 bool SdrExchangeView::ImpGetPasteLayer(const SdrObjList* pObjList, SdrLayerID& rLayer) const
110 {
111  bool bRet=false;
112  rLayer=SdrLayerID(0);
113  if (pObjList!=nullptr) {
114  const SdrPage* pPg=pObjList->getSdrPageFromSdrObjList();
115  if (pPg!=nullptr) {
116  rLayer=pPg->GetLayerAdmin().GetLayerID(maActualLayer);
117  if (rLayer==SDRLAYER_NOTFOUND) rLayer=SdrLayerID(0);
118  SdrPageView* pPV = GetSdrPageView();
119  if (pPV!=nullptr) {
120  bRet=!pPV->GetLockedLayers().IsSet(rLayer) && pPV->GetVisibleLayers().IsSet(rLayer);
121  }
122  }
123  }
124  return bRet;
125 }
126 
127 bool SdrExchangeView::Paste(const OUString& rStr, const Point& rPos, SdrObjList* pLst, SdrInsertFlags nOptions)
128 {
129  if (rStr.isEmpty())
130  return false;
131 
132  Point aPos(rPos);
133  ImpGetPasteObjList(aPos,pLst);
134  ImpLimitToWorkArea( aPos );
135  if (pLst==nullptr) return false;
136  SdrLayerID nLayer;
137  if (!ImpGetPasteLayer(pLst,nLayer)) return false;
139  if (bUnmark) UnmarkAllObj();
140  tools::Rectangle aTextRect(0,0,500,500);
141  SdrPage* pPage=pLst->getSdrPageFromSdrObjList();
142  if (pPage!=nullptr) {
143  aTextRect.SetSize(pPage->GetSize());
144  }
145  SdrRectObj* pObj = new SdrRectObj(
148  aTextRect);
149 
150  pObj->SetLayer(nLayer);
151  pObj->NbcSetText(rStr); // SetText before SetAttr, else SetAttr doesn't work!
152  if (mpDefaultStyleSheet!=nullptr) pObj->NbcSetStyleSheet(mpDefaultStyleSheet, false);
153 
155 
156  SfxItemSet aTempAttr(mpModel->GetItemPool()); // no fill, no line
157  aTempAttr.Put(XLineStyleItem(drawing::LineStyle_NONE));
158  aTempAttr.Put(XFillStyleItem(drawing::FillStyle_NONE));
159 
160  pObj->SetMergedItemSet(aTempAttr);
161 
162  pObj->FitFrameToTextSize();
163  Size aSiz(pObj->GetLogicRect().GetSize());
164  MapUnit eMap=mpModel->GetScaleUnit();
166  ImpPasteObject(pObj,*pLst,aPos,aSiz,MapMode(eMap,Point(0,0),aMap,aMap),nOptions);
167  return true;
168 }
169 
170 bool SdrExchangeView::Paste(SvStream& rInput, EETextFormat eFormat, const Point& rPos, SdrObjList* pLst, SdrInsertFlags nOptions)
171 {
172  Point aPos(rPos);
173  ImpGetPasteObjList(aPos,pLst);
174  ImpLimitToWorkArea( aPos );
175  if (pLst==nullptr) return false;
176  SdrLayerID nLayer;
177  if (!ImpGetPasteLayer(pLst,nLayer)) return false;
179  if (bUnmark) UnmarkAllObj();
180  tools::Rectangle aTextRect(0,0,500,500);
181  SdrPage* pPage=pLst->getSdrPageFromSdrObjList();
182  if (pPage!=nullptr) {
183  aTextRect.SetSize(pPage->GetSize());
184  }
185  SdrRectObj* pObj = new SdrRectObj(
188  aTextRect);
189 
190  pObj->SetLayer(nLayer);
191  if (mpDefaultStyleSheet!=nullptr) pObj->NbcSetStyleSheet(mpDefaultStyleSheet, false);
192 
194 
195  SfxItemSet aTempAttr(mpModel->GetItemPool()); // no fill, no line
196  aTempAttr.Put(XLineStyleItem(drawing::LineStyle_NONE));
197  aTempAttr.Put(XFillStyleItem(drawing::FillStyle_NONE));
198 
199  pObj->SetMergedItemSet(aTempAttr);
200 
201  pObj->NbcSetText(rInput,OUString(),eFormat);
202  pObj->FitFrameToTextSize();
203  Size aSiz(pObj->GetLogicRect().GetSize());
204  MapUnit eMap=mpModel->GetScaleUnit();
206  ImpPasteObject(pObj,*pLst,aPos,aSiz,MapMode(eMap,Point(0,0),aMap,aMap),nOptions);
207 
208  // b4967543
209  if(pObj->GetOutlinerParaObject())
210  {
212  rOutliner.SetText(*pObj->GetOutlinerParaObject());
213 
214  if(1 == rOutliner.GetParagraphCount())
215  {
216  SfxStyleSheet* pCandidate = rOutliner.GetStyleSheet(0);
217 
218  if(pCandidate)
219  {
220  if(pObj->getSdrModelFromSdrObject().GetStyleSheetPool() == pCandidate->GetPool())
221  {
222  pObj->NbcSetStyleSheet(pCandidate, true);
223  }
224  }
225  }
226  }
227 
228  return true;
229 }
230 
232  const SdrModel& rMod, const Point& rPos, SdrObjList* pLst, SdrInsertFlags nOptions)
233 {
234  const SdrModel* pSrcMod=&rMod;
235  if (pSrcMod==mpModel)
236  return false; // this can't work, right?
237 
238  const bool bUndo = IsUndoEnabled();
239 
240  if( bUndo )
241  BegUndo(SvxResId(STR_ExchangePaste));
242 
243  if( mxSelectionController.is() && mxSelectionController->PasteObjModel( rMod ) )
244  {
245  if( bUndo )
246  EndUndo();
247  return true;
248  }
249 
250  Point aPos(rPos);
251  ImpGetPasteObjList(aPos,pLst);
252  SdrPageView* pMarkPV=nullptr;
253  SdrPageView* pPV = GetSdrPageView();
254 
255  if(pPV && pPV->GetObjList() == pLst )
256  pMarkPV=pPV;
257 
258  ImpLimitToWorkArea( aPos );
259  if (pLst==nullptr)
260  return false;
261 
263  if (bUnmark)
264  UnmarkAllObj();
265 
266  // Rescale, if the Model uses a different MapUnit.
267  // Calculate the necessary factors first.
268  MapUnit eSrcUnit=pSrcMod->GetScaleUnit();
269  MapUnit eDstUnit=mpModel->GetScaleUnit();
270  bool bResize=eSrcUnit!=eDstUnit;
271  Fraction aXResize,aYResize;
272  Point aPt0;
273  if (bResize)
274  {
275  FrPair aResize(GetMapFactor(eSrcUnit,eDstUnit));
276  aXResize=aResize.X();
277  aYResize=aResize.Y();
278  }
279  SdrObjList* pDstLst=pLst;
280  sal_uInt16 nPg,nPgCount=pSrcMod->GetPageCount();
281  for (nPg=0; nPg<nPgCount; nPg++)
282  {
283  const SdrPage* pSrcPg=pSrcMod->GetPage(nPg);
284 
285  // Use SnapRect, not BoundRect here
286  tools::Rectangle aR=pSrcPg->GetAllObjSnapRect();
287 
288  if (bResize)
289  ResizeRect(aR,aPt0,aXResize,aYResize);
290  Point aDist(aPos-aR.Center());
291  Size aSiz(aDist.X(),aDist.Y());
292  size_t nCloneErrCnt = 0;
293  const size_t nObjCount = pSrcPg->GetObjCount();
294  bool bMark = pMarkPV!=nullptr && !IsTextEdit() && (nOptions&SdrInsertFlags::DONTMARK)==SdrInsertFlags::NONE;
295 
296  // #i13033#
297  // New mechanism to re-create the connections of cloned connectors
298  CloneList aCloneList;
299  std::unordered_set<rtl::OUString> aNameSet;
300  for (size_t nOb=0; nOb<nObjCount; ++nOb)
301  {
302  const SdrObject* pSrcOb=pSrcPg->GetObj(nOb);
303 
304  SdrObject* pNewObj(pSrcOb->CloneSdrObject(*mpModel));
305 
306  if (pNewObj!=nullptr)
307  {
308  if(bResize)
309  {
310  pNewObj->getSdrModelFromSdrObject().SetPasteResize(true);
311  pNewObj->NbcResize(aPt0,aXResize,aYResize);
312  pNewObj->getSdrModelFromSdrObject().SetPasteResize(false);
313  }
314 
315  // #i39861#
316  pNewObj->NbcMove(aSiz);
317 
318  const SdrPage* pPg = pDstLst->getSdrPageFromSdrObjList();
319 
320  if(pPg)
321  {
322  // #i72535#
323  const SdrLayerAdmin& rAd = pPg->GetLayerAdmin();
324  SdrLayerID nLayer(0);
325 
326  if(dynamic_cast<const FmFormObj*>( pNewObj) != nullptr)
327  {
328  // for FormControls, force to form layer
329  nLayer = rAd.GetLayerID(rAd.GetControlLayerName());
330  }
331  else
332  {
333  nLayer = rAd.GetLayerID(maActualLayer);
334  }
335 
336  if(SDRLAYER_NOTFOUND == nLayer)
337  {
338  nLayer = SdrLayerID(0);
339  }
340 
341  pNewObj->SetLayer(nLayer);
342  }
343 
344  pDstLst->InsertObjectThenMakeNameUnique(pNewObj, aNameSet);
345 
346  if( bUndo )
347  AddUndo(getSdrModelFromSdrView().GetSdrUndoFactory().CreateUndoNewObject(*pNewObj));
348 
349  if (bMark) {
350  // Don't already set Markhandles!
351  // That is instead being done by ModelHasChanged in MarkView.
352  MarkObj(pNewObj,pMarkPV,false,true);
353  }
354 
355  // #i13033#
356  aCloneList.AddPair(pSrcOb, pNewObj);
357  }
358  else
359  {
360  nCloneErrCnt++;
361  }
362  }
363 
364  // #i13033#
365  // New mechanism to re-create the connections of cloned connectors
366  aCloneList.CopyConnections();
367 
368  if(0 != nCloneErrCnt)
369  {
370 #ifdef DBG_UTIL
371  OStringBuffer aStr("SdrExchangeView::Paste(): Error when cloning ");
372 
373  if(nCloneErrCnt == 1)
374  {
375  aStr.append("a drawing object.");
376  }
377  else
378  {
379  aStr.append(static_cast<sal_Int32>(nCloneErrCnt));
380  aStr.append(" drawing objects.");
381  }
382 
383  aStr.append(" Not copying object connectors.");
384 
385  OSL_FAIL(aStr.getStr());
386 #endif
387  }
388  }
389 
390  if( bUndo )
391  EndUndo();
392 
393  return true;
394 }
395 
396 void SdrExchangeView::ImpPasteObject(SdrObject* pObj, SdrObjList& rLst, const Point& rCenter, const Size& rSiz, const MapMode& rMap, SdrInsertFlags nOptions)
397 {
398  BigInt nSizX(rSiz.Width());
399  BigInt nSizY(rSiz.Height());
400  MapUnit eSrcMU=rMap.GetMapUnit();
401  MapUnit eDstMU=mpModel->GetScaleUnit();
402  FrPair aMapFact(GetMapFactor(eSrcMU,eDstMU));
403  Fraction aDstFr(mpModel->GetScaleFraction());
404  nSizX *= double(aMapFact.X() * rMap.GetScaleX() * aDstFr);
405  nSizX *= aDstFr.GetDenominator();
406  nSizY *= double(aMapFact.Y() * rMap.GetScaleY());
407  nSizY /= aDstFr.GetNumerator();
408  tools::Long xs=nSizX;
409  tools::Long ys=nSizY;
410  // set the pos to 0, 0 for online case
412  Point aPos(isLOK ? 0 : rCenter.X()-xs/2, isLOK ? 0 : rCenter.Y()-ys/2);
413  tools::Rectangle aR(aPos.X(),aPos.Y(),aPos.X()+xs,aPos.Y()+ys);
414  pObj->SetLogicRect(aR);
415  rLst.InsertObject(pObj, SAL_MAX_SIZE);
416 
417  if( IsUndoEnabled() )
418  AddUndo(getSdrModelFromSdrView().GetSdrUndoFactory().CreateUndoNewObject(*pObj));
419 
420  SdrPageView* pMarkPV=nullptr;
421  SdrPageView* pPV = GetSdrPageView();
422 
423  if(pPV && pPV->GetObjList()==&rLst)
424  pMarkPV=pPV;
425 
426  bool bMark = pMarkPV!=nullptr && !IsTextEdit() && (nOptions&SdrInsertFlags::DONTMARK)==SdrInsertFlags::NONE;
427  if (bMark)
428  { // select object the first PageView we found
429  MarkObj(pObj,pMarkPV);
430  }
431 }
432 
433 BitmapEx SdrExchangeView::GetMarkedObjBitmapEx(bool bNoVDevIfOneBmpMarked, const sal_uInt32 nMaximumQuadraticPixels, const std::optional<Size>& rTargetDPI) const
434 {
435  BitmapEx aBmp;
436 
437  if( AreObjectsMarked() )
438  {
439  if(1 == GetMarkedObjectCount())
440  {
441  if(bNoVDevIfOneBmpMarked)
442  {
443  SdrObject* pGrafObjTmp = GetMarkedObjectByIndex( 0 );
444  SdrGrafObj* pGrafObj = dynamic_cast<SdrGrafObj*>( pGrafObjTmp );
445 
446  if( pGrafObj && ( pGrafObj->GetGraphicType() == GraphicType::Bitmap ) )
447  {
448  aBmp = pGrafObj->GetTransformedGraphic().GetBitmapEx();
449  }
450  }
451  else
452  {
453  const SdrGrafObj* pSdrGrafObj = dynamic_cast< const SdrGrafObj* >(GetMarkedObjectByIndex(0));
454 
455  if(pSdrGrafObj && pSdrGrafObj->isEmbeddedVectorGraphicData())
456  {
457  aBmp = pSdrGrafObj->GetGraphic().getVectorGraphicData()->getReplacement();
458  }
459  }
460  }
461 
462  if( aBmp.IsEmpty() )
463  {
464  // choose conversion directly using primitives to bitmap to avoid
465  // rendering errors with tiled bitmap fills (these will be tiled in a
466  // in-between metafile, but tend to show 'gaps' since the target is *no*
467  // bitmap rendering)
468  ::std::vector< SdrObject* > aSdrObjects(GetMarkedObjects());
469  const sal_uInt32 nCount(aSdrObjects.size());
470 
471  if(nCount)
472  {
473  // collect sub-primitives as group objects, thus no expensive append
474  // to existing sequence is needed
476 
477  for(sal_uInt32 a(0); a < nCount; a++)
478  {
479  SdrObject* pCandidate = aSdrObjects[a];
480  SdrGrafObj* pSdrGrafObj = dynamic_cast< SdrGrafObj* >(pCandidate);
481 
482  if(pSdrGrafObj)
483  {
484  // #122753# To ensure existence of graphic content, force swap in
485  pSdrGrafObj->ForceSwapIn();
486  }
487 
491  std::move(xRetval));
492  }
493 
494  // get logic range
495  const drawinglayer::geometry::ViewInformation2D aViewInformation2D;
496  const basegfx::B2DRange aRange(xPrimitives.getB2DRange(aViewInformation2D));
497 
498  if(!aRange.isEmpty())
499  {
500  o3tl::Length eRangeUnit = o3tl::Length::mm100;
501 
502  if (GetModel()->IsWriter())
503  {
504  eRangeUnit = o3tl::Length::twip;
505  }
506 
507  // if we have geometry and it has a range, convert to BitmapEx using
508  // common tooling
510  std::move(xPrimitives),
511  aRange,
512  nMaximumQuadraticPixels,
513  eRangeUnit,
514  rTargetDPI);
515  }
516  }
517  }
518  }
519 
520  return aBmp;
521 }
522 
523 
524 GDIMetaFile SdrExchangeView::GetMarkedObjMetaFile(bool bNoVDevIfOneMtfMarked) const
525 {
526  GDIMetaFile aMtf;
527 
528  if( AreObjectsMarked() )
529  {
531  Size aBoundSize( aBound.GetWidth(), aBound.GetHeight() );
533 
534  if( bNoVDevIfOneMtfMarked )
535  {
536  SdrObject* pGrafObjTmp = GetMarkedObjectByIndex( 0 );
537  SdrGrafObj* pGrafObj = ( GetMarkedObjectCount() ==1 ) ? dynamic_cast<SdrGrafObj*>( pGrafObjTmp ) : nullptr;
538 
539  if( pGrafObj )
540  {
541  Graphic aGraphic( pGrafObj->GetTransformedGraphic() );
542 
543  // #119735# just use GetGDIMetaFile, it will create a buffered version of contained bitmap now automatically
544  aMtf = aGraphic.GetGDIMetaFile();
545  }
546  }
547 
548  if( !aMtf.GetActionSize() )
549  {
551  const Size aDummySize(2, 2);
552 
553  pOut->SetOutputSizePixel(aDummySize);
554  pOut->EnableOutput(false);
555  pOut->SetMapMode(aMap);
556  aMtf.Clear();
557  aMtf.Record(pOut);
558 
559  DrawMarkedObj(*pOut);
560 
561  aMtf.Stop();
562  aMtf.WindStart();
563 
564  // moving the result is more reliable then setting a relative MapMode at the VDev (used
565  // before), also see #i99268# in GetObjGraphic() below. Some draw actions at
566  // the OutDev are simply not handled correctly when a MapMode is set at the
567  // target device, e.g. MetaFloatTransparentAction. Even the Move for this action
568  // was missing the manipulation of the embedded Metafile
569  aMtf.Move(-aBound.Left(), -aBound.Top());
570 
571  aMtf.SetPrefMapMode( aMap );
572 
573  // removed PrefSize extension. It is principally wrong to set a reduced size at
574  // the created MetaFile. The mentioned errors occur at output time since the integer
575  // MapModes from VCL lead to errors. It is now corrected in the VCLRenderer for
576  // primitives (and may later be done in breaking up a MetaFile to primitives)
577  aMtf.SetPrefSize(aBoundSize);
578  }
579  }
580 
581  return aMtf;
582 }
583 
584 
586 {
587  Graphic aRet;
588 
589  if( AreObjectsMarked() )
590  {
591  if( ( 1 == GetMarkedObjectCount() ) && GetSdrMarkByIndex( 0 ) )
593  else
594  aRet = GetMarkedObjMetaFile();
595  }
596 
597  return aRet;
598 }
599 
600 
602 {
603  Graphic aRet;
604 
605  // try to get a graphic from the object first
606  const SdrGrafObj* pSdrGrafObj(dynamic_cast< const SdrGrafObj* >(&rSdrObject));
607  const SdrOle2Obj* pSdrOle2Obj(dynamic_cast< const SdrOle2Obj* >(&rSdrObject));
608 
609  if(pSdrGrafObj)
610  {
611  if(pSdrGrafObj->isEmbeddedVectorGraphicData())
612  {
613  // get Metafile for Svg content
614  aRet = pSdrGrafObj->getMetafileFromEmbeddedVectorGraphicData();
615  }
616  else
617  {
618  // Make behaviour coherent with metafile
619  // recording below (which of course also takes
620  // view-transformed objects)
621  aRet = pSdrGrafObj->GetTransformedGraphic();
622  }
623  }
624  else if(pSdrOle2Obj)
625  {
626  if(pSdrOle2Obj->GetGraphic())
627  {
628  aRet = *pSdrOle2Obj->GetGraphic();
629  }
630  }
631 
632  // if graphic could not be retrieved => go the hard way and create a MetaFile
633  if((GraphicType::NONE == aRet.GetType()) || (GraphicType::Default == aRet.GetType()))
634  {
636  GDIMetaFile aMtf;
637  const tools::Rectangle aBoundRect(rSdrObject.GetCurrentBoundRect());
638  const MapMode aMap(rSdrObject.getSdrModelFromSdrObject().GetScaleUnit(),
639  Point(),
642 
643  pOut->EnableOutput(false);
644  pOut->SetMapMode(aMap);
645  aMtf.Record(pOut);
646  rSdrObject.SingleObjectPainter(*pOut);
647  aMtf.Stop();
648  aMtf.WindStart();
649 
650  // #i99268# replace the original offset from using XOutDev's SetOffset
651  // NOT (as tried with #i92760#) with another MapMode which gets recorded
652  // by the Metafile itself (what always leads to problems), but by
653  // moving the result directly
654  aMtf.Move(-aBoundRect.Left(), -aBoundRect.Top());
655  aMtf.SetPrefMapMode(aMap);
656  aMtf.SetPrefSize(aBoundRect.GetSize());
657 
658  if(aMtf.GetActionSize())
659  {
660  aRet = aMtf;
661  }
662  }
663 
664  return aRet;
665 }
666 
667 
668 ::std::vector< SdrObject* > SdrExchangeView::GetMarkedObjects() const
669 {
671  ::std::vector< SdrObject* > aRetval;
672 
673  ::std::vector< ::std::vector< SdrMark* > > aObjVectors( 2 );
674  ::std::vector< SdrMark* >& rObjVector1 = aObjVectors[ 0 ];
675  ::std::vector< SdrMark* >& rObjVector2 = aObjVectors[ 1 ];
676  const SdrLayerAdmin& rLayerAdmin = mpModel->GetLayerAdmin();
677  const SdrLayerID nControlLayerId = rLayerAdmin.GetLayerID( rLayerAdmin.GetControlLayerName() );
678 
679  for( size_t n = 0, nCount = GetMarkedObjectCount(); n < nCount; ++n )
680  {
681  SdrMark* pMark = GetSdrMarkByIndex( n );
682 
683  // paint objects on control layer on top of all other objects
684  if( nControlLayerId == pMark->GetMarkedSdrObj()->GetLayer() )
685  rObjVector2.push_back( pMark );
686  else
687  rObjVector1.push_back( pMark );
688  }
689 
690  for(const std::vector<SdrMark*> & rObjVector : aObjVectors)
691  {
692  for(SdrMark* pMark : rObjVector)
693  {
694  aRetval.push_back(pMark->GetMarkedSdrObj());
695  }
696  }
697 
698  return aRetval;
699 }
700 
701 
703 {
704  ::std::vector< SdrObject* > aSdrObjects(GetMarkedObjects());
705 
706  if(!aSdrObjects.empty())
707  {
708  sdr::contact::ObjectContactOfObjListPainter aPainter(rOut, std::move(aSdrObjects), aSdrObjects[0]->getSdrPageFromSdrObject());
709  sdr::contact::DisplayInfo aDisplayInfo;
710 
711  // do processing
712  aPainter.ProcessDisplay(aDisplayInfo);
713  }
714 }
715 
716 std::unique_ptr<SdrModel> SdrExchangeView::CreateMarkedObjModel() const
717 {
718  // Sorting the MarkList here might be problematic in the future, so
719  // use a copy.
721  std::unique_ptr<SdrModel> pNewModel(mpModel->AllocModel());
722  rtl::Reference<SdrPage> pNewPage = pNewModel->AllocPage(false);
723  pNewModel->InsertPage(pNewPage.get());
724  ::std::vector< SdrObject* > aSdrObjects(GetMarkedObjects());
725 
726  // #i13033#
727  // New mechanism to re-create the connections of cloned connectors
728  CloneList aCloneList;
729 
730  for(SdrObject* pObj : aSdrObjects)
731  {
732  SdrObject* pNewObj(nullptr);
733 
734  if(nullptr != dynamic_cast< const SdrPageObj* >(pObj))
735  {
736  // convert SdrPageObj's to a graphic representation, because
737  // virtual connection to referenced page gets lost in new model
738  pNewObj = new SdrGrafObj(
739  *pNewModel,
740  GetObjGraphic(*pObj),
741  pObj->GetLogicRect());
742  }
743  else if(nullptr != dynamic_cast< const sdr::table::SdrTableObj* >(pObj))
744  {
745  // check if we have a valid selection *different* from whole table
746  // being selected
747  if(mxSelectionController.is())
748  {
749  pNewObj = mxSelectionController->GetMarkedSdrObjClone(*pNewModel);
750  }
751  }
752 
753  if(nullptr == pNewObj)
754  {
755  // not cloned yet
756  if(pObj->GetObjIdentifier() == SdrObjKind::OLE2 && nullptr == mpModel->GetPersist())
757  {
758  // tdf#125520 - former fix was wrong, the SdrModel
759  // has to have a GetPersist() already, see task.
760  // We can still warn here when this is not the case
761  SAL_WARN( "svx", "OLE gets cloned Persist, EmbeddedObjectContainer will not be copied" );
762  }
763 
764  // use default way
765  pNewObj = pObj->CloneSdrObject(*pNewModel);
766  }
767 
768  if(pNewObj)
769  {
770  pNewPage->InsertObject(pNewObj, SAL_MAX_SIZE);
771 
772  // #i13033#
773  aCloneList.AddPair(pObj, pNewObj);
774  }
775  }
776 
777  // #i13033#
778  // New mechanism to re-create the connections of cloned connectors
779  aCloneList.CopyConnections();
780 
781  return pNewModel;
782 }
783 
784 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SdrExchangeView(SdrModel &rSdrModel, OutputDevice *pOut)
Definition: svdxcgv.cxx:57
const Fraction & GetScaleX() const
void UnmarkAllObj(SdrPageView const *pPV=nullptr)
Definition: svdmrkv.cxx:2550
void FitFrameToTextSize()
Definition: svdotext.cxx:216
GDIMetaFile getMetafileFromEmbeddedVectorGraphicData() const
Definition: svdograf.cxx:866
virtual const tools::Rectangle & GetCurrentBoundRect() const
Definition: svdobj.cxx:949
void ImpGetPasteObjList(Point &rPos, SdrObjList *&rpLst)
Definition: svdxcgv.cxx:97
void SortMarkedObjects() const
Definition: svdmrkv.hxx:265
Graphic GetAllMarkedGraphic() const
Definition: svdxcgv.cxx:585
constexpr tools::Long Left() const
virtual bool Paste(const SdrModel &rMod, const Point &rPos, SdrObjList *pLst, SdrInsertFlags nOptions)
Definition: svdxcgv.cxx:231
const Fraction & GetScaleFraction() const
Definition: svdmodel.hxx:372
bool AreObjectsMarked() const
Definition: svdmrkv.hxx:266
bool IsUndoEnabled() const
Definition: svdedtv.cxx:1073
long Long
sal_Int64 n
periodic cubic Spline (ni)
SdrObject * GetObj(size_t nNum) const
Definition: svdpage.cxx:807
size_t GetObjCount() const
Definition: svdpage.cxx:801
SfxStyleSheet * GetStyleSheet(sal_Int32 nPara)
void SetPrefSize(const Size &rSize)
void Clear()
void BegUndo()
Definition: svdedtv.hxx:178
tools::Rectangle maMaxWorkArea
Definition: svdpntv.hxx:141
sal_Int32 GetParagraphCount() const
virtual void InsertObject(SdrObject *pObj, size_t nPos=SAL_MAX_SIZE)
Definition: svdpage.cxx:329
GraphicType GetGraphicType() const
Definition: svdograf.cxx:404
sdr::contact::ViewContact & GetViewContact() const
Definition: svdobj.cxx:251
EETextFormat
Rectangle objects (rectangle, circle, ...)
Definition: svdorect.hxx:38
SdrModel * mpModel
Definition: svdpntv.hxx:125
constexpr tools::Long Width() const
HashMap_OWString_Interface aMap
MapUnit GetScaleUnit() const
Definition: svdmodel.hxx:370
void Record(OutputDevice *pOutDev)
static Graphic GetObjGraphic(const SdrObject &rSdrObject)
Generate a Graphic for the given draw object.
Definition: svdxcgv.cxx:601
const Fraction & GetScaleY() const
void ForceSwapIn() const
Definition: svdograf.cxx:506
int nCount
OUString SvxResId(TranslateId aId)
Definition: dialmgr.cxx:24
oslFileHandle & pOut
constexpr tools::Long GetWidth() const
void SetMergedItemSet(const SfxItemSet &rSet, bool bClearAllItems=false)
Definition: svdobj.cxx:1997
void EndUndo()
Definition: svdedtv.cxx:303
GDIMetaFile GetMarkedObjMetaFile(bool bNoVDevIfOneMtfMarked=false) const
Definition: svdxcgv.cxx:524
SdrOutliner & GetHitTestOutliner() const
Definition: svdmodel.hxx:322
constexpr bool IsEmpty() const
virtual void ProcessDisplay(DisplayInfo &rDisplayInfo) override
foreign graphic (StarView Graphic)
bool ImpLimitToWorkArea(Point &rPt) const
Definition: svdxcgv.cxx:64
SdrObjList * GetObjList() const
Return current List.
Definition: svdpagv.hxx:169
SdrObject * GetMarkedSdrObj() const
Definition: svdmark.hxx:68
SfxStyleSheetBasePool * GetPool()
Everything a View needs to know about a selected object.
Definition: svdmark.hxx:44
SfxStyleSheet * mpDefaultStyleSheet
Definition: svdpntv.hxx:128
bool IsEmpty() const
const SdrLayerIDSet & GetVisibleLayers() const
Definition: svdpagv.hxx:210
void AddUndo(std::unique_ptr< SdrUndoAction > pUndo)
Definition: svdedtv.hxx:182
void ResizeRect(tools::Rectangle &rRect, const Point &rRef, const Fraction &rxFact, const Fraction &ryFact)
Definition: svdtrans.cxx:38
virtual void SetLayer(SdrLayerID nLayer)
Definition: svdobj.cxx:690
const OUString & GetControlLayerName() const
Definition: svdlayer.hxx:149
void ImpPasteObject(SdrObject *pObj, SdrObjList &rLst, const Point &rCenter, const Size &rSiz, const MapMode &rMap, SdrInsertFlags nOptions)
Definition: svdxcgv.cxx:396
Graphic GetTransformedGraphic(SdrGrafObjTransformsAttrs nTransformFlags=SdrGrafObjTransformsAttrs::ALL) const
Definition: svdograf.cxx:388
virtual std::unique_ptr< SdrModel > CreateMarkedObjModel() const
Definition: svdxcgv.cxx:716
void SetText(const OutlinerParaObject &)
uno_Any a
GraphicType GetType() const
bool IsWriter() const
Definition: svdmodel.hxx:582
const Fraction & Y() const
Definition: svdtrans.hxx:233
void SingleObjectPainter(OutputDevice &rOut) const
Definition: svdobj.cxx:1047
size_t GetMarkedObjectCount() const
Definition: svdmrkv.hxx:264
const Graphic & GetGraphic() const
Definition: svdograf.cxx:383
Size GetSize() const
Definition: svdpage.cxx:1443
void SetSize(const Size &rSize)
const Fraction & X() const
Definition: svdtrans.hxx:232
const SdrPage * GetPage(sal_uInt16 nPgNum) const
Definition: svdmodel.cxx:1801
constexpr tools::Long Right() const
void CopyConnections() const
Definition: clonelist.cxx:70
friend class SdrGrafObj
Definition: svdpntv.hxx:118
SdrModel & getSdrModelFromSdrObject() const
Definition: svdobj.cxx:279
constexpr tools::Long Top() const
const SdrLayerAdmin & GetLayerAdmin() const
changing the layers does not set the modified-flag!
Definition: svdpage.cxx:1719
o3tl::strong_int< sal_Int16, struct SdrLayerIDTag > SdrLayerID
Definition: svdtypes.hxx:56
virtual void SetLogicRect(const tools::Rectangle &rRect)
Definition: svdobj.cxx:1694
void Move(tools::Long nX, tools::Long nY)
OUString maActualLayer
Definition: svdpntv.hxx:130
MapUnit GetMapUnit() const
constexpr SdrLayerID SDRLAYER_NOTFOUND(-1)
void InsertObjectThenMakeNameUnique(SdrObject *pObj)
Definition: svdpage.cxx:303
BitmapEx GetBitmapEx(const GraphicConversionParameters &rParameters=GraphicConversionParameters()) const
void WindStart()
tools::Rectangle GetMarkedObjBoundRect() const
Definition: svdmrkv.cxx:2605
This class represents an embedded or linked bitmap graphic object.
Definition: svdograf.hxx:67
Abstract DrawObject.
Definition: svdobj.hxx:259
SdrInsertFlags
Definition: svdedtv.hxx:58
constexpr Point Center() const
virtual SdrLayerID GetLayer() const
Definition: svdobj.cxx:668
constexpr tools::Long Bottom() const
void SetPasteResize(bool bOn)
Definition: svdmodel.hxx:273
const SdrLayerIDSet & GetLockedLayers() const
Definition: svdpagv.hxx:214
bool IsSet(SdrLayerID a) const
Definition: svdsob.hxx:69
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
constexpr Size GetSize() const
FrPair GetMapFactor(MapUnit eS, MapUnit eD)
Definition: svdtrans.cxx:603
void getViewIndependentPrimitive2DContainer(drawinglayer::primitive2d::Primitive2DDecompositionVisitor &rVisitor) const
virtual bool IsTextEdit() const final override
Definition: svdedxv.cxx:1694
sal_Int32 GetDenominator() const
bool ImpGetPasteLayer(const SdrObjList *pObjList, SdrLayerID &rLayer) const
Definition: svdxcgv.cxx:109
virtual SdrModel * AllocModel() const
Definition: svdmodel.cxx:585
constexpr tools::Long Height() const
virtual OutlinerParaObject * GetOutlinerParaObject() const override
Definition: svdotext.cxx:1330
::comphelper::IEmbeddedHelper * GetPersist() const
Definition: svdmodel.hxx:354
SfxStyleSheetBasePool * GetStyleSheetPool() const
Definition: svdmodel.hxx:541
virtual void DrawMarkedObj(OutputDevice &rOut) const
Definition: svdxcgv.cxx:702
void NbcSetText(const OUString &rStr)
Definition: svdotext.cxx:241
virtual SdrObject * CloneSdrObject(SdrModel &rTargetModel) const
Definition: svdobj.cxx:1070
virtual SdrPage * getSdrPageFromSdrObjList() const
Definition: svdpage.cxx:117
size_t GetActionSize() const
BitmapEx GetMarkedObjBitmapEx(bool bNoVDevIfOneBmpMarked=false, const sal_uInt32 nMaximumQuadraticPixels=500000, const std::optional< Size > &rTargetDPI=std::nullopt) const
Definition: svdxcgv.cxx:433
SdrObject * GetMarkedObjectByIndex(size_t nNum) const
Definition: svdmrkv.hxx:263
SdrPageView * GetSdrPageView() const
Definition: svdpntv.hxx:299
MapUnit
#define SAL_WARN(area, stream)
SdrModel & getSdrModelFromSdrView() const
Definition: svdpntv.hxx:257
const SfxItemPool & GetItemPool() const
Definition: svdmodel.hxx:317
basegfx::B2DRange getB2DRange(const geometry::ViewInformation2D &aViewInformation) const
bool MarkObj(const Point &rPnt, short nTol=-2, bool bToggle=false, bool bDeep=false)
Definition: svdmrkv.cxx:1920
SdrMark * GetSdrMarkByIndex(size_t nNum) const
Definition: svdmrkv.hxx:262
A SdrPage contains exactly one SdrObjList and a description of the physical page dimensions (size / m...
Definition: svdpage.hxx:373
::std::vector< SdrObject * > GetMarkedObjects() const
Definition: svdxcgv.cxx:668
void NbcSetStyleSheet(SfxStyleSheet *pNewStyleSheet, bool bDontRemoveHardAttr)
Definition: svdobj.cxx:2260
const std::shared_ptr< VectorGraphicData > & getVectorGraphicData() const
const SdrLayerAdmin & GetLayerAdmin() const
Definition: svdmodel.hxx:314
rtl::Reference< sdr::SelectionController > mxSelectionController
Definition: svdedxv.hxx:107
SdrLayerID GetLayerID(const OUString &rName) const
Definition: svdlayer.cxx:230
const tools::Rectangle & GetAllObjSnapRect() const
Definition: svdpage.cxx:728
BitmapEx convertPrimitive2DContainerToBitmapEx(primitive2d::Primitive2DContainer &&rSequence, const basegfx::B2DRange &rTargetRange, sal_uInt32 nMaximumQuadraticPixels, const o3tl::Length eTargetUnit, const std::optional< Size > &rTargetDPI)
SdrModel * GetModel() const
Definition: svdpntv.hxx:260
bool isEmbeddedVectorGraphicData() const
Definition: svdograf.cxx:861
SfxItemSet maDefaultAttr
Definition: svdpntv.hxx:142
aStr
sal_uInt16 GetPageCount() const
Definition: svdmodel.cxx:1811
const Graphic * GetGraphic() const
Definition: svdoole2.cxx:1631
void SetPrefMapMode(const MapMode &rMapMode)
constexpr tools::Long GetHeight() const
virtual const tools::Rectangle & GetLogicRect() const override
Definition: svdotxtr.cxx:69
void AddPair(const SdrObject *pOriginal, SdrObject *pClone)
Definition: clonelist.cxx:28