bump product version to 4.1.6.2
[LibreOffice.git] / svx / source / svdraw / svdxcgv.cxx
blob4d0ee93c2cb9aadabc971668c296d0fb70cd5f18
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <vector>
21 #include <editeng/editdata.hxx>
22 #include <editeng/editeng.hxx>
23 #include <rtl/strbuf.hxx>
24 #include <svx/xexch.hxx>
25 #include <svx/xflclit.hxx>
26 #include <svx/svdxcgv.hxx>
27 #include <svx/svdoutl.hxx>
28 #include <svx/svdetc.hxx>
29 #include <svx/svdundo.hxx>
30 #include <svx/svdograf.hxx>
31 #include <svx/svdoole2.hxx> // to not have OLE in SdrClipboardFormat
32 #include <svx/svdorect.hxx>
33 #include <svx/svdoedge.hxx> // for connectors via the clipboard
34 #include <svx/svdopage.hxx> // for connectors via the clipboard
35 #include <svx/svdpage.hxx>
36 #include <svx/svdpagv.hxx>
37 #include <svx/svdtrans.hxx> // for GetMapFactor, to rescale at PasteModel
38 #include "svx/svdstr.hrc" // names taken from the resource
39 #include "svx/svdglob.hxx" // StringCache
40 #include "svx/xoutbmp.hxx"
41 #include <vcl/metaact.hxx>
42 #include <svl/poolitem.hxx>
43 #include <svl/itempool.hxx>
44 #include <tools/bigint.hxx>
45 #include <sot/formats.hxx>
46 #include <clonelist.hxx>
47 #include <vcl/virdev.hxx>
48 #include <svl/style.hxx>
49 #include <fmobj.hxx>
50 #include <vcl/svgdata.hxx>
52 ////////////////////////////////////////////////////////////////////////////////////////////////////
54 SdrExchangeView::SdrExchangeView(SdrModel* pModel1, OutputDevice* pOut):
55 SdrObjEditView(pModel1,pOut)
59 sal_Bool SdrExchangeView::ImpLimitToWorkArea(Point& rPt) const
61 sal_Bool bRet(sal_False);
63 if(!aMaxWorkArea.IsEmpty())
65 if(rPt.X()<aMaxWorkArea.Left())
67 rPt.X() = aMaxWorkArea.Left();
68 bRet = sal_True;
71 if(rPt.X()>aMaxWorkArea.Right())
73 rPt.X() = aMaxWorkArea.Right();
74 bRet = sal_True;
77 if(rPt.Y()<aMaxWorkArea.Top())
79 rPt.Y() = aMaxWorkArea.Top();
80 bRet = sal_True;
83 if(rPt.Y()>aMaxWorkArea.Bottom())
85 rPt.Y() = aMaxWorkArea.Bottom();
86 bRet = sal_True;
89 return bRet;
92 void SdrExchangeView::ImpGetPasteObjList(Point& /*rPos*/, SdrObjList*& rpLst)
94 if (rpLst==NULL)
96 SdrPageView* pPV = GetSdrPageView();
98 if (pPV!=NULL) {
99 rpLst=pPV->GetObjList();
104 sal_Bool SdrExchangeView::ImpGetPasteLayer(const SdrObjList* pObjList, SdrLayerID& rLayer) const
106 sal_Bool bRet=sal_False;
107 rLayer=0;
108 if (pObjList!=NULL) {
109 const SdrPage* pPg=pObjList->GetPage();
110 if (pPg!=NULL) {
111 rLayer=pPg->GetLayerAdmin().GetLayerID(aAktLayer,sal_True);
112 if (rLayer==SDRLAYER_NOTFOUND) rLayer=0;
113 SdrPageView* pPV = GetSdrPageView();
114 if (pPV!=NULL) {
115 bRet=!pPV->GetLockedLayers().IsSet(rLayer) && pPV->GetVisibleLayers().IsSet(rLayer);
119 return bRet;
122 sal_Bool SdrExchangeView::Paste(const XubString& rStr, const Point& rPos, SdrObjList* pLst, sal_uInt32 nOptions)
124 if(!rStr.Len())
125 return sal_False;
127 Point aPos(rPos);
128 ImpGetPasteObjList(aPos,pLst);
129 ImpLimitToWorkArea( aPos );
130 if (pLst==NULL) return sal_False;
131 SdrLayerID nLayer;
132 if (!ImpGetPasteLayer(pLst,nLayer)) return sal_False;
133 bool bUnmark=(nOptions&(SDRINSERT_DONTMARK|SDRINSERT_ADDMARK))==0 && !IsTextEdit();
134 if (bUnmark) UnmarkAllObj();
135 Rectangle aTextRect(0,0,500,500);
136 SdrPage* pPage=pLst->GetPage();
137 if (pPage!=NULL) {
138 aTextRect.SetSize(pPage->GetSize());
140 SdrRectObj* pObj=new SdrRectObj(OBJ_TEXT,aTextRect);
141 pObj->SetModel(pMod);
142 pObj->SetLayer(nLayer);
143 pObj->NbcSetText(rStr); // SetText before SetAttr, else SetAttr doesn't work!
144 if (pDefaultStyleSheet!=NULL) pObj->NbcSetStyleSheet(pDefaultStyleSheet, sal_False);
146 pObj->SetMergedItemSet(aDefaultAttr);
148 SfxItemSet aTempAttr(pMod->GetItemPool()); // no fill, no line
149 aTempAttr.Put(XLineStyleItem(XLINE_NONE));
150 aTempAttr.Put(XFillStyleItem(XFILL_NONE));
152 pObj->SetMergedItemSet(aTempAttr);
154 pObj->FitFrameToTextSize();
155 Size aSiz(pObj->GetLogicRect().GetSize());
156 MapUnit eMap=pMod->GetScaleUnit();
157 Fraction aMap=pMod->GetScaleFraction();
158 ImpPasteObject(pObj,*pLst,aPos,aSiz,MapMode(eMap,Point(0,0),aMap,aMap),nOptions);
159 return sal_True;
162 sal_Bool SdrExchangeView::Paste(SvStream& rInput, const String& rBaseURL, sal_uInt16 eFormat, const Point& rPos, SdrObjList* pLst, sal_uInt32 nOptions)
164 Point aPos(rPos);
165 ImpGetPasteObjList(aPos,pLst);
166 ImpLimitToWorkArea( aPos );
167 if (pLst==NULL) return sal_False;
168 SdrLayerID nLayer;
169 if (!ImpGetPasteLayer(pLst,nLayer)) return sal_False;
170 bool bUnmark=(nOptions&(SDRINSERT_DONTMARK|SDRINSERT_ADDMARK))==0 && !IsTextEdit();
171 if (bUnmark) UnmarkAllObj();
172 Rectangle aTextRect(0,0,500,500);
173 SdrPage* pPage=pLst->GetPage();
174 if (pPage!=NULL) {
175 aTextRect.SetSize(pPage->GetSize());
177 SdrRectObj* pObj=new SdrRectObj(OBJ_TEXT,aTextRect);
178 pObj->SetModel(pMod);
179 pObj->SetLayer(nLayer);
180 if (pDefaultStyleSheet!=NULL) pObj->NbcSetStyleSheet(pDefaultStyleSheet, sal_False);
182 pObj->SetMergedItemSet(aDefaultAttr);
184 SfxItemSet aTempAttr(pMod->GetItemPool()); // no fill, no line
185 aTempAttr.Put(XLineStyleItem(XLINE_NONE));
186 aTempAttr.Put(XFillStyleItem(XFILL_NONE));
188 pObj->SetMergedItemSet(aTempAttr);
190 pObj->NbcSetText(rInput,rBaseURL,eFormat);
191 pObj->FitFrameToTextSize();
192 Size aSiz(pObj->GetLogicRect().GetSize());
193 MapUnit eMap=pMod->GetScaleUnit();
194 Fraction aMap=pMod->GetScaleFraction();
195 ImpPasteObject(pObj,*pLst,aPos,aSiz,MapMode(eMap,Point(0,0),aMap,aMap),nOptions);
197 // b4967543
198 if(pObj && pObj->GetModel() && pObj->GetOutlinerParaObject())
200 SdrOutliner& rOutliner = pObj->GetModel()->GetHitTestOutliner();
201 rOutliner.SetText(*pObj->GetOutlinerParaObject());
203 if(1L == rOutliner.GetParagraphCount())
205 SfxStyleSheet* pCandidate = rOutliner.GetStyleSheet(0L);
207 if(pCandidate)
209 if(pObj->GetModel()->GetStyleSheetPool() == &pCandidate->GetPool())
211 pObj->NbcSetStyleSheet(pCandidate, sal_True);
217 return sal_True;
220 sal_Bool SdrExchangeView::Paste(const SdrModel& rMod, const Point& rPos, SdrObjList* pLst, sal_uInt32 nOptions)
222 const SdrModel* pSrcMod=&rMod;
223 if (pSrcMod==pMod)
224 return sal_False; // this can't work, right?
226 const bool bUndo = IsUndoEnabled();
228 if( bUndo )
229 BegUndo(ImpGetResStr(STR_ExchangePaste));
231 if( mxSelectionController.is() && mxSelectionController->PasteObjModel( rMod ) )
233 if( bUndo )
234 EndUndo();
235 return sal_True;
238 Point aPos(rPos);
239 ImpGetPasteObjList(aPos,pLst);
240 SdrPageView* pMarkPV=NULL;
241 SdrPageView* pPV = GetSdrPageView();
243 if(pPV)
245 if ( pPV->GetObjList() == pLst )
246 pMarkPV=pPV;
249 ImpLimitToWorkArea( aPos );
250 if (pLst==NULL)
251 return sal_False;
253 bool bUnmark=(nOptions&(SDRINSERT_DONTMARK|SDRINSERT_ADDMARK))==0 && !IsTextEdit();
254 if (bUnmark)
255 UnmarkAllObj();
257 // Rescale, if the Model uses a different MapUnit.
258 // Calculate the necessary factors first.
259 MapUnit eSrcUnit=pSrcMod->GetScaleUnit();
260 MapUnit eDstUnit=pMod->GetScaleUnit();
261 bool bResize=eSrcUnit!=eDstUnit;
262 Fraction xResize,yResize;
263 Point aPt0;
264 if (bResize)
266 FrPair aResize(GetMapFactor(eSrcUnit,eDstUnit));
267 xResize=aResize.X();
268 yResize=aResize.Y();
270 SdrObjList* pDstLst=pLst;
271 sal_uInt16 nPg,nPgAnz=pSrcMod->GetPageCount();
272 for (nPg=0; nPg<nPgAnz; nPg++)
274 const SdrPage* pSrcPg=pSrcMod->GetPage(nPg);
276 // Use SnapRect, not BoundRect here
277 Rectangle aR=pSrcPg->GetAllObjSnapRect();
279 if (bResize)
280 ResizeRect(aR,aPt0,xResize,yResize);
281 Point aDist(aPos-aR.Center());
282 Size aSiz(aDist.X(),aDist.Y());
283 sal_uIntPtr nCloneErrCnt=0;
284 sal_uIntPtr nOb,nObAnz=pSrcPg->GetObjCount();
285 bool bMark=pMarkPV!=NULL && !IsTextEdit() && (nOptions&SDRINSERT_DONTMARK)==0;
287 // #i13033#
288 // New mechanism to re-create the connections of cloned connectors
289 CloneList aCloneList;
291 for (nOb=0; nOb<nObAnz; nOb++)
293 const SdrObject* pSrcOb=pSrcPg->GetObj(nOb);
295 SdrObject* pNeuObj = pSrcOb->Clone();
297 if (pNeuObj!=NULL)
299 if(bResize)
301 pNeuObj->GetModel()->SetPasteResize(sal_True);
302 pNeuObj->NbcResize(aPt0,xResize,yResize);
303 pNeuObj->GetModel()->SetPasteResize(sal_False);
306 // #i39861#
307 pNeuObj->SetModel(pDstLst->GetModel());
308 pNeuObj->SetPage(pDstLst->GetPage());
310 pNeuObj->NbcMove(aSiz);
312 const SdrPage* pPg = pDstLst->GetPage();
314 if(pPg)
316 // #i72535#
317 const SdrLayerAdmin& rAd = pPg->GetLayerAdmin();
318 SdrLayerID nLayer(0);
320 if(pNeuObj->ISA(FmFormObj))
322 // for FormControls, force to form layer
323 nLayer = rAd.GetLayerID(rAd.GetControlLayerName(), true);
325 else
327 nLayer = rAd.GetLayerID(aAktLayer, sal_True);
330 if(SDRLAYER_NOTFOUND == nLayer)
332 nLayer = 0;
335 pNeuObj->SetLayer(nLayer);
338 SdrInsertReason aReason(SDRREASON_VIEWCALL);
339 pDstLst->InsertObject(pNeuObj,CONTAINER_APPEND,&aReason);
341 if( bUndo )
342 AddUndo(GetModel()->GetSdrUndoFactory().CreateUndoNewObject(*pNeuObj));
344 if (bMark) {
345 // Don't already set Markhandles!
346 // That is instead being done by ModelHasChanged in MarkView.
347 MarkObj(pNeuObj,pMarkPV,sal_False,sal_True);
350 // #i13033#
351 aCloneList.AddPair(pSrcOb, pNeuObj);
353 else
355 nCloneErrCnt++;
359 // #i13033#
360 // New mechanism to re-create the connections of cloned connectors
361 aCloneList.CopyConnections();
363 if(0L != nCloneErrCnt)
365 #ifdef DBG_UTIL
366 OStringBuffer aStr(RTL_CONSTASCII_STRINGPARAM(
367 "SdrExchangeView::Paste(): Error when cloning "));
369 if(nCloneErrCnt == 1)
371 aStr.append(RTL_CONSTASCII_STRINGPARAM(
372 "a drawing object."));
374 else
376 aStr.append(static_cast<sal_Int32>(nCloneErrCnt));
377 aStr.append(RTL_CONSTASCII_STRINGPARAM(" drawing objects."));
380 aStr.append(RTL_CONSTASCII_STRINGPARAM(
381 " Not copying object connectors."));
383 OSL_FAIL(aStr.getStr());
384 #endif
388 if( bUndo )
389 EndUndo();
391 return sal_True;
394 void SdrExchangeView::ImpPasteObject(SdrObject* pObj, SdrObjList& rLst, const Point& rCenter, const Size& rSiz, const MapMode& rMap, sal_uInt32 nOptions)
396 BigInt nSizX(rSiz.Width());
397 BigInt nSizY(rSiz.Height());
398 MapUnit eSrcMU=rMap.GetMapUnit();
399 MapUnit eDstMU=pMod->GetScaleUnit();
400 FrPair aMapFact(GetMapFactor(eSrcMU,eDstMU));
401 Fraction aDstFr(pMod->GetScaleFraction());
402 nSizX*=aMapFact.X().GetNumerator();
403 nSizX*=rMap.GetScaleX().GetNumerator();
404 nSizX*=aDstFr.GetDenominator();
405 nSizX/=aMapFact.X().GetDenominator();
406 nSizX/=rMap.GetScaleX().GetDenominator();
407 nSizX/=aDstFr.GetNumerator();
408 nSizY*=aMapFact.Y().GetNumerator();
409 nSizY*=rMap.GetScaleY().GetNumerator();
410 nSizX*=aDstFr.GetDenominator();
411 nSizY/=aMapFact.Y().GetDenominator();
412 nSizY/=rMap.GetScaleY().GetDenominator();
413 nSizY/=aDstFr.GetNumerator();
414 long xs=nSizX;
415 long ys=nSizY;
416 Point aPos(rCenter.X()-xs/2,rCenter.Y()-ys/2);
417 Rectangle aR(aPos.X(),aPos.Y(),aPos.X()+xs,aPos.Y()+ys);
418 pObj->SetLogicRect(aR);
419 SdrInsertReason aReason(SDRREASON_VIEWCALL);
420 rLst.InsertObject(pObj,CONTAINER_APPEND,&aReason);
422 if( IsUndoEnabled() )
423 AddUndo(GetModel()->GetSdrUndoFactory().CreateUndoNewObject(*pObj));
425 SdrPageView* pMarkPV=NULL;
426 SdrPageView* pPV = GetSdrPageView();
428 if(pPV)
430 if (pPV->GetObjList()==&rLst)
431 pMarkPV=pPV;
434 bool bMark=pMarkPV!=NULL && !IsTextEdit() && (nOptions&SDRINSERT_DONTMARK)==0;
435 if (bMark)
436 { // select object the first PageView we found
437 MarkObj(pObj,pMarkPV);
441 BitmapEx SdrExchangeView::GetMarkedObjBitmapEx(bool bNoVDevIfOneBmpMarked) const
443 BitmapEx aBmp;
445 if( AreObjectsMarked() )
447 if(1 == GetMarkedObjectCount())
449 if(bNoVDevIfOneBmpMarked)
451 SdrObject* pGrafObjTmp = GetMarkedObjectByIndex( 0 );
452 SdrGrafObj* pGrafObj = ( GetMarkedObjectCount() == 1 ) ? PTR_CAST( SdrGrafObj, pGrafObjTmp ) : NULL;
454 if( pGrafObj && ( pGrafObj->GetGraphicType() == GRAPHIC_BITMAP ) )
456 aBmp = pGrafObj->GetTransformedGraphic().GetBitmapEx();
459 else
461 const SdrGrafObj* pSdrGrafObj = dynamic_cast< const SdrGrafObj* >(GetMarkedObjectByIndex(0));
463 if(pSdrGrafObj && pSdrGrafObj->isEmbeddedSvg())
465 aBmp = pSdrGrafObj->GetGraphic().getSvgData()->getReplacement();
470 if( !aBmp )
472 const GDIMetaFile aGDIMetaFile(GetMarkedObjMetaFile(bNoVDevIfOneBmpMarked));
473 const Rectangle aBound(GetMarkedObjBoundRect());
475 aBmp = convertMetafileToBitmapEx(
476 aGDIMetaFile,
477 basegfx::B2DRange(
478 aBound.Left(), aBound.Top(),
479 aBound.Right(), aBound.Bottom()));
483 return aBmp;
486 // -----------------------------------------------------------------------------
488 GDIMetaFile SdrExchangeView::GetMarkedObjMetaFile(bool bNoVDevIfOneMtfMarked) const
490 GDIMetaFile aMtf;
492 if( AreObjectsMarked() )
494 Rectangle aBound( GetMarkedObjBoundRect() );
495 Size aBoundSize( aBound.GetWidth(), aBound.GetHeight() );
496 MapMode aMap( pMod->GetScaleUnit(), Point(), pMod->GetScaleFraction(), pMod->GetScaleFraction() );
498 if( bNoVDevIfOneMtfMarked )
500 SdrObject* pGrafObjTmp = GetMarkedObjectByIndex( 0 );
501 SdrGrafObj* pGrafObj = ( GetMarkedObjectCount() ==1 ) ? PTR_CAST( SdrGrafObj, pGrafObjTmp ) : NULL;
503 if( pGrafObj )
505 Graphic aGraphic( pGrafObj->GetTransformedGraphic() );
507 // #119735# just use GetGDIMetaFile, it will create a bufferd version of contained bitmap now automatically
508 aMtf = aGraphic.GetGDIMetaFile();
512 if( !aMtf.GetActionSize() )
514 VirtualDevice aOut;
515 const Size aDummySize(2, 2);
517 aOut.SetOutputSizePixel(aDummySize);
518 aOut.EnableOutput(false);
519 aOut.SetMapMode(aMap);
520 aMtf.Clear();
521 aMtf.Record(&aOut);
523 DrawMarkedObj(aOut);
525 aMtf.Stop();
526 aMtf.WindStart();
528 // moving the result is more reliable then setting a relative MapMode at the VDev (used
529 // before), also see #i99268# in GetObjGraphic() below. Some draw actions at
530 // the OutDev are simply not handled correctly when a MapMode is set at the
531 // target devive, e.g. MetaFloatTransparentAction. Even the Move for this action
532 // was missing the manipulation of the embedded Metafile
533 aMtf.Move(-aBound.Left(), -aBound.Top());
535 aMtf.SetPrefMapMode( aMap );
537 // removed PrefSize extension. It is principally wrong to set a reduced size at
538 // the created MetaFile. The mentioned errors occur at output time since the integer
539 // MapModes from VCL lead to errors. It is now corrected in the VCLRenderer for
540 // primitives (and may later be done in breaking up a MetaFile to primitives)
541 aMtf.SetPrefSize(aBoundSize);
545 return aMtf;
548 // -----------------------------------------------------------------------------
550 Graphic SdrExchangeView::GetAllMarkedGraphic() const
552 Graphic aRet;
554 if( AreObjectsMarked() )
556 if( ( 1 == GetMarkedObjectCount() ) && GetSdrMarkByIndex( 0 ) )
557 aRet = SdrExchangeView::GetObjGraphic( pMod, GetMarkedObjectByIndex( 0 ) );
558 else
559 aRet = GetMarkedObjMetaFile(false);
562 return aRet;
565 // -----------------------------------------------------------------------------
567 Graphic SdrExchangeView::GetObjGraphic( const SdrModel* pModel, const SdrObject* pObj )
569 Graphic aRet;
571 if( pModel && pObj )
573 // try to get a graphic from the object first
574 const SdrGrafObj* pSdrGrafObj = dynamic_cast< const SdrGrafObj* >(pObj);
575 const SdrOle2Obj* pSdrOle2Obj = dynamic_cast< const SdrOle2Obj* >(pObj);
577 if(pSdrGrafObj)
579 if(pSdrGrafObj->isEmbeddedSvg())
581 // get Metafile for Svg content
582 aRet = pSdrGrafObj->getMetafileFromEmbeddedSvg();
584 else
586 // Make behaviour coherent with metafile
587 // recording below (which of course also takes
588 // view-transformed objects)
589 aRet = pSdrGrafObj->GetTransformedGraphic();
592 else if(pSdrOle2Obj)
594 if ( pSdrOle2Obj->GetGraphic() )
595 aRet = *pSdrOle2Obj->GetGraphic();
598 // if graphic could not be retrieved => go the hard way and create a MetaFile
599 if( ( GRAPHIC_NONE == aRet.GetType() ) || ( GRAPHIC_DEFAULT == aRet.GetType() ) )
601 VirtualDevice aOut;
602 GDIMetaFile aMtf;
603 const Rectangle aBoundRect( pObj->GetCurrentBoundRect() );
604 const MapMode aMap( pModel->GetScaleUnit(),
605 Point(),
606 pModel->GetScaleFraction(),
607 pModel->GetScaleFraction() );
609 aOut.EnableOutput( sal_False );
610 aOut.SetMapMode( aMap );
611 aMtf.Record( &aOut );
612 pObj->SingleObjectPainter( aOut );
613 aMtf.Stop();
614 aMtf.WindStart();
616 // #i99268# replace the original offset from using XOutDev's SetOffset
617 // NOT (as tried with #i92760#) with another MapMode which gets recorded
618 // by the Metafile itself (what always leads to problems), but by
619 // moving the result directly
620 aMtf.Move(-aBoundRect.Left(), -aBoundRect.Top());
622 aMtf.SetPrefMapMode( aMap );
623 aMtf.SetPrefSize( aBoundRect.GetSize() );
625 if( aMtf.GetActionSize() )
626 aRet = aMtf;
630 return aRet;
633 // -----------------------------------------------------------------------------
635 void SdrExchangeView::DrawMarkedObj(OutputDevice& rOut) const
637 SortMarkedObjects();
639 ::std::vector< ::std::vector< SdrMark* > > aObjVectors( 2 );
640 ::std::vector< SdrMark* >& rObjVector1 = aObjVectors[ 0 ];
641 ::std::vector< SdrMark* >& rObjVector2 = aObjVectors[ 1 ];
642 const SdrLayerAdmin& rLayerAdmin = pMod->GetLayerAdmin();
643 const sal_uInt32 nControlLayerId = rLayerAdmin.GetLayerID( rLayerAdmin.GetControlLayerName(), sal_False );
644 sal_uInt32 n, nCount;
646 for( n = 0, nCount = GetMarkedObjectCount(); n < nCount; n++ )
648 SdrMark* pMark = GetSdrMarkByIndex( n );
650 // paint objects on control layer on top of all other objects
651 if( nControlLayerId == pMark->GetMarkedSdrObj()->GetLayer() )
652 rObjVector2.push_back( pMark );
653 else
654 rObjVector1.push_back( pMark );
657 for( n = 0, nCount = aObjVectors.size(); n < nCount; n++ )
659 ::std::vector< SdrMark* >& rObjVector = aObjVectors[ n ];
661 for( sal_uInt32 i = 0; i < rObjVector.size(); i++ )
663 SdrMark* pMark = rObjVector[ i ];
664 pMark->GetMarkedSdrObj()->SingleObjectPainter( rOut );
669 // -----------------------------------------------------------------------------
671 SdrModel* SdrExchangeView::GetMarkedObjModel() const
673 // Sorting the MarkList here might be problematic in the future, so
674 // use a copy.
675 SortMarkedObjects();
676 SdrModel* pNeuMod=pMod->AllocModel();
677 SdrPage* pNeuPag=pNeuMod->AllocPage(sal_False);
678 pNeuMod->InsertPage(pNeuPag);
680 if( !mxSelectionController.is() || !mxSelectionController->GetMarkedObjModel( pNeuPag ) )
682 ::std::vector< ::std::vector< SdrMark* > > aObjVectors( 2 );
683 ::std::vector< SdrMark* >& rObjVector1 = aObjVectors[ 0 ];
684 ::std::vector< SdrMark* >& rObjVector2 = aObjVectors[ 1 ];
685 const SdrLayerAdmin& rLayerAdmin = pMod->GetLayerAdmin();
686 const sal_uInt32 nControlLayerId = rLayerAdmin.GetLayerID( rLayerAdmin.GetControlLayerName(), sal_False );
687 sal_uInt32 n, nCount, nCloneErrCnt = 0;
689 for( n = 0, nCount = GetMarkedObjectCount(); n < nCount; n++ )
691 SdrMark* pMark = GetSdrMarkByIndex( n );
693 // paint objects on control layer on top of all otherobjects
694 if( nControlLayerId == pMark->GetMarkedSdrObj()->GetLayer() )
695 rObjVector2.push_back( pMark );
696 else
697 rObjVector1.push_back( pMark );
700 // #i13033#
701 // New mechanism to re-create the connections of cloned connectors
702 CloneList aCloneList;
704 for( n = 0, nCount = aObjVectors.size(); n < nCount; n++ )
706 ::std::vector< SdrMark* >& rObjVector = aObjVectors[ n ];
708 for( sal_uInt32 i = 0; i < rObjVector.size(); i++ )
710 const SdrMark* pMark = rObjVector[ i ];
711 const SdrObject* pObj = pMark->GetMarkedSdrObj();
712 SdrObject* pNeuObj;
714 if( pObj->ISA( SdrPageObj ) )
716 // convert SdrPageObj's to a graphic representation, because
717 // virtual connection to referenced page gets lost in new model
718 pNeuObj = new SdrGrafObj( GetObjGraphic( pMod, pObj ), pObj->GetLogicRect() );
719 pNeuObj->SetPage( pNeuPag );
720 pNeuObj->SetModel( pNeuMod );
722 else
724 pNeuObj = pObj->Clone();
725 pNeuObj->SetPage( pNeuPag );
726 pNeuObj->SetModel( pNeuMod );
729 if( pNeuObj )
731 SdrInsertReason aReason(SDRREASON_VIEWCALL);
732 pNeuPag->InsertObject(pNeuObj,CONTAINER_APPEND,&aReason);
734 // #i13033#
735 aCloneList.AddPair(pObj, pNeuObj);
737 else
738 nCloneErrCnt++;
742 // #i13033#
743 // New mechanism to re-create the connections of cloned connectors
744 aCloneList.CopyConnections();
746 if(0L != nCloneErrCnt)
748 #ifdef DBG_UTIL
749 OStringBuffer aStr(RTL_CONSTASCII_STRINGPARAM(
750 "SdrExchangeView::GetMarkedObjModel(): Error when cloning "));
752 if(nCloneErrCnt == 1)
754 aStr.append(RTL_CONSTASCII_STRINGPARAM(
755 "a drawing object."));
757 else
759 aStr.append(static_cast<sal_Int32>(nCloneErrCnt));
760 aStr.append(RTL_CONSTASCII_STRINGPARAM(" drawing objects."));
763 aStr.append(RTL_CONSTASCII_STRINGPARAM(
764 " Not copying object connectors."));
766 OSL_FAIL(aStr.getStr());
767 #endif
770 return pNeuMod;
773 // -----------------------------------------------------------------------------
775 sal_Bool SdrExchangeView::Cut( sal_uIntPtr /*nFormat */)
777 OSL_FAIL( "SdrExchangeView::Cut: Not supported any more." );
778 return sal_False;
781 // -----------------------------------------------------------------------------
783 sal_Bool SdrExchangeView::Yank(sal_uIntPtr /*nFormat*/)
785 OSL_FAIL( "SdrExchangeView::Yank: Not supported any more." );
786 return sal_False;
789 // -----------------------------------------------------------------------------
791 sal_Bool SdrExchangeView::Paste(Window* /*pWin*/, sal_uIntPtr /*nFormat*/)
793 OSL_FAIL( "SdrExchangeView::Paste: Not supported any more." );
794 return sal_False;
797 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */