merge the formfield patch from ooo-build
[ooovba.git] / svx / source / svdraw / svdxcgv.cxx
blob4d717d4dfa7765e3f3549cce2126f71d69eea91b
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: svdxcgv.cxx,v $
10 * $Revision: 1.34.18.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svx.hxx"
34 #include <vector>
35 #include <svx/editeng.hxx>
36 #include "xexch.hxx"
37 #include <svx/xflclit.hxx>
38 #include <svx/svdxcgv.hxx>
39 #include <svx/svdoutl.hxx>
40 #include "svditext.hxx"
41 #include <svx/svdetc.hxx>
42 #include <svx/svdundo.hxx>
43 #include <svx/svdograf.hxx>
44 #include <svx/svdoole2.hxx> // fuer kein OLE im SdrClipboardFormat
45 #include <svx/svdorect.hxx>
46 #include <svx/svdoedge.hxx> // fuer Konnektoren uebers Clipboard
47 #include <svx/svdopage.hxx> // fuer Konnektoren uebers Clipboard
48 #include <svx/svdpage.hxx>
49 #include <svx/svdpagv.hxx>
50 #include <svx/svdtrans.hxx> // Fuer GetMapFactor zum umskalieren bei PasteModel
51 #include "svdstr.hrc" // Namen aus der Resource
52 #include "svdglob.hxx" // StringCache
53 #include "xoutbmp.hxx"
54 #include <vcl/metaact.hxx>
55 #include <svtools/poolitem.hxx>
56 #include <svtools/itempool.hxx>
57 #include <tools/bigint.hxx>
58 #include <sot/formats.hxx>
60 // #i13033#
61 #include <clonelist.hxx>
62 #include <vcl/virdev.hxx>
64 // b4967543
65 #include <svtools/style.hxx>
67 // #i72535#
68 #include "fmobj.hxx"
70 ////////////////////////////////////////////////////////////////////////////////////////////////////
72 SdrExchangeView::SdrExchangeView(SdrModel* pModel1, OutputDevice* pOut):
73 SdrObjEditView(pModel1,pOut)
77 ////////////////////////////////////////////////////////////////////////////////////////////////////
79 Point SdrExchangeView::GetViewCenter(const OutputDevice* pOut) const
81 Point aCenter;
82 if (pOut==NULL)
84 pOut = GetFirstOutputDevice();
86 if (pOut!=NULL) {
87 Point aOfs=pOut->GetMapMode().GetOrigin();
88 Size aOutSiz=pOut->GetOutputSize();
89 aOutSiz.Width()/=2;
90 aOutSiz.Height()/=2;
91 aCenter.X()=aOutSiz.Width() -aOfs.X();
92 aCenter.Y()=aOutSiz.Height()-aOfs.Y();
94 return aCenter;
97 Point SdrExchangeView::GetPastePos(SdrObjList* pLst, OutputDevice* pOut)
99 Point aP(GetViewCenter(pOut));
100 SdrPage* pPg=NULL;
101 if (pLst!=NULL) pPg=pLst->GetPage();
102 if (pPg!=NULL) {
103 Size aSiz(pPg->GetSize());
104 aP.X()=aSiz.Width()/2;
105 aP.Y()=aSiz.Height()/2;
107 return aP;
110 BOOL SdrExchangeView::ImpLimitToWorkArea(Point& rPt) const
112 BOOL bRet(FALSE);
114 if(!aMaxWorkArea.IsEmpty())
116 if(rPt.X()<aMaxWorkArea.Left())
118 rPt.X() = aMaxWorkArea.Left();
119 bRet = TRUE;
122 if(rPt.X()>aMaxWorkArea.Right())
124 rPt.X() = aMaxWorkArea.Right();
125 bRet = TRUE;
128 if(rPt.Y()<aMaxWorkArea.Top())
130 rPt.Y() = aMaxWorkArea.Top();
131 bRet = TRUE;
134 if(rPt.Y()>aMaxWorkArea.Bottom())
136 rPt.Y() = aMaxWorkArea.Bottom();
137 bRet = TRUE;
140 return bRet;
143 void SdrExchangeView::ImpGetPasteObjList(Point& /*rPos*/, SdrObjList*& rpLst)
145 if (rpLst==NULL)
147 SdrPageView* pPV = GetSdrPageView();
149 if (pPV!=NULL) {
150 rpLst=pPV->GetObjList();
155 BOOL SdrExchangeView::ImpGetPasteLayer(const SdrObjList* pObjList, SdrLayerID& rLayer) const
157 BOOL bRet=FALSE;
158 rLayer=0;
159 if (pObjList!=NULL) {
160 const SdrPage* pPg=pObjList->GetPage();
161 if (pPg!=NULL) {
162 rLayer=pPg->GetLayerAdmin().GetLayerID(aAktLayer,TRUE);
163 if (rLayer==SDRLAYER_NOTFOUND) rLayer=0;
164 SdrPageView* pPV = GetSdrPageView();
165 if (pPV!=NULL) {
166 bRet=!pPV->GetLockedLayers().IsSet(rLayer) && pPV->GetVisibleLayers().IsSet(rLayer);
170 return bRet;
173 ////////////////////////////////////////////////////////////////////////////////////////////////////
175 BOOL SdrExchangeView::Paste(const GDIMetaFile& rMtf, const Point& rPos, SdrObjList* pLst, UINT32 nOptions)
177 Point aPos(rPos);
178 ImpGetPasteObjList(aPos,pLst);
179 ImpLimitToWorkArea( aPos );
180 if (pLst==NULL) return FALSE;
181 SdrLayerID nLayer;
182 if (!ImpGetPasteLayer(pLst,nLayer)) return FALSE;
183 BOOL bUnmark=(nOptions&(SDRINSERT_DONTMARK|SDRINSERT_ADDMARK))==0 && !IsTextEdit();
184 if (bUnmark) UnmarkAllObj();
185 SdrGrafObj* pObj=new SdrGrafObj(Graphic(rMtf));
186 pObj->SetLayer(nLayer);
187 ImpPasteObject(pObj,*pLst,aPos,rMtf.GetPrefSize(),rMtf.GetPrefMapMode(),nOptions);
188 return TRUE;
191 BOOL SdrExchangeView::Paste(const Bitmap& rBmp, const Point& rPos, SdrObjList* pLst, UINT32 nOptions)
193 Point aPos(rPos);
194 ImpGetPasteObjList(aPos,pLst);
195 ImpLimitToWorkArea( aPos );
196 if (pLst==NULL) return FALSE;
197 SdrLayerID nLayer;
198 if (!ImpGetPasteLayer(pLst,nLayer)) return FALSE;
199 BOOL bUnmark=(nOptions&(SDRINSERT_DONTMARK|SDRINSERT_ADDMARK))==0 && !IsTextEdit();
200 if (bUnmark) UnmarkAllObj();
201 SdrGrafObj* pObj=new SdrGrafObj(Graphic(rBmp));
202 pObj->SetLayer(nLayer);
203 ImpPasteObject(pObj,*pLst,aPos,rBmp.GetSizePixel(),MapMode(MAP_PIXEL),nOptions);
204 return TRUE;
207 BOOL SdrExchangeView::Paste(const XubString& rStr, const Point& rPos, SdrObjList* pLst, UINT32 nOptions)
209 if(!rStr.Len())
210 return FALSE;
212 Point aPos(rPos);
213 ImpGetPasteObjList(aPos,pLst);
214 ImpLimitToWorkArea( aPos );
215 if (pLst==NULL) return FALSE;
216 SdrLayerID nLayer;
217 if (!ImpGetPasteLayer(pLst,nLayer)) return FALSE;
218 BOOL bUnmark=(nOptions&(SDRINSERT_DONTMARK|SDRINSERT_ADDMARK))==0 && !IsTextEdit();
219 if (bUnmark) UnmarkAllObj();
220 Rectangle aTextRect(0,0,500,500);
221 SdrPage* pPage=pLst->GetPage();
222 if (pPage!=NULL) {
223 aTextRect.SetSize(pPage->GetSize());
225 SdrRectObj* pObj=new SdrRectObj(OBJ_TEXT,aTextRect);
226 pObj->SetModel(pMod);
227 pObj->SetLayer(nLayer);
228 pObj->NbcSetText(rStr); // #32424# SetText vor SetAttr, weil SetAttr sonst unwirksam!
229 if (pDefaultStyleSheet!=NULL) pObj->NbcSetStyleSheet(pDefaultStyleSheet, sal_False);
231 pObj->SetMergedItemSet(aDefaultAttr);
233 SfxItemSet aTempAttr(pMod->GetItemPool()); // Keine Fuellung oder Linie
234 aTempAttr.Put(XLineStyleItem(XLINE_NONE));
235 aTempAttr.Put(XFillStyleItem(XFILL_NONE));
237 pObj->SetMergedItemSet(aTempAttr);
239 pObj->FitFrameToTextSize();
240 Size aSiz(pObj->GetLogicRect().GetSize());
241 MapUnit eMap=pMod->GetScaleUnit();
242 Fraction aMap=pMod->GetScaleFraction();
243 ImpPasteObject(pObj,*pLst,aPos,aSiz,MapMode(eMap,Point(0,0),aMap,aMap),nOptions);
244 return TRUE;
247 BOOL SdrExchangeView::Paste(SvStream& rInput, const String& rBaseURL, USHORT eFormat, const Point& rPos, SdrObjList* pLst, UINT32 nOptions)
249 Point aPos(rPos);
250 ImpGetPasteObjList(aPos,pLst);
251 ImpLimitToWorkArea( aPos );
252 if (pLst==NULL) return FALSE;
253 SdrLayerID nLayer;
254 if (!ImpGetPasteLayer(pLst,nLayer)) return FALSE;
255 BOOL bUnmark=(nOptions&(SDRINSERT_DONTMARK|SDRINSERT_ADDMARK))==0 && !IsTextEdit();
256 if (bUnmark) UnmarkAllObj();
257 Rectangle aTextRect(0,0,500,500);
258 SdrPage* pPage=pLst->GetPage();
259 if (pPage!=NULL) {
260 aTextRect.SetSize(pPage->GetSize());
262 SdrRectObj* pObj=new SdrRectObj(OBJ_TEXT,aTextRect);
263 pObj->SetModel(pMod);
264 pObj->SetLayer(nLayer);
265 if (pDefaultStyleSheet!=NULL) pObj->NbcSetStyleSheet(pDefaultStyleSheet, sal_False);
267 pObj->SetMergedItemSet(aDefaultAttr);
269 SfxItemSet aTempAttr(pMod->GetItemPool()); // Keine Fuellung oder Linie
270 aTempAttr.Put(XLineStyleItem(XLINE_NONE));
271 aTempAttr.Put(XFillStyleItem(XFILL_NONE));
273 pObj->SetMergedItemSet(aTempAttr);
275 pObj->NbcSetText(rInput,rBaseURL,eFormat);
276 pObj->FitFrameToTextSize();
277 Size aSiz(pObj->GetLogicRect().GetSize());
278 MapUnit eMap=pMod->GetScaleUnit();
279 Fraction aMap=pMod->GetScaleFraction();
280 ImpPasteObject(pObj,*pLst,aPos,aSiz,MapMode(eMap,Point(0,0),aMap,aMap),nOptions);
282 // b4967543
283 if(pObj && pObj->GetModel() && pObj->GetOutlinerParaObject())
285 SdrOutliner& rOutliner = pObj->GetModel()->GetHitTestOutliner();
286 rOutliner.SetText(*pObj->GetOutlinerParaObject());
288 if(1L == rOutliner.GetParagraphCount())
290 SfxStyleSheet* pCandidate = rOutliner.GetStyleSheet(0L);
292 if(pCandidate)
294 if(pObj->GetModel()->GetStyleSheetPool() == &pCandidate->GetPool())
296 pObj->NbcSetStyleSheet(pCandidate, sal_True);
302 return TRUE;
305 BOOL SdrExchangeView::Paste(const SdrModel& rMod, const Point& rPos, SdrObjList* pLst, UINT32 nOptions)
307 const SdrModel* pSrcMod=&rMod;
308 if (pSrcMod==pMod)
309 return FALSE; // na so geht's ja nun nicht
311 const bool bUndo = IsUndoEnabled();
313 if( bUndo )
314 BegUndo(ImpGetResStr(STR_ExchangePaste));
316 if( mxSelectionController.is() && mxSelectionController->PasteObjModel( rMod ) )
318 if( bUndo )
319 EndUndo();
320 return TRUE;
323 Point aPos(rPos);
324 ImpGetPasteObjList(aPos,pLst);
325 SdrPageView* pMarkPV=NULL;
326 SdrPageView* pPV = GetSdrPageView();
328 if(pPV)
330 if ( pPV->GetObjList() == pLst )
331 pMarkPV=pPV;
334 ImpLimitToWorkArea( aPos );
335 if (pLst==NULL)
336 return FALSE;
338 BOOL bUnmark=(nOptions&(SDRINSERT_DONTMARK|SDRINSERT_ADDMARK))==0 && !IsTextEdit();
339 if (bUnmark)
340 UnmarkAllObj();
342 // evtl. umskalieren bei unterschiedlicher MapUnit am Model
343 // Dafuer erstmal die Faktoren berechnen
344 MapUnit eSrcUnit=pSrcMod->GetScaleUnit();
345 MapUnit eDstUnit=pMod->GetScaleUnit();
346 BOOL bResize=eSrcUnit!=eDstUnit;
347 Fraction xResize,yResize;
348 Point aPt0;
349 if (bResize)
351 FrPair aResize(GetMapFactor(eSrcUnit,eDstUnit));
352 xResize=aResize.X();
353 yResize=aResize.Y();
355 SdrObjList* pDstLst=pLst;
356 USHORT nPg,nPgAnz=pSrcMod->GetPageCount();
357 for (nPg=0; nPg<nPgAnz; nPg++)
359 const SdrPage* pSrcPg=pSrcMod->GetPage(nPg);
361 // #104148# Use SnapRect, not BoundRect here
362 Rectangle aR=pSrcPg->GetAllObjSnapRect();
364 if (bResize)
365 ResizeRect(aR,aPt0,xResize,yResize);
366 Point aDist(aPos-aR.Center());
367 Size aSiz(aDist.X(),aDist.Y());
368 //ULONG nDstObjAnz0=pDstLst->GetObjCount();
369 ULONG nCloneErrCnt=0;
370 ULONG nOb,nObAnz=pSrcPg->GetObjCount();
371 BOOL bMark=pMarkPV!=NULL && !IsTextEdit() && (nOptions&SDRINSERT_DONTMARK)==0;
373 // #i13033#
374 // New mechanism to re-create the connections of cloned connectors
375 CloneList aCloneList;
377 for (nOb=0; nOb<nObAnz; nOb++)
379 const SdrObject* pSrcOb=pSrcPg->GetObj(nOb);
381 // #116235#
382 SdrObject* pNeuObj = pSrcOb->Clone();
384 if (pNeuObj!=NULL)
386 if(bResize)
388 pNeuObj->GetModel()->SetPasteResize(TRUE); // #51139#
389 pNeuObj->NbcResize(aPt0,xResize,yResize);
390 pNeuObj->GetModel()->SetPasteResize(FALSE); // #51139#
393 // #i39861#
394 pNeuObj->SetModel(pDstLst->GetModel());
395 pNeuObj->SetPage(pDstLst->GetPage());
397 pNeuObj->NbcMove(aSiz);
399 const SdrPage* pPg = pDstLst->GetPage();
401 if(pPg)
403 // #i72535#
404 const SdrLayerAdmin& rAd = pPg->GetLayerAdmin();
405 SdrLayerID nLayer(0);
407 if(pNeuObj->ISA(FmFormObj))
409 // for FormControls, force to form layer
410 nLayer = rAd.GetLayerID(rAd.GetControlLayerName(), true);
412 else
414 nLayer = rAd.GetLayerID(aAktLayer, TRUE);
417 if(SDRLAYER_NOTFOUND == nLayer)
419 nLayer = 0;
422 pNeuObj->SetLayer(nLayer);
425 SdrInsertReason aReason(SDRREASON_VIEWCALL);
426 pDstLst->InsertObject(pNeuObj,CONTAINER_APPEND,&aReason);
428 if( bUndo )
429 AddUndo(GetModel()->GetSdrUndoFactory().CreateUndoNewObject(*pNeuObj));
431 if (bMark) {
432 // Markhandles noch nicht sofort setzen!
433 // Das erledigt das ModelHasChanged der MarkView.
434 MarkObj(pNeuObj,pMarkPV,FALSE,TRUE);
437 // #i13033#
438 aCloneList.AddPair(pSrcOb, pNeuObj);
440 else
442 nCloneErrCnt++;
446 // #i13033#
447 // New mechanism to re-create the connections of cloned connectors
448 aCloneList.CopyConnections();
450 if(0L != nCloneErrCnt)
452 #ifdef DBG_UTIL
453 ByteString aStr("SdrExchangeView::Paste(): Fehler beim Clonen ");
455 if(nCloneErrCnt == 1)
457 aStr += "eines Zeichenobjekts.";
459 else
461 aStr += "von ";
462 aStr += ByteString::CreateFromInt32( nCloneErrCnt );
463 aStr += " Zeichenobjekten.";
466 aStr += " Objektverbindungen werden nicht mitkopiert.";
468 DBG_ERROR(aStr.GetBuffer());
469 #endif
473 if( bUndo )
474 EndUndo();
476 return TRUE;
479 BOOL SdrExchangeView::IsExchangeFormatSupported(ULONG nFormat) const
481 return( FORMAT_PRIVATE == nFormat ||
482 FORMAT_GDIMETAFILE == nFormat ||
483 FORMAT_BITMAP == nFormat ||
484 FORMAT_RTF == nFormat ||
485 FORMAT_STRING == nFormat ||
486 SOT_FORMATSTR_ID_DRAWING == nFormat ||
487 SOT_FORMATSTR_ID_EDITENGINE == nFormat );
490 void SdrExchangeView::ImpPasteObject(SdrObject* pObj, SdrObjList& rLst, const Point& rCenter, const Size& rSiz, const MapMode& rMap, UINT32 nOptions)
492 BigInt nSizX(rSiz.Width());
493 BigInt nSizY(rSiz.Height());
494 MapUnit eSrcMU=rMap.GetMapUnit();
495 MapUnit eDstMU=pMod->GetScaleUnit();
496 FrPair aMapFact(GetMapFactor(eSrcMU,eDstMU));
497 Fraction aDstFr(pMod->GetScaleFraction());
498 nSizX*=aMapFact.X().GetNumerator();
499 nSizX*=rMap.GetScaleX().GetNumerator();
500 nSizX*=aDstFr.GetDenominator();
501 nSizX/=aMapFact.X().GetDenominator();
502 nSizX/=rMap.GetScaleX().GetDenominator();
503 nSizX/=aDstFr.GetNumerator();
504 nSizY*=aMapFact.Y().GetNumerator();
505 nSizY*=rMap.GetScaleY().GetNumerator();
506 nSizX*=aDstFr.GetDenominator();
507 nSizY/=aMapFact.Y().GetDenominator();
508 nSizY/=rMap.GetScaleY().GetDenominator();
509 nSizY/=aDstFr.GetNumerator();
510 long xs=nSizX;
511 long ys=nSizY;
512 Point aPos(rCenter.X()-xs/2,rCenter.Y()-ys/2);
513 Rectangle aR(aPos.X(),aPos.Y(),aPos.X()+xs,aPos.Y()+ys);
514 pObj->SetLogicRect(aR);
515 SdrInsertReason aReason(SDRREASON_VIEWCALL);
516 rLst.InsertObject(pObj,CONTAINER_APPEND,&aReason);
518 if( IsUndoEnabled() )
519 AddUndo(GetModel()->GetSdrUndoFactory().CreateUndoNewObject(*pObj));
521 SdrPageView* pMarkPV=NULL;
522 SdrPageView* pPV = GetSdrPageView();
524 if(pPV)
526 if (pPV->GetObjList()==&rLst)
527 pMarkPV=pPV;
530 BOOL bMark=pMarkPV!=NULL && !IsTextEdit() && (nOptions&SDRINSERT_DONTMARK)==0;
531 if (bMark)
532 { // Obj in der ersten gefundenen PageView markieren
533 MarkObj(pObj,pMarkPV);
537 ////////////////////////////////////////////////////////////////////////////////////////////////////
539 Bitmap SdrExchangeView::GetMarkedObjBitmap( BOOL bNoVDevIfOneBmpMarked ) const
541 Bitmap aBmp;
543 if( AreObjectsMarked() )
545 if( bNoVDevIfOneBmpMarked )
547 SdrObject* pGrafObjTmp = GetMarkedObjectByIndex( 0 );
548 SdrGrafObj* pGrafObj = ( GetMarkedObjectCount() == 1 ) ? PTR_CAST( SdrGrafObj, pGrafObjTmp ) : NULL;
550 if( pGrafObj && ( pGrafObj->GetGraphicType() == GRAPHIC_BITMAP ) )
551 aBmp = pGrafObj->GetTransformedGraphic().GetBitmap();
554 if( !aBmp )
556 const Graphic aGraphic( GetMarkedObjMetaFile( bNoVDevIfOneBmpMarked ) );
558 // #i102089# support user's settings of AA and LineSnap when the MetaFile gets
559 // rasterconverted to a bitmap
560 const SvtOptionsDrawinglayer aDrawinglayerOpt;
561 const GraphicConversionParameters aParameters(
562 Size(),
563 false,
564 aDrawinglayerOpt.IsAntiAliasing(),
565 aDrawinglayerOpt.IsSnapHorVerLinesToDiscrete());
567 aBmp = aGraphic.GetBitmap(aParameters);
571 return aBmp;
574 // -----------------------------------------------------------------------------
576 GDIMetaFile SdrExchangeView::GetMarkedObjMetaFile( BOOL bNoVDevIfOneMtfMarked ) const
578 GDIMetaFile aMtf;
580 if( AreObjectsMarked() )
582 Rectangle aBound( GetMarkedObjBoundRect() );
583 Size aBoundSize( aBound.GetWidth(), aBound.GetHeight() );
584 MapMode aMap( pMod->GetScaleUnit(), Point(), pMod->GetScaleFraction(), pMod->GetScaleFraction() );
586 if( bNoVDevIfOneMtfMarked )
588 SdrObject* pGrafObjTmp = GetMarkedObjectByIndex( 0 );
589 SdrGrafObj* pGrafObj = ( GetMarkedObjectCount() ==1 ) ? PTR_CAST( SdrGrafObj, pGrafObjTmp ) : NULL;
591 if( pGrafObj )
593 Graphic aGraphic( pGrafObj->GetTransformedGraphic() );
595 if( aGraphic.GetType() == GRAPHIC_BITMAP )
597 const Point aPos;
599 aMtf.AddAction( new MetaBmpExScaleAction( aPos, aBoundSize, aGraphic.GetBitmapEx() ) );
600 aMtf.SetPrefMapMode( aMap );
601 aMtf.SetPrefSize( aBoundSize );
603 else
604 aMtf = aGraphic.GetGDIMetaFile();
608 if( !aMtf.GetActionCount() )
610 VirtualDevice aOut;
611 Size aDummySize( 2, 2 );
613 aOut.SetOutputSizePixel( aDummySize );
614 aOut.EnableOutput( FALSE );
615 aOut.SetMapMode( aMap );
617 aMtf.Clear();
618 aMtf.Record( &aOut );
620 // Replace offset given formally to DrawMarkedObj and used at XOutDev with relative
621 // MapMode (which was also used in XOutDev in that case). Goal is to paint the object
622 // as if TopLeft point is (0,0)
623 const Fraction aNeutralFraction(1, 1);
624 const MapMode aRelativeMapMode(MAP_RELATIVE, Point(-aBound.Left(), -aBound.Top()), aNeutralFraction, aNeutralFraction);
625 aOut.SetMapMode(aRelativeMapMode);
627 DrawMarkedObj(aOut);
629 aMtf.Stop();
630 aMtf.WindStart();
631 aMtf.SetPrefMapMode( aMap );
633 // removed PrefSize extension. It is principially wrong to set a reduced size at
634 // the created MetaFile. The mentioned errors occurr at output time since the integer
635 // MapModes from VCL lead to errors. It is now corrected in the VCLRenderer for
636 // primitives (and may later be done in breaking up a MetaFile to primitives)
637 aMtf.SetPrefSize(aBoundSize);
641 return aMtf;
644 // -----------------------------------------------------------------------------
646 Graphic SdrExchangeView::GetAllMarkedGraphic() const
648 Graphic aRet;
650 if( AreObjectsMarked() )
652 if( ( 1 == GetMarkedObjectCount() ) && GetSdrMarkByIndex( 0 ) )
653 aRet = SdrExchangeView::GetObjGraphic( pMod, GetMarkedObjectByIndex( 0 ) );
654 else
655 aRet = GetMarkedObjMetaFile( FALSE );
658 return aRet;
661 // -----------------------------------------------------------------------------
663 Graphic SdrExchangeView::GetObjGraphic( const SdrModel* pModel, const SdrObject* pObj )
665 Graphic aRet;
667 if( pModel && pObj )
669 // try to get a graphic from the object first
670 const SdrGrafObj* pSdrGrafObj = dynamic_cast< const SdrGrafObj* >(pObj);
671 const SdrOle2Obj* pSdrOle2Obj = dynamic_cast< const SdrOle2Obj* >(pObj);
673 if(pSdrGrafObj)
675 // #110981# Make behaviour coherent with metafile
676 // recording below (which of course also takes
677 // view-transformed objects)
678 aRet = pSdrGrafObj->GetTransformedGraphic();
680 else if(pSdrOle2Obj)
682 if ( pSdrOle2Obj->GetGraphic() )
683 aRet = *pSdrOle2Obj->GetGraphic();
686 // if graphic could not be retrieved => go the hard way and create a MetaFile
687 if( ( GRAPHIC_NONE == aRet.GetType() ) || ( GRAPHIC_DEFAULT == aRet.GetType() ) )
689 VirtualDevice aOut;
690 GDIMetaFile aMtf;
691 const Rectangle aBoundRect( pObj->GetCurrentBoundRect() );
692 const MapMode aMap( pModel->GetScaleUnit(),
693 Point(),
694 pModel->GetScaleFraction(),
695 pModel->GetScaleFraction() );
697 aOut.EnableOutput( FALSE );
698 aOut.SetMapMode( aMap );
699 aMtf.Record( &aOut );
700 pObj->SingleObjectPainter( aOut ); // #110094#-17
701 aMtf.Stop();
702 aMtf.WindStart();
704 // #i99268# replace the original offset from using XOutDev's SetOffset
705 // NOT (as tried with #i92760#) with another MapMode which gets recorded
706 // by the Metafile itself (what always leads to problems), but by hardly
707 // moving the result
708 aMtf.Move(-aBoundRect.Left(), -aBoundRect.Top());
710 aMtf.SetPrefMapMode( aMap );
711 aMtf.SetPrefSize( aBoundRect.GetSize() );
713 if( aMtf.GetActionCount() )
714 aRet = aMtf;
718 return aRet;
721 // -----------------------------------------------------------------------------
723 void SdrExchangeView::DrawMarkedObj(OutputDevice& rOut) const
725 SortMarkedObjects();
727 ::std::vector< ::std::vector< SdrMark* > > aObjVectors( 2 );
728 ::std::vector< SdrMark* >& rObjVector1 = aObjVectors[ 0 ];
729 ::std::vector< SdrMark* >& rObjVector2 = aObjVectors[ 1 ];
730 const SdrLayerAdmin& rLayerAdmin = pMod->GetLayerAdmin();
731 const sal_uInt32 nControlLayerId = rLayerAdmin.GetLayerID( rLayerAdmin.GetControlLayerName(), FALSE );
732 sal_uInt32 n, nCount;
734 for( n = 0, nCount = GetMarkedObjectCount(); n < nCount; n++ )
736 SdrMark* pMark = GetSdrMarkByIndex( n );
738 // paint objects on control layer on top of all otherobjects
739 if( nControlLayerId == pMark->GetMarkedSdrObj()->GetLayer() )
740 rObjVector2.push_back( pMark );
741 else
742 rObjVector1.push_back( pMark );
745 for( n = 0, nCount = aObjVectors.size(); n < nCount; n++ )
747 ::std::vector< SdrMark* >& rObjVector = aObjVectors[ n ];
749 for( sal_uInt32 i = 0; i < rObjVector.size(); i++ )
751 SdrMark* pMark = rObjVector[ i ];
752 pMark->GetMarkedSdrObj()->SingleObjectPainter( rOut ); // #110094#-17
757 // -----------------------------------------------------------------------------
759 SdrModel* SdrExchangeView::GetMarkedObjModel() const
761 // Wenn das sortieren der MarkList mal stoeren sollte,
762 // werde ich sie mir wohl kopieren muessen.
763 SortMarkedObjects();
764 SdrModel* pNeuMod=pMod->AllocModel();
765 SdrPage* pNeuPag=pNeuMod->AllocPage(FALSE);
766 pNeuMod->InsertPage(pNeuPag);
768 if( !mxSelectionController.is() || !mxSelectionController->GetMarkedObjModel( pNeuPag ) )
770 ::std::vector< ::std::vector< SdrMark* > > aObjVectors( 2 );
771 ::std::vector< SdrMark* >& rObjVector1 = aObjVectors[ 0 ];
772 ::std::vector< SdrMark* >& rObjVector2 = aObjVectors[ 1 ];
773 const SdrLayerAdmin& rLayerAdmin = pMod->GetLayerAdmin();
774 const sal_uInt32 nControlLayerId = rLayerAdmin.GetLayerID( rLayerAdmin.GetControlLayerName(), FALSE );
775 sal_uInt32 n, nCount, nCloneErrCnt = 0;
777 for( n = 0, nCount = GetMarkedObjectCount(); n < nCount; n++ )
779 SdrMark* pMark = GetSdrMarkByIndex( n );
781 // paint objects on control layer on top of all otherobjects
782 if( nControlLayerId == pMark->GetMarkedSdrObj()->GetLayer() )
783 rObjVector2.push_back( pMark );
784 else
785 rObjVector1.push_back( pMark );
788 // #i13033#
789 // New mechanism to re-create the connections of cloned connectors
790 CloneList aCloneList;
792 for( n = 0, nCount = aObjVectors.size(); n < nCount; n++ )
794 ::std::vector< SdrMark* >& rObjVector = aObjVectors[ n ];
796 for( sal_uInt32 i = 0; i < rObjVector.size(); i++ )
798 const SdrMark* pMark = rObjVector[ i ];
799 const SdrObject* pObj = pMark->GetMarkedSdrObj();
800 SdrObject* pNeuObj;
802 if( pObj->ISA( SdrPageObj ) )
804 // convert SdrPageObj's to a graphic representation, because
805 // virtual connection to referenced page gets lost in new model
806 pNeuObj = new SdrGrafObj( GetObjGraphic( pMod, pObj ), pObj->GetLogicRect() );
807 pNeuObj->SetPage( pNeuPag );
808 pNeuObj->SetModel( pNeuMod );
810 else
812 // #116235#
813 // pNeuObj = pObj->Clone( pNeuPag, pNeuMod );
814 pNeuObj = pObj->Clone();
815 pNeuObj->SetPage( pNeuPag );
816 pNeuObj->SetModel( pNeuMod );
819 if( pNeuObj )
821 SdrInsertReason aReason(SDRREASON_VIEWCALL);
822 pNeuPag->InsertObject(pNeuObj,CONTAINER_APPEND,&aReason);
824 // #i13033#
825 aCloneList.AddPair(pObj, pNeuObj);
827 else
828 nCloneErrCnt++;
832 // #i13033#
833 // New mechanism to re-create the connections of cloned connectors
834 aCloneList.CopyConnections();
836 if(0L != nCloneErrCnt)
838 #ifdef DBG_UTIL
839 ByteString aStr("SdrExchangeView::GetMarkedObjModel(): Fehler beim Clonen ");
841 if(nCloneErrCnt == 1)
843 aStr += "eines Zeichenobjekts.";
845 else
847 aStr += "von ";
848 aStr += ByteString::CreateFromInt32( nCloneErrCnt );
849 aStr += " Zeichenobjekten.";
852 aStr += " Objektverbindungen werden nicht mitkopiert.";
854 DBG_ERROR(aStr.GetBuffer());
855 #endif
858 return pNeuMod;
861 // -----------------------------------------------------------------------------
863 BOOL SdrExchangeView::Cut( ULONG /*nFormat */)
865 DBG_ERROR( "SdrExchangeView::Cut: Not supported anymore" );
866 return FALSE;
869 // -----------------------------------------------------------------------------
871 void SdrExchangeView::CutMarked( ULONG /*nFormat */)
873 DBG_ERROR( "SdrExchangeView::CutMarked: Not supported anymore" );
876 // -----------------------------------------------------------------------------
878 BOOL SdrExchangeView::Yank(ULONG /*nFormat*/)
880 DBG_ERROR( "SdrExchangeView::Yank: Not supported anymore" );
881 return FALSE;
884 // -----------------------------------------------------------------------------
886 void SdrExchangeView::YankMarked(ULONG /*nFormat*/)
888 DBG_ERROR( "YankMarked: Not supported anymore" );
891 // -----------------------------------------------------------------------------
893 BOOL SdrExchangeView::Paste(Window* /*pWin*/, ULONG /*nFormat*/)
895 DBG_ERROR( "SdrExchangeView::Paste: Not supported anymore" );
896 return FALSE;